Dune Core Modules (2.9.0)

hierarchicallagrangebasis.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_HIERARCHICALLAGRANGEBASIS_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_HIERARCHICALLAGRANGEBASIS_HH
5
7#include <dune/localfunctions/hierarchical/hierarchicalp2.hh>
8
9#include <dune/functions/functionspacebases/nodes.hh>
10#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
12
13namespace Dune {
14 namespace Functions {
15
16 // *****************************************************************************
17 // Implementation for Hierarchical Lagrange Basis
18 //
19 // -- only order k=2 is implemented up to now --
20 // -- currently only supports simplex grids --
21 //
22 // This is the reusable part of the HierarchicalLagrangeBasis. It contains
23 //
24 // HierarchicalLagrangePreBasis
25 // HierarchicalLagrangeNode
26 //
27 // The pre-basis allows to create the others and is the owner of possible shared
28 // state. These components do _not_ depend on the global basis and can be
29 // used without a global basis.
30 // *****************************************************************************
31
32 template<typename GV, int k, typename R=double>
33 class HierarchicalLagrangeNode;
34
35 template<typename GV, int k, typename R=double>
36 class HierarchicalLagrangePreBasis;
37
47 template<typename GV, int k, typename R>
49 {
50 static const int dim = GV::dimension;
51
52 public:
53
55 using GridView = GV;
56
58 using size_type = std::size_t;
59
61 using Node = HierarchicalLagrangeNode<GV, k, R>;
62
63 static constexpr size_type maxMultiIndexSize = 1;
64 static constexpr size_type minMultiIndexSize = 1;
65 static constexpr size_type multiIndexBufferSize = 1;
66
71 HierarchicalLagrangePreBasis(const GridView& gv) : gridView_(gv) , mcmgMapper_(gv,p2Layout())
72 {}
73
76 {}
77
79 const GridView& gridView() const
80 {
81 return gridView_;
82 }
83
85 void update (const GridView& gv)
86 {
87 gridView_ = gv;
88 mcmgMapper_.update(gv);
89 }
90
94 Node makeNode() const
95 {
96 return Node{};
97 }
98
101 {
102 return mcmgMapper_.size();
103 }
104
106 template<class SizePrefix>
107 size_type size(const SizePrefix prefix) const
108 {
109 assert(prefix.size() == 0 || prefix.size() == 1);
110 return (prefix.size() == 0) ? size() : 0;
111 }
112
115 {
116 return size();
117 }
118
124 {
125 // That cast to unsigned int is necessary because GV::dimension is an enum
126 return Dune::binomial(std::size_t(order() + (unsigned int)GV::dimension),std::size_t(order()));
127 }
128
129 template<typename It>
130 It indices(const Node& node, It it) const
131 {
132 for (size_type i = 0, end = node.finiteElement().size() ; i < end ; ++it, ++i)
133 {
134 Dune::LocalKey localKey = node.finiteElement().localCoefficients().localKey(i);
135 const auto& element = node.element();
136
137 *it = {{ (size_type)(mcmgMapper_.subIndex(element,localKey.subEntity(),localKey.codim())) }};
138 }
139 return it;
140 }
141
142 protected:
143 GridView gridView_;
144
145 unsigned int order() const
146 {
147 return 2;
148 }
149
150 MultipleCodimMultipleGeomTypeMapper<GridView> mcmgMapper_;
151
152 private:
157 static auto p2Layout()
158 {
159 return [](Dune::GeometryType type, int gridDim)
160 {
161 if (type.isVertex())
162 return 1;
163 if (type.isLine())
164 return 1;
165 if (type.isTriangle())
166 return 0;
167 assert(type.isTetrahedron());
168 return 0;
169 };
170 }
171 };
172
173
174
175 template<typename GV, int k, typename R>
176 class HierarchicalLagrangeNode :
177 public LeafBasisNode
178 {
179 static const int dim = GV::dimension;
180
181 public:
182
183 using size_type = std::size_t;
184 using Element = typename GV::template Codim<0>::Entity;
185 using FiniteElement = HierarchicalP2LocalFiniteElement<typename GV::ctype,R,dim>;
186
187 HierarchicalLagrangeNode() :
188 finiteElement_(),
189 element_(nullptr)
190 {}
191
193 const Element& element() const
194 {
195 return *element_;
196 }
197
202 const FiniteElement& finiteElement() const
203 {
204 return finiteElement_;
205 }
206
208 void bind(const Element& e)
209 {
210 element_ = &e;
211
212 if (e.type() != finiteElement_.type())
214 "HierarchicalLagrange-elements do not exist for elements of type " << e.type());
215
216 this->setSize(finiteElement_.size());
217 }
218
219 protected:
220
221 unsigned int order() const
222 {
223 return 2;
224 }
225
226 const FiniteElement finiteElement_;
227 const Element* element_;
228 };
229
230
231
232 namespace BasisFactory {
233
242 template<std::size_t k, typename R=double>
244 {
245 return [](const auto& gridView) {
246 return HierarchicalLagrangePreBasis<std::decay_t<decltype(gridView)>, k, R>(gridView);
247 };
248 }
249
250 } // end namespace BasisFactory
251
262 template<typename GV, int k, typename R=double>
264
265 } // end namespace Functions
266} // end namespace Dune
267
268#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_HIERARCHICALLAGRANGEBASIS_HH
Base class for Dune-Exceptions.
Definition: exceptions.hh:96
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:46
A pre-basis for a hierarchical basis.
Definition: hierarchicallagrangebasis.hh:49
std::size_t size_type
Type used for indices and size information.
Definition: hierarchicallagrangebasis.hh:58
Node makeNode() const
Create tree node.
Definition: hierarchicallagrangebasis.hh:94
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: hierarchicallagrangebasis.hh:123
void update(const GridView &gv)
Update the stored grid view & MultipleCodimMultipleGeomTypeMapper, to be called if the grid has chang...
Definition: hierarchicallagrangebasis.hh:85
HierarchicalLagrangeNode< GV, k, R > Node
Template mapping root tree path to type of created tree node.
Definition: hierarchicallagrangebasis.hh:61
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: hierarchicallagrangebasis.hh:114
GV GridView
The grid view that the FE basis is defined on.
Definition: hierarchicallagrangebasis.hh:55
HierarchicalLagrangePreBasis(const GridView &gv)
Constructor for a given grid view object with layout for second order.
Definition: hierarchicallagrangebasis.hh:71
size_type size(const SizePrefix prefix) const
Return number of possible values for next position in multi index.
Definition: hierarchicallagrangebasis.hh:107
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: hierarchicallagrangebasis.hh:79
size_type size() const
Same as size(prefix) with empty prefix.
Definition: hierarchicallagrangebasis.hh:100
void initializeIndices()
Initialize the global indices.
Definition: hierarchicallagrangebasis.hh:75
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:125
constexpr bool isTetrahedron() const
Return true if entity is a tetrahedron.
Definition: type.hh:310
constexpr bool isVertex() const
Return true if entity is a vertex.
Definition: type.hh:290
constexpr bool isTriangle() const
Return true if entity is a triangle.
Definition: type.hh:300
constexpr bool isLine() const
Return true if entity is a line segment.
Definition: type.hh:295
Describe position of one degree of freedom.
Definition: localkey.hh:23
unsigned int codim() const
Return codim of associated entity.
Definition: localkey.hh:62
unsigned int subEntity() const
Return number of associated subentity.
Definition: localkey.hh:56
size_type size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mcmgmapper.hh:204
Index subIndex(const typename GV::template Codim< 0 >::Entity &e, int i, unsigned int codim) const
Map subentity of codim 0 entity to starting index in array for dof block.
Definition: mcmgmapper.hh:185
void update(const GV &gridView)
Recalculates indices after grid adaptation.
Definition: mcmgmapper.hh:308
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
auto hierarchicalLagrange()
Create a pre-basis factory that can create a HierarchicalLagrange pre-basis.
Definition: hierarchicallagrangebasis.hh:243
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
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)