Loading...
Searching...
No Matches
rannacherturekbasis.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_RANNACHERTUREKBASIS_HH
#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_RANNACHERTUREKBASIS_HH
#include <dune/common/exceptions.hh>
#include <dune/grid/common/capabilities.hh>
#include <dune/localfunctions/common/localfiniteelementvariant.hh>
#include <dune/localfunctions/rannacherturek.hh>
#include <dune/localfunctions/crouzeixraviart.hh>
#include <dune/functions/functionspacebases/nodes.hh>
#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
#include <dune/functions/functionspacebases/leafprebasismixin.hh>
namespace Dune {
namespace Functions {
// *****************************************************************************
// This is the reusable part of the basis. It contains
//
// RannacherTurekPreBasis
// RannacherTurekNode
//
// 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 RannacherTurekNode;
template<typename GV>
class RannacherTurekPreBasis;
template<typename GV>
class RannacherTurekPreBasis :
public LeafPreBasisMixin< RannacherTurekPreBasis<GV> >
{
static const int dim = GV::dimension;
public:
using GridView = GV;
using size_type = std::size_t;
using Node = RannacherTurekNode<GV>;
RannacherTurekPreBasis(const GridView& gv) :
gridView_(gv)
{
for(auto type : gv.indexSet().types(0))
if (!type.isSimplex() && !type.isCube())
DUNE_THROW(Dune::NotImplemented, "Rannacher-Turek or Crouzeix-Raviart elements are only implemented for grids with simplex or cube elements.");
}
void initializeIndices()
{}
const GridView& gridView() const
{
return gridView_;
}
void update (const GridView& gv)
{
gridView_ = gv;
}
Node makeNode() const
{
return Node{};
}
size_type dimension() const
{
return (size_type)(gridView_.size(1));
}
size_type maxNodeSize() const
{
return 2*GV::dimension;
}
template<typename It>
It indices(const Node& node, It it) const
{
for (size_type i = 0, end = node.size() ; i < end ; ++i, ++it)
{
Dune::LocalKey localKey = node.finiteElement().localCoefficients().localKey(i);
const auto& gridIndexSet = gridView().indexSet();
const auto& element = node.element();
*it = {{ (size_type)(gridIndexSet.subIndex(element,localKey.subEntity(),1)) }};
}
return it;
}
protected:
GridView gridView_;
};
template<typename GV>
class RannacherTurekNode :
public LeafBasisNode
{
static const int dim = GV::dimension;
static const int maxSize = 2*dim;
constexpr static bool hasFixedElementType = Capabilities::hasSingleGeometryType<typename GV::Grid>::v;
using CubeFiniteElement = RannacherTurekLocalFiniteElement<typename GV::ctype,double,dim>;
using SimplexFiniteElement = CrouzeixRaviartLocalFiniteElement<typename GV::ctype,double,dim>;
constexpr static unsigned int topologyId = Capabilities::hasSingleGeometryType<typename GV::Grid>::topologyId; // meaningless if hasFixedElementType is false
constexpr static GeometryType type = GeometryType(topologyId, GV::dimension);
public:
using size_type = std::size_t;
using Element = typename GV::template Codim<0>::Entity;
using FiniteElement = std::conditional_t<hasFixedElementType,
std::conditional_t<type.isCube(),CubeFiniteElement,SimplexFiniteElement>,
LocalFiniteElementVariant<CubeFiniteElement, SimplexFiniteElement> >;
RannacherTurekNode() :
finiteElement_(),
element_(nullptr)
{}
const Element& element() const
{
return *element_;
}
const FiniteElement& finiteElement() const
{
return finiteElement_;
}
void bind(const Element& e)
{
element_ = &e;
if constexpr (!hasFixedElementType)
finiteElement_ = e.type().isCube() ? static_cast<FiniteElement>(CubeFiniteElement())
: static_cast<FiniteElement>(SimplexFiniteElement()) ;
this->setSize(finiteElement_.size());
}
protected:
FiniteElement finiteElement_;
const Element* element_;
};
namespace BasisFactory {
template<class Dummy=void>
auto rannacherTurek()
{
return [](const auto& gridView) {
return RannacherTurekPreBasis<std::decay_t<decltype(gridView)>>(gridView);
};
}
} // end namespace BasisFactory
template<typename GV>
using RannacherTurekBasis = DefaultGlobalBasis<RannacherTurekPreBasis<GV> >;
} // end namespace Functions
} // end namespace Dune
#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_RANNACHERTUREKBASIS_HH
nodes.hh
defaultglobalbasis.hh
leafprebasismixin.hh
Dune::Functions::BasisFactory::rannacherTurek
auto rannacherTurek()
Create a pre-basis factory that can create a Rannacher-Turek pre-basis.
Definition rannacherturekbasis.hh:206
Dune::Functions::RannacherTurekBasis
DefaultGlobalBasis< RannacherTurekPreBasis< GV > > RannacherTurekBasis
Rannacher-Turek basis.
Definition rannacherturekbasis.hh:230
Dune
Definition monomialset.hh:19
Dune::Functions
Definition monomialset.hh:19
Dune::Functions::BasisFactory
Definition argyrisbasis.hh:926
Dune::Functions::DefaultGlobalBasis
Global basis for given pre-basis.
Definition defaultglobalbasis.hh:53
Dune::Functions::LeafPreBasisMixin
A generic MixIn class for PreBasis.
Definition leafprebasismixin.hh:36
Dune::Functions::BasisNodeMixin::size
size_type size() const
Obtain the number of basis function in the local node.
Definition nodes.hh:162
Dune::Functions::BasisNodeMixin::setSize
void setSize(const size_type size)
Definition nodes.hh:197
Dune::Functions::LeafBasisNode
Definition nodes.hh:218
Dune::Functions::RannacherTurekNode
Definition rannacherturekbasis.hh:140
Dune::Functions::RannacherTurekNode::bind
void bind(const Element &e)
Bind to element.
Definition rannacherturekbasis.hh:181
Dune::Functions::RannacherTurekNode::FiniteElement
std::conditional_t< hasFixedElementType, std::conditional_t< type.isCube(), CubeFiniteElement, SimplexFiniteElement >, LocalFiniteElementVariant< CubeFiniteElement, SimplexFiniteElement > > FiniteElement
Definition rannacherturekbasis.hh:156
Dune::Functions::RannacherTurekNode::finiteElement_
FiniteElement finiteElement_
Definition rannacherturekbasis.hh:192
Dune::Functions::RannacherTurekNode::size_type
std::size_t size_type
Definition rannacherturekbasis.hh:154
Dune::Functions::RannacherTurekNode::Element
typename GV::template Codim< 0 >::Entity Element
Definition rannacherturekbasis.hh:155
Dune::Functions::RannacherTurekNode::RannacherTurekNode
RannacherTurekNode()
Definition rannacherturekbasis.hh:160
Dune::Functions::RannacherTurekNode::element_
const Element * element_
Definition rannacherturekbasis.hh:193
Dune::Functions::RannacherTurekNode::finiteElement
const FiniteElement & finiteElement() const
Return the LocalFiniteElement for the element we are bound to.
Definition rannacherturekbasis.hh:175
Dune::Functions::RannacherTurekNode::element
const Element & element() const
Return current element, throw if unbound.
Definition rannacherturekbasis.hh:166
Dune::Functions::RannacherTurekPreBasis
Pre-basis for a Rannacher-Turek basis.
Definition rannacherturekbasis.hh:58
Dune::Functions::RannacherTurekPreBasis::initializeIndices
void initializeIndices()
Initialize the global indices.
Definition rannacherturekbasis.hh:82
Dune::Functions::RannacherTurekPreBasis::size_type
std::size_t size_type
Type used for indices and size information.
Definition rannacherturekbasis.hh:67
Dune::Functions::RannacherTurekPreBasis::makeNode
Node makeNode() const
Create tree node.
Definition rannacherturekbasis.hh:100
Dune::Functions::RannacherTurekPreBasis::update
void update(const GridView &gv)
Update the stored grid view, to be called if the grid has changed.
Definition rannacherturekbasis.hh:92
Dune::Functions::RannacherTurekPreBasis::indices
It indices(const Node &node, It it) const
Definition rannacherturekbasis.hh:118
Dune::Functions::RannacherTurekPreBasis::GridView
GV GridView
The grid view that the FE basis is defined on.
Definition rannacherturekbasis.hh:64
Dune::Functions::RannacherTurekPreBasis::dimension
size_type dimension() const
Same as size(prefix) with empty prefix.
Definition rannacherturekbasis.hh:106
Dune::Functions::RannacherTurekPreBasis::RannacherTurekPreBasis
RannacherTurekPreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition rannacherturekbasis.hh:73
Dune::Functions::RannacherTurekPreBasis::Node
RannacherTurekNode< GV > Node
Template mapping root tree path to type of created tree node.
Definition rannacherturekbasis.hh:70
Dune::Functions::RannacherTurekPreBasis::gridView
const GridView & gridView() const
Obtain the grid view that the basis is defined on.
Definition rannacherturekbasis.hh:86
Dune::Functions::RannacherTurekPreBasis::maxNodeSize
size_type maxNodeSize() const
Get the maximal number of DOFs associated to node for any element.
Definition rannacherturekbasis.hh:112
Dune::Functions::RannacherTurekPreBasis::gridView_
GridView gridView_
Definition rannacherturekbasis.hh:132