dune-pdelab 2.10-git
Loading...
Searching...
No Matches
qkdglagrange.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3
4#ifndef DUNE_PDELAB_FINITEELEMENT_QKDGLAGRANGE_HH
5#define DUNE_PDELAB_FINITEELEMENT_QKDGLAGRANGE_HH
6
7#include <numeric>
8
9#include <dune/localfunctions/common/localbasis.hh>
14
15namespace Dune
16{
17 namespace QkStuff
18 {
19 // This is the main class
20 // usage: QkSize<2,3>::value
21 // k is the polynomial degree,
22 // n is the space dimension
23 template<int k, int n>
24 struct QkSize
25 {
26 enum{
28 };
29 };
30
31 template<>
32 struct QkSize<0,1>
33 {
34 enum{
35 value=1
36 };
37 };
38
39 template<int k>
40 struct QkSize<k,1>
41 {
42 enum{
43 value=k+1
44 };
45 };
46
47 template<int n>
48 struct QkSize<0,n>
49 {
50 enum{
51 value=1
52 };
53 };
54
55 // ith Lagrange polynomial of degree k in one dimension
56 template<class D, class R, int k>
57 R p (int i, D x)
58 {
59 R result(1.0);
60 for (int j=0; j<=k; j++)
61 if (j!=i) result *= (k*x-j)/(i-j);
62 return result;
63 }
64
65 // derivative of ith Lagrange polynomial of degree k in one dimension
66 template<class D, class R, int k>
67 R dp (int i, D x)
68 {
69 R result(0.0);
70
71 for (int j=0; j<=k; j++)
72 if (j!=i)
73 {
74 R prod( (k*1.0)/(i-j) );
75 for (int l=0; l<=k; l++)
76 if (l!=i && l!=j) prod *= (k*x-l)/(i-l);
77 result += prod;
78 }
79 return result;
80 }
81
83 template<class D, class R, int k>
85 {
86 public:
87 // ith Lagrange polynomial of degree k in one dimension
88 R p (int i, D x) const
89 {
90 R result(1.0);
91 for (int j=0; j<=k; j++)
92 if (j!=i) result *= (k*x-j)/(i-j);
93 return result;
94 }
95
96 // derivative of ith Lagrange polynomial of degree k in one dimension
97 R dp (int i, D x) const
98 {
99 R result(0.0);
100
101 for (int j=0; j<=k; j++)
102 if (j!=i)
103 {
104 R prod( (k*1.0)/(i-j) );
105 for (int l=0; l<=k; l++)
106 if (l!=i && l!=j) prod *= (k*x-l)/(i-l);
107 result += prod;
108 }
109 return result;
110 }
111
112 // get ith Lagrange point
113 R x (int i)
114 {
115 return i/((1.0)*(k+1));
116 }
117 };
118
119 template<int k, int d>
121 {
123 for (int j=0; j<d; j++)
124 {
125 alpha[j] = i % (k+1);
126 i = i/(k+1);
127 }
128 return alpha;
129 }
130
143 template<class D, class R, int k, int d>
145 {
146 enum{ n = QkSize<k,d>::value };
147 public:
149
151 unsigned int size () const
152 {
153 return QkSize<k,d>::value;
154 }
155
157 inline void evaluateFunction (const typename Traits::DomainType& in,
159 {
160 out.resize(size());
161 for (size_t i=0; i<size(); i++)
162 {
163 // convert index i to multiindex
164 Dune::FieldVector<int,d> alpha(multiindex<k,d>(i));
165
166 // initialize product
167 out[i] = 1.0;
168
169 // dimension by dimension
170 for (int j=0; j<d; j++)
171 out[i] *= p<D,R,k>(alpha[j],in[j]);
172 }
173 }
174
176 inline void
177 evaluateJacobian (const typename Traits::DomainType& in, // position
178 std::vector<typename Traits::JacobianType>& out) const // return value
179 {
180 out.resize(size());
181
182 // Loop over all shape functions
183 for (size_t i=0; i<size(); i++)
184 {
185 // convert index i to multiindex
186 Dune::FieldVector<int,d> alpha(multiindex<k,d>(i));
187
188 // Loop over all coordinate directions
189 for (int j=0; j<d; j++)
190 {
191 // Initialize: the overall expression is a product
192 // if j-th bit of i is set to -1, else 1
193 out[i][0][j] = dp<D,R,k>(alpha[j],in[j]);
194
195 // rest of the product
196 for (int l=0; l<d; l++)
197 if (l!=j)
198 out[i][0][j] *= p<D,R,k>(alpha[l],in[l]);
199 }
200 }
201 }
202
205 const typename Traits::DomainType& in,
207 {
208 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
209 if (totalOrder == 0) {
210 evaluateFunction(in, out);
211 } else {
212 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
213 }
214 }
215
217 unsigned int order () const
218 {
219 return k;
220 }
221 };
222
229 template<int k, int d>
231 {
232 public:
235 {
236 for (std::size_t i=0; i<QkSize<k,d>::value; i++)
237 li[i] = LocalKey(0,0,i);
238 }
239
242 {
243 return QkSize<k,d>::value;
244 }
245
248 {
249 return li[i];
250 }
251
252 private:
254 };
255
257 template<int k, int d, class LB>
259 {
260 public:
261
263 template<typename F, typename C>
264 void interpolate (const F& f, std::vector<C>& out) const
265 {
266 typename LB::Traits::DomainType x;
267
269
270 for (int i=0; i<QkSize<k,d>::value; i++)
271 {
272 // convert index i to multiindex
273 Dune::FieldVector<int,d> alpha(multiindex<k,d>(i));
274
275 // Generate coordinate of the i-th Lagrange point
276 for (int j=0; j<d; j++)
277 x[j] = (1.0*alpha[j])/k;
278
279 field_cast(f(x), out[i]);
280 }
281 }
282 };
283
285 template<int d, class LB>
287 {
288 public:
290 template<typename F, typename C>
291 void interpolate (const F& f, std::vector<C>& out) const
292 {
293 typename LB::Traits::DomainType x(0.5);
294
295 out.resize(1);
296 field_cast(f(x), out[0]);
297 }
298 };
299
300 }
301
304 template<class D, class R, int k, int d>
306 {
310
311 public:
312 // static number of basis functions
314
318
322 : gt(GeometryTypes::cube(d))
323 {}
324
327 const typename Traits::LocalBasisType& localBasis () const
328 {
329 return basis;
330 }
331
335 {
336 return coefficients;
337 }
338
342 {
343 return interpolation;
344 }
345
349 {
350 return basis.size();
351 }
352
356 {
357 return gt;
358 }
359
361 {
362 return new QkDGLagrangeLocalFiniteElement(*this);
363 }
364
365 private:
366 LocalBasis basis;
367 LocalCoefficients coefficients;
368 LocalInterpolation interpolation;
369 GeometryType gt;
370 };
371
373
378 template<class Geometry, class RF, int k>
381 QkDGLagrangeLocalFiniteElement<
382 typename Geometry::ctype, RF, k, Geometry::mydimension
383 >,
384 Geometry
385 >
386 {
389 > LFE;
391
392 static const LFE lfe;
393
394 public:
397 };
398
399 template<class Geometry, class RF, int k>
400 const typename QkDGFiniteElementFactory<Geometry, RF, k>::LFE
401 QkDGFiniteElementFactory<Geometry, RF, k>::lfe;
402
403}
404
405
406#endif // DUNE_PDELAB_FINITEELEMENT_QKDGLAGRANGE_HH
double alpha() const
const P & p
Definition constraints.hh:148
#define DUNE_THROW(E,...)
For backward compatibility – Do not use this!
R dp(int i, D x)
Definition qkdglagrange.hh:67
Dune::FieldVector< int, d > multiindex(int i)
Definition qkdglagrange.hh:120
GridImp::ctype ctype
static constexpr int mydimension
Definition qkdglagrange.hh:25
@ value
Definition qkdglagrange.hh:27
Lagrange polynomials of degree k at equidistant points as a class.
Definition qkdglagrange.hh:85
R x(int i)
Definition qkdglagrange.hh:113
R dp(int i, D x) const
Definition qkdglagrange.hh:97
R p(int i, D x) const
Definition qkdglagrange.hh:88
Lagrange shape functions of order k on the reference cube.
Definition qkdglagrange.hh:145
unsigned int size() const
number of shape functions
Definition qkdglagrange.hh:151
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition qkdglagrange.hh:177
LocalBasisTraits< D, d, Dune::FieldVector< D, d >, R, 1, Dune::FieldVector< R, 1 >, Dune::FieldMatrix< R, 1, d > > Traits
Definition qkdglagrange.hh:148
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition qkdglagrange.hh:157
void partial(const std::array< unsigned int, Traits::dimDomain > &order, const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate partial derivative of all shape functions.
Definition qkdglagrange.hh:204
unsigned int order() const
Polynomial order of the shape functions.
Definition qkdglagrange.hh:217
Layout map for Q1 elements.
Definition qkdglagrange.hh:231
const LocalKey & localKey(std::size_t i) const
get i'th index
Definition qkdglagrange.hh:247
QkDGLocalCoefficients()
Standard constructor.
Definition qkdglagrange.hh:234
std::size_t size() const
number of coefficients
Definition qkdglagrange.hh:241
Definition qkdglagrange.hh:259
void interpolate(const F &f, std::vector< C > &out) const
Local interpolation of a function.
Definition qkdglagrange.hh:264
void interpolate(const F &f, std::vector< C > &out) const
Local interpolation of a function.
Definition qkdglagrange.hh:291
Definition qkdglagrange.hh:306
@ n
Definition qkdglagrange.hh:313
std::size_t size() const
Definition qkdglagrange.hh:348
const Traits::LocalInterpolationType & localInterpolation() const
Definition qkdglagrange.hh:341
LocalFiniteElementTraits< LocalBasis, LocalCoefficients, LocalInterpolation > Traits
Definition qkdglagrange.hh:317
const Traits::LocalCoefficientsType & localCoefficients() const
Definition qkdglagrange.hh:334
GeometryType type() const
Definition qkdglagrange.hh:355
QkDGLagrangeLocalFiniteElement()
Definition qkdglagrange.hh:321
QkDGLagrangeLocalFiniteElement * clone() const
Definition qkdglagrange.hh:360
const Traits::LocalBasisType & localBasis() const
Definition qkdglagrange.hh:327
Factory for global-valued QkDG elements.
Definition qkdglagrange.hh:386
QkDGFiniteElementFactory()
default constructor
Definition qkdglagrange.hh:396
static const unsigned int value
Definition gridfunctionspace/tags.hh:139
T accumulate(T... args)
T resize(T... args)