5#ifndef DUNE_LOCALFUNCTIONS_NEDELEC_NEDELEC1STKINDCUBE_HH
6#define DUNE_LOCALFUNCTIONS_NEDELEC_NEDELEC1STKINDCUBE_HH
14#include <dune/geometry/referenceelements.hh>
17#include <dune/localfunctions/common/localbasis.hh>
18#include <dune/localfunctions/common/localfiniteelementtraits.hh>
19#include <dune/localfunctions/common/localinterpolation.hh>
20#include <dune/localfunctions/common/localkey.hh>
36 template<
class D,
class R,
int dim,
int k>
37 class Nedelec1stKindCubeLocalBasis
40 constexpr static std::size_t numberOfEdges =
power(2,dim-1)*dim;
43 using Traits = LocalBasisTraits<D,dim,FieldVector<D,dim>,
44 R,dim,FieldVector<R,dim>,
45 FieldMatrix<R,dim,dim> >;
53 Nedelec1stKindCubeLocalBasis()
55 std::fill(edgeOrientation_.begin(), edgeOrientation_.end(), 1.0);
60 Nedelec1stKindCubeLocalBasis(std::bitset<numberOfEdges> edgeOrientation)
61 : Nedelec1stKindCubeLocalBasis()
63 for (std::size_t i=0; i<edgeOrientation_.size(); i++)
64 edgeOrientation_[i] *= edgeOrientation[i] ? -1.0 : 1.0;
68 static constexpr unsigned int size()
70 static_assert(dim==2 || dim==3,
"Nedelec shape functions are implemented only for 2d and 3d cubes.");
74 return 3*k * (k+1) * (k+1);
83 std::vector<typename Traits::RangeType>& out)
const
85 static_assert(k==1,
"Evaluating Nédélec shape functions is implemented only for first order.");
102 out[0] = { 0, D(1) - in[0]};
103 out[1] = { 0, in[0]};
104 out[2] = { D(1) - in[1], 0};
105 out[3] = { in[1], 0};
108 if constexpr (dim==3)
127 for (std::size_t i=0; i<out.size(); i++)
130 out[0][2] = { 1 - in[0] - in[1] + in[0]*in[1]};
131 out[1][2] = { in[0] - in[0]*in[1]};
132 out[2][2] = { in[1] - in[0]*in[1]};
133 out[3][2] = { in[0]*in[1]};
135 out[4][1] = { 1 - in[0] - in[2] + in[0]*in[2]};
136 out[5][1] = { in[0] - in[0]*in[2]};
137 out[8][1] = { in[2] - in[0]*in[2]};
138 out[9][1] = { in[0]*in[2]};
140 out[6][0] = { 1 - in[1] - in[2] + in[1]*in[2]};
141 out[7][0] = { in[1] - in[1]*in[2]};
142 out[10][0] = { in[2] - in[1]*in[2]};
143 out[11][0] = { in[1]*in[2]};
146 for (std::size_t i=0; i<out.size(); i++)
147 out[i] *= edgeOrientation_[i];
156 std::vector<typename Traits::JacobianType>& out)
const
161 for (std::size_t i=0; i<out.size(); i++)
162 for (std::size_t j=0; j<dim; j++)
165 out[0][1] = { -1, 0};
168 out[2][0] = { 0, -1};
173 for (std::size_t i=0; i<out.size(); i++)
174 for(std::size_t j=0;j<dim; j++)
178 out[0][2] = {-1 +in[1], -1 + in[0], 0};
179 out[1][2] = { 1 -in[1], - in[0], 0};
180 out[2][2] = { -in[1], 1 - in[0], 0};
181 out[3][2] = { in[1], in[0], 0};
183 out[4][1] = {-1 +in[2], 0, -1 + in[0]};
184 out[5][1] = { 1 -in[2], 0, - in[0]};
185 out[8][1] = { -in[2], 0, 1 - in[0]};
186 out[9][1] = { in[2], 0, in[0]};
188 out[6][0] = { 0, -1 + in[2], -1 + in[1]};
189 out[7][0] = { 0, 1 - in[2], - in[1]};
190 out[10][0] = { 0, - in[2], 1 - in[1]};
191 out[11][0] = { 0, in[2], in[1]};
195 for (std::size_t i=0; i<out.size(); i++)
196 out[i] *= edgeOrientation_[i];
206 void partial(
const std::array<unsigned int, dim>& order,
208 std::vector<typename Traits::RangeType>& out)
const
211 if (totalOrder == 0) {
212 evaluateFunction(in, out);
213 }
else if (totalOrder == 1) {
214 auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
240 out[0] = { 0, 0, -1 +in[1]};
241 out[1] = { 0, 0, 1 -in[1]};
242 out[2] = { 0, 0, -in[1]};
243 out[3] = { 0, 0, in[1]};
245 out[4] = { 0, -1 +in[2], 0};
246 out[5] = { 0, 1 -in[2], 0};
247 out[8] = { 0, -in[2], 0};
248 out[9] = { 0, in[2], 0};
257 out[0] = { 0, 0, -1 + in[0]};
258 out[1] = { 0, 0, - in[0]};
259 out[2] = { 0, 0, 1 - in[0]};
260 out[3] = { 0, 0, in[0]};
267 out[6] = { -1 + in[2], 0, 0};
268 out[7] = { 1 - in[2], 0, 0};
269 out[10] = { - in[2], 0, 0};
270 out[11] = { in[2], 0, 0};
279 out[4] = { 0, -1 + in[0], 0};
280 out[5] = { 0, - in[0], 0};
281 out[8] = { 0, 1 - in[0], 0};
282 out[9] = { 0, in[0], 0};
284 out[6] = { -1 + in[1], 0, 0};
285 out[7] = { - in[1], 0, 0};
286 out[10] = { 1 - in[1], 0, 0};
287 out[11] = { in[1], 0, 0};
292 for (std::size_t i=0; i<out.size(); i++)
293 out[i] *= edgeOrientation_[i];
295 }
else if (totalOrder == 2) {
299 for (std::size_t i = 0; i < size(); ++i)
300 for (std::size_t j = 0; j < dim; ++j)
305 for(
size_t i=0; i<out.size(); i++)
309 if( order[0] == 1 and order[1]==1)
312 out[1] = { 0, 0, -1};
313 out[2] = { 0, 0, -1};
318 if( order[0] == 1 and order[2]==1)
321 out[5] = { 0, -1, 0};
322 out[8] = { 0, -1, 0};
327 if( order[1] == 1 and order[2]==1)
330 out[7] = { -1, 0, 0};
331 out[10] = { -1, 0, 0};
332 out[11] = { 1, 0, 0};
335 for (std::size_t i=0; i<out.size(); i++)
336 out[i] *= edgeOrientation_[i];
342 for (std::size_t i = 0; i < size(); ++i)
343 for (std::size_t j = 0; j < dim; ++j)
350 unsigned int order()
const
361 std::array<R,numberOfEdges> edgeOrientation_;
369 template <
int dim,
int k>
370 class Nedelec1stKindCubeLocalCoefficients
374 Nedelec1stKindCubeLocalCoefficients ()
377 static_assert(k==1,
"Only first-order Nédélec local coefficients are implemented.");
380 for (std::size_t i=0; i<size(); i++)
381 localKey_[i] = LocalKey(i,dim-1,0);
385 std::size_t size()
const
387 static_assert(dim==2 || dim==3,
"Nédélec shape functions are implemented only for 2d and 3d cubes.");
388 return (dim==2) ? 2*k * (k+1)
389 : 3*k * (k+1) * (k+1);
394 const LocalKey& localKey (std::size_t i)
const
400 std::vector<LocalKey> localKey_;
408 class Nedelec1stKindCubeLocalInterpolation
410 static constexpr auto dim = LB::Traits::dimDomain;
411 static constexpr auto size = LB::size();
414 constexpr static std::size_t numberOfEdges =
power(2,dim-1)*dim;
419 Nedelec1stKindCubeLocalInterpolation (std::bitset<numberOfEdges> s = 0)
423 for (std::size_t i=0; i<numberOfEdges; i++)
424 m_[i] = refElement.position(i,dim-1);
426 for (std::size_t i=0; i<numberOfEdges; i++)
428 auto vertexIterator = refElement.subEntities(i,dim-1,dim).begin();
429 auto v0 = *vertexIterator;
430 auto v1 = *(++vertexIterator);
436 edge_[i] = refElement.position(v1,dim) - refElement.position(v0,dim);
437 edge_[i] *= (s[i]) ? -1.0 : 1.0;
446 template<
typename F,
typename C>
447 void interpolate (
const F& ff, std::vector<C>& out)
const
450 auto&& f = Impl::makeFunctionWithCallOperator<typename LB::Traits::DomainType>(ff);
452 for (std::size_t i=0; i<size; i++)
456 for (
int j=0; j<dim; j++)
457 out[i] += y[j]*edge_[i][j];
463 std::array<typename LB::Traits::DomainType, numberOfEdges> m_;
465 std::array<typename LB::Traits::DomainType, numberOfEdges> edge_;
494 template<
class D,
class R,
int dim,
int k>
499 Impl::Nedelec1stKindCubeLocalCoefficients<dim,k>,
500 Impl::Nedelec1stKindCubeLocalInterpolation<Impl::Nedelec1stKindCubeLocalBasis<D,R,dim,k> > >;
502 static_assert(dim==2 || dim==3,
"Nedelec elements are only implemented for 2d and 3d elements.");
503 static_assert(k==1,
"Nedelec elements of the first kind are currently only implemented for order k==1.");
526 return coefficients_;
531 return interpolation_;
534 static constexpr unsigned int size ()
536 return Traits::LocalBasisType::size();
Nédélec elements of the first kind for cube elements.
Definition: nedelec1stkindcube.hh:496
Nedelec1stKindCubeLocalFiniteElement()=default
Default constructor.
Nedelec1stKindCubeLocalFiniteElement(std::bitset< power(2, dim-1) *dim > s)
Constructor with explicitly given edge orientations.
Definition: nedelec1stkindcube.hh:514
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 cube(unsigned int dim)
Returns a GeometryType representing a hypercube of dimension dim.
Definition: type.hh:473
constexpr T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:291
Some useful basic math stuff.
Dune namespace.
Definition: alignedallocator.hh:13
constexpr Base power(Base m, Exponent p)
Power method for integer exponents.
Definition: math.hh:75
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.