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
WebGL2 float textures are required for this simulator.
Controls
The math
An incompressible fluid with velocity , pressure and kinematic viscosity obeys the Navier-Stokes equations
The Vorticity display shows , the local spin of the fluid: one color turns counterclockwise, the other clockwise. In two dimensions vorticity is simply carried along and slowly diffused,
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.
Kolmogorov flow is driven by a body force that pushes alternate bands in opposite directions, . At high viscosity the fluid just copies the force. Lower the viscosity and the straight bands buckle, roll up and settle into a restless, self-sustained two-dimensional turbulence.
The Taylor-Green vortex array is one of the few exact solutions of the Navier-Stokes equations:
The pattern keeps its shape and simply fades at a rate set by the viscosity, which makes it a standard test for fluid codes. Stir it and the checkerboard symmetry breaks for good.
The Kelvin-Helmholtz instability: two streams slide past each other in opposite directions, and the thin layer of shear between them is unstable. Small ripples grow, the sheet of vorticity rolls up into a row of billows (the same shapes seen in clouds and on Jupiter), and neighboring billows then pair up and merge.
Wind tunnel. A steady wind enters from the left carrying streaks of smoke. What happens behind an obstacle of width in a wind of speed depends only on the Reynolds number
Below about 50 the wake is steady. Above it the wake starts to flap and sheds vortices alternately from each side: the von Karman vortex street, the reason flags flutter and wires sing in the wind. Slide the viscosity up and down to cross the threshold, or draw your own obstacle. A wing tilted this steeply is stalled: the flow tears away from its upper surface. A strip at the left and right edge quietly absorbs the wake and re-emits clean wind, so the periodic domain behaves like an open tunnel.
Vortices. Decaying Turbulence starts from a random scatter of small vortices and no forcing. Opposite-signed neighbors pair up into dipoles that travel in straight lines; like-signed ones orbit each other and merge. Energy flows to larger and larger scales (the inverse cascade) until only a few big vortices are left. Dipole Collision fires two such pairs at each other head-on: they swap partners and leave at right angles.
Torus Jet. Every simulation here has periodic boundaries, so the domain is secretly a torus. This experiment drives a jet the long way around the donut, strongest on the outer rim. The forcing, the ink transport and the brush are all scaled by the torus metric, so the outer rim is longer than the inner one, as it should be.
How it is computed. Nothing above is solved directly. The toy uses the Lattice Boltzmann method: every grid cell holds nine populations of fictitious particles, one for each lattice velocity (rest, four axis and four diagonal directions). Each step the populations hop to their neighbors and then relax toward a local equilibrium,
Density and velocity are just moments, and , and in the limit of slow flow they satisfy the Navier-Stokes equations with viscosity
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).