dune-grid
2.1.1
|
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 public: 00083 typedef typename GridImp::GridObjectFactoryType FactoryType; 00084 00085 typedef ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits; 00086 typedef typename ImplTraits::template Codim<cd>::InterfaceType HItemType; 00087 typedef typename ImplTraits::template Codim<cd>::ImplementationType ItemType; 00088 typedef typename ImplTraits::VertexType VertexType; 00089 typedef typename ImplTraits::HBndSegType HBndSegType; 00090 00091 typedef typename GridImp::template Codim<cd>::Entity Entity; 00092 typedef typename GridImp::template Codim<cd>::Geometry Geometry; 00093 00094 typedef ALU3dGridGeometry<dim-cd,GridImp::dimensionworld,GridImp> GeometryImp; 00095 typedef MakeableInterfaceObject<Geometry> GeometryObject; 00096 00097 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer; 00098 00100 typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed; 00101 00103 int level () const; 00104 00106 PartitionType partitionType() const; 00107 00109 ALU3dGridEntity(const FactoryType &factory, int level); 00110 00112 ALU3dGridEntity(const ALU3dGridEntity & org); 00113 00115 const Geometry & geometry () const; 00116 00118 GeometryType type () const; 00119 00120 // set element as normal entity 00121 void setElement(const HItemType & item); 00122 void setElement(const HItemType & item, const int level, int twist=0, int face = -1); 00123 00124 /* set entity from seed */ 00125 void setElement(const EntitySeed& seed); 00126 00128 void setGhost(const HBndSegType &ghost); 00129 00131 void removeElement (); 00132 00134 void reset ( int l ); 00135 00137 bool equals ( const ALU3dGridEntity<cd,dim,GridImp> & org ) const; 00138 00140 void setEntity ( const ALU3dGridEntity<cd,dim,GridImp> & org ); 00141 00142 // return reference to internal item 00143 const ItemType & getItem () const { return *item_; } 00144 00146 const GridImp& grid() const { return factory_.grid(); } 00147 00149 const FactoryType& factory() const { return factory_; } 00150 00152 EntitySeed seed() const 00153 { 00154 return EntitySeed( getItem(), level(), twist_, face_ ); 00155 } 00156 00157 private: 00159 GeometryImp& geoImp() const { return GridImp :: getRealImplementation(geo_); } 00160 00162 int getIndex () const; 00163 00165 PartitionType convertBndId(const HItemType & item) const ; 00166 00168 mutable GeometryObject geo_; 00169 00170 // the factory that created this entity 00171 const FactoryType& factory_; 00172 00173 // corresponding ALU3dGrid item, here face, edge, or vertex 00174 const ItemType * item_; 00175 00176 int level_; 00177 int gIndex_; 00178 int twist_; 00179 int face_; 00180 00181 mutable bool builtgeometry_; 00182 mutable PartitionType partitionType_; 00183 }; 00184 00198 //*********************** 00199 // 00200 // --ALU3dGridEntity 00201 // --0Entity 00202 // 00203 //*********************** 00204 template<int dim, class GridImp> 00205 class ALU3dGridEntity<0,dim,GridImp> 00206 : public EntityDefaultImplementation<0,dim,GridImp,ALU3dGridEntity> 00207 { 00208 static const int dimworld = remove_const< GridImp >::type::dimensionworld; 00209 static const ALU3dGridElementType elementType = remove_const< GridImp >::type::elementType; 00210 00211 typedef typename GridImp::MPICommunicatorType Comm; 00212 00213 typedef ALU3dImplTraits< elementType, Comm > ImplTraits; 00214 typedef typename ImplTraits::template Codim<0>::InterfaceType HElementType; 00215 00216 typedef typename ImplTraits::GEOElementType GEOElementType; 00217 typedef typename ImplTraits::BNDFaceType BNDFaceType; 00218 typedef typename ImplTraits::IMPLElementType IMPLElementType; 00219 typedef typename ImplTraits::HBndSegType HBndSegType; 00220 00221 enum { refine_element_t = ImplTraits::refine_element_t }; 00222 enum { coarse_element_t = ImplTraits::coarse_element_t }; 00223 enum { nosplit_element_t = ImplTraits::nosplit_element_t }; 00224 00225 typedef typename ImplTraits::MarkRuleType MarkRuleType; 00226 00227 friend class ALU3dGrid< elementType, Comm >; 00228 friend class ALU3dGridIntersectionIterator < GridImp >; 00229 friend class ALU3dGridIntersectionIterator < const GridImp >; 00230 friend class ALU3dGridHierarchicIterator < const GridImp >; 00231 friend class ALU3dGridHierarchicIterator < GridImp >; 00232 friend class ALU3dGridLevelIterator <0,All_Partition,GridImp>; 00233 friend class ALU3dGridLevelIterator <1,All_Partition,GridImp>; 00234 friend class ALU3dGridLevelIterator <2,All_Partition,GridImp>; 00235 friend class ALU3dGridLevelIterator <3,All_Partition,GridImp>; 00236 friend class ALU3dGridLeafIterator <0, All_Partition,GridImp>; 00237 friend class ALU3dGridLeafIterator <1, All_Partition,GridImp>; 00238 friend class ALU3dGridLeafIterator <2, All_Partition,GridImp>; 00239 friend class ALU3dGridLeafIterator <3, All_Partition,GridImp>; 00240 00241 friend class ALU3dGridHierarchicIndexSet< elementType, Comm >; 00242 00243 template< class > friend class ALU3dGridFactory; 00244 00245 // type of reference element 00246 typedef typename GridImp :: ReferenceElementType ReferenceElementType; 00247 00248 public: 00249 typedef typename GridImp::GridObjectFactoryType FactoryType; 00250 00251 typedef typename GridImp::template Codim<0>::Geometry Geometry; 00252 typedef ALU3dGridGeometry<dim,dimworld,GridImp> GeometryImp; 00253 typedef MakeableInterfaceObject<Geometry> GeometryObject; 00254 typedef ALU3dGridIntersectionIterator<GridImp> IntersectionIteratorImp; 00255 00256 typedef LeafIntersectionIteratorWrapper <GridImp> ALU3dGridIntersectionIteratorType; 00257 typedef LeafIntersectionIteratorWrapper <GridImp> ALU3dGridLeafIntersectionIteratorType; 00258 typedef LevelIntersectionIteratorWrapper<GridImp> ALU3dGridLevelIntersectionIteratorType; 00259 00260 typedef typename GridImp::template Codim<0>::Entity Entity; 00261 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer; 00262 00263 template <int cd> 00264 struct Codim 00265 { 00266 typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer; 00267 }; 00268 00270 typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed; 00271 00273 ALU3dGridEntity(const FactoryType& factory, int level); 00274 00276 ALU3dGridEntity(const ALU3dGridEntity & org); 00277 00279 int level () const ; 00280 00282 const Geometry & geometry () const; 00283 00285 GeometryType type () const; 00286 00288 PartitionType partitionType() const; 00289 00293 template<int cc> int count () const ; 00294 00297 template <int codim> 00298 typename Codim< codim >::EntityPointer entity (int i) const 00299 { 00300 typedef GenericGeometry::MapNumberingProvider< GridImp::dimension > Numbering; 00301 const unsigned int tid = type().id(); 00302 const int j = Numbering::template dune2generic< codim >( tid, i ); 00303 return subEntity< codim >( j ); 00304 } 00305 00306 template< int codim > 00307 typename Codim< codim >::EntityPointer subEntity ( int i ) const; 00308 00314 ALU3dGridLeafIntersectionIteratorType ileafbegin () const; 00315 00317 ALU3dGridLeafIntersectionIteratorType ileafend () const; 00318 00324 ALU3dGridLevelIntersectionIteratorType ilevelbegin () const; 00325 00327 ALU3dGridLevelIntersectionIteratorType ilevelend () const; 00328 00330 bool isLeaf () const; 00331 00334 EntityPointer father () const; 00336 bool hasFather () const 00337 { 00338 return (this->level()>0); 00339 } 00340 00350 const Geometry & geometryInFather () const; 00351 00356 ALU3dGridHierarchicIterator<GridImp> hbegin (int maxlevel) const; 00357 00359 ALU3dGridHierarchicIterator<GridImp> hend (int maxlevel) const; 00360 00361 //*************************************************************** 00362 // Interface for Adaptation 00363 //*************************************************************** 00364 00366 bool isNew () const; 00367 00369 bool mightVanish () const; 00370 00372 bool hasBoundaryIntersections () const; 00373 00374 // private method 00378 bool mark( int refCount ) const; 00379 00381 int getMark() const; 00382 00386 void setElement(HElementType &element); 00387 00388 /* set entity from seed */ 00389 void setElement(const EntitySeed& seed); 00390 00392 void setGhost(HBndSegType & ghost); 00393 00395 void reset ( int l ); 00396 00398 void removeElement(); 00399 00401 bool equals ( const ALU3dGridEntity<0,dim,GridImp> & org ) const; 00402 00403 void setEntity ( const ALU3dGridEntity<0,dim,GridImp> & org ); 00404 00408 template<int cc> int getSubIndex (int i) const; 00409 00413 int subIndex(int i, unsigned int codim) const; 00414 00415 // return reference to internal item 00416 const IMPLElementType& getItem () const { return *item_; } 00417 00418 // return reference to internal item 00419 const BNDFaceType& getGhost () const 00420 { 00421 assert( isGhost() ); 00422 return *ghost_; 00423 } 00424 00426 const GridImp& grid() const { return factory_.grid(); } 00427 00429 const FactoryType& factory() const { return factory_; } 00430 00432 bool isGhost () const{ return ImplTraits::isGhost( ghost_ ); } 00433 00435 EntitySeed seed() const 00436 { 00437 if( isGhost() ) 00438 return EntitySeed( getGhost () ); 00439 else 00440 return EntitySeed( getItem() ); 00441 } 00442 00443 private: 00445 GeometryImp& geoImp() const { return GridImp :: getRealImplementation(geo_); } 00446 00448 int getIndex () const; 00449 00451 mutable GeometryObject geo_; 00452 00453 // corresponding factory 00454 const FactoryType& factory_; 00455 00456 // the current element of grid 00457 mutable IMPLElementType* item_; 00458 00460 mutable BNDFaceType* ghost_; 00461 00462 int level_; 00463 bool isLeaf_; 00464 mutable bool builtgeometry_; 00465 00466 }; // end of ALU3dGridEntity codim = 0 00467 //********************************************************************** 00468 // 00469 // --ALU3dGridEntityPointer 00470 // --EntityPointer 00471 // --EnPointer 00475 template< int codim, class GridImp > 00476 class ALU3dGridEntityPointerBase 00477 //: public EntityPointerDefaultImplementation <codim, GridImp, ALU3dGridEntityPointer<cd,GridImp> > 00478 { 00479 typedef ALU3dGridEntityPointerBase< codim, GridImp > ThisType; 00480 enum { dim = GridImp::dimension }; 00481 enum { dimworld = GridImp::dimensionworld }; 00482 00483 typedef typename GridImp::MPICommunicatorType Comm; 00484 00485 friend class ALU3dGridEntity<codim,dim,GridImp>; 00486 friend class ALU3dGridEntity< 0,dim,GridImp>; 00487 friend class ALU3dGrid < GridImp::elementType, Comm >; 00488 00489 typedef ALU3dImplTraits<GridImp::elementType, Comm > ImplTraits; 00490 typedef typename ImplTraits::template Codim<codim>::InterfaceType HElementType; 00491 00492 typedef typename ImplTraits::HBndSegType HBndSegType; 00493 typedef typename ImplTraits::BNDFaceType BNDFaceType; 00494 public: 00495 typedef typename GridImp::GridObjectFactoryType FactoryType; 00496 00497 enum { codimension = codim }; 00498 00500 typedef typename GridImp::template Codim<codimension>::Entity Entity; 00502 typedef MakeableInterfaceObject<Entity> EntityObject; 00503 typedef typename EntityObject :: ImplementationType EntityImp; 00504 00506 typedef ThisType ALU3dGridEntityPointerType; 00507 00509 typedef ALU3dGridEntityPointer<codimension,GridImp> EntityPointerImp; 00510 00512 typedef ALU3dGridEntitySeed<codimension, GridImp> ALU3dGridEntitySeedType; 00513 00515 ALU3dGridEntityPointerBase(const FactoryType& factory, 00516 const HElementType & item); 00517 00519 ALU3dGridEntityPointerBase(const FactoryType& factory, 00520 const HElementType & item, 00521 const int level, 00522 const int twist, 00523 const int duneFace 00524 ); 00525 00527 ALU3dGridEntityPointerBase(const FactoryType& factory, 00528 const HBndSegType & ghostFace ); 00529 00531 ALU3dGridEntityPointerBase(const FactoryType& factory, 00532 const ALU3dGridEntitySeedType& seed ); 00533 00535 ALU3dGridEntityPointerBase(const ALU3dGridEntityPointerType & org); 00536 00538 ~ALU3dGridEntityPointerBase(); 00539 00541 bool equals (const ALU3dGridEntityPointerType& i) const; 00542 00544 ThisType & operator = (const ThisType & org); 00545 00547 Entity & dereference () const ; 00548 00550 int level () const ; 00551 00553 void compactify(); 00554 00555 protected: 00556 // clones object 00557 void clone (const ALU3dGridEntityPointerType & org); 00558 00559 // get entity and assign from org.entity 00560 void getEntity (const ALU3dGridEntityPointerType & org); 00561 00563 void done (); 00564 00566 void freeEntity (); 00567 00569 const GridImp& grid () const { return factory_.grid(); } 00570 00573 ALU3dGridEntityPointerBase(const FactoryType& factory, int level ); 00574 00575 // update underlying item pointer and set ghost entity 00576 void updateGhostPointer( HBndSegType & ghostFace ); 00577 // update underlying item pointer and set entity 00578 void updateEntityPointer( HElementType * item , int level = -1 ); 00579 00580 // reference to factory 00581 const FactoryType& factory_; 00582 00583 // key to gererate entity 00584 ALU3dGridEntitySeedType seed_; 00585 00586 // entity that this EntityPointer points to 00587 mutable EntityObject * entity_; 00588 00589 // is true if entity must not be released 00590 bool locked_; 00591 00592 // return reference to internal entity implementation 00593 EntityImp & entityImp () const { 00594 assert( entity_ ); 00595 return GridImp :: getRealImplementation(*entity_); 00596 } 00597 }; 00598 00602 template<class GridImp> 00603 class ALU3dGridEntityPointer<0,GridImp> : 00604 public ALU3dGridEntityPointerBase<0,GridImp> 00605 { 00606 protected: 00607 typedef ALU3dGridEntityPointerBase<0,GridImp> BaseType; 00608 00609 enum { cd = 0 }; 00610 typedef ALU3dGridEntityPointer <cd,GridImp> ThisType; 00611 enum { dim = GridImp::dimension }; 00612 enum { dimworld = GridImp::dimensionworld }; 00613 00614 typedef typename GridImp::MPICommunicatorType Comm; 00615 00616 friend class ALU3dGridEntity<cd,dim,GridImp>; 00617 friend class ALU3dGridEntity< 0,dim,GridImp>; 00618 friend class ALU3dGrid < GridImp::elementType, Comm >; 00619 00620 typedef ALU3dImplTraits<GridImp::elementType, Comm > ImplTraits; 00621 typedef typename ImplTraits::template Codim<cd>::InterfaceType HElementType; 00622 00623 typedef typename ImplTraits::HBndSegType HBndSegType; 00624 typedef typename ImplTraits::BNDFaceType BNDFaceType; 00625 00626 typedef ALU3dGridEntity< 0,dim,GridImp> ALU3dGridEntityType ; 00627 00628 using BaseType :: seed_; 00629 using BaseType :: entity_; 00630 using BaseType :: entityImp; 00631 using BaseType :: factory_; 00632 public: 00633 typedef typename GridImp::GridObjectFactoryType FactoryType; 00634 00636 typedef ALU3dGridEntitySeed<cd, GridImp> ALU3dGridEntitySeedType; 00637 00639 typedef typename GridImp::template Codim<cd>::Entity Entity; 00640 00642 typedef ThisType ALU3dGridEntityPointerType; 00643 00645 ALU3dGridEntityPointer(const FactoryType& factory, 00646 const HElementType & item) 00647 : ALU3dGridEntityPointerBase<cd,GridImp> (factory,item) {} 00648 00650 ALU3dGridEntityPointer(const FactoryType& factory, 00651 const HBndSegType & ghostFace ) 00652 : ALU3dGridEntityPointerBase<cd,GridImp> (factory,ghostFace) {} 00653 00655 ALU3dGridEntityPointer(const FactoryType& factory, const ALU3dGridEntitySeedType& seed) 00656 : ALU3dGridEntityPointerBase<cd,GridImp> (factory, seed) 00657 { 00658 // for ghost entities we have to copy right away 00659 if( seed.isGhost() ) 00660 { 00661 assert( entity_ == 0 ); 00662 entity_ = factory_.template getNewEntity<0> (); 00663 assert( entity_ ); 00664 entityImp().setGhost( *seed.ghost() ); 00665 00666 // don't free on compactify, otherwise ghost info is lost 00667 this->locked_ = true ; 00668 } 00669 } 00670 00672 ALU3dGridEntityPointer(const ALU3dGridEntityType& entity) 00673 : ALU3dGridEntityPointerBase<cd,GridImp> (entity.factory(), 00674 entity.seed() ) 00675 { 00676 // for ghost entities we have to copy right away 00677 if( entity.isGhost() ) 00678 { 00679 assert( entity_ == 0 ); 00680 entity_ = factory_.template getNewEntity<0> (); 00681 assert( entity_ ); 00682 entityImp().setEntity( entity ); 00683 00684 // don't free on compactify, otherwise ghost info is lost 00685 this->locked_ = true ; 00686 } 00687 } 00688 00690 ALU3dGridEntityPointer(const ALU3dGridEntityPointerType & org) 00691 : ALU3dGridEntityPointerBase<cd,GridImp> (org) 00692 { 00693 } 00694 00695 protected: 00698 ALU3dGridEntityPointer(const FactoryType& factory, int level ) 00699 : ALU3dGridEntityPointerBase<cd,GridImp> (factory,level) {} 00700 }; 00701 00702 00703 template<int cd, class GridImp> 00704 class ALU3dGridEntityPointer : 00705 public ALU3dGridEntityPointerBase<cd,GridImp> 00706 { 00707 protected: 00708 typedef ALU3dGridEntityPointerBase<cd,GridImp> BaseType ; 00709 typedef ALU3dGridEntityPointer <cd,GridImp> ThisType; 00710 enum { dim = GridImp::dimension }; 00711 enum { dimworld = GridImp::dimensionworld }; 00712 00713 typedef typename GridImp::MPICommunicatorType Comm; 00714 00715 friend class ALU3dGridEntity<cd,dim,GridImp>; 00716 friend class ALU3dGridEntity< 0,dim,GridImp>; 00717 friend class ALU3dGrid < GridImp::elementType, Comm >; 00718 00719 typedef ALU3dImplTraits< GridImp::elementType, Comm > ImplTraits; 00720 typedef typename ImplTraits::template Codim<cd>::InterfaceType HElementType; 00721 00722 typedef typename ImplTraits::HBndSegType HBndSegType; 00723 typedef typename ImplTraits::BNDFaceType BNDFaceType; 00724 typedef ALU3dGridEntity<cd,dim,GridImp> ALU3dGridEntityType; 00725 00726 using BaseType :: seed_; 00727 using BaseType :: entity_; 00728 using BaseType :: entityImp; 00729 using BaseType :: factory_; 00730 using BaseType :: getEntity; 00731 00732 public: 00733 typedef typename GridImp::GridObjectFactoryType FactoryType; 00734 00736 typedef ALU3dGridEntitySeed<cd, GridImp> ALU3dGridEntitySeedType; 00737 00739 typedef typename GridImp::template Codim<cd>::Entity Entity; 00740 00742 typedef ALU3dGridEntityPointer<cd,GridImp> ALU3dGridEntityPointerType; 00743 00744 protected: 00745 static const int defaultValue = -665; //ALU3dGridEntityPointerType :: defaultValue; 00746 00747 public: 00749 ALU3dGridEntityPointer(const FactoryType& factory, 00750 const int level, 00751 const HElementType & item, 00752 const int twist = defaultValue, 00753 const int duneFace = defaultValue 00754 ); 00755 00757 ALU3dGridEntityPointer(const ALU3dGridEntityType& entity) 00758 : ALU3dGridEntityPointerBase<cd,GridImp> (entity.factory(), 00759 entity.seed()) 00760 {} 00761 00763 ALU3dGridEntityPointer(const FactoryType& factory, const ALU3dGridEntitySeedType& seed) 00764 : ALU3dGridEntityPointerBase<cd,GridImp> ( factory, seed ) 00765 {} 00766 00768 ALU3dGridEntityPointer(const ALU3dGridEntityPointerType & org); 00769 00771 Entity & dereference () const ; 00772 00774 ThisType & operator = (const ThisType & org); 00775 00777 int level () const ; 00778 00779 protected: 00780 // clones object 00781 void clone (const ALU3dGridEntityPointerType & org); 00782 00783 void updateEntityPointer( HElementType * item , int level ); 00784 00787 ALU3dGridEntityPointer(const FactoryType& factory, int level ) 00788 : ALU3dGridEntityPointerBase<cd,GridImp> (factory,level) 00789 {} 00790 }; 00791 00792 } // end namespace Dune 00793 00794 #include "entity_inline.hh" 00795 00796 #if COMPILE_ALUGRID_INLINE 00797 #include "entity_imp.cc" 00798 #endif 00799 00800 #endif