Flow Lab

Syllabus / Module 16: Capstone Builds

Lesson 16.3

Capstone: Reaction–Diffusion Pattern Lab

Build a GPU-friendly Gray–Scott simulator with parameter maps, implicit/explicit options, and pattern analysis.

Written byClaude Sonnet

🌊
Why this matters for simulation: Practice for the structure of all grid-based PDE simulators.

By the end of this lesson you can…

  • Assemble a periodic Gray-Scott solver from a five-point Laplacian and a reaction term, and say which earlier lesson supplies each piece.
  • Measure the explicit step limit $2/(8D_u + F)$ by running the scheme, and build an IMEX step whose diffusion solve is exact because the Fourier modes diagonalise the periodic Laplacian.
  • Classify a point of the $(F, k)$ plane as empty, spots, stripes or labyrinth, holes or uniform with a stated numerical rule (blob count, area fraction, hole count), and say how often that rule changes its mind.
  • Compute a radial power spectrum with the FFT, read off the dominant wavelength, and compare it with a Turing linear prediction in the one place where Gray-Scott has such a prediction.
  • Predict and test what survives a seed: the smallest square seed and the smallest amplitude that invade the empty state, and the refilling of a region you have erased.
  • State, for every number the lab reports, the grid, the step, the seed and the time it was measured at, and name the three biggest limits of the lab.
On this page
·
  1. What we are building
  2. Step 1: the periodic Laplacian and one Gray-Scott step
  3. Step 2: the explicit limit and an implicit option
  4. Step 3: the (F, k) map of regimes
  5. How much to believe the map
  6. Step 4: the FFT spectrum and the Turing linear prediction
  7. Where linear theory speaks, and where it does not
  8. Step 5: painting, seeding and what survives
  9. The lab
  10. Honest limits
  11. Concept checks
  12. Problems
  13. What comes next
  14. Key Takeaways

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 (F,k)(F, k) 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.

▶ Video The Gray-Scott step in numpy, the stability limit measured and the FFT step that removes it, a map of the feed-kill plane built from many small runs, the radial spectrum of a pattern, and what survives a painted seedcaptions only
Transcript
  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  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.
  9. 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.
  10. 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:

ut=Du∇2u−uv2+F(1−u),vt=Dv∇2v+uv2−(F+k)v,u_t = D_u\nabla^2u - uv^2 + F(1 - u), \qquad v_t = D_v\nabla^2v + uv^2 - (F + k)v,

with Du=0.16D_u = 0.16, Dv=0.08D_v = 0.08, a square periodic grid of spacing 11, and the empty state (u,v)=(1,0)(u, v) = (1, 0) everywhere else. The reaction uv2uv^2 turns the feed uu into vv, the feed is replenished at rate FF, and vv is removed at rate F+kF + k. All times and lengths are in these units, so the unit of time is whatever makes Du=0.16D_u = 0.16, and nothing here is calibrated to a real chemistry.

Every result below states the grid size nn (the field is n×nn \times n), the time step hh, the seed and the time TT 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:

  1. the periodic Laplacian and a Gray-Scott step in numpy;
  2. the explicit stability limit, and an implicit (IMEX) step by FFT;
  3. the (F,k)(F, k) regime map, with a rule you can read;
  4. the FFT spectrum of a pattern, and the one honest comparison with linear theory;
  5. painting and nucleation: what survives.

Step 1: the periodic Laplacian and one Gray-Scott step

On a periodic grid of spacing 11 the Laplacian of 10.1 Finite Differences: Discretizing Derivatives is the five-point stencil with indices taken modulo nn:

(Lf)j,i=fj,i−1+fj,i+1+fj−1,i+fj+1,i−4fj,i.(Lf)_{j,i} = f_{j,i-1} + f_{j,i+1} + f_{j-1,i} + f_{j+1,i} - 4f_{j,i}.

