Dune Core Modules (2.6.0)

hierarchicalsimplexp2withelementbubble.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#ifndef DUNE_HIERARCHICAL_SIMPLEX_P2_WITH_ELEMENT_BUBBLE_LOCALBASIS_HH
4#define DUNE_HIERARCHICAL_SIMPLEX_P2_WITH_ELEMENT_BUBBLE_LOCALBASIS_HH
5
10#include <numeric>
11#include <vector>
12
15
16#include <dune/localfunctions/common/localbasis.hh>
17#include <dune/localfunctions/common/localkey.hh>
18
19namespace Dune
20{
21 template<class D, class R, int dim>
22 class HierarchicalSimplexP2WithElementBubbleLocalBasis
23 {
24 public:
25 HierarchicalSimplexP2WithElementBubbleLocalBasis()
26 {
27 DUNE_THROW(Dune::NotImplemented,"HierarchicalSimplexP2LocalBasis not implemented for dim > 3.");
28 }
29 };
30
45 template<class D, class R>
46 class HierarchicalSimplexP2WithElementBubbleLocalBasis<D,R,1>
47 {
48 public:
52
54 unsigned int size () const
55 {
56 return 3;
57 }
58
60 inline void evaluateFunction (const typename Traits::DomainType& in,
61 std::vector<typename Traits::RangeType>& out) const
62 {
63 out.resize(3);
64
65 out[0] = 1-in[0];
66 out[1] = in[0];
67 out[2] = 1-4*(in[0]-0.5)*(in[0]-0.5);
68 }
69
71 inline void
72 evaluateJacobian (const typename Traits::DomainType& in, // position
73 std::vector<typename Traits::JacobianType>& out) const // return value
74 {
75 out.resize(3);
76
77 out[0][0][0] = -1;
78 out[1][0][0] = 1;
79 out[2][0][0] = 4-8*in[0];
80 }
81
83 void partial (const std::array<unsigned int, 1>& order,
84 const typename Traits::DomainType& in, // position
85 std::vector<typename Traits::RangeType>& out) const // return value
86 {
87 auto totalOrder = order[0];
88 if (totalOrder == 0) {
89 evaluateFunction(in, out);
90 } else if (totalOrder == 1) {
91 out.resize(size());
92 out[0] = -1;
93 out[1] = 1;
94 out[2] = 4-8*in[0];
95 } else if (totalOrder == 2) {
96 out.resize(size());
97 out[0] = 0;
98 out[1] = 0;
99 out[2] =-8;
100 } else {
101 out.resize(size());
102 out[0] = out[1] = out[2] = 0;
103 }
104 }
105
108 unsigned int order () const
109 {
110 return 2;
111 }
112
113 };
114
135 template<class D, class R>
136 class HierarchicalSimplexP2WithElementBubbleLocalBasis<D,R,2>
137 {
138 public:
142
144 unsigned int size () const
145 {
146 return 7;
147 }
148
150 inline void evaluateFunction (const typename Traits::DomainType& in,
151 std::vector<typename Traits::RangeType>& out) const
152 {
153 out.resize(7);
154
155 out[0] = 1 - in[0] - in[1];
156 out[1] = 4*in[0]*(1-in[0]-in[1]);
157 out[2] = in[0];
158 out[3] = 4*in[1]*(1-in[0]-in[1]);
159 out[4] = 4*in[0]*in[1];
160 out[5] = in[1];
161 out[6] = 27*in[0]*in[1]*(1-in[0]-in[1]);
162
163 }
164
166 inline void
167 evaluateJacobian (const typename Traits::DomainType& in, // position
168 std::vector<typename Traits::JacobianType>& out) const // return value
169 {
170 out.resize(7);
171
172 out[0][0][0] = -1; out[0][0][1] = -1;
173 out[1][0][0] = 4-8*in[0]-4*in[1]; out[1][0][1] = -4*in[0];
174 out[2][0][0] = 1; out[2][0][1] = 0;
175 out[3][0][0] = -4*in[1]; out[3][0][1] = 4-4*in[0]-8*in[1];
176 out[4][0][0] = 4*in[1]; out[4][0][1] = 4*in[0];
177 out[5][0][0] = 0; out[5][0][1] = 1;
178
179 // Cubic bubble
180 out[6][0][0] = 27 * in[1] * (1 - 2*in[0] - in[1]);
181 out[6][0][1] = 27 * in[0] * (1 - 2*in[1] - in[0]);
182
183 }
184
186 void partial (const std::array<unsigned int, 2>& order,
187 const typename Traits::DomainType& in, // position
188 std::vector<typename Traits::RangeType>& out) const // return value
189 {
190 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
191 if (totalOrder == 0) {
192 evaluateFunction(in, out);
193 } else if (totalOrder == 1) {
194 out.resize(size());
195 auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
196
197 switch (direction) {
198 case 0:
199 out[0] = -1;
200 out[1] = 4-8*in[0]-4*in[1];
201 out[2] = 1;
202 out[3] = -4*in[1];
203 out[4] = 4*in[1];
204 out[5] = 0;
205 out[6] = 27 * in[1] * (1 - 2*in[0] - in[1]);
206 break;
207 case 1:
208 out[0] = -1;
209 out[1] = -4*in[0];
210 out[2] = 0;
211 out[3] = 4-4*in[0]-8*in[1];
212 out[4] = 4*in[0];
213 out[5] = 1;
214 out[6] = 27 * in[0] * (1 - 2*in[1] - in[0]);
215 break;
216 default:
217 DUNE_THROW(RangeError, "Component out of range.");
218 }
219 } else {
220 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
221 }
222 }
223
226 unsigned int order () const
227 {
228 return 3;
229 }
230
231 };
232
257 template<class D, class R>
258 class HierarchicalSimplexP2WithElementBubbleLocalBasis<D,R,3>
259 {
260 public:
264
266 unsigned int size () const
267 {
268 return 11;
269 }
270
272 void evaluateFunction (const typename Traits::DomainType& in,
273 std::vector<typename Traits::RangeType>& out) const
274 {
275 out.resize(10);
276
277 out[0] = 1 - in[0] - in[1] - in[2];
278 out[1] = 4 * in[0] * (1 - in[0] - in[1] - in[2]);
279 out[2] = in[0];
280 out[3] = 4 * in[1] * (1 - in[0] - in[1] - in[2]);
281 out[4] = 4 * in[0] * in[1];
282 out[5] = in[1];
283 out[6] = 4 * in[2] * (1 - in[0] - in[1] - in[2]);
284 out[7] = 4 * in[0] * in[2];
285 out[8] = 4 * in[1] * in[2];
286 out[9] = in[2];
287
288 // quartic element bubble
289 out[10] = 81*in[0]*in[1]*in[2]*(1-in[0]-in[1]-in[2]);
290 }
291
293 void evaluateJacobian (const typename Traits::DomainType& in, // position
294 std::vector<typename Traits::JacobianType>& out) const // return value
295 {
296 out.resize(10);
297
298 out[0][0][0] = -1; out[0][0][1] = -1; out[0][0][2] = -1;
299 out[1][0][0] = 4-8*in[0]-4*in[1]-4*in[2]; out[1][0][1] = -4*in[0]; out[1][0][2] = -4*in[0];
300 out[2][0][0] = 1; out[2][0][1] = 0; out[2][0][2] = 0;
301 out[3][0][0] = -4*in[1]; out[3][0][1] = 4-4*in[0]-8*in[1]-4*in[2]; out[3][0][2] = -4*in[1];
302 out[4][0][0] = 4*in[1]; out[4][0][1] = 4*in[0]; out[4][0][2] = 0;
303 out[5][0][0] = 0; out[5][0][1] = 1; out[5][0][2] = 0;
304 out[6][0][0] = -4*in[2]; out[6][0][1] = -4*in[2]; out[6][0][2] = 4-4*in[0]-4*in[1]-8*in[2];
305 out[7][0][0] = 4*in[2]; out[7][0][1] = 0; out[7][0][2] = 4*in[0];
306 out[8][0][0] = 0; out[8][0][1] = 4*in[2]; out[8][0][2] = 4*in[1];
307 out[9][0][0] = 0; out[9][0][1] = 0; out[9][0][2] = 1;
308
309 out[10][0][0] = 81 * in[1] * in[2] * (1 - 2*in[0] - in[1] - in[2]);
310 out[10][0][1] = 81 * in[0] * in[2] * (1 - in[0] - 2*in[1] - in[2]);
311 out[10][0][2] = 81 * in[0] * in[1] * (1 - in[0] - in[1] - 2*in[2]);
312 }
313
315 void partial (const std::array<unsigned int, 3>& order,
316 const typename Traits::DomainType& in, // position
317 std::vector<typename Traits::RangeType>& out) const // return value
318 {
319 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
320 if (totalOrder == 0) {
321 evaluateFunction(in, out);
322 } else if (totalOrder == 1) {
323 out.resize(size());
324 auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
325
326 switch (direction) {
327 case 0:
328 out[0] = -1;
329 out[1] = 4-8*in[0]-4*in[1]-4*in[2];
330 out[2] = 1;
331 out[3] = -4*in[1];
332 out[4] = 4*in[1];
333 out[5] = 0;
334 out[6] = -4*in[2];
335 out[7] = 4*in[2];
336 out[8] = 0;
337 out[9] = 0;
338 out[10] = 81 * in[1] * in[2] * (1 - 2*in[0] - in[1] - in[2]);
339 break;
340 case 1:
341 out[0] = -1;
342 out[1] = -4*in[0];
343 out[2] = 0;
344 out[3] = 4-4*in[0]-8*in[1]-4*in[2];
345 out[4] = 4*in[0];
346 out[5] = 1;
347 out[6] = -4*in[2];
348 out[7] = 0;
349 out[8] = 4*in[2];
350 out[9] = 0;
351 out[10] = 81 * in[0] * in[2] * (1 - in[0] - 2*in[1] - in[2]);
352 break;
353 case 2:
354 out[0] = -1;
355 out[1] = -4*in[0];
356 out[2] = 0;
357 out[3] = -4*in[1];
358 out[4] = 0;
359 out[5] = 0;
360 out[6] = 4-4*in[0]-4*in[1]-8*in[2];
361 out[7] = 4*in[0];
362 out[8] = 4*in[1];
363 out[9] = 1;
364 out[10] = 81 * in[0] * in[1] * (1 - in[0] - in[1] - 2*in[2]);
365 break;
366 default:
367 DUNE_THROW(RangeError, "Component out of range.");
368 }
369 } else {
370 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
371 }
372 }
373
376 unsigned int order () const
377 {
378 return 4;
379 }
380
381 };
382
383
409 template <int dim>
411 {
412 // The binomial coefficient: dim+1 over 1
413 static const int numVertices = dim+1;
414
415 // The binomial coefficient: dim+1 over 2
416 static const int numEdges = (dim+1)*dim / 2;
417
418 public:
421 : li(numVertices+numEdges + 1)
422 {
423 if (dim!=2)
424 DUNE_THROW(NotImplemented, "only for 2d");
425
426 li[0] = Dune::LocalKey(0,2,0); // Vertex (0,0)
427 li[1] = Dune::LocalKey(0,1,0); // Edge (0.5, 0)
428 li[2] = Dune::LocalKey(1,2,0); // Vertex (1,0)
429 li[3] = Dune::LocalKey(1,1,0); // Edge (0, 0.5)
430 li[4] = Dune::LocalKey(2,1,0); // Edge (0.5, 0.5)
431 li[5] = Dune::LocalKey(2,2,0); // Vertex (0,1)
432 li[6] = Dune::LocalKey(0,0,0); // Element (1/3, 1/3)
433 }
434
436 size_t size () const
437 {
438 return numVertices+numEdges + 1;
439 }
440
442 const Dune::LocalKey& localKey (size_t i) const
443 {
444 return li[i];
445 }
446
447 private:
448 std::vector<Dune::LocalKey> li;
449 };
450
451 template<class LB>
452 class HierarchicalSimplexP2WithElementBubbleLocalInterpolation
453 {
454 public:
455
457 template<typename F, typename C>
458 void interpolate (const F& f, std::vector<C>& out) const
459 {
460 typename LB::Traits::DomainType x;
461 typename LB::Traits::RangeType y;
462
463 out.resize(7);
464
465 // vertices
466 x[0] = 0.0; x[1] = 0.0; f.evaluate(x,y); out[0] = y;
467 x[0] = 1.0; x[1] = 0.0; f.evaluate(x,y); out[2] = y;
468 x[0] = 0.0; x[1] = 1.0; f.evaluate(x,y); out[5] = y;
469
470 // edge bubbles
471 x[0] = 0.5; x[1] = 0.0; f.evaluate(x,y);
472 out[1] = y - out[0]*(1-x[0]) - out[2]*x[0];
473
474 x[0] = 0.0; x[1] = 0.5; f.evaluate(x,y);
475 out[3] = y - out[0]*(1-x[1]) - out[5]*x[1];
476
477 x[0] = 0.5; x[1] = 0.5; f.evaluate(x,y);
478 out[4] = y - out[2]*x[0] - out[5]*x[1];
479
480 // element bubble
481 x[0] = 1.0/3; x[1] = 1.0/3; f.evaluate(x,y);
482
484 HierarchicalSimplexP2WithElementBubbleLocalBasis<double,double,2> shapeFunctions;
485 std::vector<typename LB::Traits::RangeType> sfValues;
486 shapeFunctions.evaluateFunction(x, sfValues);
487
488 out[6] = y;
489 for (int i=0; i<6; i++)
490 out[6] -= out[i]*sfValues[i];
491
492 }
493
494 };
495
496
497}
498#endif
A dense n x m matrix.
Definition: fmatrix.hh:68
vector space out of a tensor product of fields.
Definition: fvector.hh:93
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: hierarchicalsimplexp2withelementbubble.hh:72
LocalBasisTraits< D, 1, Dune::FieldVector< D, 1 >, R, 1, Dune::FieldVector< R, 1 >, Dune::FieldMatrix< R, 1, 1 > > Traits
export type traits for function signature
Definition: hierarchicalsimplexp2withelementbubble.hh:51
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: hierarchicalsimplexp2withelementbubble.hh:60
unsigned int order() const
Polynomial order of the shape functions (2, in this case)
Definition: hierarchicalsimplexp2withelementbubble.hh:108
unsigned int size() const
number of shape functions
Definition: hierarchicalsimplexp2withelementbubble.hh:54
void partial(const std::array< unsigned int, 1 > &order, const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate partial derivatives of all shape functions.
Definition: hierarchicalsimplexp2withelementbubble.hh:83
unsigned int size() const
number of shape functions
Definition: hierarchicalsimplexp2withelementbubble.hh:144
unsigned int order() const
Polynomial order of the shape functions (3 in this case)
Definition: hierarchicalsimplexp2withelementbubble.hh:226
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: hierarchicalsimplexp2withelementbubble.hh:150
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: hierarchicalsimplexp2withelementbubble.hh:167
void partial(const std::array< unsigned int, 2 > &order, const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate partial derivatives of all shape functions.
Definition: hierarchicalsimplexp2withelementbubble.hh:186
LocalBasisTraits< D, 2, Dune::FieldVector< D, 2 >, R, 1, Dune::FieldVector< R, 1 >, Dune::FieldMatrix< R, 1, 2 > > Traits
export type traits for function signature
Definition: hierarchicalsimplexp2withelementbubble.hh:141
unsigned int size() const
number of shape functions
Definition: hierarchicalsimplexp2withelementbubble.hh:266
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: hierarchicalsimplexp2withelementbubble.hh:272
unsigned int order() const
Polynomial order of the shape functions (4 in this case)
Definition: hierarchicalsimplexp2withelementbubble.hh:376
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: hierarchicalsimplexp2withelementbubble.hh:293
void partial(const std::array< unsigned int, 3 > &order, const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate partial derivatives of all shape functions.
Definition: hierarchicalsimplexp2withelementbubble.hh:315
LocalBasisTraits< D, 3, Dune::FieldVector< D, 3 >, R, 1, Dune::FieldVector< R, 1 >, Dune::FieldMatrix< R, 1, 3 > > Traits
export type traits for function signature
Definition: hierarchicalsimplexp2withelementbubble.hh:263
The local finite element needed for the Zou-Kornhuber estimator for Signorini problems.
Definition: hierarchicalsimplexp2withelementbubble.hh:411
size_t size() const
number of coefficients
Definition: hierarchicalsimplexp2withelementbubble.hh:436
const Dune::LocalKey & localKey(size_t i) const
get i'th index
Definition: hierarchicalsimplexp2withelementbubble.hh:442
HierarchicalSimplexP2WithElementBubbleLocalCoefficients()
Standard constructor.
Definition: hierarchicalsimplexp2withelementbubble.hh:420
Describe position of one degree of freedom.
Definition: localkey.hh:21
Default exception for dummy implementations.
Definition: exceptions.hh:261
Default exception class for range errors.
Definition: exceptions.hh:252
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.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:331
Dune namespace.
Definition: alignedallocator.hh:10
Type traits for LocalBasisVirtualInterface.
Definition: localbasis.hh:32
D DomainType
domain type
Definition: localbasis.hh:43
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)