Debian Codegraph @

dune/localfunctions/raviartthomas/raviartthomas12d/raviartthomas12dlocalbasis.hh

raw symbols SCIP
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_LOCALFUNCTIONS_RAVIARTTHOMAS12DLOCALBASIS_HH
6 #define DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS12DLOCALBASIS_HH
7
8 #include <numeric>
9 #include <vector>
10
11 #include <dune/common/fmatrix.hh>
12
13 #include "../../common/localbasis.hh"
14
15 namespace Dune
16 {
17 /**
18 * \brief First order Raviart-Thomas shape functions on the reference triangle.
19 *
20 * \tparam D Type to represent the field in the domain.
21 * \tparam R Type to represent the field in the range.
22 *
23 * \nosubgrouping
24 * \ingroup RaviartThomasImpl
25 */
26 template<class D, class R>
27 class RT12DLocalBasis
28 {
29
30 public:
31 typedef LocalBasisTraits<D,2,Dune::FieldVector<D,2>,R,2,Dune::FieldVector<R,2>,
32 Dune::FieldMatrix<R,2,2> > Traits;
33
34 /**
35 * \brief Make set number s, where 0 <= s < 8
36 *
37 * \param s Edge orientation indicator
38 */
39 RT12DLocalBasis (std::bitset<3> s = 0)
40 {
41 for (size_t i=0; i<3; i++)
42 sign_[i] = (s[i]) ? -1.0 : 1.0;
43 }
44
45 //! \brief number of shape functions
46 unsigned int size () const
47 {
48 return 8;
49 }
50
51 /**
52 * \brief Evaluate all shape functions
53 *
54 * \param in Position
55 * \param out return value
56 */
57 inline void evaluateFunction (const typename Traits::DomainType& in,
58 std::vector<typename Traits::RangeType>& out) const
59 {
60 out.resize(8);
61 out[0][0] = sign_[0]*(in[0] - 4.0*in[0]*in[1]);
62 out[0][1] = sign_[0]*(-1.0 + 5.0*in[1] - 4.0*in[1]*in[1]);
63 out[1][0] = sign_[1]*(-1.0 + 5.0*in[0] - 4.0*in[0]*in[0]);
64 out[1][1] = sign_[1]*(in[1] - 4.0*in[0]*in[1]);
65 out[2][0] = sign_[2]*(-3.0*in[0] + 4.0*in[0]*in[0] + 4.0*in[1]*in[0]);
66 out[2][1] = sign_[2]*(-3.0*in[1] + 4.0*in[0]*in[1] + 4.0*in[1]*in[1]);
67 out[3][0] = -5.0*in[0] + 8.0*in[0]*in[0] + 4.0*in[1]*in[0];
68 out[3][1] = 3.0 - 6.0*in[0] - 7.0*in[1] + 8.0*in[0]*in[1] + 4.0*in[1]*in[1];
69 out[4][0] = -3.0 + 7.0*in[0] + 6.0*in[1] - 4.0*in[0]*in[0] - 8.0*in[1]*in[0];
70 out[4][1] = 5.0*in[1] - 4.0*in[0]*in[1] - 8.0*in[1]*in[1];
71 out[5][0] = in[0] - 4.0*in[0]*in[0] + 4.0*in[1]*in[0];
72 out[5][1] = -1.0*in[1] - 4.0*in[0]*in[1] + 4.0*in[1]*in[1];
73 out[6][0] = 16.0*in[0] - 16.0*in[0]*in[0] - 8.0*in[1]*in[0];
74 out[6][1] = 8.0*in[1] - 16.0*in[0]*in[1] - 8.0*in[1]*in[1];
75 out[7][0] = 8.0*in[0] - 8.0*in[0]*in[0] - 16.0*in[1]*in[0];
76 out[7][1] = 16.0*in[1] - 8.0*in[0]*in[1] - 16.0*in[1]*in[1];
77 }
78
79 /**
80 * \brief Evaluate Jacobian of all shape functions
81 *
82 * \param in Position
83 * \param out return value
84 */
85 inline void evaluateJacobian (const typename Traits::DomainType& in,
86 std::vector<typename Traits::JacobianType>& out) const
87 {
88 out.resize(8);
89
90 out[0][0][0] = sign_[0]*(1.0 - 4.0*in[1]);
91 out[0][0][1] = sign_[0]*(-4.0*in[0]);
92 out[0][1][0] = 0.0;
93 out[0][1][1] = sign_[0]*(5.0 - 8.0*in[1]);
94
95 out[1][0][0] = sign_[1]*(5.0 - 8.0*in[0]);
96 out[1][0][1] = 0.0;
97 out[1][1][0] = sign_[1]*(-4.0*in[1]);
98 out[1][1][1] = sign_[1]*(1.0 - 4.0*in[0]);
99
100 out[2][0][0] = sign_[2]*(-3.0 + 8.0*in[0] + 4.0*in[1]);
101 out[2][0][1] = sign_[2]*(4.0*in[0]);
102 out[2][1][0] = sign_[2]*(4.0*in[1]);
103 out[2][1][1] = sign_[2]*(-3.0 + 4.0*in[0] + 8.0*in[1]);
104
105 out[3][0][0] = -5.0 + 16.0*in[0] + 4.0*in[1];
106 out[3][0][1] = 4.0*in[0];
107 out[3][1][0] = -6.0 + 8.0*in[1];
108 out[3][1][1] = -7.0 + 8.0*in[0] + 8.0*in[1];
109
110 out[4][0][0] = 7.0 - 8.0*in[0] - 8.0*in[1];
111 out[4][0][1] = 6.0 - 8.0*in[0];
112 out[4][1][0] = -4.0*in[1];
113 out[4][1][1] = 5.0 - 4.0*in[0] - 16.0*in[1];
114
115 out[5][0][0] = 1.0 - 8.0*in[0] + 4*in[1];
116 out[5][0][1] = 4.0*in[0];
117 out[5][1][0] = -4.0*in[1];
118 out[5][1][1] = -1.0 - 4.0*in[0] + 8.0*in[1];
119
120 out[6][0][0] = 16.0 - 32.0*in[0] - 8.0*in[1];
121 out[6][0][1] = -8.0*in[0];
122 out[6][1][0] = -16.0*in[1];
123 out[6][1][1] = 8.0 - 16.0*in[0] - 16.0*in[1];
124
125 out[7][0][0] = 8.0 - 16.0*in[0] - 16.0*in[1];
126 out[7][0][1] = -16.0*in[0];
127 out[7][1][0] = -8.0*in[1];
128 out[7][1][1] = 16.0 - 8.0*in[0] - 32.0*in[1];
129 }
130
131 //! \brief Evaluate partial derivatives of all shape functions
132 void partial (const std::array<unsigned int, 2>& order,
133 const typename Traits::DomainType& in, // position
134 std::vector<typename Traits::RangeType>& out) const // return value
135 {
136 auto totalOrder = std::accumulate(order.begin(), order.end(), 0);
137 if (totalOrder == 0) {
138 evaluateFunction(in, out);
139 } else if (totalOrder == 1) {
140 auto const direction = std::distance(order.begin(), std::find(order.begin(), order.end(), 1));
141 out.resize(size());
142
143 switch (direction) {
144 case 0:
145 out[0][0] = sign_[0]*(1.0 - 4.0*in[1]);
146 out[0][1] = 0.0;
147 out[1][0] = sign_[1]*(5.0 - 8.0*in[0]);
148 out[1][1] = sign_[1]*(-4.0*in[1]);
149 out[2][0] = sign_[2]*(-3.0 + 8.0*in[0] + 4.0*in[1]);
150 out[2][1] = sign_[2]*(4.0*in[1]);
151 out[3][0] = -5.0 + 16.0*in[0] + 4.0*in[1];
152 out[3][1] = -6.0 + 8.0*in[1];
153 out[4][0] = 7.0 - 8.0*in[0] - 8.0*in[1];
154 out[4][1] = -4.0*in[1];
155 out[5][0] = 1.0 - 8.0*in[0] + 4*in[1];
156 out[5][1] = -4.0*in[1];
157 out[6][0] = 16.0 - 32.0*in[0] - 8.0*in[1];
158 out[6][1] = -16.0*in[1];
159 out[7][0] = 8.0 - 16.0*in[0] - 16.0*in[1];
160 out[7][1] = -8.0*in[1];
161 break;
162 case 1:
163 out[2][1] = sign_[2]*(-3.0 + 4.0*in[0] + 8.0*in[1]);
164 out[2][0] = sign_[2]*(4.0*in[0]);
165 out[1][1] = sign_[1]*(1.0 - 4.0*in[0]);
166 out[1][0] = 0.0;
167 out[0][0] = sign_[0]*(-4.0*in[0]);
168 out[0][1] = sign_[0]*(5.0 - 8.0*in[1]);
169 out[3][0] = 4.0*in[0];
170 out[3][1] = -7.0 + 8.0*in[0] + 8.0*in[1];
171 out[4][0] = 6.0 - 8.0*in[0];
172 out[4][1] = 5.0 - 4.0*in[0] - 16.0*in[1];
173 out[5][0] = 4.0*in[0];
174 out[5][1] = -1.0 - 4.0*in[0] + 8.0*in[1];
175 out[6][0] = -8.0*in[0];
176 out[6][1] = 8.0 - 16.0*in[0] - 16.0*in[1];
177 out[7][0] = -16.0*in[0];
178 out[7][1] = 16.0 - 8.0*in[0] - 32.0*in[1];
179 break;
180 default:
181 DUNE_THROW(RangeError, "Component out of range.");
182 }
183 } else {
184 DUNE_THROW(NotImplemented, "Desired derivative order is not implemented");
185 }
186 }
187
188 //! \brief Polynomial order of the shape functions
189 unsigned int order () const
190 {
191 return 2;
192 }
193
194 private:
195 std::array<R,3> sign_;
196 };
197 }
198 #endif // DUNE_LOCALFUNCTIONS_RAVIARTTHOMAS12DLOCALBASIS_HH