1// Predefined design scripts, selectable from the interface. Each is a
2// MATLAB-syntax script that fills in the `design` struct; see design.ts for
3// the fields. A script is self-contained: the shape functions it uses are
4// ordinary MATLAB functions written at the bottom of the script itself.
6export interface Preset {
7 id: string;
8 label: string;
9 source: string;
10}
12const flatRectangle = `% A flat rectangular sheet of stainless steel, hanging freely.
13% The script is an ordinary MATLAB program that fills in a struct named
14% design. Lengths are meters; the constants at the top are the only units.
15% A field can be a number or a function handle @(x, y, r, theta) of the
16% point, measured from the center of the bounding box; the handles are
17% applied to whole grid matrices, so use elementwise operators (.*, ./, .^)
18% inside them. Anything else a script needs it defines itself, as MATLAB
19% functions at the bottom; the other presets show how. The decay of the
20% sound is not prescribed: it follows from the loss factor of the metal, its
21% thermal constants (thermoelastic damping), the radiation of each mode into
22% the air.
23inch = 0.0254; % m
24mm = 1e-3; % m
26design.name = 'Flat steel rectangle';
27design.material.E = 170e9; % Young's modulus [Pa]
28design.material.nu = 0.29; % Poisson ratio
29design.material.rho = 7900; % density [kg/m^3]
30design.material.lossFactor = 3e-4; % internal friction of the metal (typical published value)
31design.material.alpha = 17e-6; % thermal expansion [1/K] } for the thermoelastic damping
32design.material.cp = 500; % specific heat [J/(kg K)] }
33design.material.k = 16; % conductivity [W/(m K)] }
34design.bounds.width = 12*inch; % bounding box [m]
35design.bounds.height = 18*inch;
36design.thickness = 0.79*mm;
37`;
39const aluminumSquare = `% A flat 12 inch square of 6061-T6 aluminum, 1.02 mm thick.
40% Aluminum is a third the density of steel and a third as stiff, so
41% the bending frequencies land near those of a steel plate of the same size
42% and thickness. Its high thermal expansion and conductivity give it the
43% strongest thermoelastic damping of the three metals here.
44inch = 0.0254; mm = 1e-3;
45W = 12*inch;
47design.name = 'Aluminum 6061-T6 square';
48design.material.E = 68.9e9; % Young's modulus [Pa]
49design.material.nu = 0.33; % Poisson ratio
50design.material.rho = 2700; % density [kg/m^3]
51design.material.lossFactor = 1e-4; % internal friction of the metal (typical published value)
52design.material.alpha = 23.6e-6; % thermal expansion [1/K] } for the thermoelastic damping
53design.material.cp = 896; % specific heat [J/(kg K)] }
54design.material.k = 167; % conductivity [W/(m K)] }
55design.bounds.width = W;
56design.bounds.height = W;
57design.thickness = 1.02*mm;
58`;
60const bowedRectangle = `% The same steel sheet with a 3 mm parabolic bow across its width, the
61% kind of bow that rolling and handling leave in real sheet metal. The bow
62% makes the sheet a shallow shell: the linear modes couple bending to
63% stretching, and the full simulation oil-cans and wobbles when struck.
64inch = 0.0254; mm = 1e-3;
65W = 12*inch; H = 18*inch;
67design.name = 'Bowed steel rectangle';
68design.material.E = 170e9;
69design.material.nu = 0.29;
70design.material.rho = 7900;
71design.material.lossFactor = 3e-4; % internal friction of the metal (typical published value)
72design.material.alpha = 17e-6; % thermal expansion [1/K] } for the thermoelastic damping
73design.material.cp = 500; % specific heat [J/(kg K)] }
74design.material.k = 16; % conductivity [W/(m K)] }
75design.bounds.width = W;
76design.bounds.height = H;
77design.thickness = 0.79*mm;
78design.profile = @(x, y, r, theta) bow(x, W, 3*mm, 0.3); % stress-free height [m]
80function v = bow(s, span, sag, offset)
81% A parabola of the given sag across a span centered on 0; s runs along the
82% span, and the offset in -1..1 moves the crest toward one end.
83t = 2*s/span;
84v = sag * (1 - t.^2) .* (1 + offset*t);
85end
86`;
88const flatDisc = `% A flat 16 inch bronze disc, hanging freely.
89inch = 0.0254; mm = 1e-3;
90D = 16*inch;
92design.name = 'Flat bronze disc';
93design.material.E = 110e9; % bronze
94design.material.nu = 0.34;
95design.material.rho = 8800;
96design.material.lossFactor = 2e-4; % internal friction of the metal (typical published value)
97design.material.alpha = 18e-6; % thermal expansion [1/K] } for the thermoelastic damping
98design.material.cp = 370; % specific heat [J/(kg K)] }
99design.material.k = 40; % conductivity [W/(m K)] }
100design.bounds.width = D;
101design.bounds.height = D;
102design.inside = @(x, y, r, theta) r <= D/2;
103design.thickness = 1.0*mm;
104`;
106const crash16 = `% A 16 inch flat crash: bronze, lathed to a taper from 1.2 mm at the
107% center to 0.7 mm at the edge. Flat, so the linear modes are pure bending
108% modes; the tapered profile is what makes it a crash rather than a ride.
109inch = 0.0254; mm = 1e-3;
110D = 16*inch; R = D/2;
111tCenter = 1.2*mm; tEdge = 0.7*mm;
113design.name = '16 inch flat crash';
114design.material.E = 110e9;
115design.material.nu = 0.34;
116design.material.rho = 8800;
117design.material.lossFactor = 2e-4; % internal friction of the metal (typical published value)
118design.material.alpha = 18e-6; % thermal expansion [1/K] } for the thermoelastic damping
119design.material.cp = 370; % specific heat [J/(kg K)] }
120design.material.k = 40; % conductivity [W/(m K)] }
121design.bounds.width = D;
122design.bounds.height = D;
123design.inside = @(x, y, r, theta) r <= R;
124design.thickness = @(x, y, r, theta) tCenter + (tEdge - tCenter) * ramp(40*mm, R, r);
126function v = ramp(a, b, x)
127% 0 at x = a, 1 at x = b, clamped to that range outside.
128v = min(max((x - a) ./ (b - a), 0), 1);
129end
130`;
132const ride20 = `% A 20 inch flat ride: thicker bronze, 2.2 mm at the center to 1.4 mm at
133% the edge. The thickness raises every frequency in proportion, and the
134% ride has a clearer ping and a longer decay than the crash.
135inch = 0.0254; mm = 1e-3;
136D = 20*inch; R = D/2;
138design.name = '20 inch flat ride';
139design.material.E = 110e9;
140design.material.nu = 0.34;
141design.material.rho = 8800;
142design.material.lossFactor = 2e-4; % internal friction of the metal (typical published value)
143design.material.alpha = 18e-6; % thermal expansion [1/K] } for the thermoelastic damping
144design.material.cp = 370; % specific heat [J/(kg K)] }
145design.material.k = 40; % conductivity [W/(m K)] }
146design.bounds.width = D;
147design.bounds.height = D;
148design.inside = @(x, y, r, theta) r <= R;
149design.thickness = @(x, y, r, theta) 2.2*mm + (1.4*mm - 2.2*mm) * ramp(50*mm, R, r);
151function v = ramp(a, b, x)
152v = min(max((x - a) ./ (b - a), 0), 1);
153end
154`;
156const crashBell16 = `% A 16 inch crash with a shallow bow and a cosine bell. The
157% profile makes the cymbal a shallow shell: the linear model couples the
158% bending to the stretching (a larger eigenproblem, so the modes take
159% longer), and the full simulation shows the asymmetric nonlinearity of a
160% curved plate. The slopes are kept small; the interface reports the
161% largest one.
162inch = 0.0254; mm = 1e-3;
163D = 16*inch; R = D/2;
164bellR = 55*mm; bellH = 8*mm; bowH = 10*mm;
165tCenter = 1.2*mm; tEdge = 0.7*mm;
167design.name = '16 inch crash with bell';
168design.material.E = 110e9;
169design.material.nu = 0.34;
170design.material.rho = 8800;
171design.material.lossFactor = 2e-4; % internal friction of the metal (typical published value)
172design.material.alpha = 18e-6; % thermal expansion [1/K] } for the thermoelastic damping
173design.material.cp = 370; % specific heat [J/(kg K)] }
174design.material.k = 40; % conductivity [W/(m K)] }
175design.bounds.width = D;
176design.bounds.height = D;
177design.inside = @(x, y, r, theta) r <= R;
178design.thickness = @(x, y, r, theta) tCenter + (tEdge - tCenter) * ramp(bellR, R, r);
179design.profile = @(x, y, r, theta) bowH * (1 - (r/R).^2) + dome(r, bellR, bellH);
181function v = ramp(a, b, x)
182v = min(max((x - a) ./ (b - a), 0), 1);
183end
185function v = dome(d, radius, height)
186% A cosine dome of the given height and base radius, with zero slope both at
187% its rim and at its apex; d is the distance from its center.
188v = 0.5 * height * (1 + cos(pi * d / radius)) .* (d < radius);
189end
190`;
192const crashHammered16 = `% The 16 inch crash with bell, hammered: 160 shallow dents of 0.4 mm on
193% the bow, laid out on a sunflower spiral so that no two align. A hammered
194% cymbal is no longer axisymmetric, so its degenerate mode pairs split and
195% its modes mix, which is part of what makes a cymbal sound like one. The
196% dents here are what a script can express, a change of the rest shape;
197% the residual stresses of real hammering are not modeled.
198inch = 0.0254; mm = 1e-3;
199D = 16*inch; R = D/2;
200bellR = 55*mm; bellH = 8*mm; bowH = 10*mm;
201tCenter = 1.2*mm; tEdge = 0.7*mm;
202nDents = 160; dentR = 12*mm; dentDepth = 0.4*mm;
204design.name = '16 inch hammered crash';
205design.material.E = 110e9;
206design.material.nu = 0.34;
207design.material.rho = 8800;
208design.material.lossFactor = 2e-4; % internal friction of the metal (typical published value)
209design.material.alpha = 18e-6; % thermal expansion [1/K] } for the thermoelastic damping
210design.material.cp = 370; % specific heat [J/(kg K)] }
211design.material.k = 40; % conductivity [W/(m K)] }
212design.bounds.width = D;
213design.bounds.height = D;
214design.inside = @(x, y, r, theta) r <= R;
215design.thickness = @(x, y, r, theta) tCenter + (tEdge - tCenter) * ramp(bellR, R, r);
216design.profile = @(x, y, r, theta) bowH * (1 - (r/R).^2) + dome(r, bellR, bellH) + dents(x, y, bellR + dentR, R - dentR, nDents, dentR, dentDepth);
218function v = ramp(a, b, x)
219v = min(max((x - a) ./ (b - a), 0), 1);
220end
222function v = dome(d, radius, height)
223% A cosine dome of the given height and base radius, with zero slope both at
224% its rim and at its apex; d is the distance from its center.
225v = 0.5 * height * (1 + cos(pi * d / radius)) .* (d < radius);
226end
228function v = dents(x, y, r0, r1, n, rd, depth)
229% n hammer marks between the radii r0 and r1: Gaussian dents of 1/e radius
230% rd, placed on a sunflower spiral (equal area per mark, golden-angle
231% spacing) so that the pattern has no symmetry.
232v = 0 * x;
233ga = pi * (3 - sqrt(5));
234for k = 1:n
235 rk = sqrt(r0^2 + (r1^2 - r0^2) * (k - 0.5) / n);
236 tk = k * ga;
237 dx = x - rk * cos(tk); dy = y - rk * sin(tk);
238 v = v - depth * exp(-(dx.^2 + dy.^2) / rd^2);
239end
240end
241`;
243const ellipse = `% An elliptical steel plate. The outline is any test on the point;
244% an ellipse inscribed in the bounding box here. The degenerate mode pairs
245% of a disc split on an ellipse, which the mode browser shows.
246inch = 0.0254; mm = 1e-3;
247A = 14*inch; B = 10*inch;
249design.name = 'Steel ellipse';
250design.material.E = 170e9;
251design.material.nu = 0.29;
252design.material.rho = 7900;
253design.material.lossFactor = 3e-4; % internal friction of the metal (typical published value)
254design.material.alpha = 17e-6; % thermal expansion [1/K] } for the thermoelastic damping
255design.material.cp = 500; % specific heat [J/(kg K)] }
256design.material.k = 16; % conductivity [W/(m K)] }
257design.bounds.width = A;
258design.bounds.height = B;
259design.inside = @(x, y, r, theta) (x/(A/2)).^2 + (y/(B/2)).^2 <= 1;
260design.thickness = 1.0*mm;
261`;
263const thunderSheet = `% A thunder sheet: a large thin steel sheet, hung from a corner in reality.
264% Its modes are dense and low, and the full simulation turns a hard hit into
265% a roar.
266% Long at the default spacing; a coarser grid keeps it interactive.
267inch = 0.0254; mm = 1e-3;
269design.name = 'Thunder sheet';
270design.material.E = 200e9;
271design.material.nu = 0.3;
272design.material.rho = 7850;
273design.material.lossFactor = 3e-4; % internal friction of the metal (typical published value)
274design.material.alpha = 12e-6; % thermal expansion [1/K] } for the thermoelastic damping
275design.material.cp = 460; % specific heat [J/(kg K)] }
276design.material.k = 50; % conductivity [W/(m K)] }
277design.bounds.width = 24*inch;
278design.bounds.height = 36*inch;
279design.thickness = 0.5*mm;
280`;
282export const PRESETS: Preset[] = [
283 { id: "flat-rectangle", label: "Flat steel rectangle", source: flatRectangle },
284 { id: "aluminum-square", label: "Aluminum 6061-T6 square", source: aluminumSquare },
285 { id: "bowed-rectangle", label: "Bowed steel rectangle", source: bowedRectangle },
286 { id: "flat-disc", label: "Flat bronze disc", source: flatDisc },
287 { id: "crash-16", label: "16 inch flat crash", source: crash16 },
288 { id: "ride-20", label: "20 inch flat ride", source: ride20 },
289 { id: "crash-bell-16", label: "16 inch crash with bell", source: crashBell16 },
290 { id: "crash-hammered-16", label: "16 inch hammered crash", source: crashHammered16 },
291 { id: "ellipse", label: "Steel ellipse", source: ellipse },
292 { id: "thunder-sheet", label: "Thunder sheet", source: thunderSheet },
293];
295export const DEFAULT_PRESET = "crash-16";
297export function presetById(id: string): Preset | undefined {
298 return PRESETS.find((p) => p.id === id);
299}