7#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TAYLORHOODBASIS_HH
8#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TAYLORHOODBASIS_HH
10#include <dune/common/exceptions.hh>
11#include <dune/common/reservedvector.hh>
12#include <dune/common/indices.hh>
14#include <dune/typetree/powernode.hh>
15#include <dune/typetree/compositenode.hh>
17#include <dune/functions/functionspacebases/nodes.hh>
19#include <dune/functions/functionspacebases/lagrangebasis.hh>
20#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
39class TaylorHoodVelocityTree;
42class TaylorHoodBasisTree;
63template<
typename GV,
bool HI=false>
66 static const bool useHybridIndices = HI;
68 static const int dim = GV::dimension;
79 using Node = TaylorHoodBasisTree<GV>;
81 static constexpr size_type maxMultiIndexSize = useHybridIndices ? 3 : 2;
82 static constexpr size_type minMultiIndexSize = 2;
83 static constexpr size_type multiIndexBufferSize = maxMultiIndexSize;
134 template<
class SizePrefix>
137 return sizeImp<useHybridIndices>(prefix);
142 template<
bool hi,
class SizePrefix,
143 std::enable_if_t<not hi,int> = 0>
144 size_type sizeImp(
const SizePrefix& prefix)
const
146 if (prefix.size() == 0)
148 if (prefix.size() == 1)
151 return dim * pq2PreBasis_.
size();
153 return pq1PreBasis_.
size();
155 assert(prefix.size() == 2);
159 template<
bool hi,
class SizePrefix,
160 std::enable_if_t<hi,int> = 0>
161 size_type sizeImp(
const SizePrefix& prefix)
const
163 if (prefix.size() == 0)
165 if (prefix.size() == 1)
168 return pq2PreBasis_.
size();
170 return pq1PreBasis_.
size();
172 if (prefix.size() == 2)
179 assert(prefix.size() == 3);
188 return dim * pq2PreBasis_.
size() + pq1PreBasis_.
size();
197 template<
typename It>
198 It indices(
const Node& node, It it)
const
200 return indicesImp<useHybridIndices>(node, it);
210 namespace CD = Dune::Functions::ContainerDescriptors;
212 return CD::makeDescriptor(
213 CD::makeUniformDescriptor(pq2PreBasis_.
size(),
217 return CD::Array<CD::FlatVector,2>{
224 template<
class MultiIndex>
225 static const void multiIndexPushFront(MultiIndex& M,
size_type M0)
227 M.resize(M.size()+1);
228 for(std::size_t i=M.size()-1; i>0; --i)
233 template<
bool hi,
class It,
234 std::enable_if_t<not hi,int> = 0>
235 It indicesImp(
const Node& node, It multiIndices)
const
237 using namespace Dune::Indices;
238 for(std::size_t child=0; child<dim; ++child)
240 size_type subTreeSize = node.child(_0, 0).size();
241 pq2PreBasis_.indices(node.child(_0, 0), multiIndices);
242 for (std::size_t i = 0; i<subTreeSize; ++i)
244 multiIndexPushFront(multiIndices[i], 0);
245 multiIndices[i][1] = multiIndices[i][1]*dim + child;
247 multiIndices += subTreeSize;
249 size_type subTreeSize = node.child(_1).size();
250 pq1PreBasis_.indices(node.child(_1), multiIndices);
251 for (std::size_t i = 0; i<subTreeSize; ++i)
252 multiIndexPushFront(multiIndices[i], 1);
253 multiIndices += subTreeSize;
257 template<
bool hi,
class It,
258 std::enable_if_t<hi,int> = 0>
259 It indicesImp(
const Node& node, It multiIndices)
const
261 using namespace Dune::Indices;
262 for(std::size_t child=0; child<dim; ++child)
264 size_type subTreeSize = node.child(_0, 0).size();
265 pq2PreBasis_.indices(node.child(_0, 0), multiIndices);
266 for (std::size_t i = 0; i<subTreeSize; ++i)
268 multiIndexPushFront(multiIndices[i], 0);
269 multiIndices[i].push_back(i);
271 multiIndices += subTreeSize;
273 size_type subTreeSize = node.child(_1).size();
274 pq1PreBasis_.indices(node.child(_1), multiIndices);
275 for (std::size_t i = 0; i<subTreeSize; ++i)
276 multiIndexPushFront(multiIndices[i], 1);
277 multiIndices += subTreeSize;
283 PQ1PreBasis pq1PreBasis_;
284 PQ2PreBasis pq2PreBasis_;
290class TaylorHoodVelocityTree :
291 public PowerBasisNode<LagrangeNode<GV,2>, GV::dimension>
293 using PQ2Node = LagrangeNode<GV,2>;
294 using Base = PowerBasisNode<PQ2Node, GV::dimension>;
297 TaylorHoodVelocityTree()
299 for(
int i=0; i<GV::dimension; ++i)
300 this->setChild(i, std::make_shared<PQ2Node>());
305class TaylorHoodBasisTree :
306 public CompositeBasisNode<
307 TaylorHoodVelocityTree<GV>,
311 using VelocityNode=TaylorHoodVelocityTree<GV>;
312 using PressureNode=LagrangeNode<GV,1>;
314 using Base=CompositeBasisNode<VelocityNode, PressureNode>;
317 TaylorHoodBasisTree()
319 this->
template setChild<0>(std::make_shared<VelocityNode>());
320 this->
template setChild<1>(std::make_shared<PressureNode>());
326namespace BasisFactory {
336 return [](
const auto& gridView) {
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:50
void initializeIndices()
Initialize the global indices.
Definition: lagrangebasis.hh:98
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: lagrangebasis.hh:128
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: lagrangebasis.hh:172
size_type size(const SizePrefix &prefix) const
Return number of possible values for next position in multi index.
Definition: leafprebasismixin.hh:53
Pre-basis for lowest order Taylor-Hood basis.
Definition: taylorhoodbasis.hh:65
TaylorHoodPreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition: taylorhoodbasis.hh:93
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: taylorhoodbasis.hh:107
size_type size(const SizePrefix &prefix) const
Return number of possible values for next position in multi index.
Definition: taylorhoodbasis.hh:135
GV GridView
The grid view that the FE basis is defined on.
Definition: taylorhoodbasis.hh:73
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: taylorhoodbasis.hh:113
auto containerDescriptor() const
Return an container descriptor depending on the flag HI. Either return a Tuple if hybrid indices shou...
Definition: taylorhoodbasis.hh:208
TaylorHoodBasisTree< GV > Node
Template mapping root tree path to type of created tree node.
Definition: taylorhoodbasis.hh:79
size_type size() const
Same as size(prefix) with empty prefix.
Definition: taylorhoodbasis.hh:128
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition: taylorhoodbasis.hh:186
Node makeNode() const
Create tree node.
Definition: taylorhoodbasis.hh:122
void initializeIndices()
Initialize the global indices.
Definition: taylorhoodbasis.hh:100
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: taylorhoodbasis.hh:192
std::size_t size_type
Type used for indices and size information.
Definition: taylorhoodbasis.hh:76
auto taylorHood()
Create a pre-basis factory that can create a Taylor-Hood pre-basis.
Definition: taylorhoodbasis.hh:334
Definition: polynomial.hh:17