When a hydroelectric dam breaches or a tsunami surges onto a shallow coastal shelf, horizontal wavelengths vastly exceed water depth , allowing vertical hydrostatic pressure integration to collapse 3-D free-surface flow into the hyperbolic 1-D Saint-Venant shallow-water conservation system. Unlike scalar Burgers advection, shallow-water waves propagate along two coupled characteristic families , splitting an instantaneous dam break into a backward-moving depression rarefaction fan and a forward-moving hydraulic bore (shock). In this lecture we compute the exact solution of the dam-break problem over a wet bed, known as Stoker’s solution (burgers_riemann.exact_dam_break_dry_or_wet), derive and run the Harten–Lax–van Leer two-wave Riemann solver (shallow_water_1d_hll), and quantify Froude criticality and mechanical head loss across hydraulic jumps.
Learning objectives¶
Derive the 1-D Saint-Venant shallow-water conservation system, flux Jacobian eigenvalues , Riemann invariants , and Froude number .
Compute the exact solution of the dam-break problem over a wet bed (
burgers_riemann.exact_dam_break_dry_or_wet) and Rankine–Hugoniot mass/momentum jump conditions across the hydraulic bore.Formulate and benchmark the Harten–Lax–van Leer (
shallow_water_1d_hll) approximate Riemann solver, showing strict depth positivity, volume conservation, and convergence under grid refinement.Quantify Rayleigh–Bélanger energy dissipation across bores, audit centered-flux oscillations, and implement a 2nd-order MUSCL–HLL shallow-water solver.
Time: about 60 min
try: # use the installed package, or the copy in this repository
import engcfd
except ImportError:
import pathlib, subprocess, sys
for _root in [pathlib.Path.cwd(), *pathlib.Path.cwd().parents]:
if (_root / "engcfd" / "__init__.py").exists():
sys.path.insert(0, str(_root))
break
else: # on Google Colab: install from GitHub
subprocess.run([sys.executable, "-m", "pip", "install", "-q",
"git+https://github.com/ktwyw/engcfd.git"], check=True)
import engcfd
import inspect
import numpy as np
import matplotlib.pyplot as plt
from engcfd import (burgers_riemann, constants, convection_diffusion, elliptic_multigrid, grids_fvm,
lattice_boltzmann, navier_stokes, tvd_advection)
from engcfd.plotting import label_panels, panel_label, use_style
use_style()
def show_source(obj):
"""Return the source code of a library function or class."""
return inspect.getsource(obj)
def heading(text):
print(f"\n{text}\n" + "=" * len(text))1. Saint-Venant Conservation Laws, Gravity Waves & Stoker’s Exact Dam Break¶
Integrating incompressible Euler mass and horizontal momentum over water column depth under hydrostatic pressure over a flat frictionless bed yields the 1-D shallow-water system:
Evaluating the flux Jacobian gives strictly real distinct eigenvalues whenever :
For the dam-break problem over a wet bed ( at , reservoir depth across ):
Left Rarefaction Fan (): Preserves the forward Riemann invariant , giving intermediate star velocity .
Right Hydraulic Bore ( shock at speed ): Enforces Rankine–Hugoniot mass and hydrostatic-thrust jumps between and :
heading("Demonstration 1: Exact Wet-Bed Dam Break & Rankine-Hugoniot Bore Verification")
L_sw = 10.0
x_dam = 5.0
hL_sw, hR_sw = 2.0, 0.5
t_sw = 0.60
g_val = constants.G_STD
x_sw = np.linspace(0.0, L_sw, 500)
exact_db = burgers_riemann.exact_dam_break_dry_or_wet(x_sw, t=t_sw, h_left=hL_sw, h_right=hR_sw, x_dam=x_dam, g=g_val)
hs, us, S_bore = exact_db["h_star"], exact_db["u_star"], exact_db["shock_speed"]
# Verify Riemann invariant across rarefaction AND both Rankine-Hugoniot equations across bore:
inv_left = 2.0 * np.sqrt(g_val * hL_sw)
inv_star = us + 2.0 * np.sqrt(g_val * hs)
rh_mass_res = abs(S_bore * (hs - hR_sw) - hs * us)
rh_mom_res = abs(S_bore * (hs * us) - (hs * (us ** 2) + 0.5 * g_val * (hs ** 2 - hR_sw ** 2)))
print(f"Reservoir h_L = {hL_sw:.2f} m, Tailwater h_R = {hR_sw:.2f} m")
print(f"Star state: h* = {hs:.5f} m, u* = {us:.5f} m/s, Bore speed S = {S_bore:.5f} m/s")
print(f"Rarefaction invariant drift = {abs(inv_left - inv_star):.2e}")
print(f"Rankine-Hugoniot residuals = mass: {rh_mass_res:.2e}, momentum: {rh_mom_res:.2e}")
assert hR_sw < hs < hL_sw and us > 0.0 and S_bore > np.sqrt(g_val * hR_sw)
assert np.isclose(inv_left, inv_star, atol=1e-12)
assert rh_mass_res < 1e-12 and rh_mom_res < 1e-11
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10.8, 4.0))
ax1.plot(x_sw, exact_db["h"], lw=2.2, color="#1f4e79")
ax1.axvline(x_dam - np.sqrt(g_val * hL_sw) * t_sw, ls=":", color="gray", label="Rarefaction head")
ax1.axvline(x_dam + S_bore * t_sw, ls="--", color="#c0392b", label="Hydraulic bore $x_{\\mathrm{dam}} + S t$")
ax1.set_xlabel("Position $x$ [m]")
ax1.set_ylabel("Water Depth $h(x, t)$ [m]")
ax1.set_title(f"Stoker Exact Depth Profile ($t = {t_sw:.2f}$ s)")
ax1.legend(fontsize=8.5)
fr_exact = np.abs(exact_db["u"]) / np.sqrt(g_val * exact_db["h"])
ax2.plot(x_sw, exact_db["u"], lw=2.0, color="#2ca02c", label="Velocity $u(x, t)$ [m/s]")
ax2.plot(x_sw, fr_exact, lw=1.8, ls="--", color="#d62728", label="Froude $\\mathrm{Fr} = |u|/\\sqrt{gh}$ [-]")
ax2.set_xlabel("Position $x$ [m]")
ax2.set_ylabel("$u$ [m/s] or $\\mathrm{Fr}$ [-]")
ax2.set_title("Particle Velocity & Local Froude Number")
ax2.legend(fontsize=8.5)
label_panels(fig)
plt.show()
Demonstration 1: Exact Wet-Bed Dam Break & Rankine-Hugoniot Bore Verification
=============================================================================
Reservoir h_L = 2.00 m, Tailwater h_R = 0.50 m
Star state: h* = 1.10349 m, u* = 2.27815 m/s, Bore speed S = 4.16561 m/s
Rarefaction invariant drift = 0.00e+00
Rankine-Hugoniot residuals = mass: 0.00e+00, momentum: 0.00e+00

