In linear advection (), every point on a wave travels at the same speed , so smooth waves stay smooth forever. In real compressible gas dynamics, traffic waves, and nonlinear acoustics, higher-velocity fluid overtakes slower fluid ahead of it (), relentlessly steepening smooth compressions into viscous shock layers of thickness . Even more remarkably, although and are algebraically identical for smooth functions, discretizing the non-conservative form across a shock predicts a physically wrong shock propagation speed (the Hou–LeFloch theorem). In this lecture we verify exact nonlinear solutions via the Cole–Hopf transformation (burgers_riemann.cole_hopf_viscous_burgers_exact), compare conservative Godunov and Rusanov solvers (solve_viscous_burgers_1d), and show the Rankine–Hugoniot jump condition .
Learning objectives¶
Derive the Cole–Hopf nonlinear-to-linear transformation mapping the 1-D viscous Burgers equation onto the linear heat equation (
burgers_riemann.cole_hopf_viscous_burgers_exact).Analyze nonlinear wave steepening and verify viscous shock thickness scaling against Taylor’s exact traveling shock profile.
Prove the Rankine–Hugoniot shock speed and execute the Hou–LeFloch failure-mode audit comparing conservative
godunov/rusanovvs.nonconservativediscretizations (solve_viscous_burgers_1d).Verify Osher’s exact entropy-satisfying Godunov flux identity, audit Roe sonic expansion shocks, and implement a 2nd-order MUSCL–Godunov viscous Burgers 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. Nonlinear Steepening & the Exact Cole–Hopf Transformation¶
The 1-D viscous Burgers equation is the canonical prototype uniting nonlinear convective steepening with Newtonian viscous dissipation ():
Independently discovered by Hopf (1950) and Cole (1951), the nonlinear substitution
cancels the quadratic nonlinearity identically whenever satisfies the linear heat equation . Specifically, choosing the strictly positive single-mode heat solution (, ) yields the exact closed-form periodic benchmark in burgers_riemann.cole_hopf_viscous_burgers_exact:
When is close to 1 (e.g. ), the denominator becomes very small near , producing a steep asymmetric sawtooth shock wave that subsequently relaxes via viscous decay.
heading("Demonstration 1: Exact Cole-Hopf Solution & Conservative Godunov FVM Verification")
L_ch = 2.0 * np.pi
n_ch = 256
dx_ch = L_ch / n_ch
x_ch = (np.arange(n_ch) + 0.5) * dx_ch
nu_ch = 0.15
a0_ch = 1.12
# 1. Verify directly via 4th-order/spectral Fourier derivatives that cole_hopf_viscous_burgers_exact solves PDE (1.1):
t_pde = 0.40
dt_fd = 1e-6
u_c = burgers_riemann.cole_hopf_viscous_burgers_exact(x_ch, t_pde, nu=nu_ch, L=L_ch, offset_a0=a0_ch)
u_p = burgers_riemann.cole_hopf_viscous_burgers_exact(x_ch, t_pde + dt_fd, nu=nu_ch, L=L_ch, offset_a0=a0_ch)
u_m = burgers_riemann.cole_hopf_viscous_burgers_exact(x_ch, t_pde - dt_fd, nu=nu_ch, L=L_ch, offset_a0=a0_ch)
ut_num = (u_p - u_m) / (2.0 * dt_fd)
k_fft = np.fft.fftfreq(n_ch, d=dx_ch / (2.0 * np.pi))
u_hat = np.fft.fft(u_c)
ux_spec = np.real(np.fft.ifft(1j * k_fft * u_hat))
uxx_spec = np.real(np.fft.ifft(-(k_fft ** 2) * u_hat))
pde_residual = float(np.max(np.abs(ut_num + u_c * ux_spec - nu_ch * uxx_spec)))
print(f"Cole-Hopf exact PDE residual max |u_t + u*u_x - nu*u_xx| = {pde_residual:.3e}")
assert pde_residual < 1e-9
# 2. Integrate from t = 0 to t = 1.0 via solve_viscous_burgers_1d (Godunov + SSP-RK2):
u0_ch = burgers_riemann.cole_hopf_viscous_burgers_exact(x_ch, 0.0, nu=nu_ch, L=L_ch, offset_a0=a0_ch)
t_end_ch = 1.0
n_steps_ch = 1250
dt_ch = t_end_ch / n_steps_ch
sol_god = burgers_riemann.solve_viscous_burgers_1d(u0_ch, L=L_ch, nu=nu_ch, dt=dt_ch, n_steps=n_steps_ch, flux="godunov", periodic=True)
sol_rus = burgers_riemann.solve_viscous_burgers_1d(u0_ch, L=L_ch, nu=nu_ch, dt=dt_ch, n_steps=n_steps_ch, flux="rusanov", periodic=True)
u_exact_end = burgers_riemann.cole_hopf_viscous_burgers_exact(x_ch, t_end_ch, nu=nu_ch, L=L_ch, offset_a0=a0_ch)
err_god = float(np.sqrt(np.mean((sol_god["final"] - u_exact_end) ** 2)))
err_rus = float(np.sqrt(np.mean((sol_rus["final"] - u_exact_end) ** 2)))
imp_drift = float(np.max(np.abs(sol_god["impulses"] - sol_god["impulses"][0])))
print(f"Godunov L2 error = {err_god:.4e}, Rusanov L2 error = {err_rus:.4e}, Impulse drift = {imp_drift:.2e}")
assert imp_drift < 1e-14
assert err_god < 3e-3 and err_rus < 4e-3
fig, ax = plt.subplots(figsize=(7.4, 4.1))
for tv, ls in [(0.0, "--"), (0.4, "-."), (1.0, "-")]:
ax.plot(x_ch, burgers_riemann.cole_hopf_viscous_burgers_exact(x_ch, tv, nu=nu_ch, L=L_ch, offset_a0=a0_ch), ls, lw=1.8, label=f"Cole-Hopf Exact ($t={tv:.1f}$)")
ax.plot(x_ch[::6], sol_god["final"][::6], "ko", ms=4.5, label="Godunov FVM ($t=1.0$)")
ax.set_xlabel("Position $x$ [rad]")
ax.set_ylabel("Velocity $u(x, t)$ [m/s]")
ax.set_title(r"Periodic Viscous Burgers Evolution ($\nu = 0.15$, $a_0 = 1.12$)")
ax.legend(fontsize=8.5)
Demonstration 1: Exact Cole-Hopf Solution & Conservative Godunov FVM Verification
=================================================================================
Cole-Hopf exact PDE residual max |u_t + u*u_x - nu*u_xx| = 1.552e-10
Godunov L2 error = 1.2917e-03, Rusanov L2 error = 1.3563e-03, Impulse drift = 3.49e-16

