// The structural model: arched orthotropic top (shallow shell: w, u, v), flat orthotropic back // (Kirchhoff: w), bass bar (eccentric beam under the top), back cross bars, soundpost spring and // a 3-DOF bridge, all on one plate grid. Single global "up" (+z) convention for both plates' w. import { Terms, Skyline, groupEnergies, type PackedTerms } from "./sparse.ts"; import { HOLE, IN, bilinear, nodeX, type FEParams, type Grid } from "./geometry.ts"; import { addBending, addMembrane, nodeKxx, ortho } from "./plate.ts"; /** Optional extra FE parameters (not in Params.fe yet): flat-back cross bars. */ export interface FEExtra { /** number of cross bars glued across the flat back (0 = none) */ backBarCount?: number; /** cross bar height and width, m (spruce) */ backBarHeight?: number; backBarWidth?: number; } export const G_TOP = 0, G_BACK = 1, G_BRIDGE = 2, G_POST = 3; export const GROUP_NAMES = ["top", "back", "bridge", "post"]; export interface Structure { g: Grid; n: number; M: Float64Array; T: PackedTerms; K: Skyline; topW: Int32Array; topU: Int32Array; topV: Int32Array; backW: Int32Array; /** bridge DOFs: vertical translation and lateral translation at notch height, in-plane rotation */ bV: number; bZ: number; bT: number; notchY: number[]; /** kinetic-energy group of each DOF (0 top, 1 back, 2 bridge) */ keGroup: Int8Array; info: Record; } export function buildStructure(fe: FEParams, g: Grid): Structure { const ex = fe as FEParams & FEExtra; const { nx, ns, h } = g; const L = fe.bodyLength; const xb = fe.bridgePos * L; const nn = nx * ns; const topW = new Int32Array(nn).fill(-1), topU = new Int32Array(nn).fill(-1), topV = new Int32Array(nn).fill(-1); const backW = new Int32Array(nn).fill(-1); const backType = new Int8Array(nn); for (let k = 0; k < nn; k++) backType[k] = g.type[k] === IN || g.type[k] === HOLE ? IN : 0; // bridge DOFs are numbered right after the last grid row the feet touch (small envelope) const iFoot = Math.floor((xb - g.x0) / h) + 1; let n = 0; let bV = -1, bZ = -1, bT = -1; for (let i = 0; i < nx; i++) { for (let j = 0; j < ns; j++) { const k = i * ns + j; if (g.type[k] === IN) { topW[k] = n++; topU[k] = n++; topV[k] = n++; } if (backType[k] === IN) backW[k] = n++; } if (i === iFoot) { bV = n++; bZ = n++; bT = n++; } } const M = new Float64Array(n); const keGroup = new Int8Array(n); const top = ortho(fe.topEL, fe.topER, fe.topG, fe.topNu, fe.topRho, fe.topThickness); const back = ortho(fe.backEL, fe.backER, fe.backG, fe.backNu, fe.backRho, fe.backThickness); const area = h * h; let mTop = 0, mBack = 0; for (let k = 0; k < nn; k++) { if (topW[k] >= 0) { const m = top.rhoh * area; M[topW[k]] += m; M[topU[k]] += m; M[topV[k]] += m; mTop += m; } if (backW[k] >= 0) { M[backW[k]] += back.rhoh * area; keGroup[backW[k]] = 1; mBack += back.rhoh * area; } } const T = new Terms(); // plates addBending(T, g, topW, top, G_TOP, fe.rimRotK); addMembrane(T, g, topW, topU, topV, top, G_TOP); const gBack: Grid = { ...g, type: backType }; addBending(T, gBack, backW, back, G_BACK, fe.rimRotK); const dof = (arr: Int32Array, i: number, j: number) => (i < 0 || j < 0 || i >= nx || j >= ns ? -1 : arr[i * ns + j]); const st = [1 / (h * h), -2 / (h * h), 1 / (h * h)]; // ---- bass bar: eccentric spruce beam along x under the bass foot let mBar = 0; if (fe.barHeight > 0 && fe.barWidth > 0 && fe.barLength > 0) { const sBar = -fe.footSpan / 2; const fj = (sBar - g.s0) / h; const j0 = Math.floor(fj), a = fj - j0; const cols = [j0, j0 + 1], cw = [1 - a, a]; const E = fe.topEL; for (let i = 0; i < nx; i++) { const dx = Math.abs(nodeX(g, i) - xb); if (dx > fe.barLength / 2) continue; const dEnd = fe.barLength / 2 - dx; const taper = Math.min(1, 0.35 + (0.65 * dEnd) / (0.25 * fe.barLength)); const hb = fe.barHeight * taper, b = fe.barWidth; const EI = (E * b * hb ** 3) / 12, EA = E * b * hb; const e = fe.topThickness / 2 + hb / 2; const bi: number[] = [], bc: number[] = [], ai: number[] = [], ac: number[] = []; for (let c = 0; c < 2; c++) { const j = cols[c], wt = cw[c]; if (wt === 0) continue; for (let q = -1; q <= 1; q++) { bi.push(dof(topW, i + q, j)); bc.push(wt * st[q + 1]); ai.push(dof(topW, i + q, j)); ac.push(e * wt * st[q + 1]); } ai.push(dof(topU, i + 1, j), dof(topU, i - 1, j), dof(topW, i, j)); ac.push(wt / (2 * h), -wt / (2 * h), -wt * nodeKxx(g, i, j)); } T.add(bi, bc, EI * h, G_TOP); T.add(ai, ac, EA * h, G_TOP); const m = fe.topRho * b * hb * h; for (let c = 0; c < 2; c++) { const k = i * ns + cols[c]; if (topW[k] < 0) continue; M[topW[k]] += m * cw[c]; M[topU[k]] += m * cw[c]; M[topV[k]] += m * cw[c]; } mBar += m; } } // ---- back cross bars (spruce, across s): composite T-section bending stiffness minus the plate's own let mBackBars = 0; const nBars = Math.max(0, Math.round(ex.backBarCount ?? 4)); const bbH = ex.backBarHeight ?? 0.022, bbW = ex.backBarWidth ?? 0.016; const xPost = xb - fe.postOffset; const barXs: number[] = []; if (nBars > 0 && bbH > 0 && bbW > 0) { for (let k = 0; k < nBars; k++) { let x = L * (nBars === 1 ? 0.5 : 0.15 + (0.7 * k) / (nBars - 1)); // the bar nearest the soundpost runs just beside it (as on flat-back basses), not under it if (Math.abs(x - xPost) < 0.07 * L) x = x < xPost ? xPost - 0.035 : xPost + 0.035; barXs.push(x); } const t = fe.backThickness; const Ef = fe.backER, Ew = fe.topEL; const bf = Math.min(0.15, 25 * t); const Af = bf * t, Aw = bbW * bbH; const zw = t / 2 + bbH / 2; const zn = (Ew * Aw * zw) / (Ew * Aw + Ef * Af); const EIc = Ef * ((bf * t ** 3) / 12 + Af * zn * zn) + Ew * ((bbW * bbH ** 3) / 12 + Aw * (zw - zn) ** 2); const EIbar = Math.max(EIc - back.D22 * bf, (Ew * bbW * bbH ** 3) / 12); for (const xbar of barXs) { const fi = (xbar - g.x0) / h; const i0 = Math.floor(fi), a = fi - i0; const rows = [i0, i0 + 1], rw = [1 - a, a]; for (let j = 0; j < ns; j++) { if (dof(backW, i0, j) < 0 && dof(backW, i0 + 1, j) < 0) continue; const bi: number[] = [], bc: number[] = []; for (let r = 0; r < 2; r++) for (let q = -1; q <= 1; q++) { bi.push(dof(backW, rows[r], j + q)); bc.push(rw[r] * st[q + 1]); } T.add(bi, bc, EIbar * h, G_BACK); const m = fe.topRho * bbW * bbH * h; for (let r = 0; r < 2; r++) { const d = dof(backW, rows[r], j); if (d >= 0) M[d] += m * rw[r]; } mBackBars += m; } } } // ---- soundpost: spring between top w and back w at (xb - postOffset, +footSpan/2) { const ip = bilinear(g, xPost, fe.footSpan / 2); const idx: number[] = [], c: number[] = []; for (let q = 0; q < 4; q++) { idx.push(topW[ip.nodes[q]], backW[ip.nodes[q]]); c.push(ip.wts[q], -ip.wts[q]); } T.add(idx, c, fe.postK, G_POST); } // ---- bridge const f = fe.footSpan, H = fe.bridgeHeight, kb = fe.bridgeK; const kv = 40 * kb, kth = 10 * kb * f * f; const fB = bilinear(g, xb, -f / 2), fT = bilinear(g, xb, f / 2); { // vertical: V - (wB + wT)/2 const idx = [bV], c = [1]; for (let q = 0; q < 4; q++) { idx.push(topW[fB.nodes[q]], topW[fT.nodes[q]]); c.push(-0.5 * fB.wts[q], -0.5 * fT.wts[q]); } T.add(idx, c, kv, G_BRIDGE); } { // rotation: θ - (wT - wB)/f const idx = [bT], c = [1]; for (let q = 0; q < 4; q++) { idx.push(topW[fT.nodes[q]], topW[fB.nodes[q]]); c.push(-fT.wts[q] / f, fB.wts[q] / f); } T.add(idx, c, kth, G_BRIDGE); } { // lateral rocking compliance at the top: Z - (v_feet - H θ_feet) const idx = [bZ], c = [1]; for (let q = 0; q < 4; q++) { idx.push(topV[fB.nodes[q]], topV[fT.nodes[q]], topW[fT.nodes[q]], topW[fB.nodes[q]]); c.push(-0.5 * fB.wts[q], -0.5 * fT.wts[q], (H * fT.wts[q]) / f, (-H * fB.wts[q]) / f); } T.add(idx, c, kb, G_BRIDGE); } // The notch-level DOFs carry the effective mass of the bridge's in-plane rocking about its feet, // ≈ m (r_g / H)² ≈ 0.35 m for a tapered bridge (uniform rod: 1/3); the rest sits on the feet. const mTopB = 0.35 * fe.bridgeMass, mFoot = 0.325 * fe.bridgeMass; const notchY = [0, 1, 2, 3].map((i) => (i - 1.5) * fe.stringSpacing); const wTop = 4 * fe.stringSpacing; M[bV] = mTopB; M[bZ] = mTopB; M[bT] = (mTopB * wTop * wTop) / 12; keGroup[bV] = keGroup[bZ] = keGroup[bT] = 2; for (const fp of [fB, fT]) for (let q = 0; q < 4; q++) { const d = topW[fp.nodes[q]]; if (d >= 0) M[d] += mFoot * fp.wts[q]; } const P = T.pack(); // guard against DOFs without stiffness (would give spurious zero modes) const K = Skyline.fromTerms(n, P); let zeroRows = 0; for (let i = 0; i < n; i++) if (!(K.val[K.rowOff[i] + i] > 0)) zeroRows++; let nTopNodes = 0, nHole = 0; for (let k = 0; k < nn; k++) { if (g.type[k] === IN) nTopNodes++; if (g.type[k] === HOLE) nHole++; } return { g, n, M, T: P, K, topW, topU, topV, backW, bV, bZ, bT, notchY, keGroup, info: { dofs: n, topNodes: nTopNodes, holeNodes: nHole, skylineEntries: K.stored, topPlateMass: mTop, backPlateMass: mBack, bassBarMass: mBar, backBarsMass: mBackBars, backBarX: barXs.map((x) => x.toFixed(3)).join(","), zeroStiffnessRows: zeroRows, bridgeLateralHz: Math.sqrt(kb / mTopB) / (2 * Math.PI), bridgeVerticalHz: Math.sqrt(kv / mTopB) / (2 * Math.PI), }, }; } /** Per-mode diagnostics: bridge coupling, strain-energy split, kinetic-energy split. */ export function modeInfo(S: Structure, x: Float64Array, lam: number): { by: number[]; bz: number[]; pe: number[]; ke: number[] } { const by = S.notchY.map((y) => x[S.bV] + x[S.bT] * y); const bz = S.notchY.map(() => x[S.bZ]); const e = groupEnergies(S.T, x, 4); const tot = e[0] + e[1] + e[2] + e[3] || lam || 1; const pe = Array.from(e, (v) => v / tot); const ke = [0, 0, 0]; for (let i = 0; i < S.n; i++) ke[S.keGroup[i]] += S.M[i] * x[i] * x[i]; const kt = ke[0] + ke[1] + ke[2] || 1; return { by, bz, pe, ke: ke.map((v) => v / kt) }; }