/ concept-collection / turing-surface-cache
Sign in
concept-collection / turing-surface-cache
turing-surface-cache / src / mgpu / registry.ts
83 lines · 2.9 KBCodeBlameHistory
2 * The available models: their MATLAB source, and the metadata the host owns.
3 *
4 * A model's *algorithm* lives in its .m file. Everything around it lives here:
5 * the parameter names the .m may take as arguments, their defaults and slider
6 * ranges, which grid fields to render, and the dealiasing degree. The .m
7 * declares nothing about these — it just names the parameters it wants, and
8 * `CompiledModel` matches each against this table.
9 *
10 * Trimmed from turing-surface: this app ships one model (Schnakenberg, flux
11 * form). The discrete parameter choices the app actually offers live in
12 * src/cache/options.ts; the min/max/step here are only the numeric bounds.
13 *
14 * Naming convention, documented in each .m:
15 * `u`, `v`, ... grid fields the model computes and the app renders
16 * `U`, `V`, ... the corresponding spectral state (uppercase)
17 */
18import schnakenbergSource from '../../models/schnakenberg.m?raw';
20export type Params = Record<string, number>;
22/** A tunable scalar the .m may take as an argument. */
23export interface ParamSpec {
24 key: string;
25 label: string;
26 value: number;
27 min: number;
28 max: number;
29 step: number;
30 /**
31 * This parameter is a random seed: its value picks a draw and means nothing
32 * on its own, so the UI offers a button that jumps to another one rather
33 * than a box to type a number into. `min`/`max` still bound what the button
34 * picks.
35 */
36 reseed?: boolean;
39export interface MModel {
40 key: string;
41 label: string;
42 blurb: string;
43 /** Grid fields to render, one panel each. */
44 species: string[];
45 /** Spectral state names the .m advances. */
46 state: string[];
47 params: ParamSpec[];
48 /** Polynomial degree of the reaction in the fields, for grid dealiasing. */
49 pdeg: number;
50 /** Amplitude of the seeded perturbation handed to `init`. */
51 seedAmp: number;
52 /** MATLAB source — the algorithm itself. */
53 source: string;
56/** Spectral state names follow the grid-field names, uppercased. */
57const stateFor = (species: string[]): string[] => species.map((s) => s.toUpperCase());
59const schnakenberg: MModel = {
60 key: 'schnakenberg',
61 label: 'Schnakenberg',
62 blurb: 'Turing spots.',
63 species: ['u', 'v'],
64 state: stateFor(['u', 'v']),
65 params: [
66 { key: 'a', label: 'a', value: 0.1, min: 0.01, max: 0.5, step: 0.01 },
67 { key: 'b', label: 'b', value: 0.9, min: 0.1, max: 2, step: 0.05 },
68 { key: 'D1', label: 'D₁', value: 4e-4, min: 1e-5, max: 5e-3, step: 1e-5 },
69 { key: 'D2', label: 'D₂', value: 8e-3, min: 1e-4, max: 5e-2, step: 1e-4 },
70 { key: 'dt', label: 'dt', value: 0.05, min: 0.005, max: 0.5, step: 0.005 },
71 ],
72 pdeg: 3,
73 seedAmp: 1e-2,
74 source: schnakenbergSource,
75};
77export const mModels: MModel[] = [schnakenberg];
79export const mModelByKey = (key: string): MModel | undefined =>
80 mModels.find((m) => m.key === key);
82export const defaultParams = (m: MModel): Params =>
83 Object.fromEntries(m.params.map((p) => [p.key, p.value]));
moveopenescclose