Dune Core Modules (2.8.0)

localbasis.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_LOCALFUNCTIONS_BREZZIDOUGLASFORTINMARINI_CUBE_LOCALBASIS_HH
4#define DUNE_LOCALFUNCTIONS_BREZZIDOUGLASFORTINMARINI_CUBE_LOCALBASIS_HH
5
6#include <algorithm>
7#include <array>
8#include <bitset>
9#include <numeric>
10#include <vector>
11
14#include <dune/common/math.hh>
17
18#include <dune/localfunctions/common/localbasis.hh>
19
20namespace Dune
21{
33 template<class D, class R, unsigned int dim, unsigned int order>
35 {
36 static_assert( AlwaysFalse<D>::value,
37 "`BDFMCubeLocalBasis` not implemented for chosen `dim` and `order`." );
38 };
39
40
41#ifndef DOXYGEN
42 template<class D, class R, unsigned int dim>
43 class BDFMCubeLocalBasis<D, R, dim, 0>
44 {
45 static_assert( AlwaysFalse<D>::value,
46 "`BDFMCubeLocalBasis` not defined for order 0." );
47 };
48#endif // #ifndef DOXYGEN
49
50
56 template<class D, class R >
57 class BDFMCubeLocalBasis<D, R, 2, 1>
58 {
62
63 public:
65
68 {
69 std::fill(s_.begin(), s_.end(), 1);
70 }
71
77 BDFMCubeLocalBasis (std::bitset<4> s)
78 {
79 for (auto i : range(4))
80 s_[i] = s[i] ? -1 : 1;
81 }
82
84 unsigned int size () const { return 4; }
85
92 inline void evaluateFunction (const DomainType& in, std::vector<RangeType>& out) const
93 {
94 out.resize(4);
95
96 out[0] = {s_[0]*(in[0]-1), 0 };
97 out[1] = {s_[1]*(in[0]) , 0 };
98 out[2] = {0, s_[2]*(in[1]-1)};
99 out[3] = {0, s_[3]*(in[1]) };
100 }
101
108 inline void evaluateJacobian (const DomainType& in, std::vector<JacobianType>& out) const
109 {
110 out.resize(4);
111
112 out[0] = {{s_[0], 0}, {0, 0}};
113 out[1] = {{s_[1], 0}, {0, 0}};
114 out[2] = {{0, 0}, {0, s_[2]}};
115 out[3] = {{0, 0}, {0, s_[3]}};
116 }
117
125 void partial (const std::array<unsigned int, 2>& order,
126 const DomainType& in,
127 std::vector<RangeType>& out) const
128 {
129 if (std::accumulate(order.begin(), order.end(), 0) == 0)
130 evaluateFunction(in, out);
131 else
132 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
133 }
134
136 unsigned int order () const { return 1; }
137
138 private:
139 std::array<R, 4> s_;
140 };
141
142
148 template<class D, class R >
149 class BDFMCubeLocalBasis<D, R, 2, 2>
150 {
154
155 public:
157
160 {
161 std::fill(s_.begin(), s_.end(), 1);
162 }
163
169 BDFMCubeLocalBasis (std::bitset<4> s)
170 {
171 for (auto i : range(4))
172 s_[i] = s[i] ? -1 : 1;
173 }
174
176 unsigned int size () const { return 10; }
177
184 inline void evaluateFunction (const DomainType& in, std::vector<RangeType>& out) const
185 {
186 out.resize(10);
187
188 const auto& x = in[0];
189 const auto& y = in[1];
190
191 auto pre = 1-x;
192 out[0] = {pre*s_[0]*(3*x-1), 0};
193 out[1] = { pre*3*(2*y-1), 0};
194
195 pre = x;
196 out[2] = {pre*s_[1]*(3*x-2), 0};
197 out[3] = {pre* 3*(2*y-1), 0};
198
199 pre = 1-y;
200 out[4] = {0, pre*s_[2]*(3*y-1)};
201 out[5] = {0, pre*3*(2*x-1)};
202
203 pre = y;
204 out[6] = {0, pre*s_[3]*(3*y-2)};
205 out[7] = {0, pre*3*(2*x-1)};
206
207 out[8] = {6*x*(1-x), 0};
208
209 out[9] = {0, 6*y*(1-y)};
210 }
211
218 inline void evaluateJacobian (const DomainType& in, std::vector<JacobianType>& out) const
219 {
220 out.resize(10);
221
222 const auto& x = in[0];
223 const auto& y = in[1];
224
225 out[0] = {{s_[0]*(4-6*x), 0}, {0, 0}};
226 out[1] = {{3-6*y, 6-6*x}, {0, 0}};
227
228 out[2] = {{s_[1]*(6*x-2), 0}, {0, 0}};
229 out[3] = {{6*y-3, 6*x}, {0, 0}};
230
231 out[4] = {{0, 0}, {0, s_[2]*(4-6*y)}};
232 out[5] = {{0, 0}, {6-6*y, 3-6*x}};
233
234 out[6] = {{0, 0}, {0, s_[3]*(6*y-2)}};
235 out[7] = {{0, 0}, {6*y, 6*x-3}};
236
237 out[8] = {{6-12*x, 0}, {0, 0}};
238
239 out[9] = {{0, 0}, {0, 6-12*y}};
240 }
241
249 void partial (const std::array<unsigned int, 2>& order,
250 const DomainType& in,
251 std::vector<RangeType>& out) const
252 {
253 if (std::accumulate(order.begin(), order.end(), 0) == 0)
254 evaluateFunction(in, out);
255 else
256 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
257 }
258
260 unsigned int order () const { return 2; }
261
262 private:
263 std::array<R, 4> s_;
264 };
265
266
272 template<class D, class R >
273 class BDFMCubeLocalBasis<D, R, 2, 3>
274 {
278
279 public:
281
284 {
285 std::fill(s_.begin(), s_.end(), 1);
286 }
287
293 BDFMCubeLocalBasis (std::bitset<4> s)
294 {
295 for (auto i : range(4))
296 s_[i] = s[i] ? -1 : 1;
297 }
298
300 unsigned int size () const { return 18; }
301
308 inline void evaluateFunction (const DomainType& in, std::vector<RangeType>& out) const
309 {
310 out.resize(18);
311
312 const auto& x = in[0];
313 const auto& y = in[1];
314
315 auto pre = 1-x;
316 out[0] = {pre*s_[0]*-1*(10*x*x-8*x+1), 0};
317 out[1] = {pre* 3*(1-3*x)*(2*y-1), 0};
318 out[2] = {pre* s_[0]*-5*(6*y*y-6*y+1), 0};
319
320 pre = x;
321 out[3] = {pre*s_[1]*(10*x*x-12*x+3), 0};
322 out[4] = {pre* 3*(3*x-2)*(2*y-1), 0};
323 out[5] = {pre*s_[1]*5*(6*y*y-6*y+1), 0};
324
325 pre = 1-y;
326 out[6] = {0, pre*s_[2]*-1*(10*y*y-8*y+1)};
327 out[7] = {0, pre* 3*(1-3*y)*(2*x-1)};
328 out[8] = {0, pre*s_[2]*-5*( 6*x*x-6*x+1)};
329
330 pre = y;
331 out[9] = {0, pre*s_[3]*(10*y*y-12*y+3)};
332 out[10] = {0, pre* 3*(3*y-2)*(2*x-1)};
333 out[11] = {0, pre*s_[3]*5*(6*x*x-6*x+1)};
334
335 pre = x*(1-x);
336 out[12] = {pre* 6 , 0};
337 out[14] = {pre*30*(2*x-1), 0};
338 out[16] = {pre*18*(2*y-1), 0};
339
340 pre = y*(1-y);
341 out[13] = {0, pre* 6 };
342 out[15] = {0, pre*18*(2*x-1)};
343 out[17] = {0, pre*30*(2*y-1)};
344 }
345
352 inline void evaluateJacobian (const DomainType& in, std::vector<JacobianType>& out) const
353 {
354 out.resize(18);
355
356 const auto& x = in[0];
357 const auto& y = in[1];
358
359 out[0] = {{s_[0]*(30*x*x-36*x+9), 0}, {0, 0}};
360 out[1] = {{ 6*(6*x*y-3*x-4*y+2), 6*(3*x*x-4*x+1)}, {0, 0}};
361 out[2] = {{s_[0]*5*(6*y*y-6*y+1), s_[0]*30*(x-1)*(2*y-1)}, {0, 0}};
362
363 out[3] = {{ s_[1]*30*x*x-24*x+3, 0}, {0, 0}};
364 out[4] = {{ 6*(3*x-1)*(2*y-1), 6*x*(3*x-2)}, {0, 0}};
365 out[5] = {{s_[1]*5*(6*y*y-6*y+1), s_[1]*30*x*(2*y-1)}, {0, 0}};
366
367 out[6] = {{0, 0}, { 0, s_[2]*(30*y*y-36*y+9)}};
368 out[7] = {{0, 0}, { 6*(3*y*y-4*y+1), 6*(6*y*x-3*y-4*x+2)}};
369 out[8] = {{0, 0}, {s_[2]*30*(y-1)*(2*x-1), s_[2]*5*(6*x*x-6*x+1)}};
370
371 out[9] = {{0, 0}, { 0, s_[3]*30*y*y-24*y+3}};
372 out[10] = {{0, 0}, { 6*y*(3*y-2), 6*(3*y-1)*(2*x-1)}};
373 out[11] = {{0, 0}, {s_[3]*30*y*(2*x-1), s_[3]*5*(6*x*x-6*x+1)}};
374
375 out[12] = {{ -6*(2*x-1), 0}, {0, 0}};
376 out[14] = {{ -30*(6*x*x-6*x+1), 0}, {0, 0}};
377 out[16] = {{-18*(2*x-1)*(2*y-1), 36*x*(1-x)}, {0, 0}};
378
379 out[13] = {{0, 0}, { 0, -6*(2*y-1)}};
380 out[15] = {{0, 0}, {36*y*(1-y), -18*(2*y-1)*(2*x-1)}};
381 out[17] = {{0, 0}, { 0, -30*(6*y*y-6*y+1)}};
382 }
383
391 void partial (const std::array<unsigned int, 2>& order,
392 const DomainType& in,
393 std::vector<RangeType>& out) const
394 {
395 if (std::accumulate(order.begin(), order.end(), 0) == 0)
396 evaluateFunction(in, out);
397 else
398 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
399 }
400
402 unsigned int order () const { return 3; }
403
404 private:
405 std::array<R, 4> s_;
406 };
407
408} // namespace Dune
409
410#endif // #ifndef DUNE_LOCALFUNCTIONS_BREZZIDOUGLASFORTINMARINI_CUBE_LOCALBASIS_HH
unsigned int size() const
number of shape functions
Definition: localbasis.hh:84
unsigned int order() const
Polynomial order of the shape functions.
Definition: localbasis.hh:136
void evaluateFunction(const DomainType &in, std::vector< RangeType > &out) const
Evaluate all shape functions.
Definition: localbasis.hh:92
BDFMCubeLocalBasis()
Standard constructor.
Definition: localbasis.hh:67
void partial(const std::array< unsigned int, 2 > &order, const DomainType &in, std::vector< RangeType > &out) const
Evaluate all partial derivatives of all shape functions.
Definition: localbasis.hh:125
void evaluateJacobian(const DomainType &in, std::vector< JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: localbasis.hh:108
BDFMCubeLocalBasis(std::bitset< 4 > s)
Make set number s, where 0<= s < 16.
Definition: localbasis.hh:77
void evaluateFunction(const DomainType &in, std::vector< RangeType > &out) const
Evaluate all shape functions.
Definition: localbasis.hh:184
void partial(const std::array< unsigned int, 2 > &order, const DomainType &in, std::vector< RangeType > &out) const
Evaluate all partial derivatives of all shape functions.
Definition: localbasis.hh:249
unsigned int size() const
number of shape functions
Definition: localbasis.hh:176
BDFMCubeLocalBasis()
Standard constructor.
Definition: localbasis.hh:159
void evaluateJacobian(const DomainType &in, std::vector< JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: localbasis.hh:218
unsigned int order() const
Polynomial order of the shape functions.
Definition: localbasis.hh:260
BDFMCubeLocalBasis(std::bitset< 4 > s)
Make set number s, where 0<= s < 16.
Definition: localbasis.hh:169
BDFMCubeLocalBasis()
Standard constructor.
Definition: localbasis.hh:283
void evaluateJacobian(const DomainType &in, std::vector< JacobianType > &out) const
Evaluate Jacobian of all shape functions.
Definition: localbasis.hh:352
BDFMCubeLocalBasis(std::bitset< 4 > s)
Make set number s, where 0<= s < 16.
Definition: localbasis.hh:293
unsigned int size() const
number of shape functions
Definition: localbasis.hh:300
unsigned int order() const
Polynomial order of the shape functions.
Definition: localbasis.hh:402
void evaluateFunction(const DomainType &in, std::vector< RangeType > &out) const
Evaluate all shape functions.
Definition: localbasis.hh:308
void partial(const std::array< unsigned int, 2 > &order, const DomainType &in, std::vector< RangeType > &out) const
Evaluate all partial derivatives of all shape functions.
Definition: localbasis.hh:391
Brezzi-Douglas-Fortin-Marini shape functions on a reference cube.
Definition: localbasis.hh:35
A dense n x m matrix.
Definition: fmatrix.hh:69
vector space out of a tensor product of fields.
Definition: fvector.hh:95
Default exception for dummy implementations.
Definition: exceptions.hh:261
Traits for type conversions and type information.
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
Some useful basic math stuff.
Dune namespace.
Definition: alignedallocator.hh:11
Utilities for reduction like operations on ranges.
template which always yields a false value
Definition: typetraits.hh:124
Type traits for LocalBasisVirtualInterface.
Definition: localbasis.hh:32
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Nov 13, 23:29, 2024)