Rectangles, Mode Pairs, and the Gray-Scott Lab
The 1D solver already gives the full workflow. In 2D, the ideas stay the same but the geometry becomes richer.
A field on \([0, L_x] \times [0, L_y]\) becomes a matrix.
The second derivative becomes the 5-point Laplacian.
Mode pairs generate spots, stripes, fronts, and labyrinths.
\[ \Delta u(x,y) \approx \frac{u(x+dx,y) + u(x-dx,y) + u(x,y+dx) + u(x,y-dx) - 4u(x,y)}{dx^2} \]
lap = -4 * field
lap += np.roll(field, 1, axis=0)
lap += np.roll(field, -1, axis=0)
lap += np.roll(field, 1, axis=1)
lap += np.roll(field, -1, axis=1)
lap = lap / dx**2This is still the same vectorized idea from session 6, now applied along two axes.
Copy the nearest interior row or column.
Pin the edge to a prescribed value.
Keep the np.roll() wrapping and do not overwrite the edges.
For zero flux on a rectangle,
With Neumann boundaries on \([0, L_x] \times [0, L_y]\),
\[ \lambda_{n_x,n_y} = -\left(\frac{n_x\pi}{L_x}\right)^2 - \left(\frac{n_y\pi}{L_y}\right)^2. \]
The temporal matrix is still
\[ A_{n_x,n_y} = J + \lambda_{n_x,n_y} D. \]
So the 1D workflow survives intact. The only change is that one mode number becomes a pair.
Take \(L_x = 20\), \(L_y = 50\), \(a = 0.4\), \(b = 1\), \(\gamma = 1\).
\(d = 30\)
\(d = 20\)
\[ \frac{\partial u}{\partial t} = d_1 \Delta u - u v^2 + f(1-u), \qquad \frac{\partial v}{\partial t} = d_2 \Delta v + u v^2 - (f+k)v \]
The numerical recipe is nearly unchanged.
For periodic boundaries on a rectangle,
\[ \lambda_{m,n} = -\left(\frac{2\pi m}{L_x}\right)^2 - \left(\frac{2\pi n}{L_y}\right)^2. \]
That is the main conceptual bridge from Gierer-Meinhardt to Gray-Scott.
for _ in range(num_steps):
lap_u = np.roll(u, 1, axis=0) + np.roll(u, -1, axis=0)
lap_u += np.roll(u, 1, axis=1) + np.roll(u, -1, axis=1) - 4 * u
lap_v = np.roll(v, 1, axis=0) + np.roll(v, -1, axis=0)
lap_v += np.roll(v, 1, axis=1) + np.roll(v, -1, axis=1) - 4 * v
u += dt * (d1 * lap_u - u * v**2 + f * (1 - u))
v += dt * (d2 * lap_v + u * v**2 - (f + k) * v)With periodic boundaries, this loop is complete. With Neumann or Dirichlet data, the edge values must be overwritten after each Euler step.
Use the predicted mode pairs to interpret stripes and spots on a rectangle.
Turn the solver into an interactive experiment with drawing, pause, and sliders.
Applied Math Lab