The Lab
Original — built for the Lab

Ink

Every swirl here is the Navier–Stokes equations being solved live on your graphics card. Drag through the pool and the water you push has to go somewhere, so it curls back on itself. The page measures the one rule that makes it look like water: after every frame, what the stirring squeezed into the flow is cut by hundreds to a thousand times.

PhysicsFluid dynamicsStable FluidsWebGLMultigrid
After Jos Stam's "Stable Fluids", SIGGRAPH 1999
Loading demo…

Water is almost impossible to squeeze. Push on one part of it and the rest has to move out of the way at once, all the way across the pool. That single fact — incompressibility — is why a dragged finger leaves a pair of counter-rotating whirlpools behind it, why smoke rises in mushroom caps, and why two streams sliding past each other roll up into the curling waves physicists call Kelvin–Helmholtz billows. None of those shapes are programmed here. They fall out of the rule.

For decades, simulating that rule on a computer was slow and fragile: take too large a time step and the numbers blow up. In 1999 Jos Stam published a method he called Stable Fluids, built from two ideas. To move the fluid along, look backwards — ask where the water at each point came from a moment ago and copy what was there, which can never run away. Then, to make it incompressible, solve for a pressure field and subtract its slope, which removes exactly the part of the motion that would squeeze or stretch the water. The method was unconditionally stable, and within a few years it was running in games and film.

The surprise is how much work that second step does. Every frame, your strokes and the backward-looking transport leave the flow slightly compressible; the coral line on the chart shows how much. The pressure solve takes it back out, and the teal line shows what is left: at the default setting, several hundred to a thousand times less. Switch the solver to plain Jacobi and the gap collapses. Each Jacobi sweep only passes news one cell sideways, so with thirty sweeps the far side of the pool never hears about your stroke — the water bunches up and the ink gathers into sinks, as if it were a gas. Multigrid runs the same sweeps on coarser and coarser copies of the grid so the news crosses the pool in a handful of steps, and the water becomes water again.

The same algorithm, or close relatives of it, drives the smoke in visual effects, weather and ocean models, the airflow over a car in a wind tunnel simulation, and the swirl of paint in digital painting apps. The obstacle mode puts the letters G M in the stream: watch the wake shed eddies off their corners, the same way air peels off a bridge deck or a wing at a steep angle.

Next in the Lab
Strange AttractorOpen

Twenty thousand points of light trace Lorenz's butterfly. Drop a knot of 500 in one spot and watch the wings tear it apart.