5 #ifndef DUNE_GRID_YASPGRIDENTITY_HH 6 #define DUNE_GRID_YASPGRIDENTITY_HH 8 #include <dune/common/math.hh> 9 #include <dune/geometry/type.hh> 41 static constexpr
int evaluate(
int d,
int c)
43 return _values[_offsets[d] + c];
48 BinomialTable() =
delete;
51 static constexpr
int nextValue(
int& r,
int& c)
53 const auto result = Dune::binomial(r, c);
64 template<std::size_t... I>
65 static constexpr std::array<int,
sizeof...(I)> computeValues(std::index_sequence<I...>)
68 return {{ ((void)I, nextValue(r, c))... }};
71 template<std::size_t... I>
72 static constexpr std::array<int,
sizeof...(I)> computeOffsets(std::index_sequence<I...>)
73 {
return {{ (I*(I+1)/2)... }}; }
75 static constexpr std::array<int,(n+1)*(n+2)/2> _values = computeValues(std::make_index_sequence<(n+1)*(n+2)/2>{});
76 static constexpr std::array<int,n+1> _offsets = computeOffsets(std::make_index_sequence<n+1>{});
85 template<
int dimworld>
86 constexpr
int subEnt(
int d,
int c)
88 return (d < c ? 0 : BinomialTable<dimworld>::evaluate(d,c) << c);
93 template<
typename F,
int dim>
94 struct EntityShiftTable
96 typedef std::bitset<dim> value_type;
98 static value_type evaluate(
int i,
int codim)
100 return {_values[_offsets[codim] + i]};
106 EntityShiftTable() =
delete;
109 static constexpr
int nextOffset(
int& offset,
int codim)
116 offset += subEnt<dim>(dim, codim-1);
120 template<std::size_t... I>
121 static constexpr std::array<int,
sizeof...(I)> computeOffsets(std::index_sequence<I...>)
124 return {{ (nextOffset(offset, I))... }};
128 static constexpr
unsigned char nextValue(
int& codim,
int& i)
130 const auto result = F::evaluate(i, codim);
133 if (i >= subEnt<dim>(dim, codim)) {
141 template<std::size_t... I>
142 static constexpr std::array<
unsigned char,
sizeof...(I)> computeValues(std::index_sequence<I...>)
144 int codim = 0, i = 0;
145 return {{ ((void)I, nextValue(codim, i))... }};
148 static constexpr std::array<int,dim+1> _offsets = computeOffsets(std::make_index_sequence<dim+1>{});
149 static constexpr std::array<unsigned char,Dune::power(3,dim)> _values = computeValues(std::make_index_sequence<Dune::power(3,dim)>{});
155 struct calculate_entity_shift
157 static constexpr
unsigned long long evaluate(
int index,
int cc)
160 for (
int d = dim; d>0; d--)
164 if (index < subEnt<dim>(d-1,cc))
165 result |= 1ull << (d-1);
168 index = (index - subEnt<dim>(d-1, cc)) % subEnt<dim>(d-1,cc-1);
185 std::bitset<dim> entityShift(
int index,
int cc)
187 return EntityShiftTable<calculate_entity_shift<dim>,dim>::evaluate(index,cc);
192 struct calculate_entity_move
194 static constexpr
unsigned long long evaluate(
int index,
int cc)
197 for (
int d = dim; d>0; d--)
202 result &= ~(1ull << (d-1));
203 result |= index & (1ull << (d-1));
205 index &= ~(1<<(d-1));
207 if (index >= subEnt<dim>(d-1,cc))
209 if ((index - subEnt<dim>(d-1,cc)) / subEnt<dim>(d-1,cc-1) == 1)
211 result |= 1ull << (d-1);
213 index = (index - subEnt<dim>(d-1, cc)) % subEnt<dim>(d-1,cc-1);
230 std::bitset<dim> entityMove(
int index,
int cc)
232 return EntityShiftTable<calculate_entity_move<dim>,dim>::evaluate(index,cc);
239 template<
int codim,
int dim,
class Gr
idImp>
241 :
public EntityDefaultImplementation <codim,dim,GridImp,YaspEntity>
244 template<
int, PartitionIteratorType,
typename>
248 typedef typename GridImp::ctype
ctype;
251 typedef typename GridImp::Traits::template Codim<codim>::GeometryImpl
GeometryImpl;
290 return Dune::Yasp::subEnt<dim>(dim-codim,cc-codim);
296 if (
_g->interior[codim].inside(
_it.coord(),
_it.shift()))
298 if (
_g->interiorborder[codim].inside(
_it.coord(),
_it.shift()))
300 if (
_g->overlap[codim].inside(
_it.coord(),
_it.shift()))
302 if (
_g->overlapfront[codim].inside(
_it.coord(),
_it.shift()))
307 typedef typename GridImp::YGridLevelIterator
YGLI;
308 typedef typename GridImp::YGrid::Iterator
I;
323 return _it == e._it &&
_g == e._g;
336 std::array<int,dim> size;
338 for (
int i=0; i<dim; i++)
341 size[i] =
_g->mg->levelSize(
_g->level(), i);
354 for (
int i=dim-1; i>=0; i--)
366 return _it.superindex();
374 std::bitset<dim-codim> subent_shift = Dune::Yasp::entityShift<dim-codim>(i,cc-codim);
375 std::bitset<dim-codim> subent_move = Dune::Yasp::entityMove<dim-codim>(i,cc-codim);
377 std::bitset<dim> shift =
_it.shift();
378 std::array<int, dim> coord =
_it.coord();
379 for (
int j=0, k=0; j<dim; j++)
384 coord[j] += subent_move[k];
385 shift[j] = subent_shift[k];
389 int which =
_g->overlapfront[cc].shiftmapping(shift);
390 return _g->overlapfront[cc].superindex(coord,which);
405 template<
int dim,
class Gr
idImp>
409 constexpr
static int dimworld = GridImp::dimensionworld;
411 typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl
GeometryImpl;
413 template<
int, PartitionIteratorType,
typename>
420 typedef typename GridImp::ctype
ctype;
422 typedef typename GridImp::YGridLevelIterator
YGLI;
423 typedef typename GridImp::YGrid::Iterator
I;
445 typedef typename GridImp::YGrid::iTupel
iTupel;
466 return _it == e._it &&
_g == e._g;
482 if (
_g->interior[0].inside(
_it.coord(),
_it.shift()))
484 if (
_g->overlap[0].inside(
_it.coord(),
_it.shift()))
486 DUNE_THROW(
GridError,
"Impossible GhostEntity");
493 auto ll =
_it.lowerleft();
494 auto ur =
_it.upperright();
497 for (
int i=0; i<dimworld; i++) {
501 auto size =
_g->mg->domainSize()[i];
505 auto size =
_g->mg->domainSize()[i];
512 GeometryImpl _geometry(ll,ur);
530 return Dune::Yasp::subEnt<dim>(dim,cc);
539 return Dune::Yasp::subEnt<dim>(dim,codim);
548 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
552 for (
int j=0; j<dim; j++)
556 int which =
_g->overlapfront[cc].shiftmapping(Dune::Yasp::entityShift<dim>(i,cc));
565 DUNE_THROW(
GridError,
"tried to call father on level 0");
575 for (
int k=0; k<dim; k++) coord[k] = coord[k]/2;
583 return (
_g->level()>0);
591 FieldVector<ctype,dim> ll(0.0),ur(0.5);
593 for (
int k=0; k<dim; k++)
613 return (
_g->level() ==
yaspgrid()->maxLevel());
694 for (
int i=dim-1; i>=0; i--)
706 return _it.superindex();
713 std::bitset<dim> shift = Dune::Yasp::entityShift<dim>(i,cc);
714 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
716 int trailing = (cc == dim) ? 1000 : 0;
718 std::array<int,dim> size =
_g->mg->levelSize(
_g->level());
719 std::array<int, dim> coord =
_it.coord();
720 for (
int j=0; j<dim; j++)
731 for (
int j=0; j<dim; j++)
737 for (
int k=0; k<
_g->level(); k++)
738 if (coord[j] & (1<<k))
742 trailing =
std::min(trailing,zeroes);
754 for (
int j=dim-1; j>=0; j--)
767 std::bitset<dim> shift = Dune::Yasp::entityShift<dim>(i,cc);
768 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
770 std::array<int, dim> coord =
_it.coord();
771 for (
int j=0; j<dim; j++)
774 int which =
_g->overlapfront[cc].shiftmapping(shift);
775 return _g->overlapfront[cc].superindex(coord,which);
784 template<
int dim,
class Gr
idImp>
788 constexpr
static int dimworld = GridImp::dimensionworld;
790 template<
int, PartitionIteratorType,
typename>
793 typedef typename GridImp::Traits::template Codim<dim>::GeometryImpl
GeometryImpl;
796 typedef typename GridImp::ctype
ctype;
798 typedef typename GridImp::YGridLevelIterator
YGLI;
799 typedef typename GridImp::YGrid::Iterator
I;
809 typedef typename GridImp::YGrid::iTupel
iTupel;
826 return _it == e._it &&
_g == e._g;
845 return Dune::Yasp::subEnt<dim>(dim-dim,cc-dim);
850 GeometryImpl _geometry((
_it).lowerleft());
865 if (
_g->interior[dim].inside(
_it.coord(),
_it.shift()))
867 if (
_g->interiorborder[dim].inside(
_it.coord(),
_it.shift()))
869 if (
_g->overlap[dim].inside(
_it.coord(),
_it.shift()))
871 if (
_g->overlapfront[dim].inside(
_it.coord(),
_it.shift()))
894 for (
int i=0; i<dim; i++)
902 for (
int i=0; i<dim; i++)
906 for (
int j=0; j<
_g->level(); j++)
907 if (
_it.coord(i)&(1<<j))
911 trailing =
std::min(trailing,zeros);
915 int level =
_g->level()-trailing;
925 for (
int i=dim-1; i>=0; i--)
951 #endif // DUNE_GRID_YASPGRIDENTITY_HH int level() const
level of this element
Definition: yaspgridentity.hh:470
ghost entities
Definition: gridenums.hh:35
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:30
concept Entity
Model of a grid entity.
Definition: concepts/entity.hh:119
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition: yaspgridentity.hh:464
unsigned int subEntities(unsigned int codim) const
Definition: yaspgridentity.hh:537
const GridImp * yaspgrid() const
Definition: yaspgridentity.hh:397
constexpr GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: yaspgridentity.hh:519
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: yaspgridentity.hh:835
YaspEntity(const YGLI &g, I &&it)
Definition: yaspgridentity.hh:455
Entity father() const
Inter-level access to father element on coarser grid. Assumes that meshes are nested.
Definition: yaspgridentity.hh:561
YaspEntity(YGLI &&g, I &&it)
Definition: yaspgridentity.hh:819
const YGLI & gridlevel() const
Definition: yaspgridentity.hh:394
on boundary between interior and overlap
Definition: gridenums.hh:32
GridImp::ctype ctype
Definition: yaspgridentity.hh:248
Geometry geometry() const
geometry of this entity
Definition: yaspgridentity.hh:491
on boundary between overlap and ghost
Definition: gridenums.hh:34
GridImp::YGrid::Iterator I
Definition: yaspgridentity.hh:799
LevelIntersectionIterator ilevelend() const
Reference to one past the last neighbor.
Definition: yaspgridentity.hh:656
YGLI & gridlevel()
Definition: yaspgridentity.hh:608
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition: yaspgridentity.hh:824
GridImp::PersistentIndexType PersistentIndexType
define the type used for persistent indices
Definition: yaspgridentity.hh:806
LevelIntersectionIterator ilevelbegin() const
returns intersection iterator for first intersection
Definition: yaspgridentity.hh:638
Geometry geometry() const
geometry of this entity
Definition: yaspgridentity.hh:270
int compressedIndex() const
consecutive, codim-wise, level-wise index
Definition: yaspgridentity.hh:364
unsigned int subEntities(unsigned int cc) const
Definition: yaspgridentity.hh:843
const int yaspgrid_level_bits
Definition: yaspgrid.hh:48
GridImp::YGrid::Iterator I
Definition: yaspgridentity.hh:423
LeafIntersectionIterator ileafbegin() const
returns intersection iterator for first intersection
Definition: yaspgridentity.hh:631
const int yaspgrid_dim_bits
Definition: yaspgrid.hh:47
GridImp::template Codim< 0 >::Entity Entity
Definition: yaspgridentity.hh:434
int count() const
Definition: yaspgridentity.hh:528
I _it
Definition: yaspgridentity.hh:399
const I & transformingsubiterator() const
Definition: yaspgridentity.hh:605
YaspEntity()
Definition: yaspgridentity.hh:448
GridImp::Traits::template Codim< codim >::GeometryImpl GeometryImpl
Definition: yaspgridentity.hh:251
GridImp::template Codim< 0 >::EntitySeed EntitySeed
Definition: yaspgridentity.hh:435
GridImp::YGridLevelIterator YGLI
Definition: yaspgridentity.hh:798
concept Geometry
Model of a geometry object.
Definition: concepts/geometry.hh:29
constexpr GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: yaspgridentity.hh:279
GridImp::PersistentIndexType PersistentIndexType
Definition: yaspgridentity.hh:330
GridImp::YGrid::Iterator I
Definition: yaspgridentity.hh:308
GridImp::YGrid::iTupel iTupel
define type used for coordinates in grid module
Definition: yaspgridentity.hh:445
PartitionType partitionType() const
return partition type attribute
Definition: yaspgridentity.hh:294
GridImp::ctype ctype
Definition: yaspgridentity.hh:420
Geometry geometry() const
geometry of this entity
Definition: yaspgridentity.hh:849
YaspIntersectionIterator enables iteration over intersections with neighboring codim 0 entities...
Definition: yaspgrid.hh:59
GridImp::template Codim< codim >::EntitySeed EntitySeed
Definition: yaspgridentity.hh:253
GridImp::template Codim< cd >::Entity Entity
Definition: yaspgridentity.hh:431
YaspEntity(YGLI &&g, I &&it)
Definition: yaspgridentity.hh:459
YaspEntity(const YGLI &g, const I &it)
Definition: yaspgridentity.hh:312
all interior entities
Definition: gridenums.hh:31
I & transformingsubiterator()
Definition: yaspgridentity.hh:607
int level() const
level of this element
Definition: yaspgridentity.hh:256
IntersectionIterator ibegin() const
returns intersection iterator for first intersection
Definition: yaspgridentity.hh:625
GridImp::template Codim< dim >::Geometry Geometry
Definition: yaspgridentity.hh:801
GridImp::YGridLevelIterator YGLI
Definition: yaspgridentity.hh:307
bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt()
Definition: yaspgridentity.hh:622
bool isNew() const
Returns true, if the entity has been created during the last call to adapt()
Definition: yaspgridentity.hh:618
GridImp::LevelIntersectionIterator IntersectionIterator
Definition: yaspgridentity.hh:436
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: yaspgridentity.hh:264
int subCompressedIndex(int, unsigned int) const
subentity compressed index simply returns compressedIndex
Definition: yaspgridentity.hh:877
const YGLI & gridlevel() const
Definition: yaspgridentity.hh:606
YaspEntity()
Definition: yaspgridentity.hh:309
GridImp::ctype ctype
Definition: yaspgridentity.hh:796
Definition: yaspgrid.hh:56
int level() const
level of this element
Definition: yaspgridentity.hh:830
IdType id(const typename std::remove_const< GridImp >::type::Traits::template Codim< cd >::Entity &e) const
get id of an entity
Definition: yaspgrididset.hh:44
bool isLeaf() const
Definition: yaspgridentity.hh:611
YaspEntity(const YGLI &g, const I &it)
Definition: yaspgridentity.hh:815
GridImp::LeafIntersectionIterator LeafIntersectionIterator
Definition: yaspgridentity.hh:438
all entities lying in the overlap zone
Definition: gridenums.hh:33
bool hasFather() const
returns true if father entity exists
Definition: yaspgridentity.hh:581
GridImp::PersistentIndexType PersistentIndexType
define the type used for persistent indices
Definition: yaspgridentity.hh:442
static constexpr int mydimension
geometry dimension
Definition: common/geometry.hh:94
Codim< cc >::Entity subEntity(int i) const
Definition: yaspgridentity.hh:545
PartitionType partitionType() const
return partition type attribute
Definition: yaspgridentity.hh:863
YaspHierarchicIterator enables iteration over son entities of codim 0.
Definition: yaspgrid.hh:61
Include standard header files.
Definition: agrid.hh:59
const GridImp * yaspgrid() const
Definition: yaspgridentity.hh:943
Iterates over entities of one grid level.
Definition: yaspgrid.hh:58
GridImp::YGrid::iTupel iTupel
define type used for coordinates in grid module
Definition: yaspgridentity.hh:809
The general version that handles all codimensions but 0 and dim.
Definition: yaspgrid.hh:55
I & transformingsubiterator()
Definition: yaspgridentity.hh:940
YGLI & gridlevel()
Definition: yaspgridentity.hh:941
GridImp::template Codim< codim >::Geometry Geometry
Definition: yaspgridentity.hh:250
GridImp::YGridLevelIterator YGLI
Definition: yaspgridentity.hh:422
PartitionType partitionType() const
return partition type attribute
Definition: yaspgridentity.hh:480
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: yaspgridentity.hh:475
LocalGeometry geometryInFather() const
Definition: yaspgridentity.hh:588
persistent, globally unique Ids
Definition: yaspgrid.hh:63
Describes the minimal information necessary to create a fully functional YaspEntity.
Definition: yaspgrid.hh:57
unsigned int subEntities(unsigned int cc) const
Definition: yaspgridentity.hh:288
const YGLI & gridlevel() const
Definition: yaspgridentity.hh:939
const I & transformingsubiterator() const
Definition: yaspgridentity.hh:393
Default Implementations for EntityImp.
Definition: common/entity.hh:541
const GridImp * yaspgrid() const
Definition: yaspgridentity.hh:609
YaspEntity()
Definition: yaspgridentity.hh:812
GridImp::LevelIntersectionIterator LevelIntersectionIterator
Definition: yaspgridentity.hh:437
I & transformingsubiterator()
Definition: yaspgridentity.hh:395
HierarchicIterator hend(int) const
Returns iterator to one past the last son.
Definition: yaspgridentity.hh:671
constexpr GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: yaspgridentity.hh:857
PersistentIndexType persistentIndex() const
globally unique, persistent index
Definition: yaspgridentity.hh:333
HierarchicIterator hbegin(int maxlevel) const
Definition: yaspgridentity.hh:665
YGLI _g
Definition: yaspgridentity.hh:400
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
GridImp::HierarchicIterator HierarchicIterator
Definition: yaspgridentity.hh:439
const I & transformingsubiterator() const
Definition: yaspgridentity.hh:938
Implementation of Level- and LeafIndexSets for YaspGrid.
Definition: yaspgrid.hh:62
IntersectionIterator iend() const
Reference to one past the last neighbor.
Definition: yaspgridentity.hh:644
int subCompressedIndex(int i, unsigned int cc) const
subentity compressed index
Definition: yaspgridentity.hh:370
GridImp::template Codim< dim >::EntitySeed EntitySeed
Definition: yaspgridentity.hh:803
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:18
LeafIntersectionIterator ileafend() const
Reference to one past the last neighbor.
Definition: yaspgridentity.hh:650
GridImp::template Codim< 0 >::Geometry Geometry
Definition: yaspgridentity.hh:425
GridImp::template Codim< cd >::EntitySeed EntitySeed
The corresponding entity seed (for storage of entities)
Definition: common/entity.hh:554
YaspEntity(const YGLI &g, const I &it)
Definition: yaspgridentity.hh:451
YaspEntity(YGLI &&g, const I &&it)
Definition: yaspgridentity.hh:316
concept EntitySeed
Model of an entity seed.
Definition: concepts/entity.hh:25
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition: yaspgridentity.hh:321
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:348
YGLI & gridlevel()
Definition: yaspgridentity.hh:396
GridImp::template Codim< 0 >::LocalGeometry LocalGeometry
Definition: yaspgridentity.hh:426