-
Notifications
You must be signed in to change notification settings - Fork 2
/
FD_compWise_WENO5LF1d.m
144 lines (125 loc) · 4.68 KB
/
FD_compWise_WENO5LF1d.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
function res = FD_compWise_WENO5LF1d(a,q,dx)
% *************************************************************************
%
% Component-wise Finite Difference-1d for the Euler Equations
%
% Based on:
% ---------
% Shu, Chi-Wang. "Essentially non-oscillatory and weighted essentially
% non-oscillatory schemes for hyperbolic conservation laws." Advanced
% numerical approximation of nonlinear hyperbolic equations. Springer,
% Berlin, Heidelberg, 1998. 325-432.
%
% coded by Manuel Diaz, 02.10.2012, NTU Taiwan.
% last updated on 2018.06.20, NHRI Taiwan.
% *************************************************************************
%
% Domain cells (I{i}) reference:
%
% | | u(i) | |
% | u(i-1) |___________| |
% |___________| | u(i+1) |
% | | |___________|
% ...|-----0-----|-----0-----|-----0-----|...
% | i-1 | i | i+1 |
% |- +|- +|- +|
% i-3/2 i-1/2 i+1/2 i+3/2
%
% ENO stencils (S{r}) reference:
%
%
% |___________S2__________|
% | |
% |___________S1__________| |
% | | |
% |___________S0__________| | |
% ..|---o---|---o---|---o---|---o---|---o---|...
% | I{i-2}| I{i-1}| I{i} | I{i+1}| I{i+2}|
% -|
% i+1/2
%
%
% |___________S0__________|
% | |
% | |___________S1__________|
% | | |
% | | |___________S2__________|
% ..|---o---|---o---|---o---|---o---|---o---|...
% | I{i-2}| I{i-1}| I{i} | I{i+1}| I{i+2}|
% |+
% i-1/2
%
% WENO stencil: S{i} = [ I{i-2},...,I{i+2} ]
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Careful!: by using circshift over our domain, we are implicitly creating a
% favorable code that automatically includes periodical boundary conditions.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Lax-Friedrichs (LF) Flux Splitting
v=0.5*(F(q)+a*q); u=circshift(0.5*(F(q)-a*q),[0,-1]);
%% Right Flux
% Choose the positive fluxes, 'v', to compute the left cell boundary flux:
% $u_{i+1/2}^{-}$
vmm = circshift(v,[0 2]);
vm = circshift(v,[0 1]);
vp = circshift(v,[0 -1]);
vpp = circshift(v,[0 -2]);
% Polynomials
p0n = (2*vmm - 7*vm + 11*v)/6;
p1n = ( -vm + 5*v + 2*vp)/6;
p2n = (2*v + 5*vp - vpp )/6;
% Smooth Indicators (Beta factors)
B0n = 13/12*(vmm-2*vm+v ).^2 + 1/4*(vmm-4*vm+3*v).^2;
B1n = 13/12*(vm -2*v +vp ).^2 + 1/4*(vm-vp).^2;
B2n = 13/12*(v -2*vp+vpp).^2 + 1/4*(3*v-4*vp+vpp).^2;
% Constants
d0n = 1/10; d1n = 6/10; d2n = 3/10; epsilon = 1e-6;
% Alpha weights
alpha0n = d0n./(epsilon + B0n).^2;
alpha1n = d1n./(epsilon + B1n).^2;
alpha2n = d2n./(epsilon + B2n).^2;
alphasumn = alpha0n + alpha1n + alpha2n;
% ENO stencils weigths
w0n = alpha0n./alphasumn;
w1n = alpha1n./alphasumn;
w2n = alpha2n./alphasumn;
% Numerical Flux at cell boundary, $u_{i+1/2}^{-}$;
hn = w0n.*p0n + w1n.*p1n + w2n.*p2n;
%% Left Flux
% Choose the negative fluxes, 'u', to compute the left cell boundary flux:
% $u_{i-1/2}^{+}$
umm = circshift(u,[0 2]);
um = circshift(u,[0 1]);
up = circshift(u,[0 -1]);
upp = circshift(u,[0 -2]);
% Polynomials
p0p = ( -umm + 5*um + 2*u )/6;
p1p = ( 2*um + 5*u - up )/6;
p2p = (11*u - 7*up + 2*upp)/6;
% Smooth Indicators (Beta factors)
B0p = 13/12*(umm-2*um+u ).^2 + 1/4*(umm-4*um+3*u).^2;
B1p = 13/12*(um -2*u +up ).^2 + 1/4*(um-up).^2;
B2p = 13/12*(u -2*up+upp).^2 + 1/4*(3*u -4*up+upp).^2;
% Constants
d0p = 3/10; d1p = 6/10; d2p = 1/10; epsilon = 1e-6;
% Alpha weights
alpha0p = d0p./(epsilon + B0p).^2;
alpha1p = d1p./(epsilon + B1p).^2;
alpha2p = d2p./(epsilon + B2p).^2;
alphasump = alpha0p + alpha1p + alpha2p;
% ENO stencils weigths
w0p = alpha0p./alphasump;
w1p = alpha1p./alphasump;
w2p = alpha2p./alphasump;
% Numerical Flux at cell boundary, $u_{i-1/2}^{+}$;
hp = w0p.*p0p + w1p.*p1p + w2p.*p2p;
%% Compute finite volume residual term, df/dx.
res = (hp-circshift(hp,[0,1])+hn-circshift(hn,[0,1]))/dx;
end
% Compute flux vector
function flux = F(q)
global gamma
% primary properties
rho=q(1,:); u=q(2,:)./rho; E=q(3,:); p=(gamma-1)*(E-0.5*rho.*u.^2);
% flux vector of conserved properties
flux=[rho.*u; rho.*u.^2+p; u.*(E+p)];
end