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)
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;
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>
242 friend class YaspLevelIterator;
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;
261 EntitySeed seed()
const
263 return EntitySeed(YaspEntitySeed<codim,GridImp>(_g->level(), _it.coord(), _it.which()));
267 Geometry geometry ()
const
269 GeometryImpl _geometry(_it.lowerleft(),_it.upperright(),_it.shift());
270 return Geometry(_geometry);
277 unsigned int subEntities (
unsigned int cc)
const
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;
301 YaspEntity (
const YGLI& g,
const I& it)
305 YaspEntity (YGLI&& g,
const I&& it)
306 : _it(
std::move(it)), _g(
std::move(g))
310 bool equals (
const YaspEntity& e)
const
312 return _it == e._it && _g == e._g;
319 typedef typename GridImp::PersistentIndexType PersistentIndexType;
322 PersistentIndexType persistentIndex ()
const
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());
339 id =
id << yaspgrid_level_bits;
340 id =
id+PersistentIndexType(_g->level());
343 for (
int i=dim-1; i>=0; i--)
345 id =
id << yaspgrid_dim_bits;
346 id =
id+PersistentIndexType(_it.coord(i));
353 int compressedIndex ()
const
355 return _it.superindex();
359 int subCompressedIndex (
int i,
unsigned int cc)
const
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);
390 const I& transformingsubiterator()
const {
return _it; }
391 const YGLI& gridlevel()
const {
return _g; }
392 I& transformingsubiterator() {
return _it; }
393 YGLI& gridlevel() {
return _g; }
394 const GridImp * yaspgrid()
const {
return _g->mg; }
402 template<
int dim,
class Gr
idImp>
403 class YaspEntity<0,dim,GridImp>
404 :
public EntityDefaultImplementation <0,dim,GridImp,YaspEntity>
406 enum { dimworld = GridImp::dimensionworld };
408 typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl GeometryImpl;
410 template<
int, PartitionIteratorType,
typename>
411 friend class YaspLevelIterator;
414 friend class YaspHierarchicIterator;
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;
423 typedef typename GridImp::template Codim< 0 >::LocalGeometry LocalGeometry;
428 typedef typename GridImp::template Codim<cd>::Entity Entity;
431 typedef typename GridImp::template Codim<0>::Entity Entity;
432 typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
433 typedef typename GridImp::LevelIntersectionIterator IntersectionIterator;
434 typedef typename GridImp::LevelIntersectionIterator LevelIntersectionIterator;
435 typedef typename GridImp::LeafIntersectionIterator LeafIntersectionIterator;
436 typedef typename GridImp::HierarchicIterator HierarchicIterator;
439 typedef typename GridImp::PersistentIndexType PersistentIndexType;
442 typedef typename GridImp::YGrid::iTupel iTupel;
448 YaspEntity (
const YGLI& g,
const I& it)
452 YaspEntity (
const YGLI& g, I&& it)
453 : _it(
std::move(it)), _g(g)
456 YaspEntity (YGLI&& g, I&& it)
457 : _it(
std::move(it)), _g(
std::move(g))
461 bool equals (
const YaspEntity& e)
const
463 return _it == e._it && _g == e._g;
467 int level ()
const {
return _g->level(); }
472 EntitySeed seed ()
const {
473 return EntitySeed(YaspEntitySeed<0,GridImp>(_g->level(), _it.coord()));
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");
488 Geometry geometry ()
const {
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 );
517 template<
int cc>
int count ()
const
519 return Dune::Yasp::subEnt<dim>(dim,cc);
526 unsigned int subEntities (
unsigned int codim)
const
528 return Dune::Yasp::subEnt<dim>(dim,codim);
534 typename Codim<cc>::Entity subEntity (
int i)
const
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));
546 return typename Codim<cc>::Entity(YaspEntity<cc,GridImp::dimension,GridImp>(_g,_g->overlapfront[cc].begin(coord, which)));
550 Entity father ()
const
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;
566 return Entity(YaspEntity<0,GridImp::dimension,GridImp>(cg,cg->overlap[0].begin(coord)));
570 bool hasFather ()
const
572 return (_g->level()>0);
577 LocalGeometry geometryInFather ()
const
580 FieldVector<ctype,dim> ll(0.0),ur(0.5);
582 for (
int k=0; k<dim; k++)
591 return LocalGeometry( YaspGeometry<dim,dim,GridImp>(ll,ur) );
594 const I& transformingsubiterator ()
const {
return _it; }
595 const YGLI& gridlevel ()
const {
return _g; }
596 I& transformingsubiterator() {
return _it; }
597 YGLI& gridlevel() {
return _g; }
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; }
611 bool mightVanish ()
const {
return false; }
614 IntersectionIterator ibegin ()
const
616 return YaspIntersectionIterator<GridImp>(*
this,
false);
620 LeafIntersectionIterator ileafbegin ()
const
623 return YaspIntersectionIterator<GridImp>(*
this, ! isLeaf() );
627 LevelIntersectionIterator ilevelbegin ()
const
633 IntersectionIterator iend ()
const
635 return YaspIntersectionIterator<GridImp>(*
this,
true);
639 LeafIntersectionIterator ileafend ()
const
645 LevelIntersectionIterator ilevelend ()
const
654 HierarchicIterator hbegin (
int maxlevel)
const
656 return YaspHierarchicIterator<GridImp>(_g,_it,maxlevel);
660 HierarchicIterator hend (
int maxlevel)
const
662 return YaspHierarchicIterator<GridImp>(_g,_it,_g->level());
672 PersistentIndexType persistentIndex ()
const
675 PersistentIndexType
id(_it.shift().to_ulong());
678 id =
id << yaspgrid_level_bits;
679 id =
id+PersistentIndexType(_g->level());
683 for (
int i=dim-1; i>=0; i--)
685 id =
id << yaspgrid_dim_bits;
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());
739 id =
id << yaspgrid_level_bits;
740 id =
id+PersistentIndexType(_g->level()-trailing);
743 for (
int j=dim-1; j>=0; j--)
745 id =
id << yaspgrid_dim_bits;
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>
779 class YaspEntity<dim,dim,GridImp>
780 :
public EntityDefaultImplementation <dim,dim,GridImp,YaspEntity>
782 enum { dimworld = GridImp::dimensionworld };
784 template<
int, PartitionIteratorType,
typename>
785 friend class YaspLevelIterator;
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;
800 typedef typename GridImp::PersistentIndexType PersistentIndexType;
803 typedef typename GridImp::YGrid::iTupel iTupel;
809 YaspEntity (
const YGLI& g,
const I& it)
813 YaspEntity (YGLI&& g, I&& it)
814 : _it(
std::move(it)), _g(
std::move(g))
818 bool equals (
const YaspEntity& e)
const
820 return _it == e._it && _g == e._g;
824 int level ()
const {
return _g->level();}
829 EntitySeed seed ()
const {
830 return EntitySeed(YaspEntitySeed<dim,GridImp>(_g->level(), _it.coord(), _it.which()));
837 unsigned int subEntities (
unsigned int cc)
const
839 return Dune::Yasp::subEnt<dim>(dim-dim,cc-dim);
843 Geometry geometry ()
const {
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()))
863 int subCompressedIndex (
int,
unsigned int )
const
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);
907 id =
id << yaspgrid_level_bits;
908 id =
id+PersistentIndexType(level);
911 for (
int i=dim-1; i>=0; i--)
913 id =
id << yaspgrid_dim_bits;
914 id =
id+PersistentIndexType(_it.coord(i)>>trailing);
921 int compressedIndex ()
const {
return _it.superindex();}
924 const I& transformingsubiterator()
const {
return _it; }
925 const YGLI& gridlevel()
const {
return _g; }
926 I& transformingsubiterator() {
return _it; }
927 YGLI& gridlevel() {
return _g; }
929 const GridImp * yaspgrid()
const {
return _g->mg; }
persistent, globally unique Ids
Definition: yaspgrididset.hh:23
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
Implementation of Level- and LeafIndexSets for YaspGrid.
Definition: yaspgridindexsets.hh:23
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
constexpr auto equals(T1 &&t1, T2 &&t2)
Equality comparison.
Definition: hybridutilities.hh:441
int binomial(int upper, int lower)
calculate
Definition: simplex.cc:294
Dune namespace.
Definition: alignment.hh:11