Sei sulla pagina 1di 10

WENO-based first and second centered derivatives

This document derives the coefficients necessary to implement WENO-based derivatives following ideas from the
following papers:
1. Jiang and Peng, Weighted ENO schemes for Hamilton--Jacobit Equations, SIAM J. Sci. Comput. 2000
2. Shu, High order weighted essentially nonoscillatory schemes for convection dominated problems, SIAM Review
2009
3. Martin, Taylor, Wu, and Weirs, A bandwidth-optimized WENO scheme for the effective direct numerical simula-
tion of compressible turbulence, J. Comput. Phys 2006
Note that the order-of-accuracy of these schemes is optimized, not their bandwidth.
Initialization
Build a list of uniform gridpoints with spacing x and function values f
i
. Use that list to build the j
th
interpolating
polynomial for j 1, ..., r.
In[1]:= StencilPoints[r_] : Table[{i x, u
i
}, {i, (r 1), (r 1)}]
SubstencilPoints[r_, j_] : Take[StencilPoints[r], {j, j r 1}]
StencilPolynomial[r_, j_] :
Collect]InterpolatingPolynomial[SubstencilPoints[r, j], x], u
_
, Simplify|
Check these functions will return the three expected interpolant values at x/2 for the r = 3 case from Shus 2009
SIAM Review paper equations (2.1), (2.2), and (2.3).
In[4]:= StencilPoints[3]
Table[StencilPolynomial[3, j], {j, 3}] //. x
x
2
// Expand // MatrixForm
Out[4]= {{2 x, u
2
, {x, u
1
, {0, u
0
, {x, u
1
, {2 x, u
2

Out[5]//MatrixForm=
3 u2
8

5 u1
4

15 u0
8

u1
8

3 u0
4

3 u1
8
3 u0
8

3 u1
4

u2
8
Compute smoothness indicators following Shu 2009 equation (2.8). These smoothness indicators were originally
proposed in Jiang and Shu JCP 1996 and will likely not match those used for flux reconstruction from earlier papers.
In[6]:= StencilSmoothness[r_, j_] : Together]Expand]Sum]
x
2 d1
Integrate]D[StencilPolynomial[r, j], {x, d}]
2
, x,
x
2
,
x
2
|
, {d, r 1}|||
Check smoothness indicators against the result from Shu 2009 equation (2.9).
In[7]:= StencilSmoothness[3, 1]
StencilSmoothness[3, 2]
StencilSmoothness[3, 3]
Out[7]=
1
3
4 u
2
2
19 u
2
u
1
25 u
1
2
11 u
2
u
0
31 u
1
u
0
10 u
0
2
|
Out[8]=
1
3
4 u
1
2
13 u
1
u
0
13 u
0
2
5 u
1
u
1
13 u
0
u
1
4 u
1
2
|
Out[9]=
1
3
10 u
0
2
31 u
0
u
1
25 u
1
2
11 u
0
u
2
19 u
1
u
2
4 u
2
2
|
Using a Horner factorization of the smoothness indicators may provide a cleaner (and possibly more performant)
representation when r > 3.
In[10]:= SmoothnessFactor[r_, A_] : Map[Together, HornerForm[A, Last[Transpose[StencilPoints[r]]]]]
The optimal, full-width stencil (in terms of order of accuracy) for a given derivative at x=0 is
In[11]:= Optimal[r_, d_] :
D[InterpolatingPolynomial[StencilPoints[r], x], {x, d}] //. x 0 // Together
The stencil-by-stencil contributions for a given derivative at x = 0 are
In[12]:= Contributions[r_, d_] :
D[Table[StencilPolynomial[r, j], {j, r}], {x, d}] //. x 0 // Together
The linear weights must satisfy these constraints resulting from combining the stencil-by-stencil contributions to match
the optimal result.
In[13]:= LinearWeights[r_, d_] : Quiet]With]] Table]
j
, {j, r}|,
Solve[{
.Contributions[r, d] Optimal[r, d],
Total[] 1
}, , Reals]|| /. Rule Equal
We will need to extract tables of coefficients of u
i
.
In[14]:= CoefficientTable[r_, A_] : Table[Coefficient[A, u
i
], {i, (r 1), (r 1)}]
We will want to perform linear solves on these tables of coefficients.
In[15]:= LinearSolveWeights[r_, d_] : LinearSolve[
CoefficientTable[r, Contributions[r, d]], CoefficientTable[r, Optimal[r, d]]]
Nonlinear weights should be computed in the usual WENO manner from these linear weights following Shu 2009
equation (2.10).
3-point WENO derivative stencil
In[16]:= r 2;
First derivative
Display the optimal 3-point stencil coefficients for the derivative, the 2-point substencil coefficients, and the linear
weights necessary to recover the maximum order of accuracy.
2 WENO Centered Derivatives.nb
In[17]:= d 1;
o[r, d] Optimal[r, d]
s[r, d] Contributions[r, d]
w[r, d] LinearWeights[r, d]
Out[18]=
u
1
u
1
2 x
Out[19]=
u
1
u
0
x
,
u
0
u
1
x

