/ concept-collection / turing-surface-cache
Sign in
concept-collection / turing-surface-cache
turing-surface-cache / src / geom / registry.ts
72 lines · 2.5 KBBlameHistoryRaw
1/**
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 type { ParamSpec, Params } from '../mgpu/registry.ts';
17export interface MGeometry {
18 key: string;
19 label: string;
20 blurb: string;
21 params: ParamSpec[];
22 /** MATLAB source — the shape itself. */
23 source: string;
26const sphere: MGeometry = {
27 key: 'sphere',
28 label: 'Sphere',
29 blurb: 'The unit sphere — the reference case.',
30 params: [],
31 source: sphereSource,
32};
34const ellipsoid: MGeometry = {
35 key: 'ellipsoid',
36 label: 'Ellipsoid',
37 blurb: 'The sphere with each axis scaled independently.',
38 params: [
39 { key: 'ax', label: 'a', value: 1.5, min: 0.2, max: 3, step: 0.05 },
40 { key: 'ay', label: 'b', value: 1, min: 0.2, max: 3, step: 0.05 },
41 { key: 'az', label: 'c', value: 0.6, min: 0.2, max: 3, step: 0.05 },
42 ],
43 source: ellipsoidSource,
44};
46const peanut: MGeometry = {
47 key: 'peanut',
48 label: 'Peanut',
49 blurb: 'A dumbbell pinched at the equator.',
50 params: [
51 { key: 'waist', label: 'waist', value: 0.6, min: 0, max: 0.9, step: 0.05 },
52 { key: 'stretch', label: 'stretch', value: 0.6, min: 0, max: 2, step: 0.05 },
53 ],
54 source: peanutSource,
55};
57export const mGeometries: MGeometry[] = [sphere, ellipsoid, peanut];
59export const mGeometryByKey = (key: string): MGeometry | undefined =>
60 mGeometries.find((g) => g.key === key);
62export const defaultGeometryParams = (g: MGeometry): Params =>
63 Object.fromEntries(g.params.map((p) => [p.key, p.value]));
65/** The geometry every result is checked against, and what a caller who names
66 * none gets: the case where the solver is exact. */
67export const SPHERE_KEY = 'sphere';
69/** What the app and the benchmark start on. Not the sphere: this project
70 * exists for the other shapes, and opening on the reference case would hide
71 * the one thing it adds. */
72export const DEFAULT_GEOMETRY_KEY = 'ellipsoid';
moveopenescclose