♨️ Rayleigh-Bénard Convection — Thermal Cells
Heat a fluid layer from below: above a critical Rayleigh number, ordered convection rolls spontaneously form, transporting heat far more efficiently than conduction.
About this simulation
This simulation runs a 2D Boussinesq model of Rayleigh-Bénard convection on a 96×48 lattice grid. Each step advects and diffuses a temperature field, adds a buoyancy force proportional to the Rayleigh number (Ra) and the local temperature gradient, then solves the Poisson equation ∇²ψ = -ω (where ψ is the stream function and ω is vorticity) with 20 Gauss-Seidel iterations to recover a divergence-free velocity field from u = ∂ψ/∂y, v = -∂ψ/∂x. The bottom row is fixed hot (T=1), the top row fixed cold (T=0), and the side walls use Thom's no-slip vorticity formula. Raise Ra above the critical value 1708 and stationary conduction gives way to rotating convection rolls.
🔬 What it shows
A cross-section of fluid trapped between a heated floor and a cooled ceiling, coloured from blue (cold) to orange-red (hot). Below the critical Rayleigh number the field stays smoothly stratified — pure conduction; above it, the buoyancy term destabilises the layer and the colour map reorganises into alternating rising and sinking convection rolls, with white arrows showing the local velocity field.
🎮 How to use it
Drag the Rayleigh number slider (500-50,000) to push the system past Rac ≈ 1708 and trigger convection; the Prandtl number slider (0.1-10) changes how viscous vs. thermal the fluid behaves, reshaping roll texture. Sim speed scales the number of physics substeps per frame, and the velocity-arrows toggle hides or shows the flow overlay. Click or drag directly on the canvas to stir the fluid by hand, injecting vorticity and heat at that point. Pause/Play and Reset control playback, and the stat box reports the live state, Ra/Rac ratio and Nusselt number.
💡 Did you know?
The Nusselt number shown in the HUD (Nu = 1 + a normalised convective heat flux) is exactly the quantity physicists measure in real Rayleigh-Bénard experiments with tanks of water or gas to compare against theory: Nu stays at 1 for pure conduction and climbs as convection strengthens, following well-studied scaling laws with Ra.
Frequently asked questions
Why is the simulation grid only 96×48 cells?
The stream-function/vorticity method requires solving a Poisson equation with Gauss-Seidel relaxation every single frame (20 iterations here), and that cost grows quickly with grid size. A 96×48 lattice is coarse enough to update in real time in the browser while still being fine enough to resolve the roll pattern, whose natural wavelength is roughly twice the layer depth.
What happens when I click or drag on the canvas?
The stirAt() function converts your pointer position into the nearest interior grid cell and adds +0.6 to its vorticity and +0.3 to its temperature (capped at 1). This lets you manually kick-start convection cells below Rac, or disrupt an existing roll pattern to watch it reorganise.
How are the top, bottom and side walls handled?
The bottom row is pinned to T = 1 (hot) and the top row to T = 0 (cold) every step, which is what drives the whole system. The side walls are insulated (zero temperature gradient) so no heat escapes sideways. All four walls are rigid and no-slip, enforced on vorticity with Thom's formula ωwall = -2·ψadjacent, which reproduces zero velocity at the boundary without needing a ghost layer.
How does the simulation keep the flow incompressible without solving Navier-Stokes directly?
Instead of tracking pressure, the code uses the vorticity-stream function formulation: vorticity ω is transported and diffused directly, then ∇²ψ = -ω is solved (via 20 Gauss-Seidel iterations per frame) to recover a stream function ψ whose derivatives, u = ∂ψ/∂y and v = -∂ψ/∂x, are automatically divergence-free by construction — incompressibility is guaranteed by the math, not enforced with an extra pressure-correction step.
Why does the "State" badge flip between Conductive and Convecting?
It checks two things: whether Ra/Rac is above 1 and whether the average kinetic energy of the velocity field has grown past a small threshold (1e-4). Near the threshold the ratio alone can be misleading — the perturbation added at seed time takes a moment to grow into visible rolls — so the badge only switches to "Convecting" once real motion is detected.
Heat a fluid layer from below: above a critical Rayleigh number, ordered convection rolls spontaneously form, transporting heat far more efficiently than conduction.
3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install