DUNE PDELab (unstable)

lagrangedgbasis.hh
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
13#include <dune/functions/functionspacebases/nodes.hh>
14#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
15#include <dune/functions/functionspacebases/lagrangebasis.hh>
16#include <dune/functions/functionspacebases/leafprebasismappermixin.hh>
17
18
19
20
21namespace Dune {
22namespace Functions {
23
24
25
26// *****************************************************************************
27// This is the reusable part of the basis. It contains
28//
29// LagrangeDGPreBasis
30// LagrangeDGNode
31//
32// The pre-basis allows to create the others and is the owner of possible shared
33// state. These components do _not_ depend on the global basis and local view
34// and can be used without a global basis.
35// *****************************************************************************
36
37template<typename GV, int k, typename R=double>
38using LagrangeDGNode = LagrangeNode<GV, k, R>;
39
48template<typename GV, int k, typename R=double>
51{
53
54 static constexpr bool useDynamicOrder = (k<0);
55
56 static MCMGLayout dofLayout(int order)
57 {
58 return [order](Dune::GeometryType type, size_t dimGrid) {
59 if (type.dim() == dimGrid)
60 {
61 if (type.isLine())
62 return order+1;
63 if (type.isTriangle())
64 return (order+1)*(order+2)/2;
65 if (type.isQuadrilateral())
66 return (order+1)*(order+1);
67 if (type.isTetrahedron())
68 return (order+1)*(order+2)*(order+3)/6;
69 if (type.isPrism())
70 return (order+1)*(order+1)*(order+2)/2;
71 if (type.isHexahedron())
72 return (order+1)*(order+1)*(order+1);
73 if (type.isPyramid())
74 return (order+1)*(order+2)*(2*order+3)/6;
75 DUNE_THROW(Dune::NotImplemented, "Using LagrangeDGPreBasis with non-supported GeometryType");
76 }
77 return 0;
78 };
79 }
80
81public:
82
84 using GridView = GV;
85 using size_type = typename Base::size_type;
86 using Node = LagrangeDGNode<GV, k, R>;
87
95 requires(k>=0)
96 : Base(gv, dofLayout(k))
97 , order_(k)
98 {}
99
106 LagrangeDGPreBasis(const GridView& gv, unsigned int order)
107 requires(k<0)
108 : Base(gv, dofLayout(order))
109 , order_(order)
110 {}
111
115 Node makeNode() const
116 {
117 return Node{order_};
118 }
119
120 template<class Node, class It>
121 It indices(const Node& node, It it) const
122 {
123 size_type elementOffset = Base::mapper_.index(node.element());
124 for(auto i : Dune::range(node.size()))
125 {
126 *it = {{ (size_type)(elementOffset+i) }};
127 ++it;
128 }
129 return it;
130 }
131
133 unsigned int order() const
134 {
135 return (useDynamicOrder) ? order_ : k;
136 }
137
138protected:
139
140 unsigned int order_;
141};
142
143
144
145namespace BasisFactory {
146
155template<std::size_t order, typename R=double>
157{
158 return [](const auto& gridView) {
159 return LagrangeDGPreBasis<std::decay_t<decltype(gridView)>, order, R>(gridView);
160 };
161}
162
171template<typename R=double>
172auto lagrangeDG(unsigned int order)
173{
174 return [order](const auto& gridView) {
175 return LagrangeDGPreBasis<std::decay_t<decltype(gridView)>, -1, R>(gridView, order);
176 };
177}
178
179} // end namespace BasisFactory
180
181
182
183// *****************************************************************************
184// This is the actual global basis implementation based on the reusable parts.
185// *****************************************************************************
186
195template<typename GV, int k=-1, typename R=double>
197
198
199
200} // end namespace Functions
201} // end namespace Dune
202
203
204#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_LAGRANGEDGBASIS_HH
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:53
PreBasis implementation for a Lagrangean-DG finite element space.
Definition: lagrangedgbasis.hh:51
Node makeNode() const
Create tree node.
Definition: lagrangedgbasis.hh:115
LagrangeDGPreBasis(const GridView &gv, unsigned int order)
Constructor for a given grid view object.
Definition: lagrangedgbasis.hh:106
unsigned int order() const
Polynomial order used in the local Lagrange finite-elements.
Definition: lagrangedgbasis.hh:133
LagrangeDGPreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition: lagrangedgbasis.hh:94
GV GridView
The grid view that the FE space is defined on.
Definition: lagrangedgbasis.hh:84
A generic MixIn class for PreBasis with flat indices computed from a mapper.
Definition: leafprebasismappermixin.hh:62
std::size_t size_type
Type used for index digits.
Definition: leafprebasismappermixin.hh:71
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:114
constexpr bool isPyramid() const
Return true if entity is a pyramid.
Definition: type.hh:304
constexpr bool isTetrahedron() const
Return true if entity is a tetrahedron.
Definition: type.hh:299
constexpr bool isPrism() const
Return true if entity is a prism.
Definition: type.hh:309
constexpr unsigned int dim() const
Return dimension of the type.
Definition: type.hh:360
constexpr bool isTriangle() const
Return true if entity is a triangle.
Definition: type.hh:289
constexpr bool isLine() const
Return true if entity is a line segment.
Definition: type.hh:284
constexpr bool isQuadrilateral() const
Return true if entity is a quadrilateral.
Definition: type.hh:294
constexpr bool isHexahedron() const
Return true if entity is a hexahedron.
Definition: type.hh:314
Default exception for dummy implementations.
Definition: exceptions.hh:357
A few common exception classes.
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
auto lagrangeDG(unsigned int order)
Create a pre-basis factory that can create a LagrangeDG pre-basis.
Definition: lagrangedgbasis.hh:172
std::function< size_t(GeometryType, int)> MCMGLayout
layout function for MultipleCodimMultipleGeomTypeMapper
Definition: mcmgmapper.hh:64
static constexpr IntegralRange< std::decay_t< T > > range(T &&from, U &&to) noexcept
free standing function for setting up a range based for loop over an integer range for (auto i: range...
Definition: rangeutilities.hh:293
Some useful basic math stuff.
Dune namespace
Definition: alignedallocator.hh:13
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden & Uni Heidelberg  |  generated with Hugo v0.111.3 (Jun 10, 22:32, 2026)