3#ifndef DUNE_FUNCTIONS_FUNCTIONSPACEBASES_BREZZIDOUGLASMARINIBASIS_HH
4#define DUNE_FUNCTIONS_FUNCTIONSPACEBASES_BREZZIDOUGLASMARINIBASIS_HH
8#include <dune/geometry/referenceelements.hh>
10#include <dune/localfunctions/common/virtualinterface.hh>
11#include <dune/localfunctions/common/virtualwrappers.hh>
13#include <dune/localfunctions/brezzidouglasmarini/brezzidouglasmarini1cube2d.hh>
14#include <dune/localfunctions/brezzidouglasmarini/brezzidouglasmarini1cube3d.hh>
15#include <dune/localfunctions/brezzidouglasmarini/brezzidouglasmarini1simplex2d.hh>
16#include <dune/localfunctions/brezzidouglasmarini/brezzidouglasmarini2cube2d.hh>
17#include <dune/localfunctions/brezzidouglasmarini/brezzidouglasmarini2simplex2d.hh>
19#include <dune/functions/functionspacebases/globalvaluedlocalfiniteelement.hh>
20#include <dune/functions/functionspacebases/nodes.hh>
21#include <dune/functions/functionspacebases/defaultglobalbasis.hh>
28 template<
int dim,
typename D,
typename R, std::
size_t k>
29 struct BDMSimplexLocalInfo
31 static_assert((AlwaysFalse<D>::value),
"The requested type of BDM element is not implemented, sorry!");
34 template<
typename D,
typename R>
35 struct BDMSimplexLocalInfo<2,D,R,1>
37 using FiniteElement = BDM1Simplex2DLocalFiniteElement<D,R>;
38 static const std::size_t Variants = 8;
41 template<
typename D,
typename R>
42 struct BDMSimplexLocalInfo<2,D,R,2>
44 using FiniteElement = BDM2Simplex2DLocalFiniteElement<D,R>;
45 static const std::size_t Variants = 8;
48 template<
int dim,
typename D,
typename R, std::
size_t k>
49 struct BDMCubeLocalInfo
51 static_assert((AlwaysFalse<D>::value),
"The requested type of BDM element is not implemented, sorry!");
54 template<
typename D,
typename R>
55 struct BDMCubeLocalInfo<2,D,R,1>
57 using FiniteElement = BDM1Cube2DLocalFiniteElement<D,R>;
58 static const std::size_t Variants = 16;
61 template<
typename D,
typename R>
62 struct BDMCubeLocalInfo<2,D,R,2>
64 using FiniteElement = BDM2Cube2DLocalFiniteElement<D,R>;
65 static const std::size_t Variants = 16;
68 template<
typename D,
typename R>
69 struct BDMCubeLocalInfo<3,D,R,1>
71 using FiniteElement = BDM1Cube3DLocalFiniteElement<D,R>;
72 static const std::size_t Variants = 64;
75 template<
typename GV,
int dim,
typename R, std::
size_t k>
76 class BDMLocalFiniteElementMap
78 using D =
typename GV::ctype;
79 using CubeFiniteElement =
typename BDMCubeLocalInfo<dim, D, R, k>::FiniteElement;
80 using SimplexFiniteElement =
typename BDMSimplexLocalInfo<dim, D, R, k>::FiniteElement;
84 using T = LocalBasisTraits<D, dim, FieldVector<D,dim>, R, dim, FieldVector<R,dim>, FieldMatrix<D,dim,dim> >;
85 using FiniteElement = LocalFiniteElementVirtualInterface<T>;
87 BDMLocalFiniteElementMap(
const GV& gv)
88 : is_(&(gv.indexSet())), orient_(gv.size(0))
90 cubeVariant_.resize(BDMCubeLocalInfo<dim, D, R, k>::Variants);
91 simplexVariant_.resize(BDMSimplexLocalInfo<dim, D, R, k>::Variants);
94 for (
size_t i = 0; i < cubeVariant_.size(); i++)
95 cubeVariant_[i] = std::make_unique<LocalFiniteElementVirtualImp<CubeFiniteElement> >(CubeFiniteElement(i));
97 for (
size_t i = 0; i < simplexVariant_.size(); i++)
98 simplexVariant_[i] = std::make_unique<LocalFiniteElementVirtualImp<SimplexFiniteElement> >(SimplexFiniteElement(i));
102 for(
const auto& cell : elements(gv))
104 unsigned int myId = is_->index(cell);
107 for (
const auto& intersection : intersections(gv,cell))
109 if (intersection.neighbor() && (is_->index(intersection.outside()) > myId))
110 orient_[myId] |= (1 << intersection.indexInInside());
116 template<
class EntityType>
117 const FiniteElement& find(
const EntityType& e)
const
119 if (e.type().isCube())
120 return *cubeVariant_[orient_[is_->index(e)]];
122 return *simplexVariant_[orient_[is_->index(e)]];
126 std::vector<std::unique_ptr<LocalFiniteElementVirtualImp<CubeFiniteElement> > > cubeVariant_;
127 std::vector<std::unique_ptr<LocalFiniteElementVirtualImp<SimplexFiniteElement> > > simplexVariant_;
128 const typename GV::IndexSet* is_;
129 std::vector<unsigned char> orient_;
147template<
typename GV,
int k>
148class BrezziDouglasMariniNode;
150template<
typename GV,
int k>
151class BrezziDouglasMariniPreBasis
153 static const int dim = GV::dimension;
154 using FiniteElementMap =
typename Impl::BDMLocalFiniteElementMap<GV, dim, double, k>;
160 using size_type = std::size_t;
162 using Node = BrezziDouglasMariniNode<GV, k>;
164 static constexpr size_type maxMultiIndexSize = 1;
165 static constexpr size_type minMultiIndexSize = 1;
166 static constexpr size_type multiIndexBufferSize = 1;
169 BrezziDouglasMariniPreBasis(
const GridView& gv) :
171 finiteElementMap_(gv)
175 if (gv.indexSet().types(0).size() > 1)
179 void initializeIndices()
182 codimOffset_[1] = codimOffset_[0] + dofsPerCodim_[0] * gridView_.size(0);
188 const GridView& gridView()
const
194 void update (
const GridView& gv)
202 Node makeNode()
const
204 return Node{&finiteElementMap_};
207 size_type size()
const
209 return dofsPerCodim_[0] * gridView_.size(0) + dofsPerCodim_[1] * gridView_.size(1);
213 template<
class SizePrefix>
214 size_type size(
const SizePrefix prefix)
const
216 assert(prefix.size() == 0 || prefix.size() == 1);
217 return (prefix.size() == 0) ? size() : 0;
221 size_type dimension()
const
226 size_type maxNodeSize()
const
230 GeometryType elementType = *(gridView_.indexSet().types(0).begin());
232 return dofsPerCodim_[0] + dofsPerCodim_[1] * numFaces;
240 template<
typename It>
241 It indices(
const Node& node, It it)
const
243 const auto& gridIndexSet = gridView().indexSet();
244 const auto& element = node.element();
247 if (not(element.type().isCube()) and not(element.type().isSimplex()))
250 for(std::size_t i=0, end=node.size(); i<end; ++i, ++it)
252 Dune::LocalKey localKey = node.finiteElement().localCoefficients().localKey(i);
256 size_t codim = localKey.
codim();
258 *it = { codimOffset_[codim] +
259 dofsPerCodim_[codim] * gridIndexSet.subIndex(element, subentity, codim) + localKey.
index() };
267 std::array<size_t,dim+1> codimOffset_;
268 FiniteElementMap finiteElementMap_;
270 std::array<int,2> dofsPerCodim_ {{dim*(k-1)*3, dim+(k-1)}};
275template<
typename GV,
int k>
276class BrezziDouglasMariniNode :
279 static const int dim = GV::dimension;
283 using size_type = std::size_t;
284 using Element =
typename GV::template Codim<0>::Entity;
285 using FiniteElementMap =
typename Impl::BDMLocalFiniteElementMap<GV, dim, double, k>;
286 using FiniteElement = Impl::GlobalValuedLocalFiniteElement<Impl::ContravariantPiolaTransformator,
287 typename FiniteElementMap::FiniteElement,
290 BrezziDouglasMariniNode(
const FiniteElementMap* finiteElementMap) :
292 finiteElementMap_(finiteElementMap)
296 const Element& element()
const
305 const FiniteElement& finiteElement()
const
307 return finiteElement_;
311 void bind(
const Element& e)
314 finiteElement_.bind((finiteElementMap_->find(*element_)), e);
315 this->setSize(finiteElement_.size());
320 FiniteElement finiteElement_;
321 const Element* element_;
322 const FiniteElementMap* finiteElementMap_;
327namespace BasisFactory {
336template<std::
size_t k>
339 return [](
const auto& gridView) {
340 return BrezziDouglasMariniPreBasis<std::decay_t<
decltype(gridView)>, k>(gridView);
359template<
typename GV,
int k>
360using BrezziDouglasMariniBasis = DefaultGlobalBasis<BrezziDouglasMariniPreBasis<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
Default exception for dummy implementations.
Definition: exceptions.hh:263
A few common exception classes.
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
auto brezziDouglasMarini()
Create a pre-basis factory that can create a Brezzi-Douglas-Marini pre-basis.
Definition: brezzidouglasmarinibasis.hh:337
Dune namespace.
Definition: alignedallocator.hh:13
static const ReferenceElement & general(const GeometryType &type)
get general reference elements
Definition: referenceelements.hh:198