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.

6. Flux limiters and total-variation-diminishing schemes

School of Engineering, Nazarbayev University

In Lecture 5, von Neumann analysis showed a conflict: first-order upwind advection guarantees positivity and monotonicity but smears sharp concentration fronts with heavy O(Δx)O(\Delta x) numerical diffusion, whereas second-order linear schemes like Lax–Wendroff and Beam–Warming preserve wave amplitude better at the cost of non-physical Gibbs overshoots and undershoots. Can any linear constant-coefficient scheme achieve second-order accuracy without creating spurious oscillations? In 1959, Godunov proved that the answer is no, forcing modern CFD to become nonlinear even when solving a linear PDE. In this lecture we map Sweby’s (1984) second-order Total Variation Diminishing (TVD) admissibility region (tvd_advection.in_sweby_tvd_region), evaluate classical and high-resolution limiters (minmod, van_leer, mc, superbee), and verify exact mass conservation alongside TV(qn+1)≤TV(qn)\mathrm{TV}(q^{n+1}) \leq \mathrm{TV}(q^n) on discontinuous and smooth wave packets (advect_1d_periodic).

Learning objectives

  1. Explain Godunov’s (1959) order-barrier theorem and derive the conservative MUSCL/flux-limited interface flux Fi+1/2F_{i+1/2} parameterized by local gradient ratio ri+1/2r_{i+1/2} and limiter ψ(r)\psi(r).

  2. Verify Sweby’s (1984) second-order TVD admissibility bounds (tvd_advection.in_sweby_tvd_region) across linear schemes (upwind, lax_wendroff, beam_warming) and nonlinear limiters (minmod, van_leer, mc, superbee).

  3. Prove discrete mass conservation and Total Variation Diminishing stability TV(qn+1)≤TV(qn)\mathrm{TV}(q^{n+1}) \leq \mathrm{TV}(q^n) (total_variation_1d_periodic, advect_1d_periodic) on periodic square pulses and smooth Gaussian waves.

  4. Implement Koren’s third-order upwind-biased TVD limiter from scratch and audit CFL stability and limiter symmetry properties.

Time: about 60 min

1. Godunov’s Order-Barrier Theorem & Sweby’s 2nd-Order TVD Region

Consider 1-D conservative scalar advection on a periodic domain x∈[0,L)x \in [0, L) with constant velocity u>0u > 0 and Courant number ν=u ΔtΔx∈(0,1]\nu = \frac{u\,\Delta t}{\Delta x} \in (0, 1]:

∂q∂t+u∂q∂x=0,qin+1=qin−ν(f^i+1/2−f^i−1/2)(1.1)\frac{\partial q}{\partial t} + u\frac{\partial q}{\partial x} = 0, \qquad q_i^{n+1} = q_i^n - \nu\left(\hat{f}_{i+1/2} - \hat{f}_{i-1/2}\right) \tag{1.1}

Following Sweby (1984), we write the normalized cell-face flux f^i+1/2=Fi+1/2/u\hat{f}_{i+1/2} = F_{i+1/2}/u as the first-order upwind flux plus a limited anti-diffusive Lax–Wendroff correction:

f^i+1/2=qi⏟1st-order upwind+12(1−ν) ψ(ri+1/2) (qi+1−qi),ri+1/2≡qi−qi−1qi+1−qi(1.2)\hat{f}_{i+1/2} = \underbrace{q_i}_{\text{1st-order upwind}} + \frac{1}{2}(1 - \nu)\,\psi(r_{i+1/2})\,(q_{i+1} - q_i), \qquad r_{i+1/2} \equiv \frac{q_i - q_{i-1}}{q_{i+1} - q_i} \tag{1.2}

where ri+1/2r_{i+1/2} measures the ratio of upwind-to-local consecutive gradients:

  • Linear constant-ψ\psi choices: ψ(r)=0\psi(r) = 0 recovers 1st-order Upwind; ψ(r)=1\psi(r) = 1 recovers Lax–Wendroff; ψ(r)=r\psi(r) = r recovers Beam–Warming.

  • Godunov’s Theorem (1959): Any linear numerical scheme that preserves monotonicity (does not create new extrema) is at most first-order accurate.

  • Total Variation & Sweby’s TVD Theorem (1984): Defining discrete periodic total variation TV(q)=∑i∣qi−qi−1∣\mathrm{TV}(q) = \sum_i |q_i - q_{i-1}|, a scheme is Total Variation Diminishing (TV(qn+1)≤TV(qn)\mathrm{TV}(q^{n+1}) \leq \mathrm{TV}(q^n)) and second-order accurate on smooth monotone profiles (ψ(1)=1\psi(1) = 1) if ψ(r)\psi(r) lies inside Sweby’s shaded region:

