dune-grid
2.2.0
|
00001 #ifndef DUNE_GRID_ENTITY_HH 00002 #define DUNE_GRID_ENTITY_HH 00003 00004 #include <dune/common/typetraits.hh> 00005 #include "grid.hh" 00006 #include "entitypointer.hh" 00007 00008 namespace Dune 00009 { 00010 00056 template<int cd, int dim, class GridImp, template<int,int,class> class EntityImp> 00057 class Entity 00058 { 00059 #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS 00060 public: 00061 #else 00062 protected: 00063 // give the GridDefaultImplementation class access to the realImp 00064 friend class GridDefaultImplementation< 00065 GridImp::dimension, GridImp::dimensionworld, 00066 typename GridImp::ctype, 00067 typename GridImp::GridFamily> ; 00068 #endif 00069 // type of underlying implementation, for internal use only 00070 typedef EntityImp< cd, dim, GridImp > Implementation; 00071 00073 Implementation &impl () { return realEntity; } 00075 const Implementation &impl () const { return realEntity; } 00076 00077 protected: 00078 Implementation realEntity; 00079 00080 public: 00081 00082 //=========================================================== 00086 //=========================================================== 00087 00089 typedef typename GridImp::template Codim<cd>::Geometry Geometry; 00090 00092 typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed; 00093 00094 enum { 00096 codimension=cd 00097 }; 00098 enum { 00100 dimension=dim 00101 }; 00102 enum { 00104 mydimension=dim-cd 00105 }; 00106 enum { 00108 dimensionworld=GridImp::dimensionworld 00109 }; 00110 00112 typedef typename GridImp::ctype ctype; 00114 00115 00116 00117 //=========================================================== 00121 //=========================================================== 00122 00124 int level () const { return realEntity.level(); } 00125 00127 PartitionType partitionType () const { return realEntity.partitionType(); } 00128 00141 Geometry geometry () const { return realEntity.geometry(); } 00143 00147 GeometryType type () const { return realEntity.type(); } 00148 00152 EntitySeed seed () const { return realEntity.seed(); } 00153 00154 //=========================================================== 00158 //=========================================================== 00159 00161 explicit Entity(const EntityImp<cd,dim,GridImp> & e) : realEntity(e) {}; 00162 00163 /* not part of the interface but maybe in later versions 00164 \brief Id of the boundary which is associated with the entity, 00165 returns 0 for inner entities, arbitrary int otherwise 00166 */ 00167 //int boundaryId () const { return realEntity.boundaryId(); } 00168 00170 00171 protected: 00172 typedef typename remove_const<GridImp>::type mutableGridImp; 00173 00174 //=========================================================== 00178 //=========================================================== 00179 00180 // need to make copy constructor of EntityPointer work for any iterator 00181 //friend class Dune::EntityPointer<GridImp, 00182 // typename GridImp::GridFamily::Traits::template Codim<cd>::EntityPointerImpl>; 00183 template< class, class > friend class Dune::EntityPointer; 00184 00185 protected: 00187 Entity(const Entity& rhs) : realEntity(rhs.realEntity) {}; 00189 Entity & operator = (const Entity& rhs) { 00190 realEntity = rhs.realEntity; 00191 return *this; 00192 } 00194 }; 00195 00206 template<int dim, class GridImp, template<int,int,class> class EntityImp> 00207 class Entity <0,dim,GridImp,EntityImp> 00208 { 00209 #if DUNE_GRID_EXPERIMENTAL_GRID_EXTENSIONS 00210 public: 00211 #else 00212 protected: 00213 // give the GridDefaultImplementation class access to the realImp 00214 friend class GridDefaultImplementation< 00215 GridImp::dimension, GridImp::dimensionworld, 00216 typename GridImp::ctype, 00217 typename GridImp::GridFamily> ; 00218 #endif 00219 // type of underlying implementation, for internal use only 00220 typedef EntityImp< 0, dim, GridImp > Implementation; 00221 00223 Implementation &impl () { return realEntity; } 00225 const Implementation &impl () const { return realEntity; } 00226 00227 protected: 00228 Implementation realEntity; 00229 00230 typedef typename remove_const<GridImp>::type mutableGridImp; 00231 00232 public: 00233 00234 //=========================================================== 00238 //=========================================================== 00239 00241 typedef typename GridImp::template Codim<0>::Geometry Geometry; 00242 00244 typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed; 00245 00253 typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry; 00254 00256 template <int cd> 00257 struct Codim 00258 { 00259 typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer; 00260 }; 00261 00263 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer; 00264 00266 typedef typename GridImp::LeafIntersectionIterator LeafIntersectionIterator; 00267 00269 typedef typename GridImp::LevelIntersectionIterator LevelIntersectionIterator; 00270 00272 typedef typename GridImp::HierarchicIterator HierarchicIterator; 00273 00274 enum { 00276 codimension=0 00277 }; 00278 enum { 00280 dimension=dim 00281 }; 00282 enum { 00284 mydimension=dim 00285 }; 00286 enum { 00288 dimensionworld=GridImp::dimensionworld 00289 }; 00291 typedef typename GridImp::ctype ctype; 00293 00294 00295 //=========================================================== 00299 //=========================================================== 00300 00302 int level () const { return realEntity.level(); } 00303 00305 PartitionType partitionType () const { return realEntity.partitionType(); } 00306 00308 Geometry geometry () const { return realEntity.geometry(); } 00310 00314 GeometryType type () const { return realEntity.type(); } 00315 00319 EntitySeed seed () const { return realEntity.seed(); } 00320 00321 //=========================================================== 00325 //=========================================================== 00326 00332 template<int cc> int count () const { return realEntity.template count<cc>(); } 00333 00344 template< int codim > 00345 typename Codim< codim >::EntityPointer subEntity ( int i ) const 00346 { 00347 return realEntity.template subEntity< codim >( i ); 00348 } 00349 00360 LeafIntersectionIterator ileafbegin () const 00361 { 00362 return realEntity.ileafbegin(); 00363 } 00364 00371 LeafIntersectionIterator ileafend () const 00372 { 00373 return realEntity.ileafend(); 00374 } 00375 00386 LevelIntersectionIterator ilevelbegin () const 00387 { 00388 return realEntity.ilevelbegin(); 00389 } 00390 00397 LevelIntersectionIterator ilevelend () const 00398 { 00399 return realEntity.ilevelend(); 00400 } 00401 00411 EntityPointer father () const 00412 { 00413 return realEntity.father(); 00414 } 00415 00419 bool hasFather () const 00420 { 00421 return realEntity.hasFather(); 00422 } 00423 00425 bool isLeaf () const 00426 { 00427 return realEntity.isLeaf(); 00428 } 00429 00433 bool isRegular() const { return realEntity.isRegular(); } 00434 00460 LocalGeometry geometryInFather () const { return realEntity.geometryInFather(); } 00461 00473 HierarchicIterator hbegin (int maxlevel) const 00474 { 00475 return realEntity.hbegin(maxlevel); 00476 } 00477 00485 HierarchicIterator hend (int maxlevel) const 00486 { 00487 return realEntity.hend(maxlevel); 00488 } 00489 00492 bool isNew () const { return realEntity.isNew(); } 00493 00498 bool mightVanish () const { return realEntity.mightVanish(); } 00499 00500 //=========================================================== 00504 //=========================================================== 00508 bool hasBoundaryIntersections () const { return realEntity.hasBoundaryIntersections(); } 00509 00511 explicit Entity(const EntityImp<0,dim,GridImp> & e) : realEntity(e) {}; 00512 00513 // @copydoc Dune::Entity::boundaryId() 00514 // maybe available in later versions 00515 //int boundaryId () const { return realEntity.boundaryId(); } 00516 00517 /* not part of the interface, mybe in later versions 00518 \brief The boundaryId of the i-th subentity of codimension <tt>cc</tt> 00519 00520 This does the same as <code>entity<cc>(i).boundaryId()</code>, but it is 00521 usually a lot faster. 00522 */ 00523 /* 00524 template <int cc> int subBoundaryId ( int i ) const 00525 { 00526 return realEntity.subBoundaryId<cc>(i); 00527 } 00528 */ 00529 00531 00532 00533 protected: 00534 //=========================================================== 00538 //=========================================================== 00539 00540 // need to make copy constructor of EntityPointer work for any iterator 00541 //friend class Dune::EntityPointer<GridImp, 00542 // typename GridImp::GridFamily::Traits::template Codim<0>::EntityPointerImpl>; 00543 template< class, class > friend class Dune::EntityPointer; 00544 00545 protected: 00547 Entity(const Entity& rhs) : realEntity(rhs.realEntity) {}; 00549 Entity & operator = (const Entity& rhs) { 00550 realEntity = rhs.realEntity; 00551 return *this; 00552 }; 00554 }; 00555 00556 00557 //******************************************************************** 00568 template<int cd, int dim, class GridImp, template<int,int,class> class EntityImp> 00569 class EntityDefaultImplementation 00570 { 00571 public: 00573 enum { codimension=cd }; 00574 00576 enum { dimension=dim }; 00577 00579 enum { mydimension=dim-cd }; 00580 00582 enum { dimensionworld=GridImp::dimensionworld }; 00583 00585 typedef typename GridImp::ctype ctype; 00586 00588 typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed; 00589 00591 typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer; 00592 00596 GeometryType type () const { return asImp().geometry().type(); }; 00597 00598 private: 00600 EntityImp<cd,dim,GridImp>& asImp () 00601 { 00602 return static_cast<EntityImp<cd,dim,GridImp>&>(*this); 00603 } 00604 const EntityImp<cd,dim,GridImp>& asImp () const 00605 { 00606 return static_cast<const EntityImp<cd,dim,GridImp>&>(*this); 00607 } 00608 }; // end EntityDefaultImplementation 00609 00610 //******************************************************************** 00621 template<int dim, class GridImp, template<int,int,class> class EntityImp> 00622 class EntityDefaultImplementation <0,dim,GridImp,EntityImp> 00623 { 00624 public: 00626 enum { codimension=0 }; 00627 00629 enum { dimension=dim }; 00630 00632 enum { mydimension=dim }; 00633 00635 enum { dimensionworld=GridImp::dimensionworld }; 00636 00638 typedef typename GridImp::ctype ctype; 00639 00641 typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed; 00642 00644 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer; 00645 00649 bool isRegular() const { return true; } 00650 00654 GeometryType type () const { return asImp().geometry().type(); }; 00655 00656 /* maybe in later versions 00657 * \brief Default implementation for access to boundaryId of sub entities 00658 * 00659 * Default implementation for access to boundaryId via interface method 00660 * entity<codim>.boundaryId(), default is very slow, but works, can be 00661 * overloaded be the actual grid implementation. 00662 */ 00663 /* 00664 template <int cc> int subBoundaryId ( int i ) const 00665 { 00666 return (asImp().template entity<cc>(i))->boundaryId(); 00667 } 00668 */ 00669 00672 bool isNew () const { return false; } 00673 00676 bool mightVanish () const { return false; } 00677 00682 bool hasBoundaryIntersections () const 00683 { 00684 { 00685 typedef typename GridImp::LevelIntersectionIterator IntersectionIterator; 00686 IntersectionIterator end = asImp().ilevelend(); 00687 for(IntersectionIterator it = asImp().ilevelbegin(); it != end; ++it) 00688 { 00689 if( it->boundary() ) return true; 00690 } 00691 } 00692 00693 { 00694 typedef typename GridImp::LeafIntersectionIterator IntersectionIterator; 00695 IntersectionIterator end = asImp().ileafend(); 00696 for(IntersectionIterator it = asImp().ileafbegin(); it != end; ++it) 00697 { 00698 if( it->boundary() ) return true; 00699 } 00700 } 00701 00702 return false; 00703 } 00704 00705 private: 00706 // Barton-Nackman trick 00707 EntityImp<0,dim,GridImp>& asImp () { return static_cast<EntityImp<0,dim,GridImp>&>(*this); } 00708 const EntityImp<0,dim,GridImp>& asImp () const { return static_cast<const EntityImp<0,dim,GridImp>&>(*this); } 00709 }; 00710 00711 } 00712 00713 #endif // DUNE_GRID_ENTITY_HH