-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEuler_HLLC.cpp
181 lines (162 loc) · 4.54 KB
/
Euler_HLLC.cpp
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include "1D_BTCS.h"
using namespace std;
void Euler_hllc()
{
int nx = 256;
double dx = 1.0 / nx;
double dt = 0.0001;
double t = 0.2;
int nt = ceil(t / dt);
vector<double> x(nx, 0);
vector<vector<double>> qt(3, vector<double>(nx, 0));//temperory array by RK3 scheme
vector<vector<vector<double>>> q(nt, vector<vector<double>>(3, vector<double>(nx, 0)));//all timesteps
vector<vector<double>> r(3, vector<double>(nx, 0));//general spatial FD
double gamma = 1.4;//specific gas ratio
//Sod's Riemann problem
//left side
double rhoL = 1.0;
double uL = 0.0;
double pL = 1.0;
//right side
double rhoR = 0.125;
double uR = 0.0;
double pR = 0.1;
double rho, u, p, e = 0;
//grid
for (int i = 0; i < nx; i++)
{
x[i] = (i + 0.5) * dx;
}
double xc = 0.5;
for (int i = 0; i < nx; i++)
{
rho = x[i] > 0.5 ? rhoR : rhoL;
u = x[i] > 0.5 ? uR : uL;
p = x[i] > 0.5 ? pR : pL;
e = p / (rho * (gamma - 1.0)) + 0.5 * u * u;
q[0][0][i] = rho;
q[0][1][i] = rho * u;
q[0][2][i] = rho * e;
}
for (int j = 1; j < nt; j++)// one time step
{
rhs_hllc(nx, dx, gamma, q[j - 1], r);
for (int i = 0; i < nx; i++)
{
qt[0][i] = q[j - 1][0][i] + dt * r[0][i];
qt[1][i] = q[j - 1][1][i] + dt * r[1][i];
qt[2][i] = q[j - 1][2][i] + dt * r[2][i];
}
rhs_hllc(nx, dx, gamma, qt, r);
for (int i = 0; i < nx; i++)
{
qt[0][i] = 0.75 * q[j - 1][0][i] + 0.25 * qt[0][i] + dt / 4.0 * r[0][i];
qt[1][i] = 0.75 * q[j - 1][1][i] + 0.25 * qt[1][i] + dt / 4.0 * r[1][i];
qt[2][i] = 0.75 * q[j - 1][2][i] + 0.25 * qt[2][i] + dt / 4.0 * r[2][i];
}
rhs_hllc(nx, dx, gamma, qt, r);
for (int i = 0; i < nx; i++)
{
q[j][0][i] = q[j - 1][0][i] / 3.0 + 2.0 / 3.0 * qt[0][i] + dt * 2.0 / 3.0 * r[0][i];
q[j][1][i] = q[j - 1][1][i] / 3.0 + 2.0 / 3.0 * qt[1][i] + dt * 2.0 / 3.0 * r[1][i];
q[j][2][i] = q[j - 1][2][i] / 3.0 + 2.0 / 3.0 * qt[2][i] + dt * 2.0 / 3.0 * r[2][i];
}
}
ofstream outfile("hllc.dat");
if (outfile.is_open())
{
for (int m = 0; m < 3; m++)
{
for (int i = 0; i < nx; i++)
{
outfile << q[nt - 1][m][i] << " ";
}
outfile << endl;
}
outfile << endl;
}
else
{
std::cerr << "Error: unable to open file for writing" << std::endl;
}
return;
}
void rhs_hllc(int nx, double dx, double gamma, vector<vector<double>> q, vector<vector<double>>& r)
{
//left and right side fluxes at the interface
vector<vector<double>> qL(3, vector<double>(nx + 1, 0));
vector<vector<double>> qR(3, vector<double>(nx + 1, 0));
vector<vector<double>> fL(3, vector<double>(nx + 1, 0));
vector<vector<double>> fR(3, vector<double>(nx + 1, 0));
vector<vector<double>> f(3, vector<double>(nx + 1, 0));
qL = wenoL_roe(nx, q);
qR = wenoR_roe(nx, q);
flux_roe(nx, gamma, qL, fL);
flux_roe(nx, gamma, qR, fR);
hllc(nx, gamma, qL, qR, f, fL, fR);
for (int i = 0; i < nx; i++)
{
for (int m = 0; m < 3; m++)
{
r[m][i] = -(f[m][i + 1] - f[m][i]) / dx;
}
}
return;
}
void hllc(int nx, double gamma, vector<vector<double>> uL, vector<vector<double>> uR, vector<vector<double>>& f, vector<vector<double>> fL, vector<vector<double>> fR)
{
vector<double> Ds(3, 0);
Ds[1] = 1.0;
double gm = gamma - 1.0;
for (int i = 0; i < nx + 1; i++)
{
//Leftand right states :
double rhLL = uL[0][i];
double uuLL = uL[1][i] / rhLL;
double eeLL = uL[2][i] / rhLL;
double ppLL = gm * (eeLL * rhLL - 0.5 * rhLL * (uuLL * uuLL));
double aaLL = sqrt(abs(gamma * ppLL / rhLL));
double rhRR = uR[0][i];
double uuRR = uR[1][i] / rhRR;
double eeRR = uR[2][i] / rhRR;
double ppRR = gm * (eeRR * rhRR - 0.5 * rhRR * (uuRR * uuRR));
double aaRR = sqrt(abs(gamma * ppRR / rhRR));
// compute SLand Sr
double SL = min(uuLL, uuRR) - max(aaLL, aaRR);
double SR = max(uuLL, uuRR) + max(aaLL, aaRR);
// compute compound speed
double SP = (ppRR - ppLL + rhLL * uuLL * (SL - uuLL) - rhRR * uuRR * (SR - uuRR)) / (rhLL * (SL - uuLL) - rhRR * (SR - uuRR)); //never get zero
// compute compound pressure
double PLR = 0.5 * (ppLL + ppRR + rhLL * (SL - uuLL) * (SP - uuLL) + rhRR * (SR - uuRR) * (SP - uuRR));
// compute D
Ds[2] = SP;
if (SL >= 0.0)
{
for (int m = 0; m < 3; m++)
{
f[m][i] = fL[m][i];
}
}
else if (SR <= 0.0)
{
for (int m = 0; m < 3; m++)
{
f[m][i] = fR[m][i];
}
}
else if ((SP >= 0.0) & (SL <= 0.0))
{
for (int m = 0; m < 3; m++)
{
f[m][i] = (SP * (SL * uL[m][i] - fL[m][i]) + SL * PLR * Ds[m]) / (SL - SP);
}
}
else if ((SP <= 0.0) & (SR >= 0.0))
{
for (int m = 0; m < 3; m++)
{
f[m][i] = (SP * (SR * uR[m][i] - fR[m][i]) + SR * PLR * Ds[m]) / (SR - SP);
}
}
}
}