Loading...
Searching...
No Matches
taylorhoodbasis.hh
Go to the documentation of this file.
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later
#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TAYLORHOODBASIS_HH
#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TAYLORHOODBASIS_HH
#include <dune/common/exceptions.hh>
#include <dune/common/reservedvector.hh>
#include <dune/common/indices.hh>
#include <dune/functions/functionspacebases/nodes.hh>
#include <dune/functions/functionspacebases/lagrangebasis.hh>
#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
namespace Dune {
namespace Functions {
// *****************************************************************************
// This is the reusable part of the basis. It contains
//
// TaylorHoodPreBasis
// TaylorHoodBasisTree
// TaylorHoodVelocityTree
//
// The pre-basis allows to create the others and is the owner of possible shared
// state. These components do _not_ depend on the global basis and local view
// and can be used without a global basis.
// *****************************************************************************
template<typename GV>
class TaylorHoodVelocityTree;
template<typename GV>
class TaylorHoodBasisTree;
template<typename GV, bool HI=false>
class TaylorHoodPreBasis
{
static const bool useHybridIndices = HI;
static const int dim = GV::dimension;
public:
using GridView = GV;
using size_type = std::size_t;
using Node = TaylorHoodBasisTree<GV>;
static constexpr size_type maxMultiIndexSize = useHybridIndices ? 3 : 2;
static constexpr size_type minMultiIndexSize = 2;
static constexpr size_type multiIndexBufferSize = maxMultiIndexSize;
private:
using PQ1PreBasis = LagrangePreBasis<GV,1>;
using PQ2PreBasis = LagrangePreBasis<GV,2>;
public:
TaylorHoodPreBasis(const GridView& gv) :
gridView_(gv),
pq1PreBasis_(gv),
pq2PreBasis_(gv)
{}
void initializeIndices()
{
pq1PreBasis_.initializeIndices();
pq2PreBasis_.initializeIndices();
}
const GridView& gridView() const
{
return gridView_;
}
void update (const GridView& gv)
{
pq1PreBasis_.update(gv);
pq2PreBasis_.update(gv);
}
Node makeNode() const
{
return Node{};
}
size_type size() const
{
return 2;
}
template<class SizePrefix>
size_type size(const SizePrefix& prefix) const
{
return sizeImp<useHybridIndices>(prefix);
}
private:
template<bool hi, class SizePrefix,
std::enable_if_t<not hi,int> = 0>
size_type sizeImp(const SizePrefix& prefix) const
{
if (prefix.size() == 0)
return 2;
if (prefix.size() == 1)
{
if (prefix[0] == 0)
return dim * pq2PreBasis_.size();
if (prefix[0] == 1)
return pq1PreBasis_.size();
}
assert(prefix.size() == 2);
return 0;
}
template<bool hi, class SizePrefix,
std::enable_if_t<hi,int> = 0>
size_type sizeImp(const SizePrefix& prefix) const
{
if (prefix.size() == 0)
return 2;
if (prefix.size() == 1)
{
if (prefix[0] == 0)
return pq2PreBasis_.size();
if (prefix[0] == 1)
return pq1PreBasis_.size();
}
if (prefix.size() == 2)
{
if (prefix[0] == 0)
return dim;
if (prefix[0] == 1)
return 0;
}
assert(prefix.size() == 3);
return 0;
}
public:
size_type dimension() const
{
return dim * pq2PreBasis_.size() + pq1PreBasis_.size();
}
size_type maxNodeSize() const
{
return dim * pq2PreBasis_.maxNodeSize() + pq1PreBasis_.maxNodeSize();
}
template<typename It>
It indices(const Node& node, It it) const
{
return indicesImp<useHybridIndices>(node, it);
}
auto containerDescriptor() const
{
namespace CD = Dune::Functions::ContainerDescriptors;
if constexpr(HI)
return CD::makeDescriptor(
CD::makeUniformDescriptor(pq2PreBasis_.size(),
CD::FlatArray<GV::dimension>{}),
CD::FlatVector{pq1PreBasis_.size()});
else
return CD::Array<CD::FlatVector,2>{
CD::FlatVector{GV::dimension * pq2PreBasis_.size()},
CD::FlatVector{pq1PreBasis_.size()} };
}
protected:
template<class MultiIndex>
static const void multiIndexPushFront(MultiIndex& M, size_type M0)
{
M.resize(M.size()+1);
for(std::size_t i=M.size()-1; i>0; --i)
M[i] = M[i-1];
M[0] = M0;
}
template<bool hi, class It,
std::enable_if_t<not hi,int> = 0>
It indicesImp(const Node& node, It multiIndices) const
{
using namespace Dune::Indices;
for(std::size_t child=0; child<dim; ++child)
{
size_type subTreeSize = node.child(_0, 0).size();
pq2PreBasis_.indices(node.child(_0, 0), multiIndices);
for (std::size_t i = 0; i<subTreeSize; ++i)
{
multiIndexPushFront(multiIndices[i], 0);
multiIndices[i][1] = multiIndices[i][1]*dim + child;
}
multiIndices += subTreeSize;
}
size_type subTreeSize = node.child(_1).size();
pq1PreBasis_.indices(node.child(_1), multiIndices);
for (std::size_t i = 0; i<subTreeSize; ++i)
multiIndexPushFront(multiIndices[i], 1);
multiIndices += subTreeSize;
return multiIndices;
}
template<bool hi, class It,
std::enable_if_t<hi,int> = 0>
It indicesImp(const Node& node, It multiIndices) const
{
using namespace Dune::Indices;
for(std::size_t child=0; child<dim; ++child)
{
size_type subTreeSize = node.child(_0, 0).size();
pq2PreBasis_.indices(node.child(_0, 0), multiIndices);
for (std::size_t i = 0; i<subTreeSize; ++i)
{
multiIndexPushFront(multiIndices[i], 0);
multiIndices[i].push_back(i);
}
multiIndices += subTreeSize;
}
size_type subTreeSize = node.child(_1).size();
pq1PreBasis_.indices(node.child(_1), multiIndices);
for (std::size_t i = 0; i<subTreeSize; ++i)
multiIndexPushFront(multiIndices[i], 1);
multiIndices += subTreeSize;
return multiIndices;
}
GridView gridView_;
PQ1PreBasis pq1PreBasis_;
PQ2PreBasis pq2PreBasis_;
};
template<typename GV>
class TaylorHoodVelocityTree :
public PowerBasisNode<LagrangeNode<GV,2>, GV::dimension>
{
using PQ2Node = LagrangeNode<GV,2>;
using Base = PowerBasisNode<PQ2Node, GV::dimension>;
public:
TaylorHoodVelocityTree()
{
for(int i=0; i<GV::dimension; ++i)
this->setChild(i, PQ2Node());
}
};
template<typename GV>
class TaylorHoodBasisTree :
public CompositeBasisNode<
TaylorHoodVelocityTree<GV>,
LagrangeNode<GV,1>
>
{
using VelocityNode=TaylorHoodVelocityTree<GV>;
using PressureNode=LagrangeNode<GV,1>;
using Base=CompositeBasisNode<VelocityNode, PressureNode>;
public:
TaylorHoodBasisTree()
{
this->template setChild<0>(VelocityNode());
this->template setChild<1>(PressureNode());
}
};
namespace BasisFactory {
inline auto taylorHood()
{
return [](const auto& gridView) {
return TaylorHoodPreBasis<std::decay_t<decltype(gridView)>>(gridView);
};
}
} // end namespace BasisFactory
// *****************************************************************************
// This is the actual global basis implementation based on the reusable parts.
// *****************************************************************************
template<typename GV>
using TaylorHoodBasis = DefaultGlobalBasis<TaylorHoodPreBasis<GV> >;
} // end namespace Functions
} // end namespace Dune
#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_TAYLORHOODBASIS_HH
nodes.hh
lagrangebasis.hh
defaultglobalbasis.hh
Dune::Functions::BasisFactory::taylorHood
auto taylorHood()
Create a pre-basis factory that can create a Taylor-Hood pre-basis.
Definition taylorhoodbasis.hh:330
Dune::Functions::TaylorHoodBasis
DefaultGlobalBasis< TaylorHoodPreBasis< GV > > TaylorHoodBasis
Nodal basis for a lowest order Taylor-Hood Lagrangean finite element space.
Definition taylorhoodbasis.hh:365
Dune
Definition monomialset.hh:19
Dune::Functions
Definition monomialset.hh:19
Dune::Functions::ContainerDescriptors
Definition containerfactory.hh:20
Dune::Functions::DefaultGlobalBasis
Global basis for given pre-basis.
Definition defaultglobalbasis.hh:53
Dune::Functions::LagrangeNode
Definition lagrangebasis.hh:379
Dune::Functions::LagrangePreBasis
A pre-basis for a PQ-lagrange bases with given order.
Definition lagrangebasis.hh:65
Dune::Functions::LeafPreBasisMixin< LagrangePreBasis< GV, k, R > >::size
size_type size(const SizePrefix &prefix) const
Definition leafprebasismixin.hh:53
Dune::Functions::PowerBasisNode< LagrangeNode< GV, 2 >, GV::dimension >::PowerBasisNode
PowerBasisNode()=default
Dune::Functions::PowerBasisNode< LagrangeNode< GV, 2 >, GV::dimension >::setChild
void setChild(Index i, TT &&t)
Definition nodes.hh:317
Dune::Functions::CompositeBasisNode< TaylorHoodVelocityTree< GV >, LagrangeNode< GV, 1 > >::CompositeBasisNode
CompositeBasisNode()=default
Dune::Functions::CompositeBasisNode::child
const auto & child(Dune::index_constant< i > ii) const
Definition nodes.hh:408
Dune::Functions::CompositeBasisNode< TaylorHoodVelocityTree< GV >, LagrangeNode< GV, 1 > >::setChild
void setChild(TT &&t, Dune::index_constant< i > ii={})
Definition nodes.hh:458
Dune::Functions::TaylorHoodVelocityTree
Definition taylorhoodbasis.hh:288
Dune::Functions::TaylorHoodVelocityTree::TaylorHoodVelocityTree
TaylorHoodVelocityTree()
Definition taylorhoodbasis.hh:293
Dune::Functions::TaylorHoodBasisTree
Definition taylorhoodbasis.hh:306
Dune::Functions::TaylorHoodBasisTree::TaylorHoodBasisTree
TaylorHoodBasisTree()
Definition taylorhoodbasis.hh:313
Dune::Functions::TaylorHoodPreBasis
Pre-basis for lowest order Taylor-Hood basis.
Definition taylorhoodbasis.hh:61
Dune::Functions::TaylorHoodPreBasis::TaylorHoodPreBasis
TaylorHoodPreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition taylorhoodbasis.hh:89
Dune::Functions::TaylorHoodPreBasis::gridView
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition taylorhoodbasis.hh:103
Dune::Functions::TaylorHoodPreBasis::minMultiIndexSize
static constexpr size_type minMultiIndexSize
Definition taylorhoodbasis.hh:78
Dune::Functions::TaylorHoodPreBasis::size
size_type size(const SizePrefix &prefix) const
Return number of possible values for next position in multi index.
Definition taylorhoodbasis.hh:131
Dune::Functions::TaylorHoodPreBasis::gridView_
GridView gridView_
Definition taylorhoodbasis.hh:277
Dune::Functions::TaylorHoodPreBasis::GridView
GV GridView
The grid view that the FE basis is defined on.
Definition taylorhoodbasis.hh:69
Dune::Functions::TaylorHoodPreBasis::update
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition taylorhoodbasis.hh:109
Dune::Functions::TaylorHoodPreBasis::containerDescriptor
auto containerDescriptor() const
Return an container descriptor depending on the flag HI. Either return a Tuple if hybrid indices shou...
Definition taylorhoodbasis.hh:204
Dune::Functions::TaylorHoodPreBasis::Node
TaylorHoodBasisTree< GV > Node
Template mapping root tree path to type of created tree node.
Definition taylorhoodbasis.hh:75
Dune::Functions::TaylorHoodPreBasis::pq2PreBasis_
PQ2PreBasis pq2PreBasis_
Definition taylorhoodbasis.hh:280
Dune::Functions::TaylorHoodPreBasis::size
size_type size() const
Same as size(prefix) with empty prefix.
Definition taylorhoodbasis.hh:124
Dune::Functions::TaylorHoodPreBasis::dimension
size_type dimension() const
Get the total dimension of the space spanned by this basis.
Definition taylorhoodbasis.hh:182
Dune::Functions::TaylorHoodPreBasis::pq1PreBasis_
PQ1PreBasis pq1PreBasis_
Definition taylorhoodbasis.hh:279
Dune::Functions::TaylorHoodPreBasis::multiIndexPushFront
static const void multiIndexPushFront(MultiIndex &M, size_type M0)
Definition taylorhoodbasis.hh:221
Dune::Functions::TaylorHoodPreBasis::maxMultiIndexSize
static constexpr size_type maxMultiIndexSize
Definition taylorhoodbasis.hh:77
Dune::Functions::TaylorHoodPreBasis::makeNode
Node makeNode() const
Create tree node.
Definition taylorhoodbasis.hh:118
Dune::Functions::TaylorHoodPreBasis::indices
It indices(const Node &node, It it) const
Definition taylorhoodbasis.hh:194
Dune::Functions::TaylorHoodPreBasis::multiIndexBufferSize
static constexpr size_type multiIndexBufferSize
Definition taylorhoodbasis.hh:79
Dune::Functions::TaylorHoodPreBasis::initializeIndices
void initializeIndices()
Initialize the global indices.
Definition taylorhoodbasis.hh:96
Dune::Functions::TaylorHoodPreBasis::maxNodeSize
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition taylorhoodbasis.hh:188
Dune::Functions::TaylorHoodPreBasis::size_type
std::size_t size_type
Type used for indices and size information.
Definition taylorhoodbasis.hh:72
Dune::Functions::TaylorHoodPreBasis::indicesImp
It indicesImp(const Node &node, It multiIndices) const
Definition taylorhoodbasis.hh:231