💧 Real-Time Fluid Simulation

A 2D Navier–Stokes solver using Jos Stam's unconditionally stable semi-Lagrangian method. Click and drag on the canvas to inject velocity and dye. The solver handles diffusion, advection, and pressure projection each frame to keep the flow divergence-free (incompressible). 🇺🇦 Українська

Display

Presets

Max speed0
Total density0
Grid size

The Navier–Stokes Equations

The incompressible Navier–Stokes equations govern fluid motion: ∂u/∂t = −(u·∇)u + ν∇²u + f paired with the continuity constraint ∇·u = 0. Stam's method splits each time step into three stages: (1) Add forces — inject velocity/density from mouse input; (2) Diffuse — spread quantities using an implicit Gauss–Seidel solver; (3) Advect — trace particle positions backward in time (semi-Lagrangian) and interpolate; then (4) Project — remove divergence from the velocity field using a Helmholtz decomposition. This approach is unconditionally stable for any time step, unlike explicit methods that blow up when dt is large.