// The only .m file the simulator puts in scope of a design script. It is not // a design helper: the trailer that evaluatePlate appends calls it to sample // a field (a number or a function handle) on the grid matrices, or the decay // time on a row of frequencies, and to report a bad return value in the // script's own terms. Design scripts define whatever shape functions they // need themselves, at the bottom of the script. import type { WorkspaceFile } from "numbl"; const SAMPLE = `function v = cymbalsim_field(f, what, x, y, r, theta) % Samples a design field (a number or a function handle) on the grid matrices. if isa(f, 'function_handle') try v = f(x, y, r, theta); catch e error('%s: %s', what, e.message); end elseif isnumeric(f) || islogical(f) v = f; else error('%s must be a number or a function handle @(x, y, r, theta)', what); end if isscalar(v) v = double(v) * ones(size(x)); elseif ~isequal(size(v), size(x)) 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)); else v = double(v); end end `; const T60 = `function v = cymbalsim_t60(f, freqs) % Samples the decay time on a row of frequencies when it is a function handle. try v = f(freqs); catch e error('design.loss.T60: %s', e.message); end if isscalar(v) v = double(v) * ones(size(freqs)); elseif numel(v) ~= numel(freqs) error('design.loss.T60 returned %d values for %d frequencies; use elementwise operators (./, .^)', numel(v), numel(freqs)); else v = double(v); end end `; export const RUNTIME_FILES: WorkspaceFile[] = [ { name: "cymbalsim_field.m", source: SAMPLE }, { name: "cymbalsim_t60.m", source: T60 }, ];