Loading...
Searching...
No Matches
refinedlagrangebasis.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_REFINEDLAGRANGEBASIS_HH
#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_REFINEDLAGRANGEBASIS_HH
#include <type_traits>
#include <dune/common/exceptions.hh>
#include <dune/common/math.hh>
#include <dune/localfunctions/refined.hh>
#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
#include <dune/functions/functionspacebases/leafprebasismappermixin.hh>
#include <dune/functions/functionspacebases/nodes.hh>
#include <dune/geometry/type.hh>
#include <dune/grid/common/mcmgmapper.hh>
namespace Dune {
namespace Functions {
template<typename GV, int k, typename R>
class RefinedLagrangeNode;
template <typename GV, int k, typename R = double>
class RefinedLagrangePreBasis :
public LeafPreBasisMapperMixin< GV >
{
using Base = LeafPreBasisMapperMixin< GV >;
static const int dim = GV::dimension;
// refined basis only implemented for P0 and P1
static_assert(k == 0 || k == 1);
// the layout is defined in terms of a MCMGLayout specialized for k == 0 or 1
static MCMGLayout dofLayout()
{
if constexpr(k == 0)
// a refined P0 basis assigns each element 2^dim DOFs
return [](GeometryType gt, int) -> size_t {
return (gt.dim() == dim) ? (1 << dim) : 0;
};
else if constexpr(k == 1)
// a refined P1 basis has the same layout as a P2 basis
return [](GeometryType gt, int) -> size_t {
return Dune::binomial(int(k),int(gt.dim()));
};
else
DUNE_THROW(Dune::NotImplemented,
"Refined basis not implemented for higher-order Lagrange (k>=2) elements.");
}
public:
using GridView = GV;
using Node = RefinedLagrangeNode<GV, k, R>;
RefinedLagrangePreBasis (const GridView& gv)
: Base(gv, dofLayout())
{
for (auto gt : gv.indexSet().types(0)) {
if (!gt.isSimplex())
DUNE_THROW(Dune::NotImplemented,
"Refined Lagrange basis only implemented for simplex grids.");
}
}
Node makeNode () const
{
return Node{};
}
static constexpr unsigned int order()
{
return k;
}
};
template <typename GV, int k, typename R>
class RefinedLagrangeNode
: public LeafBasisNode
{
static constexpr int dim = GV::dimension;
// refined basis only implemented for P0 and P1
static_assert(k == 0 || k == 1);
public:
using Element = typename GV::template Codim<0>::Entity;
using FiniteElement = std::conditional_t<(k==0),
Dune::RefinedP0LocalFiniteElement<typename GV::ctype,R,dim>,
Dune::RefinedP1LocalFiniteElement<typename GV::ctype,R,dim>>;
RefinedLagrangeNode ()
: finiteElement_{}
, element_(nullptr)
{}
const Element& element () const
{
return *element_;
}
const FiniteElement& finiteElement () const
{
return finiteElement_;
}
void bind (const Element& e)
{
element_ = &e;
this->setSize(finiteElement_.size());
}
static constexpr unsigned int order()
{
return k;
}
protected:
const FiniteElement finiteElement_;
const Element* element_;
};
namespace BasisFactory {
template <int k, typename R=double>
auto refinedLagrange ()
{
return [](const auto& gridView) {
return RefinedLagrangePreBasis<std::decay_t<decltype(gridView)>, k, R>(gridView);
};
}
} // end namespace BasisFactory
template <typename GV, int k, typename R=double>
using RefinedLagrangeBasis = DefaultGlobalBasis<RefinedLagrangePreBasis<GV,k,R> >;
} // end namespace Functions
} // end namespace Dune
#endif // DUNE_FUNCTIONS_FUNCTIONSPACEBASES_REFINEDLAGRANGEBASIS_HH
nodes.hh
leafprebasismappermixin.hh
defaultglobalbasis.hh
Dune::Functions::RefinedLagrangeBasis
DefaultGlobalBasis< RefinedLagrangePreBasis< GV, k, R > > RefinedLagrangeBasis
Nodal basis of a continuous Lagrange finite-element space on a uniformly refined simplex element.
Definition refinedlagrangebasis.hh:226
Dune::Functions::BasisFactory::refinedLagrange
auto refinedLagrange()
Create a pre-basis factory that can create a RefinedLagrange pre-basis.
Definition refinedlagrangebasis.hh:202
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::LeafPreBasisMapperMixin::LeafPreBasisMapperMixin
LeafPreBasisMapperMixin(const GridView &gv, Dune::MCMGLayout layout)
Construct from GridView and local DOF layout.
Definition leafprebasismappermixin.hh:74
Dune::Functions::BasisNodeMixin::setSize
void setSize(const size_type size)
Definition nodes.hh:197
Dune::Functions::LeafBasisNode
Definition nodes.hh:218
Dune::Functions::RefinedLagrangeNode
Definition refinedlagrangebasis.hh:120
Dune::Functions::RefinedLagrangeNode::FiniteElement
std::conditional_t<(k==0), Dune::RefinedP0LocalFiniteElement< typename GV::ctype, R, dim >, Dune::RefinedP1LocalFiniteElement< typename GV::ctype, R, dim > > FiniteElement
Type of the local finite-element.
Definition refinedlagrangebasis.hh:131
Dune::Functions::RefinedLagrangeNode::finiteElement
const FiniteElement & finiteElement() const
Return the LocalFiniteElement for the element we are bound to.
Definition refinedlagrangebasis.hh:164
Dune::Functions::RefinedLagrangeNode::element_
const Element * element_
Definition refinedlagrangebasis.hh:187
Dune::Functions::RefinedLagrangeNode::bind
void bind(const Element &e)
Bind the node to the element e.
Definition refinedlagrangebasis.hh:170
Dune::Functions::RefinedLagrangeNode::finiteElement_
const FiniteElement finiteElement_
Definition refinedlagrangebasis.hh:186
Dune::Functions::RefinedLagrangeNode::order
static constexpr unsigned int order()
Polynomial order used in the local Lagrange finite-elements in subdomains of the element.
Definition refinedlagrangebasis.hh:180
Dune::Functions::RefinedLagrangeNode::Element
typename GV::template Codim< 0 >::Entity Element
Type of the element in the GridView.
Definition refinedlagrangebasis.hh:128
Dune::Functions::RefinedLagrangeNode::RefinedLagrangeNode
RefinedLagrangeNode()
The default constructor initializes all members to their default.
Definition refinedlagrangebasis.hh:144
Dune::Functions::RefinedLagrangeNode::element
const Element & element() const
Return current element. The behavior is undefined if the node is not bound to any element.
Definition refinedlagrangebasis.hh:153
Dune::Functions::RefinedLagrangePreBasis
A pre-basis for a refined Lagrange bases.
Definition refinedlagrangebasis.hh:46
Dune::Functions::RefinedLagrangePreBasis::order
static constexpr unsigned int order()
Polynomial order used in the local Lagrange finite-elements.
Definition refinedlagrangebasis.hh:109
Dune::Functions::RefinedLagrangePreBasis::makeNode
Node makeNode() const
Create tree node.
Definition refinedlagrangebasis.hh:97
Dune::Functions::RefinedLagrangePreBasis::Node
RefinedLagrangeNode< GV, k, R > Node
Type of the refined Lagrange tree node.
Definition refinedlagrangebasis.hh:78
Dune::Functions::RefinedLagrangePreBasis::GridView
GV GridView
The grid view that the FE basis is defined on.
Definition refinedlagrangebasis.hh:75
Dune::Functions::RefinedLagrangePreBasis::RefinedLagrangePreBasis
RefinedLagrangePreBasis(const GridView &gv)
Constructor for a given grid view object.
Definition refinedlagrangebasis.hh:86