13#ifndef LAGRANGESPACE_HH
14#define LAGRANGESPACE_HH
20#include "boost/multi_array.hpp"
22#include "dune/grid/common/capabilities.hh"
49 template <
class ScalarType,
class GV,
bool restricted=false>
56 typedef typename GridView::Grid
Grid;
60 using ctype =
typename Grid::ctype;
62 static int const dim = Grid::dimension;
87 size_t size(Dune::GeometryType gt)
const
105 typename IndexSet::IndexType
subIndex(
Cell const& cell,
int subentity,
int codim)
const
107 return indexSet().subIndex(cell,subentity,codim);
122 Dune::GeometryType(Dune::GeometryType::simplex,
dim),ord);
138 if (cell.type().isSimplex())
140 if (cell.type().isCube())
144 throw LookupException(
"No Lagrangian shape functions on cubes defined.\n",__FILE__,__LINE__);
146 throw LookupException(
"Not supported geometry type.\n",__FILE__,__LINE__);
177 template <
class GlobalIndices>
179 : m(globalIndices.
size())
185 assert(m==0 || n==m);
192 template <
class Matrix>
201 template <
int d,
int k>
210 template <
class Matrix>
223 for (
int i=0; i<m; ++i)
224 K.incrementrowsize(i);
226 for (
int i=0; i<m; ++i)
229 for (
int i=0; i<m; ++i)
251 template <
class ScalarType,
class GV>
266 int const ord = this->
order();
267 int const dim = GV::Grid::dimension;
272 if ( gt.isSimplex() )
274 if (
dim==1)
return ord+1;
275 if (
dim==2)
return (ord+1)*(ord+2)/2;
276 if (
dim==3)
return (ord+1)*(ord+2)*(ord+3)/6;
277 assert(
"Unknown dimension"==0);
279 if ( gt.isCube() )
return pow(ord+1,
dim);
280 if ( gt.isPyramid() || gt.isPrism() || gt.isNone() ) assert(
"Not implemented"==0);
291 template <
class ShapeFunction,
class Dummy>
293 Dune::GeometryType& gt,
int& subentity,
int& codim,
int& indexInSubentity, Dummy&)
const
298 indexInSubentity = n;
310 template <
class ScalarType,
class GV>
340 Base(Implementation(
gridView,order))
344 template <
class ScalarType,
class GV>
374 Base(Implementation(
gridView,order))
380 template <
class ScalarType,
class GV,
class ShapeFunctionFilter=ScalarSpaceDetail::AllShapeFunctions>
383 public ShapeFunctionFilter
394 : Base(
gridView,
order), ShapeFunctionFilter(shapeFunctionFilter)
405 int const ord = this->
order();
409 if (gt.dim()==0)
return 1;
410 if (gt.dim()==1)
return ord-1;
411 if (gt.dim()==2)
return std::max(0,(ord-2)*(ord-1)/2);
412 if (gt.dim()==3)
return std::max(0,(ord-3)*(ord-2)*(ord-1)/6);
413 assert(
"Unknown dimension"==0);
415 if(gt.isCube())
return std::max(0.0,pow(ord-1,gt.dim()));
416 if(gt.isPyramid() || gt.isPrism()) assert(
"Not implemented"==0);
418 assert(
"Unknown geometry type"==0);
436 template <
class ShapeFunction,
class Data>
438 Dune::GeometryType& gt,
int& subentity,
int& codim,
int& indexInSubentity, Data& data)
const
440 int const dim = Cell::dimension;
441 int const ord = this->
order();
442 IndexSet
const& is = this->
indexSet();
445 std::tie(dummy,codim,subentity,indexInSubentity) = sf.
location();
450 gt = is.types(codim)[0];
453 assert(gt.isSimplex());
458 if (codim>0 && codim<dim && ord>2)
461 std::array<int,dim+1> xi =
barycentric(SimplexLagrangeDetail::tupleIndex<dim>(ord,n),ord);
463 int nVertices =
dim+1-codim;
479 for (
int i=0; i<nVertices; ++i)
480 idx[i] = xi[pi[i]]-1;
484 indexInSubentity = SimplexLagrangeDetail::local(idx,
dim-codim,ord-nVertices);
500 template <
class ScalarType,
class GV>
535 Base(Implementation(
gridView,order))
544 template <
class GV,
class SupportOracle,
class ScalarType=
double>
549 using Index =
typename GV::IndexSet::IndexType;
555 SupportOracle&& supportOracle_)
557 , supportOracle(std::move(supportOracle_))
563 auto const& is = gv.indexSet();
564 int const dim = GV::dimension;
570 for (
int codim=0; codim<=
dim; ++codim)
571 for(
auto const& geoType: is.types(codim))
573 auto& idx = support[geoType];
574 idx.resize(is.size(geoType),-1);
580 Dune::GeometryType cellGeometryType;
581 for (
auto const& cell : elements(gv))
583 cellGeometryType = cell.type();
584 size_t const cellIndex = is.index(cell);
586 if (supportOracle(cell))
588 support[cellGeometryType][cellIndex] = 0;
589 auto refElem = referenceElement(cell.geometry());
594 for (
int codim=1; codim<=
dim; ++codim)
595 for (
int i=0; i<refElem.size(codim); ++i)
596 support[refElem.type(i,codim)][is.subIndex(cell,i,codim)] = 0;
602 for (
auto& p: support)
606 for (
size_t i=0; i<p.second.size(); ++i)
607 if (p.second[i] >= 0)
611 supportSize[p.first] = idx;
618 size_t size(Dune::GeometryType gt)
const
620 return supportSize.find(gt)->second;
630 auto it = support.find(cell.type());
631 if (it==support.end())
633 return it->second[this->
indexSet().index(cell)] >= 0;
638 auto subentityGeometryType = referenceElement(cell).type(subentity,codim);
639 auto it = support.find(subentityGeometryType);
641 if (it==support.end())
642 throw LookupException(
"Geometry type of provided cell not contained in the index set.",__FILE__,__LINE__);
644 auto const& s = it->second;
645 return s[this->
indexSet().subIndex(cell,subentity,codim)];
649 SupportOracle supportOracle;
650 std::map<Dune::GeometryType,size_t> supportSize;
651 std::map<Dune::GeometryType,std::vector<long>> support;
673 template <
class GV,
class SupportOracle,
class ScalarType=
double>
675 :
public UniformScalarMapper<ContinuousLagrangeMapperSubdomainImplementation<GV,SupportOracle,ScalarType>>
716 : Base(Implementation(
gridView,order,std::move(supportOracle)))
ContinuousLagrangeMapper(GridView const &gridView, int order)
Constructor.
static int const continuity
Base::ShapeFunctionSet ShapeFunctionSet
FunctionSpaceElement< FEFunctionSpace< ContinuousLagrangeMapper >, m > Element_t
Type of the FunctionSpaceElement, associated to the FEFunctionSpace.
int dofOnEntity(Dune::GeometryType gt) const
Returns the number of degrees of freedom (global ansatz functions) uniquely associated to the given s...
ContinuousLagrangeMapperImplementation(GV const &gridView, int order, ShapeFunctionFilter shapeFunctionFilter=ShapeFunctionFilter())
GridView::IndexSet IndexSet
void entityIndex(Cell const &cell, ShapeFunction const &sf, int n, Dune::GeometryType >, int &subentity, int &codim, int &indexInSubentity, Data &data) const
Returns the geometry type, subentity number in cell and subentity codimension for the subentity to wh...
static int const continuity
Continuity of the functions in this space. If the support is restricted to a proper subdomain,...
ContinuousLagrangeMapperSubdomain(GridView const &gridView, int order, SupportOracle &&supportOracle)
Constructor.
Base::ShapeFunctionSet ShapeFunctionSet
ContinuousLagrangeMapperSubdomainImplementation(GridView const &gridView, int order, SupportOracle &&supportOracle_)
bool inSupport(typename Base::Cell const &cell) const
Tells whether the given cell is contained in the support.
Index subIndex(typename Base::Cell const &cell, int subentity, int codim) const
size_t size(Dune::GeometryType gt) const
Returns the number of entities of given geometry type in our support.
DiscontinuousLagrangeMapper(GridView const &gridView, int order)
FunctionSpaceElement< FEFunctionSpace< Self >, m > Element_t
Type of the FunctionSpaceElement, associated to the FEFunctionSpace.
static int const continuity
int dofOnEntity(Dune::GeometryType gt) const
void entityIndex(Cell const &cell, ShapeFunction const &sf, int n, Dune::GeometryType >, int &subentity, int &codim, int &indexInSubentity, Dummy &) const
DiscontinuousLagrangeMapperImplementation(GV const &gridView, int order)
DiscontinuousLagrangeMapperSubdomain(GridView const &gridView, int order)
static int const continuity
A class for representing finite element functions.
A class for computing permutations of local vertex numbers of simplex subentities to a globally uniqu...
std::array< int, dimension+1-codim > barycentricSubsetPermutation(int e) const
Computes a permutation of barycentric coordinates to globally unique ordering.
Combiner(GlobalIndices const &globalIndices, ShapeFunctionSet const &sfs)
void rightTransform(Matrix &A) const
In-place computation of . Since is the identity, this is a no-op.
void rightTransform(std::vector< VariationalArg< Scalar, d, k > > &v) const
In-place computation of row vectors .
void leftPseudoInverse(Matrix &A) const
In-place computation of .
typename LagrangeShapeFunctionSetContainer< ctype, dim, Scalar, restricted >::value_type ShapeFunctionSet
bool inSupport(Cell const &cell) const
Tells whether the given cell is contained in the support.
IndexSet::IndexType subIndex(Cell const &cell, int subentity, int codim) const
Returns the index of the specified subentity.
typename Grid::ctype ctype
ShapeFunctionSet const & shapeFunctions(Cell const &cell) const
ShapeFunctionSet const & lowerShapeFunctions(Cell const &cell) const
GridView::IndexSet IndexSet
ShapeFunctionSet const & emptyShapeFunctionSet() const
void update()
This is called on grid modifications and can be overwritten if internal data needs to be recomputed o...
size_t size(Dune::GeometryType gt) const
The number of entities of given geometry type in our support.
GridView const & gridView() const
Kaskade::Cell< GridView > Cell
ScalarConverter< Cell, Scalar > Converter
LagrangeMapperImplementation(GridView const &gridView_, int order_)
IndexSet const & indexSet() const
The index set obtained from gridView().
ShapeFunctionSet< ctype, dimension, Scalar > value_type
An exception that can be thrown whenever a key lookup fails.
A Converter for scalar shape functions that do not change their value under transformation from refer...
virtual std::tuple< int, int, int, int > location() const =0
Returns a tuple (nominalOrder,codim,entity,index) giving detailed information about the location of t...
This file contains various utility functions that augment the basic functionality of Dune.
FEFunctionSpace and FunctionSpaceElement and the like.
FunctionSpaceElement< FEFunctionSpace< Self >, m > Element_t
Type of the FunctionSpaceElement, associated to the FEFunctionSpace.
FunctionSpaceElement< FEFunctionSpace< ContinuousLagrangeMapperSubdomain >, m > Element_t
Type of the FunctionSpaceElement, associated to the FEFunctionSpace.
typename GridView::template Codim< 0 >::Entity Cell
The type of cells (entities of codimension 0) in the grid view.
Dune::FieldVector< CoordType, dim+1 > barycentric(Dune::FieldVector< CoordType, dim > const &x)
Computes the barycentric coordinates of a point in the unit simplex.
define Lagrange type shape functions for simplicial elements of arbitrary dimension and order
typename GetScalar< Type >::type ScalarType
Extracts the scalar field type from linear algebra data types.
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....
FunctionSpaceElement< FEFunctionSpace< ContinuousLagrangeMapper >, m > type
FunctionSpaceElement< FEFunctionSpace< ContinuousLagrangeMapperSubdomain >, m > type
FunctionSpaceElement< FEFunctionSpace< Self >, m > type
FunctionSpaceElement< FEFunctionSpace< Self >, m > type
void treatBoundary(Data &, GridView const &, Cell const &, int, int) const
A class that stores values, gradients, and Hessians of evaluated shape functions.