0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 1% Schnakenberg reaction-diffusion on a closed surface.
2%
3% du/dt = D1*lap_g(u) + a - u + u^2*v
4% dv/dt = D2*lap_g(v) + b - u^2*v
5%
62e6cc4Simplify UI text and built-in .m script commentsJeremy Magland 6% Explicit reaction, implicit diffusion (IMEX Euler). The implicit solve
7% splits lap_g = lap_s + dlap: the round-sphere part lap_s is diagonal in
8% spherical-harmonic space (eigenvalues -lam), and the loop iterates the
9% geometric correction dlap from that exact solve. Grid fields are npts x 1;
8144287WIP: added code for Laplace-Beltrami operator evaluation on smooth genus-0 surfaceOwen Melia 10% spectral fields are real 2 x nlm. See docs/richardson-iteration.md.
591a4f5Reduce the Laplace-Beltrami matvec to 6 transforms per species per iterationDan Fortunato 11%
12% The correction evaluates lap_g in flux form -- 6 transforms per species
13% per iteration where the Cartesian-gradient form (Algorithm 4 of
14% evolving_surface/notes/algos.tex) needs 12. See
15% docs/reduced-transforms.md, and models/schnakenberg_alg4.m
16% for the original form kept as a live reference.
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 17
18function [U, V, u, v] = init(noise, a, b)
19 us = a + b;
20 vs = b / (us * us);
a4fee9cBatch independent transforms through one Legendre dispatchDan Fortunato 21 [U, V] = analys(us + noise, vs * ones(numel(noise), 1));
22 [u, v] = synth(U, V);
e4d6a3bPrecondition with the operator's symbol; project the correction onto the bandDan Fortunato 25function [Un, Vn, u, v] = step(U, V, lam, filt, gx, gy, gz, p1, p2, q2, r, jhat, a, b, D1, D2, dt, niter)
a4fee9cBatch independent transforms through one Legendre dispatchDan Fortunato 26 % Grouped transforms -- [a, b] = synth(x, y) -- are explicit batching:
27 % output k is the transform of input k, and the whole group runs as one
28 % batched Legendre dispatch, or as many as the device's lane width allows
29 % (src/mgpu/plan.ts, materializeTransforms). The grouping is a promise of
30 % independence, never of a lane width, so the same source runs anywhere.
31 [u, v] = synth(U, V);
62e6cc4Simplify UI text and built-in .m script commentsJeremy Magland 34 % Right-hand side of the implicit solve (I - dt*D*lap_g) Unew = B.
36 rv = b - uuv;
37 [Ru, Rv] = analys(ru, rv);
38 Bu = U + dt * Ru;
39 Bv = V + dt * Rv;
e4d6a3bPrecondition with the operator's symbol; project the correction onto the bandDan Fortunato 41 % Preconditioned solve, then iterate the geometric correction. jhat is
42 % the host's minimax scale over the operator's symbol eigenvalues mu(x)
43 % -- the inverse squared principal stretches of the embedding, direction
44 % included (src/geom/geometry.ts, Jhat): preconditioning with lam/jhat
45 % contracts every mode and direction at rate
46 % (muMax - muMin)/(muMax + muMin) < 1 on any surface, where the plain
47 % lam (jhat = 1) diverges wherever mu > 2 -- docs/reduced-transforms.md
48 % Sec 10. The answer never depends on jhat (the lamJ term added inside
49 % dLu is the term divided back out); only the convergence rate does. On
50 % the sphere mu = 1 and lamJ = lam.
51 lamJ = lam ./ jhat;
52 Un = Bu ./ (1 + (dt * D1) * lamJ);
53 Vn = Bv ./ (1 + (dt * D2) * lamJ);
55 for k = 1:niter
591a4f5Reduce the Laplace-Beltrami matvec to 6 transforms per species per iterationDan Fortunato 56 % dlap = lap_g - lap_s at the current iterate, in flux form
a4fee9cBatch independent transforms through one Legendre dispatchDan Fortunato 57 % (docs/reduced-transforms.md Sec 4). The sin-weighted derivatives
58 % sin(theta)*dtheta(u) and dphi(u) -- both smooth on the sphere,
59 % synthesized straight from the dthetac/dphic coefficient shuffles --
60 % are combined pointwise through the precomputed weights p1,p2,q2 into
0d99c91Differentiate the phi flux in grid spaceDan Fortunato 61 % two fluxes P,Q, also smooth. The theta flux P goes back to
62 % coefficients, through the same shuffle again, and is synthesized as
63 % sin(theta)*dtheta(P); the phi flux Q never leaves the grid -- d/dphi
64 % is diagonal in the Fourier index, so dphig differentiates it with two
65 % FFT stages and no Legendre work (masking m past filt's reach). Their
66 % sum, scaled by r, is lap_g(u). The only division by sin(theta)
67 % anywhere is folded into p1,p2,q2,r at precompute time.
e4d6a3bPrecondition with the operator's symbol; project the correction onto the bandDan Fortunato 68 % lamJ.*Un adds back the preconditioner's -lap_s(Un)/jhat, since lam
69 % holds +l(l+1). filt zeroes the top two degrees, where the derivative
70 % recurrences cannot exactly represent a derivative -- and the correction
71 % itself is projected onto the same band (algos.tex Algorithm 5 zeroes
72 % the same coefficients): without that, each iteration replaces a bit
73 % more of the top degrees' implicit diffusion with nothing (their fixed
74 % point is the undiffused Bu), and the two species un-diffuse at
75 % different rates -- a spurious Turing band at the band edge.
77 % The two species share each grouped call: the four gradient
0d99c91Differentiate the phi flux in grid spaceDan Fortunato 78 % syntheses, the two theta-flux analyses, the two divergence syntheses
79 % and the two final analyses each run as one batched dispatch.
8144287WIP: added code for Laplace-Beltrami operator evaluation on smooth genus-0 surfaceOwen Melia 80 Fu = Un .* filt;
82 vtu = dthetac(Fu);
83 vpu = dphic(Fu);
84 vtv = dthetac(Fv);
85 vpv = dphic(Fv);
86 [Ftu, Fpu, Ftv, Fpv] = synth(vtu, vpu, vtv, vpv);
591a4f5Reduce the Laplace-Beltrami matvec to 6 transforms per species per iterationDan Fortunato 87 Pu = p1 .* Ftu + p2 .* Fpu;
88 Qu = p2 .* Ftu + q2 .* Fpu;
89 Pv = p1 .* Ftv + p2 .* Fpv;
90 Qv = p2 .* Ftv + q2 .* Fpv;
a4fee9cBatch independent transforms through one Legendre dispatchDan Fortunato 92 Pcu = PAu .* filt;
93 Pcv = PAv .* filt;
95 scv = dthetac(Pcv);
a4fee9cBatch independent transforms through one Legendre dispatchDan Fortunato 96 [Lu, Lv] = synth(scu, scv);
98 dQv = dphig(Qv);
99 lapu = r .* (Lu + dQu);
100 lapv = r .* (Lv + dQv);
a4fee9cBatch independent transforms through one Legendre dispatchDan Fortunato 101 [LAu, LAv] = analys(lapu, lapv);
e4d6a3bPrecondition with the operator's symbol; project the correction onto the bandDan Fortunato 102 dLu = (LAu + lamJ .* Un) .* filt;
103 dLv = (LAv + lamJ .* Vn) .* filt;
8144287WIP: added code for Laplace-Beltrami operator evaluation on smooth genus-0 surfaceOwen Melia 104
e4d6a3bPrecondition with the operator's symbol; project the correction onto the bandDan Fortunato 105 Un = (Bu + (dt * D1) * dLu) ./ (1 + (dt * D1) * lamJ);
106 Vn = (Bv + (dt * D2) * dLv) ./ (1 + (dt * D2) * lamJ);
108end