/ proof-of-concept / steelsim41
Sign in
proof-of-concept / steelsim41
steelsim41 / src / presets.ts
148 lines · 6.0 KBBlameHistoryRaw
1// Predefined design scripts, selectable from the interface. Each is a plain
2// JavaScript script body that returns the design object; see design.ts for
3// the fields and the helpers in scope.
5export interface Preset {
6 id: string;
7 label: string;
8 source: string;
9}
11const flatRectangle = `// A flat rectangular sheet of stainless steel, hanging freely (no mount).
12// Lengths are meters; inch and mm are conversion constants.
13// Every field can be a number or a function (x, y, r, theta) of the point,
14// measured from the center of the bounding box.
15return {
16 name: "Flat steel rectangle",
17 material: { E: 170e9, nu: 0.29, rho: 7900 },
18 bounds: { width: 12 * inch, height: 18 * inch },
19 thickness: 0.79 * mm,
20 profile: 0,
21 mount: null,
22 loss: { sigma0: 1.15, sigma1: 5e-4, sigmaIn: 20 },
23};
24`;
26const bowedRectangle = `// The same steel sheet with a 3 mm parabolic bow across its width, the
27// kind of bow that rolling and handling leave in real sheet metal. The bow
28// makes the sheet a shallow shell, which oil-cans and wobbles when struck.
29const W = 12 * inch, H = 18 * inch;
30return {
31 name: "Bowed steel rectangle",
32 material: { E: 170e9, nu: 0.29, rho: 7900 },
33 bounds: { width: W, height: H },
34 thickness: 0.79 * mm,
35 // bow(s, span, sag, offset): parabola of the given sag across the span; the
36 // offset in -1..1 moves the crest toward one edge.
37 profile: (x, y) => bow(x, W, 3 * mm, 0.3),
38 mount: null,
39 loss: { sigma0: 1.15, sigma1: 5e-4, sigmaIn: 20 },
40};
41`;
43const flatDisc = `// A flat 16 inch steel disc with a center hole, sitting on a stand: the
44// nodes within the mount radius are tied to the ground by a spring (the felt)
45// and a dashpot, spread over the mount area.
46const D = 16 * inch;
47return {
48 name: "Flat steel disc",
49 material: { E: 170e9, nu: 0.29, rho: 7900 },
50 bounds: { width: D, height: D },
51 inside: circle(D, 12 * mm), // diameter, hole diameter
52 thickness: 1.0 * mm,
53 profile: 0,
54 mount: { radius: 20 * mm, stiffness: 2e4, damping: 5 },
55 loss: { sigma0: 1.15, sigma1: 5e-4, sigmaIn: 20 },
56};
57`;
59const crash16 = `// A 16 inch crash: B20 bronze, tapered from the bell to the edge, with a
60// shallow bow and a cosine bell. The shallow-shell model behind the
61// simulation is strained where the slope of the profile exceeds about 0.1
62// to 0.2, so the bow and the bell are a little flatter than on a real crash.
63const D = 16 * inch, R = D / 2;
64const bellR = 60 * mm, bellH = 12 * mm; // base radius and height of the bell
65const bowH = 16 * mm; // rise from the edge to the foot of the bell
66return {
67 name: "16 inch crash",
68 material: { E: 110e9, nu: 0.34, rho: 8800 },
69 bounds: { width: D, height: D },
70 inside: circle(D, 12 * mm),
71 // Taper: 1.4 mm at the bell, 0.8 mm at the edge.
72 thickness: (x, y, r) => lerp(1.4 * mm, 0.8 * mm, clamp((r - bellR) / (R - bellR), 0, 1)),
73 // A paraboloidal bow plus the bell; dome(d, radius, height) has zero slope at its rim.
74 profile: (x, y, r) => bowH * (1 - (r / R) ** 2) + dome(r, bellR, bellH),
75 mount: { radius: 20 * mm, stiffness: 2e4, damping: 5 },
76 loss: { sigma0: 0.6, sigma1: 2.5e-4, sigmaIn: 20 },
77};
78`;
80const ride20 = `// A 20 inch ride: heavier bronze, a larger bell, a flatter bow. The taper
81// is stronger than on the crash, and the mount is a little stiffer.
82const D = 20 * inch, R = D / 2;
83const bellR = 70 * mm, bellH = 14 * mm;
84const bowH = 15 * mm;
85return {
86 name: "20 inch ride",
87 material: { E: 110e9, nu: 0.34, rho: 8800 },
88 bounds: { width: D, height: D },
89 inside: circle(D, 12 * mm),
90 thickness: (x, y, r) => lerp(2.0 * mm, 1.1 * mm, smoothstep(bellR, R, r)),
91 profile: (x, y, r) => bowH * (1 - (r / R) ** 2) + dome(r, bellR, bellH),
92 mount: { radius: 22 * mm, stiffness: 3e4, damping: 8 },
93 loss: { sigma0: 0.5, sigma1: 2e-4, sigmaIn: 20 },
94};
95`;
97const ellipseTwist = `// A steel ellipse with a saddle (twist) and a bow, hanging freely. The
98// twist raises two opposite quadrants and lowers the other two, which
99// breaks the symmetry of the disc modes.
100const W = 14 * inch, H = 20 * inch;
101return {
102 name: "Steel ellipse with a twist",
103 material: { E: 170e9, nu: 0.29, rho: 7900 },
104 bounds: { width: W, height: H },
105 inside: ellipse(W, H),
106 thickness: 0.79 * mm,
107 profile: (x, y) => {
108 const X = (2 * x) / W, Y = (2 * y) / H; // -1..1 over the bounding box
109 return 2 * mm * X * Y + bow(y, H, 2 * mm);
110 },
111 mount: null,
112 loss: { sigma0: 1.15, sigma1: 5e-4, sigmaIn: 20 },
113};
114`;
116const china18 = `// An 18 inch china: a conical bow that falls from the bell toward a flange,
117// and an upturned edge that rises again over the outer 45 mm. The bell is
118// square-topped (a plateau with rounded shoulders). The edge slope is well
119// beyond the shallow-shell range, so this preset is the least trustworthy.
120const D = 18 * inch, R = D / 2;
121const bellR = 65 * mm, bellH = 14 * mm;
122const flangeR = R - 45 * mm, bowH = 14 * mm, edgeH = 12 * mm;
123return {
124 name: "18 inch china",
125 material: { E: 110e9, nu: 0.34, rho: 8800 },
126 bounds: { width: D, height: D },
127 inside: circle(D, 12 * mm),
128 thickness: (x, y, r) => lerp(1.6 * mm, 0.9 * mm, smoothstep(bellR, flangeR, r)),
129 profile: (x, y, r) =>
130 bowH * Math.max(0, 1 - r / flangeR) // cone down to the flange
131 + edgeH * smoothstep(flangeR, R, r) // upturned edge
132 + bellH * (1 - smoothstep(bellR - 20 * mm, bellR, r)), // flat-topped bell
133 mount: { radius: 20 * mm, stiffness: 2e4, damping: 5 },
134 loss: { sigma0: 0.7, sigma1: 3e-4, sigmaIn: 20 },
135};
136`;
138export const PRESETS: Preset[] = [
139 { id: "flat-rectangle", label: "Flat steel rectangle", source: flatRectangle },
140 { id: "bowed-rectangle", label: "Bowed steel rectangle", source: bowedRectangle },
141 { id: "flat-disc", label: "Flat steel disc on a stand", source: flatDisc },
142 { id: "crash-16", label: "16 inch crash", source: crash16 },
143 { id: "ride-20", label: "20 inch ride", source: ride20 },
144 { id: "ellipse-twist", label: "Steel ellipse with a twist", source: ellipseTwist },
145 { id: "china-18", label: "18 inch china", source: china18 },
146];
148export const DEFAULT_PRESET = PRESETS[0];
↑↓ move↵openescclose