1// The only .m file the simulator puts in scope of a design script. It is not
2// a design helper: evaluatePlate's trailer calls it to sample a field (a
3// number or a function handle) on the grid matrices and to report a bad
4// return value in the script's own terms. Design scripts define whatever
5// shape functions they need themselves, at the bottom of the script.
7import type { WorkspaceFile } from "numbl";
9const SAMPLE = `function v = steelsim_field(f, what, x, y, r, theta)
10% Samples a design field (a number or a function handle) on the grid matrices.
11if isa(f, 'function_handle')
12 try
13 v = f(x, y, r, theta);
14 catch e
15 error('%s: %s', what, e.message);
16 end
17elseif isnumeric(f) || islogical(f)
18 v = f;
19else
20 error('%s must be a number or a function handle @(x, y, r, theta)', what);
21end
22if isscalar(v)
23 v = double(v) * ones(size(x));
24elseif ~isequal(size(v), size(x))
25 error('%s returned a %d x %d array for a %d x %d grid; use elementwise operators (.*, ./, .^)', what, size(v, 1), size(v, 2), size(x, 1), size(x, 2));
26else
27 v = double(v);
28end
29end
30`;
32export const RUNTIME_FILES: WorkspaceFile[] = [{ name: "steelsim_field.m", source: SAMPLE }];