/ forks / turing-surface
Sign in
forks / turing-surface
forked from github.com/concept-collection/turing-surface
144 lines · 4.9 KBCodeBlameHistory
2 * The available geometries: their MATLAB source, and the metadata the host owns.
3 *
4 * The same split as the model registry — the .m is the shape, everything around
5 * it (parameter names, defaults, slider ranges) lives here, and the .m declares
6 * which of them it wants by naming them as arguments.
7 *
8 * `sphere` is first and is not merely one entry among several: it is the case
9 * the whole project is checked against, where the surface is exactly the unit
10 * sphere and every result must match turing-sphere.
11 */
12import sphereSource from '../../geometries/sphere.m?raw';
13import ellipsoidSource from '../../geometries/ellipsoid.m?raw';
14import peanutSource from '../../geometries/peanut.m?raw';
15import bumpySource from '../../geometries/bumpy.m?raw';
0ae15cfSeed runs from smooth random fields, and add the blob geometryDan Fortunato 16import blobSource from '../../geometries/blob.m?raw';
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 17import type { ParamSpec, Params } from '../mgpu/registry.ts';
19export interface MGeometry {
20 key: string;
21 label: string;
22 blurb: string;
23 params: ParamSpec[];
24 /** MATLAB source — the shape itself. */
25 source: string;
27 * When set, the shape IS these spherical-harmonic coefficients and `source`
28 * is a display-only stub: Geometry.create re-indexes them onto the session's
29 * band instead of evaluating any .m. How a surface handed over by another
30 * app (reharm's "Export to turing-surface") enters the pipeline.
31 */
32 coeffs?: ImportedCoeffs;
35/** A surface as coefficients of x, y, z — the same three arrays a reference
36 * file's /geometry group holds, in the shared SHTNS layout (src/sht/layout.ts). */
37export interface ImportedCoeffs {
38 lmax: number;
39 mmax: number;
40 X: Float32Array;
41 Y: Float32Array;
42 Z: Float32Array;
45const sphere: MGeometry = {
46 key: 'sphere',
47 label: 'Sphere',
62e6cc4Simplify UI text and built-in .m script commentsJeremy Magland 48 blurb: 'The unit sphere — the reference case.',
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 49 params: [],
50 source: sphereSource,
51};
53const ellipsoid: MGeometry = {
54 key: 'ellipsoid',
55 label: 'Ellipsoid',
62e6cc4Simplify UI text and built-in .m script commentsJeremy Magland 56 blurb: 'The sphere with each axis scaled independently.',
58 { key: 'ax', label: 'a', value: 1.5, min: 0.2, max: 3, step: 0.05 },
59 { key: 'ay', label: 'b', value: 1, min: 0.2, max: 3, step: 0.05 },
60 { key: 'az', label: 'c', value: 0.6, min: 0.2, max: 3, step: 0.05 },
61 ],
62 source: ellipsoidSource,
63};
65const peanut: MGeometry = {
66 key: 'peanut',
67 label: 'Peanut',
62e6cc4Simplify UI text and built-in .m script commentsJeremy Magland 68 blurb: 'A dumbbell pinched at the equator.',
70 { key: 'waist', label: 'waist', value: 0.6, min: 0, max: 0.9, step: 0.05 },
71 { key: 'stretch', label: 'stretch', value: 0.6, min: 0, max: 2, step: 0.05 },
72 ],
73 source: peanutSource,
74};
76const bumpy: MGeometry = {
77 key: 'bumpy',
78 label: 'Bumpy',
62e6cc4Simplify UI text and built-in .m script commentsJeremy Magland 79 blurb: 'Equatorial lobes plus a pear-shaped offset.',
81 { key: 'amp', label: 'amp', value: 0.3, min: 0, max: 0.6, step: 0.02 },
82 { key: 'nlobe', label: 'lobes', value: 5, min: 1, max: 12, step: 1 },
83 { key: 'pear', label: 'pear', value: 0.15, min: -0.4, max: 0.4, step: 0.05 },
84 ],
85 source: bumpySource,
86};
0ae15cfSeed runs from smooth random fields, and add the blob geometryDan Fortunato 88const blob: MGeometry = {
89 key: 'blob',
90 label: 'Blob',
91 blurb: 'The sphere warped by a smooth random function — a fresh shape per seed.',
92 params: [
93 { key: 'amp', label: 'amp', value: 0.5, min: 0, max: 0.8, step: 0.05 },
94 { key: 'scale', label: 'λ', value: 1, min: 0.5, max: 3, step: 0.1 },
95 { key: 'seed', label: 'seed', value: 1, min: 0, max: 9999, step: 1, reseed: true },
96 ],
97 source: blobSource,
98};
100export const mGeometries: MGeometry[] = [sphere, ellipsoid, peanut, bumpy, blob];
102export const mGeometryByKey = (key: string): MGeometry | undefined =>
103 mGeometries.find((g) => g.key === key);
105export const defaultGeometryParams = (g: MGeometry): Params =>
106 Object.fromEntries(g.params.map((p) => [p.key, p.value]));
108/** The geometry every result is checked against, and what a caller who names
109 * none gets: the case where the solver is exact. */
110export const SPHERE_KEY = 'sphere';
77f627eAccept a surface handed over as coefficients (reharm's export button)Dan Fortunato 112/** The dropdown key an imported surface lives under. Not in `mGeometries`:
113 * the entry exists only after an import arrives, and the page owns it. */
114export const IMPORTED_GEOMETRY_KEY = 'imported';
116/**
117 * Wrap a handed-over surface as a geometry the rest of the app can hold like
118 * any registry entry. No parameters — the shape is whatever the coefficients
119 * say — and the .m slot carries a note rather than code, since the import
120 * path in Geometry.create never evaluates it.
121 */
122export function makeImportedGeometry(
123 name: string,
124 blurb: string,
125 coeffs: ImportedCoeffs,
126): MGeometry {
127 return {
128 key: IMPORTED_GEOMETRY_KEY,
129 label: name,
130 blurb,
131 params: [],
132 source:
133 `% ${name}\n` +
134 `% This surface was handed over as spherical-harmonic coefficients\n` +
135 `% (lmax ${coeffs.lmax}), so there is no .m to edit: the solver uses the\n` +
136 `% coefficients directly, and edits here have no effect.\n`,
137 coeffs,
138 };
0af3386Reaction-diffusion on spherical-harmonic surfacesJeremy Magland 141/** What the app and the benchmark start on. Not the sphere: this project
142 * exists for the other shapes, and opening on the reference case would hide
143 * the one thing it adds. */
144export const DEFAULT_GEOMETRY_KEY = 'ellipsoid';
↑↓ move↵openescclose