3#ifndef DUNE_LOCALFUNCTIONS_LAGRANGE_LAGRANGECUBE_HH
4#define DUNE_LOCALFUNCTIONS_LAGRANGE_LAGRANGECUBE_HH
20namespace Dune {
namespace Impl
23 template<
class LocalBasis>
24 class LagrangeCubeLocalInterpolation;
36 template<
class D,
class R,
unsigned int dim,
unsigned int k>
37 class LagrangeCubeLocalBasis
39 friend class LagrangeCubeLocalInterpolation<LagrangeCubeLocalBasis<D,R,
dim,k> >;
42 static R p(
unsigned int i, D x)
45 for (
unsigned int j=0; j<=k; j++)
46 if (j!=i) result *= (k*x-j)/((
int)i-(int)j);
51 static R dp(
unsigned int i, D x)
55 for (
unsigned int j=0; j<=k; j++)
59 R prod( (k*1.0)/((
int)i-(
int)j) );
60 for (
unsigned int l=0; l<=k; l++)
62 prod *= (k*x-l)/((
int)i-(int)l);
71 static R ddp(
unsigned int j, D x)
75 for (
unsigned int i=0; i<=k; i++)
82 for (
unsigned int m=0; m<=k; m++)
87 R prod( (k*1.0)/((
int)j-(
int)m) );
88 for (
unsigned int l=0; l<=k; l++)
89 if (l!=i && l!=j && l!=m)
90 prod *= (k*x-l)/((
int)j-(int)l);
94 result += sum * ( (k*1.0)/((
int)j-(int)i) );
104 for (
unsigned int j=0; j<
dim; j++)
106 alpha[j] = i % (k+1);
113 using Traits = LocalBasisTraits<D,dim,FieldVector<D,dim>,R,1,FieldVector<R,1>,FieldMatrix<R,1,dim> >;
117 static constexpr unsigned int size ()
137 for (
size_t i=0; i<
size(); i++)
141 for (
unsigned int j=0; j<
dim; j++)
143 out[i] *= (i & (1<<j)) ? x[j] : 1-x[j];
149 for (
size_t i=0; i<
size(); i++)
158 for (
unsigned int j=0; j<
dim; j++)
159 out[i] *= p(alpha[j],x[j]);
184 for (
size_t i=0; i<
size(); i++)
187 for (
unsigned int j=0; j<
dim; j++)
191 out[i][0][j] = (i & (1<<j)) ? 1 : -1;
193 for (
unsigned int l=0; l<
dim; l++)
197 out[i][0][j] *= (i & (1<<l)) ? x[l] : 1-x[l];
207 for (
size_t i=0; i<
size(); i++)
213 for (
unsigned int j=0; j<
dim; j++)
217 out[i][0][j] = dp(alpha[j],x[j]);
220 for (
unsigned int l=0; l<
dim; l++)
222 out[i][0][j] *= p(alpha[l],x[l]);
243 out[0] = (totalOrder==0);
251 evaluateFunction(in, out);
253 else if (totalOrder == 1)
258 if (direction >=
dim)
259 DUNE_THROW(RangeError,
"Direction of partial derivative not found!");
266 out[i] = (i & (1<<direction)) ? 1 : -1;
268 for (
unsigned int j = 0; j <
dim; ++j)
272 out[i] *= (i & (1<<j)) ? in[j] : 1-in[j];
276 else if (totalOrder == 2)
279 for (
size_t i=0; i<
size(); i++)
293 out[i][0] *= p(alpha[l],in[l]);
297 out[i][0] *= dp(alpha[l],in[l]);
303 DUNE_THROW(NotImplemented,
"Desired derivative order is not implemented");
309 DUNE_THROW(NotImplemented,
"Partial derivative of order " << totalOrder <<
" is not implemented!");
317 for (
size_t i=0; i<
size(); i++)
331 out[i][0] *= p(alpha[l],in[l]);
334 out[i][0] *= dp(alpha[l],in[l]);
337 out[i][0] *= ddp(alpha[l],in[l]);
340 DUNE_THROW(NotImplemented,
"Desired derivative order is not implemented");
347 static constexpr unsigned int order ()
358 template<
unsigned int dim,
unsigned int k>
359 class LagrangeCubeLocalCoefficients
365 for (
unsigned int j=0; j<
dim; j++)
367 alpha[j] = i % (k+1);
378 unsigned lastIndex=0;
385 subEntity[lastIndex++] = 0;
386 for (
unsigned i = 0; i < k - 1; ++i)
387 subEntity[lastIndex++] = 0;
389 subEntity[lastIndex++] = 1;
398 unsigned lastIndex=0;
412 subEntity[lastIndex++] = 0;
413 for (
unsigned i = 0; i < k - 1; ++i)
414 subEntity[lastIndex++] = 2;
416 subEntity[lastIndex++] = 1;
419 for (
unsigned e = 0; e < k - 1; ++e) {
420 subEntity[lastIndex++] = 0;
421 for (
unsigned i = 0; i < k - 1; ++i)
422 subEntity[lastIndex++] = 0;
423 subEntity[lastIndex++] = 1;
427 subEntity[lastIndex++] = 2;
428 for (
unsigned i = 0; i < k - 1; ++i)
429 subEntity[lastIndex++] = 3;
431 subEntity[lastIndex++] = 3;
440 unsigned lastIndex=0;
442 const unsigned numIndices =
power(k+1,
dim);
443 const unsigned numFaceIndices =
power(k+1,
dim-1);
445 const unsigned numInnerEdgeDofs = k-1;
466 subEntity[lastIndex++] = 0;
467 for (
unsigned i = 0; i < numInnerEdgeDofs; ++i)
468 subEntity[lastIndex++] = 6;
470 subEntity[lastIndex++] = 1;
473 for (
unsigned e = 0; e < numInnerEdgeDofs; ++e) {
474 subEntity[lastIndex++] = 4;
475 for (
unsigned i = 0; i < numInnerEdgeDofs; ++i)
476 subEntity[lastIndex++] = 4;
477 subEntity[lastIndex++] = 5;
481 subEntity[lastIndex++] = 2;
482 for (
unsigned i = 0; i < k - 1; ++i)
483 subEntity[lastIndex++] = 7;
484 subEntity[lastIndex++] = 3;
486 assert(numFaceIndices==lastIndex);
490 for(
unsigned f = 0; f < numInnerEdgeDofs; ++f) {
493 subEntity[lastIndex++] = 0;
494 for (
unsigned i = 0; i < numInnerEdgeDofs; ++i)
495 subEntity[lastIndex++] = 2;
496 subEntity[lastIndex++] = 1;
499 for (
unsigned e = 0; e < numInnerEdgeDofs; ++e) {
500 subEntity[lastIndex++] = 0;
501 for (
unsigned i = 0; i < numInnerEdgeDofs; ++i)
502 subEntity[lastIndex++] = 0;
503 subEntity[lastIndex++] = 1;
507 subEntity[lastIndex++] = 2;
508 for (
unsigned i = 0; i < numInnerEdgeDofs; ++i)
509 subEntity[lastIndex++] = 3;
510 subEntity[lastIndex++] = 3;
512 assert(lastIndex==(f+1+1)*numFaceIndices);
517 subEntity[lastIndex++] = 4;
518 for (
unsigned i = 0; i < k - 1; ++i)
519 subEntity[lastIndex++] = 10;
520 subEntity[lastIndex++] = 5;
523 for (
unsigned e = 0; e < k - 1; ++e) {
524 subEntity[lastIndex++] = 8;
525 for (
unsigned i = 0; i < k - 1; ++i)
526 subEntity[lastIndex++] = 5;
527 subEntity[lastIndex++] = 9;
531 subEntity[lastIndex++] = 6;
532 for (
unsigned i = 0; i < k - 1; ++i)
533 subEntity[lastIndex++] = 11;
534 subEntity[lastIndex++] = 7;
536 assert(numIndices==lastIndex);
541 LagrangeCubeLocalCoefficients ()
546 localKeys_[0] = LocalKey(0,0,0);
553 localKeys_[i] = LocalKey(i,
dim,0);
569 for (
unsigned int j=0; j<
dim; j++)
570 if (mIdx[j]==0 or mIdx[j]==k)
587 for (
int j=
dim-1; j>=0; j--)
588 if (mIdx[j]>0 && mIdx[j]<k)
610 for (
size_t i=0; i<
size(); i++)
611 localKeys_[i] = LocalKey(subEntity[i], codim[i],
index[i]);
623 return localKeys_[i];
634 template<
class LocalBasis>
635 class LagrangeCubeLocalInterpolation
646 template<
typename F,
typename C>
649 constexpr auto dim = LocalBasis::Traits::dimDomain;
650 constexpr auto k = LocalBasis::order();
651 using D =
typename LocalBasis::Traits::DomainFieldType;
653 typename LocalBasis::Traits::DomainType x;
654 auto&& f = Impl::makeFunctionWithCallOperator<typename LocalBasis::Traits::DomainType>(ff);
656 out.
resize(LocalBasis::size());
661 auto center = ReferenceElements<D,dim>::cube().position(0,0);
669 for (
unsigned int i=0; i<LocalBasis::size(); i++)
672 for (
int j=0; j<
dim; j++)
673 x[j] = (i & (1<<j)) ? 1.0 : 0.0;
681 for (
unsigned int i=0; i<LocalBasis::size(); i++)
687 for (
unsigned int j=0; j<
dim; j++)
688 x[j] = (1.0*alpha[j])/k;
707 template<
class D,
class R,
int dim,
int k>
714 Impl::LagrangeCubeLocalCoefficients<dim,k>,
715 Impl::LagrangeCubeLocalInterpolation<Impl::LagrangeCubeLocalBasis<D,R,dim,k> > >;
735 return coefficients_;
742 return interpolation_;
755 return GeometryTypes::cube(
dim);
759 Impl::LagrangeCubeLocalBasis<D,R,dim,k> basis_;
760 Impl::LagrangeCubeLocalCoefficients<dim,k> coefficients_;
761 Impl::LagrangeCubeLocalInterpolation<Impl::LagrangeCubeLocalBasis<D,R,dim,k> > interpolation_;
std::ptrdiff_t index() const
constexpr Mantissa power(Mantissa m, Exponent p)
D DomainType
domain type
Definition common/localbasis.hh:43
traits helper struct
Definition localfiniteelementtraits.hh:11
LB LocalBasisType
Definition localfiniteelementtraits.hh:14
LC LocalCoefficientsType
Definition localfiniteelementtraits.hh:18
LI LocalInterpolationType
Definition localfiniteelementtraits.hh:22
Lagrange finite element for cubes with arbitrary compile-time dimension and polynomial order.
Definition lagrangecube.hh:709
const Traits::LocalBasisType & localBasis() const
Returns the local basis, i.e., the set of shape functions.
Definition lagrangecube.hh:726
LagrangeCubeLocalFiniteElement()
Default constructor.
Definition lagrangecube.hh:722
const Traits::LocalInterpolationType & localInterpolation() const
Returns object that evaluates degrees of freedom.
Definition lagrangecube.hh:740
static constexpr GeometryType type()
The reference element that the local finite element is defined on.
Definition lagrangecube.hh:753
static constexpr std::size_t size()
The number of shape functions.
Definition lagrangecube.hh:746
const Traits::LocalCoefficientsType & localCoefficients() const
Returns the assignment of the degrees of freedom to the element subentities.
Definition lagrangecube.hh:733