Dune Core Modules (2.8.0)

taylorhoodbasis.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_TAYLORHOODBASIS_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TAYLORHOODBASIS_HH
5
8#include <dune/common/indices.hh>
9
10#include <dune/typetree/powernode.hh>
11#include <dune/typetree/compositenode.hh>
12
13#include <dune/functions/functionspacebases/nodes.hh>
14
15#include <dune/functions/functionspacebases/lagrangebasis.hh>
16#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
17
18namespace Dune {
19namespace Functions {
20
21
22// *****************************************************************************
23// This is the reusable part of the basis. It contains
24//
25// TaylorHoodPreBasis
26// TaylorHoodBasisTree
27// TaylorHoodVelocityTree
28//
29// The pre-basis allows to create the others and is the owner of possible shared
30// state. These components do _not_ depend on the global basis and local view
31// and can be used without a global basis.
32// *****************************************************************************
33
34template<typename GV>
35class TaylorHoodVelocityTree;
36
37template<typename GV>
38class TaylorHoodBasisTree;
39
60template<typename GV, class MI, bool HI=false>
62{
63 static const bool useHybridIndices = HI;
64
65 static const int dim = GV::dimension;
66
67public:
68
70 using GridView = GV;
71
73 using size_type = std::size_t;
74
76 using Node = TaylorHoodBasisTree<GV>;
77
79 using IndexSet = Impl::DefaultNodeIndexSet<TaylorHoodPreBasis>;
80
82 using MultiIndex = MI;
83
86
87private:
88
89 using PQMultiIndex = std::array<size_type, 1>;
92
93public:
94
97 gridView_(gv),
98 pq1PreBasis_(gv),
99 pq2PreBasis_(gv)
100 {}
101
104 {
105 pq1PreBasis_.initializeIndices();
106 pq2PreBasis_.initializeIndices();
107 }
108
110 const GridView& gridView() const
111 {
112 return gridView_;
113 }
114
116 void update (const GridView& gv)
117 {
118 pq1PreBasis_.update(gv);
119 pq2PreBasis_.update(gv);
120 }
121
126 {
127 return Node{};
128 }
129
137 [[deprecated("Warning: The IndexSet typedef and the makeIndexSet method are deprecated. "\
138 "As a replacement use the indices() method of the PreBasis directly.")]]
140 {
141 return IndexSet{*this};
142 }
143
146 {
147 return 2;
148 }
149
151 size_type size(const SizePrefix prefix) const
152 {
153 return sizeImp<useHybridIndices>(prefix);
154 }
155
156private:
157
158 template<bool hi,
159 typename std::enable_if<not hi,int>::type = 0>
160 size_type sizeImp(const SizePrefix prefix) const
161 {
162 if (prefix.size() == 0)
163 return 2;
164 if (prefix.size() == 1)
165 {
166 if (prefix[0] == 0)
167 return dim * pq2PreBasis_.size();
168 if (prefix[0] == 1)
169 return pq1PreBasis_.size();
170 }
171 assert(prefix.size() == 2);
172 return 0;
173 }
174
175 template<bool hi,
176 typename std::enable_if<hi,int>::type = 0>
177 size_type sizeImp(const SizePrefix prefix) const
178 {
179 if (prefix.size() == 0)
180 return 2;
181 if (prefix.size() == 1)
182 {
183 if (prefix[0] == 0)
184 return pq2PreBasis_.size();
185 if (prefix[0] == 1)
186 return pq1PreBasis_.size();
187 }
188 if (prefix.size() == 2)
189 {
190 if (prefix[0] == 0)
191 return dim;
192 if (prefix[0] == 1)
193 return 0;
194 }
195 assert(prefix.size() == 3);
196 return 0;
197 }
198
199public:
200
203 {
204 return dim * pq2PreBasis_.size() + pq1PreBasis_.size();
205 }
206
209 {
210 return dim * pq2PreBasis_.maxNodeSize() + pq1PreBasis_.maxNodeSize();
211 }
212
213 template<typename It>
214 It indices(const Node& node, It it) const
215 {
216 return indicesImp<useHybridIndices>(node, it);
217 }
218
219protected:
220
221 static const void multiIndexPushFront(MultiIndex& M, size_type M0)
222 {
223 M.resize(M.size()+1);
224 for(std::size_t i=M.size()-1; i>0; --i)
225 M[i] = M[i-1];
226 M[0] = M0;
227 }
228
229 template<bool hi, class It,
230 typename std::enable_if<not hi,int>::type = 0>
231 It indicesImp(const Node& node, It multiIndices) const
232 {
233 using namespace Dune::Indices;
234 for(std::size_t child=0; child<dim; ++child)
235 {
236 size_type subTreeSize = node.child(_0, 0).size();
237 pq2PreBasis_.indices(node.child(_0, 0), multiIndices);
238 for (std::size_t i = 0; i<subTreeSize; ++i)
239 {
240 multiIndexPushFront(multiIndices[i], 0);
241 multiIndices[i][1] = multiIndices[i][1]*dim + child;
242 }
243 multiIndices += subTreeSize;
244 }
245 size_type subTreeSize = node.child(_1).size();
246 pq1PreBasis_.indices(node.child(_1), multiIndices);
247 for (std::size_t i = 0; i<subTreeSize; ++i)
248 multiIndexPushFront(multiIndices[i], 1);
249 multiIndices += subTreeSize;
250 return multiIndices;
251 }
252
253 template<bool hi, class It,
254 typename std::enable_if<hi,int>::type = 0>
255 It indicesImp(const Node& node, It multiIndices) const
256 {
257 using namespace Dune::Indices;
258 for(std::size_t child=0; child<dim; ++child)
259 {
260 size_type subTreeSize = node.child(_0, 0).size();
261 pq2PreBasis_.indices(node.child(_0, 0), multiIndices);
262 for (std::size_t i = 0; i<subTreeSize; ++i)
263 {
264 multiIndexPushFront(multiIndices[i], 0);
265 multiIndices[i].push_back(i);
266 }
267 multiIndices += subTreeSize;
268 }
269 size_type subTreeSize = node.child(_1).size();
270 pq1PreBasis_.indices(node.child(_1), multiIndices);
271 for (std::size_t i = 0; i<subTreeSize; ++i)
272 multiIndexPushFront(multiIndices[i], 1);
273 multiIndices += subTreeSize;
274 return multiIndices;
275 }
276
277 GridView gridView_;
278
279 PQ1PreBasis pq1PreBasis_;
280 PQ2PreBasis pq2PreBasis_;
281};
282
283
284
285template<typename GV>
286class TaylorHoodVelocityTree :
287 public PowerBasisNode<LagrangeNode<GV,2>, GV::dimension>
288{
289 using PQ2Node = LagrangeNode<GV,2>;
290 using Base = PowerBasisNode<PQ2Node, GV::dimension>;
291
292public:
293 TaylorHoodVelocityTree()
294 {
295 for(int i=0; i<GV::dimension; ++i)
296 this->setChild(i, std::make_shared<PQ2Node>());
297 }
298};
299
300template<typename GV>
301class TaylorHoodBasisTree :
302 public CompositeBasisNode<
303 TaylorHoodVelocityTree<GV>,
304 LagrangeNode<GV,1>
305 >
306{
307 using VelocityNode=TaylorHoodVelocityTree<GV>;
308 using PressureNode=LagrangeNode<GV,1>;
309
310 using Base=CompositeBasisNode<VelocityNode, PressureNode>;
311
312public:
313 TaylorHoodBasisTree()
314 {
315 this->template setChild<0>(std::make_shared<VelocityNode>());
316 this->template setChild<1>(std::make_shared<PressureNode>());
317 }
318};
319
320
321
322namespace BasisFactory {
323
324namespace Imp {
325
326class TaylorHoodPreBasisFactory
327{
328public:
329 static const std::size_t requiredMultiIndexSize=2;
330
331 template<class MultiIndex, class GridView>
332 auto makePreBasis(const GridView& gridView) const
333 {
334 return TaylorHoodPreBasis<GridView, MultiIndex>(gridView);
335 }
336
337};
338
339} // end namespace BasisFactory::Imp
340
348{
349 return Imp::TaylorHoodPreBasisFactory();
350}
351
352} // end namespace BasisFactory
353
354// *****************************************************************************
355// This is the actual global basis implementation based on the reusable parts.
356// *****************************************************************************
357
379template<typename GV>
381
382
383
384} // end namespace Functions
385} // end namespace Dune
386
387
388#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TAYLORHOODBASIS_HH
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:47
size_type size() const
Same as size(prefix) with empty prefix.
Definition: lagrangebasis.hh:161
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: lagrangebasis.hh:133
void initializeIndices()
Initialize the global indices.
Definition: lagrangebasis.hh:103
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: lagrangebasis.hh:204
Pre-basis for lowest order Taylor-Hood basis.
Definition: taylorhoodbasis.hh:62
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: taylorhoodbasis.hh:110
TaylorHoodBasisTree< GV > Node
Template mapping root tree path to type of created tree node.
Definition: taylorhoodbasis.hh:76
size_type size(const SizePrefix prefix) const
Return number of possible values for next position in multi index.
Definition: taylorhoodbasis.hh:151
GV GridView
The grid view that the FE basis is defined on.
Definition: taylorhoodbasis.hh:70
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: taylorhoodbasis.hh:82
std::size_t size_type
Type used for indices and size information.
Definition: taylorhoodbasis.hh:73
TaylorHoodPreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition: taylorhoodbasis.hh:96
Dune::ReservedVector< size_type, 2 > SizePrefix
Type used for prefixes handed to the size() method.
Definition: taylorhoodbasis.hh:85
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: taylorhoodbasis.hh:116
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: taylorhoodbasis.hh:208
size_type size() const
Same as size(prefix) with empty prefix.
Definition: taylorhoodbasis.hh:145
Impl::DefaultNodeIndexSet< TaylorHoodPreBasis > IndexSet
Type of created tree node index set.
Definition: taylorhoodbasis.hh:79
void initializeIndices()
Initialize the global indices.
Definition: taylorhoodbasis.hh:103
IndexSet makeIndexSet() const
Create tree node index set.
Definition: taylorhoodbasis.hh:139
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: taylorhoodbasis.hh:202
Node makeNode() const
Create tree node.
Definition: taylorhoodbasis.hh:125
Grid view abstract base class.
Definition: gridview.hh:63
A Vector class with statically reserved memory.
Definition: reservedvector.hh:43
void setChild(T &t, index_constant< i >={})
Sets the i-th child to the passed-in value.
Definition: powernode.hh:144
A few common exception classes.
constexpr index_constant< 0 > _0
Compile time index with value 0.
Definition: indices.hh:51
constexpr index_constant< 1 > _1
Compile time index with value 1.
Definition: indices.hh:54
auto taylorHood()
Create a pre-basis factory that can create a Taylor-Hood pre-basis.
Definition: taylorhoodbasis.hh:347
ImplementationDefined child(Node &&node, Indices... indices)
Extracts the child of a node given by a sequence of compile-time and run-time indices.
Definition: childextraction.hh:126
Namespace with predefined compile time indices for the range [0,19].
Definition: indices.hh:49
Dune namespace.
Definition: alignedallocator.hh:11
An stl-compliant random-access container which stores everything on the stack.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 22, 23:30, 2024)