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>
24 template<
int dim,
int dimworld, ALU3dGr
idElementType,
class >
27 template<
int cd,
int dim,
class Gr
idImp>
28 class ALU3dGridEntity;
36 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
38 :
public IndexSet< ALU3dGrid< dim, dimworld, elType, Comm >, ALU3dGridHierarchicIndexSet< dim, dimworld, elType, Comm > >
44 friend class ALU3dGrid<dim, dimworld, elType, Comm >;
55 template <
class EntityType>
56 int index (
const EntityType & ep)
const
58 enum { cd = EntityType :: codimension };
64 int index (
const typename GridType::Traits::template Codim< codim >::Entity &entity )
const
66 return entity.impl().getIndex();
69 template<
class Entity >
70 int subIndex (
const Entity &entity,
int i,
unsigned int codim )
const
72 return subIndex< Entity::codimension >( entity, i, codim );
77 int subIndex (
const typename GridType::Traits::template Codim< cd >::Entity &e,
int i,
unsigned int codim )
const
80 return e.impl().subIndex( i, codim );
85 int size ( GeometryType type )
const
87 if( elType ==
tetra && !type.isSimplex() )
return 0;
88 if( elType ==
hexa && !type.isCube() )
return 0;
94 int size (
int codim )
const
101 const std::vector<GeometryType>&
geomTypes (
int codim)
const
107 template <
class EntityType>
108 bool contains (
const EntityType &)
const {
return true; }
112 const GridType & grid_;
128 ALUMacroKey(
const A&a,
const A&b,
const A&c,
const A&d) : BaseType(a,b,c,d) {}
132 BaseType::operator = (org);
138 return ( (this->_a == org._a) &&
139 (this->_b == org._b) &&
140 (this->_c == org._c) &&
141 (this->_d == org._d) );
147 return ( (!this->
operator == (org)) && (!this->
operator <(org)) );
160 void print(std::ostream & out)
const
162 out <<
"[" << this->_a <<
"," << this->_b <<
"," << this->_c <<
"," << this->_d <<
"]";
167 std::size_t seed = 0;
168 hash_combine(seed,arg._a);
169 hash_combine(seed,arg._b);
170 hash_combine(seed,arg._c);
171 hash_combine(seed,arg._d);
184 template <
class MacroKeyImp,
class IntegerImp =
int>
205 : key_(key) , nChild_(
nChild)
212 , nChild_(org.nChild_)
220 nChild_ = org.nChild_;
238 if(
equals(org))
return true;
244 if(
equals(org))
return true;
245 else return !
lesser(org);
258 const MacroKeyImp &
getKey()
const {
return key_; }
260 int codim()
const {
return int(codim_) ; }
261 int level()
const {
return int(level_) ; }
265 return ( (nChild_ >= 0) && (codim_ >= 0) && (level_ >= 0) );
275 void print(std::ostream & out)
const
277 out <<
"AluGridID: (" <<
getKey() <<
"," << nChild_ <<
"," << int(codim_) <<
"," << int(level_) <<
")";
282 std::size_t seed = hash<MacroKeyImp>()(arg.
getKey());
283 hash_combine(seed,arg.nChild_);
284 hash_combine(seed,arg.codim_);
285 hash_combine(seed,arg.level_);
297 if(nChild_ == org.nChild_)
299 if( codim_ == org.codim_)
300 return level_ < org.level_;
301 return codim_ < org.codim_;
304 return nChild_ < org.nChild_;
313 return ( (
getKey() == org.
getKey() ) && (nChild_ == org.nChild_)
314 && (codim_ == org.codim_) && (level_ == org.level_) );
325 inline std::ostream& operator<< (std::ostream& s,
const ALUMacroKey & key)
331 template <
class KeyImp>
332 inline std::ostream& operator<< (std::ostream& s,
const ALUGridId<KeyImp> &
id)
343 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
344 class ALU3dGridGlobalIdSet
345 :
public IdSet< ALU3dGrid< dim, dimworld, elType, Comm >, ALU3dGridGlobalIdSet< dim, dimworld, elType, Comm >,
346 ALUGridId< ALUMacroKey > >,
349 typedef ALU3dGrid< dim, dimworld, elType, Comm > GridType;
350 typedef typename GridType::HierarchicIndexSet HierarchicIndexSetType;
352 typedef ALU3dImplTraits< elType, Comm > ImplTraitsType;
353 typedef typename ImplTraitsType::IMPLElementType IMPLElementType;
354 typedef typename ImplTraitsType::GEOElementType GEOElementType;
355 typedef typename ImplTraitsType::GEOFaceType GEOFaceType;
356 typedef typename ImplTraitsType::GEOEdgeType GEOEdgeType;
358 typedef typename ImplTraitsType::GitterImplType GitterImplType;
360 typedef typename ImplTraitsType::HElementType HElementType;
361 typedef typename ImplTraitsType::HFaceType HFaceType;
362 typedef typename ImplTraitsType::HEdgeType HEdgeType;
363 typedef typename ImplTraitsType::VertexType VertexType;
364 typedef typename ImplTraitsType::HBndSegType HBndSegType;
366 typedef EntityCount< elType > EntityCountType;
368 using ALU3DSPACE AdaptRestrictProlongType::postRefinement;
369 using ALU3DSPACE AdaptRestrictProlongType::preCoarsening;
372 typedef ALUGridId< ALUMacroKey > IdType;
375 typedef ALUMacroKey MacroKeyType;
377 typedef ALUGridId < MacroKeyType > MacroIdType;
378 enum { numCodim = 4 };
380 typedef typename GridType::Traits::template Codim<0>::Entity EntityCodim0Type;
383 mutable std::map< int , IdType > ids_[ numCodim ];
386 const GridType & grid_;
389 const HierarchicIndexSetType & hset_;
393 enum { startOffSet_ = 0 };
395 typedef typename std::array<int,4> AT;
402 const std::array<std::array<int, 4>, 4> offset = (dim == 3) ?
404 std::array<AT,4>{{AT{{8,12,6,1}},AT{{-1,4,4,1}}, AT{{-1,-1,2,1}}, AT{{-1,-1,-1,1}}}}:
405 std::array<AT,4>{{AT{{8,8,1,0}}, AT{{-1,4,3,0}}, AT{{-1,-1,2,1}}, AT{{-1,-1,-1,1}}}}
408 std::array<AT,4>{{AT{{4,4,1,0}},AT{{-1,4,4,1}}, AT{{-1,-1,2,1}}, AT{{-1,-1,-1,1}}}}:
409 std::array<AT,4>{{AT{{4,3,0,0}}, AT{{-1,4,3,0}}, AT{{-1,-1,2,1}}, AT{{-1,-1,-1,1}}}}
414 const int nChildren = ( dim == 3) ? 8 : 5;
415 const std::array<int, 4> nEntitiesFactor = ( (elType == hexa) ? AT{{1, 3 , 3, 1}} : AT{{1, 2, 2, 1}} );
421 using IdSet < GridType , ALU3dGridGlobalIdSet, IdType > :: subId;
424 ALU3dGridGlobalIdSet(
const GridType & grid);
426 virtual ~ALU3dGridGlobalIdSet() {}
434 template <
class IterType>
435 void checkId(
const IdType & macroId,
const IterType & idIter)
const
438 IdType
id = getId(macroId);
439 for(
int i=0 ;i<numCodim; ++i)
441 typedef typename std::map<int,IdType>::iterator IteratorType;
442 IteratorType end = ids_[i].end();
443 for(IteratorType it = ids_[i].begin(); it != end; ++it)
445 if(idIter == it)
continue;
446 const IdType & checkMId = (*it).second;
447 IdType checkId = getId(checkMId);
451 std::cout <<
id <<
" equals " << checkId << std::endl;
452 std::cout << idIter->first <<
" != " << it->first << std::endl;
454 DUNE_THROW(GridError,
" " <<
id <<
" equals " << checkId <<
"\n");
458 bool lesser = (
id < checkId);
459 bool greater = (
id > checkId);
461 if( lesser == greater )
464 DUNE_THROW(GridError,
" lesser equals greater of one id ");
472 void uniquenessCheck()
const;
474 void setChunkSize(
int chunkSize ) {}
479 IdType buildMacroVertexId(
const VertexType & item );
481 IdType buildMacroEdgeId(
const HEdgeType & item );
483 IdType buildMacroFaceId(
const HFaceType & item );
485 IdType buildMacroElementId(
const HElementType & item );
491 template <
int cd,
class Item>
492 IdType createId(
const Item& item ,
const IdType& creatorId ,
int nChild )
497 const int level = creatorId.level();
498 const typename IdType::IntegerType nElements = std::pow(nChildren,level);
499 const int creatorNumber = creatorId.nChild();
500 const int creatorCodim = creatorId.codim();
501 const int childOffSet = offset[creatorCodim][cd];
504 alugrid_assert ( creatorNumber < nEntitiesFactor[creatorCodim] * nElements );
506 typename IdType::IntegerType newChild = creatorNumber * childOffSet + nChild;
507 for(
int i=cd ; i > creatorCodim ; i--)
509 newChild += nEntitiesFactor[i] * nElements * offset[i][cd];
512 IdType newId( creatorId.getKey() , newChild , cd, level + 1 );
519 void buildElementIds(
const HElementType & item ,
const IdType & macroId ,
int nChild);
522 void buildInteriorElementIds(
const HElementType & item ,
const IdType & fatherId);
525 void buildFaceIds(
const HFaceType & face,
const IdType & fatherId ,
int innerFace );
528 void buildInteriorFaceIds(
const HFaceType & face,
const IdType & faceId);
531 void buildEdgeIds(
const HEdgeType & edge,
const IdType & fatherId ,
int inneredge);
533 void buildInteriorEdgeIds(
const HEdgeType & edge,
const IdType & edgeId);
536 void buildVertexIds(
const VertexType & vertex,
const IdType & fatherId );
538 friend class ALU3dGrid< dim, dimworld, elType, Comm >;
540 const IdType & getId(
const IdType & macroId)
const
547 template <
class EntityType>
548 IdType id (
const EntityType & ep)
const
550 enum { codim = ( dim == EntityType :: codimension ) ? 3 : EntityType :: codimension };
551 alugrid_assert ( ids_[codim].find( hset_.index(ep) ) != ids_[codim].end() );
552 const IdType & macroId = ids_[codim][hset_.index(ep)];
554 return getId(macroId);
559 IdType id (
const typename GridType:: template Codim<cd> :: Entity & ep)
const
561 const unsigned int codim = ( dim == cd ) ? 3 : cd ;
562 alugrid_assert ( ids_[codim].find( hset_.index(ep) ) != ids_[codim].end() );
563 const IdType & macroId = ids_[codim][hset_.index(ep)];
565 return getId(macroId);
569 IdType subId (
const EntityCodim0Type &e,
int i,
unsigned int codim )
const
571 const int hIndex = hset_.subIndex( e, i, codim );
573 const unsigned int idCodim = ( dim == codim ) ? 3 : codim ;
574 alugrid_assert ( ids_[ idCodim ].find( hIndex ) != ids_[ idCodim ].end() );
575 const IdType ¯oId = ids_[ idCodim ][ hIndex ];
577 return getId( macroId );
581 int postRefinement( HElementType & item );
584 int preCoarsening( HElementType & elem );
587 int preCoarsening ( HBndSegType & el );
590 int postRefinement ( HBndSegType & el );
601 template<
int dim,
int dimworld, ALU3dGr
idElementType elType,
class Comm >
602 class ALU3dGridLocalIdSet
603 :
public IdSet< ALU3dGrid< dim, dimworld, elType, Comm >, ALU3dGridLocalIdSet< dim, dimworld, elType, Comm >, int >,
606 typedef ALU3dGridLocalIdSet< dim, dimworld, elType, Comm > This;
608 typedef ALU3dImplTraits< elType, Comm > ImplTraitsType;
609 typedef typename ImplTraitsType::HElementType HElementType;
610 typedef typename ImplTraitsType::HBndSegType HBndSegType;
612 typedef ALU3dGrid< dim, dimworld, elType, Comm > GridType;
613 typedef typename GridType::HierarchicIndexSet HierarchicIndexSetType;
616 enum { codimOffSet = 300000000 };
617 typedef typename GridType::Traits::template Codim<0>::Entity EntityCodim0Type;
620 ALU3dGridLocalIdSet(
const GridType & grid) : hset_(grid.hierarchicIndexSet())
622 for(
int codim = 0; codim <= GridType::dimension; ++codim )
623 codimStart_[ codim ] = codim * codimOffSet;
626 friend class ALU3dGrid< dim, dimworld, elType, Comm >;
629 void updateIdSet() {}
631 using ALU3DSPACE AdaptRestrictProlongType :: postRefinement ;
632 using ALU3DSPACE AdaptRestrictProlongType :: preCoarsening ;
640 using IdSet < GridType , ALU3dGridLocalIdSet, IdType > :: subId;
643 template <
class EntityType>
644 int id (
const EntityType & ep)
const
646 enum { cd = EntityType :: codimension };
648 return codimStart_[cd] + hset_.index(ep);
653 int id (
const typename GridType:: template Codim<codim> :: Entity & ep)
const
657 return codimStart_[codim] + hset_.index(ep);
661 IdType subId (
const EntityCodim0Type &e,
int i,
unsigned int codim )
const
664 return codimStart_[ codim ] + hset_.subIndex( e, i, codim );
668 int preCoarsening( HElementType & elem ) {
return 0; }
670 int postRefinement( HElementType & item ) {
return 0; }
673 int preCoarsening ( HBndSegType & el ) {
return 0; }
676 int postRefinement ( HBndSegType & el ) {
return 0; }
678 void setChunkSize(
int chunkSize ) {}
682 const HierarchicIndexSetType & hset_;
685 int codimStart_[ GridType::dimension+1 ];
690#if COMPILE_ALUGRID_INLINE
#define ALU3DSPACE
Definition: alu3dinclude.hh:7
DUNE_DEFINE_HASH(DUNE_HASH_TEMPLATE_ARGS(), DUNE_HASH_TYPE(Dune::ALUMacroKey)) DUNE_DEFINE_HASH(DUNE_HASH_TEMPLATE_ARGS(typename MacroKeyImp)
DUNE_HASH_TYPE(Dune::ALUGridId< MacroKeyImp >)) namespace Dune
Definition: indexsets.hh:321
#define alugrid_assert(EX)
Definition: alugrid_assert.hh:20
Definition: alu3dinclude.hh:63
@ hexa
Definition: topology.hh:12
@ tetra
Definition: topology.hh:12
[ provides Dune::Grid ]
Definition: 3d/grid.hh:429
int hierSetSize(int cd) const
Definition: grid_inline.hh:73
const std::vector< GeometryType > & geomTypes(int codim) const
deliver all geometry types used in this grid
Definition: 3d/grid.hh:1058
static const int dimension
Definition: 3d/grid.hh:490
hierarchic index set of ALU3dGrid
Definition: indexsets.hh:39
int size(GeometryType type) const
Definition: indexsets.hh:85
int size(int codim) const
return size of indexset, i.e. maxindex+1
Definition: indexsets.hh:94
const std::vector< GeometryType > & geomTypes(int codim) const
deliver all geometry types used in this grid
Definition: indexsets.hh:101
bool contains(const EntityType &) const
return true because all entities are contained in this set
Definition: indexsets.hh:108
int index(const EntityType &ep) const
return hierarchic index of given entity
Definition: indexsets.hh:56
int index(const typename GridType::Traits::template Codim< codim >::Entity &entity) const
return hierarchic index of given entity
Definition: indexsets.hh:64
GridType::Traits::template Codim< 0 >::Entity EntityCodim0Type
Definition: indexsets.hh:52
int subIndex(const Entity &entity, int i, unsigned int codim) const
Definition: indexsets.hh:70
int subIndex(const typename GridType::Traits::template Codim< cd >::Entity &e, int i, unsigned int codim) const
return subIndex i of given entity for subEntity with codim
Definition: indexsets.hh:77
Definition: indexsets.hh:121
void extractKey(std::vector< int > &key) const
Definition: indexsets.hh:151
bool operator==(const ALUMacroKey &org) const
Definition: indexsets.hh:136
void print(std::ostream &out) const
Definition: indexsets.hh:160
friend std::size_t hash_value(const ALUMacroKey &arg)
Definition: indexsets.hh:165
ALUMacroKey(const A &a, const A &b, const A &c, const A &d)
Definition: indexsets.hh:128
ALUMacroKey & operator=(const ALUMacroKey &org)
Definition: indexsets.hh:130
ALUMacroKey(const ALUMacroKey &org)
Definition: indexsets.hh:129
bool operator>(const ALUMacroKey &org) const
Definition: indexsets.hh:145
ALUMacroKey()
Definition: indexsets.hh:127
Definition: indexsets.hh:186
int codim() const
Definition: indexsets.hh:260
bool operator!=(const ALUGridId &org) const
Definition: indexsets.hh:231
IntegerType nChild() const
Definition: indexsets.hh:259
friend std::size_t hash_value(const ALUGridId &arg)
Definition: indexsets.hh:280
bool lesser(const ALUGridId &org) const
Definition: indexsets.hh:291
ALUGridId()
Definition: indexsets.hh:198
bool isValid() const
Definition: indexsets.hh:263
bool operator==(const ALUGridId &org) const
Definition: indexsets.hh:226
bool operator>=(const ALUGridId &org) const
Definition: indexsets.hh:242
bool operator<(const ALUGridId &org) const
Definition: indexsets.hh:248
void reset()
Definition: indexsets.hh:268
ALUGridId(const MacroKeyImp &key, const IntegerType nChild, const int codim, const int level)
Definition: indexsets.hh:204
IntegerImp IntegerType
Definition: indexsets.hh:188
bool operator>(const ALUGridId &org) const
Definition: indexsets.hh:253
void print(std::ostream &out) const
Definition: indexsets.hh:275
int level() const
Definition: indexsets.hh:261
bool equals(const ALUGridId &org) const
Definition: indexsets.hh:311
bool operator<=(const ALUGridId &org) const
Definition: indexsets.hh:236
ALUGridId & operator=(const ALUGridId &org)
Definition: indexsets.hh:217
ALUGridId(const ALUGridId &org)
Definition: indexsets.hh:210
const MacroKeyImp & getKey() const
Definition: indexsets.hh:258