CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   System Analysis (https://www.cfd-online.com/Forums/system-analysis/)
-   -   sod's test by lax-friedrichs method (https://www.cfd-online.com/Forums/system-analysis/213119-sods-test-lax-friedrichs-method.html)

mend4x December 15, 2018 07:14

sod's test by lax-friedrichs method
 
1 Attachment(s)
hi everyone!
I've been solving Sod's Shock Tube Problem with Lax-Friedrichs method on C++. I use this link as the main one. But I face the problem with defining entropy. I found
  • density,
  • velocity,
  • pressure,
  • Mach number,
  • speed of sound;
but entropy fails. Can anyone help me with it?


P.S. I attached the archive with code and graphs

Eifoehn4 December 20, 2018 13:40

Dear mend4x,
Entropy in general is a value, which is calculated via integral relation. This means, you have to know the reference state to compare your solution. Nevertheless you can compare the difference between two neighboor cells or you can shift your solution to the correct level.
You should also check if the reference solution uses Entropy per mass or Entropy per volume.

If your calculation variables match the reference, then the problem is only a post-processing issue.

set::set() October 18, 2019 00:58

Hello, thanks for sharing. I've used your code to do some test of performance with c++. I would like to suggest to you two things.

First is. The code is far from optimal because you are doing things in consecutive loops that take the same limits. For example here:

for (int i = 0; i < nx; i++) {
x[i] = x0 + i * dx;
}

for (int i = 0; i < nx; i++) {
if (x[i] < 0) {
ro[i] = 1.;
u[i] = .0;
p[i] = 100000.;
} else if (x[i] >= 0) {
ro[i] = .125;
u[i] = .0;
p[i] = 10000.;
}
}

You can do simply:

for (int i = 0; i < nx; i++) {
x[i] = x0 + i * dx;
if (x[i] < 0) {
ro[i] = 1.;
u[i] = .0;
p[i] = 100000.;
} else if (x[i] >= 0) {
ro[i] = .125;
u[i] = .0;
p[i] = 10000.;
}
}

But this things are minor issues, the real problem is you can't rely in your code since you don't initialize variables. I have done some memory test and some arrays like this V[nx][3], Vn[nx][3], F[nx][3] take eventually random values. Since your are passing this Vn[0][j] and Vn[nx][j] to V[0][j] and V[nx][j] without assign any value to Vn your code will give you unexpected results. You can simply initialize to some value by writing this simple line:

double Vn[nx][3]{0};

thanks for sharing, cheers!


All times are GMT -4. The time now is 12:22.