1 #ifndef DUNE_ALU3DGRIDINDEXSETS_HH
2 #define DUNE_ALU3DGRIDINDEXSETS_HH
8 #include <dune/common/stdstreams.hh>
9 #include <dune/common/bigunsignedint.hh>
26 template< ALU3dGr
idElementType,
class >
29 template<
int cd,
int dim,
class Gr
idImp>
30 class ALU3dGridEntity;
38 template< ALU3dGr
idElementType elType,
class Comm >
40 :
public IndexSet< ALU3dGrid< elType, Comm >, ALU3dGridHierarchicIndexSet< elType, Comm > >
58 template <
class EntityType>
59 int index (
const EntityType & ep)
const
61 enum { cd = EntityType :: codimension };
67 int index (
const typename GridType::Traits::template Codim< codim >::Entity &entity )
const
83 if( elType ==
tetra && !type.isSimplex() )
return 0;
84 if( elType ==
hexa && !type.isCube() )
return 0;
90 int size (
int codim )
const
97 const std::vector<GeometryType>&
geomTypes (
int codim)
const
103 template <
class EntityType>
104 bool contains (
const EntityType &)
const {
return true; }
108 const GridType & grid_;
124 ALUMacroKey(
const A&a,
const A&b,
const A&c,
const A&d) : BaseType(a,b,c,d) {}
134 return ( (this->_a == org._a) &&
135 (this->_b == org._b) &&
136 (this->_c == org._c) &&
137 (this->_d == org._d) );
143 return ( (!this->
operator == (org)) && (!this->
operator <(org)) );
146 void print(std::ostream & out)
const
148 out <<
"[" << this->_a <<
"," << this->_b <<
"," << this->_c <<
"," << this->_d <<
"]";
152 template <
class MacroKeyImp>
165 : key_(key) , nChild_(nChild)
171 , nChild_(org.nChild_)
178 nChild_ = org.nChild_;
195 if(
equals(org))
return true;
201 if(
equals(org))
return true;
202 else return !
lesser(org);
215 const MacroKeyImp &
getKey()
const {
return key_; }
217 int codim()
const {
return codim_; }
221 return ( (nChild_ >= 0) && (codim_ >= 0) );
230 void print(std::ostream & out)
const
232 out <<
"(" <<
getKey() <<
"," << nChild_ <<
"," << codim_ <<
")";
243 if(nChild_ == org.nChild_)
245 return codim_ < org.codim_;
248 return nChild_ < org.nChild_;
257 return ( (
getKey() == org.
getKey() ) && (nChild_ == org.nChild_)
258 && (codim_ == org.codim_) );
268 template <
class KeyImp>
269 inline std::ostream& operator<< (std::ostream& s, const ALUGridId<KeyImp> & id)
281 template< ALU3dGr
idElementType elType,
class Comm >
283 :
public IdSet< ALU3dGrid< elType, Comm >, ALU3dGridGlobalIdSet< elType, Comm > ,
284 typename ALU3dGrid< elType, Comm >::Traits::GlobalIdType >,
290 typedef ALU3dImplTraits< elType, Comm > ImplTraitsType;
291 typedef typename ImplTraitsType::IMPLElementType IMPLElementType;
292 typedef typename ImplTraitsType::GEOElementType GEOElementType;
293 typedef typename ImplTraitsType::GEOFaceType GEOFaceType;
294 typedef typename ImplTraitsType::GEOEdgeType GEOEdgeType;
296 typedef typename ImplTraitsType::GitterImplType GitterImplType;
298 typedef typename ImplTraitsType::HElementType HElementType;
299 typedef typename ImplTraitsType::HFaceType HFaceType;
300 typedef typename ImplTraitsType::HEdgeType HEdgeType;
301 typedef typename ImplTraitsType::VertexType VertexType;
302 typedef typename ImplTraitsType::HBndSegType HBndSegType;
317 typedef typename GridType::Traits::template Codim<0>::Entity EntityCodim0Type;
319 mutable std::map< int , IdType > ids_[numCodim];
323 const GridType & grid_;
326 const HierarchicIndexSetType & hset_;
332 enum { startOffSet_ = 0 };
338 using IdSet < GridType , ALU3dGridGlobalIdSet, IdType >
:: subId;
342 : grid_(grid), hset_(grid.hierarchicIndexSet())
349 const int vxKey[4] = {0,1,3,4};
350 for(
int i=0; i<4; i++) vertexKey_[i] = vxKey[i];
354 assert( elType ==
tetra );
357 const int vxKey[4] = {0,1,2,3};
358 for(
int i=0; i<4; i++) vertexKey_[i] = vxKey[i];
377 for(
int i=0 ;i<numCodim; ++i)
379 std::cout <<
"*****************************************************\n";
380 std::cout <<
"Ids for codim " << i <<
"\n";
381 std::cout <<
"*****************************************************\n";
382 for(
unsigned int k=0; k<ids_[i].size(); ++k)
384 std::cout <<
"Item[" << i <<
"," << k <<
"] has id " << ids_[i][k] <<
"\n";
386 std::cout <<
"\n\n\n";
390 template <
class IterType>
395 for(
int i=0 ;i<numCodim; ++i)
397 typedef typename std::map<int,IdType>::iterator IteratorType;
398 IteratorType end = ids_[i].end();
399 for(IteratorType it = ids_[i].begin(); it != end; ++it)
402 if(idIter == it)
continue;
404 const IdType & checkMId = (*it).second;
409 std::cout <<
id <<
" equals " << checkId <<
"\n";
410 assert(
id != checkId );
411 DUNE_THROW(
GridError,
" " <<
id <<
" equals " << checkId <<
"\n");
417 assert( lesser != greater );
418 if( lesser == greater )
420 assert( lesser != greater );
421 DUNE_THROW(
GridError,
" lesser equals greater of one id ");
431 for(
int i=0 ;i<numCodim; i++)
433 typedef typename std::map<int,IdType>::iterator IteratorType;
434 IteratorType end = ids_[i].end();
435 for(IteratorType it = ids_[i].begin(); it != end; ++it)
438 const IdType &
id = (*it).second;
447 chunkSize_ = chunkSize;
453 for(
int i=0; i<numCodim; ++i)
458 GitterImplType &gitter = grid_.
myGrid();
462 typename ALU3DSPACE AccessIterator< VertexType >::Handle fw( gitter.container() );
463 for( fw.first (); !fw.done(); fw.next() )
465 int idx = fw.item().getIndex();
472 typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 3, Ghost_Partition, Comm > IteratorType;
473 IteratorType fw (grid_ , 0 , grid_.
nlinks() );
474 typedef typename IteratorType :: val_t val_t;
475 for (fw.first () ; ! fw.done () ; fw.next ())
477 val_t & item = fw.item();
478 assert( item.first );
479 VertexType & vx = * (item.first);
480 int idx = vx.getIndex();
487 typename ALU3DSPACE AccessIterator< HEdgeType >::Handle w( gitter.container() );
488 for (w.first(); !w.done(); w.next())
490 int idx = w.item().getIndex();
498 typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 2, Ghost_Partition, Comm > IteratorType;
499 IteratorType fw( grid_, 0, grid_.
nlinks() );
500 typedef typename IteratorType :: val_t val_t;
501 for (fw.first () ; ! fw.done () ; fw.next ())
503 val_t & item = fw.item();
504 assert( item.first );
505 HEdgeType & edge = * (item.first);
506 int idx = edge.getIndex();
516 typename ALU3DSPACE AccessIterator< HFaceType >::Handle w( gitter.container() );
517 for (w.first () ; ! w.done () ; w.next ())
519 int idx = w.item().getIndex();
527 typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 1, Ghost_Partition, Comm > IteratorType;
528 IteratorType fw (grid_ , 0 , grid_.
nlinks() );
529 typedef typename IteratorType :: val_t val_t;
530 for (fw.first () ; ! fw.done () ; fw.next ())
532 val_t & item = fw.item();
533 assert( item.first );
534 HFaceType & face = * (item.first);
535 int idx = face.getIndex();
543 typename ALU3DSPACE AccessIterator< HElementType >::Handle w( gitter.container() );
544 for (w.first () ; ! w.done () ; w.next ())
546 int idx = w.item().getIndex();
554 typedef typename ALU3DSPACE ALU3dGridLevelIteratorWrapper< 0, Ghost_Partition, Comm > IteratorType;
555 IteratorType fw (grid_ , 0 , grid_.
nlinks() );
556 typedef typename IteratorType :: val_t val_t;
557 for (fw.first () ; ! fw.done () ; fw.next ())
559 val_t & item = fw.item();
560 assert( item.second );
561 HElementType & elem = * ( item.second->getGhost().first );
562 int idx = elem.getIndex();
572 #if ! ALU3DGRID_PARALLEL
580 int vx[4] = { item.ident(), -1, -1, -1};
589 const GEOEdgeType & edge =
static_cast<const GEOEdgeType &
> (item);
590 int vx[4] = {-1,-1,-1,-1};
591 for(
int i=0; i<2; ++i)
593 vx[i] = edge.myvertex(i)->ident();
604 const GEOFaceType & face =
static_cast<const GEOFaceType &
> (item);
605 int vx[4] = {-1,-1,-1,-1};
606 for(
int i=0; i<3; ++i)
608 vx[i] = face.myvertex(i)->ident();
619 const GEOElementType & elem =
static_cast<const GEOElementType &
> (item);
620 int vx[4] = {-1,-1,-1,-1};
621 for(
int i=0; i<4; ++i)
623 vx[i] = elem.myvertex(vertexKey_[i])->ident();
634 assert( creatorId.isValid() );
637 enum { childOffSet = ((cd == 1) && (elType ==
hexa)) ? 16 : 8 };
638 enum { codimOffSet = 4 };
640 assert( nChild < childOffSet );
642 int newChild = (creatorId.nChild() * childOffSet ) + nChild;
643 int newCodim = (creatorId.codim() * codimOffSet ) + ( cd + startOffSet_ );
645 IdType newId( creatorId.getKey() , newChild , newCodim );
646 assert( newId != creatorId );
654 ids_[codim][item.getIndex()] = createId<codim>(item,macroId,nChild);
656 const IdType & itemId = ids_[codim][item.getIndex()];
664 assert( fatherId.isValid() );
668 const VertexType * v = item.innerVertex() ;
675 int inneredge = startOffSet_;
676 for(
const HEdgeType * e = item.innerHedge () ; e ; e = e->next ())
685 int innerface = startOffSet_;
686 for(
const HFaceType * f = item.innerHface () ; f ; f = f->next ())
695 int numChild = startOffSet_;
696 for(
const HElementType * child = item.down(); child; child =child->next() )
709 ids_[codim][face.getIndex()] = createId<codim>(face,fatherId,innerFace);
710 const IdType & faceId = ids_[codim][face.getIndex()];
718 assert( faceId.isValid () );
722 const VertexType * v = face.innerVertex() ;
729 int inneredge = startOffSet_;
730 for (
const HEdgeType * e = face.innerHedge () ; e ; e = e->next ())
739 int child = startOffSet_;
740 for(
const HFaceType * f = face.down () ; f ; f = f->next ())
742 assert( child == f->nChild()+startOffSet_);
753 ids_[codim][edge.getIndex()] = createId<codim>(edge,fatherId,inneredge);
754 const IdType & edgeId = ids_[codim][edge.getIndex()];
760 assert( edgeId.isValid() );
764 const VertexType * v = edge.innerVertex() ;
770 int child = startOffSet_;
771 for (
const HEdgeType * e = edge.down () ; e ; e = e->next ())
773 assert( child == e->nChild()+ startOffSet_ );
785 ids_[codim][vertex.getIndex()] = createId<codim>(
vertex,fatherId,1);
786 assert( ids_[codim][vertex.getIndex()].isValid() );
798 template <
class EntityType>
801 enum { cd = EntityType :: codimension };
802 assert( ids_[cd].find( hset_.
index(ep) ) != ids_[cd].end() );
803 const IdType & macroId = ids_[cd][hset_.
index(ep)];
804 assert( macroId.isValid() );
805 return getId(macroId);
810 IdType id (
const typename GridType:: template Codim<codim> :: Entity & ep)
const
812 assert( ids_[codim].find( hset_.
index(ep) ) != ids_[codim].end() );
813 const IdType & macroId = ids_[codim][hset_.
index(ep)];
814 assert( macroId.isValid() );
815 return getId(macroId);
819 IdType subId (
const EntityCodim0Type &e,
int i,
unsigned int codim )
const
821 const int hIndex = hset_.
subIndex( e, i, codim );
822 assert( ids_[ codim ].find( hIndex ) != ids_[ codim ].end() );
823 const IdType ¯oId = ids_[ codim ][ hIndex ];
824 assert( macroId.isValid() );
825 return getId( macroId );
828 template <
int d, ALU3dGr
idElementType element_t >
835 template <
class MyIdSet,
class IdStorageType>
836 static void buildFace(MyIdSet &
set,
const HElementType & item,
int faceNum,
837 IdStorageType & ids )
839 const IMPLElementType & elem =
static_cast<const IMPLElementType &
> (item);
840 const HFaceType & face = *(elem.myhface3(faceNum));
841 const IdType &
id = ids[face.getIndex()];
842 assert(
id.isValid() );
843 set.buildInteriorFaceIds(face,
id);
851 template <
class MyIdSet,
class IdStorageType>
852 static void buildFace(MyIdSet &
set,
const HElementType & item,
int faceNum,
853 IdStorageType & ids )
855 const IMPLElementType & elem =
static_cast<const IMPLElementType &
> (item);
856 const HFaceType & face = *(elem.myhface4(faceNum));
857 const IdType &
id = ids[face.getIndex()];
858 assert(
id.isValid() );
859 set.buildInteriorFaceIds(face,
id);
867 enum { elCodim = 0 };
868 const IdType & fatherId = ids_[elCodim][item.getIndex()];
869 assert( fatherId.isValid() );
873 for(
int i=0; i<EntityCountType::numFaces; ++i)
875 enum { faceCodim = 1 };
876 BuildIds< GridType::dimension, elType >::buildFace(*
this,item,i,ids_[faceCodim]);
879 for(
int i=0; i<EntityCountType::numEdges; ++i)
881 enum { edgeCodim = 2 };
882 const IMPLElementType & elem =
static_cast<const IMPLElementType &
> (item);
883 const HEdgeType & edge = *( elem.myhedge1(i));
884 const IdType &
id = ids_[edgeCodim][edge.getIndex()];
885 assert(
id.isValid() );
933 template< ALU3dGr
idElementType elType,
class Comm >
935 :
public IdSet< ALU3dGrid< elType, Comm >, ALU3dGridLocalIdSet< elType, Comm >, int >,
940 typedef ALU3dImplTraits< elType, Comm > ImplTraitsType;
941 typedef typename ImplTraitsType::HElementType HElementType;
942 typedef typename ImplTraitsType::HBndSegType HBndSegType;
948 enum { codimMultiplier = 300000000 };
949 typedef typename GridType::Traits::template Codim<0>::Entity EntityCodim0Type;
955 codimStart_[ codim ] = codim * codimMultiplier;
972 template <
class EntityType>
973 int id (
const EntityType & ep)
const
975 enum { cd = EntityType :: codimension };
976 assert( hset_.size(cd) < codimMultiplier );
977 return codimStart_[cd] + hset_.index(ep);
982 int id (
const typename GridType:: template Codim<codim> :: Entity & ep)
const
985 assert( hset_.size(codim) < codimMultiplier );
986 return codimStart_[codim] + hset_.index(ep);
990 IdType subId (
const EntityCodim0Type &e,
int i,
unsigned int codim )
const
992 assert( hset_.size( codim ) < codimMultiplier );
993 return codimStart_[ codim ] + hset_.subIndex( e, i, codim );
1011 const HierarchicIndexSetType & hset_;
1019 #endif // #ifndef DUNE_ALU3DGRIDINDEXSETS_HH