DUNE PDELab (git)

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