Dune Core Modules (2.8.0)

hierarchicalsimplexp2localbasis.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_LOCALBASIS_HH
4#define DUNE_HIERARCHICAL_SIMPLEX_P2_LOCALBASIS_HH
5
10#include <numeric>
11
14
15#include <dune/localfunctions/common/localbasis.hh>
16
17namespace Dune
18{
19 template<class D, class R, int dim>
20 class HierarchicalSimplexP2LocalBasis
21 {
22 public:
23 HierarchicalSimplexP2LocalBasis()
24 {
25 DUNE_THROW(Dune::NotImplemented,"HierarchicalSimplexP2LocalBasis not implemented for dim > 3.");
26 }
27 };
28
43 template<class D, class R>
44 class HierarchicalSimplexP2LocalBasis<D,R,1>
45 {
46 public:
50
52 unsigned int size () const
53 {
54 return 3;
55 }
56
58 inline void evaluateFunction (const typename Traits::DomainType& in,
59 std::vector<typename Traits::RangeType>& out) const
60 {
61 out.resize(3);
62
63 out[0] = 1-in[0];
64 out[1] = 1-4*(in[0]-0.5)*(in[0]-0.5);
65 out[2] = in[0];
66 }
67
69 inline void
70 evaluateJacobian (const typename Traits::DomainType& in, // position
71 std::vector<typename Traits::JacobianType>& out) const // return value
72 {
73 out.resize(3);
74
75 out[0][0][0] = -1;
76 out[1][0][0] = 4-8*in[0];
77 out[2][0][0] = 1;
78 }
79
81 void partial (const std::array<unsigned int, 1>& order,
82 const typename Traits::DomainType& in, // position
83 std::vector<typename Traits::RangeType>& out) const // return value
84 {
85 auto totalOrder = order[0];
86 if (totalOrder == 0) {
87 evaluateFunction(in, out);
88 } else if (totalOrder == 1) {
89 out.resize(size());
90 out[0] = -1;
91 out[1] = 4-8*in[0];
92 out[2] = 1;
93 } else if (totalOrder == 2) {
94 out.resize(size());
95 out[0] = 0;
96 out[1] = -8;
97 out[2] = 0;
98 } else {
99 out.resize(size());
100 out[0] = out[1] = out[2] = 0;
101 }
102 }
103
106 unsigned int order () const
107 {
108 return 2;
109 }
110
111 };
112
132 template<class D, class R>
133 class HierarchicalSimplexP2LocalBasis<D,R,2>
134 {
135 public:
139
141 unsigned int size () const
142 {
143 return 6;
144 }
145
147 inline void evaluateFunction (const typename Traits::DomainType& in,
148 std::vector<typename Traits::RangeType>& out) const
149 {
150 out.resize(6);
151
152 out[0] = 1 - in[0] - in[1];
153 out[1] = 4*in[0]*(1-in[0]-in[1]);
154 out[2] = in[0];
155 out[3] = 4*in[1]*(1-in[0]-in[1]);
156 out[4] = 4*in[0]*in[1];
157 out[5] = in[1];
158
159 }
160
162 inline void
163 evaluateJacobian (const typename Traits::DomainType& in, // position
164 std::vector<typename Traits::JacobianType>& out) const // return value
165 {
166 out.resize(6);
167
168 out[0][0][0] = -1; out[0][0][1] = -1;
169 out[1][0][0] = 4-8*in[0]-4*in[1]; out[1][0][1] = -4*in[0];
170 out[2][0][0] = 1; out[2][0][1] = 0;
171 out[3][0][0] = -4*in[1]; out[3][0][1] = 4-4*in[0]-8*in[1];
172 out[4][0][0] = 4*in[1]; out[4][0][1] = 4*in[0];
173 out[5][0][0] = 0; out[5][0][1] = 1;
174 }
175
177 void partial (const std::array<unsigned int, 2>& order,
178 const typename Traits::DomainType& in, // position
179 std::vector<typename Traits::RangeType>& out) const // return value
180 {
181 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
182 if (totalOrder == 0) {
183 evaluateFunction(in, out);
184 } else if (totalOrder == 1) {
185 out.resize(size());
186 auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
187
188 switch (direction) {
189 case 0:
190 out[0] = -1;
191 out[1] = 4-8*in[0]-4*in[1];
192 out[2] = 1;
193 out[3] = -4*in[1];
194 out[4] = 4*in[1];
195 out[5] = 0;
196 break;
197 case 1:
198 out[0] = -1;
199 out[1] = -4*in[0];
200 out[2] = 0;
201 out[3] = 4-4*in[0]-8*in[1];
202 out[4] = 4*in[0];
203 out[5] = 1;
204 break;
205 default:
206 DUNE_THROW(RangeError, "Component out of range.");
207 }
208 } else {
209 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
210 }
211 }
212
215 unsigned int order () const
216 {
217 return 2;
218 }
219
220 };
221
245 template<class D, class R>
246 class HierarchicalSimplexP2LocalBasis<D,R,3>
247 {
248 public:
252
254 unsigned int size () const
255 {
256 return 10;
257 }
258
260 void evaluateFunction (const typename Traits::DomainType& in,
261 std::vector<typename Traits::RangeType>& out) const
262 {
263 out.resize(10);
264
265 out[0] = 1 - in[0] - in[1] - in[2];
266 out[1] = 4 * in[0] * (1 - in[0] - in[1] - in[2]);
267 out[2] = in[0];
268 out[3] = 4 * in[1] * (1 - in[0] - in[1] - in[2]);
269 out[4] = 4 * in[0] * in[1];
270 out[5] = in[1];
271 out[6] = 4 * in[2] * (1 - in[0] - in[1] - in[2]);
272 out[7] = 4 * in[0] * in[2];
273 out[8] = 4 * in[1] * in[2];
274 out[9] = in[2];
275 }
276
278 void evaluateJacobian (const typename Traits::DomainType& in, // position
279 std::vector<typename Traits::JacobianType>& out) const // return value
280 {
281 out.resize(10);
282
283 out[0][0][0] = -1; out[0][0][1] = -1; out[0][0][2] = -1;
284 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];
285 out[2][0][0] = 1; out[2][0][1] = 0; out[2][0][2] = 0;
286 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];
287 out[4][0][0] = 4*in[1]; out[4][0][1] = 4*in[0]; out[4][0][2] = 0;
288 out[5][0][0] = 0; out[5][0][1] = 1; out[5][0][2] = 0;
289 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];
290 out[7][0][0] = 4*in[2]; out[7][0][1] = 0; out[7][0][2] = 4*in[0];
291 out[8][0][0] = 0; out[8][0][1] = 4*in[2]; out[8][0][2] = 4*in[1];
292 out[9][0][0] = 0; out[9][0][1] = 0; out[9][0][2] = 1;
293 }
294
296 void partial (const std::array<unsigned int, 3>& order,
297 const typename Traits::DomainType& in, // position
298 std::vector<typename Traits::RangeType>& out) const // return value
299 {
300 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
301 if (totalOrder == 0) {
302 evaluateFunction(in, out);
303 } else if (totalOrder == 1) {
304 out.resize(size());
305 auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
306
307 switch (direction) {
308 case 0:
309 out[0] = -1;
310 out[1] = 4-8*in[0]-4*in[1]-4*in[2];
311 out[2] = 1;
312 out[3] = -4*in[1];
313 out[4] = 4*in[1];
314 out[5] = 0;
315 out[6] = -4*in[2];
316 out[7] = 4*in[2];
317 out[8] = 0;
318 out[9] = 0;
319 break;
320 case 1:
321 out[0] = -1;
322 out[1] = -4*in[0];
323 out[2] = 0;
324 out[3] = 4-4*in[0]-8*in[1]-4*in[2];
325 out[4] = 4*in[0];
326 out[5] = 1;
327 out[6] = -4*in[2];
328 out[7] = 0;
329 out[8] = 4*in[2];
330 out[9] = 0;
331 break;
332 case 2:
333 out[0] = -1;
334 out[1] = -4*in[0];
335 out[2] = 0;
336 out[3] = -4*in[1];
337 out[4] = 0;
338 out[5] = 0;
339 out[6] = 4-4*in[0]-4*in[1]-8*in[2];
340 out[7] = 4*in[0];
341 out[8] = 4*in[1];
342 out[9] = 1;
343 break;
344 default:
345 DUNE_THROW(RangeError, "Component out of range.");
346 }
347 } else {
348 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
349 }
350 }
351
354 unsigned int order () const
355 {
356 return 2;
357 }
358
359 };
360}
361#endif
A dense n x m matrix.
Definition: fmatrix.hh:69
vector space out of a tensor product of fields.
Definition: fvector.hh:95
unsigned int order() const
Polynomial order of the shape functions (2, in this case)
Definition: hierarchicalsimplexp2localbasis.hh:106
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: hierarchicalsimplexp2localbasis.hh:49
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: hierarchicalsimplexp2localbasis.hh:81
unsigned int size() const
number of shape functions
Definition: hierarchicalsimplexp2localbasis.hh:52
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:70
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:58
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: hierarchicalsimplexp2localbasis.hh:138
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: hierarchicalsimplexp2localbasis.hh:177
unsigned int size() const
number of shape functions
Definition: hierarchicalsimplexp2localbasis.hh:141
unsigned int order() const
Polynomial order of the shape functions (2 in this case)
Definition: hierarchicalsimplexp2localbasis.hh:215
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:163
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:147
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: hierarchicalsimplexp2localbasis.hh:251
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:260
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:278
unsigned int size() const
number of shape functions
Definition: hierarchicalsimplexp2localbasis.hh:254
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: hierarchicalsimplexp2localbasis.hh:296
unsigned int order() const
Polynomial order of the shape functions (2 in this case)
Definition: hierarchicalsimplexp2localbasis.hh:354
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
constexpr T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:289
Dune namespace.
Definition: alignedallocator.hh:11
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 (Nov 21, 23:30, 2024)