3#ifndef DUNE_GEOMETRY_REFINEMENT_HCUBE_CC
4#define DUNE_GEOMETRY_REFINEMENT_HCUBE_CC
42#include <dune/common/fvector.hh>
43#include <dune/common/iteratorfacades.hh>
44#include <dune/common/power.hh>
53 namespace RefinementImp
72 template<
int dimension_,
class CoordType>
80 template<
int codimension>
87 static unsigned nVertices(
unsigned level);
91 static unsigned nElements(
unsigned level);
96 template<
int dimension,
class CoordType>
97 template<
int codimension>
100 class SubEntityIterator;
104 template<
int dimension,
class CoordType>
110 return Power<dimension>::eval((1u<<level)+1u);
113 template<
int dimension,
class CoordType>
121 template<
int dimension,
class CoordType>
129 template<
int dimension,
class CoordType>
134 static_assert(dimension >= 0,
135 "Negative dimension given, what the heck is that supposed to mean?");
137 return 1u<<(level*unsigned(dimension));
140 template<
int dimension,
class CoordType>
148 template<
int dimension,
class CoordType>
172 template<
int dimension,
class CoordType,
int codimension>
175 template<
int dimension,
class CoordType,
int codimension>
181 template<
int dimension,
class CoordType>
192 const Common & asCommon()
const
194 return *
static_cast<const Common*
>(
this);
198 template<
int dimension,
class CoordType>
199 typename RefinementSubEntityIteratorSpecial<dimension, CoordType, dimension>::CoordVector
203 std::array<unsigned int, dimension> v(asCommon().vertexCoord());
205 for (
int d = 0; d < dimension; d++)
207 c[d] = v[d]*1.0 / (1 << asCommon()._level);
214 template<
int dimension,
class CoordType>
227 const Common & asCommon()
const
229 return *
static_cast<const Common*
>(
this);
233 template<
int dimension,
class CoordType>
234 typename RefinementSubEntityIteratorSpecial<dimension, CoordType, 0>::IndexVector
238 enum { nIndices = (1 << dimension) };
241 std::array<unsigned int, dimension> e(asCommon().cellCoord());
245 std::array<unsigned int, dimension> v;
246 for(
int i = 0; i < nIndices; ++i)
248 for (
int d = 0; d < dimension; d++)
255 vec[nIndices-1-i] = asCommon().vertexIdx(v);
260 template<
int dimension,
class CoordType>
265 std::array<unsigned int, dimension> v(asCommon().cellCoord());
267 for (
int d=0; d<dimension; d++)
269 c[d] = (v[d]*1.0 + 0.5) / (1<<asCommon()._level);
275 template<
int dimension,
class CoordType>
276 template<
int codimension>
278 :
public ForwardIteratorFacade<typename RefinementImp<dimension,
279 CoordType>::template Codim<codimension>::SubEntityIterator, int>,
298 std::array<unsigned int, dimension>
299 cellCoord(
unsigned int idx)
const
301 return idx2coord(idx, 1u<<_level);
304 std::array<unsigned int, dimension>
305 vertexCoord(
unsigned int idx)
const
307 return idx2coord(idx, (1u<<_level)+1u);
310 std::array<unsigned int, dimension>
313 return cellCoord(_index);
316 std::array<unsigned int, dimension>
319 return vertexCoord(_index);
322 std::array<unsigned int, dimension>
323 idx2coord(
unsigned int idx,
unsigned int w)
const
325 std::array<unsigned int, dimension> c;
326 for (
unsigned int d = 0; d <
dimension; d++)
335 coord2idx(std::array<unsigned int, dimension> c,
unsigned int w)
const
338 for (
unsigned int d =
dimension; d > 0; d--)
347 vertexIdx(std::array<unsigned int, dimension> c)
const
349 return coord2idx(c, (1u<<_level)+1u);
354 template<
int dimension,
class CoordType>
355 template<
int codimension>
356 RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::
357 SubEntityIterator(
unsigned int index,
unsigned int level)
358 : _index(index), _level(level)
361 template<
int dimension,
class CoordType>
362 template<
int codimension>
364 RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::
365 equals(
const This &other)
const
367 return ((_index == other._index) && (_level == other._level));
370 template<
int dimension,
class CoordType>
371 template<
int codimension>
373 RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::
379 template<
int dimension,
class CoordType>
380 template<
int codimension>
382 RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::
388 template<
int dimension,
class CoordType>
389 template<
int codimension>
390 typename RefinementImp<dimension, CoordType>::template Codim<codimension>::Geometry
391 RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::geometry ()
const
393 std::array<unsigned int,dimension> intCoords = idx2coord(_index,1u<<_level);
395 Dune::FieldVector<CoordType,dimension> lower;
396 Dune::FieldVector<CoordType,dimension> upper;
398 assert(codimension == 0 or codimension ==
dimension);
400 if (codimension == 0) {
403 lower[j] = double(intCoords[j]) / double(1u<<_level);
404 upper[j] = double(intCoords[j] + 1) / double(1u<<_level);
408 lower[j] = upper[j] =
double(intCoords[j]) / double(1u<<_level);
425 template<
unsigned topologyId,
class CoordType,
unsigned coerceToId,
428 topologyId, CoordType, coerceToId, dim,
429 typename std::enable_if<
431 (GenericGeometry::CubeTopology<dim>::type::id >> 1) ==
433 (GenericGeometry::CubeTopology<dim>::type::id >> 1) ==
438 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:19
A geometry implementation for axis-aligned hypercubes.
Definition axisalignedcubegeometry.hh:49
Static tag representing a codimension.
Definition dimension.hh:22
Refinement implementation for hypercubes
Definition hcube.cc:74
static VertexIterator vBegin(unsigned level)
Definition hcube.cc:116
Codim< 0 >::SubEntityIterator ElementIterator
Definition hcube.cc:84
@ dimension
Definition hcube.cc:76
static ElementIterator eEnd(unsigned level)
Definition hcube.cc:151
FieldVector< int,(1<< dimension)> IndexVector
Definition hcube.cc:85
static unsigned nElements(unsigned level)
Definition hcube.cc:132
static VertexIterator vEnd(unsigned level)
Definition hcube.cc:124
Codim< dimension >::SubEntityIterator VertexIterator
Definition hcube.cc:82
FieldVector< CoordType, dimension > CoordVector
Definition hcube.cc:83
static unsigned nVertices(unsigned level)
Definition hcube.cc:107
RefinementImp< dimension, CoordType > Refinement
Definition hcube.cc:78
static ElementIterator eBegin(unsigned level)
Definition hcube.cc:143
Dune::AxisAlignedCubeGeometry< CoordType, dimension-codimension, dimension > Geometry
Definition hcube.cc:101
SubEntityIterator base class for hypercube refinement.
Definition hcube.cc:173
Refinement::CoordVector CoordVector
Definition hcube.cc:187
Refinement::template Codim< dimension >::SubEntityIterator Common
Definition hcube.cc:186
RefinementImp< dimension, CoordType > Refinement
Definition hcube.cc:185
RefinementImp< dimension, CoordType > Refinement
Definition hcube.cc:218
Refinement::template Codim< 0 >::SubEntityIterator Common
Definition hcube.cc:219
Refinement::CoordVector CoordVector
Definition hcube.cc:221
Refinement::IndexVector IndexVector
Definition hcube.cc:220
SubEntityIterator(unsigned int index, unsigned int level)
bool equals(const This &other) const
Geometry geometry() const
RefinementImp< dimension, CoordType > Refinement
Definition hcube.cc:283
Refinement::template Codim< codimension >::SubEntityIterator This
Definition hcube.cc:284