Patterns from a reaction¶
One of two substances that diffuse and react, long after a small seed was set: it has grown into a pattern of bands.
import sympy as sp
import pdemagic as pm
x, y, t = sp.symbols("x y t", real=True)
a = sp.Function("a")(x, y, t)
b = sp.Function("b")(x, y, t)
tile = pm.Space(x, y, periodic={x: (0, 1), y: (0, 1)})
seed = sp.exp(-((x - 0.5) ** 2 + (y - 0.5) ** 2) / 0.01)
ripple = 1 + sp.cos(6 * sp.pi * x) * sp.cos(4 * sp.pi * y) / 4
reaction = pm.Problem(
sp.Eq(a.diff(t), 2e-5 * pm.laplacian(a) - a * b**2 + 0.037 * (1 - a)),
sp.Eq(b.diff(t), 1e-5 * pm.laplacian(b) + a * b**2 - 0.097 * b),
domain=tile,
time=(t, 0.0, 2000.0),
initial={a: 1 - seed / 2, b: seed / 2 * ripple},
)
plan = pm.plan(reaction)
plan.grid.shape = [96, 96]
plan.times.count = 2
plan.method.tolerance = 1e-4
pm.solve(reaction, plan).plot(b)
What it shows¶
The Gray–Scott model: a substance a is fed in, a substance b feeds
on it at the rate \(a\,b^2\) and decays, and both diffuse, a twice as
fast as b. That is a system of two nonlinear equations on a periodic
tile. From a seed of b in the middle the reaction spreads outwards as
a band, which buckles as it grows. The seed is rippled a little, and
that decides where. The picture shows b at the end of the time span.
What pdemagic decided¶
The planner chose exponential time stepping of fourth order
(exponential_runge_kutta): the diffusion is exact, with the
exponential of a 2×2 matrix for every wave, and the reaction is stepped.
The plan changes three entries: the grid has 96 by 96 points, because
the pattern is finer than the seed, which is all the planner knows, only
the first and the last time are recorded, and the tolerance of a step is
\(10^{-4}\) in place of \(10^{-10}\), which is plenty for a picture. The
diagnostic solution_tail is \(3\cdot10^{-3}\): the bands are resolved,
though not to many digits.