Task 2 of 5

Cross the Line

Nothing about the kernel you just wrote is wrong. Hand it a step size that is slightly too big and it will still compute exactly what you asked for — and the field will be at 10²⁴ in eighty steps.

Look again at that centre weight, 1 − 4α. At α = 0.1 it is +0.6, the new value really is an average of five old ones, and an average can never leave the range of the things it averaged. At α = 0.4 it is −0.6, and "average" has become a lie: a cell that sits above its neighbours is now pushed further above them every step. In dims dimensions the centre weight is 1 − 2·dims·α, so the tipping point is α = 1/(2·dims) — which, written in the quantities you actually control, is the limit every explicit solver lives under:

dt  ≤  dx² / (2 · D · dims)
       dims = 2 on a 2D grid

Past it, the fastest pattern the grid can hold — a checkerboard of alternating hot and cold cells — is multiplied by |1 − 8α| every step instead of damped. At α = 0.4 that is 2.2× per step, and there is always some checkerboard in there, if only from rounding. Ten steps: ×2,700. Eighty steps: the run below.

the fastest pattern the grid can hold, flipping and growing, every step
Goal: work out dtMax, then run the same eighty-step simulation twice — once safely inside the limit, once past it — and watch the console. The stepping loop is written for you: N-Body already made a meal of how to advance a simulation, and the only thing that matters here is how far each step goes.

Requirements

Hint 1 — where the numbers come from

Each of the 2 · dims neighbours takes an α-sized bite out of the centre, so the centre keeps 1 − 2·dims·α. Set that to zero, substitute α = D·dt/dx², and solve for dt.

Hint 2 — the two runs
const dtMax = dx * dx / (2 * D * DIMS);
await run('SAFE', 0.4 * dtMax);
await run('PAST THE LINE', 1.6 * dtMax);

Same idea elsewhere

Every production explicit solver computes this number and refuses to exceed it: CFL conditions in fluid codes, the diffusion-number check in a thermal simulation, the substepping loop in a cloth or fluid solver on the GPU. It is also why GPU simulations so often become launch-bound — halving dx to sharpen a picture quarters the legal dt, so the same second of simulated time costs four times as many kernel launches.

All tasks in The Heat Equation & Stability

  1. One Explicit Step
  2. Cross the Line
  3. Sixteen Step Sizes at Once
  4. Solve, Don’t Step
  5. Stable Is Not Accurate

This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.