dune-grid
2.2.0
|
00001 #ifndef DUNE_ALU3DGRIDENTITY_HH 00002 #define DUNE_ALU3DGRIDENTITY_HH 00003 00004 // System includes 00005 00006 // Dune includes 00007 #include <dune/grid/common/entity.hh> 00008 #include <dune/grid/alugrid/common/intersectioniteratorwrapper.hh> 00009 00010 // Local includes 00011 #include "alu3dinclude.hh" 00012 #include "iterator.hh" 00013 #include "entityseed.hh" 00014 00015 namespace Dune 00016 { 00017 00018 // Forward declarations 00019 template<int cd, int dim, class GridImp> 00020 class ALU3dGridEntity; 00021 template<int cd, PartitionIteratorType pitype, class GridImp > 00022 class ALU3dGridLevelIterator; 00023 template<int cd, class GridImp > 00024 class ALU3dGridEntityPointer; 00025 template<int mydim, int coorddim, class GridImp> 00026 class ALU3dGridGeometry; 00027 template<class GridImp> 00028 class ALU3dGridHierarchicIterator; 00029 template<class GridImp> 00030 class ALU3dGridIntersectionIterator; 00031 template<int codim, PartitionIteratorType, class GridImp> 00032 class ALU3dGridLeafIterator; 00033 template< ALU3dGridElementType, class > 00034 class ALU3dGrid; 00035 00042 template<int cd, int dim, class GridImp> 00043 class ALU3dGridEntity : 00044 public EntityDefaultImplementation <cd,dim,GridImp,ALU3dGridEntity> 00045 { 00046 // default just returns level 00047 template <class GridType, int cdim> 00048 struct GetLevel 00049 { 00050 template <class ItemType> 00051 static int getLevel(const GridType & grid, const ItemType & item ) 00052 { 00053 return item.level(); 00054 } 00055 }; 00056 00057 // for leaf vertices the level is somewhat difficult to obtain, because 00058 // this the maximum of levels of elements that have this vertex as sub 00059 // entity 00060 template <class GridType> 00061 struct GetLevel<GridType,3> 00062 { 00063 template <class ItemType> 00064 static int getLevel(const GridType & grid, const ItemType & item) 00065 { 00066 return (item.isLeafEntity()) ? grid.getLevelOfLeafVertex(item) : item.level(); 00067 } 00068 }; 00069 00070 enum { dimworld = GridImp::dimensionworld }; 00071 00072 typedef typename GridImp::MPICommunicatorType Comm; 00073 00074 friend class ALU3dGrid< GridImp::elementType, Comm >; 00075 friend class ALU3dGridEntity < 0, dim, GridImp >; 00076 friend class ALU3dGridLevelIterator < cd, All_Partition, GridImp >; 00077 00078 friend class ALU3dGridHierarchicIndexSet< GridImp::elementType, Comm >; 00079 00080 template< class > friend class ALU3dGridFactory; 00081 00082 typedef typename GridImp::Traits::template Codim< cd >::GeometryImpl GeometryImpl; 00083 00084 public: 00085 typedef typename GridImp::GridObjectFactoryType FactoryType; 00086 00087 typedef ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits; 00088 typedef typename ImplTraits::template Codim<cd>::InterfaceType HItemType; 00089 typedef typename ImplTraits::template Codim<cd>::ImplementationType ItemType; 00090 typedef typename ImplTraits::VertexType VertexType; 00091 typedef typename ImplTraits::HBndSegType HBndSegType; 00092 00093 typedef typename GridImp::template Codim<cd>::Entity Entity; 00094 typedef typename GridImp::template Codim<cd>::Geometry Geometry; 00095 00096 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer; 00097 00099 typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed; 00100 00102 int level () const; 00103 00105 PartitionType partitionType() const; 00106 00108 ALU3dGridEntity(const FactoryType &factory, int level); 00109 00111 ALU3dGridEntity(const ALU3dGridEntity & org); 00112 00114 Geometry geometry () const; 00115 00117 GeometryType type () const; 00118 00119 // set element as normal entity 00120 void setElement(const HItemType & item); 00121 void setElement(const HItemType & item, const int level, int twist=0, int face = -1); 00122 00123 /* set entity from seed */ 00124 void setElement(const EntitySeed& seed); 00125 00127 void setGhost(const HBndSegType &ghost); 00128 00130 void removeElement (); 00131 00133 void reset ( int l ); 00134 00136 bool equals ( const ALU3dGridEntity<cd,dim,GridImp> & org ) const; 00137 00139 void setEntity ( const ALU3dGridEntity<cd,dim,GridImp> & org ); 00140 00141 // return reference to internal item 00142 const ItemType & getItem () const { return *item_; } 00143 00145 const GridImp& grid() const { return factory_.grid(); } 00146 00148 const FactoryType& factory() const { return factory_; } 00149 00151 EntitySeed seed() const 00152 { 00153 return EntitySeed( getItem(), level(), twist_, face_ ); 00154 } 00155 00156 private: 00158 int getIndex () const; 00159 00161 PartitionType convertBndId(const HItemType & item) const ; 00162 00164 mutable GeometryImpl geo_; 00165 00166 // the factory that created this entity 00167 const FactoryType& factory_; 00168 00169 // corresponding ALU3dGrid item, here face, edge, or vertex 00170 const ItemType * item_; 00171 00172 int level_; 00173 int gIndex_; 00174 int twist_; 00175 int face_; 00176 00177 mutable PartitionType partitionType_; 00178 }; 00179 00193 //*********************** 00194 // 00195 // --ALU3dGridEntity 00196 // --0Entity 00197 // 00198 //*********************** 00199 template<int dim, class GridImp> 00200 class ALU3dGridEntity<0,dim,GridImp> 00201 : public EntityDefaultImplementation<0,dim,GridImp,ALU3dGridEntity> 00202 { 00203 static const int dimworld = remove_const< GridImp >::type::dimensionworld; 00204 static const ALU3dGridElementType elementType = remove_const< GridImp >::type::elementType; 00205 00206 typedef typename GridImp::MPICommunicatorType Comm; 00207 00208 typedef ALU3dImplTraits< elementType, Comm > ImplTraits; 00209 typedef typename ImplTraits::template Codim<0>::InterfaceType HElementType; 00210 00211 typedef typename ImplTraits::GEOElementType GEOElementType; 00212 typedef typename ImplTraits::BNDFaceType BNDFaceType; 00213 typedef typename ImplTraits::IMPLElementType IMPLElementType; 00214 typedef typename ImplTraits::HBndSegType HBndSegType; 00215 00216 enum { refine_element_t = ImplTraits::refine_element_t }; 00217 enum { bisect_element_t = ImplTraits::bisect_element_t }; 00218 enum { coarse_element_t = ImplTraits::coarse_element_t }; 00219 enum { nosplit_element_t = ImplTraits::nosplit_element_t }; 00220 00221 typedef typename ImplTraits::MarkRuleType MarkRuleType; 00222 00223 friend class ALU3dGrid< elementType, Comm >; 00224 friend class ALU3dGridIntersectionIterator < GridImp >; 00225 friend class ALU3dGridIntersectionIterator < const GridImp >; 00226 friend class ALU3dGridHierarchicIterator < const GridImp >; 00227 friend class ALU3dGridHierarchicIterator < GridImp >; 00228 friend class ALU3dGridLevelIterator <0,All_Partition,GridImp>; 00229 friend class ALU3dGridLevelIterator <1,All_Partition,GridImp>; 00230 friend class ALU3dGridLevelIterator <2,All_Partition,GridImp>; 00231 friend class ALU3dGridLevelIterator <3,All_Partition,GridImp>; 00232 friend class ALU3dGridLeafIterator <0, All_Partition,GridImp>; 00233 friend class ALU3dGridLeafIterator <1, All_Partition,GridImp>; 00234 friend class ALU3dGridLeafIterator <2, All_Partition,GridImp>; 00235 friend class ALU3dGridLeafIterator <3, All_Partition,GridImp>; 00236 00237 friend class ALU3dGridHierarchicIndexSet< elementType, Comm >; 00238 00239 template< class > friend class ALU3dGridFactory; 00240 00241 // type of reference element 00242 typedef typename GridImp :: ReferenceElementType ReferenceElementType; 00243 00244 typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl GeometryImpl; 00245 typedef typename GridImp::Traits::template Codim< 0 >::LocalGeometryImpl LocalGeometryImpl; 00246 00247 public: 00248 typedef typename GridImp::GridObjectFactoryType FactoryType; 00249 00250 typedef typename GridImp::template Codim< 0 >::Geometry Geometry; 00251 typedef typename GridImp::template Codim< 0 >::LocalGeometry LocalGeometry; 00252 typedef ALU3dGridIntersectionIterator<GridImp> IntersectionIteratorImp; 00253 00254 typedef LeafIntersectionIteratorWrapper <GridImp> ALU3dGridIntersectionIteratorType; 00255 typedef LeafIntersectionIteratorWrapper <GridImp> ALU3dGridLeafIntersectionIteratorType; 00256 typedef LevelIntersectionIteratorWrapper<GridImp> ALU3dGridLevelIntersectionIteratorType; 00257 00258 typedef typename GridImp::template Codim<0>::Entity Entity; 00259 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer; 00260 00261 template <int cd> 00262 struct Codim 00263 { 00264 typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer; 00265 }; 00266 00268 typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed; 00269 00271 ALU3dGridEntity(const FactoryType& factory, int level); 00272 00274 ALU3dGridEntity(const ALU3dGridEntity & org); 00275 00277 int level () const ; 00278 00280 Geometry geometry () const; 00281 00283 GeometryType type () const; 00284 00286 PartitionType partitionType() const; 00287 00291 template<int cc> int count () const ; 00292 00295 template <int codim> 00296 typename Codim< codim >::EntityPointer entity (int i) const 00297 { 00298 typedef GenericGeometry::MapNumberingProvider< GridImp::dimension > Numbering; 00299 const unsigned int tid = type().id(); 00300 const int j = Numbering::template dune2generic< codim >( tid, i ); 00301 return subEntity< codim >( j ); 00302 } 00303 00304 template< int codim > 00305 typename Codim< codim >::EntityPointer subEntity ( int i ) const; 00306 00312 ALU3dGridLeafIntersectionIteratorType ileafbegin () const; 00313 00315 ALU3dGridLeafIntersectionIteratorType ileafend () const; 00316 00322 ALU3dGridLevelIntersectionIteratorType ilevelbegin () const; 00323 00325 ALU3dGridLevelIntersectionIteratorType ilevelend () const; 00326 00328 bool isLeaf () const; 00329 00332 EntityPointer father () const; 00334 bool hasFather () const 00335 { 00336 return (this->level()>0); 00337 } 00338 00348 LocalGeometry geometryInFather () const; 00349 00354 ALU3dGridHierarchicIterator<GridImp> hbegin (int maxlevel) const; 00355 00357 ALU3dGridHierarchicIterator<GridImp> hend (int maxlevel) const; 00358 00359 //*************************************************************** 00360 // Interface for Adaptation 00361 //*************************************************************** 00362 00364 bool isNew () const; 00365 00367 bool mightVanish () const; 00368 00370 bool hasBoundaryIntersections () const; 00371 00372 // private method 00376 bool mark( int refCount ) const; 00377 00379 int getMark() const; 00380 00384 void setElement(HElementType &element); 00385 00386 /* set entity from seed */ 00387 void setElement(const EntitySeed& seed); 00388 00390 void setGhost(HBndSegType & ghost); 00391 00393 void reset ( int l ); 00394 00396 void removeElement(); 00397 00399 bool equals ( const ALU3dGridEntity<0,dim,GridImp> & org ) const; 00400 00401 void setEntity ( const ALU3dGridEntity<0,dim,GridImp> & org ); 00402 00406 template<int cc> int getSubIndex (int i) const; 00407 00411 int subIndex(int i, unsigned int codim) const; 00412 00413 // return reference to internal item 00414 const IMPLElementType& getItem () const { return *item_; } 00415 00416 // return reference to internal item 00417 const BNDFaceType& getGhost () const 00418 { 00419 assert( isGhost() ); 00420 return *ghost_; 00421 } 00422 00424 const GridImp& grid() const { return factory_.grid(); } 00425 00427 const FactoryType& factory() const { return factory_; } 00428 00430 bool isGhost () const{ return ImplTraits::isGhost( ghost_ ); } 00431 00433 EntitySeed seed() const 00434 { 00435 if( isGhost() ) 00436 return EntitySeed( getGhost () ); 00437 else 00438 return EntitySeed( getItem() ); 00439 } 00440 00441 private: 00443 int getIndex () const; 00444 00446 mutable GeometryImpl geo_; 00447 00448 // corresponding factory 00449 const FactoryType& factory_; 00450 00451 // the current element of grid 00452 mutable IMPLElementType* item_; 00453 00455 mutable BNDFaceType* ghost_; 00456 00457 int level_; 00458 bool isLeaf_; 00459 00460 }; // end of ALU3dGridEntity codim = 0 00461 //********************************************************************** 00462 // 00463 // --ALU3dGridEntityPointer 00464 // --EntityPointer 00465 // --EnPointer 00469 template< int codim, class GridImp > 00470 class ALU3dGridEntityPointerBase 00471 //: public EntityPointerDefaultImplementation <codim, GridImp, ALU3dGridEntityPointer<cd,GridImp> > 00472 { 00473 typedef ALU3dGridEntityPointerBase< codim, GridImp > ThisType; 00474 enum { dim = GridImp::dimension }; 00475 enum { dimworld = GridImp::dimensionworld }; 00476 00477 typedef typename GridImp::MPICommunicatorType Comm; 00478 00479 friend class ALU3dGridEntity<codim,dim,GridImp>; 00480 friend class ALU3dGridEntity< 0,dim,GridImp>; 00481 friend class ALU3dGrid < GridImp::elementType, Comm >; 00482 00483 typedef ALU3dImplTraits<GridImp::elementType, Comm > ImplTraits; 00484 typedef typename ImplTraits::template Codim<codim>::InterfaceType HElementType; 00485 00486 typedef typename ImplTraits::HBndSegType HBndSegType; 00487 typedef typename ImplTraits::BNDFaceType BNDFaceType; 00488 public: 00489 typedef typename GridImp::GridObjectFactoryType FactoryType; 00490 00491 enum { codimension = codim }; 00492 00494 typedef typename GridImp::template Codim<codimension>::Entity Entity; 00496 typedef MakeableInterfaceObject<Entity> EntityObject; 00497 typedef typename EntityObject :: ImplementationType EntityImp; 00498 00500 typedef ThisType ALU3dGridEntityPointerType; 00501 00503 typedef ALU3dGridEntityPointer<codimension,GridImp> EntityPointerImp; 00504 00506 typedef ALU3dGridEntitySeed<codimension, GridImp> ALU3dGridEntitySeedType; 00507 00509 ALU3dGridEntityPointerBase(const FactoryType& factory, 00510 const HElementType & item); 00511 00513 ALU3dGridEntityPointerBase(const FactoryType& factory, 00514 const HElementType & item, 00515 const int level, 00516 const int twist, 00517 const int duneFace 00518 ); 00519 00521 ALU3dGridEntityPointerBase(const FactoryType& factory, 00522 const HBndSegType & ghostFace ); 00523 00525 ALU3dGridEntityPointerBase(const FactoryType& factory, 00526 const ALU3dGridEntitySeedType& seed ); 00527 00529 ALU3dGridEntityPointerBase(const ALU3dGridEntityPointerType & org); 00530 00532 ~ALU3dGridEntityPointerBase(); 00533 00535 bool equals (const ALU3dGridEntityPointerType& i) const; 00536 00538 ThisType & operator = (const ThisType & org); 00539 00541 Entity & dereference () const ; 00542 00544 int level () const ; 00545 00546 protected: 00547 // clones object 00548 void clone (const ALU3dGridEntityPointerType & org); 00549 00550 // get entity and assign from org.entity 00551 void getEntity (const ALU3dGridEntityPointerType & org); 00552 00554 void done (); 00555 00557 void freeEntity (); 00558 00560 const GridImp& grid () const { return factory_.grid(); } 00561 00564 ALU3dGridEntityPointerBase(const FactoryType& factory, int level ); 00565 00566 // update underlying item pointer and set ghost entity 00567 void updateGhostPointer( HBndSegType & ghostFace ); 00568 // update underlying item pointer and set entity 00569 void updateEntityPointer( HElementType * item , int level = -1 ); 00570 00571 // reference to factory 00572 const FactoryType& factory_; 00573 00574 // key to gererate entity 00575 ALU3dGridEntitySeedType seed_; 00576 00577 // entity that this EntityPointer points to 00578 mutable EntityObject * entity_; 00579 00580 // is true if entity must not be released 00581 bool locked_; 00582 00583 // return reference to internal entity implementation 00584 EntityImp & entityImp () const { 00585 assert( entity_ ); 00586 return GridImp :: getRealImplementation(*entity_); 00587 } 00588 }; 00589 00593 template<class GridImp> 00594 class ALU3dGridEntityPointer<0,GridImp> : 00595 public ALU3dGridEntityPointerBase<0,GridImp> 00596 { 00597 protected: 00598 typedef ALU3dGridEntityPointerBase<0,GridImp> BaseType; 00599 00600 enum { cd = 0 }; 00601 typedef ALU3dGridEntityPointer <cd,GridImp> ThisType; 00602 enum { dim = GridImp::dimension }; 00603 enum { dimworld = GridImp::dimensionworld }; 00604 00605 typedef typename GridImp::MPICommunicatorType Comm; 00606 00607 friend class ALU3dGridEntity<cd,dim,GridImp>; 00608 friend class ALU3dGridEntity< 0,dim,GridImp>; 00609 friend class ALU3dGrid < GridImp::elementType, Comm >; 00610 00611 typedef ALU3dImplTraits<GridImp::elementType, Comm > ImplTraits; 00612 typedef typename ImplTraits::template Codim<cd>::InterfaceType HElementType; 00613 00614 typedef typename ImplTraits::HBndSegType HBndSegType; 00615 typedef typename ImplTraits::BNDFaceType BNDFaceType; 00616 00617 typedef ALU3dGridEntity< 0,dim,GridImp> ALU3dGridEntityType ; 00618 00619 using BaseType :: seed_; 00620 using BaseType :: entity_; 00621 using BaseType :: entityImp; 00622 using BaseType :: factory_; 00623 public: 00624 typedef typename GridImp::GridObjectFactoryType FactoryType; 00625 00627 typedef ALU3dGridEntitySeed<cd, GridImp> ALU3dGridEntitySeedType; 00628 00630 typedef typename GridImp::template Codim<cd>::Entity Entity; 00631 00633 typedef ThisType ALU3dGridEntityPointerType; 00634 00636 ALU3dGridEntityPointer(const FactoryType& factory, 00637 const HElementType & item) 00638 : ALU3dGridEntityPointerBase<cd,GridImp> (factory,item) {} 00639 00641 ALU3dGridEntityPointer(const FactoryType& factory, 00642 const HBndSegType & ghostFace ) 00643 : ALU3dGridEntityPointerBase<cd,GridImp> (factory,ghostFace) {} 00644 00646 ALU3dGridEntityPointer(const FactoryType& factory, const ALU3dGridEntitySeedType& seed) 00647 : ALU3dGridEntityPointerBase<cd,GridImp> (factory, seed) 00648 { 00649 // for ghost entities we have to copy right away 00650 if( seed.isGhost() ) 00651 { 00652 assert( entity_ == 0 ); 00653 entity_ = factory_.template getNewEntity<0> (); 00654 assert( entity_ ); 00655 entityImp().setGhost( *seed.ghost() ); 00656 00657 // don't free on compactify, otherwise ghost info is lost 00658 this->locked_ = true ; 00659 } 00660 } 00661 00663 ALU3dGridEntityPointer(const ALU3dGridEntityType& entity) 00664 : ALU3dGridEntityPointerBase<cd,GridImp> (entity.factory(), 00665 entity.seed() ) 00666 { 00667 // for ghost entities we have to copy right away 00668 if( entity.isGhost() ) 00669 { 00670 assert( entity_ == 0 ); 00671 entity_ = factory_.template getNewEntity<0> (); 00672 assert( entity_ ); 00673 entityImp().setEntity( entity ); 00674 00675 // don't free on compactify, otherwise ghost info is lost 00676 this->locked_ = true ; 00677 } 00678 } 00679 00681 ALU3dGridEntityPointer(const ALU3dGridEntityPointerType & org) 00682 : ALU3dGridEntityPointerBase<cd,GridImp> (org) 00683 { 00684 } 00685 00686 protected: 00689 ALU3dGridEntityPointer(const FactoryType& factory, int level ) 00690 : ALU3dGridEntityPointerBase<cd,GridImp> (factory,level) {} 00691 }; 00692 00693 00694 template<int cd, class GridImp> 00695 class ALU3dGridEntityPointer : 00696 public ALU3dGridEntityPointerBase<cd,GridImp> 00697 { 00698 protected: 00699 typedef ALU3dGridEntityPointerBase<cd,GridImp> BaseType ; 00700 typedef ALU3dGridEntityPointer <cd,GridImp> ThisType; 00701 enum { dim = GridImp::dimension }; 00702 enum { dimworld = GridImp::dimensionworld }; 00703 00704 typedef typename GridImp::MPICommunicatorType Comm; 00705 00706 friend class ALU3dGridEntity<cd,dim,GridImp>; 00707 friend class ALU3dGridEntity< 0,dim,GridImp>; 00708 friend class ALU3dGrid < GridImp::elementType, Comm >; 00709 00710 typedef ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits; 00711 typedef typename ImplTraits::template Codim<cd>::InterfaceType HElementType; 00712 00713 typedef typename ImplTraits::HBndSegType HBndSegType; 00714 typedef typename ImplTraits::BNDFaceType BNDFaceType; 00715 typedef ALU3dGridEntity<cd,dim,GridImp> ALU3dGridEntityType; 00716 00717 using BaseType :: seed_; 00718 using BaseType :: entity_; 00719 using BaseType :: entityImp; 00720 using BaseType :: factory_; 00721 using BaseType :: getEntity; 00722 00723 public: 00724 typedef typename GridImp::GridObjectFactoryType FactoryType; 00725 00727 typedef ALU3dGridEntitySeed<cd, GridImp> ALU3dGridEntitySeedType; 00728 00730 typedef typename GridImp::template Codim<cd>::Entity Entity; 00731 00733 typedef ALU3dGridEntityPointer<cd,GridImp> ALU3dGridEntityPointerType; 00734 00735 protected: 00736 static const int defaultValue = -665; //ALU3dGridEntityPointerType :: defaultValue; 00737 00738 public: 00740 ALU3dGridEntityPointer(const FactoryType& factory, 00741 const int level, 00742 const HElementType & item, 00743 const int twist = defaultValue, 00744 const int duneFace = defaultValue 00745 ); 00746 00748 ALU3dGridEntityPointer(const ALU3dGridEntityType& entity) 00749 : ALU3dGridEntityPointerBase<cd,GridImp> (entity.factory(), 00750 entity.seed()) 00751 {} 00752 00754 ALU3dGridEntityPointer(const FactoryType& factory, const ALU3dGridEntitySeedType& seed) 00755 : ALU3dGridEntityPointerBase<cd,GridImp> ( factory, seed ) 00756 {} 00757 00759 ALU3dGridEntityPointer(const ALU3dGridEntityPointerType & org); 00760 00762 Entity & dereference () const ; 00763 00765 ThisType & operator = (const ThisType & org); 00766 00768 int level () const ; 00769 00770 protected: 00771 // clones object 00772 void clone (const ALU3dGridEntityPointerType & org); 00773 00774 void updateEntityPointer( HElementType * item , int level ); 00775 00778 ALU3dGridEntityPointer(const FactoryType& factory, int level ) 00779 : ALU3dGridEntityPointerBase<cd,GridImp> (factory,level) 00780 {} 00781 }; 00782 00783 } // end namespace Dune 00784 00785 #include "entity_inline.hh" 00786 00787 #if COMPILE_ALUGRID_INLINE 00788 #include "entity_imp.cc" 00789 #endif 00790 00791 #endif