Essay · Visual studies

A convincing fluid is not a converged solver

Separate advection, numerical diffusion, and pressure projection, then measure Jacobi convergence.

A fluid demo can look more convincing as its numerical errors become harder to see. Dye hides the grid, interpolation smooths rough motion, and extra vorticity puts back the small swirls that transport lost. The useful question is which parts of the image come from the equations and which come from the numerical and rendering choices.

The visualization adapts Pavel Dobryakov’s WebGL solver. Dragging adds momentum and dye to grid fields. Pressure convergence opens an independent Poisson experiment so you can inspect a quantity the colors do not reveal: the residual left after the pressure solve.

Separate transport from incompressibility #

An incompressible velocity field satisfies ∇⋅u=0\nabla\cdot u=0. A typical projection scheme first computes an intermediate velocity u∗u^* using advection and forces, then removes a pressure gradient:

Δp=ρΔt∇⋅u∗,un+1=u∗−Δtρ∇p.\Delta p=\frac{\rho}{\Delta t}\nabla\cdot u^*,\qquad u^{n+1}=u^*-\frac{\Delta t}{\rho}\nabla p.

These equations suggest a clean cancellation of divergence. On a grid, the discrete divergence, gradient, Laplacian and boundary treatment must agree for that cancellation to hold. An accurate solve of the wrong discrete operator is not an accurate projection.

The dye is a transported scalar field. It makes velocity visible but does not establish that the velocity is divergence-free, energy-conserving or physically calibrated. Keep that distinction in mind when a visually appealing setting seems “more realistic.”

Stable transport can still lose information #

Semi-Lagrangian advection traces a cell backward through the velocity field and interpolates the previous field at the departure point. It is robust at interactive time steps, but interpolation introduces numerical diffusion. Fine structures disappear even when there is little intended physical viscosity.

The Vorticity control adds a confinement force to reinforce rotational detail. That compensates visually for lost motion; it is not a direct material viscosity setting. Dissipation controls dye fading. A persistent bright filament can reflect a dye setting rather than a conserved structure in the flow.

Try the same short stroke with low and high vorticity, then change only dissipation. Pause and reset between comparisons. The first intervention changes the motion; the second changes how long its tracer remains visible.

Measure what the pressure iteration leaves behind #

The analytical experiment solves a five-point discrete Poisson equation on a unit square with homogeneous Dirichlet pressure boundaries. Its right-hand side is a sine mode. Starting from zero pressure, Jacobi iteration updates each interior cell from the previous iteration’s four neighbors.

The reported residual is

∥b−Δhp∥2∥b∥2.\frac{\lVert b-\Delta_h p\rVert_2}{\lVert b\rVert_2}.

At fixed iteration count, change the grid from 24×24 to 48×48. The smooth mode converges more slowly. For this sine eigenmode, the Jacobi error multiplier is cos⁡(mπ/(n+1))\cos(m\pi/(n+1)) per step, where mm is the mode and nn the interior grid width. Low-frequency error on a fine grid can survive hundreds of iterations.

The pressure image normalizes its colors to the current maximum. It may therefore look nearly unchanged while the numerical residual differs substantially. The fixed logarithmic residual plot is the evidence to use. Increase the sine mode and compare convergence, remembering that Jacobi is not uniformly good at removing every grid-frequency error.

Resolution changes the algorithmic budget #

Doubling a two-dimensional grid gives four times as many cells. For smooth error, Jacobi can also need roughly four times as many iterations to achieve a comparable reduction. A seemingly modest resolution change can therefore make this part of the solve about sixteen times more expensive.

Multigrid addresses the slow mode by moving it onto a coarser grid, where it becomes easier to remove. FFT-based solvers exploit special boundary conditions and regular geometry. Conjugate-gradient methods need the appropriate symmetric positive-definite formulation and benefit from preconditioning. The useful choice depends on the operator and boundaries, not on which algorithm name sounds most sophisticated.

The convergence panel does not instrument the WebGL renderer. Its forcing and boundary conditions are controlled for analysis. Before making a physical claim about a simulation, I would want residuals, conservation diagnostics and refinement studies from that simulation itself. A stable time step and a pleasing vortex are necessary for an interactive demo; neither establishes convergence to the intended flow.

Further reading #

Dobryakov’s WebGL Fluid Simulation provides the renderer. NVIDIA’s Fast Fluid Dynamics Simulation on the GPU connects advection and projection to texture-based computation. Stam’s Stable Fluids explains the numerical approach that made this class of interaction practical.

Related articles