/ concept-collection / turing-sphere-2
Sign in
concept-collection / turing-sphere-2
turing-sphere-2 / scripts / longrun-node.ts
43 lines · 1.5 KBBlameHistoryRaw
1/**
2 * Long-run sanity check (CPU f64, lmax 31): run Schnakenberg to t = 100 and
3 * confirm the pattern saturates into O(1)-contrast spots rather than decaying
4 * or blowing up. Run: node scripts/longrun-node.ts
5 */
6import { CpuBackend } from '../src/solver/backend.ts';
7import { Simulation, gridForLmax } from '../src/solver/simulation.ts';
8import { models, defaultParams } from '../src/solver/models.ts';
10const schnak = models[0];
11const params = defaultParams(schnak);
12const lmax = 31;
13const { nlat, nphi } = gridForLmax(lmax, schnak.pdeg);
14const backend = new CpuBackend({ lmax, mmax: lmax, nlat, nphi });
15const sim = new Simulation(backend, schnak, params);
16await sim.init(1);
18const nsteps = Math.round(100 / params.dt);
19const t0 = performance.now();
20for (let s = 0; s < nsteps; s++) {
21 await sim.step();
22 if ((s + 1) % 400 === 0) {
23 let lo = Infinity, hi = -Infinity;
24 for (const v of sim.V[0]) {
25 if (v < lo) lo = v;
26 if (v > hi) hi = v;
27 }
28 console.log(
29 `t=${sim.t.toFixed(1).padStart(5)} u in [${lo.toFixed(4)}, ${hi.toFixed(4)}] ` +
30 `contrast ${(hi - lo).toFixed(4)}`,
31 );
32 }
34console.log(`${((performance.now() - t0) / nsteps).toFixed(1)} ms/step CPU`);
36let lo = Infinity, hi = -Infinity;
37for (const v of sim.V[0]) {
38 if (v < lo) lo = v;
39 if (v > hi) hi = v;
41const ok = Number.isFinite(lo) && hi - lo > 0.3 && hi - lo < 5;
42console.log(ok ? 'PASS: saturated O(1) pattern' : 'FAIL: no saturated pattern');
43process.exit(ok ? 0 : 1);
moveopenescclose