dune-geometry  2.2.0
geometry.hh
Go to the documentation of this file.
00001 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002 // vi: set et ts=8 sw=2 sts=2:
00003 
00004 #ifndef DUNE_GENERICGEOMETRY_GEOMETRY_HH
00005 #define DUNE_GENERICGEOMETRY_GEOMETRY_HH
00006 
00007 #include <dune/common/typetraits.hh>
00008 #include <dune/common/nullptr.hh>
00009 
00010 #include <dune/geometry/referenceelements.hh>
00011 #include <dune/geometry/genericgeometry/mappingprovider.hh>
00012 #include <dune/geometry/genericgeometry/geometrytraits.hh>
00013 
00014 namespace Dune
00015 {
00016 
00017   namespace GenericGeometry
00018   {
00019 
00171     // BasicGeometry
00172     // -------------
00173 
00247     template< int mydim, class Traits >
00248     class BasicGeometry
00249     {
00250       typedef typename Traits :: CoordTraits CoordTraits;
00251 
00252       static const int dimGrid = Traits :: dimGrid;
00253 
00255       template< int, class > friend class BasicGeometry;
00256 
00257     public:
00258 
00260       static const int mydimension = mydim;
00261 
00263       static const int coorddimension = Traits :: dimWorld;
00264       
00266       typedef typename CoordTraits :: ctype ctype;
00267 
00269       typedef FieldVector< ctype, mydimension > LocalCoordinate;
00270 
00272       typedef FieldVector< ctype, coorddimension > GlobalCoordinate;
00273 
00274     private:
00275       dune_static_assert( (0 <= mydimension) && (mydimension <= dimGrid),
00276                           "Invalid geometry dimension." );
00277 
00278       static const int codimension = dimGrid - mydimension;
00279 
00280       template< bool >
00281       struct Hybrid
00282       {
00283         typedef HybridMapping< dimGrid, Traits > Mapping;
00284       };
00285 
00286       template< bool >
00287       struct NonHybrid
00288       {
00289         typedef typename GenericGeometry::Topology< Traits::topologyId, dimGrid >::type Topology;
00290         typedef GenericGeometry::NonHybridMapping< Topology, Traits > Mapping;
00291       };
00292 
00293       typedef typename SelectType< Traits::hybrid, Hybrid< true >, NonHybrid< false > >::Type::Mapping
00294         ElementMapping;
00295       typedef GenericGeometry::MappingProvider< ElementMapping, codimension > MappingProvider;
00296 
00297     protected:
00298       typedef typename MappingProvider::Mapping Mapping;
00299 
00300     public:
00306       typedef typename Mapping::JacobianTransposed JacobianTransposed;
00312       typedef typename Mapping::JacobianInverseTransposed Jacobian;
00313       // for cenvencience, Jacobian is the name of the type in the geometry interface 
00314       typedef Jacobian JacobianInverseTransposed;
00315 
00316     public:
00319       BasicGeometry ()
00320       : mapping_( nullptr )
00321       {}
00322 
00328       template< class CoordVector >
00329       DUNE_DEPRECATED BasicGeometry ( const unsigned int topologyId, const CoordVector &coords )
00330       {
00331         mapping_ = MappingProvider::construct( topologyId, coords, mappingStorage_ );
00332       }
00333 
00343       template< class CoordVector >
00344       DUNE_DEPRECATED BasicGeometry ( const unsigned int topologyId, const CoordVector &coords, const bool affine )
00345       {
00346         mapping_ = MappingProvider::construct( topologyId, coords, affine, mappingStorage_ );
00347       }
00348 
00350       template< class CoordVector >
00351       BasicGeometry ( const GeometryType &type, const CoordVector &coords )
00352       {
00353         mapping_ = MappingProvider::construct( type.id(), coords, mappingStorage_ );
00354       }
00355       
00369       template< int fatherdim >
00370       BasicGeometry ( const BasicGeometry< fatherdim, Traits > &father, int i )
00371       {
00372         const unsigned int codim = fatherdim - mydim;
00373         mapping_ = father.mapping_->template trace< codim >( i, mappingStorage_ );
00374       }
00375 
00377       BasicGeometry ( const BasicGeometry &other )
00378       : mapping_( other.mapping_ ? other.mapping_->clone( mappingStorage_ ) : nullptr )
00379       {}
00380 
00382       ~BasicGeometry ()
00383       {
00384         if( mapping_ )
00385           mapping_->~Mapping();
00386       }
00387       
00389       const BasicGeometry &operator= ( const BasicGeometry &other )
00390       {
00391         if( mapping_ )
00392           mapping_->~Mapping();
00393         mapping_ = (other.mapping_) ? other.mapping_->clone( mappingStorage_ ) : nullptr;
00394         return *this;
00395       }
00396 
00404       operator bool () const
00405       {
00406         return bool( mapping_ );
00407       }
00408 
00410       GeometryType type () const
00411       {
00412         return mapping_->type();
00413       }
00414 
00416       int corners () const
00417       {
00418         return mapping_->numCorners();
00419       }
00420 
00422       GlobalCoordinate corner ( const int i ) const
00423       {
00424         return mapping_->corner( i );
00425       }
00426 
00428       GlobalCoordinate global ( const LocalCoordinate &local ) const
00429       {
00430         return mapping_->global( local );
00431       }
00432 
00434       LocalCoordinate local ( const GlobalCoordinate &global ) const
00435       {
00436         return mapping_->local( global );
00437       }
00438 
00440       GlobalCoordinate center () const
00441       {
00442         return mapping_->center();
00443       }
00444 
00446       bool affine () const
00447       {
00448         return mapping_->affine();
00449       }
00450 
00452       ctype integrationElement ( const LocalCoordinate &local ) const
00453       {
00454         return mapping_->integrationElement( local );
00455       }
00456 
00458       ctype volume () const
00459       {
00460         return mapping_->volume();
00461       }
00462 
00467       const JacobianTransposed &jacobianTransposed ( const LocalCoordinate &local ) const
00468       {
00469         return mapping_->jacobianTransposed( local );
00470       }
00471 
00474       const JacobianInverseTransposed &jacobianInverseTransposed ( const LocalCoordinate &local ) const
00475       {
00476         return mapping_->jacobianInverseTransposed( local );
00477       }
00478 
00479     private:
00480 
00482       Mapping* mapping_;
00483       
00489       char mappingStorage_[ MappingProvider::maxMappingSize ];
00490     };
00491 
00492 
00493 
00494     // Geometry
00495     // --------
00496 
00509     template< int mydim, int cdim, class Grid >
00510     class Geometry
00511     : public BasicGeometry< mydim, GlobalGeometryTraits< Grid > >
00512     {
00513       typedef BasicGeometry< mydim, GlobalGeometryTraits< Grid > > Base;
00514 
00515     protected:
00516       typedef typename Base::Mapping Mapping;
00517 
00518     public:
00519         
00520       Geometry ()
00521       {}
00522         
00523       template< class CoordVector >
00524       DUNE_DEPRECATED Geometry ( const unsigned int topologyId, const CoordVector &coords )
00525       : Base( topologyId, coords )
00526       {}
00527 
00528       template< class CoordVector >
00529       DUNE_DEPRECATED Geometry ( const unsigned int topologyId, const CoordVector &coords, const bool affine )
00530       : Base( topologyId, coords, affine )
00531       {}
00532 
00534       template< class Geo >
00535       explicit Geometry ( const Geo &geo )
00536       : Base( geo.type(), geo, geo.affine() )
00537       {}
00538 
00540       template< class CoordVector >
00541       Geometry ( const GeometryType &type, const CoordVector &coords )
00542       : Base( type, coords )
00543       {}
00544       
00546       template< int fatherdim >
00547       Geometry ( const Geometry< fatherdim, cdim, Grid > &father, int i )
00548       : Base( father, i )
00549       {}
00550     };
00551 
00552 
00553 
00554     // LocalGeometry
00555     // -------------
00556 
00569     template< int mydim, int cdim, class Grid >
00570     class LocalGeometry
00571     : public BasicGeometry< mydim, LocalGeometryTraits< Grid > >
00572     {
00573       typedef BasicGeometry< mydim, LocalGeometryTraits< Grid > > Base;
00574 
00575     protected:
00576       typedef typename Base::Mapping Mapping;
00577 
00578     public:
00579       template< class CoordVector >
00580       DUNE_DEPRECATED LocalGeometry ( const unsigned int topologyId, const CoordVector &coords )
00581       : Base( topologyId, coords )
00582       {}
00583 
00584       template< class CoordVector >
00585       DUNE_DEPRECATED LocalGeometry ( const unsigned int topologyId, const CoordVector &coords, const bool affine )
00586       : Base( topologyId, coords, affine )
00587       {}
00588 
00590       template< class Geo >
00591       explicit LocalGeometry ( const Geo &geo )
00592       : Base( geo.type(), geo, geo.affine() )
00593       {}
00594 
00596       template< class CoordVector >
00597       LocalGeometry ( const GeometryType &type, const CoordVector &coords )
00598       : Base( type, coords )
00599       {}
00600       
00602       template< int fatherdim >
00603       LocalGeometry ( const Geometry< fatherdim, cdim, Grid > &father, int i )
00604       : Base( father, i )
00605       {}
00606     };
00607 
00608   }
00609 
00610 }
00611 
00612 #endif // #ifndef DUNE_GENERICGEOMETRY_GEOMETRY_HH