Loading...
Searching...
No Matches
hcubetriangulation.cc
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
#ifndef DUNE_GEOMETRY_REFINEMENT_HCUBETRIANGULATION_CC
#define DUNE_GEOMETRY_REFINEMENT_HCUBETRIANGULATION_CC
#include <dune/geometry/referenceelements.hh>
#include <dune/geometry/type.hh>
#include "base.cc"
#include "simplex.cc"
namespace Dune
{
namespace RefinementImp
{
namespace HCubeTriangulation {
// ////////////
//
// Utilities
//
using Simplex::getPermutation;
using Simplex::referenceToKuhn;
// ////////////////////////////////////
//
// Refine a hypercube with simplices
//
// forward declaration of the iterator base
template<int dimension, class CoordType, int codimension>
class RefinementIteratorSpecial;
template<int dimension_, class CoordType>
class RefinementImp
{
public:
constexpr static int dimension = dimension_;
typedef CoordType ctype;
template<int codimension>
struct Codim;
typedef typename Codim<dimension>::SubEntityIterator VertexIterator;
typedef FieldVector<CoordType, dimension> CoordVector;
typedef typename Codim<0>::SubEntityIterator ElementIterator;
typedef FieldVector<int, dimension+1> IndexVector;
static int nVertices(int nIntervals);
static VertexIterator vBegin(int nIntervals);
static VertexIterator vEnd(int nIntervals);
static int nElements(int nIntervals);
static ElementIterator eBegin(int nIntervals);
static ElementIterator eEnd(int nIntervals);
private:
friend class RefinementIteratorSpecial<dimension, CoordType, 0>;
friend class RefinementIteratorSpecial<dimension, CoordType, dimension>;
typedef Simplex::RefinementImp<dimension, CoordType> BackendRefinement;
};
template<int dimension, class CoordType>
template<int codimension>
struct RefinementImp<dimension, CoordType>::Codim
{
class SubEntityIterator;
typedef Dune::MultiLinearGeometry<CoordType,dimension-codimension,dimension> Geometry;
};
template<int dimension, class CoordType>
int
RefinementImp<dimension, CoordType>::
nVertices(int nIntervals)
{
return BackendRefinement::nVertices(nIntervals) * factorial(int(dimension));
}
template<int dimension, class CoordType>
typename RefinementImp<dimension, CoordType>::VertexIterator
RefinementImp<dimension, CoordType>::
vBegin(int nIntervals)
{
return VertexIterator(nIntervals);
}
template<int dimension, class CoordType>
typename RefinementImp<dimension, CoordType>::VertexIterator
RefinementImp<dimension, CoordType>::
vEnd(int nIntervals)
{
return VertexIterator(nIntervals, true);
}
template<int dimension, class CoordType>
int
RefinementImp<dimension, CoordType>::
nElements(int nIntervals)
{
return BackendRefinement::nElements(nIntervals) * factorial(int(dimension));
}
template<int dimension, class CoordType>
typename RefinementImp<dimension, CoordType>::ElementIterator
RefinementImp<dimension, CoordType>::
eBegin(int nIntervals)
{
return ElementIterator(nIntervals);
}
template<int dimension, class CoordType>
typename RefinementImp<dimension, CoordType>::ElementIterator
RefinementImp<dimension, CoordType>::
eEnd(int nIntervals)
{
return ElementIterator(nIntervals, true);
}
// //////////////
//
// The iterator
//
// vertices
template<int dimension, class CoordType>
class RefinementIteratorSpecial<dimension, CoordType, dimension>
{
public:
typedef RefinementImp<dimension, CoordType> Refinement;
typedef typename Refinement::CoordVector CoordVector;
typedef typename Refinement::template Codim<dimension>::Geometry Geometry;
RefinementIteratorSpecial(int nIntervals, bool end = false);
void increment();
CoordVector coords() const;
Geometry geometry() const;
int index() const;
protected:
typedef typename Refinement::BackendRefinement BackendRefinement;
typedef typename BackendRefinement::template Codim<dimension>::SubEntityIterator BackendIterator;
constexpr static int nKuhnSimplices = factorial(int(dimension));
int nIntervals_;
int kuhnIndex;
BackendIterator backend;
const BackendIterator backendEnd;
};
template<int dimension, class CoordType>
RefinementIteratorSpecial<dimension, CoordType, dimension>::
RefinementIteratorSpecial(int nIntervals, bool end)
: nIntervals_(nIntervals), kuhnIndex(0),
backend(BackendRefinement::vBegin(nIntervals_)),
backendEnd(BackendRefinement::vEnd(nIntervals_))
{
if (end)
kuhnIndex = nKuhnSimplices;
}
template<int dimension, class CoordType>
void
RefinementIteratorSpecial<dimension, CoordType, dimension>::
increment()
{
++backend;
if (backend == backendEnd)
{
backend = BackendRefinement::vBegin(nIntervals_);
++kuhnIndex;
}
}
template<int dimension, class CoordType>
typename RefinementIteratorSpecial<dimension, CoordType, dimension>::CoordVector
RefinementIteratorSpecial<dimension, CoordType, dimension>::
coords() const
{
return referenceToKuhn(backend.coords(), getPermutation<dimension>(kuhnIndex));
}
template<int dimension, class CoordType>
typename RefinementIteratorSpecial<dimension, CoordType, dimension>::Geometry
RefinementIteratorSpecial<dimension, CoordType, dimension>::geometry () const
{
std::vector<CoordVector> corners(1);
corners[0] = referenceToKuhn(backend.coords(), getPermutation<dimension>(kuhnIndex));
return Geometry(GeometryTypes::vertex, corners);
}
template<int dimension, class CoordType>
int
RefinementIteratorSpecial<dimension, CoordType, dimension>::
index() const
{
return kuhnIndex*BackendRefinement::nVertices(nIntervals_) + backend.index();
}
// elements
template<int dimension, class CoordType>
class RefinementIteratorSpecial<dimension, CoordType, 0>
{
public:
typedef RefinementImp<dimension, CoordType> Refinement;
typedef typename Refinement::IndexVector IndexVector;
typedef typename Refinement::CoordVector CoordVector;
typedef typename Refinement::template Codim<0>::Geometry Geometry;
RefinementIteratorSpecial(int nIntervals_, bool end = false);
RefinementIteratorSpecial(const RefinementIteratorSpecial<dimension, CoordType, 0> &other);
void increment();
IndexVector vertexIndices() const;
int index() const;
CoordVector coords() const;
Geometry geometry() const;
private:
CoordVector global(const CoordVector &local) const;
protected:
typedef typename Refinement::BackendRefinement BackendRefinement;
typedef typename BackendRefinement::template Codim<0>::SubEntityIterator BackendIterator;
constexpr static int nKuhnSimplices = factorial(dimension);
int nIntervals_;
int kuhnIndex;
BackendIterator backend;
const BackendIterator backendEnd;
};
template<int dimension, class CoordType>
RefinementIteratorSpecial<dimension, CoordType, 0>::
RefinementIteratorSpecial(int nIntervals, bool end)
: nIntervals_(nIntervals), kuhnIndex(0),
backend(BackendRefinement::eBegin(nIntervals_)),
backendEnd(BackendRefinement::eEnd(nIntervals_))
{
if (end)
kuhnIndex = nKuhnSimplices;
}
template<int dimension, class CoordType>
RefinementIteratorSpecial<dimension, CoordType, 0>::
RefinementIteratorSpecial(const RefinementIteratorSpecial<dimension, CoordType, 0> &other)
: nIntervals_(other.nIntervals_), kuhnIndex(other.kuhnIndex),
backend(other.backend),
backendEnd(other.backendEnd)
{}
template<int dimension, class CoordType>
void
RefinementIteratorSpecial<dimension, CoordType, 0>::
increment()
{
++backend;
if (backend == backendEnd)
{
backend = BackendRefinement::eBegin(nIntervals_);
++kuhnIndex;
}
}
template<int dimension, class CoordType>
typename RefinementIteratorSpecial<dimension, CoordType, 0>::IndexVector
RefinementIteratorSpecial<dimension, CoordType, 0>::
vertexIndices() const
{
IndexVector indices = backend.vertexIndices();
int base = kuhnIndex * BackendRefinement::nVertices(nIntervals_);
indices += base;
return indices;
}
template<int dimension, class CoordType>
int
RefinementIteratorSpecial<dimension, CoordType, 0>::
index() const
{
return kuhnIndex*BackendRefinement::nElements(nIntervals_) + backend.index();
}
template<int dimension, class CoordType>
typename RefinementIteratorSpecial<dimension, CoordType, 0>::CoordVector
RefinementIteratorSpecial<dimension, CoordType, 0>::
coords() const
{
return global(backend.coords());
}
template<int dimension, class CoordType>
typename RefinementIteratorSpecial<dimension, CoordType, 0>::Geometry
RefinementIteratorSpecial<dimension, CoordType, 0>::geometry () const
{
const typename BackendIterator::Geometry &bgeo =
backend.geometry();
std::vector<CoordVector> corners(dimension+1);
for(int i = 0; i <= dimension; ++i)
corners[i] = global(bgeo.corner(i));
return Geometry(bgeo.type(), corners);
}
template<int dimension, class CoordType>
typename RefinementIteratorSpecial<dimension, CoordType, 0>::CoordVector
RefinementIteratorSpecial<dimension, CoordType, 0>::
global(const CoordVector &local) const
{
return referenceToKuhn(local, getPermutation<dimension>(kuhnIndex));
}
// common
template<int dimension, class CoordType>
template<int codimension>
class RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator
: public ForwardIteratorFacade<typename RefinementImp<dimension, CoordType>::template Codim<codimension>::SubEntityIterator, int>,
public RefinementIteratorSpecial<dimension, CoordType, codimension>
{
public:
typedef RefinementImp<dimension, CoordType> Refinement;
typedef SubEntityIterator This;
SubEntityIterator(int nIntervals, bool end = false);
bool equals(const This &other) const;
protected:
using RefinementIteratorSpecial<dimension, CoordType, codimension>::kuhnIndex;
using RefinementIteratorSpecial<dimension, CoordType, codimension>::backend;
};
#ifndef DOXYGEN
template<int dimension, class CoordType>
template<int codimension>
RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::
SubEntityIterator(int nIntervals, bool end)
: RefinementIteratorSpecial<dimension, CoordType, codimension>(nIntervals, end)
{}
template<int dimension, class CoordType>
template<int codimension>
bool
RefinementImp<dimension, CoordType>::Codim<codimension>::SubEntityIterator::
equals(const This &other) const
{ return kuhnIndex == other.kuhnIndex && backend == other.backend; }
#endif // DOXYGEN
} // namespace HCubeTriangulation
} // namespace RefinementImp
namespace RefinementImp
{
// ///////////////////////
//
// The refinement traits
//
#ifndef DOXYGEN
template<unsigned topologyId, class CoordType, unsigned coerceToId,
int dim>
struct Traits<
topologyId, CoordType, coerceToId, dim,
typename std::enable_if<
(dim >= 2 &&
(GeometryTypes::cube(dim).id() >> 1) ==
(topologyId >> 1) &&
(GeometryTypes::simplex(dim).id() >> 1) ==
(coerceToId >> 1)
)>::type
>
{
typedef HCubeTriangulation::RefinementImp<dim, CoordType> Imp;
};
#endif
} // namespace RefinementImp
} // namespace Dune
#endif // DUNE_GEOMETRY_REFINEMENT_HCUBETRIANGULATION_CC
simplex.cc
This file contains the Refinement implementation for simplices (triangles, tetrahedrons....
base.cc
This file contains the parts independent of a particular Refinement implementation.
referenceelements.hh
type.hh
A unique label for each type of element that can occur in a grid.
Dune::GeometryTypes::vertex
constexpr GeometryType vertex
GeometryType representing a vertex.
Definition type.hh:492
std
STL namespace.
Dune
Definition affinegeometry.hh:22
Dune::RefinementImp::HCubeTriangulation
This namespace contains the Refinement implementation for triangulating hypercubes (GeometryType::cub...
Definition hcubetriangulation.cc:46
Dune::RefinementImp::HCubeTriangulation::getPermutation
FieldVector< int, n > getPermutation(int m)
Calculate permutation from it's index.
Definition simplex.cc:293
Dune::RefinementImp::HCubeTriangulation::referenceToKuhn
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
Dune::RefinementImp::Simplex::getPermutation
FieldVector< int, n > getPermutation(int m)
Calculate permutation from it's index.
Definition simplex.cc:293
Dune::RefinementImp::Simplex::referenceToKuhn
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
Dune::Codim
Static tag representing a codimension.
Definition dimension.hh:24
Dune::MultiLinearGeometry
generic geometry implementation based on corner coordinates
Definition multilineargeometry.hh:181
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial
Definition hcubetriangulation.cc:63
Dune::RefinementImp::HCubeTriangulation::RefinementImp
Definition hcubetriangulation.cc:67
Dune::RefinementImp::HCubeTriangulation::RefinementImp::vEnd
static VertexIterator vEnd(int nIntervals)
Definition hcubetriangulation.cc:121
Dune::RefinementImp::HCubeTriangulation::RefinementImp::vBegin
static VertexIterator vBegin(int nIntervals)
Definition hcubetriangulation.cc:113
Dune::RefinementImp::HCubeTriangulation::RefinementImp::nElements
static int nElements(int nIntervals)
Definition hcubetriangulation.cc:129
Dune::RefinementImp::HCubeTriangulation::RefinementImp< dimension, CoordType >::Codim< codimension >::This
SubEntityIterator This
Definition hcubetriangulation.cc:360
Dune::RefinementImp::HCubeTriangulation::RefinementImp::CoordVector
FieldVector< CoordType, dimension > CoordVector
Definition hcubetriangulation.cc:76
Dune::RefinementImp::HCubeTriangulation::RefinementImp< dimension, CoordType >::Codim< codimension >::equals
bool equals(const This &other) const
Dune::RefinementImp::HCubeTriangulation::RefinementImp< dimension, CoordType >::Codim< codimension >::SubEntityIterator
SubEntityIterator(int nIntervals, bool end=false)
Dune::RefinementImp::HCubeTriangulation::RefinementImp::ctype
CoordType ctype
Definition hcubetriangulation.cc:71
Dune::RefinementImp::HCubeTriangulation::RefinementImp::ElementIterator
Codim< 0 >::SubEntityIterator ElementIterator
Definition hcubetriangulation.cc:77
Dune::RefinementImp::HCubeTriangulation::RefinementImp::IndexVector
FieldVector< int, dimension+1 > IndexVector
Definition hcubetriangulation.cc:78
Dune::RefinementImp::HCubeTriangulation::RefinementImp::eBegin
static ElementIterator eBegin(int nIntervals)
Definition hcubetriangulation.cc:137
Dune::RefinementImp::HCubeTriangulation::RefinementImp::eEnd
static ElementIterator eEnd(int nIntervals)
Definition hcubetriangulation.cc:145
Dune::RefinementImp::HCubeTriangulation::RefinementImp< dimension, CoordType >::dimension
static constexpr int dimension
Definition hcubetriangulation.cc:69
Dune::RefinementImp::HCubeTriangulation::RefinementImp::VertexIterator
Codim< dimension >::SubEntityIterator VertexIterator
Definition hcubetriangulation.cc:75
Dune::RefinementImp::HCubeTriangulation::RefinementImp::nVertices
static int nVertices(int nIntervals)
Definition hcubetriangulation.cc:105
Dune::RefinementImp::HCubeTriangulation::RefinementImp< dimension, CoordType >::Codim< codimension >::Refinement
RefinementImp< dimension, CoordType > Refinement
Definition hcubetriangulation.cc:359
Dune::RefinementImp::HCubeTriangulation::RefinementImp::Codim
Definition hcubetriangulation.cc:97
Dune::RefinementImp::HCubeTriangulation::RefinementImp::SubEntityIterator::Geometry
Dune::MultiLinearGeometry< CoordType, dimension-codimension, dimension > Geometry
Definition hcubetriangulation.cc:99
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, dimension >::nKuhnSimplices
static constexpr int nKuhnSimplices
Definition hcubetriangulation.cc:176
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, dimension >::index
int index() const
Definition hcubetriangulation.cc:229
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, dimension >::nIntervals_
int nIntervals_
Definition hcubetriangulation.cc:178
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, dimension >::increment
void increment()
Definition hcubetriangulation.cc:199
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, dimension >::kuhnIndex
int kuhnIndex
Definition hcubetriangulation.cc:180
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, dimension >::CoordVector
Refinement::CoordVector CoordVector
Definition hcubetriangulation.cc:161
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, dimension >::geometry
Geometry geometry() const
Definition hcubetriangulation.cc:219
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, dimension >::Geometry
Refinement::template Codim< dimension >::Geometry Geometry
Definition hcubetriangulation.cc:162
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, dimension >::BackendIterator
BackendRefinement::template Codim< dimension >::SubEntityIterator BackendIterator
Definition hcubetriangulation.cc:175
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, dimension >::BackendRefinement
Refinement::BackendRefinement BackendRefinement
Definition hcubetriangulation.cc:174
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, dimension >::backend
BackendIterator backend
Definition hcubetriangulation.cc:181
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, dimension >::Refinement
RefinementImp< dimension, CoordType > Refinement
Definition hcubetriangulation.cc:160
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, dimension >::coords
CoordVector coords() const
Definition hcubetriangulation.cc:212
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, dimension >::backendEnd
const BackendIterator backendEnd
Definition hcubetriangulation.cc:182
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, dimension >::RefinementIteratorSpecial
RefinementIteratorSpecial(int nIntervals, bool end=false)
Definition hcubetriangulation.cc:187
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::BackendIterator
BackendRefinement::template Codim< 0 >::SubEntityIterator BackendIterator
Definition hcubetriangulation.cc:260
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::index
int index() const
Definition hcubetriangulation.cc:317
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::backend
BackendIterator backend
Definition hcubetriangulation.cc:266
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::coords
CoordVector coords() const
Definition hcubetriangulation.cc:325
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::nKuhnSimplices
static constexpr int nKuhnSimplices
Definition hcubetriangulation.cc:261
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::vertexIndices
IndexVector vertexIndices() const
Definition hcubetriangulation.cc:304
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::RefinementIteratorSpecial
RefinementIteratorSpecial(int nIntervals_, bool end=false)
Definition hcubetriangulation.cc:272
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::CoordVector
Refinement::CoordVector CoordVector
Definition hcubetriangulation.cc:241
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::backendEnd
const BackendIterator backendEnd
Definition hcubetriangulation.cc:267
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::kuhnIndex
int kuhnIndex
Definition hcubetriangulation.cc:265
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::increment
void increment()
Definition hcubetriangulation.cc:291
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::BackendRefinement
Refinement::BackendRefinement BackendRefinement
Definition hcubetriangulation.cc:259
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::nIntervals_
int nIntervals_
Definition hcubetriangulation.cc:263
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::IndexVector
Refinement::IndexVector IndexVector
Definition hcubetriangulation.cc:240
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::Refinement
RefinementImp< dimension, CoordType > Refinement
Definition hcubetriangulation.cc:239
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::geometry
Geometry geometry() const
Definition hcubetriangulation.cc:332
Dune::RefinementImp::HCubeTriangulation::RefinementIteratorSpecial< dimension, CoordType, 0 >::Geometry
Refinement::template Codim< 0 >::Geometry Geometry
Definition hcubetriangulation.cc:242
Dune::RefinementImp::Simplex::RefinementImp
Definition simplex.cc:361
Dune::RefinementImp::Simplex::RefinementImp< dimension, CoordType >::nVertices
static int nVertices(int nIntervals)
Dune::RefinementImp::Simplex::RefinementImp< dimension, CoordType >::nElements
static int nElements(int nIntervals)
Dune::RefinementImp::Simplex::RefinementImp< dimension, CoordType >::vBegin
static VertexIterator vBegin(int nIntervals)
Dune::RefinementImp::Simplex::RefinementImp< dimension, CoordType >::eBegin
static ElementIterator eBegin(int nIntervals)