Dune Core Modules (2.8.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/flatmultiindex.hh>
11#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
13
14namespace Dune {
15 namespace Functions {
16
17 // *****************************************************************************
18 // Implementation for Hierarchical Lagrange Basis
19 //
20 // -- only order k=2 is implemented up to now --
21 // -- currently only supports simplex grids --
22 //
23 // This is the reusable part of the HierarchicalLagrangeBasis. It contains
24 //
25 // HierarchicalLagrangePreBasis
26 // HierarchicalLagrangeNode
27 //
28 // The pre-basis allows to create the others and is the owner of possible shared
29 // state. These components do _not_ depend on the global basis and can be
30 // used without a global basis.
31 // *****************************************************************************
32
33 template<typename GV, int k, typename R=double>
34 class HierarchicalLagrangeNode;
35
36 template<typename GV, int k, class MI, typename R=double>
37 class HierarchicalLagrangePreBasis;
38
49 template<typename GV, int k, class MI, typename R>
51 {
52 static const int dim = GV::dimension;
53
54 public:
55
57 using GridView = GV;
58
60 using size_type = std::size_t;
61
63 using Node = HierarchicalLagrangeNode<GV, k, R>;
64
66 using IndexSet = Impl::DefaultNodeIndexSet<HierarchicalLagrangePreBasis>;
67
69 using MultiIndex = MI;
70
73
78 HierarchicalLagrangePreBasis(const GridView& gv) : gridView_(gv) , mcmgMapper_(gv,p2Layout())
79 {}
80
83 {}
84
86 const GridView& gridView() const
87 {
88 return gridView_;
89 }
90
92 void update (const GridView& gv)
93 {
94 gridView_ = gv;
95 mcmgMapper_.update(gv);
96 }
97
102 {
103 return Node{};
104 }
105
113 {
114 return IndexSet{*this};
115 }
116
119 {
120 return mcmgMapper_.size();
121 }
122
124 size_type size(const SizePrefix prefix) const
125 {
126 assert(prefix.size() == 0 || prefix.size() == 1);
127 return (prefix.size() == 0) ? size() : 0;
128 }
129
132 {
133 return size();
134 }
135
141 {
142 // That cast to unsigned int is necessary because GV::dimension is an enum
143 return Dune::binomial(std::size_t(order() + (unsigned int)GV::dimension),std::size_t(order()));
144 }
145
146 template<typename It>
147 It indices(const Node& node, It it) const
148 {
149 for (size_type i = 0, end = node.finiteElement().size() ; i < end ; ++it, ++i)
150 {
151 Dune::LocalKey localKey = node.finiteElement().localCoefficients().localKey(i);
152 const auto& element = node.element();
153
154 *it = {{ (size_type)(mcmgMapper_.subIndex(element,localKey.subEntity(),localKey.codim())) }};
155 }
156 return it;
157 }
158
159 protected:
160 GridView gridView_;
161
162 unsigned int order() const
163 {
164 return 2;
165 }
166
167 MultipleCodimMultipleGeomTypeMapper<GridView> mcmgMapper_;
168
169 private:
174 static auto p2Layout()
175 {
176 return [](Dune::GeometryType type, int gridDim)
177 {
178 if (type.isVertex())
179 return 1;
180 if (type.isLine())
181 return 1;
182 if (type.isTriangle())
183 return 0;
184 assert(type.isTetrahedron());
185 return 0;
186 };
187 }
188 };
189
190
191
192 template<typename GV, int k, typename R>
193 class HierarchicalLagrangeNode :
194 public LeafBasisNode
195 {
196 static const int dim = GV::dimension;
197
198 public:
199
200 using size_type = std::size_t;
201 using Element = typename GV::template Codim<0>::Entity;
202 using FiniteElement = HierarchicalP2LocalFiniteElement<typename GV::ctype,R,dim>;
203
204 HierarchicalLagrangeNode() :
205 finiteElement_(),
206 element_(nullptr)
207 {}
208
210 const Element& element() const
211 {
212 return *element_;
213 }
214
219 const FiniteElement& finiteElement() const
220 {
221 return finiteElement_;
222 }
223
225 void bind(const Element& e)
226 {
227 element_ = &e;
228
229 if (e.type() != finiteElement_.type())
231 "HierarchicalLagrange-elements do not exist for elements of type " << e.type());
232
233 this->setSize(finiteElement_.size());
234 }
235
236 protected:
237
238 unsigned int order() const
239 {
240 return 2;
241 }
242
243 const FiniteElement finiteElement_;
244 const Element* element_;
245 };
246
247
248
249 namespace BasisFactory {
250
251 namespace Impl {
252
253 template<int k, typename R=double>
254 class HierarchicalLagrangePreBasisFactory
255 {
256
257 public:
258 static const std::size_t requiredMultiIndexSize = 1;
259
260 template<class MultiIndex, class GridView>
261 auto makePreBasis(const GridView& gridView) const
262 {
263 return HierarchicalLagrangePreBasis<GridView, k, MultiIndex, R>(gridView);
264 }
265
266 };
267 } // end namespace BasisFactory::Impl
268
269
278 template<std::size_t k, typename R=double>
280 {
281 return Impl::HierarchicalLagrangePreBasisFactory<k,R>();
282 }
283
284 } // end namespace BasisFactory
285
296 template<typename GV, int k, typename R=double>
298
299 } // end namespace Functions
300} // end namespace Dune
301
302#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_HIERARCHICALLAGRANGEBASIS_HH
Base class for Dune-Exceptions.
Definition: exceptions.hh:94
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:47
A pre-basis for a hierarchical basis.
Definition: hierarchicallagrangebasis.hh:51
size_type size() const
Same as size(prefix) with empty prefix.
Definition: hierarchicallagrangebasis.hh:118
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: hierarchicallagrangebasis.hh:69
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: hierarchicallagrangebasis.hh:86
Impl::DefaultNodeIndexSet< HierarchicalLagrangePreBasis > IndexSet
Type of created tree node index set.
Definition: hierarchicallagrangebasis.hh:66
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: hierarchicallagrangebasis.hh:140
size_type size(const SizePrefix prefix) const
Return number of possible values for next position in multi index.
Definition: hierarchicallagrangebasis.hh:124
Node makeNode() const
Create tree node.
Definition: hierarchicallagrangebasis.hh:101
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: hierarchicallagrangebasis.hh:131
HierarchicalLagrangePreBasis(const GridView &gv)
Constructor for a given grid view object with layout for second order.
Definition: hierarchicallagrangebasis.hh:78
GV GridView
The grid view that the FE basis is defined on.
Definition: hierarchicallagrangebasis.hh:57
IndexSet makeIndexSet() const
Create tree node index set.
Definition: hierarchicallagrangebasis.hh:112
void initializeIndices()
Initialize the global indices.
Definition: hierarchicallagrangebasis.hh:82
std::size_t size_type
Type used for indices and size information.
Definition: hierarchicallagrangebasis.hh:60
void update(const GridView &gv)
Update the stored grid view & MultipleCodimMultipleGeomTypeMapper, to be called if the grid has chang...
Definition: hierarchicallagrangebasis.hh:92
HierarchicalLagrangeNode< GV, k, R > Node
Template mapping root tree path to type of created tree node.
Definition: hierarchicallagrangebasis.hh:63
Unique label for each type of entities that can occur in DUNE grids.
Definition: type.hh:123
constexpr bool isTetrahedron() const
Return true if entity is a tetrahedron.
Definition: type.hh:308
constexpr bool isVertex() const
Return true if entity is a vertex.
Definition: type.hh:288
constexpr bool isTriangle() const
Return true if entity is a triangle.
Definition: type.hh:298
constexpr bool isLine() const
Return true if entity is a line segment.
Definition: type.hh:293
Describe position of one degree of freedom.
Definition: localkey.hh:21
unsigned int codim() const
Return codim of associated entity.
Definition: localkey.hh:60
unsigned int subEntity() const
Return number of associated subentity.
Definition: localkey.hh:54
size_type size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mcmgmapper.hh:202
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:183
void update(const GV &gridView)
Recalculates indices after grid adaptation.
Definition: mcmgmapper.hh:306
A Vector class with statically reserved memory.
Definition: reservedvector.hh:43
size_type size() const
Returns number of elements in the vector.
Definition: reservedvector.hh:184
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
auto hierarchicalLagrange()
Create a pre-basis factory that can create a HierarchicalLagrange pre-basis.
Definition: hierarchicallagrangebasis.hh:279
Mapper for multiple codim and multiple geometry types.
Dune namespace.
Definition: alignedallocator.hh:11
static constexpr T binomial(const T &n, const T &k) noexcept
calculate the binomial coefficient n over k as a constexpr
Definition: math.hh:128
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)