dune-functions 2.9.0
taylorhoodbasis.hh
Go to the documentation of this file.
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
6#include <dune/common/exceptions.hh>
7#include <dune/common/reservedvector.hh>
8#include <dune/common/indices.hh>
9
10#include <dune/typetree/powernode.hh>
11#include <dune/typetree/compositenode.hh>
12
14
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
59template<typename GV, bool HI=false>
61{
62 static const bool useHybridIndices = HI;
63
64 static const int dim = GV::dimension;
65
66public:
67
69 using GridView = GV;
70
72 using size_type = std::size_t;
73
76
77 static constexpr size_type maxMultiIndexSize = useHybridIndices ? 3 : 2;
78 static constexpr size_type minMultiIndexSize = 2;
80
81private:
82
85
86public:
87
90 gridView_(gv),
91 pq1PreBasis_(gv),
92 pq2PreBasis_(gv)
93 {}
94
97 {
100 }
101
103 const GridView& gridView() const
104 {
105 return gridView_;
106 }
107
109 void update (const GridView& gv)
110 {
113 }
114
119 {
120 return Node{};
121 }
122
125 {
126 return 2;
127 }
128
130 template<class SizePrefix>
131 size_type size(const SizePrefix& prefix) const
132 {
133 return sizeImp<useHybridIndices>(prefix);
134 }
135
136private:
137
138 template<bool hi, class SizePrefix,
139 typename std::enable_if<not hi,int>::type = 0>
140 size_type sizeImp(const SizePrefix& prefix) const
141 {
142 if (prefix.size() == 0)
143 return 2;
144 if (prefix.size() == 1)
145 {
146 if (prefix[0] == 0)
147 return dim * pq2PreBasis_.size();
148 if (prefix[0] == 1)
149 return pq1PreBasis_.size();
150 }
151 assert(prefix.size() == 2);
152 return 0;
153 }
154
155 template<bool hi, class SizePrefix,
156 typename std::enable_if<hi,int>::type = 0>
157 size_type sizeImp(const SizePrefix& prefix) const
158 {
159 if (prefix.size() == 0)
160 return 2;
161 if (prefix.size() == 1)
162 {
163 if (prefix[0] == 0)
164 return pq2PreBasis_.size();
165 if (prefix[0] == 1)
166 return pq1PreBasis_.size();
167 }
168 if (prefix.size() == 2)
169 {
170 if (prefix[0] == 0)
171 return dim;
172 if (prefix[0] == 1)
173 return 0;
174 }
175 assert(prefix.size() == 3);
176 return 0;
177 }
178
179public:
180
183 {
184 return dim * pq2PreBasis_.size() + pq1PreBasis_.size();
185 }
186
189 {
191 }
192
193 template<typename It>
194 It indices(const Node& node, It it) const
195 {
196 return indicesImp<useHybridIndices>(node, it);
197 }
198
199protected:
200
201 template<class MultiIndex>
202 static const void multiIndexPushFront(MultiIndex& M, size_type M0)
203 {
204 M.resize(M.size()+1);
205 for(std::size_t i=M.size()-1; i>0; --i)
206 M[i] = M[i-1];
207 M[0] = M0;
208 }
209
210 template<bool hi, class It,
211 typename std::enable_if<not hi,int>::type = 0>
212 It indicesImp(const Node& node, It multiIndices) const
213 {
214 using namespace Dune::Indices;
215 for(std::size_t child=0; child<dim; ++child)
216 {
217 size_type subTreeSize = node.child(_0, 0).size();
218 pq2PreBasis_.indices(node.child(_0, 0), multiIndices);
219 for (std::size_t i = 0; i<subTreeSize; ++i)
220 {
221 multiIndexPushFront(multiIndices[i], 0);
222 multiIndices[i][1] = multiIndices[i][1]*dim + child;
223 }
224 multiIndices += subTreeSize;
225 }
226 size_type subTreeSize = node.child(_1).size();
227 pq1PreBasis_.indices(node.child(_1), multiIndices);
228 for (std::size_t i = 0; i<subTreeSize; ++i)
229 multiIndexPushFront(multiIndices[i], 1);
230 multiIndices += subTreeSize;
231 return multiIndices;
232 }
233
234 template<bool hi, class It,
235 typename std::enable_if<hi,int>::type = 0>
236 It indicesImp(const Node& node, It multiIndices) const
237 {
238 using namespace Dune::Indices;
239 for(std::size_t child=0; child<dim; ++child)
240 {
241 size_type subTreeSize = node.child(_0, 0).size();
242 pq2PreBasis_.indices(node.child(_0, 0), multiIndices);
243 for (std::size_t i = 0; i<subTreeSize; ++i)
244 {
245 multiIndexPushFront(multiIndices[i], 0);
246 multiIndices[i].push_back(i);
247 }
248 multiIndices += subTreeSize;
249 }
250 size_type subTreeSize = node.child(_1).size();
251 pq1PreBasis_.indices(node.child(_1), multiIndices);
252 for (std::size_t i = 0; i<subTreeSize; ++i)
253 multiIndexPushFront(multiIndices[i], 1);
254 multiIndices += subTreeSize;
255 return multiIndices;
256 }
257
259
262};
263
264
265
266template<typename GV>
268 public PowerBasisNode<LagrangeNode<GV,2>, GV::dimension>
269{
272
273public:
275 {
276 for(int i=0; i<GV::dimension; ++i)
277 this->setChild(i, std::make_shared<PQ2Node>());
278 }
279};
280
281template<typename GV>
283 public CompositeBasisNode<
284 TaylorHoodVelocityTree<GV>,
285 LagrangeNode<GV,1>
286 >
287{
290
292
293public:
295 {
296 this->template setChild<0>(std::make_shared<VelocityNode>());
297 this->template setChild<1>(std::make_shared<PressureNode>());
298 }
299};
300
301
302
303namespace BasisFactory {
304
311inline auto taylorHood()
312{
313 return [](const auto& gridView) {
314 return TaylorHoodPreBasis<std::decay_t<decltype(gridView)>>(gridView);
315 };
316}
317
318} // end namespace BasisFactory
319
320// *****************************************************************************
321// This is the actual global basis implementation based on the reusable parts.
322// *****************************************************************************
323
345template<typename GV>
347
348
349
350} // end namespace Functions
351} // end namespace Dune
352
353
354#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TAYLORHOODBASIS_HH
auto taylorHood()
Create a pre-basis factory that can create a Taylor-Hood pre-basis.
Definition: taylorhoodbasis.hh:311
Definition: polynomial.hh:10
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:46
Definition: lagrangebasis.hh:387
It indices(const Node &node, It it) const
Definition: lagrangebasis.hh:192
void initializeIndices()
Initialize the global indices.
Definition: lagrangebasis.hh:96
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: lagrangebasis.hh:126
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: lagrangebasis.hh:184
size_type size() const
Same as size(prefix) with empty prefix.
Definition: lagrangebasis.hh:140
size_type size() const
Definition: nodes.hh:142
Definition: nodes.hh:193
Definition: nodes.hh:219
Definition: taylorhoodbasis.hh:269
TaylorHoodVelocityTree()
Definition: taylorhoodbasis.hh:274
Definition: taylorhoodbasis.hh:287
TaylorHoodBasisTree()
Definition: taylorhoodbasis.hh:294
Pre-basis for lowest order Taylor-Hood basis.
Definition: taylorhoodbasis.hh:61
TaylorHoodPreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition: taylorhoodbasis.hh:89
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: taylorhoodbasis.hh:103
static constexpr size_type minMultiIndexSize
Definition: taylorhoodbasis.hh:78
size_type size(const SizePrefix &prefix) const
Return number of possible values for next position in multi index.
Definition: taylorhoodbasis.hh:131
GridView gridView_
Definition: taylorhoodbasis.hh:258
GV GridView
The grid view that the FE basis is defined on.
Definition: taylorhoodbasis.hh:69
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: taylorhoodbasis.hh:109
PQ2PreBasis pq2PreBasis_
Definition: taylorhoodbasis.hh:261
size_type size() const
Same as size(prefix) with empty prefix.
Definition: taylorhoodbasis.hh:124
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: taylorhoodbasis.hh:182
PQ1PreBasis pq1PreBasis_
Definition: taylorhoodbasis.hh:260
static const void multiIndexPushFront(MultiIndex &M, size_type M0)
Definition: taylorhoodbasis.hh:202
static constexpr size_type maxMultiIndexSize
Definition: taylorhoodbasis.hh:77
Node makeNode() const
Create tree node.
Definition: taylorhoodbasis.hh:118
It indices(const Node &node, It it) const
Definition: taylorhoodbasis.hh:194
static constexpr size_type multiIndexBufferSize
Definition: taylorhoodbasis.hh:79
void initializeIndices()
Initialize the global indices.
Definition: taylorhoodbasis.hh:96
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: taylorhoodbasis.hh:188
std::size_t size_type
Type used for indices and size information.
Definition: taylorhoodbasis.hh:72
It indicesImp(const Node &node, It multiIndices) const
Definition: taylorhoodbasis.hh:212