import { SCENARIO_PRESETS } from "./presets"; import type { MethodId, ProblemSpec } from "./types"; /** The default problem: the reference centre hit. */ export function defaultSpec(): ProblemSpec { return cloneSpec(SCENARIO_PRESETS[0].spec); } /** Deep-copy a spec (specs are plain data). */ export function cloneSpec(spec: ProblemSpec): ProblemSpec { return JSON.parse(JSON.stringify(spec)) as ProblemSpec; } /** * The part of the spec the modes stage depends on: the plate, the elastic * constants, the hole, the thread's length (its spring), the sample rate * (the 0.47 fs cutoff), the mode cap and the method's numerics. Two specs * with the same key have the same modes, so the host reuses them and runs * only the strike stage. The material's Q, the dashpot, the hammer, the * strike point, the probe, the microphone and the rest of the render * settings belong to the strike stage. */ export function modesKey(spec: ProblemSpec, method: MethodId): string { const { plate, material, hole, thread, render } = spec; return JSON.stringify({ method, plate, E: material.E, nu: material.nu, rho: material.rho, hole, length: thread.length, fs: render.fs, modes: render.modes, numerics: method === "rr" ? spec.rr : spec.fem, }); }