dune-grid
2.1.1
|
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 protected: 00059 EntityImp<cd,dim,GridImp> realEntity; 00060 public: 00061 00062 //=========================================================== 00066 //=========================================================== 00067 // this is needed by EntityPointer 00068 // for an intermediate time until all entity seeds 00069 // are implemented 00070 //protected: 00071 // The type of the wrapped implementation, for internal use only 00072 typedef EntityImp<cd,dim,GridImp> ImplementationType; 00073 00074 public: 00076 typedef typename GridImp::template Codim<cd>::Geometry Geometry; 00077 00079 typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed; 00080 00081 enum { 00083 codimension=cd 00084 }; 00085 enum { 00087 dimension=dim 00088 }; 00089 enum { 00091 mydimension=dim-cd 00092 }; 00093 enum { 00095 dimensionworld=GridImp::dimensionworld 00096 }; 00097 00099 typedef typename GridImp::ctype ctype; 00101 00102 00103 00104 //=========================================================== 00108 //=========================================================== 00109 00111 int level () const { return realEntity.level(); } 00112 00114 PartitionType partitionType () const { return realEntity.partitionType(); } 00115 00125 const Geometry& geometry () const { return realEntity.geometry(); } 00127 00131 GeometryType type () const { return realEntity.type(); } 00132 00136 EntitySeed seed () const { return realEntity.seed(); } 00137 00138 //=========================================================== 00142 //=========================================================== 00143 00145 explicit Entity(const EntityImp<cd,dim,GridImp> & e) : realEntity(e) {}; 00146 00147 /* not part of the interface but maybe in later versions 00148 \brief Id of the boundary which is associated with the entity, 00149 returns 0 for inner entities, arbitrary int otherwise 00150 */ 00151 //int boundaryId () const { return realEntity.boundaryId(); } 00152 00154 00155 protected: 00156 typedef typename remove_const<GridImp>::type mutableGridImp; 00157 00158 //=========================================================== 00162 //=========================================================== 00163 00164 // give the GridDefaultImplementation class access to the realImp 00165 friend class GridDefaultImplementation< 00166 GridImp::dimension, GridImp::dimensionworld, 00167 typename GridImp::ctype, 00168 typename GridImp::GridFamily> ; 00169 00170 /* make entity pointer friend */ 00171 friend class Dune::EntityPointer<GridImp, 00172 typename GridImp::GridFamily::Traits::template Codim<cd>::EntityPointerImpl>; 00173 00175 EntityImp<cd,dim,GridImp> & getRealImp() { return realEntity; } 00177 const EntityImp<cd,dim,GridImp> & getRealImp() const { return realEntity; } 00178 00179 protected: 00181 Entity(const Entity& rhs) : realEntity(rhs.realEntity) {}; 00183 Entity & operator = (const Entity& rhs) { 00184 realEntity = rhs.realEntity; 00185 return *this; 00186 } 00188 }; 00189 00200 template<int dim, class GridImp, template<int,int,class> class EntityImp> 00201 class Entity <0,dim,GridImp,EntityImp> 00202 { 00203 protected: 00204 typedef typename remove_const<GridImp>::type mutableGridImp; 00205 00206 EntityImp<0,dim,GridImp> realEntity; 00207 00208 // this is needed by EntityPointer 00209 // for an intermediate time until all entity seeds 00210 // are implemented 00211 public: 00212 // The type of the wrapped implementation, for internal use only 00213 typedef EntityImp<0,dim,GridImp> ImplementationType; 00214 00215 public: 00216 //=========================================================== 00220 //=========================================================== 00221 00223 typedef typename GridImp::template Codim<0>::Geometry Geometry; 00224 00226 typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed; 00227 00235 typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry; 00236 00238 template <int cd> 00239 struct Codim 00240 { 00241 typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer; 00242 }; 00243 00245 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer; 00246 00248 typedef typename GridImp::LeafIntersectionIterator LeafIntersectionIterator; 00249 00251 typedef typename GridImp::LevelIntersectionIterator LevelIntersectionIterator; 00252 00254 typedef typename GridImp::HierarchicIterator HierarchicIterator; 00255 00256 enum { 00258 codimension=0 00259 }; 00260 enum { 00262 dimension=dim 00263 }; 00264 enum { 00266 mydimension=dim 00267 }; 00268 enum { 00270 dimensionworld=GridImp::dimensionworld 00271 }; 00273 typedef typename GridImp::ctype ctype; 00275 00276 00277 //=========================================================== 00281 //=========================================================== 00282 00284 int level () const { return realEntity.level(); } 00285 00287 PartitionType partitionType () const { return realEntity.partitionType(); } 00288 00290 const Geometry& geometry () const { return realEntity.geometry(); } 00292 00296 GeometryType type () const { return realEntity.type(); } 00297 00301 EntitySeed seed () const { return realEntity.seed(); } 00302 00303 //=========================================================== 00307 //=========================================================== 00308 00314 template<int cc> int count () const { return realEntity.count<cc>(); } 00315 00326 template< int codim > 00327 typename Codim< codim >::EntityPointer subEntity ( int i ) const 00328 { 00329 return realEntity.subEntity< codim >( i ); 00330 } 00331 00342 LeafIntersectionIterator ileafbegin () const 00343 { 00344 return realEntity.ileafbegin(); 00345 } 00346 00353 LeafIntersectionIterator ileafend () const 00354 { 00355 return realEntity.ileafend(); 00356 } 00357 00368 LevelIntersectionIterator ilevelbegin () const 00369 { 00370 return realEntity.ilevelbegin(); 00371 } 00372 00379 LevelIntersectionIterator ilevelend () const 00380 { 00381 return realEntity.ilevelend(); 00382 } 00383 00393 EntityPointer father () const 00394 { 00395 return realEntity.father(); 00396 } 00397 00401 bool hasFather () const 00402 { 00403 return realEntity.hasFather(); 00404 } 00405 00407 bool isLeaf () const 00408 { 00409 return realEntity.isLeaf(); 00410 } 00411 00415 bool isRegular() const { return realEntity.isRegular(); } 00416 00435 const LocalGeometry& geometryInFather () const 00436 { 00437 return realEntity.geometryInFather(); 00438 } 00439 00451 HierarchicIterator hbegin (int maxlevel) const 00452 { 00453 return realEntity.hbegin(maxlevel); 00454 } 00455 00463 HierarchicIterator hend (int maxlevel) const 00464 { 00465 return realEntity.hend(maxlevel); 00466 } 00467 00470 bool isNew () const { return realEntity.isNew(); } 00471 00476 bool mightVanish () const { return realEntity.mightVanish(); } 00477 00478 //=========================================================== 00482 //=========================================================== 00486 bool hasBoundaryIntersections () const { return realEntity.hasBoundaryIntersections(); } 00487 00489 explicit Entity(const EntityImp<0,dim,GridImp> & e) : realEntity(e) {}; 00490 00491 // @copydoc Dune::Entity::boundaryId() 00492 // maybe available in later versions 00493 //int boundaryId () const { return realEntity.boundaryId(); } 00494 00495 /* not part of the interface, mybe in later versions 00496 \brief The boundaryId of the i-th subentity of codimension <tt>cc</tt> 00497 00498 This does the same as <code>entity<cc>(i).boundaryId()</code>, but it is 00499 usually a lot faster. 00500 */ 00501 /* 00502 template <int cc> int subBoundaryId ( int i ) const 00503 { 00504 return realEntity.subBoundaryId<cc>(i); 00505 } 00506 */ 00507 00509 00510 00511 protected: 00512 //=========================================================== 00516 //=========================================================== 00517 00518 // give the GridDefaultImplementation class access to the realImp 00519 friend class GridDefaultImplementation< 00520 GridImp::dimension, GridImp::dimensionworld, 00521 typename GridImp::ctype, 00522 typename GridImp::GridFamily> ; 00523 00524 /* make entity pointer friend */ 00525 friend class Dune::EntityPointer<GridImp, 00526 typename GridImp::GridFamily::Traits::template Codim<0>::EntityPointerImpl>; 00527 00529 EntityImp<0,dim,GridImp> & getRealImp() { return realEntity; } 00531 const EntityImp<0,dim,GridImp> & getRealImp() const { return realEntity; } 00532 00533 protected: 00535 Entity(const Entity& rhs) : realEntity(rhs.realEntity) {}; 00537 Entity & operator = (const Entity& rhs) { 00538 realEntity = rhs.realEntity; 00539 return *this; 00540 }; 00542 }; 00543 00544 00545 //******************************************************************** 00556 template<int cd, int dim, class GridImp, template<int,int,class> class EntityImp> 00557 class EntityDefaultImplementation 00558 { 00559 public: 00561 enum { codimension=cd }; 00562 00564 enum { dimension=dim }; 00565 00567 enum { mydimension=dim-cd }; 00568 00570 enum { dimensionworld=GridImp::dimensionworld }; 00571 00573 typedef typename GridImp::ctype ctype; 00574 00576 typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed; 00577 00579 typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer; 00580 00584 GeometryType type () const { return asImp().geometry().type(); }; 00585 00588 EntitySeed seed () const DUNE_DEPRECATED 00589 { 00590 return EntitySeedHelper :: SeedReturner< 00591 EntitySeed, EntityPointer >::generateSeed ( asImp() ); 00592 } 00593 00594 private: 00596 EntityImp<cd,dim,GridImp>& asImp () 00597 { 00598 return static_cast<EntityImp<cd,dim,GridImp>&>(*this); 00599 } 00600 const EntityImp<cd,dim,GridImp>& asImp () const 00601 { 00602 return static_cast<const EntityImp<cd,dim,GridImp>&>(*this); 00603 } 00604 }; // end EntityDefaultImplementation 00605 00606 //******************************************************************** 00617 template<int dim, class GridImp, template<int,int,class> class EntityImp> 00618 class EntityDefaultImplementation <0,dim,GridImp,EntityImp> 00619 { 00620 public: 00622 enum { codimension=0 }; 00623 00625 enum { dimension=dim }; 00626 00628 enum { mydimension=dim }; 00629 00631 enum { dimensionworld=GridImp::dimensionworld }; 00632 00634 typedef typename GridImp::ctype ctype; 00635 00637 typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed; 00638 00640 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer; 00641 00645 bool isRegular() const { return true; } 00646 00650 GeometryType type () const { return asImp().geometry().type(); }; 00651 00654 EntitySeed seed () const DUNE_DEPRECATED 00655 { 00656 return EntitySeedHelper :: SeedReturner< 00657 EntitySeed, EntityPointer >::generateSeed ( asImp() ); 00658 } 00659 00660 /* maybe in later versions 00661 * \brief Default implementation for access to boundaryId of sub entities 00662 * 00663 * Default implementation for access to boundaryId via interface method 00664 * entity<codim>.boundaryId(), default is very slow, but works, can be 00665 * overloaded be the actual grid implementation. 00666 */ 00667 /* 00668 template <int cc> int subBoundaryId ( int i ) const 00669 { 00670 return (asImp().template entity<cc>(i))->boundaryId(); 00671 } 00672 */ 00673 00676 bool isNew () const { return false; } 00677 00680 bool mightVanish () const { return false; } 00681 00686 bool hasBoundaryIntersections () const 00687 { 00688 { 00689 typedef typename GridImp::LevelIntersectionIterator IntersectionIterator; 00690 IntersectionIterator end = asImp().ilevelend(); 00691 for(IntersectionIterator it = asImp().ilevelbegin(); it != end; ++it) 00692 { 00693 if( it->boundary() ) return true; 00694 } 00695 } 00696 00697 { 00698 typedef typename GridImp::LeafIntersectionIterator IntersectionIterator; 00699 IntersectionIterator end = asImp().ileafend(); 00700 for(IntersectionIterator it = asImp().ileafbegin(); it != end; ++it) 00701 { 00702 if( it->boundary() ) return true; 00703 } 00704 } 00705 00706 return false; 00707 } 00708 00709 private: 00710 // Barton-Nackman trick 00711 EntityImp<0,dim,GridImp>& asImp () { return static_cast<EntityImp<0,dim,GridImp>&>(*this); } 00712 const EntityImp<0,dim,GridImp>& asImp () const { return static_cast<const EntityImp<0,dim,GridImp>&>(*this); } 00713 }; 00714 00715 } 00716 00717 #endif // DUNE_GRID_ENTITY_HH