Figure 8.1. Decay of a sine wave under the viscous Burgers equation: the Cole–Hopf solution at three times and the finite-volume Godunov solution at the last time.
What Demonstration 1 shows. Near , positive velocity on the left () collides with negative velocity on the right (), creating an intense stationary viscous shock layer whose thickness gradually broadens as momentum diffuses across while conserving total periodic impulse to .
2. Taylor’s Traveling Viscous Shock Profile & Shock Thickness Scaling ¶
For a non-periodic step connecting upstream velocity to slower downstream velocity , Equation (1.1) admits G. I. Taylor’s (1910) exact steady-profile traveling viscous shock wave moving at speed :
Differentiating Equation (2.1) at the shock center gives the Prandtl–Taylor maximum-slope shock thickness:
As , linearly with , while the propagation speed is independent of viscosity .
heading("Demonstration 2: Viscous Shock Layer Thickness delta = 8*nu / Delta_u")
L_sh = 6.0
n_sh = 384
dx_sh = L_sh / n_sh
x_sh = (np.arange(n_sh) + 0.5) * dx_sh
uL_sh, uR_sh = 1.4, 0.2
du_sh = uL_sh - uR_sh
s_sh = 0.5 * (uL_sh + uR_sh)
x0_sh = 2.4
t_sh = 1.0
nu_sweep = [0.030, 0.060, 0.120, 0.240]
measured_deltas, exact_deltas = [], []
print(f"{'nu [m^2/s]':>11s} | {'Exact 8*nu/du':>14s} | {'FVM delta':>11s} | {'Profile L2 Err':>14s}")
print("-" * 60)
fig, ax = plt.subplots(figsize=(7.4, 4.1))
for nu_v in nu_sweep:
u_init_t = 0.5 * (uL_sh + uR_sh) - 0.5 * du_sh * np.tanh(du_sh * (x_sh - x0_sh) / (4.0 * nu_v))
u_ref_t = 0.5 * (uL_sh + uR_sh) - 0.5 * du_sh * np.tanh(du_sh * (x_sh - x0_sh - s_sh * t_sh) / (4.0 * nu_v))
dt_v = min(0.25 * dx_sh / uL_sh, 0.22 * (dx_sh ** 2) / nu_v)
n_st_v = int(np.ceil(t_sh / dt_v))
dt_v = t_sh / n_st_v
out_v = burgers_riemann.solve_viscous_burgers_1d(u_init_t, L=L_sh, nu=nu_v, dt=dt_v, n_steps=n_st_v, flux="godunov", periodic=False)
u_num = out_v["final"]
max_slope = float(np.max(np.abs(np.gradient(u_num, dx_sh))))
d_num = du_sh / max_slope
d_ex = 8.0 * nu_v / du_sh
l2_t = float(np.sqrt(np.mean((u_num - u_ref_t) ** 2)))
measured_deltas.append(d_num)
exact_deltas.append(d_ex)
print(f"{nu_v:11.3f} | {d_ex:14.4f} | {d_num:11.4f} | {l2_t:14.3e}")
assert l2_t < 1.2e-2
ax.plot(x_sh, u_num, lw=1.9, label=f"FVM $\\nu={nu_v:.3f}$ ($\\delta={d_num:.3f}$)")
ax.plot(x_sh, u_ref_t, "k:", lw=1.1)
# Doubling nu doubles shock thickness linearly:
ratios_d = np.array(measured_deltas[1:]) / np.array(measured_deltas[:-1])
assert np.allclose(ratios_d, 2.0, rtol=0.12)
ax.axvline(x0_sh + s_sh * t_sh, color="gray", ls="--", lw=1.2, label=f"Exact shock center $x_0 + s t = {x0_sh + s_sh*t_sh:.2f}$")
ax.set_xlabel("Position $x$ [m]")
ax.set_ylabel("Velocity $u(x, t)$ [m/s]")
ax.set_title(r"Taylor Viscous Burgers Shocks ($\delta = 8\nu / \Delta u$, dotted = exact)")
ax.legend(fontsize=8)
Demonstration 2: Viscous Shock Layer Thickness delta = 8*nu / Delta_u
=====================================================================
nu [m^2/s] | Exact 8*nu/du | FVM delta | Profile L2 Err
------------------------------------------------------------
0.030 | 0.2000 | 0.2413 | 1.015e-02
0.060 | 0.4000 | 0.4365 | 6.540e-03
0.120 | 0.8000 | 0.8284 | 3.608e-03
0.240 | 1.6000 | 1.6195 | 2.633e-03

