5#ifndef DUNE_GEOMETRY_REFINEMENT_HCUBE_CC
6#define DUNE_GEOMETRY_REFINEMENT_HCUBE_CC
44#include <dune/common/fvector.hh>
45#include <dune/common/iteratorfacades.hh>
54 namespace RefinementImp
73 template<
int dimension_,
class CoordType>
82 template<
int codimension>
89 static unsigned nVertices(
unsigned nIntervals);
93 static unsigned nElements(
unsigned nIntervals);
98 template<
int dimension,
class CoordType>
99 template<
int codimension>
102 class SubEntityIterator;
106 template<
int dimension,
class CoordType>
112 return Dune::power(nIntervals+1u,
unsigned(dimension));
115 template<
int dimension,
class CoordType>
118 vBegin(
unsigned nIntervals)
123 template<
int dimension,
class CoordType>
126 vEnd(
unsigned nIntervals)
131 template<
int dimension,
class CoordType>
136 static_assert(dimension >= 0,
137 "Negative dimension given, what the heck is that supposed to mean?");
139 return Dune::power(nIntervals,
unsigned(dimension));
142 template<
int dimension,
class CoordType>
145 eBegin(
unsigned nIntervals)
150 template<
int dimension,
class CoordType>
153 eEnd(
unsigned nIntervals)
174 template<
int dimension,
class CoordType,
int codimension>
177 template<
int dimension,
class CoordType,
int codimension>
183 template<
int dimension,
class CoordType>
194 const Common & asCommon()
const
196 return *
static_cast<const Common*
>(
this);
200 template<
int dimension,
class CoordType>
201 typename RefinementSubEntityIteratorSpecial<dimension, CoordType, dimension>::CoordVector
205 std::array<unsigned int, dimension> v(asCommon().vertexCoord());
207 for (
int d = 0; d < dimension; d++)
209 c[d] = v[d]*1.0 / asCommon()._nIntervals;
216 template<
int dimension,
class CoordType>
229 const Common & asCommon()
const
231 return *
static_cast<const Common*
>(
this);
235 template<
int dimension,
class CoordType>
236 typename RefinementSubEntityIteratorSpecial<dimension, CoordType, 0>::IndexVector
240 constexpr static int nIndices = 1 << dimension;
243 std::array<unsigned int, dimension> e(asCommon().cellCoord());
247 for(
int i = 0; i < nIndices; ++i)
250 std::array<unsigned int, dimension> alpha(asCommon().idx2multiidx(i));
251 for (
int d = 0; d < dimension; d++) {
252 vec[i] += (alpha[d] + e[d]) * base;
253 base *= asCommon()._nIntervals+1;
259 template<
int dimension,
class CoordType>
264 std::array<unsigned int, dimension> v(asCommon().cellCoord());
266 for (
int d=0; d<dimension; d++)
268 c[d] = (v[d]*1.0 + 0.5) / asCommon()._nIntervals;
274 template<
int dimension,
class CoordType>
275 template<
int codimension>
277 :
public ForwardIteratorFacade<typename RefinementImp<dimension,
278 CoordType>::template Codim<codimension>::SubEntityIterator, int>,
295 unsigned int _nIntervals;
297 std::array<unsigned int, dimension>
298 cellCoord(
unsigned int idx)
const
300 return idx2coord(idx, _nIntervals);
303 std::array<unsigned int, dimension>
304 vertexCoord(
unsigned int idx)
const
306 return idx2coord(idx, _nIntervals+1u);
309 std::array<unsigned int, dimension>
312 return cellCoord(_index);
315 std::array<unsigned int, dimension>
318 return vertexCoord(_index);
321 std::array<unsigned int, dimension>
322 idx2coord(
unsigned int idx,
unsigned int w)
const
324 std::array<unsigned int, dimension> c;
325 for (
unsigned int d = 0; d <
dimension; d++)
334 coord2idx(std::array<unsigned int, dimension> c,
unsigned int w)
const
337 for (
unsigned int d =
dimension; d > 0; d--)
345 std::array<unsigned int, dimension>
346 idx2multiidx(
unsigned int idx)
const
348 std::array<unsigned int, dimension> alpha;
349 for (
unsigned int i = 0; i <
dimension; ++i)
350 alpha[i] = (idx >> i) & 1u;
356 template<
int dimension,
class CoordType>
357 template<
int codimension>
358 RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::
359 SubEntityIterator(
unsigned int index,
unsigned int nIntervals)
360 : _index(index), _nIntervals(nIntervals)
363 template<
int dimension,
class CoordType>
364 template<
int codimension>
366 RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::
367 equals(
const This &other)
const
369 return ((_index == other._index) && (_nIntervals == other._nIntervals));
372 template<
int dimension,
class CoordType>
373 template<
int codimension>
375 RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::
381 template<
int dimension,
class CoordType>
382 template<
int codimension>
384 RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::
390 template<
int dimension,
class CoordType>
391 template<
int codimension>
392 typename RefinementImp<dimension, CoordType>::template Codim<codimension>::Geometry
393 RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::geometry ()
const
395 std::array<unsigned int,dimension> intCoords = idx2coord(_index,_nIntervals);
397 Dune::FieldVector<CoordType,dimension> lower;
398 Dune::FieldVector<CoordType,dimension> upper;
400 assert(codimension == 0 or codimension ==
dimension);
402 if constexpr (codimension == 0) {
405 lower[j] = double(intCoords[j]) / double(_nIntervals);
406 upper[j] = double(intCoords[j] + 1) / double(_nIntervals);
413 lower[j] = upper[j] =
double(intCoords[j]) / double(_nIntervals);
430 template<
unsigned topologyId,
class CoordType,
unsigned coerceToId,
433 topologyId, CoordType, coerceToId, dim,
434 typename std::enable_if<
436 (GeometryTypes::cube(dim).id() >> 1) ==
438 (GeometryTypes::cube(dim).id() >> 1) ==
443 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:75
Codim< 0 >::SubEntityIterator ElementIterator
Definition hcube.cc:86
static ElementIterator eEnd(unsigned nIntervals)
Definition hcube.cc:153
static unsigned nVertices(unsigned nIntervals)
Definition hcube.cc:109
static VertexIterator vEnd(unsigned nIntervals)
Definition hcube.cc:126
FieldVector< int,(1<< dimension)> IndexVector
Definition hcube.cc:87
Codim< dimension >::SubEntityIterator VertexIterator
Definition hcube.cc:84
FieldVector< CoordType, dimension > CoordVector
Definition hcube.cc:85
static unsigned nElements(unsigned nIntervals)
Definition hcube.cc:134
RefinementImp< dimension, CoordType > Refinement
Definition hcube.cc:80
static ElementIterator eBegin(unsigned nIntervals)
Definition hcube.cc:145
static constexpr int dimension
Know your own dimension.
Definition hcube.cc:78
static VertexIterator vBegin(unsigned nIntervals)
Definition hcube.cc:118
Dune::AxisAlignedCubeGeometry< CoordType, dimension-codimension, dimension > Geometry
Definition hcube.cc:103
SubEntityIterator base class for hypercube refinement.
Definition hcube.cc:175
Refinement::CoordVector CoordVector
Definition hcube.cc:189
Refinement::template Codim< dimension >::SubEntityIterator Common
Definition hcube.cc:188
RefinementImp< dimension, CoordType > Refinement
Definition hcube.cc:187
RefinementImp< dimension, CoordType > Refinement
Definition hcube.cc:220
Refinement::template Codim< 0 >::SubEntityIterator Common
Definition hcube.cc:221
Refinement::CoordVector CoordVector
Definition hcube.cc:223
Refinement::IndexVector IndexVector
Definition hcube.cc:222
SubEntityIterator(unsigned int index, unsigned int nIntervals)
bool equals(const This &other) const
Geometry geometry() const
RefinementImp< dimension, CoordType > Refinement
Definition hcube.cc:282
Refinement::template Codim< codimension >::SubEntityIterator This
Definition hcube.cc:283