Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

10. The Euler equations and the Sod shock tube

School of Engineering, Nazarbayev University

In high-speed aerodynamics, supersonic nozzles, and detonation tubes, density, velocity, and thermodynamic internal energy evolve as an inseparable 3×33\times 3 hyperbolic conservation system: the compressible Euler equations. In 1978, Sod proposed a test problem, the rupture of a diaphragm separating high-pressure driver gas (ρL=1,uL=0,pL=1)(\rho_L=1, u_L=0, p_L=1) from low-pressure driven gas (ρR=0.125,uR=0,pR=0.1)(\rho_R=0.125, u_R=0, p_R=0.1), which produces all three wave families of gas dynamics: a left-running isentropic rarefaction fan, a middle entropy-carrying contact discontinuity, and a right-running supersonic shock wave. In this lecture we compute the exact solution of the Riemann problem by Newton iteration on the pressure (burgers_riemann.exact_sod_shock_tube), compare 1st-order HLL vs. 2nd-order MUSCL–minmod shock-capturing (euler_1d_sod_shock_tube), and implement a three-wave HLLC contact-resolving Riemann flux.

Learning objectives

  1. Formulate the 1-D compressible Euler conservation vector q=[ρ,ρu,E]⊤\mathbf{q} = [\rho, \rho u, E]^\top, ideal-gas equation of state p=(γ−1)(E−12ρu2)p = (\gamma - 1)(E - \frac{1}{2}\rho u^2), and characteristic wave speeds (u−a,u,u+a)(u - a, u, u + a).

  2. Compute the exact solution of the Sod shock-tube problem (burgers_riemann.exact_sod_shock_tube), checking isentropic invariance across the rarefaction, pressure/velocity continuity across the contact wave, and Rankine–Hugoniot shock jumps.

  3. Compare 1st-order HLL (muscl=False) against 2nd-order MUSCL–minmod + SSP-RK2 (muscl=True) in euler_1d_sod_shock_tube, verifying integral conservation of mass, momentum, and total energy.

  4. Diagnose HLL smearing of stationary contact discontinuities and implement the three-wave HLLC Riemann solver from scratch.

Time: about 60 min

1. 1-D Compressible Euler Equations and the exact solution of the Sod problem

Neglecting viscosity and heat conduction, compressible conservation of mass, momentum, and total energy per unit volume E=ρe+12ρu2E = \rho e + \frac{1}{2}\rho u^2 reads:

∂∂t[ρρuE]+∂∂x[ρuρu2+pu(E+p)]=0,p=(γ−1)(E−12ρu2),a=γpρ(1.1)\frac{\partial}{\partial t}\begin{bmatrix} \rho \\ \rho u \\ E \end{bmatrix} + \frac{\partial}{\partial x}\begin{bmatrix} \rho u \\ \rho u^2 + p \\ u(E + p) \end{bmatrix} = \mathbf{0}, \qquad p = (\gamma - 1)\left(E - \frac{1}{2}\rho u^2\right), \qquad a = \sqrt{\frac{\gamma p}{\rho}} \tag{1.1}

where γ=cp/cv\gamma = c_p / c_v (γ=1.4\gamma = 1.4 for diatomic air, constants.GAMMA_AIR) and aa is the isentropic speed of sound. The 3×33\times 3 flux Jacobian ∂F/∂q\partial\mathbf{F}/\partial\mathbf{q} possesses three real eigenvalues:

λ1=u−a    (left acoustic),λ2=u    (entropy / contact),λ3=u+a    (right acoustic)(1.2)\lambda_1 = u - a \;\;\text{(left acoustic)}, \qquad \lambda_2 = u \;\;\text{(entropy / contact)}, \qquad \lambda_3 = u + a \;\;\text{(right acoustic)} \tag{1.2}

