Fluid dynamics
Real-time 2D fluid simulation using Jos Stam’s stable fluids method. Click and drag to inject velocity and dye into the fluid. Place obstacles that deflect the flow. Switch between visualization modes to see dye advection, velocity fields, pressure, and vorticity.
∂u/∂t + (u · ∇)u = −∇p + ν∇²u ∇ · u = 0
Navier-Stokes equations
The Navier-Stokes equations describe how fluids move. They encode conservation of momentum and mass for a viscous, incompressible fluid. Despite their deceptive simplicity, proving whether smooth solutions always exist in 3D is one of the Clay Millennium Prize Problems.
Stable fluids method
Jos Stam’s 1999 stable fluids algorithm solves the Navier-Stokes equations using operator splitting: add forces, diffuse (viscosity), advect (self-advection via semi-Lagrangian backtracing), and project (enforce incompressibility via pressure solve). The method is unconditionally stable — no matter how large the time step, the simulation never blows up.
Visualization modes
Dye shows passive scalar transport — ink carried by the flow. Velocity renders the vector field directly. Pressure shows the scalar pressure field that enforces incompressibility. Vorticity highlights rotating regions of the fluid — the curl of the velocity field. Speed maps the magnitude of velocity to color.
Obstacles
Obstacles enforce a no-slip boundary condition: fluid velocity is set to zero inside solid cells. This creates the flow separation, vortex shedding, and wake patterns that make fluid dynamics visually rich.