// Fast finite-element model of a free bar with a varying thickness profile: // - vertical bending: Timoshenko beam (2-node elements, w and rotation ψ, reduced shear // integration), shear modulus G_LR, rotary inertia included; // - torsion: Saint-Venant, with the torsion constant of an orthotropic rectangle. // Eigenvalues come from Sturm-sequence bisection on banded LDLᵀ factors and eigenvectors // from inverse iteration, so asking for a few modes costs well under a millisecond. import { thickness, woodStiffness, AIR } from './bar.js'; const KAPPA = 5 / 6; export const NE = 160; // elements along the length // ---------- banded symmetric matrices (upper band, row-major, width b+1) ---------- function band(n, b) { return { n, b, A: new Float64Array(n * (b + 1)) }; } function addSym(m, i, j, v) { // add v to (i,j) and (j,i) if (j < i) [i, j] = [j, i]; m.A[i * (m.b + 1) + (j - i)] += v; } // LDLᵀ of K - lam M. Fills L (band by column) and d; returns the number of negative pivots. function ldl(K, M, lam, L, d) { const { n, b } = K, w = b + 1; let neg = 0; for (let j = 0; j < n; j++) { let s = K.A[j * w] - lam * M.A[j * w]; for (let k = Math.max(0, j - b); k < j; k++) { const l = L[k * w + (j - k)]; s -= l * l * d[k]; } if (s === 0) s = 1e-300; d[j] = s; if (s < 0) neg++; const iMax = Math.min(n - 1, j + b); for (let i = j + 1; i <= iMax; i++) { let t = K.A[j * w + (i - j)] - lam * M.A[j * w + (i - j)]; for (let k = Math.max(0, i - b); k < j; k++) t -= L[k * w + (i - k)] * L[k * w + (j - k)] * d[k]; L[j * w + (i - j)] = t / s; } } return neg; } function ldlSolve(L, d, n, b, r) { const w = b + 1, x = Float64Array.from(r); for (let i = 0; i < n; i++) for (let k = Math.max(0, i - b); k < i; k++) x[i] -= L[k * w + (i - k)] * x[k]; for (let i = 0; i < n; i++) x[i] /= d[i]; for (let i = n - 1; i >= 0; i--) for (let k = i + 1; k <= Math.min(n - 1, i + b); k++) x[i] -= L[i * w + (k - i)] * x[k]; return x; } function bandMul(m, x) { const { n, b } = m, w = b + 1, y = new Float64Array(n); for (let i = 0; i < n; i++) { y[i] += m.A[i * w] * x[i]; for (let k = 1; k <= b && i + k < n; k++) { const v = m.A[i * w + k]; y[i] += v * x[i + k]; y[i + k] += v * x[i]; } } return y; } class Eig { constructor(K, M, nRigid) { this.K = K; this.M = M; this.nRigid = nRigid; this.L = new Float64Array(K.n * (K.b + 1)); this.d = new Float64Array(K.n); } count(lam) { return ldl(this.K, this.M, lam, this.L, this.d); } // m-th flexible eigenvalue (m = 1, 2, ...), by bisection value(m, guess) { const want = m + this.nRigid; let lo = 1, hi = guess > 0 ? guess * 1.5 : 1e6; while (this.count(hi) < want) { lo = hi; hi *= 4; } let cLo = this.count(lo); while (cLo >= want) { hi = lo; lo /= 4; cLo = this.count(lo); } for (let it = 0; it < 80 && hi / lo - 1 > 1e-11; it++) { const mid = Math.sqrt(lo * hi); if (this.count(mid) >= want) hi = mid; else lo = mid; } return Math.sqrt(lo * hi); } // mass-normalized eigenvector by inverse iteration vector(lam) { const { K, M } = this, n = K.n; let x = Float64Array.from({ length: n }, (_, i) => Math.sin(1.3 + 0.37 * i) + 0.5 * Math.cos(0.11 * i)); this.count(lam * (1 - 1e-9)); for (let it = 0; it < 4; it++) { x = ldlSolve(this.L, this.d, n, K.b, bandMul(M, x)); const mx = bandMul(M, x); let s = 0; for (let i = 0; i < n; i++) s += x[i] * mx[i]; s = 1 / Math.sqrt(s); for (let i = 0; i < n; i++) x[i] *= s; } return x; } } // ---------- assembly ---------- function sections(b, ne) { const le = (b.L * 1e-3) / ne, W = b.W * 1e-3; const out = []; for (let e = 0; e < ne; e++) { const h = thickness(b, ((e + 0.5) * b.L) / ne) * 1e-3; out.push({ le, A: W * h, I: (W * h ** 3) / 12, h, W }); } return out; } function bendingSystem(b, mat, ne) { const C = woodStiffness(mat.EL * 1e9); const n = 2 * (ne + 1); const K = band(n, 3), M = band(n, 3); for (const [e, s] of sections(b, ne).entries()) { const o = 2 * e, { le, A, I } = s; // bending on ψ const kb = (C.E * I) / le; addSym(K, o + 1, o + 1, kb); addSym(K, o + 3, o + 3, kb); addSym(K, o + 1, o + 3, -kb); // shear, one-point integration: γ = (w2-w1)/le - (ψ1+ψ2)/2 const B = [-1 / le, -0.5, 1 / le, -0.5], ks = KAPPA * C.gxz * A * le; for (let i = 0; i < 4; i++) for (let j = i; j < 4; j++) addSym(K, o + i, o + j, ks * B[i] * B[j]); // consistent mass: translation and rotary inertia const mt = (mat.rho * A * le) / 6, mr = (mat.rho * I * le) / 6; addSym(M, o, o, 2 * mt); addSym(M, o + 2, o + 2, 2 * mt); addSym(M, o, o + 2, mt); addSym(M, o + 1, o + 1, 2 * mr); addSym(M, o + 3, o + 3, 2 * mr); addSym(M, o + 1, o + 3, mr); } return new Eig(K, M, 2); } // Torsion constant of a b × t rectangle (isotropic), b ≥ t not required. function rectJ(b, t) { if (b < t) [b, t] = [t, b]; const r = t / b; return b * t ** 3 * (1 / 3 - 0.21 * r * (1 - r ** 4 / 12)); } function torsionSystem(b, mat, ne) { const C = woodStiffness(mat.EL * 1e9); const n = ne + 1; const K = band(n, 1), M = band(n, 1); // orthotropic: stretch the width by alpha = sqrt(G_LT / G_LR), isotropic with G_LT const alpha = Math.sqrt(C.gxy / C.gxz); for (const [e, s] of sections(b, ne).entries()) { const { le, h, W } = s; const GJ = alpha * C.gxy * rectJ(W / alpha, h); const Ip = (W * h * (W * W + h * h)) / 12; const k = GJ / le, m = (mat.rho * Ip * le) / 6; addSym(K, e, e, k); addSym(K, e + 1, e + 1, k); addSym(K, e, e + 1, -k); addSym(M, e, e, 2 * m); addSym(M, e + 1, e + 1, 2 * m); addSym(M, e, e + 1, m); } return new Eig(K, M, 1); } // First `count` vertical bending frequencies (Hz). Used by the tuner. export function bendFreqs(b, mat, count = 3, ne = NE) { const eig = bendingSystem(b, mat, ne); const out = []; let guess = 0; for (let m = 1; m <= count; m++) { const lam = eig.value(m, guess); out.push(Math.sqrt(lam) / (2 * Math.PI)); guess = lam * 4; } return out; } /** * All bending and torsion modes below fmax (Hz). * Returns [{ kind: 'B'|'T', idx, f, shape: Float64Array (nodal w (m/√kg) or twist (rad/√(kg·m²))) }] */ export function feModes(b, mat, { fmax = 24000, ne = NE } = {}) { const modes = []; for (const [kind, sys, stride] of [['B', bendingSystem(b, mat, ne), 2], ['T', torsionSystem(b, mat, ne), 1]]) { const lamMax = (2 * Math.PI * fmax) ** 2; const nFlex = sys.count(lamMax) - sys.nRigid; let guess = 0; for (let m = 1; m <= nFlex; m++) { const lam = sys.value(m, guess); guess = lam * 1.2; const v = sys.vector(lam); const shape = new Float64Array(ne + 1); for (let i = 0; i <= ne; i++) shape[i] = v[i * stride]; // sign: positive at the left end if (shape[0] < 0) for (let i = 0; i <= ne; i++) shape[i] = -shape[i]; modes.push({ kind, idx: m, f: Math.sqrt(lam) / (2 * Math.PI), shape }); } } modes.sort((p, q) => p.f - q.f); return modes; } // ---------- top-surface grid model, shared with the FDTD analysis ---------- /** * Sample FE modes on a grid of cells over the top face. Vertical displacement per unit * modal coordinate: bending w(x); torsion θ(x)·(y - W/2). * Returns a bar model: { source, design, nx, ny, modes: [{ f, label, sigRad, phi }] }. */ export function feBarModel(b, mat, opts = {}) { const ne = opts.ne ?? NE; const fe = feModes(b, mat, { fmax: opts.fmax ?? 24000, ne }); const nx = opts.nx ?? 120, ny = opts.ny ?? 8; const modes = fe.map((m) => { const phi = new Float32Array(nx * ny); for (let i = 0; i < nx; i++) { const u = ((i + 0.5) / nx) * ne, i0 = Math.min(ne - 1, Math.floor(u)), fu = u - i0; const s = m.shape[i0] * (1 - fu) + m.shape[i0 + 1] * fu; for (let j = 0; j < ny; j++) { const y = ((j + 0.5) / ny - 0.5) * b.W * 1e-3; phi[j * nx + i] = m.kind === 'B' ? s : s * y; } } return { f: m.f, label: `${m.kind}${m.idx}`, kind: m.kind, phi, sigRad: 0 }; }); const model = { source: 'FE', design: { ...b }, nx, ny, modes }; for (const m of model.modes) m.sigRad = dipoleRadDecay(model, m); // the f1 nodal lines (where the support cords go) const s = fe.find((m) => m.kind === 'B')?.shape; model.nodes = []; if (s) for (let i = 0; i < ne; i++) if (s[i] * s[i + 1] < 0) model.nodes.push(((i + s[i] / (s[i] - s[i + 1])) / ne) * b.L); return model; } // Cell geometry of a grid model (m). export function cellGeom(model) { const b = model.design; const dx = (b.L * 1e-3) / model.nx, dy = (b.W * 1e-3) / model.ny; return { dx, dy, dA: dx * dy, x: (i) => (i + 0.5) * dx, y: (j) => (j + 0.5) * dy }; } // Effective dipole volume per unit top area (m): added mass of a strip of width W plus the // bar's own volume. A bar slice moving with velocity v acts as a dipole of moment v·V. export const dipoleDepth = (b) => ((Math.PI * b.W) / 4 + b.h0) * 1e-3; /** * Radiation decay rate (1/s, amplitude) of one mode, treating every top-face cell as a * vertical point dipole in free space. Power of a set of z-dipoles in a plane: * P = ρω⁴/(24πc³) ΣΣ DᵢDⱼ C(k rᵢⱼ), C(u) = 1.5 (j0(u) - j1(u)/u). */ export function dipoleRadDecay(model, m) { const b = model.design; const { dx, dy } = cellGeom(model); // coarse cells (about 40 x 4) for the double sum const sx = Math.max(1, Math.round(model.nx / 40)), sy = Math.max(1, Math.round(model.ny / 4)); const V = dipoleDepth(b) * dx * dy; const pts = []; for (let i0 = 0; i0 < model.nx; i0 += sx) { for (let j0 = 0; j0 < model.ny; j0 += sy) { let D = 0, cx = 0, cy = 0, n = 0; for (let i = i0; i < Math.min(model.nx, i0 + sx); i++) { for (let j = j0; j < Math.min(model.ny, j0 + sy); j++) { D += m.phi[j * model.nx + i] * V; cx += (i + 0.5) * dx; cy += (j + 0.5) * dy; n++; } } pts.push([cx / n, cy / n, D]); } } const w = 2 * Math.PI * m.f, k = w / AIR.c; let S = 0; for (let p = 0; p < pts.length; p++) { for (let q = 0; q < pts.length; q++) { const u = k * Math.hypot(pts[p][0] - pts[q][0], pts[p][1] - pts[q][1]); let C = 1; if (u > 1e-4) { const j0 = Math.sin(u) / u, j1 = Math.sin(u) / (u * u) - Math.cos(u) / u; C = 1.5 * (j0 - j1 / u); } S += pts[p][2] * pts[q][2] * C; } } // energy of a unit-amplitude mass-normalized mode is ω²/2; σ = P / (2E) return (AIR.rho * w ** 4 * Math.max(0, S)) / (24 * Math.PI * AIR.c ** 3); }