28f8ec1mesh-pde-solver: upload a quad mesh, solve PDEs on the surface in-browserJeremy Magland 1# CLAUDE.md
3Tips for future agents working in this repo.
5## Architecture
7```
f4de30dSimplify the solver to run-per-solve; drop the uihtml event bridgeJeremy Magland 8matlab/ the MATLAB project each solve runs standalone
9 main.m `mip load --install surfacefun` -> jsondecode params.json
10 -> solve_pde('mesh.msh', params) -> write result.json
43c610bUse surfacemesh.import instead of the hand-rolled mesh readersJeremy Magland 11 solve_pde.m surfacemesh.import -> resample -> surfaceop -> per-patch data
28f8ec1mesh-pde-solver: upload a quad mesh, solve PDEs on the surface in-browserJeremy Magland 12src/mesh/ Pyodide + meshio upload pipeline (bridge.py runs in Pyodide)
f4de30dSimplify the solver to run-per-solve; drop the uihtml event bridgeJeremy Magland 13src/engine/ run-per-solve wrapper over numbl/browser's
14 createNumblSession: solve() boots a fresh session with
15 mesh.msh + params.json staged, reads result.json back via
16 session.readFile, and disposes the worker. numbl owns the
17 worker, VFS, mip bootstrap, and IndexedDB package
18 persistence; prewarm() at page load triggers the one-time
19 package download.
3cc1e4cSupport triangle meshes; view-mode toolbar; drop upload size capJeremy Magland 20src/pde/presets.ts PDE definitions, presets, slow-mesh warning threshold
28f8ec1mesh-pde-solver: upload a quad mesh, solve PDEs on the surface in-browserJeremy Magland 21src/render/ three.js SurfaceView (mesh preview / solution) + parula
22scripts/engine-test.mjs headless Node check of the whole MATLAB pipeline
23```
25## Key gotchas
3cc1e4cSupport triangle meshes; view-mode toolbar; drop upload size capJeremy Magland 27- **numbl >= 0.4.12 from npm.** Needs `NumblSession.readFile` (0.4.10),
43c610bUse surfacemesh.import instead of the hand-rolled mesh readersJeremy Magland 28 enumeration-class support and the 1×1-tensor broadcast-assignment fix
29 (0.4.11 — surfacefun's `surfacemesh.patchtype` / `dealm` idiom depend on
3cc1e4cSupport triangle meshes; view-mode toolbar; drop upload size capJeremy Magland 30 both), and the 1×1-tensor gather-orientation fix (0.4.12 — surfacefun's
31 `trianglepts` recursion breaks without it; see numbl's
32 `test_scalar_tensor_vector_index_shape.m`). To develop against a local
33 numbl checkout, point package.json at
43c610bUse surfacemesh.import instead of the hand-rolled mesh readersJeremy Magland 34 `file:../../numbl` and run `npm run build:lib && npm run build:browser`
35 there after source changes; when switching back to a `^` range,
36 `rm -rf node_modules package-lock.json && npm install` (else `npm ci` fails
37 on the stale `file:` link).
3cc1e4cSupport triangle meshes; view-mode toolbar; drop upload size capJeremy Magland 38- **surfacemesh.import needs MSH 4.1, one cell type.** surfacefun's gmsh
39 reader (`+surfacemesh/+import/gmsh.m`) parses MSH 4.1 node-entity blocks,
40 not 2.2, and accepts triangle (type 2) or quad (type 3) elements — but
41 errors on meshes containing both. `src/mesh/bridge.py` and
42 `scripts/make_samples.py` write the canonical 4.1 form (one surface entity
43 block, sequential 1-based ids); the bridge splits quads into triangles
44 when an upload mixes the two kinds. Uploaded .msh files in other layouts
45 pass through meshio and get rewritten to 4.1.
46- **Triangle patches are flat vectors, not grids.** An order-p tri patch
47 holds n(n+1)/2 points (n = p+1) in surfacefun's `trianglepts(n)` ordering;
48 quad patches are column-major n-by-n grids. `solve_pde.m` reports `ptype`
49 plus points-per-edge `n`, and SurfaceView triangulates tri patches with a
50 JS port of surfacefun's `trilattice.m`.
f4de30dSimplify the solver to run-per-solve; drop the uihtml event bridgeJeremy Magland 51- **Solve errors reject the solve() promise** with the MATLAB error message
52 (a failed script run is a numbl bootError). Each solve is a fresh session,
53 so nothing needs to stay alive across failures.
28f8ec1mesh-pde-solver: upload a quad mesh, solve PDEs on the surface in-browserJeremy Magland 54- **jsonencode collapses 1-element vectors to scalars.** Patch arrays are
3cc1e4cSupport triangle meshes; view-mode toolbar; drop upload size capJeremy Magland 55 at least (p+1)(p+2)/2 >= 6 long so it never bites here, but remember it
56 when adding payload fields.
28f8ec1mesh-pde-solver: upload a quad mesh, solve PDEs on the surface in-browserJeremy Magland 57- Package caching: numbl/browser persists /system (mip + installed
43c610bUse surfacemesh.import instead of the hand-rolled mesh readersJeremy Magland 58 packages) in IndexedDB, wiped after 30 min of inactivity (numbl's default;
59 lowered from 24 h so a rebuilt surfacefun package refreshes without a manual
60 clear) — the prewarm session at page load re-downloads ~28 MB after a wipe;
61 solves after that only pay a per-run `mip load` (~1 s). Delete the
62 `numbl-embed-system` IndexedDB database to force a cold boot.
64## Testing
66- `npm run engine-test` — full headless solve in Node against the local
67 numbl build (dist-lib), including a quantitative eigenfunction check. It
f4de30dSimplify the solver to run-per-solve; drop the uihtml event bridgeJeremy Magland 68 runs matlab/main.m standalone per solve (as the browser does), sharing
69 one VFS across solves as the stand-in for IndexedDB persistence, and
28f8ec1mesh-pde-solver: upload a quad mesh, solve PDEs on the surface in-browserJeremy Magland 70 passes the mip search path explicitly, exercising the same
71 searchPaths-scan behavior the numbl/browser session relies on. Downloads
72 are cached in `.cache/` keyed by URL; delete the cache to test fresh
73 installs.
74- `python3 <venv>/bin/python` with meshio 5.3.5 can exercise
75 `src/mesh/bridge.py` outside Pyodide (redirect its `/work` constant).
76- Browser verification (Pyodide upload path, session boot, IndexedDB
77 persistence across reloads, 3D view) is manual: `npm run dev`.