Figure 8.2. Traveling viscous shocks for four viscosities. Solid lines: finite-volume solution; dotted lines: the exact tanh profile; the vertical line is the exact position of the shock center.
What Demonstration 2 shows. Every computed shock is centered at regardless of viscosity , while doubling doubles the shock transition thickness .
3. Rankine–Hugoniot Jump Condition & the Hou–LeFloch Non-Conservative Failure Mode¶
In the inviscid limit , classical derivatives cease to exist across a shock jump , and only the integral conservation law remains valid:
For a shock moving at speed inside , Equation (3.1) yields the Rankine–Hugoniot jump relation:
What happens if a programmer discretizes the non-conservative advective form (flux="nonconservative" in solve_viscous_burgers_1d)? Because does not telescope when summed across cells, momentum is silently destroyed at the shock front. For , let us watch nonconservative stall behind the true Rankine–Hugoniot shock.
heading("Demonstration 3: Conservative vs Non-Conservative Shock Speed")
L_hl = 4.0
n_hl = 400
dx_hl = L_hl / n_hl
x_hl = (np.arange(n_hl) + 0.5) * dx_hl
x0_hl = 0.80
uL_hl, uR_hl = 2.0, 0.0
u0_hl = np.where(x_hl < x0_hl, uL_hl, uR_hl)
t_hl = 1.0
n_st_hl = 1000
dt_hl = t_hl / n_st_hl # CFL = 2.0 * 0.001 / 0.01 = 0.20
god_hl = burgers_riemann.solve_viscous_burgers_1d(u0_hl, L=L_hl, nu=0.0, dt=dt_hl, n_steps=n_st_hl, flux="godunov", periodic=False)
rus_hl = burgers_riemann.solve_viscous_burgers_1d(u0_hl, L=L_hl, nu=0.0, dt=dt_hl, n_steps=n_st_hl, flux="rusanov", periodic=False)
nc_hl = burgers_riemann.solve_viscous_burgers_1d(u0_hl, L=L_hl, nu=0.0, dt=dt_hl, n_steps=n_st_hl, flux="nonconservative", periodic=False)
s_rh = 0.5 * (uL_hl + uR_hl)
x_shock_exact = x0_hl + s_rh * t_hl # 0.80 + 1.00 = 1.80 m
u_exact_hl = np.where(x_hl < x_shock_exact, uL_hl, uR_hl)
# Estimate shock position where u crosses midpoint 0.5*(uL + uR) = 1.0:
x_god = float(x_hl[np.argmin(np.abs(god_hl["final"] - 1.0))])
x_rus = float(x_hl[np.argmin(np.abs(rus_hl["final"] - 1.0))])
x_nc = float(x_hl[np.argmin(np.abs(nc_hl["final"] - 1.0))])
# Exact integral impulse gain over [0, L] while right boundary u=0: dI/dt = 0.5*uL^2 - 0.5*uR^2 = 2.0 -> delta_I = 2.0
dI_exact = 0.5 * (uL_hl ** 2 - uR_hl ** 2) * t_hl
dI_god = float(god_hl["impulses"][-1] - god_hl["impulses"][0])
dI_rus = float(rus_hl["impulses"][-1] - rus_hl["impulses"][0])
dI_nc = float(nc_hl["impulses"][-1] - nc_hl["impulses"][0])
print(f"Exact Rankine-Hugoniot: x_shock = {x_shock_exact:.3f} m | Impulse gain dI = {dI_exact:.4f}")
print(f"Conservative Godunov : x_shock = {x_god:.3f} m | Impulse gain dI = {dI_god:.4f}")
print(f"Conservative Rusanov : x_shock = {x_rus:.3f} m | Impulse gain dI = {dI_rus:.4f}")
print(f"Non-conservative u*ux : x_shock = {x_nc:.3f} m | Impulse gain dI = {dI_nc:.4f} (the shock does not move)")
assert np.isclose(dI_god, dI_exact, atol=1e-12)
assert np.isclose(dI_rus, dI_exact, atol=1e-12)
assert abs(x_god - x_shock_exact) <= 1.5 * dx_hl
assert abs(x_rus - x_shock_exact) <= 1.5 * dx_hl
# Non-conservative scheme with u_R = 0 freezes the shock completely at x_0
assert x_nc < 0.90 and dI_nc < 0.05
fig, ax = plt.subplots(figsize=(7.4, 4.1))
ax.plot(x_hl, u_exact_hl, "k--", lw=2.0, label=f"Exact Rankine-Hugoniot ($x_s = {x_shock_exact:.2f}$ m)")
ax.plot(x_hl, god_hl["final"], lw=2.0, color="#1f77b4", label="Conservative Godunov FVM")
ax.plot(x_hl, rus_hl["final"], lw=1.7, color="#2ca02c", label="Conservative Rusanov FVM")
ax.plot(x_hl, nc_hl["final"], lw=2.0, color="#d62728", label="Non-Conservative $u_t + u u_x = 0$ ")
ax.set_xlabel("Position $x$ [m]")
ax.set_ylabel("Velocity $u(x, t=1)$ [m/s]")
ax.set_title("Lax-Wendroff / Hou-LeFloch Demonstration: Shock Stalling Under Non-Conservative Form")
ax.legend(fontsize=8.5)
Demonstration 3: Conservative vs Non-Conservative Shock Speed
=============================================================
Exact Rankine-Hugoniot: x_shock = 1.800 m | Impulse gain dI = 2.0000
Conservative Godunov : x_shock = 1.805 m | Impulse gain dI = 2.0000
Conservative Rusanov : x_shock = 1.805 m | Impulse gain dI = 2.0000
Non-conservative u*ux : x_shock = 0.005 m | Impulse gain dI = 0.0000 (the shock does not move)