Out[20]=
1

1
2
,
2

1
2

Second derivative
The r=2 case only has a trivial second derivative.
Smoothness indicators
In[21]:= Table[StencilSmoothness[r, j], {j, r}] // Simplify // MatrixForm
Out[21]//MatrixForm=
u
1
u
0
)
2
u
0
u
1
)
2
5-point WENO derivative stencils
In[22]:= r 3;
First derivative
In[23]:= d 1;
Display the optimal 5-point stencil coefficients for the derivative, the 3-point substencil coefficients, and the linear
weights necessary to recover the maximum order of accuracy.
In[24]:= o[r, d] Optimal[r, d]
s[r, d] Contributions[r, d]
w[r, d] LinearWeights[r, d]
Out[24]=
u
2
8 u
1
8 u
1
u
2
12 x
Out[25]=
u
2
4 u
1
3 u
0
2 x
,
u
1
u
1
2 x
,
3 u
0
4 u
1
u
2
2 x

Out[26]= {{
1
1
2
5 u
2
16 u
1
18 u
0
8 u
1
u
2
6 u
2

2
18 u
1

2
18 u
0

2
6 u
1

2
) /
6 u
2
24 u
1
36 u
0
24 u
1
6 u
2
),

3
5 u
2
16 u
1
18 u
0
8 u
1
u
2
6 u
2

2
18 u
1

2
18 u
0

2
6 u
1

2
) /
6 u
2
24 u
1
36 u
0
24 u
1
6 u
2
)
Brute forcing the solve for the linear weights is less fruitful in the r = 3 case. Extract the various coefficients and
perform a linear solve.
WENO Centered Derivatives.nb 3
In[27]:= CoefficientTable[r, o[r, d]] // MatrixForm
CoefficientTable[r, s[r, d]] // Transpose // MatrixForm
Out[27]//MatrixForm=
1
12 x

2
3 x
0
2
3 x

1
12 x
Out[28]//MatrixForm=
1
2 x

2
x
3
2 x
0 0
0
1
2 x
0
1
2 x
0
0 0
3
2 x
2
x

1
2 x
In[29]:= w[r, d] LinearSolveWeights[r, d]
Total[w[r, d]]
Out[29]=
1
6
,
2
3
,
1
6

Out[30]= 1
Second derivative
In[31]:= d 2;
Display the optimal 5-point stencil coefficients for the derivative, the 3-point substencil coefficients, and the linear
weights necessary to recover the maximum order of accuracy.
In[32]:= o[r, d] Optimal[r, d]
s[r, d] Contributions[r, d]
Out[32]=
u
2
16 u
1
30 u
0
16 u
1
u
2
12 x
2
Out[33]=
u
2
2 u
1
u
0
x
2
,
u
1
2 u
0
u
1
x
2
,
u
0
2 u
1
u
2
x
2

In[34]:= w[r, d] LinearSolveWeights[r, d]


