FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
scalar_basis.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
10#include <kernel/space/node_functional_base.hpp>
11#include <kernel/cubature/dynamic_factory.hpp>
12
13
14namespace FEAT
15{
16 namespace Space
17 {
18 namespace Bernstein2
19 {
25 namespace Intern
26 {
27 // p0, p1 and p2 are the 1D Bernstein basis functions on the reference interval [-1,+1].
28 // These are used for the tensor-product approach in the Hypercube evaluators.
29
30 // Bernstein basis function for left vertex.
31 template<typename T_>
32 inline T_ p0(T_ x)
33 {
34 return T_(0.25) * (T_(1) - T_(2) * x + x * x);
35 }
36
37 // Bernstein basis function for right vertex.
38 template<typename T_>
39 inline T_ p1(T_ x)
40 {
41 return T_(0.25) * (T_(1) + T_(2) * x + x * x);
42 }
43
44 // Bernstein basis function for edge midpoint.
45 template<typename T_>
46 inline T_ p2(T_ x)
47 {
48
49 return T_(0.5) * (T_(1) - x * x);
50 }
51
52 // The first order derivatives of the basis functions.
53
54 template<typename T_>
55 inline T_ d1p0(T_ x)
56 {
57 return T_(0.5) * (x - T_(1));
58 }
59
60 template<typename T_>
61 inline T_ d1p1(T_ x)
62 {
63 return T_(0.5) * (x + T_(1));
64 }
65
66 template<typename T_>
67 inline T_ d1p2(T_ x)
68 {
69
70 return -x;
71 }
72
73 // The second order derivatives of the basis functions.
74
75 template<typename T_>
76 inline T_ d2p0(T_)
77 {
78 return T_(0.5);
79 }
80
81 template<typename T_>
82 inline T_ d2p1(T_)
83 {
84 return T_(0.5);
85 }
86
87 template<typename T_>
88 inline T_ d2p2(T_)
89 {
90
91 return T_(-1);
92 }
93
94 // Templatefunction to evaluate the basisfunctions without having to call the function manually.
95 // This is especially great, if you need to evaluate the basisfunctions inside a for-loop.
96 template<typename T_>
97 T_ p(int i,T_ x)
98 {
99 switch (i)
100 {
101 case 0:
102 return p0(x);
103 break;
104 case 1:
105 return p1(x);
106 break;
107 case 2:
108 return p2(x);
109 default:
110 XABORTM("You can only use p0,p1,p2. The basisfunction p"+stringify( i)+" is not available.");
111 std::abort();
112 }
113 }
114
115 // q0, q1 and q2 are the 1D basis functions on the reference interval [-1,+1].
116 // These are used for the tensor-product approach in the Hypercube evaluators.
117 // The basisfunctions satisfy int_(-1,1) p_i(x)*q_j(x) dx = kron_i,j
118
119 // Orthogonal basis function for left vertex.
120 template<typename T_>
121 inline T_ q0(T_ x)
122 {
123 return T_(-0.75) - T_(1.5) * x + T_(3.75) * x * x;
124 }
125
126 // Orthogonal basis function for right vertex.
127 template<typename T_>
128 inline T_ q1(T_ x)
129 {
130 return T_(-0.75) + T_(1.5) * x + T_(3.75) * x * x;
131 }
132
133 // Orthogonal basis function for edge midpoint.
134 template<typename T_>
135 inline T_ q2(T_ x)
136 {
137 return T_(3) - T_(7.5) * x * x;
138 }
139
140 // The first order derivatives of the orthogonal basis functions.
141
142 template<typename T_>
143 inline T_ d1q0(T_ x)
144 {
145 return T_(7.5) * x - T_(1.5);
146 }
147
148 template<typename T_>
149 inline T_ d1q1(T_ x)
150 {
151 return T_(7.5) * x + T_(1.5);
152 }
153
154 template<typename T_>
155 inline T_ d1q2(T_ x)
156 {
157
158 return T_(-15) * x;
159 }
160
161 // The second order derivatives of the orthogonal basis functions.
162
163 template<typename T_>
164 inline T_ d2q0(T_)
165 {
166 return T_(7.5);
167 }
168
169 template<typename T_>
170 inline T_ d2q1(T_)
171 {
172 return T_(7.5);
173 }
174
175 template<typename T_>
176 inline T_ d2q2(T_)
177 {
178
179 return T_(-15);
180 }
181
182 // Templatefunction to evaluate the orthogonal functions without having to call the function manually.
183 // This is especially great, if you need to evaluate the orthogonal functions inside a for-loop.
184 template<typename T_>
185 T_ q(int i, T_ x)
186 {
187 switch (i)
188 {
189 case 0:
190 return q0(x);
191 break;
192 case 1:
193 return q1(x);
194 break;
195 case 2:
196 return q2(x);
197 default:
198 XABORTM("You can only use q0,q1,q2. The basisfunction q"+ stringify(i)+" is not available.");
199 std::abort();
200 }
201 }
202
203 // This function evaluates sum_{i=0}^2 koef_i *q_i(x) and is used in node_functional.
204 template<typename T_>
205 T_ base_q(T_ x, Tiny::Vector<T_, 3> koef)
206 {
207 T_ rsl = T_(0);
208 for (int qx = 0; qx < 3; ++qx)
209 {
210 rsl += koef(qx ) * q(qx, x);
211 } // end for qx
212 return rsl;
213 }
214
215 // This function evaluates sum_{i,j=0}^2 koef_i,j *q_i(x)*q_j(y) and is used in node_functional.
216 template<typename T_>
217 T_ base_q(T_ x, T_ y, Tiny::Vector<T_, 9> koef)
218 {
219 T_ rsl = T_(0);
220 for (int qx = 0; qx < 3; ++qx)
221 {
222 for (int qy = 0; qy < 3; ++qy)
223 {
224 rsl+=koef( qx * 3 + qy)* q(qx,x)*q(qy,y);
225 } // end for qy
226 } // end for qx
227 return rsl;
228 }
229
230 // This function evaluates sum_{i,j,k=0}^2 koef_i,j,k *q_i(x)*q_j(y)*q_k(z) and is used in node_functional.
231 template<typename T_>
232 T_ base_q(T_ x, T_ y, T_ z, Tiny::Vector<T_, 27> koef)
233 {
234 T_ rsl = T_(0);
235 for (int qz = 0; qz < 3; ++qz)
236 {
237 for (int qx = 0; qx < 3; ++qx)
238 {
239 for (int qy = 0; qy < 3; ++qy)
240 {
241 rsl += koef(qz*9+qx * 3 + qy) * q(qx, x) * q(qy, y)*q(qz,z);
242 } // end for qy
243 } // end for qx
244 } // end for qz
245 return rsl;
246 }
247 } // namespace Intern
248 } // namespace Bernstein2
249 } // namespace Space
250} // namespace FEAT
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
FEAT Kernel base header.
Tiny Vector class template.
FEAT namespace.
Definition: adjactor.hpp:12
String stringify(const T_ &item)
Converts an item into a String.
Definition: string.hpp:944