Skip to content
Snippets Groups Projects
Commit 65776003 authored by alkaemper's avatar alkaemper
Browse files

a working new id set implementation

parent e5442786
No related branches found
No related tags found
No related merge requests found
...@@ -230,7 +230,7 @@ buildMacroVertexId(const VertexType & item ) ...@@ -230,7 +230,7 @@ buildMacroVertexId(const VertexType & item )
int vx[4] = { item.ident(), -1, -1, -1}; int vx[4] = { item.ident(), -1, -1, -1};
enum { codim = 3 }; enum { codim = 3 };
MacroKeyType key(vx[0],vx[1],vx[2],vx[3]); MacroKeyType key(vx[0],vx[1],vx[2],vx[3]);
return MacroIdType(key, 1, codim, startOffSet_ ); return MacroIdType(key, 0, codim, startOffSet_ );
} }
template<int dim, int dimworld, ALU3dGridElementType elType, class Comm > template<int dim, int dimworld, ALU3dGridElementType elType, class Comm >
...@@ -248,7 +248,7 @@ buildMacroEdgeId(const HEdgeType & item ) ...@@ -248,7 +248,7 @@ buildMacroEdgeId(const HEdgeType & item )
enum { codim = 2 }; enum { codim = 2 };
MacroKeyType key(vx[0],vx[1],vx[2],vx[3]); MacroKeyType key(vx[0],vx[1],vx[2],vx[3]);
return MacroIdType(key, 1, codim, startOffSet_ ); return MacroIdType(key, 0, codim, startOffSet_ );
} }
template<int dim, int dimworld, ALU3dGridElementType elType, class Comm > template<int dim, int dimworld, ALU3dGridElementType elType, class Comm >
...@@ -266,7 +266,7 @@ buildMacroFaceId(const HFaceType & item ) ...@@ -266,7 +266,7 @@ buildMacroFaceId(const HFaceType & item )
enum { codim = 1 }; enum { codim = 1 };
MacroKeyType key(vx[0],vx[1],vx[2],vx[3]); MacroKeyType key(vx[0],vx[1],vx[2],vx[3]);
return MacroIdType(key,1, codim, startOffSet_ ); return MacroIdType(key,0, codim, startOffSet_ );
} }
template<int dim, int dimworld, ALU3dGridElementType elType, class Comm > template<int dim, int dimworld, ALU3dGridElementType elType, class Comm >
...@@ -283,7 +283,7 @@ buildMacroElementId(const HElementType & item ) ...@@ -283,7 +283,7 @@ buildMacroElementId(const HElementType & item )
} }
enum { codim = 0 }; enum { codim = 0 };
MacroKeyType key(vx[0],vx[1],vx[2],vx[3]); MacroKeyType key(vx[0],vx[1],vx[2],vx[3]);
return MacroIdType(key,1, codim, startOffSet_ ); return MacroIdType(key,0, codim, startOffSet_ );
} }
// build ids for all children of this element // build ids for all children of this element
...@@ -440,8 +440,8 @@ ALU3dGridGlobalIdSet< dim, dimworld, elType, Comm > :: ...@@ -440,8 +440,8 @@ ALU3dGridGlobalIdSet< dim, dimworld, elType, Comm > ::
buildVertexIds(const VertexType & vertex, const IdType & fatherId ) buildVertexIds(const VertexType & vertex, const IdType & fatherId )
{ {
enum { codim = 3 }; enum { codim = 3 };
// inner vertex number is 1 // inner vertex number is 0
ids_[codim][vertex.getIndex()] = createId<codim>(vertex,fatherId,1); ids_[codim][vertex.getIndex()] = createId<codim>(vertex,fatherId,0);
alugrid_assert ( ids_[codim][vertex.getIndex()].isValid() ); alugrid_assert ( ids_[codim][vertex.getIndex()].isValid() );
} }
......
...@@ -191,33 +191,35 @@ namespace Dune ...@@ -191,33 +191,35 @@ namespace Dune
MacroKeyImp key_; MacroKeyImp key_;
IntegerType nChild_; IntegerType nChild_;
int codimLevel_; signed char codim_;
signed char level_;
// this means that only up to 100 levels are allowed
static constexpr int codimOffset = 100 ;
public: public:
ALUGridId() : key_() ALUGridId() : key_()
, nChild_(-1) , nChild_(-1)
, codimLevel_(-1) , codim_(-1)
, level_(-1)
{} {}
explicit ALUGridId(const MacroKeyImp & key, const IntegerType nChild , const int codim, const int level) explicit ALUGridId(const MacroKeyImp & key, const IntegerType nChild , const int codim, const int level)
: key_(key) , nChild_(nChild) : key_(key) , nChild_(nChild)
, codimLevel_( codim * codimOffset + level ) , codim_( codim )
, level_( level )
{} {}
ALUGridId(const ALUGridId & org ) ALUGridId(const ALUGridId & org )
: key_(org.key_) : key_(org.key_)
, nChild_(org.nChild_) , nChild_(org.nChild_)
, codimLevel_(org.codimLevel_) , codim_(org.codim_)
, level_(org.level_)
{} {}
ALUGridId & operator = (const ALUGridId & org ) ALUGridId & operator = (const ALUGridId & org )
{ {
key_ = org.key_; key_ = org.key_;
nChild_ = org.nChild_; nChild_ = org.nChild_;
codimLevel_ = org.codimLevel_; codim_ = org.codim_;
level_ = org.level_;
return *this; return *this;
} }
...@@ -255,30 +257,32 @@ namespace Dune ...@@ -255,30 +257,32 @@ namespace Dune
const MacroKeyImp & getKey() const { return key_; } const MacroKeyImp & getKey() const { return key_; }
IntegerType nChild() const { return nChild_; } IntegerType nChild() const { return nChild_; }
int codim() const { return codimLevel_ / codimOffset ; } int codim() const { return int(codim_) ; }
int level() const { return codimLevel_ % codimOffset ; } int level() const { return int(level_) ; }
bool isValid () const bool isValid () const
{ {
return ( (nChild_ >= 0) && (codimLevel_ >= 0) ); return ( (nChild_ >= 0) && (codim_ >= 0) && (level_ >= 0) );
} }
void reset() void reset()
{ {
nChild_ = -1; nChild_ = -1;
codimLevel_ = -1; codim_ = -1;
level_ = -1;
} }
void print(std::ostream & out) const void print(std::ostream & out) const
{ {
out << "AluGridID: (" << getKey() << "," << nChild_ << "," << codimLevel_ << ")"; out << "AluGridID: (" << getKey() << "," << nChild_ << "," << int(codim_) << "," << int(level_) << ")";
} }
inline friend std::size_t hash_value(const ALUGridId& arg) inline friend std::size_t hash_value(const ALUGridId& arg)
{ {
std::size_t seed = hash<MacroKeyImp>()(arg.getKey()); std::size_t seed = hash<MacroKeyImp>()(arg.getKey());
hash_combine(seed,arg.nChild_); hash_combine(seed,arg.nChild_);
hash_combine(seed,arg.codimLevel_); hash_combine(seed,arg.codim_);
hash_combine(seed,arg.level_);
return seed; return seed;
} }
...@@ -292,7 +296,9 @@ namespace Dune ...@@ -292,7 +296,9 @@ namespace Dune
{ {
if(nChild_ == org.nChild_) if(nChild_ == org.nChild_)
{ {
return codimLevel_ < org.codimLevel_; if( codim_ == org.codim_)
return level_ < org.level_;
return codim_ < org.codim_;
} }
else else
return nChild_ < org.nChild_; return nChild_ < org.nChild_;
...@@ -305,7 +311,7 @@ namespace Dune ...@@ -305,7 +311,7 @@ namespace Dune
bool equals(const ALUGridId & org) const bool equals(const ALUGridId & org) const
{ {
return ( (getKey() == org.getKey() ) && (nChild_ == org.nChild_) return ( (getKey() == org.getKey() ) && (nChild_ == org.nChild_)
&& (codimLevel_ == org.codimLevel_) ); && (codim_ == org.codim_) && (level_ == org.level_) );
} }
}; };
...@@ -480,17 +486,21 @@ namespace Dune { ...@@ -480,17 +486,21 @@ namespace Dune {
const IntType nElements = std::pow(8,level); const IntType nElements = std::pow(8,level);
const std::array<IntType, 4> nEntities ({nElements, 3* nElements, 3* nElements, nElements}); const std::array<IntType, 4> nEntities ({nElements, 3* nElements, 3* nElements, nElements});
const std::array<std::array<int, 4>, 3> offset = {AT({8,12,6,1}),AT({-1,4,4,1}),AT({-1,-1,2,1})}; const std::array<std::array<int, 4>, 4> offset = {AT({8,12,6,1}),AT({-1,4,4,1}),AT({-1,-1,2,1}),AT({-1,-1,-1,1})};
const int childOffSet = offset[creatorCodim][cd]; const int childOffSet = offset[creatorCodim][cd];
alugrid_assert ( nChild < childOffSet ); alugrid_assert ( nChild < childOffSet );
typename IdType::IntegerType newChild = creatorNumber * childOffSet + nChild; alugrid_assert ( childOffSet > 0);
alugrid_assert ( creatorNumber < nEntities[creatorCodim] );
typename IdType::IntegerType newChild = creatorNumber * childOffSet + nChild;
for(int i=cd ; i > creatorCodim ; i--) for(int i=cd ; i > creatorCodim ; i--)
{ {
alugrid_assert(offset[i][cd] > 0);
newChild += nEntities[i] * offset[i][cd]; newChild += nEntities[i] * offset[i][cd];
} }
IdType newId( creatorId.getKey() , newChild , cd, creatorId.level() + 1 ); IdType newId( creatorId.getKey() , newChild , cd, level + 1 );
alugrid_assert( newId.isValid() );
alugrid_assert( newId != creatorId ); alugrid_assert( newId != creatorId );
return newId; return newId;
} }
...@@ -499,7 +509,7 @@ namespace Dune { ...@@ -499,7 +509,7 @@ namespace Dune {
const IntType nElements = std::pow(8,level); const IntType nElements = std::pow(8,level);
const std::array<IntType, 4> nEntities ({nElements, 2* nElements, (3* nElements)/4, nElements/2}); const std::array<IntType, 4> nEntities ({nElements, 2* nElements, (3* nElements)/4, nElements/2});
const std::array<std::array<int, 4>, 3> offset = {AT({4,12,1,0}),AT({-1,4,3,0}),AT({-1,-1,2,1})}; const std::array<std::array<int, 4>, 4> offset = {AT({8,8,1,0}),AT({-1,4,3,0}),AT({-1,-1,2,1}),AT({-1,-1,-1,1})};
const int childOffSet = offset[creatorCodim][cd]; const int childOffSet = offset[creatorCodim][cd];
alugrid_assert ( nChild < childOffSet ); alugrid_assert ( nChild < childOffSet );
...@@ -508,6 +518,10 @@ namespace Dune { ...@@ -508,6 +518,10 @@ namespace Dune {
{ {
newChild += nEntities[i] * offset[i][cd]; newChild += nEntities[i] * offset[i][cd];
} }
IdType newId( creatorId.getKey() , newChild , cd, level + 1 );
alugrid_assert( newId.isValid() );
alugrid_assert( newId != creatorId );
return newId;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment