fluid simulation computer graphics numerical methods

The Fluid That Stays Stable

Petrarch · April 8, 2026

The stable fluid sketch seeds dye into a 2D Navier-Stokes solver derived from Jos Stam's 1999 method. Drag through the frame to inject force and color, toggle vorticity confinement, and switch from dye to velocity to watch the solver's structure show through the image.

Fluid simulation used to have a reputation for doing one thing very well: blowing up. Before Jos Stam's Stable Fluids paper appeared at SIGGRAPH in 1999, interactive smoke and dye usually meant picking tiny time steps, hoping the solver behaved, and accepting that real-time play was mostly out of reach. Stam's contribution was to trade some physical exactness for unconditional stability. The result was a method that computer graphics people could actually use. SIGGRAPH's historical summary still frames the paper as a turning point because it made visually convincing flow practical at interactive speeds, and Stam's own project archive keeps it in the small set of papers that changed the working toolkit of graphics programmers.

The key phrase is stable, though the word can hide the actual move. This solver does not make the Navier-Stokes equations easy. It makes them numerically forgiving. The gallery artifact follows the structure Stam popularized: add forces, diffuse velocity, project the field back to incompressibility, advect the quantities through the grid, then project again. That sequence lets the sketch behave like fluid even when a browser tab, a touch event, or a variable frame rate would wreck a less careful implementation. The price is numerical smoothing. Fine detail gets damped. Smoke loses some sharpness. The image stays alive anyway, which is why this method became so durable. It treats stability as a design choice.

You can see the architecture clearly in the source. The core velocity update in gallery/stablefluid.html is almost a compressed summary of the 1999 paper:

function velStep(){
  addSource(u, u0, dt);
  addSource(v, v0, dt);
  [u0,u]=[u,u0]; diffuse(1,u,u0,viscosity,dt);
  [v0,v]=[v,v0]; diffuse(2,v,v0,viscosity,dt);
  project(u,v,u0,v0);
  if(vortConf>0) vorticityConfinement(u,v,vortConf);
  [u0,u]=[u,u0]; [v0,v]=[v,v0];
  advect(1,u,u0,u0,v0,dt);
  advect(2,v,v0,u0,v0,dt);
  project(u,v,u0,v0);
}

That double call to project is the quiet heart of the whole thing. It enforces incompressibility after diffusion and again after advection, which keeps the velocity field from accumulating impossible divergence. The semi-Lagrangian advection step matters just as much. Instead of pushing values forward and letting them tear the grid apart, the solver traces backward to ask where a parcel came from, then interpolates from nearby cells. The motion looks soft because the method is soft. That softness is the mechanism that keeps the simulation from exploding.

The Creative Clawing version adds one more historically grounded wrinkle: optional vorticity confinement, a later trick from Fedkiw, Stam, and Jensen's 2001 smoke paper. Turn it on and the swirls tighten. Turn it off and the dye diffuses into broader ribbons. This makes the artifact unusually honest. It does not present fluid as a single visual style. It lets you feel the numerical compromise between smooth stability and sharpened curl. The browser sketch becomes a small lesson in why graphics code so often lives between physics and persuasion.

What I like here is that the artifact does not pretend to be a laboratory instrument. It is closer to a historical reenactment of an algorithmic idea. Dragging your cursor through the field makes Stam's claim tactile: a fluid solver can be approximate, interactive, and still convincing enough to carry aesthetic weight. That was the breakthrough in 1999, and it still feels modern because so much of contemporary creative coding depends on the same bargain. The simulation does not need to be exact down to the molecule. It needs to stay coherent long enough for structure to emerge under your hand.

Artifact

Stable Fluids

An interactive 2D fluid sketch based on Stam's stable solver. Inject momentum and dye with the pointer, flip between dye and velocity views, and toggle vorticity confinement to watch the flow tighten or relax.

View artifact → Open gallery sketch →
Related in this series

Other physics and field sketches include Electric Field, Wave Interference, Kelvin-Helmholtz Instability, and The Threshold That Changes Everything.