3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_NEDELECBASIS_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_NEDELECBASIS_HH
12#include <dune/localfunctions/common/localfiniteelementvariant.hh>
13#include <dune/localfunctions/nedelec.hh>
15#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
16#include <dune/functions/functionspacebases/globalvaluedlocalfiniteelement.hh>
17#include <dune/functions/functionspacebases/nodes.hh>
19namespace Dune::Functions
24 template<
typename GV,
int dim,
typename R, std::
size_t order>
25 class Nedelec1stKindLocalFiniteElementMap
27 using D =
typename GV::ctype;
28 constexpr static bool hasFixedElementType = Capabilities::hasSingleGeometryType<typename GV::Grid>::v;
30 using CubeFiniteElement = Nedelec1stKindCubeLocalFiniteElement<D,R,dim,order>;
31 using SimplexFiniteElement = Nedelec1stKindSimplexLocalFiniteElement<D,R,dim,order>;
35 using T = LocalBasisTraits<D, dim, FieldVector<D,dim>, R, dim, FieldVector<R,dim>, FieldMatrix<D,dim,dim> >;
37 constexpr static unsigned int topologyId = Capabilities::hasSingleGeometryType<typename GV::Grid>::topologyId;
40 using FiniteElement = std::conditional_t<hasFixedElementType,
41 std::conditional_t<type.isCube(),CubeFiniteElement,SimplexFiniteElement>,
42 LocalFiniteElementVariant<CubeFiniteElement, SimplexFiniteElement> >;
44 static std::size_t numVariants(GeometryType type)
47 DUNE_THROW(NotImplemented,
"Only Nedelec elements of order 1 are implemented!");
49 auto numEdges = referenceElement<D,dim>(type).size(dim-1);
50 return power(2,numEdges);
53 Nedelec1stKindLocalFiniteElementMap(
const GV& gv)
55 orientation_(gv.size(0))
58 if constexpr (hasFixedElementType)
60 variants_.resize(numVariants(type));
61 for (
size_t i = 0; i < numVariants(type); i++)
62 variants_[i] = FiniteElement(i);
69 variants_[i] = SimplexFiniteElement(i);
76 const auto& indexSet = gv.indexSet();
78 for(
const auto& element : elements(gv))
81 auto elementIndex = elementMapper_.index(element);
82 orientation_[elementIndex] = 0;
84 for (std::size_t i=0; i<element.subEntities(dim-1); i++)
87 auto localV0 = refElement.subEntity(i,dim-1, 0,dim);
88 auto localV1 = refElement.subEntity(i,dim-1, 1,dim);
91 auto globalV0 = indexSet.subIndex(element,localV0,dim);
92 auto globalV1 = indexSet.subIndex(element,localV1,dim);
94 if ( (localV0<localV1 && globalV0>globalV1) || (localV0>localV1 && globalV0<globalV1) )
95 orientation_[elementIndex] |= (1 << i);
98 if constexpr (!hasFixedElementType)
99 if (element.type().isCube())
104 template<
class Element>
105 const auto& find(
const Element& element)
const
107 return variants_[orientation_[elementMapper_.index(element)]];
111 std::vector<FiniteElement> variants_;
113 std::vector<unsigned short> orientation_;
131template<
typename GV,
typename Range, std::
size_t kind,
int order>
134template<
typename GV,
typename Range, std::
size_t kind,
int order>
137 static const int dim = GV::dimension;
138 static_assert(kind==1,
"Only the Nedelec basis of the first kind is currently implemented!");
139 using FiniteElementMap =
typename Impl::Nedelec1stKindLocalFiniteElementMap<GV, dim, Range, order>;
146 using size_type = std::size_t;
148 using Node = NedelecNode<GV, Range, kind, order>;
150 static constexpr size_type maxMultiIndexSize = 1;
151 static constexpr size_type minMultiIndexSize = 1;
152 static constexpr size_type multiIndexBufferSize = 1;
155 NedelecPreBasis(
const GridView& gv) :
157 finiteElementMap_(gv),
161 DUNE_THROW(NotImplemented,
"Only Nedelec elements of the first kind are implemented!");
165 if (gv.indexSet().types(0).size() > 2)
166 DUNE_THROW(NotImplemented,
"Nédélec basis is only implemented for grids with simplex and cube elements");
168 for(
auto type : gv.indexSet().types(0))
169 if (!type.isSimplex() && !type.isCube())
170 DUNE_THROW(NotImplemented,
"Nédélec basis is only implemented for grids with simplex or cube elements.");
173 DUNE_THROW(NotImplemented,
"Only first-order elements are implemented");
175 if (dim!=2 && dim!=3)
176 DUNE_THROW(NotImplemented,
"Only 2d and 3d Nédélec elements are implemented");
179 void initializeIndices()
184 const GridView& gridView()
const
190 void update (
const GridView& gv)
193 mapper_.update(gridView_);
199 Node makeNode()
const
201 return Node{&finiteElementMap_};
204 size_type size()
const
206 return mapper_.size();
210 template<
class SizePrefix>
211 size_type size(
const SizePrefix& prefix)
const
213 assert(prefix.size() == 0 || prefix.size() == 1);
214 return (prefix.size() == 0) ? size() : 0;
217 size_type dimension()
const
222 size_type maxNodeSize()
const
224 size_type result = 0;
225 for (
auto&& type : gridView_.indexSet().types(0))
227 size_type numEdges = referenceElement<typename GV::ctype,dim>(type).size(dim-1);
228 result = std::max(result, numEdges);
237 template<
typename It>
238 It indices(
const Node& node, It it)
const
240 const auto& element = node.element();
243 if (not(element.type().isCube()) and not(element.type().isSimplex()))
244 DUNE_THROW(NotImplemented,
"NedelecBasis only implemented for cube and simplex elements.");
246 for(std::size_t i=0, end=node.size(); i<end; ++i, ++it)
248 Dune::LocalKey localKey = node.finiteElement().localCoefficients().localKey(i);
249 *it = { mapper_.subIndex(element, localKey.
subEntity(), localKey.
codim()) + localKey.
index() };
257 FiniteElementMap finiteElementMap_;
263template<
typename GV,
typename Range,
size_t kind,
int order>
267 static const int dim = GV::dimension;
271 using size_type = std::size_t;
272 using Element =
typename GV::template Codim<0>::Entity;
273 static_assert(kind==1,
"Only Nedelec elements of the first kind are implemented!");
274 using FiniteElementMap =
typename Impl::Nedelec1stKindLocalFiniteElementMap<GV, dim, Range, order>;
275 using FiniteElement = Impl::GlobalValuedLocalFiniteElement<Impl::CovariantPiolaTransformator,
276 typename FiniteElementMap::FiniteElement,
279 NedelecNode(
const FiniteElementMap* finiteElementMap) :
281 finiteElementMap_(finiteElementMap)
285 const Element& element()
const
294 const FiniteElement& finiteElement()
const
296 return finiteElement_;
300 void bind(
const Element& e)
303 finiteElement_.bind((finiteElementMap_->find(*element_)), e);
304 this->setSize(finiteElement_.size());
309 FiniteElement finiteElement_;
310 const Element* element_;
311 const FiniteElementMap* finiteElementMap_;
316namespace BasisFactory {
327template<std::
size_t kind, std::
size_t order,
typename Range=
double>
330 return [](
const auto& gridView) {
331 return NedelecPreBasis<std::decay_t<
decltype(gridView)>, Range, kind, order>(gridView);
350template<
typename GV, std::
size_t kind, std::
size_t order,
typename Range=
double>
351using NedelecBasis = DefaultGlobalBasis<NedelecPreBasis<GV, Range, kind, order > >;
Describe position of one degree of freedom.
Definition: localkey.hh:23
unsigned int index() const
Return offset within subentity.
Definition: localkey.hh:68
unsigned int codim() const
Return codim of associated entity.
Definition: localkey.hh:62
unsigned int subEntity() const
Return number of associated subentity.
Definition: localkey.hh:56
Implementation class for a multiple codim and multiple geometry type mapper.
Definition: mcmgmapper.hh:129
A few common exception classes.
A set of traits classes to store static information about grid implementation.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
auto nedelec()
Create a pre-basis factory that can create a Nédélec pre-basis.
Definition: nedelecbasis.hh:328
unspecified value type referenceElement(T &&... t)
Returns a reference element for the objects t....
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:472
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition: type.hh:463
MCMGLayout mcmgLayout(Codim< codim >)
layout for entities of codimension codim
Definition: mcmgmapper.hh:72
MCMGLayout mcmgElementLayout()
layout for elements (codim-0 entities)
Definition: mcmgmapper.hh:97
Mapper for multiple codim and multiple geometry types.
constexpr Base power(Base m, Exponent p)
Power method for integer exponents.
Definition: math.hh:75