In Sod’s (1978) shock tube (x∈[0,1]x \in [0, 1], diaphragm at x0=0.5x_0 = 0.5, (ρL,uL,pL)=(1,0,1)(\rho_L, u_L, p_L) = (1, 0, 1) and (ρR,uR,pR)=(0.125,0,0.1)(\rho_R, u_R, p_R) = (0.125, 0, 0.1)):

  • λ1=u−a\lambda_1 = u - a (Left Rarefaction): Expands isentropically (p/ργ=pL/ρLγ=1p / \rho^\gamma = p_L / \rho_L^\gamma = 1) down to star pressure p∗p^* and density ρL∗=ρL(p∗/pL)1/γ\rho_L^* = \rho_L (p^*/p_L)^{1/\gamma}.

  • λ2=u∗\lambda_2 = u^* (Contact Discontinuity at x0+u∗tx_0 + u^* t): Pressure p∗p^* and velocity u∗u^* are continuous, while density jumps from ρL∗\rho_L^* down to hotter, higher-entropy ρR∗\rho_R^*.

  • λ3=u+a\lambda_3 = u + a (Right Shock at speed SR>aRS_R > a_R): Irreversibly compresses driven gas across Rankine–Hugoniot jump relations, increasing entropy indicator p/ργp/\rho^\gamma.


Demonstration 1: Exact Sod Shock Tube — 5 Regions, Entropy Jump & Rankine-Hugoniot check
========================================================================================
Exact Sod star values (gamma=1.4): p* = 0.303130, u* = 0.927453
Contact density jump: rho*_L = 0.426319 -> rho*_R = 0.265574 | Shock speed S_R = 1.752156
Rankine-Hugoniot residuals across S_R: mass=2.78e-17, mom=1.11e-16, energy=2.22e-16
<Figure size 1188x440 with 2 Axes>

Figure 10.1. Exact solution of the Sod problem at t=0.20t = 0.20. (a) Density, pressure and velocity; the vertical lines mark the contact discontinuity and the shock. (b) The quantity p/ργp/\rho^\gamma, which is constant along the rarefaction and changes at the contact discontinuity and at the shock.

What Demonstration 1 shows. Panel (b) shows p/ργp/\rho^\gamma. It stays at 1.000 across the whole rarefaction, because the expansion is smooth and reversible. It jumps to 1.940 at the contact discontinuity (x=0.685x = 0.685), which separates the expanded driver gas from the gas that the shock has passed, and falls to 1.838=0.1/0.1251.41.838 = 0.1/0.125^{1.4} at the shock (x=0.850x = 0.850), the value of the undisturbed gas on the right. The shock therefore raises p/ργp/\rho^\gamma from 1.838 to 1.940: the entropy increases across it.


2. 1st-Order HLL vs. 2nd-Order MUSCL–minmod (euler_1d_sod_shock_tube)

We now solve the Sod shock tube numerically on N=400N = 400 cells via burgers_riemann.euler_1d_sod_shock_tube comparing muscl=False (1st-order piecewise-constant HLL) against muscl=True (2nd-order minmod slope reconstruction + HLL + SSP-RK2), and verify exact integral conservation of total mass, momentum impulse (pL−pR)t(p_L - p_R)t, and total energy.


Demonstration 2: 1st-Order HLL vs 2nd-Order MUSCL-minmod on Sod Shock Tube (N = 400)
====================================================================================
1st-Order HLL    | steps=386 | L1(rho)=7.6819e-03 | dMass=0.00e+00 | dMom=5.55e-17 | dEng=0.00e+00
2nd-Order MUSCL  | steps=388 | L1(rho)=2.6174e-03 | dMass=0.00e+00 | dMom=2.78e-17 | dEng=0.00e+00
<Figure size 1188x440 with 2 Axes>

Figure 10.2. The Sod problem on 400 cells with the first-order HLL scheme and with MUSCL reconstruction (minmod limiter), compared with the exact solution. (a) Density. (b) Velocity.

