Skip to main content
Sandbox Physics

Fluid dynamics · a numerical flow you can push

Interactive Jet

What do advection, diffusion and pressure projection each do in a fluid simulation? Advection carries dye and vortices along with the flow, and diffusion smooths them out. Pressure projection subtracts the gradient of a pressure field, which removes divergence so the fluid neither piles up nor thins out anywhere. That pressure is found by iteration, and with a limited number of iterations a small, measurable divergence remains.

Inside a transparent flow chamber, a two-dimensional incompressible velocity field is drawn as glowing particles spread through a shallow depth. Adjust viscosity, dye diffusion, pressure iterations and vorticity enhancement to see how the jet entrains surrounding fluid and leaves a wake behind a cylinder. Drag through the test section with the fluid brush to inject dye and momentum.

Interactive modelInteractive Jet
Last solver-step cost0 ms0\,\mathrm{ms}
Simulation time0.0000 s0.0000\,\mathrm{s}
Current field DliveD_{\mathrm{live}}0.0000 s−10.0000\,\mathrm{s^{-1}}
Last solve: before DbeforeD_{\mathrm{before}}n/a\text{n/a}
Last solve: after DafterD_{\mathrm{after}}n/a\text{n/a}
Divergence reductionn/a\text{n/a}
Last solve iterationsn/a\text{n/a}
Projection snapshotNo projection yet
Mean kinetic energy K/ρK/\rho0.00 J kg−10.00\,\mathrm{J\,kg^{-1}}
Peak vorticity ∣ω∣max⁡\lvert\omega\rvert_{\max}0.00 s−10.00\,\mathrm{s^{-1}}

Physics tutorial

Interactive Jet: what advection, diffusion, and projection each do

BackgroundThe simulation stores velocity and dye on a fixed grid. Each time step alternates velocity diffusion, advection and pressure projection, then carries the dye along. The horizontal and vertical cell spacings are used separately, and slow playback does not change the time units of the readouts.

Why it mattersTaking the solver apart step by step makes the swirls more than a visual effect. You can measure the divergence before and after pressure projection and see the trade-off between stability and numerical dissipation.

Start with the essentials

Focus question
After you push the velocity field around at will, why does one pressure projection bring it back close to incompressible?
One-sentence intuition
Projection subtracts the gradient of a potential from the intermediate velocity. Paint while paused and project only, and you compare the same field before and after. Finite iterations on a collocated grid leave a residual you can measure, so the field does not satisfy ∇h⋅u=0\nabla_h\cdot\boldsymbol{u}=0 exactly.

Core mathematical model

Incompressible velocity evolution

∂u∂t+(u⋅∇)u=−∇p+ν∇2u+f,∇⋅u=0\frac{\partial\boldsymbol{u}}{\partial t}+\left(\boldsymbol{u}\cdot\nabla\right)\boldsymbol{u}=-\nabla p+\nu\nabla^2\boldsymbol{u}+\boldsymbol{f},\qquad \nabla\cdot\boldsymbol{u}=0

Advection carries momentum along, viscosity diffuses velocity gradients, the nozzle and brush supply force, and pressure keeps the flow incompressible.

Semi-Lagrangian backtrace

ϕn+1(x)≈ϕn ⁣(x−Δt un(x))\phi^{n+1}(\boldsymbol{x})\approx\phi^n\!\left(\boldsymbol{x}-\Delta t\,\boldsymbol{u}^n(\boldsymbol{x})\right)

From each grid point, trace backward along the velocity and interpolate the old field at the landing point. The step is robust, but repeated interpolation smooths out detail.

Pressure projection

∇h2φ=∇h⋅u∗,u′=u∗−∇hφ\nabla_h^2\varphi=\nabla_h\cdot\boldsymbol{u}^{*},\qquad \boldsymbol{u}'=\boldsymbol{u}^{*}-\nabla_h\varphi

The stored quantity is a velocity potential with the time step and density folded in, so it is not a pressure in pascals. The grid cells are rectangular, so the Poisson relaxation weights the horizontal and vertical directions differently. With a finite number of iterations, the projection does not guarantee zero divergence.

Root-mean-square divergence of the current field

Dlive=1Nf∑i∈fluid(∇h⋅u)i2,R=DbeforeDafterD_{\mathrm{live}}=\sqrt{\frac{1}{N_f}\sum_{i\in\mathrm{fluid}}\left(\nabla_h\cdot\boldsymbol{u}\right)_i^2},\qquad R=\frac{D_{\mathrm{before}}}{D_{\mathrm{after}}}

The live value is recomputed from the current velocity. The before and after values from the last projection are a saved pair, marked stale once you paint or change a parameter. When the field is zero, the reduction ratio is undefined.

Common difficulties

Stable does not mean accurate

Typical misconceptionIf the algorithm never blows up, every small vortex must be right.

Better mental modelSemi-Lagrangian advection stays stable at large time steps, but its interpolation adds numerical dissipation. Vorticity enhancement puts back visual detail; it cannot recover the true scales that were lost.

Particles in depth do not make the solver three-dimensional

Typical misconceptionBecause the particles fill a depth, the solver must resolve three-dimensional turbulence.

Better mental modelEvery particle samples the same two-dimensional velocity slice. The depth makes the structure easier to see, but it cannot produce three-dimensional vortex stretching.

Run the experiment

  1. 01

    Build a cylinder wake

    Choose Cylinder wake and let the dye pass the obstacle.

    What to observe: The jet slows and splits in front of the cylinder. Behind it is a slow wake with vortices that alternate in rotation.
  2. 02

    Inspect pressure projection

    Pause, arm the brush and paint a disturbance. Enable Divergence diagnostic and click Project only. Change the iteration count, then project again.

    What to observe: The before value equals the live divergence just before the click, and the after value equals the new live divergence. Time and dye do not advance. More iterations usually shrink the residual, but that still does not prove exact incompressibility.
  3. 03

    Add momentum by hand

    Arm the fluid brush and drag sideways through the wake. Turn it off when you want to orbit the chamber.

    What to observe: Dye and velocity change together where you drag. The new disturbance is then advected, diffused and projected again.

Conceptual inspiration: FluidMotion. Original simulations and graphics; the model limits are described above.

FeedbackSomething broken, confusing, or missing on this page?Tell us
What kind of feedback?

Sent with this page’s address, its Lab ID, the site language and your device type. Please leave out personal details. Feedback is kept for up to 12 months.Privacy policy