13#ifndef FEM_LAGRANGESHAPEFUNCTIONS_HH
14#define FEM_LAGRANGESHAPEFUNCTIONS_HH
32#include <dune/common/config.h>
33#include <dune/common/fvector.hh>
34#include <dune/geometry/referenceelements.hh>
35#include <dune/geometry/quadraturerules.hh>
51 template <
class ctype,
int dimension,
class Scalar>
52 class LagrangeSimplexShapeFunctionSet;
57 namespace SimplexLagrangeDetail {
64 inline int size(
int dim,
int order)
79 inline int local(
int const* xi,
int dim,
int order)
81 assert(std::accumulate(xi,xi+dim,0)<=order);
84 for (
int dir=0; dir<dim; ++dir)
85 for (
int i=0; i<xi[dir]; ++i) {
86 local += size(dim-1-dir,order);
102 std::array<int,dim> tupleIndex(
int const order,
int const loc)
106 std::array<int,dim> xi;
107 std::fill(begin(xi),end(xi),0);
109 for (
int dir=0; dir<dim; ++dir) {
110 int s = size(dim-1-dir,m);
111 while (k>=s && s>0) {
115 s = size(dim-1-dir,m);
118 assert(local(&xi[0],dim,order)==loc);
131 for (
int i=0; i<dim; ++i)
132 x[i] = order==0? 1.0/(dim+1):
static_cast<double>(xi[i])/(order>0? order: 1);
140 template <
size_t dim_1>
141 int codim(std::array<int,dim_1>
const& xi)
150 for (
int i=0; i<=dim; ++i)
151 if (xi[i]==0) ++
count;
163 template <
size_t dim_1>
164 int entity(std::array<int,dim_1>
const& xi)
174 if (xi[0]!=0)
return 1;
175 if (xi[1]!=0)
return 0;
177 default: assert(
false);
185 if (xi[0]==0)
return 1;
186 if (xi[1]==0)
return 0;
187 if (xi[2]==0)
return 2;
190 if (xi[0]!=0)
return 1;
191 if (xi[1]!=0)
return 2;
192 if (xi[2]!=0)
return 0;
201 if (xi[0]==0)
return 2 ;
202 if (xi[1]==0)
return 1 ;
203 if (xi[2]==0)
return 0 ;
204 if (xi[3]==0)
return 3 ;
207 if (xi[0]==0 && xi[1]==0)
return 3;
208 if (xi[0]==0 && xi[2]==0)
return 1;
209 if (xi[0]==0 && xi[3]==0)
return 5;
210 if (xi[1]==0 && xi[2]==0)
return 0;
211 if (xi[1]==0 && xi[3]==0)
return 4;
212 if (xi[2]==0 && xi[3]==0)
return 2;
215 if (xi[0]!=0)
return 1;
216 if (xi[1]!=0)
return 2;
217 if (xi[2]!=0)
return 3;
218 if (xi[3]!=0)
return 0;
223 assert(
"Unknown dimension/codimension\n"==0);
246 template <
class ctype,
int dimension,
class Scalar,
bool restricted>
247 struct ChooseShapeFunctionSet
249 typedef LagrangeSimplexShapeFunctionSet<ctype,dimension,Scalar> type;
252 template <
class ctype,
int dimension,
class Scalar>
253 struct ChooseShapeFunctionSet<ctype,dimension,Scalar,true>
255 typedef RestrictedShapeFunctionSet<LagrangeSimplexShapeFunctionSet<ctype,dimension,Scalar> > type;
293 std::array<int,dim+1>
index(
int i)
const
300 std::vector<std::array<int,dim+1>>
ls;
312 template <
int dim,
class Real=
double>
336 std::vector<Real> normalization;
341 template <
int dim,
class Real=
double>
353 std::vector<Real> lobatto;
381 template <
class ctype,
int dimension,
class Basis,
class Scalar=
double>
385 static int const dim = dimension;
399 : local_(-1), codim_(-1), entity_(-1), entityIndex_(-1) {}
408 std::shared_ptr<Basis const> basis_)
412 int const order = basis->order();
427 auto xi = basis->index(local_);
429 codim_ = SimplexLagrangeDetail::codim(xi);
430 entity_ = SimplexLagrangeDetail::entity(xi);
432 int yi[
dim-codim_+1];
434 for (
int i=0; i<=
dim; ++i)
437 assert(j==
dim-codim_+1);
438 entityIndex_ = SimplexLagrangeDetail::local(yi,
dim-codim_,order-(
dim-codim_+1));
439 assert(entityIndex_>=0);
457 return basis->value(local_,x);
472 for (
int dir=0; dir<
dim; ++dir)
473 d[0][dir] = basis->derivative(local_,dir,x);
490 for (
int dir1=0; dir1<
dim; ++dir1)
491 for (
int dir2=0; dir2<=dir1; ++dir2)
492 d[0][dir1][dir2] = basis->derivative2(local_,dir1,dir2,x);
494 for (
int dir1=0; dir1<
dim; ++dir1)
495 for (
int dir2=dir1+1; dir2<
dim; ++dir2)
496 d[0][dir1][dir2] = d[0][dir2][dir1];
501 virtual std::tuple<int,int,int,int>
location()
const
503 return std::make_tuple(basis->order(),codim_,entity_,entityIndex_);
512 std::shared_ptr<Basis const> basis;
523 template <
class ctype,
int dimension,
class Scalar>
537 int const dim = dimension;
538 int const n = basis->size();
541 for (
int i=0; i<n; ++i)
544 for (
int j=0; j<dim; ++j)
545 this->
iNodes[i] = basis->nodalPosition(i);
557 for(
size_t i=0; i<other.
sf.size(); ++i)
558 sf.push_back(std::make_unique<value_type>(
dynamic_cast<value_type const&
>(other[i])));
569 assert(A.N()==
sf.size());
576 assert(index>=0 && index <
sf.size());
577 sf.erase(
sf.begin()+index);
582 std::vector<std::unique_ptr<ShapeFunction<ctype,dimension,Scalar>>>
sf;
585 std::shared_ptr<Basis const> basis;
612 template <
class ctype,
int dimension,
class Scalar,
int O>
616 static int const dim = dimension;
633 : local_(other.local_), codim_(other.codim_), entity_(other.entity_), entityIndex_(other.entityIndex_),
634 xi(other.xi), normalization(other.normalization), node(other.node)
654 return normalization * evaluateNonNormalized(x);
659 return normalization * evaluateNonNormalized(x);
672 assert(0<=dir && dir<
dim);
673 return normalization * evaluateDerivativeNonNormalized(dir,x);
679 for (
int dir=0; dir<
dim; ++dir)
680 d[0][dir] = normalization * evaluateDerivativeNonNormalized(dir,x);
688 for (
int dir1=0; dir1<
dim; ++dir1)
689 for (
int dir2=0; dir2<
dim; ++dir2)
690 dd[0][dir1][dir2] = normalization * evaluate2ndDerivativeNonNormalized(dir1,dir2,x);
702 int codim()
const {
return codim_; }
717 template <
class Cell>
723 if (entityIndex_ >= 0)
729 assert(
"Not implemented!"==0);
739 for (
int i=0; i<
dim; ++i)
740 pos[i] = node[xi[i]];
744 virtual std::tuple<int,int,int,int>
location()
const {
745 return std::make_tuple(
order,codim_,entity_,entityIndex_);
760 for (
int i=0; i<
dim; ++i)
761 for (
int k=0; k<=
order; ++k)
771 static bool visited =
false;
775 std::cerr <<
"Not implemented: Lagrange cube shape function 2nd derivative at " << __FILE__ <<
":" << __LINE__ <<
"\n";
782 template <
class ctype,
int dimension,
class Scalar,
int O>
787 template <
class ctype,
int dimension,
class Scalar,
int Ord>
805 virtual Dune::GeometryType
type()
const {
return Dune::GeometryType(Dune::GeometryType::cube,dimension); }
808 std::vector<value_type> sf;
820 template <
class ctype,
int dimension,
class Scalar,
bool restricted=false>
829 using Key = std::pair<Dune::GeometryType,int>;
830 using Value = std::unique_ptr<value_type>;
831 typedef std::map<Key,Value> Container;
833 using ActualSimplexSFS =
typename SimplexLagrangeDetail::ChooseShapeFunctionSet<ctype,dimension,Scalar,restricted>::type;
856 mutable Container container;
857 mutable std::mutex mut;
859 value_type const& createShapeFunctionSet(Dune::GeometryType simplex,
int order)
const;
870 template <
class ctype,
int dimension,
class Scalar=
double,
bool restricted=false>
876 return container(type,order);
A LAPACK-compatible dense matrix class with shape specified at runtime.
Lagrange shape functions on an equidistant grid over the simplex. These are polynomial basis function...
Real value(int i, Vector const &xi) const
Real derivative(int i, int dir, Vector const &xi) const
EquidistantLagrange(int order)
Constructor.
Vector nodalPosition(int i) const
The spatial location of the interpolation node associated with the i-th basis function.
Real derivative2(int i, int dir1, int dir2, Vector const &xi) const
int order() const
The polynomial ansatz order of this Lagrange basis.
int size() const
The number of Lagrange polynomials.
std::vector< std::array< int, dim+1 > > ls
LagrangeBase(int order)
Constructor.
std::array< int, dim+1 > index(int i) const
Scalar Lagrange shape functions on the unit cube.
int entity() const
Returns the subentity number of the smallest codimension subentity on which the associated node is lo...
int localindex(int) const
Returns the local index of the shape function.
LagrangeCubeShapeFunction()
virtual Dune::FieldVector< Scalar, 1 > evaluateFunction(Dune::FieldVector< ctype, dim > const &x) const
Evaluates the shape function (all components at once).
LagrangeCubeShapeFunction(LagrangeCubeShapeFunction const &other)
virtual std::tuple< int, int, int, int > location() const
Returns a tuple (nominalOrder,codim,entity,index) giving detailed information about the location of t...
virtual Dune::FieldMatrix< ResultType, 1, dim > evaluateDerivative(Dune::FieldVector< CoordType, dim > const &x) const
Evaluates the derivative of the shape function (all components and all directions at once).
ResultType evaluateDerivative(int, int dir, Dune::FieldVector< CoordType, dim > const &x) const
Evaluates the partial derivative of the shape function in coordinate direction dir.
int entityIndex(Cell const &) const
Returns the local index on the subentity.
virtual Tensor< ResultType, 1, dim, dim > evaluate2ndDerivative(Dune::FieldVector< CoordType, dim > const &x) const
Evaluates the second derivative of the shape function (all components and all directions at once).
int codim() const
Returns the codimension of the subentity on which the associated node is located.
ResultType evaluateFunction(int, Dune::FieldVector< CoordType, dim > const &x) const
Evaluates the shape function at point x.
LagrangeCubeShapeFunction(Dune::FieldVector< int, dimension > const &xi_)
Creates a shape function associated to the node with indices xi_.
Dune::FieldVector< CoordType, dim > position() const
Returns the element-local position of the node associated to the shape function.
virtual void interpolate(typename ShapeFunctionSet< ctype, dimension, Scalar >::SfValueArray const &A, Matrix &IA) const
LagrangeCubeShapeFunctionSet()
virtual value_type const & operator[](int i) const
Random access to a shape function.
LagrangeCubeShapeFunction< ctype, dimension, Scalar, Ord > value_type
virtual Dune::GeometryType type() const
ShapeFunctionSet< ctype, dimension, Scalar >::Matrix Matrix
ShapeFunctionSet< ctype, dimension, Scalar > value_type
virtual value_type const & operator()(Dune::GeometryType type, int order) const
Obtain a reference to a (persistent) shape function set of given order on cells of the given geometry...
LagrangeShapeFunctionSetContainer()
Scalar Lagrange shape functions on the unit simplex.
LagrangeSimplexShapeFunction()
Default constructor.
virtual std::tuple< int, int, int, int > location() const
Returns a tuple (nominalOrder,codim,entity,index) giving detailed information about the location of t...
virtual Dune::FieldVector< Scalar, 1 > evaluateFunction(Dune::FieldVector< CoordType, dim > const &x) const
Evaluates the shape function at point x.
virtual Dune::FieldMatrix< Scalar, 1, dim > evaluateDerivative(Dune::FieldVector< CoordType, dim > const &x) const
Evaluates the derivative of the shape function.
virtual Tensor< Scalar, 1, dim, dim > evaluate2ndDerivative(Dune::FieldVector< CoordType, dim > const &x) const
Evaluates the second derivative of the shape function.
LagrangeSimplexShapeFunction(int local, std::shared_ptr< Basis const > basis_)
Creates a shape function associated to the node with tuple index xi_. The entries in xi_ have to be n...
LagrangeSimplexShapeFunction(LagrangeSimplexShapeFunction const &other)=default
Copy constructor.
A container of Lagrange shape functions of order Ord on the unit simplex of grid dimension....
LagrangeSimplexShapeFunction< ctype, dimension, Basis, Scalar > value_type
virtual ShapeFunction< ctype, dimension, Scalar > const & operator[](int i) const
Random access to a shape function.
LagrangeSimplexShapeFunctionSet(int order)
void removeShapeFunction(size_t index)
virtual void interpolate(typename ShapeFunctionSet< ctype, dimension, Scalar >::SfValueArray const &A, Matrix &IA) const
std::vector< std::unique_ptr< ShapeFunction< ctype, dimension, Scalar > > > sf
LagrangeSimplexShapeFunctionSet(LagrangeSimplexShapeFunctionSet const &other)
ShapeFunctionSet< ctype, dimension, Scalar >::Matrix Matrix
Real value(int i, Vector const &x) const
Vector nodalPosition(int i) const
Real derivative(int i, int dir, Vector const &xi) const
LobattoGridLagrange(int order)
Real derivative2(int i, int dir1, int dir2, Vector const &xi) const
Base class for sets of shape function containers.
A set of shape functions.
Scalar Scalar
Scalar field type.
InterpolationNodes iNodes
int order() const
Maximal polynomial order of shape functions.
int count(Cell const &cell, int codim)
Computes the number of subentities of codimension c of a given entity.
typename GridView::template Codim< 0 >::Entity Cell
The type of cells (entities of codimension 0) in the grid view.
constexpr int binomial(int n, int k)
Computes the binomial coefficient .
LagrangeShapeFunctionSetContainer< ctype, dimension, Scalar, restricted >::value_type const & lagrangeShapeFunctionSet(Dune::GeometryType type, int order)
Returns a Lagrange shape function set for given reference element type and given polynomial order....