What Demonstration 2 shows. MUSCL-minmod cuts l1_rho_error by more than 2×2\times compared to 1st-order HLL, strongly sharpening the rarefaction head/tail corners, the contact discontinuity at x=0.685x = 0.685, and the right shock at x=0.850x = 0.850 while maintaining zero non-physical oscillations and exact integral conservation of mass, momentum, and total energy to 10-14.


3. Mesh Convergence Rate: Contact Discontinuities vs. Self-Steepening Shocks

We sweep grid resolution N∈{100,200,400,800}N \in \{100, 200, 400, 800\} for both muscl=False and muscl=True. Why do linear contact discontinuities converge more slowly in L1L_1 than compressive shocks? Because characteristics run parallel to a contact (λ2=u∗\lambda_2 = u^* on both sides), so numerical diffusion grows as O(t)O(\sqrt{t}) without nonlinear characteristic convergence to re-steepen it.


Demonstration 3: Mesh Refinement Sweep (N = 100..800) — 1st-Order HLL vs 2nd-Order MUSCL
========================================================================================
N = 100 | 1st-Order HLL L1(rho) = 1.9082e-02 | 2nd-Order MUSCL L1(rho) = 8.7145e-03
N = 200 | 1st-Order HLL L1(rho) = 1.2128e-02 | 2nd-Order MUSCL L1(rho) = 4.6812e-03
N = 400 | 1st-Order HLL L1(rho) = 7.6819e-03 | 2nd-Order MUSCL L1(rho) = 2.6174e-03
N = 800 | 1st-Order HLL L1(rho) = 4.8512e-03 | 2nd-Order MUSCL L1(rho) = 1.4926e-03
Observed Sod L1(rho) rates (400->800): 1st-Order HLL = 0.663 vs MUSCL = 0.810
<Figure size 748x440 with 1 Axes>

Figure 10.3. L1L_1 error of the density against the number of cells for the two schemes. Both orders are below 1 because the solution is discontinuous; the legend gives the fitted rates.

What Demonstration 3 shows. MUSCL on N=200N = 200 cells already outperforms 1st-order HLL on N=400N = 400 cells, and on N=800N = 800 cells reduces the L1L_1 density error by a factor of 3.3, mainly because the reconstruction keeps the contact discontinuity and the corners of the rarefaction sharper.


4. Specific-Heat Ratio γ\gamma Sweep

How does molecular degrees-of-freedom thermodynamics (γ=5/3≈1.667\gamma = 5/3 \approx 1.667 for monatomic Argon/Helium, γ=1.4\gamma = 1.4 for diatomic Air/N2\mathrm{N}_2, γ=1.2\gamma = 1.2 for hot polyatomic combustion products) alter shock speed SRS_R, star pressure p∗p^*, and shock compression ρR∗/ρR\rho_R^* / \rho_R?


Demonstration 4: Specific-Heat Ratio Sensitivity (Monatomic vs Air vs Polyatomic Gas)
=====================================================================================
Gas Type                  |       p* |       u* |  Shock S_R |  rho*_R / rho_R | Max Limit (g+1)/(g-1)
--------------------------------------------------------------------------------------------------
Polyatomic (gamma=1.20)   |  0.31274 |  1.01132 |    1.68290 |          2.5059 |                 11.00
Diatomic Air (gamma=1.40) |  0.30313 |  0.92745 |    1.75216 |          2.1246 |                  6.00
Monatomic Ar (gamma=5/3)  |  0.29395 |  0.84119 |    1.84447 |          1.8384 |                  4.00

Inside the algorithm

Higher γ\gamma means fewer internal rotational/vibrational modes to absorb energy, stiffening acoustic speed a=γp/ρa = \sqrt{\gamma p/\rho} so the shock propagates faster (SR=1.68→1.75→1.84S_R = 1.68 \to 1.75 \to 1.84 for γ=1.2,1.4,5/3\gamma = 1.2, 1.4, 5/3) while limiting maximum density compression below γ+1γ−1\frac{\gamma + 1}{\gamma - 1} (11.0→6.0→4.011.0 \to 6.0 \to 4.0).

