1 #ifndef DUNE_ALU3DGRIDINDEXSETS_HH
2 #define DUNE_ALU3DGRIDINDEXSETS_HH
6 #include <dune/common/stdstreams.hh>
7 #include <dune/common/bigunsignedint.hh>
8 #include <dune/common/hash.hh>
10 #include <dune/grid/common/grid.hh>
11 #include <dune/grid/common/indexidset.hh>
23 template<
int dim,
int dimworld, ALU3dGr
idElementType,
class >
26 template<
int cd,
int dim,
class Gr
idImp>
27 class ALU3dGridEntity;
35 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
36 class ALU3dGridHierarchicIndexSet
37 :
public IndexSet< ALU3dGrid< dim, dimworld, elType, Comm >, ALU3dGridHierarchicIndexSet< dim, dimworld, elType, Comm > >
39 typedef ALU3dGridHierarchicIndexSet< dim, dimworld, elType, Comm > This;
43 friend class ALU3dGrid<dim, dimworld, elType, Comm >;
54 template <
class EntityType>
55 int index (
const EntityType & ep)
const
57 enum { cd = EntityType :: codimension };
63 int index (
const typename GridType::Traits::template Codim< codim >::Entity &entity )
const
65 return GridType::getRealImplementation( entity ).getIndex();
72 return GridType::getRealImplementation( e ).subIndex( i, codim );
77 int size ( GeometryType type )
const
79 if( elType ==
tetra && !type.isSimplex() )
return 0;
80 if( elType ==
hexa && !type.isCube() )
return 0;
86 int size (
int codim )
const
93 const std::vector<GeometryType>&
geomTypes (
int codim)
const
99 template <
class EntityType>
100 bool contains (
const EntityType &)
const {
return true; }
104 const GridType & grid_;
120 ALUMacroKey(
const A&a,
const A&b,
const A&c,
const A&d) : BaseType(a,b,c,d) {}
124 BaseType::operator = (org);
130 return ( (this->_a == org._a) &&
131 (this->_b == org._b) &&
132 (this->_c == org._c) &&
133 (this->_d == org._d) );
139 return ( (!this->
operator == (org)) && (!this->
operator <(org)) );
152 void print(std::ostream & out)
const
154 out <<
"[" << this->_a <<
"," << this->_b <<
"," << this->_c <<
"," << this->_d <<
"]";
157 #ifdef HAVE_DUNE_HASH
158 inline friend std::size_t hash_value(
const ALUMacroKey& arg)
160 std::size_t seed = 0;
161 hash_combine(seed,arg._a);
162 hash_combine(seed,arg._b);
163 hash_combine(seed,arg._c);
164 hash_combine(seed,arg._d);
167 #endif // HAVE_DUNE_HASH
171 template <
class MacroKeyImp>
185 : key_(key) , nChild_(
nChild)
191 , nChild_(org.nChild_)
198 nChild_ = org.nChild_;
215 if(
equals(org))
return true;
221 if(
equals(org))
return true;
222 else return !
lesser(org);
235 const MacroKeyImp &
getKey()
const {
return key_; }
237 int codim()
const {
return codim_; }
241 return ( (nChild_ >= 0) && (codim_ >= 0) );
250 void print(std::ostream & out)
const
252 out <<
"(" <<
getKey() <<
"," << nChild_ <<
"," << codim_ <<
")";
255 #ifdef HAVE_DUNE_HASH
257 inline friend std::size_t hash_value(
const ALUGridId& arg)
259 std::size_t seed = hash<MacroKeyImp>()(arg.
getKey());
260 hash_combine(seed,arg.
nChild());
261 hash_combine(seed,arg.
codim());
265 #endif // HAVE_DUNE_HASH
275 if(nChild_ == org.nChild_)
277 return codim_ < org.codim_;
280 return nChild_ < org.nChild_;
289 return ( (
getKey() == org.
getKey() ) && (nChild_ == org.nChild_)
290 && (codim_ == org.codim_) );
309 template <
class KeyImp>
321 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
322 class ALU3dGridGlobalIdSet
323 :
public IdSet< ALU3dGrid< dim, dimworld, elType, Comm >, ALU3dGridGlobalIdSet< dim, dimworld, elType, Comm >,
324 typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::GlobalIdType >,
330 typedef ALU3dImplTraits< elType, Comm > ImplTraitsType;
331 typedef typename ImplTraitsType::IMPLElementType IMPLElementType;
332 typedef typename ImplTraitsType::GEOElementType GEOElementType;
333 typedef typename ImplTraitsType::GEOFaceType GEOFaceType;
334 typedef typename ImplTraitsType::GEOEdgeType GEOEdgeType;
336 typedef typename ImplTraitsType::GitterImplType GitterImplType;
338 typedef typename ImplTraitsType::HElementType HElementType;
339 typedef typename ImplTraitsType::HFaceType HFaceType;
340 typedef typename ImplTraitsType::HEdgeType HEdgeType;
341 typedef typename ImplTraitsType::VertexType VertexType;
342 typedef typename ImplTraitsType::HBndSegType HBndSegType;
344 typedef EntityCount< elType > EntityCountType;
346 using ALU3DSPACE AdaptRestrictProlongType::postRefinement;
347 using ALU3DSPACE AdaptRestrictProlongType::preCoarsening;
356 enum { numCodim = 4 };
358 typedef typename GridType::Traits::template Codim<0>::Entity EntityCodim0Type;
361 mutable std::map< int , IdType > ids_[ numCodim ];
364 const GridType & grid_;
367 const HierarchicIndexSetType & hset_;
371 enum { startOffSet_ = 0 };
377 using IdSet < GridType , ALU3dGridGlobalIdSet, IdType >
:: subId;
381 : grid_(grid), hset_(grid.hierarchicIndexSet())
387 const int vxKey[4] = {0,1,3,4};
388 for(
int i=0; i<4; i++) vertexKey_[i] = vxKey[i];
395 const int vxKey[4] = {0,1,2,3};
396 for(
int i=0; i<4; i++) vertexKey_[i] = vxKey[i];
415 for(
int i=0 ;i<numCodim; ++i)
417 std::cout <<
"*****************************************************\n";
418 std::cout <<
"Ids for codim " << i <<
"\n";
419 std::cout <<
"*****************************************************\n";
420 for(
unsigned int k=0; k<ids_[i].size(); ++k)
422 std::cout <<
"Item[" << i <<
"," << k <<
"] has id " << ids_[i][k] <<
"\n";
424 std::cout <<
"\n\n\n";
428 template <
class IterType>
433 for(
int i=0 ;i<numCodim; ++i)
435 typedef typename std::map<int,IdType>::iterator IteratorType;
436 IteratorType end = ids_[i].end();
437 for(IteratorType it = ids_[i].begin(); it != end; ++it)
439 if(idIter == it)
continue;
440 const IdType & checkMId = (*it).second;
445 std::cout <<
id <<
" equals " <<
checkId <<
"\n";
447 DUNE_THROW(GridError,
" " <<
id <<
" equals " <<
checkId <<
"\n");
454 if( lesser == greater )
457 DUNE_THROW(GridError,
" lesser equals greater of one id ");
467 for(
int i=0 ;i<numCodim; i++)
469 typedef typename std::map<int,IdType>::iterator IteratorType;
470 IteratorType end = ids_[i].end();
471 for(IteratorType it = ids_[i].begin(); it != end; ++it)
473 const IdType &
id = (*it).second;
487 for(
int i=0; i<numCodim; ++i)
492 GitterImplType &gitter = grid_.myGrid();
496 typename ALU3DSPACE AccessIterator< VertexType >::Handle fw( gitter.container() );
497 for( fw.first (); !fw.done(); fw.next() )
499 int idx = fw.item().getIndex();
506 typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 3, Ghost_Partition, Comm > IteratorType;
507 IteratorType fw (grid_ , 0 , grid_.nlinks() );
508 typedef typename IteratorType :: val_t val_t;
509 for (fw.first () ; ! fw.done () ; fw.next ())
511 val_t & item = fw.item();
513 VertexType & vx = * (item.first);
514 int idx = vx.getIndex();
522 typename ALU3DSPACE AccessIterator< HEdgeType >::Handle w( gitter.container() );
523 for (w.first(); !w.done(); w.next())
525 int idx = w.item().getIndex();
533 typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 2, Ghost_Partition, Comm > IteratorType;
534 IteratorType fw( grid_, 0, grid_.nlinks() );
535 typedef typename IteratorType :: val_t val_t;
536 for (fw.first () ; ! fw.done () ; fw.next ())
538 val_t & item = fw.item();
540 HEdgeType & edge = * (item.first);
541 int idx = edge.getIndex();
552 typename ALU3DSPACE AccessIterator< HFaceType >::Handle w( gitter.container() );
553 for (w.first () ; ! w.done () ; w.next ())
555 int idx = w.item().getIndex();
563 typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 1, Ghost_Partition, Comm > IteratorType;
564 IteratorType fw (grid_ , 0 , grid_.nlinks() );
565 typedef typename IteratorType :: val_t val_t;
566 for (fw.first () ; ! fw.done () ; fw.next ())
568 val_t & item = fw.item();
570 HFaceType & face = * (item.first);
571 int idx = face.getIndex();
579 typename ALU3DSPACE AccessIterator< HElementType >::Handle w( gitter.container() );
580 for (w.first () ; ! w.done () ; w.next ())
582 int idx = w.item().getIndex();
590 typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 0, Ghost_Partition, Comm > IteratorType;
591 IteratorType fw (grid_ , 0 , grid_.nlinks() );
592 typedef typename IteratorType :: val_t val_t;
593 for (fw.first () ; ! fw.done () ; fw.next ())
595 val_t & item = fw.item();
597 HElementType & elem = * ( item.second->getGhost().first );
598 int idx = elem.getIndex();
614 int vx[4] = { item.ident(), -1, -1, -1};
623 const GEOEdgeType & edge = static_cast<const GEOEdgeType &> (item);
624 int vx[4] = {-1,-1,-1,-1};
625 for(
int i=0; i<2; ++i)
627 vx[i] = edge.myvertex(i)->ident();
638 const GEOFaceType & face = static_cast<const GEOFaceType &> (item);
639 int vx[4] = {-1,-1,-1,-1};
640 for(
int i=0; i<3; ++i)
642 vx[i] = face.myvertex(i)->ident();
653 const GEOElementType & elem = static_cast<const GEOElementType &> (item);
654 int vx[4] = {-1,-1,-1,-1};
655 for(
int i=0; i<4; ++i)
657 vx[i] = elem.myvertex(vertexKey_[i])->ident();
664 template <
int cd,
class Item>
670 enum { childOffSet = (dim == 2) ? 4 : ((cd == 1) && (elType ==
hexa)) ? 16 : 8 };
671 enum { codimOffSet = 4 };
675 int newChild = (creatorId.nChild() * childOffSet ) + nChild;
676 int level = ((creatorId.codim()-startOffSet_)/codimOffSet) +1;
677 int newCodim = (codimOffSet * level + cd +startOffSet_);
679 IdType newId( creatorId.getKey() , newChild , newCodim );
688 ids_[codim][item.getIndex()] = createId<codim>(item,macroId,nChild);
690 const IdType & itemId = ids_[codim][item.getIndex()];
702 const VertexType * v = item.innerVertex() ;
709 int inneredge = startOffSet_;
710 for(
const HEdgeType * e = item.innerHedge () ; e ; e = e->next ())
719 int innerface = startOffSet_;
720 for(
const HFaceType * f = item.innerHface () ; f ; f = f->next ())
729 int numChild = startOffSet_;
730 for(
const HElementType * child = item.down(); child; child =child->next() )
743 ids_[codim][face.getIndex()] = createId<codim>(face,fatherId,innerFace);
744 const IdType & faceId = ids_[codim][face.getIndex()];
756 const VertexType * v = face.innerVertex() ;
763 int inneredge = startOffSet_;
764 for (
const HEdgeType * e = face.innerHedge () ; e ; e = e->next ())
773 int child = startOffSet_;
774 for(
const HFaceType * f = face.down () ; f ; f = f->next ())
787 ids_[codim][edge.getIndex()] = createId<codim>(edge,fatherId,inneredge);
788 const IdType & edgeId = ids_[codim][edge.getIndex()];
798 const VertexType * v = edge.innerVertex() ;
804 int child = startOffSet_;
805 for (
const HEdgeType * e = edge.down () ; e ; e = e->next ())
819 ids_[codim][vertex.getIndex()] = createId<codim>(vertex,fatherId,1);
832 template <
class EntityType>
835 enum { codim = ( dim == EntityType :: codimension ) ? 3 : EntityType :: codimension };
836 alugrid_assert ( ids_[codim].find( hset_.index(ep) ) != ids_[codim].end() );
837 const IdType & macroId = ids_[codim][hset_.index(ep)];
839 return getId(macroId);
844 IdType id (
const typename GridType:: template Codim<cd> :: Entity & ep)
const
846 const unsigned int codim = ( dim == cd ) ? 3 : cd ;
847 alugrid_assert ( ids_[codim].find( hset_.index(ep) ) != ids_[codim].end() );
848 const IdType & macroId = ids_[codim][hset_.index(ep)];
850 return getId(macroId);
854 IdType subId (
const EntityCodim0Type &e,
int i,
unsigned int codim )
const
856 const int hIndex = hset_.subIndex( e, i, codim );
858 const unsigned int idCodim = ( dim == codim ) ? 3 : codim ;
859 alugrid_assert ( ids_[ idCodim ].find( hIndex ) != ids_[ idCodim ].end() );
860 const IdType ¯oId = ids_[ idCodim ][ hIndex ];
862 return getId( macroId );
869 enum { elCodim = 0 };
870 const IdType & fatherId = ids_[elCodim][item.getIndex()];
875 const IMPLElementType & elem = static_cast<const IMPLElementType &> (item);
876 for(
int i=0; i<EntityCountType::numFaces; ++i)
878 enum { faceCodim = 1 };
879 const HFaceType & face = *( elem.myhface( i ) );
880 const IdType &
id = ids_[faceCodim][face.getIndex()];
886 for(
int i=0; i<EntityCountType::numEdges; ++i)
888 enum { edgeCodim = 2 };
889 const HEdgeType & edge = *( elem.myhedge(i));
890 const IdType &
id = ids_[edgeCodim][edge.getIndex()];
940 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
941 class ALU3dGridLocalIdSet
942 :
public IdSet< ALU3dGrid< dim, dimworld, elType, Comm >, ALU3dGridLocalIdSet< dim, dimworld, elType, Comm >, int >,
945 typedef ALU3dGridLocalIdSet< dim, dimworld, elType, Comm > This;
947 typedef ALU3dImplTraits< elType, Comm > ImplTraitsType;
948 typedef typename ImplTraitsType::HElementType HElementType;
949 typedef typename ImplTraitsType::HBndSegType HBndSegType;
955 enum { codimMultiplier = 300000000 };
956 typedef typename GridType::Traits::template Codim<0>::Entity EntityCodim0Type;
959 ALU3dGridLocalIdSet(
const GridType & grid) : hset_(grid.hierarchicIndexSet())
962 codimStart_[ codim ] = codim * codimMultiplier;
968 void updateIdSet() {}
970 using ALU3DSPACE AdaptRestrictProlongType :: postRefinement ;
971 using ALU3DSPACE AdaptRestrictProlongType :: preCoarsening ;
979 using IdSet < GridType , ALU3dGridLocalIdSet, IdType >
:: subId;
982 template <
class EntityType>
983 int id (
const EntityType & ep)
const
985 enum { cd = EntityType :: codimension };
987 return codimStart_[cd] + hset_.
index(ep);
992 int id (
const typename GridType:: template Codim<codim> :: Entity & ep)
const
996 return codimStart_[codim] + hset_.
index(ep);
1000 IdType subId (
const EntityCodim0Type &e,
int i,
unsigned int codim )
const
1003 return codimStart_[ codim ] + hset_.
subIndex( e, i, codim );
1021 const HierarchicIndexSetType & hset_;
1029 #endif // #ifndef DUNE_ALU3DGRIDINDEXSETS_HH