5#ifndef DUNE_GRID_COMMON_REFINEMENT_SIMPLEX_CC
6#define DUNE_GRID_COMMON_REFINEMENT_SIMPLEX_CC
245#include <dune/common/fvector.hh>
246#include <dune/common/math.hh>
256 namespace RefinementImp {
279 template<
int dimension>
283 for(
int i = 0; i < dimension; ++i)
284 index += Dune::binomial(dimension-i + point[i]-1, dimension-i);
295 FieldVector<int, n> perm;
296 for(
int i = 0; i < n; ++i)
300 for(
int i = 1; i <= n; ++i)
303 for(
int i = n; i > 0; --i) {
307 int t = perm[i-1]; perm[i-1] = perm[i-1-d]; perm[i-1-d] = t;
320 template<
int dimension,
class CoordType>
321 FieldVector<CoordType, dimension>
323 FieldVector<CoordType, dimension> point,
325 const FieldVector<int, dimension> &kuhn)
327 for(
int i = dimension - 1; i > 0; --i)
328 point[kuhn[i-1]] += point[kuhn[i]];
339 template<
int dimension,
class CoordType>
340 FieldVector<CoordType, dimension>
342 FieldVector<CoordType, dimension> point,
344 const FieldVector<int, dimension> &kuhn)
346 for(
int i = 0; i < dimension - 1; ++i)
347 point[kuhn[i]] -= point[kuhn[i+1]];
359 template<
int dimension_,
class CoordType>
366 template<
int codimension>
382 template<
int dimension,
class CoordType>
383 template<
int codimension>
386 class SubEntityIterator;
391 template<
int dimension,
class CoordType>
396 return Dune::binomial(dimension + nIntervals, (
int)dimension);
399 template<
int dimension,
class CoordType>
407 template<
int dimension,
class CoordType>
415 template<
int dimension,
class CoordType>
420 return Dune::power(nIntervals,
int(dimension));
423 template<
int dimension,
class CoordType>
431 template<
int dimension,
class CoordType>
444 template<
int dimension,
class CoordType,
int codimension>
449 template<
int dimension,
class CoordType>
461 bool equals(
const This &other)
const;
468 typedef FieldVector<int, dimension>
Vertex;
474 template<
int dimension,
class CoordType>
479 vertex[0] = (end) ? size + 1 : 0;
480 for(
int i = 1; i < dimension; ++ i)
484 template<
int dimension,
class CoordType>
489 assert(vertex[0] <= size);
490 for(
int i = dimension - 1; i >= 0; --i) {
492 if(i == 0 || vertex[i] <= vertex[i-1])
499 template<
int dimension,
class CoordType>
504 return size == other.
size && vertex == other.
vertex;
507 template<
int dimension,
class CoordType>
515 for(
int i = 0; i < dimension; ++i)
516 coords[i] = CoordType(ref[i]) / size;
520 template<
int dimension,
class CoordType>
524 std::vector<CoordVector> corners(1);
526 return Geometry(GeometryTypes::vertex, corners);
529 template<
int dimension,
class CoordType>
539 template<
int dimension,
class CoordType>
552 bool equals(
const This &other)
const;
564 typedef FieldVector<int, dimension>
Vertex;
565 constexpr static int nKuhnIntervals = Dune::factorial(dimension);
573 template<
int dimension,
class CoordType>
576 : kuhnIndex(0), size(nIntervals), index_(0)
578 for(
int i = 0; i < dimension; ++i)
581 index_ = Refinement::nElements(nIntervals);
586 template<
int dimension,
class CoordType>
591 assert(origin[0] < size);
597 if(kuhnIndex == nKuhnIntervals) {
600 for(
int i = dimension - 1; i >= 0; --i) {
602 if(i == 0 || origin[i] <= origin[i-1])
610 FieldVector<int, dimension> perm = getPermutation<dimension>(kuhnIndex);
612 bool outside =
false;
613 for(
int i = 0; i < dimension; ++i) {
617 if(corner[perm[i]] > corner[perm[i]-1]) {
627 template<
int dimension,
class CoordType>
632 return size == other.
size && index_ == other.
index_;
635 template<
int dimension,
class CoordType>
641 FieldVector<int, dimension> perm = getPermutation<dimension>(kuhnIndex);
644 for(
int i = 0; i < dimension; ++i) {
648 if (kuhnIndex%2 == 1)
649 for(
int i = 0; i < (dimension+1)/2; ++i) {
651 indices[i] = indices[dimension-i];
652 indices[dimension-i] = t;
657 template<
int dimension,
class CoordType>
665 template<
int dimension,
class CoordType>
671 ::simplex().position(0,0));
674 template<
int dimension,
class CoordType>
678 std::vector<CoordVector> corners(dimension+1);
680 for(
int i = 0; i <= dimension; ++i)
681 corners[i] = global(refelem.position(i, dimension));
682 return Geometry(refelem.type(), corners);
685 template<
int dimension,
class CoordType>
688 global(
const CoordVector &local)
const {
692 v /= (
typename CoordVector::value_type)size;
698 template<
int dimension,
class CoordType>
699 template<
int codimension>
701 :
public ForwardIteratorFacade<typename RefinementImp<dimension, CoordType>::template Codim<codimension>::SubEntityIterator, int>,
712 template<
int dimension,
class CoordType>
713 template<
int codimension>
726 namespace RefinementImp {
734 template<
unsigned topologyId,
class CoordType,
unsigned coerceToId,
737 topologyId, CoordType, coerceToId, dim,
738 typename
std::enable_if<
739 ((GeometryTypes::simplex(dim).id() >> 1) ==
741 (GeometryTypes::simplex(dim).id() >> 1) ==
746 typedef Simplex::RefinementImp<dim, CoordType> Imp;
A unique label for each type of element that can occur in a grid.
This file contains the parts independent of a particular Refinement implementation.
Definition affinegeometry.hh:21
int pointIndex(const FieldVector< int, dimension > &point)
calculate the index of a given gridpoint within a Kuhn0 simplex
Definition simplex.cc:280
FieldVector< int, n > getPermutation(int m)
Calculate permutation from it's index.
Definition simplex.cc:293
FieldVector< CoordType, dimension > referenceToKuhn(FieldVector< CoordType, dimension > point, const FieldVector< int, dimension > &kuhn)
Map from the reference simplex to some Kuhn simplex.
Definition simplex.cc:322
FieldVector< CoordType, dimension > kuhnToReference(FieldVector< CoordType, dimension > point, const FieldVector< int, dimension > &kuhn)
Map from some Kuhn simplex to the reference simplex.
Definition simplex.cc:341
Class providing access to the singletons of the reference elements.
Definition referenceelements.hh:128
static const ReferenceElement & simplex()
get simplex reference elements
Definition referenceelements.hh:162
Static tag representing a codimension.
Definition dimension.hh:24
Implement a MultiLinearGeometry with additional caching.
Definition multilineargeometry.hh:526
Definition simplex.cc:361
Codim< dimension >::SubEntityIterator VertexIterator
Definition simplex.cc:368
FieldVector< int, dimension+1 > IndexVector
Definition simplex.cc:371
CoordType ctype
Definition simplex.cc:364
static int nVertices(int nIntervals)
Definition simplex.cc:394
static int nElements(int nIntervals)
Definition simplex.cc:418
static ElementIterator eEnd(int nIntervals)
Definition simplex.cc:434
static VertexIterator vEnd(int nIntervals)
Definition simplex.cc:410
Codim< 0 >::SubEntityIterator ElementIterator
Definition simplex.cc:370
static VertexIterator vBegin(int nIntervals)
Definition simplex.cc:402
static ElementIterator eBegin(int nIntervals)
Definition simplex.cc:426
FieldVector< CoordType, dimension > CoordVector
Definition simplex.cc:369
static constexpr int dimension
Definition simplex.cc:363
Definition simplex.cc:385
Dune::CachedMultiLinearGeometry< CoordType, dimension-codimension, dimension > Geometry
Definition simplex.cc:388
Definition simplex.cc:445
Definition simplex.cc:451
Refinement::CoordVector CoordVector
Definition simplex.cc:454
RefinementImp< dimension, CoordType > Refinement
Definition simplex.cc:453
Vertex vertex
Definition simplex.cc:471
Refinement::template Codim< dimension >::Geometry Geometry
Definition simplex.cc:455
RefinementIteratorSpecial< dimension, CoordType, dimension > This
Definition simplex.cc:456
FieldVector< int, dimension > Vertex
Definition simplex.cc:468
int size
Definition simplex.cc:470
Definition simplex.cc:541
int kuhnIndex
Definition simplex.cc:568
FieldVector< int, dimension > Vertex
Definition simplex.cc:564
Vertex origin
Definition simplex.cc:567
int index_
Definition simplex.cc:570
Refinement::template Codim< 0 >::Geometry Geometry
Definition simplex.cc:546
Refinement::IndexVector IndexVector
Definition simplex.cc:544
Refinement::CoordVector CoordVector
Definition simplex.cc:545
RefinementIteratorSpecial< dimension, CoordType, 0 > This
Definition simplex.cc:547
RefinementImp< dimension, CoordType > Refinement
Definition simplex.cc:543
int size
Definition simplex.cc:569
SubEntityIterator(int nIntervals, bool end=false)
RefinementImp< dimension, CoordType > Refinement
Definition simplex.cc:705