Go to the documentation of this file.
3 #ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_LAGRANGEBASIS_HH
4 #define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_LAGRANGEBASIS_HH
6 #include <dune/common/exceptions.hh>
8 #include <dune/localfunctions/lagrange.hh>
9 #include <dune/localfunctions/lagrange/equidistantpoints.hh>
10 #include <dune/localfunctions/lagrange/pqkfactory.hh>
32 template<
typename GV,
int k,
typename R=
double>
35 template<
typename GV,
int k,
class MI,
typename R=
double>
38 template<
typename GV,
int k,
class MI,
typename R=
double>
58 template<
typename GV,
int k,
class MI,
typename R>
61 static const int dim = GV::dimension;
62 static const bool useDynamicOrder = (k<0);
74 template<
typename,
int,
class,
typename>
100 if (!useDynamicOrder &&
order!=std::numeric_limits<unsigned int>::max())
101 DUNE_THROW(RangeError,
"Template argument k has to be -1 when supplying a run-time order!");
103 for (
int i=0; i<=dim; i++)
194 DUNE_THROW(Dune::NotImplemented,
"No size method for " << dim <<
"d grids available yet!");
200 assert(prefix.size() == 0 || prefix.size() == 1);
201 return (prefix.size() == 0) ?
size() : 0;
215 return power(
order()+1, (
unsigned int)GV::dimension);
223 return (useDynamicOrder) ?
order_ : k;
254 return order() == 0 ? (dim == simplexDim ? 1 : 0) : Dune::binomial(std::size_t(
order()-1),simplexDim);
292 template<
typename GV,
int k,
typename R>
297 template<
typename Domain,
typename Range,
int dim>
298 class LagrangeRunTimeLFECache
301 using FiniteElementType = LagrangeLocalFiniteElement<EquidistantPointSet,dim,Domain,Range>;
303 const FiniteElementType& get(GeometryType type)
305 auto i = data_.find(type);
307 i = data_.emplace(type,FiniteElementType(type,
order_)).first;
311 std::map<GeometryType, FiniteElementType> data_;
315 static const int dim = GV::dimension;
316 static const bool useDynamicOrder = (k<0);
318 using FiniteElementCache =
typename std::conditional<(useDynamicOrder),
319 LagrangeRunTimeLFECache<typename GV::ctype, R, dim>,
320 PQkLocalFiniteElementCache<typename GV::ctype, R, dim, k>
326 using Element =
typename GV::template Codim<0>::Entity;
342 Hybrid::ifElse(Std::bool_constant<(useDynamicOrder)>(),
377 return (useDynamicOrder) ?
order_ : k;
390 template<
typename GV,
int k,
class MI,
typename R>
393 enum {dim = GV::dimension};
394 static const bool useDynamicOrder = (k<0);
433 assert(
node_ !=
nullptr);
438 template<
typename It>
441 assert(
node_ !=
nullptr);
449 auto dofDim = dim - localKey.codim();
456 if (k==1 || dofDim==0) {
457 *it = {{ (
size_type)(gridIndexSet.subIndex(element,localKey.subEntity(),dim)) }};
467 + localKey.index() }};
472 const auto refElement
473 = Dune::referenceElement<double,dim>(element.type());
477 auto v0 = (
size_type)gridIndexSet.subIndex(element,refElement.subEntity(localKey.subEntity(),localKey.codim(),0,dim),dim);
478 auto v1 = (
size_type)gridIndexSet.subIndex(element,refElement.subEntity(localKey.subEntity(),localKey.codim(),1,dim),dim);
479 bool flip = (v0 > v1);
486 + localKey.index() }};
495 if (element.type().isTriangle())
500 else if (element.type().isQuadrilateral())
506 DUNE_THROW(Dune::NotImplemented,
"2d elements have to be triangles or quadrilaterals");
509 const auto refElement
510 = Dune::referenceElement<double,dim>(element.type());
513 DUNE_THROW(Dune::NotImplemented,
"LagrangeNodalBasis for 3D grids is only implemented if k<=3");
515 if (
order()==3 and !refElement.type(localKey.subEntity(), localKey.codim()).isTriangle())
516 DUNE_THROW(Dune::NotImplemented,
"LagrangeNodalBasis for 3D grids with k==3 is only implemented if the grid is a simplex grid");
527 if (element.type().isTetrahedron())
532 else if (element.type().isHexahedron())
537 else if (element.type().isPrism())
542 else if (element.type().isPyramid())
548 DUNE_THROW(Dune::NotImplemented,
"3d elements have to be tetrahedra, hexahedra, prisms, or pyramids");
550 DUNE_THROW(Dune::NotImplemented,
"Grids of dimension larger than 3 are no supported");
552 DUNE_THROW(Dune::NotImplemented,
"Grid contains elements not supported for the LagrangeNodalBasis");
571 namespace BasisFactory {
575 template<
int k,
typename R=
double>
576 class LagrangePreBasisFactory
578 static const bool useDynamicOrder = (k<0);
580 static const std::size_t requiredMultiIndexSize = 1;
583 LagrangePreBasisFactory() : order_(0)
587 LagrangePreBasisFactory(
unsigned int order)
591 template<
class MultiIndex,
class Gr
idView>
592 auto makePreBasis(
const GridView& gridView)
const
594 return (useDynamicOrder)
615 template<std::
size_t k,
typename R=
double>
618 return Imp::LagrangePreBasisFactory<k,R>();
628 template<
typename R=
double>
631 return Imp::LagrangePreBasisFactory<-1,R>(order);
661 template<
typename GV,
int k=-1,
typename R=
double>
672 #endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_LAGRANGEBASIS_HH
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: lagrangebasis.hh:211
size_type hexahedronOffset_
Definition: lagrangebasis.hh:286
std::array< size_type, dim+1 > dofsPerSimplex_
Definition: lagrangebasis.hh:274
typename GV::template Codim< 0 >::Entity Element
Definition: lagrangebasis.hh:326
size_type computeDofsPerPyramid() const
Definition: lagrangebasis.hh:268
LagrangeNode()
Constructor without order (uses the compile-time value)
Definition: lagrangebasis.hh:330
const Element & element() const
Return current element, throw if unbound.
Definition: lagrangebasis.hh:351
size_type triangleOffset_
Definition: lagrangebasis.hh:281
size_type dofsPerPrism_
Definition: lagrangebasis.hh:276
PQMultiIndex MultiIndex
Type used for global numbering of the basis vectors.
Definition: lagrangebasis.hh:86
size_type quadrilateralOffset_
Definition: lagrangebasis.hh:282
LagrangeNode(unsigned int order)
Constructor with a run-time order.
Definition: lagrangebasis.hh:336
unsigned int order_
Definition: lagrangebasis.hh:381
size_type dofsPerCube(std::size_t cubeDim) const
Number of degrees of freedom assigned to a cube (without the ones assigned to its faces!...
Definition: lagrangebasis.hh:236
std::size_t size_type
Type used for indices and size information.
Definition: lagrangebasis.hh:70
LagrangePreBasis(const GridView &gv)
Constructor for a given grid view object with compile-time order.
Definition: lagrangebasis.hh:92
std::size_t size_type
Definition: lagrangebasis.hh:325
size_type prismOffset_
Definition: lagrangebasis.hh:285
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: lagrangebasis.hh:143
A pre-basis for a PQ-lagrange bases with given order.
Definition: lagrangebasis.hh:39
size_type tetrahedronOffset_
Definition: lagrangebasis.hh:283
auto lagrange()
Create a pre-basis factory that can create a Lagrange pre-basis.
Definition: lagrangebasis.hh:616
auto order() const
Definition: lagrangebasis.hh:559
size_type computeDofsPerPrism() const
Definition: lagrangebasis.hh:263
unsigned int order() const
Definition: lagrangebasis.hh:375
void bind(const Node &node)
Bind the view to a grid element.
Definition: lagrangebasis.hh:417
LagrangeNodeIndexSet(const PreBasis &preBasis)
Definition: lagrangebasis.hh:407
typename FiniteElementCache::FiniteElementType FiniteElement
Definition: lagrangebasis.hh:327
size_type dofsPerPyramid_
Definition: lagrangebasis.hh:277
size_type computeDofsPerCube(std::size_t cubeDim) const
Number of degrees of freedom assigned to a cube (without the ones assigned to its faces!...
Definition: lagrangebasis.hh:258
GridView gridView_
Definition: lagrangebasis.hh:219
void bind(const Element &e)
Bind to element.
Definition: lagrangebasis.hh:366
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: lagrangebasis.hh:137
size_type dofsPerPrism() const
Definition: lagrangebasis.hh:241
FiniteElementCache cache_
Definition: lagrangebasis.hh:383
unsigned int order() const
Definition: lagrangebasis.hh:221
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:46
const Element * element_
Definition: lagrangebasis.hh:385
size_type pyramidOffset_
Definition: lagrangebasis.hh:284
size_type computeDofsPerSimplex(std::size_t simplexDim) const
Number of degrees of freedom assigned to a simplex (without the ones assigned to its faces!...
Definition: lagrangebasis.hh:252
size_type size() const
Same as size(prefix) with empty prefix.
Definition: lagrangebasis.hh:168
void initializeIndices()
Initialize the global indices.
Definition: lagrangebasis.hh:113
Definition: lagrangebasis.hh:36
const FiniteElement * finiteElement_
Definition: lagrangebasis.hh:384
Dune::ReservedVector< size_type, 1 > SizePrefix
Type used for prefixes handed to the size() method.
Definition: lagrangebasis.hh:89
size_type edgeOffset_
Definition: lagrangebasis.hh:280
size_type size(const SizePrefix prefix) const
Return number of possible values for next position in multi index.
Definition: lagrangebasis.hh:198
const unsigned int order_
Definition: lagrangebasis.hh:227
Definition: polynomial.hh:10
const PreBasis * preBasis_
Definition: lagrangebasis.hh:564
Definition: lagrangebasis.hh:33
size_type vertexOffset_
Definition: lagrangebasis.hh:279
void unbind()
Unbind the view.
Definition: lagrangebasis.hh:424
Node makeNode() const
Create tree node.
Definition: lagrangebasis.hh:151
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: lagrangebasis.hh:401
LagrangePreBasis(const GridView &gv, unsigned int order)
Constructor for a given grid view object and run-time order.
Definition: lagrangebasis.hh:97
GV GridView
The grid view that the FE basis is defined on.
Definition: lagrangebasis.hh:67
auto power(ChildPreBasisFactory &&childPreBasisFactory, const IndexMergingStrategy &ims)
Create a pre-basis factory that can build a PowerPreBasis.
Definition: powerbasis.hh:483
It indices(It it) const
Maps from subtree index set [0..size-1] to a globally unique multi index in global basis.
Definition: lagrangebasis.hh:439
std::array< size_type, dim+1 > dofsPerCube_
Definition: lagrangebasis.hh:275
IndexSet makeIndexSet() const
Create tree node index set.
Definition: lagrangebasis.hh:162
size_type size() const
Size of subtree rooted in this node (element-local)
Definition: lagrangebasis.hh:431
std::size_t size_type
Definition: lagrangebasis.hh:398
const FiniteElement & finiteElement() const
Return the LocalFiniteElement for the element we are bound to.
Definition: lagrangebasis.hh:360
const Node * node_
Definition: lagrangebasis.hh:566
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: lagrangebasis.hh:205
size_type dofsPerPyramid() const
Definition: lagrangebasis.hh:246
size_type dofsPerSimplex(std::size_t simplexDim) const
Number of degrees of freedom assigned to a simplex (without the ones assigned to its faces!...
Definition: lagrangebasis.hh:230