dune-grid
2.2.0
|
00001 #ifndef DUNE_ALU2DGRIDENTITY_HH 00002 #define DUNE_ALU2DGRIDENTITY_HH 00003 00004 // System includes 00005 00006 // Dune includes 00007 #include <dune/grid/common/entity.hh> 00008 //#include <dune/grid/common/intersectioniteratorwrapper.hh> 00009 00010 // Local includes 00011 #include <dune/grid/alugrid/2d/intersection.hh> 00012 #include <dune/grid/alugrid/2d/iterator.hh> 00013 #include <dune/grid/alugrid/2d/entityseed.hh> 00014 00015 namespace Dune { 00016 // Forward declarations 00017 template<int cd, int dim, class GridImp> 00018 class ALU2dGridEntity; 00019 template<int cd, PartitionIteratorType pitype, class GridImp > 00020 class ALU2dGridLevelIterator; 00021 template< int codim, class GridImp > 00022 class ALU2dGridEntityPointer; 00023 template<int mydim, int coorddim, class GridImp> 00024 class ALU2dGridGeometry; 00025 template<class GridImp> 00026 class ALU2dGridHierarchicIterator; 00027 template<class GridImp> 00028 class ALU2dGridLevelIntersectionIterator; 00029 template<class GridImp> 00030 class ALU2dGridLeafIntersectionIterator; 00031 template<class GridImp> 00032 class ALU2dGridIntersectionIterator; 00033 template<int codim, PartitionIteratorType, class GridImp> 00034 class ALU2dGridLeafIterator; 00035 template< int dim, int dimworld, ALU2DSPACE ElementType eltype > 00036 class ALU2dGrid; 00037 00038 //********************************************************************** 00039 // 00040 // --ALU2dGridEntity 00041 // --Entity 00042 // 00043 //********************************************************************** 00050 template<int cd, int dim, class GridImp> 00051 class ALU2dGridEntity : 00052 public EntityDefaultImplementation <cd,dim,GridImp,ALU2dGridEntity> 00053 { 00054 static const int dimworld = GridImp::dimensionworld; 00055 static const ALU2DSPACE ElementType eltype = GridImp::elementType; 00056 00057 friend class ALU2dGrid< dim, dimworld, eltype >; 00058 friend class ALU2dGridIntersectionIterator < GridImp >; 00059 friend class ALU2dGridIntersectionIterator < const GridImp >; 00060 friend class ALU2dGridLevelIntersectionIterator < GridImp >; 00061 friend class ALU2dGridLevelIntersectionIterator < const GridImp >; 00062 friend class ALU2dGridLeafIntersectionIterator < GridImp >; 00063 friend class ALU2dGridLeafIntersectionIterator < const GridImp >; 00064 friend class ALU2dGridHierarchicIterator < const GridImp >; 00065 friend class ALU2dGridHierarchicIterator < GridImp >; 00066 friend class ALU2dGridLevelIterator <0,All_Partition,GridImp>; 00067 friend class ALU2dGridLevelIterator <1,All_Partition,GridImp>; 00068 friend class ALU2dGridLevelIterator <2,All_Partition,GridImp>; 00069 friend class ALU2dGridLeafIterator <0, All_Partition,GridImp>; 00070 friend class ALU2dGridLeafIterator <1, All_Partition,GridImp>; 00071 friend class ALU2dGridLeafIterator <2, All_Partition,GridImp>; 00072 friend class ALU2dGridMakeableEntity<0,dim,GridImp>; 00073 00074 friend class ALU2dGridHierarchicIndexSet<dim,dimworld,eltype>; 00075 00076 typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType ; 00077 00078 typedef typename GridImp::Traits::template Codim< cd >::GeometryImpl GeometryImpl; 00079 00080 public: 00081 typedef typename GridImp :: GridObjectFactoryType FactoryType; 00082 00083 typedef typename Dune::ALU2dImplTraits< dimworld, eltype >::template Codim<cd>::InterfaceType ElementType; 00084 typedef typename Dune::ALU2dImplTraits< dimworld, eltype >::template Codim<2>::InterfaceType VertexType; 00085 00087 typedef typename GridImp::template Codim<cd>::Entity Entity; 00089 typedef typename GridImp::template Codim<cd>::Geometry Geometry; 00090 00092 typedef typename GridImp::template Codim<cd>::EntitySeed EntitySeed; 00093 00095 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer; 00096 00098 int level () const; 00099 00101 ALU2dGridEntity(const FactoryType& factory, int level); 00102 00104 ALU2dGridEntity(const ALU2dGridEntity & org); 00105 00107 Geometry geometry () const; 00108 00110 GeometryType type() const ; 00111 00113 void removeElement(); 00114 00118 00119 void setElement(const ElementType &element, int face=-1, int level = -1) const; 00120 void setElement(const EntitySeed& seed ) const; 00121 void setElement(const HElementType & el, const VertexType & vx); 00122 void setElement(const ALU2dGridEntity & org) const 00123 { 00124 setElement(*(org.item_), org.face_); 00125 } 00126 00128 bool equals ( const ALU2dGridEntity<cd,dim,GridImp> & org ) const; 00129 00132 PartitionType partitionType() const{ return InteriorEntity; } 00133 00138 int boundaryId () const; 00139 00144 EntityPointer ownersFather () const; 00145 00147 FieldVector<alu2d_ctype, dim>& positionInOwnersFather () const; 00148 00150 const GridImp& grid() const { return factory_.grid(); } 00151 00153 const FactoryType& factory() const { return factory_; } 00154 00156 ElementType& getItem() const 00157 { 00158 assert( item_ ); 00159 return *item_; 00160 } 00161 00163 EntitySeed seed() const 00164 { 00165 return EntitySeed( getItem(), level(), getFace() ); 00166 } 00167 00168 // return internal face 00169 int getFace() const { return face_; } 00170 00172 int getIndex () const; 00173 00174 private: 00176 const FactoryType& factory_; 00177 00179 mutable ElementType * item_; 00181 00182 mutable GeometryImpl geoObj_; 00183 00184 mutable int level_; 00185 mutable int face_; 00186 }; 00187 00201 //*********************** 00202 // 00203 // --ALU2dGridEntity 00204 // --0Entity 00205 // 00206 //*********************** 00207 template<int dim, class GridImp> 00208 class ALU2dGridEntity<0,dim,GridImp> 00209 : public EntityDefaultImplementation<0,dim,GridImp,ALU2dGridEntity> 00210 { 00211 static const int dimworld = GridImp::dimensionworld; 00212 static const ALU2DSPACE ElementType eltype = GridImp::elementType; 00213 00214 friend class ALU2dGrid< dim, dimworld, eltype >; 00215 friend class ALU2dGridIntersectionIterator < GridImp >; 00216 friend class ALU2dGridIntersectionIterator < const GridImp >; 00217 friend class ALU2dGridLevelIntersectionIterator < GridImp >; 00218 friend class ALU2dGridLevelIntersectionIterator < const GridImp >; 00219 friend class ALU2dGridLeafIntersectionIterator < GridImp >; 00220 friend class ALU2dGridLeafIntersectionIterator < const GridImp >; 00221 friend class ALU2dGridHierarchicIterator < const GridImp >; 00222 friend class ALU2dGridHierarchicIterator < GridImp >; 00223 friend class ALU2dGridLevelIterator <0,All_Partition,GridImp>; 00224 friend class ALU2dGridLevelIterator <1,All_Partition,GridImp>; 00225 friend class ALU2dGridLevelIterator <2,All_Partition,GridImp>; 00226 friend class ALU2dGridLeafIterator <0, All_Partition,GridImp>; 00227 friend class ALU2dGridLeafIterator <1, All_Partition,GridImp>; 00228 friend class ALU2dGridLeafIterator <2, All_Partition,GridImp>; 00229 friend class ALU2dGridMakeableEntity<0,dim,GridImp>; 00230 00231 friend class ALU2dGridHierarchicIndexSet<dim,dimworld,eltype>; 00232 00233 typedef typename ALU2dImplTraits< dimworld, eltype >::HElementType HElementType ; 00234 00235 typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl GeometryImpl; 00236 typedef typename GridImp::Traits::template Codim< 0 >::LocalGeometryImpl LocalGeometryImpl; 00237 00238 public: 00239 typedef typename GridImp :: GridObjectFactoryType FactoryType; 00240 00242 typedef typename GridImp::template Codim<0>::Geometry Geometry; 00244 typedef typename GridImp::template Codim<0>::LocalGeometry LocalGeometry; 00245 00247 typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed; 00248 00250 typedef LeafIntersectionIteratorWrapper< GridImp > ALU2dGridLeafIntersectionIteratorType; 00251 typedef LevelIntersectionIteratorWrapper< GridImp > ALU2dGridLevelIntersectionIteratorType; 00252 typedef ALU2dGridLeafIntersectionIteratorType ALU2dGridIntersectionIteratorType; 00253 00255 typedef typename GridImp::template Codim<0>::Entity Entity; 00257 //typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer; 00258 typedef ALU2dGridEntityPointer<0,GridImp> EntityPointer; 00259 00260 template <int cd> 00261 struct Codim 00262 { 00263 typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer; 00264 }; 00265 00267 ALU2dGridEntity(const FactoryType& factory, int level); 00268 00270 ALU2dGridEntity(const ALU2dGridEntity & org); 00271 00273 int level () const ; 00274 00276 Geometry geometry () const; 00277 00279 GeometryType type() const ; 00280 00284 template<int cc> 00285 int count () const 00286 { 00287 assert( item_ ); 00288 return (cc==0) ? 1 : item_->numvertices(); 00289 } 00290 00295 int boundaryId () const { 00296 // elements are always inside of our Domain 00297 return 0; 00298 } 00299 00306 // As ibegin() and iend() are deprecated these methods will deliver a LeafIntersectionIterator 00307 ALU2dGridIntersectionIteratorType ibegin () const 00308 { 00309 return ileafbegin(); 00310 } 00312 ALU2dGridIntersectionIteratorType iend () const 00313 { 00314 return ileafend(); 00315 } 00316 00317 ALU2dGridLevelIntersectionIteratorType ilevelbegin () const 00318 { 00319 return ALU2dGridLevelIntersectionIteratorType( *this, this->level(),false); 00320 } 00321 ALU2dGridLevelIntersectionIteratorType ilevelend () const 00322 { 00323 return ALU2dGridLevelIntersectionIteratorType( *this, this->level(),true); 00324 } 00325 ALU2dGridLeafIntersectionIteratorType ileafbegin () const 00326 { 00327 return ALU2dGridLeafIntersectionIteratorType( *this, this->level(), false); 00328 } 00329 ALU2dGridLeafIntersectionIteratorType ileafend () const 00330 { 00331 return ALU2dGridLeafIntersectionIteratorType( *this, this->level(),true); 00332 } 00333 00335 bool isLeaf () const; 00336 00339 EntityPointer father () const; 00340 00342 bool hasFather () const 00343 { 00344 return (this->level()>0); 00345 } 00346 00351 ALU2dGridHierarchicIterator<GridImp> hbegin (int maxLevel) const 00352 { 00353 return ALU2dGridHierarchicIterator<GridImp> (factory(), *item_ , maxLevel,false); 00354 } 00355 00357 ALU2dGridHierarchicIterator<GridImp> hend (int maxLevel) const 00358 { 00359 return ALU2dGridHierarchicIterator<GridImp> (factory(), *item_, maxLevel,true); 00360 } 00361 00364 template <int cc> 00365 typename Codim<cc>::EntityPointer entity (int i) const; 00366 00369 template< int codim > 00370 typename Codim< codim >::EntityPointer subEntity ( int i ) const 00371 { 00372 int j = i; 00373 // apply mapping for codim 1 00374 // dune to alu 00375 switch (codim) 00376 { 00377 case 1: 00378 if( item_->numvertices() == 3 ) 00379 j = 2 - i; 00380 else 00381 switch (i) { case 0: j=2;break; 00382 case 1: j=0;break; 00383 case 2: j=3;break; 00384 case 3: j=1;break; 00385 } 00386 break; 00387 case 2: 00388 if( item_->numvertices() == 4 ) 00389 switch (i) { case 0: j=0;break; 00390 case 1: j=1;break; 00391 case 2: j=3;break; 00392 case 3: j=2;break; 00393 } 00394 break; 00395 } 00396 return entity< codim >( j ); 00397 } 00398 00400 PartitionType partitionType() const 00401 { 00402 #if ALU2DGRID_PARALLEL 00403 return grid().rankManager().partitionType( item_->getIndex() ); 00404 #else 00405 return InteriorEntity; 00406 #endif 00407 } 00408 00415 template <int cc> 00416 int subBoundaryId ( int i ) const; 00417 00418 00429 LocalGeometry geometryInFather () const; 00430 00432 bool mightVanish () const 00433 { 00434 return ((item_->is(ALU2DSPACE Refco::crs))==1); 00435 } 00436 00437 bool isNew () const 00438 { 00439 return ((item_->wasRefined())==1); 00440 } 00441 00442 //*************************************************************** 00443 // Interface for Adaptation 00444 //*************************************************************** 00445 00446 public: 00450 bool mark(int refCount) const; 00451 00453 int getMark() const; 00454 00458 void setElement(const HElementType &element, int face=-1, int level = -1) const; 00459 void setElement(const EntitySeed& seed ) const; 00460 00461 void setElement(const ALU2dGridEntity & org) const { 00462 setElement(*(org.item_)); 00463 } 00464 00466 void reset ( int l ); 00467 00469 void removeElement(); 00470 00472 bool equals ( const ALU2dGridEntity<0,dim,GridImp> & org ) const; 00473 00474 // return reference to HElement (needed by IntersectionIterator) 00475 HElementType & getItem() const 00476 { 00477 assert( item_ ); 00478 return *item_; 00479 } 00480 00482 EntitySeed seed() const 00483 { 00484 return EntitySeed( getItem() ); 00485 } 00486 00488 const GridImp& grid() const { return factory_.grid(); } 00489 00491 const FactoryType& factory() const { return factory_; } 00492 00493 // return internal face 00494 int getFace() const { return -1; } 00495 00497 int getIndex () const; 00498 00499 private: 00501 int nChild () const; 00502 00506 template<int cc> int getSubIndex (int i) const; 00507 00508 int subIndex (int i, unsigned int codim) const; 00509 00511 const FactoryType& factory_; 00512 00514 mutable HElementType *item_; 00515 00517 mutable GeometryImpl geoObj_; 00518 00520 mutable bool isLeaf_; 00521 00522 }; // end of ALU2dGridEntity codim = 0 00523 00524 00525 //********************************************************************** 00526 // 00527 // --ALU2dGridEntityPointer 00528 // --EntityPointer 00529 // --EnPointer 00530 //********************************************************************** 00534 template< int codim, class GridImp > 00535 class ALU2dGridEntityPointer 00536 { 00537 // type of this class 00538 typedef ALU2dGridEntityPointer< codim, GridImp > ThisType; 00539 00540 static const int dim = GridImp::dimension; 00541 static const int dimworld = GridImp::dimensionworld; 00542 static const ALU2DSPACE ElementType eltype = GridImp::elementType; 00543 00544 typedef typename Dune::ALU2dImplTraits< dimworld, eltype >::template Codim<codim>::InterfaceType ElementType; 00545 00546 public: 00547 typedef typename GridImp :: GridObjectFactoryType FactoryType; 00548 00549 enum { codimension = codim }; 00550 00552 typedef typename GridImp::template Codim<codimension>::Entity Entity; 00553 00555 typedef typename GridImp::template Codim<codimension>::EntitySeed EntitySeed; 00557 typedef ALU2dGridEntity<codimension,dim,GridImp> EntityImp; 00558 typedef MakeableInterfaceObject<Entity> EntityObj; 00559 00560 typedef ALU2dGridEntityPointer<codimension,GridImp> EntityPointerImp; 00561 00563 ALU2dGridEntityPointer ( const FactoryType& factory, 00564 const ElementType &item, 00565 int face = -1, 00566 int level = -1 00567 ); 00568 00570 ALU2dGridEntityPointer(const FactoryType& factory, const EntitySeed& seed) ; 00571 00573 ALU2dGridEntityPointer(const EntityImp& entity) ; 00574 00576 ALU2dGridEntityPointer(const FactoryType& factory) ; 00577 00579 ALU2dGridEntityPointer(const ThisType & org) ; 00580 00582 ~ALU2dGridEntityPointer(); 00583 00585 // this may have to be changed! 00586 bool equals (const ThisType & i) const; 00587 00589 Entity & dereference() const ; 00590 00592 int level () const; 00593 00595 ThisType & operator = (const ThisType & org); 00596 00598 const GridImp& grid() const { return factory_.grid(); } 00599 00600 protected: 00601 EntityImp & entityImp(); 00602 const EntityImp & entityImp() const; 00603 00605 void done (); 00606 00608 void updateEntityPointer( ElementType * item, int face=-1, int level=-1 ); 00609 00611 const FactoryType& factory_; 00612 00614 EntitySeed seed_ ; 00615 00617 mutable EntityObj * entity_; 00618 }; 00619 00620 } // end namespace Dune 00621 00622 #include "entity_imp.cc" 00623 #endif