3 #ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TAYLORHOODBASIS_HH
4 #define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TAYLORHOODBASIS_HH
6 #include <dune/common/exceptions.hh>
7 #include <dune/common/reservedvector.hh>
8 #include <dune/common/indices.hh>
10 #include <dune/typetree/powernode.hh>
11 #include <dune/typetree/compositenode.hh>
13 #include <dune/functions/functionspacebases/nodes.hh>
15 #include <dune/functions/functionspacebases/lagrangebasis.hh>
16 #include <dune/functions/functionspacebases/defaultglobalbasis.hh>
35 class TaylorHoodVelocityTree;
38 class TaylorHoodBasisTree;
59 template<
typename GV,
bool HI=false>
62 static const bool useHybridIndices = HI;
64 static const int dim = GV::dimension;
75 using Node = TaylorHoodBasisTree<GV>;
77 static constexpr
size_type maxMultiIndexSize = useHybridIndices ? 3 : 2;
78 static constexpr
size_type minMultiIndexSize = 2;
79 static constexpr
size_type multiIndexBufferSize = maxMultiIndexSize;
130 template<
class SizePrefix>
133 return sizeImp<useHybridIndices>(prefix);
138 template<
bool hi,
class SizePrefix,
139 std::enable_if_t<not hi,int> = 0>
140 size_type sizeImp(
const SizePrefix& prefix)
const
142 if (prefix.size() == 0)
144 if (prefix.size() == 1)
147 return dim * pq2PreBasis_.
size();
149 return pq1PreBasis_.
size();
151 assert(prefix.size() == 2);
155 template<
bool hi,
class SizePrefix,
156 std::enable_if_t<hi,int> = 0>
157 size_type sizeImp(
const SizePrefix& prefix)
const
159 if (prefix.size() == 0)
161 if (prefix.size() == 1)
164 return pq2PreBasis_.
size();
166 return pq1PreBasis_.
size();
168 if (prefix.size() == 2)
175 assert(prefix.size() == 3);
184 return dim * pq2PreBasis_.
size() + pq1PreBasis_.
size();
193 template<
typename It>
194 It indices(
const Node& node, It it)
const
196 return indicesImp<useHybridIndices>(node, it);
206 namespace CD = Dune::Functions::ContainerDescriptors;
208 return CD::makeDescriptor(
209 CD::makeUniformDescriptor(pq2PreBasis_.
size(),
213 return CD::Array<CD::FlatVector,2>{
220 template<
class MultiIndex>
221 static const void multiIndexPushFront(MultiIndex& M,
size_type M0)
223 M.resize(M.size()+1);
224 for(std::size_t i=M.size()-1; i>0; --i)
229 template<
bool hi,
class It,
230 std::enable_if_t<not hi,int> = 0>
231 It indicesImp(
const Node& node, It multiIndices)
const
233 using namespace Dune::Indices;
234 for(std::size_t child=0; child<dim; ++child)
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)
240 multiIndexPushFront(multiIndices[i], 0);
241 multiIndices[i][1] = multiIndices[i][1]*dim + child;
243 multiIndices += subTreeSize;
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;
253 template<
bool hi,
class It,
254 std::enable_if_t<hi,int> = 0>
255 It indicesImp(
const Node& node, It multiIndices)
const
257 using namespace Dune::Indices;
258 for(std::size_t child=0; child<dim; ++child)
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)
264 multiIndexPushFront(multiIndices[i], 0);
265 multiIndices[i].push_back(i);
267 multiIndices += subTreeSize;
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;
279 PQ1PreBasis pq1PreBasis_;
280 PQ2PreBasis pq2PreBasis_;
285 template<
typename GV>
286 class TaylorHoodVelocityTree :
287 public PowerBasisNode<LagrangeNode<GV,2>, GV::dimension>
289 using PQ2Node = LagrangeNode<GV,2>;
290 using Base = PowerBasisNode<PQ2Node, GV::dimension>;
293 TaylorHoodVelocityTree()
295 for(
int i=0; i<GV::dimension; ++i)
296 this->setChild(i, std::make_shared<PQ2Node>());
300 template<
typename GV>
301 class TaylorHoodBasisTree :
302 public CompositeBasisNode<
303 TaylorHoodVelocityTree<GV>,
307 using VelocityNode=TaylorHoodVelocityTree<GV>;
308 using PressureNode=LagrangeNode<GV,1>;
310 using Base=CompositeBasisNode<VelocityNode, PressureNode>;
313 TaylorHoodBasisTree()
315 this->
template setChild<0>(std::make_shared<VelocityNode>());
316 this->
template setChild<1>(std::make_shared<PressureNode>());
322 namespace BasisFactory {
364 template<
typename GV>
Global basis for given pre-basis.
Definition: defaultglobalbasis.hh:46
void initializeIndices()
Initialize the global indices.
Definition: lagrangebasis.hh:94
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: lagrangebasis.hh:124
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition: lagrangebasis.hh:168
size_type size(const SizePrefix &prefix) const
Return number of possible values for next position in multi index.
Definition: leafprebasismixin.hh:49
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
size_type size(const SizePrefix &prefix) const
Return number of possible values for next position in multi index.
Definition: taylorhoodbasis.hh:131
GV GridView
The grid view that the FE basis is defined on.
Definition: taylorhoodbasis.hh:69
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition: taylorhoodbasis.hh:103
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition: taylorhoodbasis.hh:109
auto containerDescriptor() const
Return an container descriptor depending on the flag HI. Either return a Tuple if hybrid indices shou...
Definition: taylorhoodbasis.hh:204
TaylorHoodBasisTree< GV > Node
Template mapping root tree path to type of created tree node.
Definition: taylorhoodbasis.hh:75
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
Node makeNode() const
Create tree node.
Definition: taylorhoodbasis.hh:118
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
auto taylorHood()
Create a pre-basis factory that can create a Taylor-Hood pre-basis.
Definition: taylorhoodbasis.hh:330
Definition: polynomial.hh:13