Total[w[r, d]]
Out[34]=
1
12
,
7
6
,
1
12

Out[35]= 1
Smoothness indicators
In[36]:= Table[StencilSmoothness[r, j], {j, r}] // MatrixForm
Out[36]//MatrixForm=
1
3
4 u
2
2
19 u
2
u
1
25 u
1
2
11 u
2
u
0
31 u
1
u
0
10 u
0
2
|
1
3
4 u
1
2
13 u
1
u
0
13 u
0
2
5 u
1
u
1
13 u
0
u
1
4 u
1
2
|
1
3
10 u
0
2
31 u
0
u
1
25 u
1
2
11 u
0
u
2
19 u
1
u
2
4 u
2
2
|
These smoothness indicators may be factored as in Jiang and Shu JCP 1996 equations (3.2), (3.3), and (3.4).
4 WENO Centered Derivatives.nb
In[37]:= With]
IS0
13
12
(u
2
2 u
1
u
0
)
2

1
4
(u
2
4 u
1
3 u
0
)
2
,
IS1
13
12
(u
1
2 u
0
u
1
)
2

1
4
(u
1
u
1
)
2
,
IS2
13
12
(u
0
2 u
1
u
2
)
2

1
4
(3 u
0
4 u
1
u
2
)
2
,
FullSimplify[{
IS0 StencilSmoothness[3, 1],
IS1 StencilSmoothness[3, 2],
IS2 StencilSmoothness[3, 3]
}]|
Out[37]= {True, True, True
Placing the indicators into HornerForm may also reduce their computational complexity:
In[38]:= Table[SmoothnessFactor[r, StencilSmoothness[r, j]], {j, r}] // MatrixForm
Out[38]//MatrixForm=
1
3
u
1
25 u
1
31 u
0
)
10 u
0
2
3

1
3
u
2
4 u
2
19 u
1
11 u
0
)
13
3
u
0
u
0
u
1
)
4 u
1
2
3

1
3
u
1
4 u
1
13 u
0
5 u
1
)
1
3
u
1
25 u
1
19 u
2
)
4 u
2
2
3

1
3
u
0
10 u
0
31 u
1
11 u
2
)
7-point WENO derivative stencils
In[39]:= r 4;
First derivative
In[40]:= d 1;
Display the optimal 7-point stencil coefficients for the derivative, the 4-point substencil coefficients, and the linear
weights necessary to recover the maximum order of accuracy.
In[41]:= o[r, d] Optimal[r, d]
s[r, d] Contributions[r, d];
CoefficientTable[r, s[r, d]] // Transpose // MatrixForm
Out[41]=
u
3
9 u
2
45 u
1
45 u
1
9 u
2
u
3
60 x
Out[43]//MatrixForm=

1
3 x
3
2 x

3
x
11
6 x
0 0 0
0
1
6 x

1
x
1
2 x
1
3 x
0 0
0 0
1
3 x

1
2 x
1
x

1
6 x
0
0 0 0
11
6 x
3
x

3
2 x
1
3 x
In[44]:= w[r, d] LinearSolveWeights[r, d]
Total[w[r, d]]
Out[44]=
1
20
,
9
20
,
9
20
,
1
20

Out[45]= 1
WENO Centered Derivatives.nb 5
Second derivative
No full-accuracy WENO-based second derivative exists for the r=4 case with these substencils. The second and third
substencils are identical and so the resulting linear weight problem has no solution. Moreover, the repeated substencil
usage makes it unlikely that a general point discontinuity can be circumnavigated by the scheme.
In[46]:= d 2;
In[47]:= o[r, d] Optimal[r, d]
s[r, d] Contributions[r, d];
CoefficientTable[r, s[r, d]] // Transpose // MatrixForm
Out[47]=
1
180 x
2
2 u
3
27 u
2
270 u
1
490 u
0
270 u
1
27 u
2
2 u
3
)
Out[49]//MatrixForm=

1
x
2
4
x
2

