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>
238 :
public EntityDefaultImplementation <codim,dim,GridImp,YaspEntity>
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;
269 GeometryImpl _geometry(_it.lowerleft(),_it.upperright(),_it.shift());
270 return Geometry(_geometry);
279 return Dune::Yasp::subEnt<dim>(dim-codim,cc-codim);
285 if (_g->interior[codim].inside(_it.coord(),_it.shift()))
287 if (_g->interiorborder[codim].inside(_it.coord(),_it.shift()))
289 if (_g->overlap[codim].inside(_it.coord(),_it.shift()))
291 if (_g->overlapfront[codim].inside(_it.coord(),_it.shift()))
296 typedef typename GridImp::YGridLevelIterator
YGLI;
297 typedef typename GridImp::YGrid::Iterator
I;
306 : _it(
std::move(it)), _g(
std::move(g))
312 return _it == e._it && _g == e._g;
325 std::array<int,dim> size;
327 for (
int i=0; i<dim; i++)
330 size[i] = _g->mg->levelSize(_g->level(), i);
336 PersistentIndexType
id(_it.shift().to_ulong());
340 id =
id+PersistentIndexType(_g->level());
343 for (
int i=dim-1; i>=0; i--)
346 id =
id+PersistentIndexType(_it.coord(i));
355 return _it.superindex();
363 std::bitset<dim> ent_shift = _it.shift();
364 std::bitset<dim-codim> subent_shift = Dune::Yasp::entityShift<dim-codim>(i,cc);
365 std::bitset<dim-codim> subent_move = Dune::Yasp::entityMove<dim-codim>(i,cc);
367 std::bitset<dim> shift,move;
368 for (
int curDim=0,j=0; curDim < dim; curDim++)
369 if (ent_shift[curDim])
371 shift[curDim] = subent_shift[j];
372 move[curDim] = subent_move[j];
376 std::array<int, dim> size = _g->mg->levelSize(_g->level());
377 std::array<int, dim> coord = _it.coord();
378 for (
int j=0; j<dim; j++)
386 int which = _g->overlapfront[cc].shiftmapping(shift);
387 return _g->overlapfront[cc].superindex(coord,which);
394 const GridImp *
yaspgrid()
const {
return _g->mg; }
402 template<
int dim,
class Gr
idImp>
406 enum { dimworld = GridImp::dimensionworld };
408 typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl GeometryImpl;
410 template<
int, PartitionIteratorType,
typename>
417 typedef typename GridImp::ctype
ctype;
419 typedef typename GridImp::YGridLevelIterator
YGLI;
420 typedef typename GridImp::YGrid::Iterator
I;
422 typedef typename GridImp::template Codim< 0 >::Geometry
Geometry;
432 typedef typename GridImp::template Codim<0>::EntitySeed
EntitySeed;
442 typedef typename GridImp::YGrid::iTupel
iTupel;
453 : _it(
std::move(it)), _g(g)
457 : _it(
std::move(it)), _g(
std::move(g))
463 return _it == e._it && _g == e._g;
467 int level ()
const {
return _g->level(); }
479 if (_g->interior[0].inside(_it.coord(),_it.shift()))
481 if (_g->overlap[0].inside(_it.coord(),_it.shift()))
483 DUNE_THROW(
GridError,
"Impossible GhostEntity");
490 auto ll = _it.lowerleft();
491 auto ur = _it.upperright();
494 for (
int i=0; i<dimworld; i++) {
495 if (gridlevel()->mg->isPeriodic(i)) {
496 int coord = transformingsubiterator().coord(i);
498 auto size = _g->mg->domainSize()[i];
501 }
else if (coord + 1 > gridlevel()->mg->levelSize(gridlevel()->level(),i)) {
502 auto size = _g->mg->domainSize()[i];
509 GeometryImpl _geometry(ll,ur);
510 return Geometry( _geometry );
519 return Dune::Yasp::subEnt<dim>(dim,cc);
528 return Dune::Yasp::subEnt<dim>(dim,codim);
537 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
540 iTupel coord = _it.coord();
541 for (
int j=0; j<dim; j++)
545 int which = _g->overlapfront[cc].shiftmapping(Dune::Yasp::entityShift<dim>(i,cc));
554 DUNE_THROW(
GridError,
"tried to call father on level 0");
561 iTupel coord = _it.coord();
564 for (
int k=0; k<dim; k++) coord[k] = coord[k]/2;
572 return (_g->level()>0);
580 FieldVector<ctype,dim> ll(0.0),ur(0.5);
582 for (
int k=0; k<dim; k++)
598 const GridImp*
yaspgrid ()
const {
return _g->mg; }
602 return (_g->level() == yaspgrid()->maxLevel());
607 bool isNew ()
const {
return yaspgrid()->adaptRefCount > 0 && yaspgrid()->maxLevel() < _g->level() + yaspgrid()->adaptRefCount; }
633 IntersectionIterator
iend ()
const 654 HierarchicIterator
hbegin (
int maxlevel)
const 660 HierarchicIterator
hend (
int maxlevel)
const 672 PersistentIndexType persistentIndex ()
const 675 PersistentIndexType
id(_it.shift().to_ulong());
679 id =
id+PersistentIndexType(_g->level());
683 for (
int i=dim-1; i>=0; i--)
686 id =
id+PersistentIndexType(_it.coord(i));
693 int compressedIndex ()
const 695 return _it.superindex();
699 PersistentIndexType subPersistentIndex (
int i,
int cc)
const 702 std::bitset<dim> shift = Dune::Yasp::entityShift<dim>(i,cc);
703 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
705 int trailing = (cc == dim) ? 1000 : 0;
707 std::array<int,dim> size = _g->mg->levelSize(_g->level());
708 std::array<int, dim> coord = _it.coord();
709 for (
int j=0; j<dim; j++)
720 for (
int j=0; j<dim; j++)
726 for (
int k=0; k<_g->level(); k++)
727 if (coord[j] & (1<<k))
731 trailing =
std::min(trailing,zeroes);
736 PersistentIndexType
id(shift.to_ulong());
740 id =
id+PersistentIndexType(_g->level()-trailing);
743 for (
int j=dim-1; j>=0; j--)
746 id =
id+PersistentIndexType(coord[j]>>trailing);
753 int subCompressedIndex (
int i,
int cc)
const 756 std::bitset<dim> shift = Dune::Yasp::entityShift<dim>(i,cc);
757 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
759 std::array<int,dim> size = _g->mg->levelSize(_g->level());
760 std::array<int, dim> coord = _it.coord();
761 for (
int j=0; j<dim; j++)
764 size[j] += !shift[j];
768 int which = _g->overlapfront[cc].shiftmapping(shift);
769 return _g->overlapfront[cc].superindex(coord,which);
778 template<
int dim,
class Gr
idImp>
782 enum { dimworld = GridImp::dimensionworld };
784 template<
int, PartitionIteratorType,
typename>
787 typedef typename GridImp::Traits::template Codim<dim>::GeometryImpl GeometryImpl;
790 typedef typename GridImp::ctype
ctype;
792 typedef typename GridImp::YGridLevelIterator
YGLI;
793 typedef typename GridImp::YGrid::Iterator
I;
795 typedef typename GridImp::template Codim<dim>::Geometry
Geometry;
797 typedef typename GridImp::template Codim<dim>::EntitySeed
EntitySeed;
803 typedef typename GridImp::YGrid::iTupel
iTupel;
814 : _it(
std::move(it)), _g(
std::move(g))
820 return _it == e._it && _g == e._g;
824 int level ()
const {
return _g->level();}
839 return Dune::Yasp::subEnt<dim>(dim-dim,cc-dim);
844 GeometryImpl _geometry((_it).lowerleft());
845 return Geometry( _geometry );
851 if (_g->interior[dim].inside(_it.coord(),_it.shift()))
853 if (_g->interiorborder[dim].inside(_it.coord(),_it.shift()))
855 if (_g->overlap[dim].inside(_it.coord(),_it.shift()))
857 if (_g->overlapfront[dim].inside(_it.coord(),_it.shift()))
865 return compressedIndex();
875 PersistentIndexType persistentIndex ()
const 878 iTupel size = _g->mg->levelSize(_g->level());
880 for (
int i=0; i<dim; i++)
888 for (
int i=0; i<dim; i++)
892 for (
int j=0; j<_g->level(); j++)
893 if (_it.coord(i)&(1<<j))
897 trailing =
std::min(trailing,zeros);
901 int level = _g->level()-trailing;
904 PersistentIndexType
id(0);
908 id =
id+PersistentIndexType(level);
911 for (
int i=dim-1; i>=0; i--)
914 id =
id+PersistentIndexType(_it.coord(i)>>trailing);
921 int compressedIndex ()
const {
return _it.superindex();}
929 const GridImp *
yaspgrid()
const {
return _g->mg; }
937 #endif // DUNE_GRID_YASPGRIDENTITY_HH GridImp::YGrid::Iterator I
Definition: yaspgridentity.hh:297
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: yaspgridentity.hh:829
const GridImp * yaspgrid() const
Definition: yaspgridentity.hh:394
LevelIntersectionIterator ilevelend() const
Reference to one past the last neighbor.
Definition: yaspgridentity.hh:645
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition: yaspgridentity.hh:461
unsigned int subEntities(unsigned int cc) const
Definition: yaspgridentity.hh:837
all entities lying in the overlap zone
Definition: gridenums.hh:31
GridImp::template Codim< 0 >::Geometry Geometry
Definition: yaspgridentity.hh:422
I _it
Definition: yaspgridentity.hh:396
LeafIntersectionIterator ileafend() const
Reference to one past the last neighbor.
Definition: yaspgridentity.hh:639
YaspEntity(const YGLI &g, const I &it)
Definition: yaspgridentity.hh:448
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:16
YaspEntity(YGLI &&g, I &&it)
Definition: yaspgridentity.hh:813
HierarchicIterator hend(int maxlevel) const
Returns iterator to one past the last son.
Definition: yaspgridentity.hh:660
unsigned int subEntities(unsigned int codim) const
Definition: yaspgridentity.hh:526
ghost entities
Definition: gridenums.hh:33
bool hasFather() const
returns true if father entity exists
Definition: yaspgridentity.hh:570
const I & transformingsubiterator() const
Definition: yaspgridentity.hh:390
GridImp::ctype ctype
Definition: yaspgridentity.hh:417
I & transformingsubiterator()
Definition: yaspgridentity.hh:392
int subCompressedIndex(int i, unsigned int cc) const
subentity compressed index
Definition: yaspgridentity.hh:359
GridImp::YGridLevelIterator YGLI
Definition: yaspgridentity.hh:296
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:28
GridImp::Traits::template Codim< codim >::GeometryImpl GeometryImpl
Definition: yaspgridentity.hh:248
GridImp::PersistentIndexType PersistentIndexType
Definition: yaspgridentity.hh:319
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition: yaspgridentity.hh:818
PartitionType partitionType() const
return partition type attribute
Definition: yaspgridentity.hh:849
I & transformingsubiterator()
Definition: yaspgridentity.hh:596
GridImp::template Codim< codim >::Geometry Geometry
Definition: yaspgridentity.hh:247
GridImp::template Codim< 0 >::EntitySeed EntitySeed
Definition: yaspgridentity.hh:432
YGLI _g
Definition: yaspgridentity.hh:932
on boundary between interior and overlap
Definition: gridenums.hh:30
Geometry geometry() const
geometry of this entity
Definition: yaspgridentity.hh:267
YGLI & gridlevel()
Definition: yaspgridentity.hh:597
GridImp::LevelIntersectionIterator LevelIntersectionIterator
Definition: yaspgridentity.hh:434
YaspEntity()
Definition: yaspgridentity.hh:806
YaspEntity()
Definition: yaspgridentity.hh:445
YGLI & gridlevel()
Definition: yaspgridentity.hh:927
int level() const
level of this element
Definition: yaspgridentity.hh:253
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:346
GridImp::YGrid::iTupel iTupel
define type used for coordinates in grid module
Definition: yaspgridentity.hh:442
GridImp::LeafIntersectionIterator LeafIntersectionIterator
Definition: yaspgridentity.hh:435
Geometry geometry() const
geometry of this entity
Definition: yaspgridentity.hh:488
GridImp::YGrid::Iterator I
Definition: yaspgridentity.hh:793
int subCompressedIndex(int, unsigned int) const
subentity compressed index simply returns compressedIndex
Definition: yaspgridentity.hh:863
GridImp::template Codim< 0 >::LocalGeometry LocalGeometry
Definition: yaspgridentity.hh:423
const GridImp * yaspgrid() const
Definition: yaspgridentity.hh:598
GridImp::YGridLevelIterator YGLI
Definition: yaspgridentity.hh:792
YaspEntity(YGLI &&g, const I &&it)
Definition: yaspgridentity.hh:305
bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt()
Definition: yaspgridentity.hh:611
bool isLeaf() const
Definition: yaspgridentity.hh:600
GridImp::PersistentIndexType PersistentIndexType
define the type used for persistent indices
Definition: yaspgridentity.hh:800
bool isNew() const
Returns true, if the entity has been created during the last call to adapt()
Definition: yaspgridentity.hh:607
PartitionType partitionType() const
return partition type attribute
Definition: yaspgridentity.hh:283
YaspEntity(const YGLI &g, const I &it)
Definition: yaspgridentity.hh:809
GridImp::YGrid::iTupel iTupel
define type used for coordinates in grid module
Definition: yaspgridentity.hh:803
YGLI & gridlevel()
Definition: yaspgridentity.hh:393
LevelIntersectionIterator ilevelbegin() const
returns intersection iterator for first intersection
Definition: yaspgridentity.hh:627
int level() const
level of this element
Definition: yaspgridentity.hh:467
YaspHierarchicIterator enables iteration over son entities of codim 0.
Definition: yaspgrid.hh:64
on boundary between overlap and ghost
Definition: gridenums.hh:32
unsigned int subEntities(unsigned int cc) const
Definition: yaspgridentity.hh:277
const YGLI & gridlevel() const
Definition: yaspgridentity.hh:391
GridImp::YGrid::Iterator I
Definition: yaspgridentity.hh:420
int compressedIndex() const
consecutive, codim-wise, level-wise index
Definition: yaspgridentity.hh:353
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: yaspgridentity.hh:261
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
I & transformingsubiterator()
Definition: yaspgridentity.hh:926
Default Implementations for EntityImp.
Definition: common/entity.hh:568
int level() const
level of this element
Definition: yaspgridentity.hh:824
const int yaspgrid_dim_bits
Definition: yaspgrid.hh:49
Geometry geometry() const
geometry of this entity
Definition: yaspgridentity.hh:843
const YGLI & gridlevel() const
Definition: yaspgridentity.hh:925
GridImp::HierarchicIterator HierarchicIterator
Definition: yaspgridentity.hh:436
const int yaspgrid_level_bits
Definition: yaspgrid.hh:50
const I & transformingsubiterator() const
Definition: yaspgridentity.hh:924
Entity father() const
Inter-level access to father element on coarser grid. Assumes that meshes are nested.
Definition: yaspgridentity.hh:550
int count() const
Definition: yaspgridentity.hh:517
Include standard header files.
Definition: agrid.hh:59
PartitionType partitionType() const
return partition type attribute
Definition: yaspgridentity.hh:477
GridImp::YGridLevelIterator YGLI
Definition: yaspgridentity.hh:419
Iterates over entities of one grid level.
Definition: yaspgrid.hh:61
GridImp::ctype ctype
Definition: yaspgridentity.hh:245
GridImp::template Codim< 0 >::Entity Entity
Definition: yaspgridentity.hh:431
YaspEntity(YGLI &&g, I &&it)
Definition: yaspgridentity.hh:456
Definition: yaspgrid.hh:58
GridImp::template Codim< cd >::Entity Entity
Definition: yaspgridentity.hh:428
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: yaspgridentity.hh:472
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition: yaspgridentity.hh:310
IntersectionIterator iend() const
Reference to one past the last neighbor.
Definition: yaspgridentity.hh:633
persistent, globally unique Ids
Definition: yaspgrid.hh:66
int level() const
ask for level of entity
Definition: yaspgridentitypointer.hh:72
YaspEntity(const YGLI &g, I &&it)
Definition: yaspgridentity.hh:452
const I & transformingsubiterator() const
Definition: yaspgridentity.hh:594
PersistentIndexType persistentIndex() const
globally unique, persistent index
Definition: yaspgridentity.hh:322
Describes the minimal information necessary to create a fully functional YaspEntity.
Definition: yaspgrid.hh:60
The general version that handles all codimensions but 0 and dim.
Definition: yaspgrid.hh:57
IntersectionIterator ibegin() const
returns intersection iterator for first intersection
Definition: yaspgridentity.hh:614
YaspEntity()
Definition: yaspgridentity.hh:298
const GridImp * yaspgrid() const
Definition: yaspgridentity.hh:929
all interior entities
Definition: gridenums.hh:29
GridImp::template Codim< dim >::Geometry Geometry
Definition: yaspgridentity.hh:795
LeafIntersectionIterator ileafbegin() const
returns intersection iterator for first intersection
Definition: yaspgridentity.hh:620
Codim< cc >::Entity subEntity(int i) const
Definition: yaspgridentity.hh:534
GridImp::ctype ctype
Definition: yaspgridentity.hh:790
YaspEntity(const YGLI &g, const I &it)
Definition: yaspgridentity.hh:301
I _it
Definition: yaspgridentity.hh:931
Implementation of Level- and LeafIndexSets for YaspGrid.
Definition: yaspgrid.hh:65
const YGLI & gridlevel() const
Definition: yaspgridentity.hh:595
HierarchicIterator hbegin(int maxlevel) const
Definition: yaspgridentity.hh:654
LocalGeometry geometryInFather() const
Definition: yaspgridentity.hh:577
YaspIntersectionIterator enables iteration over intersections with neighboring codim 0 entities...
Definition: yaspgrid.hh:62
GridImp::template Codim< codim >::EntitySeed EntitySeed
Definition: yaspgridentity.hh:250
GridImp::LevelIntersectionIterator IntersectionIterator
Definition: yaspgridentity.hh:433
GridImp::PersistentIndexType PersistentIndexType
define the type used for persistent indices
Definition: yaspgridentity.hh:439
YGLI _g
Definition: yaspgridentity.hh:397
GridImp::template Codim< dim >::EntitySeed EntitySeed
Definition: yaspgridentity.hh:797