13#ifndef HIERARCHICSHAPEFUNCTIONS_HH
14#define HIERARCHICSHAPEFUNCTIONS_HH
29#include <dune/common/fvector.hh>
30#include <dune/geometry/referenceelements.hh>
44 template <
class,
int,
class>
class HierarchicSimplexShapeFunctionSet;
45 template <
class,
int,
class>
class HierarchicExtensionSimplexShapeFunctionSet;
50 namespace HierarchicDetail {
58 int nSubentities(
int d,
int c);
66 int cdimSize(
int d,
int p,
int c);
73 int size(
int d,
int p);
81 std::pair<int,int> codim(
int d,
int p,
int k);
93 std::tuple<int,int,int> tupleIndex(
int d,
int p,
int k);
104 double shapeFunction(
int d,
int p,
int k,
double const b[]);
116 void dShapeFunction(
int d,
int p,
int k,
double const b[],
double* grad);
123 int actualOrder(
int d,
int p,
int k);
136 int entityPermutation(
int d,
int c,
int e,
int const vGlobal[]);
152 std::tuple<int,int> sfPermutation(
int d,
int p,
int c,
int e,
int k,
int const vGlobal[]);
155 template <
class ctype,
int dimension,
class Scalar,
bool restricted>
156 struct ChooseShapeFunctionSet
158 typedef HierarchicSimplexShapeFunctionSet<ctype,dimension,Scalar> type;
161 template <
class ctype,
int dimension,
class Scalar>
162 struct ChooseShapeFunctionSet<ctype,dimension,Scalar,true>
164 typedef RestrictedShapeFunctionSet<HierarchicSimplexShapeFunctionSet<ctype,dimension,Scalar> > type;
167 template <
class ctype,
int dimension,
class Scalar,
bool restricted>
168 struct ChooseExtensionShapeFunctionSet
170 typedef HierarchicExtensionSimplexShapeFunctionSet<ctype,dimension,Scalar> type;
173 template <
class ctype,
int dimension,
class Scalar>
174 struct ChooseExtensionShapeFunctionSet<ctype,dimension,Scalar,true>
176 typedef RestrictedShapeFunctionSet<HierarchicExtensionSimplexShapeFunctionSet<ctype,dimension,Scalar> > type;
254 template <
class ctype,
int dimension,
class Scalar>
258 static int const dim = dimension;
275 order_(
order), number_(k)
278 assert(0<=k && k<HierarchicDetail::size(
dim,
order));
279 std::tie(codim_,entity_,entityIndex_) = HierarchicDetail::tupleIndex(
dim,
order,k);
280 actualOrder = HierarchicDetail::actualOrder(
dim,order_,k);
284 : actualOrder(other.actualOrder), order_(other.order_), number_(other.number_),
285 codim_(other.codim_), entity_(other.entity_), entityIndex_(other.entityIndex_)
297 return HierarchicDetail::shapeFunction(
dim,order_,number_,&zeta[0]);
311 HierarchicDetail::dShapeFunction(
dim,order_,number_,&zeta[0],&bgrad[0]);
314 for (
int i=0; i<
dim; ++i)
315 grad[0][i] = bgrad[i]-bgrad[
dim];
344 static bool visited =
false;
348 std::cerr <<
"Not implemented: Hierarchic shape function 2nd derivative at " << __FILE__ <<
":" << __LINE__ <<
"\n";
364 virtual std::tuple<int,int,int,int>
location()
const
366 return std::make_tuple(order_,codim_,entity_,entityIndex_);
374 int order()
const {
return actualOrder; }
397 template <
class ctype,
int dimension,
class Scalar>
421 for (
int o=0; o<=ord; ++o) {
422 int n = HierarchicDetail::size(dimension,o);
423 for (
int i=0; i<n; ++i) {
445 for (
int i=0; i<n; ++i) {
446 for (
int j=0; j<dimension; ++j)
447 this->
iNodes[i][j] =
static_cast<ctype
>(b[j])/this->
order_;
452 computePseudoInverse();
471 virtual Dune::GeometryType
type()
const {
return Dune::GeometryType(Dune::GeometryType::simplex,dimension); }
482 assert(index>=0 && index <
sf.size());
483 sf.erase(
sf.begin()+index);
485 computePseudoInverse();
489 std::vector<value_type>
sf;
493 void computePseudoInverse()
497 for (
int j=0; j<
sf.size(); ++j)
498 for (
int i=0; i<this->
iNodes.size(); ++i)
499 A[i][j] =
sf[j].evaluateFunction(this->
iNodes[i]);
510 template <
class ctype,
int dimension,
class Scalar,
bool restricted = false>
517 typedef std::map<std::pair<Dune::GeometryType,int>,
value_type const*> Container;
518 typedef typename HierarchicDetail::ChooseShapeFunctionSet<ctype,dimension,Scalar,restricted>::type ShapeFunctionType;
529 Dune::GeometryType simplex(Dune::GeometryType::simplex,dimension);
536 container.insert(
typename Container::value_type(std::make_pair(simplex,i),sfs));
543 for (
typename Container::iterator i=container.begin(); i!=container.end(); ++i)
549 typename Container::const_iterator i = container.find(std::make_pair(type,order));
550 assert(i!=container.end());
568 template <
class ctype,
int dimension,
class Scalar>
577 return container(type,order);
593 template <
class ctype,
int dimension,
class Scalar>
612 int n = HierarchicDetail::size(dimension,ord);
618 for (
int i=0; i<n; ++i) {
634 for (
int i=0; i<m; ++i) {
635 for (
int j=0; j<dimension; ++j)
636 this->
iNodes[i][j] =
static_cast<ctype
>(b[j])/this->
order_;
641 computePseudoInverse();
652 virtual Dune::GeometryType
type()
const
654 return Dune::GeometryType(Dune::GeometryType::simplex,dimension);
666 assert(index>=0 && index <
sf.size());
667 sf.erase(
sf.begin()+index);
669 computePseudoInverse();
673 std::vector<value_type>
sf;
677 void computePseudoInverse()
680 for (
int j=0; j<
sf.size(); ++j)
681 for (
int i=0; i<this->
iNodes.size(); ++i)
682 A[i][j] =
sf[j].evaluateFunction(this->
iNodes[i]);
690 template <
class ctype,
int dimension,
class Scalar,
bool restricted = false>
697 typedef std::map<std::pair<Dune::GeometryType,int>,
value_type const*> Container;
698 typedef typename HierarchicDetail::ChooseExtensionShapeFunctionSet<ctype,dimension,Scalar,restricted>::type ShapeFunctionType;
709 Dune::GeometryType simplex(Dune::GeometryType::simplex,dimension);
716 container.insert(
typename Container::value_type(std::make_pair(simplex,i),sfs));
723 for (
typename Container::iterator i=container.begin(); i!=container.end(); ++i)
729 typename Container::const_iterator i = container.find(std::make_pair(type,order));
730 assert(i!=container.end());
748 template <
class ctype,
int dimension,
class Scalar>
757 return container(type,order);
A LAPACK-compatible dense matrix class with shape specified at runtime.
void resize(size_type r, size_type c)
Resizes the matrix to r x c, leaving the entries in an undefined state.
ShapeFunctionSet< ctype, dimension, Scalar > value_type
HierarchicExtensionShapeFunctionSetContainer(int maxOrder)
virtual value_type const & operator()(Dune::GeometryType type, int order) const
access a shape function via type and order
virtual ~HierarchicExtensionShapeFunctionSetContainer()
A container of hierarchic shape functions of nominal order Ord on the unit simplex of grid dimension....
HierarchicExtensionSimplexShapeFunctionSet(HierarchicExtensionSimplexShapeFunctionSet const &other)=default
HierarchicSimplexShapeFunction< ctype, dimension, Scalar > value_type
HierarchicExtensionSimplexShapeFunctionSet(HierarchicExtensionSimplexShapeFunctionSet &&other)=default
virtual void interpolate(typename ShapeFunctionSet< ctype, dimension, Scalar >::SfValueArray const &A, Matrix &IA) const
std::vector< value_type > sf
virtual Dune::GeometryType type() const
DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > > pinv
HierarchicExtensionSimplexShapeFunctionSet(int ord)
void removeShapeFunction(size_t index)
virtual value_type const & operator[](int i) const
Random access to a shape function.
ShapeFunctionSet< ctype, dimension, Scalar >::Matrix Matrix
ShapeFunctionSet< ctype, dimension, Scalar > value_type
HierarchicShapeFunctionSetContainer(int maxOrder)
virtual ~HierarchicShapeFunctionSetContainer()
virtual value_type const & operator()(Dune::GeometryType type, int order) const
access a shape function via type and order
Scalar hierarchic shape functions on the unit simplex.
virtual Dune::FieldVector< ResultType, comps > evaluateFunction(Dune::FieldVector< CoordType, dim > const &x) const
int order() const
The actual polynomial order of the shape function.
HierarchicSimplexShapeFunction()
HierarchicSimplexShapeFunction(int order, int k)
Creates the k-th shape function of given order.
virtual Tensor< Scalar, 1, dim, dim > evaluate2ndDerivative(Dune::FieldVector< CoordType, dim > const &x) const
Evaluates the second derivative of the shape function.
HierarchicSimplexShapeFunction(HierarchicSimplexShapeFunction const &other)
virtual std::tuple< int, int, int, int > location() const
Information about the association of the shape function to subentities of the simplex.
virtual Dune::FieldMatrix< Scalar, 1, dim > evaluateDerivative(Dune::FieldVector< CoordType, dim > const &x) const
Evaluates the derivative of the shape function.
A container of hierarchic shape functions (see HierarchicSimplexShapeFunction) up to a given nominal ...
std::vector< value_type > sf
virtual void interpolate(typename ShapeFunctionSet< ctype, dimension, Scalar >::SfValueArray const &A, Matrix &IA) const
ShapeFunctionSet< ctype, dimension, Scalar >::Matrix Matrix
HierarchicSimplexShapeFunctionSet(int ord)
Constructs a hierarchic shape function set.
virtual Dune::GeometryType type() const
virtual ~HierarchicSimplexShapeFunctionSet()
HierarchicSimplexShapeFunction< ctype, dimension, Scalar > value_type
void removeShapeFunction(size_t index)
DynamicMatrix< Dune::FieldMatrix< Scalar, 1, 1 > > pinv
virtual value_type const & operator[](int i) const
Random access to a shape function.
HierarchicSimplexShapeFunctionSet(HierarchicSimplexShapeFunctionSet &&other)=default
Move constructor.
HierarchicSimplexShapeFunctionSet(HierarchicSimplexShapeFunctionSet const &other)=default
Copy constructor.
Base class for sets of shape function containers.
A set of shape functions.
Scalar Scalar
Scalar field type.
InterpolationNodes iNodes
void initHierarchicalProjection(ShapeFunctionSet< ctype, dimension, T, comp > const *sfl)
Initialize the hierarchical projection matrix based on the given lower order shape function set.
int maxOrder(Evaluators const &evals)
Computes the maximum ansatz order used in a collection of evaluators.
Dune::FieldVector< CoordType, dim+1 > barycentric(Dune::FieldVector< CoordType, dim > const &x)
Computes the barycentric coordinates of a point in the unit simplex.
Dune::FieldVector< T, n > max(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise maximum.
constexpr int binomial(int n, int k)
Computes the binomial coefficient .
void next_multiindex(It first, It last, int const m)
Computes the next nonnegative multiindex of order m.
HierarchicShapeFunctionSetContainer< ctype, dimension, Scalar >::value_type const & hierarchicShapeFunctionSet(Dune::GeometryType type, int order)
Returns a Hierarchic shape function set for given reference element type and given polynomial order....
void pseudoinverse(SLAPMatrix< Scalar > A, SLAPMatrix< Scalar > &Ainv)
HierarchicExtensionShapeFunctionSetContainer< ctype, dimension, Scalar >::value_type const & hierarchicExtensionShapeFunctionSet(Dune::GeometryType type, int order)