5
x
2
2
x
2
0 0 0
0 0
1
x
2

2
x
2
1
x
2
0 0
0 0
1
x
2

2
x
2
1
x
2
0 0
0 0 0
2
x
2

5
x
2
4
x
2

1
x
2
In[50]:= w[r, d] LinearSolveWeights[r, d]
Total[w[r, d]]
LinearSolve::nosol : Linear equation encountered that has no solution.
Out[50]= LinearSolve|
1
x
2
, 0, 0, 0,
4
x
2
, 0, 0, 0,
5
x
2
,
1
x
2
,
1
x
2
, 0,

2
x
2
,
2
x
2
,
2
x
2
,
2
x
2
, 0,
1
x
2
,
1
x
2
,
5
x
2
, 0, 0, 0,
4
x
2
, 0, 0, 0,
1
x
2
,

1
90 x
2
,
3
20 x
2
,
3
2 x
2
,
49
18 x
2
,
3
2 x
2
,
3
20 x
2
,
1
90 x
2
|
Out[51]=
89
90 x
2
,
1
90 x
2
,
1
90 x
2
,
1
90 x
2
,

77
20 x
2
,
3
20 x
2
,
3
20 x
2
,
3
20 x
2
,
7
2 x
2
,
5
2 x
2
,
5
2 x
2
,
3
2 x
2
,

13
18 x
2
,
85
18 x
2
,
85
18 x
2
,
13
18 x
2
,
3
2 x
2
,
5
2 x
2
,
5
2 x
2
,
7
2 x
2
,

3
20 x
2
,
3
20 x
2
,
3
20 x
2
,
77
20 x
2
,
1
90 x
2
,
1
90 x
2
,
1
90 x
2
,
89
90 x
2

Smoothness indicators
In[52]:= Do]Print]IS
(j1)
StencilSmoothness[r, j]|, {j, r}|
6 WENO Centered Derivatives.nb
IS
0

1
2880
6649 u
3
2
47214 u
3
u
2
85641 u
2
2
56694 u
3
u
1

210282 u
2
u
1
134241 u
1
2
22778 u
3
u
0
86214 u
2
u
0
114894 u
1
u
0
25729 u
0
2
|
IS
1

1
2880
3169 u
2
2
19374 u
2
u
1
33441 u
1
2
19014 u
2
u
0

70602 u
1
u
0
41001 u
0
2
5978 u
2
u
1
23094 u
1
u
1
30414 u
0
u
1
6649 u
1
2
|
IS
2

1
2880
6649 u
1
2
30414 u
1
u
0
41001 u
0
2
23094 u
1
u
1

70602 u
0
u
1
33441 u
1
2
5978 u
1
u
2
19014 u
0
u
2
19374 u
1
u
2
3169 u
2
2
|
IS
3

1
2880
25729 u
0
2
114894 u
0
u
1
134241 u
1
2
86214 u
0
u
2

210282 u
1
u
2
85641 u
2
2
22778 u
0
u
3
56694 u
1
u
3
47214 u
2
u
3
6649 u
3
2
|
In[53]:= Do]Print]IS
(j1)
SmoothnessFactor[r, StencilSmoothness[r, j]]|, {j, r}|
IS
0

1
960
u
1
44747 u
1
38298 u
0
)
u
3
6649 u
3
47214 u
2
56694 u
1
22778 u
0
)
2880

25729 u
0
2
2880

1
960
u
2
28547 u
2
70094 u
1
28738 u
0
)
IS
1

1
960
u
0
13667 u
0
10138 u
1
)
u
2
3169 u
2
19374 u
1
19014 u
0
5978 u
1
)
2880

6649 u
1
2
2880

1
960
u
1
11147 u
1
23534 u
0
7698 u
1
)
IS
2

1
960
u
1
11147 u
1
6458 u
2
)
u
1
6649 u
1
30414 u
0
23094 u
1
5978 u
2
)
2880

3169 u
2
2
2880

1
960
u
0
13667 u
0
23534 u
1
6338 u
2
)
IS
3

