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>::EntityPointer
EntityPointer;
251 typedef typename GridImp::template Codim<codim>::EntitySeed
EntitySeed;
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;
300 #if not (defined(__GNUC__) && (__GNUC__ < 5) && (__GNUC_MINOR__ < 5))
311 return _it == e._it &&
_g == e._g;
324 Dune::array<int,dim> size;
326 for (
int i=0; i<dim; i++)
329 size[i] =
_g->mg->levelSize(
_g->level(), i);
342 for (
int i=dim-1; i>=0; i--)
354 return _it.superindex();
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);
401 template<
int dim,
class Gr
idImp>
405 enum { dimworld = GridImp::dimensionworld };
407 typedef typename GridImp::Traits::template Codim< 0 >::GeometryImpl
GeometryImpl;
409 template<
int, PartitionIteratorType,
typename>
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;
433 typedef typename GridImp::template Codim<0>::EntitySeed
EntitySeed;
443 typedef typename GridImp::YGrid::iTupel
iTupel;
460 #if not (defined(__GNUC__) && (__GNUC__ < 5) && (__GNUC_MINOR__ < 5))
471 return _it == e._it &&
_g == e._g;
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");
498 auto ll =
_it.lowerleft();
499 auto ur =
_it.upperright();
502 for (
int i=0; i<dimworld; i++) {
506 auto size =
_g->mg->domainSize()[i];
510 auto size =
_g->mg->domainSize()[i];
517 GeometryImpl _geometry(ll,ur);
527 return Dune::Yasp::subEnt<dim>(dim,cc);
536 return Dune::Yasp::subEnt<dim>(dim,codim);
545 std::bitset<dim>
move = Dune::Yasp::entityMove<dim>(i,cc);
549 for (
int j=0; j<dim; j++)
553 int which =
_g->overlapfront[cc].shiftmapping(Dune::Yasp::entityShift<dim>(i,cc));
562 DUNE_THROW(
GridError,
"tried to call father on level 0");
572 for (
int k=0; k<dim; k++) coord[k] = coord[k]/2;
580 return (
_g->level()>0);
588 FieldVector<ctype,dim> ll(0.0),ur(0.5);
590 for (
int k=0; k<dim; k++)
610 return (
_g->level() ==
yaspgrid()->maxLevel());
691 for (
int i=dim-1; i>=0; i--)
703 return _it.superindex();
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);
751 for (
int j=dim-1; j>=0; j--)
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>
790 enum { dimworld = GridImp::dimensionworld };
792 template<
int, PartitionIteratorType,
typename>
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;
812 typedef typename GridImp::template Codim<dim>::EntitySeed
EntitySeed;
818 typedef typename GridImp::YGrid::iTupel
iTupel;
831 #if not (defined(__GNUC__) && (__GNUC__ < 5) && (__GNUC_MINOR__ < 5))
834 :
_it(std::move(it)),
_g(std::move(g))
842 return _it == e._it &&
_g == e._g;
857 GeometryImpl _geometry((
_it).lowerleft());
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()))
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;
924 for (
int i=dim-1; i>=0; i--)
950 #endif // DUNE_GRID_YASPGRIDENTITY_HH
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition: yaspgridentity.hh:309
GridImp::LevelIntersectionIterator LevelIntersectionIterator
Definition: yaspgridentity.hh:435
I & transformingsubiterator()
Definition: yaspgridentity.hh:604
The general version that handles all codimensions but 0 and dim.
Definition: yaspgrid.hh:57
YGLI & gridlevel()
Definition: yaspgridentity.hh:605
Describes the minimal information necessary to create a fully functional YaspEntity.
Definition: yaspgrid.hh:60
on boundary between overlap and ghost
Definition: gridenums.hh:32
GridImp::template Codim< dim >::EntityPointer EntityPointer
Definition: yaspgridentity.hh:811
Entity father() const
Inter-level access to father element on coarser grid. Assumes that meshes are nested.
Definition: yaspgridentity.hh:558
Geometry geometry() const
geometry of this entity
Definition: yaspgridentity.hh:496
Base class for exceptions in Dune grid modules.
Definition: exceptions.hh:16
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: yaspgridentity.hh:480
persistent, globally unique Ids
Definition: yaspgrid.hh:66
GridImp::template Codim< dim >::Geometry Geometry
Definition: yaspgridentity.hh:803
IdType id(const typename remove_const< GridImp >::type::Traits::template Codim< cd >::Entity &e) const
get id of an entity
Definition: yaspgrididset.hh:42
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: yaspgridentity.hh:851
YaspEntity(const YGLI &g, const I &it)
Definition: yaspgridentity.hh:824
IntersectionIterator ibegin() const
returns intersection iterator for first intersection
Definition: yaspgridentity.hh:622
GridImp::PersistentIndexType PersistentIndexType
Definition: yaspgridentity.hh:318
ghost entities
Definition: gridenums.hh:33
bool mightVanish() const
Returns true, if entity might disappear during the next call to adapt()
Definition: yaspgridentity.hh:619
I _it
Definition: yaspgridentity.hh:395
static void(*)(*)(*)(*)(*)(*) move(const double *)
Definition: partitiondisplay.cc:122
const YGLI & gridlevel() const
Definition: yaspgridentity.hh:938
YGLI & gridlevel()
Definition: yaspgridentity.hh:940
unsigned int subEntities(unsigned int codim) const
Definition: yaspgridentity.hh:534
Iterates over entities of one grid level.
Definition: yaspgrid.hh:61
LeafIntersectionIterator ileafend() const
Reference to one past the last neighbor.
Definition: yaspgridentity.hh:647
HierarchicIterator hend(int maxlevel) const
Returns iterator to one past the last son.
Definition: yaspgridentity.hh:668
GridImp::YGrid::iTupel iTupel
define type used for coordinates in grid module
Definition: yaspgridentity.hh:443
GridImp::template Codim< cd >::EntitySeed EntitySeed
The corresponding entity seed (for storage of entities)
Definition: common/entity.hh:752
YGLI _g
Definition: yaspgridentity.hh:396
GridImp::YGridLevelIterator YGLI
Definition: yaspgridentity.hh:418
const YGLI & gridlevel() const
Definition: yaspgridentity.hh:390
GridImp::YGrid::iTupel iTupel
define type used for coordinates in grid module
Definition: yaspgridentity.hh:818
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition: yaspgridentity.hh:840
on boundary between interior and overlap
Definition: gridenums.hh:30
YaspEntity()
Definition: yaspgridentity.hh:821
GridImp::template Codim< dim >::EntitySeed EntitySeed
Definition: yaspgridentity.hh:812
int subCompressedIndex(int, unsigned int) const
subentity compressed index simply returns compressedIndex
Definition: yaspgridentity.hh:876
I & transformingsubiterator()
Definition: yaspgridentity.hh:391
Definition: yaspgrid.hh:58
PartitionType partitionType() const
return partition type attribute
Definition: yaspgridentity.hh:275
all interior entities
Definition: gridenums.hh:29
const GridImp * yaspgrid() const
Definition: yaspgridentity.hh:942
GridImp::template Codim< 0 >::Entity Entity
Definition: yaspgridentity.hh:432
YaspEntity(const YGLI &g, const I &it)
Definition: yaspgridentity.hh:293
const I & transformingsubiterator() const
Definition: yaspgridentity.hh:602
GridImp::HierarchicIterator HierarchicIterator
Definition: yaspgridentity.hh:437
GridImp::PersistentIndexType PersistentIndexType
define the type used for persisitent indices
Definition: yaspgridentity.hh:815
GridImp::YGrid::Iterator I
Definition: yaspgridentity.hh:419
Default Implementations for EntityImp.
Definition: common/entity.hh:739
GridImp::template Codim< 0 >::EntityPointer EntityPointer
Definition: yaspgridentity.hh:431
I _it
Definition: yaspgridentity.hh:944
bool isNew() const
Returns true, if the entity has been created during the last call to adapt()
Definition: yaspgridentity.hh:615
YaspEntity()
Definition: yaspgridentity.hh:446
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:28
const GridImp * yaspgrid() const
Definition: yaspgridentity.hh:606
GridImp::YGridLevelIterator YGLI
Definition: yaspgridentity.hh:800
Geometry geometry() const
geometry of this entity
Definition: yaspgridentity.hh:268
GridImp::YGrid::Iterator I
Definition: yaspgridentity.hh:801
int level() const
ask for level of entity
Definition: yaspgridentitypointer.hh:80
YGLI & gridlevel()
Definition: yaspgridentity.hh:392
LevelIntersectionIterator ilevelbegin() const
returns intersection iterator for first intersection
Definition: yaspgridentity.hh:635
GridImp::template Codim< 0 >::EntitySeed EntitySeed
Definition: yaspgridentity.hh:433
YaspEntity()
Definition: yaspgridentity.hh:290
GridImp::template Codim< 0 >::Geometry Geometry
Definition: yaspgridentity.hh:421
GridImp::ctype ctype
Definition: yaspgridentity.hh:245
GridImp::template Codim< 0 >::LocalGeometry LocalGeometry
Definition: yaspgridentity.hh:422
YaspIntersectionIterator enables iteration over intersections with neighboring codim 0 entities...
Definition: yaspgrid.hh:62
const I & transformingsubiterator() const
Definition: yaspgridentity.hh:389
LeafIntersectionIterator ileafbegin() const
returns intersection iterator for first intersection
Definition: yaspgridentity.hh:628
Implementation of Level- and LeafIndexSets for YaspGrid.
Definition: yaspgrid.hh:65
const int yaspgrid_dim_bits
Definition: yaspgrid.hh:49
YGLI _g
Definition: yaspgridentity.hh:945
LevelIntersectionIterator ilevelend() const
Reference to one past the last neighbor.
Definition: yaspgridentity.hh:653
GridImp::YGrid::Iterator I
Definition: yaspgridentity.hh:289
GridImp::template Codim< cd >::Entity Entity
Definition: yaspgridentity.hh:428
GridImp::template Codim< codim >::Geometry Geometry
Definition: yaspgridentity.hh:247
GridImp::LevelIntersectionIterator IntersectionIterator
Definition: yaspgridentity.hh:434
bool hasFather() const
returns true if father entity exists
Definition: yaspgridentity.hh:578
PersistentIndexType persistentIndex() const
globally unique, persistent index
Definition: yaspgridentity.hh:321
int subCompressedIndex(int i, unsigned int cc) const
subentity compressed index
Definition: yaspgridentity.hh:358
int level() const
level of this element
Definition: yaspgridentity.hh:254
const YGLI & gridlevel() const
Definition: yaspgridentity.hh:603
GridImp::Traits::template Codim< codim >::GeometryImpl GeometryImpl
Definition: yaspgridentity.hh:248
GridImp::template Codim< codim >::EntitySeed EntitySeed
Definition: yaspgridentity.hh:251
bool equals(const YaspEntity &e) const
Return true when two iterators over the same grid are equal (!).
Definition: yaspgridentity.hh:469
GridImp::template Codim< cd >::EntityPointer EntityPointer
Definition: yaspgridentity.hh:808
int level() const
level of this element
Definition: yaspgridentity.hh:475
GridImp::YGridLevelIterator YGLI
Definition: yaspgridentity.hh:288
all entities lying in the overlap zone
Definition: gridenums.hh:31
int compressedIndex() const
consecutive, codim-wise, level-wise index
Definition: yaspgridentity.hh:352
GridImp::template Codim< cd >::EntityPointer EntityPointer
Definition: yaspgridentity.hh:427
IntersectionIterator iend() const
Reference to one past the last neighbor.
Definition: yaspgridentity.hh:641
YaspHierarchicIterator enables iteration over son entities of codim 0.
Definition: yaspgrid.hh:64
bool isLeaf() const
Definition: yaspgridentity.hh:608
const GridImp * yaspgrid() const
Definition: yaspgridentity.hh:393
PartitionType partitionType() const
return partition type attribute
Definition: yaspgridentity.hh:485
GridImp::LeafIntersectionIterator LeafIntersectionIterator
Definition: yaspgridentity.hh:436
int count() const
Definition: yaspgridentity.hh:525
PartitionType partitionType() const
return partition type attribute
Definition: yaspgridentity.hh:862
int level() const
level of this element
Definition: yaspgridentity.hh:846
const I & transformingsubiterator() const
Definition: yaspgridentity.hh:937
GridImp::PersistentIndexType PersistentIndexType
define the type used for persisitent indices
Definition: yaspgridentity.hh:440
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:346
GridImp::ctype ctype
Definition: yaspgridentity.hh:416
I & transformingsubiterator()
Definition: yaspgridentity.hh:939
LocalGeometry geometryInFather() const
Definition: yaspgridentity.hh:585
Geometry geometry() const
geometry of this entity
Definition: yaspgridentity.hh:856
EntitySeed seed() const
Return the entity seed which contains sufficient information to generate the entity again and uses as...
Definition: yaspgridentity.hh:262
YaspEntity(const YGLI &g, I &&it)
Definition: yaspgridentity.hh:453
HierarchicIterator hbegin(int maxlevel) const
Definition: yaspgridentity.hh:662
Codim< cc >::Entity subEntity(int i) const
Definition: yaspgridentity.hh:542
const int yaspgrid_level_bits
Definition: yaspgrid.hh:50
GridImp::ctype ctype
Definition: yaspgridentity.hh:798
YaspEntity(const YGLI &g, const I &it)
Definition: yaspgridentity.hh:449
GridImp::template Codim< codim >::EntityPointer EntityPointer
Definition: yaspgridentity.hh:250