← index
project· 12 min read

What Numerical Diffusion Really Is

Numerical diffusion is not a vague error: it is a real viscosity that the scheme adds to your equations, and it can be predicted and measured to three digits. A few lines of C show how big it is and where it comes from.

CCFDNumerical Methods

Technical Index

  1. The equation you are really solving — The modified equation of the upwind scheme
  2. Three schemes, one profile — Diffusion, dispersion and limiters
  3. Measuring the viscosity — Theory and experiment, to three digits
  4. Accuracy and order — What “second order” means near a discontinuity
  5. False diffusion in 2D — When the flow is not aligned with the grid
  6. What this means for real CFD — Effective Reynolds number and scheme choice

Everybody who has run a CFD simulation has heard of numerical diffusion: “upwind is diffusive”, “use a second-order scheme”, “the result is smeared”. It is often described as a generic inaccuracy, something like noise. It is not. Numerical diffusion is a physical viscosity that the discretization adds to the equations, with a precise value that depends on the mesh size, the velocity and the time step. In this article I derive it, then measure it with a small C program, and show that the two agree to three significant digits.

1. The equation you are really solving

Take the simplest transport equation there is, pure advection of a quantity uu with constant velocity a>0a > 0:

∂u∂t+a ∂u∂x=0\frac{\partial u}{\partial t} + a\,\frac{\partial u}{\partial x} = 0

Its exact solution just moves the initial profile at speed aa without changing its shape: nothing spreads, nothing decays. There is no diffusion in this equation.

The first-order upwind scheme approximates the space derivative with the value on the upstream side:

uin+1=uin−C (uin−ui−1n),C=a ΔtΔxu_i^{n+1} = u_i^n - C\,\left(u_i^n - u_{i-1}^n\right), \qquad C = \frac{a\,\Delta t}{\Delta x}

where CC is the CFL (Courant) number. Expanding ui−1u_{i-1} and un+1u^{n+1} in Taylor series and keeping the first terms that the scheme gets wrong, one finds that the discrete solution satisfies, to leading order, a different equation:

∂u∂t+a ∂u∂x=νnum ∂2u∂x2,νnum=a Δx2 (1−C)\frac{\partial u}{\partial t} + a\,\frac{\partial u}{\partial x} = \nu_{num}\,\frac{\partial^2 u}{\partial x^2}, \qquad \nu_{num} = \frac{a\,\Delta x}{2}\,(1 - C)

This is the modified equation. The scheme does not solve pure advection: it solves an advection–diffusion equation, with a diffusion coefficient νnum\nu_{num} that does not exist in the physics. That is numerical diffusion, and the formula already says a lot:

  • it is proportional to Δx\Delta x: halving the cell size halves it, but never removes it;
  • it is proportional to the velocity: faster flow, more numerical viscosity;
  • it depends on the time step through (1−C)(1 - C): it vanishes at C=1C = 1, where upwind moves the profile exactly one cell per step, and it is largest for small time steps. For an implicit steady-state solver (C→0C \to 0 in practice) it is simply a Δx/2a\,\Delta x / 2.

The last point is counterintuitive: reducing the time step makes this scheme more diffusive, not less.

2. Three schemes, one profile

To see it, I wrote numdiff.c, which advects a profile on a periodic domain [0,1)[0, 1) with a=1a = 1 for exactly one revolution (t=1t = 1): the exact solution at the end is the initial profile. The profile contains a square wave (a discontinuity) and a Gaussian (a smooth bump, standard deviation σ0=0.04\sigma_0 = 0.04).

I compare three schemes, all written as one flux-limited family, which makes the difference between them a single function ϕ\phi:

