DUNE PDELab (git)

refinedlagrangebasis.hh
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_REFINEDLAGRANGEBASIS_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_REFINEDLAGRANGEBASIS_HH
5
6#include <type_traits>
7
9#include <dune/common/math.hh>
10
12
13#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
14#include <dune/functions/functionspacebases/leafprebasismappermixin.hh>
15#include <dune/functions/functionspacebases/nodes.hh>
16
17#include <dune/geometry/type.hh>
18
20
21
22namespace Dune {
23namespace Functions {
24
25template<typename GV, int k, typename R>
26class RefinedLagrangeNode;
27
39template <typename GV, int k, typename R = double>
41 public LeafPreBasisMapperMixin< GV >
42{
44
45 static const int dim = GV::dimension;
46
47 // refined basis only implemented for P0 and P1
48 static_assert(k == 0 || k == 1);
49
50 // the layout is defined in terms of a MCMGLayout specialized for k == 0 or 1
51 static MCMGLayout dofLayout()
52 {
53 if constexpr(k == 0)
54 // a refined P0 basis assigns each element 2^dim DOFs
55 return [](GeometryType gt, int) -> size_t {
56 return (gt.dim() == dim) ? (1 << dim) : 0;
57 };
58 else if constexpr(k == 1)
59 // a refined P1 basis has the same layout as a P2 basis
60 return [](GeometryType gt, int) -> size_t {
61 return Dune::binomial(int(k),int(gt.dim()));
62 };
63 else
65 "Refined basis not implemented for higher-order Lagrange (k>=2) elements.");
66 }
67
68public:
69
71 using GridView = GV;
72
74 using Node = RefinedLagrangeNode<GV, k, R>;
75
83 : Base(gv, dofLayout())
84 {
85 for (auto gt : gv.indexSet().types(0)) {
86 if (!gt.isSimplex())
88 "Refined Lagrange basis only implemented for simplex grids.");
89 }
90 }
91
93 Node makeNode () const
94 {
95 return Node{};
96 }
97
105 static constexpr unsigned int order()
106 {
107 return k;
108 }
109};
110
111
112
113template <typename GV, int k, typename R>
114class RefinedLagrangeNode
115 : public LeafBasisNode
116{
117 static constexpr int dim = GV::dimension;
118
119 // refined basis only implemented for P0 and P1
120 static_assert(k == 0 || k == 1);
121
122public:
124 using Element = typename GV::template Codim<0>::Entity;
125
127 using FiniteElement = std::conditional_t<(k==0),
130
140 RefinedLagrangeNode ()
141 : finiteElement_{}
142 , element_(nullptr)
143 {}
144
149 const Element& element () const
150 {
151 return *element_;
152 }
153
160 const FiniteElement& finiteElement () const
161 {
162 return finiteElement_;
163 }
164
166 void bind (const Element& e)
167 {
168 element_ = &e;
169 this->setSize(finiteElement_.size());
170 }
171
176 static constexpr unsigned int order()
177 {
178 return k;
179 }
180
181protected:
182 const FiniteElement finiteElement_;
183 const Element* element_;
184};
185
186
187
188namespace BasisFactory {
189
197template <int k, typename R=double>
199{
200 return [](const auto& gridView) {
201 return RefinedLagrangePreBasis<std::decay_t<decltype(gridView)>, k, R>(gridView);
202 };
203}
204
205} // end namespace BasisFactory
206
207
221template <typename GV, int k, typename R=double>
223
224} // end namespace Functions
225} // end namespace Dune
226
227
228#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_REFINEDLAGRANGEBASIS_HH
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:46
A generic MixIn class for PreBasis with flat indices computed from a mapper.
Definition: leafprebasismappermixin.hh:58
GV GridView
Type of the associated GridView.
Definition: leafprebasismappermixin.hh:64
A pre-basis for a refined Lagrange bases.
Definition: refinedlagrangebasis.hh:42
static constexpr unsigned int order()
Polynomial order used in the local Lagrange finite-elements.
Definition: refinedlagrangebasis.hh:105
Node makeNode() const
Create tree node.
Definition: refinedlagrangebasis.hh:93
RefinedLagrangeNode< GV, k, R > Node
Type of the refined Lagrange tree node.
Definition: refinedlagrangebasis.hh:74
RefinedLagrangePreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition: refinedlagrangebasis.hh:82
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
Default exception for dummy implementations.
Definition: exceptions.hh:263
Local finite element that is piecewise P0 on a once uniformly refined reference geometry.
Definition: refinedp0.hh:29
Piecewise linear continuous Lagrange functions on a uniformly refined simplex element.
Definition: refinedp1.hh:29
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
bool gt(const T &first, const T &second, typename EpsilonType< T >::Type epsilon)
test if first greater than second
Definition: float_cmp.cc:158
auto refinedLagrange()
Create a pre-basis factory that can create a RefinedLagrange pre-basis.
Definition: refinedlagrangebasis.hh:198
std::function< size_t(GeometryType, int)> MCMGLayout
layout function for MultipleCodimMultipleGeomTypeMapper
Definition: mcmgmapper.hh:64
Some useful basic math stuff.
Mapper for multiple codim and multiple geometry types.
Dune namespace.
Definition: alignedallocator.hh:13
static constexpr T binomial(const T &n, const T &k) noexcept
calculate the binomial coefficient n over k as a constexpr
Definition: math.hh:131
Convenience header that includes all available LocalFiniteElements based on uniform element refinemen...
Static tag representing a codimension.
Definition: dimension.hh:24
A unique label for each type of element that can occur in a grid.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)