pattern formation · PDE · C · spectral solver · Nov 2026
Heat a thin layer of fluid from below and, past a threshold, it stops being flat: it breaks into rolls, into hexagons, into something. There is no blueprint for the pattern — it is the same equations everywhere, and the layout is selected by the dynamics. The Swift–Hohenberg equation is the canonical toy model for that: one scalar field, one PDE, and it spontaneously grows stripes, spots and grain boundaries.
The trick is the operator (1 + ∇²)². Written in
Fourier space it is (1 − k²)², so a mode of wavenumber
k grows only near k = 1 and every other scale is damped.
Turn up ε and a narrow ring of wavelengths is amplified from
tiny random fluctuations; the cubic −u³ then saturates them
to a finite amplitude. Which waves win, and at what angles, is the whole pattern.

ε = 0.10, started from pure white noise, after 1200 steps. Gold
is u > 0, blue is u < 0. Adjacent bands of rolls meet at
grain boundaries; the little knots are dislocations — the
signature texture of the equation.
This is the same run from the first instant: structureless grey noise, then pinpoints of contrast, then a field of rolls that coarsens and settles. Scrub it.
26 frames, one every 20 steps, from step 0 (pure noise) to step 500.
ε to 0.30 and drop a single bright
seed at the centre: it nucleates perfect concentric rings that march
outward — a target. A point defect, grown from nothing.
û and step it with an
exponential time–differing 4th-order Runge–Kutta scheme: the stiff
linear term is handled exactly, the cubic is the nonlinearity. Because the field
is real, the linear propagators phi_1, phi_2, phi_3 collapse to real
combinations — no complex contour integration.1/N² so a forward–inverse
round-trip is identity. It demands a power-of-two grid, which cost me a few
segfaults before I stopped asking it for 640.amax. Pure rolls saturate near √(2ε) ≈ 0.45
for ε=0.1 (I measure 0.61 with a rich grain-boundary mix);
the seeded hexagons reach √(2ε) for 0.30. The solver
lands where the amplitude equation says it should.back to the lab ·
source: ~/src/sh.c