The science of simulation / Chapter 03
Follow the flow.
Account for every cell.
Move a tracer through a channel. Find out what a numerical method preserves and what it changes.
Your first experiment
Will the plume return unchanged? Keep physical diffusivity at zero and run one circuit. Compare the calculated shape with the exact reference, then try a finer mesh.
The experiment / Conservative transport
Transport a tracer.
A one-metre periodic channel: material leaving the right end re-enters on the left. Flow speed is prescribed.
Understand the numerics · inspect a cell and its fluxes
Every face has two neighbours.
Click a cell in the plot, or choose it below. The same face flux leaves one cell and enters the next. When all cell budgets are added, the internal contributions cancel.
This shared-flux bookkeeping is why a finite-volume method can preserve total tracer while still changing its shape.
∂c/∂t + ∂(uc)/∂x = κ ∂²c/∂x²
The solver stores a cell average, rather than the value at a point. It uses a first-order upwind advective flux, a centred diffusive flux and a forward-Euler time step. The boundaries are periodic, so material leaving the right end re-enters on the left.
Fᵢ₊½ = u cᵢ − κ(cᵢ₊₁ − cᵢ)/Δx
cᵢⁿ⁺¹ = cᵢⁿ − (Δt/Δx)(Fᵢ₊½ − Fᵢ₋½)
The amber reference is an analytical Fourier-series solution, integrated over each cell. Physical diffusion acts in both solutions; additional spreading in the numerical solution is a discretization effect.
C = uΔt/Δx · D = κΔt/Δx² · C + 2D ≤ 1
This explicit scheme uses the displayed stability restriction. It is a condition for this particular discretization, not a universal CFD rule. An unstable step is blocked so it cannot be mistaken for a physical result.
Check the result · compare four meshes
A conserved solution can still be inaccurate.
Repeat the pure-transport problem for one full circuit on four meshes. Every run conserves mass; finer cells reduce the shape error. This separates conservation from accuracy.
20, 40, 80 and 160 cells · u = 0.5 m/s · κ = 0 · C = 0.5 · final time 2 s.
Run the study to compare the error against the exact solution.
Try this: set physical diffusivity to zero and Courant number to 1. Why does this particular one-dimensional upwind scheme transport the cell averages exactly by one cell each step?
Reveal the explanation
At C = 1 and D = 0, the update reduces to cᵢⁿ⁺¹ = cᵢ₋₁ⁿ. It is a perfect cell shift for constant velocity on this uniform periodic mesh. This special case is not a reason to use C = 1 indiscriminately in a general CFD solver.
What a complete engineering CFD study adds
Go further · why pressure corrects the flow
What moves a fluid?
A velocity field carries momentum from place to place. Viscosity redistributes it. Pressure gradients and body forces accelerate it. Mass must balance throughout.
CFD is the application: computational fluid dynamics. Finite volumes, finite differences and finite elements are different ways to discretize its equations. FEM and CFD are not opposing categories.
ρ[∂u/∂t + (u · ∇)u] = −∇p + μ∇²u + f
∇ · u = 0
Constant-density Newtonian fluid; μ is dynamic viscosity. Geometry, initial conditions and boundary conditions complete the problem.
A second experiment / One incompressibility correction
Pressure repairs a flow that does not balance.
An intermediate velocity can move too much fluid into some cells and too much out of others. Solve a pressure equation, then subtract its gradient. Watch the local volume imbalance fall.
Click either field, or select its coordinates.
See the projection method, the mesh and the boundary conditions
∇²p = (ρ/Δt) ∇ · u*
unew = u* − (Δt/ρ) ∇p
The domain is a periodic 1 m × 1 m square with 24 × 24 cells, density ρ = 1 kg/m³ and correction interval Δt = 0.02 s. Pressures live at cell centres; velocity components live on faces. Matching discrete divergence and gradient operators form a five-point Poisson equation. Weighted Jacobi iterations solve it, with zero mean pressure fixing the arbitrary constant.
The starting field is a known divergence-free circulation plus a deliberately added gradient field. This manufactured problem lets us test the correction against a known answer. It is an actual numerical pressure projection, one stage of an incompressible solver; it does not evolve the full Navier–Stokes equations, model turbulence or predict a product flow. The arrows depict computed velocities rather than particles traced over time.
A small pressure residual means the algebraic system has been solved accurately. It does not prove the chosen physical model matches an experiment.
Sources and further reading
- Clawpack documentation: the project's finite-volume framework for conservation laws.
- LeVeque: advection–diffusion example: companion material for Finite Volume Methods for Hyperbolic Problems.
- A. J. Chorin, Numerical solution of the Navier–Stokes equations (1968): the projection approach to incompressible flow.
- Chorin's original paper, author-hosted PDF.
The browser experiments are independent educational implementations; they do not embed these software packages.
What connects the core path: a material law relates stress to deformation, a finite element model assembles local equations, and a flow calculation tracks conserved quantities through cells.