Fi+1/2=a ui+a2 (1−C) ϕ(ri) (ui+1−ui),ri=ui−ui−1ui+1−uiF_{i+1/2} = a\,u_i + \frac{a}{2}\,(1 - C)\,\phi(r_i)\,\left(u_{i+1} - u_i\right), \qquad r_i = \frac{u_i - u_{i-1}}{u_{i+1} - u_i}
Scheme Limiter ϕ(r)\phi(r) Order Modified equation adds
upwind 0 1 diffusion ∝∂2u/∂x2\propto \partial^2 u/\partial x^2
Lax-Wendroff 1 2 dispersion ∝∂3u/∂x3\propto \partial^3 u/\partial x^3
van Leer (TVD) (r+∣r∣)/(1+∣r∣)(r + \lvert r\rvert)/(1 + \lvert r\rvert) 2 where smooth switches between the two

The second term of the flux is an anti-diffusive correction: Lax-Wendroff adds it everywhere and cancels the numerical diffusion exactly, van Leer adds it only where the solution is smooth (where r≈1r \approx 1) and switches it off near jumps and extrema.

Profiles after one revolution with the three schemes

Scheme Minimum of uu Maximum of uu Gaussian peak
exact 0 1 1.00
upwind 0.0002 0.954 0.62
Lax-Wendroff −0.231 1.232 0.99
van Leer 0.0000 1.000 0.94

200 cells, CFL = 0.5, one revolution. Values of uu are dimensionless (the initial profile goes from 0 to 1).

  • Upwind is smooth and never creates new maxima or minima, but it diffuses: the square wave becomes a bell, and the Gaussian loses about 37% of its peak while getting wider. This is exactly what a physical viscosity would do.
  • Lax-Wendroff has no numerical diffusion, but its error is dispersive: waves of different wavelength travel at slightly different speeds, and around the discontinuity they separate into oscillations, with values down to −0.23 and up to 1.23. For a concentration, a temperature or a turbulent kinetic energy, these are unphysical values that can make a solver diverge.
  • van Leer keeps the square wave sharp and bounded between 0 and 1. The price is visible on the Gaussian: near the peak the limiter switches back to upwind, so it loses 6% of its height (“clipping”).

This is Godunov’s theorem at work: a linear scheme that never creates new extrema can be at most first order. You can have monotone or accurate, not both, unless the scheme is nonlinear, i.e. it adapts to the solution like a limiter does. Every TVD/NVD scheme in a CFD code (limitedLinear, vanLeer, MUSCL, SuperBee in OpenFOAM) is a version of this idea.

3. Measuring the viscosity

If numerical diffusion is really a viscosity, it should be measurable like one. A Gaussian under pure diffusion stays Gaussian, and its variance grows linearly in time:

σ2(t)=σ02+2 ν t⇒ν=σ2(t)−σ022 t\sigma^2(t) = \sigma_0^2 + 2\,\nu\,t \quad\Rightarrow\quad \nu = \frac{\sigma^2(t) - \sigma_0^2}{2\,t}

So the program advects the Gaussian with upwind for one revolution, computes the variance of the discrete solution before and after, and turns the growth into a viscosity. No fitting, no free parameter. Then it compares it with the modified equation, νnum=Δx (1−C)/2\nu_{num} = \Delta x\,(1 - C)/2 (here a=1a = 1 and the domain length is 1, so everything is dimensionless).

Measured numerical viscosity vs CFL number for four grids

Cells NN CFL CC ν\nu predicted ν\nu measured Measured / predicted
100 0.1 4.500e-3 4.559e-3 1.013
100 0.5 2.500e-3 2.501e-3 1.000
100 0.9 5.000e-4 4.995e-4 0.999
100 1.0 0 0 exact
200 0.1 2.250e-3 2.251e-3 1.000
200 0.5 1.250e-3 1.250e-3 1.000
400 0.1 1.125e-3 1.125e-3 1.000
800 0.1 5.625e-4 5.625e-4 1.000
800 0.9 6.250e-5 6.251e-5 1.000

Dimensionless viscosity (a=1a = 1, domain length 1). Full table in viscosity.csv.

The measured value matches the formula to three or four significant digits on every grid. The only visible deviation, 1.3% at N=100N = 100, C=0.1C = 0.1, is the coarsest and most diffused case, where the next terms of the Taylor expansion start to count. At C=1C = 1 the Gaussian comes back unchanged: zero viscosity, as predicted.

