/ proof-of-concept / steelsim21
Sign in
proof-of-concept / steelsim21
steelsim21 / matching / modes.ts
47 lines · 2.4 KBBlameHistoryRaw
1// Linearized mode frequencies of the simulated sheet (with its initial bow), for
2// comparing the model's partials with a recording without running the simulator.
3//
4// Usage: node modes.ts OUT.bin [key=value ...]
5// Writes the mass-symmetrized stiffness of all three displacement fields over the
6// nodes of the sheet as float64, and prints JSON with the degrees of freedom and the
7// grid; eigenvalues are then omega^2 (see modes.py).
8import { writeFileSync } from "node:fs";
9import { accelerations, type Fields } from "../src/sim/cpuRef.ts";
10import { defaultParams, initialShape, makeGrid, makeMaterial, nodeWeight, type PhysParams } from "../src/params.ts";
12const out = process.argv[2];
13const p: PhysParams = { ...defaultParams };
14for (const a of process.argv.slice(3)) {
15 const [k, v] = a.split("=");
16 const d = (p as unknown as Record<string, unknown>)[k];
17 (p as unknown as Record<string, unknown>)[k] = typeof d === "number" ? parseFloat(v) : v;
19const g = makeGrid(p);
20const m = makeMaterial(p);
21const w0 = Float64Array.from(initialShape(p, g));
22const nodes: number[] = [];
23for (let k = 0; k < g.n; k++) if (nodeWeight(g, k % g.nx, Math.floor(k / g.nx)) > 0) nodes.push(k);
24const N = nodes.length;
25const n = 3 * N;
26const mass = (d: number) => m.rhoh * g.hx * g.hy * nodeWeight(g, nodes[d % N] % g.nx, Math.floor(nodes[d % N] / g.nx));
27const x: Fields = { u: new Float64Array(g.n), v: new Float64Array(g.n), w: new Float64Array(g.n) };
28const y: Fields = { u: new Float64Array(g.n), v: new Float64Array(g.n), w: new Float64Array(g.n) };
29const y0: Fields = { u: new Float64Array(g.n), v: new Float64Array(g.n), w: new Float64Array(g.n) };
30accelerations(g, m, x, y0, w0); // rest state (zero for a stress-free bow)
31const eps = 1e-9;
32const K = new Float64Array(n * n);
33const arr = (f: Fields, c: number) => (c === 0 ? f.u : c === 1 ? f.v : f.w);
34for (let col = 0; col < n; col++) {
35 const c = Math.floor(col / N), k = nodes[col % N];
36 arr(x, c)[k] = eps;
37 accelerations(g, m, x, y, w0);
38 arr(x, c)[k] = 0;
39 const sc = Math.sqrt(1 / mass(col)) / eps;
40 for (let row = 0; row < n; row++) {
41 const rc = Math.floor(row / N), rk = nodes[row % N];
42 const acc = arr(y, rc)[rk] - arr(y0, rc)[rk];
43 K[row * n + col] = -acc * Math.sqrt(mass(row)) * sc;
44 }
46writeFileSync(out, Buffer.from(K.buffer));
47console.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 } }));
↑↓ move↵openescclose