Dune-Functions 2.12-git
Loading...
Searching...
No Matches
lagrangedgbasis.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
5// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
6
7#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_LAGRANGEDGBASIS_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_LAGRANGEDGBASIS_HH
9
11#include <dune/common/math.hh>
12
20
25
26
27
28
29namespace Dune {
30namespace Functions {
31
32
33
34// *****************************************************************************
35// This is the reusable part of the basis. It contains
36//
37// LagrangeDGPreBasis
38// LagrangeDGNode
39//
40// The pre-basis allows to create the others and is the owner of possible shared
41// state. These components do _not_ depend on the global basis and local view
42// and can be used without a global basis.
43// *****************************************************************************
44
45template<typename GV, int k, typename R=double>
47 public LeafBasisNode
48{
49 static constexpr int dim = GV::dimension;
50
51 // A simple cache handing storing exactly one LFE. This can be
52 // used for grids with only a single element type. In contrast to
53 // StaticLagrangeLocalFiniteElementCache this also supports
54 // Lagrange*LocalFiniteElement with run-time order.
55 template <class LFE>
56 class SingleLocalFiniteElementCache
57 {
58 LFE lfe_;
59 public:
60 using FiniteElementType = LFE;
61
62 template<class... Args>
63 SingleLocalFiniteElementCache(Args&&... args)
64 : lfe_(std::forward<Args>(args)...)
65 {}
66
68 const FiniteElementType& get ([[maybe_unused]] Dune::GeometryType type) const
69 {
70 return lfe_;
71 }
72 };
73
74 template<class LFE>
76
77 template<class D, class RR, std::size_t dim, int compileTimeOrder>
78 class ImplementedLagrangeDGFiniteElements : public Dune::Impl::ImplementedLagrangeFiniteElements<D, RR, dim, compileTimeOrder>
79 {
80 using Base = Dune::Impl::ImplementedLagrangeFiniteElements<D, RR, dim, compileTimeOrder>;
81 public:
82
83 using Base::Base;
84
85 auto getImplementations() const
86 {
87 return std::apply([&](auto... indexLFEPair) {
88 return std::make_tuple(
89 std::make_pair(std::get<0>(indexLFEPair), [lfe = std::get<1>(indexLFEPair)()]() { return DG<std::decay_t<decltype(lfe)>>(lfe); })...
90 );
91 }, Base::getImplementations());
92 }
93 };
94
95 template<class D, class RR, std::size_t dim, int compileTimeOrder = -1>
97
98 // Utility function to construct the FiniteElementCache type.
99 // Since the function is just a helper to generate a type,
100 // it hands out a MetaType<T> instead of a raw T.
101 static constexpr auto makeCacheType()
102 {
103 using D = typename GV::ctype;
105 {
107 if constexpr (type.isSimplex())
108 return Dune::MetaType<SingleLocalFiniteElementCache<DG<Dune::LagrangeSimplexLocalFiniteElement<D,R,dim,k>>>>{};
109 else if constexpr (type.isCube())
110 return Dune::MetaType<SingleLocalFiniteElementCache<DG<Dune::LagrangeCubeLocalFiniteElement<D,R,dim,k>>>>{};
111 else if constexpr (type.isPrism())
112 return Dune::MetaType<SingleLocalFiniteElementCache<DG<Dune::LagrangePrismLocalFiniteElement<D,R,k>>>>{};
113 else if constexpr (type.isPyramid())
114 return Dune::MetaType<SingleLocalFiniteElementCache<DG<Dune::LagrangePyramidLocalFiniteElement<D,R,k>>>>{};
115 }
116 else
118 }
119
120 using FiniteElementCache = typename decltype(makeCacheType())::type;
121
122public:
123
125 using Element = typename GV::template Codim<0>::Entity;
126 using FiniteElement = typename FiniteElementCache::FiniteElementType;
127
132
134 LagrangeDGNode(unsigned int order) :
135 cache_(order),
136 finiteElement_(nullptr),
137 element_(nullptr)
138 {}
139
141 const Element& element() const
142 {
143 return *element_;
144 }
145
151 {
152 return *finiteElement_;
153 }
154
156 void bind(const Element& e)
157 {
158 element_ = &e;
159 finiteElement_ = &(cache_.get(element_->type()));
160 this->setSize(finiteElement_->size());
161 }
162
163protected:
164
165 FiniteElementCache cache_;
168};
169
170
171
180template<typename GV, int k, typename R=double>
183{
185
186 static constexpr bool useDynamicOrder = (k<0);
187
188 static MCMGLayout dofLayout(int order)
189 {
190 return [order](Dune::GeometryType type, size_t dimGrid) {
191 if (type.dim() == dimGrid)
192 {
193 if (type.isLine())
194 return order+1;
195 if (type.isTriangle())
196 return (order+1)*(order+2)/2;
197 if (type.isQuadrilateral())
198 return (order+1)*(order+1);
199 if (type.isTetrahedron())
200 return (order+1)*(order+2)*(order+3)/6;
201 if (type.isPrism())
202 return (order+1)*(order+1)*(order+2)/2;
203 if (type.isHexahedron())
204 return (order+1)*(order+1)*(order+1);
205 if (type.isPyramid())
206 return (order+1)*(order+2)*(2*order+3)/6;
207 DUNE_THROW(Dune::NotImplemented, "Using LagrangeDGPreBasis with non-supported GeometryType");
208 }
209 return 0;
210 };
211 }
212
213public:
214
216 using GridView = GV;
217 using size_type = typename Base::size_type;
219
227 requires(k>=0)
228 : Base(gv, dofLayout(k))
229 , order_(k)
230 {}
231
238 LagrangeDGPreBasis(const GridView& gv, unsigned int order)
239 requires(k<0)
240 : Base(gv, dofLayout(order))
241 , order_(order)
242 {}
243
248 {
249 return Node{order_};
250 }
251
252 template<class Node, class It>
253 It indices(const Node& node, It it) const
254 {
255 size_type elementOffset = Base::mapper_.index(node.element());
256 for(auto i : Dune::range(node.size()))
257 {
258 *it = {{ (size_type)(elementOffset+i) }};
259 ++it;
260 }
261 return it;
262 }
263
265 unsigned int order() const
266 {
267 return (useDynamicOrder) ? order_ : k;
268 }
269
270protected:
271
272 unsigned int order_;
273};
274
275
276
277namespace BasisFactory {
278
287template<std::size_t order, typename R=double>
289{
290 return [](const auto& gridView) {
291 return LagrangeDGPreBasis<std::decay_t<decltype(gridView)>, order, R>(gridView);
292 };
293}
294
303template<typename R=double>
304auto lagrangeDG(unsigned int order)
305{
306 return [order](const auto& gridView) {
307 return LagrangeDGPreBasis<std::decay_t<decltype(gridView)>, -1, R>(gridView, order);
308 };
309}
310
311} // end namespace BasisFactory
312
313
314
315// *****************************************************************************
316// This is the actual global basis implementation based on the reusable parts.
317// *****************************************************************************
318
327template<typename GV, int k=-1, typename R=double>
329
330
331
332} // end namespace Functions
333} // end namespace Dune
334
335
336#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_LAGRANGEDGBASIS_HH
static constexpr IntegralRange< T > range(T from, T to) noexcept
size_type dim() const
#define DUNE_THROW(E,...)
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
constexpr bool isPyramid() const
constexpr bool isTetrahedron() const
constexpr bool isPrism() const
constexpr unsigned int dim() const
constexpr bool isTriangle() const
constexpr bool isLine() const
constexpr bool isQuadrilateral() const
constexpr bool isHexahedron() const
Index index(const EntityType &e) const
T apply(T... args)
size_type size() const
Obtain the number of basis function in the local node.
Definition nodes.hh:158
void setSize(const size_type size)
Definition nodes.hh:193
Global basis for given pre-basis.
Definition defaultglobalbasis.hh:53
Definition lagrangedgbasis.hh:48
const Element & element() const
Return current element, throw if unbound.
Definition lagrangedgbasis.hh:141
void bind(const Element &e)
Bind to element.
Definition lagrangedgbasis.hh:156
const Element * element_
Definition lagrangedgbasis.hh:167
FiniteElementCache cache_
Definition lagrangedgbasis.hh:165
const FiniteElement * finiteElement_
Definition lagrangedgbasis.hh:166
typename FiniteElementCache::FiniteElementType FiniteElement
Definition lagrangedgbasis.hh:126
const FiniteElement & finiteElement() const
Return the LocalFiniteElement for the element we are bound to.
Definition lagrangedgbasis.hh:150
LagrangeDGNode(unsigned int order)
Constructor with a run-time order.
Definition lagrangedgbasis.hh:134
typename GV::template Codim< 0 >::Entity Element
Definition lagrangedgbasis.hh:125
LagrangeDGNode()
Constructor without order (uses the compile-time value)
Definition lagrangedgbasis.hh:129
PreBasis implementation for a Lagrangean-DG finite element space.
Definition lagrangedgbasis.hh:183
Node makeNode() const
Create tree node.
Definition lagrangedgbasis.hh:247
LagrangeDGPreBasis(const GridView &gv, unsigned int order)
Constructor for a given grid view object.
Definition lagrangedgbasis.hh:238
typename Base::size_type size_type
Definition lagrangedgbasis.hh:217
unsigned int order() const
Polynomial order used in the local Lagrange finite-elements.
Definition lagrangedgbasis.hh:265
LagrangeDGPreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition lagrangedgbasis.hh:226
It indices(const Node &node, It it) const
Definition lagrangedgbasis.hh:253
unsigned int order_
Definition lagrangedgbasis.hh:272
GV GridView
The grid view that the FE space is defined on.
Definition lagrangedgbasis.hh:216
Definition nodes.hh:214
A generic MixIn class for PreBasis with flat indices computed from a mapper.
Definition leafprebasismappermixin.hh:62
Dune::MultipleCodimMultipleGeomTypeMapper< GridView > mapper_
Definition leafprebasismappermixin.hh:133
std::size_t size_type
Type used for index digits.
Definition leafprebasismappermixin.hh:71
auto lagrangeDG()
Create a pre-basis factory that can create a LagrangeDG pre-basis.
Definition lagrangedgbasis.hh:288
T make_pair(T... args)
T make_tuple(T... args)