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>
244 template<
int, PartitionIteratorType,
typename>
248 typedef typename GridImp::ctype
ctype;
250 typedef typename GridImp::template Codim<codim>::Geometry
Geometry;
251 typedef typename GridImp::Traits::template Codim<codim>::GeometryImpl
GeometryImpl;
253 typedef typename GridImp::template Codim<codim>::EntitySeed
EntitySeed;
279 constexpr GeometryType
type ()
const
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;
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;
425 typedef typename GridImp::template Codim< 0 >::Geometry
Geometry;
435 typedef typename GridImp::template Codim<0>::EntitySeed
EntitySeed;
445 typedef typename GridImp::YGrid::iTupel
iTupel;
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);
519 constexpr GeometryType
type ()
const
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;
801 typedef typename GridImp::template Codim<dim>::Geometry
Geometry;
803 typedef typename GridImp::template Codim<dim>::EntitySeed
EntitySeed;
809 typedef typename GridImp::YGrid::iTupel
iTupel;
845 return Dune::Yasp::subEnt<dim>(dim-dim,cc-dim);
850 GeometryImpl _geometry((
_it).lowerleft());
857 constexpr GeometryType
type ()
const
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()))
892 iTupel size =
_g->mg->levelSize(
_g->level());
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--)
PartitionType
Attributes used in the generic overlap model.
Definition gridenums.hh:30
@ FrontEntity
on boundary between overlap and ghost
Definition gridenums.hh:34
@ InteriorEntity
all interior entities
Definition gridenums.hh:31
@ GhostEntity
ghost entities
Definition gridenums.hh:35
@ BorderEntity
on boundary between interior and overlap
Definition gridenums.hh:32
@ OverlapEntity
all entities lying in the overlap zone
Definition gridenums.hh:33
Include standard header files.
Definition agrid.hh:60
const int yaspgrid_level_bits
Definition yaspgrid.hh:48
const int yaspgrid_dim_bits
Definition yaspgrid.hh:47
Default Implementations for EntityImp.
Definition common/entity.hh:542
Base class for exceptions in Dune grid modules.
Definition exceptions.hh:20
static constexpr int mydimension
geometry dimension
Definition common/geometry.hh:94
The general version that handles all codimensions but 0 and dim.
Definition yaspgridgeometry.hh:31
Definition yaspgridentity.hh:242
int level() const
level of this element
Definition yaspgridentity.hh:256
Geometry geometry() const
geometry of this entity
Definition yaspgridentity.hh:270
GridImp::ctype ctype
Definition yaspgridentity.hh:248
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
PersistentIndexType persistentIndex() const
globally unique, persistent index
Definition yaspgridentity.hh:333
const YGLI & gridlevel() const
Definition yaspgridentity.hh:394
const I & transformingsubiterator() const
Definition yaspgridentity.hh:393
YGLI _g
Definition yaspgridentity.hh:400
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition yaspgridentity.hh:321
PartitionType partitionType() const
return partition type attribute
Definition yaspgridentity.hh:294
GridImp::Traits::template Codim< codim >::GeometryImpl GeometryImpl
Definition yaspgridentity.hh:251
YGLI & gridlevel()
Definition yaspgridentity.hh:396
int subCompressedIndex(int i, unsigned int cc) const
subentity compressed index
Definition yaspgridentity.hh:370
GridImp::YGridLevelIterator YGLI
Definition yaspgridentity.hh:307
GridImp::YGrid::Iterator I
Definition yaspgridentity.hh:308
const GridImp * yaspgrid() const
Definition yaspgridentity.hh:397
GridImp::template Codim< codim >::EntitySeed EntitySeed
Definition yaspgridentity.hh:253
YaspEntity(YGLI &&g, const I &&it)
Definition yaspgridentity.hh:316
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition yaspgridentity.hh:264
int compressedIndex() const
consecutive, codim-wise, level-wise index
Definition yaspgridentity.hh:364
YaspEntity(const YGLI &g, const I &it)
Definition yaspgridentity.hh:312
I _it
Definition yaspgridentity.hh:399
YaspEntity()
Definition yaspgridentity.hh:309
GridImp::template Codim< codim >::Geometry Geometry
Definition yaspgridentity.hh:250
GridImp::PersistentIndexType PersistentIndexType
Definition yaspgridentity.hh:330
unsigned int subEntities(unsigned int cc) const
Definition yaspgridentity.hh:288
I & transformingsubiterator()
Definition yaspgridentity.hh:395
Describes the minimal information necessary to create a fully functional YaspEntity.
Definition yaspgridentityseed.hh:18
Iterates over entities of one grid level.
Definition yaspgridleveliterator.hh:19
YaspIntersectionIterator enables iteration over intersections with neighboring codim 0 entities.
Definition yaspgridintersectioniterator.hh:22
YaspHierarchicIterator enables iteration over son entities of codim 0.
Definition yaspgridhierarchiciterator.hh:20
Implementation of Level- and LeafIndexSets for YaspGrid.
Definition yaspgridindexsets.hh:25
persistent, globally unique Ids
Definition yaspgrididset.hh:25
LeafIntersectionIterator ileafbegin() const
returns intersection iterator for first intersection
Definition yaspgridentity.hh:631
GridImp::template Codim< 0 >::LocalGeometry LocalGeometry
Definition yaspgridentity.hh:426
Codim< cc >::Entity subEntity(int i) const
Definition yaspgridentity.hh:545
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition yaspgridentity.hh:464
YaspEntity(const YGLI &g, I &&it)
Definition yaspgridentity.hh:455
int count() const
Definition yaspgridentity.hh:528
GridImp::template Codim< 0 >::EntitySeed EntitySeed
Definition yaspgridentity.hh:435
GridImp::PersistentIndexType PersistentIndexType
define the type used for persistent indices
Definition yaspgridentity.hh:442
GridImp::YGrid::iTupel iTupel
define type used for coordinates in grid module
Definition yaspgridentity.hh:445
const YGLI & gridlevel() const
Definition yaspgridentity.hh:606
IntersectionIterator iend() const
Reference to one past the last neighbor.
Definition yaspgridentity.hh:644
const I & transformingsubiterator() const
Definition yaspgridentity.hh:605
GridImp::ctype ctype
Definition yaspgridentity.hh:420
YGLI & gridlevel()
Definition yaspgridentity.hh:608
YaspEntity(const YGLI &g, const I &it)
Definition yaspgridentity.hh:451
const GridImp * yaspgrid() const
Definition yaspgridentity.hh:609
int level() const
level of this element
Definition yaspgridentity.hh:470
GridImp::LeafIntersectionIterator LeafIntersectionIterator
Definition yaspgridentity.hh:438
YaspEntity(YGLI &&g, I &&it)
Definition yaspgridentity.hh:459
PartitionType partitionType() const
return partition type attribute
Definition yaspgridentity.hh:480
LevelIntersectionIterator ilevelend() const
Reference to one past the last neighbor.
Definition yaspgridentity.hh:656
bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt()
Definition yaspgridentity.hh:622
GridImp::HierarchicIterator HierarchicIterator
Definition yaspgridentity.hh:439
GridImp::template Codim< 0 >::Entity Entity
Definition yaspgridentity.hh:434
LevelIntersectionIterator ilevelbegin() const
returns intersection iterator for first intersection
Definition yaspgridentity.hh:638
LeafIntersectionIterator ileafend() const
Reference to one past the last neighbor.
Definition yaspgridentity.hh:650
YaspEntity()
Definition yaspgridentity.hh:448
GridImp::YGrid::Iterator I
Definition yaspgridentity.hh:423
GridImp::template Codim< 0 >::Geometry Geometry
Definition yaspgridentity.hh:425
Geometry geometry() const
geometry of this entity
Definition yaspgridentity.hh:491
Entity father() const
Inter-level access to father element on coarser grid. Assumes that meshes are nested.
Definition yaspgridentity.hh:561
bool isNew() const
Returns true, if the entity has been created during the last call to adapt()
Definition yaspgridentity.hh:618
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:475
HierarchicIterator hbegin(int maxlevel) const
Definition yaspgridentity.hh:665
IntersectionIterator ibegin() const
returns intersection iterator for first intersection
Definition yaspgridentity.hh:625
GridImp::YGridLevelIterator YGLI
Definition yaspgridentity.hh:422
unsigned int subEntities(unsigned int codim) const
Definition yaspgridentity.hh:537
LocalGeometry geometryInFather() const
Definition yaspgridentity.hh:588
GridImp::LevelIntersectionIterator IntersectionIterator
Definition yaspgridentity.hh:436
GridImp::LevelIntersectionIterator LevelIntersectionIterator
Definition yaspgridentity.hh:437
I & transformingsubiterator()
Definition yaspgridentity.hh:607
bool isLeaf() const
Definition yaspgridentity.hh:611
bool hasFather() const
returns true if father entity exists
Definition yaspgridentity.hh:581
GridImp::template Codim< cd >::Entity Entity
Definition yaspgridentity.hh:431
int level() const
level of this element
Definition yaspgridentity.hh:830
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition yaspgridentity.hh:824
YGLI & gridlevel()
Definition yaspgridentity.hh:941
Geometry geometry() const
geometry of this entity
Definition yaspgridentity.hh:849
YaspEntity(const YGLI &g, const I &it)
Definition yaspgridentity.hh:815
unsigned int subEntities(unsigned int cc) const
Definition yaspgridentity.hh:843
PartitionType partitionType() const
return partition type attribute
Definition yaspgridentity.hh:863
GridImp::ctype ctype
Definition yaspgridentity.hh:796
GridImp::YGridLevelIterator YGLI
Definition yaspgridentity.hh:798
GridImp::PersistentIndexType PersistentIndexType
define the type used for persistent indices
Definition yaspgridentity.hh:806
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition yaspgridentity.hh:835
const GridImp * yaspgrid() const
Definition yaspgridentity.hh:943
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
GridImp::YGrid::Iterator I
Definition yaspgridentity.hh:799
I & transformingsubiterator()
Definition yaspgridentity.hh:940
const I & transformingsubiterator() const
Definition yaspgridentity.hh:938
GridImp::YGrid::iTupel iTupel
define type used for coordinates in grid module
Definition yaspgridentity.hh:809
GridImp::template Codim< dim >::Geometry Geometry
Definition yaspgridentity.hh:801
const YGLI & gridlevel() const
Definition yaspgridentity.hh:939
YaspEntity(YGLI &&g, I &&it)
Definition yaspgridentity.hh:819
YaspEntity()
Definition yaspgridentity.hh:812
GridImp::template Codim< dim >::EntitySeed EntitySeed
Definition yaspgridentity.hh:803