ψ(r)=0(r≤0),min⁡(r,1)≤ψ(r)≤min⁡(2r,2)(r>0)(1.3)\psi(r) = 0 \quad (r \leq 0), \qquad \min(r, 1) \leq \psi(r) \leq \min(2r, 2) \quad (r > 0) \tag{1.3}

At any local extremum, consecutive slopes have opposite signs (r≤0r \leq 0), forcing ψ(r)=0\psi(r) = 0 so the TVD scheme locally reverts to monotone 1st-order upwind to prevent overshoot. The four standard TVD limiters in tvd_advection.flux_limiter span this region from most diffusive (minmod, the lower Sweby boundary) to most compressive (superbee, the upper Sweby boundary):

ψminmod(r)=max⁡(0,min⁡(1,r)),ψVL(r)=r+∣r∣1+∣r∣,ψMC(r)=max⁡ ⁣(0,min⁡ ⁣(2r,1+r2,2)),ψSB(r)=max⁡(0,min⁡(2r,1),min⁡(r,2))(1.4)\psi_{\mathrm{minmod}}(r) = \max\bigl(0, \min(1, r)\bigr), \qquad \psi_{\mathrm{VL}}(r) = \frac{r + |r|}{1 + |r|}, \qquad \psi_{\mathrm{MC}}(r) = \max\!\left(0, \min\!\left(2r, \frac{1+r}{2}, 2\right)\right), \qquad \psi_{\mathrm{SB}}(r) = \max\bigl(0, \min(2r, 1), \min(r, 2)\bigr) \tag{1.4}

Demonstration 1: Sweby 2nd-Order TVD Region & Flux Limiter Hierarchy
====================================================================
Scheme          |  psi(0.5) |  psi(1.0) |  psi(2.0) |  In 2nd-Order Sweby TVD?
----------------------------------------------------------------------------
upwind          |    0.0000 |    0.0000 |    0.0000 |                    False
lax_wendroff    |    1.0000 |    1.0000 |    1.0000 |                    False
beam_warming    |    0.5000 |    1.0000 |    2.0000 |                    False
minmod          |    0.5000 |    1.0000 |    1.0000 |                     True
van_leer        |    0.6667 |    1.0000 |    1.3333 |                     True
mc              |    0.7500 |    1.0000 |    1.5000 |                     True
superbee        |    1.0000 |    1.0000 |    2.0000 |                     True
<Figure size 814x473 with 1 Axes>

Figure 6.1. The Sweby diagram. The shaded area is the region in which a limiter ψ(r)\psi(r) gives a second-order total-variation-diminishing scheme; the minmod and superbee limiters are its lower and upper boundaries, and all limiters pass through the point (1,1)(1, 1).

What Demonstration 1 shows. Every linear second-order scheme (lax_wendroff with ψ=1\psi=1, beam_warming with ψ=r\psi=r) exits Sweby’s TVD region, either for r<0.5r < 0.5 or r>2r > 2, explaining why constant-coefficient second-order schemes inevitably generate dispersive ripples near discontinuities. Conversely, minmod, van_leer, mc, and superbee remain strictly inside Sweby’s region, pass through (r=1,ψ=1)(r=1, \psi=1) for second-order fidelity on smooth ramps, and satisfy the ordering ψminmod(r)≤ψVL(r)≤ψMC(r)≤ψSB(r)\psi_{\mathrm{minmod}}(r) \leq \psi_{\mathrm{VL}}(r) \leq \psi_{\mathrm{MC}}(r) \leq \psi_{\mathrm{SB}}(r) for all r∈Rr \in \mathbb{R}.


2. Discontinuous Square-Wave Advection & Discrete Total Variation Audit

