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];
47 [[deprecated(
"Use binomial from dune-common's math.hh")]]
48 static constexpr int binomial(
int d,
int c)
51 for (
int i=d-c+1; i<=d; i++)
53 for (
long i=2; i<=c; i++)
60 BinomialTable() =
delete;
63 static constexpr int nextValue(
int& r,
int& c)
65 const auto result = Dune::binomial(r, c);
76 template<std::size_t... I>
77 static constexpr std::array<int,
sizeof...(I)> computeValues(std::index_sequence<I...>)
80 return {{ ((void)I, nextValue(r, c))... }};
83 template<std::size_t... I>
84 static constexpr std::array<int,
sizeof...(I)> computeOffsets(std::index_sequence<I...>)
85 {
return {{ (I*(I+1)/2)... }}; }
87 static constexpr std::array<int,(n+1)*(n+2)/2> _values = computeValues(std::make_index_sequence<(n+1)*(n+2)/2>{});
88 static constexpr std::array<int,n+1> _offsets = computeOffsets(std::make_index_sequence<n+1>{});
91#if __cplusplus < 201703L
93 constexpr std::array<int,(n+1)*(n+2)/2> BinomialTable<n>::_values;
95 constexpr std::array<int,n+1> BinomialTable<n>::_offsets;
104 template<
int dimworld>
105 constexpr int subEnt(
int d,
int c)
107 return (d < c ? 0 : BinomialTable<dimworld>::evaluate(d,c) << c);
112 template<
typename F,
int dim>
113 struct EntityShiftTable
115 typedef std::bitset<dim> value_type;
117 static value_type evaluate(
int i,
int codim)
119 return {_values[_offsets[codim] + i]};
125 EntityShiftTable() =
delete;
128 static constexpr int nextOffset(
int& offset,
int codim)
135 offset += subEnt<dim>(dim, codim-1);
139 template<std::size_t... I>
140 static constexpr std::array<int,
sizeof...(I)> computeOffsets(std::index_sequence<I...>)
143 return {{ (nextOffset(offset, I))... }};
147 static constexpr unsigned char nextValue(
int& codim,
int& i)
149 const auto result = F::evaluate(i, codim);
152 if (i >= subEnt<dim>(dim, codim)) {
160 template<std::size_t... I>
161 static constexpr std::array<
unsigned char,
sizeof...(I)> computeValues(std::index_sequence<I...>)
163 int codim = 0, i = 0;
164 return {{ ((void)I, nextValue(codim, i))... }};
167 static constexpr std::array<int,dim+1> _offsets = computeOffsets(std::make_index_sequence<dim+1>{});
168 static constexpr std::array<
unsigned char,Dune::power(3,dim)> _values = computeValues(std::make_index_sequence<Dune::power(3,dim)>{});
172#if __cplusplus < 201703L
173 template<
typename F,
int dim>
174 constexpr std::array<int,dim+1> EntityShiftTable<F, dim>::_offsets;
175 template<
typename F,
int dim>
176 constexpr std::array<
unsigned char,Dune::power(3,dim)> EntityShiftTable<F, dim>::_values;
181 struct calculate_entity_shift
183 static constexpr unsigned long long evaluate(
int index,
int cc)
186 for (
int d = dim; d>0; d--)
190 if (index < subEnt<dim>(d-1,cc))
191 result |= 1ull << (d-1);
194 index = (index - subEnt<dim>(d-1, cc)) % subEnt<dim>(d-1,cc-1);
211 std::bitset<dim> entityShift(
int index,
int cc)
213 return EntityShiftTable<calculate_entity_shift<dim>,dim>::evaluate(index,cc);
218 struct calculate_entity_move
220 static constexpr unsigned long long evaluate(
int index,
int cc)
223 for (
int d = dim; d>0; d--)
228 result &= ~(1ull << (d-1));
229 result |= index & (1ull << (d-1));
231 index &= ~(1<<(d-1));
233 if (index >= subEnt<dim>(d-1,cc))
235 if ((index - subEnt<dim>(d-1,cc)) / subEnt<dim>(d-1,cc-1) == 1)
237 result |= 1ull << (d-1);
239 index = (index - subEnt<dim>(d-1, cc)) % subEnt<dim>(d-1,cc-1);
256 std::bitset<dim> entityMove(
int index,
int cc)
258 return EntityShiftTable<calculate_entity_move<dim>,dim>::evaluate(index,cc);
265 template<
int codim,
int dim,
class Gr
idImp>
270 template<
int, PartitionIteratorType,
typename>
274 typedef typename GridImp::ctype
ctype;
276 typedef typename GridImp::template Codim<codim>::Geometry
Geometry;
277 typedef typename GridImp::Traits::template Codim<codim>::GeometryImpl
GeometryImpl;
279 typedef typename GridImp::template Codim<codim>::EntitySeed
EntitySeed;
316 return Dune::Yasp::subEnt<dim>(dim-codim,cc-codim);
322 if (
_g->interior[codim].inside(
_it.coord(),
_it.shift()))
324 if (
_g->interiorborder[codim].inside(
_it.coord(),
_it.shift()))
326 if (
_g->overlap[codim].inside(
_it.coord(),
_it.shift()))
328 if (
_g->overlapfront[codim].inside(
_it.coord(),
_it.shift()))
333 typedef typename GridImp::YGridLevelIterator
YGLI;
334 typedef typename GridImp::YGrid::Iterator
I;
362 std::array<int,dim> size;
364 for (
int i=0; i<dim; i++)
367 size[i] =
_g->mg->levelSize(
_g->level(), i);
380 for (
int i=dim-1; i>=0; i--)
392 return _it.superindex();
400 std::bitset<dim-codim> subent_shift = Dune::Yasp::entityShift<dim-codim>(i,cc-codim);
401 std::bitset<dim-codim> subent_move = Dune::Yasp::entityMove<dim-codim>(i,cc-codim);
403 std::bitset<dim> shift =
_it.shift();
404 std::array<int, dim> coord =
_it.coord();
405 for (
int j=0, k=0; j<dim; j++)
410 coord[j] += subent_move[k];
411 shift[j] = subent_shift[k];
415 int which =
_g->overlapfront[cc].shiftmapping(shift);
416 return _g->overlapfront[cc].superindex(coord,which);
431 template<
int dim,
class Gr
idImp>
435 constexpr static int dimworld = GridImp::dimensionworld;
437 typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl
GeometryImpl;
439 template<
int, PartitionIteratorType,
typename>
446 typedef typename GridImp::ctype
ctype;
448 typedef typename GridImp::YGridLevelIterator
YGLI;
449 typedef typename GridImp::YGrid::Iterator
I;
451 typedef typename GridImp::template Codim< 0 >::Geometry
Geometry;
461 typedef typename GridImp::template Codim<0>::EntitySeed
EntitySeed;
471 typedef typename GridImp::YGrid::iTupel
iTupel;
508 if (
_g->interior[0].inside(
_it.coord(),
_it.shift()))
510 if (
_g->overlap[0].inside(
_it.coord(),
_it.shift()))
512 DUNE_THROW(
GridError,
"Impossible GhostEntity");
519 auto ll =
_it.lowerleft();
520 auto ur =
_it.upperright();
523 for (
int i=0; i<dimworld; i++) {
527 auto size =
_g->mg->domainSize()[i];
531 auto size =
_g->mg->domainSize()[i];
538 GeometryImpl _geometry(ll,ur);
556 return Dune::Yasp::subEnt<dim>(dim,cc);
565 return Dune::Yasp::subEnt<dim>(dim,codim);
574 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
578 for (
int j=0; j<dim; j++)
582 int which =
_g->overlapfront[cc].shiftmapping(Dune::Yasp::entityShift<dim>(i,cc));
591 DUNE_THROW(
GridError,
"tried to call father on level 0");
601 for (
int k=0; k<dim; k++) coord[k] = coord[k]/2;
609 return (
_g->level()>0);
617 FieldVector<ctype,dim> ll(0.0),ur(0.5);
619 for (
int k=0; k<dim; k++)
639 return (
_g->level() ==
yaspgrid()->maxLevel());
720 for (
int i=dim-1; i>=0; i--)
732 return _it.superindex();
739 std::bitset<dim> shift = Dune::Yasp::entityShift<dim>(i,cc);
740 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
742 int trailing = (cc == dim) ? 1000 : 0;
744 std::array<int,dim> size =
_g->mg->levelSize(
_g->level());
745 std::array<int, dim> coord =
_it.coord();
746 for (
int j=0; j<dim; j++)
757 for (
int j=0; j<dim; j++)
763 for (
int k=0; k<
_g->level(); k++)
764 if (coord[j] & (1<<k))
768 trailing =
std::min(trailing,zeroes);
780 for (
int j=dim-1; j>=0; j--)
793 std::bitset<dim> shift = Dune::Yasp::entityShift<dim>(i,cc);
794 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
796 std::array<int, dim> coord =
_it.coord();
797 for (
int j=0; j<dim; j++)
800 int which =
_g->overlapfront[cc].shiftmapping(shift);
801 return _g->overlapfront[cc].superindex(coord,which);
810 template<
int dim,
class Gr
idImp>
814 constexpr static int dimworld = GridImp::dimensionworld;
816 template<
int, PartitionIteratorType,
typename>
819 typedef typename GridImp::Traits::template Codim<dim>::GeometryImpl
GeometryImpl;
822 typedef typename GridImp::ctype
ctype;
824 typedef typename GridImp::YGridLevelIterator
YGLI;
825 typedef typename GridImp::YGrid::Iterator
I;
827 typedef typename GridImp::template Codim<dim>::Geometry
Geometry;
829 typedef typename GridImp::template Codim<dim>::EntitySeed
EntitySeed;
835 typedef typename GridImp::YGrid::iTupel
iTupel;
871 return Dune::Yasp::subEnt<dim>(dim-dim,cc-dim);
876 GeometryImpl _geometry((
_it).lowerleft());
891 if (
_g->interior[dim].inside(
_it.coord(),
_it.shift()))
893 if (
_g->interiorborder[dim].inside(
_it.coord(),
_it.shift()))
895 if (
_g->overlap[dim].inside(
_it.coord(),
_it.shift()))
897 if (
_g->overlapfront[dim].inside(
_it.coord(),
_it.shift()))
918 iTupel size =
_g->mg->levelSize(
_g->level());
920 for (
int i=0; i<dim; i++)
928 for (
int i=0; i<dim; i++)
932 for (
int j=0; j<
_g->level(); j++)
933 if (
_it.coord(i)&(1<<j))
937 trailing =
std::min(trailing,zeros);
941 int level =
_g->level()-trailing;
951 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
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:348
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
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:268
int level() const
level of this element
Definition: yaspgridentity.hh:282
Geometry geometry() const
geometry of this entity
Definition: yaspgridentity.hh:296
GridImp::ctype ctype
Definition: yaspgridentity.hh:274
constexpr GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: yaspgridentity.hh:305
PersistentIndexType persistentIndex() const
globally unique, persistent index
Definition: yaspgridentity.hh:359
const YGLI & gridlevel() const
Definition: yaspgridentity.hh:420
const I & transformingsubiterator() const
Definition: yaspgridentity.hh:419
YGLI _g
Definition: yaspgridentity.hh:426
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition: yaspgridentity.hh:347
PartitionType partitionType() const
return partition type attribute
Definition: yaspgridentity.hh:320
GridImp::Traits::template Codim< codim >::GeometryImpl GeometryImpl
Definition: yaspgridentity.hh:277
YGLI & gridlevel()
Definition: yaspgridentity.hh:422
int subCompressedIndex(int i, unsigned int cc) const
subentity compressed index
Definition: yaspgridentity.hh:396
GridImp::YGridLevelIterator YGLI
Definition: yaspgridentity.hh:333
GridImp::YGrid::Iterator I
Definition: yaspgridentity.hh:334
const GridImp * yaspgrid() const
Definition: yaspgridentity.hh:423
GridImp::template Codim< codim >::EntitySeed EntitySeed
Definition: yaspgridentity.hh:279
YaspEntity(YGLI &&g, const I &&it)
Definition: yaspgridentity.hh:342
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: yaspgridentity.hh:290
int compressedIndex() const
consecutive, codim-wise, level-wise index
Definition: yaspgridentity.hh:390
YaspEntity(const YGLI &g, const I &it)
Definition: yaspgridentity.hh:338
I _it
Definition: yaspgridentity.hh:425
YaspEntity()
Definition: yaspgridentity.hh:335
GridImp::template Codim< codim >::Geometry Geometry
Definition: yaspgridentity.hh:276
GridImp::PersistentIndexType PersistentIndexType
Definition: yaspgridentity.hh:356
unsigned int subEntities(unsigned int cc) const
Definition: yaspgridentity.hh:314
I & transformingsubiterator()
Definition: yaspgridentity.hh:421
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
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
LeafIntersectionIterator ileafbegin() const
returns intersection iterator for first intersection
Definition: yaspgridentity.hh:657
GridImp::template Codim< 0 >::LocalGeometry LocalGeometry
Definition: yaspgridentity.hh:452
Codim< cc >::Entity subEntity(int i) const
Definition: yaspgridentity.hh:571
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition: yaspgridentity.hh:490
YaspEntity(const YGLI &g, I &&it)
Definition: yaspgridentity.hh:481
int count() const
Definition: yaspgridentity.hh:554
GridImp::template Codim< 0 >::EntitySeed EntitySeed
Definition: yaspgridentity.hh:461
GridImp::PersistentIndexType PersistentIndexType
define the type used for persistent indices
Definition: yaspgridentity.hh:468
GridImp::YGrid::iTupel iTupel
define type used for coordinates in grid module
Definition: yaspgridentity.hh:471
const YGLI & gridlevel() const
Definition: yaspgridentity.hh:632
IntersectionIterator iend() const
Reference to one past the last neighbor.
Definition: yaspgridentity.hh:670
const I & transformingsubiterator() const
Definition: yaspgridentity.hh:631
GridImp::ctype ctype
Definition: yaspgridentity.hh:446
YGLI & gridlevel()
Definition: yaspgridentity.hh:634
YaspEntity(const YGLI &g, const I &it)
Definition: yaspgridentity.hh:477
const GridImp * yaspgrid() const
Definition: yaspgridentity.hh:635
int level() const
level of this element
Definition: yaspgridentity.hh:496
GridImp::LeafIntersectionIterator LeafIntersectionIterator
Definition: yaspgridentity.hh:464
YaspEntity(YGLI &&g, I &&it)
Definition: yaspgridentity.hh:485
PartitionType partitionType() const
return partition type attribute
Definition: yaspgridentity.hh:506
LevelIntersectionIterator ilevelend() const
Reference to one past the last neighbor.
Definition: yaspgridentity.hh:682
bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt()
Definition: yaspgridentity.hh:648
GridImp::HierarchicIterator HierarchicIterator
Definition: yaspgridentity.hh:465
GridImp::template Codim< 0 >::Entity Entity
Definition: yaspgridentity.hh:460
LevelIntersectionIterator ilevelbegin() const
returns intersection iterator for first intersection
Definition: yaspgridentity.hh:664
LeafIntersectionIterator ileafend() const
Reference to one past the last neighbor.
Definition: yaspgridentity.hh:676
YaspEntity()
Definition: yaspgridentity.hh:474
GridImp::YGrid::Iterator I
Definition: yaspgridentity.hh:449
GridImp::template Codim< 0 >::Geometry Geometry
Definition: yaspgridentity.hh:451
Geometry geometry() const
geometry of this entity
Definition: yaspgridentity.hh:517
Entity father() const
Inter-level access to father element on coarser grid. Assumes that meshes are nested.
Definition: yaspgridentity.hh:587
bool isNew() const
Returns true, if the entity has been created during the last call to adapt()
Definition: yaspgridentity.hh:644
constexpr GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: yaspgridentity.hh:545
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: yaspgridentity.hh:501
HierarchicIterator hbegin(int maxlevel) const
Definition: yaspgridentity.hh:691
IntersectionIterator ibegin() const
returns intersection iterator for first intersection
Definition: yaspgridentity.hh:651
GridImp::YGridLevelIterator YGLI
Definition: yaspgridentity.hh:448
unsigned int subEntities(unsigned int codim) const
Definition: yaspgridentity.hh:563
LocalGeometry geometryInFather() const
Definition: yaspgridentity.hh:614
GridImp::LevelIntersectionIterator IntersectionIterator
Definition: yaspgridentity.hh:462
GridImp::LevelIntersectionIterator LevelIntersectionIterator
Definition: yaspgridentity.hh:463
I & transformingsubiterator()
Definition: yaspgridentity.hh:633
bool isLeaf() const
Definition: yaspgridentity.hh:637
bool hasFather() const
returns true if father entity exists
Definition: yaspgridentity.hh:607
GridImp::template Codim< cd >::Entity Entity
Definition: yaspgridentity.hh:457
int level() const
level of this element
Definition: yaspgridentity.hh:856
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition: yaspgridentity.hh:850
YGLI & gridlevel()
Definition: yaspgridentity.hh:967
Geometry geometry() const
geometry of this entity
Definition: yaspgridentity.hh:875
YaspEntity(const YGLI &g, const I &it)
Definition: yaspgridentity.hh:841
unsigned int subEntities(unsigned int cc) const
Definition: yaspgridentity.hh:869
PartitionType partitionType() const
return partition type attribute
Definition: yaspgridentity.hh:889
GridImp::ctype ctype
Definition: yaspgridentity.hh:822
GridImp::YGridLevelIterator YGLI
Definition: yaspgridentity.hh:824
GridImp::PersistentIndexType PersistentIndexType
define the type used for persistent indices
Definition: yaspgridentity.hh:832
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: yaspgridentity.hh:861
const GridImp * yaspgrid() const
Definition: yaspgridentity.hh:969
constexpr GeometryType type() const
Return the name of the reference element. The type can be used to access the Dune::ReferenceElement.
Definition: yaspgridentity.hh:883
GridImp::YGrid::Iterator I
Definition: yaspgridentity.hh:825
I & transformingsubiterator()
Definition: yaspgridentity.hh:966
const I & transformingsubiterator() const
Definition: yaspgridentity.hh:964
GridImp::YGrid::iTupel iTupel
define type used for coordinates in grid module
Definition: yaspgridentity.hh:835
GridImp::template Codim< dim >::Geometry Geometry
Definition: yaspgridentity.hh:827
const YGLI & gridlevel() const
Definition: yaspgridentity.hh:965
YaspEntity(YGLI &&g, I &&it)
Definition: yaspgridentity.hh:845
YaspEntity()
Definition: yaspgridentity.hh:838
GridImp::template Codim< dim >::EntitySeed EntitySeed
Definition: yaspgridentity.hh:829