1// The solver and problem sources, inlined into the bundle by vite. Used by
2// the worker (which needs the MATLAB text to run a numbl solver) and by the
3// problem page's source listing, which also shows the TypeScript and WGSL
4// of a WebGPU solver. The node CLI reads the same files from disk.
6import { getSolver, solverFiles, solverSourceDir } from "../solvers";
8const files = {
9 ...(import.meta.glob("../{problems,solvers}/**/*.m", {
10 query: "?raw",
11 import: "default",
12 eager: true,
13 }) as Record<string, string>),
14 // Only a WebGPU solver's own directory, not the registry modules that sit
15 // one level up.
16 ...(import.meta.glob("../solvers/*/*.ts", {
17 query: "?raw",
18 import: "default",
19 eager: true,
20 }) as Record<string, string>),
21};
23function get(path: string): string {
24 const src = files[path];
25 if (!src) throw new Error(`missing solver source: ${path}`);
26 return src;
27}
29export function matlabBase() {
30 return {
31 buildProblem: get("../problems/laplace2d/matlab/build_problem.m"),
32 bdata: get("../problems/laplace2d/matlab/laplace2d_bdata.m"),
33 };
34}
36/** The solver.m of a registry solver, resolved through its manifest so
37 * that entries sharing a file (mfs and mfs-mat) read the one source. */
38export function solverSource(solverId: string): string {
39 return get(`../solvers/${solverSourceDir(getSolver(solverId))}/solver.m`);
40}
42/** Every source file of a solver, named, for the page's listing. */
43export function solverSourceFiles(
44 solverId: string
45): { name: string; code: string }[] {
46 return solverFiles(getSolver(solverId)).map((f) => ({
47 name: f.split("/").pop() as string,
48 code: get(`../solvers/${f}`),
49 }));
50}