DUNE-FUNCTIONS (2.7)

rannacherturekbasis.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_RANNACHERTUREKBASIS_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_RANNACHERTUREKBASIS_HH
5
6#include <dune/common/exceptions.hh>
7
8#include <dune/localfunctions/rannacherturek.hh>
9
10#include <dune/typetree/leafnode.hh>
11
12#include <dune/functions/functionspacebases/nodes.hh>
13#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
14#include <dune/functions/functionspacebases/flatmultiindex.hh>
15
16
17namespace Dune {
18namespace Functions {
19
20// *****************************************************************************
21// This is the reusable part of the basis. It contains
22//
23// RannacherTurekPreBasis
24// RannacherTurekNodeIndexSet
25// RannacherTurekNode
26//
27// The pre-basis allows to create the others and is the owner of possible shared
28// state. These three components do _not_ depend on the global basis or index
29// set and can be used without a global basis.
30// *****************************************************************************
31
32template<typename GV>
33class RannacherTurekNode;
34
35template<typename GV, class MI>
36class RannacherTurekNodeIndexSet;
37
38template<typename GV, class MI>
39class RannacherTurekPreBasis;
40
54template<typename GV, class MI>
56{
57 static const int dim = GV::dimension;
58
59public:
60
62 using GridView = GV;
63
65 using size_type = std::size_t;
66
68 using Node = RannacherTurekNode<GV>;
69
71 using IndexSet = RannacherTurekNodeIndexSet<GV, MI>;
72
74 using MultiIndex = MI;
75
77 using SizePrefix = Dune::ReservedVector<size_type, 1>;
78
81 gridView_(gv)
82 {}
83
86 {}
87
89 const GridView& gridView() const
90 {
91 return gridView_;
92 }
93
95 void update (const GridView& gv)
96 {
97 gridView_ = gv;
98 }
99
104 {
105 return Node{};
106 }
107
115 {
116 return IndexSet{*this};
117 }
118
121 {
122 return (size_type)(gridView_.size(1));
123 }
124
126 size_type size(const SizePrefix prefix) const
127 {
128 assert(prefix.size() == 0 || prefix.size() == 1);
129 return (prefix.size() == 0) ? size() : 0;
130 }
131
134 {
135 return size();
136 }
137
140 {
141 return 2*GV::dimension;
142 }
143
144protected:
145 GridView gridView_;
146};
147
148
149
150template<typename GV>
151class RannacherTurekNode :
152 public LeafBasisNode
153{
154 static const int dim = GV::dimension;
155 static const int maxSize = 2*dim;
156
157public:
158
159 using size_type = std::size_t;
160 using Element = typename GV::template Codim<0>::Entity;
161 using FiniteElement = RannacherTurekLocalFiniteElement<typename GV::ctype, double, dim>;
162
163 RannacherTurekNode() :
164 finiteElement_(),
165 element_(nullptr)
166 {}
167
169 const Element& element() const
170 {
171 return *element_;
172 }
173
178 const FiniteElement& finiteElement() const
179 {
180 return finiteElement_;
181 }
182
184 void bind(const Element& e)
185 {
186 element_ = &e;
187#ifndef NDEBUG
188 if (e.type() != finiteElement_.type())
189 DUNE_THROW(Dune::Exception,
190 "Rannacher-Turek elements do not exist for elements of type " << e.type());
191#endif
192 this->setSize(finiteElement_.size());
193 }
194
195protected:
196
197 const FiniteElement finiteElement_;
198 const Element* element_;
199};
200
201
202
203template<typename GV, class MI>
204class RannacherTurekNodeIndexSet
205{
206 enum {dim = GV::dimension};
207
208public:
209
210 using size_type = std::size_t;
211
213 using MultiIndex = MI;
214
215 using PreBasis = RannacherTurekPreBasis<GV, MI>;
216
217 using Node = RannacherTurekNode<GV>;
218
219 RannacherTurekNodeIndexSet(const PreBasis& preBasis) :
220 preBasis_(&preBasis)
221 {}
222
228 void bind(const Node& node)
229 {
230 node_ = &node;
231 }
232
235 void unbind()
236 {
237 node_ = nullptr;
238 }
239
242 size_type size() const
243 {
244 return (size_type)(node_->finiteElement().size());
245 }
246
248 template<typename It>
249 It indices(It it) const
250 {
251 for (size_type i = 0, end = size() ; i < end ; ++i, ++it)
252 {
253 Dune::LocalKey localKey = node_->finiteElement().localCoefficients().localKey(i);
254 const auto& gridIndexSet = preBasis_->gridView().indexSet();
255 const auto& element = node_->element();
256
257 *it = {{ (size_type)(gridIndexSet.subIndex(element,localKey.subEntity(),1)) }};
258 }
259 return it;
260 }
261
262protected:
263 const PreBasis* preBasis_;
264
265 const Node* node_;
266};
267
268
269
270namespace BasisFactory {
271
272namespace Imp {
273
274template<class Dummy=void>
275class RannacherTurekPreBasisFactory
276{
277public:
278 static const std::size_t requiredMultiIndexSize = 1;
279
280 template<class MultiIndex, class GridView>
281 auto makePreBasis(const GridView& gridView) const
282 {
283 return RannacherTurekPreBasis<GridView, MultiIndex>(gridView);
284 }
285
286};
287
288} // end namespace BasisFactory::Imp
289
290
291
297template<class Dummy=void>
299{
300 return Imp::RannacherTurekPreBasisFactory<void>();
301}
302
303} // end namespace BasisFactory
304
305
306
307
319template<typename GV>
321
322} // end namespace Functions
323} // end namespace Dune
324
325#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_RANNACHERTUREKBASIS_HH
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:47
Pre-basis for a Rannacher-Turek basis.
Definition: rannacherturekbasis.hh:56
Dune::ReservedVector< size_type, 1 > SizePrefix
Type used for prefixes handed to the size() method.
Definition: rannacherturekbasis.hh:77
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: rannacherturekbasis.hh:139
IndexSet makeIndexSet() const
Create tree node index set.
Definition: rannacherturekbasis.hh:114
std::size_t size_type
Type used for indices and size information.
Definition: rannacherturekbasis.hh:65
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: rannacherturekbasis.hh:133
GV GridView
The grid view that the FE basis is defined on.
Definition: rannacherturekbasis.hh:62
size_type size() const
Same as size(prefix) with empty prefix.
Definition: rannacherturekbasis.hh:120
RannacherTurekNode< GV > Node
Template mapping root tree path to type of created tree node.
Definition: rannacherturekbasis.hh:68
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: rannacherturekbasis.hh:74
size_type size(const SizePrefix prefix) const
Return number of possible values for next position in multi index.
Definition: rannacherturekbasis.hh:126
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: rannacherturekbasis.hh:95
Node makeNode() const
Create tree node.
Definition: rannacherturekbasis.hh:103
RannacherTurekNodeIndexSet< GV, MI > IndexSet
Template mapping root tree path to type of created tree node index set.
Definition: rannacherturekbasis.hh:71
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: rannacherturekbasis.hh:89
void initializeIndices()
Initialize the global indices.
Definition: rannacherturekbasis.hh:85
RannacherTurekPreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition: rannacherturekbasis.hh:80
auto rannacherTurek()
Create a pre-basis factory that can create a Rannacher-Turek pre-basis.
Definition: rannacherturekbasis.hh:298
Definition: polynomial.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)