u
0
25729 u
0
114894 u
1
86214 u
2
22778 u
3
)
2880

1
960
u
2
28547 u
2
15738 u
3
)
6649 u
3
2
2880

1
960
u
1
44747 u
1
70094 u
2
18898 u
3
)
9-point WENO derivative stencils
In[54]:= r 5;
First derivative
In[55]:= d 1;
Display the optimal 9-point stencil coefficients for the derivative, the 5-point substencil coefficients, and the linear
weights necessary to recover the maximum order of accuracy.
WENO Centered Derivatives.nb 7
In[56]:= o[r, d] Optimal[r, d]
s[r, d] Contributions[r, d];
CoefficientTable[r, s[r, d]] // Transpose // MatrixForm
Out[56]=
1
840 x
3 u
4
32 u
3
168 u
2
672 u
1
672 u
1
168 u
2
32 u
3
3 u
4
)
Out[58]//MatrixForm=
1
4 x

4
3 x
3
x

4
x
25
12 x
0 0 0 0
0
1
12 x
1
2 x

3
2 x
5
6 x
1
4 x
0 0 0
0 0
1
12 x

2
3 x
0
2
3 x

1
12 x
0 0
0 0 0
1
4 x

5
6 x
3
2 x

1
2 x
1
12 x
0
0 0 0 0
25
12 x
4
x

3
x
4
3 x

1
4 x
In[59]:= w[r, d] LinearSolveWeights[r, d]
Total[w[r, d]]
Out[59]=
1
70
,
8
35
,
18
35
,
8
35
,
1
70

Out[60]= 1
Second derivative
In[61]:= d 2;
Display the optimal 7-point stencil coefficients for the derivative, the 4-point substencil coefficients, and the linear
weights necessary to recover the maximum order of accuracy.
In[62]:= o[r, d] Optimal[r, d]
s[r, d] Contributions[r, d];
CoefficientTable[r, s[r, d]] // Transpose // MatrixForm
Out[62]=
1
5040 x
2
9 u
4
128 u
3
1008 u
2
8064 u
1
14350 u
0
8064 u
1
1008 u
2
128 u
3
9 u
4
)
Out[64]//MatrixForm=
11
12 x
2

14
3 x
2
19
2 x
2

26
3 x
2
35
12 x
2
0 0 0 0
0
1
12 x
2
1
3 x
2
1
2 x
2

5
3 x
2
11
12 x
2
0 0 0
0 0
1
12 x
2
4
3 x
2

5
2 x
2
4
3 x
2

1
12 x
2
0 0
0 0 0
11
12 x
2

5
3 x
2
1
2 x
2
1
3 x
2

1
12 x
2
0
0 0 0 0
35
12 x
2

26
3 x
2
19
2 x
2

14
3 x
2
11
12 x
2
In[65]:= w[r, d] LinearSolveWeights[r, d]
Total[w[r, d]]
Out[65]=
3
1540
,
226
1155
,
293
210
,
226
1155
,
3
1540

Out[66]= 1
Smoothness indicators
In[67]:= Do]Print]IS
(j1)
StencilSmoothness[r, j]|, {j, r}|
8 WENO Centered Derivatives.nb
IS
0

1
60480
279134 u
4
2
2 569471 u
4
u
3
5 951369 u
3
2
4 503117 u
4
u
2
21022356 u
3
u
2
18768339 u
2
2

3 568693 u
4
u
1
16810942 u
3
u
1
30442116 u
2
u
1
12627689 u
1
2
1 076779 u
4
u
0

5 121853 u
3
u
0
9 424677 u
2
u
0
8 055511 u
1
u
0
1 337954 u
0
2
|
IS
1

1
60480
82364 u
3
2
725461 u
3
u
2
1 650569 u
2
2
1 186167 u
3
u
1

5 550816 u
2
u
1
4 854159 u
1
2
847303 u
3
u
0
4 054702 u
2
u
0
7 357656 u
1
u
0

