// Linearized mode frequencies of the simulated sheet (with its initial bow), for // comparing the model's partials with a recording without running the simulator. // // Usage: node modes.ts OUT.bin [key=value ...] // Writes the mass-symmetrized stiffness of all three displacement fields over the // nodes of the sheet as float64, and prints JSON with the degrees of freedom and the // grid; eigenvalues are then omega^2 (see modes.py). import { writeFileSync } from "node:fs"; import { accelerations, type Fields } from "../src/sim/cpuRef.ts"; import { defaultParams, initialShape, makeGrid, makeMaterial, nodeWeight, type PhysParams } from "../src/params.ts"; const out = process.argv[2]; const p: PhysParams = { ...defaultParams }; for (const a of process.argv.slice(3)) { const [k, v] = a.split("="); const d = (p as unknown as Record)[k]; (p as unknown as Record)[k] = typeof d === "number" ? parseFloat(v) : v; } const g = makeGrid(p); const m = makeMaterial(p); const w0 = Float64Array.from(initialShape(p, g)); const nodes: number[] = []; for (let k = 0; k < g.n; k++) if (nodeWeight(g, k % g.nx, Math.floor(k / g.nx)) > 0) nodes.push(k); const N = nodes.length; const n = 3 * N; const mass = (d: number) => m.rhoh * g.hx * g.hy * nodeWeight(g, nodes[d % N] % g.nx, Math.floor(nodes[d % N] / g.nx)); const x: Fields = { u: new Float64Array(g.n), v: new Float64Array(g.n), w: new Float64Array(g.n) }; const y: Fields = { u: new Float64Array(g.n), v: new Float64Array(g.n), w: new Float64Array(g.n) }; const y0: Fields = { u: new Float64Array(g.n), v: new Float64Array(g.n), w: new Float64Array(g.n) }; accelerations(g, m, x, y0, w0); // rest state (zero for a stress-free bow) const eps = 1e-9; const K = new Float64Array(n * n); const arr = (f: Fields, c: number) => (c === 0 ? f.u : c === 1 ? f.v : f.w); for (let col = 0; col < n; col++) { const c = Math.floor(col / N), k = nodes[col % N]; arr(x, c)[k] = eps; accelerations(g, m, x, y, w0); arr(x, c)[k] = 0; const sc = Math.sqrt(1 / mass(col)) / eps; for (let row = 0; row < n; row++) { const rc = Math.floor(row / N), rk = nodes[row % N]; const acc = arr(y, rc)[rk] - arr(y0, rc)[rk]; K[row * n + col] = -acc * Math.sqrt(mass(row)) * sc; } } writeFileSync(out, Buffer.from(K.buffer)); console.log(JSON.stringify({ n, N, nx: g.nx, ny: g.ny, params: { E: p.E, nu: p.nu, rho: p.rho, h: p.h, bowShape: p.bowShape, bowAmplitude: p.bowAmplitude, spacing: p.spacing } }));