Welcome, space traveler!

Mathematician + Developer + Cat DadMath, code, cats, books and faith. Since 2024.

Hydrodynamics

A real-time fluid you can reach into. Drag to stir the ink, draw walls and watch vortices peel off them, drop your name into a wind tunnel, or wrap the whole flow around a donut. Press Space to pause.

Simulation

Controls

Brush
Look
Simulation
Drop something in

Whatever you drop becomes a solid wall the fluid has to flow around. Try it in a Wind tunnel experiment: your name sheds its own vortex street.

The math

An incompressible fluid with velocity u, pressure p and kinematic viscosity ν obeys the Navier-Stokes equations

∂u∂t+(u⋅∇)u=−∇p+νΔu+F,∇⋅u=0.
The Vorticity display shows ω=∂xuy−∂yux, the local spin of the fluid: one color turns counterclockwise, the other clockwise. In two dimensions vorticity is simply carried along and slowly diffused,
∂ω∂t+u⋅∇ω=νΔω,
which is why like-signed vortices merge into ever larger ones instead of breaking down, the opposite of what happens in three dimensions.

Stir it yourself. In Stirred Ink three slow invisible paddles wander around and keep the fluid moving; Still Water is a calm tank that only does what you make it do. Drag fast for jets and mushroom-shaped vortex pairs, switch the brush to Draw wall to build channels and baffles, and turn Ink refresh to zero if you want a purely passive dye that only ever gets mixed.

How it is computed. Nothing above is solved directly. The toy uses the Lattice Boltzmann method: every grid cell holds nine populations fi of fictitious particles, one for each lattice velocity ci (rest, four axis and four diagonal directions). Each step the populations hop to their neighbors and then relax toward a local equilibrium,

fi(x+ci,t+1)=fi(x,t)−ω(fi−fieq),fieq=wiρ(1+3ci⋅u+92(ci⋅u)2−32|u|2).
Density and velocity are just moments, ρ=∑ifi and ρu=∑icifi, and in the limit of slow flow they satisfy the Navier-Stokes equations with viscosity
ν=13(1ω−12).
Walls are the simplest thing imaginable: a population that would hop into a wall bounces straight back. A Smagorinsky term raises the relaxation time where the flow is strained hardest, which keeps the low-viscosity experiments stable. The whole update is one fragment shader, run several times per frame on float textures.

What you are looking at. The ink is a hue carried by the flow, stored as a point on the color wheel so that mixing never fades it to gray. The white streaks are tracer particles riding the velocity field. Relief lights the pressure field as if it were a water surface, so the low-pressure core of every vortex becomes a dimple, just like the whirlpool over a drain. The fluid is very slightly compressible, so a hard stir also sends out faint sound waves; watch for them in the Pressure display.

References: Kruger et al., "The Lattice Boltzmann Method" (2017); Succi, "The Lattice Boltzmann Equation" (2001); Van Dyke, "An Album of Fluid Motion" (1982).

Prime clock

2

a new prime every two seconds