This is what “numerical diffusion” really means. It is not an unpredictable error spread over the solution: the upwind scheme solves the advection–diffusion equation with a well-defined viscosity, and the solution you get is the exact physical behaviour of a fluid with that viscosity. The plot also shows the time-step paradox: on every grid, the smaller the CFL number, the more viscous the result.

4. Accuracy and order

The same program measures the L1L_1 error after one revolution on grids from 50 to 1600 cells, separately for the smooth Gaussian and for the square wave.

L1 error vs number of cells

Profile Scheme L1 error, N = 100 L1 error, N = 1600 Observed order
Gaussian upwind 6.6e-2 8.7e-3 0.88
Gaussian Lax-Wendroff 2.6e-2 1.2e-4 2.00
Gaussian van Leer 9.5e-3 2.8e-5 2.19
square upwind 1.1e-1 2.8e-2 0.50
square Lax-Wendroff 7.4e-2 1.5e-2 0.60
square van Leer 3.4e-2 4.4e-3 0.74

L1 error: average absolute difference from the exact solution (dimensionless). Observed order: slope between N = 800 and N = 1600, i.e. the error is divided by 2p2^{p} when the cells are doubled.

Two lessons:

  • On a smooth profile the formal order is what you get: doubling the cells divides the upwind error by 2 and the second-order errors by 4. At 1600 cells upwind is still 300 times less accurate than van Leer.
  • On a discontinuity every scheme drops below first order. The error is concentrated in the few cells around the jump, and a smeared jump of width ww costs an error proportional to ww. For upwind the smearing width grows like νnum t∝Δx\sqrt{\nu_{num}\,t} \propto \sqrt{\Delta x}, hence order 0.5. “Second order” is a promise about smooth regions, not about shocks, interfaces or sharp fronts.

5. False diffusion in 2D

In more than one dimension a new effect appears. Consider a steady 2D flow at an angle θ\theta to the grid, carrying a step: u=1u = 1 on one side of a streamline, u=0u = 0 on the other. The exact solution keeps the step perfectly sharp along the streamline. With upwind on a square grid of side hh and velocity components (Ucos⁡θ,Usin⁡θ)(U\cos\theta, U\sin\theta), the modified equation has a diffusion term in each grid direction, and part of it acts across the streamlines. This is the classic false diffusion described by de Vahl Davis and Mallinson in the 1970s.

The program solves this problem on the unit square, with the step entering at the corner. With positive velocity components, upwind can be solved in a single sweep through the grid.

Steady upwind solution of a step advected at 0, 22.5 and 45 degrees

200 × 200 cells. Light: u=1u = 1, dark: u=0u = 0. Dashed line: position of the exact (sharp) step.

  • At 0°, with the flow aligned with the grid, the step stays perfectly sharp: zero cells smeared at the outlet. The numerical diffusion is all along the flow, where the solution does not change.
  • At 22.5° and 45° the step spreads more and more as it travels. The same scheme, the same mesh, the same physics: only the angle between the flow and the grid changed.

At 45° the update of every cell is simply the average of the cell on its left and the one below it. That is exactly the rule of a random walk moving left or down with equal probability: the value in a cell is the probability that such a walk reaches the "u=1u = 1" boundary first. Numerical diffusion here is literally a random walk on the mesh, and like any random walk its spread grows with the square root of the number of steps. The modified equation predicts it: at 45° the numerical viscosity is Uh/(22)U h / (2\sqrt{2}) in every direction, so after a distance ss the step should have a Gaussian profile with variance s h/2s\,h/\sqrt{2} and a 10–90% width of 2.563 s h/22.563\,\sqrt{s\,h/\sqrt{2}}.

Width of the smeared step vs distance, measured and predicted

