3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TAYLORHOODBASIS_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TAYLORHOODBASIS_HH
9#include <dune/typetree/powernode.hh>
10#include <dune/typetree/compositenode.hh>
12#include <dune/functions/functionspacebases/nodes.hh>
14#include <dune/functions/functionspacebases/lagrangebasis.hh>
15#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
35class TaylorHoodVelocityTree;
38class TaylorHoodBasisTree;
40template<
typename GV,
class MI,
bool HI>
41class TaylorHoodNodeIndexSet;
65template<
typename GV,
class MI,
bool HI=false>
68 static const bool useHybridIndices = HI;
70 static const int dim = GV::dimension;
72 template<
class,
class,
bool>
73 friend class TaylorHoodNodeIndexSet;
84 using Node = TaylorHoodBasisTree<GV>;
87 using IndexSet = TaylorHoodNodeIndexSet<GV, MI, HI>;
97 using PQMultiIndex = std::array<size_type, 1>;
158 return sizeImp<useHybridIndices>(prefix);
164 typename std::enable_if<not hi,int>::type = 0>
167 if (prefix.size() == 0)
169 if (prefix.size() == 1)
172 return dim * pq2PreBasis_.
size();
174 return pq1PreBasis_.
size();
176 assert(prefix.size() == 2);
181 typename std::enable_if<hi,int>::type = 0>
184 if (prefix.size() == 0)
186 if (prefix.size() == 1)
189 return pq2PreBasis_.
size();
191 return pq1PreBasis_.
size();
193 if (prefix.size() == 2)
200 assert(prefix.size() == 3);
209 return dim * pq2PreBasis_.
size() + pq1PreBasis_.
size();
221 PQ1PreBasis pq1PreBasis_;
222 PQ2PreBasis pq2PreBasis_;
228class TaylorHoodVelocityTree :
229 public PowerBasisNode<LagrangeNode<GV,2>, GV::dimension>
231 using PQ2Node = LagrangeNode<GV,2>;
232 using Base = PowerBasisNode<PQ2Node, GV::dimension>;
235 TaylorHoodVelocityTree()
237 for(
int i=0; i<GV::dimension; ++i)
238 this->setChild(i, std::make_shared<PQ2Node>());
243class TaylorHoodBasisTree :
244 public CompositeBasisNode<
245 TaylorHoodVelocityTree<GV>,
249 using VelocityNode=TaylorHoodVelocityTree<GV>;
250 using PressureNode=LagrangeNode<GV,1>;
252 using Base=CompositeBasisNode<VelocityNode, PressureNode>;
255 TaylorHoodBasisTree()
257 this->
template setChild<0>(std::make_shared<VelocityNode>());
258 this->
template setChild<1>(std::make_shared<PressureNode>());
264template<
typename GV,
class MI,
bool HI>
265class TaylorHoodNodeIndexSet
267 static const bool useHybridIndices = HI;
269 static const int dim = GV::dimension;
273 using size_type = std::size_t;
276 using MultiIndex = MI;
278 using PreBasis = TaylorHoodPreBasis<GV, MI, HI>;
280 using Node = TaylorHoodBasisTree<GV>;
282 using PQ1NodeIndexSet =
typename PreBasis::PQ1PreBasis::IndexSet;
283 using PQ2NodeIndexSet =
typename PreBasis::PQ2PreBasis::IndexSet;
285 TaylorHoodNodeIndexSet(
const PreBasis & preBasis) :
286 preBasis_(&preBasis),
287 pq1NodeIndexSet_(preBasis_->pq1PreBasis_.makeIndexSet()),
288 pq2NodeIndexSet_(preBasis_->pq2PreBasis_.makeIndexSet())
291 void bind(
const Node& node)
293 using namespace TypeTree::Indices;
295 pq1NodeIndexSet_.bind(node.child(
_1));
296 pq2NodeIndexSet_.bind(node.child(
_0, 0));
302 pq1NodeIndexSet_.unbind();
303 pq2NodeIndexSet_.unbind();
306 size_type size()
const
308 return node_->size();
311 template<
typename It>
312 It indices(It multiIndices)
const
314 return indicesImp<useHybridIndices>(multiIndices);
317 static const void multiIndexPushFront(MultiIndex& M, size_type M0)
319 M.resize(M.size()+1);
320 for(std::size_t i=M.size()-1; i>0; --i)
325 template<
bool hi,
class It,
326 typename std::enable_if<not hi,int>::type = 0>
327 It indicesImp(It multiIndices)
const
331 size_type subTreeSize = pq2NodeIndexSet_.size();
332 pq2NodeIndexSet_.indices(multiIndices);
333 for (std::size_t i = 0; i<subTreeSize; ++i)
335 multiIndexPushFront(multiIndices[i], 0);
336 multiIndices[i][1] = multiIndices[i][1]*dim +
child;
338 multiIndices += subTreeSize;
340 pq1NodeIndexSet_.indices(multiIndices);
341 size_type subTreeSize = pq1NodeIndexSet_.size();
342 for (std::size_t i = 0; i<subTreeSize; ++i)
343 multiIndexPushFront(multiIndices[i], 1);
344 multiIndices += subTreeSize;
348 template<
bool hi,
class It,
349 typename std::enable_if<hi,int>::type = 0>
350 It indicesImp(It multiIndices)
const
354 size_type subTreeSize = pq2NodeIndexSet_.size();
355 pq2NodeIndexSet_.indices(multiIndices);
356 for (std::size_t i = 0; i<subTreeSize; ++i)
358 multiIndexPushFront(multiIndices[i], 0);
359 multiIndices[i].push_back(i);
361 multiIndices += subTreeSize;
363 pq1NodeIndexSet_.indices(multiIndices);
364 size_type subTreeSize = pq1NodeIndexSet_.size();
365 for (std::size_t i = 0; i<subTreeSize; ++i)
366 multiIndexPushFront(multiIndices[i], 1);
367 multiIndices += subTreeSize;
372 const PreBasis* preBasis_;
373 PQ1NodeIndexSet pq1NodeIndexSet_;
374 PQ2NodeIndexSet pq2NodeIndexSet_;
381namespace BasisFactory {
385class TaylorHoodPreBasisFactory
388 static const std::size_t requiredMultiIndexSize=2;
390 template<
class MultiIndex,
class Gr
idView>
391 auto makePreBasis(
const GridView& gridView)
const
393 return TaylorHoodPreBasis<GridView, MultiIndex>(gridView);
408 return Imp::TaylorHoodPreBasisFactory();
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:47
size_type size() const
Same as size(prefix) with empty prefix.
Definition: lagrangebasis.hh:168
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: lagrangebasis.hh:143
void initializeIndices()
Initialize the global indices.
Definition: lagrangebasis.hh:113
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: lagrangebasis.hh:211
Pre-basis for lowest order Taylor-Hood basis.
Definition: taylorhoodbasis.hh:67
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: taylorhoodbasis.hh:118
TaylorHoodBasisTree< GV > Node
Template mapping root tree path to type of created tree node.
Definition: taylorhoodbasis.hh:84
size_type size(const SizePrefix prefix) const
Return number of possible values for next position in multi index.
Definition: taylorhoodbasis.hh:156
GV GridView
The grid view that the FE basis is defined on.
Definition: taylorhoodbasis.hh:78
MI MultiIndex
Type used for global numbering of the basis vectors.
Definition: taylorhoodbasis.hh:90
std::size_t size_type
Type used for indices and size information.
Definition: taylorhoodbasis.hh:81
TaylorHoodPreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition: taylorhoodbasis.hh:104
Dune::ReservedVector< size_type, 2 > SizePrefix
Type used for prefixes handed to the size() method.
Definition: taylorhoodbasis.hh:93
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: taylorhoodbasis.hh:124
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: taylorhoodbasis.hh:213
size_type size() const
Same as size(prefix) with empty prefix.
Definition: taylorhoodbasis.hh:150
void initializeIndices()
Initialize the global indices.
Definition: taylorhoodbasis.hh:111
IndexSet makeIndexSet() const
Create tree node index set.
Definition: taylorhoodbasis.hh:144
TaylorHoodNodeIndexSet< GV, MI, HI > IndexSet
Template mapping root tree path to type of created tree node index set.
Definition: taylorhoodbasis.hh:87
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: taylorhoodbasis.hh:207
Node makeNode() const
Create tree node.
Definition: taylorhoodbasis.hh:133
Grid view abstract base class.
Definition: gridview.hh:60
A Vector class with statically reserved memory.
Definition: reservedvector.hh:43
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:406
Dune namespace.
Definition: alignedallocator.hh:14
An stl-compliant random-access container which stores everything on the stack.