/ music / acoustic-base
Sign in
music / acoustic-base
acoustic-base / src / fe / structure.ts
300 lines · 10.5 KBBlameHistoryRaw
1// The structural model: arched orthotropic top (shallow shell: w, u, v), flat orthotropic back
2// (Kirchhoff: w), bass bar (eccentric beam under the top), back cross bars, soundpost spring and
3// a 3-DOF bridge, all on one plate grid. Single global "up" (+z) convention for both plates' w.
5import { Terms, Skyline, groupEnergies, type PackedTerms } from "./sparse.ts";
6import { HOLE, IN, bilinear, nodeX, type FEParams, type Grid } from "./geometry.ts";
7import { addBending, addMembrane, nodeKxx, ortho } from "./plate.ts";
9/** Optional extra FE parameters (not in Params.fe yet): flat-back cross bars. */
10export interface FEExtra {
11 /** number of cross bars glued across the flat back (0 = none) */
12 backBarCount?: number;
13 /** cross bar height and width, m (spruce) */
14 backBarHeight?: number;
15 backBarWidth?: number;
18export const G_TOP = 0, G_BACK = 1, G_BRIDGE = 2, G_POST = 3;
19export const GROUP_NAMES = ["top", "back", "bridge", "post"];
21export interface Structure {
22 g: Grid;
23 n: number;
24 M: Float64Array;
25 T: PackedTerms;
26 K: Skyline;
27 topW: Int32Array;
28 topU: Int32Array;
29 topV: Int32Array;
30 backW: Int32Array;
31 /** bridge DOFs: vertical translation and lateral translation at notch height, in-plane rotation */
32 bV: number;
33 bZ: number;
34 bT: number;
35 notchY: number[];
36 /** kinetic-energy group of each DOF (0 top, 1 back, 2 bridge) */
37 keGroup: Int8Array;
38 info: Record<string, number | string>;
41export function buildStructure(fe: FEParams, g: Grid): Structure {
42 const ex = fe as FEParams & FEExtra;
43 const { nx, ns, h } = g;
44 const L = fe.bodyLength;
45 const xb = fe.bridgePos * L;
46 const nn = nx * ns;
47 const topW = new Int32Array(nn).fill(-1), topU = new Int32Array(nn).fill(-1), topV = new Int32Array(nn).fill(-1);
48 const backW = new Int32Array(nn).fill(-1);
49 const backType = new Int8Array(nn);
50 for (let k = 0; k < nn; k++) backType[k] = g.type[k] === IN || g.type[k] === HOLE ? IN : 0;
51 // bridge DOFs are numbered right after the last grid row the feet touch (small envelope)
52 const iFoot = Math.floor((xb - g.x0) / h) + 1;
53 let n = 0;
54 let bV = -1, bZ = -1, bT = -1;
55 for (let i = 0; i < nx; i++) {
56 for (let j = 0; j < ns; j++) {
57 const k = i * ns + j;
58 if (g.type[k] === IN) {
59 topW[k] = n++;
60 topU[k] = n++;
61 topV[k] = n++;
62 }
63 if (backType[k] === IN) backW[k] = n++;
64 }
65 if (i === iFoot) {
66 bV = n++;
67 bZ = n++;
68 bT = n++;
69 }
70 }
71 const M = new Float64Array(n);
72 const keGroup = new Int8Array(n);
73 const top = ortho(fe.topEL, fe.topER, fe.topG, fe.topNu, fe.topRho, fe.topThickness);
74 const back = ortho(fe.backEL, fe.backER, fe.backG, fe.backNu, fe.backRho, fe.backThickness);
75 const area = h * h;
76 let mTop = 0, mBack = 0;
77 for (let k = 0; k < nn; k++) {
78 if (topW[k] >= 0) {
79 const m = top.rhoh * area;
80 M[topW[k]] += m;
81 M[topU[k]] += m;
82 M[topV[k]] += m;
83 mTop += m;
84 }
85 if (backW[k] >= 0) {
86 M[backW[k]] += back.rhoh * area;
87 keGroup[backW[k]] = 1;
88 mBack += back.rhoh * area;
89 }
90 }
91 const T = new Terms();
92 // plates
93 addBending(T, g, topW, top, G_TOP, fe.rimRotK);
94 addMembrane(T, g, topW, topU, topV, top, G_TOP);
95 const gBack: Grid = { ...g, type: backType };
96 addBending(T, gBack, backW, back, G_BACK, fe.rimRotK);
98 const dof = (arr: Int32Array, i: number, j: number) => (i < 0 || j < 0 || i >= nx || j >= ns ? -1 : arr[i * ns + j]);
99 const st = [1 / (h * h), -2 / (h * h), 1 / (h * h)];
101 // ---- bass bar: eccentric spruce beam along x under the bass foot
102 let mBar = 0;
103 if (fe.barHeight > 0 && fe.barWidth > 0 && fe.barLength > 0) {
104 const sBar = -fe.footSpan / 2;
105 const fj = (sBar - g.s0) / h;
106 const j0 = Math.floor(fj), a = fj - j0;
107 const cols = [j0, j0 + 1], cw = [1 - a, a];
108 const E = fe.topEL;
109 for (let i = 0; i < nx; i++) {
110 const dx = Math.abs(nodeX(g, i) - xb);
111 if (dx > fe.barLength / 2) continue;
112 const dEnd = fe.barLength / 2 - dx;
113 const taper = Math.min(1, 0.35 + (0.65 * dEnd) / (0.25 * fe.barLength));
114 const hb = fe.barHeight * taper, b = fe.barWidth;
115 const EI = (E * b * hb ** 3) / 12, EA = E * b * hb;
116 const e = fe.topThickness / 2 + hb / 2;
117 const bi: number[] = [], bc: number[] = [], ai: number[] = [], ac: number[] = [];
118 for (let c = 0; c < 2; c++) {
119 const j = cols[c], wt = cw[c];
120 if (wt === 0) continue;
121 for (let q = -1; q <= 1; q++) {
122 bi.push(dof(topW, i + q, j));
123 bc.push(wt * st[q + 1]);
124 ai.push(dof(topW, i + q, j));
125 ac.push(e * wt * st[q + 1]);
126 }
127 ai.push(dof(topU, i + 1, j), dof(topU, i - 1, j), dof(topW, i, j));
128 ac.push(wt / (2 * h), -wt / (2 * h), -wt * nodeKxx(g, i, j));
129 }
130 T.add(bi, bc, EI * h, G_TOP);
131 T.add(ai, ac, EA * h, G_TOP);
132 const m = fe.topRho * b * hb * h;
133 for (let c = 0; c < 2; c++) {
134 const k = i * ns + cols[c];
135 if (topW[k] < 0) continue;
136 M[topW[k]] += m * cw[c];
137 M[topU[k]] += m * cw[c];
138 M[topV[k]] += m * cw[c];
139 }
140 mBar += m;
141 }
142 }
144 // ---- back cross bars (spruce, across s): composite T-section bending stiffness minus the plate's own
145 let mBackBars = 0;
146 const nBars = Math.max(0, Math.round(ex.backBarCount ?? 4));
147 const bbH = ex.backBarHeight ?? 0.022, bbW = ex.backBarWidth ?? 0.016;
148 const xPost = xb - fe.postOffset;
149 const barXs: number[] = [];
150 if (nBars > 0 && bbH > 0 && bbW > 0) {
151 for (let k = 0; k < nBars; k++) {
152 let x = L * (nBars === 1 ? 0.5 : 0.15 + (0.7 * k) / (nBars - 1));
153 // the bar nearest the soundpost runs just beside it (as on flat-back basses), not under it
154 if (Math.abs(x - xPost) < 0.07 * L) x = x < xPost ? xPost - 0.035 : xPost + 0.035;
155 barXs.push(x);
156 }
157 const t = fe.backThickness;
158 const Ef = fe.backER, Ew = fe.topEL;
159 const bf = Math.min(0.15, 25 * t);
160 const Af = bf * t, Aw = bbW * bbH;
161 const zw = t / 2 + bbH / 2;
162 const zn = (Ew * Aw * zw) / (Ew * Aw + Ef * Af);
163 const EIc = Ef * ((bf * t ** 3) / 12 + Af * zn * zn) + Ew * ((bbW * bbH ** 3) / 12 + Aw * (zw - zn) ** 2);
164 const EIbar = Math.max(EIc - back.D22 * bf, (Ew * bbW * bbH ** 3) / 12);
165 for (const xbar of barXs) {
166 const fi = (xbar - g.x0) / h;
167 const i0 = Math.floor(fi), a = fi - i0;
168 const rows = [i0, i0 + 1], rw = [1 - a, a];
169 for (let j = 0; j < ns; j++) {
170 if (dof(backW, i0, j) < 0 && dof(backW, i0 + 1, j) < 0) continue;
171 const bi: number[] = [], bc: number[] = [];
172 for (let r = 0; r < 2; r++)
173 for (let q = -1; q <= 1; q++) {
174 bi.push(dof(backW, rows[r], j + q));
175 bc.push(rw[r] * st[q + 1]);
176 }
177 T.add(bi, bc, EIbar * h, G_BACK);
178 const m = fe.topRho * bbW * bbH * h;
179 for (let r = 0; r < 2; r++) {
180 const d = dof(backW, rows[r], j);
181 if (d >= 0) M[d] += m * rw[r];
182 }
183 mBackBars += m;
184 }
185 }
186 }
188 // ---- soundpost: spring between top w and back w at (xb - postOffset, +footSpan/2)
189 {
190 const ip = bilinear(g, xPost, fe.footSpan / 2);
191 const idx: number[] = [], c: number[] = [];
192 for (let q = 0; q < 4; q++) {
193 idx.push(topW[ip.nodes[q]], backW[ip.nodes[q]]);
194 c.push(ip.wts[q], -ip.wts[q]);
195 }
196 T.add(idx, c, fe.postK, G_POST);
197 }
199 // ---- bridge
200 const f = fe.footSpan, H = fe.bridgeHeight, kb = fe.bridgeK;
201 const kv = 40 * kb, kth = 10 * kb * f * f;
202 const fB = bilinear(g, xb, -f / 2), fT = bilinear(g, xb, f / 2);
203 {
204 // vertical: V - (wB + wT)/2
205 const idx = [bV], c = [1];
206 for (let q = 0; q < 4; q++) {
207 idx.push(topW[fB.nodes[q]], topW[fT.nodes[q]]);
208 c.push(-0.5 * fB.wts[q], -0.5 * fT.wts[q]);
209 }
210 T.add(idx, c, kv, G_BRIDGE);
211 }
212 {
213 // rotation: θ - (wT - wB)/f
214 const idx = [bT], c = [1];
215 for (let q = 0; q < 4; q++) {
216 idx.push(topW[fT.nodes[q]], topW[fB.nodes[q]]);
217 c.push(-fT.wts[q] / f, fB.wts[q] / f);
218 }
219 T.add(idx, c, kth, G_BRIDGE);
220 }
221 {
222 // lateral rocking compliance at the top: Z - (v_feet - H θ_feet)
223 const idx = [bZ], c = [1];
224 for (let q = 0; q < 4; q++) {
225 idx.push(topV[fB.nodes[q]], topV[fT.nodes[q]], topW[fT.nodes[q]], topW[fB.nodes[q]]);
226 c.push(-0.5 * fB.wts[q], -0.5 * fT.wts[q], (H * fT.wts[q]) / f, (-H * fB.wts[q]) / f);
227 }
228 T.add(idx, c, kb, G_BRIDGE);
229 }
230 // The notch-level DOFs carry the effective mass of the bridge's in-plane rocking about its feet,
231 // ≈ m (r_g / H)² ≈ 0.35 m for a tapered bridge (uniform rod: 1/3); the rest sits on the feet.
232 const mTopB = 0.35 * fe.bridgeMass, mFoot = 0.325 * fe.bridgeMass;
233 const notchY = [0, 1, 2, 3].map((i) => (i - 1.5) * fe.stringSpacing);
234 const wTop = 4 * fe.stringSpacing;
235 M[bV] = mTopB;
236 M[bZ] = mTopB;
237 M[bT] = (mTopB * wTop * wTop) / 12;
238 keGroup[bV] = keGroup[bZ] = keGroup[bT] = 2;
239 for (const fp of [fB, fT])
240 for (let q = 0; q < 4; q++) {
241 const d = topW[fp.nodes[q]];
242 if (d >= 0) M[d] += mFoot * fp.wts[q];
243 }
245 const P = T.pack();
246 // guard against DOFs without stiffness (would give spurious zero modes)
247 const K = Skyline.fromTerms(n, P);
248 let zeroRows = 0;
249 for (let i = 0; i < n; i++) if (!(K.val[K.rowOff[i] + i] > 0)) zeroRows++;
251 let nTopNodes = 0, nHole = 0;
252 for (let k = 0; k < nn; k++) {
253 if (g.type[k] === IN) nTopNodes++;
254 if (g.type[k] === HOLE) nHole++;
255 }
256 return {
257 g,
258 n,
259 M,
260 T: P,
261 K,
262 topW,
263 topU,
264 topV,
265 backW,
266 bV,
267 bZ,
268 bT,
269 notchY,
270 keGroup,
271 info: {
272 dofs: n,
273 topNodes: nTopNodes,
274 holeNodes: nHole,
275 skylineEntries: K.stored,
276 topPlateMass: mTop,
277 backPlateMass: mBack,
278 bassBarMass: mBar,
279 backBarsMass: mBackBars,
280 backBarX: barXs.map((x) => x.toFixed(3)).join(","),
281 zeroStiffnessRows: zeroRows,
282 bridgeLateralHz: Math.sqrt(kb / mTopB) / (2 * Math.PI),
283 bridgeVerticalHz: Math.sqrt(kv / mTopB) / (2 * Math.PI),
284 },
285 };
288/** Per-mode diagnostics: bridge coupling, strain-energy split, kinetic-energy split. */
289export function modeInfo(S: Structure, x: Float64Array, lam: number): { by: number[]; bz: number[]; pe: number[]; ke: number[] } {
290 const by = S.notchY.map((y) => x[S.bV] + x[S.bT] * y);
291 const bz = S.notchY.map(() => x[S.bZ]);
292 const e = groupEnergies(S.T, x, 4);
293 const tot = e[0] + e[1] + e[2] + e[3] || lam || 1;
294 const pe = Array.from(e, (v) => v / tot);
295 const ke = [0, 0, 0];
296 for (let i = 0; i < S.n; i++) ke[S.keGroup[i]] += S.M[i] * x[i] * x[i];
297 const kt = ke[0] + ke[1] + ke[2] || 1;
298 return { by, bz, pe, ke: ke.map((v) => v / kt) };
↑↓ move↵openescclose