5#ifndef DUNE_GEOMETRY_REFINEMENT_HCUBE_CC
6#define DUNE_GEOMETRY_REFINEMENT_HCUBE_CC
43#include <dune/common/fvector.hh>
44#include <dune/common/iteratorfacades.hh>
53 namespace RefinementImp
72 template<
int dimension_,
class CoordType>
81 template<
int codimension>
88 static unsigned nVertices(
unsigned nIntervals);
92 static unsigned nElements(
unsigned nIntervals);
97 template<
int dimension,
class CoordType>
98 template<
int codimension>
101 class SubEntityIterator;
105 template<
int dimension,
class CoordType>
111 return Dune::power(nIntervals+1u,
static_cast<unsigned>(dimension));
114 template<
int dimension,
class CoordType>
117 vBegin(
unsigned nIntervals)
122 template<
int dimension,
class CoordType>
125 vEnd(
unsigned nIntervals)
130 template<
int dimension,
class CoordType>
135 static_assert(dimension >= 0,
136 "Negative dimension given, what the heck is that supposed to mean?");
138 return Dune::power(nIntervals,
static_cast<unsigned>(dimension));
141 template<
int dimension,
class CoordType>
144 eBegin(
unsigned nIntervals)
149 template<
int dimension,
class CoordType>
152 eEnd(
unsigned nIntervals)
173 template<
int dimension,
class CoordType,
int codimension>
176 template<
int dimension,
class CoordType,
int codimension>
182 template<
int dimension,
class CoordType>
193 const Common & asCommon()
const
195 return *
static_cast<const Common*
>(
this);
199 template<
int dimension,
class CoordType>
204 std::array<unsigned int, dimension> v(asCommon().vertexCoord());
206 for (
int d = 0; d < dimension; d++)
208 c[d] = v[d]*1.0 / asCommon()._nIntervals;
215 template<
int dimension,
class CoordType>
228 const Common & asCommon()
const
230 return *
static_cast<const Common*
>(
this);
234 template<
int dimension,
class CoordType>
239 constexpr static int nIndices = 1 << dimension;
242 std::array<unsigned int, dimension> e(asCommon().cellCoord());
246 for(
int i = 0; i < nIndices; ++i)
249 std::array<unsigned int, dimension> alpha(asCommon().idx2multiidx(i));
250 for (
int d = 0; d < dimension; d++) {
251 vec[i] += (alpha[d] + e[d]) * base;
252 base *= asCommon()._nIntervals+1;
258 template<
int dimension,
class CoordType>
263 std::array<unsigned int, dimension> v(asCommon().cellCoord());
265 for (
int d=0; d<dimension; d++)
267 c[d] = (v[d]*1.0 + 0.5) / asCommon()._nIntervals;
273 template<
int dimension,
class CoordType>
274 template<
int codimension>
276 :
public ForwardIteratorFacade<typename RefinementImp<dimension,
277 CoordType>::template Codim<codimension>::SubEntityIterator, int>,
294 unsigned int _nIntervals;
296 std::array<unsigned int, dimension>
297 cellCoord(
unsigned int idx)
const
299 return idx2coord(idx, _nIntervals);
302 std::array<unsigned int, dimension>
303 vertexCoord(
unsigned int idx)
const
305 return idx2coord(idx, _nIntervals+1u);
308 std::array<unsigned int, dimension>
311 return cellCoord(_index);
314 std::array<unsigned int, dimension>
317 return vertexCoord(_index);
320 std::array<unsigned int, dimension>
321 idx2coord(
unsigned int idx,
unsigned int w)
const
323 std::array<unsigned int, dimension> c;
324 for (
unsigned int d = 0; d <
dimension; d++)
333 coord2idx(std::array<unsigned int, dimension> c,
unsigned int w)
const
336 for (
unsigned int d =
dimension; d > 0; d--)
344 std::array<unsigned int, dimension>
345 idx2multiidx(
unsigned int idx)
const
347 std::array<unsigned int, dimension> alpha;
348 for (
unsigned int i = 0; i <
dimension; ++i)
349 alpha[i] = (idx >> i) & 1u;
355 template<
int dimension,
class CoordType>
356 template<
int codimension>
357 RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::
358 SubEntityIterator(
unsigned int index,
unsigned int nIntervals)
359 : _index(index), _nIntervals(nIntervals)
362 template<
int dimension,
class CoordType>
363 template<
int codimension>
365 RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::
366 equals(
const This &other)
const
368 return ((_index == other._index) && (_nIntervals == other._nIntervals));
371 template<
int dimension,
class CoordType>
372 template<
int codimension>
374 RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::
380 template<
int dimension,
class CoordType>
381 template<
int codimension>
383 RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::
389 template<
int dimension,
class CoordType>
390 template<
int codimension>
391 typename RefinementImp<dimension, CoordType>::template Codim<codimension>::Geometry
392 RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::geometry ()
const
394 std::array<unsigned int,dimension> intCoords = idx2coord(_index,_nIntervals);
396 Dune::FieldVector<CoordType,dimension> lower;
397 Dune::FieldVector<CoordType,dimension> upper;
399 assert(codimension == 0 or codimension ==
dimension);
401 if constexpr (codimension == 0) {
404 lower[j] = double(intCoords[j]) / double(_nIntervals);
405 upper[j] = double(intCoords[j] + 1) / double(_nIntervals);
412 lower[j] = upper[j] =
double(intCoords[j]) / double(_nIntervals);
429 template<
unsigned topologyId,
class CoordType,
unsigned coerceToId,
432 topologyId, CoordType, coerceToId, dim,
433 typename
std::enable_if<
435 (GeometryTypes::cube(dim).id() >> 1) ==
437 (GeometryTypes::cube(dim).id() >> 1) ==
442 typedef HCube::RefinementImp<dim, CoordType> Imp;
This file contains the parts independent of a particular Refinement implementation.
A geometry implementation for axis-aligned hypercubes.
Definition affinegeometry.hh:21
A geometry implementation for axis-aligned hypercubes.
Definition axisalignedcubegeometry.hh:50
Static tag representing a codimension.
Definition dimension.hh:24
Refinement implementation for hypercubes
Definition hcube.cc:74
static ElementIterator eEnd(unsigned nIntervals)
Definition hcube.cc:152
static unsigned nVertices(unsigned nIntervals)
Definition hcube.cc:108
static VertexIterator vEnd(unsigned nIntervals)
Definition hcube.cc:125
FieldVector< int,(1<< dimension)> IndexVector
Definition hcube.cc:86
Codim< 0 >::SubEntityIterator ElementIterator
Definition hcube.cc:85
static unsigned nElements(unsigned nIntervals)
Definition hcube.cc:133
RefinementImp< dimension, CoordType > Refinement
Definition hcube.cc:79
FieldVector< CoordType, dimension > CoordVector
Definition hcube.cc:84
static ElementIterator eBegin(unsigned nIntervals)
Definition hcube.cc:144
Codim< dimension >::SubEntityIterator VertexIterator
Definition hcube.cc:83
static constexpr int dimension
Know your own dimension.
Definition hcube.cc:77
static VertexIterator vBegin(unsigned nIntervals)
Definition hcube.cc:117
Dune::AxisAlignedCubeGeometry< CoordType, dimension-codimension, dimension > Geometry
Definition hcube.cc:102
SubEntityIterator base class for hypercube refinement.
Definition hcube.cc:174
RefinementImp< dimension, CoordType > Refinement
Definition hcube.cc:186
Refinement::template Codim< dimension >::SubEntityIterator Common
Definition hcube.cc:187
Refinement::CoordVector CoordVector
Definition hcube.cc:188
Refinement::CoordVector CoordVector
Definition hcube.cc:222
Refinement::IndexVector IndexVector
Definition hcube.cc:221
Refinement::template Codim< 0 >::SubEntityIterator Common
Definition hcube.cc:220
RefinementImp< dimension, CoordType > Refinement
Definition hcube.cc:219
SubEntityIterator(unsigned int index, unsigned int nIntervals)
bool equals(const This &other) const
Geometry geometry() const
RefinementImp< dimension, CoordType > Refinement
Definition hcube.cc:281
Refinement::template Codim< codimension >::SubEntityIterator This
Definition hcube.cc:282