3#ifndef DUNE_GRID_YASPGRIDENTITY_HH
4#define DUNE_GRID_YASPGRIDENTITY_HH
39 for (
int d = 0; d <= n; ++d)
42 for (
int c = 0; c <= d; ++c, ++offset)
43 _values[offset] = binomial(d,c);
50 static int evaluate(
int d,
int c)
52 return _values[_offsets[d] + c];
59 static bool _initialized;
60 static std::array<int,(n+1)*(n+2)/2> _values;
61 static std::array<int,n+1> _offsets;
66 static int binomial(
int d,
int c)
69 for (
int i=d-c+1; i<=d; i++)
71 for (
long i=2; i<=c; i++)
78 bool BinomialTable<n>::_initialized =
false;
80 std::array<int,(n+1)*(n+2)/2> BinomialTable<n>::_values;
82 std::array<int,n+1> BinomialTable<n>::_offsets;
90 template<
int dimworld>
91 int subEnt(
int d,
int c)
93 return (d < c ? 0 : BinomialTable<dimworld>::evaluate(d,c) << c);
98 template<
typename F,
int dim>
99 struct EntityShiftTable
102 typedef std::bitset<dim> value_type;
110 for (
int codim = 0; codim <= dim; ++codim)
112 _offsets[codim] = offset;
113 for (
int i = 0; i < subEnt<dim>(dim,codim); ++i, ++offset)
114 _values[offset] =
static_cast<unsigned char>(f(i,codim).to_ulong());
119 static value_type evaluate(
int i,
int codim)
121 return {_values[_offsets[codim] + i]};
129 static bool _initialized;
130 static std::array<int,dim+1> _offsets;
131 static std::array<unsigned char,StaticPower<3,dim>::power> _values;
135 template<
typename F,
int dim>
136 bool EntityShiftTable<F,dim>::_initialized =
false;
137 template<
typename F,
int dim>
138 std::array<int,dim+1> EntityShiftTable<F,dim>::_offsets;
139 template<
typename F,
int dim>
140 std::array<unsigned char,StaticPower<3,dim>::power> EntityShiftTable<F,dim>::_values;
144 struct calculate_entity_shift
146 calculate_entity_shift()
148 BinomialTable<dim>::init();
151 std::bitset<dim> operator()(
int index,
int cc)
const
153 std::bitset<dim> result(0ull);
154 for (
int d = dim; d>0; d--)
158 if (index < subEnt<dim>(d-1,cc))
162 index = (index - subEnt<dim>(d-1, cc)) % subEnt<dim>(d-1,cc-1);
179 std::bitset<dim> entityShift(
int index,
int cc)
181 return EntityShiftTable<calculate_entity_shift<dim>,dim>::evaluate(index,cc);
186 struct calculate_entity_move
189 calculate_entity_move()
191 BinomialTable<dim>::init();
194 std::bitset<dim> operator()(
int index,
int cc)
const
196 std::bitset<dim> result(0ull);
197 for (
int d = dim; d>0; d--)
201 result[d-1] = index & (1<<(d-1));
202 index &= ~(1<<(d-1));
204 if (index >= subEnt<dim>(d-1,cc))
206 if ((index - subEnt<dim>(d-1,cc)) / subEnt<dim>(d-1,cc-1) == 1)
210 index = (index - subEnt<dim>(d-1, cc)) % subEnt<dim>(d-1,cc-1);
227 std::bitset<dim> entityMove(
int index,
int cc)
229 return EntityShiftTable<calculate_entity_move<dim>,dim>::evaluate(index,cc);
236 template<
int codim,
int dim,
class Gr
idImp>
241 template<
int, PartitionIteratorType,
typename>
245 typedef typename GridImp::ctype
ctype;
247 typedef typename GridImp::template Codim<codim>::Geometry
Geometry;
248 typedef typename GridImp::Traits::template Codim<codim>::GeometryImpl
GeometryImpl;
250 typedef typename GridImp::template Codim<codim>::EntitySeed
EntitySeed;
276 if (
_g->interior[codim].inside(
_it.coord(),
_it.shift()))
278 if (
_g->interiorborder[codim].inside(
_it.coord(),
_it.shift()))
280 if (
_g->overlap[codim].inside(
_it.coord(),
_it.shift()))
282 if (
_g->overlapfront[codim].inside(
_it.coord(),
_it.shift()))
287 typedef typename GridImp::YGridLevelIterator
YGLI;
288 typedef typename GridImp::YGrid::Iterator
I;
299#if not (defined(__GNUC__) && (__GNUC__ < 5) && (__GNUC_MINOR__ < 5))
323 std::array<int,dim> size;
325 for (
int i=0; i<dim; i++)
328 size[i] =
_g->mg->levelSize(
_g->level(), i);
341 for (
int i=dim-1; i>=0; i--)
353 return _it.superindex();
361 std::bitset<dim> ent_shift =
_it.shift();
362 std::bitset<dim-codim> subent_shift = Dune::Yasp::entityShift<dim-codim>(i,cc);
363 std::bitset<dim-codim> subent_move = Dune::Yasp::entityMove<dim-codim>(i,cc);
365 std::bitset<dim> shift,move;
366 for (
int curDim=0,j=0; curDim < dim; curDim++)
367 if (ent_shift[curDim])
369 shift[curDim] = subent_shift[j];
370 move[curDim] = subent_move[j];
374 std::array<int, dim> size =
_g->mg->levelSize(
_g->level());
375 std::array<int, dim> coord =
_it.coord();
376 for (
int j=0; j<dim; j++)
384 int which =
_g->overlapfront[cc].shiftmapping(shift);
385 return _g->overlapfront[cc].superindex(coord,which);
400 template<
int dim,
class Gr
idImp>
404 enum { dimworld = GridImp::dimensionworld };
406 typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl
GeometryImpl;
408 template<
int, PartitionIteratorType,
typename>
415 typedef typename GridImp::ctype
ctype;
417 typedef typename GridImp::YGridLevelIterator
YGLI;
418 typedef typename GridImp::YGrid::Iterator
I;
420 typedef typename GridImp::template Codim< 0 >::Geometry
Geometry;
430 typedef typename GridImp::template Codim<0>::EntitySeed
EntitySeed;
440 typedef typename GridImp::YGrid::iTupel
iTupel;
457#if not (defined(__GNUC__) && (__GNUC__ < 5) && (__GNUC_MINOR__ < 5))
484 if (
_g->interior[0].inside(
_it.coord(),
_it.shift()))
486 if (
_g->overlap[0].inside(
_it.coord(),
_it.shift()))
488 DUNE_THROW(
GridError,
"Impossible GhostEntity");
495 auto ll =
_it.lowerleft();
496 auto ur =
_it.upperright();
499 for (
int i=0; i<dimworld; i++) {
503 auto size =
_g->mg->domainSize()[i];
507 auto size =
_g->mg->domainSize()[i];
514 GeometryImpl _geometry(ll,ur);
524 return Dune::Yasp::subEnt<dim>(dim,cc);
533 return Dune::Yasp::subEnt<dim>(dim,codim);
542 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
546 for (
int j=0; j<dim; j++)
550 int which =
_g->overlapfront[cc].shiftmapping(Dune::Yasp::entityShift<dim>(i,cc));
559 DUNE_THROW(
GridError,
"tried to call father on level 0");
569 for (
int k=0; k<dim; k++) coord[k] = coord[k]/2;
577 return (
_g->level()>0);
585 FieldVector<ctype,dim> ll(0.0),ur(0.5);
587 for (
int k=0; k<dim; k++)
607 return (
_g->level() ==
yaspgrid()->maxLevel());
688 for (
int i=dim-1; i>=0; i--)
700 return _it.superindex();
707 std::bitset<dim> shift = Dune::Yasp::entityShift<dim>(i,cc);
708 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
710 int trailing = (cc == dim) ? 1000 : 0;
712 std::array<int,dim> size =
_g->mg->levelSize(
_g->level());
713 std::array<int, dim> coord =
_it.coord();
714 for (
int j=0; j<dim; j++)
725 for (
int j=0; j<dim; j++)
731 for (
int k=0; k<
_g->level(); k++)
732 if (coord[j] & (1<<k))
736 trailing = std::min(trailing,zeroes);
748 for (
int j=dim-1; j>=0; j--)
761 std::bitset<dim> shift = Dune::Yasp::entityShift<dim>(i,cc);
762 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
764 std::array<int,dim> size =
_g->mg->levelSize(
_g->level());
765 std::array<int, dim> coord =
_it.coord();
766 for (
int j=0; j<dim; j++)
769 size[j] += !shift[j];
773 int which =
_g->overlapfront[cc].shiftmapping(shift);
774 return _g->overlapfront[cc].superindex(coord,which);
783 template<
int dim,
class Gr
idImp>
787 enum { dimworld = GridImp::dimensionworld };
789 template<
int, PartitionIteratorType,
typename>
792 typedef typename GridImp::Traits::template Codim<dim>::GeometryImpl
GeometryImpl;
795 typedef typename GridImp::ctype
ctype;
797 typedef typename GridImp::YGridLevelIterator
YGLI;
798 typedef typename GridImp::YGrid::Iterator
I;
800 typedef typename GridImp::template Codim<dim>::Geometry
Geometry;
802 typedef typename GridImp::template Codim<dim>::EntitySeed
EntitySeed;
808 typedef typename GridImp::YGrid::iTupel
iTupel;
821#if not (defined(__GNUC__) && (__GNUC__ < 5) && (__GNUC_MINOR__ < 5))
847 GeometryImpl _geometry((
_it).lowerleft());
854 if (
_g->interior[dim].inside(
_it.coord(),
_it.shift()))
856 if (
_g->interiorborder[dim].inside(
_it.coord(),
_it.shift()))
858 if (
_g->overlap[dim].inside(
_it.coord(),
_it.shift()))
860 if (
_g->overlapfront[dim].inside(
_it.coord(),
_it.shift()))
881 iTupel size =
_g->mg->levelSize(
_g->level());
883 for (
int i=0; i<dim; i++)
891 for (
int i=0; i<dim; i++)
895 for (
int j=0; j<
_g->level(); j++)
896 if (
_it.coord(i)&(1<<j))
900 trailing = std::min(trailing,zeros);
904 int level =
_g->level()-trailing;
914 for (
int i=dim-1; i>=0; i--)
PartitionType
Attributes used in the generic overlap model.
Definition gridenums.hh:28
@ FrontEntity
on boundary between overlap and ghost
Definition gridenums.hh:32
@ InteriorEntity
all interior entities
Definition gridenums.hh:29
@ GhostEntity
ghost entities
Definition gridenums.hh:33
@ BorderEntity
on boundary between interior and overlap
Definition gridenums.hh:30
@ OverlapEntity
all entities lying in the overlap zone
Definition gridenums.hh:31
Include standard header files.
Definition agrid.hh:60
const int yaspgrid_level_bits
Definition yaspgrid.hh:50
const int yaspgrid_dim_bits
Definition yaspgrid.hh:49
Default Implementations for EntityImp.
Definition common/entity.hh:544
Base class for exceptions in Dune grid modules.
Definition exceptions.hh:18
The general version that handles all codimensions but 0 and dim.
Definition yaspgridgeometry.hh:29
Definition yaspgridentity.hh:239
int level() const
level of this element
Definition yaspgridentity.hh:253
Geometry geometry() const
geometry of this entity
Definition yaspgridentity.hh:267
GridImp::ctype ctype
Definition yaspgridentity.hh:245
PersistentIndexType persistentIndex() const
globally unique, persistent index
Definition yaspgridentity.hh:320
const YGLI & gridlevel() const
Definition yaspgridentity.hh:389
const I & transformingsubiterator() const
Definition yaspgridentity.hh:388
YGLI _g
Definition yaspgridentity.hh:395
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition yaspgridentity.hh:308
PartitionType partitionType() const
return partition type attribute
Definition yaspgridentity.hh:274
GridImp::Traits::template Codim< codim >::GeometryImpl GeometryImpl
Definition yaspgridentity.hh:248
YGLI & gridlevel()
Definition yaspgridentity.hh:391
int subCompressedIndex(int i, unsigned int cc) const
subentity compressed index
Definition yaspgridentity.hh:357
GridImp::YGridLevelIterator YGLI
Definition yaspgridentity.hh:287
GridImp::YGrid::Iterator I
Definition yaspgridentity.hh:288
const GridImp * yaspgrid() const
Definition yaspgridentity.hh:392
GridImp::template Codim< codim >::EntitySeed EntitySeed
Definition yaspgridentity.hh:250
YaspEntity(YGLI &&g, const I &&it)
Definition yaspgridentity.hh:301
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition yaspgridentity.hh:261
int compressedIndex() const
consecutive, codim-wise, level-wise index
Definition yaspgridentity.hh:351
YaspEntity(const YGLI &g, const I &it)
Definition yaspgridentity.hh:292
I _it
Definition yaspgridentity.hh:394
YaspEntity()
Definition yaspgridentity.hh:289
GridImp::template Codim< codim >::Geometry Geometry
Definition yaspgridentity.hh:247
GridImp::PersistentIndexType PersistentIndexType
Definition yaspgridentity.hh:317
I & transformingsubiterator()
Definition yaspgridentity.hh:390
Describes the minimal information necessary to create a fully functional YaspEntity.
Definition yaspgridentityseed.hh:16
Iterates over entities of one grid level.
Definition yaspgridleveliterator.hh:18
YaspIntersectionIterator enables iteration over intersections with neighboring codim 0 entities.
Definition yaspgridintersectioniterator.hh:20
YaspHierarchicIterator enables iteration over son entities of codim 0.
Definition yaspgridhierarchiciterator.hh:19
Implementation of Level- and LeafIndexSets for YaspGrid.
Definition yaspgridindexsets.hh:23
persistent, globally unique Ids
Definition yaspgrididset.hh:23
LeafIntersectionIterator ileafbegin() const
returns intersection iterator for first intersection
Definition yaspgridentity.hh:625
GridImp::template Codim< 0 >::LocalGeometry LocalGeometry
Definition yaspgridentity.hh:421
Codim< cc >::Entity subEntity(int i) const
Definition yaspgridentity.hh:539
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition yaspgridentity.hh:466
YaspEntity(const YGLI &g, I &&it)
Definition yaspgridentity.hh:450
int count() const
Definition yaspgridentity.hh:522
GridImp::template Codim< 0 >::EntitySeed EntitySeed
Definition yaspgridentity.hh:430
GridImp::PersistentIndexType PersistentIndexType
define the type used for persistent indices
Definition yaspgridentity.hh:437
GridImp::YGrid::iTupel iTupel
define type used for coordinates in grid module
Definition yaspgridentity.hh:440
const YGLI & gridlevel() const
Definition yaspgridentity.hh:600
IntersectionIterator iend() const
Reference to one past the last neighbor.
Definition yaspgridentity.hh:638
const I & transformingsubiterator() const
Definition yaspgridentity.hh:599
GridImp::ctype ctype
Definition yaspgridentity.hh:415
YGLI & gridlevel()
Definition yaspgridentity.hh:602
YaspEntity(const YGLI &g, const I &it)
Definition yaspgridentity.hh:446
const GridImp * yaspgrid() const
Definition yaspgridentity.hh:603
int level() const
level of this element
Definition yaspgridentity.hh:472
GridImp::LeafIntersectionIterator LeafIntersectionIterator
Definition yaspgridentity.hh:433
YaspEntity(YGLI &&g, I &&it)
Definition yaspgridentity.hh:459
PartitionType partitionType() const
return partition type attribute
Definition yaspgridentity.hh:482
LevelIntersectionIterator ilevelend() const
Reference to one past the last neighbor.
Definition yaspgridentity.hh:650
bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt()
Definition yaspgridentity.hh:616
GridImp::HierarchicIterator HierarchicIterator
Definition yaspgridentity.hh:434
GridImp::template Codim< 0 >::Entity Entity
Definition yaspgridentity.hh:429
LevelIntersectionIterator ilevelbegin() const
returns intersection iterator for first intersection
Definition yaspgridentity.hh:632
LeafIntersectionIterator ileafend() const
Reference to one past the last neighbor.
Definition yaspgridentity.hh:644
YaspEntity()
Definition yaspgridentity.hh:443
GridImp::YGrid::Iterator I
Definition yaspgridentity.hh:418
GridImp::template Codim< 0 >::Geometry Geometry
Definition yaspgridentity.hh:420
Geometry geometry() const
geometry of this entity
Definition yaspgridentity.hh:493
Entity father() const
Inter-level access to father element on coarser grid. Assumes that meshes are nested.
Definition yaspgridentity.hh:555
bool isNew() const
Returns true, if the entity has been created during the last call to adapt()
Definition yaspgridentity.hh:612
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition yaspgridentity.hh:477
HierarchicIterator hbegin(int maxlevel) const
Definition yaspgridentity.hh:659
IntersectionIterator ibegin() const
returns intersection iterator for first intersection
Definition yaspgridentity.hh:619
GridImp::YGridLevelIterator YGLI
Definition yaspgridentity.hh:417
unsigned int subEntities(unsigned int codim) const
Definition yaspgridentity.hh:531
LocalGeometry geometryInFather() const
Definition yaspgridentity.hh:582
GridImp::LevelIntersectionIterator IntersectionIterator
Definition yaspgridentity.hh:431
GridImp::LevelIntersectionIterator LevelIntersectionIterator
Definition yaspgridentity.hh:432
I & transformingsubiterator()
Definition yaspgridentity.hh:601
bool isLeaf() const
Definition yaspgridentity.hh:605
bool hasFather() const
returns true if father entity exists
Definition yaspgridentity.hh:575
GridImp::template Codim< cd >::Entity Entity
Definition yaspgridentity.hh:426
int level() const
level of this element
Definition yaspgridentity.hh:836
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition yaspgridentity.hh:830
YGLI & gridlevel()
Definition yaspgridentity.hh:930
Geometry geometry() const
geometry of this entity
Definition yaspgridentity.hh:846
YaspEntity(const YGLI &g, const I &it)
Definition yaspgridentity.hh:814
PartitionType partitionType() const
return partition type attribute
Definition yaspgridentity.hh:852
YGLI _g
Definition yaspgridentity.hh:935
GridImp::ctype ctype
Definition yaspgridentity.hh:795
GridImp::YGridLevelIterator YGLI
Definition yaspgridentity.hh:797
GridImp::PersistentIndexType PersistentIndexType
define the type used for persistent indices
Definition yaspgridentity.hh:805
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition yaspgridentity.hh:841
const GridImp * yaspgrid() const
Definition yaspgridentity.hh:932
GridImp::YGrid::Iterator I
Definition yaspgridentity.hh:798
I & transformingsubiterator()
Definition yaspgridentity.hh:929
const I & transformingsubiterator() const
Definition yaspgridentity.hh:927
I _it
Definition yaspgridentity.hh:934
GridImp::YGrid::iTupel iTupel
define type used for coordinates in grid module
Definition yaspgridentity.hh:808
GridImp::template Codim< dim >::Geometry Geometry
Definition yaspgridentity.hh:800
const YGLI & gridlevel() const
Definition yaspgridentity.hh:928
YaspEntity(YGLI &&g, I &&it)
Definition yaspgridentity.hh:823
YaspEntity()
Definition yaspgridentity.hh:811
GridImp::template Codim< dim >::EntitySeed EntitySeed
Definition yaspgridentity.hh:802