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 · 6. Flux limiters and total-variation-diminishing schemes

School of Engineering, Nazarbayev University

Worked solutions to the three exercises of Lecture 6. 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. Verify across r∈[0.05,20.0]r \in [0.05, 20.0] that minmod, van_leer, mc, and superbee satisfy Sweby’s forward–backward gradient symmetry ψ(r)=r ψ(1/r)\psi(r) = r\,\psi(1/r) to 10-14, while lax_wendroff and beam_warming break self-symmetry and instead satisfy mutual duality ψBW(r)=r ψLW(1/r)\psi_{\mathrm{BW}}(r) = r\,\psi_{\mathrm{LW}}(1/r).


Exercise 1: Sweby Gradient-Ratio Symmetry psi(r) == r * psi(1/r)
================================================================
minmod       | max |psi(r) - r*psi(1/r)| = 1.110e-16
van_leer     | max |psi(r) - r*psi(1/r)| = 4.441e-16
mc           | max |psi(r) - r*psi(1/r)| = 2.220e-16
superbee     | max |psi(r) - r*psi(1/r)| = 2.220e-16
Confirmed: all 4 TVD limiters are self-symmetric, while Lax-Wendroff and Beam-Warming are exact duals

Explanation. Rewriting the anti-diffusive correction ψ(ri+1/2)(qi+1−qi)=ψ(ri+1/2)ri+1/2(qi−qi−1)\psi(r_{i+1/2})(q_{i+1} - q_i) = \frac{\psi(r_{i+1/2})}{r_{i+1/2}}(q_i - q_{i-1}) shows that swapping the roles of the downwind difference (qi+1−qi)(q_{i+1}-q_i) and upwind difference (qi−qi−1)(q_i - q_{i-1}) replaces (r,ψ(r))(r, \psi(r)) by (1/r,ψ(r)/r)(1/r, \psi(r)/r). Self-symmetry ψ(r)/r=ψ(1/r)\psi(r)/r = \psi(1/r) ensures that leading and trailing edges of a symmetric pulse are compressed identically without skewing its center of mass.


Exercise 2

Problem. Verify that tvd_advection.advect_1d_periodic raises ValueError for ∣CFL∣>1|\mathrm{CFL}| > 1, non-positive dt/L, and unknown scheme names, and quantify the exponential Total Variation blow-up of an unguarded explicit step at CFL=1.25\mathrm{CFL} = 1.25.


Exercise 2: CFL > 1 Instability & Input Guards
==============================================
Guard verified (CFL = 1.25 > 1): raised ValueError as expected.
Guard verified (Negative CFL = -1.2): raised ValueError as expected.
Guard verified (Non-positive dt): raised ValueError as expected.
Guard verified (Unknown limiter): raised ValueError as expected.
Unguarded nu = 1.25 after 30 steps: TV exploded from 2.00 to 3.835e+05

Explanation. For ν=uΔt/Δx>1\nu = u\Delta t/\Delta x > 1, the exact characteristic foot xi−uΔtx_i - u\Delta t originates upstream of xi−1x_{i-1}, outside the stencil {i−1,i,i+1}\{i-1, i, i+1\}. By the Courant–Friedrichs–Lewy theorem, Harten’s incremental weights Ci−1/2+=ν[1+12(1−ν)(ψ(ri+1/2)/ri+1/2−ψ(ri−1/2))]C_{i-1/2}^+ = \nu\bigl[1 + \frac{1}{2}(1-\nu)(\psi(r_{i+1/2})/r_{i+1/2} - \psi(r_{i-1/2}))\bigr] violate 0≤C+≤10 \leq C^+ \leq 1 when ν>1\nu > 1 (since 1−ν<01 - \nu < 0 flips the anti-diffusive term’s sign and produces negative convex-combination weights), and the solution oscillates and diverges.


Exercise 3

Problem. Implement Koren’s third-order upwind-biased TVD limiter ψKoren(r)=max⁡ ⁣(0,min⁡(2r,2+r3,2))\psi_{\mathrm{Koren}}(r) = \max\!\bigl(0, \min(2r, \frac{2 + r}{3}, 2)\bigr) (matching f^i+1/2=−qi−1+5qi+2qi+16\hat{f}_{i+1/2} = \frac{-q_{i-1} + 5q_i + 2q_{i+1}}{6} for r=qi−qi−1qi+1−qir = \frac{q_i - q_{i-1}}{q_{i+1} - q_i}) inside a 3-stage Shu–Osher SSP-RK3 solver advect_1d_koren_rk3(q_init, L, u, dt, n_steps). Verify Sweby admissibility, ψKoren(1)=1\psi_{\mathrm{Koren}}(1) = 1, ψKoren′(1)=1/3\psi_{\mathrm{Koren}}'(1) = 1/3, square-wave TVD monotonicity, and strictly lower L2L_2 error than van_leer and >4×> 4\times lower L2L_2 error than minmod on q0(x)=sin⁡4(πx)q_0(x) = \sin^4(\pi x).


Exercise 3: Implement It Yourself — Koren 3rd-Order TVD Limiter + Shu-Osher SSP-RK3
===================================================================================
Smooth sin^4(pi*x) L2 error (N=160, CFL=0.4): Koren-RK3 = 5.504e-04 < van Leer = 9.865e-04 < minmod = 2.685e-03

Summary. Watch out for gradient-ratio conventions in the CFD literature. In Sweby’s r=qi−qi−1qi+1−qir = \frac{q_i - q_{i-1}}{q_{i+1} - q_i} convention, exact 3rd-order quadratic finite-volume reconstruction f^i+1/2=−qi−1+5qi+2qi+16\hat{f}_{i+1/2} = \frac{-q_{i-1} + 5q_i + 2q_{i+1}}{6} corresponds to ψKoren(r)=2+r3\psi_{\mathrm{Koren}}(r) = \frac{2 + r}{3} (ψ′(1)=1/3\psi'(1) = 1/3, whereas defining rinv=1/rr_{\mathrm{inv}} = 1/r gives 1+2rinv3\frac{1 + 2 r_{\mathrm{inv}}}{3}). Paired with Shu–Osher 3-stage SSP-RK3, Koren’s limiter gives a smaller error than van Leer and minmod on smooth waves while enforcing strict TVD monotonicity on shocks.