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>
32 template<
int dim,
typename D,
typename R, std::
size_t k>
33 struct RaviartThomasSimplexLocalInfo
36 using FiniteElement =
void*;
39 template<
typename D,
typename R>
40 struct RaviartThomasSimplexLocalInfo<2,D,R,0>
42 using FiniteElement = RT02DLocalFiniteElement<D,R>;
45 template<
typename D,
typename R>
46 struct RaviartThomasSimplexLocalInfo<2,D,R,1>
48 using FiniteElement = RT12DLocalFiniteElement<D,R>;
51 template<
typename D,
typename R>
52 struct RaviartThomasSimplexLocalInfo<3,D,R,0>
54 using FiniteElement = RT03DLocalFiniteElement<D,R>;
57 template<
int dim,
typename D,
typename R, std::
size_t k>
58 struct RaviartThomasCubeLocalInfo
61 using FiniteElement =
void*;
64 template<
typename D,
typename R>
65 struct RaviartThomasCubeLocalInfo<2,D,R,0>
67 using FiniteElement = RT0Cube2DLocalFiniteElement<D,R>;
70 template<
typename D,
typename R>
71 struct RaviartThomasCubeLocalInfo<2,D,R,1>
73 using FiniteElement = RT1Cube2DLocalFiniteElement<D,R>;
76 template<
typename D,
typename R>
77 struct RaviartThomasCubeLocalInfo<2,D,R,2>
79 using FiniteElement = RT2Cube2DLocalFiniteElement<D,R>;
82 template<
typename D,
typename R>
83 struct RaviartThomasCubeLocalInfo<3,D,R,0>
85 using FiniteElement = RT0Cube3DLocalFiniteElement<D,R>;
88 template<
typename D,
typename R>
89 struct RaviartThomasCubeLocalInfo<3,D,R,1>
91 using FiniteElement = RT1Cube3DLocalFiniteElement<D,R>;
94 template<
typename GV,
int dim,
typename R, std::
size_t k>
95 class RaviartThomasLocalFiniteElementMap
97 using D =
typename GV::ctype;
98 constexpr static bool hasFixedElementType = Capabilities::hasSingleGeometryType<typename GV::Grid>::v;
100 using CubeFiniteElement =
typename RaviartThomasCubeLocalInfo<dim, D, R, k>::FiniteElement;
101 using SimplexFiniteElement =
typename RaviartThomasSimplexLocalInfo<dim, D, R, k>::FiniteElement;
105 using T = LocalBasisTraits<D, dim, FieldVector<D,dim>, R, dim, FieldVector<R,dim>, FieldMatrix<D,dim,dim> >;
107 constexpr static unsigned int topologyId = Capabilities::hasSingleGeometryType<typename GV::Grid>::topologyId;
110 using FiniteElement = std::conditional_t<hasFixedElementType,
111 std::conditional_t<type.isCube(),CubeFiniteElement,SimplexFiniteElement>,
112 LocalFiniteElementVariant<CubeFiniteElement, SimplexFiniteElement> >;
116 static std::size_t numVariants(GeometryType type)
118 auto numFacets = referenceElement<D,dim>(type).size(1);
119 return power(2,numFacets);
122 RaviartThomasLocalFiniteElementMap(
const GV& gv)
126 if constexpr (hasFixedElementType)
128 variants_.resize(numVariants(type));
129 for (
size_t i = 0; i < numVariants(type); i++)
130 variants_[i] = FiniteElement(i);
137 variants_[i] = SimplexFiniteElement(i);
142 for(
const auto& cell : elements(gv))
144 unsigned int myId = elementMapper_.index(cell);
147 for (
const auto& intersection : intersections(gv,cell))
149 if (intersection.neighbor() && (elementMapper_.index(intersection.outside()) > myId))
150 orient_[myId] |= (1 << intersection.indexInInside());
154 if constexpr (!hasFixedElementType)
155 if (cell.type().isCube())
160 template<
class EntityType>
161 const FiniteElement& find(
const EntityType& e)
const
163 return variants_[orient_[elementMapper_.index(e)]];
167 std::vector<FiniteElement> variants_;
169 std::vector<unsigned char> orient_;
187template<
typename GV,
int k>
188class RaviartThomasNode;
190template<
typename GV,
int k>
191class RaviartThomasPreBasis
193 static const int dim = GV::dimension;
194 using FiniteElementMap =
typename Impl::RaviartThomasLocalFiniteElementMap<GV, dim, double, k>;
200 using size_type = std::size_t;
202 using Node = RaviartThomasNode<GV, k>;
204 static constexpr size_type maxMultiIndexSize = 1;
205 static constexpr size_type minMultiIndexSize = 1;
206 static constexpr size_type multiIndexBufferSize = 1;
209 RaviartThomasPreBasis(
const GridView& gv) :
211 finiteElementMap_(gv)
214 if (gv.indexSet().types(0).size() > 1 and k>0)
217 for(
auto type : gv.indexSet().types(0))
218 if (!type.isSimplex() && !type.isCube())
222 const static int dofsPerElement = type.isCube() ? ((dim == 2) ? k*(k+1)*dim : k*(k+1)*(k+1)*dim) : k*dim;
223 const static int dofsPerFace = type.isCube() ? (dim-2)*2*k+k+1 : (dim-1)*k+1 ;
225 dofsPerCodim_ = {{dofsPerElement, dofsPerFace}};
228 void initializeIndices()
231 codimOffset_[1] = codimOffset_[0] + dofsPerCodim_[0] * gridView_.size(0);
236 const GridView& gridView()
const
242 void update (
const GridView& gv)
250 Node makeNode()
const
252 return Node{&finiteElementMap_};
255 size_type size()
const
257 return dofsPerCodim_[0] * gridView_.size(0) + dofsPerCodim_[1] * gridView_.size(1);
261 template<
class SizePrefix>
262 size_type size(
const SizePrefix& prefix)
const
264 assert(prefix.size() == 0 || prefix.size() == 1);
265 return (prefix.size() == 0) ? size() : 0;
269 size_type dimension()
const
274 size_type maxNodeSize()
const
276 size_type result = 0;
277 for (
auto&& type : gridView_.indexSet().types(0))
280 const static int dofsPerElement = type.isCube() ? ((dim == 2) ? k*(k+1)*dim : k*(k+1)*(k+1)*dim) : k*dim;
281 const static int dofsPerFace = type.isCube() ? (dim-2)*2*k+k+1 : (dim-1)*k+1 ;
282 result = std::max(result, dofsPerElement + dofsPerFace * numFaces);
293 template<
typename It>
294 It indices(
const Node& node, It it)
const
296 const auto& gridIndexSet = gridView().indexSet();
297 const auto& element = node.element();
300 if (not(element.type().isCube()) and not(element.type().isSimplex()))
303 for(std::size_t i=0, end=node.size(); i<end; ++i, ++it)
305 Dune::LocalKey localKey = node.finiteElement().localCoefficients().localKey(i);
309 size_t codim = localKey.
codim();
311 if (not(codim==0 or codim==1))
314 *it = { codimOffset_[codim] +
315 dofsPerCodim_[codim] * gridIndexSet.subIndex(element, subentity, codim) + localKey.
index() };
323 std::array<size_t,dim+1> codimOffset_;
324 FiniteElementMap finiteElementMap_;
326 std::array<int,dim+1> dofsPerCodim_;
331template<
typename GV,
int k>
332class RaviartThomasNode :
335 static const int dim = GV::dimension;
339 using size_type = std::size_t;
340 using Element =
typename GV::template Codim<0>::Entity;
341 using FiniteElementMap =
typename Impl::RaviartThomasLocalFiniteElementMap<GV, dim, double, k>;
342 using FiniteElement = Impl::GlobalValuedLocalFiniteElement<Impl::ContravariantPiolaTransformator,
343 typename FiniteElementMap::FiniteElement,
346 RaviartThomasNode(
const FiniteElementMap* finiteElementMap) :
348 finiteElementMap_(finiteElementMap)
352 const Element& element()
const
361 const FiniteElement& finiteElement()
const
363 return finiteElement_;
367 void bind(
const Element& e)
370 finiteElement_.bind((finiteElementMap_->find(*element_)), e);
371 this->setSize(finiteElement_.size());
376 FiniteElement finiteElement_;
377 const Element* element_;
378 const FiniteElementMap* finiteElementMap_;
381namespace BasisFactory {
390template<std::
size_t k>
393 return [](
const auto& gridView) {
394 return RaviartThomasPreBasis<std::decay_t<
decltype(gridView)>, k>(gridView);
413template<
typename GV,
int k>
414using RaviartThomasBasis = DefaultGlobalBasis<RaviartThomasPreBasis<GV, k> >;
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
Default exception for dummy implementations.
Definition: exceptions.hh:263
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 raviartThomas()
Create a pre-basis factory that can create a Raviart-Thomas pre-basis.
Definition: raviartthomasbasis.hh:391
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 mcmgElementLayout()
layout for elements (codim-0 entities)
Definition: mcmgmapper.hh:97
Mapper for multiple codim and multiple geometry types.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr Base power(Base m, Exponent p)
Power method for integer exponents.
Definition: math.hh:75
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:198