In numpy this is four np.roll calls, and the wraparound is free. A Gray-Scott step is then one line per species: u←u+h(DuLu−uv2+F(1−u))u \leftarrow u + h(D_uLu - uv^2 + F(1-u)) and v←v+h(DvLv+uv2−(F+k)v)v \leftarrow v + h(D_vLv + uv^2 - (F+k)v), 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 500500 steps from the same seed on 64×6464 \times 64 cells gives fields that differ by exactly 00 (compared in node, not in numpy).

The Laplacian has a property that the rest of the capstone leans on. The plane waves exp⁡(i(qxx+qyy))\exp(i(q_xx + q_yy)) with q=2πm/nq = 2\pi m/n, m=0,…,n−1m = 0, \dots, n-1, are exactly periodic on the grid, and the stencil acts on one of them by a number:

L ei(qxx+qyy)=−λ ei(qxx+qyy),λ(mx,my)=(2−2cos⁡qx)+(2−2cos⁡qy).L\,e^{i(q_xx + q_yy)} = -\lambda\,e^{i(q_xx + q_yy)}, \qquad \lambda(m_x, m_y) = (2 - 2\cos q_x) + (2 - 2\cos q_y).

So the Fourier modes are the eigenvectors of LL, with eigenvalues −λ-\lambda that are never positive. The smallest nonzero λ\lambda belongs to the longest wave, and for the checkerboard (mx,my)=(n/2,n/2)(m_x, m_y) = (n/2, n/2) it is λ=8\lambda = 8, the largest of all. That is the same fact as the diagonalisation of 1.6 Change of Basis & Diagonalization, with a matrix of size n2n^2 and a basis the FFT computes in O(n2log⁡n)O(n^2\log n) operations; 10.12 Spectral Methods & the FFT used it for derivatives. In this capstone it makes the implicit step trivial.

🐍 PythonStep 1 and the explicit limit: the periodic Laplacian, its FFT eigenvalues, and where explicit Euler blows up
⌘/Ctrl + Enter

