/ proof-of-concept / plate-dynamics-lab-2
Sign in
proof-of-concept / plate-dynamics-lab-2
plate-dynamics-lab-2 / packages / core / src / spec / defaults.ts
37 lines · 1.3 KBBlameHistoryRaw
1import { SCENARIO_PRESETS } from "./presets";
2import type { MethodId, ProblemSpec } from "./types";
4/** The default problem: the reference centre hit. */
5export function defaultSpec(): ProblemSpec {
6 return cloneSpec(SCENARIO_PRESETS[0].spec);
7}
9/** Deep-copy a spec (specs are plain data). */
10export function cloneSpec(spec: ProblemSpec): ProblemSpec {
11 return JSON.parse(JSON.stringify(spec)) as ProblemSpec;
14/**
15 * The part of the spec the modes stage depends on: the plate, the elastic
16 * constants, the hole, the thread's length (its spring), the sample rate
17 * (the 0.47 fs cutoff), the mode cap and the method's numerics. Two specs
18 * with the same key have the same modes, so the host reuses them and runs
19 * only the strike stage. The material's Q, the dashpot, the hammer, the
20 * strike point, the probe, the microphone and the rest of the render
21 * settings belong to the strike stage.
22 */
23export function modesKey(spec: ProblemSpec, method: MethodId): string {
24 const { plate, material, hole, thread, render } = spec;
25 return JSON.stringify({
26 method,
27 plate,
28 E: material.E,
29 nu: material.nu,
30 rho: material.rho,
31 hole,
32 length: thread.length,
33 fs: render.fs,
34 modes: render.modes,
35 numerics: method === "rr" ? spec.rr : spec.fem,
36 });
↑↓ move↵openescclose