11 #ifndef CUBBYFLOW_PDE_IMPL_HPP 12 #define CUBBYFLOW_PDE_IMPL_HPP 21 const T invdx = 1 / dx;
22 std::array<T, 2> dfx{};
24 dfx[0] = invdx * (d0[1] - d0[0]);
25 dfx[1] = invdx * (d0[2] - d0[1]);
31 T
Upwind1(T* d0, T dx,
bool isDirectionPositive)
33 const T invdx = 1 / dx;
34 return isDirectionPositive ? (invdx * (d0[1] - d0[0]))
35 : invdx * (d0[2] - d0[1]);
41 const T hinvdx = 0.5f / dx;
42 return hinvdx * (d0[2] - d0[0]);
46 std::array<T, 2>
ENO3(T* d0, T dx)
48 const T invdx = 1 / dx;
49 const T hinvdx = invdx / 2;
50 const T tinvdx = invdx / 3;
51 T d1[6], d2[5], d3[2];
54 std::array<T, 2> dfx{};
56 d1[0] = invdx * (d0[1] - d0[0]);
57 d1[1] = invdx * (d0[2] - d0[1]);
58 d1[2] = invdx * (d0[3] - d0[2]);
59 d1[3] = invdx * (d0[4] - d0[3]);
60 d1[4] = invdx * (d0[5] - d0[4]);
61 d1[5] = invdx * (d0[6] - d0[5]);
63 d2[0] = hinvdx * (d1[1] - d1[0]);
64 d2[1] = hinvdx * (d1[2] - d1[1]);
65 d2[2] = hinvdx * (d1[3] - d1[2]);
66 d2[3] = hinvdx * (d1[4] - d1[3]);
67 d2[4] = hinvdx * (d1[5] - d1[4]);
69 for (
int k = 0; k < 2; ++k)
71 if (std::fabs(d2[k + 1]) < std::fabs(d2[k + 2]))
75 d3[0] = tinvdx * (d2[k + 1] - d2[k]);
76 d3[1] = tinvdx * (d2[k + 2] - d2[k + 1]);
82 d3[0] = tinvdx * (d2[k + 2] - d2[k + 1]);
83 d3[1] = tinvdx * (d2[k + 3] - d2[k + 2]);
86 if (std::fabs(d3[0]) < std::fabs(d3[1]))
96 T dq2 = c * (2 * (1 - k) - 1) * dx;
97 T dq3 = cstar * (3 *
Square(1 - kstar) - 6 * (1 - kstar) + 2) * dx * dx;
99 dfx[k] = dq1 + dq2 + dq3;
105 template <
typename T>
106 T
ENO3(T* d0, T dx,
bool isDirectionPositive)
108 const T invdx = 1 / dx;
109 const T hinvdx = invdx / 2;
110 const T tinvdx = invdx / 3;
111 T d1[6], d2[5], d3[2];
115 d1[0] = invdx * (d0[1] - d0[0]);
116 d1[1] = invdx * (d0[2] - d0[1]);
117 d1[2] = invdx * (d0[3] - d0[2]);
118 d1[3] = invdx * (d0[4] - d0[3]);
119 d1[4] = invdx * (d0[5] - d0[4]);
120 d1[5] = invdx * (d0[6] - d0[5]);
122 d2[0] = hinvdx * (d1[1] - d1[0]);
123 d2[1] = hinvdx * (d1[2] - d1[1]);
124 d2[2] = hinvdx * (d1[3] - d1[2]);
125 d2[3] = hinvdx * (d1[4] - d1[3]);
126 d2[4] = hinvdx * (d1[5] - d1[4]);
128 int k = isDirectionPositive ? 0 : 1;
130 if (std::fabs(d2[k + 1]) < std::fabs(d2[k + 2]))
134 d3[0] = tinvdx * (d2[k + 1] - d2[k]);
135 d3[1] = tinvdx * (d2[k + 2] - d2[k + 1]);
141 d3[0] = tinvdx * (d2[k + 2] - d2[k + 1]);
142 d3[1] = tinvdx * (d2[k + 3] - d2[k + 2]);
145 if (std::fabs(d3[0]) < std::fabs(d3[1]))
155 T dq2 = c * (2 * (1 - k) - 1) * dx;
156 T dq3 = cstar * (3 *
Square(1 - kstar) - 6 * (1 - kstar) + 2) * dx * dx;
158 return dq1 + dq2 + dq3;
161 template <
typename T>
162 std::array<T, 2>
WENO5(T* v, T h, T eps)
164 static const T c13 = T(1.0 / 3.0), c14 = T(0.25), c16 = T(1.0 / 6.0);
165 static const T c56 = T(5.0 / 6.0), c76 = T(7.0 / 6.0), c116 = T(11.0 / 6.0);
166 static const T c1312 = T(13.0 / 12.0);
168 const T hinv = T(1) / h;
169 std::array<T, 2> dfx{};
172 for (
int k = 0; k < 2; ++k)
176 for (
int m = 0; m < 5; ++m)
178 vdev[m] = (v[m + 1] - v[m]) * hinv;
183 for (
int m = 0; m < 5; ++m)
185 vdev[m] = (v[6 - m] - v[5 - m]) * hinv;
189 const T phix1 = vdev[0] * c13 - vdev[1] * c76 + vdev[2] * c116;
190 const T phix2 = -vdev[1] * c16 + vdev[2] * c56 + vdev[3] * c13;
191 const T phix3 = vdev[2] * c13 + vdev[3] * c56 - vdev[4] * c16;
193 T s1 = c1312 *
Square(vdev[0] - 2 * vdev[1] + vdev[2]) +
194 c14 *
Square(vdev[0] - 4 * vdev[1] + 3 * vdev[2]);
195 T s2 = c1312 *
Square(vdev[1] - 2 * vdev[2] + vdev[3]) +
196 c14 *
Square(vdev[1] - vdev[3]);
197 T s3 = c1312 *
Square(vdev[2] - 2 * vdev[3] + vdev[4]) +
198 c14 *
Square(3 * vdev[2] - 4 * vdev[3] + vdev[4]);
200 T alpha1 = T(0.1 /
Square(s1 + eps));
201 T alpha2 = T(0.6 /
Square(s2 + eps));
202 T alpha3 = T(0.3 /
Square(s3 + eps));
204 T sum = alpha1 + alpha2 + alpha3;
206 dfx[k] = (alpha1 * phix1 + alpha2 * phix2 + alpha3 * phix3) / sum;
212 template <
typename T>
213 T
WENO5(T* v, T h,
bool isDirectionPositive, T eps)
215 static const T c13 = T(1.0 / 3.0), c14 = T(0.25), c16 = T(1.0 / 6.0);
216 static const T c56 = T(5.0 / 6.0), c76 = T(7.0 / 6.0), c116 = T(11.0 / 6.0);
217 static const T c1312 = T(13.0 / 12.0);
219 const T hinv = T(1) / h;
222 if (isDirectionPositive)
224 for (
int m = 0; m < 5; ++m)
226 vdev[m] = (v[m + 1] - v[m]) * hinv;
231 for (
int m = 0; m < 5; ++m)
233 vdev[m] = (v[6 - m] - v[5 - m]) * hinv;
237 const T phix1 = vdev[0] * c13 - vdev[1] * c76 + vdev[2] * c116;
238 const T phix2 = -vdev[1] * c16 + vdev[2] * c56 + vdev[3] * c13;
239 const T phix3 = vdev[2] * c13 + vdev[3] * c56 - vdev[4] * c16;
241 T s1 = c1312 *
Square(vdev[0] - 2 * vdev[1] + vdev[2]) +
242 c14 *
Square(vdev[0] - 4 * vdev[1] + 3 * vdev[2]);
243 T s2 = c1312 *
Square(vdev[1] - 2 * vdev[2] + vdev[3]) +
244 c14 *
Square(vdev[1] - vdev[3]);
245 T s3 = c1312 *
Square(vdev[2] - 2 * vdev[3] + vdev[4]) +
246 c14 *
Square(3 * vdev[2] - 4 * vdev[3] + vdev[4]);
248 T alpha1 = T(0.1 /
Square(s1 + eps));
249 T alpha2 = T(0.6 /
Square(s2 + eps));
250 T alpha3 = T(0.3 /
Square(s3 + eps));
252 T sum = alpha1 + alpha2 + alpha3;
254 return (alpha1 * phix1 + alpha2 * phix2 + alpha3 * phix3) / sum;
std::array< T, 2 > ENO3(T *d0, T dx)
3rd order ENO. d0[3] is the origin.
Definition: PDE-Impl.hpp:46
std::enable_if_t< std::is_arithmetic< T >::value, T > Square(T x)
Returns the square of x.
Definition: MathUtils-Impl.hpp:154
std::array< T, 2 > WENO5(T *v, T h, T eps)
5th order WENO. d0[3] is the origin.
Definition: PDE-Impl.hpp:162
T CD2(T *d0, T dx)
2nd order central differencing. d0[1] is the origin.
Definition: PDE-Impl.hpp:39
Definition: pybind11Utils.hpp:20
std::array< T, 2 > Upwind1(T *d0, T dx)
1st order upwind differencing. d0[1] is the origin.
Definition: PDE-Impl.hpp:19