We advect a sharp rectangular concentration pulse q0(x)∈{0,1}q_0(x) \in \{0, 1\} through one complete periodic revolution (t=L/u=1.0t = L/u = 1.0) on N=200N = 200 cells at CFL=0.5\mathrm{CFL} = 0.5 using tvd_advection.advect_1d_periodic. Because q0q_0 jumps up once from 0→10 \to 1 and jumps down once from 1→01 \to 0, its exact periodic total variation is TV(q0)=∣1−0∣+∣0−1∣=2.0\mathrm{TV}(q_0) = |1 - 0| + |0 - 1| = 2.0 at all times. We audit three exact invariants:

  1. Telescoping Mass Conservation: ∑iqinΔx=∑iqi0Δx\sum_i q_i^n \Delta x = \sum_i q_i^0 \Delta x to rounding error (10-14) for every conservative flux scheme.

  2. Step-by-Step TVD Monotonicity: TV(qn+1)≤TV(qn)\mathrm{TV}(q^{n+1}) \leq \mathrm{TV}(q^n) at every single step for upwind and all four Sweby limiters, versus immediate TV blow-up (TV>2.4\mathrm{TV} > 2.4) for lax_wendroff.

  3. Shock/Contact Sharpness: Comparing L1L_1 error 1N∑i∣qiN−qi0∣\frac{1}{N}\sum_i |q_i^N - q_i^0| across limiters.


Demonstration 2: One-Period Square-Wave Advection — Gibbs Oscillations vs TVD Sharpness
=======================================================================================
Scheme         |  Mass Drift |  Max dTV/step |  Final TV |     Min q |     Max q |  L1 Error
--------------------------------------------------------------------------------------------
upwind         |    1.11e-16 |     +4.44e-16 |    1.9946 |   +0.0000 |   +0.9973 |   0.07974
lax_wendroff   |    1.67e-16 |     +5.00e-01 |    3.9352 |   -0.2321 |   +1.2321 |   0.05225
minmod         |    5.55e-17 |     +4.44e-16 |    2.0000 |   +0.0000 |   +1.0000 |   0.03141
van_leer       |    1.11e-16 |     +4.44e-16 |    2.0000 |   +0.0000 |   +1.0000 |   0.02038
mc             |    2.78e-16 |     +6.66e-16 |    2.0000 |   +0.0000 |   +1.0000 |   0.01695
superbee       |    3.89e-16 |     +6.66e-16 |    2.0000 |   +0.0000 |   +1.0000 |   0.00876
<Figure size 1210x451 with 2 Axes>

Figure 6.2. Advection of a square pulse over one period on 200 cells at Courant number 0.5. (a) The final profiles of six schemes. (b) Total variation against the time step: it grows for the Lax–Wendroff scheme and does not grow for the upwind scheme and the limited schemes, whose curves coincide.

What Demonstration 2 shows. After one period, first-order upwind rounds the corners of the square wave (L1L_1 error 0.080, the largest of the six schemes) but creates no new extrema, while lax_wendroff oscillates, with negative values (qmin⁡=−0.232q_{\min} = -0.232), overshoots (qmax⁡=1.232q_{\max} = 1.232) and a total variation that rises from 2 to 3.94. All four nonlinear Sweby limiters hold 0≤qin≤10 \leq q_i^n \leq 1 and TV(qn)≤2.0000\mathrm{TV}(q^n) \leq 2.0000 at every step, and superbee has the smallest L1L_1 error (0.0088).


3. Smooth Gaussian + Square Wave Trade-Off & Grid Convergence Rate

If superbee is sharpest on step discontinuities, why don’t all industrial CFD codes use superbee everywhere? Because superbee applies an anti-diffusive flux factor ψ=2\psi = 2 on gentle slopes, over-steepening (“squaring off”) smooth Gaussian hills. We test a composite two-pulse profile (a smooth Gaussian peak plus a sharp rectangular pulse) alongside a formal grid-refinement order-of-accuracy study on a smooth C∞C^\infty wave q(x,0)=sin⁡4(πx)q(x, 0) = \sin^4(\pi x).


Demonstration 3: Composite Gaussian + Square Wave & Smooth-Wave Mesh Convergence
================================================================================
Observed L1 convergence order (N=256->512): Upwind = 0.973, van Leer = 2.185, MC = 2.371
N=512 L1 error: Upwind = 7.820e-03 vs van Leer = 2.140e-05 vs MC = 8.517e-06
<Figure size 1210x451 with 2 Axes>

