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.

Solutions · 10. The Euler equations and the Sod shock tube

School of Engineering, Nazarbayev University

Worked solutions to the three exercises of Lecture 10. Each solution is computed here and checked with assert statements against an exact identity or an independent calculation. The first code cell sets up the notebook and runs Demonstration 1 of the lecture without showing its output, because some of the solutions use its variables.

Exercise 1

Problem. 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.


Exercise 1: Strong-Shock Compression Limit (gamma + 1)/(gamma - 1) == 6.0 for Air
=================================================================================
p_L =       1.0 | p*/p_R =       3.03 | Shock Mach M_s =     1.66 | rho*_R / rho_R =  2.12459
p_L =      10.0 | p*/p_R =      21.98 | Shock Mach M_s =     4.36 | rho*_R / rho_R =  4.74931
p_L =     100.0 | p*/p_R =     210.86 | Shock Mach M_s =    13.45 | rho*_R / rho_R =  5.83860
p_L =   10000.0 | p*/p_R =   20985.82 | Shock Mach M_s =   134.12 | rho*_R / rho_R =  5.99833
p_L = 1000000.0 | p*/p_R = 2098481.44 | Shock Mach M_s =  1341.16 | rho*_R / rho_R =  5.99998

Explanation. From the Rankine–Hugoniot density relation ρR∗ρR=p∗/pR+(γ−1)/(γ+1)(γ−1)/(γ+1) (p∗/pR)+1\frac{\rho_R^*}{\rho_R} = \frac{p^*/p_R + (\gamma-1)/(\gamma+1)}{(\gamma-1)/(\gamma+1)\,(p^*/p_R) + 1}, taking the hypersonic limit p∗/pR→∞p^*/p_R \to \infty cancels p∗/pRp^*/p_R between numerator and denominator, leaving lim⁡Ms→∞ρR∗ρR=γ+1γ−1=6\lim_{M_s \to \infty} \frac{\rho_R^*}{\rho_R} = \frac{\gamma + 1}{\gamma - 1} = 6 for γ=1.4\gamma = 1.4: the work done by a very strong shock raises the temperature of the gas, while the density ratio stays bounded.


Exercise 2

Problem. 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.


Exercise 2: Two-Wave HLL Smearing of a Stationary Contact Discontinuity
=======================================================================
Exact stationary Euler flux       : [0. 1. 0.]
Two-wave HLL flux across u=0 jump : [0.76489 1.      0.     ]
Spurious HLL mass flux F_HLL[0]   : +0.764886 (matches formula +0.764886)

Explanation. Because two-wave HLL replaces the entire Riemann fan between SL=−aLS_L = -a_L and SR=+aRS_R = +a_R by a single averaged state qHLL\mathbf{q}_{\mathrm{HLL}}, it ignores the middle contact wave λ2=u=0\lambda_2 = u = 0 completely. Consequently, HLL misinterprets a benign stationary temperature/density interface as an acoustic disturbance and gives a spurious mass flux of +0.765 per unit time across a gas at rest, which is the reason for the three-wave HLLC solver of Exercise 3.


Exercise 3

Problem. 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.


Exercise 3: Implement It Yourself — Three-Wave HLLC Contact-Resolving Euler Solver
==================================================================================
HLLC flux on stationary contact: [0. 1. 0.] (exact = [0, 1, 0])
1st-Order HLL  (N=400) L1(rho) = 7.6819e-03
1st-Order HLLC (N=400) L1(rho) = 7.2395e-03 (sharper contact wave)

Summary. Restoring the middle contact wave S∗S^* in HLLC eliminates stationary contact diffusion to rounding error (10-16) and sharpens the moving Sod contact discontinuity at x=0.685x = 0.685; on 400 cells the L1L_1 density error falls from 7.7×10−37.7\times 10^{-3} to 7.2×10−37.2\times 10^{-3}.