5#ifndef DUNE_LOCALFUNCTIONS_LAGRANGE_LAGRANGECUBE_HH
6#define DUNE_LOCALFUNCTIONS_LAGRANGE_LAGRANGECUBE_HH
21namespace Dune {
namespace Impl
24 template<
class LocalBasis>
25 class LagrangeCubeLocalInterpolation;
37 template<
class D,
class R,
unsigned int dim,
unsigned int k>
38 class LagrangeCubeLocalBasis
40 friend class LagrangeCubeLocalInterpolation<LagrangeCubeLocalBasis<D,R,
dim,k> >;
43 static R p(
unsigned int i, D x)
46 for (
unsigned int j=0; j<=k; j++)
47 if (j!=i) result *= (k*x-j)/((
int)i-(int)j);
52 static R dp(
unsigned int i, D x)
56 for (
unsigned int j=0; j<=k; j++)
60 R prod( (k*1.0)/((
int)i-(
int)j) );
61 for (
unsigned int l=0; l<=k; l++)
63 prod *= (k*x-l)/((
int)i-(int)l);
72 static R ddp(
unsigned int j, D x)
76 for (
unsigned int i=0; i<=k; i++)
83 for (
unsigned int m=0; m<=k; m++)
88 R prod( (k*1.0)/((
int)j-(
int)m) );
89 for (
unsigned int l=0; l<=k; l++)
90 if (l!=i && l!=j && l!=m)
91 prod *= (k*x-l)/((
int)j-(int)l);
95 result += sum * ( (k*1.0)/((
int)j-(int)i) );
105 for (
unsigned int j=0; j<
dim; j++)
107 alpha[j] = i % (k+1);
114 using Traits = LocalBasisTraits<D,dim,FieldVector<D,dim>,R,1,FieldVector<R,1>,FieldMatrix<R,1,dim> >;
118 static constexpr unsigned int size ()
138 for (
size_t i=0; i<
size(); i++)
142 for (
unsigned int j=0; j<
dim; j++)
144 out[i] *= (i & (1<<j)) ? x[j] : 1-x[j];
150 for (
size_t i=0; i<
size(); i++)
159 for (
unsigned int j=0; j<
dim; j++)
160 out[i] *= p(alpha[j],x[j]);
185 for (
size_t i=0; i<
size(); i++)
188 for (
unsigned int j=0; j<
dim; j++)
192 out[i][0][j] = (i & (1<<j)) ? 1 : -1;
194 for (
unsigned int l=0; l<
dim; l++)
198 out[i][0][j] *= (i & (1<<l)) ? x[l] : 1-x[l];
208 for (
size_t i=0; i<
size(); i++)
214 for (
unsigned int j=0; j<
dim; j++)
218 out[i][0][j] = dp(alpha[j],x[j]);
221 for (
unsigned int l=0; l<
dim; l++)
223 out[i][0][j] *= p(alpha[l],x[l]);
244 out[0] = (totalOrder==0);
252 evaluateFunction(in, out);
254 else if (totalOrder == 1)
259 if (direction >=
dim)
260 DUNE_THROW(RangeError,
"Direction of partial derivative not found!");
267 out[i] = (i & (1<<direction)) ? 1 : -1;
269 for (
unsigned int j = 0; j <
dim; ++j)
273 out[i] *= (i & (1<<j)) ? in[j] : 1-in[j];
277 else if (totalOrder == 2)
280 for (
size_t i=0; i<
size(); i++)
294 out[i][0] *= p(alpha[l],in[l]);
298 out[i][0] *= dp(alpha[l],in[l]);
304 DUNE_THROW(NotImplemented,
"Desired derivative order is not implemented");
310 DUNE_THROW(NotImplemented,
"Partial derivative of order " << totalOrder <<
" is not implemented!");
318 for (
size_t i=0; i<
size(); i++)
332 out[i][0] *= p(alpha[l],in[l]);
335 out[i][0] *= dp(alpha[l],in[l]);
338 out[i][0] *= ddp(alpha[l],in[l]);
341 DUNE_THROW(NotImplemented,
"Desired derivative order is not implemented");
348 static constexpr unsigned int order ()
359 template<
unsigned int dim,
unsigned int k>
360 class LagrangeCubeLocalCoefficients
366 for (
unsigned int j=0; j<
dim; j++)
368 alpha[j] = i % (k+1);
379 unsigned lastIndex=0;
386 subEntity[lastIndex++] = 0;
387 for (
unsigned i = 0; i < k - 1; ++i)
388 subEntity[lastIndex++] = 0;
390 subEntity[lastIndex++] = 1;
399 unsigned lastIndex=0;
413 subEntity[lastIndex++] = 0;
414 for (
unsigned i = 0; i < k - 1; ++i)
415 subEntity[lastIndex++] = 2;
417 subEntity[lastIndex++] = 1;
420 for (
unsigned e = 0; e < k - 1; ++e) {
421 subEntity[lastIndex++] = 0;
422 for (
unsigned i = 0; i < k - 1; ++i)
423 subEntity[lastIndex++] = 0;
424 subEntity[lastIndex++] = 1;
428 subEntity[lastIndex++] = 2;
429 for (
unsigned i = 0; i < k - 1; ++i)
430 subEntity[lastIndex++] = 3;
432 subEntity[lastIndex++] = 3;
441 unsigned lastIndex=0;
443 const unsigned numIndices =
power(k+1,
dim);
444 const unsigned numFaceIndices =
power(k+1,
dim-1);
446 const unsigned numInnerEdgeDofs = k-1;
467 subEntity[lastIndex++] = 0;
468 for (
unsigned i = 0; i < numInnerEdgeDofs; ++i)
469 subEntity[lastIndex++] = 6;
471 subEntity[lastIndex++] = 1;
474 for (
unsigned e = 0; e < numInnerEdgeDofs; ++e) {
475 subEntity[lastIndex++] = 4;
476 for (
unsigned i = 0; i < numInnerEdgeDofs; ++i)
477 subEntity[lastIndex++] = 4;
478 subEntity[lastIndex++] = 5;
482 subEntity[lastIndex++] = 2;
483 for (
unsigned i = 0; i < k - 1; ++i)
484 subEntity[lastIndex++] = 7;
485 subEntity[lastIndex++] = 3;
487 assert(numFaceIndices==lastIndex);
491 for(
unsigned f = 0; f < numInnerEdgeDofs; ++f) {
494 subEntity[lastIndex++] = 0;
495 for (
unsigned i = 0; i < numInnerEdgeDofs; ++i)
496 subEntity[lastIndex++] = 2;
497 subEntity[lastIndex++] = 1;
500 for (
unsigned e = 0; e < numInnerEdgeDofs; ++e) {
501 subEntity[lastIndex++] = 0;
502 for (
unsigned i = 0; i < numInnerEdgeDofs; ++i)
503 subEntity[lastIndex++] = 0;
504 subEntity[lastIndex++] = 1;
508 subEntity[lastIndex++] = 2;
509 for (
unsigned i = 0; i < numInnerEdgeDofs; ++i)
510 subEntity[lastIndex++] = 3;
511 subEntity[lastIndex++] = 3;
513 assert(lastIndex==(f+1+1)*numFaceIndices);
518 subEntity[lastIndex++] = 4;
519 for (
unsigned i = 0; i < k - 1; ++i)
520 subEntity[lastIndex++] = 10;
521 subEntity[lastIndex++] = 5;
524 for (
unsigned e = 0; e < k - 1; ++e) {
525 subEntity[lastIndex++] = 8;
526 for (
unsigned i = 0; i < k - 1; ++i)
527 subEntity[lastIndex++] = 5;
528 subEntity[lastIndex++] = 9;
532 subEntity[lastIndex++] = 6;
533 for (
unsigned i = 0; i < k - 1; ++i)
534 subEntity[lastIndex++] = 11;
535 subEntity[lastIndex++] = 7;
537 assert(numIndices==lastIndex);
542 LagrangeCubeLocalCoefficients ()
547 localKeys_[0] = LocalKey(0,0,0);
554 localKeys_[i] = LocalKey(i,
dim,0);
570 for (
unsigned int j=0; j<
dim; j++)
571 if (mIdx[j]==0 or mIdx[j]==k)
588 for (
int j=
dim-1; j>=0; j--)
589 if (mIdx[j]>0 && mIdx[j]<k)
611 for (
size_t i=0; i<
size(); i++)
612 localKeys_[i] = LocalKey(subEntity[i], codim[i],
index[i]);
624 return localKeys_[i];
635 template<
class LocalBasis>
636 class LagrangeCubeLocalInterpolation
647 template<
typename F,
typename C>
650 constexpr auto dim = LocalBasis::Traits::dimDomain;
651 constexpr auto k = LocalBasis::order();
652 using D =
typename LocalBasis::Traits::DomainFieldType;
654 typename LocalBasis::Traits::DomainType x;
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> > >;
728 return coefficients_;
735 return interpolation_;
748 return GeometryTypes::cube(
dim);
752 Impl::LagrangeCubeLocalBasis<D,R,dim,k> basis_;
753 Impl::LagrangeCubeLocalCoefficients<dim,k> coefficients_;
754 Impl::LagrangeCubeLocalInterpolation<Impl::LagrangeCubeLocalBasis<D,R,dim,k> > interpolation_;
std::ptrdiff_t index() const
#define DUNE_THROW(E,...)
constexpr Base power(Base m, Exponent p)
D DomainType
domain type
Definition common/localbasis.hh:43
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
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:719
const Traits::LocalInterpolationType & localInterpolation() const
Returns object that evaluates degrees of freedom.
Definition lagrangecube.hh:733
static constexpr GeometryType type()
The reference element that the local finite element is defined on.
Definition lagrangecube.hh:746
static constexpr std::size_t size()
The number of shape functions.
Definition lagrangecube.hh:739
const Traits::LocalCoefficientsType & localCoefficients() const
Returns the assignment of the degrees of freedom to the element subentities.
Definition lagrangecube.hh:726