dune-grid
2.2.0
|
00001 #ifndef DUNE_GEOGRID_ENTITY_HH 00002 #define DUNE_GEOGRID_ENTITY_HH 00003 00004 #include <dune/common/nullptr.hh> 00005 00006 #include <dune/geometry/referenceelements.hh> 00007 00008 #include <dune/grid/common/grid.hh> 00009 #include <dune/grid/geometrygrid/capabilities.hh> 00010 #include <dune/grid/geometrygrid/cornerstorage.hh> 00011 00012 namespace Dune 00013 { 00014 00015 namespace GeoGrid 00016 { 00017 00018 // Internal Forward Declarations 00019 // ----------------------------- 00020 00031 template< int codim, class Grid, bool fake = !(Capabilities::hasHostEntity< Grid, codim >::v) > 00032 class EntityBase; 00033 00046 template< int codim, int dim, class Grid > 00047 class Entity; 00048 00049 00050 00051 // External Forward Declarations 00052 // ----------------------------- 00053 00054 template< class Grid > 00055 class LevelIntersectionIterator; 00056 00057 template< class Grid > 00058 class LeafIntersectionIterator; 00059 00060 template< class Grid > 00061 class HierarchicIterator; 00062 00063 00064 00065 // EntityBase (real) 00066 // ----------------- 00067 00075 template< int codim, class Grid > 00076 class EntityBase< codim, Grid, false > 00077 { 00078 typedef typename remove_const< Grid >::type::Traits Traits; 00079 00080 public: 00084 00085 static const int codimension = codim; 00087 static const int dimension = Traits::dimension; 00089 static const int mydimension = dimension - codimension; 00091 static const int dimensionworld = Traits::dimensionworld; 00092 00094 static const bool fake = false; 00095 00101 00102 typedef typename Traits::ctype ctype; 00103 00105 typedef typename Traits::template Codim< codimension >::Geometry Geometry; 00108 private: 00109 typedef typename Traits::HostGrid HostGrid; 00110 typedef typename Traits::CoordFunction CoordFunction; 00111 00112 public: 00116 00117 typedef typename HostGrid::template Codim< codimension >::Entity HostEntity; 00119 typedef typename HostGrid::template Codim< codimension >::EntityPointer HostEntityPointer; 00120 00122 typedef typename Traits::template Codim< codimension >::EntitySeed EntitySeed; 00123 00125 typedef typename HostGrid::template Codim< 0 >::Entity HostElement; 00128 typedef typename Traits::template Codim< codim >::GeometryImpl GeometryImpl; 00129 00130 private: 00131 typedef typename HostGrid::template Codim< codimension >::Geometry HostGeometry; 00132 00133 typedef GeoGrid::CoordVector< mydimension, Grid, fake > CoordVector; 00134 00135 public: 00145 explicit EntityBase ( const Grid &grid ) 00146 : geo_( grid ), 00147 hostEntity_( nullptr ) 00148 {} 00149 00156 explicit EntityBase ( const GeometryImpl &geo ) 00157 : geo_( geo ), 00158 hostEntity_( nullptr ) 00159 {} 00160 00161 EntityBase ( const EntityBase &other ) 00162 : geo_( other.geo_ ), 00163 hostEntity_( nullptr ) 00164 {} 00165 00168 const EntityBase &operator= ( const EntityBase &other ) 00169 { 00170 geo_ = other.geo_; 00171 hostEntity_ = nullptr; 00172 return *this; 00173 } 00174 00175 operator bool () const { return bool( hostEntity_ ); } 00176 00177 public: 00185 GeometryType type () const 00186 { 00187 return hostEntity().type(); 00188 } 00189 00190 unsigned int topologyId () const DUNE_DEPRECATED 00191 { 00192 return type().id(); 00193 } 00194 00196 int level () const 00197 { 00198 return hostEntity().level(); 00199 } 00200 00202 PartitionType partitionType () const 00203 { 00204 return hostEntity().partitionType(); 00205 } 00206 00221 Geometry geometry () const 00222 { 00223 if( !geo_ ) 00224 { 00225 CoordVector coords( hostEntity(), grid().coordFunction() ); 00226 geo_ = GeometryImpl( grid(), type(), coords ); 00227 } 00228 return Geometry( geo_ ); 00229 } 00230 00232 EntitySeed seed () const { return EntitySeed( hostEntity().seed() ); } 00239 const Grid &grid () const { return geo_.grid(); } 00240 00241 const HostEntity &hostEntity () const 00242 { 00243 assert( *this ); 00244 return *hostEntity_; 00245 } 00246 00254 void initialize ( const HostEntity &hostEntity ) { hostEntity_ = &hostEntity; } 00255 00263 template< class HostIndexSet > 00264 typename HostIndexSet::IndexType 00265 index ( const HostIndexSet &indexSet ) const 00266 { 00267 return indexSet.template index< codimension >( hostEntity() ); 00268 } 00269 00279 template< class HostIndexSet > 00280 typename HostIndexSet::IndexType 00281 subIndex ( const HostIndexSet &indexSet, int i, unsigned int cd ) const 00282 { 00283 return indexSet.subIndex( hostEntity(), i, cd ); 00284 } 00285 00293 template< class HostIndexSet > 00294 bool isContained ( const HostIndexSet &indexSet ) const 00295 { 00296 return indexSet.contains( hostEntity() ); 00297 } 00298 00306 template< class HostIdSet > 00307 typename HostIdSet::IdType id ( const HostIdSet &idSet ) const 00308 { 00309 return idSet.template id< codimension >( hostEntity() ); 00310 } 00313 private: 00314 mutable GeometryImpl geo_; 00315 const HostEntity *hostEntity_; 00316 }; 00317 00318 00319 00320 // EntityBase (fake) 00321 // ----------------- 00322 00330 template< int codim, class Grid > 00331 class EntityBase< codim, Grid, true > 00332 { 00333 typedef typename remove_const< Grid >::type::Traits Traits; 00334 00335 public: 00339 00340 static const int codimension = codim; 00342 static const int dimension = Traits::dimension; 00344 static const int mydimension = dimension - codimension; 00346 static const int dimensionworld = Traits::dimensionworld; 00347 00349 static const bool fake = true; 00355 00356 typedef typename Traits::ctype ctype; 00357 00359 typedef typename Traits::template Codim< codimension >::Geometry Geometry; 00362 private: 00363 typedef typename Traits::HostGrid HostGrid; 00364 typedef typename Traits::CoordFunction CoordFunction; 00365 00366 public: 00370 00371 typedef typename HostGrid::template Codim< codimension >::Entity HostEntity; 00373 typedef typename HostGrid::template Codim< codimension >::EntityPointer HostEntityPointer; 00374 00376 typedef typename Traits::template Codim< codimension >::EntitySeed EntitySeed; 00377 00379 typedef typename HostGrid::template Codim< 0 >::Entity HostElement; 00382 typedef typename Traits::template Codim< codimension >::GeometryImpl GeometryImpl; 00383 00384 private: 00385 typedef typename HostGrid::template Codim< 0 >::Geometry HostGeometry; 00386 typedef typename HostGrid::template Codim< dimension >::EntityPointer HostVertexPointer; 00387 00388 typedef GeoGrid::CoordVector< mydimension, Grid, fake > CoordVector; 00389 00390 public: 00401 EntityBase ( const Grid &grid, int subEntity ) 00402 : geo_( grid ), 00403 hostElement_( nullptr ), 00404 subEntity_( subEntity ) 00405 {} 00406 00414 EntityBase ( const GeometryImpl &geo, int subEntity ) 00415 : geo_( geo ), 00416 hostElement_( nullptr ), 00417 subEntity_( subEntity ) 00418 {} 00419 00420 EntityBase ( const EntityBase &other ) 00421 : geo_( other.geo_ ), 00422 hostElement_( nullptr ), 00423 subEntity_( other.subEntity_ ) 00424 {} 00425 00428 const EntityBase &operator= ( const EntityBase &other ) 00429 { 00430 geo_ = other.geo_; 00431 hostElement_ = nullptr; 00432 subEntity_ = other.subEntity_; 00433 return *this; 00434 } 00435 00436 operator bool () const { return bool( hostElement_ ); } 00437 00445 GeometryType type () const 00446 { 00447 const GenericReferenceElement< ctype, dimension > &refElement 00448 = GenericReferenceElements< ctype, dimension >::general( hostElement().type() ); 00449 return refElement.type( subEntity_, codimension ); 00450 } 00451 00452 unsigned int topologyId () const DUNE_DEPRECATED 00453 { 00454 const GenericReferenceElement< ctype, dimension > &refElement 00455 = GenericReferenceElements< ctype, dimension >::general( hostElement().type() ); 00456 return refElement.topologyId( subEntity_, codimension ); 00457 } 00458 00460 int level () const 00461 { 00462 return hostElement().level(); 00463 } 00464 00466 PartitionType partitionType () const 00467 { 00468 if( !(Capabilities::isParallel< HostGrid >::v) ) 00469 return InteriorEntity; 00470 00471 const GenericReferenceElement< ctype, dimension > &refElement 00472 = GenericReferenceElements< ctype, dimension >::general( hostElement().type() ); 00473 00474 PartitionType type = vertexPartitionType( refElement, 0 ); 00475 if( (type != BorderEntity) && (type != FrontEntity) ) 00476 return type; 00477 00478 const int numVertices = refElement.size( subEntity_, codimension, dimension ); 00479 for( int i = 1; i < numVertices; ++i ) 00480 { 00481 PartitionType vtxType = vertexPartitionType( refElement, i ); 00482 if( (vtxType != BorderEntity) && (vtxType != FrontEntity) ) 00483 return vtxType; 00484 if( type != vtxType ) 00485 return OverlapEntity; 00486 } 00487 assert( (type == BorderEntity) || (type == FrontEntity) ); 00488 return type; 00489 } 00490 00505 Geometry geometry () const 00506 { 00507 if( !geo_ ) 00508 { 00509 CoordVector coords( hostElement(), subEntity_, grid().coordFunction() ); 00510 geo_ = GeometryImpl( grid(), type(), coords ); 00511 } 00512 return Geometry( geo_ ); 00513 } 00514 00516 EntitySeed seed () const { return EntitySeed( hostElement().seed(), subEntity_ ); } 00522 const Grid &grid () const { return geo_.grid(); } 00523 00524 const HostEntity &hostEntity () const 00525 { 00526 DUNE_THROW( NotImplemented, "HostGrid has no entities of codimension " << codimension << "." ); 00527 } 00528 00529 const HostElement &hostElement () const 00530 { 00531 assert( *this ); 00532 return *hostElement_; 00533 } 00534 00535 int subEntity () const { return subEntity_; } 00536 00544 void initialize ( const HostElement &hostElement ) { hostElement_ = &hostElement; } 00545 00553 template< class HostIndexSet > 00554 typename HostIndexSet::IndexType index ( const HostIndexSet &indexSet ) const 00555 { 00556 return indexSet.subIndex( hostElement(), subEntity_, codimension ); 00557 } 00558 00568 template< class HostIndexSet > 00569 typename HostIndexSet::IndexType 00570 subIndex ( const HostIndexSet &indexSet, int i, unsigned int cd ) const 00571 { 00572 const GenericReferenceElement< ctype, dimension > &refElement 00573 = GenericReferenceElements< ctype, dimension >::general( hostElement().type() ); 00574 const int j = refElement.subEntity( subEntity_, codimension, i, codimension+cd ); 00575 return indexSet.subIndex( hostElement(), j, codimension+cd ); 00576 } 00577 00585 template< class HostIndexSet > 00586 bool isContained ( const HostIndexSet &indexSet ) const 00587 { 00588 return indexSet.contains( hostElement() ); 00589 } 00590 00598 template< class HostIdSet > 00599 typename HostIdSet::IdType id ( const HostIdSet &idSet ) const 00600 { 00601 return idSet.subId( hostElement(), subEntity_, codimension ); 00602 } 00605 private: 00606 PartitionType 00607 vertexPartitionType ( const GenericReferenceElement< ctype, dimension > &refElement, int i ) const 00608 { 00609 const int j = refElement.subEntity( subEntity_, codimension, 0, dimension ); 00610 return hostElement().template subEntity< dimension >( j )->partitionType(); 00611 } 00612 00613 private: 00614 mutable GeometryImpl geo_; 00615 const HostElement *hostElement_; 00616 unsigned int subEntity_; 00617 }; 00618 00619 00620 00621 // Entity 00622 // ------ 00623 00624 template< int codim, int dim, class Grid > 00625 class Entity 00626 : public EntityBase< codim, Grid > 00627 { 00628 typedef EntityBase< codim, Grid > Base; 00629 00630 public: 00631 typedef typename Base::HostEntity HostEntity; 00632 typedef typename Base::HostElement HostElement; 00633 typedef typename Base::GeometryImpl GeometryImpl; 00634 00635 explicit Entity ( const Grid &grid ) 00636 : Base( grid ) 00637 {} 00638 00639 explicit Entity ( const GeometryImpl &geo ) 00640 : Base( geo ) 00641 {} 00642 00643 Entity ( const Grid &grid, int subEntity ) 00644 : Base( grid, subEntity ) 00645 {} 00646 00647 Entity ( const GeometryImpl &geo, int subEntity ) 00648 : Base( geo, subEntity ) 00649 {} 00650 }; 00651 00652 00653 00654 // Entity for codimension 0 00655 // ------------------------ 00656 00657 template< int dim, class Grid > 00658 class Entity< 0, dim, Grid > 00659 : public EntityBase< 0, Grid > 00660 { 00661 typedef EntityBase< 0, Grid > Base; 00662 00663 typedef typename remove_const< Grid >::type::Traits Traits; 00664 00665 public: 00669 00670 static const int codimension = Base::codimension; 00672 static const int dimension = Base::dimension; 00674 static const int mydimension = Base::mydimension; 00676 static const int dimensionworld = Base::dimensionworld; 00677 00679 static const bool fake = Base::fake; 00685 00686 typedef typename Traits::template Codim< codimension >::LocalGeometry LocalGeometry; 00688 typedef typename Traits::template Codim< codimension >::EntityPointer EntityPointer; 00689 00691 typedef typename Traits::HierarchicIterator HierarchicIterator; 00693 typedef typename Traits::LeafIntersectionIterator LeafIntersectionIterator; 00695 typedef typename Traits::LevelIntersectionIterator LevelIntersectionIterator; 00696 00699 typedef typename Base::HostEntity HostEntity; 00700 typedef typename Base::HostElement HostElement; 00701 typedef typename Base::GeometryImpl GeometryImpl; 00702 00703 using Base::grid; 00704 using Base::hostEntity; 00705 00706 explicit Entity ( const Grid &grid ) 00707 : Base( grid ) 00708 {} 00709 00710 explicit Entity ( const GeometryImpl &geo ) 00711 : Base( geo ) 00712 {} 00713 00714 template< int codim > 00715 int count () const 00716 { 00717 return hostEntity().template count< codim >(); 00718 } 00719 00720 template< int codim > 00721 typename Grid::template Codim< codim >::EntityPointer 00722 subEntity ( int i ) const 00723 { 00724 typedef typename Traits::template Codim< codim >::EntityPointerImpl EntityPointerImpl; 00725 return EntityPointerImpl( grid(), hostEntity(), i ); 00726 } 00727 00728 LevelIntersectionIterator ilevelbegin () const 00729 { 00730 typedef GeoGrid::LevelIntersectionIterator< Grid > LevelIntersectionIteratorImpl; 00731 return LevelIntersectionIteratorImpl( *this, hostEntity().ilevelbegin() ); 00732 } 00733 00734 LevelIntersectionIterator ilevelend () const 00735 { 00736 typedef GeoGrid::LevelIntersectionIterator< Grid > LevelIntersectionIteratorImpl; 00737 return LevelIntersectionIteratorImpl( *this, hostEntity().ilevelend() ); 00738 } 00739 00740 LeafIntersectionIterator ileafbegin () const 00741 { 00742 typedef GeoGrid::LeafIntersectionIterator< Grid > LeafIntersectionIteratorImpl; 00743 return LeafIntersectionIteratorImpl( *this, hostEntity().ileafbegin() ); 00744 } 00745 00746 LeafIntersectionIterator ileafend () const 00747 { 00748 typedef GeoGrid::LeafIntersectionIterator< Grid > LeafIntersectionIteratorImpl; 00749 return LeafIntersectionIteratorImpl( *this, hostEntity().ileafend() ); 00750 } 00751 00752 bool hasBoundaryIntersections () const 00753 { 00754 return hostEntity().hasBoundaryIntersections(); 00755 } 00756 00757 bool isLeaf () const 00758 { 00759 return hostEntity().isLeaf(); 00760 } 00761 00762 EntityPointer father () const 00763 { 00764 typedef typename Traits::template Codim< 0 >::EntityPointerImpl EntityPointerImpl; 00765 return EntityPointerImpl( grid(), hostEntity().father() ); 00766 } 00767 00768 bool hasFather () const 00769 { 00770 return hostEntity().hasFather(); 00771 } 00772 00773 LocalGeometry geometryInFather () const 00774 { 00775 return hostEntity().geometryInFather(); 00776 } 00777 00778 HierarchicIterator hbegin ( int maxLevel ) const 00779 { 00780 typedef GeoGrid::HierarchicIterator< Grid > HierarchicIteratorImpl; 00781 return HierarchicIteratorImpl( grid(), hostEntity().hbegin( maxLevel ) ); 00782 } 00783 00784 HierarchicIterator hend ( int maxLevel ) const 00785 { 00786 typedef GeoGrid::HierarchicIterator< Grid > HierarchicIteratorImpl; 00787 return HierarchicIteratorImpl( grid(), hostEntity().hend( maxLevel ) ); 00788 } 00789 00790 bool isRegular () const 00791 { 00792 return hostEntity().isRegular(); 00793 } 00794 00795 bool isNew () const 00796 { 00797 return hostEntity().isNew(); 00798 } 00799 00800 bool mightVanish () const 00801 { 00802 return hostEntity().mightVanish(); 00803 } 00804 }; 00805 00806 } // namespace GeoGrid 00807 00808 } // namespace Dune 00809 00810 #endif // #ifndef DUNE_GEOGRID_ENTITY_HH