Figure 8.3. A shock moving into fluid at rest, at s. The two conservative schemes place the shock at the position given by the Rankine–Hugoniot condition; the non-conservative upwind scheme leaves it at its initial position.
What Demonstration 3 shows. When , the non-conservative upwind stencil evaluates in the first cell ahead of the jump, freezing the shock at ( instead of ). Meanwhile, conservative Godunov and Rusanov telescope interior fluxes identically, matching both and .
4. Transonic Rarefaction Fan ¶
What happens if we flip the jump so fluid pulls apart ()? Characteristics diverge, creating a continuous centered rarefaction fan for passing smoothly through the sonic point . We verify solve_viscous_burgers_1d(..., flux="godunov") on this transonic expansion.
heading("Demonstration 4: Entropy-Satisfying Transonic Rarefaction Fan (u_L = -1, u_R = +1)")
L_rar = 4.0
n_rar = 400
dx_rar = L_rar / n_rar
x_rar = (np.arange(n_rar) + 0.5) * dx_rar
x0_rar = 2.0
u0_rar = np.where(x_rar < x0_rar, -1.0, 1.0)
t_rar = 0.80
n_st_rar = 400
dt_rar = t_rar / n_st_rar
rar_god = burgers_riemann.solve_viscous_burgers_1d(u0_rar, L=L_rar, nu=0.0, dt=dt_rar, n_steps=n_st_rar, flux="godunov", periodic=False)
xi_rar = (x_rar - x0_rar) / t_rar
u_rar_exact = np.where(xi_rar <= -1.0, -1.0, np.where(xi_rar >= 1.0, 1.0, xi_rar))
l1_rar = float(np.mean(np.abs(rar_god["final"] - u_rar_exact)))
u_at_sonic = float(0.5 * (rar_god["final"][n_rar // 2 - 1] + rar_god["final"][n_rar // 2]))
print(f"Transonic rarefaction L1 error = {l1_rar:.4e} | Sonic-point velocity u(x0, t) = {u_at_sonic:+.3e}")
assert l1_rar < 0.012 and abs(u_at_sonic) < 1e-12
Demonstration 4: Entropy-Satisfying Transonic Rarefaction Fan (u_L = -1, u_R = +1)
==================================================================================
Transonic rarefaction L1 error = 1.1354e-02 | Sonic-point velocity u(x0, t) = +0.000e+00
Inside the algorithm¶
Why does _burgers_godunov_flux handle compressions, supersonic ramps, and sonic points in one formula? For any convex flux with sonic minimum at , Osher’s exact Riemann formula collapses all four wave cases into a single branch-free expression:
Below we inspect burgers_riemann._burgers_godunov_flux and verify exact identity with Osher’s formula across state pairs .
Check against the library¶
heading("Inside the Algorithm: burgers_riemann._burgers_godunov_flux vs Osher Convex Min-Max Formula")
print(show_source(burgers_riemann._burgers_godunov_flux))
u_1d = np.linspace(-3.0, 3.0, 101)
UL_g, UR_g = np.meshgrid(u_1d, u_1d, indexing="ij")
f_lib = burgers_riemann._burgers_godunov_flux(UL_g, UR_g)
f_osher = 0.5 * np.maximum(np.maximum(UL_g, 0.0) ** 2, np.minimum(UR_g, 0.0) ** 2)
max_flux_diff = float(np.max(np.abs(f_lib - f_osher)))
print(f"Max |f_lib(uL, uR) - f_osher(uL, uR)| over 101x101 state grid = {max_flux_diff:.3e}")
assert np.allclose(f_lib, f_osher, rtol=1e-15, atol=1e-15)
Inside the Algorithm: burgers_riemann._burgers_godunov_flux vs Osher Convex Min-Max Formula
===========================================================================================
def _burgers_godunov_flux(ul: np.ndarray, ur: np.ndarray) -> np.ndarray:
"""Exact entropy-satisfying Godunov numerical flux for f(u) = 0.5 * u^2."""
fl = 0.5 * (ul**2)
fr = 0.5 * (ur**2)
shock = np.where(0.5 * (ul + ur) >= 0.0, fl, fr)
raref = np.where(ul >= 0.0, fl, np.where(ur <= 0.0, fr, 0.0))
return np.where(ul > ur, shock, raref)
Max |f_lib(uL, uR) - f_osher(uL, uR)| over 101x101 state grid = 0.000e+00
Exercises¶
Worked solutions are in 08_solutions.ipynb. The cell below the list is a short self-check to start from.
Verify a result. Perform a grid-refinement study () for
solve_viscous_burgers_1d(..., flux='godunov', periodic=True)againstcole_hopf_viscous_burgers_exact(), asserting first-order convergence and exact impulse conservation.Find how it fails. Verify
cole_hopf_viscous_burgers_exactinput guards (, ) and demonstrate that unfixed Roe flux produces an unphysical stationary expansion shock on while_burgers_godunov_fluxresolves the exact rarefaction fan.Implement it yourself. Implement
solve_muscl_viscous_burgers_1d(u_init, L, nu, dt, n_steps)using periodicminmodslope reconstruction,_burgers_godunov_flux, centered viscous diffusion, and SSP-RK2. Verify convergence oncole_hopf_viscous_burgers_exact() and assert lower error than 1st-ordersolve_viscous_burgers_1dat .
heading("Self-check for the exercises")
x_c8 = np.linspace(0.0, 2.0 * np.pi, 64, endpoint=False)
u_c8 = burgers_riemann.cole_hopf_viscous_burgers_exact(x_c8, t=0.5, nu=0.2, L=2.0 * np.pi, offset_a0=2.0)
assert np.isclose(np.sum(u_c8), 0.0, atol=1e-13)
assert np.isclose(burgers_riemann._burgers_godunov_flux(np.array([-1.0]), np.array([1.0]))[0], 0.0, atol=1e-15)
print("Cole-Hopf zero-mean antisymmetry and Godunov sonic-point flux verified")
print("All checks passed.")
Self-check for the exercises
============================
Cole-Hopf zero-mean antisymmetry and Godunov sonic-point flux verified
All checks passed.