Dune Core Modules (2.10.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// SPDX-FileCopyrightInfo: Copyright © DUNE Project contributors, see file LICENSE.md in module root
4// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5#ifndef DUNE_HIERARCHICAL_SIMPLEX_P2_LOCALBASIS_HH
6#define DUNE_HIERARCHICAL_SIMPLEX_P2_LOCALBASIS_HH
7
12#include <numeric>
13
16
17#include <dune/localfunctions/common/localbasis.hh>
18
19namespace Dune
20{
21 template<class D, class R, int dim>
22 class HierarchicalSimplexP2LocalBasis
23 {
24 public:
25 HierarchicalSimplexP2LocalBasis()
26 {
27 DUNE_THROW(Dune::NotImplemented,"HierarchicalSimplexP2LocalBasis not implemented for dim > 3.");
28 }
29 };
30
46 template<class D, class R>
47 class HierarchicalSimplexP2LocalBasis<D,R,1>
48 {
49 public:
53
55 unsigned int size () const
56 {
57 return 3;
58 }
59
61 inline void evaluateFunction (const typename Traits::DomainType& in,
62 std::vector<typename Traits::RangeType>& out) const
63 {
64 out.resize(3);
65
66 out[0] = 1-in[0];
67 out[1] = 1-4*(in[0]-0.5)*(in[0]-0.5);
68 out[2] = in[0];
69 }
70
72 inline void
73 evaluateJacobian (const typename Traits::DomainType& in, // position
74 std::vector<typename Traits::JacobianType>& out) const // return value
75 {
76 out.resize(3);
77
78 out[0][0][0] = -1;
79 out[1][0][0] = 4-8*in[0];
80 out[2][0][0] = 1;
81 }
82
84 void partial (const std::array<unsigned int, 1>& order,
85 const typename Traits::DomainType& in, // position
86 std::vector<typename Traits::RangeType>& out) const // return value
87 {
88 auto totalOrder = order[0];
89 if (totalOrder == 0) {
90 evaluateFunction(in, out);
91 } else if (totalOrder == 1) {
92 out.resize(size());
93 out[0] = -1;
94 out[1] = 4-8*in[0];
95 out[2] = 1;
96 } else if (totalOrder == 2) {
97 out.resize(size());
98 out[0] = 0;
99 out[1] = -8;
100 out[2] = 0;
101 } else {
102 out.resize(size());
103 out[0] = out[1] = out[2] = 0;
104 }
105 }
106
109 unsigned int order () const
110 {
111 return 2;
112 }
113
114 };
115
136 template<class D, class R>
137 class HierarchicalSimplexP2LocalBasis<D,R,2>
138 {
139 public:
143
145 unsigned int size () const
146 {
147 return 6;
148 }
149
151 inline void evaluateFunction (const typename Traits::DomainType& in,
152 std::vector<typename Traits::RangeType>& out) const
153 {
154 out.resize(6);
155
156 out[0] = 1 - in[0] - in[1];
157 out[1] = 4*in[0]*(1-in[0]-in[1]);
158 out[2] = in[0];
159 out[3] = 4*in[1]*(1-in[0]-in[1]);
160 out[4] = 4*in[0]*in[1];
161 out[5] = 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(6);
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
181 void partial (const std::array<unsigned int, 2>& order,
182 const typename Traits::DomainType& in, // position
183 std::vector<typename Traits::RangeType>& out) const // return value
184 {
185 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
186 if (totalOrder == 0) {
187 evaluateFunction(in, out);
188 } else if (totalOrder == 1) {
189 out.resize(size());
190 auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
191
192 switch (direction) {
193 case 0:
194 out[0] = -1;
195 out[1] = 4-8*in[0]-4*in[1];
196 out[2] = 1;
197 out[3] = -4*in[1];
198 out[4] = 4*in[1];
199 out[5] = 0;
200 break;
201 case 1:
202 out[0] = -1;
203 out[1] = -4*in[0];
204 out[2] = 0;
205 out[3] = 4-4*in[0]-8*in[1];
206 out[4] = 4*in[0];
207 out[5] = 1;
208 break;
209 default:
210 DUNE_THROW(RangeError, "Component out of range.");
211 }
212 } else {
213 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
214 }
215 }
216
219 unsigned int order () const
220 {
221 return 2;
222 }
223
224 };
225
250 template<class D, class R>
251 class HierarchicalSimplexP2LocalBasis<D,R,3>
252 {
253 public:
257
259 unsigned int size () const
260 {
261 return 10;
262 }
263
265 void evaluateFunction (const typename Traits::DomainType& in,
266 std::vector<typename Traits::RangeType>& out) const
267 {
268 out.resize(10);
269
270 out[0] = 1 - in[0] - in[1] - in[2];
271 out[1] = 4 * in[0] * (1 - in[0] - in[1] - in[2]);
272 out[2] = in[0];
273 out[3] = 4 * in[1] * (1 - in[0] - in[1] - in[2]);
274 out[4] = 4 * in[0] * in[1];
275 out[5] = in[1];
276 out[6] = 4 * in[2] * (1 - in[0] - in[1] - in[2]);
277 out[7] = 4 * in[0] * in[2];
278 out[8] = 4 * in[1] * in[2];
279 out[9] = in[2];
280 }
281
283 void evaluateJacobian (const typename Traits::DomainType& in, // position
284 std::vector<typename Traits::JacobianType>& out) const // return value
285 {
286 out.resize(10);
287
288 out[0][0][0] = -1; out[0][0][1] = -1; out[0][0][2] = -1;
289 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];
290 out[2][0][0] = 1; out[2][0][1] = 0; out[2][0][2] = 0;
291 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];
292 out[4][0][0] = 4*in[1]; out[4][0][1] = 4*in[0]; out[4][0][2] = 0;
293 out[5][0][0] = 0; out[5][0][1] = 1; out[5][0][2] = 0;
294 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];
295 out[7][0][0] = 4*in[2]; out[7][0][1] = 0; out[7][0][2] = 4*in[0];
296 out[8][0][0] = 0; out[8][0][1] = 4*in[2]; out[8][0][2] = 4*in[1];
297 out[9][0][0] = 0; out[9][0][1] = 0; out[9][0][2] = 1;
298 }
299
301 void partial (const std::array<unsigned int, 3>& order,
302 const typename Traits::DomainType& in, // position
303 std::vector<typename Traits::RangeType>& out) const // return value
304 {
305 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
306 if (totalOrder == 0) {
307 evaluateFunction(in, out);
308 } else if (totalOrder == 1) {
309 out.resize(size());
310 auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
311
312 switch (direction) {
313 case 0:
314 out[0] = -1;
315 out[1] = 4-8*in[0]-4*in[1]-4*in[2];
316 out[2] = 1;
317 out[3] = -4*in[1];
318 out[4] = 4*in[1];
319 out[5] = 0;
320 out[6] = -4*in[2];
321 out[7] = 4*in[2];
322 out[8] = 0;
323 out[9] = 0;
324 break;
325 case 1:
326 out[0] = -1;
327 out[1] = -4*in[0];
328 out[2] = 0;
329 out[3] = 4-4*in[0]-8*in[1]-4*in[2];
330 out[4] = 4*in[0];
331 out[5] = 1;
332 out[6] = -4*in[2];
333 out[7] = 0;
334 out[8] = 4*in[2];
335 out[9] = 0;
336 break;
337 case 2:
338 out[0] = -1;
339 out[1] = -4*in[0];
340 out[2] = 0;
341 out[3] = -4*in[1];
342 out[4] = 0;
343 out[5] = 0;
344 out[6] = 4-4*in[0]-4*in[1]-8*in[2];
345 out[7] = 4*in[0];
346 out[8] = 4*in[1];
347 out[9] = 1;
348 break;
349 default:
350 DUNE_THROW(RangeError, "Component out of range.");
351 }
352 } else {
353 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
354 }
355 }
356
359 unsigned int order () const
360 {
361 return 2;
362 }
363
364 };
365}
366#endif
A dense n x m matrix.
Definition: fmatrix.hh:117
vector space out of a tensor product of fields.
Definition: fvector.hh:91
unsigned int order() const
Polynomial order of the shape functions (2, in this case)
Definition: hierarchicalsimplexp2localbasis.hh:109
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:52
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:84
unsigned int size() const
number of shape functions
Definition: hierarchicalsimplexp2localbasis.hh:55
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:73
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:61
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:142
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:181
unsigned int size() const
number of shape functions
Definition: hierarchicalsimplexp2localbasis.hh:145
unsigned int order() const
Polynomial order of the shape functions (2 in this case)
Definition: hierarchicalsimplexp2localbasis.hh:219
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:167
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:151
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:256
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:265
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:283
unsigned int size() const
number of shape functions
Definition: hierarchicalsimplexp2localbasis.hh:259
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:301
unsigned int order() const
Polynomial order of the shape functions (2 in this case)
Definition: hierarchicalsimplexp2localbasis.hh:359
Default exception for dummy implementations.
Definition: exceptions.hh:263
Default exception class for range errors.
Definition: exceptions.hh:254
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:218
constexpr T accumulate(Range &&range, T value, F &&f)
Accumulate values.
Definition: hybridutilities.hh:279
Dune namespace.
Definition: alignedallocator.hh:13
constexpr std::integral_constant< std::size_t, sizeof...(II)> size(std::integer_sequence< T, II... >)
Return the size of the sequence.
Definition: integersequence.hh:75
Type traits for LocalBasisVirtualInterface.
Definition: localbasis.hh:35
D DomainType
domain type
Definition: localbasis.hh:43
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 27, 23:30, 2024)