Dune Core Modules (2.9.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 (C) 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
45 template<class D, class R>
46 class HierarchicalSimplexP2LocalBasis<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] = 1-4*(in[0]-0.5)*(in[0]-0.5);
67 out[2] = in[0];
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] = 4-8*in[0];
79 out[2][0][0] = 1;
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] = 4-8*in[0];
94 out[2] = 1;
95 } else if (totalOrder == 2) {
96 out.resize(size());
97 out[0] = 0;
98 out[1] = -8;
99 out[2] = 0;
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
134 template<class D, class R>
135 class HierarchicalSimplexP2LocalBasis<D,R,2>
136 {
137 public:
141
143 unsigned int size () const
144 {
145 return 6;
146 }
147
149 inline void evaluateFunction (const typename Traits::DomainType& in,
150 std::vector<typename Traits::RangeType>& out) const
151 {
152 out.resize(6);
153
154 out[0] = 1 - in[0] - in[1];
155 out[1] = 4*in[0]*(1-in[0]-in[1]);
156 out[2] = in[0];
157 out[3] = 4*in[1]*(1-in[0]-in[1]);
158 out[4] = 4*in[0]*in[1];
159 out[5] = in[1];
160
161 }
162
164 inline void
165 evaluateJacobian (const typename Traits::DomainType& in, // position
166 std::vector<typename Traits::JacobianType>& out) const // return value
167 {
168 out.resize(6);
169
170 out[0][0][0] = -1; out[0][0][1] = -1;
171 out[1][0][0] = 4-8*in[0]-4*in[1]; out[1][0][1] = -4*in[0];
172 out[2][0][0] = 1; out[2][0][1] = 0;
173 out[3][0][0] = -4*in[1]; out[3][0][1] = 4-4*in[0]-8*in[1];
174 out[4][0][0] = 4*in[1]; out[4][0][1] = 4*in[0];
175 out[5][0][0] = 0; out[5][0][1] = 1;
176 }
177
179 void partial (const std::array<unsigned int, 2>& order,
180 const typename Traits::DomainType& in, // position
181 std::vector<typename Traits::RangeType>& out) const // return value
182 {
183 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
184 if (totalOrder == 0) {
185 evaluateFunction(in, out);
186 } else if (totalOrder == 1) {
187 out.resize(size());
188 auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
189
190 switch (direction) {
191 case 0:
192 out[0] = -1;
193 out[1] = 4-8*in[0]-4*in[1];
194 out[2] = 1;
195 out[3] = -4*in[1];
196 out[4] = 4*in[1];
197 out[5] = 0;
198 break;
199 case 1:
200 out[0] = -1;
201 out[1] = -4*in[0];
202 out[2] = 0;
203 out[3] = 4-4*in[0]-8*in[1];
204 out[4] = 4*in[0];
205 out[5] = 1;
206 break;
207 default:
208 DUNE_THROW(RangeError, "Component out of range.");
209 }
210 } else {
211 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
212 }
213 }
214
217 unsigned int order () const
218 {
219 return 2;
220 }
221
222 };
223
247 template<class D, class R>
248 class HierarchicalSimplexP2LocalBasis<D,R,3>
249 {
250 public:
254
256 unsigned int size () const
257 {
258 return 10;
259 }
260
262 void evaluateFunction (const typename Traits::DomainType& in,
263 std::vector<typename Traits::RangeType>& out) const
264 {
265 out.resize(10);
266
267 out[0] = 1 - in[0] - in[1] - in[2];
268 out[1] = 4 * in[0] * (1 - in[0] - in[1] - in[2]);
269 out[2] = in[0];
270 out[3] = 4 * in[1] * (1 - in[0] - in[1] - in[2]);
271 out[4] = 4 * in[0] * in[1];
272 out[5] = in[1];
273 out[6] = 4 * in[2] * (1 - in[0] - in[1] - in[2]);
274 out[7] = 4 * in[0] * in[2];
275 out[8] = 4 * in[1] * in[2];
276 out[9] = in[2];
277 }
278
280 void evaluateJacobian (const typename Traits::DomainType& in, // position
281 std::vector<typename Traits::JacobianType>& out) const // return value
282 {
283 out.resize(10);
284
285 out[0][0][0] = -1; out[0][0][1] = -1; out[0][0][2] = -1;
286 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];
287 out[2][0][0] = 1; out[2][0][1] = 0; out[2][0][2] = 0;
288 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];
289 out[4][0][0] = 4*in[1]; out[4][0][1] = 4*in[0]; out[4][0][2] = 0;
290 out[5][0][0] = 0; out[5][0][1] = 1; out[5][0][2] = 0;
291 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];
292 out[7][0][0] = 4*in[2]; out[7][0][1] = 0; out[7][0][2] = 4*in[0];
293 out[8][0][0] = 0; out[8][0][1] = 4*in[2]; out[8][0][2] = 4*in[1];
294 out[9][0][0] = 0; out[9][0][1] = 0; out[9][0][2] = 1;
295 }
296
298 void partial (const std::array<unsigned int, 3>& order,
299 const typename Traits::DomainType& in, // position
300 std::vector<typename Traits::RangeType>& out) const // return value
301 {
302 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
303 if (totalOrder == 0) {
304 evaluateFunction(in, out);
305 } else if (totalOrder == 1) {
306 out.resize(size());
307 auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
308
309 switch (direction) {
310 case 0:
311 out[0] = -1;
312 out[1] = 4-8*in[0]-4*in[1]-4*in[2];
313 out[2] = 1;
314 out[3] = -4*in[1];
315 out[4] = 4*in[1];
316 out[5] = 0;
317 out[6] = -4*in[2];
318 out[7] = 4*in[2];
319 out[8] = 0;
320 out[9] = 0;
321 break;
322 case 1:
323 out[0] = -1;
324 out[1] = -4*in[0];
325 out[2] = 0;
326 out[3] = 4-4*in[0]-8*in[1]-4*in[2];
327 out[4] = 4*in[0];
328 out[5] = 1;
329 out[6] = -4*in[2];
330 out[7] = 0;
331 out[8] = 4*in[2];
332 out[9] = 0;
333 break;
334 case 2:
335 out[0] = -1;
336 out[1] = -4*in[0];
337 out[2] = 0;
338 out[3] = -4*in[1];
339 out[4] = 0;
340 out[5] = 0;
341 out[6] = 4-4*in[0]-4*in[1]-8*in[2];
342 out[7] = 4*in[0];
343 out[8] = 4*in[1];
344 out[9] = 1;
345 break;
346 default:
347 DUNE_THROW(RangeError, "Component out of range.");
348 }
349 } else {
350 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
351 }
352 }
353
356 unsigned int order () const
357 {
358 return 2;
359 }
360
361 };
362}
363#endif
A dense n x m matrix.
Definition: fmatrix.hh:117
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:108
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:51
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:83
unsigned int size() const
number of shape functions
Definition: hierarchicalsimplexp2localbasis.hh:54
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:72
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:60
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:140
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:179
unsigned int size() const
number of shape functions
Definition: hierarchicalsimplexp2localbasis.hh:143
unsigned int order() const
Polynomial order of the shape functions (2 in this case)
Definition: hierarchicalsimplexp2localbasis.hh:217
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:165
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:149
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:253
void evaluateFunction(const typename Traits::DomainType &in, std::vector< typename Traits::RangeType > &out) const
Evaluate all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:262
void evaluateJacobian(const typename Traits::DomainType &in, std::vector< typename Traits::JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: hierarchicalsimplexp2localbasis.hh:280
unsigned int size() const
number of shape functions
Definition: hierarchicalsimplexp2localbasis.hh:256
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:298
unsigned int order() const
Polynomial order of the shape functions (2 in this case)
Definition: hierarchicalsimplexp2localbasis.hh:356
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:291
Dune namespace.
Definition: alignedallocator.hh:13
Type traits for LocalBasisVirtualInterface.
Definition: localbasis.hh:34
D DomainType
domain type
Definition: localbasis.hh:42
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)