Go to the documentation of this file.
3 #ifndef DUNE_GRID_YASPGRIDENTITY_HH
4 #define DUNE_GRID_YASPGRIDENTITY_HH
36 static constexpr
int evaluate(
int d,
int c)
38 return _values[_offsets[d] + c];
42 static constexpr
int binomial(
int d,
int c)
45 for (
int i=d-c+1; i<=d; i++)
47 for (
long i=2; i<=c; i++)
54 BinomialTable() =
delete;
57 static constexpr
int nextValue(
int& r,
int& c)
59 const auto result = binomial(r, c);
70 template<std::size_t... I>
71 static constexpr std::array<int,
sizeof...(I)> computeValues(std::index_sequence<I...>)
74 return {{ ((void)I, nextValue(r, c))... }};
77 template<std::size_t... I>
78 static constexpr std::array<int,
sizeof...(I)> computeOffsets(std::index_sequence<I...>)
79 {
return {{ (I*(I+1)/2)... }}; }
81 static constexpr std::array<int,(n+1)*(n+2)/2> _values = computeValues(std::make_index_sequence<(n+1)*(n+2)/2>{});
82 static constexpr std::array<int,n+1> _offsets = computeOffsets(std::make_index_sequence<n+1>{});
85 #if __cplusplus < 201703L
87 constexpr std::array<int,(n+1)*(n+2)/2> BinomialTable<n>::_values;
89 constexpr std::array<int,n+1> BinomialTable<n>::_offsets;
98 template<
int dimworld>
99 constexpr
int subEnt(
int d,
int c)
101 return (d < c ? 0 : BinomialTable<dimworld>::evaluate(d,c) << c);
106 template<
typename F,
int dim>
107 struct EntityShiftTable
109 typedef std::bitset<dim> value_type;
111 static value_type evaluate(
int i,
int codim)
113 return {_values[_offsets[codim] + i]};
119 EntityShiftTable() =
delete;
122 static constexpr
int nextOffset(
int& offset,
int codim)
129 offset += subEnt<dim>(dim, codim-1);
133 template<std::size_t... I>
134 static constexpr std::array<int,
sizeof...(I)> computeOffsets(std::index_sequence<I...>)
137 return {{ (nextOffset(offset, I))... }};
141 static constexpr
unsigned char nextValue(
int& codim,
int& i)
143 const auto result = F::evaluate(i, codim);
146 if (i >= subEnt<dim>(dim, codim)) {
154 template<std::size_t... I>
155 static constexpr std::array<
unsigned char,
sizeof...(I)> computeValues(std::index_sequence<I...>)
157 int codim = 0, i = 0;
158 return {{ ((void)I, nextValue(codim, i))... }};
161 static constexpr std::array<int,dim+1> _offsets = computeOffsets(std::make_index_sequence<dim+1>{});
162 static constexpr std::array<unsigned char,StaticPower<3,dim>::power> _values = computeValues(std::make_index_sequence<StaticPower<3,dim>::power>{});
166 #if __cplusplus < 201703L
167 template<
typename F,
int dim>
168 constexpr std::array<int,dim+1> EntityShiftTable<F, dim>::_offsets;
169 template<
typename F,
int dim>
170 constexpr std::array<unsigned char,StaticPower<3,dim>::power> EntityShiftTable<F, dim>::_values;
175 struct calculate_entity_shift
177 static constexpr
unsigned long long evaluate(
int index,
int cc)
180 for (
int d = dim; d>0; d--)
184 if (index < subEnt<dim>(d-1,cc))
185 result |= 1ull << (d-1);
188 index = (index - subEnt<dim>(d-1, cc)) % subEnt<dim>(d-1,cc-1);
205 std::bitset<dim> entityShift(
int index,
int cc)
207 return EntityShiftTable<calculate_entity_shift<dim>,dim>::evaluate(index,cc);
212 struct calculate_entity_move
214 static constexpr
unsigned long long evaluate(
int index,
int cc)
217 for (
int d = dim; d>0; d--)
222 result &= ~(1ull << (d-1));
223 result |= index & (1ull << (d-1));
225 index &= ~(1<<(d-1));
227 if (index >= subEnt<dim>(d-1,cc))
229 if ((index - subEnt<dim>(d-1,cc)) / subEnt<dim>(d-1,cc-1) == 1)
231 result |= 1ull << (d-1);
233 index = (index - subEnt<dim>(d-1, cc)) % subEnt<dim>(d-1,cc-1);
250 std::bitset<dim> entityMove(
int index,
int cc)
252 return EntityShiftTable<calculate_entity_move<dim>,dim>::evaluate(index,cc);
259 template<
int codim,
int dim,
class Gr
idImp>
261 :
public EntityDefaultImplementation <codim,dim,GridImp,YaspEntity>
264 template<
int, PartitionIteratorType,
typename>
268 typedef typename GridImp::ctype
ctype;
270 typedef typename GridImp::template Codim<codim>::Geometry
Geometry;
271 typedef typename GridImp::Traits::template Codim<codim>::GeometryImpl
GeometryImpl;
273 typedef typename GridImp::template Codim<codim>::EntitySeed
EntitySeed;
302 return Dune::Yasp::subEnt<dim>(dim-codim,cc-codim);
308 if (
_g->interior[codim].inside(
_it.coord(),
_it.shift()))
310 if (
_g->interiorborder[codim].inside(
_it.coord(),
_it.shift()))
312 if (
_g->overlap[codim].inside(
_it.coord(),
_it.shift()))
314 if (
_g->overlapfront[codim].inside(
_it.coord(),
_it.shift()))
319 typedef typename GridImp::YGridLevelIterator
YGLI;
320 typedef typename GridImp::YGrid::Iterator
I;
329 :
_it(std::move(it)),
_g(std::move(g))
335 return _it == e._it &&
_g == e._g;
348 std::array<int,dim> size;
350 for (
int i=0; i<dim; i++)
353 size[i] =
_g->mg->levelSize(
_g->level(), i);
366 for (
int i=dim-1; i>=0; i--)
378 return _it.superindex();
386 std::bitset<dim-codim> subent_shift = Dune::Yasp::entityShift<dim-codim>(i,cc-codim);
387 std::bitset<dim-codim> subent_move = Dune::Yasp::entityMove<dim-codim>(i,cc-codim);
389 std::bitset<dim> shift =
_it.shift();
390 std::array<int, dim> coord =
_it.coord();
391 for (
int j=0, k=0; j<dim; j++)
396 coord[j] += subent_move[k];
397 shift[j] = subent_shift[k];
401 int which =
_g->overlapfront[cc].shiftmapping(shift);
402 return _g->overlapfront[cc].superindex(coord,which);
417 template<
int dim,
class Gr
idImp>
421 enum { dimworld = GridImp::dimensionworld };
423 typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl
GeometryImpl;
425 template<
int, PartitionIteratorType,
typename>
432 typedef typename GridImp::ctype
ctype;
434 typedef typename GridImp::YGridLevelIterator
YGLI;
435 typedef typename GridImp::YGrid::Iterator
I;
437 typedef typename GridImp::template Codim< 0 >::Geometry
Geometry;
447 typedef typename GridImp::template Codim<0>::EntitySeed
EntitySeed;
457 typedef typename GridImp::YGrid::iTupel
iTupel;
468 :
_it(std::move(it)),
_g(g)
472 :
_it(std::move(it)),
_g(std::move(g))
478 return _it == e._it &&
_g == e._g;
494 if (
_g->interior[0].inside(
_it.coord(),
_it.shift()))
496 if (
_g->overlap[0].inside(
_it.coord(),
_it.shift()))
498 DUNE_THROW(
GridError,
"Impossible GhostEntity");
505 auto ll =
_it.lowerleft();
506 auto ur =
_it.upperright();
509 for (
int i=0; i<dimworld; i++) {
513 auto size =
_g->mg->domainSize()[i];
517 auto size =
_g->mg->domainSize()[i];
524 GeometryImpl _geometry(ll,ur);
534 return Dune::Yasp::subEnt<dim>(dim,cc);
543 return Dune::Yasp::subEnt<dim>(dim,codim);
552 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
556 for (
int j=0; j<dim; j++)
560 int which =
_g->overlapfront[cc].shiftmapping(Dune::Yasp::entityShift<dim>(i,cc));
569 DUNE_THROW(
GridError,
"tried to call father on level 0");
579 for (
int k=0; k<dim; k++) coord[k] = coord[k]/2;
587 return (
_g->level()>0);
595 FieldVector<ctype,dim> ll(0.0),ur(0.5);
597 for (
int k=0; k<dim; k++)
617 return (
_g->level() ==
yaspgrid()->maxLevel());
698 for (
int i=dim-1; i>=0; i--)
710 return _it.superindex();
717 std::bitset<dim> shift = Dune::Yasp::entityShift<dim>(i,cc);
718 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
720 int trailing = (cc == dim) ? 1000 : 0;
722 std::array<int,dim> size =
_g->mg->levelSize(
_g->level());
723 std::array<int, dim> coord =
_it.coord();
724 for (
int j=0; j<dim; j++)
735 for (
int j=0; j<dim; j++)
741 for (
int k=0; k<
_g->level(); k++)
742 if (coord[j] & (1<<k))
746 trailing = std::min(trailing,zeroes);
758 for (
int j=dim-1; j>=0; j--)
771 std::bitset<dim> shift = Dune::Yasp::entityShift<dim>(i,cc);
772 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
774 std::array<int, dim> coord =
_it.coord();
775 for (
int j=0; j<dim; j++)
778 int which =
_g->overlapfront[cc].shiftmapping(shift);
779 return _g->overlapfront[cc].superindex(coord,which);
788 template<
int dim,
class Gr
idImp>
792 enum { dimworld = GridImp::dimensionworld };
794 template<
int, PartitionIteratorType,
typename>
797 typedef typename GridImp::Traits::template Codim<dim>::GeometryImpl
GeometryImpl;
800 typedef typename GridImp::ctype
ctype;
802 typedef typename GridImp::YGridLevelIterator
YGLI;
803 typedef typename GridImp::YGrid::Iterator
I;
805 typedef typename GridImp::template Codim<dim>::Geometry
Geometry;
807 typedef typename GridImp::template Codim<dim>::EntitySeed
EntitySeed;
813 typedef typename GridImp::YGrid::iTupel
iTupel;
824 :
_it(std::move(it)),
_g(std::move(g))
830 return _it == e._it &&
_g == e._g;
849 return Dune::Yasp::subEnt<dim>(dim-dim,cc-dim);
854 GeometryImpl _geometry((
_it).lowerleft());
861 if (
_g->interior[dim].inside(
_it.coord(),
_it.shift()))
863 if (
_g->interiorborder[dim].inside(
_it.coord(),
_it.shift()))
865 if (
_g->overlap[dim].inside(
_it.coord(),
_it.shift()))
867 if (
_g->overlapfront[dim].inside(
_it.coord(),
_it.shift()))
890 for (
int i=0; i<dim; i++)
898 for (
int i=0; i<dim; i++)
902 for (
int j=0; j<
_g->level(); j++)
903 if (
_it.coord(i)&(1<<j))
907 trailing = std::min(trailing,zeros);
911 int level =
_g->level()-trailing;
921 for (
int i=dim-1; i>=0; i--)
947 #endif // DUNE_GRID_YASPGRIDENTITY_HH
I _it
Definition: yaspgridentity.hh:411
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: yaspgridentity.hh:284
GridImp::ctype ctype
Definition: yaspgridentity.hh:432
bool isNew() const
Returns true, if the entity has been created during the last call to adapt()
Definition: yaspgridentity.hh:622
LeafIntersectionIterator ileafend() const
Reference to one past the last neighbor.
Definition: yaspgridentity.hh:654
const I & transformingsubiterator() const
Definition: yaspgridentity.hh:609
GridImp::PersistentIndexType PersistentIndexType
define the type used for persistent indices
Definition: yaspgridentity.hh:454
GridImp::template Codim< 0 >::Entity Entity
Definition: yaspgridentity.hh:446
YaspEntity(YGLI &&g, I &&it)
Definition: yaspgridentity.hh:823
YaspEntity(YGLI &&g, I &&it)
Definition: yaspgridentity.hh:471
GridImp::template Codim< 0 >::Geometry Geometry
Definition: yaspgridentity.hh:437
The general version that handles all codimensions but 0 and dim.
Definition: yaspgrid.hh:59
GridImp::template Codim< dim >::Geometry Geometry
Definition: yaspgridentity.hh:805
YGLI & gridlevel()
Definition: yaspgridentity.hh:408
PartitionType partitionType() const
return partition type attribute
Definition: yaspgridentity.hh:859
IntersectionIterator ibegin() const
returns intersection iterator for first intersection
Definition: yaspgridentity.hh:629
int level() const
level of this element
Definition: yaspgridentity.hh:834
GridImp::ctype ctype
Definition: yaspgridentity.hh:268
Entity father() const
Inter-level access to father element on coarser grid. Assumes that meshes are nested.
Definition: yaspgridentity.hh:565
GridImp::template Codim< codim >::EntitySeed EntitySeed
Definition: yaspgridentity.hh:273
Codim< cc >::Entity subEntity(int i) const
Definition: yaspgridentity.hh:549
GridImp::template Codim< cd >::Entity Entity
Definition: yaspgridentity.hh:443
YaspEntity(const YGLI &g, const I &it)
Definition: yaspgridentity.hh:819
YGLI & gridlevel()
Definition: yaspgridentity.hh:937
I & transformingsubiterator()
Definition: yaspgridentity.hh:936
GridImp::LevelIntersectionIterator IntersectionIterator
Definition: yaspgridentity.hh:448
const YGLI & gridlevel() const
Definition: yaspgridentity.hh:406
LeafIntersectionIterator ileafbegin() const
returns intersection iterator for first intersection
Definition: yaspgridentity.hh:635
Geometry geometry() const
geometry of this entity
Definition: yaspgridentity.hh:290
GridImp::HierarchicIterator HierarchicIterator
Definition: yaspgridentity.hh:451
YGLI _g
Definition: yaspgridentity.hh:412
GridImp::YGrid::iTupel iTupel
define type used for coordinates in grid module
Definition: yaspgridentity.hh:813
IdType id(const typename std::remove_const< GridImp >::type::Traits::template Codim< cd >::Entity &e) const
get id of an entity
Definition: yaspgrididset.hh:42
int count() const
Definition: yaspgridentity.hh:532
YaspEntity(YGLI &&g, const I &&it)
Definition: yaspgridentity.hh:328
HierarchicIterator hend(int maxlevel) const
Returns iterator to one past the last son.
Definition: yaspgridentity.hh:675
const int yaspgrid_level_bits
Definition: yaspgrid.hh:52
Implementation of Level- and LeafIndexSets for YaspGrid.
Definition: yaspgrid.hh:66
@ OverlapEntity
all entities lying in the overlap zone
Definition: gridenums.hh:31
I & transformingsubiterator()
Definition: yaspgridentity.hh:407
GridImp::YGrid::Iterator I
Definition: yaspgridentity.hh:435
Geometry geometry() const
geometry of this entity
Definition: yaspgridentity.hh:853
GridImp::Traits::template Codim< codim >::GeometryImpl GeometryImpl
Definition: yaspgridentity.hh:271
YaspEntity(const YGLI &g, I &&it)
Definition: yaspgridentity.hh:467
GridImp::PersistentIndexType PersistentIndexType
Definition: yaspgridentity.hh:342
@ InteriorEntity
all interior entities
Definition: gridenums.hh:29
PartitionType partitionType() const
return partition type attribute
Definition: yaspgridentity.hh:492
const GridImp * yaspgrid() const
Definition: yaspgridentity.hh:613
const I & transformingsubiterator() const
Definition: yaspgridentity.hh:934
PartitionType partitionType() const
return partition type attribute
Definition: yaspgridentity.hh:306
GridImp::YGrid::Iterator I
Definition: yaspgridentity.hh:803
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: yaspgridentity.hh:487
bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt()
Definition: yaspgridentity.hh:626
int compressedIndex() const
consecutive, codim-wise, level-wise index
Definition: yaspgridentity.hh:376
bool isLeaf() const
Definition: yaspgridentity.hh:615
YaspEntity()
Definition: yaspgridentity.hh:321
Describes the minimal information necessary to create a fully functional YaspEntity.
Definition: yaspgrid.hh:61
YaspEntity(const YGLI &g, const I &it)
Definition: yaspgridentity.hh:324
LevelIntersectionIterator ilevelend() const
Reference to one past the last neighbor.
Definition: yaspgridentity.hh:660
YaspEntity()
Definition: yaspgridentity.hh:816
@ GhostEntity
ghost entities
Definition: gridenums.hh:33
unsigned int subEntities(unsigned int cc) const
Definition: yaspgridentity.hh:300
IntersectionIterator iend() const
Reference to one past the last neighbor.
Definition: yaspgridentity.hh:648
GridImp::template Codim< dim >::EntitySeed EntitySeed
Definition: yaspgridentity.hh:807
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition: yaspgridentity.hh:333
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition: yaspgridentity.hh:828
const YGLI & gridlevel() const
Definition: yaspgridentity.hh:610
GridImp::YGridLevelIterator YGLI
Definition: yaspgridentity.hh:319
unsigned int subEntities(unsigned int codim) const
Definition: yaspgridentity.hh:541
int level() const
level of this element
Definition: yaspgridentity.hh:482
unsigned int subEntities(unsigned int cc) const
Definition: yaspgridentity.hh:847
GridImp::YGridLevelIterator YGLI
Definition: yaspgridentity.hh:802
GridImp::YGrid::iTupel iTupel
define type used for coordinates in grid module
Definition: yaspgridentity.hh:457
LevelIntersectionIterator ilevelbegin() const
returns intersection iterator for first intersection
Definition: yaspgridentity.hh:642
YGLI _g
Definition: yaspgridentity.hh:942
int subCompressedIndex(int, unsigned int) const
subentity compressed index simply returns compressedIndex
Definition: yaspgridentity.hh:873
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition: yaspgridentity.hh:476
HierarchicIterator hbegin(int maxlevel) const
Definition: yaspgridentity.hh:669
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:16
int subCompressedIndex(int i, unsigned int cc) const
subentity compressed index
Definition: yaspgridentity.hh:382
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:28
YaspIntersectionIterator enables iteration over intersections with neighboring codim 0 entities.
Definition: yaspgrid.hh:63
persistent, globally unique Ids
Definition: yaspgrid.hh:67
@ BorderEntity
on boundary between interior and overlap
Definition: gridenums.hh:30
I _it
Definition: yaspgridentity.hh:941
GridImp::LevelIntersectionIterator LevelIntersectionIterator
Definition: yaspgridentity.hh:449
@ FrontEntity
on boundary between overlap and ghost
Definition: gridenums.hh:32
Default Implementations for EntityImp.
Definition: common/entity.hh:547
const YGLI & gridlevel() const
Definition: yaspgridentity.hh:935
LocalGeometry geometryInFather() const
Definition: yaspgridentity.hh:592
I & transformingsubiterator()
Definition: yaspgridentity.hh:611
int level() const
level of this element
Definition: yaspgridentity.hh:276
YaspEntity(const YGLI &g, const I &it)
Definition: yaspgridentity.hh:463
GridImp::PersistentIndexType PersistentIndexType
define the type used for persistent indices
Definition: yaspgridentity.hh:810
const GridImp * yaspgrid() const
Definition: yaspgridentity.hh:939
PersistentIndexType persistentIndex() const
globally unique, persistent index
Definition: yaspgridentity.hh:345
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: yaspgridentity.hh:839
bool hasFather() const
returns true if father entity exists
Definition: yaspgridentity.hh:585
YaspHierarchicIterator enables iteration over son entities of codim 0.
Definition: yaspgrid.hh:65
Iterates over entities of one grid level.
Definition: yaspgrid.hh:62
GridImp::YGrid::Iterator I
Definition: yaspgridentity.hh:320
GridImp::template Codim< codim >::Geometry Geometry
Definition: yaspgridentity.hh:270
const I & transformingsubiterator() const
Definition: yaspgridentity.hh:405
Include standard header files.
Definition: agrid.hh:58
GridImp::YGridLevelIterator YGLI
Definition: yaspgridentity.hh:434
GridImp::template Codim< 0 >::EntitySeed EntitySeed
Definition: yaspgridentity.hh:447
const int yaspgrid_dim_bits
Definition: yaspgrid.hh:51
GridImp::ctype ctype
Definition: yaspgridentity.hh:800
Definition: yaspgrid.hh:60
Geometry geometry() const
geometry of this entity
Definition: yaspgridentity.hh:503
GridImp::LeafIntersectionIterator LeafIntersectionIterator
Definition: yaspgridentity.hh:450
GridImp::template Codim< 0 >::LocalGeometry LocalGeometry
Definition: yaspgridentity.hh:438
const GridImp * yaspgrid() const
Definition: yaspgridentity.hh:409
YaspEntity()
Definition: yaspgridentity.hh:460
YGLI & gridlevel()
Definition: yaspgridentity.hh:612