Figure 6.3. (a) A Gaussian and a square pulse after one period for the upwind scheme and four limiters. (b) L1L_1 error after one period for a smooth sin⁡4\sin^4 profile against the number of cells; the legend gives the fitted slopes.

What Demonstration 3 shows. On the smooth sin⁡4(πx)\sin^4(\pi x) wave, van_leer and mc achieve O(Δx2)O(\Delta x^2) convergence in the L1L_1 norm (at N=512N = 512 their errors are 365 and 918 times smaller than that of first-order upwind), while on the composite wave packet mc and van_leer avoid superbee’s flat-topping of the smooth Gaussian hill, which is why van_leer and mc are common general-purpose choices.


4. Courant Number Sweep

Look closely at the anti-diffusive term in Equation (1.2): 12(1−ν)ψ(r)(qi+1−qi)\frac{1}{2}(1 - \nu)\psi(r)(q_{i+1} - q_i). What happens as we sweep the Courant number ν=uΔt/Δx∈{0.2,0.5,0.8,1.0}\nu = u\Delta t/\Delta x \in \{0.2, 0.5, 0.8, 1.0\} over one fixed physical revolution T=L/uT = L/u? At the unit Courant number ν=1.0\nu = 1.0, (1−ν)=0(1 - \nu) = 0 vanishes identically, turning every flux-limited scheme into exact characteristic cell-to-cell shift qin+1=qi−1nq_i^{n+1} = q_{i-1}^n with zero numerical diffusion.


Demonstration 4: Courant Number Sensitivity & Exact Shift Property at CFL = 1
=============================================================================
   CFL |  Steps |  Upwind L1 Err |  van Leer L1 Err |  Superbee L1 Err
----------------------------------------------------------------------
  0.20 |    800 |   1.127754e-01 |     2.792668e-02 |     1.114020e-02
  0.50 |    320 |   8.913654e-02 |     2.402122e-02 |     1.095456e-02
  0.80 |    200 |   5.629568e-02 |     1.898174e-02 |     1.050752e-02
  1.00 |    160 |   0.000000e+00 |     0.000000e+00 |     0.000000e+00

Inside the algorithm

In Demonstration 4, taking smaller time steps (CFL=0.20\mathrm{CFL} = 0.20, requiring 800 updates per period) actually increases numerical diffusion compared to CFL=0.80\mathrm{CFL} = 0.80, because modified-equation numerical diffusivity scales with (1−ν)(1 - \nu) and accumulates across more discrete projection steps.

Below we inspect tvd_advection._step_1d_periodic_flux_limited directly and verify a NumPy implementation, for both positive (u>0u > 0) and negative (u<0u < 0) advection velocities, against tvd_advection.advect_1d_periodic to rounding error.

Check against the library


Inside the Algorithm: tvd_advection._step_1d_periodic_flux_limited
==================================================================
def _step_1d_periodic_flux_limited(q: np.ndarray, cfl_signed: float, kind: str) -> np.ndarray:
    """Advance 1-D periodic scalar q by one conservative flux-limited step at Courant number cfl_signed."""
    if abs(cfl_signed) < 1e-15:
        return q.copy()
    if cfl_signed > 0.0:
        nu = cfl_signed
        dq_up = q - np.roll(q, 1)
        dq_loc = np.roll(q, -1) - q
        r_face = np.where(np.abs(dq_loc) > 1e-14, dq_up / np.where(np.abs(dq_loc) > 1e-14, dq_loc, 1.0), 0.0)
        psi = flux_limiter(r_face, kind=kind)
        # Interface flux F_{i+1/2} / u:
        f_half = q + 0.5 * (1.0 - nu) * psi * dq_loc
        return q - nu * (f_half - np.roll(f_half, 1))
    nu = -cfl_signed
    # By reflection symmetry for u < 0:
    q_rev = q[::-1]
    q_next_rev = _step_1d_periodic_flux_limited(q_rev, nu, kind=kind)
    return q_next_rev[::-1]

Manual vs library max |diff| = 0.00e+00; negative-velocity TVD verified.

Exercises

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

  1. Verify a result. 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).

  2. Find how it fails. 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.

  3. Implement it yourself. 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).


Self-check for the exercises
============================
Sweby TVD admissibility and square-wave monotonicity checks passed
All checks passed.