Dune Core Modules (2.8.0)

rannacherturek2dlocalbasis.hh
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_RANNACHER_TUREK_2D_LOCALBASIS_HH
4#define DUNE_RANNACHER_TUREK_2D_LOCALBASIS_HH
5
6#include <numeric>
7#include <vector>
8
11
12#include <dune/localfunctions/common/localbasis.hh>
13
14namespace Dune
15{
16
17 template< class D, class R >
18 struct RannacherTurek2DLocalBasis
19 {
20 typedef LocalBasisTraits< D, 2, FieldVector< D, 2 >,
21 R, 1, FieldVector< R, 1 >,
22 FieldMatrix< R, 1, 2 > > Traits;
23
25 unsigned int size () const
26 {
27 return 4;
28 }
29
31 inline void evaluateFunction ( const typename Traits::DomainType &in,
32 std::vector< typename Traits::RangeType > &out ) const
33 {
34 out.resize(4);
35 typename Traits::DomainFieldType qbase = in[0]*in[0]-in[1]*in[1];
36 out[0] = .75 - 2*in[0] + in[1] + qbase;
37 out[1] = -.25 + in[1] + qbase;
38 out[2] = .75 + in[0] - 2*in[1] - qbase;
39 out[3] = -.25 + in[0] - qbase;
40 }
41
43 inline void evaluateJacobian ( const typename Traits::DomainType &in,
44 std::vector< typename Traits::JacobianType > &out ) const
45 {
46 out.resize(4);
47
48 // see http://www.dune-project.org/doc/doxygen/html/classDune_1_1C1LocalBasisInterface.html#d6f8368f8aa43439cc7ef10419f6e2ea
49 // out[i][j][k] = d_k \phi^i_j , where \phi^i_j is the j'th component of the i'th shape function.
50
51 out[0][0][0] = -2 + 2*in[0]; out[0][0][1] = 1 - 2*in[1];
52 out[1][0][0] = 2*in[0]; out[1][0][1] = 1 - 2*in[1];
53 out[2][0][0] = 1 - 2*in[0]; out[2][0][1] = -2 + 2*in[1];
54 out[3][0][0] = 1 - 2*in[0]; out[3][0][1] = 2*in[1];
55 }
56
58 void partial (const std::array<unsigned int, 2>& order,
59 const typename Traits::DomainType& in, // position
60 std::vector<typename Traits::RangeType>& out) const // return value
61 {
62 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
63 if (totalOrder == 0) {
64 evaluateFunction(in, out);
65 } else if (totalOrder == 1) {
66 auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
67 out.resize(size());
68
69 switch (direction) {
70 case 0:
71 out[0] = -2 + 2*in[0];
72 out[1] = 2*in[0];
73 out[2] = 1 - 2*in[0];
74 out[3] = 1 - 2*in[0];
75 break;
76 case 1:
77 out[0] = 1 - 2*in[1];
78 out[1] = 1 - 2*in[1];
79 out[2] = -2 + 2*in[1];
80 out[3] = 2*in[1];
81 break;
82 default:
83 DUNE_THROW(RangeError, "Component out of range.");
84 }
85 } else if (totalOrder == 2) {
86 auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 2));
87 out.resize(size());
88
89 switch (direction) {
90 case 0:
91 out[0] = out[1] = 2;
92 out[2] = out[3] =-2;
93 break;
94 case 1:
95 out[0] = out[1] =-2;
96 out[2] = out[3] = 2;
97 break;
98 default:
99 out[0] = out[1] = out[2] = out[3] = 0;
100 break;
101 }
102 } else {
103 out[0] = out[1] = out[2] = out[3] = 0;
104 }
105 }
106
108 unsigned int order () const
109 {
110 // must be 2 here since it contains x^2 and x^2
111 return 2;
112 }
113 };
114
115} //namespace Dune
116
117#endif // #ifndef DUNE_RANNACHER_TUREK_2D_LOCALBASIS_HH
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
constexpr T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:289
Dune namespace.
Definition: alignedallocator.hh:11
D DomainType
domain type
Definition: localbasis.hh:43
DF DomainFieldType
Export type for domain field.
Definition: localbasis.hh:34
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 22, 23:33, 2024)