Cells per side Width at s=0.1s = 0.1 Width at s=0.4s = 0.4 Width at s=1.0s = 1.0 Predicted at s=1.0s = 1.0
100 0.068 0.137 0.216 0.215
200 0.048 0.097 0.153 0.152
400 0.034 0.068 0.108 0.108

Width: distance across the flow between the points where u=0.1u = 0.1 and u=0.9u = 0.9. ss: distance travelled from the corner. Both as a fraction of the domain size.

Again, prediction and measurement agree within 1%. And the numbers are large: on a 100 × 100 grid a sharp interface becomes more than a fifth of the domain wide after crossing it. Refining the mesh helps slowly: 4 times more cells per side (16 times more cells) only halves the width, because it scales with h\sqrt{h}.

6. What this means for real CFD

Compare the numerical viscosity with the physical one. Take air (ν≈1.5⋅10−5\nu \approx 1.5\cdot10^{-5} m²/s) at U=10U = 10 m/s on a mesh with 1 mm cells, solved with first-order upwind in a steady (implicit) solver:

νnum≈U Δx2=10⋅0.0012=5⋅10−3 m2/s≈330 νair\nu_{num} \approx \frac{U\,\Delta x}{2} = \frac{10 \cdot 0.001}{2} = 5\cdot10^{-3}\ \text{m}^2/\text{s} \approx 330\,\nu_{air}

On a car 4 m long, the physical Reynolds number is UL/ν≈2.7⋅106U L / \nu \approx 2.7\cdot10^{6}. The flow that pure upwind would actually compute, wherever the velocity varies along the flow, behaves like one at about UL/νnum≈8 000U L/\nu_{num} \approx 8\,000. These are order-of-magnitude numbers (in a RANS simulation the turbulent viscosity is also hundreds of times the molecular one, and numerical diffusion only acts where the solution has gradients), but they show the point: with a first-order scheme, the mesh can easily be more viscous than the physics you want to simulate. Wakes decay too fast, vortices fade, separation moves, recirculation zones shrink.

What follows in practice:

  • Use upwind to start, not to finish. First-order upwind is extremely robust precisely because it is diffusive: the numerical viscosity damps everything. A common strategy is to start a difficult case with upwind and then switch to a second-order bounded scheme (linearUpwind, limitedLinear, LUST in OpenFOAM) for the results.
  • Bounded quantities need limiters. For quantities that must stay in a range (volume fractions, kk, ε\varepsilon, ω\omega, species), the overshoots of an unlimited second-order scheme like the −0.23 above can make the solver diverge. That is why the turbulence equations are often discretized with bounded or upwind-biased schemes even when the momentum equation is second order.
  • Align the mesh with the flow when you can. False diffusion is zero along the grid lines and maximal at 45°. Prism layers and hexahedral cells aligned with a boundary layer or a wake add little cross-stream diffusion; a tetrahedral mesh or a structured mesh crossed at an angle adds much more.
  • Refinement is slow medicine. With a first-order scheme the error falls like Δx\Delta x, and the width of a smeared front only like Δx\sqrt{\Delta x}. A second-order scheme on a coarser mesh is usually far cheaper than first-order on a finer one.
  • Smaller time steps do not fix it. For explicit upwind the numerical viscosity even grows as the CFL number decreases. Accuracy in space and in time are separate problems.
  • Numerical diffusion is not always the enemy. Some approaches use it on purpose: in implicit LES the dissipation of the scheme plays the role of the subgrid-scale model. The difference is that it is chosen and controlled, not suffered.

The common thread is the same as in the previous articles: a simulation is a model of a model. The equations are discretized, and the discretization changes the equations in a precise way. Knowing how is what turns a colourful picture into a result you can trust.

Reproduce it

All the files are available: numdiff.c, plot_nd.py and the data profiles.csv, convergence.csv, viscosity.csv, falsediff.csv.

gcc -O3 -march=native numdiff.c -o numdiff -lm
mkdir -p out && ./numdiff out        # all three experiments, ~0.3 s
mkdir -p figures && python3 plot_nd.py out figures   # SVG charts + 2D field images (needs ImageMagick)