3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_RAVIARTTHOMASBASIS_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_RAVIARTTHOMASBASIS_HH
12#include <dune/localfunctions/common/localfiniteelementvariant.hh>
13#include <dune/localfunctions/raviartthomas.hh>
14#include <dune/localfunctions/raviartthomas/raviartthomas0cube2d.hh>
15#include <dune/localfunctions/raviartthomas/raviartthomas0cube3d.hh>
16#include <dune/localfunctions/raviartthomas/raviartthomas02d.hh>
17#include <dune/localfunctions/raviartthomas/raviartthomas03d.hh>
18#include <dune/localfunctions/raviartthomas/raviartthomas1cube2d.hh>
19#include <dune/localfunctions/raviartthomas/raviartthomas1cube3d.hh>
20#include <dune/localfunctions/raviartthomas/raviartthomas12d.hh>
21#include <dune/localfunctions/raviartthomas/raviartthomas2cube2d.hh>
23#include <dune/functions/functionspacebases/globalvaluedlocalfiniteelement.hh>
24#include <dune/functions/functionspacebases/nodes.hh>
25#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
26#include <dune/functions/functionspacebases/flatmultiindex.hh>
33 template<
int dim,
typename D,
typename R, std::
size_t k>
34 struct RaviartThomasSimplexLocalInfo
37 using FiniteElement =
void*;
40 template<
typename D,
typename R>
41 struct RaviartThomasSimplexLocalInfo<2,D,R,0>
43 using FiniteElement = RT02DLocalFiniteElement<D,R>;
46 template<
typename D,
typename R>
47 struct RaviartThomasSimplexLocalInfo<2,D,R,1>
49 using FiniteElement = RT12DLocalFiniteElement<D,R>;
52 template<
typename D,
typename R>
53 struct RaviartThomasSimplexLocalInfo<3,D,R,0>
55 using FiniteElement = RT03DLocalFiniteElement<D,R>;
58 template<
int dim,
typename D,
typename R, std::
size_t k>
59 struct RaviartThomasCubeLocalInfo
62 using FiniteElement =
void*;
65 template<
typename D,
typename R>
66 struct RaviartThomasCubeLocalInfo<2,D,R,0>
68 using FiniteElement = RT0Cube2DLocalFiniteElement<D,R>;
71 template<
typename D,
typename R>
72 struct RaviartThomasCubeLocalInfo<2,D,R,1>
74 using FiniteElement = RT1Cube2DLocalFiniteElement<D,R>;
77 template<
typename D,
typename R>
78 struct RaviartThomasCubeLocalInfo<2,D,R,2>
80 using FiniteElement = RT2Cube2DLocalFiniteElement<D,R>;
83 template<
typename D,
typename R>
84 struct RaviartThomasCubeLocalInfo<3,D,R,0>
86 using FiniteElement = RT0Cube3DLocalFiniteElement<D,R>;
89 template<
typename D,
typename R>
90 struct RaviartThomasCubeLocalInfo<3,D,R,1>
92 using FiniteElement = RT1Cube3DLocalFiniteElement<D,R>;
95 template<
typename GV,
int dim,
typename R, std::
size_t k>
96 class RaviartThomasLocalFiniteElementMap
98 using D =
typename GV::ctype;
99 constexpr static bool hasFixedElementType = Capabilities::hasSingleGeometryType<typename GV::Grid>::v;
101 using CubeFiniteElement =
typename RaviartThomasCubeLocalInfo<dim, D, R, k>::FiniteElement;
102 using SimplexFiniteElement =
typename RaviartThomasSimplexLocalInfo<dim, D, R, k>::FiniteElement;
106 using T = LocalBasisTraits<D, dim, FieldVector<D,dim>, R, dim, FieldVector<R,dim>, FieldMatrix<D,dim,dim> >;
108 constexpr static unsigned int topologyId = Capabilities::hasSingleGeometryType<typename GV::Grid>::topologyId;
111 using FiniteElement = std::conditional_t<hasFixedElementType,
112 std::conditional_t<type.isCube(),CubeFiniteElement,SimplexFiniteElement>,
113 LocalFiniteElementVariant<CubeFiniteElement, SimplexFiniteElement> >;
117 static std::size_t numVariants(GeometryType type)
119 auto numFacets = referenceElement<D,dim>(type).size(1);
120 return power(2,numFacets);
123 RaviartThomasLocalFiniteElementMap(
const GV& gv)
127 if constexpr (hasFixedElementType)
129 variants_.resize(numVariants(type));
130 for (
size_t i = 0; i < numVariants(type); i++)
131 variants_[i] = FiniteElement(i);
138 variants_[i] = SimplexFiniteElement(i);
143 for(
const auto& cell : elements(gv))
145 unsigned int myId = elementMapper_.index(cell);
148 for (
const auto& intersection : intersections(gv,cell))
150 if (intersection.neighbor() && (elementMapper_.index(intersection.outside()) > myId))
151 orient_[myId] |= (1 << intersection.indexInInside());
155 if constexpr (!hasFixedElementType)
156 if (cell.type().isCube())
161 template<
class EntityType>
162 const FiniteElement& find(
const EntityType& e)
const
164 return variants_[orient_[elementMapper_.index(e)]];
168 std::vector<FiniteElement> variants_;
170 std::vector<unsigned char> orient_;
188template<
typename GV,
int k>
189class RaviartThomasNode;
191template<
typename GV,
int k,
class MI>
192class RaviartThomasPreBasis
194 static const int dim = GV::dimension;
195 using FiniteElementMap =
typename Impl::RaviartThomasLocalFiniteElementMap<GV, dim, double, k>;
201 using size_type = std::size_t;
203 using Node = RaviartThomasNode<GV, k>;
206 using IndexSet = Impl::DefaultNodeIndexSet<RaviartThomasPreBasis>;
209 using MultiIndex = MI;
214 RaviartThomasPreBasis(
const GridView& gv) :
216 finiteElementMap_(gv)
219 if (gv.indexSet().types(0).size() > 1 and k>0)
222 for(
auto type : gv.indexSet().types(0))
223 if (!type.isSimplex() && !type.isCube())
227 const static int dofsPerElement = type.isCube() ? ((dim == 2) ? k*(k+1)*dim : k*(k+1)*(k+1)*dim) : k*dim;
228 const static int dofsPerFace = type.isCube() ? (dim-2)*2*k+k+1 : (dim-1)*k+1 ;
230 dofsPerCodim_ = {{dofsPerElement, dofsPerFace}};
233 void initializeIndices()
236 codimOffset_[1] = codimOffset_[0] + dofsPerCodim_[0] * gridView_.size(0);
241 const GridView& gridView()
const
247 void update (
const GridView& gv)
255 Node makeNode()
const
257 return Node{&finiteElementMap_};
267 [[deprecated(
"Warning: The IndexSet typedef and the makeIndexSet method are deprecated. "\
268 "As a replacement use the indices() method of the PreBasis directly.")]]
269 IndexSet makeIndexSet()
const
271 return IndexSet{*
this};
274 size_type size()
const
276 return dofsPerCodim_[0] * gridView_.size(0) + dofsPerCodim_[1] * gridView_.size(1);
280 size_type size(
const SizePrefix prefix)
const
282 assert(prefix.size() == 0 || prefix.size() == 1);
283 return (prefix.size() == 0) ? size() : 0;
287 size_type dimension()
const
292 size_type maxNodeSize()
const
294 size_type result = 0;
295 for (
auto&& type : gridView_.indexSet().types(0))
298 const static int dofsPerElement = type.isCube() ? ((dim == 2) ? k*(k+1)*dim : k*(k+1)*(k+1)*dim) : k*dim;
299 const static int dofsPerFace = type.isCube() ? (dim-2)*2*k+k+1 : (dim-1)*k+1 ;
300 result =
std::max(result, dofsPerElement + dofsPerFace * numFaces);
311 template<
typename It>
312 It indices(
const Node& node, It it)
const
314 const auto& gridIndexSet = gridView().indexSet();
315 const auto& element = node.element();
318 if (not(element.type().isCube()) and not(element.type().isSimplex()))
321 for(std::size_t i=0, end=node.size(); i<end; ++i, ++it)
323 Dune::LocalKey localKey = node.finiteElement().localCoefficients().localKey(i);
327 size_t codim = localKey.
codim();
329 if (not(codim==0 or codim==1))
332 *it = { codimOffset_[codim] +
333 dofsPerCodim_[codim] * gridIndexSet.subIndex(element, subentity, codim) + localKey.
index() };
341 std::array<size_t,dim+1> codimOffset_;
342 FiniteElementMap finiteElementMap_;
344 std::array<int,dim+1> dofsPerCodim_;
349template<
typename GV,
int k>
350class RaviartThomasNode :
353 static const int dim = GV::dimension;
357 using size_type = std::size_t;
358 using Element =
typename GV::template Codim<0>::Entity;
359 using FiniteElementMap =
typename Impl::RaviartThomasLocalFiniteElementMap<GV, dim, double, k>;
360 using FiniteElement = Impl::GlobalValuedLocalFiniteElement<Impl::ContravariantPiolaTransformator,
361 typename FiniteElementMap::FiniteElement,
364 RaviartThomasNode(
const FiniteElementMap* finiteElementMap) :
366 finiteElementMap_(finiteElementMap)
370 const Element& element()
const
379 const FiniteElement& finiteElement()
const
381 return finiteElement_;
385 void bind(
const Element& e)
388 finiteElement_.bind((finiteElementMap_->find(*element_)), e);
389 this->setSize(finiteElement_.size());
394 FiniteElement finiteElement_;
395 const Element* element_;
396 const FiniteElementMap* finiteElementMap_;
399namespace BasisFactory {
403template<std::
size_t k>
404class RaviartThomasPreBasisFactory
407 static const std::size_t requiredMultiIndexSize=1;
409 template<
class MultiIndex,
class Gr
idView>
410 auto makePreBasis(
const GridView& gridView)
const
412 return RaviartThomasPreBasis<GridView, k, MultiIndex>(gridView);
426template<std::
size_t k>
429 return Imp::RaviartThomasPreBasisFactory<k>();
447template<
typename GV,
int k>
448using RaviartThomasBasis = DefaultGlobalBasis<RaviartThomasPreBasis<GV, k, FlatMultiIndex<std::size_t>> >;
Describe position of one degree of freedom.
Definition: localkey.hh:21
unsigned int index() const
Return offset within subentity.
Definition: localkey.hh:66
unsigned int codim() const
Return codim of associated entity.
Definition: localkey.hh:60
unsigned int subEntity() const
Return number of associated subentity.
Definition: localkey.hh:54
Implementation class for a multiple codim and multiple geometry type mapper.
Definition: mcmgmapper.hh:127
Default exception for dummy implementations.
Definition: exceptions.hh:261
A Vector class with statically reserved memory.
Definition: reservedvector.hh:43
A set of traits classes to store static information about grid implementation.
A few common exception classes.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:130
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
auto raviartThomas()
Create a pre-basis factory that can create a Raviart-Thomas pre-basis.
Definition: raviartthomasbasis.hh:427
constexpr GeometryType cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:470
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition: type.hh:461
MCMGLayout mcmgElementLayout()
layout for elements (codim-0 entities)
Definition: mcmgmapper.hh:95
auto max(ADLTag< 0 >, const V &v1, const V &v2)
implements binary Simd::max()
Definition: defaults.hh:79
Mapper for multiple codim and multiple geometry types.
Dune namespace.
Definition: alignedallocator.hh:11
constexpr Mantissa power(Mantissa m, Exponent p)
Power method for integer exponents.
Definition: math.hh:73
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:196