1#ifndef DUNE_ALU3DGRIDINDEXSETS_HH
2#define DUNE_ALU3DGRIDINDEXSETS_HH
13#include "alu3dinclude.hh"
16#include "alu3diterators.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 >;
52 typedef typename GridType::Traits::template
Codim<0>::Entity EntityCodim0Type;
55 template <
class EntityType>
56 int index (
const EntityType & ep)
const
58 enum { cd = EntityType :: codimension };
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 );
80 return e.impl().subIndex( i, codim );
87 if( elType == tetra && !type.
isSimplex() )
return 0;
88 if( elType == hexa && !type.
isCube() )
return 0;
90 return this->
size(GridType::dimension-type.
dim());
94 int size (
int codim )
const
97 return grid_.hierSetSize(codim);
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_;
120 class ALUMacroKey :
public ALU3DSPACE Key4<int>
123 typedef ALUMacroKey ThisType;
124 typedef ALU3DSPACE Key4<A> BaseType;
127 ALUMacroKey() : BaseType(-1,-1,-1,-1) {}
128 ALUMacroKey(
const A&a,
const A&b,
const A&c,
const A&d) : BaseType(a,b,c,d) {}
129 ALUMacroKey(
const ALUMacroKey & org ) : BaseType(org) {}
130 ALUMacroKey & operator = (
const ALUMacroKey & org )
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) );
145 bool operator > (
const ALUMacroKey & org)
const
147 return ( (!this->
operator == (org)) && (!this->
operator <(org)) );
151 void extractKey(std::vector<int> &key)
const
153 alugrid_assert ( key.size() == 4 );
160 void print(std::ostream & out)
const
162 out <<
"[" << this->_a <<
"," << this->_b <<
"," << this->_c <<
"," << this->_d <<
"]";
165 inline friend std::size_t hash_value(
const ALUMacroKey& arg)
167 std::size_t seed = 0;
184 template <
class MacroKeyImp,
class IntegerImp = u
int>
188 typedef IntegerImp IntegerType;
204 explicit ALUGridId(
const MacroKeyImp & key,
const IntegerType nChild ,
const int codim,
const int level)
205 : key_(key) , nChild_(nChild)
210 ALUGridId(
const ALUGridId & org )
212 , nChild_(org.nChild_)
217 ALUGridId & operator = (
const ALUGridId & org )
220 nChild_ = org.nChild_;
238 if(
equals(org))
return true;
239 else return lesser(org);
244 if(
equals(org))
return true;
245 else return ! lesser(org);
255 return (!
equals(org) && ! lesser(org));
258 const MacroKeyImp & getKey()
const {
return key_; }
259 IntegerType nChild()
const {
return nChild_; }
260 int codim()
const {
return int(codim_) ; }
261 int level()
const {
return int(level_) ; }
263 bool isValid ()
const
265 return ( (codim_ >= 0) && (level_ >= 0) );
275 void print(std::ostream & out)
const
277 out <<
"AluGridID: (" << getKey() <<
"," << nChild_ <<
"," << int(codim_) <<
"," << int(level_) <<
")";
280 inline friend std::size_t hash_value(
const ALUGridId& arg)
282 std::size_t seed = hash<MacroKeyImp>()(arg.getKey());
291 bool lesser(
const ALUGridId & org)
const
293 if(getKey() < org.getKey() )
return true;
294 if(getKey() > org.getKey() )
return false;
295 if(getKey() == org.getKey() )
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_;
306 alugrid_assert (
equals(org) );
311 bool equals(
const ALUGridId & org)
const
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 > >,
347 public ALU3DSPACE AdaptRestrictProlongType
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;
453 alugrid_assert (
id != checkId );
454 DUNE_THROW(GridError,
" " <<
id <<
" equals " << checkId <<
"\n");
458 bool lesser = (
id < checkId);
459 bool greater = (
id > checkId);
460 alugrid_assert ( lesser != greater );
461 if( lesser == greater )
463 alugrid_assert ( 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 )
494 alugrid_assert ( creatorId.isValid() );
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];
503 alugrid_assert ( nChild < childOffSet );
504 alugrid_assert ( (
unsigned int)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 );
513 alugrid_assert( newId.isValid() );
514 alugrid_assert( newId != creatorId );
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)];
553 alugrid_assert ( macroId.isValid() );
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)];
564 alugrid_assert ( macroId.isValid() );
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 ];
576 alugrid_assert ( macroId.isValid() );
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 >,
604 public ALU3DSPACE AdaptRestrictProlongType
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 };
647 alugrid_assert ( hset_.size(cd) < codimOffSet );
648 return codimStart_[cd] + hset_.index(ep);
653 int id (
const typename GridType:: template Codim<codim> :: Entity & ep)
const
656 alugrid_assert ( hset_.size(codim) < codimOffSet );
657 return codimStart_[codim] + hset_.index(ep);
661 IdType subId (
const EntityCodim0Type &e,
int i,
unsigned int codim )
const
663 alugrid_assert ( hset_.size( codim ) < codimOffSet );
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
691 #include "indexsets.cc"
Portable very large unsigned integers.
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
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
[ provides Dune::Grid ]
Definition: grid.hh:434
const std::vector< GeometryType > & geomTypes(int codim) const
deliver all geometry types used in this grid
Definition: grid.hh:1066
Wrapper class for entities.
Definition: entity.hh:66
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:125
constexpr unsigned int dim() const
Return dimension of the type.
Definition: type.hh:371
constexpr bool isCube() const
Return true if entity is a cube of any dimension.
Definition: type.hh:335
constexpr bool isSimplex() const
Return true if entity is a simplex of any dimension.
Definition: type.hh:330
Index Set Interface base class.
Definition: indexidset.hh:78
Different resources needed by all grid implementations.
topology of a Cartesian grid
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition: type.hh:506
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:402
EnableIfInterOperable< T1, T2, bool >::type operator<(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:637
EnableIfInterOperable< T1, T2, bool >::type operator>(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:683
EnableIfInterOperable< T1, T2, bool >::type operator<=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:660
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:237
EnableIfInterOperable< T1, T2, bool >::type operator>=(const RandomAccessIteratorFacade< T1, V1, R1, D > &lhs, const RandomAccessIteratorFacade< T2, V2, R2, D > &rhs)
Comparison operator.
Definition: iteratorfacades.hh:705
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:259
Support for calculating hash values of objects.
#define DUNE_DEFINE_HASH(template_args, type)
Defines the required struct specialization to make type hashable via Dune::hash.
Definition: hash.hh:100
#define DUNE_HASH_TYPE(...)
Wrapper macro for the type to be hashed in DUNE_DEFINE_HASH.
Definition: hash.hh:117
#define DUNE_HASH_TEMPLATE_ARGS(...)
Wrapper macro for the template arguments in DUNE_DEFINE_HASH.
Definition: hash.hh:109
Provides base classes for index and id sets.
Dune namespace.
Definition: alignedallocator.hh:13
void hash_combine(std::size_t &seed, const T &arg)
Calculates the hash value of arg and combines it in-place with seed.
Definition: hash.hh:307
Standard Dune debug streams.
Static tag representing a codimension.
Definition: dimension.hh:24