-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRoeFlux2d.jl
More file actions
162 lines (127 loc) · 4.28 KB
/
RoeFlux2d.jl
File metadata and controls
162 lines (127 loc) · 4.28 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
@inline @everywhere function RoeFlux2d(
primL::Array{Float64,1},primR::Array{Float64,1},
nx::Float64,ny::Float64,side::Float64, gamma::Float64)::Array{Float64,1}
# [1] P. L. Roe, Approximate Riemann Solvers, Parameter Vectors and
# Difference Schemes, Journal of Computational Physics, 43, pp. 357-372.
#
# [2] H. Nishikawa and K. Kitamura, Very Simple, Carbuncle-Free,
# Boundary-Layer Resolving, Rotated-Hybrid Riemann Solvers,
# Journal of Computational Physics, 227, pp. 2560-2581, 2008.
# -------------------------------------------------------------------------
# Input: primL(1:4) = left state (rhoL, uL, vL, pL)
# primR(1:4) = right state (rhoR, uR, vR, pR)
# njk(2) = Face normal (L -> R). Must be a unit vector.
#
# Output: flux(1:4) = numerical flux
# wsn = half the max wave speed (to be used for time step calculations)
# -------------------------------------------------------------------------
#%Tangent vector (Do you like it? Actually, Roe flux can be implemented without any tangent vector. See "I do like CFD, VOL.1" for details.)
mx::Float64 = -ny;
my::Float64 = nx;
# Left state
rhoL::Float64 = primL[1];
uL::Float64 = primL[2];
vL::Float64 = primL[3];
unL::Float64 = uL*nx+vL*ny;
umL::Float64 = uL*mx+vL*my;
pL::Float64 = primL[4];
aL::Float64 = sqrt(gamma*pL/rhoL);
HL::Float64 = aL*aL/(gamma-1.0) + 0.5*(uL*uL+vL*vL);
# Right state
rhoR::Float64 = primR[1];
uR::Float64 = primR[2];
vR::Float64 = primR[3];
unR::Float64 = uR*nx+vR*ny;
umR::Float64 = uR*mx+vR*my;
pR::Float64 = primR[4];
aR::Float64 = sqrt(gamma*pR/rhoR);
HR::Float64 = aR*aR/(gamma-1.0) + 0.5*(uR*uR+vR*vR);
# First compute the Roe Averages
RT::Float64 = sqrt(rhoR/rhoL);
rho::Float64 = RT*rhoL;
u::Float64 = (uL+RT*uR)/(1.0+RT);
v::Float64 = (vL+RT*vR)/(1.0+RT);
H::Float64 = (HL+RT* HR)/(1.0+RT);
a::Float64 = sqrt( (gamma-1.0)*(H-0.5*(u*u+v*v)) );
un::Float64 = u*nx+v*ny;
um::Float64 = u*mx+v*my;
# Wave Strengths
drho::Float64 = rhoR - rhoL;
dp::Float64 = pR - pL;
dun::Float64 = unR - unL;
dum::Float64 = umR - umL;
LdU = zeros(Float64,4);
LdU[1] = (dp - rho*a*dun )/(2.0*a*a);
LdU[2] = rho*dum;
LdU[3] = drho - dp/(a*a);
LdU[4] = (dp + rho*a*dun )/(2.0*a*a);
# Wave Speed
ws = zeros(Float64,4);
ws[1] = abs(un-a);
ws[2] = abs(un);
ws[3] = abs(un);
ws[4] = abs(un+a);
# Harten's Entropy Fix JCP(1983), 49, pp357-393:
# only for the nonlinear fields.
dws = zeros(Float64,4);
dws[1]=1.0/5.0;
if ws[1] < dws[1]
ws[1] = 0.5*( ws[1]*ws[1]/dws[1] + dws[1] );
end
dws[4]=1.0/5.0;
if ws[4] < dws[4]
ws[4] = 0.5*( ws[4]*ws[4]/dws[4] + dws[4] );
end
#Right Eigenvectors
Rv = zeros(Float64,4,4);
Rv[1,1] = 1.0;
Rv[2,1] = u - a*nx;
Rv[3,1] = v - a*ny;
Rv[4,1] = H - un*a;
Rv[1,2] = 0.0;
Rv[2,2] = mx;
Rv[3,2] = my;
Rv[4,2] = um;
Rv[1,3] = 1.0;
Rv[2,3] = u;
Rv[3,3] = v;
Rv[4,3] = 0.5*(u*u + v*v);
Rv[1,4] = 1.0;
Rv[2,4] = u + a*nx;
Rv[3,4] = v + a*ny;
Rv[4,4] = H + un*a;
#Dissipation Term
diss = zeros(Float64,4);
# @simd for i=1:4;
# @simd for j=1:4;
# diss[i] = diss[i] + ws[j]*LdU[j]*Rv[i,j];
# end
# end
for i=1:4;
for j=1:4;
diss[i] = diss[i] + ws[j]*LdU[j]*Rv[i,j];
end
end
#Compute the flux.
fL = zeros(Float64,4)
fL[1] = rhoL*unL;
fL[2] = rhoL*unL * uL + pL*nx;
fL[3] = rhoL*unL * vL + pL*ny;
fL[4] = rhoL*unL * HL;
fR = zeros(Float64,4)
fR[1] = rhoR*unR;
fR[2] = rhoR*unR * uR + pR*nx;
fR[3] = rhoR*unR * vR + pR*ny;
fR[4] = rhoR*unR * HR;
flux = zeros(Float64,4)
# flux[1] = 0.5 * (fL[1] + fR[1] - diss[1]);
# flux[2] = 0.5 * (fL[2] + fR[2] - diss[2]);
# flux[3] = 0.5 * (fL[3] + fR[3] - diss[3]);
# flux[4] = 0.5 * (fL[4] + fR[4] - diss[4]);
#wsn = 0.5*(abs(un) + a); #Normal max wave speed times half
flux[1] = -0.5 * (fL[1] + fR[1] - diss[1]) * side;
flux[2] = -0.5 * (fL[2] + fR[2] - diss[2]) * side;
flux[3] = -0.5 * (fL[3] + fR[3] - diss[3]) * side;
flux[4] = -0.5 * (fL[4] + fR[4] - diss[4]) * side;
return flux;
end