Figure 9.1. Exact solution of the dam-break problem at s. (a) Water depth; the vertical lines mark the head of the rarefaction and the bore. (b) Velocity and local Froude number.
What Demonstration 1 shows. At the solution has four zones: the undisturbed reservoir (), the rarefaction (), the constant state and the bore, which has reached and moves at , faster than the wave speed of the tailwater.
2. Harten–Lax–van Leer (HLL) Two-Wave Riemann Solver (shallow_water_1d_hll)¶
Instead of running an iterative rootfinder at every cell interface , Harten, Lax & van Leer (1983) bound the leftmost and rightmost acoustic signal speeds by and . Integrating conservation across the Riemann fan yields the closed-form HLL numerical flux:
We benchmark burgers_riemann.shallow_water_1d_hll directly against Stoker’s exact solution.
heading("Demonstration 2: HLL Approximate Riemann Solver vs exact solution")
n_hll = 400
dx_hll = L_sw / n_hll
xc_hll = (np.arange(n_hll) + 0.5) * dx_hll
h0_hll = np.where(xc_hll < x_dam, hL_sw, hR_sw)
hu0_hll = np.zeros_like(xc_hll)
n_steps_hll = 300
dt_hll = t_sw / n_steps_hll
sol_hll = burgers_riemann.shallow_water_1d_hll(h0_hll, hu0_hll, L=L_sw, dt=dt_hll, n_steps=n_steps_hll, g=g_val)
ref_hll = burgers_riemann.exact_dam_break_dry_or_wet(xc_hll, t=t_sw, h_left=hL_sw, h_right=hR_sw, x_dam=x_dam, g=g_val)
vol_init = float(np.sum(h0_hll) * dx_hll)
vol_final = float(np.sum(sol_hll["h"]) * dx_hll)
l1_h = float(np.mean(np.abs(sol_hll["h"] - ref_hll["h"])))
l1_u = float(np.mean(np.abs(sol_hll["u"] - ref_hll["u"])))
print(f"Total water volume: init = {vol_init:.6f} m^2, final = {vol_final:.6f} m^2, |drift| = {abs(vol_final - vol_init):.2e}")
print(f"HLL (N=400) L1 errors: depth = {l1_h:.4e} m, velocity = {l1_u:.4e} m/s")
assert np.isclose(vol_final, vol_init, atol=1e-12)
assert np.all(sol_hll["h"] > 0.0)
assert l1_h < 0.012 and l1_u < 0.025
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10.8, 4.0))
ax1.plot(xc_hll, ref_hll["h"], "k--", lw=1.8, label="Exact solution")
ax1.plot(xc_hll, sol_hll["h"], lw=1.8, color="#1f77b4", label="HLL FVM ($N=400$)")
ax1.set_xlabel("Position $x$ [m]")
ax1.set_ylabel("Depth $h(x, t)$ [m]")
ax1.set_title("Dam-Break Water Depth: HLL vs. Stoker")
ax1.legend()
ax2.plot(xc_hll, ref_hll["u"], "k--", lw=1.8, label="Exact solution")
ax2.plot(xc_hll, sol_hll["u"], lw=1.8, color="#2ca02c", label="HLL FVM ($N=400$)")
ax2.set_xlabel("Position $x$ [m]")
ax2.set_ylabel("Velocity $u(x, t)$ [m/s]")
ax2.set_title("Dam-Break Velocity: HLL vs. Stoker")
ax2.legend()
label_panels(fig)
plt.show()
Demonstration 2: HLL Approximate Riemann Solver vs exact solution
=================================================================
Total water volume: init = 12.500000 m^2, final = 12.500000 m^2, |drift| = 0.00e+00
HLL (N=400) L1 errors: depth = 8.3228e-03 m, velocity = 2.3981e-02 m/s

