// Finite-element body of the double bass: plates + bars + post + bridge (structural modes by // shift-invert Lanczos), air cavity (finite-volume modes), f-hole plugs, symmetric modal // structural–acoustic coupling, energy-weighted damping, and radiation to a listener by a sum of // simple sources. Pure TypeScript; runs in Node and in a browser worker. // // Damping of a coupled mode k (ω_k, unit modal mass, potential energy ω_k² η̂²/2 at amplitude η̂): // ζ = ½ [Σ_g η_g U_g + U_air / cavityQ] / U_tot (material + cavity-wall losses) // + Σ_p κ_p R_p / (2 m_p ω) (viscous f-hole wall losses) // + ρ0 ω (1 + g(ka)) Σ_ab q_a q_b sinc(k R_ab) / (8π c) (radiation) // with U_g the strain energy in top (plate + bass bar + post), back (plate + bars), bridge springs, // U_air the air-spring energy; κ_p the kinetic-energy fraction of plug p, R_p = P l sqrt(ωρ0μ/2) // its wall resistance; q_a the outward volume displacement per unit η of source patch a (top, // back, plugs), R_ab their distances. The radiated power is that of free-field simple sources; // g(ka) = (ka)²/(1+(ka)²) with a the body's equivalent radius blends in the doubling of a closed // body face (baffle effect) at high frequency. The listener pressure uses the same sources with // an obliquity factor 1 + g cos θ. import { feInputsKey, type Params } from "../core/params.ts"; import type { BodyMode, BodyModel } from "../core/types.ts"; import { statisticalModes } from "../core/body.ts"; import { eigsSliced } from "./eigen.ts"; import { HOLE, makeArch, makeBodyGrid, makeFHoles, makeOutline, markFHoles, nodeS, nodeX, slotEffectiveLength } from "./geometry.ts"; import { buildStructure, modeInfo, GROUP_NAMES } from "./structure.ts"; import { buildCavity, cavityModes, makePlug, surfaceStencil } from "./air.ts"; import { solveCoupled } from "./coupling.ts"; import type { FEShapes } from "./shapes.ts"; export type { FEExtra } from "./structure.ts"; const AIR_MU = 1.81e-5; const now = () => (typeof performance !== "undefined" ? performance.now() : Date.now()); /** opts.shapes: also compute the mode shapes for the 3D view (FEShapes) and hand them over. */ export function computeFEBody(p: Params, onProgress?: (msg: string, frac: number) => void, opts: { shapes?: (s: FEShapes) => void } = {}): BodyModel { const fe = p.fe; const T0 = now(); const timings: Record = {}; let tMark = T0; const lap = (name: string) => { const t = now(); timings[name] = Math.round(t - tMark) / 1000; tMark = t; }; const prog = (msg: string, frac: number) => onProgress?.(msg, Math.min(1, Math.max(0, frac))); const warnings: string[] = []; const rho0 = fe.airRho, c0 = fe.airC; const L = fe.bodyLength; const xb = fe.bridgePos * L; const fHi = fe.fmax * 1.15; // subsystem modes are computed with a margin above fmax // ---------------------------------------------------------------- geometry prog("geometry", 0); const outline = makeOutline(fe); const arch = makeArch(fe, outline); const h = fe.gridH; const g = makeBodyGrid(fe, outline, arch, h); const holes = makeFHoles(fe); markFHoles(g, holes); lap("geometry"); // ---------------------------------------------------------------- structure prog("assembling structure", 0.02); const S = buildStructure(fe, g); if (Number(S.info.zeroStiffnessRows) > 0) warnings.push(`structure: ${S.info.zeroStiffnessRows} DOFs without stiffness`); lap("assembly"); const sr = eigsSliced(S.K, S.M, -1, (2 * Math.PI * fHi) ** 2, { countExp: 2, perSlice: 60, label: "structure", seed: 3, onProgress: (m, f) => prog(m, 0.04 + 0.46 * f), }); warnings.push(...sr.warnings); const ns = sr.lam.length; const sOmega2 = Float64Array.from(sr.lam, (l) => Math.max(l, 0)); lap("structureModes"); // per structural mode: bridge coupling, energy splits, surface displacements const topNodes: number[] = [], backNodes: number[] = []; for (let k = 0; k < g.nx * g.ns; k++) { if (S.topW[k] >= 0) topNodes.push(k); if (S.backW[k] >= 0) backNodes.push(k); } const nTop = topNodes.length, nBack = backNodes.length; const sBy: number[][] = [], sBz: number[][] = [], sPe: number[][] = [], sKe: number[][] = []; const Wt = new Float64Array(ns * nTop), Wb = new Float64Array(ns * nBack); for (let m = 0; m < ns; m++) { const x = sr.vec[m]; const mi = modeInfo(S, x, sOmega2[m]); sBy.push(mi.by); sBz.push(mi.bz); sPe.push(mi.pe); sKe.push(mi.ke); for (let a = 0; a < nTop; a++) Wt[m * nTop + a] = x[S.topW[topNodes[a]]]; for (let a = 0; a < nBack; a++) Wb[m * nBack + a] = x[S.backW[backNodes[a]]]; } sr.vec.length = 0; // free lap("structureInfo"); // ---------------------------------------------------------------- air cavity prog("air cavity", 0.5); const ha = Math.min(0.04, Math.max(0.022, 1.4 * h)); // air cells: ~6 per wavelength at 2.5 kHz const cav = buildCavity( 0, L, outline.maxHalf, ha, (x, s) => Math.abs(s) < outline.halfWidth(x), (x, s) => fe.ribDepth + arch(x, s), ); const am = cavityModes(cav, c0, fHi, (m, f) => prog(m, 0.5 + 0.2 * f)); warnings.push(...am.warnings); const na = am.omega.length; lap("airModes"); // ψ on the plate surfaces const topZ = (x: number, s: number) => fe.ribDepth + arch(x, s); const psiTop = new Float64Array(na * nTop), psiBack = new Float64Array(na * nBack); { const stT = topNodes.map((k) => surfaceStencil(cav, nodeX(g, Math.floor(k / g.ns)), nodeS(g, k % g.ns), "top")); const stB = backNodes.map((k) => surfaceStencil(cav, nodeX(g, Math.floor(k / g.ns)), nodeS(g, k % g.ns), "bottom")); for (let j = 0; j < na; j++) { const psi = am.psi[j]; for (let a = 0; a < nTop; a++) { const st = stT[a]; let v = 0; for (let q = 0; q < st.cells.length; q++) v += st.wts[q] * psi[st.cells[q]]; psiTop[j * nTop + a] = v; } for (let a = 0; a < nBack; a++) { const st = stB[a]; let v = 0; for (let q = 0; q < st.cells.length; q++) v += st.wts[q] * psi[st.cells[q]]; psiBack[j * nBack + a] = v; } } } // f-hole plugs const plugs = holes.map((fh) => { const lEff = slotEffectiveLength(fh.length, fh.width, fe.topThickness); const pl = makePlug(cav, am, fh.area, lEff, fe.topThickness, fh.pts, rho0, c0); return { fh, ...pl, x: fh.xc, s: fh.sc, z: topZ(fh.xc, fh.sc) }; }); const np = plugs.length; const nm = ns + np; const area = h * h; const Smat = new Float64Array(nm * na); for (let m = 0; m < ns; m++) for (let j = 0; j < na; j++) { let s = 0; const ot = m * nTop, pt = j * nTop; for (let a = 0; a < nTop; a++) s += Wt[ot + a] * psiTop[pt + a]; let sb = 0; const ob = m * nBack, pb = j * nBack; for (let a = 0; a < nBack; a++) sb += Wb[ob + a] * psiBack[pb + a]; Smat[m * na + j] = area * (s - sb); // back outward normal is −z } for (let q = 0; q < np; q++) { const pl = plugs[q]; const f = pl.A / Math.sqrt(pl.mp); for (let j = 0; j < na; j++) Smat[(ns + q) * na + j] = f * pl.psiBar[j]; } const omega2m = new Float64Array(nm); omega2m.set(sOmega2); const Dj = new Float64Array(na).fill(rho0 * c0 * c0); lap("couplingSetup"); // ---------------------------------------------------------------- coupled problem prog(`coupled problem (${nm} + ${na} DOFs)`, 0.72); const cr = solveCoupled({ omega2: omega2m, S: Smat, airOmega: am.omega, D: Dj }); lap("coupledEig"); // ---------------------------------------------------------------- radiation setup (patches) prog("radiation", 0.9); const topArea = outline.area; const aEq = 0.5 * Math.sqrt(topArea / Math.PI); const mic = { x: xb, s: 0, z: topZ(xb, 0) + fe.micDistance }; interface Level { L: number; nP: number; px: Float64Array; py: Float64Array; pz: Float64Array; nz: Float64Array; // outward normal z component (±1) Q: Float64Array; // ns × (nP - np) patch volumes per structural mode R: Float64Array; // nP × nP distances } const levels: Level[] = []; for (let Lv = 1; Lv <= 4; Lv++) { const ids = new Map(); const memb: { plate: number; a: number; patch: number }[] = []; const px: number[] = [], py: number[] = [], pz: number[] = [], pn: number[] = [], cnt: number[] = []; const addNode = (plate: number, a: number, k: number) => { const i = Math.floor(k / g.ns), j = k % g.ns; const key = (plate * 100000 + (i >> Lv)) * 100000 + (j >> Lv); let id = ids.get(key); if (id === undefined) { id = px.length; ids.set(key, id); px.push(0); py.push(0); pz.push(0); pn.push(plate === 0 ? 1 : -1); cnt.push(0); } const x = nodeX(g, i), s = nodeS(g, j); px[id] += x; py[id] += s; pz[id] += plate === 0 ? topZ(x, s) : 0; cnt[id]++; memb.push({ plate, a, patch: id }); }; topNodes.forEach((k, a) => addNode(0, a, k)); backNodes.forEach((k, a) => addNode(1, a, k)); const nS = px.length; for (let id = 0; id < nS; id++) { px[id] /= cnt[id]; py[id] /= cnt[id]; pz[id] /= cnt[id]; } for (const pl of plugs) { px.push(pl.x); py.push(pl.s); pz.push(pl.z); pn.push(1); } const nP = px.length; const Q = new Float64Array(ns * nS); for (let m = 0; m < ns; m++) { const o = m * nS; for (const mb of memb) { const v = mb.plate === 0 ? Wt[m * nTop + mb.a] : -Wb[m * nBack + mb.a]; Q[o + mb.patch] += v * area; } } const R = new Float64Array(nP * nP); for (let a = 0; a < nP; a++) for (let b = 0; b < nP; b++) R[a * nP + b] = Math.hypot(px[a] - px[b], py[a] - py[b], pz[a] - pz[b]); levels.push({ L: Lv, nP, px: Float64Array.from(px), py: Float64Array.from(py), pz: Float64Array.from(pz), nz: Float64Array.from(pn), Q, R }); } lap("radiationSetup"); // ---------------------------------------------------------------- coupled modes -> BodyModes const losses = [fe.topLoss, fe.backLoss, 0.02, fe.topLoss]; // top, back, bridge, post const modes: BodyMode[] = []; const diag: { f: number; ke: number[]; pe: number[]; zParts: number[] }[] = []; const nc = cr.nc; const kept: number[] = []; let dropped = 0; for (let k = 0; k < nc; k++) { const w2 = cr.omega2[k]; const f = Math.sqrt(Math.max(w2, 0)) / (2 * Math.PI); if (f > fe.fmax) break; if (f < 5) { dropped++; continue; // flow-through (one hole in, the other out) mode: no stiffness, no bridge coupling } const w = 2 * Math.PI * f; const y = cr.Y.subarray(k * nc, (k + 1) * nc); const by = [0, 0, 0, 0], bz = [0, 0, 0, 0]; const peG = [0, 0, 0, 0], keG = [0, 0, 0]; let pePlate = 0; for (let m = 0; m < ns; m++) { const e = y[m]; if (e === 0) continue; for (let i = 0; i < 4; i++) { by[i] += e * sBy[m][i]; bz[i] += e * sBz[m][i]; } const e2 = e * e; const pe = e2 * sOmega2[m]; pePlate += pe; for (let gI = 0; gI < 4; gI++) peG[gI] += pe * sPe[m][gI]; for (let gI = 0; gI < 3; gI++) keG[gI] += e2 * sKe[m][gI]; } let kePlug = 0, keAir = 0; for (let q = 0; q < np; q++) kePlug += y[ns + q] ** 2; for (let r = 0; r < nc - nm; r++) keAir += y[nm + r] ** 2; const peAir = Math.max(0, w2 - pePlate); // material + cavity losses let zMat = 0; for (let gI = 0; gI < 4; gI++) zMat += losses[gI] * peG[gI]; zMat = (0.5 * (zMat + peAir / fe.cavityQ)) / w2; // viscous losses in the f-holes let zVisc = 0; for (let q = 0; q < np; q++) { const pl = plugs[q]; const perim = 2 * (pl.fh.length + pl.fh.width); const lv = fe.topThickness + 0.5 * (pl.lEff - fe.topThickness); const Rm = perim * lv * Math.sqrt((w * rho0 * AIR_MU) / 2); zVisc += (y[ns + q] ** 2 * Rm) / (2 * pl.mp * w); } // radiation: patch sources at the coarsest adequate level const kw = w / c0; const lam = (2 * Math.PI) / kw; let lvl = levels[0]; for (const lv of levels) if (h * 2 ** lv.L <= lam / 3) lvl = lv; const nP = lvl.nP, nS = nP - np; const qv = new Float64Array(nP); for (let m = 0; m < ns; m++) { const e = y[m]; if (e === 0) continue; const o = m * nS; for (let a = 0; a < nS; a++) qv[a] += e * lvl.Q[o + a]; } for (let q = 0; q < np; q++) qv[nS + q] = (plugs[q].A / Math.sqrt(plugs[q].mp)) * y[ns + q]; const ka = kw * aEq; const gk = (ka * ka) / (1 + ka * ka); let pRe = 0, pIm = 0; for (let a = 0; a < nP; a++) { const dx = mic.x - lvl.px[a], dy = mic.s - lvl.py[a], dz = mic.z - lvl.pz[a]; const R = Math.hypot(dx, dy, dz); const cosT = (lvl.nz[a] * dz) / R; const amp = (rho0 * qv[a] * (1 + gk * cosT)) / (4 * Math.PI * R); const ph = -kw * (R - fe.micDistance); pRe += amp * Math.cos(ph); pIm += amp * Math.sin(ph); } let pw = 0; for (let a = 0; a < nP; a++) { const qa = qv[a]; if (qa === 0) continue; let s = 0; const ro = a * nP; for (let b = a + 1; b < nP; b++) { const x = kw * lvl.R[ro + b]; s += qv[b] * (x < 1e-8 ? 1 : Math.sin(x) / x); } pw += qa * (qa + 2 * s); } const zRad = Math.max(0, (rho0 * w * (1 + gk) * pw) / (8 * Math.PI * c0)); const zeta = zMat + zVisc + zRad; modes.push({ f, zeta, by, bz, radRe: pRe, radIm: pIm }); kept.push(k); diag.push({ f, ke: [keG[0], keG[1], keG[2], kePlug, keAir], pe: [...peG, peAir], zParts: [zMat, zVisc, zRad] }); } // labels let a0Found = false; const counters: Record = { top: 0, back: 0, bridge: 0, air: 0 }; let a0f = NaN; for (let k = 0; k < modes.length; k++) { const ke = diag[k].ke; const airKe = ke[3] + ke[4]; if (!a0Found && ke[3] >= 0.25) { modes[k].label = "A0"; a0Found = true; a0f = modes[k].f; continue; } const cand: [string, number][] = [ ["top", ke[0]], ["back", ke[1]], ["bridge", ke[2]], ["air", airKe], ]; cand.sort((a, b) => b[1] - a[1]); const name = cand[0][0]; counters[name]++; modes[k].label = `${name}${counters[name]}`; } lap("modes"); const nFE = modes.length; // ---------------------------------------------------------------- mode shapes for the 3D view if (opts.shapes) { prog("mode shapes", 0.95); const nCols = cav.nCols, kz = Math.floor(cav.nz / 2); const top = new Float32Array(nFE * nTop), back = new Float32Array(nFE * nBack); const air = new Float32Array(nFE * nCols), plug = new Float32Array(nFE * np); const Pj = new Float64Array(na); const tt = new Float64Array(nTop), bb = new Float64Array(nBack); for (let q = 0; q < nFE; q++) { const y = cr.Y.subarray(kept[q] * nc, (kept[q] + 1) * nc); tt.fill(0); bb.fill(0); for (let m = 0; m < ns; m++) { const e = y[m]; if (e === 0) continue; const ot = m * nTop, ob = m * nBack; for (let a = 0; a < nTop; a++) tt[a] += e * Wt[ot + a]; for (let a = 0; a < nBack; a++) bb[a] += e * Wb[ob + a]; } top.set(tt, q * nTop); back.set(bb, q * nBack); // cavity pressure P_j = -D_j (S_j^T eta - r_j), r_j = Y_r omega_j / sqrt(D_j) (0 for the static mode) for (let j = 0; j < na; j++) { let sv = 0; for (let m = 0; m < nm; m++) sv += Smat[m * na + j] * y[m]; Pj[j] = -Dj[j] * sv; } for (let r = 0; r < cr.rj.length; r++) { const j = cr.rj[r]; Pj[j] += Dj[j] * (y[nm + r] * am.omega[j]) / Math.sqrt(Dj[j]); } for (let c = 0; c < nCols; c++) { let v = 0; const cell = c * cav.nz + kz; for (let j = 0; j < na; j++) v += Pj[j] * am.psi[j][cell]; air[q * nCols + c] = v; } for (let qq = 0; qq < np; qq++) plug[q * np + qq] = y[ns + qq] / Math.sqrt(plugs[qq].mp); } opts.shapes({ feKey: feInputsKey(p), nModes: nFE, grid: { nx: g.nx, ns: g.ns, h: g.h, x0: g.x0, s0: g.s0 }, topNodes: Int32Array.from(topNodes), backNodes: Int32Array.from(backNodes), cav: { nxA: cav.nxA, nsA: cav.nsA, x0: cav.x0, s0: cav.s0, ha: cav.ha, col: Int32Array.from(cav.col), colH: Float32Array.from(cav.colH) }, plugs: plugs.map((pl) => ({ xc: pl.fh.xc, sc: pl.fh.sc, tilt: pl.fh.tilt, length: pl.fh.length, width: pl.fh.width })), top, back, air, plug, }); lap("shapes"); } // ---------------------------------------------------------------- statistical continuation let nStat = 0; let statInfo: Record = {}; if (fe.statAbove && nFE > 10) { // continue the structural modes only (air-dominated cavity modes radiate and couple weakly) const structural = modes.filter((_, k) => diag[k].ke[0] + diag[k].ke[1] + diag[k].ke[2] >= 0.5); const band = structural.filter((m) => m.f >= 0.6 * fe.fmax && m.f <= fe.fmax); const density = band.length / (0.4 * fe.fmax); const near = structural.filter((m) => m.f >= 0.7 * fe.fmax); const loss = (2 * near.reduce((s, m) => s + m.zeta, 0)) / Math.max(1, near.length); const plateMass = Number(S.info.topPlateMass) + Number(S.info.backPlateMass); const fHigh = Math.max(p.body.statFHigh, fe.fmax * 1.5); const stat = statisticalModes({ fLow: fe.fmax, fHigh, density: Math.max(density, 1e-3), mass: plateMass, lossFactor: () => loss, lateralRatio: p.body.lateralRatio, // unfiltered here (bridge resonances far away); the FE bridge's own filters are applied below bridgeF: 1e9, bridgeQ: 1, radCorner: p.body.radCorner, radScale: p.body.radScale, plateArea: topArea, notchY: S.notchY, micDistance: fe.micDistance, airRho: rho0, seed: p.body.seed + 101, }); // the FE bridge above fmax: vertical/rotation through its stiff vertical resonance, lateral // through the in-plane rocking resonance (rigid-feet values; lateral Q from the parametric // body, vertical Q = 2: the bouncing bridge is heavily loaded by the plate) const fV = Number(S.info.bridgeVerticalHz), fL = Number(S.info.bridgeLateralHz); for (const m of stat) { const gv = resGain(m.f, fV, 2), gl = resGain(m.f, fL, p.body.bridgeQ); m.by = m.by.map((v) => v * gv); m.bz = m.bz.map((v) => v * gl); } // match the rms levels of the FE modes just below fmax so the spectrum continues smoothly const rms = (arr: BodyMode[], fn: (m: BodyMode) => number) => Math.sqrt(arr.reduce((s, m) => s + fn(m) ** 2, 0) / Math.max(1, arr.length)); const statNear = stat.filter((m) => m.f <= fe.fmax / 0.7); if (statNear.length > 3 && near.length > 3) { const ky = rms(near, (m) => Math.hypot(...m.by) / 2) / Math.max(1e-30, rms(statNear, (m) => Math.hypot(...m.by) / 2)); const kz = rms(near, (m) => m.bz[0]) / Math.max(1e-30, rms(statNear, (m) => m.bz[0])); const kr = rms(near, (m) => Math.hypot(m.radRe, m.radIm)) / Math.max(1e-30, rms(statNear, (m) => Math.hypot(m.radRe, m.radIm))); for (const m of stat) { m.by = m.by.map((v) => v * ky); m.bz = m.bz.map((v) => v * kz); m.radRe *= kr; m.radIm *= kr; m.label = "stat"; } statInfo = { density, loss, plateMass, scaleBy: ky, scaleBz: kz, scaleRad: kr, fHigh }; } else { for (const m of stat) m.label = "stat"; statInfo = { density, loss, plateMass, fHigh }; } modes.push(...stat); nStat = stat.length; lap("statistical"); } const total = (now() - T0) / 1000; prog("done", 1); return { name: "fe", source: "fe", modes, meta: { feKey: feInputsKey(p), timings: { ...timings, total }, grid: { h, nx: g.nx, ns: g.ns, topNodes: nTop, backNodes: nBack, holeNodes: countType(g.type, HOLE) }, structure: { ...S.info, modes: ns, slices: sr.slices, lanczosSteps: sr.steps, factorizations: sr.factorizations, groups: GROUP_NAMES }, air: { h: cav.ha, nz: cav.nz, columns: cav.nCols, cells: cav.n, volume: cav.volume, modes: na, lanczosSteps: am.steps, firstHz: am.omega.slice(1, 6).map((w) => w / 2 / Math.PI) }, plugs: plugs.map((pl) => ({ area: pl.A, lEff: pl.lEff, nearFieldDl: pl.dl, lUsed: pl.lUsed, mass: pl.mp })), helmholtzEstimateHz: np > 0 ? (c0 / (2 * Math.PI)) * Math.sqrt(plugs.reduce((s, pl) => s + pl.A / pl.lEff, 0) / cav.volume) : null, coupled: { dofs: nc, feModes: nFE, droppedLow: dropped }, a0Hz: a0f, topArea, statModes: nStat, stat: statInfo, diag: diag.map((d) => ({ f: d.f, ke: d.ke.map((v) => +v.toFixed(4)), pe: d.pe.map((v) => +(v / (2 * Math.PI * d.f) ** 2).toFixed(4)), z: d.zParts.map((v) => +v.toExponential(3)) })), warnings, }, }; } /** |1 / (1 - r² + i r/Q)|, r = f/f0 */ function resGain(f: number, f0: number, q: number): number { const r = f / f0; return 1 / Math.hypot(1 - r * r, r / q); } function countType(t: Int8Array, v: number): number { let n = 0; for (let k = 0; k < t.length; k++) if (t[k] === v) n++; return n; }