5#ifndef DUNE_LOCALFUNCTIONS_NEDELEC_NEDELEC1STKINDSIMPLEX_HH
6#define DUNE_LOCALFUNCTIONS_NEDELEC_NEDELEC1STKINDSIMPLEX_HH
13#include <dune/geometry/referenceelements.hh>
16#include <dune/localfunctions/common/localbasis.hh>
17#include <dune/localfunctions/common/localfiniteelementtraits.hh>
18#include <dune/localfunctions/common/localinterpolation.hh>
19#include <dune/localfunctions/common/localkey.hh>
35 template<
class D,
class R,
int dim,
int k>
36 class Nedelec1stKindSimplexLocalBasis
39 constexpr static std::size_t numberOfEdges = dim*(dim+1)/2;
42 using Traits = LocalBasisTraits<D,dim,FieldVector<D,dim>,
43 R,dim,FieldVector<R,dim>,
44 FieldMatrix<R,dim,dim> >;
52 Nedelec1stKindSimplexLocalBasis()
54 std::fill(edgeOrientation_.begin(), edgeOrientation_.end(), 1.0);
59 Nedelec1stKindSimplexLocalBasis(std::bitset<numberOfEdges> edgeOrientation)
60 : Nedelec1stKindSimplexLocalBasis()
62 for (std::size_t i=0; i<edgeOrientation_.size(); i++)
63 edgeOrientation_[i] *= edgeOrientation[i] ? -1.0 : 1.0;
67 static constexpr unsigned int size()
69 static_assert(dim==2 || dim==3,
"Nedelec shape functions are implemented only for 2d and 3d simplices.");
73 return k * (k+2) * (k+3) / 2;
82 std::vector<typename Traits::RangeType>& out)
const
84 static_assert(k==1,
"Evaluating Nédélec shape functions is implemented only for first order.");
92 out[0] = {D(1) - in[1], in[0]};
93 out[1] = {in[1], -in[0]+D(1)};
94 out[2] = {-in[1], in[0]};
116 out[0] = { 1 - in[1] - in[2], in[0] , in[0] };
117 out[1] = { in[1] , 1 - in[0] - in[2], in[1]};
118 out[2] = { - in[1] , in[0] , 0 };
119 out[3] = { in[2], in[2], 1 - in[0] - in[1]};
120 out[4] = { -in[2], 0 , in[0] };
121 out[5] = { 0 , -in[2], in[1]};
124 for (std::size_t i=0; i<out.size(); i++)
125 out[i] *= edgeOrientation_[i];
134 std::vector<typename Traits::JacobianType>& out)
const
139 out[0][0] = { 0, -1};
145 out[2][0] = { 0, -1};
150 out[0][0] = { 0,-1,-1};
151 out[0][1] = { 1, 0, 0};
152 out[0][2] = { 1, 0, 0};
154 out[1][0] = { 0, 1, 0};
155 out[1][1] = {-1, 0, -1};
156 out[1][2] = { 0, 1, 0};
158 out[2][0] = { 0, -1, 0};
159 out[2][1] = { 1, 0, 0};
160 out[2][2] = { 0, 0, 0};
162 out[3][0] = { 0, 0, 1};
163 out[3][1] = { 0, 0, 1};
164 out[3][2] = {-1, -1, 0};
166 out[4][0] = { 0, 0, -1};
167 out[4][1] = { 0, 0, 0};
168 out[4][2] = { 1, 0, 0};
170 out[5][0] = { 0, 0, 0};
171 out[5][1] = { 0, 0, -1};
172 out[5][2] = { 0, 1, 0};
175 for (std::size_t i=0; i<out.size(); i++)
176 out[i] *= edgeOrientation_[i];
186 void partial(
const std::array<unsigned int, dim>& order,
188 std::vector<typename Traits::RangeType>& out)
const
191 if (totalOrder == 0) {
192 evaluateFunction(in, out);
193 }
else if (totalOrder == 1) {
194 auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
246 for (std::size_t i=0; i<out.size(); i++)
247 out[i] *= edgeOrientation_[i];
251 for (std::size_t i = 0; i < size(); ++i)
252 for (std::size_t j = 0; j < dim; ++j)
259 unsigned int order()
const
267 std::array<R,numberOfEdges> edgeOrientation_;
275 template <
int dim,
int k>
276 class Nedelec1stKindSimplexLocalCoefficients
280 Nedelec1stKindSimplexLocalCoefficients ()
283 static_assert(k==1,
"Only first-order Nédélec local coefficients are implemented.");
286 for (std::size_t i=0; i<size(); i++)
287 localKey_[i] = LocalKey(i,dim-1,0);
291 std::size_t size()
const
293 static_assert(dim==2 || dim==3,
"Nédélec shape functions are implemented only for 2d and 3d simplices.");
294 return (dim==2) ? k * (k+2)
295 : k * (k+2) * (k+3) / 2;
300 const LocalKey& localKey (std::size_t i)
const
306 std::vector<LocalKey> localKey_;
314 class Nedelec1stKindSimplexLocalInterpolation
316 static constexpr auto dim = LB::Traits::dimDomain;
317 static constexpr auto size = LB::size();
320 constexpr static std::size_t numberOfEdges = dim*(dim+1)/2;
325 Nedelec1stKindSimplexLocalInterpolation (std::bitset<numberOfEdges> s = 0)
329 for (std::size_t i=0; i<numberOfEdges; i++)
330 m_[i] = refElement.position(i,dim-1);
332 for (std::size_t i=0; i<numberOfEdges; i++)
334 auto vertexIterator = refElement.subEntities(i,dim-1,dim).begin();
335 auto v0 = *vertexIterator;
336 auto v1 = *(++vertexIterator);
341 edge_[i] = refElement.position(v1,dim) - refElement.position(v0,dim);
342 edge_[i] *= (s[i]) ? -1.0 : 1.0;
351 template<
typename F,
typename C>
352 void interpolate (
const F& ff, std::vector<C>& out)
const
355 auto&& f = Impl::makeFunctionWithCallOperator<typename LB::Traits::DomainType>(ff);
357 for (std::size_t i=0; i<size; i++)
361 for (
int j=0; j<dim; j++)
362 out[i] += y[j]*edge_[i][j];
368 std::array<typename LB::Traits::DomainType, numberOfEdges> m_;
370 std::array<typename LB::Traits::DomainType, numberOfEdges> edge_;
401 template<
class D,
class R,
int dim,
int k>
406 Impl::Nedelec1stKindSimplexLocalCoefficients<dim,k>,
407 Impl::Nedelec1stKindSimplexLocalInterpolation<Impl::Nedelec1stKindSimplexLocalBasis<D,R,dim,k> > >;
409 static_assert(dim==2 || dim==3,
"Nedelec elements are only implemented for 2d and 3d elements.");
410 static_assert(k==1,
"Nedelec elements of the first kind are currently only implemented for order k==1.");
433 return coefficients_;
438 return interpolation_;
441 static constexpr unsigned int size ()
443 return Traits::LocalBasisType::size();
Nédélec elements of the first kind for simplex elements.
Definition: nedelec1stkindsimplex.hh:403
Nedelec1stKindSimplexLocalFiniteElement()=default
Default constructor.
Nedelec1stKindSimplexLocalFiniteElement(std::bitset< dim *(dim+1)/2 > s)
Constructor with explicitly given edge orientations.
Definition: nedelec1stkindsimplex.hh:421
GeometryType
Type representing VTK's entity geometry types.
Definition: common.hh:132
Implements a matrix constructed from a given type representing a field and compile-time given number ...
Implements a vector constructed from a given type representing a field and a compile-time given size.
constexpr GeometryType simplex(unsigned int dim)
Returns a GeometryType representing a simplex of dimension dim.
Definition: type.hh:464
constexpr T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:291
Dune namespace.
Definition: alignedallocator.hh:13
D DomainType
domain type
Definition: localbasis.hh:42
traits helper struct
Definition: localfiniteelementtraits.hh:13
LB LocalBasisType
Definition: localfiniteelementtraits.hh:16
LC LocalCoefficientsType
Definition: localfiniteelementtraits.hh:20
LI LocalInterpolationType
Definition: localfiniteelementtraits.hh:24
A unique label for each type of element that can occur in a grid.