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 >
37 :
public IndexSet< ALU3dGrid< dim, dimworld, elType, Comm >, ALU3dGridHierarchicIndexSet< dim, dimworld, elType, Comm > >
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 <<
"]";
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);
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_ <<
")";
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());
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 >
323 :
public IdSet< ALU3dGrid< dim, dimworld, elType, Comm >, ALU3dGridGlobalIdSet< dim, dimworld, elType, Comm >,
324 typename ALU3dGrid< dim, dimworld, elType, Comm >::Traits::GlobalIdType >,
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;
346 using ALU3DSPACE AdaptRestrictProlongType::postRefinement;
347 using ALU3DSPACE AdaptRestrictProlongType::preCoarsening;
350 typedef typename GridType::Traits::GlobalIdType
IdType;
355 typedef ALUGridId < MacroKeyType > MacroIdType;
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 };
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};
617 MacroIdType
id(key,1, codim + startOffSet_ );
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();
632 MacroIdType
id( key,1, codim + startOffSet_ );
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();
647 MacroIdType
id(key,1, codim + startOffSet_ );
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();
661 return MacroIdType(key,1, codim + startOffSet_ );
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);
823 friend class ALU3dGrid< dim, dimworld, elType, Comm >;
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 >
942 :
public IdSet< ALU3dGrid< dim, dimworld, elType, Comm >, ALU3dGridLocalIdSet< dim, dimworld, elType, Comm >, int >,
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;
962 codimStart_[ codim ] = codim * codimMultiplier;
965 friend class ALU3dGrid< dim, dimworld, elType, Comm >;
968 void updateIdSet() {}
970 using ALU3DSPACE AdaptRestrictProlongType :: postRefinement ;
971 using ALU3DSPACE AdaptRestrictProlongType :: preCoarsening ;
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_;
#define alugrid_assert(EX)
Definition alugrid_assert.hh:20
#define ALU3DSPACE
Definition alu3dinclude.hh:24
Definition alu3dinclude.hh:80
@ hexa
Definition topology.hh:12
@ tetra
Definition topology.hh:12
std::ostream & operator<<(std ::ostream &out, const ALU3dGridEntitySeed< cd, GridImp > &key)
print alugrid entity key to std::stream
Definition entityseed.hh:372
Definition alu3dinclude.hh:259
[ provides Dune::Grid ]
Definition 3d/grid.hh:468
int hierSetSize(int cd) const
Definition grid_inline.hh:100
const std::vector< GeometryType > & geomTypes(int codim) const
deliver all geometry types used in this grid
Definition 3d/grid.hh:1134
static const int dimension
Definition 3d/grid.hh:529
Definition indexsets.hh:326
void setChunkSize(int chunkSize)
Definition indexsets.hh:480
void buildVertexIds(const VertexType &vertex, const IdType &fatherId)
Definition indexsets.hh:815
virtual ~ALU3dGridGlobalIdSet()
Definition indexsets.hh:403
int preCoarsening(HElementType &elem)
Definition indexsets.hh:899
IdType buildMacroElementId(const HElementType &item)
Definition indexsets.hh:651
void checkId(const IdType ¯oId, const IterType &idIter) const
Definition indexsets.hh:429
IdType buildMacroVertexId(const VertexType &item)
Definition indexsets.hh:612
ALU3dGridGlobalIdSet(const GridType &grid)
create id set, only allowed for ALU3dGrid
Definition indexsets.hh:380
void buildEdgeIds(const HEdgeType &edge, const IdType &fatherId, int inneredge)
Definition indexsets.hh:784
void updateIdSet()
Definition indexsets.hh:406
GridType::Traits::GlobalIdType IdType
Definition indexsets.hh:350
void buildFaceIds(const HFaceType &face, const IdType &fatherId, int innerFace)
Definition indexsets.hh:740
int preCoarsening(HBndSegType &el)
Definition indexsets.hh:926
void buildIdSet()
Definition indexsets.hh:485
void buildInteriorElementIds(const HElementType &item, const IdType &fatherId)
Definition indexsets.hh:696
IdType buildMacroEdgeId(const HEdgeType &item)
Definition indexsets.hh:621
void buildInteriorFaceIds(const HFaceType &face, const IdType &faceId)
Definition indexsets.hh:750
void uniquenessCheck() const
Definition indexsets.hh:465
IdType id(const EntityType &ep) const
return global id of given entity
Definition indexsets.hh:833
int postRefinement(HElementType &item)
Definition indexsets.hh:866
int postRefinement(HBndSegType &el)
prolong data, elem is the father
Definition indexsets.hh:929
void buildElementIds(const HElementType &item, const IdType ¯oId, int nChild)
Definition indexsets.hh:685
const IdType & getId(const IdType ¯oId) const
Definition indexsets.hh:825
void buildInteriorEdgeIds(const HEdgeType &edge, const IdType &edgeId)
Definition indexsets.hh:792
IdType subId(const EntityCodim0Type &e, int i, unsigned int codim) const
return subId of given entity
Definition indexsets.hh:854
IdType createId(const Item &item, const IdType &creatorId, int nChild)
Definition indexsets.hh:665
IdType buildMacroFaceId(const HFaceType &item)
Definition indexsets.hh:636
IdType id(const typename GridType::template Codim< cd > ::Entity &ep) const
return global id of given entity
Definition indexsets.hh:844
void print() const
Definition indexsets.hh:413
hierarchic index set of ALU3dGrid
Definition indexsets.hh:944
int id(const typename GridType::template Codim< codim > ::Entity &ep) const
return global id of given entity
Definition indexsets.hh:992
int postRefinement(HBndSegType &el)
prolong data, elem is the father
Definition indexsets.hh:1015
void setChunkSize(int chunkSize)
Definition indexsets.hh:1017
int id(const EntityType &ep) const
return global id of given entity
Definition indexsets.hh:983
int preCoarsening(HElementType &elem)
Definition indexsets.hh:1007
int preCoarsening(HBndSegType &el)
Definition indexsets.hh:1012
int IdType
export type of id
Definition indexsets.hh:975
int postRefinement(HElementType &item)
Definition indexsets.hh:1009
IdType subId(const EntityCodim0Type &e, int i, unsigned int codim) const
return subId of given entity
Definition indexsets.hh:1000
hierarchic index set of ALU3dGrid
Definition indexsets.hh:38
int size(GeometryType type) const
Definition indexsets.hh:77
int size(int codim) const
return size of indexset, i.e. maxindex+1
Definition indexsets.hh:86
const std::vector< GeometryType > & geomTypes(int codim) const
deliver all geometry types used in this grid
Definition indexsets.hh:93
bool contains(const EntityType &) const
return true because all entities are contained in this set
Definition indexsets.hh:100
int index(const EntityType &ep) const
return hierarchic index of given entity
Definition indexsets.hh:55
int index(const typename GridType::Traits::template Codim< codim >::Entity &entity) const
return hierarchic index of given entity
Definition indexsets.hh:63
GridType::Traits::template Codim< 0 >::Entity EntityCodim0Type
Definition indexsets.hh:51
int subIndex(const EntityCodim0Type &e, int i, unsigned int codim) const
return subIndex i of given entity for subEntity with codim
Definition indexsets.hh:69
Definition indexsets.hh:113
void extractKey(std::vector< int > &key) const
Definition indexsets.hh:143
bool operator==(const ALUMacroKey &org) const
Definition indexsets.hh:128
void print(std::ostream &out) const
Definition indexsets.hh:152
ALUMacroKey(const A &a, const A &b, const A &c, const A &d)
Definition indexsets.hh:120
ALUMacroKey & operator=(const ALUMacroKey &org)
Definition indexsets.hh:122
ALUMacroKey(const ALUMacroKey &org)
Definition indexsets.hh:121
bool operator>(const ALUMacroKey &org) const
Definition indexsets.hh:137
ALUMacroKey()
Definition indexsets.hh:119
Definition indexsets.hh:173
bool operator!=(const ALUGridId &org) const
Definition indexsets.hh:208
bool isValid() const
Definition indexsets.hh:239
bool operator>=(const ALUGridId &org) const
Definition indexsets.hh:219
int codim() const
Definition indexsets.hh:237
void print(std::ostream &out) const
Definition indexsets.hh:250
const MacroKeyImp & getKey() const
Definition indexsets.hh:235
bool operator<=(const ALUGridId &org) const
Definition indexsets.hh:213
bool operator<(const ALUGridId &org) const
Definition indexsets.hh:225
ALUGridId & operator=(const ALUGridId &org)
Definition indexsets.hh:195
void reset()
Definition indexsets.hh:244
ALUGridId(const MacroKeyImp &key, int nChild, int cd)
Definition indexsets.hh:184
bool equals(const ALUGridId &org) const
Definition indexsets.hh:287
ALUGridId(const ALUGridId &org)
Definition indexsets.hh:189
bool lesser(const ALUGridId &org) const
Definition indexsets.hh:269
bool operator==(const ALUGridId &org) const
Definition indexsets.hh:203
bool operator>(const ALUGridId &org) const
Definition indexsets.hh:230
int nChild() const
Definition indexsets.hh:236
ALUGridId()
Definition indexsets.hh:179
Definition topology.hh:15