45 static T weno3(
const T *x,
T delta,
bool plus,
T eps = 1e-6) {
47 for (
unsigned i = 0; i < 4; ++i) {
48 dx[i] = x[i + 1] - x[i];
53 T rp = (eps + FiniteDifferences::square(dx[3] - dx[2])) /
54 (eps + FiniteDifferences::square(dx[2] - dx[1]));
55 T wp = 1.0 / (1 + 2.0 * FiniteDifferences::square(rp));
56 result = dx[1] + dx[2] - wp * (dx[3] - 2.0 * dx[2] + dx[1]);
58 T rp = (eps + FiniteDifferences::square(dx[1] - dx[0])) /
59 (eps + FiniteDifferences::square(dx[2] - dx[1]));
60 T wp = 1.0 / (1 + 2.0 * FiniteDifferences::square(rp));
61 result = dx[1] + dx[2] - wp * (dx[0] - 2.0 * dx[1] + dx[2]);
64 return result / (2.0 * delta);
70 static T weno5(
const T *x,
T dx,
bool plus,
T eps = 1e-6) {
73 T v1 = (x[1] - x[0]) / dx;
74 T v2 = (x[2] - x[1]) / dx;
75 T v3 = (x[3] - x[2]) / dx;
76 T v4 = (x[4] - x[3]) / dx;
77 T v5 = (x[5] - x[4]) / dx;
79 T p1 = v1 / 3.0 - 7 * v2 / 6.0 + 11 * v3 / 6.0;
80 T p2 = -v2 / 6.0 + 5 * v3 / 6.0 + v4 / 3.0;
81 T p3 = v3 / 3.0 + 5 * v4 / 6.0 - v5 / 6.0;
83 T s1 = 13 / 12.0 * FiniteDifferences::square(v1 - 2 * v2 + v3) +
84 1 / 4.0 * FiniteDifferences::square(v1 - 4 * v2 + 3 * v3);
85 T s2 = 13 / 12.0 * FiniteDifferences::square(v2 - 2 * v3 + v4) +
86 1 / 4.0 * FiniteDifferences::square(v2 - v4);
87 T s3 = 13 / 12.0 * FiniteDifferences::square(v3 - 2 * v4 + v5) +
88 1 / 4.0 * FiniteDifferences::square(3 * v3 - 4 * v4 + v5);
90 T al1 = 0.1 / (eps + s1);
91 T al2 = 0.6 / (eps + s2);
92 T al3 = 0.3 / (eps + s3);
94 T alsum = al1 + al2 + al3;
100 return w1 * p1 + w2 * p2 + w3 * p3;
102 T v1 = (x[6] - x[5]) / dx;
103 T v2 = (x[5] - x[4]) / dx;
104 T v3 = (x[4] - x[3]) / dx;
105 T v4 = (x[3] - x[2]) / dx;
106 T v5 = (x[2] - x[1]) / dx;
108 T p1 = v1 / 3.0 - 7 * v2 / 6.0 + 11 * v3 / 6.0;
109 T p2 = -v2 / 6.0 + 5 * v3 / 6.0 + v4 / 3.0;
110 T p3 = v3 / 3.0 + 5 * v4 / 6.0 - v5 / 6.0;
112 T s1 = 13 / 12.0 * FiniteDifferences::square(v1 - 2 * v2 + v3) +
113 1 / 4.0 * FiniteDifferences::square(v1 - 4 * v2 + 3 * v3);
114 T s2 = 13 / 12.0 * FiniteDifferences::square(v2 - 2 * v3 + v4) +
115 1 / 4.0 * FiniteDifferences::square(v2 - v4);
116 T s3 = 13 / 12.0 * FiniteDifferences::square(v3 - 2 * v4 + v5) +
117 1 / 4.0 * FiniteDifferences::square(3 * v3 - 4 * v4 + v5);
119 T al1 = 0.1 / (eps + s1);
120 T al2 = 0.6 / (eps + s2);
121 T al3 = 0.3 / (eps + s3);
123 T alsum = al1 + al2 + al3;
129 return w1 * p1 + w2 * p2 + w3 * p3;