PDE solvers · Waves and transport (hyperbolic)
The Euler equations of gas dynamics
- Method
- finite volumes with the HLL approximate Riemann flux, first order; the exact solution is computed alongside
- Checked
- Sod's shock tube: the exact solution against the jump conditions, then the computed plateau, shock position, conservation and L1 convergence against it
Mass, momentum and energy of a compressible gas, with . Sod's problem is a membrane at with dense, high-pressure gas on the left; at it bursts. Three waves come out: a rarefaction fan moving left, a contact discontinuity (density jumps, pressure and velocity do not) and a shock, both moving right.
Finite volumes store cell averages and move them by the fluxes through the cell walls, so whatever leaves one cell enters the next and the totals are conserved to rounding — which is what puts shocks at the right speed. The flux at a wall is a Riemann problem between the two neighbors. HLL does not solve it; it keeps only the fastest left- and right-going signal speeds and the one averaged state between them, which gives , with , .
The exact solution needs one number, the pressure between the waves, which solves ; is a shock branch or a rarefaction branch depending on the side of that falls. It is monotone, so bisection finds it. Everything else follows in closed form. The jump conditions across the shock are tested directly from the conservation laws, so the exact solution is not taken on trust either.
A first-order scheme smears the contact over many cells (like ) and the shock over a few, so in the L1 norm it converges at an order below one. That is measured, not hidden.
What the run shows
- the exact shock obeys the jump conditions: mass and momentum through it balance
- and energy: (E + p)(u - S) + p S balances across it
- mass and energy are conserved to rounding
- momentum grows by exactly the pressure difference times the time
- between contact and shock the computed velocity and pressure sit on the exact plateau
- the shock is where the exact solution puts it, to within a cell
- the density converges in L1, at an order below one: the contact smears like sqrt(t)
- P_STAR
- 0.30313
- U_STAR
- 0.927453
- RHO_STAR_L
- 0.426319
- RHO_STAR_R
- 0.265574
- SHOCK_SPEED
- 1.75216
- mass
- 0.5625
- energy
- 1.375
- momentum
- 0.18
- plateau_u
- 0.927563
- plateau_p
- 0.30316
- x_shock
- 0.850431
- found_shock
- 0.850935
- err_200
- 0.0102339
- err_400
- 0.00648211
- l1_order
- 0.658826
Computed when this page was built, by the same interpreter that runs it in your browser: 7 of 7 tests,
under 0.1 s. The numbers above are the program's show lines.
The program
245 lines, 10 functions. It is editable: change it and press Run (or ⌘/Ctrl + Enter). The tests at the bottom run too, so if your change breaks the solver, a test fails.
pressure_term- One side's term in the pressure equation: a shock if p is above that side's pressure, a rarefaction if below.
star_pressure- The pressure between the waves, by bisection. Both gases start at rest.
exact_density- The exact density at the points x, at time t: left state, fan, two plateaus, right state.
pressure- Pressure from the conserved variables, a 3 x m array of (rho, rho u, E).
physical_flux- The physical flux of each cell's state.
hll_flux- The HLL flux through every cell's RIGHT wall (column i: between cells i and i + 1).
initial_state- Sod's initial state on n cells plus one ghost cell at each end.
solve_sod- March n cells to T_END at a Courant number of 0.9. The ghost cells copy their neighbors.
centers- Cell centers, ghosts included.
density_error- L1 error of the density over the interior cells.