Home

HomeChapter 03 / 8Stable fluids on the GPU

Implemented

233 words · 1 min read · Arsh Shah

Fluid

Making fluid from velocity

A fluid is not drawn. It emerges from a sequence of small corrections applied to a field: move it, disturb it, measure its compression, then remove that compression. RowSim solves a two-dimensional incompressible velocity field using Jos Stam’s stable-fluids decomposition on Metal, with architecture-conditioned pressure solvers and a second ripple field that carries wave memory through the same carrier flow.

Incompressible Navier–Stokes, decomposed

Fluid is not a texture. Each frame moves the field, disturbs it, measures compression, and removes that compression so ∇·u = 0. Stam’s stable-fluids decomposition is the method;[113] the claim is perceptual rather than numerical — that an incompressible field is what makes the motion read as fluid rather than as a smear. Dijkstra’s point about abstraction holds here too: the field is exact at a level other than the numeric readout.[036][Th.]

Governing relations

Three equations behind the fluid

How velocity changes each frame.

Fig. 03.1

Momentum, divergence-free flow, and the pressure Poisson solve — the three relations the fluid chapter depends on.

Trace backward to move forward

Semi-Lagrangian advection is unconditionally stable. The price is blur; vorticity confinement buys the swirl back.[043][116] Stam’s later GPU notes treat the same trade as a real-time constraint rather than a numerical luxury.[114]

Velocity field

How a 2D flow looks on a grid.

A synthetic curl-noise field for teaching — not the Metal advection or vorticity kernels. Click a mode to focus on flow, swirl, or speed.

01 · FlowEach arrow is a velocity sample. Direction is where the fluid moves; longer means faster.

Fig. 03.2

Teaching velocity field (curl noise). Arrows show flow; tint shows swirl. Not the Metal vorticity kernel.

Pressure makes the field incompressible

Sixteen red/black pairs on Apple Silicon; twenty Jacobi sweeps on the fallback. Same constraint, two ownership models. Bridson’s fluids notes are the engineering reading of that constraint.[022]

Pressure solve

Checkerboard updates, faster convergence.

Brightness is pressure on a 14×9 grid. Red and black cells take turns so neighbours stay fixed during each sweep — about 2× faster than Jacobi for the same sweep count.

01 · RedUpdate every red cell from its four black neighbours. Half the grid advances in one parallel pass.

Fig. 03.3

Checkerboard pressure solve on a 14×9 grid. Red then black sweeps; sixteen pairs on Apple Silicon.

A second field for wave memory

A damped wave rides the carrier and couples back into velocity. Roll and azimuth become rings, not badges.

Wave profile

A 1D slice of the ripple field.

Same damped wave update as WaveCompute.metal. Open ends, two pulse sites, defaults c=0.4 and d=0.02.

01 · HeightSolid curve is wave height h(x,t) right now — the surface the ripples ride on.

Fig. 03.4

1D damped wave matching WaveCompute.metal. Ghost = previous frame; pulses ≈ oar entry (c=0.4, d=0.02).

Related

Open all formulas

Works cited

Superscripts use the thesis bibliography number. Click a number to return to the first mention.

  1. [113]

    Jos Stam (1999).

    Stable fluids.

    Proceedings of SIGGRAPH ’99, pp. 121–128. ACM.

    doi:10.1145/311535.311548

  2. [036]

    Edsger W. Dijkstra (1972).

    The humble programmer.

    Communications of the ACM, 15(10), 859–866.

    doi:10.1145/355604.361591

  3. [114]

    Jos Stam (2003).

    Real-time fluid dynamics for games.

    Game Developers Conference (GDC).

  4. [043]

    Ronald Fedkiw, Jos Stam, and Henrik Wann Jensen (2001).

    Visual simulation of smoke.

    Proceedings of SIGGRAPH 2001. ACM.

    doi:10.1145/383259.383260

  5. [022]

    Robert Bridson (2015).

    Fluid Simulation for Computer Graphics.

    CRC Press, 2nd edition.

  6. [116]

    John Steinhoff and David Underhill (1994).

    Modification of the Euler equations for “vorticity confinement”.

    Physics of Fluids, 6(8), 2738–2744.

    doi:10.1063/1.868164

  7. [Th.]

    Arsh Shah (2026).

    RowSim: Designing and Evaluating Ambient Interaction in Mixed-Reality Rowing.

    Master’s thesis, Dalhousie University, Halifax, NS.

    ch. 3hdl.handle.net/10222/86331PDF