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>::EntityPointer EntityPointer;
251 typedef typename GridImp::template Codim<codim>::EntitySeed EntitySeed;
262 EntitySeed seed()
const
264 return EntitySeed(YaspEntitySeed<codim,GridImp>(_g->level(), _it.coord(), _it.which()));
268 Geometry geometry ()
const
270 GeometryImpl _geometry(_it.lowerleft(),_it.upperright(),_it.shift());
271 return Geometry(_geometry);
277 if (_g->interior[codim].inside(_it.coord(),_it.shift()))
279 if (_g->interiorborder[codim].inside(_it.coord(),_it.shift()))
281 if (_g->overlap[codim].inside(_it.coord(),_it.shift()))
283 if (_g->overlapfront[codim].inside(_it.coord(),_it.shift()))
288 typedef typename GridImp::YGridLevelIterator YGLI;
289 typedef typename GridImp::YGrid::Iterator I;
293 YaspEntity (
const YGLI& g,
const I& it)
300#if not (defined(__GNUC__) && (__GNUC__ < 5) && (__GNUC_MINOR__ < 5))
302 YaspEntity (YGLI&& g,
const I&& it)
303 : _it(
std::move(it)), _g(
std::move(g))
309 bool equals (
const YaspEntity& e)
const
311 return _it == e._it && _g == e._g;
318 typedef typename GridImp::PersistentIndexType PersistentIndexType;
321 PersistentIndexType persistentIndex ()
const
324 Dune::array<int,dim> size;
326 for (
int i=0; i<dim; i++)
329 size[i] = _g->mg->levelSize(_g->level(), i);
335 PersistentIndexType
id(_it.shift().to_ulong());
338 id =
id << yaspgrid_level_bits;
339 id =
id+PersistentIndexType(_g->level());
342 for (
int i=dim-1; i>=0; i--)
344 id =
id << yaspgrid_dim_bits;
345 id =
id+PersistentIndexType(_it.coord(i));
352 int compressedIndex ()
const
354 return _it.superindex();
358 int subCompressedIndex (
int i,
unsigned int cc)
const
362 std::bitset<dim> ent_shift = _it.shift();
363 std::bitset<dim-codim> subent_shift = Dune::Yasp::entityShift<dim-codim>(i,cc);
364 std::bitset<dim-codim> subent_move = Dune::Yasp::entityMove<dim-codim>(i,cc);
366 std::bitset<dim> shift,move;
367 for (
int i=0,j=0; i<dim; i++)
370 shift[i] = subent_shift[j];
371 move[i] = subent_move[j];
375 Dune::array<int, dim> size = _g->mg->levelSize(_g->level());
376 Dune::array<int, dim> coord = _it.coord();
377 for (
int j=0; j<dim; j++)
385 int which = _g->overlapfront[cc].shiftmapping(shift);
386 return _g->overlapfront[cc].superindex(coord,which);
389 const I& transformingsubiterator()
const {
return _it; }
390 const YGLI& gridlevel()
const {
return _g; }
391 I& transformingsubiterator() {
return _it; }
392 YGLI& gridlevel() {
return _g; }
393 const GridImp * yaspgrid()
const {
return _g->mg; }
401 template<
int dim,
class Gr
idImp>
402 class YaspEntity<0,dim,GridImp>
403 :
public EntityDefaultImplementation <0,dim,GridImp,YaspEntity>
405 enum { dimworld = GridImp::dimensionworld };
407 typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl GeometryImpl;
409 template<
int, PartitionIteratorType,
typename>
410 friend class YaspLevelIterator;
413 friend class YaspHierarchicIterator;
416 typedef typename GridImp::ctype ctype;
418 typedef typename GridImp::YGridLevelIterator YGLI;
419 typedef typename GridImp::YGrid::Iterator I;
421 typedef typename GridImp::template Codim< 0 >::Geometry Geometry;
422 typedef typename GridImp::template Codim< 0 >::LocalGeometry LocalGeometry;
427 typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
428 typedef typename GridImp::template Codim<cd>::Entity Entity;
431 typedef typename GridImp::template Codim<0>::EntityPointer EntityPointer;
432 typedef typename GridImp::template Codim<0>::Entity Entity;
433 typedef typename GridImp::template Codim<0>::EntitySeed EntitySeed;
434 typedef typename GridImp::LevelIntersectionIterator IntersectionIterator;
435 typedef typename GridImp::LevelIntersectionIterator LevelIntersectionIterator;
436 typedef typename GridImp::LeafIntersectionIterator LeafIntersectionIterator;
437 typedef typename GridImp::HierarchicIterator HierarchicIterator;
440 typedef typename GridImp::PersistentIndexType PersistentIndexType;
443 typedef typename GridImp::YGrid::iTupel iTupel;
449 YaspEntity (
const YGLI& g,
const I& it)
453 YaspEntity (
const YGLI& g, I&& it)
454 : _it(
std::move(it)), _g(g)
460#if not (defined(__GNUC__) && (__GNUC__ < 5) && (__GNUC_MINOR__ < 5))
462 YaspEntity (YGLI&& g, I&& it)
463 : _it(
std::move(it)), _g(
std::move(g))
469 bool equals (
const YaspEntity& e)
const
471 return _it == e._it && _g == e._g;
475 int level ()
const {
return _g->level(); }
480 EntitySeed seed ()
const {
481 return EntitySeed(YaspEntitySeed<0,GridImp>(_g->level(), _it.coord()));
487 if (_g->interior[0].inside(_it.coord(),_it.shift()))
489 if (_g->overlap[0].inside(_it.coord(),_it.shift()))
491 DUNE_THROW(GridError,
"Impossible GhostEntity");
496 Geometry geometry ()
const {
498 auto ll = _it.lowerleft();
499 auto ur = _it.upperright();
502 for (
int i=0; i<dimworld; i++) {
503 if (gridlevel()->mg->isPeriodic(i)) {
504 int coord = transformingsubiterator().coord(i);
506 auto size = _g->mg->domainSize()[i];
509 }
else if (coord + 1 > gridlevel()->mg->levelSize(gridlevel()->level(),i)) {
510 auto size = _g->mg->domainSize()[i];
517 GeometryImpl _geometry(ll,ur);
518 return Geometry( _geometry );
525 template<
int cc>
int count ()
const
527 return Dune::Yasp::subEnt<dim>(dim,cc);
534 unsigned int subEntities (
unsigned int codim)
const
536 return Dune::Yasp::subEnt<dim>(dim,codim);
542 typename Codim<cc>::Entity subEntity (
int i)
const
545 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
548 iTupel coord = _it.coord();
549 for (
int j=0; j<dim; j++)
553 int which = _g->overlapfront[cc].shiftmapping(Dune::Yasp::entityShift<dim>(i,cc));
554 return typename Codim<cc>::Entity(YaspEntity<cc,GridImp::dimension,GridImp>(_g,_g->overlapfront[cc].begin(coord, which)));
558 Entity father ()
const
562 DUNE_THROW(GridError,
"tried to call father on level 0");
569 iTupel coord = _it.coord();
572 for (
int k=0; k<dim; k++) coord[k] = coord[k]/2;
574 return Entity(YaspEntity<0,GridImp::dimension,GridImp>(cg,cg->overlap[0].begin(coord)));
578 bool hasFather ()
const
580 return (_g->level()>0);
585 LocalGeometry geometryInFather ()
const
588 FieldVector<ctype,dim> ll(0.0),ur(0.5);
590 for (
int k=0; k<dim; k++)
599 return LocalGeometry( YaspGeometry<dim,dim,GridImp>(ll,ur) );
602 const I& transformingsubiterator ()
const {
return _it; }
603 const YGLI& gridlevel ()
const {
return _g; }
604 I& transformingsubiterator() {
return _it; }
605 YGLI& gridlevel() {
return _g; }
606 const GridImp* yaspgrid ()
const {
return _g->mg; }
610 return (_g->level() == yaspgrid()->maxLevel());
615 bool isNew ()
const {
return yaspgrid()->adaptRefCount > 0 && yaspgrid()->maxLevel() < _g->level() + yaspgrid()->adaptRefCount; }
619 bool mightVanish ()
const {
return false; }
622 IntersectionIterator ibegin ()
const
624 return YaspIntersectionIterator<GridImp>(*
this,
false);
628 LeafIntersectionIterator ileafbegin ()
const
631 return YaspIntersectionIterator<GridImp>(*
this, ! isLeaf() );
635 LevelIntersectionIterator ilevelbegin ()
const
641 IntersectionIterator iend ()
const
643 return YaspIntersectionIterator<GridImp>(*
this,
true);
647 LeafIntersectionIterator ileafend ()
const
653 LevelIntersectionIterator ilevelend ()
const
662 HierarchicIterator hbegin (
int maxlevel)
const
664 return YaspHierarchicIterator<GridImp>(_g,_it,maxlevel);
668 HierarchicIterator hend (
int maxlevel)
const
670 return YaspHierarchicIterator<GridImp>(_g,_it,_g->level());
680 PersistentIndexType persistentIndex ()
const
683 PersistentIndexType
id(_it.shift().to_ulong());
686 id =
id << yaspgrid_level_bits;
687 id =
id+PersistentIndexType(_g->level());
691 for (
int i=dim-1; i>=0; i--)
693 id =
id << yaspgrid_dim_bits;
694 id =
id+PersistentIndexType(_it.coord(i));
701 int compressedIndex ()
const
703 return _it.superindex();
707 PersistentIndexType subPersistentIndex (
int i,
int cc)
const
710 std::bitset<dim> shift = Dune::Yasp::entityShift<dim>(i,cc);
711 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
713 int trailing = (cc == dim) ? 1000 : 0;
715 Dune::array<int,dim> size = _g->mg->levelSize(_g->level());
716 Dune::array<int, dim> coord = _it.coord();
717 for (
int j=0; j<dim; j++)
728 for (
int j=0; j<dim; j++)
734 for (
int k=0; k<_g->level(); k++)
735 if (coord[j] & (1<<k))
739 trailing = std::min(trailing,zeroes);
744 PersistentIndexType
id(shift.to_ulong());
747 id =
id << yaspgrid_level_bits;
748 id =
id+PersistentIndexType(_g->level()-trailing);
751 for (
int j=dim-1; j>=0; j--)
753 id =
id << yaspgrid_dim_bits;
754 id =
id+PersistentIndexType(coord[j]>>trailing);
761 int subCompressedIndex (
int i,
int cc)
const
764 std::bitset<dim> shift = Dune::Yasp::entityShift<dim>(i,cc);
765 std::bitset<dim> move = Dune::Yasp::entityMove<dim>(i,cc);
767 Dune::array<int,dim> size = _g->mg->levelSize(_g->level());
768 Dune::array<int, dim> coord = _it.coord();
769 for (
int j=0; j<dim; j++)
772 size[j] += !shift[j];
776 int which = _g->overlapfront[cc].shiftmapping(shift);
777 return _g->overlapfront[cc].superindex(coord,which);
786 template<
int dim,
class Gr
idImp>
787 class YaspEntity<dim,dim,GridImp>
788 :
public EntityDefaultImplementation <dim,dim,GridImp,YaspEntity>
790 enum { dimworld = GridImp::dimensionworld };
792 template<
int, PartitionIteratorType,
typename>
793 friend class YaspLevelIterator;
795 typedef typename GridImp::Traits::template Codim<dim>::GeometryImpl GeometryImpl;
798 typedef typename GridImp::ctype ctype;
800 typedef typename GridImp::YGridLevelIterator YGLI;
801 typedef typename GridImp::YGrid::Iterator I;
803 typedef typename GridImp::template Codim<dim>::Geometry Geometry;
808 typedef typename GridImp::template Codim<cd>::EntityPointer EntityPointer;
811 typedef typename GridImp::template Codim<dim>::EntityPointer EntityPointer;
812 typedef typename GridImp::template Codim<dim>::EntitySeed EntitySeed;
815 typedef typename GridImp::PersistentIndexType PersistentIndexType;
818 typedef typename GridImp::YGrid::iTupel iTupel;
824 YaspEntity (
const YGLI& g,
const I& it)
831#if not (defined(__GNUC__) && (__GNUC__ < 5) && (__GNUC_MINOR__ < 5))
833 YaspEntity (YGLI&& g, I&& it)
834 : _it(
std::move(it)), _g(
std::move(g))
840 bool equals (
const YaspEntity& e)
const
842 return _it == e._it && _g == e._g;
846 int level ()
const {
return _g->level();}
851 EntitySeed seed ()
const {
852 return EntitySeed(YaspEntitySeed<dim,GridImp>(_g->level(), _it.coord(), _it.which()));
856 Geometry geometry ()
const {
857 GeometryImpl _geometry((_it).lowerleft());
858 return Geometry( _geometry );
864 if (_g->interior[dim].inside(_it.coord(),_it.shift()))
866 if (_g->interiorborder[dim].inside(_it.coord(),_it.shift()))
868 if (_g->overlap[dim].inside(_it.coord(),_it.shift()))
870 if (_g->overlapfront[dim].inside(_it.coord(),_it.shift()))
876 int subCompressedIndex (
int,
unsigned int )
const
878 return compressedIndex();
888 PersistentIndexType persistentIndex ()
const
891 iTupel size = _g->mg->levelSize(_g->level());
893 for (
int i=0; i<dim; i++)
901 for (
int i=0; i<dim; i++)
905 for (
int j=0; j<_g->level(); j++)
906 if (_it.coord(i)&(1<<j))
910 trailing = std::min(trailing,zeros);
914 int level = _g->level()-trailing;
917 PersistentIndexType
id(0);
920 id =
id << yaspgrid_level_bits;
921 id =
id+PersistentIndexType(level);
924 for (
int i=dim-1; i>=0; i--)
926 id =
id << yaspgrid_dim_bits;
927 id =
id+PersistentIndexType(_it.coord(i)>>trailing);
934 int compressedIndex ()
const {
return _it.superindex();}
937 const I& transformingsubiterator()
const {
return _it; }
938 const YGLI& gridlevel()
const {
return _g; }
939 I& transformingsubiterator() {
return _it; }
940 YGLI& gridlevel() {
return _g; }
942 const GridImp * yaspgrid()
const {
return _g->mg; }
persistent, globally unique Ids
Definition: yaspgrididset.hh:23
IdType id(const typename 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:243
int binomial(int upper, int lower)
calculate
Definition: simplex.cc:292
Dune namespace.
Definition: alignment.hh:10