Below we inspect burgers_riemann.exact_sod_shock_tube and trace the Newton–Raphson iteration on f(p∗)=fL(p∗)+fR(p∗)+(uR−uL)=0f(p^*) = f_L(p^*) + f_R(p^*) + (u_R - u_L) = 0, and check its quadratic convergence.

Check against the library


Inside the Algorithm: Toro Newton-Raphson Star-Pressure Solver in exact_sod_shock_tube
======================================================================================
def exact_sod_shock_tube(
    x: np.ndarray,
    t: float,
    x0: float = 0.5,
    gamma: float = GAMMA_AIR,
    left_state: tuple[float, float, float] = (1.0, 0.0, 1.0),
    right_state: tuple[float, float, float] = (0.125, 0.0, 0.1),
) -> dict:
    """Exact Toro (2009) Riemann solution for the 1-D compressible Euler Sod shock tube."""
    if t <= 0.0:
        raise ValueError("Time t must be strictly positive.")
    rho_l, u_l, p_l = map(float, left_state)
    rho_r, u_r, p_r = map(float, right_state)
    a_l = float(np.sqrt(gamma * p_l / rho_l))
    a_r = float(np.sqrt(gamma * p_r / rho_r))

    def wave_f(p: float, rho_k: float, p_k: float, a_k: float) -> tuple[float, float]:
        if p > p_k:
            ak = 2.0 / ((gamma + 1.0) * rho_k)
            bk = ((gamma - 1.0) / (gamma + 1.0)) * p_k
            qrt = float(np.sqrt(ak / (p + bk)))
            f_val = (p - p_k) * qrt
            df_val = qrt * (1.0 - 0.5 * (p - p_k) / (p + bk))
            return f_val, df_val
        pr = p / p_k
        f_val = (2.0 * a_k / (gamma - 1.0)) * (pr ** ((gamma - 1.0) / (2.0 * gamma)) - 1.0)
        df_val = (1.0 / (rho_k * a_k)) * (pr ** (-(gamma + 1.0) / (2.0 * gamma)))
        return float(f_val), float(df_val)

    p_star = 0.5 * (p_l + p_r)
    for _ in range(40):
        fl, dfl = wave_f(p_star, rho_l, p_l, a_l)
        fr, dfr = wave_f(p_star, rho_r, p_r, a_r)
        dp = -(fl + fr + (u_r - u_l)) / (dfl + dfr)
        p_star = max(1e-12, p_star + dp)
        if abs(dp) < 1e-13 * p_star:
            break

    fl, _ = wave_f(p_star, rho_l, p_l, a_l)
    fr, _ = wave_f(p_star, rho_r, p_r, a_r)
    u_star = 0.5 * (u_l + u_r + fr - fl)

    # Left rarefaction & right shock structure (standard Sod p_r < p_star < p_l):
    rho_star_l = rho_l * ((p_star / p_l) ** (1.0 / gamma))
    a_star_l = a_l * ((p_star / p_l) ** ((gamma - 1.0) / (2.0 * gamma)))
    gm_gp = (gamma - 1.0) / (gamma + 1.0)
    pr_ratio = p_star / p_r
    rho_star_r = rho_r * ((pr_ratio + gm_gp) / (gm_gp * pr_ratio + 1.0))
    s_shock_r = u_r + a_r * float(np.sqrt(((gamma + 1.0) / (2.0 * gamma)) * pr_ratio + (gamma - 1.0) / (2.0 * gamma)))

    xi = (np.asarray(x, dtype=float) - float(x0)) / float(t)
    rho = np.empty_like(xi)
    u = np.empty_like(xi)
    p = np.empty_like(xi)

    sh_l = u_l - a_l
    st_l = u_star - a_star_l

    m1 = xi <= sh_l
    m2 = (xi > sh_l) & (xi < st_l)
    m3 = (xi >= st_l) & (xi < u_star)
    m4 = (xi >= u_star) & (xi < s_shock_r)
    m5 = xi >= s_shock_r

    rho[m1], u[m1], p[m1] = rho_l, u_l, p_l

    u_fan = (2.0 / (gamma + 1.0)) * (a_l + 0.5 * (gamma - 1.0) * u_l + xi[m2])
    a_fan = (2.0 / (gamma + 1.0)) * (a_l + 0.5 * (gamma - 1.0) * (u_l - xi[m2]))
    rho[m2] = rho_l * ((a_fan / a_l) ** (2.0 / (gamma - 1.0)))
    u[m2] = u_fan
    p[m2] = p_l * ((a_fan / a_l) ** (2.0 * gamma / (gamma - 1.0)))

    rho[m3], u[m3], p[m3] = rho_star_l, u_star, p_star
    rho[m4], u[m4], p[m4] = rho_star_r, u_star, p_star
    rho[m5], u[m5], p[m5] = rho_r, u_r, p_r

    energy = p / (gamma - 1.0) + 0.5 * rho * (u**2)
    return {
        "x": np.asarray(x, dtype=float),
        "rho": rho,
        "u": u,
        "p": p,
        "energy": energy,
        "p_star": float(p_star),
        "u_star": float(u_star),
        "rho_star_left": float(rho_star_l),
        "rho_star_right": float(rho_star_r),
        "shock_speed": float(s_shock_r),
    }