2 932409 u
0
2
221869 u
3
u
1
1 079563 u
2
u
1
2 013987 u
1
u
1
1 714561 u
0
u
1
279134 u
1
2
|
IS
2

1
60480
82364 u
2
2
601771 u
2
u
1
1 228889 u
1
2
799977 u
2
u
0

3 495756 u
1
u
0
2 695779 u
0
2
461113 u
2
u
1
2 100862 u
1
u
1
3 495756 u
0
u
1

1 228889 u
1
2
98179 u
2
u
2
461113 u
1
u
2
799977 u
0
u
2
601771 u
1
u
2
82364 u
2
2
|
IS
3

1
60480
279134 u
1
2
1 714561 u
1
u
0
2 932409 u
0
2
2 013987 u
1
u
1

7 357656 u
0
u
1
4 854159 u
1
2
1 079563 u
1
u
2
4 054702 u
0
u
2
5 550816 u
1
u
2

1 650569 u
2
2
221869 u
1
u
3
847303 u
0
u
3
1 186167 u
1
u
3
725461 u
2
u
3
82364 u
3
2
|
IS
4

1
60480
1 337954 u
0
2
8 055511 u
0
u
1
12627689 u
1
2
9 424677 u
0
u
2

30442116 u
1
u
2
18768339 u
2
2
5 121853 u
0
u
3
16810942 u
1
u
3
21022356 u
2
u
3

5 951369 u
3
2
1 076779 u
0
u
4
3 568693 u
1
u
4
4 503117 u
2
u
4
2 569471 u
3
u
4
279134 u
4
2
|
In[68]:= Do]Print]IS
(j1)
SmoothnessFactor[r, StencilSmoothness[r, j]]|, {j, r}|
WENO Centered Derivatives.nb 9
IS
0

u
1
12627689 u
1
8 055511 u
0
)
60480

1
60480
u
3
5 951369 u
3
21022356 u
2
16810942 u
1
5 121853 u
0
)
668977 u
0
2
30240

1
60480
u
4
279134 u
4
2 569471 u
3
4 503117 u
2
3 568693 u
1
1 076779 u
0
)
u
2
6 256113 u
2
10147372 u
1
3 141559 u
0
)
20160
IS
1

u
0
2 932409 u
0
1 714561 u
1
)
60480

1
60480
u
2
1 650569 u
2
5 550816 u
1
4 054702 u
0
1 079563 u
1
)
139567 u
1
2
30240

1
60480
u
3
82364 u
3
725461 u
2
1 186167 u
1
847303 u
0
221869 u
1
)
u
1
1 618053 u
1
2 452552 u
0
671329 u
1
)
20160
IS
2

u
1
1 228889 u
1
601771 u
2
)
60480

1
60480
u
1
1 228889 u
1
3 495756 u
0
2 100862 u
1
461113 u
2
)
20591 u
2
2
15120

1
60480
u
2
82364 u
2
601771 u
1
799977 u
0
461113 u
1
98179 u
2
)
u
0
898593 u
0
1 165252 u
1
266659 u
2
)
20160
IS
3

1
60480
u
0
2 932409 u
0
7 357656 u
1
4 054702 u
2
847303 u
3
)
u
2
1 650569 u
2
725461 u
3
)
60480

20591 u
3
2
15120

1
60480
u
1
279134 u
1
1 714561 u
0
2 013987 u
1
1 079563 u
2
221869 u
3
)
u
1
1 618053 u
1
1 850272 u
2
395389 u
3
)
20160
IS
4

1
60480
u
1
12627689 u
1
30442116 u
2
16810942 u
3
3 568693 u
4
)
u
3
5 951369 u
3
2 569471 u
4
)
60480

139567 u
4
2
30240

1
60480
u
0
1 337954 u
0
8 055511 u
1
9 424677 u
2
5 121853 u
3
1 076779 u
4
)
u
2
6 256113 u
2
7 007452 u
3
1 501039 u
4
)
20160
10 WENO Centered Derivatives.nb

Potrebbero piacerti anche