15.5 Reaction–Diffusion & Turing Patterns ended with a promise and a warning. The promise was that two chemicals that merely react and diffuse can draw spots, stripes and labyrinths. The warning was that the standard demonstration, the Gray-Scott model, is a poor model to analyse: its empty state is stable for every feed and kill rate, so nothing grows from noise, and a pattern has to be started by a finite seed. This capstone takes the warning seriously and builds a small laboratory around it. We write the periodic Laplacian and one Gray-Scott step ourselves, measure the stability limit that decides how large a step we may take, replace the explicit step by one whose diffusion half is solved exactly with the FFT, draw a map of the plane by running a few hundred small simulations, take the Fourier spectrum of the patterns and ask what a linear theory can say about their wavelength (very little, and we will see exactly where it can say something), and finally paint seeds onto the grid and see what survives. The structure is the one every grid PDE simulator shares, which is the reason it is a capstone: a stencil, a time stepper with a stability limit, an analysis step, and honest bookkeeping about what each number means.
Transcript
- The reaction-diffusion lesson ended with a warning: the empty state of Gray-Scott is stable, so patterns need a seed. This capstone builds a laboratory around that fact. First the solver. On a periodic grid the Laplacian is a five-point stencil, four rolls of the array, and a Gray-Scott step is explicit Euler, matching the lesson exactly after 500 steps. The key fact: Fourier waves are exact eigenvectors of this Laplacian, with eigenvalue minus lambda, and the checkerboard has the largest, 8.
- Step two: how big a step may we take? Explicit Euler multiplies the checkerboard by 1 minus h times 8 D u plus F, so it is stable only below 2 over that rate. At F equals 0.03, bisecting on the running scheme gives 1.52672, the same as the formula. A full run on a 64 by 64 grid stays bounded at h equals 1.52 and blows up at 1.53. Halve the grid spacing and the limit falls to 0.38835. Quarter it: 0.09751.
- The cure is to make diffusion implicit. Fourier modes diagonalise the Laplacian, so the solve is a division by 1 plus h D u lambda at each wave number: exact, and never above 1. At h equals 8 the explicit factor on the checkerboard is minus 9.24; the implicit one is 0.0890. The step stays bounded to h equals 16 and fails at 20. But it is first order: error 0.01917 at h equals 1 against 0.00791, and the blob count drifts from 22 to 17. At 495 microseconds a step against 20.9, it costs about 24 times as much.
- Step three: the map. For 247 points of F and k, the lab runs a 48 by 48 box from three small seeds to time 3000, then classifies the final v by a rule that fits on a card: empty if v stays under 0.05, uniform if it is flat, holes, spots, and otherwise stripes or labyrinth. The count: 104 empty, 101 uniform, 22 labyrinth, 12 spots, 5 holes, 3 still splitting. The white curve is where a second uniform state is born.
- Three cells. At F 0.03, k 0.062: 15 blobs covering 23.4 percent. At 0.04 and 0.06: one connected structure, 51.3 percent, with 3 holes. At 0.07 and 0.0625 the seeds die. How far to believe it? Rerun at time 1500 and 11 cells change label; at 6000, 10. The splitting label is weakest: the mitosis point is called plain spots. And the labyrinth label really means not spots.
- Where can linear theory speak? About the empty state the Jacobian is diagonal and negative, and diffusion only adds to that: no wave number grows, so seeded patterns have no linear wavelength. A second uniform state exists only when F is at least 4 times F plus k squared. That holds at 10458 of 19291 lattice points, and it is Turing unstable at just 67, a thin sliver on the white curve. At the spots preset, 4 times 0.092 squared is 0.0339, above F: no theory.
- Take the sliver: F 0.074, k 0.062. Linear theory predicts the fastest growth, 0.01499, at q equal 0.490: 12.82 cells. Start from the uniform state plus noise on 128 cells and read the radial spectrum, the ring-averaged power of the FFT. The peak sits at m equal 10, 12.80 cells, from time 200 through the nonlinear stage; at time 700, v spans 0.0006 to 0.4736. The prediction has a shelf life: by time 13000 the labyrinth has coarsened, and the peak is at m equal 8.
- Step five: what survives. The empty state is stable, so a seed must be big enough. At F 0.03, k 0.062, a seed of side 3 dies; side 5 grows into 24 spots. In amplitude, v of 0.19 invades and 0.18 dies: a nucleation threshold. Now erase the left half of a spot pattern: 12 blobs remain. The spots refill from the survivors: 20 blobs, covering 23.7 percent against 21.9. Same statistics, different pattern.
- The lab puts it together. The field of v, the clickable regime map, and the spectrum with its peak sit side by side, with a readout of the measured numbers. Sliders move F, k, and the step h; a menu switches between explicit and IMEX; the pointer paints seeds or erases. Try three things: push h past 1.53 on explicit Euler and watch it stop; load a map cell near the spots edge and paint extra seeds; load F 0.074, k 0.062 from noise and see the prediction land on the spectrum.
- Honest limits. The map is a rule, a box, and a time: 10 or 11 of 247 cells change. A wavelength is predicted only in a sliver, 67 of 19291 points, and even there it coarsens. The five-point Laplacian prefers the axes. IMEX is first order and no speed-up here. The deeper limit is boundaries: the FFT trick needs a periodic square. Next is the drum synthesizer, L-16.4: the same Laplacian eigenproblem on a shape you draw, where a sparse eigensolver replaces the FFT and eigenvalues become pitches.
What we are building
The model is the one of 15.5 Reaction–Diffusion & Turing Patterns:
with , , a square periodic grid of spacing , and the empty state everywhere else. The reaction turns the feed into , the feed is replenished at rate , and is removed at rate . All times and lengths are in these units, so the unit of time is whatever makes , and nothing here is calibrated to a real chemistry.
Every result below states the grid size (the field is ), the time step , the seed and the time at which it was measured. Each was produced twice: once by the lab’s own functions run under node, and once by an independent numpy and scipy program written separately (different code for the stencil, the blob counter, the spectrum and the random numbers). Where the two disagreed by more than rounding, I would have said so; they did not. A few claims come from memory and are marked, and the timing numbers are the one kind I could not recompute independently, since they belong to one machine.
Five steps build the lab, then the lab itself:
- the periodic Laplacian and a Gray-Scott step in numpy;
- the explicit stability limit, and an implicit (IMEX) step by FFT;
- the regime map, with a rule you can read;
- the FFT spectrum of a pattern, and the one honest comparison with linear theory;
- painting and nucleation: what survives.
Step 1: the periodic Laplacian and one Gray-Scott step
On a periodic grid of spacing the Laplacian of 10.1 Finite Differences: Discretizing Derivatives is the five-point stencil with indices taken modulo :
In numpy this is four np.roll calls, and the wraparound is free. A Gray-Scott step is then one line per species: and , which is explicit Euler, the first method of the Euler family in 4.2 The Euler Family: Forward, Backward, Heun & Midpoint. The lab’s step is the same arithmetic as the step in 15.5 Reaction–Diffusion & Turing Patterns: running both for steps from the same seed on cells gives fields that differ by exactly (compared in node, not in numpy).
The Laplacian has a property that the rest of the capstone leans on. The plane waves with , , are exactly periodic on the grid, and the stencil acts on one of them by a number:
So the Fourier modes are the eigenvectors of , with eigenvalues that are never positive. The smallest nonzero belongs to the longest wave, and for the checkerboard it is , the largest of all. That is the same fact as the diagonalisation of 1.6 Change of Basis & Diagonalization, with a matrix of size and a basis the FFT computes in operations; 10.12 Spectral Methods & the FFT used it for derivatives. In this capstone it makes the implicit step trivial.
The playground prints the eigenvalue check, the measured limit and a full nonlinear test. For the empty state the Jacobian of the reaction is , and the checkerboard of decays or grows per step by , so explicit Euler is stable only for . Running the scheme, bisecting on whether the per-step factor exceeds ( grid, steps, seed-free), gives at in both programs, against the formula’s ; the formula and the measurement agree to . The full nonlinear run on cells from a square seed (, plus the small tilt of 15.5 Reaction–Diffusion & Turing Patterns) stays bounded to at and is unbounded at . The limit predicted from the linear theory about the empty state is the real limit of the nonlinear pattern too.
Step 2: the explicit limit and an implicit option
The explicit limit has nothing to do with the chemistry. It is the diffusion number of 10.2 Explicit Methods for the Heat Equation, in two dimensions, nudged by the reaction. It also scales with the grid: halve the spacing and the diffusion terms grow fourfold, so the limit falls to a quarter. Treating and as multiplied by and by , which is what spacings and do (for the same physical diffusivities), the measured limits are and at (the same two numbers from the lab and from numpy, and the formula agrees). A fine grid in a hurry wants an implicit diffusion step, and 10.4 Implicit Methods & Crank–Nicolson showed that implicit steps are stable for any in the diffusion part.
The usual obstacle is the linear solve , a banded system that needs a tridiagonal or conjugate-gradient solver in two dimensions. On a periodic grid there is no obstacle. The FFT diagonalises , so in Fourier space the system is , a division at each wave vector. The scheme, called IMEX (implicit for the stiff linear part, explicit for the nonlinear reaction), is
with and . It is first order in , like explicit Euler, and it cannot be unstable because of diffusion, whatever the wave vector: the factor is always between and . You build it now. The tests check three things the scheme must satisfy: the empty state is a fixed point, the diffusion solve is exact (the residual of the implicit equation is round-off), and it stays bounded at , five times the explicit limit.
How well does it work? Here is the lab’s measurement on cells at , , from the square seed above, with the error in taken at against explicit Euler at (the reference, taken as truth):
| scheme and step | max error in | rms error in |
|---|---|---|
| explicit, | ||
| explicit, | ||
| IMEX, | ||
| IMEX, | ||
| IMEX, | ||
| IMEX, | ||
| IMEX, | ||
| IMEX, |
The error doubles with , which is first order, and at equal the IMEX step is about two and a half times less accurate than the explicit one, because treating the reaction explicitly while implicitly damping the diffusion is a splitting error. The stability range is wide: the IMEX run stays bounded to at and is unbounded at ; a bisection on that test puts the edge at about (the bisection assumes the test is monotone in , which I did not check beyond the two points). That is times the explicit limit. It is not free. The pattern’s statistics drift as grows: at the number of blobs of above is for explicit and for IMEX , at and at . Stable does not mean right.
Step 3: the (F, k) map of regimes
The map is the lab’s central instrument. For every point of a lattice of feeds and kills , which is cells, the lab runs a small simulation: a periodic grid, explicit Euler at , three square seeds (, ) at positions drawn by a seeded generator (mulberry32, seed ), for . Then it classifies the final field of with a rule that fits on a card:
- empty: , the seeds died;
- uniform: is not empty but its standard deviation is below , so it filled the box evenly;
- holes: the area where exceeds and the complement () has at least connected pieces;
- spots: at least separate blobs of , covering under , each averaging under of the box (and labelled “splitting” instead if the blob count rose by more than in the last steps);
- stripes / labyrinth: everything else, that is, few connected blobs, or a connected network.
A blob is a connected set of cells under the four-neighbour rule on the periodic grid, so a blob may wrap across an edge. Counting blobs is a flood fill, and it is the exercise of this step.
The whole map, lattice by lattice, comes out as: empty, uniform, stripes or labyrinth, spots, holes and spots still splitting, totalling . Both programs gave the same label in every one of the cells. The structure matches the standard picture of Gray-Scott (from memory: the classification is due to Pearson, 1993, and the model to Gray and Scott, 1984): spots hug the upper-left edge of the pattern-forming region, labyrinths sit on its fat side, a large lower-right region fills with uniform , and above the top edge everything is empty. In the sim the dashed curve is . It is the saddle-node line where a second, non-empty uniform state is born; step 4 explains why that matters.
The three lines the playground prints are the same numbers the sim computes for those cells: at , the lattice cell holds blobs covering ; at , it holds connected structure covering with holes; at , the seeds die.
How much to believe the map
A rule on a card is a measurement and not a theorem. Four checks of its stability, all on the same lattice and seeds:
- Run time. Repeating the map at changes the label of of the cells; at , cells. They sit on the borders between regimes and on the “splitting” cells, which are transients by definition: the blob count is still rising. The regime of a border cell is a statement about a time as much as a point.
- Box size. The box holds only a few wavelengths. At and the cell has spots and stays a labyrinth ( pieces, ); the labels agree, the counts scale with area.
- The splitting label is the weakest. The mitosis point of the standard picture, , , is labelled plain spots by this rule on the lattice ( blobs, , count unchanged over the last steps). A static rule cannot reliably see a process.
- Worms. The cell has small blobs covering and is labelled labyrinth, because a few elongated blobs fail the “spots” test. “Stripes / labyrinth” really means “not spots”.
Step 4: the FFT spectrum and the Turing linear prediction
A pattern has a typical length. To measure it we take the FFT of minus its mean, square the magnitudes, and average the power over rings of wave vectors with the same (rounded to an integer, the ring index). The ring average is the radial power spectrum . Its peak is the dominant number of wavelengths across the box, and the dominant wavelength is cells. Averaging over a ring (a mean, not a sum) matters: the ring at has about wave vectors in it, so a sum would favour large for no physical reason. You write it now.
Where linear theory speaks, and where it does not
15.5 Reaction–Diffusion & Turing Patterns found the Turing wavelength of the Brusselator from the dispersion relation: linearise about a uniform state, replace by , and ask for the wave numbers whose growth rate is positive. Do the same for Gray-Scott and the first thing to check is which uniform states exist. The empty state always exists and its Jacobian is stable for every and , and diffusion adds to a stable diagonal: no wave number grows. The spots, stripes and labyrinths of steps 3 and 5 are not Turing patterns of the empty state. They are nonlinear: a finite seed invades, and its pattern wavelength is set by the shape of the front and the fronts’ interaction, for which nothing in this lesson gives a formula.
A second, non-empty uniform state exists when and have a solution, which gives , real exactly when
and then with . Near the three presets of 15.5 Reaction–Diffusion & Turing Patterns this inequality fails, so no linear theory exists at the spots, the labyrinth or the splitting point: against , and against ; at , the two sides are both (the saddle-node itself). The non-empty states exist only on the other side of the dashed curve in the sim, the lower-right part of the map.
There, a Turing instability is possible. For each state the lab computes the Jacobian and the eigenvalue of largest real part of as a function of . The state must be stable to uniform changes (, ) while some still grows. On a lattice of points ( to in steps of , to in steps of ) a non-empty state exists at points, and a Turing-unstable one at only : a thin sliver along the saddle-node curve (dotted in the sim). Both programs return the same three numbers.
Take , , the largest growth rate on the lattice. There and , so is only above the threshold and the two uniform states are close: and . The first has and , stable to uniform change. The second has , a saddle, and is not relevant. For the first, the growth rate , with , is positive for from to , the wavelengths from to , with the maximum at , a continuum wavelength of cells. On a -cell box the available waves have cycles across, and the axis modes (wavelengths , , ) grow at , and per unit time, within of each other. The peak is flat, so the spectrum can place it only to within a bin or two.
Now run the experiment: start on the uniform state plus noise of amplitude (seed of mulberry32, explicit Euler at , cells) and read the spectrum.
| peak (wavelength) | centroid wavelength | range of | |
|---|---|---|---|
| () | to | ||
| () | to | ||
| () | to | ||
| () | to | ||
| () | (labyrinth, piece, holes) | ||
| () | (labyrinth, piece, holes) | ||
| () | (labyrinth, piece, holes) |
The measured peak sits on the predicted from (at the noise itself had not yet been filtered and the peak was elsewhere, so I do not quote it), through the nonlinear saturation and out to . At the labyrinth has slowly coarsened and the peak has moved to , cells: the linear theory describes the pattern that forms, not the one the system ends up in. The agreement is real but it is a prediction about an unusually favourable corner, and it has a shelf life. Note what the last rows say: by the range of is to . This is not a small ripple on the uniform state; is nearly zero between the spots, which means the system has been thrown into the basin of the empty state, as it should be ( is tiny where is). The wavelength survives the first nonlinear stage here. There is no reason to expect that at other parameters.
The spectrum of a pattern that does come from a seed (the cases of step 3) is not predicted by anything above, so we only measure it. On a box from the central seed with the small tilt, explicit and : the spots preset (, ) has peak , wavelength , centroid , with blobs covering ; the labyrinth preset (, ) has peak , wavelength , centroid , one connected structure covering . Both are filled boxes. The splitting point (, ) and the slow-growth point (, ) have not yet filled the box at ( blobs covering , and one blob covering ); their spectra peak at , which is the envelope of one growing cluster. A spectrum only measures a wavelength when the pattern fills the periodic box, and the lab shows the peak whatever the state of the field, so check the field.
Step 5: painting, seeding and what survives
The empty state is stable, so a pattern needs a finite disturbance. How big? A square seed with , centred in a box, run to at with explicit Euler. At , :
- seeds of side and cells (half-width and ) vanish;
- seeds of side and (half-width and ) grow into spots covering and of the box.
At , the threshold falls in the same place: side dies, side gives a labyrinth ( connected pieces, of the box). Once the seed is large enough, its exact size no longer matters for the count: every seed from side to gave the same spots at this box and time. The amplitude has a threshold too. With a seed, and , the spots invade for and die for at ; at the threshold lies between and . Those are nucleation thresholds, as in a first-order phase transition: below the critical nucleus the empty state wins, above it a front grows. They are the picture behind the “Fisher front” language of 15.5 Reaction–Diffusion & Turing Patterns, with the new knowledge that this particular front is not an exact travelling wave but a ring of splitting spots.
Noise is a different, uglier case. Fill the whole box with random uniformly distributed in (and with a second uniform draw in , mulberry32 seed ) and run to : at , the field returns to empty for , and . At , it does the same for and but for it grows a labyrinth. The outcome does not depend monotonically on the amplitude: bigger noise is not “more seed”. Whether a random field contains a supercritical nucleus is a matter of chance.
Painting is the interactive version of both experiments. Draw a stroke in the sim and a ridge of either nucleates or does not, depending on its width and on where you are on the map. The second experiment is the refill. Run the spots to ( blobs, ), then erase the left half of the box back to the empty state: blobs and remain. Continuing, the count is at more steps ( of the area, growing), at () and at (). The spots invade the erased region from the surviving half, the area fraction returns to within two percentage points of the original ( against ), and the number of spots does not: , not . The same statistics come back, but the pattern is a different pattern.
The lab
The sim below puts the whole chain in one place. The left panel is the field of (or ); the right column holds the regime map (computed in the background, one cell at a time, and clickable) and the radial spectrum with its peak marked. Sliders move and live, the stepper menu switches between explicit Euler and the FFT-based IMEX step, the step slider changes , and the pointer paints seeds or erases to empty. The readout reports the measured regime and its numbers, the spectrum peak, and the linear theory where one exists. Three things to try: push above with explicit Euler and watch the field blow up (the lab detects it and stops rather than draw nonsense), then switch to IMEX at the same ; load a map cell near the edge of the spots region and paint extra seeds; and load , and start from noise about the uniform state to see the linear prediction land on the spectrum.
Honest limits
- The map is a rule, a box and a time. It uses cells, three seeds, one seed set and . A different rule would draw different borders, and or of cells change label when the run time changes. A published map of this model comes from long runs on large grids, with extra regimes (spirals, solitons, chaos) that the lab does not separate (from memory).
- The wavelength is not predicted by anything except in a sliver. Linear theory applies where a non-empty uniform state exists and is Turing unstable ( of lattice points), and there it matched a -cell box to the bin from to , after which the pattern coarsened to . It says nothing about the spots, the labyrinths or the splitting, which are nonlinear.
- The five-point Laplacian is anisotropic. Its eigenvalue depends on direction at short wavelengths, so patterns on the square grid have a slight preference for the axes. The radial spectrum hides this by averaging over a ring.
- The IMEX step is first order and not a speed-up at this grid. It is stable far beyond the explicit limit, and its accuracy falls as grows. It earns its keep on fine grids or large diffusivities. The lab is plain JavaScript on the CPU: nothing in it is a GPU shader, and I measured no GPU speed.
- Nothing is fitted to a real pattern. Whether any animal’s coat or any chemical dish is described by these equations is a question for experiments, as 15.5 Reaction–Diffusion & Turing Patterns said.
Concept checks
Problems
For pure diffusion of with and spacing , the checkerboard mode has . Find its amplification factor per step for explicit Euler and for the implicit (FFT) step at , and say what each does.
Show worked solution
Explicit Euler multiplies the mode by : it flips sign and grows ninefold per step, an instability. The implicit step divides by , a factor : the checkerboard is damped almost completely in one step. For comparison, the explicit factor with the reaction’s decay rate included is , which equals exactly at the explicit limit (at ).
Linearise Gray-Scott about the empty state and show that explicit Euler on the checkerboard is stable for . For , , , find which species sets the limit and its value.
Show worked solution
At with and small, is second order in , so and . For the checkerboard acts as , so explicit Euler multiplies by and by . Each factor lies in exactly when . The decay rates are for and for . The limits are and . The species sets it, the one with the larger diffusivity, and the limit is , as the lab measures.
(a) Show that a non-empty uniform state of Gray-Scott satisfies and , and that real solutions need . (b) For , find the two values of and the corresponding . (c) Say why the two states are nearly equal.
Show worked solution
(a) Setting with gives , so . Setting gives ; with this is , and substituting and multiplying by gives , that is . Its discriminant is , which is nonnegative exactly when .
(b) , so and , whose square root is . Then , so and , and and .
(c) The discriminant is tiny: sits only above the saddle-node threshold where the two states merge, so the square root is small and they differ by about . This is the region where the Turing sliver of the lab lives.
What comes next
We built a small simulator and then distrusted each number it printed, which is the habit that separates a simulator from a screensaver. The obvious upgrades are all absent: a faster FFT (the real-input trick halves the work), a higher-order IMEX scheme (the first-order splitting error is what the table shows), a rule for the regimes that reads a long run on a big box, and non-periodic boundaries, where the FFT trick fails.
That last limit is the doorway to the next capstone, L-16.4, the Drum and Membrane Mode Synthesizer. The whole of step 2 rested on one fact: on a periodic square the Laplacian has eigenvectors that we know in closed form, the Fourier modes, so applying a function of is a transform, a multiplication and an inverse transform. The question that capstone asks is what the eigenvectors of the Laplacian are on a shape you draw, where no formula and no FFT is available. A sparse eigensolver finds them, and instead of you get the drum’s modes, whose eigenvalues are the squares of its pitches. It is the same Laplacian eigenproblem, and the same ; what changes is how you solve it. I have not run that capstone’s computation here, so what I can promise is the link and not its results.
Key Takeaways
- A periodic Gray-Scott step is a five-point Laplacian (four
np.rollcalls) plus a pointwise reaction; the lab’s explicit step is bit-for-bit the step of the reaction-diffusion lesson. - The explicit step limit is , the decay rate of the checkerboard about the empty state: at measured and by formula; stays bounded and blows up (to on a grid).
- On a periodic grid the Fourier modes are exact eigenvectors of the Laplacian with eigenvalue , , so an implicit diffusion solve is a division in Fourier space; the IMEX step stays bounded to (about times the explicit limit) but is first order and, on this coarse grid, costs more than it saves.
- The map from small runs gives empty, uniform, labyrinth, spots, holes and splitting cells; to cells change with the run time, and the splitting label is the least reliable.
- The empty state is always stable, so patterns grown from seeds have no linear prediction. A non-empty uniform state exists only for and is Turing unstable at only of lattice points; at , the predicted cells matched the spectrum peak at on cells until the labyrinth coarsened (peak at ).
- A radial power spectrum (ring-averaged of minus its mean) gives a dominant wavelength only when the pattern fills the periodic box; on unfilled boxes the peak is the cluster’s envelope.
- Seeds must be large enough: at , a side- seed dies and a side- seed grows into spots (, ); in a seed invades and does not. Erased regions refill to the same area fraction but not the same pattern.
- State the grid, the step, the seed and the time for every number, and recompute it independently; the same rule that makes a map is the rule that makes its limits.