Newton iter 1: p* = 0.245538897712679, |dp| = 3.045e-01
Newton iter 2: p* = 0.298411084566338, |dp| = 5.287e-02
Newton iter 3: p* = 0.303101195525898, |dp| = 4.690e-03
Newton iter 4: p* = 0.303130176965532, |dp| = 2.898e-05
Newton iter 5: p* = 0.303130178050647, |dp| = 1.085e-09
Newton iter 6: p* = 0.303130178050647, |dp| = 2.031e-17

Exercises

Worked solutions are in 10_solutions.ipynb. The cell below the list is a short self-check to start from.

  1. Verify a result. Sweep driver pressure pL∈{1,10,102,104,106}p_L \in \{1, 10, 10^2, 10^4, 10^6\} in exact_sod_shock_tube (ρL=1,uL=0\rho_L=1, u_L=0, right state (0.125,0,0.1)(0.125, 0, 0.1), γ=1.4\gamma = 1.4), verifying that shock Mach number Ms=SR/aRM_s = S_R / a_R grows unboundedly while post-shock compression ρR∗/ρR\rho_R^* / \rho_R approaches γ+1γ−1=6.0\frac{\gamma+1}{\gamma-1} = 6.0 monotonically from below.

  2. Find how it fails. Verify exact_sod_shock_tube raises ValueError for t≤0t \leq 0, and show algebraically and numerically that on a stationary contact jump (ρL=1,u=0,p=1)(\rho_L=1, u=0, p=1) vs. (ρR=0.125,u=0,p=1)(\rho_R=0.125, u=0, p=1), two-wave HLL produces spurious mass diffusion FHLL(1)≠0F_{\mathrm{HLL}}^{(1)} \neq 0 that smears the motionless interface.

  3. Implement it yourself. Implement hllc_euler_flux(ql, qr, gamma=1.4) (vectorized over cell faces (3, M)). Verify exact preservation of the stationary contact from Exercise 2 (FHLLC=[0,p,0]⊤F_{\mathrm{HLLC}} = [0, p, 0]^\top to 10-15), and integrate the 1st-order Sod shock tube (N=400,t=0.20N = 400, t = 0.20) with HLLC to show strictly smaller l1_rho_error than 1st-order HLL.


Self-check for the exercises
============================
MUSCL Sod check (N=120): steps = 115, L1(rho) = 7.3040e-03
All checks passed.