genericgeometry/geometry.hh

00001 #ifndef DUNE_GENERICGEOMETRY_GEOMETRY_HH
00002 #define DUNE_GENERICGEOMETRY_GEOMETRY_HH
00003 
00004 #include <dune/grid/common/geometry.hh>
00005 
00006 #include <dune/grid/genericgeometry/mappingprovider.hh>
00007 #include <dune/grid/genericgeometry/geometrytraits.hh>
00008 
00009 namespace Dune
00010 {
00011 
00012   namespace GenericGeometry
00013   {
00014 
00167     // BasicGeometry
00168     // -------------
00169 
00260     template< int mydim, class Traits >
00261     class BasicGeometry
00262     {
00263       typedef typename Traits :: CoordTraits CoordTraits;
00264 
00265       static const int dimGrid = Traits :: dimGrid;
00266 
00267       template< int, class > friend class BasicGeometry;
00268 
00269     public:
00270 
00272       static const int mydimension = mydim;
00273 
00275       static const int coorddimension = Traits :: dimWorld;
00276       
00278       typedef typename CoordTraits :: ctype ctype;
00279 
00281       typedef FieldVector< ctype, mydimension > LocalCoordinate;
00282 
00284       typedef FieldVector< ctype, coorddimension > GlobalCoordinate;
00285 
00287       typedef FieldMatrix< ctype, coorddimension, mydimension > Jacobian;
00288 
00289     private:
00290       dune_static_assert( (0 <= mydimension) && (mydimension <= dimGrid),
00291                           "Invalid geometry dimension." );
00292 
00293       static const int codimension = dimGrid - mydimension;
00294 
00295       template< bool >
00296       struct Hybrid
00297       {
00298         typedef HybridMapping< dimGrid, Traits > Mapping;
00299       };
00300 
00301       template< bool >
00302       struct NonHybrid
00303       {
00304         typedef typename Convert< Traits :: dunetype, dimGrid > :: type Topology;
00305         typedef GenericGeometry :: CachedMapping< Topology, Traits > Mapping;
00306       };
00307 
00308       typedef GenericGeometry :: DuneGeometryTypeProvider< mydimension, Traits :: linetype >
00309         DuneGeometryTypeProvider;
00310 
00311       typedef typename ProtectedIf< Traits :: hybrid, Hybrid, NonHybrid > :: Mapping
00312         ElementMapping;
00313       typedef GenericGeometry :: MappingProvider< ElementMapping, codimension >
00314         MappingProvider;
00315 
00316     protected:
00317       typedef typename MappingProvider :: Mapping Mapping;
00318 
00319     private:
00320       Mapping *mapping_;
00321 
00322     public:
00323 
00325       BasicGeometry ()
00326       : mapping_( 0 )
00327       {}
00328 
00329 #if 0
00330 
00331       explicit BasicGeometry ( Mapping &mapping ) 
00332       : mapping_( &mapping ) 
00333       {
00334         ++mapping_->referenceCount;
00335       }
00336 #endif
00337  
00339       template< class CoordVector >
00340       BasicGeometry ( const GeometryType &type, const CoordVector &coords )
00341       : mapping_( MappingProvider :: mapping( type, coords ) )
00342       {
00343         mapping_->referenceCount = 1;
00344       }
00345       
00348       template< int fatherdim >
00349       BasicGeometry ( const BasicGeometry< fatherdim, Traits > &father, int i )
00350       : mapping_( subMapping( father, i ) )
00351       {
00352         mapping_->referenceCount = 1;
00353       }
00354 
00356       BasicGeometry ( const BasicGeometry &other )
00357       : mapping_( other.mapping_ )
00358       {
00359         if( mapping_ != 0 )
00360           ++(mapping_->referenceCount);
00361       }
00362 
00364       ~BasicGeometry ()
00365       {
00366         if( (mapping_ != 0) && ((--mapping_->referenceCount) == 0) )
00367           delete mapping_;
00368       }
00369       
00371       BasicGeometry &operator= ( const BasicGeometry &other )
00372       {
00373         if( other.mapping_ != 0 )
00374           ++(other.mapping_->referenceCount);
00375         if( (mapping_ != 0) && (--(mapping_->referenceCount) == 0) )
00376           delete mapping_;
00377         mapping_ = other.mapping_;
00378         return *this;
00379       }
00380 
00384       bool operator! () const
00385       {
00386         return (mapping_ == 0);
00387       }
00388       
00390       GeometryType type () const
00391       {
00392         return DuneGeometryTypeProvider :: type( mapping().topologyId() );
00393       }
00394 
00396       int corners () const
00397       {
00398         return mapping().numCorners();
00399       }
00400 
00402       const GlobalCoordinate &operator[] ( int i ) const
00403       {
00404         return mapping().corner( i );
00405       }
00406 
00408       GlobalCoordinate global ( const LocalCoordinate &local ) const
00409       {
00410         return mapping().global( local );
00411       }
00412 
00414       LocalCoordinate local ( const GlobalCoordinate &global ) const
00415       {
00416         return mapping().local( global );
00417       }
00418 
00420       bool checkInside ( const LocalCoordinate &local ) const
00421       {
00422         return mapping().checkInside( local );
00423       }
00424 
00426       bool affine () const
00427       {
00428         return mapping().affine();
00429       }
00430 
00432       ctype integrationElement ( const LocalCoordinate &local ) const
00433       {
00434         return mapping().integrationElement( local );
00435       }
00436 
00438       ctype volume () const
00439       {
00440         return mapping().volume();
00441       }
00442 
00445       const Jacobian &jacobianInverseTransposed ( const LocalCoordinate &local ) const
00446       {
00447         return mapping().jacobianInverseTransposed( local );
00448       }
00449 
00453       GlobalCoordinate normal ( int face, const LocalCoordinate &local ) const
00454       {
00455         const unsigned int tid = mapping().topologyId();
00456         const unsigned int i = MapNumberingProvider< mydimension >
00457                                  :: template dune2generic< 1 >( tid, face );
00458         return mapping().normal( i, local );
00459       }
00460 
00461     private:
00462       const Mapping &mapping () const
00463       {
00464         assert( mapping_ != 0 );
00465         return *mapping_;
00466       }
00467       template< int fatherdim >
00468       Mapping *
00469       subMapping ( const BasicGeometry< fatherdim, Traits > &father, int i )
00470       {
00471         const unsigned int codim = fatherdim - mydim;
00472         const unsigned int ftid = father.mapping().topologyId();
00473         const unsigned int j = MapNumberingProvider< fatherdim >
00474                                  :: template dune2generic< codim >( ftid, i );
00475         return father.mapping().template trace< codim >( j );
00476       }
00477 
00478     };
00479 
00480 
00481 
00482     // Geometry
00483     // --------
00484 
00497     template< int mydim, int cdim, class Grid >
00498     class Geometry
00499     : public BasicGeometry< mydim, GlobalGeometryTraits< Grid > >
00500     {
00501       typedef BasicGeometry< mydim, GlobalGeometryTraits< Grid > > Base;
00502 
00503     protected:
00504       typedef typename Base :: Mapping Mapping;
00505 
00506     public:
00508       Geometry ()
00509       : Base()
00510       {}
00511       
00513       explicit Geometry ( Mapping &mapping ) 
00514       : Base( mapping ) 
00515       {}
00516  
00518       template< class Geo >
00519       explicit Geometry ( const Geo &geo )
00520       : Base( geo.type(), geo )
00521       {}
00522 
00524       template< class CoordVector >
00525       Geometry ( const GeometryType &type,
00526                  const CoordVector &coords )
00527       : Base( type, coords )
00528       {}
00529       
00531       template< int fatherdim >
00532       Geometry ( const Geometry< fatherdim, cdim, Grid > &father, int i )
00533       : Base( father, i )
00534       {}
00535     };
00536 
00537 
00538 
00539     // LocalGeometry
00540     // -------------
00541 
00554     template< int mydim, int cdim, class Grid >
00555     class LocalGeometry
00556     : public BasicGeometry< mydim, LocalGeometryTraits< Grid > >
00557     {
00558       typedef BasicGeometry< mydim, LocalGeometryTraits< Grid > > Base;
00559 
00560     protected:
00561       typedef typename Base :: Mapping Mapping;
00562 
00563     public:
00565       LocalGeometry ()
00566       : Base()
00567       {}
00568       
00570       explicit LocalGeometry ( Mapping &mapping ) 
00571       : Base( mapping ) 
00572       {}
00573  
00575       template< class Geo >
00576       explicit LocalGeometry ( const Geo &geo )
00577       : Base( geo.type(), geo )
00578       {}
00579 
00581       template< class CoordVector >
00582       LocalGeometry ( const GeometryType &type, const CoordVector &coords )
00583       : Base( type, coords )
00584       {}
00585       
00587       template< int fatherdim >
00588       LocalGeometry ( const Geometry< fatherdim, cdim, Grid > &father, int i )
00589       : Base( father, i )
00590       {}
00591     };
00592 
00593   }
00594 
00595 }
00596 
00597 #endif

Generated on Sun Nov 15 22:28:40 2009 for dune-grid by  doxygen 1.5.6