/ concept-collection / turing-surface
Sign in
concept-collection / turing-surface
114 lines · 5.2 KBCodeBlameHistory
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.
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.
0ae15cfSeed runs from smooth random fields, and add the blob geometryDan Fortunato 18% The uniform steady state, perturbed by a smooth random field: chebfun's
19% randnfun3 on the surface's bounding box, restricted to the surface by
20% evaluating it at the grid points -- the way surfacefun seeds a run. lam3
21% is its wavelength; the draw is seeded on the host, the sum over its
22% Fourier modes runs on the GPU (src/mgpu/randnfun3.ts).
23function [U, V, u, v] = init(lam3, gx, gy, gz, a, b)
24 f = randnfun3(lam3, gx, gy, gz);
26 vs = b / (us * us);
0ae15cfSeed runs from smooth random fields, and add the blob geometryDan Fortunato 27 [U, V] = analys(us + 0.01*f, vs * ones(numel(f), 1));
a4fee9cBatch independent transforms through one Legendre dispatchDan Fortunato 28 [u, v] = synth(U, V);
e4d6a3bPrecondition with the operator's symbol; project the correction onto the bandDan Fortunato 31function [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 32 % Grouped transforms -- [a, b] = synth(x, y) -- are explicit batching:
33 % output k is the transform of input k, and the whole group runs as one
34 % batched Legendre dispatch, or as many as the device's lane width allows
35 % (src/mgpu/plan.ts, materializeTransforms). The grouping is a promise of
36 % independence, never of a lane width, so the same source runs anywhere.
37 [u, v] = synth(U, V);
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 38 uuv = u .* u .* v;
62e6cc4Simplify UI text and built-in .m script commentsJeremy Magland 40 % Right-hand side of the implicit solve (I - dt*D*lap_g) Unew = B.
42 rv = b - uuv;
43 [Ru, Rv] = analys(ru, rv);
44 Bu = U + dt * Ru;
45 Bv = V + dt * Rv;
e4d6a3bPrecondition with the operator's symbol; project the correction onto the bandDan Fortunato 47 % Preconditioned solve, then iterate the geometric correction. jhat is
48 % the host's minimax scale over the operator's symbol eigenvalues mu(x)
49 % -- the inverse squared principal stretches of the embedding, direction
50 % included (src/geom/geometry.ts, Jhat): preconditioning with lam/jhat
51 % contracts every mode and direction at rate
52 % (muMax - muMin)/(muMax + muMin) < 1 on any surface, where the plain
53 % lam (jhat = 1) diverges wherever mu > 2 -- docs/reduced-transforms.md
54 % Sec 10. The answer never depends on jhat (the lamJ term added inside
55 % dLu is the term divided back out); only the convergence rate does. On
56 % the sphere mu = 1 and lamJ = lam.
57 lamJ = lam ./ jhat;
58 Un = Bu ./ (1 + (dt * D1) * lamJ);
59 Vn = Bv ./ (1 + (dt * D2) * lamJ);
61 for k = 1:niter
591a4f5Reduce the Laplace-Beltrami matvec to 6 transforms per species per iterationDan Fortunato 62 % dlap = lap_g - lap_s at the current iterate, in flux form
a4fee9cBatch independent transforms through one Legendre dispatchDan Fortunato 63 % (docs/reduced-transforms.md Sec 4). The sin-weighted derivatives
64 % sin(theta)*dtheta(u) and dphi(u) -- both smooth on the sphere,
65 % synthesized straight from the dthetac/dphic coefficient shuffles --
66 % are combined pointwise through the precomputed weights p1,p2,q2 into
0d99c91Differentiate the phi flux in grid spaceDan Fortunato 67 % two fluxes P,Q, also smooth. The theta flux P goes back to
68 % coefficients, through the same shuffle again, and is synthesized as
69 % sin(theta)*dtheta(P); the phi flux Q never leaves the grid -- d/dphi
70 % is diagonal in the Fourier index, so dphig differentiates it with two
71 % FFT stages and no Legendre work (masking m past filt's reach). Their
72 % sum, scaled by r, is lap_g(u). The only division by sin(theta)
73 % anywhere is folded into p1,p2,q2,r at precompute time.
e4d6a3bPrecondition with the operator's symbol; project the correction onto the bandDan Fortunato 74 % lamJ.*Un adds back the preconditioner's -lap_s(Un)/jhat, since lam
75 % holds +l(l+1). filt zeroes the top two degrees, where the derivative
76 % recurrences cannot exactly represent a derivative -- and the correction
77 % itself is projected onto the same band (algos.tex Algorithm 5 zeroes
78 % the same coefficients): without that, each iteration replaces a bit
79 % more of the top degrees' implicit diffusion with nothing (their fixed
80 % point is the undiffused Bu), and the two species un-diffuse at
81 % different rates -- a spurious Turing band at the band edge.
83 % The two species share each grouped call: the four gradient
0d99c91Differentiate the phi flux in grid spaceDan Fortunato 84 % syntheses, the two theta-flux analyses, the two divergence syntheses
85 % and the two final analyses each run as one batched dispatch.
88 vtu = dthetac(Fu);
89 vpu = dphic(Fu);
90 vtv = dthetac(Fv);
91 vpv = dphic(Fv);
92 [Ftu, Fpu, Ftv, Fpv] = synth(vtu, vpu, vtv, vpv);
94 Qu = p2 .* Ftu + q2 .* Fpu;
95 Pv = p1 .* Ftv + p2 .* Fpv;
96 Qv = p2 .* Ftv + q2 .* Fpv;
0d99c91Differentiate the phi flux in grid spaceDan Fortunato 97 [PAu, PAv] = analys(Pu, Pv);
99 Pcv = PAv .* filt;
0d99c91Differentiate the phi flux in grid spaceDan Fortunato 100 scu = dthetac(Pcu);
101 scv = dthetac(Pcv);
a4fee9cBatch independent transforms through one Legendre dispatchDan Fortunato 102 [Lu, Lv] = synth(scu, scv);
0d99c91Differentiate the phi flux in grid spaceDan Fortunato 103 dQu = dphig(Qu);
104 dQv = dphig(Qv);
105 lapu = r .* (Lu + dQu);
106 lapv = r .* (Lv + dQv);
a4fee9cBatch independent transforms through one Legendre dispatchDan Fortunato 107 [LAu, LAv] = analys(lapu, lapv);
e4d6a3bPrecondition with the operator's symbol; project the correction onto the bandDan Fortunato 108 dLu = (LAu + lamJ .* Un) .* filt;
109 dLv = (LAv + lamJ .* Vn) .* filt;
e4d6a3bPrecondition with the operator's symbol; project the correction onto the bandDan Fortunato 111 Un = (Bu + (dt * D1) * dLu) ./ (1 + (dt * D1) * lamJ);
112 Vn = (Bv + (dt * D2) * dLv) ./ (1 + (dt * D2) * lamJ);
114end
moveopenescclose