Partial Differential Equations in 2D

Rectangles, Mode Pairs, and the Gray-Scott Lab

From an Interval to a Rectangle

The 1D solver already gives the full workflow. In 2D, the ideas stay the same but the geometry becomes richer.

Data shape

A field on \([0, L_x] \times [0, L_y]\) becomes a matrix.

Diffusion stencil

The second derivative becomes the 5-point Laplacian.

Visible payoff

Mode pairs generate spots, stripes, fronts, and labyrinths.

Rectangular Grid and 5-Point Stencil

\[ \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**2

This is still the same vectorized idea from session 6, now applied along two axes.

Boundary Conditions in 2D

Neumann

Copy the nearest interior row or column.

Dirichlet

Pin the edge to a prescribed value.

Periodic

Keep the np.roll() wrapping and do not overwrite the edges.

For zero flux on a rectangle,

uv[:, 0, :] = uv[:, 1, :]
uv[:, -1, :] = uv[:, -2, :]
uv[:, :, 0] = uv[:, :, 1]
uv[:, :, -1] = uv[:, :, -2]

Gierer-Meinhardt in 2D Uses Mode Pairs

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.

Domain Geometry Changes the Leading Pattern

Take \(L_x = 20\), \(L_y = 50\), \(a = 0.4\), \(b = 1\), \(\gamma = 1\).

Case A

\(d = 30\)

  • Turing unstable
  • Leading 2D mode: \((0, 7)\)
  • The longer \(y\) direction admits more oscillations, so stripes align with the geometry
Case B

\(d = 20\)

  • No unstable 2D modes
  • The homogeneous state stays dominant

Gray-Scott Reuses the Same Solver

\[ \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.

  • Same rectangular grid
  • Same 5-point stencil
  • Same explicit Euler update
  • Different reaction term
  • Periodic boundaries instead of Neumann

Periodic Boundaries Change the Spectrum

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.

The Core 2D Update Loop

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.

From Solver to Lab

Gierer-Meinhardt

Use the predicted mode pairs to interpret stripes and spots on a rectangle.

Gray-Scott

Turn the solver into an interactive experiment with drawing, pause, and sliders.

Module Pages