geometrygrid/entity.hh

Go to the documentation of this file.
00001 #ifndef DUNE_GEOGRID_ENTITY_HH
00002 #define DUNE_GEOGRID_ENTITY_HH
00003 
00004 #include <dune/grid/common/genericreferenceelements.hh>
00005 #include <dune/grid/common/grid.hh>
00006 
00007 #include <dune/grid/geometrygrid/capabilities.hh>
00008 #include <dune/grid/geometrygrid/cornerstorage.hh>
00009 
00010 namespace Dune
00011 {
00012 
00013   namespace GeoGrid
00014   {
00015  
00016     // Internal Forward Declarations
00017     // -----------------------------
00018 
00029     template< int codim, class Grid, bool fake = !(Capabilities::hasHostEntity< Grid, codim >::v) >
00030     class EntityBase;
00031 
00044     template< int codim, int dim, class Grid >
00045     class Entity;
00046 
00047 
00048 
00049     // External Forward Declarations
00050     // -----------------------------
00051 
00052     template< class Grid >
00053     class LevelIntersectionIterator;
00054 
00055     template< class Grid >
00056     class LeafIntersectionIterator;
00057 
00058     template< class Grid >
00059     class HierarchicIterator;
00060 
00061 
00062 
00063     // EntityBase (real)
00064     // -----------------
00065 
00073     template< int codim, class Grid >
00074     class EntityBase< codim, Grid, false >
00075     {
00076       typedef typename remove_const< Grid >::type::Traits Traits;
00077 
00078     public:
00082 
00083       static const int codimension = codim;
00085       static const int dimension = Traits::dimension;
00087       static const int mydimension = dimension - codimension;
00089       static const int dimensionworld = Traits::dimensionworld;
00090 
00092       static const bool fake = false;
00093 
00099 
00100       typedef typename Traits::ctype ctype;
00101 
00103       typedef typename Traits::template Codim< codimension >::Geometry Geometry;
00106     private:
00107       typedef typename Traits::HostGrid HostGrid;
00108       typedef typename Traits::CoordFunction CoordFunction;
00109 
00110     public:
00114 
00115       typedef typename HostGrid::template Codim< codimension >::Entity HostEntity;
00117       typedef typename HostGrid::template Codim< codimension >::EntityPointer HostEntityPointer;
00118 
00120       typedef typename Traits::template Codim< codimension >::EntitySeed EntitySeed;
00121 
00123       typedef typename HostGrid::template Codim< 0 >::Entity HostElement;
00126     private:
00127       typedef typename HostGrid::template Codim< codimension >::Geometry HostGeometry;
00128       
00129       typedef typename GenericGeometry::GlobalGeometryTraits< Grid >::template Codim< codimension >::CoordVector
00130         CoordVector;
00131 
00132       typedef MakeableInterfaceObject< Geometry > MakeableGeometry;
00133       typedef typename MakeableGeometry::ImplementationType GeometryImpl;
00134 
00135     public:
00147       EntityBase ( const Grid &grid, const HostEntity &hostEntity )
00148       : grid_( &grid ),
00149         hostEntity_( &hostEntity ),
00150         geo_( GeometryImpl() )
00151       {}
00152 
00153       EntityBase ( const EntityBase &other )
00154       : grid_( other.grid_ ),
00155         hostEntity_( other.hostEntity_ ),
00156         geo_( GeometryImpl() )
00157       {}
00158 
00161     private:
00162       EntityBase &operator= ( const EntityBase & );
00163 
00164     public:
00172       GeometryType type () const
00173       {
00174         return hostEntity().type();
00175       }
00176 
00177       unsigned int topologyId () const DUNE_DEPRECATED
00178       {
00179         return type().id();
00180       }
00181 
00183       int level () const
00184       {
00185         return hostEntity().level();
00186       }
00187       
00189       PartitionType partitionType () const
00190       {
00191         return hostEntity().partitionType();
00192       }
00193 
00208       const Geometry &geometry () const
00209       {
00210         GeometryImpl &geo = Grid::getRealImplementation( geo_ );
00211         if( !geo )
00212         {
00213           CoordVector coords( hostEntity(), grid().coordFunction() );
00214           geo = GeometryImpl( type(), coords );
00215         }
00216         return geo_;
00217       }
00218       
00220       EntitySeed seed () const { return EntitySeed( hostEntity().seed() ); }
00227       const Grid &grid () const
00228       {
00229         return *grid_;
00230       }
00231 
00232       const HostEntity &hostEntity () const
00233       {
00234         return *hostEntity_;
00235       }
00236 
00244       template< class HostIndexSet >
00245       typename HostIndexSet::IndexType
00246       index ( const HostIndexSet &indexSet ) const
00247       {
00248         return indexSet.template index< codimension >( hostEntity() );
00249       }
00250 
00260       template< class HostIndexSet >
00261       typename HostIndexSet::IndexType
00262       subIndex ( const HostIndexSet &indexSet, int i, unsigned int cd ) const
00263       {
00264         return indexSet.subIndex( hostEntity(), i, cd );
00265       }
00266 
00274       template< class HostIndexSet >
00275       bool isContained ( const HostIndexSet &indexSet ) const
00276       {
00277         return indexSet.contains( hostEntity() );
00278       }
00279 
00287       template< class HostIdSet >
00288       typename HostIdSet::IdType id ( const HostIdSet &idSet ) const
00289       {
00290         return idSet.template id< codimension >( hostEntity() );
00291       }
00294     private:
00295       const Grid *grid_;
00296       const HostEntity *hostEntity_;
00297       mutable MakeableGeometry geo_;
00298     };
00299 
00300 
00301 
00302     // EntityBase (fake)
00303     // -----------------
00304 
00312     template< int codim, class Grid >
00313     class EntityBase< codim, Grid, true >
00314     {
00315       typedef typename remove_const< Grid >::type::Traits Traits;
00316 
00317     public:
00321 
00322       static const int codimension = codim;
00324       static const int dimension = Traits::dimension;
00326       static const int mydimension = dimension - codimension;
00328       static const int dimensionworld = Traits::dimensionworld;
00329 
00331       static const bool fake = true;
00337 
00338       typedef typename Traits::ctype ctype;
00339       
00341       typedef typename Traits::template Codim< codimension >::Geometry Geometry;
00344     private:
00345       typedef typename Traits::HostGrid HostGrid;
00346       typedef typename Traits::CoordFunction CoordFunction;
00347 
00348     public:
00352 
00353       typedef typename HostGrid::template Codim< codimension >::Entity HostEntity;
00355       typedef typename HostGrid::template Codim< codimension >::EntityPointer HostEntityPointer;
00356 
00358       typedef typename Traits::template Codim< codimension >::EntitySeed EntitySeed;
00359 
00361       typedef typename HostGrid::template Codim< 0 >::Entity HostElement;
00364     private:
00365       typedef typename HostGrid::template Codim< 0 >::Geometry HostGeometry;
00366       typedef typename HostGrid::template Codim< dimension >::EntityPointer HostVertexPointer;
00367 
00368       typedef typename GenericGeometry::GlobalGeometryTraits< Grid >::template Codim< codimension >::CoordVector
00369         CoordVector;
00370       
00371       typedef MakeableInterfaceObject< Geometry > MakeableGeometry;
00372       typedef typename MakeableGeometry::ImplementationType GeometryImpl;
00373 
00374     public:
00388       EntityBase ( const Grid &grid, const HostElement &hostElement, int subEntity )
00389       : grid_( &grid ),
00390         hostElement_( &hostElement ),
00391         subEntity_( subEntity ),
00392         geo_( GeometryImpl() )
00393       {}
00394 
00395       EntityBase ( const EntityBase &other )
00396       : grid_( other.grid_ ),
00397         hostElement_( other.hostElement_ ),
00398         subEntity_( other.subEntity_ ),
00399         geo_( GeometryImpl() )
00400       {}
00401 
00404     private:
00405       EntityBase &operator= ( const EntityBase & );
00406 
00407     public:
00415       GeometryType type () const
00416       {
00417         const GenericReferenceElement< ctype, dimension > &refElement
00418           = GenericReferenceElements< ctype, dimension >::general( hostElement().type() );
00419         return refElement.type( subEntity_, codimension );
00420       }
00421 
00422       unsigned int topologyId () const DUNE_DEPRECATED
00423       {
00424         const GenericReferenceElement< ctype, dimension > &refElement
00425           = GenericReferenceElements< ctype, dimension >::general( hostElement().type() );
00426         return refElement.topologyId( subEntity_, codimension );
00427       }
00428 
00430       int level () const
00431       {
00432         return hostElement().level();
00433       }
00434 
00436       PartitionType partitionType () const
00437       {
00438         if( !(Capabilities::isParallel< HostGrid >::v) )
00439           return InteriorEntity;
00440 
00441         const GenericReferenceElement< ctype, dimension > &refElement
00442           = GenericReferenceElements< ctype, dimension >::general( hostElement().type() );
00443 
00444         PartitionType type = vertexPartitionType( refElement, 0 );
00445         if( (type != BorderEntity) && (type != FrontEntity) )
00446           return type;
00447 
00448         const int numVertices = refElement.size( subEntity_, codimension, dimension );
00449         for( int i = 1; i < numVertices; ++i )
00450         {
00451           PartitionType vtxType = vertexPartitionType( refElement, i );
00452           if( (vtxType != BorderEntity) && (vtxType != FrontEntity) )
00453             return vtxType;
00454           if( type != vtxType )
00455             return OverlapEntity;
00456         }
00457         assert( (type == BorderEntity) || (type == FrontEntity) );
00458         return type;
00459       }
00460 
00475       const Geometry &geometry () const
00476       {
00477         GeometryImpl &geo = Grid::getRealImplementation( geo_ );
00478         if( !geo )
00479         {
00480           CoordVector coords( hostElement(), subEntity_, grid().coordFunction() );
00481           geo = GeometryImpl( type(), coords );
00482         }
00483         return geo_;
00484       }
00486       EntitySeed seed () const { return EntitySeed( hostElement().seed(), subEntity_ ); }
00492       const Grid &grid () const
00493       {
00494         return *grid_;
00495       }
00496 
00497       const HostEntity &hostEntity () const
00498       {
00499         DUNE_THROW( NotImplemented, "HostGrid has no entities of codimension " << codimension << "." );
00500       }
00501 
00502       const HostElement &hostElement () const
00503       {
00504         return *hostElement_;
00505       }
00506 
00507       int subEntity () const
00508       {
00509         return subEntity_;
00510       }
00511 
00519       template< class HostIndexSet >
00520       typename HostIndexSet::IndexType index ( const HostIndexSet &indexSet ) const
00521       {
00522         return indexSet.subIndex( hostElement(), subEntity_, codimension );
00523       }
00524 
00534       template< class HostIndexSet >
00535       typename HostIndexSet::IndexType
00536       subIndex ( const HostIndexSet &indexSet, int i, unsigned int cd ) const
00537       {
00538         const GenericReferenceElement< ctype, dimension > &refElement
00539           = GenericReferenceElements< ctype, dimension >::general( hostElement().type() );
00540         const int j = refElement.subEntity( subEntity_, codimension, i, codimension+cd );
00541         return indexSet.subIndex( hostElement(), j, codimension+cd );
00542       }
00543 
00551       template< class HostIndexSet >
00552       bool isContained ( const HostIndexSet &indexSet ) const
00553       {
00554         return indexSet.contains( hostElement() );
00555       }
00556 
00564       template< class HostIdSet >
00565       typename HostIdSet::IdType id ( const HostIdSet &idSet ) const
00566       {
00567         return idSet.subId( hostElement(), subEntity_, codimension );
00568       }
00571     private:
00572       PartitionType
00573       vertexPartitionType ( const GenericReferenceElement< ctype, dimension > &refElement, int i ) const
00574       {
00575         const int j = refElement.subEntity( subEntity_, codimension, 0, dimension );
00576         return hostElement().template subEntity< dimension >( j )->partitionType();
00577       }
00578 
00579     private:
00580       const Grid *grid_;
00581       const HostElement *hostElement_;
00582       unsigned int subEntity_;
00583       mutable Geometry geo_;
00584     };
00585 
00586 
00587 
00588     // Entity
00589     // ------
00590 
00591     template< int codim, int dim, class Grid >
00592     class Entity
00593     : public EntityBase< codim, Grid >
00594     {
00595       typedef EntityBase< codim, Grid > Base;
00596 
00597     public:
00598       typedef typename Base::HostEntity HostEntity;
00599       typedef typename Base::HostElement HostElement;
00600 
00601       Entity ( const Grid &grid, const HostEntity &hostEntity )
00602       : Base( grid, hostEntity )
00603       {}
00604 
00605       Entity ( const Grid &grid, const HostElement &hostElement, int subEntity )
00606       : Base( grid, hostElement, subEntity )
00607       {}
00608     };
00609 
00610 
00611 
00612     // Entity for codimension 0
00613     // ------------------------
00614 
00615     template< int dim, class Grid >
00616     class Entity< 0, dim, Grid >
00617     : public EntityBase< 0, Grid >
00618     {
00619       typedef EntityBase< 0, Grid > Base;
00620 
00621       typedef typename remove_const< Grid >::type::Traits Traits;
00622 
00623     public:
00627 
00628       static const int codimension = Base::codimension;
00630       static const int dimension = Base::dimension;
00632       static const int mydimension = Base::mydimension;
00634       static const int dimensionworld = Base::dimensionworld;
00635 
00637       static const bool fake = Base::fake;
00643 
00644       typedef typename Traits::template Codim< codimension >::LocalGeometry LocalGeometry;
00646       typedef typename Traits::template Codim< codimension >::EntityPointer EntityPointer;
00647 
00649       typedef typename Traits::HierarchicIterator HierarchicIterator;
00651       typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator;
00653       typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator;
00654 
00657       typedef typename Base::HostEntity HostEntity;
00658       typedef typename Base::HostElement HostElement;
00659 
00660       using Base::grid;
00661       using Base::hostEntity;
00662 
00663       Entity ( const Grid &grid, const HostEntity &hostEntity )
00664       : Base( grid, hostEntity )
00665       {}
00666 
00667       template< int codim >
00668       int count () const
00669       {
00670         return hostEntity().template count< codim >();
00671       }
00672       
00673       template< int codim >
00674       typename Grid::template Codim< codim >::EntityPointer
00675       subEntity ( int i ) const
00676       {
00677         typedef typename Traits::template Codim< codim >::EntityPointerImpl EntityPointerImpl;
00678         return EntityPointerImpl( grid(), hostEntity(), i );
00679       }
00680 
00681       LevelIntersectionIterator ilevelbegin () const
00682       {
00683         typedef GeoGrid::LevelIntersectionIterator< Grid > LevelIntersectionIteratorImpl;
00684         return LevelIntersectionIteratorImpl( *this, hostEntity().ilevelbegin() );
00685       }
00686       
00687       LevelIntersectionIterator ilevelend () const
00688       {
00689         typedef GeoGrid::LevelIntersectionIterator< Grid > LevelIntersectionIteratorImpl;
00690         return LevelIntersectionIteratorImpl( *this, hostEntity().ilevelend() );
00691       }
00692       
00693       LeafIntersectionIterator ileafbegin () const
00694       {
00695         typedef GeoGrid::LeafIntersectionIterator< Grid > LeafIntersectionIteratorImpl;
00696         return LeafIntersectionIteratorImpl( *this, hostEntity().ileafbegin() );
00697       }
00698       
00699       LeafIntersectionIterator ileafend () const
00700       {
00701         typedef GeoGrid::LeafIntersectionIterator< Grid > LeafIntersectionIteratorImpl;
00702         return LeafIntersectionIteratorImpl( *this, hostEntity().ileafend() );
00703       }
00704 
00705       bool hasBoundaryIntersections () const
00706       {
00707         return hostEntity().hasBoundaryIntersections();
00708       }
00709 
00710       bool isLeaf () const
00711       {
00712         return hostEntity().isLeaf();
00713       }
00714    
00715       EntityPointer father () const
00716       {
00717         typedef typename Traits::template Codim< 0 >::EntityPointerImpl EntityPointerImpl;
00718         return EntityPointerImpl( grid(), hostEntity().father() );
00719       }
00720 
00721       bool hasFather () const
00722       {
00723         return hostEntity().hasFather();
00724       }
00725         
00726       const LocalGeometry &geometryInFather () const
00727       {
00728         return hostEntity().geometryInFather();
00729       }
00730    
00731       HierarchicIterator hbegin ( int maxLevel ) const
00732       {
00733         typedef GeoGrid::HierarchicIterator< Grid > HierarchicIteratorImpl;
00734         return HierarchicIteratorImpl( grid(), hostEntity().hbegin( maxLevel ) );
00735       }
00736       
00737       HierarchicIterator hend ( int maxLevel ) const
00738       {
00739         typedef GeoGrid::HierarchicIterator< Grid > HierarchicIteratorImpl;
00740         return HierarchicIteratorImpl( grid(), hostEntity().hend( maxLevel ) );
00741       }
00742 
00743       bool isRegular () const
00744       {
00745         return hostEntity().isRegular();
00746       }
00747 
00748       bool isNew () const
00749       {
00750         return hostEntity().isNew();
00751       }
00752             
00753       bool mightVanish () const
00754       {
00755         return hostEntity().mightVanish();
00756       }
00757     };
00758 
00759   }
00760 
00761 }
00762 
00763 #endif // #ifndef DUNE_GEOGRID_ENTITY_HH

Generated on Fri Apr 29 2011 with Doxygen (ver 1.7.1) [doxygen-log,error-log].