Figure 9.2. First-order finite-volume solution with the HLL flux on 400 cells (solid lines) and the exact solution (dashed lines). (a) Depth. (b) Velocity.
What Demonstration 2 shows. Without any adjustable parameter, the conservative two-wave HLL flux captures both the rarefaction slope and the position of the bore () without oscillations while conserving total water volume to 10-14.
3. Hydraulic-Bore Energy Dissipation & Subcritical-to-Supercritical Transition¶
Saint-Venant conserves mass and momentum across a hydraulic bore, but not mechanical energy. In the bore’s moving frame, turbulent roller churning dissipates specific mechanical head according to the Rayleigh–Bélanger head-loss theorem:
We sweep the tailwater-to-reservoir depth ratio to watch the post-wave star Froude number cross (transonic/supercritical transition at ).
heading("Demonstration 3: Tailwater Depth Ratio Sweep — Froude Criticality & Belanger Head Loss")
ratios_hr = [0.70, 0.40, 0.25, 0.15, 0.10, 0.04, 0.02]
fr_stars, head_losses = [], []
print(f"{'h_R / h_L':>10s} | {'h* / h_L':>9s} | {'Fr* = u*/c*':>12s} | {'S / c_L':>9s} | {'Head Loss dH/h_L':>17s}")
print("-" * 68)
for r_h in ratios_hr:
ex_r = burgers_riemann.exact_dam_break_dry_or_wet(np.array([5.0]), t=0.5, h_left=1.0, h_right=r_h, x_dam=5.0, g=g_val)
hs_r, us_r, sb_r = ex_r["h_star"], ex_r["u_star"], ex_r["shock_speed"]
fr_s = us_r / float(np.sqrt(g_val * hs_r))
dh_loss = ((hs_r - r_h) ** 3) / (4.0 * hs_r * r_h)
fr_stars.append(fr_s)
head_losses.append(dh_loss)
print(f"{r_h:10.3f} | {hs_r:9.4f} | {fr_s:12.4f} | {sb_r/np.sqrt(g_val):9.4f} | {dh_loss:17.4f}")
assert dh_loss > 0.0
# Verify subcritical Fr* < 1 at h_R/h_L = 0.15 vs supercritical Fr* > 1 at h_R/h_L = 0.10
assert fr_stars[3] < 1.0 and fr_stars[4] > 1.0
assert all(head_losses[i + 1] > head_losses[i] for i in range(len(head_losses) - 1))
Demonstration 3: Tailwater Depth Ratio Sweep — Froude Criticality & Belanger Head Loss
======================================================================================
h_R / h_L | h* / h_L | Fr* = u*/c* | S / c_L | Head Loss dH/h_L
--------------------------------------------------------------------
0.700 | 0.8431 | 0.1782 | 0.9640 | 0.0012
0.400 | 0.6627 | 0.4569 | 0.9382 | 0.0171
0.250 | 0.5517 | 0.6925 | 0.9406 | 0.0498
0.150 | 0.4576 | 0.9566 | 0.9627 | 0.1060
0.100 | 0.3962 | 1.1775 | 0.9914 | 0.1639
0.040 | 0.2863 | 1.7376 | 1.0808 | 0.3263
0.020 | 0.2224 | 2.2406 | 1.1611 | 0.4662
What Demonstration 3 shows. When tailwater is relatively deep (), the post-dam flow is subcritical () so the rarefaction tail retreats upstream of the dam. Once , turns supercritical, sweeping the rarefaction tail downstream past while fixing depth right at the dam site at critical flow ().
4. HLL Grid-Refinement Convergence¶
How fast does 1st-order shallow_water_1d_hll converge in norm when a discontinuous bore is present? We sweep at fixed Courant ratio .
heading("Demonstration 4: Grid-Refinement Convergence of shallow_water_1d_hll")
grids_sw = [100, 200, 400, 800]
errs_h_sw = []
for ng in grids_sw:
dxg = L_sw / ng
xcg = (np.arange(ng) + 0.5) * dxg
h0g = np.where(xcg < x_dam, hL_sw, hR_sw)
hu0g = np.zeros_like(xcg)
n_stg = int(round(0.75 * ng * t_sw))
dtg = t_sw / n_stg
out_g = burgers_riemann.shallow_water_1d_hll(h0g, hu0g, L=L_sw, dt=dtg, n_steps=n_stg, g=g_val)
ref_g = burgers_riemann.exact_dam_break_dry_or_wet(xcg, t=t_sw, h_left=hL_sw, h_right=hR_sw, x_dam=x_dam, g=g_val)
e_h = float(np.mean(np.abs(out_g["h"] - ref_g["h"])))
errs_h_sw.append(e_h)
print(f"N = {ng:4d} | steps = {n_stg:4d} | L1 depth error = {e_h:.4e} m")
rate_sw = float(np.log2(errs_h_sw[-2] / errs_h_sw[-1]))
print(f"Observed L1 convergence rate (400 -> 800): {rate_sw:.3f}")
assert all(errs_h_sw[i + 1] < errs_h_sw[i] for i in range(len(errs_h_sw) - 1))
assert rate_sw > 0.80
Demonstration 4: Grid-Refinement Convergence of shallow_water_1d_hll
====================================================================
N = 100 | steps = 45 | L1 depth error = 2.0462e-02 m
N = 200 | steps = 90 | L1 depth error = 1.1736e-02 m
N = 400 | steps = 180 | L1 depth error = 6.6982e-03 m
N = 800 | steps = 360 | L1 depth error = 3.7998e-03 m
Observed L1 convergence rate (400 -> 800): 0.818
Inside the algorithm¶
Even with a jump discontinuity, smearing a shock across cells of width contributes to the integral norm (unlike the norm, which saturates at across shocks), which is consistent with the observed rate of 0.82 between 400 and 800 cells (the corners of the rarefaction are also smeared, which keeps the rate below 1).
Below we inspect burgers_riemann.shallow_water_1d_hll and verify two fundamental algebraic properties of the HLL Riemann flux in pure NumPy: consistency and supercritical upwinding ( when ).
Check against the library¶
heading("Inside the Algorithm: Consistency & Supercritical Upwinding of shallow_water_1d_hll")
print(show_source(burgers_riemann.shallow_water_1d_hll))
def hll_sw_pair(hl: float, ul: float, hr: float, ur: float, g: float = constants.G_STD) -> np.ndarray:
"""Evaluate 2-component HLL shallow-water flux [F_mass, F_mom] for a single (L, R) state pair."""
hul, hur = hl * ul, hr * ur
cl, cr = np.sqrt(g * hl), np.sqrt(g * hr)
sl = min(ul - cl, ur - cr)
sr = max(ul + cl, ur + cr)
fl = np.array([hul, hul * ul + 0.5 * g * (hl ** 2)])
fr = np.array([hur, hur * ur + 0.5 * g * (hr ** 2)])
if sl >= 0.0:
return fl
if sr <= 0.0:
return fr
ql = np.array([hl, hul])
qr = np.array([hr, hur])
return (sr * fl - sl * fr + sl * sr * (qr - ql)) / (sr - sl)
# 1. Consistency F_HLL(q, q) == F(q):
f_cons = hll_sw_pair(1.8, -0.7, 1.8, -0.7)
f_exact_q = np.array([1.8 * (-0.7), 1.8 * 0.49 + 0.5 * constants.G_STD * (1.8 ** 2)])
assert np.allclose(f_cons, f_exact_q, rtol=1e-15, atol=1e-15)
# 2. Rightward supercritical flow (u > sqrt(g*h) => S_L > 0 => pure upwind F_L):
f_sup = hll_sw_pair(1.0, 5.0, 0.8, 4.5)
f_left_exact = np.array([5.0, 25.0 + 0.5 * constants.G_STD * 1.0])
assert np.allclose(f_sup, f_left_exact, rtol=1e-15, atol=1e-15)
print("HLL consistency and supercritical pure-upwind property verified to 1e-15")
Inside the Algorithm: Consistency & Supercritical Upwinding of shallow_water_1d_hll
===================================================================================
def shallow_water_1d_hll(
h_init: np.ndarray,
hu_init: np.ndarray,
L: float,
dt: float,
n_steps: int,
g: float = G_STD,
) -> dict:
"""Solve 1-D shallow-water equations with transmissive BCs via Harten-Lax-van Leer (HLL) Riemann solver."""
h = np.asarray(h_init, dtype=float).ravel().copy()
hu = np.asarray(hu_init, dtype=float).ravel().copy()
dx = float(L) / h.size
for _ in range(n_steps):
hp = np.pad(h, 1, mode="edge")
hup = np.pad(hu, 1, mode="edge")
hl, hr = hp[:-1], hp[1:]
hul, hur = hup[:-1], hup[1:]
ul = hul / hl
ur = hur / hr
cl = np.sqrt(g * hl)
cr = np.sqrt(g * hr)
sl = np.minimum(ul - cl, ur - cr)
sr = np.maximum(ul + cl, ur + cr)
f1_l, f1_r = hul, hur
f2_l = hul * ul + 0.5 * g * (hl**2)
f2_r = hur * ur + 0.5 * g * (hr**2)
denom = np.where(sr - sl > 1e-14, sr - sl, 1.0)
f1_hll = (sr * f1_l - sl * f1_r + sl * sr * (hr - hl)) / denom
f2_hll = (sr * f2_l - sl * f2_r + sl * sr * (hur - hul)) / denom
f1 = np.where(sl >= 0.0, f1_l, np.where(sr <= 0.0, f1_r, f1_hll))
f2 = np.where(sl >= 0.0, f2_l, np.where(sr <= 0.0, f2_r, f2_hll))
h = h - (dt / dx) * (f1[1:] - f1[:-1])
hu = hu - (dt / dx) * (f2[1:] - f2[:-1])
return {"h": h, "hu": hu, "u": hu / h}
HLL consistency and supercritical pure-upwind property verified to 1e-15
Exercises¶
Worked solutions are in 09_solutions.ipynb. The cell below the list is a short self-check to start from.
Verify a result. Find the critical tailwater ratio where using
exact_dam_break_dry_or_wet, and check numerically across that depth and Froude number at lock onto and .Find how it fails. Verify
exact_dam_break_dry_or_wetraisesValueErrorfor invalid inputs (, , ), and show that centered forward-Euler fluxes without HLL wave-speed viscosity produce severe TV blow-up / non-physical depths on the dam break.Implement it yourself. Implement
shallow_water_1d_muscl_hll(h_init, hu_init, L, dt, n_steps, g)usingminmodpiecewise-linear interface reconstruction, HLL Riemann fluxes, and SSP-RK2 time stepping. Benchmark at against 1st-ordershallow_water_1d_hllon the Stoker dam break (), asserting exact volume conservation and lower depth and velocity errors.
heading("Self-check for the exercises")
ex_c9 = burgers_riemann.exact_dam_break_dry_or_wet(np.array([4.0, 5.0, 6.0]), t=0.2, h_left=2.0, h_right=0.5, x_dam=5.0)
assert ex_c9["h"][0] > ex_c9["h"][1] > ex_c9["h"][2]
assert ex_c9["shock_speed"] > np.sqrt(constants.G_STD * 0.5)
print("Stoker dam-break wave ordering and supersonic bore speed verified")
print("All checks passed.")
Self-check for the exercises
============================
Stoker dam-break wave ordering and supersonic bore speed verified
All checks passed.