Advection–diffusion and limiters
FVM advection_diffusion_fvm.py
A fluid carries a concentration towards a wall faster than diffusion can spread it, so all the change is squeezed into a thin boundary layer at the wall. On a grid too coarse to resolve that layer, what does each finite-volume scheme do with it?

One marker per cell centre, for \(0.7\le x\le1\), against the exact solution (dashed). The 20 cells are five times wider than the layer.
The problem
with the exact solution \(u=(e^{x/\varepsilon}-1)/(e^{1/\varepsilon}-1)\). The cell Péclet number is 2.5.
The jNO code
The convection is written in divergence form, and the scheme rides on the outer derivative, as a jno.fd(...)
stencil does. Five schemes are one dictionary:
schemes = {
"first order": jno.fv(recon="none"),
"unlimited": jno.fv(limiter=None),
"van Albada": jno.fv(),
"minmod": jno.fv(limiter="minmod"),
"HLL + van Leer": jno.fv(flux="hll", limiter="vanleer"),
}
for name, scheme in schemes.items():
prob = jno.fvm([ui.d(x, scheme=scheme) - EPS * ui.xx, u(xl) - 0.0, u(xr) - 1.0])
The default Rusanov flux is exact upwinding for a linear flux, and the default van Albada limiter is smooth, so Newton converges on the steady problem.
Result
The unlimited second-order reconstruction undershoots to \(-0.09\). First order, van Albada, minmod and HLL with van Leer all stay in \([0,1]\).
Full script
The whole script, as it runs in the tests
"""Convection-dominated transport: numerical fluxes and limiters with ``jno.fv``.
u' - eps u'' = 0 on (0, 1), u(0) = 0, u(1) = 1, eps = 0.01: a boundary layer at x = 1.
Write the convection in divergence form, ``ui.d(x, scheme=jno.fv(...))``: the scheme rides on the outer
derivative, as a ``jno.fd(...)`` stencil does. At a cell Peclet number of 2.5 the unlimited second-order
reconstruction oscillates; every limiter keeps the solution in [0, 1].
"""
import jax
jax.config.update("jax_enable_x64", True)
import numpy as np
import jno
run = jno.setup(__file__)
EPS = 0.01
d = jno.Path(0.0, 0.0).line_to(1.0, 0.0).curve(size=0.05).domain()
x = d.variable("interior", split=True)[0]
xl, xr = d.variable("left", split=True)[0], d.variable("right", split=True)[0]
u = d.unknown()
ui = u.bind(x=x)
schemes = {
"first order": jno.fv(recon="none"),
"unlimited": jno.fv(limiter=None),
"van Albada": jno.fv(),
"minmod": jno.fv(limiter="minmod"),
"HLL + van Leer": jno.fv(flux="hll", limiter="vanleer"),
}
sols = {}
for name, scheme in schemes.items():
prob = jno.fvm([ui.d(x, scheme=scheme) - EPS * ui.xx, u(xl) - 0.0, u(xr) - 1.0])
sols[name] = sol = np.asarray(prob.solve())
print(f"{name:15s} range [{sol.min():+.3f}, {sol.max():.3f}]")
if name != "unlimited":
assert sol.min() > -1e-3 and sol.max() < 1 + 1e-3