The playground prints the eigenvalue check, the measured limit and a full nonlinear test. For the empty state (1,0)(1, 0) the Jacobian of the reaction is diag(−F,−(F+k))\mathrm{diag}(-F, -(F+k)), and the checkerboard of uu decays or grows per step by 1−h(8Du+F)1 - h(8D_u + F), so explicit Euler is stable only for h≤2/(8Du+F)h \le 2/(8D_u + F). Running the scheme, bisecting on whether the per-step factor exceeds 11 (16×1616 \times 16 grid, 4040 steps, seed-free), gives 1.526721.52672 at F=0.03F = 0.03 in both programs, against the formula’s 1.526721.52672; the formula and the measurement agree to 4×10−84 \times 10^{-8}. The full nonlinear run on 64×6464 \times 64 cells from a 17×1717 \times 17 square seed (u=0.5u = 0.5, v=0.25v = 0.25 plus the small tilt of 15.5 Reaction–Diffusion & Turing Patterns) stays bounded to T=2000T = 2000 at h=1.52h = 1.52 and is unbounded at h=1.53h = 1.53. 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, D h/Δx2≤1/4D\,h/\Delta x^2 \le 1/4 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 DuD_u and DvD_v as multiplied by 44 and by 1616, which is what spacings 1/21/2 and 1/41/4 do (for the same physical diffusivities), the measured limits are 0.388350.38835 and 0.097510.09751 at F=0.03F = 0.03 (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 hh in the diffusion part.

The usual obstacle is the linear solve (I−hD L) unew=rhs(I - hD\,L)\,u^{\text{new}} = \text{rhs}, 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 LL, so in Fourier space the system is (1+hDλ) u^new=rhs^(1 + hD\lambda)\,\hat u^{\text{new}} = \hat{\text{rhs}}, a division at each wave vector. The scheme, called IMEX (implicit for the stiff linear part, explicit for the nonlinear reaction), is

u^new=u+h Ru(u,v)^1+hDuλ,v^new=v+h Rv(u,v)^1+hDvλ,\hat u^{\text{new}} = \frac{\widehat{u + h\,R_u(u, v)}}{1 + hD_u\lambda}, \qquad \hat v^{\text{new}} = \frac{\widehat{v + h\,R_v(u, v)}}{1 + hD_v\lambda},

with Ru=−uv2+F(1−u)R_u = -uv^2 + F(1-u) and Rv=uv2−(F+k)vR_v = uv^2 - (F+k)v. It is first order in hh, like explicit Euler, and it cannot be unstable because of diffusion, whatever the wave vector: the factor 1/(1+hDλ)1/(1 + hD\lambda) is always between 00 and 11. 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 h=8h = 8, five times the explicit limit.

🧪 Coding exerciseExercise: the IMEX step with an exact FFT diffusion solve
⌘/Ctrl + Enter

How well does it work? Here is the lab’s measurement on 64×6464 \times 64 cells at F=0.03F = 0.03, k=0.062k = 0.062, from the square seed above, with the error in vv taken at T=200T = 200 against explicit Euler at h=0.05h = 0.05 (the reference, taken as truth):

scheme and stepmax error in vvrms error in vv
explicit, h=0.5h = 0.50.003640.003640.000440.00044
explicit, h=1h = 10.007910.007910.000960.00096
IMEX, h=0.25h = 0.250.005000.005000.000700.00070
IMEX, h=0.5h = 0.50.009900.009900.001400.00140
IMEX, h=1h = 10.019170.019170.002750.00275
IMEX, h=2h = 20.036430.036430.005210.00521
IMEX, h=4h = 40.064500.064500.009300.00930
IMEX, h=8h = 80.105940.105940.015160.01516

The error doubles with hh, which is first order, and at equal hh 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 T=2000T = 2000 at h=16h = 16 and is unbounded at h=20h = 20; a bisection on that test puts the edge at about 17.417.4 (the bisection assumes the test is monotone in hh, which I did not check beyond the two points). That is 1111 times the explicit limit. It is not free. The pattern’s statistics drift as hh grows: at T=2000T = 2000 the number of blobs of vv above 0.20.2 is 2222 for explicit h=1h = 1 and for IMEX h=1h = 1, 2121 at h=4h = 4 and 1717 at h=8h = 8. Stable does not mean right.

◆ Interactive Stability and the implicit option: set explicit Euler, push the step h past 1.53 and watch the field blow up, then switch to IMEX at h = 8 and compare the patterns

Loading simulation…

Step 3: the (F, k) map of regimes

The map is the lab’s central instrument. For every point of a lattice of 1919 feeds F=0.010,0.015,…,0.100F = 0.010, 0.015, \dots, 0.100 and 1313 kills k=0.040,0.0425,…,0.0700k = 0.040, 0.0425, \dots, 0.0700, which is 247247 cells, the lab runs a small simulation: a 48×4848 \times 48 periodic grid, explicit Euler at h=1h = 1, three 7×77 \times 7 square seeds (u=0.5u = 0.5, v=0.25v = 0.25) at positions drawn by a seeded generator (mulberry32, seed 77), for T=3000T = 3000. Then it classifies the final field of vv with a rule that fits on a card:

  • empty: max⁡v<0.05\max v \lt 0.05, the seeds died;
  • uniform: vv is not empty but its standard deviation is below 0.010.01, so it filled the box evenly;
  • holes: the area where v>0.2v \gt 0.2 exceeds 55%55\% and the complement (v≤0.2v \le 0.2) has at least 33 connected pieces;
  • spots: at least 33 separate blobs of v>0.2v \gt 0.2, covering under 40%40\%, each averaging under 2%2\% of the box (and labelled “splitting” instead if the blob count rose by more than 10%10\% in the last 300300 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.

🧪 Coding exerciseExercise: count the blobs of a mask on a periodic grid
⌘/Ctrl + Enter

The whole map, lattice by lattice, comes out as: 104104 empty, 101101 uniform, 2222 stripes or labyrinth, 1212 spots, 55 holes and 33 spots still splitting, totalling 247247. Both programs gave the same label in every one of the 247247 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 vv, and above the top edge everything is empty. In the sim the dashed curve is k=F/2−Fk = \sqrt F/2 - F. It is the saddle-node line F=4(F+k)2F = 4(F+k)^2 where a second, non-empty uniform state is born; step 4 explains why that matters.

🐍 PythonThree cells of the map in numpy: spots, a labyrinth and an empty cell
⌘/Ctrl + Enter

The three lines the playground prints are the same numbers the sim computes for those cells: at F=0.03F = 0.03, k=0.062k = 0.062 the lattice cell holds 1515 blobs covering 23.4%23.4\%; at F=0.04F = 0.04, k=0.06k = 0.06 it holds 11 connected structure covering 51.3%51.3\% with 33 holes; at F=0.07F = 0.07, k=0.0625k = 0.0625 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 T=1500T = 1500 changes the label of 1111 of the 247247 cells; at T=6000T = 6000, 1010 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 48×4848 \times 48 box holds only a few wavelengths. At 64×6464 \times 64 and T=6000T = 6000 the cell (0.03,0.062)(0.03, 0.062) has 2929 spots and (0.04,0.06)(0.04, 0.06) stays a labyrinth (22 pieces, 50.7%50.7\%); the labels agree, the counts scale with area.
  • The splitting label is the weakest. The mitosis point of the standard picture, F=0.0367F = 0.0367, k=0.0649k = 0.0649, is labelled plain spots by this rule on the lattice (1010 blobs, 19.4%19.4\%, count unchanged over the last 300300 steps). A static rule cannot reliably see a process.
  • Worms. The cell (0.058,0.065)(0.058, 0.065) has 33 small blobs covering 12.5%12.5\% 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 vv minus its mean, square the magnitudes, and average the power over rings of wave vectors with the same ∣m∣=mx2+my2|m| = \sqrt{m_x^2 + m_y^2} (rounded to an integer, the ring index). The ring average is the radial power spectrum P(m)P(m). Its peak is the dominant number of wavelengths across the box, and the dominant wavelength is n/mn/m cells. Averaging over a ring (a mean, not a sum) matters: the ring at mm has about 2πm2\pi m wave vectors in it, so a sum would favour large mm for no physical reason. You write it now.

🧪 Coding exerciseExercise: the radial power spectrum and the dominant wavelength
⌘/Ctrl + Enter

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 ∇2\nabla^2 by −λ-\lambda, and ask for the wave numbers whose growth rate σ(λ)\sigma(\lambda) is positive. Do the same for Gray-Scott and the first thing to check is which uniform states exist. The empty state (1,0)(1, 0) always exists and its Jacobian diag(−F,−(F+k))\mathrm{diag}(-F, -(F+k)) is stable for every FF and kk, and diffusion adds −Dλ-D\lambda 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 (u,v)(u, v) exists when uv=F+kuv = F + k and F(1−u)=(F+k)vF(1-u) = (F+k)v have a solution, which gives (F+k)v2/F−v+(F+k)=0(F+k)v^2/F - v + (F+k) = 0, real exactly when

F≥4(F+k)2,F \ge 4(F+k)^2,

and then v=F(1±1−4(F+k)2/F)/(2(F+k))v = F\big(1 \pm \sqrt{1 - 4(F+k)^2/F}\big)/(2(F+k)) with u=(F+k)/vu = (F+k)/v. 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: 4(0.092)2=0.03394(0.092)^2 = 0.0339 against F=0.03F = 0.03, and 4(0.1016)2=0.04134(0.1016)^2 = 0.0413 against 0.03670.0367; at F=0.04F = 0.04, k=0.06k = 0.06 the two sides are both 0.040.04 (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 J=(−v2−F−2uvv22uv−(F+k))J = \begin{pmatrix} -v^2 - F & -2uv \\ v^2 & 2uv - (F+k) \end{pmatrix} and the eigenvalue of largest real part of J−λ diag(Du,Dv)J - \lambda\,\mathrm{diag}(D_u, D_v) as a function of λ\lambda. The state must be stable to uniform changes (tr J<0\mathrm{tr}\,J \lt 0, det⁡J>0\det J \gt 0) while some λ>0\lambda \gt 0 still grows. On a lattice of 191×101=19291191 \times 101 = 19291 points (F=0.005F = 0.005 to 0.1000.100 in steps of 0.00050.0005, k=0.030k = 0.030 to 0.0800.080 in steps of 0.00050.0005) a non-empty state exists at 1045810458 points, and a Turing-unstable one at only 6767: a thin sliver along the saddle-node curve (dotted in the sim). Both programs return the same three numbers.

Take F=0.074F = 0.074, k=0.062k = 0.062, the largest growth rate on the lattice. There s=F+k=0.136s = F + k = 0.136 and 4s2=0.0739844s^2 = 0.073984, so FF is only 1.6×10−51.6 \times 10^{-5} above the threshold and the two uniform states are close: (u,v)=(0.4926,0.2761)(u, v) = (0.4926, 0.2761) and (0.5074,0.2681)(0.5074, 0.2681). The first has tr J=−0.01421\mathrm{tr}\,J = -0.01421 and det⁡J=3.004×10−4\det J = 3.004 \times 10^{-4}, stable to uniform change. The second has det⁡J=−2.92×10−4\det J = -2.92 \times 10^{-4}, a saddle, and is not relevant. For the first, the growth rate σ(q)\sigma(q), with q2=λq^2 = \lambda, is positive for qq from 0.17950.1795 to 0.85350.8535, the wavelengths 2π/q2\pi/q from 7.47.4 to 35.035.0, with the maximum σ=0.01499\sigma = 0.01499 at q=0.490q = 0.490, a continuum wavelength of 12.8212.82 cells. On a 128128-cell box the available waves have mm cycles across, and the axis modes m=9,10,11m = 9, 10, 11 (wavelengths 14.2214.22, 12.8012.80, 11.6411.64) grow at 0.014660.01466, 0.014980.01498 and 0.014760.01476 per unit time, within 2.2%2.2\% 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 10−310^{-3} (seed 33 of mulberry32, explicit Euler at h=1h = 1, 128×128128 \times 128 cells) and read the spectrum.

ttpeak mm (wavelength)centroid wavelengthrange of vv
2002001010 (12.8012.80)12.9412.940.26700.2670 to 0.28240.2824
3003001010 (12.8012.80)12.9412.940.21890.2189 to 0.29700.2970
4004001010 (12.8012.80)13.0313.030.00840.0084 to 0.34030.3403
7007001010 (12.8012.80)13.0913.090.00060.0006 to 0.47360.4736
400040001010 (12.8012.80)13.1213.12(labyrinth, 11 piece, 2727 holes)
800080001010 (12.8012.80)13.1613.16(labyrinth, 11 piece, 2727 holes)
130001300088 (16.0016.00)15.5915.59(labyrinth, 11 piece, 2626 holes)

The measured peak sits on the predicted m=10m = 10 from t=200t = 200 (at t=100t = 100 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 t=8000t = 8000. At t=13000t = 13000 the labyrinth has slowly coarsened and the peak has moved to m=8m = 8, 16.016.0 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 t=700t = 700 the range of vv is 0.00060.0006 to 0.470.47. This is not a small ripple on the uniform state; vv is nearly zero between the spots, which means the system has been thrown into the basin of the empty state, as it should be (uv2u v^2 is tiny where vv is). The wavelength survives the first nonlinear stage here. There is no reason to expect that at other parameters.

🐍 PythonLinear prediction and a noise run in numpy: F = 0.074, k = 0.062
⌘/Ctrl + Enter
◆ Interactive The one place with a linear prediction: F = 0.074, k = 0.062, started from noise about the uniform state. The orange line in the spectrum is the predicted wavelength

Loading simulation…

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 128×128128 \times 128 box from the central 17×1717 \times 17 seed with the small tilt, explicit h=1h = 1 and T=8000T = 8000: the spots preset (F=0.03F = 0.03, k=0.062k = 0.062) has peak m=11m = 11, wavelength 11.6411.64, centroid 11.6611.66, with 110110 blobs covering 23.1%23.1\%; the labyrinth preset (F=0.04F = 0.04, k=0.06k = 0.06) has peak m=10m = 10, wavelength 12.8012.80, centroid 12.5612.56, one connected structure covering 52.5%52.5\%. Both are filled boxes. The splitting point (F=0.0367F = 0.0367, k=0.0649k = 0.0649) and the slow-growth point (F=0.058F = 0.058, k=0.065k = 0.065) have not yet filled the box at T=8000T = 8000 (6363 blobs covering 15.9%15.9\%, and one blob covering 3.5%3.5\%); their spectra peak at m=1m = 1, 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 u=0.5u = 0.5, v=0.25v = 0.25 centred in a 64×6464 \times 64 box, run to T=3000T = 3000 at h=1h = 1 with explicit Euler. At F=0.03F = 0.03, k=0.062k = 0.062:

  • seeds of side 11 and 33 cells (half-width 00 and 11) vanish;
  • seeds of side 55 and 77 (half-width 22 and 33) grow into 2424 spots covering 21.7%21.7\% and 21.9%21.9\% of the box.

At F=0.04F = 0.04, k=0.06k = 0.06 the threshold falls in the same place: side 33 dies, side 55 gives a labyrinth (22 connected pieces, 50.8%50.8\% of the box). Once the seed is large enough, its exact size no longer matters for the count: every seed from side 55 to 77 gave the same 2424 spots at this box and time. The amplitude has a threshold too. With a 7×77 \times 7 seed, u=0.5u = 0.5 and v=av = a, the spots invade for a≥0.19a \ge 0.19 and die for a≤0.18a \le 0.18 at F=0.03F = 0.03; at F=0.04F = 0.04 the threshold lies between 0.190.19 and 0.200.20. 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 vv uniformly distributed in [0,a][0, a] (and u=1−(a/2) ru = 1 - (a/2)\,r with rr a second uniform draw in [0,1][0, 1], mulberry32 seed 55) and run to T=3000T = 3000: at F=0.03F = 0.03, k=0.062k = 0.062 the field returns to empty for a=0.05a = 0.05, 0.20.2 and 0.50.5. At F=0.04F = 0.04, k=0.06k = 0.06 it does the same for a=0.05a = 0.05 and 0.50.5 but for a=0.2a = 0.2 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 vv 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 T=3000T = 3000 (2424 blobs, 21.9%21.9\%), then erase the left half of the box back to the empty state: 1212 blobs and 10.9%10.9\% remain. Continuing, the count is 1212 at 500500 more steps (15.8%15.8\% of the area, growing), 2020 at 15001500 (23.3%23.3\%) and 2020 at 30003000 (23.7%23.7\%). The spots invade the erased region from the surviving half, the area fraction returns to within two percentage points of the original (23.7%23.7\% against 21.9%21.9\%), and the number of spots does not: 2020, not 2424. The same statistics come back, but the pattern is a different pattern.

🐍 PythonNucleation in numpy: a seed of side 3 dies, a seed of side 5 grows into 24 spots
⌘/Ctrl + Enter

The lab

The sim below puts the whole chain in one place. The left panel is the field of vv (or uu); 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 FF and kk live, the stepper menu switches between explicit Euler and the FFT-based IMEX step, the step slider changes hh, 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 hh above 1.531.53 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 hh; load a map cell near the edge of the spots region and paint extra seeds; and load F=0.074F = 0.074, k=0.062k = 0.062 and start from noise about the uniform state to see the linear prediction land on the spectrum.

◆ Interactive The pattern lab: move F and k or click the map, paint seeds with the pointer, switch the stepper and read the spectrum (128 x 128 field, 48 x 48 map cells)

Loading simulation…

Honest limits

  • The map is a rule, a box and a time. It uses 48×4848 \times 48 cells, three seeds, one seed set and T=3000T = 3000. A different rule would draw different borders, and 1010 or 1111 of 247247 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 (6767 of 1929119291 lattice points), and there it matched a 128128-cell box to the bin from t=200t = 200 to 80008000, after which the pattern coarsened to m=8m = 8. It says nothing about the spots, the labyrinths or the splitting, which are nonlinear.
  • The five-point Laplacian is anisotropic. Its eigenvalue λ\lambda 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 hh 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

✅ Concept check

At $F = 0.05$ with $D_u = 0.16$ (spacing $1$), what is the explicit Euler limit $2/(8D_u + F)$?

✅ Concept check

On a $64 \times 64$ periodic grid, what is $\lambda$ for the Fourier mode $(m_x, m_y) = (8, 0)$, so that the five-point Laplacian multiplies it by $-\lambda$?

✅ Concept check

Why is the IMEX step with $h = 8$ stable when explicit Euler at the same $h$ is not?

✅ Concept checkselect all that apply

Select all that are true of the Gray-Scott linear (Turing) analysis in this capstone.

✅ Concept check

A $3 \times 3$ square seed ($u = 0.5$, $v = 0.25$) in an empty $64 \times 64$ box at $F = 0.03$, $k = 0.062$ is run for $3000$ steps. What does the lab find?

✅ Concept check

A $128 \times 128$ pattern has its radial spectrum peak at $m = 10$. What is the dominant wavelength?

Problems

✏️ Pen & paperImplicit against explicit on the checkerboard●○○

For pure diffusion of uu with Du=0.16D_u = 0.16 and spacing 11, the checkerboard mode has λ=8\lambda = 8. Find its amplification factor per step for explicit Euler and for the implicit (FFT) step at h=8h = 8, and say what each does.

Show worked solution

Explicit Euler multiplies the mode by 1−hDuλ=1−8×0.16×8=1−10.24=−9.241 - hD_u\lambda = 1 - 8 \times 0.16 \times 8 = 1 - 10.24 = -9.24: it flips sign and grows ninefold per step, an instability. The implicit step divides by 1+hDuλ=1+10.24=11.241 + hD_u\lambda = 1 + 10.24 = 11.24, a factor 0.08900.0890: the checkerboard is damped almost completely in one step. For comparison, the explicit factor with the reaction’s decay rate FF included is 1−h(8Du+F)1 - h(8D_u + F), which equals exactly −1-1 at the explicit limit h=1.5267h = 1.5267 (at F=0.03F = 0.03).

✏️ Pen & paperDeriving the explicit limit●●○

Linearise Gray-Scott about the empty state (u,v)=(1,0)(u, v) = (1, 0) and show that explicit Euler on the checkerboard is stable for h≤min⁡(2/(8Du+F),  2/(8Dv+F+k))h \le \min\big(2/(8D_u + F),\; 2/(8D_v + F + k)\big). For F=0.03F = 0.03, k=0.062k = 0.062, Du=0.16D_u = 0.16, Dv=0.08D_v = 0.08 find which species sets the limit and its value.

Show worked solution

At (1,0)(1, 0) with u=1+au = 1 + a and v=bv = b small, uv2uv^2 is second order in bb, so at=DuLa−Faa_t = D_uLa - Fa and bt=DvLb−(F+k)bb_t = D_vLb - (F + k)b. For the checkerboard LL acts as −8-8, so explicit Euler multiplies aa by 1−h(8Du+F)1 - h(8D_u + F) and bb by 1−h(8Dv+F+k)1 - h(8D_v + F + k). Each factor lies in [−1,1][-1, 1] exactly when h≤2/(decay rate)h \le 2/(\text{decay rate}). The decay rates are 8×0.16+0.03=1.318 \times 0.16 + 0.03 = 1.31 for aa and 8×0.08+0.092=0.7328 \times 0.08 + 0.092 = 0.732 for bb. The limits are 2/1.31=1.52672/1.31 = 1.5267 and 2/0.732=2.73222/0.732 = 2.7322. The uu species sets it, the one with the larger diffusivity, and the limit is 1.52671.5267, as the lab measures.

✏️ Pen & paperA uniform state just above the saddle-node●●●

(a) Show that a non-empty uniform state of Gray-Scott satisfies uv=F+kuv = F + k and (F+k)v2/F−v+(F+k)=0(F + k)v^2/F - v + (F+k) = 0, and that real solutions need F≥4(F+k)2F \ge 4(F+k)^2. (b) For F=0.074F = 0.074, k=0.062k = 0.062 find the two values of vv and the corresponding uu. (c) Say why the two states are nearly equal.

Show worked solution

(a) Setting vt=0v_t = 0 with v≠0v \neq 0 gives uv2=(F+k)vuv^2 = (F+k)v, so uv=F+kuv = F + k. Setting ut=0u_t = 0 gives −uv2+F(1−u)=0-uv^2 + F(1-u) = 0; with uv2=(F+k)vuv^2 = (F+k)v this is F(1−u)=(F+k)vF(1-u) = (F+k)v, and substituting u=(F+k)/vu = (F+k)/v and multiplying by v/Fv/F gives v−(F+k)=(F+k)v2/Fv - (F+k) = (F+k)v^2/F, that is (F+k)v2/F−v+(F+k)=0(F+k)v^2/F - v + (F+k) = 0. Its discriminant is 1−4(F+k)2/F1 - 4(F+k)^2/F, which is nonnegative exactly when F≥4(F+k)2F \ge 4(F+k)^2.

(b) s=F+k=0.136s = F + k = 0.136, so 4s2=0.0739844s^2 = 0.073984 and 1−4s2/F=1−0.073984/0.074=2.162×10−41 - 4s^2/F = 1 - 0.073984/0.074 = 2.162 \times 10^{-4}, whose square root is 0.014700.01470. Then v=F(1±0.01470)/(2s)=0.074(1±0.0147)/0.272=0.27206(1±0.0147)v = F(1 \pm 0.01470)/(2s) = 0.074(1 \pm 0.0147)/0.272 = 0.27206(1 \pm 0.0147), so v=0.2761v = 0.2761 and 0.26810.2681, and u=s/v=0.4926u = s/v = 0.4926 and 0.50740.5074.

(c) The discriminant is tiny: FF sits only 1.6×10−51.6 \times 10^{-5} above the saddle-node threshold where the two states merge, so the square root is small and they differ by about 3%3\%. 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 LL 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 ei(qxx+qyy)e^{i(q_xx + q_yy)} you get the drum’s modes, whose eigenvalues are the squares of its pitches. It is the same Laplacian eigenproblem, and the same λ\lambda; 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.roll calls) 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 2/(8Du+F)2/(8D_u + F), the decay rate of the uu checkerboard about the empty state: 1.52671.5267 at F=0.03F = 0.03 measured and by formula; h=1.52h = 1.52 stays bounded and 1.531.53 blows up (to T=2000T = 2000 on a 64×6464 \times 64 grid).
  • On a periodic grid the Fourier modes are exact eigenvectors of the Laplacian with eigenvalue −λ-\lambda, λ=(2−2cos⁡qx)+(2−2cos⁡qy)\lambda = (2 - 2\cos q_x) + (2 - 2\cos q_y), so an implicit diffusion solve is a division in Fourier space; the IMEX step stays bounded to h=16h = 16 (about 1111 times the explicit limit) but is first order and, on this coarse grid, costs more than it saves.
  • The (F,k)(F, k) map from 247247 small runs gives 104104 empty, 101101 uniform, 2222 labyrinth, 1212 spots, 55 holes and 33 splitting cells; 1010 to 1111 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 F≥4(F+k)2F \ge 4(F + k)^2 and is Turing unstable at only 6767 of 1929119291 lattice points; at F=0.074F = 0.074, k=0.062k = 0.062 the predicted 12.8212.82 cells matched the spectrum peak at m=10m = 10 on 128128 cells until the labyrinth coarsened (peak m=8m = 8 at t=13000t = 13000).
  • A radial power spectrum (ring-averaged ∣v^∣2|\hat v|^2 of vv minus its mean) gives a dominant wavelength n/mn/m only when the pattern fills the periodic box; on unfilled boxes the peak is the cluster’s envelope.
  • Seeds must be large enough: at F=0.03F = 0.03, k=0.062k = 0.062 a side-33 seed dies and a side-55 seed grows into 2424 spots (64×6464 \times 64, T=3000T = 3000); v≥0.19v \ge 0.19 in a 7×77 \times 7 seed invades and 0.180.18 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.
Finished this lesson?

Mark it complete to track your progress (saved in this browser). Reading every section does this for you.