@rulecad/cad 0.8.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +45 -16
- package/CHANGELOG.md +724 -0
- package/EXAMPLES.md +61 -54
- package/README.md +376 -98
- package/TUTORIAL.md +2 -2
- package/bin/cad.mjs +2664 -541
- package/lib/animate.mjs +173 -49
- package/lib/assembly.mjs +1883 -435
- package/lib/beams.mjs +256 -52
- package/lib/belts.mjs +66 -15
- package/lib/board-work.mjs +12 -0
- package/lib/bought.mjs +309 -53
- package/lib/buildpage.mjs +179 -29
- package/lib/cache-file.mjs +105 -0
- package/lib/carried.mjs +201 -0
- package/lib/clone.mjs +194 -42
- package/lib/code-text.mjs +28 -0
- package/lib/design-imports.mjs +127 -0
- package/lib/design.mjs +871 -147
- package/lib/designshapes.mjs +142 -0
- package/lib/drive.mjs +187 -63
- package/lib/edit.mjs +922 -192
- package/lib/errors.mjs +16 -3
- package/lib/estimates.mjs +51 -0
- package/lib/explain.mjs +62 -13
- package/lib/fasten.mjs +2708 -507
- package/lib/fe-key.mjs +29 -0
- package/lib/fittings.mjs +721 -122
- package/lib/fixings.mjs +38 -13
- package/lib/framebuild.mjs +790 -175
- package/lib/framecheck.mjs +1901 -368
- package/lib/framegen.mjs +108 -22
- package/lib/frameheat.mjs +225 -42
- package/lib/frameprint.mjs +513 -108
- package/lib/frames.mjs +86 -18
- package/lib/framesize.mjs +719 -120
- package/lib/frametip.mjs +235 -0
- package/lib/gait.mjs +135 -23
- package/lib/grip.mjs +62 -13
- package/lib/guides.mjs +1403 -230
- package/lib/host.mjs +129 -23
- package/lib/inplace.mjs +171 -36
- package/lib/jigs.mjs +360 -78
- package/lib/joins.mjs +697 -118
- package/lib/jsonedit.mjs +88 -26
- package/lib/kept.mjs +84 -0
- package/lib/kit.mjs +439 -69
- package/lib/layout.mjs +2 -1
- package/lib/links.mjs +149 -42
- package/lib/list.mjs +334 -64
- package/lib/live-guard.mjs +68 -0
- package/lib/live-shape.mjs +96 -24
- package/lib/live.mjs +189 -59
- package/lib/loads.mjs +597 -136
- package/lib/machine.mjs +372 -74
- package/lib/magnets.mjs +162 -44
- package/lib/measured.mjs +1080 -117
- package/lib/mesh.mjs +526 -119
- package/lib/meshcmd.mjs +215 -60
- package/lib/motors.mjs +1002 -214
- package/lib/motorsvg.mjs +114 -32
- package/lib/names.mjs +18 -1
- package/lib/optimise.mjs +991 -287
- package/lib/order.mjs +515 -114
- package/lib/panels.mjs +482 -94
- package/lib/parts.mjs +81 -23
- package/lib/pins.mjs +163 -44
- package/lib/plates.mjs +223 -35
- package/lib/player.mjs +37 -9
- package/lib/power.mjs +64 -13
- package/lib/preview.mjs +83 -16
- package/lib/profilemeasure.mjs +572 -129
- package/lib/rules.mjs +17 -6
- package/lib/sandbox-hooks.mjs +179 -27
- package/lib/sandbox-lock.mjs +225 -0
- package/lib/sandbox-preload.mjs +2 -2
- package/lib/sandbox-run.mjs +122 -25
- package/lib/sandbox.mjs +667 -75
- package/lib/schema.mjs +42 -11
- package/lib/seats.mjs +227 -49
- package/lib/services.mjs +261 -52
- package/lib/sheet.mjs +963 -179
- package/lib/slotnuts.mjs +213 -34
- package/lib/targets/gist.mjs +4 -1
- package/lib/targets.mjs +22 -4
- package/lib/task.mjs +376 -79
- package/lib/versions.mjs +285 -39
- package/lib/wires.mjs +228 -45
- package/lib/workspace.mjs +200 -14
- package/package.json +19 -19
- package/schemas/assembly.schema.json +2 -2
- package/schemas/project.schema.json +6 -0
- package/templates/coupons/MEASURE.md +109 -0
- package/templates/coupons/assemblies/fixings-test.json +20 -0
- package/templates/coupons/assemblies/slot-test.json +11 -0
- package/templates/coupons/objects/fixings-coupon.js +88 -0
- package/templates/coupons/objects/fixings-coupon.json +26 -0
- package/templates/coupons/objects/holds-coupon.js +130 -0
- package/templates/coupons/objects/holds-coupon.json +42 -0
- package/templates/coupons/objects/slot-coupon.js +89 -0
- package/templates/coupons/objects/slot-coupon.json +29 -0
- package/templates/coupons/project.json +10 -0
package/lib/framecheck.mjs
CHANGED
|
@@ -27,47 +27,163 @@ import { massesOf } from './loads.mjs';
|
|
|
27
27
|
import { axisOf, workingSpeed, trainFrom, atCurrent, mountTorque } from './motors.mjs';
|
|
28
28
|
import { joinStiffness, PANEL_DEFAULTS } from '@rulecad/frames';
|
|
29
29
|
import { printableCheck, couponChecks, printedOption } from './frameprint.mjs';
|
|
30
|
+
import { tipOf, tipCheck, tipsWay } from './frametip.mjs';
|
|
30
31
|
|
|
31
32
|
const G = 9.80665;
|
|
32
33
|
const FEET = ['foot', 'levelling-foot', 'castor-plate', 'stacking-foot'];
|
|
33
|
-
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2],
|
|
34
|
-
|
|
34
|
+
const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2],
|
|
35
|
+
sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
36
|
+
const add = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]],
|
|
37
|
+
scale = (a, k) => [a[0] * k, a[1] * k, a[2] * k];
|
|
35
38
|
const cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
36
|
-
const rowsAt = (W, p) =>
|
|
37
|
-
|
|
39
|
+
const rowsAt = (W, p) =>
|
|
40
|
+
[0, 1, 2].map((k) => W[4 * k] * p[0] + W[4 * k + 1] * p[1] + W[4 * k + 2] * p[2] + W[4 * k + 3]);
|
|
41
|
+
const n3 = (x, d = 3) => String(+Number(x).toFixed(d)),
|
|
42
|
+
r3 = (x) => +Number(x).toFixed(3),
|
|
43
|
+
r4 = (p) => p.map(r3);
|
|
38
44
|
const fig = (x) => String(+Number(x).toPrecision(3));
|
|
39
45
|
// a sag in mm to three places, or where that gives fewer than three figures (under 0.1 mm), to three figures: a stiff
|
|
40
46
|
// frame's micrometres are still figures
|
|
41
47
|
const small = (x) => x && Math.abs(x) < 0.1;
|
|
42
|
-
const sagN = (x) => (small(x) ? fig(x) : n3(x)),
|
|
48
|
+
const sagN = (x) => (small(x) ? fig(x) : n3(x)),
|
|
49
|
+
sagR = (x) => (small(x) ? +Number(x).toPrecision(3) : r3(x));
|
|
43
50
|
const shown = (v) => (v === undefined ? 'nothing' : JSON.stringify(v));
|
|
44
51
|
|
|
45
52
|
/** The working figures of the frame checks, each with what it rests on. */
|
|
46
53
|
export const FRAME_CHECK = {
|
|
47
|
-
sag: {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
sag: {
|
|
55
|
+
value: 360,
|
|
56
|
+
unit: 'span per mm',
|
|
57
|
+
rule: "Where nothing else sets a limit, a beam may sag by its span over this much: a floor member's limit under the load it carries, a starting figure for a frame that holds things still. A guide's own tolerance, the assembly's frame.limit or its task's accuracy set a tighter one",
|
|
58
|
+
kind: 'default',
|
|
59
|
+
source:
|
|
60
|
+
"International Building Code, Table 1604.3, floor members under live load, l/360 (as reproduced in 780 CMR 1604.3, Massachusetts State Building Code); a building's serviceability figure taken as a frame's starting point",
|
|
61
|
+
checked: '2026-11-17',
|
|
62
|
+
},
|
|
63
|
+
margin: {
|
|
64
|
+
value: 2,
|
|
65
|
+
unit: '×',
|
|
66
|
+
rule: 'A beam, a join or a beam in compression is checked against about twice its load: under this margin it warns, under 1 it fails',
|
|
67
|
+
kind: 'default',
|
|
68
|
+
source: "The kit's standard of sizing from the load with about twice the margin (issue 240)",
|
|
69
|
+
checked: '2026-11-17',
|
|
70
|
+
},
|
|
71
|
+
link: {
|
|
72
|
+
value: 1000,
|
|
73
|
+
unit: '×',
|
|
74
|
+
rule: "A join's link from b's axis to a's end is a beam this many times stiffer than the stiffest beam it joins: rigid beside them, and not so stiff that the solve loses its digits",
|
|
75
|
+
kind: 'default',
|
|
76
|
+
source: 'A working figure of @rulecad/cad: doubles keep about 16 digits, and a ratio of 1000 costs 3 of them',
|
|
77
|
+
checked: '2026-11-17',
|
|
78
|
+
},
|
|
79
|
+
euler: {
|
|
80
|
+
value: 1,
|
|
81
|
+
unit: '',
|
|
82
|
+
rule: "A beam in compression is checked against Euler's load for its length with both ends pinned (effective length factor 1). That rests on its ends being held from moving sideways, as in a braced bay or on fixed feet, where a join holding an end more than a pin does only raises the load. A post of a frame free to sway (an open frame on pinned feet) buckles sooner, at an effective length factor of 2 or more: that is left to the whole frame's own buckling factor, frame.buckling's second finding, solved with the joins' springs",
|
|
83
|
+
kind: 'default',
|
|
84
|
+
source:
|
|
85
|
+
"Euler's column, P = π² E I / (K L)², K = 1 for both ends pinned (Roark's Formulas for Stress and Strain, 7th ed., table 15.1, case 1a)",
|
|
86
|
+
checked: '2026-11-17',
|
|
87
|
+
},
|
|
88
|
+
push: {
|
|
89
|
+
value: 20,
|
|
90
|
+
unit: 'N',
|
|
91
|
+
rule: 'Where the assembly gives no frame.rack.load, the side push a frame is racked by at its top: a hand steadying it, or a bump while working at it. The stiffness it reports does not depend on this figure; only the sway against the limit does',
|
|
92
|
+
kind: 'estimate',
|
|
93
|
+
source: 'A working figure of @rulecad/cad, with no measurement behind it',
|
|
94
|
+
checked: '2026-11-17',
|
|
95
|
+
},
|
|
96
|
+
sway: {
|
|
97
|
+
value: 400,
|
|
98
|
+
unit: 'height per mm',
|
|
99
|
+
rule: "Where nothing else sets a limit, a frame may sway at its top by its height over this much under the side push: the lenient end of the drift limits in common use for buildings under wind, taken as a frame's starting point. The task's accuracy or frame.rack.limit set a tighter one",
|
|
100
|
+
kind: 'default',
|
|
101
|
+
source:
|
|
102
|
+
'ASCE/SEI 7-22, Commentary to Appendix C, section CC.2.2: drift limits in common usage are on the order of 1/600 to 1/400 of the building or storey height',
|
|
103
|
+
checked: '2026-11-17',
|
|
104
|
+
},
|
|
105
|
+
order: {
|
|
106
|
+
value: ['gusset', 'brace', 'panel'],
|
|
107
|
+
unit: '',
|
|
108
|
+
rule: "The changes that stiffen a bay against racking, cheapest first: gussets at its corners (four printed or bought plates), one diagonal brace (a length of the bay's own profile and two fittings), a panel (a sheet and its clips). The first in this order that brings the sway under the limit is advised, in one bay before every bay that way",
|
|
109
|
+
kind: 'default',
|
|
110
|
+
source: 'A working order of @rulecad/cad, by the parts each needs; cad list prices them',
|
|
111
|
+
checked: '2026-11-17',
|
|
112
|
+
},
|
|
113
|
+
clip: {
|
|
114
|
+
value: 200,
|
|
115
|
+
unit: 'N/mm',
|
|
116
|
+
rule: "How stiffly one panel clip holds the sheet's edge from sliding along the beam: the clip grips the sheet by friction and its edge sits half a millimetre off the step, so this is a guess at the friction's stiffness, the weak link of a panel as a shear web",
|
|
117
|
+
kind: 'estimate',
|
|
118
|
+
source: 'A working guess of @rulecad/cad, with no measurement behind it: a panel on the joint rig would measure it',
|
|
119
|
+
checked: '2026-11-17',
|
|
120
|
+
},
|
|
121
|
+
band: {
|
|
122
|
+
value: 0.2,
|
|
123
|
+
unit: '',
|
|
124
|
+
rule: "A mode within this share of a frequency the machine dwells at (a stepper's full-step rate at its working speed) is near enough to ring",
|
|
125
|
+
kind: 'estimate',
|
|
126
|
+
source:
|
|
127
|
+
'A working figure of @rulecad/cad: a lightly damped mode amplifies a forcing within about ±20% of it several times over',
|
|
128
|
+
checked: '2026-11-17',
|
|
129
|
+
},
|
|
130
|
+
together: {
|
|
131
|
+
value: 32,
|
|
132
|
+
unit: 'poses',
|
|
133
|
+
rule: "Where two or more moving joints are mounted on the frame's beams, they are also swept together: every joint at each end and each step of frame.sweep, all combined, where that makes no more than this many poses; else each at its ends and middle combined, where that makes no more than this many; else every joint at the same share of its travel at once, and at its ends in every combination that fits under this many. So a gantry's carriage at the middle of a beam that is itself at the middle of its travel is found",
|
|
134
|
+
kind: 'default',
|
|
135
|
+
source:
|
|
136
|
+
'A working figure of @rulecad/cad: each pose is a solve of the whole frame, so the combinations are held to a number a check takes seconds over',
|
|
137
|
+
checked: '2026-11-25',
|
|
138
|
+
},
|
|
139
|
+
sweep: {
|
|
140
|
+
value: 4,
|
|
141
|
+
unit: 'steps',
|
|
142
|
+
rule: 'A moving joint mounted on a beam is solved at each end of its travel and at this many equal steps of it between (its quarters), so a worst place between the ends is found: a carriage between two supports at its middle, an arm on a hinge where it lies level',
|
|
143
|
+
kind: 'default',
|
|
144
|
+
source:
|
|
145
|
+
'A working figure of @rulecad/cad: quarters hold a middle and the quarter points, each step one more solve of every check',
|
|
146
|
+
checked: '2026-11-24',
|
|
147
|
+
},
|
|
148
|
+
ramp: {
|
|
149
|
+
value: 500,
|
|
150
|
+
unit: 'mm/s²',
|
|
151
|
+
rule: "Where the task gives no accel, the acceleration a move ramps at: a move at the task's speed ramps for speed over this many seconds, and shakes the frame at about one over that time",
|
|
152
|
+
kind: 'default',
|
|
153
|
+
source: "The same default as cad machine's task.accel (lib/machine.mjs)",
|
|
154
|
+
checked: '2026-11-17',
|
|
155
|
+
},
|
|
59
156
|
};
|
|
60
157
|
|
|
61
158
|
/** The sheets a panel is cut from as a shear web: each one's modulus and Poisson's ratio, with what each rests on. */
|
|
62
159
|
export const SHEET_STIFFNESS = {
|
|
63
|
-
acrylic: {
|
|
64
|
-
|
|
65
|
-
|
|
160
|
+
acrylic: {
|
|
161
|
+
E: 3300,
|
|
162
|
+
nu: 0.37,
|
|
163
|
+
kind: 'spec',
|
|
164
|
+
source:
|
|
165
|
+
"Evonik PLEXIGLAS GS technical information (2025): modulus of elasticity 3300 MPa (ISO 527-2, short-term), Poisson's ratio 0.37 (ISO 527-1)",
|
|
166
|
+
},
|
|
167
|
+
polycarbonate: {
|
|
168
|
+
E: 2400,
|
|
169
|
+
nu: 0.38,
|
|
170
|
+
kind: 'community',
|
|
171
|
+
source: "Typical figures for solid polycarbonate sheet, not checked against one maker's data sheet",
|
|
172
|
+
},
|
|
173
|
+
aluminium: {
|
|
174
|
+
E: 70000,
|
|
175
|
+
nu: 0.33,
|
|
176
|
+
kind: 'community',
|
|
177
|
+
source: 'Typical figures for wrought aluminium alloys, not checked against a 5754 data sheet',
|
|
178
|
+
},
|
|
66
179
|
};
|
|
67
180
|
|
|
68
181
|
// A web's bar is of a made-up material this stiff, its area chosen to give the stiffness wanted along it
|
|
69
182
|
const WEB_E = 1000;
|
|
70
|
-
const unitv = (v) => {
|
|
183
|
+
const unitv = (v) => {
|
|
184
|
+
const l = Math.hypot(...v);
|
|
185
|
+
return v.map((c) => c / l);
|
|
186
|
+
};
|
|
71
187
|
|
|
72
188
|
// The bays of a frame: four beams round a rectangle in one plane, two each way, each neighbouring pair joined to each
|
|
73
189
|
// other or both joined to one beam at one place (the top of a corner-post box: its rails join the posts, not each
|
|
@@ -75,34 +191,75 @@ const unitv = (v) => { const l = Math.hypot(...v); return v.map((c) => c / l); }
|
|
|
75
191
|
// both join (a join puts a station on the beam it lands on there).
|
|
76
192
|
function baysOf(beams, joins, nodes, nodeAt) {
|
|
77
193
|
const direct = (p, q) => joins.some((x) => (x.A.id === p && x.B.id === q) || (x.A.id === q && x.B.id === p));
|
|
78
|
-
const reachOf = (id) => {
|
|
194
|
+
const reachOf = (id) => {
|
|
195
|
+
const m = beams.get(id).m.profile;
|
|
196
|
+
return Math.max(m.width, m.height);
|
|
197
|
+
};
|
|
79
198
|
// the beams p and q both join at one place: a's end on b's axis within a profile's width of the other's
|
|
80
|
-
const memo = new Map(),
|
|
81
|
-
|
|
82
|
-
|
|
199
|
+
const memo = new Map(),
|
|
200
|
+
via = (p, q) => {
|
|
201
|
+
const key = `${p}|${q}`;
|
|
202
|
+
if (!memo.has(key)) memo.set(key, through(p, q));
|
|
203
|
+
return memo.get(key);
|
|
204
|
+
};
|
|
205
|
+
const through = (p, q) => {
|
|
206
|
+
const out = new Set();
|
|
207
|
+
for (const x of joins)
|
|
208
|
+
for (const y of joins) {
|
|
209
|
+
if (x === y) continue;
|
|
210
|
+
const [xo, xr, xz] = x.A.id === p ? [p, x.B.id, x.zb] : x.B.id === p ? [p, x.A.id, x.za] : [];
|
|
211
|
+
const [yo, yr, yz] = y.A.id === q ? [q, y.B.id, y.zb] : y.B.id === q ? [q, y.A.id, y.za] : [];
|
|
212
|
+
if (xo && yo && xr === yr && xr !== p && xr !== q && Math.abs(xz - yz) <= reachOf(xr)) out.add(xr);
|
|
213
|
+
}
|
|
214
|
+
return [...out];
|
|
215
|
+
};
|
|
83
216
|
const linked = (p, q) => direct(p, q) || via(p, q).length > 0;
|
|
84
|
-
const ids = [...beams.keys()],
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
217
|
+
const ids = [...beams.keys()],
|
|
218
|
+
out = [],
|
|
219
|
+
seen = new Set();
|
|
220
|
+
const par = (p, q) => Math.abs(Math.abs(dot(p.u, q.u)) - 1) < 1e-3,
|
|
221
|
+
square = (p, q) => Math.abs(dot(p.u, q.u)) < 1e-3;
|
|
222
|
+
for (const a of ids)
|
|
223
|
+
for (const b of ids)
|
|
224
|
+
if (b !== a && linked(a, b))
|
|
225
|
+
for (const c of ids)
|
|
226
|
+
if (c !== a && c !== b && linked(b, c))
|
|
227
|
+
for (const d of ids) {
|
|
228
|
+
if ([a, b, c].includes(d) || !linked(c, d) || !linked(d, a)) continue;
|
|
229
|
+
const key = [a, b, c, d].sort().join(',');
|
|
230
|
+
if (seen.has(key)) continue;
|
|
231
|
+
const B = [a, b, c, d].map((id) => beams.get(id));
|
|
232
|
+
if (!(par(B[0], B[2]) && par(B[1], B[3]) && square(B[0], B[1]))) continue;
|
|
233
|
+
const n = unitv(cross(B[0].u, B[1].u));
|
|
234
|
+
if (B.some((q) => Math.abs(dot(sub(q.A, B[0].A), n)) > 1)) continue;
|
|
235
|
+
const reach = Math.max(...B.map((q) => Math.max(q.m.profile.width, q.m.profile.height)));
|
|
236
|
+
const corners = B.map((p, i) => {
|
|
237
|
+
const q = B[(i + 1) % 4],
|
|
238
|
+
X = add(p.A, scale(p.u, dot(sub(q.A, p.A), p.u)));
|
|
239
|
+
let best = null,
|
|
240
|
+
gap = Infinity;
|
|
241
|
+
for (const r of [p, q, ...via(p.id, q.id).map((id) => beams.get(id))])
|
|
242
|
+
for (const z of r.stations) {
|
|
243
|
+
const nm = nodeAt(r, z),
|
|
244
|
+
g = Math.hypot(...sub(nodes[nm], X));
|
|
245
|
+
if (g < gap) {
|
|
246
|
+
gap = g;
|
|
247
|
+
best = nm;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
return gap <= reach ? best : null;
|
|
251
|
+
});
|
|
252
|
+
if (corners.some((x) => !x) || new Set(corners).size < 4) continue;
|
|
253
|
+
seen.add(key);
|
|
254
|
+
const P = corners.map((x) => nodes[x]);
|
|
255
|
+
out.push({
|
|
256
|
+
beams: [a, b, c, d],
|
|
257
|
+
n,
|
|
258
|
+
corners,
|
|
259
|
+
size: [Math.hypot(...sub(P[1], P[0])), Math.hypot(...sub(P[2], P[1]))],
|
|
260
|
+
name: [a, b, c, d].join('-'),
|
|
261
|
+
});
|
|
262
|
+
}
|
|
106
263
|
return out;
|
|
107
264
|
}
|
|
108
265
|
|
|
@@ -118,11 +275,41 @@ function baysOf(beams, joins, nodes, nodeAt) {
|
|
|
118
275
|
* @param {{ corners: string[], size: number[] }} bay @param {string} sheet @param {number} t mm @param {number} clips how many hold it (0: worked out from the pitch) @param {string} id
|
|
119
276
|
*/
|
|
120
277
|
function webOf(bay, sheet, t, clips, id) {
|
|
121
|
-
const m = SHEET_STIFFNESS[sheet] ?? SHEET_STIFFNESS.acrylic,
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
278
|
+
const m = SHEET_STIFFNESS[sheet] ?? SHEET_STIFFNESS.acrylic,
|
|
279
|
+
[a, h] = bay.size,
|
|
280
|
+
d = Math.hypot(a, h),
|
|
281
|
+
Gs = m.E / (2 * (1 + m.nu));
|
|
282
|
+
const n =
|
|
283
|
+
clips > 0
|
|
284
|
+
? clips
|
|
285
|
+
: 2 *
|
|
286
|
+
(Math.max(2, Math.ceil(a / PANEL_DEFAULTS.pitch.value) + 1) +
|
|
287
|
+
Math.max(2, Math.ceil(h / PANEL_DEFAULTS.pitch.value) + 1));
|
|
288
|
+
const sheetBar = (Gs * t * d * d) / (a * h),
|
|
289
|
+
clipBar = (d * d * n * FRAME_CHECK.clip.value) / (4 * (a + h) ** 2),
|
|
290
|
+
k = 1 / (1 / sheetBar + 1 / clipBar),
|
|
291
|
+
A = (k * d) / WEB_E;
|
|
292
|
+
return {
|
|
293
|
+
id,
|
|
294
|
+
sheet,
|
|
295
|
+
thickness: t,
|
|
296
|
+
clips: n,
|
|
297
|
+
sheetBar,
|
|
298
|
+
clipBar,
|
|
299
|
+
k,
|
|
300
|
+
rests: [
|
|
301
|
+
{ name: `${sheet} sheet`, E: m.E, nu: m.nu, kind: m.kind, source: m.source },
|
|
302
|
+
{ name: 'frame.clip', value: FRAME_CHECK.clip.value, kind: FRAME_CHECK.clip.kind },
|
|
303
|
+
],
|
|
304
|
+
element: {
|
|
305
|
+
id: `panel ${id}`,
|
|
306
|
+
a: bay.corners[0],
|
|
307
|
+
b: bay.corners[2],
|
|
308
|
+
section: { A, Iy: A * (d / 10) ** 2, Iz: A * (d / 10) ** 2, J: A * (d / 10) ** 2 },
|
|
309
|
+
material: { E: WEB_E, G: WEB_E / 2.6, density: 0 },
|
|
310
|
+
ends: { a: 'ball', b: 'pinned' },
|
|
311
|
+
},
|
|
312
|
+
};
|
|
126
313
|
}
|
|
127
314
|
|
|
128
315
|
// How a frame moves where nothing holds it, in words, from each way @rulecad/fea finds it moves (frame().mechanisms,
|
|
@@ -135,28 +322,81 @@ function howFree(fm, ways) {
|
|
|
135
322
|
const out = new Map();
|
|
136
323
|
for (const w of ways ?? []) {
|
|
137
324
|
const sh = w.shape ?? {};
|
|
138
|
-
let lead = null,
|
|
139
|
-
|
|
325
|
+
let lead = null,
|
|
326
|
+
most = 0,
|
|
327
|
+
spin = null,
|
|
328
|
+
turn = 0;
|
|
329
|
+
for (const [n, v] of Object.entries(sh)) {
|
|
330
|
+
const t = Math.hypot(v[0], v[1], v[2]),
|
|
331
|
+
r = Math.hypot(v[3], v[4], v[5]);
|
|
332
|
+
if (t > most) {
|
|
333
|
+
most = t;
|
|
334
|
+
lead = n;
|
|
335
|
+
}
|
|
336
|
+
if (r > turn) {
|
|
337
|
+
turn = r;
|
|
338
|
+
spin = n;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
140
341
|
const nearest = (v) => 'xyz'[[0, 1, 2].reduce((p, q) => (Math.abs(v[q]) > Math.abs(v[p]) ? q : p), 0)];
|
|
141
342
|
let says;
|
|
142
343
|
if (lead && most > 1e-6) {
|
|
143
|
-
const d = sh[lead].slice(0, 3),
|
|
144
|
-
|
|
344
|
+
const d = sh[lead].slice(0, 3),
|
|
345
|
+
v = dot(d, fm.down),
|
|
346
|
+
h = sub(d, scale(fm.down, v));
|
|
347
|
+
says =
|
|
348
|
+
Math.hypot(...h) >= Math.abs(v)
|
|
349
|
+
? `the frame tips over along ${nearest(h)}`
|
|
350
|
+
: `${beamOfNode(lead)} drops at ${lead}`;
|
|
145
351
|
} else if (spin) {
|
|
146
|
-
const r = sh[spin].slice(3),
|
|
147
|
-
|
|
352
|
+
const r = sh[spin].slice(3),
|
|
353
|
+
b = fm.beams.get(beamOfNode(spin));
|
|
354
|
+
says =
|
|
355
|
+
b && Math.abs(Math.abs(dot(unitv(r), b.u)) - 1) < 1e-3
|
|
356
|
+
? `${b.id} spins on its own axis`
|
|
357
|
+
: `it turns about ${nearest(r)} at ${spin}`;
|
|
148
358
|
} else says = `it moves at ${w.node} (${w.freedom})`;
|
|
149
359
|
out.set(says, [...(out.get(says) ?? []), { node: w.node, freedom: w.freedom }]);
|
|
150
360
|
}
|
|
151
361
|
return [...out].map(([says, at]) => ({ says, at }));
|
|
152
362
|
}
|
|
153
363
|
// the ways in one clause each, and where each is free: "the frame tips over along y (free at z2.b: rx)"
|
|
154
|
-
const howSaid = (hs) =>
|
|
364
|
+
const howSaid = (hs) =>
|
|
365
|
+
hs
|
|
366
|
+
.map(
|
|
367
|
+
(h) =>
|
|
368
|
+
`${h.says} (free at ${[...h.at.reduce((m, l) => m.set(l.node, [...(m.get(l.node) ?? []), l.freedom]), new Map())].map(([n, fr]) => `${n}: ${fr.join(', ')}`).join('; ')})`,
|
|
369
|
+
)
|
|
370
|
+
.join(', and ');
|
|
155
371
|
// the mechanisms of a solved frame that match freedoms named (a refusal's or buckling's), by node and freedom
|
|
156
|
-
const waysAt = (solved, ls) =>
|
|
372
|
+
const waysAt = (solved, ls) =>
|
|
373
|
+
(solved?.mechanisms ?? []).filter((m) => ls.some((l) => l.node === m.node && l.freedom === m.freedom));
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* The springs at an element's ends from the joins there, { a, b }: where two joins hold one end (a printed brace
|
|
377
|
+
* bracket beside the blind join asked for), their springs stand side by side, so their stiffnesses add, each way.
|
|
378
|
+
* @param {{ end: 'a' | 'b', k: { twist: number, bending: number } }[]} list @returns {Record<string, { rx: number, ry: number, rz: number }>}
|
|
379
|
+
*/
|
|
380
|
+
export function endSprings(list) {
|
|
381
|
+
const out = {};
|
|
382
|
+
for (const { end, k } of list) {
|
|
383
|
+
const e = (out[end] ??= { rx: 0, ry: 0, rz: 0 });
|
|
384
|
+
e.rx += k.twist;
|
|
385
|
+
e.ry += k.bending;
|
|
386
|
+
e.rz += k.bending;
|
|
387
|
+
}
|
|
388
|
+
return out;
|
|
389
|
+
}
|
|
157
390
|
|
|
158
391
|
// what a join's spring rests on, in a few words
|
|
159
|
-
const restsWord = (k) =>
|
|
392
|
+
const restsWord = (k) =>
|
|
393
|
+
k.measured?.bending && k.measured?.twist
|
|
394
|
+
? 'measured'
|
|
395
|
+
: k.fitting
|
|
396
|
+
? 'a printed fitting by finite elements'
|
|
397
|
+
: k.bought?.own
|
|
398
|
+
? `${k.bought.set}'s own figures, ${k.kind}`
|
|
399
|
+
: 'an estimate';
|
|
160
400
|
|
|
161
401
|
/**
|
|
162
402
|
* The frame of a built assembly as @rulecad/fea/frame's model, with what it rests on: the beams it holds, its nodes and
|
|
@@ -169,84 +409,214 @@ export function frameModelOf(s, helpers) {
|
|
|
169
409
|
if (!motion || !s.objects.some((o) => o.beam && !o.unplaced)) return null;
|
|
170
410
|
// beams with no joins and nothing said of their supports are parts held by other means (fastened to a plate, a lone
|
|
171
411
|
// upright on a printed base): not a frame to solve
|
|
172
|
-
if (
|
|
173
|
-
|
|
412
|
+
if (
|
|
413
|
+
!s.joins?.length &&
|
|
414
|
+
!['supports', 'limit', 'points', 'rack', 'printed', 'size'].some((k) => s.a.frame?.[k] != null)
|
|
415
|
+
)
|
|
416
|
+
return null;
|
|
417
|
+
const { placeItems, jointValues, mul } = helpers,
|
|
418
|
+
ids = motion.items.map((x) => x[0]),
|
|
419
|
+
base = jointValues(motion, motion.pose ?? undefined),
|
|
420
|
+
worlds = placeItems(motion, base);
|
|
174
421
|
const opts = s.a.frame ?? {};
|
|
175
|
-
if (typeof opts !== 'object' || Array.isArray(opts))
|
|
176
|
-
|
|
422
|
+
if (typeof opts !== 'object' || Array.isArray(opts))
|
|
423
|
+
throw new Error(
|
|
424
|
+
`frame is { "supports", "limit", "points", "rack", "cut", "heat", "printed", "size" } (got ${shown(opts)})`,
|
|
425
|
+
);
|
|
426
|
+
for (const k of Object.keys(opts))
|
|
427
|
+
if (!['supports', 'limit', 'points', 'rack', 'cut', 'heat', 'printed', 'size'].includes(k))
|
|
428
|
+
throw new Error(`frame has no "${k}": it takes supports, limit, points, rack, cut, heat, printed, size`);
|
|
177
429
|
printedOption(opts.printed);
|
|
178
430
|
if (opts.rack != null) {
|
|
179
|
-
if (typeof opts.rack !== 'object' || Array.isArray(opts.rack))
|
|
180
|
-
|
|
181
|
-
|
|
431
|
+
if (typeof opts.rack !== 'object' || Array.isArray(opts.rack))
|
|
432
|
+
throw new Error(
|
|
433
|
+
`frame.rack is { "load": 20, "limit": 1 }: the side push in N and the sway allowed in mm (got ${shown(opts.rack)})`,
|
|
434
|
+
);
|
|
435
|
+
for (const k of Object.keys(opts.rack))
|
|
436
|
+
if (!['load', 'limit'].includes(k)) throw new Error(`frame.rack has no "${k}": it takes load (N) and limit (mm)`);
|
|
437
|
+
for (const k of ['load', 'limit'])
|
|
438
|
+
if (opts.rack[k] != null && !(s.num(opts.rack[k]) > 0))
|
|
439
|
+
throw new Error(
|
|
440
|
+
`frame.rack.${k} is ${k === 'load' ? 'the side push in N' : 'the sway allowed in mm'}, above 0 (got ${shown(opts.rack[k])})`,
|
|
441
|
+
);
|
|
182
442
|
}
|
|
183
|
-
const byChild = new Map(motion.joints.map((j) => [j.child, j])),
|
|
184
|
-
|
|
185
|
-
const
|
|
443
|
+
const byChild = new Map(motion.joints.map((j) => [j.child, j])),
|
|
444
|
+
moving = (j) => !j.at && j.type !== 'fixed';
|
|
445
|
+
const movesWith = (k) => {
|
|
446
|
+
for (let i = k, n = 0; n < 99; n++) {
|
|
447
|
+
const j = byChild.get(i);
|
|
448
|
+
if (!j) return false;
|
|
449
|
+
if (moving(j)) return true;
|
|
450
|
+
i = j.parent;
|
|
451
|
+
}
|
|
452
|
+
return false;
|
|
453
|
+
};
|
|
454
|
+
const down = (() => {
|
|
455
|
+
const g = motion.gravity || [0, 0, -1],
|
|
456
|
+
l = Math.hypot(...g) || 1;
|
|
457
|
+
return g.map((c) => c / l);
|
|
458
|
+
})();
|
|
186
459
|
// the beams: still ones only (a beam on a carriage is a load, not the frame: its weight is carried below)
|
|
187
|
-
const beams = new Map(),
|
|
460
|
+
const beams = new Map(),
|
|
461
|
+
left = [],
|
|
462
|
+
riding = [],
|
|
463
|
+
loose = [];
|
|
188
464
|
for (const o of s.objects) {
|
|
189
465
|
if (!o.beam || o.unplaced) continue;
|
|
190
466
|
const k = ids.indexOf(o.id);
|
|
191
467
|
if (k < 0) continue;
|
|
192
|
-
if (movesWith(k)) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
468
|
+
if (movesWith(k)) {
|
|
469
|
+
riding.push({ o, k });
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
const W = worlds[k],
|
|
473
|
+
m = o.beam,
|
|
474
|
+
L = m.length,
|
|
475
|
+
A = rowsAt(W, [0, 0, 0]),
|
|
476
|
+
u = [W[2], W[6], W[10]],
|
|
477
|
+
top = [W[1], W[5], W[9]];
|
|
478
|
+
const mat = m.profile.material,
|
|
479
|
+
F = m.figures,
|
|
480
|
+
E = m.material?.modulus ?? mat?.modulus,
|
|
481
|
+
nu = mat?.poisson ?? mat?.figures?.poisson?.value;
|
|
482
|
+
const Gs = mat?.figures?.shear_modulus?.value ?? (E && nu != null ? E / (2 * (1 + nu)) : null),
|
|
483
|
+
grams = m.weight?.sheet ?? m.mass ?? 0;
|
|
196
484
|
// a printed beam's strength is the plastic's for its pose: along its layers lying down, across them standing up
|
|
197
485
|
const strength = m.printed?.strength ?? mat?.strength ?? mat?.figures?.strength?.value ?? null;
|
|
198
|
-
beams.set(o.id, {
|
|
199
|
-
|
|
486
|
+
beams.set(o.id, {
|
|
487
|
+
id: o.id,
|
|
488
|
+
k,
|
|
489
|
+
m,
|
|
490
|
+
L,
|
|
491
|
+
W,
|
|
492
|
+
A,
|
|
493
|
+
u,
|
|
494
|
+
top,
|
|
495
|
+
E,
|
|
496
|
+
G: Gs,
|
|
497
|
+
strength,
|
|
498
|
+
alloy: m.material?.name ?? mat?.name ?? null,
|
|
499
|
+
grams,
|
|
500
|
+
section: {
|
|
501
|
+
A: F.area.value,
|
|
502
|
+
Iy: F.inertiaX.value,
|
|
503
|
+
Iz: F.inertiaY.value,
|
|
504
|
+
J: F.torsion.value,
|
|
505
|
+
Wy: F.modulusX.value,
|
|
506
|
+
Wz: F.modulusY.value,
|
|
507
|
+
},
|
|
508
|
+
stations: new Set([0, L]),
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
const missing = [...beams.values()]
|
|
512
|
+
.filter((b) => !(b.E > 0 && b.G > 0 && b.section.Iy > 0 && b.section.J > 0))
|
|
513
|
+
.map((b) => b.id);
|
|
514
|
+
for (const id of missing) {
|
|
515
|
+
beams.delete(id);
|
|
516
|
+
left.push(id);
|
|
200
517
|
}
|
|
201
|
-
const missing = [...beams.values()].filter((b) => !(b.E > 0 && b.G > 0 && b.section.Iy > 0 && b.section.J > 0)).map((b) => b.id);
|
|
202
|
-
for (const id of missing) { beams.delete(id); left.push(id); }
|
|
203
518
|
if (!beams.size) return { beams, left, missing, empty: true };
|
|
204
|
-
const at = (b, z) => add(b.A, scale(b.u, z))
|
|
205
|
-
const snap = (b, z) => {
|
|
519
|
+
const at = (b, z) => add(b.A, scale(b.u, z));
|
|
520
|
+
const snap = (b, z) => {
|
|
521
|
+
for (const q of b.stations) if (Math.abs(q - z) < 0.05) return q;
|
|
522
|
+
b.stations.add(z);
|
|
523
|
+
return z;
|
|
524
|
+
};
|
|
206
525
|
// where an item's chain of mounts meets a still beam: that joint, and whether anything on the way moves
|
|
207
|
-
const mountOf = (k) => {
|
|
526
|
+
const mountOf = (k) => {
|
|
527
|
+
let mover = null;
|
|
528
|
+
for (let i = k, n = 0; n < 99; n++) {
|
|
529
|
+
const j = byChild.get(i);
|
|
530
|
+
if (!j) return null;
|
|
531
|
+
if (moving(j)) mover = mover ?? j;
|
|
532
|
+
if (beams.has(ids[j.parent])) return { beam: beams.get(ids[j.parent]), joint: j, mover };
|
|
533
|
+
i = j.parent;
|
|
534
|
+
}
|
|
535
|
+
return null;
|
|
536
|
+
};
|
|
208
537
|
// a mount's station on its beam at a set of joint values: a slide along the beam moves it
|
|
209
538
|
// (a beam a riding beam also rests on, parallel to its joint's beam: the same station there, turned by sign and moved by shift)
|
|
210
|
-
const mountStation = (mt, values) => {
|
|
539
|
+
const mountStation = (mt, values) => {
|
|
540
|
+
const j = mt.joint,
|
|
541
|
+
z = j.a[11],
|
|
542
|
+
v = j.type === 'prismatic' ? (values[j.id]?.[0] ?? 0) : 0;
|
|
543
|
+
return Math.max(0, Math.min(mt.beam.L, (mt.shift ?? 0) + (mt.sign ?? 1) * (z + v * j.a[10])));
|
|
544
|
+
};
|
|
211
545
|
|
|
212
546
|
// the beams a riding beam o (item k, its joint mt on a still beam) lies on: its joint's beam, at the joint's anchor
|
|
213
547
|
// along o, and one other still beam parallel to it, square to o, its axis as far below o's and under o's length.
|
|
214
548
|
// Each takes the share of o's weight the lever rule gives (o's weight at its middle); null where there is no other
|
|
215
549
|
// such beam, more than one, or o's middle is not between them (then its joint's beam carries it all)
|
|
216
550
|
const restsOn = (o, k, mt) => {
|
|
217
|
-
const W = worlds[k],
|
|
551
|
+
const W = worlds[k],
|
|
552
|
+
u = [W[2], W[6], W[10]],
|
|
553
|
+
O = rowsAt(W, [0, 0, 0]),
|
|
554
|
+
L = o.beam.length,
|
|
555
|
+
T = mt.beam;
|
|
218
556
|
if (Math.abs(dot(u, T.u)) > 1e-3) return null;
|
|
219
|
-
const s1 = mt.joint.b[11],
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
557
|
+
const s1 = mt.joint.b[11],
|
|
558
|
+
P1 = rowsAt(W, [0, 0, s1]),
|
|
559
|
+
drop = dot(sub(add(T.A, scale(T.u, dot(sub(P1, T.A), T.u))), P1), down);
|
|
560
|
+
const others = [...beams.values()]
|
|
561
|
+
.filter((b) => b !== T && Math.abs(Math.abs(dot(b.u, T.u)) - 1) < 1e-6)
|
|
562
|
+
.map((b) => {
|
|
563
|
+
const s2 = dot(sub(b.A, O), u),
|
|
564
|
+
P2 = add(O, scale(u, s2)),
|
|
565
|
+
foot = add(b.A, scale(b.u, dot(sub(P2, b.A), b.u)));
|
|
566
|
+
return {
|
|
567
|
+
b,
|
|
568
|
+
s2,
|
|
569
|
+
gap: Math.hypot(...sub(sub(foot, P2), scale(down, dot(sub(foot, P2), down)))),
|
|
570
|
+
drop: dot(sub(foot, P2), down),
|
|
571
|
+
};
|
|
572
|
+
})
|
|
573
|
+
.filter(
|
|
574
|
+
(x) => x.s2 >= -1e-6 && x.s2 <= L + 1e-6 && Math.abs(x.s2 - s1) > 1 && x.gap < 1 && Math.abs(x.drop - drop) < 1,
|
|
575
|
+
);
|
|
224
576
|
if (others.length !== 1) return null;
|
|
225
|
-
const { b, s2 } = others[0],
|
|
577
|
+
const { b, s2 } = others[0],
|
|
578
|
+
c = L / 2,
|
|
579
|
+
p1 = (s2 - c) / (s2 - s1);
|
|
226
580
|
if (!(p1 >= 0 && p1 <= 1)) return null;
|
|
227
|
-
const sign = Math.sign(dot(b.u, T.u)),
|
|
228
|
-
|
|
581
|
+
const sign = Math.sign(dot(b.u, T.u)),
|
|
582
|
+
shift = dot(sub(T.A, b.A), b.u);
|
|
583
|
+
return [
|
|
584
|
+
{ mount: mt, part: p1, s: s1 },
|
|
585
|
+
{ mount: { ...mt, beam: b, sign, shift }, part: 1 - p1, s: s2 },
|
|
586
|
+
];
|
|
229
587
|
};
|
|
230
588
|
|
|
231
589
|
// the poses: as drawn, each named pose, and each moving joint mounted on a beam swept through its travel: each end and
|
|
232
590
|
// frame.sweep steps between (a step where it is drawn is the drawn pose)
|
|
233
591
|
const poses = [{ label: 'as drawn', values: base }];
|
|
234
592
|
for (const p of Object.keys(motion.poses || {})) poses.push({ label: `pose ${p}`, values: jointValues(motion, p) });
|
|
235
|
-
const movers = motion.joints.filter((j) => moving(j) && beams.has(ids[j.parent]) && j.dofs?.length === 1),
|
|
593
|
+
const movers = motion.joints.filter((j) => moving(j) && beams.has(ids[j.parent]) && j.dofs?.length === 1),
|
|
594
|
+
steps = FRAME_CHECK.sweep.value;
|
|
236
595
|
for (const j of movers) {
|
|
237
|
-
const [lo, hi] = j.dofs[0],
|
|
238
|
-
|
|
596
|
+
const [lo, hi] = j.dofs[0],
|
|
597
|
+
drawn = base[j.id]?.[0],
|
|
598
|
+
between = Array.from({ length: steps - 1 }, (_, k) => lo + ((hi - lo) * (k + 1)) / steps).filter(
|
|
599
|
+
(v) => !(drawn != null && Math.abs(drawn - v) < 1e-6),
|
|
600
|
+
);
|
|
601
|
+
for (const v of [lo, hi, ...between])
|
|
602
|
+
poses.push({ label: `${j.id} at ${n3(v, 1)}`, values: { ...base, [j.id]: [v] } });
|
|
239
603
|
}
|
|
240
604
|
// and swept together (frame.together): every combination of their steps, else of their ends and middles, else all at
|
|
241
605
|
// one share of their travel at once and their ends combined; a combination already solved is not solved again
|
|
242
606
|
const together = { joints: movers.map((j) => j.id), how: null };
|
|
243
607
|
if (movers.length > 1) {
|
|
244
|
-
const cap = FRAME_CHECK.together.value,
|
|
245
|
-
|
|
608
|
+
const cap = FRAME_CHECK.together.value,
|
|
609
|
+
at = (j, share) => j.dofs[0][0] + (j.dofs[0][1] - j.dofs[0][0]) * share;
|
|
610
|
+
const shares = (n) => Array.from({ length: n + 1 }, (_, k) => k / n),
|
|
611
|
+
grid = (sh) => movers.reduce((acc, j) => acc.flatMap((c) => sh.map((x) => [...c, [j, at(j, x)]])), [[]]);
|
|
246
612
|
let combos;
|
|
247
|
-
if ((steps + 1) ** movers.length <= cap) {
|
|
248
|
-
|
|
249
|
-
|
|
613
|
+
if ((steps + 1) ** movers.length <= cap) {
|
|
614
|
+
combos = grid(shares(steps));
|
|
615
|
+
together.how = `every combination of their ${steps + 1} places each`;
|
|
616
|
+
} else if (3 ** movers.length <= cap) {
|
|
617
|
+
combos = grid(shares(2));
|
|
618
|
+
together.how = 'every combination of their ends and middles';
|
|
619
|
+
} else {
|
|
250
620
|
combos = shares(steps).map((x) => movers.map((j) => [j, at(j, x)]));
|
|
251
621
|
if (2 ** movers.length <= cap) combos.push(...grid([0, 1]));
|
|
252
622
|
together.how = `all at one share of their travel at once, in ${steps} steps${2 ** movers.length <= cap ? ', and their ends in every combination' : ''} (too many joints to combine every place: ${3 ** movers.length} poses for their ends and middles alone)`;
|
|
@@ -256,7 +626,10 @@ export function frameModelOf(s, helpers) {
|
|
|
256
626
|
const key = JSON.stringify(c.map(([, v]) => r3(v)));
|
|
257
627
|
if (seen.has(key)) continue;
|
|
258
628
|
seen.add(key);
|
|
259
|
-
poses.push({
|
|
629
|
+
poses.push({
|
|
630
|
+
label: c.map(([j, v]) => `${j.id} at ${n3(v, 1)}`).join(', '),
|
|
631
|
+
values: { ...base, ...Object.fromEntries(c.map(([j, v]) => [j.id, [v]])) },
|
|
632
|
+
});
|
|
260
633
|
}
|
|
261
634
|
}
|
|
262
635
|
// what a joint must push or turn against ("loads" on joints: a force on a slide, a torque on a hinge, and a belt's
|
|
@@ -266,10 +639,21 @@ export function frameModelOf(s, helpers) {
|
|
|
266
639
|
const onJoints = [];
|
|
267
640
|
for (const l of motion.loads || []) {
|
|
268
641
|
if (l.joint == null || l.beltWeight || !(Math.abs(l.value) > 0)) continue;
|
|
269
|
-
const j = motion.joints.find((x) => x.id === l.joint),
|
|
642
|
+
const j = motion.joints.find((x) => x.id === l.joint),
|
|
643
|
+
mt = j ? mountOf(j.child) : null;
|
|
270
644
|
if (!j) continue;
|
|
271
|
-
if (!mt) {
|
|
272
|
-
|
|
645
|
+
if (!mt) {
|
|
646
|
+
loose.push(`the load on ${j.id}`);
|
|
647
|
+
continue;
|
|
648
|
+
}
|
|
649
|
+
onJoints.push({
|
|
650
|
+
joint: j,
|
|
651
|
+
value: Math.abs(l.value),
|
|
652
|
+
unit: j.type === 'prismatic' ? 'N' : 'N m',
|
|
653
|
+
note: l.note ?? null,
|
|
654
|
+
belt: l.belt ?? null,
|
|
655
|
+
mount: mt,
|
|
656
|
+
});
|
|
273
657
|
}
|
|
274
658
|
// a motor turning a joint mounted on a beam, the motor itself on a still beam: what it does to the frame. Driving a
|
|
275
659
|
// hinge, the torque it turns the arm with is held at its own mount (the arm's inertia pushes back through it): its
|
|
@@ -279,32 +663,104 @@ export function frameModelOf(s, helpers) {
|
|
|
279
663
|
const stalls = [];
|
|
280
664
|
for (const d of motion.drives || []) {
|
|
281
665
|
if (!d.joint) continue;
|
|
282
|
-
const fg = (x) => d.model?.figures?.[x]?.value,
|
|
283
|
-
|
|
284
|
-
|
|
666
|
+
const fg = (x) => d.model?.figures?.[x]?.value,
|
|
667
|
+
hold = atCurrent(d.model, d.spec, fg('holding_torque') ?? fg('stall_torque') ?? 0);
|
|
668
|
+
for (const j of motion.joints.filter(
|
|
669
|
+
(x) => moving(x) && x.dofs?.length === 1 && !motion.joints.some((y) => y.follow?.[0] === x.id),
|
|
670
|
+
)) {
|
|
671
|
+
let t;
|
|
672
|
+
try {
|
|
673
|
+
t = trainFrom(motion, j.id);
|
|
674
|
+
} catch {
|
|
675
|
+
continue;
|
|
676
|
+
}
|
|
285
677
|
if (t.root !== d.joint) continue;
|
|
286
|
-
const mt = mountOf(j.child),
|
|
678
|
+
const mt = mountOf(j.child),
|
|
679
|
+
mm = mountOf(d.item);
|
|
287
680
|
if (!mt) continue;
|
|
288
|
-
if (!mm || mm.mover) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
681
|
+
if (!mm || mm.mover) {
|
|
682
|
+
loose.push(`${d.id}'s push on ${j.id} (the motor moves with what it drives, or is on no beam)`);
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
const out = (T) =>
|
|
686
|
+
t.slide != null
|
|
687
|
+
? (T * t.ratio * t.efficiency * 1000 * Math.PI) / (180 * t.slide)
|
|
688
|
+
: T * t.ratio * t.efficiency,
|
|
689
|
+
unit = t.slide != null ? 'N' : 'N m';
|
|
690
|
+
if (j.type === 'revolute') {
|
|
691
|
+
let avail = 0;
|
|
692
|
+
try {
|
|
693
|
+
avail = mountTorque(d);
|
|
694
|
+
} catch {
|
|
695
|
+
avail = 0;
|
|
696
|
+
}
|
|
697
|
+
if (avail > 0)
|
|
698
|
+
onJoints.push({
|
|
699
|
+
joint: j,
|
|
700
|
+
value: out(avail),
|
|
701
|
+
unit,
|
|
702
|
+
note: `${d.id}'s reaction, the most torque it turns ${j.id} with`,
|
|
703
|
+
belt: null,
|
|
704
|
+
mount: mm,
|
|
705
|
+
motor: d.id,
|
|
706
|
+
});
|
|
707
|
+
}
|
|
708
|
+
if (hold > 0)
|
|
709
|
+
for (const [end, sign] of [
|
|
710
|
+
[j.dofs[0][0], -1],
|
|
711
|
+
[j.dofs[0][1], 1],
|
|
712
|
+
])
|
|
713
|
+
stalls.push({
|
|
714
|
+
joint: j,
|
|
715
|
+
motor: d.id,
|
|
716
|
+
value: out(hold),
|
|
717
|
+
unit,
|
|
718
|
+
sign,
|
|
719
|
+
end,
|
|
720
|
+
mount: mt,
|
|
721
|
+
motorMount: mm,
|
|
722
|
+
hold,
|
|
723
|
+
label: `${j.id} at ${n3(end, 1)}, ${d.id} stalled against its stop`,
|
|
724
|
+
});
|
|
292
725
|
}
|
|
293
726
|
}
|
|
294
|
-
const cases = [
|
|
295
|
-
...
|
|
727
|
+
const cases = [
|
|
728
|
+
...(onJoints.length
|
|
729
|
+
? poses.flatMap((c) => [
|
|
730
|
+
{ ...c, label: `${c.label}, joint loads +`, push: 1 },
|
|
731
|
+
{ ...c, label: `${c.label}, joint loads -`, push: -1 },
|
|
732
|
+
])
|
|
733
|
+
: poses),
|
|
734
|
+
...stalls.map((x) => ({ label: x.label, values: { ...base, [x.joint.id]: [x.end] }, stall: x })),
|
|
735
|
+
];
|
|
296
736
|
|
|
297
737
|
// what weighs on the frame: items (beams' own weight is the elements'), and the masses of "loads"
|
|
298
|
-
const masses = massesOf(s, { placeItems, jointValues }),
|
|
738
|
+
const masses = massesOf(s, { placeItems, jointValues }),
|
|
739
|
+
carried = [],
|
|
740
|
+
unknown = [];
|
|
299
741
|
// a panel (not a door) on a bay of frame beams is a shear web of the frame: its weight goes to its bay's corners; on
|
|
300
742
|
// beams that make no bay, its weight is spread along those of the frame
|
|
301
|
-
const sheets = (s.panels ?? [])
|
|
743
|
+
const sheets = (s.panels ?? [])
|
|
744
|
+
.filter((p) => !p.door && p.bay?.some((id) => beams.has(id)))
|
|
745
|
+
.map((p) => ({ ...p, kg: (p.model?.grams ?? 0) / 1000 }));
|
|
302
746
|
for (const q of masses) {
|
|
303
|
-
if (
|
|
304
|
-
|
|
747
|
+
if (
|
|
748
|
+
beams.has(q.id) ||
|
|
749
|
+
left.includes(q.id) ||
|
|
750
|
+
riding.some((x) => x.o.id === q.id) ||
|
|
751
|
+
sheets.some((p) => p.id === q.id)
|
|
752
|
+
)
|
|
753
|
+
continue;
|
|
754
|
+
if (!q.known) {
|
|
755
|
+
unknown.push(q.id);
|
|
756
|
+
continue;
|
|
757
|
+
}
|
|
305
758
|
if (!(q.kg > 0)) continue;
|
|
306
759
|
const mt = mountOf(q.item);
|
|
307
|
-
if (!mt) {
|
|
760
|
+
if (!mt) {
|
|
761
|
+
loose.push(q.id);
|
|
762
|
+
continue;
|
|
763
|
+
}
|
|
308
764
|
carried.push({ id: q.id, item: q.item, kg: q.kg, centre: q.centre, mount: mt });
|
|
309
765
|
}
|
|
310
766
|
// a beam riding a moving joint (a gantry's cross beam on its carriages): its sheet's weight at its middle, carried
|
|
@@ -313,125 +769,292 @@ export function frameModelOf(s, helpers) {
|
|
|
313
769
|
// though its joint is on one: its weight is shared between them by the lever rule, as a beam on two supports
|
|
314
770
|
const rides = [];
|
|
315
771
|
for (const { o, k } of riding) {
|
|
316
|
-
const kg = (o.beam.weight?.sheet ?? o.beam.mass ?? 0) / 1000,
|
|
317
|
-
|
|
318
|
-
|
|
772
|
+
const kg = (o.beam.weight?.sheet ?? o.beam.mass ?? 0) / 1000,
|
|
773
|
+
mt = mountOf(k),
|
|
774
|
+
on = byChild.get(k);
|
|
775
|
+
if (!(kg > 0)) {
|
|
776
|
+
unknown.push(o.id);
|
|
777
|
+
continue;
|
|
778
|
+
}
|
|
779
|
+
if (!mt) {
|
|
780
|
+
loose.push(o.id);
|
|
781
|
+
continue;
|
|
782
|
+
}
|
|
319
783
|
const share = mt.joint.child === k ? restsOn(o, k, mt) : null;
|
|
320
|
-
if (share)
|
|
784
|
+
if (share)
|
|
785
|
+
for (const x of share) carried.push({ id: o.id, item: k, kg: kg * x.part, centre: [0, 0, x.s], mount: x.mount });
|
|
321
786
|
else carried.push({ id: o.id, item: k, kg, centre: [0, 0, o.beam.length / 2], mount: mt });
|
|
322
|
-
rides.push({
|
|
787
|
+
rides.push({
|
|
788
|
+
id: o.id,
|
|
789
|
+
joint: (mt.mover ?? on)?.id ?? null,
|
|
790
|
+
kg,
|
|
791
|
+
on: share ? share.map((x) => ({ beam: x.mount.beam.id, share: x.part })) : [{ beam: mt.beam.id, share: 1 }],
|
|
792
|
+
});
|
|
323
793
|
}
|
|
324
794
|
const loads = [];
|
|
325
795
|
(motion.loads || []).forEach((l, i) => {
|
|
326
796
|
if (l.mass == null) return;
|
|
327
|
-
const said = s.a.loads?.[i]?.at,
|
|
328
|
-
|
|
797
|
+
const said = s.a.loads?.[i]?.at,
|
|
798
|
+
where =
|
|
799
|
+
typeof said === 'string'
|
|
800
|
+
? said
|
|
801
|
+
: said?.item
|
|
802
|
+
? `${said.item}${said.at ? ` at (${said.at.map((x) => n3(s.num(x), 1)).join(', ')})` : ''}`
|
|
803
|
+
: ids[l.item],
|
|
804
|
+
point = [l.frame[3], l.frame[7], l.frame[11]];
|
|
805
|
+
if (beams.has(ids[l.item])) {
|
|
806
|
+
const b = beams.get(ids[l.item]);
|
|
807
|
+
loads.push({
|
|
808
|
+
index: i,
|
|
809
|
+
kg: l.mass,
|
|
810
|
+
where,
|
|
811
|
+
item: l.item,
|
|
812
|
+
point,
|
|
813
|
+
beam: b,
|
|
814
|
+
z: snap(b, Math.max(0, Math.min(b.L, point[2]))),
|
|
815
|
+
note: l.note,
|
|
816
|
+
});
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
329
819
|
const mt = mountOf(l.item);
|
|
330
|
-
if (!mt) {
|
|
820
|
+
if (!mt) {
|
|
821
|
+
loose.push(`load ${i + 1} (${where})`);
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
331
824
|
loads.push({ index: i, kg: l.mass, where, item: l.item, point, mount: mt, note: l.note });
|
|
332
825
|
});
|
|
333
|
-
for (const c of [...carried, ...loads.filter((l) => l.mount), ...onJoints])
|
|
334
|
-
|
|
826
|
+
for (const c of [...carried, ...loads.filter((l) => l.mount), ...onJoints])
|
|
827
|
+
for (const cs of poses) snap(c.mount.beam, mountStation(c.mount, cs.values));
|
|
828
|
+
for (const x of stalls) {
|
|
829
|
+
const v = { ...base, [x.joint.id]: [x.end] };
|
|
830
|
+
snap(x.mount.beam, mountStation(x.mount, v));
|
|
831
|
+
snap(x.motorMount.beam, mountStation(x.motorMount, v));
|
|
832
|
+
}
|
|
335
833
|
// named points, and every guide's travel
|
|
336
834
|
const points = (opts.points ?? []).map((p, i) => {
|
|
337
|
-
const t = String(p),
|
|
338
|
-
|
|
835
|
+
const t = String(p),
|
|
836
|
+
id = t.split('.')[0],
|
|
837
|
+
b = beams.get(id);
|
|
838
|
+
if (!b)
|
|
839
|
+
throw new Error(
|
|
840
|
+
`frame.points ${i + 1}: ${shown(p)} is on a beam of the frame, as x1.top@50% (beams: ${[...beams.keys()].join(', ')})`,
|
|
841
|
+
);
|
|
339
842
|
const r = motion.address(t, `frame.points ${i + 1}`);
|
|
340
843
|
return { where: t, beam: b, z: snap(b, Math.max(0, Math.min(b.L, r.frame[11]))) };
|
|
341
844
|
});
|
|
342
|
-
const guides = (s.guides || [])
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
845
|
+
const guides = (s.guides || [])
|
|
846
|
+
.filter((g) => beams.has(g.beam))
|
|
847
|
+
.map((g) => {
|
|
848
|
+
const b = beams.get(g.beam),
|
|
849
|
+
from = Math.max(0, g.from),
|
|
850
|
+
to = Math.min(b.L, g.from + g.length);
|
|
851
|
+
snap(b, from);
|
|
852
|
+
snap(b, to);
|
|
853
|
+
snap(b, (from + to) / 2);
|
|
854
|
+
return {
|
|
855
|
+
id: g.id,
|
|
856
|
+
kind: g.kind,
|
|
857
|
+
beam: b,
|
|
858
|
+
from,
|
|
859
|
+
to,
|
|
860
|
+
tolerance: (g.terms ?? g.model?.terms ?? []).find((x) => x.term === 'rail parallelism') ?? null,
|
|
861
|
+
};
|
|
862
|
+
});
|
|
347
863
|
|
|
348
864
|
// supports
|
|
349
865
|
const supports = [];
|
|
350
866
|
if (opts.supports != null) {
|
|
351
|
-
if (typeof opts.supports !== 'object' || Array.isArray(opts.supports))
|
|
352
|
-
|
|
867
|
+
if (typeof opts.supports !== 'object' || Array.isArray(opts.supports))
|
|
868
|
+
throw new Error(`frame.supports is { "z1.a": "pinned", "z2.a": "fixed" } (got ${shown(opts.supports)})`);
|
|
869
|
+
if (!Object.keys(opts.supports).length)
|
|
870
|
+
throw new Error(
|
|
871
|
+
'frame.supports names no support: give at least one place the frame is held, as { "z1.a": "pinned" }, or leave supports out to stand the frame on its feet or its lowest ends',
|
|
872
|
+
);
|
|
353
873
|
for (const [addr, how] of Object.entries(opts.supports)) {
|
|
354
|
-
const id = addr.split('.')[0],
|
|
355
|
-
|
|
356
|
-
if (!
|
|
874
|
+
const id = addr.split('.')[0],
|
|
875
|
+
b = beams.get(id);
|
|
876
|
+
if (!b)
|
|
877
|
+
throw new Error(
|
|
878
|
+
`frame.supports: "${addr}" is on a beam of the frame, as z1.a or x1.bottom@50% (beams: ${[...beams.keys()].join(', ')})`,
|
|
879
|
+
);
|
|
880
|
+
if (!['pinned', 'fixed', 'resting'].includes(how))
|
|
881
|
+
throw new Error(
|
|
882
|
+
`frame.supports: "${addr}" is held pinned (from moving), fixed (from turning too) or resting (from moving and from twisting about the beam's length: a beam lying across a round bar) (got ${shown(how)})`,
|
|
883
|
+
);
|
|
357
884
|
const k = b.u.findIndex((c) => Math.abs(Math.abs(c) - 1) < 1e-6);
|
|
358
|
-
if (how === 'resting' && k < 0)
|
|
885
|
+
if (how === 'resting' && k < 0)
|
|
886
|
+
throw new Error(
|
|
887
|
+
`frame.supports: "${addr}" rests on a bar, held from twisting about its length, and ${id} does not run along x, y or z: hold it pinned or fixed`,
|
|
888
|
+
);
|
|
359
889
|
const r = motion.address(addr, 'frame.supports');
|
|
360
|
-
supports.push({
|
|
890
|
+
supports.push({
|
|
891
|
+
where: addr,
|
|
892
|
+
beam: b,
|
|
893
|
+
z: snap(b, Math.max(0, Math.min(b.L, r.frame[11]))),
|
|
894
|
+
how,
|
|
895
|
+
why: 'frame.supports',
|
|
896
|
+
said: true,
|
|
897
|
+
...(how === 'resting' ? { twist: `r${'xyz'[k]}` } : {}),
|
|
898
|
+
});
|
|
361
899
|
}
|
|
362
900
|
} else {
|
|
363
901
|
for (const it of s.a.items || []) {
|
|
364
|
-
const kind = it.fitting?.kind ?? (it.bought && /foot|castor/i.test(it.bought) ? 'foot' : null),
|
|
902
|
+
const kind = it.fitting?.kind ?? (it.bought && /foot|castor/i.test(it.bought) ? 'foot' : null),
|
|
903
|
+
m = typeof it.at === 'string' ? /^([\w-]+)\.([ab])(\.\d+)?$/.exec(it.at.trim()) : null;
|
|
365
904
|
if (!m || !FEET.includes(kind) || !beams.has(m[1])) continue;
|
|
366
905
|
const b = beams.get(m[1]);
|
|
367
|
-
if (!supports.some((x) => x.beam === b && x.z === (m[2] === 'a' ? 0 : b.L)))
|
|
906
|
+
if (!supports.some((x) => x.beam === b && x.z === (m[2] === 'a' ? 0 : b.L)))
|
|
907
|
+
supports.push({
|
|
908
|
+
where: `${m[1]}.${m[2]}`,
|
|
909
|
+
beam: b,
|
|
910
|
+
z: m[2] === 'a' ? 0 : b.L,
|
|
911
|
+
how: 'pinned',
|
|
912
|
+
why: `${it.id}, a ${kind}`,
|
|
913
|
+
});
|
|
368
914
|
}
|
|
369
915
|
if (!supports.length) {
|
|
370
|
-
const ends = [...beams.values()].flatMap((b) =>
|
|
916
|
+
const ends = [...beams.values()].flatMap((b) =>
|
|
917
|
+
[
|
|
918
|
+
['a', 0],
|
|
919
|
+
['b', b.L],
|
|
920
|
+
].map(([e, z]) => ({ b, e, z, h: -dot(at(b, z), down) })),
|
|
921
|
+
);
|
|
371
922
|
const low = Math.min(...ends.map((x) => x.h));
|
|
372
|
-
for (const x of ends)
|
|
923
|
+
for (const x of ends)
|
|
924
|
+
if (x.h <= low + 1)
|
|
925
|
+
supports.push({ where: `${x.b.id}.${x.e}`, beam: x.b, z: x.z, how: 'pinned', why: 'a lowest end' });
|
|
373
926
|
}
|
|
374
927
|
}
|
|
375
928
|
|
|
376
929
|
// joins between beams of the frame
|
|
377
930
|
const joins = [];
|
|
378
931
|
for (const j of s.joins || []) {
|
|
379
|
-
const [ai, bi] = j.items,
|
|
932
|
+
const [ai, bi] = j.items,
|
|
933
|
+
A = beams.get(ai),
|
|
934
|
+
B = beams.get(bi);
|
|
380
935
|
if (!A || !B) continue;
|
|
381
|
-
const e = j.end[0],
|
|
936
|
+
const e = j.end[0],
|
|
937
|
+
zb = j.model.b.end != null ? (j.model.b.end === 'a' ? 0 : B.L) : j.model.b.distance;
|
|
382
938
|
joins.push({ j, A, B, e, za: e === 'a' ? 0 : A.L, zb: snap(B, zb), k: j.model.stiffness });
|
|
383
939
|
}
|
|
384
940
|
// only what a support holds through joins: the rest is left out, by name
|
|
385
|
-
const group = new Map([...beams.keys()].map((id) => [id, id])),
|
|
941
|
+
const group = new Map([...beams.keys()].map((id) => [id, id])),
|
|
942
|
+
root = (x) => {
|
|
943
|
+
while (group.get(x) !== x) x = group.get(x);
|
|
944
|
+
return x;
|
|
945
|
+
};
|
|
386
946
|
for (const x of joins) group.set(root(x.A.id), root(x.B.id));
|
|
387
947
|
const held = new Set(supports.map((x) => root(x.beam.id)));
|
|
388
|
-
for (const id of [...beams.keys()])
|
|
948
|
+
for (const id of [...beams.keys()])
|
|
949
|
+
if (!held.has(root(id))) {
|
|
950
|
+
left.push(id);
|
|
951
|
+
beams.delete(id);
|
|
952
|
+
}
|
|
389
953
|
const keep = (x) => beams.has(x.beam?.id ?? x.mount?.beam.id);
|
|
390
954
|
|
|
391
955
|
// nodes and elements
|
|
392
|
-
const nodes = {},
|
|
956
|
+
const nodes = {},
|
|
957
|
+
elements = [],
|
|
958
|
+
sections = {},
|
|
959
|
+
materials = {},
|
|
960
|
+
nameAt = new Map();
|
|
393
961
|
const nodeName = (b, z) => (z === 0 ? `${b.id}.a` : z === b.L ? `${b.id}.b` : `${b.id}@${n3(z)}`);
|
|
394
962
|
let stiffest = 0;
|
|
395
963
|
for (const b of beams.values()) {
|
|
396
964
|
const zs = [...b.stations].sort((p, q) => p - q);
|
|
397
|
-
for (const z of zs) {
|
|
965
|
+
for (const z of zs) {
|
|
966
|
+
const n = nodeName(b, z);
|
|
967
|
+
nodes[n] = at(b, z);
|
|
968
|
+
nameAt.set(`${b.id}|${z}`, n);
|
|
969
|
+
}
|
|
398
970
|
sections[b.id] = b.section;
|
|
399
|
-
materials[b.id] = { E: b.E, G: b.G, density: b.grams > 0 ?
|
|
971
|
+
materials[b.id] = { E: b.E, G: b.G, density: b.grams > 0 ? b.grams / 1000 / b.L / (b.section.A * 1e-6) : 0 };
|
|
400
972
|
stiffest = Math.max(stiffest, b.E * Math.max(b.section.Iy, b.section.Iz), b.E * b.section.A);
|
|
401
|
-
for (let i = 0; i + 1 < zs.length; i++)
|
|
973
|
+
for (let i = 0; i + 1 < zs.length; i++)
|
|
974
|
+
elements.push({
|
|
975
|
+
id: `${b.id}#${i + 1}`,
|
|
976
|
+
of: b.id,
|
|
977
|
+
a: nodeName(b, zs[i]),
|
|
978
|
+
b: nodeName(b, zs[i + 1]),
|
|
979
|
+
section: b.id,
|
|
980
|
+
material: b.id,
|
|
981
|
+
up: b.top,
|
|
982
|
+
});
|
|
402
983
|
}
|
|
403
|
-
const nodeAt = (b, z) => {
|
|
404
|
-
|
|
984
|
+
const nodeAt = (b, z) => {
|
|
985
|
+
for (const q of b.stations) if (Math.abs(q - z) < 0.05) return nameAt.get(`${b.id}|${q}`);
|
|
986
|
+
return undefined;
|
|
987
|
+
};
|
|
988
|
+
const big = FRAME_CHECK.link.value,
|
|
989
|
+
rigidE = (stiffest * big) / 1e6;
|
|
405
990
|
materials.link = { E: rigidE, G: rigidE / 2.6 };
|
|
406
991
|
sections.link = { A: 1e6 / 1e3, Iy: 1e6, Iz: 1e6, J: 1e6 }; // (E × these: the link a thousand times the stiffest beam's EI and EA)
|
|
407
992
|
const springs = [];
|
|
408
993
|
for (const x of joins) {
|
|
409
994
|
if (!beams.has(x.A.id)) continue;
|
|
410
|
-
const an = nodeAt(x.A, x.za),
|
|
411
|
-
|
|
995
|
+
const an = nodeAt(x.A, x.za),
|
|
996
|
+
bn = nodeAt(x.B, x.zb),
|
|
997
|
+
gap = Math.hypot(...sub(nodes[an], nodes[bn]));
|
|
998
|
+
// (one rigid link from b's place to a's end, however many joins hold that end there: a brace beside a blind join)
|
|
999
|
+
if (gap > 1e-6 && !elements.some((q) => q.section === 'link' && q.a === bn && q.b === an))
|
|
1000
|
+
elements.push({ id: `join ${x.j.index + 1}`, a: bn, b: an, section: 'link', material: 'link' });
|
|
412
1001
|
const el = elements.find((q) => q.of === x.A.id && (x.e === 'a' ? q.a === an : q.b === an));
|
|
413
1002
|
springs.push({ x, el, end: x.e === 'a' ? 'a' : 'b' });
|
|
414
1003
|
}
|
|
415
1004
|
// bays: four beams joined round a rectangle in one plane, two each way; each corner the node where two of their axes
|
|
416
1005
|
// cross (the station a join put on the beam it lands on)
|
|
417
|
-
const bays = baysOf(
|
|
1006
|
+
const bays = baysOf(
|
|
1007
|
+
beams,
|
|
1008
|
+
joins.filter((x) => beams.has(x.A.id) && beams.has(x.B.id)),
|
|
1009
|
+
nodes,
|
|
1010
|
+
nodeAt,
|
|
1011
|
+
);
|
|
418
1012
|
// each panel on a bay as a shear web: one diagonal bar, free to bend at both ends, as stiff along it as the sheet in shear in
|
|
419
1013
|
// series with its clips' grip
|
|
420
1014
|
// a panel whose beams make no bay (not joined round it) is no web, but it lies on its beams: its weight is spread
|
|
421
1015
|
// along each of them, a quarter each
|
|
422
|
-
const webs = [],
|
|
1016
|
+
const webs = [],
|
|
1017
|
+
heldSheets = [],
|
|
1018
|
+
laid = [];
|
|
423
1019
|
for (const p of sheets) {
|
|
424
1020
|
const bay = bays.find((b) => b.beams.length === p.bay.length && p.bay.every((id) => b.beams.includes(id)));
|
|
425
|
-
if (!bay) {
|
|
1021
|
+
if (!bay) {
|
|
1022
|
+
const on = p.bay.filter((id) => beams.has(id));
|
|
1023
|
+
if (p.kg > 0 && on.length) laid.push({ id: p.id, kg: p.kg, beams: on });
|
|
1024
|
+
else if (!on.length) loose.push(p.id);
|
|
1025
|
+
continue;
|
|
1026
|
+
}
|
|
426
1027
|
const w = webOf(bay, p.sheet, p.thickness, p.items.length, p.id);
|
|
427
|
-
webs.push(w);
|
|
1028
|
+
webs.push(w);
|
|
1029
|
+
heldSheets.push({ ...p, bay: bays.indexOf(bay) });
|
|
1030
|
+
elements.push(w.element);
|
|
428
1031
|
}
|
|
429
|
-
const supportMap = {},
|
|
1032
|
+
const supportMap = {},
|
|
1033
|
+
mapSupports = () => {
|
|
1034
|
+
for (const sp of supports.filter(keep))
|
|
1035
|
+
supportMap[nodeAt(sp.beam, sp.z)] =
|
|
1036
|
+
sp.how === 'fixed' ? 'fixed' : { x: true, y: true, z: true, ...(sp.twist ? { [sp.twist]: true } : {}) };
|
|
1037
|
+
};
|
|
430
1038
|
mapSupports();
|
|
431
1039
|
// (a freedom nothing holds, which the loads do not move, is held for the solve and named in frame.solve: a frame in
|
|
432
1040
|
// one plane on pinned feet sways out of it, a beam pinned at both ends spins on its axis)
|
|
433
|
-
const withSprings = (rigid) => ({
|
|
434
|
-
|
|
1041
|
+
const withSprings = (rigid) => ({
|
|
1042
|
+
nodes,
|
|
1043
|
+
sections,
|
|
1044
|
+
materials,
|
|
1045
|
+
supports: supportMap,
|
|
1046
|
+
gravity: scale(down, G),
|
|
1047
|
+
loose: 'hold',
|
|
1048
|
+
elements: elements.map((q) => {
|
|
1049
|
+
const sp = rigid ? [] : springs.filter((p) => p.el === q);
|
|
1050
|
+
return sp.length
|
|
1051
|
+
? {
|
|
1052
|
+
...q,
|
|
1053
|
+
ends: endSprings(sp.map((p) => ({ end: p.end, k: p.x.k }))),
|
|
1054
|
+
}
|
|
1055
|
+
: q;
|
|
1056
|
+
}),
|
|
1057
|
+
});
|
|
435
1058
|
|
|
436
1059
|
// Supports guessed at the lowest ends are pinned. Where that leaves the frame free to move (two posts and a rail
|
|
437
1060
|
// leaning over out of their plane, a beam on the floor rolling on its axis with a post on it), the guess takes
|
|
@@ -447,72 +1070,233 @@ export function frameModelOf(s, helpers) {
|
|
|
447
1070
|
let free = [];
|
|
448
1071
|
// (in the model as solved and in the pieces modes and buckling are solved in, where a freedom can show that
|
|
449
1072
|
// rounding hid in the whole: either says the frame is free)
|
|
450
|
-
for (const rigid of [false, true])
|
|
1073
|
+
for (const rigid of [false, true])
|
|
1074
|
+
for (const m of [withSprings(rigid), subdivide(withSprings(rigid), 4)])
|
|
1075
|
+
try {
|
|
1076
|
+
free.push(...solveFrame(m).mechanisms);
|
|
1077
|
+
} catch {
|
|
1078
|
+
/* refused: said by the solve itself */
|
|
1079
|
+
}
|
|
451
1080
|
if (free.length) {
|
|
452
1081
|
for (const x of guessed) {
|
|
453
|
-
const lies = supports.some((y) => y !== x && y.beam === x.beam) && axisOfBeam(x.beam) >= 0,
|
|
454
|
-
|
|
1082
|
+
const lies = supports.some((y) => y !== x && y.beam === x.beam) && axisOfBeam(x.beam) >= 0,
|
|
1083
|
+
stands = Math.abs(dot(x.beam.u, down)) > 1 - 1e-6;
|
|
1084
|
+
if (lies)
|
|
1085
|
+
Object.assign(x, {
|
|
1086
|
+
how: 'resting',
|
|
1087
|
+
why: 'a lowest end of a beam lying on its face',
|
|
1088
|
+
twist: `r${'xyz'[axisOfBeam(x.beam)]}`,
|
|
1089
|
+
});
|
|
455
1090
|
else if (stands) Object.assign(x, { how: 'fixed', why: 'a lowest end, standing on its end face' });
|
|
456
1091
|
}
|
|
457
1092
|
mapSupports();
|
|
458
1093
|
const seen = new Set();
|
|
459
|
-
const ways = free.filter((l) => {
|
|
460
|
-
|
|
461
|
-
|
|
1094
|
+
const ways = free.filter((l) => {
|
|
1095
|
+
const k = `${l.node} ${l.freedom}`;
|
|
1096
|
+
return !seen.has(k) && seen.add(k);
|
|
1097
|
+
});
|
|
1098
|
+
guess = {
|
|
1099
|
+
free: ways.map(({ node, freedom }) => ({ node, freedom })),
|
|
1100
|
+
ways,
|
|
1101
|
+
supports: guessed
|
|
1102
|
+
.filter((x) => x.why !== 'a lowest end')
|
|
1103
|
+
.map((x) => ({ where: x.where, how: x.how, why: x.why })),
|
|
1104
|
+
};
|
|
462
1105
|
if (!guess.supports.length) guess = null; // (nothing changed: the guess stays pinned, and the solve says what is free)
|
|
463
1106
|
}
|
|
464
1107
|
}
|
|
465
1108
|
// the loads at each pose: every carried item's and load's weight as a force and a moment at its node
|
|
466
1109
|
const nodeLoads = (values, only, push, stall) => {
|
|
467
|
-
const W = placeItems(motion, values),
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
1110
|
+
const W = placeItems(motion, values),
|
|
1111
|
+
out = [];
|
|
1112
|
+
const put = (b, z, C, kg) => {
|
|
1113
|
+
const n = nodeAt(b, z);
|
|
1114
|
+
if (!n)
|
|
1115
|
+
throw new Error(`frame: no node on ${b.id} at ${n3(z)} mm for a load (a pose this check did not foresee)`);
|
|
1116
|
+
const F = scale(down, kg * G);
|
|
1117
|
+
out.push({ node: n, force: F, moment: cross(sub(C, nodes[n]), F) });
|
|
1118
|
+
};
|
|
1119
|
+
for (const c of only ? [] : carried.filter(keep))
|
|
1120
|
+
put(c.mount.beam, mountStation(c.mount, values), rowsAt(W[c.item], c.centre), c.kg);
|
|
1121
|
+
for (const l of loads.filter(keep)) {
|
|
1122
|
+
if (only && only !== l) continue;
|
|
1123
|
+
const C = rowsAt(W[l.item], l.point);
|
|
1124
|
+
if (l.beam) put(l.beam, l.z, C, l.kg);
|
|
1125
|
+
else put(l.mount.beam, mountStation(l.mount, values), C, l.kg);
|
|
1126
|
+
}
|
|
1127
|
+
for (const p of only ? [] : heldSheets)
|
|
1128
|
+
for (const n of bays[p.bay].corners) out.push({ node: n, force: scale(down, (p.kg / 4) * G), moment: [0, 0, 0] });
|
|
1129
|
+
for (const p of only ? [] : laid)
|
|
1130
|
+
for (const id of p.beams) {
|
|
1131
|
+
const b = beams.get(id),
|
|
1132
|
+
w = scale(down, ((p.kg / p.beams.length) * G) / b.L);
|
|
1133
|
+
for (const q of elements) if (q.of === id) out.push({ element: q.id, spread: w });
|
|
1134
|
+
}
|
|
473
1135
|
// a joint's load, one way (push 1) or the other (-1): a slide's force along its axis through the joint's place, a
|
|
474
1136
|
// hinge's torque about its axis, each at the node where its chain meets the beam
|
|
475
1137
|
for (const x of only || !push ? [] : onJoints.filter(keep)) {
|
|
476
1138
|
const n = nodeAt(x.mount.beam, mountStation(x.mount, values));
|
|
477
|
-
if (!n)
|
|
478
|
-
|
|
479
|
-
|
|
1139
|
+
if (!n)
|
|
1140
|
+
throw new Error(
|
|
1141
|
+
`frame: no node on ${x.mount.beam.id} for the load on ${x.joint.id} (a pose this check did not foresee)`,
|
|
1142
|
+
);
|
|
1143
|
+
const { O, Z } = axisOf(motion, W, x.joint, mul),
|
|
1144
|
+
F = x.unit === 'N' ? scale(Z, push * x.value) : [0, 0, 0];
|
|
1145
|
+
out.push({
|
|
1146
|
+
node: n,
|
|
1147
|
+
force: F,
|
|
1148
|
+
moment: x.unit === 'N' ? cross(sub(O, nodes[n]), F) : scale(Z, push * x.value * 1000),
|
|
1149
|
+
});
|
|
480
1150
|
}
|
|
481
1151
|
// a motor stalled against a stop: the push (or turn) on the stop at the joint's place, and back on the motor's mount,
|
|
482
1152
|
// both along the joint's line, so they cancel in the whole and load the frame between them
|
|
483
1153
|
if (stall && !only && keep(stall) && keep({ mount: stall.motorMount })) {
|
|
484
1154
|
const { O, Z } = axisOf(motion, W, stall.joint, mul);
|
|
485
|
-
for (const [mt, k] of [
|
|
1155
|
+
for (const [mt, k] of [
|
|
1156
|
+
[stall.mount, 1],
|
|
1157
|
+
[stall.motorMount, -1],
|
|
1158
|
+
]) {
|
|
486
1159
|
const n = nodeAt(mt.beam, mountStation(mt, values));
|
|
487
|
-
if (!n)
|
|
1160
|
+
if (!n)
|
|
1161
|
+
throw new Error(
|
|
1162
|
+
`frame: no node on ${mt.beam.id} for ${stall.motor}'s stall (a pose this check did not foresee)`,
|
|
1163
|
+
);
|
|
488
1164
|
const F = stall.unit === 'N' ? scale(Z, k * stall.sign * stall.value) : [0, 0, 0];
|
|
489
|
-
out.push({
|
|
1165
|
+
out.push({
|
|
1166
|
+
node: n,
|
|
1167
|
+
force: F,
|
|
1168
|
+
moment: stall.unit === 'N' ? cross(sub(O, nodes[n]), F) : scale(Z, k * stall.sign * stall.value * 1000),
|
|
1169
|
+
});
|
|
490
1170
|
}
|
|
491
1171
|
}
|
|
492
1172
|
return out;
|
|
493
1173
|
};
|
|
494
1174
|
// the same masses for a modal solve: each at the node it is carried at, in kg (its offset's rotary inertia left out)
|
|
495
1175
|
const nodeMasses = (values) => {
|
|
496
|
-
const out = {},
|
|
1176
|
+
const out = {},
|
|
1177
|
+
put = (b, z, kg) => {
|
|
1178
|
+
const n = nodeAt(b, z);
|
|
1179
|
+
out[n] = (out[n] ?? 0) + kg;
|
|
1180
|
+
};
|
|
497
1181
|
for (const c of carried.filter(keep)) put(c.mount.beam, mountStation(c.mount, values), c.kg);
|
|
498
|
-
for (const l of loads.filter(keep)) {
|
|
1182
|
+
for (const l of loads.filter(keep)) {
|
|
1183
|
+
if (l.beam) put(l.beam, l.z, l.kg);
|
|
1184
|
+
else put(l.mount.beam, mountStation(l.mount, values), l.kg);
|
|
1185
|
+
}
|
|
499
1186
|
for (const p of heldSheets) for (const n of bays[p.bay].corners) out[n] = (out[n] ?? 0) + p.kg / 4;
|
|
500
1187
|
// (a panel laid on its beams: each beam's share at its elements' ends, half an element's length each)
|
|
501
|
-
for (const p of laid)
|
|
1188
|
+
for (const p of laid)
|
|
1189
|
+
for (const id of p.beams) {
|
|
1190
|
+
const b = beams.get(id);
|
|
1191
|
+
for (const q of elements)
|
|
1192
|
+
if (q.of === id) {
|
|
1193
|
+
const share = ((p.kg / p.beams.length) * Math.hypot(...sub(nodes[q.b], nodes[q.a]))) / b.L / 2;
|
|
1194
|
+
out[q.a] = (out[q.a] ?? 0) + share;
|
|
1195
|
+
out[q.b] = (out[q.b] ?? 0) + share;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
502
1198
|
return out;
|
|
503
1199
|
};
|
|
504
1200
|
const kept = new Set(carried.filter(keep).map((c) => c.id));
|
|
505
1201
|
// what is mounted only on beams left out (not held by a support through joins): not weighed, and named
|
|
506
|
-
const off = [
|
|
507
|
-
|
|
508
|
-
|
|
1202
|
+
const off = [
|
|
1203
|
+
...new Map(
|
|
1204
|
+
[...carried, ...loads]
|
|
1205
|
+
.filter((c) => !keep(c) && !kept.has(c.id))
|
|
1206
|
+
.map((c) => [c.id ?? `load ${c.index + 1} at ${c.where}`, (c.mount?.beam ?? c.beam).id]),
|
|
1207
|
+
),
|
|
1208
|
+
].map(([id, on]) => ({ id, on }));
|
|
1209
|
+
return {
|
|
1210
|
+
beams,
|
|
1211
|
+
left,
|
|
1212
|
+
missing,
|
|
1213
|
+
loose,
|
|
1214
|
+
unknown,
|
|
1215
|
+
off,
|
|
1216
|
+
riding: rides.filter((x) => kept.has(x.id)),
|
|
1217
|
+
carried: carried.filter(keep),
|
|
1218
|
+
loads: loads.filter(keep),
|
|
1219
|
+
points,
|
|
1220
|
+
guides: guides.filter(keep),
|
|
1221
|
+
supports: supports.filter(keep),
|
|
1222
|
+
joins: joins.filter((x) => beams.has(x.A.id)),
|
|
1223
|
+
cases,
|
|
1224
|
+
poses,
|
|
1225
|
+
onJoints: onJoints.filter(keep),
|
|
1226
|
+
stalls: stalls.filter((x) => keep(x) && keep({ mount: x.motorMount })),
|
|
1227
|
+
together,
|
|
1228
|
+
down,
|
|
1229
|
+
nodes,
|
|
1230
|
+
nodeAt,
|
|
1231
|
+
guess,
|
|
1232
|
+
model: withSprings(false),
|
|
1233
|
+
rigid: withSprings(true),
|
|
1234
|
+
springs, // (each join's spring: the join, the element at a's end and which end of it; frame sizing rebuilds them)
|
|
1235
|
+
nodeLoads,
|
|
1236
|
+
nodeMasses,
|
|
1237
|
+
bays,
|
|
1238
|
+
webs,
|
|
1239
|
+
sheets: heldSheets,
|
|
1240
|
+
laid,
|
|
1241
|
+
elements,
|
|
1242
|
+
mountStation,
|
|
1243
|
+
worlds,
|
|
1244
|
+
axisOf: (j) => axisOf(motion, worlds, j, mul),
|
|
1245
|
+
};
|
|
509
1246
|
}
|
|
510
1247
|
|
|
511
1248
|
// the downward movement of a node, and along a beam between two stations (the worst of the element stations there)
|
|
512
1249
|
const sagAt = (r, node, down) => dot(r.displacements[node].slice(0, 3), down);
|
|
1250
|
+
|
|
1251
|
+
/**
|
|
1252
|
+
* A join's part in the drop of one load, from the frame's own solve (join.drop, and cad measured working back to the
|
|
1253
|
+
* spring): the load alone, its own weight left out (a dial set to 0 with the hook on and read with the mass hung), as
|
|
1254
|
+
* drawn, with the join's bending spring set to any figure. The joins in `together` take their spring from the same
|
|
1255
|
+
* rule, so a figure written back moves them too: each is set to the figure times its factor. Every other join's spring
|
|
1256
|
+
* is as it is. Null where the solve has no spring for the join or no node for the load.
|
|
1257
|
+
* @param {object} fm frameModelOf's @param {number} index the join's index @param {object} load one of fm.loads
|
|
1258
|
+
* @param {Map<number, number>} [together] other joins' indices, each with its spring as a multiple of this join's
|
|
1259
|
+
* @returns {{ dropAt: (bending: number) => number, spring: number } | null} the drop in mm at the load's node, for a
|
|
1260
|
+
* bending spring in N·mm/rad (Infinity: the join, and those with it, held rigid in bending), and the spring it has
|
|
1261
|
+
*/
|
|
1262
|
+
export function joinDropOf(fm, index, load, together = new Map()) {
|
|
1263
|
+
const factor = (p) => (p.x.j.index === index ? 1 : together.get(p.x.j.index)),
|
|
1264
|
+
mine = fm.springs.filter((p) => p.el && factor(p) > 0);
|
|
1265
|
+
if (!mine.some((p) => p.x.j.index === index) || !fm.cases.length) return null;
|
|
1266
|
+
const loads = fm.nodeLoads(fm.cases[0].values, load),
|
|
1267
|
+
node = loads[0]?.node;
|
|
1268
|
+
if (!node) return null;
|
|
1269
|
+
const dropAt = (bending) => {
|
|
1270
|
+
const model = {
|
|
1271
|
+
...fm.model,
|
|
1272
|
+
elements: fm.model.elements.map((q) => {
|
|
1273
|
+
const sp = mine.filter((p) => p.el.id === q.id);
|
|
1274
|
+
if (!sp.length) return q;
|
|
1275
|
+
const ends = { ...q.ends };
|
|
1276
|
+
for (const p of sp) {
|
|
1277
|
+
const k = bending * factor(p);
|
|
1278
|
+
ends[p.end] = { ...ends[p.end], ry: k, rz: k };
|
|
1279
|
+
}
|
|
1280
|
+
return { ...q, ends };
|
|
1281
|
+
}),
|
|
1282
|
+
};
|
|
1283
|
+
return sagAt(solveFrame(model).statics({ loads, gravity: [0, 0, 0] }), node, fm.down);
|
|
1284
|
+
};
|
|
1285
|
+
return { dropAt, spring: mine.find((p) => p.x.j.index === index).x.k.bending };
|
|
1286
|
+
}
|
|
513
1287
|
function sagAlong(r, beam, from, to, down) {
|
|
514
|
-
let most = -Infinity,
|
|
515
|
-
|
|
1288
|
+
let most = -Infinity,
|
|
1289
|
+
where = from;
|
|
1290
|
+
for (const e of r.elements)
|
|
1291
|
+
if (e.of === beam.id)
|
|
1292
|
+
e.along.x.forEach((x, i) => {
|
|
1293
|
+
const z = (e._from ?? 0) + x,
|
|
1294
|
+
v = dot(e.along.d[i], down);
|
|
1295
|
+
if (z >= from - 1e-6 && z <= to + 1e-6 && v > most) {
|
|
1296
|
+
most = v;
|
|
1297
|
+
where = z;
|
|
1298
|
+
}
|
|
1299
|
+
});
|
|
516
1300
|
return { sag: most, z: where };
|
|
517
1301
|
}
|
|
518
1302
|
|
|
@@ -523,167 +1307,552 @@ function sagAlong(r, beam, from, to, down) {
|
|
|
523
1307
|
*/
|
|
524
1308
|
export function frameChecks(s, f, helpers) {
|
|
525
1309
|
let fm;
|
|
526
|
-
try {
|
|
1310
|
+
try {
|
|
1311
|
+
fm = frameModelOf(s, helpers);
|
|
1312
|
+
} catch (e) {
|
|
1313
|
+
f('fail', `frame: ${e.message}`, 'frame: refused', { code: 'frame.solve' });
|
|
1314
|
+
return null;
|
|
1315
|
+
}
|
|
527
1316
|
if (!fm) return null;
|
|
528
|
-
if (fm.empty) {
|
|
1317
|
+
if (fm.empty) {
|
|
1318
|
+
if (fm.missing.length)
|
|
1319
|
+
f(
|
|
1320
|
+
'info',
|
|
1321
|
+
`the frame is not solved: ${fm.missing.join(', ')} ${fm.missing.length > 1 ? 'give' : 'gives'} no modulus, shear modulus or second moments`,
|
|
1322
|
+
null,
|
|
1323
|
+
{ code: 'frame.solve', refs: { beams: fm.missing } },
|
|
1324
|
+
);
|
|
1325
|
+
return null;
|
|
1326
|
+
}
|
|
529
1327
|
const solved = solveAll(fm);
|
|
530
|
-
if (solved.error) {
|
|
531
|
-
|
|
532
|
-
|
|
1328
|
+
if (solved.error) {
|
|
1329
|
+
const guessed = fm.supports.every((x) => x.why.startsWith('a lowest end'));
|
|
1330
|
+
f(
|
|
1331
|
+
guessed ? 'info' : 'warn',
|
|
1332
|
+
`the frame is not solved: ${solved.error}. Its supports: ${fm.supports.map((x) => `${x.where} (${x.why})`).join(', ') || 'none'}${guessed ? '. Say where it is held: "frame": { "supports": { "z1.a": "pinned" } }, or fit its feet' : ''}`,
|
|
1333
|
+
guessed ? null : 'frame: not solved',
|
|
1334
|
+
{ code: 'frame.solve', refs: { supports: fm.supports.map((x) => x.where), code: solved.code } },
|
|
1335
|
+
);
|
|
1336
|
+
return null;
|
|
1337
|
+
}
|
|
1338
|
+
const { results } = solved,
|
|
1339
|
+
down = fm.down,
|
|
1340
|
+
margin = FRAME_CHECK.margin.value,
|
|
1341
|
+
held = solved.loose ?? [];
|
|
533
1342
|
// how it moves there, in words: the frame tipping over along y, a beam spinning on its axis
|
|
534
|
-
const heldHow = howFree(fm, solved.mechanisms),
|
|
1343
|
+
const heldHow = howFree(fm, solved.mechanisms),
|
|
1344
|
+
heldSaid = howSaid(heldHow);
|
|
535
1345
|
// what the joins rest on, counted by kind
|
|
536
1346
|
const kinds = new Map();
|
|
537
|
-
for (const x of fm.joins) {
|
|
1347
|
+
for (const x of fm.joins) {
|
|
1348
|
+
const key = `${x.j.kind}${x.j.fitting ? ` (${x.j.fitting})` : ''}: ${restsWord(x.k)}`;
|
|
1349
|
+
kinds.set(key, (kinds.get(key) ?? 0) + 1);
|
|
1350
|
+
}
|
|
538
1351
|
const estimates = fm.joins.filter((x) => !(x.k.measured?.bending && x.k.measured?.twist)).length;
|
|
539
|
-
const restsJoins = fm.joins.length
|
|
1352
|
+
const restsJoins = fm.joins.length
|
|
1353
|
+
? `${fm.joins.length} join${fm.joins.length > 1 ? 's' : ''}' springs (${[...kinds].map(([k, n]) => `${n} ${k}`).join('; ')})`
|
|
1354
|
+
: 'no joins';
|
|
540
1355
|
// what every figure rests on: the joins' springs are an estimate while any is, whether or not they move a figure
|
|
541
1356
|
const restsOn = estimates ? 'estimate' : fm.joins.length ? 'measured' : 'beams';
|
|
542
|
-
const rests = fm.joins.map((x) => ({
|
|
1357
|
+
const rests = fm.joins.map((x) => ({
|
|
1358
|
+
join: x.j.index,
|
|
1359
|
+
kind: x.j.kind,
|
|
1360
|
+
bending: x.k.bending,
|
|
1361
|
+
twist: x.k.twist,
|
|
1362
|
+
value: restsWord(x.k),
|
|
1363
|
+
}));
|
|
543
1364
|
// supports guessed and changed from pinned (fm.guess): the solve warns, and racking, buckling and the modes say they rest on it
|
|
544
|
-
const guess = fm.guess
|
|
545
|
-
const and = (xs) => (xs.length > 1 ? `${xs.slice(0, -1).join(', ')} and ${xs[xs.length - 1]}` : xs[0] ?? '');
|
|
546
|
-
const posts = guess ? guess.supports.filter((x) => x.how === 'fixed').map((x) => x.where) : [],
|
|
547
|
-
|
|
548
|
-
const
|
|
1365
|
+
const guess = fm.guess;
|
|
1366
|
+
const and = (xs) => (xs.length > 1 ? `${xs.slice(0, -1).join(', ')} and ${xs[xs.length - 1]}` : (xs[0] ?? ''));
|
|
1367
|
+
const posts = guess ? guess.supports.filter((x) => x.how === 'fixed').map((x) => x.where) : [],
|
|
1368
|
+
lying = guess ? guess.supports.filter((x) => x.how !== 'fixed').map((x) => x.where) : [];
|
|
1369
|
+
const guessHeld = [
|
|
1370
|
+
posts.length ? `${and(posts)} fixed, standing on ${posts.length > 1 ? 'their end faces' : 'its end face'}` : null,
|
|
1371
|
+
lying.length
|
|
1372
|
+
? `${and(lying)} resting, held from twisting as ${lying.length > 1 ? 'ends of beams' : 'an end of a beam'} lying on its face`
|
|
1373
|
+
: null,
|
|
1374
|
+
]
|
|
1375
|
+
.filter(Boolean)
|
|
1376
|
+
.join(', and ');
|
|
1377
|
+
const guessHow = guess ? howFree(fm, guess.ways) : [],
|
|
1378
|
+
guessSaid = howSaid(guessHow);
|
|
549
1379
|
// supports guessed at the lowest ends and left pinned: nothing in the assembly says the frame stands there
|
|
550
|
-
const pinnedGuess = fm.supports.filter((x) => x.why === 'a lowest end').map((x) => x.where),
|
|
1380
|
+
const pinnedGuess = fm.supports.filter((x) => x.why === 'a lowest end').map((x) => x.where),
|
|
1381
|
+
guessedOnly = fm.supports.length > 0 && fm.supports.every((x) => x.why.startsWith('a lowest end'));
|
|
551
1382
|
if (guess) {
|
|
552
1383
|
const said = f;
|
|
553
|
-
f = (level, text, card, extra = {}) =>
|
|
554
|
-
|
|
555
|
-
|
|
1384
|
+
f = (level, text, card, extra = {}) =>
|
|
1385
|
+
['frame.rack', 'frame.buckling', 'frame.frequency'].includes(extra.code)
|
|
1386
|
+
? said(
|
|
1387
|
+
level,
|
|
1388
|
+
`${text}. This rests on supports guessed, not given: ${guessHeld}, where on pinned feet nothing would hold it: ${guessSaid}`,
|
|
1389
|
+
card,
|
|
1390
|
+
{ ...extra, refs: { ...extra.refs, guessed: guess.supports.map((x) => x.where) } },
|
|
1391
|
+
)
|
|
1392
|
+
: said(level, text, card, extra);
|
|
556
1393
|
}
|
|
557
|
-
f(
|
|
558
|
-
|
|
1394
|
+
f(
|
|
1395
|
+
guessedOnly ? 'warn' : 'info',
|
|
1396
|
+
`the frame is solved as ${fm.beams.size} beam${fm.beams.size > 1 ? 's' : ''} on ${Object.keys(fm.nodes).length} nodes, held at ${fm.supports.map((x) => `${x.where} (${x.how}, ${x.why})`).join(', ')}, under its own weight${fm.carried.length ? `, ${new Set(fm.carried.map((c) => c.id)).size} item${new Set(fm.carried.map((c) => c.id)).size > 1 ? 's' : ''} mounted on it` : ''}${fm.loads.length ? ` and ${fm.loads.length} load${fm.loads.length > 1 ? 's' : ''}` : ''}${fm.onJoints.length ? `, with ${fm.onJoints.map((x) => `${n3(x.value, 3)} ${x.unit} on ${x.joint.id}${x.belt || x.motor ? ` (${x.note})` : ''}`).join(', ')} carried into ${[...new Set(fm.onJoints.map((x) => x.mount.beam.id))].join(', ')} through ${fm.onJoints.length > 1 ? 'their joints, each' : 'its joint,'} one way and then the other` : ''}${fm.stalls.length ? `, and ${[...new Map(fm.stalls.map((x) => [`${x.motor} ${x.joint.id}`, x])).values()].map((x) => `${x.motor} stalled against ${x.joint.id}'s stop at each end of its travel (${n3(x.value, 3)} ${x.unit} from its ${n3(x.hold, 3)} N m holding torque, on the stop and back on its mount on ${x.motorMount.beam.id})`).join(', ')}` : ''}, in ${fm.poses.length} pose${fm.poses.length > 1 ? 's' : ''}${fm.together.how ? ` (${fm.together.joints.join(', ')} each swept and then together: ${fm.together.how})` : ''}${fm.onJoints.length || fm.stalls.length ? ` (${fm.cases.length} cases)` : ''}; ${restsJoins}${estimates ? `, ${estimates} of them an estimate until the joint rig (issue 264) measures it, so each figure is given with the joins rigid too` : ''}${fm.riding.length ? `. ${fm.riding.map((x) => `${x.id} rides on ${x.joint}, its ${n3(x.kg, 3)} kg weighed on the frame${x.on.length > 1 ? `, shared as it lies: ${x.on.map((q) => `${n3(q.share * 100, 0)}% on ${q.beam}`).join(', ')}` : `, all of it on ${x.on[0].beam}, the beam its joint is on`}`).join('; ')}` : ''}${fm.webs.length ? `. ${fm.webs.map((w) => `${w.id} is a shear web on its bay, ${n3(w.k, 0)} N/mm along its diagonal (${w.clips} clips, their grip an estimate)`).join('; ')}` : ''}${fm.laid.length ? `. ${fm.laid.map((p) => `${p.id} lies on ${p.beams.join(', ')}, which are not joined round it as a bay: its ${n3(p.kg, 3)} kg is spread along them, and it is no shear web`).join('; ')}` : ''}${held.length ? `. Nothing holds it one way: ${heldSaid}, with nothing resisting. Its loads do not move it that way, so it is held there for the sag and the stresses; its modes and buckling count it free (frame.frequency, frame.buckling), and a push that way finds it free (frame.rack). Hold it with "frame": { "supports" } fixed or resting, or join it into a box` : ''}${fm.left.length ? `. Left out: ${fm.left.join(', ')} (not held by a support through joins)` : ''}${fm.off.length ? `. Not weighed on the frame, as the beam carrying it is left out: ${fm.off.map((x) => `${x.id} (on ${x.on})`).join(', ')}` : ''}${fm.loose.length ? `. Not on a beam, so not weighed on the frame: ${fm.loose.join(', ')}` : ''}${fm.unknown.length ? `. No mass known for ${fm.unknown.join(', ')}` : ''}${guess ? `. Its supports are guessed: nothing says where it is held (no feet, no "frame": { "supports" }), and on its lowest ends pinned, as a foot stands on a floor, nothing would hold it: ${guessSaid}. So it is solved with ${guessHeld}${pinnedGuess.length ? ` (${and(pinnedGuess)} pinned, a guess too)` : ''}, and every sag, rack, buckling and frequency figure rests on those ends held from turning, which nothing in the assembly gives. Give it feet, or say how it is held in "frame": { "supports" }` : guessedOnly ? `. Its supports are guessed: nothing says where it is held (no feet, no "frame": { "supports" }), so it stands on its lowest ends, ${and(pinnedGuess)}, pinned, as feet stand on a floor, and every figure rests on that. Give it feet, or say how it is held in "frame": { "supports" }` : ''}`,
|
|
1397
|
+
guessedOnly ? 'frame: supports guessed' : null,
|
|
1398
|
+
{
|
|
1399
|
+
code: 'frame.solve',
|
|
1400
|
+
values: {
|
|
1401
|
+
beams: fm.beams.size,
|
|
1402
|
+
nodes: Object.keys(fm.nodes).length,
|
|
1403
|
+
cases: fm.cases.length,
|
|
1404
|
+
poses: fm.poses.length,
|
|
1405
|
+
joins: fm.joins.length,
|
|
1406
|
+
estimates,
|
|
1407
|
+
},
|
|
1408
|
+
refs: {
|
|
1409
|
+
supports: fm.supports.map((x) => x.where),
|
|
1410
|
+
...(guess
|
|
1411
|
+
? {
|
|
1412
|
+
guessed: [...guess.supports.map((x) => x.where), ...pinnedGuess],
|
|
1413
|
+
free: guess.free,
|
|
1414
|
+
how: guessHow.map((h) => h.says),
|
|
1415
|
+
}
|
|
1416
|
+
: guessedOnly
|
|
1417
|
+
? { guessed: pinnedGuess }
|
|
1418
|
+
: {}),
|
|
1419
|
+
left: fm.left,
|
|
1420
|
+
off: fm.off,
|
|
1421
|
+
onJoints: fm.onJoints.map((x) => ({
|
|
1422
|
+
joint: x.joint.id,
|
|
1423
|
+
value: r3(x.value),
|
|
1424
|
+
unit: x.unit,
|
|
1425
|
+
beam: x.mount.beam.id,
|
|
1426
|
+
note: x.note,
|
|
1427
|
+
})),
|
|
1428
|
+
stalls: fm.stalls.map((x) => ({
|
|
1429
|
+
joint: x.joint.id,
|
|
1430
|
+
motor: x.motor,
|
|
1431
|
+
end: r3(x.end),
|
|
1432
|
+
value: r3(x.value),
|
|
1433
|
+
unit: x.unit,
|
|
1434
|
+
hold: r3(x.hold),
|
|
1435
|
+
stop: x.mount.beam.id,
|
|
1436
|
+
mount: x.motorMount.beam.id,
|
|
1437
|
+
})),
|
|
1438
|
+
together: fm.together,
|
|
1439
|
+
held,
|
|
1440
|
+
...(held.length ? { how: heldHow.map((h) => h.says) } : {}),
|
|
1441
|
+
laid: fm.laid.map((p) => ({ id: p.id, kg: r3(p.kg), beams: p.beams })),
|
|
1442
|
+
riding: fm.riding.map((x) => ({ ...x, kg: r3(x.kg) })),
|
|
1443
|
+
loose: fm.loose,
|
|
1444
|
+
rests,
|
|
1445
|
+
},
|
|
1446
|
+
},
|
|
1447
|
+
);
|
|
559
1448
|
|
|
560
1449
|
// ---- frame.deflection: each load's point, each named point, every guide ----
|
|
561
|
-
|
|
1450
|
+
// A beam drawn printed creeps under a load it holds for months: the frame solved again, with the joins' springs, its
|
|
1451
|
+
// printed beams bending as if at their creep share of their modulus (PRINTED_DEFAULTS.creep_modulus, an estimate), in
|
|
1452
|
+
// every case but a motor stalled against its stop (a moment, not a load held)
|
|
1453
|
+
const crept = creptOf(fm, results);
|
|
1454
|
+
const worst = (fn) => {
|
|
1455
|
+
let w = null,
|
|
1456
|
+
long = null;
|
|
1457
|
+
for (const r of results) {
|
|
1458
|
+
const v = fn(r.spring, r),
|
|
1459
|
+
v0 = fn(r.rigid, r);
|
|
1460
|
+
if (!w || v.sag > w.sag) w = { ...v, rigid: v0.sag, case: { ...r.case, alone: r.alone } };
|
|
1461
|
+
const c = crept?.results.get(r);
|
|
1462
|
+
if (c) {
|
|
1463
|
+
const vc = fn(c, r);
|
|
1464
|
+
if (!long || vc.sag > long.sag) long = { sag: vc.sag, z: vc.z, case: r.case };
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
if (w && long) w.creep = long;
|
|
1468
|
+
return w;
|
|
1469
|
+
};
|
|
562
1470
|
const limitFor = (b, own) => {
|
|
563
1471
|
if (own) return { value: own.value, from: `${own.from}` };
|
|
564
|
-
if (s.a.frame?.limit != null) return { value: s.num(s.a.frame.limit), from:
|
|
565
|
-
if (s.task?.accuracy != null) return { value: s.task.accuracy, from:
|
|
566
|
-
return {
|
|
1472
|
+
if (s.a.frame?.limit != null) return { value: s.num(s.a.frame.limit), from: "the assembly's frame.limit" };
|
|
1473
|
+
if (s.task?.accuracy != null) return { value: s.task.accuracy, from: "the task's accuracy" };
|
|
1474
|
+
return {
|
|
1475
|
+
value: b.L / FRAME_CHECK.sag.value,
|
|
1476
|
+
from: `${b.id}'s span, ${n3(b.L, 1)} mm, over ${FRAME_CHECK.sag.value} (frame.sag)`,
|
|
1477
|
+
};
|
|
567
1478
|
};
|
|
568
1479
|
const report = (what, where, b, w, own, alone, P) => {
|
|
569
|
-
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
|
|
1480
|
+
// held to the worse of its sag now and after creep, where a beam of the frame is printed
|
|
1481
|
+
const long = w.creep && w.creep.sag > w.sag ? w.creep : null,
|
|
1482
|
+
sagHeld = long ? long.sag : w.sag;
|
|
1483
|
+
const lim = limitFor(b, own),
|
|
1484
|
+
level = sagHeld > lim.value ? 'fail' : 'pass',
|
|
1485
|
+
soft = estimates && w.sag > w.rigid * 1.001;
|
|
1486
|
+
const creepSaid = long
|
|
1487
|
+
? `; after creep (estimate): ${sagN(long.sag)} mm${fm.cases.length > 1 && long.case.label !== w.case.label ? `, worst ${long.case.label}` : ''}, ${crept.said} under a load held for months (PRINTED_DEFAULTS.creep_modulus, a working figure with no long test behind it), held to the limit as the worse`
|
|
1488
|
+
: '';
|
|
1489
|
+
const text = `${what} sags ${sagN(w.sag)} mm${fm.cases.length > 1 ? `, worst ${w.case.label}` : ''}, with the joins' springs; ${sagN(w.rigid)} mm with the joins rigid${alone ? ` (of these, ${sagN(alone.sag)} and ${sagN(alone.rigid)} mm from ${alone.what} alone)` : ''}${creepSaid}. ${soft ? `The first rests on ${restsJoins}, so the true sag lies near it, and the rigid figure is the least it can be` : `It rests on ${restsJoins}`}: against ${n3(lim.value)} mm, ${lim.from}${level === 'fail' ? `: ${n3(sagHeld / lim.value, 2)} times over${long ? ' after creep' : ''}. Stiffen the beam (a deeper profile), shorten its span, or stiffen its joins` : ''}`;
|
|
1490
|
+
f(level, text, level === 'fail' ? `${where}: sags ${n3(sagHeld, 2)} mm${long ? ' after creep' : ''}` : null, {
|
|
1491
|
+
code: 'frame.deflection',
|
|
1492
|
+
at: r4(P),
|
|
1493
|
+
values: {
|
|
1494
|
+
sag: sagR(w.sag),
|
|
1495
|
+
rigid: sagR(w.rigid),
|
|
1496
|
+
limit: r3(lim.value),
|
|
1497
|
+
...(alone ? { alone: sagR(alone.sag), aloneRigid: sagR(alone.rigid) } : {}),
|
|
1498
|
+
...(w.creep ? { creep: sagR(w.creep.sag) } : {}),
|
|
1499
|
+
},
|
|
1500
|
+
refs: {
|
|
1501
|
+
beam: b.id,
|
|
1502
|
+
where,
|
|
1503
|
+
pose: w.case.label,
|
|
1504
|
+
limit: lim.from,
|
|
1505
|
+
rests,
|
|
1506
|
+
restsOn,
|
|
1507
|
+
...(w.creep ? { creep: crept.refs } : {}),
|
|
1508
|
+
},
|
|
1509
|
+
});
|
|
573
1510
|
};
|
|
574
1511
|
for (const l of fm.loads) {
|
|
575
|
-
const b = l.beam ?? l.mount.beam,
|
|
1512
|
+
const b = l.beam ?? l.mount.beam,
|
|
1513
|
+
zOf = (values) => (l.beam ? l.z : fm.mountStation(l.mount, values));
|
|
576
1514
|
const w = worst((res, r) => ({ sag: sagAt(res, fm.nodeAt(b, zOf(r.values)), down) }));
|
|
577
1515
|
const one = w.case.alone?.get(l);
|
|
578
|
-
report(
|
|
1516
|
+
report(
|
|
1517
|
+
`${b.id} at ${l.where}`,
|
|
1518
|
+
l.where,
|
|
1519
|
+
b,
|
|
1520
|
+
w,
|
|
1521
|
+
null,
|
|
1522
|
+
one ? { ...one, what: `the ${n3(l.kg, 3)} kg there` } : null,
|
|
1523
|
+
fm.nodes[fm.nodeAt(b, zOf(w.case.values))],
|
|
1524
|
+
);
|
|
1525
|
+
}
|
|
1526
|
+
for (const p of fm.points) {
|
|
1527
|
+
const n = fm.nodeAt(p.beam, p.z),
|
|
1528
|
+
w = worst((r) => ({ sag: sagAt(r, n, down) }));
|
|
1529
|
+
report(`${p.beam.id} at ${p.where}`, p.where, p.beam, w, null, null, fm.nodes[n]);
|
|
579
1530
|
}
|
|
580
|
-
for (const p of fm.points) { const n = fm.nodeAt(p.beam, p.z), w = worst((r) => ({ sag: sagAt(r, n, down) })); report(`${p.beam.id} at ${p.where}`, p.where, p.beam, w, null, null, fm.nodes[n]); }
|
|
581
1531
|
for (const g of fm.guides) {
|
|
582
|
-
const w = worst((r) => sagAlong(r, g.beam, g.from, g.to, down)),
|
|
583
|
-
|
|
1532
|
+
const w = worst((r) => sagAlong(r, g.beam, g.from, g.to, down)),
|
|
1533
|
+
own = g.tolerance
|
|
1534
|
+
? {
|
|
1535
|
+
value: g.tolerance.value,
|
|
1536
|
+
from: `the rail's own parallelism over its length (${g.tolerance.note ?? g.tolerance.term})`,
|
|
1537
|
+
}
|
|
1538
|
+
: null;
|
|
1539
|
+
report(
|
|
1540
|
+
`${g.beam.id} under guide ${g.id}, between ${n3(g.from, 1)} and ${n3(g.to, 1)} mm`,
|
|
1541
|
+
`${g.id}`,
|
|
1542
|
+
g.beam,
|
|
1543
|
+
w,
|
|
1544
|
+
own,
|
|
1545
|
+
null,
|
|
1546
|
+
add(g.beam.A, scale(g.beam.u, w.z)),
|
|
1547
|
+
);
|
|
584
1548
|
// kept for the error budget: the task's terms take the beam's sag along the guide from here (lib/task.mjs terms)
|
|
585
|
-
(s.frameGuideSag ??= new Map()).set(g.id, {
|
|
1549
|
+
(s.frameGuideSag ??= new Map()).set(g.id, {
|
|
1550
|
+
sag: sagR(w.sag),
|
|
1551
|
+
rigid: sagR(w.rigid),
|
|
1552
|
+
pose: w.case.label,
|
|
1553
|
+
restsOn,
|
|
1554
|
+
beam: g.beam.id,
|
|
1555
|
+
});
|
|
586
1556
|
}
|
|
587
1557
|
|
|
588
1558
|
// ---- frame.stress: the worst in each beam against its alloy; the moment at each join against its fitting ----
|
|
589
1559
|
const beamRows = [];
|
|
590
1560
|
for (const b of fm.beams.values()) {
|
|
591
1561
|
let w = null;
|
|
592
|
-
for (const r of results)
|
|
1562
|
+
for (const r of results)
|
|
1563
|
+
for (const [model, res] of [
|
|
1564
|
+
['springs', r.spring],
|
|
1565
|
+
['rigid', r.rigid],
|
|
1566
|
+
])
|
|
1567
|
+
for (const e of res.elements)
|
|
1568
|
+
if (e.of === b.id && e.stress && (!w || e.stress.peak > w.peak)) w = { ...e.stress, case: r.case, model, e };
|
|
593
1569
|
if (!w) continue;
|
|
594
1570
|
const m = b.strength ? b.strength / w.peak : Infinity;
|
|
595
1571
|
beamRows.push({ b, w, margin: m });
|
|
596
1572
|
}
|
|
597
1573
|
for (const { b, w, margin: m } of beamRows) {
|
|
598
|
-
if (!b.strength) {
|
|
1574
|
+
if (!b.strength) {
|
|
1575
|
+
f(
|
|
1576
|
+
'info',
|
|
1577
|
+
`${b.id}: ${n3(w.peak, 2)} MPa at worst, and ${b.alloy ?? 'its alloy'} gives no strength to check it against`,
|
|
1578
|
+
null,
|
|
1579
|
+
{ code: 'frame.stress', values: { stress: r3(w.peak) }, refs: { beam: b.id } },
|
|
1580
|
+
);
|
|
1581
|
+
continue;
|
|
1582
|
+
}
|
|
599
1583
|
const level = m < 1 ? 'fail' : m < margin ? 'warn' : 'pass';
|
|
600
1584
|
if (level === 'pass' && beamRows.length > 1) continue;
|
|
601
1585
|
const P = add(b.A, scale(b.u, (w.e._from ?? 0) + w.x));
|
|
602
|
-
f(
|
|
603
|
-
|
|
1586
|
+
f(
|
|
1587
|
+
level,
|
|
1588
|
+
`${b.id}: ${n3(w.peak, 2)} MPa at worst (${n3(w.bending, 2)} of it bending), ${w.model === 'rigid' ? 'with the joins rigid' : "with the joins' springs"}${fm.cases.length > 1 ? `, ${w.case.label}` : ''}, against ${b.alloy}'s ${b.strength} MPa: ${n3(m, 1)} times under it${level !== 'pass' ? `, where about ${margin} is wanted. A deeper profile or a shorter span` : ''}`,
|
|
1589
|
+
level === 'pass' ? null : `${b.id}: stress ${n3(m, 1)}×`,
|
|
1590
|
+
{
|
|
1591
|
+
code: 'frame.stress',
|
|
1592
|
+
at: r4(P),
|
|
1593
|
+
between: [r4(b.A), r4(add(b.A, scale(b.u, b.L)))],
|
|
1594
|
+
values: { stress: r3(w.peak), bending: r3(w.bending), strength: b.strength, margin: r3(m) },
|
|
1595
|
+
refs: { beam: b.id, pose: w.case.label, joins: w.model },
|
|
1596
|
+
},
|
|
1597
|
+
);
|
|
604
1598
|
}
|
|
605
1599
|
const passing = beamRows.filter((x) => x.b.strength && x.margin >= margin);
|
|
606
1600
|
if (beamRows.length > 1 && passing.length) {
|
|
607
1601
|
const low = passing.reduce((p, q) => (q.margin < p.margin ? q : p));
|
|
608
|
-
f(
|
|
609
|
-
|
|
1602
|
+
f(
|
|
1603
|
+
'pass',
|
|
1604
|
+
`${passing.length === beamRows.length ? 'every beam' : `${passing.length} beams`} stays under its alloy's strength with ${margin} times to spare: the most stressed is ${low.b.id}, ${n3(low.w.peak, 2)} MPa against ${low.b.strength} MPa, ${n3(low.margin, 1)} times under`,
|
|
1605
|
+
null,
|
|
1606
|
+
{
|
|
1607
|
+
code: 'frame.stress',
|
|
1608
|
+
at: r4(add(low.b.A, scale(low.b.u, low.b.L / 2))),
|
|
1609
|
+
values: { stress: r3(low.w.peak), strength: low.b.strength, margin: r3(low.margin), beams: passing.length },
|
|
1610
|
+
refs: { beam: low.b.id, beams: passing.map((x) => x.b.id) },
|
|
1611
|
+
},
|
|
1612
|
+
);
|
|
610
1613
|
}
|
|
611
|
-
const rated = [],
|
|
1614
|
+
const rated = [],
|
|
1615
|
+
unrated = [];
|
|
612
1616
|
for (const x of fm.joins) {
|
|
613
|
-
let M = 0,
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
1617
|
+
let M = 0,
|
|
1618
|
+
T = 0,
|
|
1619
|
+
at = null;
|
|
1620
|
+
for (const r of results)
|
|
1621
|
+
for (const [model, res] of [
|
|
1622
|
+
['springs', r.spring],
|
|
1623
|
+
['rigid', r.rigid],
|
|
1624
|
+
]) {
|
|
1625
|
+
const mine = res.elements.filter((q) => q.of === x.A.id),
|
|
1626
|
+
e = x.e === 'a' ? mine[0] : mine[mine.length - 1];
|
|
1627
|
+
if (!e) continue;
|
|
1628
|
+
const end = x.e === 'a' ? e.ends.a : e.ends.b,
|
|
1629
|
+
m = Math.hypot(end[4], end[5]);
|
|
1630
|
+
if (!at || m > M) {
|
|
1631
|
+
M = m;
|
|
1632
|
+
T = Math.abs(end[3]);
|
|
1633
|
+
at = { case: r.case, model };
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
const fit = x.j.fitted?.model,
|
|
1637
|
+
cap =
|
|
1638
|
+
fit?.load?.force && fit.margin && Array.isArray(fit.load.at)
|
|
1639
|
+
? fit.load.force * Math.hypot(...fit.load.at) * fit.margin
|
|
1640
|
+
: null;
|
|
1641
|
+
(cap ? rated : unrated).push({
|
|
1642
|
+
x,
|
|
1643
|
+
M,
|
|
1644
|
+
T,
|
|
1645
|
+
at,
|
|
1646
|
+
fit,
|
|
1647
|
+
cap,
|
|
1648
|
+
margin: cap ? cap / (M || 1e-9) : null,
|
|
1649
|
+
P: fm.nodes[fm.nodeAt(x.A, x.za)],
|
|
1650
|
+
refs: { join: x.j.index, kind: x.j.kind, a: x.j.a, b: x.j.b },
|
|
1651
|
+
});
|
|
621
1652
|
}
|
|
622
1653
|
for (const q of rated) {
|
|
623
1654
|
const level = q.margin < 1 ? 'fail' : q.margin < margin ? 'warn' : 'pass';
|
|
624
1655
|
if (level === 'pass' && rated.length > 1) continue;
|
|
625
|
-
f(
|
|
626
|
-
|
|
1656
|
+
f(
|
|
1657
|
+
level,
|
|
1658
|
+
`${q.x.j.label}: ${n3(q.M / 1000, 3)} N·m bending at ${q.x.A.id}'s end ${q.x.e} (${q.at.model === 'rigid' ? 'joins rigid' : "joins' springs"}${fm.cases.length > 1 ? `, ${q.at.case.label}` : ''}), against about ${n3(q.cap / 1000, 2)} N·m ${q.x.j.fitted.item} takes: its ${q.fit.load.force} N at ${n3(Math.hypot(...q.fit.load.at), 1)} mm from the corner, ${n3(q.fit.margin, 1)} times under its plastic's strength by finite elements, scaled as the load grows: ${n3(q.margin, 1)} times under it${level !== 'pass' ? `, where about ${margin} is wanted. A larger design load on the join ("load") sizes a stouter fitting` : ''}`,
|
|
1659
|
+
level === 'pass' ? null : `${q.x.j.label}: ${n3(q.margin, 1)}×`,
|
|
1660
|
+
{
|
|
1661
|
+
code: 'frame.stress',
|
|
1662
|
+
at: r4(q.P),
|
|
1663
|
+
values: { moment: r3(q.M), twist: r3(q.T), strength: r3(q.cap), margin: r3(q.margin) },
|
|
1664
|
+
refs: { ...q.refs, item: q.x.j.fitted.item },
|
|
1665
|
+
},
|
|
1666
|
+
);
|
|
627
1667
|
}
|
|
628
1668
|
const okRated = rated.filter((q) => q.margin >= margin);
|
|
629
1669
|
if (rated.length > 1 && okRated.length) {
|
|
630
1670
|
const low = okRated.reduce((p, q) => (q.margin < p.margin ? q : p));
|
|
631
|
-
f(
|
|
632
|
-
|
|
1671
|
+
f(
|
|
1672
|
+
'pass',
|
|
1673
|
+
`${okRated.length} joins with printed fittings each take their moment with ${margin} times to spare: the nearest is ${low.x.j.label}, ${n3(low.M / 1000, 3)} N·m against about ${n3(low.cap / 1000, 2)} N·m, ${n3(low.margin, 1)} times under`,
|
|
1674
|
+
null,
|
|
1675
|
+
{
|
|
1676
|
+
code: 'frame.stress',
|
|
1677
|
+
at: r4(low.P),
|
|
1678
|
+
values: { moment: r3(low.M), strength: r3(low.cap), margin: r3(low.margin), joins: okRated.length },
|
|
1679
|
+
refs: { ...low.refs, item: low.x.j.fitted.item },
|
|
1680
|
+
},
|
|
1681
|
+
);
|
|
633
1682
|
}
|
|
634
1683
|
if (unrated.length) {
|
|
635
|
-
const most = unrated.reduce((p, q) => (q.M > p.M ? q : p)),
|
|
636
|
-
|
|
637
|
-
|
|
1684
|
+
const most = unrated.reduce((p, q) => (q.M > p.M ? q : p)),
|
|
1685
|
+
kindsOf = [...new Set(unrated.map((q) => q.x.j.kind))];
|
|
1686
|
+
f(
|
|
1687
|
+
'info',
|
|
1688
|
+
`${unrated.length} join${unrated.length > 1 ? 's' : ''} (${kindsOf.join(', ')}) ha${unrated.length > 1 ? 've' : 's'} no strength in the kit to check against: the largest moment is ${n3(most.M / 1000, 3)} N·m bending and ${n3(most.T / 1000, 3)} N·m twist at ${most.x.j.label}`,
|
|
1689
|
+
null,
|
|
1690
|
+
{
|
|
1691
|
+
code: 'frame.stress',
|
|
1692
|
+
at: r4(most.P),
|
|
1693
|
+
values: { moment: r3(most.M), twist: r3(most.T), joins: unrated.length },
|
|
1694
|
+
refs: { ...most.refs, moments: unrated.map((q) => ({ join: q.x.j.index, moment: r3(q.M), twist: r3(q.T) })) },
|
|
1695
|
+
},
|
|
1696
|
+
);
|
|
638
1697
|
}
|
|
639
1698
|
// ---- frame.buckling: each beam in compression against Euler's load, and the frame's own first factor ----
|
|
640
1699
|
const squeezed = [];
|
|
641
1700
|
for (const b of fm.beams.values()) {
|
|
642
|
-
let N = 0,
|
|
643
|
-
|
|
1701
|
+
let N = 0,
|
|
1702
|
+
w = null;
|
|
1703
|
+
for (const r of results)
|
|
1704
|
+
for (const res of [r.spring, r.rigid])
|
|
1705
|
+
for (const e of res.elements)
|
|
1706
|
+
if (e.of === b.id && e.axial < N) {
|
|
1707
|
+
N = e.axial;
|
|
1708
|
+
w = r.case;
|
|
1709
|
+
}
|
|
644
1710
|
if (N >= 0) continue;
|
|
645
|
-
const I = Math.min(b.section.Iy, b.section.Iz),
|
|
1711
|
+
const I = Math.min(b.section.Iy, b.section.Iz),
|
|
1712
|
+
Pcr = (Math.PI ** 2 * b.E * I) / (FRAME_CHECK.euler.value * b.L) ** 2;
|
|
646
1713
|
squeezed.push({ b, N: -N, Pcr, margin: Pcr / -N, case: w });
|
|
647
1714
|
}
|
|
648
1715
|
for (const q of squeezed) {
|
|
649
1716
|
const level = q.margin < 1 ? 'fail' : q.margin < margin ? 'warn' : 'pass';
|
|
650
1717
|
if (level === 'pass' && squeezed.length > 1) continue;
|
|
651
|
-
f(
|
|
652
|
-
|
|
1718
|
+
f(
|
|
1719
|
+
level,
|
|
1720
|
+
`${q.b.id}: ${n3(q.N, 2)} N along it in compression, against ${n3(q.Pcr, 0)} N it buckles at with both ends pinned (Euler, ${n3(q.b.L, 1)} mm): ${n3(q.margin, 1)} times under it`,
|
|
1721
|
+
level === 'pass' ? null : `${q.b.id}: buckles ${n3(q.margin, 1)}×`,
|
|
1722
|
+
{
|
|
1723
|
+
code: 'frame.buckling',
|
|
1724
|
+
at: r4(add(q.b.A, scale(q.b.u, q.b.L / 2))),
|
|
1725
|
+
between: [r4(q.b.A), r4(add(q.b.A, scale(q.b.u, q.b.L)))],
|
|
1726
|
+
values: { compression: r3(q.N), euler: r3(q.Pcr), margin: r3(q.margin) },
|
|
1727
|
+
refs: { beam: q.b.id, pose: q.case?.label },
|
|
1728
|
+
},
|
|
1729
|
+
);
|
|
653
1730
|
}
|
|
654
1731
|
const okSq = squeezed.filter((q) => q.margin >= margin);
|
|
655
1732
|
if (squeezed.length > 1 && okSq.length) {
|
|
656
1733
|
const low = okSq.reduce((p, q) => (q.margin < p.margin ? q : p));
|
|
657
|
-
f(
|
|
658
|
-
|
|
1734
|
+
f(
|
|
1735
|
+
'pass',
|
|
1736
|
+
`${okSq.length} beam${okSq.length > 1 ? 's are' : ' is'} in compression, each far under its buckling load with both ends pinned: the nearest is ${low.b.id}, ${n3(low.N, 2)} N against ${n3(low.Pcr, 0)} N, ${n3(low.margin, 1)} times under`,
|
|
1737
|
+
null,
|
|
1738
|
+
{
|
|
1739
|
+
code: 'frame.buckling',
|
|
1740
|
+
at: r4(add(low.b.A, scale(low.b.u, low.b.L / 2))),
|
|
1741
|
+
values: { compression: r3(low.N), euler: r3(low.Pcr), margin: r3(low.margin), beams: okSq.length },
|
|
1742
|
+
refs: { beam: low.b.id },
|
|
1743
|
+
},
|
|
1744
|
+
);
|
|
659
1745
|
}
|
|
660
1746
|
try {
|
|
661
|
-
const drawn = results[0],
|
|
662
|
-
|
|
663
|
-
|
|
1747
|
+
const drawn = results[0],
|
|
1748
|
+
fine = solveFrame(subdivide(fm.model, 4)),
|
|
1749
|
+
bk = fine.buckling({ loads: drawn.loads, count: 1 }),
|
|
1750
|
+
factor = bk.factors[0];
|
|
1751
|
+
const shape = bk.modes[0].shape,
|
|
1752
|
+
lead = Object.entries(shape).reduce((p, q) =>
|
|
1753
|
+
Math.hypot(...q[1].slice(0, 3)) > Math.hypot(...p[1].slice(0, 3)) ? q : p,
|
|
1754
|
+
),
|
|
1755
|
+
beam = lead[0].split(/[.@#/]/)[0];
|
|
1756
|
+
const listed = (ls) =>
|
|
1757
|
+
[...ls.reduce((m, l) => m.set(l.node, [...(m.get(l.node) ?? []), l.freedom]), new Map())]
|
|
1758
|
+
.map(([n, fr]) => `${n} (${fr.join(', ')})`)
|
|
1759
|
+
.join(', ');
|
|
664
1760
|
if (bk.tipped) {
|
|
665
1761
|
// nothing holds the frame where it is free, and its loads as drawn lean it further that way: it tips over before anything buckles
|
|
666
1762
|
const how = howFree(fm, waysAt(fine, bk.tipped));
|
|
667
|
-
f(
|
|
668
|
-
|
|
1763
|
+
f(
|
|
1764
|
+
'fail',
|
|
1765
|
+
`the whole frame tips over under its load as drawn before anything buckles: nothing holds it one way, ${how.length ? howSaid(how) : `free at ${listed(bk.tipped)}`}, and its squeezed beams lean it further that way, ${beam} moving most. Its buckling factor is 0. Hold it with "frame": { "supports" } fixed, brace it out of its plane, or join it into a box`,
|
|
1766
|
+
'frame tips over',
|
|
1767
|
+
{
|
|
1768
|
+
code: 'frame.buckling',
|
|
1769
|
+
at: r4(fm.nodes[lead[0]] ?? fm.nodes[Object.keys(fm.nodes)[0]]),
|
|
1770
|
+
values: { factor: 0 },
|
|
1771
|
+
refs: { beam, restsOn, tipped: bk.tipped, how: how.map((h) => h.says) },
|
|
1772
|
+
},
|
|
1773
|
+
);
|
|
669
1774
|
} else {
|
|
670
|
-
const level = factor < 1 ? 'fail' : factor < margin ? 'warn' : 'pass',
|
|
671
|
-
|
|
672
|
-
|
|
1775
|
+
const level = factor < 1 ? 'fail' : factor < margin ? 'warn' : 'pass',
|
|
1776
|
+
rests = bk.rests ?? [];
|
|
1777
|
+
f(
|
|
1778
|
+
level,
|
|
1779
|
+
`the whole frame, with the joins' springs, buckles first at ${rests.length ? 'no more than ' : ''}${n3(factor, 1)} times its load as drawn, ${beam} moving most: ${level === 'pass' ? 'far from it' : 'too near it: brace it, or a stiffer profile'} (rests on ${restsJoins})${rests.length ? `. Nothing holds it at ${listed(rests)}, where its loads pull it back as a hanging frame's do: the figure is with it held there, so the true one may be lower` : ''}`,
|
|
1780
|
+
level === 'pass' ? null : `frame buckles at ${n3(factor, 1)}×`,
|
|
1781
|
+
{
|
|
1782
|
+
code: 'frame.buckling',
|
|
1783
|
+
at: r4(fm.nodes[lead[0]] ?? fm.nodes[Object.keys(fm.nodes)[0]]),
|
|
1784
|
+
values: { factor: r3(factor) },
|
|
1785
|
+
refs: { beam, restsOn, ...(rests.length ? { rests } : {}) },
|
|
1786
|
+
},
|
|
1787
|
+
);
|
|
673
1788
|
}
|
|
674
|
-
} catch (e) {
|
|
675
|
-
|
|
676
|
-
|
|
1789
|
+
} catch (e) {
|
|
1790
|
+
if (e.code !== 'fea.frame.compression')
|
|
1791
|
+
f('info', `the frame's own buckling factor is not found: ${e.message}`, null, { code: 'frame.buckling' });
|
|
1792
|
+
}
|
|
1793
|
+
// ---- frame.tip: whether it tips over on its feet, under its weight and under frame.rack's push (frametip.mjs) ----
|
|
1794
|
+
let tip = null;
|
|
1795
|
+
try {
|
|
1796
|
+
const rk = rackOf(s, fm);
|
|
1797
|
+
tip = tipOf(fm, results, rk, sideways(down));
|
|
1798
|
+
tipCheck(tip, rk, f);
|
|
1799
|
+
} catch (e) {
|
|
1800
|
+
f('info', `whether the frame tips over is not found: ${e.message}`, null, { code: 'frame.tip' });
|
|
1801
|
+
}
|
|
1802
|
+
try {
|
|
1803
|
+
rackCheck(s, fm, f, { restsJoins, restsOn, tip });
|
|
1804
|
+
} catch (e) {
|
|
1805
|
+
f('info', `the frame's racking is not found: ${e.message}`, null, { code: 'frame.rack' });
|
|
1806
|
+
}
|
|
1807
|
+
try {
|
|
1808
|
+
frequencyCheck(s, fm, f, { restsJoins, restsOn, heldSaid });
|
|
1809
|
+
} catch (e) {
|
|
1810
|
+
f('info', `the frame's modes are not found: ${e.message}`, null, { code: 'frame.frequency' });
|
|
1811
|
+
}
|
|
677
1812
|
const ctx = { results, limitFor, sagAt, sagAlong, excitesOf, restsJoins, restsOn, margin };
|
|
678
|
-
try {
|
|
679
|
-
|
|
1813
|
+
try {
|
|
1814
|
+
couponChecks(s, fm, f, ctx);
|
|
1815
|
+
} catch (e) {
|
|
1816
|
+
f('info', `the beam coupon's figures are not predicted: ${e.message}`, null, { code: 'beam.coupon' });
|
|
1817
|
+
}
|
|
1818
|
+
if (s.a.frame?.printed != null)
|
|
1819
|
+
try {
|
|
1820
|
+
printableCheck(s, fm, f, ctx);
|
|
1821
|
+
} catch (e) {
|
|
1822
|
+
f('info', `which beams can be printed is not found: ${e.message}`, null, { code: 'beam.printable' });
|
|
1823
|
+
}
|
|
680
1824
|
return { model: fm, results };
|
|
681
1825
|
}
|
|
682
1826
|
|
|
1827
|
+
/**
|
|
1828
|
+
* frame.tip alone: the frame solved under its weight in each case (as frameChecks does), and whether it tips over on its
|
|
1829
|
+
* feet under that and under frame.rack's push, without the other checks. For a quick look over many sizes (the
|
|
1830
|
+
* create-rulecad sizes test). Null where there is no frame to solve; throws where it is not solved.
|
|
1831
|
+
* @param {object} s a built assembly @param {{ placeItems: Function, jointValues: Function, mul: Function }} helpers
|
|
1832
|
+
* @returns {{ findings: { level: string, text: string, code: string, values?: object, refs?: object }[], tip: object, rack: object | null } | null}
|
|
1833
|
+
*/
|
|
1834
|
+
export function frameTip(s, helpers) {
|
|
1835
|
+
const fm = frameModelOf(s, helpers);
|
|
1836
|
+
if (!fm || fm.empty) return null;
|
|
1837
|
+
const solved = solveAll(fm);
|
|
1838
|
+
if (solved.error) throw new Error(`the frame is not solved: ${solved.error}`);
|
|
1839
|
+
const rack = rackOf(s, fm),
|
|
1840
|
+
tip = tipOf(fm, solved.results, rack, sideways(fm.down)),
|
|
1841
|
+
findings = [];
|
|
1842
|
+
tipCheck(tip, rack, (level, text, card, extra = {}) => findings.push({ level, text, ...extra }));
|
|
1843
|
+
return { findings, tip, rack };
|
|
1844
|
+
}
|
|
1845
|
+
|
|
683
1846
|
// the two directions across "down" a frame is racked in, each named by the world axis it is nearest
|
|
684
1847
|
export function sideways(down) {
|
|
685
|
-
const flat = (v) => sub(v, scale(down, dot(v, down))),
|
|
686
|
-
|
|
1848
|
+
const flat = (v) => sub(v, scale(down, dot(v, down))),
|
|
1849
|
+
x = flat([1, 0, 0]),
|
|
1850
|
+
e1 = Math.hypot(...x) > 0.5 ? unitv(x) : unitv(flat([0, 1, 0])),
|
|
1851
|
+
e2 = unitv(cross(down, e1));
|
|
1852
|
+
const name = (v) => {
|
|
1853
|
+
const k = [0, 1, 2].reduce((p, q) => (Math.abs(v[q]) > Math.abs(v[p]) ? q : p), 0);
|
|
1854
|
+
return `along ${'xyz'[k]}`;
|
|
1855
|
+
};
|
|
687
1856
|
return [e1, e2].map((v) => ({ dir: v, name: name(v) }));
|
|
688
1857
|
}
|
|
689
1858
|
|
|
@@ -704,72 +1873,194 @@ const RACK_PANEL = { sheet: 'acrylic', thickness: 3 };
|
|
|
704
1873
|
* @returns {{ F: number, loadFrom: string, top: string[], H: number, lim: { value: number, from: string } } | null}
|
|
705
1874
|
*/
|
|
706
1875
|
export function rackOf(s, fm) {
|
|
707
|
-
const opts = s.a.frame?.rack ?? {},
|
|
1876
|
+
const opts = s.a.frame?.rack ?? {},
|
|
1877
|
+
F = opts.load != null ? s.num(opts.load) : FRAME_CHECK.push.value,
|
|
1878
|
+
down = fm.down,
|
|
1879
|
+
height = (n) => -dot(fm.nodes[n], down);
|
|
708
1880
|
const feet = fm.supports.map((sp) => fm.nodeAt(sp.beam, sp.z)).filter(Boolean);
|
|
709
|
-
const pool = fm.bays.length ? [...new Set(fm.bays.flatMap((b) => b.corners))] : Object.keys(fm.nodes),
|
|
1881
|
+
const pool = fm.bays.length ? [...new Set(fm.bays.flatMap((b) => b.corners))] : Object.keys(fm.nodes),
|
|
1882
|
+
topH = Math.max(...pool.map(height)),
|
|
1883
|
+
top = pool.filter((n) => height(n) > topH - 1);
|
|
710
1884
|
const H = topH - Math.min(...feet.map(height));
|
|
711
1885
|
if (!(H > 1) || !top.length) return null;
|
|
712
|
-
const lim =
|
|
1886
|
+
const lim =
|
|
1887
|
+
opts.limit != null
|
|
1888
|
+
? { value: s.num(opts.limit), from: "the assembly's frame.rack.limit" }
|
|
1889
|
+
: s.task?.accuracy != null
|
|
1890
|
+
? { value: s.task.accuracy, from: "the task's accuracy" }
|
|
1891
|
+
: {
|
|
1892
|
+
value: H / FRAME_CHECK.sway.value,
|
|
1893
|
+
from: `its height, ${n3(H, 1)} mm, over ${FRAME_CHECK.sway.value} (frame.sway)`,
|
|
1894
|
+
};
|
|
713
1895
|
return { F, loadFrom: opts.load != null ? 'frame.rack.load' : `frame.push, an estimate`, top, H, lim };
|
|
714
1896
|
}
|
|
715
1897
|
|
|
716
1898
|
/** How a frame moves where nothing holds it, in words (see howFree): for the sizing's racking limit. @param {object} fm @param {object[]} ways frame().mechanisms */
|
|
717
1899
|
export const freeSaid = (fm, ways) => howSaid(howFree(fm, ways));
|
|
718
1900
|
|
|
719
|
-
function rackCheck(s, fm, f, { restsJoins, restsOn }) {
|
|
1901
|
+
function rackCheck(s, fm, f, { restsJoins, restsOn, tip }) {
|
|
720
1902
|
const rk = rackOf(s, fm);
|
|
721
1903
|
if (!rk) return;
|
|
722
|
-
const { F, top, H, lim, loadFrom } = rk,
|
|
723
|
-
|
|
724
|
-
const
|
|
1904
|
+
const { F, top, H, lim, loadFrom } = rk,
|
|
1905
|
+
down = fm.down;
|
|
1906
|
+
const swayOf = (model, dir) => {
|
|
1907
|
+
const r = solveFrame(model).statics({
|
|
1908
|
+
loads: top.map((n) => ({ node: n, force: scale(dir, F / top.length) })),
|
|
1909
|
+
gravity: [0, 0, 0],
|
|
1910
|
+
});
|
|
1911
|
+
return top.reduce((t, n) => t + dot(r.displacements[n].slice(0, 3), dir), 0) / top.length;
|
|
1912
|
+
};
|
|
1913
|
+
const base = fm.model,
|
|
1914
|
+
els = base.elements;
|
|
725
1915
|
// the changes, each as the model's elements with it made
|
|
726
|
-
const brace = (bay) => {
|
|
1916
|
+
const brace = (bay) => {
|
|
1917
|
+
const lightest = bay.beams.map((id) => fm.beams.get(id)).reduce((p, q) => (q.section.Iy < p.section.Iy ? q : p));
|
|
1918
|
+
return [
|
|
1919
|
+
{
|
|
1920
|
+
id: `brace ${bay.name}`,
|
|
1921
|
+
a: bay.corners[0],
|
|
1922
|
+
b: bay.corners[2],
|
|
1923
|
+
section: lightest.section,
|
|
1924
|
+
material: { E: lightest.E, G: lightest.G, density: 0 },
|
|
1925
|
+
ends: { a: 'ball', b: 'ball' },
|
|
1926
|
+
},
|
|
1927
|
+
];
|
|
1928
|
+
};
|
|
727
1929
|
const panel = (bay) => [webOf(bay, RACK_PANEL.sheet, RACK_PANEL.thickness, 0, bay.name).element];
|
|
728
|
-
const gussetOn = (bays, list) =>
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
1930
|
+
const gussetOn = (bays, list) =>
|
|
1931
|
+
list.map((q) => {
|
|
1932
|
+
if (!q.ends || q.of == null) return q;
|
|
1933
|
+
let ends = q.ends;
|
|
1934
|
+
for (const x of fm.joins) {
|
|
1935
|
+
const bay = bays.find((b) => b.beams.includes(x.A.id) && b.beams.includes(x.B.id));
|
|
1936
|
+
if (!bay || x.A.id !== q.of) continue;
|
|
1937
|
+
const key = x.e === 'a' ? 'a' : 'b',
|
|
1938
|
+
mine = list.filter((e) => e.of === x.A.id),
|
|
1939
|
+
el = x.e === 'a' ? mine[0] : mine[mine.length - 1];
|
|
1940
|
+
if (el !== q || !ends[key] || typeof ends[key] !== 'object') continue;
|
|
1941
|
+
const axis = Math.abs(dot(bay.n, x.A.top)) > 0.7 ? 'rz' : 'ry',
|
|
1942
|
+
g = joinStiffness('gusset', x.A.m).bending;
|
|
1943
|
+
ends = { ...ends, [key]: { ...ends[key], [axis]: ends[key][axis] + g } };
|
|
1944
|
+
}
|
|
1945
|
+
return ends === q.ends ? q : { ...q, ends };
|
|
1946
|
+
});
|
|
1947
|
+
const made = (kind, bays) => ({
|
|
1948
|
+
...base,
|
|
1949
|
+
elements: kind === 'gusset' ? gussetOn(bays, els) : [...els, ...bays.flatMap(kind === 'brace' ? brace : panel)],
|
|
740
1950
|
});
|
|
741
|
-
const
|
|
742
|
-
|
|
1951
|
+
const what = {
|
|
1952
|
+
gusset: 'gussets at the corners of',
|
|
1953
|
+
brace: 'one diagonal brace in',
|
|
1954
|
+
panel: `a ${RACK_PANEL.thickness} mm ${RACK_PANEL.sheet} panel on`,
|
|
1955
|
+
};
|
|
743
1956
|
for (const { dir, name } of sideways(down)) {
|
|
1957
|
+
const { tips, tipSaid } = tipsWay(tip, name);
|
|
744
1958
|
let sway, rigid;
|
|
745
|
-
try {
|
|
1959
|
+
try {
|
|
1960
|
+
sway = swayOf(base, dir);
|
|
1961
|
+
rigid = swayOf(fm.rigid, dir);
|
|
1962
|
+
} catch (e) {
|
|
746
1963
|
if (e.code !== 'fea.frame.mechanism' || !e.driven) throw e;
|
|
747
1964
|
// a frame free to move this way (one plane on pinned feet, pushed across it): the push finds nothing to hold it
|
|
748
|
-
const at = e.loose.map((l) => `${l.node} (${l.freedom})`).join(', '),
|
|
749
|
-
|
|
750
|
-
|
|
1965
|
+
const at = e.loose.map((l) => `${l.node} (${l.freedom})`).join(', '),
|
|
1966
|
+
how = howFree(fm, waysAt(solveFrame(base), e.loose));
|
|
1967
|
+
f(
|
|
1968
|
+
'warn',
|
|
1969
|
+
`racked ${name}: nothing holds the frame that way, ${how.length ? howSaid(how) : `free at ${at}`}, so ${n3(F, 1)} N pushed at the top (${loadFrom}) moves it with nothing resisting. Fix its feet ("frame": { "supports" } fixed), or join beams across it to make a bay that way and brace it`,
|
|
1970
|
+
`racks ${name}: nothing holds it`,
|
|
1971
|
+
{
|
|
1972
|
+
code: 'frame.rack',
|
|
1973
|
+
at: r4(fm.nodes[top[0]]),
|
|
1974
|
+
values: { load: r3(F), limit: r3(lim.value), height: r3(H), tips: tips == null ? null : r3(tips) },
|
|
1975
|
+
refs: {
|
|
1976
|
+
direction: name,
|
|
1977
|
+
dir: r4(dir),
|
|
1978
|
+
top,
|
|
1979
|
+
free: e.loose,
|
|
1980
|
+
how: how.map((h) => h.says),
|
|
1981
|
+
limit: lim.from,
|
|
1982
|
+
load: loadFrom,
|
|
1983
|
+
restsOn,
|
|
1984
|
+
advise: null,
|
|
1985
|
+
},
|
|
1986
|
+
},
|
|
1987
|
+
);
|
|
751
1988
|
continue;
|
|
752
1989
|
}
|
|
753
|
-
const k = F / sway,
|
|
754
|
-
|
|
1990
|
+
const k = F / sway,
|
|
1991
|
+
k0 = F / rigid;
|
|
1992
|
+
const open = fm.bays.filter(
|
|
1993
|
+
(b, i) => Math.abs(dot(b.n, down)) < 0.1 && Math.abs(dot(b.n, dir)) < 0.1 && !fm.sheets.some((p) => p.bay === i),
|
|
1994
|
+
);
|
|
755
1995
|
const options = [];
|
|
756
1996
|
for (const kind of FRAME_CHECK.order.value) {
|
|
757
1997
|
if (!open.length) break;
|
|
758
|
-
const one = open
|
|
1998
|
+
const one = open
|
|
1999
|
+
.map((b) => ({ bays: [b], sway: swayOf(made(kind, [b]), dir) }))
|
|
2000
|
+
.reduce((p, q) => (q.sway < p.sway ? q : p));
|
|
759
2001
|
options.push({ kind, ...one, every: false });
|
|
760
2002
|
if (open.length > 1) options.push({ kind, bays: open, sway: swayOf(made(kind, open), dir), every: true });
|
|
761
2003
|
}
|
|
762
|
-
for (const o of options) {
|
|
2004
|
+
for (const o of options) {
|
|
2005
|
+
o.stiffness = F / o.sway;
|
|
2006
|
+
o.gain = sway / o.sway;
|
|
2007
|
+
}
|
|
763
2008
|
// open bays that hold the push by their joins' bending alone: a brace in each makes it many times stiffer
|
|
764
|
-
const braced = options.find((o) => o.kind === 'brace' && (o.every || open.length === 1)),
|
|
765
|
-
|
|
766
|
-
const
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
2009
|
+
const braced = options.find((o) => o.kind === 'brace' && (o.every || open.length === 1)),
|
|
2010
|
+
loose = braced && braced.gain >= 10;
|
|
2011
|
+
const over = sway > lim.value,
|
|
2012
|
+
singles = options.filter((o) => !o.every),
|
|
2013
|
+
pick = options
|
|
2014
|
+
.filter((o) => !o.every)
|
|
2015
|
+
.concat(options.filter((o) => o.every))
|
|
2016
|
+
.find((o) => o.sway <= lim.value);
|
|
2017
|
+
const say = (o) =>
|
|
2018
|
+
`${o.every ? `${what[o.kind].replace(/^one /, 'a ')} each of ${o.bays.map((b) => b.name).join(', ')}` : `${what[o.kind]} ${o.bays[0].name}`}`;
|
|
2019
|
+
const text = `racked ${name}: ${n3(F, 1)} N pushed at the top (${loadFrom}) sways it ${n3(sway)} mm with the joins' springs, ${fig(k)} N/mm${loose ? ` (low: its open bays hold the push by their joins' bending alone)` : ''}; ${n3(rigid)} mm, ${fig(k0)} N/mm, with the joins rigid. It rests on ${restsJoins}: against ${n3(lim.value)} mm, ${lim.from}${over ? `, ${n3(sway / lim.value, 2)} times over` : ''}. ${
|
|
2020
|
+
open.length
|
|
2021
|
+
? `Solved with each change: ${singles.map((o) => `${say(o)} makes it ${fig(o.stiffness)} N/mm (${n3(o.gain, 1)} times)`).join('; ')}${
|
|
2022
|
+
options.some((o) => o.every)
|
|
2023
|
+
? `; in every open bay ${name} (${open.length}): ${options
|
|
2024
|
+
.filter((o) => o.every)
|
|
2025
|
+
.map((o) => `${o.kind}s ${n3(o.gain, 1)} times`)
|
|
2026
|
+
.join(', ')}`
|
|
2027
|
+
: ''
|
|
2028
|
+
}. ${over ? (pick ? `The cheapest that brings it under the limit: ${say(pick)}, ${n3(pick.sway)} mm` : 'None of these alone brings it under the limit: stiffer joins, a stiffer profile, or bracing and panels together') : 'It stands within the limit as it is'}`
|
|
2029
|
+
: `There is no open bay of four joined beams ${name} to brace${over ? ': join beams round the sides to make one, then brace it' : ''}`
|
|
2030
|
+
}${tipSaid}`;
|
|
2031
|
+
f(over ? 'warn' : 'pass', text, over ? `racks ${name}: ${n3(sway, 2)} mm` : null, {
|
|
2032
|
+
code: 'frame.rack',
|
|
2033
|
+
at: r4(fm.nodes[top[0]]),
|
|
2034
|
+
values: {
|
|
2035
|
+
load: r3(F),
|
|
2036
|
+
sway: r3(sway),
|
|
2037
|
+
stiffness: r3(k),
|
|
2038
|
+
rigid: r3(rigid),
|
|
2039
|
+
rigidStiffness: r3(k0),
|
|
2040
|
+
limit: r3(lim.value),
|
|
2041
|
+
height: r3(H),
|
|
2042
|
+
tips: tips == null ? null : r3(tips),
|
|
2043
|
+
options: options.map((o) => ({
|
|
2044
|
+
kind: o.kind,
|
|
2045
|
+
bays: o.bays.map((b) => b.name),
|
|
2046
|
+
every: o.every,
|
|
2047
|
+
sway: r3(o.sway),
|
|
2048
|
+
stiffness: r3(o.stiffness),
|
|
2049
|
+
gain: r3(o.gain),
|
|
2050
|
+
})),
|
|
2051
|
+
},
|
|
2052
|
+
refs: {
|
|
2053
|
+
direction: name,
|
|
2054
|
+
dir: r4(dir),
|
|
2055
|
+
top,
|
|
2056
|
+
low: !!loose,
|
|
2057
|
+
limit: lim.from,
|
|
2058
|
+
load: loadFrom,
|
|
2059
|
+
restsOn,
|
|
2060
|
+
advise: over && pick ? { kind: pick.kind, bays: pick.bays.map((b) => b.name) } : null,
|
|
2061
|
+
panels: fm.webs.map((w) => ({ id: w.id, sheet: w.sheet, clips: w.clips, rests: w.rests })),
|
|
2062
|
+
},
|
|
2063
|
+
});
|
|
773
2064
|
}
|
|
774
2065
|
}
|
|
775
2066
|
|
|
@@ -781,8 +2072,27 @@ function rackCheck(s, fm, f, { restsJoins, restsOn }) {
|
|
|
781
2072
|
*/
|
|
782
2073
|
export function excitesOf(s) {
|
|
783
2074
|
const excites = [];
|
|
784
|
-
for (const d of s.motion.drives ?? [])
|
|
785
|
-
|
|
2075
|
+
for (const d of s.motion.drives ?? [])
|
|
2076
|
+
if (d.model?.stepAngle) {
|
|
2077
|
+
const rpm = workingSpeed(d.model, d.spec, d.supply),
|
|
2078
|
+
at = (rpm / 60) * (360 / d.model.stepAngle);
|
|
2079
|
+
excites.push({
|
|
2080
|
+
kind: 'step',
|
|
2081
|
+
what: `${d.id}'s full steps at ${n3(rpm, 1)} rpm`,
|
|
2082
|
+
Hz: at,
|
|
2083
|
+
from: d.spec.speed != null ? "the motor item's speed" : `the working speed of a ${d.model.name}`,
|
|
2084
|
+
});
|
|
2085
|
+
}
|
|
2086
|
+
if (s.task?.speed) {
|
|
2087
|
+
const acc = s.task.accel ?? FRAME_CHECK.ramp.value,
|
|
2088
|
+
t = s.task.speed / acc;
|
|
2089
|
+
excites.push({
|
|
2090
|
+
kind: 'move',
|
|
2091
|
+
what: `the task's moves, ramping to ${n3(s.task.speed, 1)} mm/s in ${n3(t, 3)} s`,
|
|
2092
|
+
Hz: 1 / t,
|
|
2093
|
+
from: s.task.accel != null ? "the task's speed and accel" : "the task's speed and frame.ramp",
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
786
2096
|
return excites;
|
|
787
2097
|
}
|
|
788
2098
|
|
|
@@ -793,27 +2103,75 @@ export function excitesOf(s) {
|
|
|
793
2103
|
* shakes the frame at about 1/t, and the lowest mode should stand twice that clear).
|
|
794
2104
|
*/
|
|
795
2105
|
function frequencyCheck(s, fm, f, { restsJoins, restsOn, heldSaid }) {
|
|
796
|
-
const solveIn = (model, values, count) =>
|
|
2106
|
+
const solveIn = (model, values, count) =>
|
|
2107
|
+
solveFrame(subdivide({ ...model, masses: fm.nodeMasses(values) }, 4)).modes({ count });
|
|
797
2108
|
let worst = null;
|
|
798
|
-
for (const c of fm.poses) {
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
2109
|
+
for (const c of fm.poses) {
|
|
2110
|
+
const r = solveIn(fm.model, c.values, 3);
|
|
2111
|
+
if (!worst || r.frequencies[0] < worst.r.frequencies[0]) worst = { c, r };
|
|
2112
|
+
}
|
|
2113
|
+
const hz = worst.r.frequencies,
|
|
2114
|
+
low = hz[0],
|
|
2115
|
+
rigid = solveIn(fm.rigid, worst.c.values, 1).frequencies[0];
|
|
2116
|
+
const shape = worst.r.modes[0].shape,
|
|
2117
|
+
lead = Object.entries(shape).reduce((p, q) =>
|
|
2118
|
+
Math.hypot(...q[1].slice(0, 3)) > Math.hypot(...p[1].slice(0, 3)) ? q : p,
|
|
2119
|
+
),
|
|
2120
|
+
beam = lead[0].split(/[.@#/]/)[0];
|
|
2121
|
+
const carried = Object.values(fm.nodeMasses(worst.c.values)).reduce((t, x) => t + x, 0),
|
|
2122
|
+
own = [...fm.beams.values()].reduce((t, b) => t + b.grams / 1000, 0);
|
|
802
2123
|
const excites = excitesOf(s);
|
|
803
|
-
const margin = FRAME_CHECK.margin.value,
|
|
804
|
-
|
|
805
|
-
const
|
|
2124
|
+
const margin = FRAME_CHECK.margin.value,
|
|
2125
|
+
band = FRAME_CHECK.band.value;
|
|
2126
|
+
const moves = excites.filter((x) => x.kind === 'move'),
|
|
2127
|
+
steps = excites.filter((x) => x.kind === 'step');
|
|
2128
|
+
const need = moves.length ? Math.max(...moves.map((x) => x.Hz)) * margin : 0,
|
|
2129
|
+
near = steps
|
|
2130
|
+
.map((x) => ({
|
|
2131
|
+
...x,
|
|
2132
|
+
modes: [...new Set(hz.filter((h) => Math.abs(h - x.Hz) <= band * x.Hz).map((h) => n3(h, 1)))],
|
|
2133
|
+
}))
|
|
2134
|
+
.filter((x) => x.modes.length);
|
|
806
2135
|
// a mode of 0 Hz is the frame moving where nothing holds it (fea's modes count a held freedom free): never a pass
|
|
807
2136
|
const free = worst.r.modes.filter((m) => m.free).length;
|
|
808
|
-
const level0 = !excites.length
|
|
2137
|
+
const level0 = !excites.length
|
|
2138
|
+
? 'info'
|
|
2139
|
+
: moves.length && low < need / margin
|
|
2140
|
+
? 'fail'
|
|
2141
|
+
: low < need || near.length
|
|
2142
|
+
? 'warn'
|
|
2143
|
+
: 'pass',
|
|
2144
|
+
level = free && (level0 === 'info' || level0 === 'pass') ? 'warn' : level0;
|
|
809
2145
|
const target = Math.max(need, ...near.map((x) => x.Hz * (1 + band)));
|
|
810
|
-
const advice = free
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
2146
|
+
const advice = free
|
|
2147
|
+
? `. Hold it there with "frame": { "supports" } fixed, brace it, or join it into a box: then it has a mode to lift`
|
|
2148
|
+
: level === 'warn' || level === 'fail'
|
|
2149
|
+
? `. To lift it to ${n3(target, 1)} Hz takes about ${n3((target / low) ** 2, 2)} times the stiffness where ${beam} moves (a deeper profile, a shorter span, stiffer joins or a brace), or as many times less mass moving with it`
|
|
2150
|
+
: '';
|
|
2151
|
+
const text = `the lowest mode is ${n3(low, 1)} Hz${free ? `: nothing holds the frame one way${heldSaid ? `, ${heldSaid}` : ''}, so it moves that way with nothing resisting${free > 1 ? ` (${free} such modes)` : ''}` : ''}${fm.poses.length > 1 ? `, worst ${worst.c.label}` : ''}, ${beam} moving most${fm.joins.length ? `, with the joins' springs; ${n3(rigid, 1)} Hz with the joins rigid` : ''}. Its next: ${hz
|
|
2152
|
+
.slice(1)
|
|
2153
|
+
.map((h) => `${n3(h, 1)} Hz`)
|
|
2154
|
+
.join(
|
|
2155
|
+
', ',
|
|
2156
|
+
)}. With ${n3(own, 3)} kg of beams and ${n3(carried, 3)} kg carried, each item's mass at the node it is carried at (its rotary inertia left out); it rests on ${restsJoins}. ${
|
|
2157
|
+
excites.length
|
|
2158
|
+
? `The machine excites: ${excites.map((x) => `${x.what}, ${n3(x.Hz, 1)} Hz`).join('; ')}. ${near.length ? `A mode within ${band * 100}% of ${near.map((x) => `${x.what} (the mode${x.modes.length > 1 ? 's' : ''} at ${x.modes.join(' and ')} Hz)`).join(', ')}: it rings while the motor runs at that speed` : ''}${near.length && moves.length ? '; ' : ''}${moves.length ? (low < need ? `under ${margin} times the moves' ${n3(need / margin, 1)} Hz` : `${n3(low / (need / margin), 1)} times over the moves' ${n3(need / margin, 1)} Hz, where ${margin} is wanted`) : ''}`
|
|
2159
|
+
: 'Nothing named excites it: no stepper drives a joint and the assembly has no task'
|
|
2160
|
+
}${advice}`;
|
|
2161
|
+
f(level, text.replace(/\. $/, ''), level === 'warn' || level === 'fail' ? `frame mode ${n3(low, 1)} Hz` : null, {
|
|
2162
|
+
code: 'frame.frequency',
|
|
2163
|
+
at: r4(fm.nodes[lead[0]] ?? fm.nodes[Object.keys(fm.nodes)[0]]),
|
|
2164
|
+
values: {
|
|
2165
|
+
Hz: r3(low),
|
|
2166
|
+
rigid: r3(rigid),
|
|
2167
|
+
modes: hz.map(r3),
|
|
2168
|
+
...(free ? { free } : {}),
|
|
2169
|
+
beams: r3(own),
|
|
2170
|
+
carried: r3(carried),
|
|
2171
|
+
...(excites.length ? { excites: excites.map((x) => ({ what: x.what, Hz: r3(x.Hz), kind: x.kind })) } : {}),
|
|
2172
|
+
},
|
|
2173
|
+
refs: { pose: worst.c.label, beam, restsOn, excites: excites.map((x) => ({ what: x.what, from: x.from })) },
|
|
2174
|
+
});
|
|
817
2175
|
}
|
|
818
2176
|
|
|
819
2177
|
/**
|
|
@@ -824,18 +2182,47 @@ function frequencyCheck(s, fm, f, { restsJoins, restsOn, heldSaid }) {
|
|
|
824
2182
|
*/
|
|
825
2183
|
export function frameMode(s, helpers) {
|
|
826
2184
|
let fm;
|
|
827
|
-
try {
|
|
2185
|
+
try {
|
|
2186
|
+
fm = frameModelOf(s, helpers);
|
|
2187
|
+
} catch {
|
|
2188
|
+
return null;
|
|
2189
|
+
}
|
|
828
2190
|
if (!fm || fm.empty) return null;
|
|
829
2191
|
try {
|
|
830
2192
|
let worst = null;
|
|
831
|
-
for (const c of fm.poses) {
|
|
832
|
-
|
|
2193
|
+
for (const c of fm.poses) {
|
|
2194
|
+
const m = subdivide({ ...fm.model, masses: fm.nodeMasses(c.values) }, 4),
|
|
2195
|
+
r = solveFrame(m).modes({ count: 1 });
|
|
2196
|
+
if (!worst || r.frequencies[0] < worst.r.frequencies[0]) worst = { c, r, m };
|
|
2197
|
+
}
|
|
2198
|
+
const shape = worst.r.modes[0].shape,
|
|
2199
|
+
pts = Object.values(worst.m.nodes),
|
|
2200
|
+
size = Math.max(...[0, 1, 2].map((k) => Math.max(...pts.map((p) => p[k])) - Math.min(...pts.map((p) => p[k])))),
|
|
2201
|
+
k = size / 10;
|
|
833
2202
|
const move = (n) => scale((shape[n] ?? [0, 0, 0]).slice(0, 3), k);
|
|
834
|
-
const lines = worst.m.elements.map((e) => ({
|
|
835
|
-
|
|
2203
|
+
const lines = worst.m.elements.map((e) => ({
|
|
2204
|
+
id: String(e.id),
|
|
2205
|
+
a: worst.m.nodes[e.a],
|
|
2206
|
+
b: worst.m.nodes[e.b],
|
|
2207
|
+
da: move(e.a),
|
|
2208
|
+
db: move(e.b),
|
|
2209
|
+
}));
|
|
2210
|
+
const lead = Object.entries(shape).reduce((p, q) =>
|
|
2211
|
+
Math.hypot(...q[1].slice(0, 3)) > Math.hypot(...p[1].slice(0, 3)) ? q : p,
|
|
2212
|
+
),
|
|
2213
|
+
beam = lead[0].split(/[.@#/]/)[0];
|
|
836
2214
|
const Hz = worst.r.frequencies[0];
|
|
837
|
-
return {
|
|
838
|
-
|
|
2215
|
+
return {
|
|
2216
|
+
Hz,
|
|
2217
|
+
pose: worst.c.label,
|
|
2218
|
+
beam,
|
|
2219
|
+
lines,
|
|
2220
|
+
scale: k,
|
|
2221
|
+
label: `lowest mode ${n3(Hz, 1)} Hz${fm.poses.length > 1 ? `, ${worst.c.label}` : ''}, ${beam} moving most; its movement drawn as a tenth of the frame's size (scaled)`,
|
|
2222
|
+
};
|
|
2223
|
+
} catch {
|
|
2224
|
+
return null;
|
|
2225
|
+
}
|
|
839
2226
|
}
|
|
840
2227
|
|
|
841
2228
|
/**
|
|
@@ -843,13 +2230,27 @@ export function frameMode(s, helpers) {
|
|
|
843
2230
|
* up) or another side, the frame as drawn faint behind. @param {ReturnType<typeof frameMode>} md @param {{ view?: 'front' | 'side' | 'top', title?: string }} [o] @returns {string}
|
|
844
2231
|
*/
|
|
845
2232
|
export function frameModeSvg(md, o = {}) {
|
|
846
|
-
const [i, j] = o.view === 'side' ? [1, 2] : o.view === 'top' ? [0, 1] : [0, 2],
|
|
847
|
-
|
|
848
|
-
const
|
|
849
|
-
|
|
2233
|
+
const [i, j] = o.view === 'side' ? [1, 2] : o.view === 'top' ? [0, 1] : [0, 2],
|
|
2234
|
+
all = md.lines.flatMap((l) => [l.a, l.b, add(l.a, l.da), add(l.b, l.db), sub(l.a, l.da), sub(l.b, l.db)]);
|
|
2235
|
+
const lo = [Math.min(...all.map((p) => p[i])), Math.min(...all.map((p) => p[j]))],
|
|
2236
|
+
hi = [Math.max(...all.map((p) => p[i])), Math.max(...all.map((p) => p[j]))];
|
|
2237
|
+
const W = 640,
|
|
2238
|
+
pad = 40,
|
|
2239
|
+
k = (W - 2 * pad) / Math.max(hi[0] - lo[0], hi[1] - lo[1], 1),
|
|
2240
|
+
H = Math.ceil((hi[1] - lo[1]) * k + 2 * pad + 56);
|
|
2241
|
+
const X = (p) => (pad + (p[i] - lo[0]) * k).toFixed(1),
|
|
2242
|
+
Y = (p) => (H - 56 - pad - (p[j] - lo[1]) * k).toFixed(1),
|
|
2243
|
+
pts = (a, b) => `${X(a)},${Y(a)} ${X(b)},${Y(b)}`;
|
|
850
2244
|
const esc = (t) => String(t).replace(/&/g, '&').replace(/</g, '<');
|
|
851
2245
|
// (from one extreme: a viewer that shows no animation shows the mode at its largest)
|
|
852
|
-
const swing = (l) =>
|
|
2246
|
+
const swing = (l) =>
|
|
2247
|
+
[
|
|
2248
|
+
pts(add(l.a, l.da), add(l.b, l.db)),
|
|
2249
|
+
pts(l.a, l.b),
|
|
2250
|
+
pts(sub(l.a, l.da), sub(l.b, l.db)),
|
|
2251
|
+
pts(l.a, l.b),
|
|
2252
|
+
pts(add(l.a, l.da), add(l.b, l.db)),
|
|
2253
|
+
].join(';');
|
|
853
2254
|
return `<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}" font-family="system-ui, sans-serif">
|
|
854
2255
|
<rect width="100%" height="100%" fill="#fff"/>
|
|
855
2256
|
${md.lines.map((l) => `<polyline points="${pts(l.a, l.b)}" fill="none" stroke="#ddd" stroke-width="6" stroke-linecap="round"/>`).join('\n')}
|
|
@@ -866,34 +2267,131 @@ ${o.title ? `<text x="${pad}" y="${H - 40}" font-size="13" font-weight="600">${e
|
|
|
866
2267
|
* @param {object} s a built assembly @returns {{ file: string, Hz: number, beam: string } | null}
|
|
867
2268
|
*/
|
|
868
2269
|
export function writeFrameMode(s) {
|
|
869
|
-
const md = frameMode(s, { placeItems, jointValues, mul }),
|
|
2270
|
+
const md = frameMode(s, { placeItems, jointValues, mul }),
|
|
2271
|
+
file = paths.exports(s.project, `${s.name}.frame-mode.svg`);
|
|
870
2272
|
if (fs.existsSync(file)) fs.rmSync(file);
|
|
871
2273
|
if (!md) return null;
|
|
872
2274
|
// the two views that hold the mode's largest movement, the one across the frame's larger extent first
|
|
873
|
-
const move = [0, 1, 2].map((k) => md.lines.reduce((t, l) => t + Math.abs(l.da[k]) + Math.abs(l.db[k]), 0)),
|
|
874
|
-
|
|
875
|
-
const
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
2275
|
+
const move = [0, 1, 2].map((k) => md.lines.reduce((t, l) => t + Math.abs(l.da[k]) + Math.abs(l.db[k]), 0)),
|
|
2276
|
+
most = move.indexOf(Math.max(...move));
|
|
2277
|
+
const extent = [0, 1, 2].map(
|
|
2278
|
+
(k) =>
|
|
2279
|
+
Math.max(...md.lines.flatMap((l) => [l.a[k], l.b[k]])) - Math.min(...md.lines.flatMap((l) => [l.a[k], l.b[k]])),
|
|
2280
|
+
);
|
|
2281
|
+
const VIEWS = { front: [0, 2], side: [1, 2], top: [0, 1] },
|
|
2282
|
+
names = { front: 'from the front', side: 'from the side', top: 'from above' };
|
|
2283
|
+
const [v1, v2] = Object.keys(VIEWS)
|
|
2284
|
+
.filter((v) => VIEWS[v].includes(most))
|
|
2285
|
+
.sort((p, q) => extent[VIEWS[q].find((k) => k !== most)] - extent[VIEWS[p].find((k) => k !== most)]);
|
|
2286
|
+
const front = frameModeSvg(md, { view: v1, title: `${s.a.title || s.name}, ${names[v1]}` }),
|
|
2287
|
+
side = frameModeSvg(md, { view: v2, title: names[v2] });
|
|
2288
|
+
const h = (t) => Number(/height="(\d+)"/.exec(t)[1]),
|
|
2289
|
+
inner = (t) => t.replace(/^<svg[^>]*>\n?/, '').replace(/<\/svg>\s*$/, '');
|
|
879
2290
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
880
|
-
fs.writeFileSync(
|
|
2291
|
+
fs.writeFileSync(
|
|
2292
|
+
file,
|
|
2293
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="640" height="${h(front) + h(side)}" viewBox="0 0 640 ${h(front) + h(side)}" font-family="system-ui, sans-serif">\n${inner(front)}\n<g transform="translate(0 ${h(front)})">${inner(side)}</g>\n</svg>\n`,
|
|
2294
|
+
);
|
|
881
2295
|
return { file, Hz: md.Hz, beam: md.beam };
|
|
882
2296
|
}
|
|
883
2297
|
|
|
884
2298
|
// every pose's solve, with the springs and rigid; and, as drawn, each load alone
|
|
2299
|
+
// The frame after creep, where any beam is drawn printed: each printed beam's modulus at its creep share
|
|
2300
|
+
// (PRINTED_DEFAULTS.creep_modulus, the share beamCreep takes), the joins' springs as they are, solved in each case
|
|
2301
|
+
// but a motor's stall (a moment, not a load held for months). Null where no beam is printed or the solve fails.
|
|
2302
|
+
function creptOf(fm, results) {
|
|
2303
|
+
const printed = [...fm.beams.values()].filter((b) => b.m?.printed?.creep?.modulus > 0);
|
|
2304
|
+
if (!printed.length) return null;
|
|
2305
|
+
const share = (b) => b.m.printed.creep.modulus,
|
|
2306
|
+
model = {
|
|
2307
|
+
...fm.model,
|
|
2308
|
+
materials: {
|
|
2309
|
+
...fm.model.materials,
|
|
2310
|
+
...Object.fromEntries(
|
|
2311
|
+
printed.map((b) => {
|
|
2312
|
+
const m = fm.model.materials[b.id];
|
|
2313
|
+
return [b.id, { ...m, E: m.E * share(b), G: m.G * share(b) }];
|
|
2314
|
+
}),
|
|
2315
|
+
),
|
|
2316
|
+
},
|
|
2317
|
+
};
|
|
2318
|
+
let solver;
|
|
2319
|
+
try {
|
|
2320
|
+
solver = solveFrame(model);
|
|
2321
|
+
} catch (e) {
|
|
2322
|
+
// (a fault in the kit is thrown on, not taken for a frame it cannot solve)
|
|
2323
|
+
if (e instanceof TypeError || e instanceof ReferenceError) throw e;
|
|
2324
|
+
return null;
|
|
2325
|
+
}
|
|
2326
|
+
const out = new Map();
|
|
2327
|
+
for (const r of results) {
|
|
2328
|
+
if (r.case.stall) continue;
|
|
2329
|
+
const res = solver.statics({ loads: r.loads });
|
|
2330
|
+
for (const e of res.elements)
|
|
2331
|
+
if (e.of != null) {
|
|
2332
|
+
const b = fm.beams.get(e.of),
|
|
2333
|
+
el = model.elements.find((q) => q.id === e.id);
|
|
2334
|
+
e._from = dot(sub(fm.nodes[el.a], b.A), b.u);
|
|
2335
|
+
}
|
|
2336
|
+
out.set(r, res);
|
|
2337
|
+
}
|
|
2338
|
+
const shares = [...new Set(printed.map(share))],
|
|
2339
|
+
ids = printed.map((b) => b.id);
|
|
2340
|
+
return {
|
|
2341
|
+
results: out,
|
|
2342
|
+
said: `${ids.join(', ')} printed bending as if at ${shares.join(' or ')} of ${ids.length > 1 ? 'their' : 'its'} modulus`,
|
|
2343
|
+
refs: {
|
|
2344
|
+
beams: ids,
|
|
2345
|
+
share: shares.length === 1 ? shares[0] : shares,
|
|
2346
|
+
rule: 'PRINTED_DEFAULTS.creep_modulus',
|
|
2347
|
+
kind: 'estimate',
|
|
2348
|
+
},
|
|
2349
|
+
};
|
|
2350
|
+
}
|
|
2351
|
+
|
|
885
2352
|
function solveAll(fm) {
|
|
886
2353
|
let fs, fr, results;
|
|
887
|
-
try {
|
|
888
|
-
|
|
2354
|
+
try {
|
|
2355
|
+
fs = solveFrame(fm.model);
|
|
2356
|
+
fr = solveFrame(fm.rigid);
|
|
2357
|
+
} catch (e) {
|
|
2358
|
+
return { error: e.message, code: e.code };
|
|
2359
|
+
}
|
|
2360
|
+
try {
|
|
2361
|
+
results = solveCases(fm, fs, fr);
|
|
2362
|
+
} catch (e) {
|
|
2363
|
+
if (e.code !== 'fea.frame.mechanism') throw e;
|
|
2364
|
+
return { error: e.message, code: e.code };
|
|
2365
|
+
}
|
|
889
2366
|
// each element's start along its beam, for sagAlong
|
|
890
|
-
for (const r of results)
|
|
2367
|
+
for (const r of results)
|
|
2368
|
+
for (const res of [r.spring, r.rigid])
|
|
2369
|
+
for (const e of res.elements)
|
|
2370
|
+
if (e.of != null) {
|
|
2371
|
+
const b = fm.beams.get(e.of),
|
|
2372
|
+
el = fm.model.elements.find((q) => q.id === e.id);
|
|
2373
|
+
e._from = dot(sub(fm.nodes[el.a], b.A), b.u);
|
|
2374
|
+
}
|
|
891
2375
|
return { results, loose: fs.loose, mechanisms: fs.mechanisms };
|
|
892
2376
|
}
|
|
893
2377
|
function solveCases(fm, fs, fr) {
|
|
894
2378
|
const results = fm.cases.map((c) => {
|
|
895
|
-
const loads = fm.nodeLoads(c.values, null, c.push, c.stall),
|
|
896
|
-
|
|
2379
|
+
const loads = fm.nodeLoads(c.values, null, c.push, c.stall),
|
|
2380
|
+
spring = fs.statics({ loads }),
|
|
2381
|
+
rigid = fr.statics({ loads }),
|
|
2382
|
+
out = { case: c, loads, spring, rigid, values: c.values };
|
|
2383
|
+
{
|
|
2384
|
+
out.alone = new Map();
|
|
2385
|
+
for (const l of fm.loads) {
|
|
2386
|
+
const ll = fm.nodeLoads(c.values, l),
|
|
2387
|
+
n = ll[0]?.node;
|
|
2388
|
+
if (!n) continue;
|
|
2389
|
+
out.alone.set(l, {
|
|
2390
|
+
sag: sagAt(fs.statics({ loads: ll, gravity: [0, 0, 0] }), n, fm.down),
|
|
2391
|
+
rigid: sagAt(fr.statics({ loads: ll, gravity: [0, 0, 0] }), n, fm.down),
|
|
2392
|
+
});
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
897
2395
|
return out;
|
|
898
2396
|
});
|
|
899
2397
|
return results;
|
|
@@ -908,19 +2406,42 @@ function solveCases(fm, fs, fr) {
|
|
|
908
2406
|
*/
|
|
909
2407
|
export function frameShape(s, helpers, o = {}) {
|
|
910
2408
|
let fm;
|
|
911
|
-
try {
|
|
2409
|
+
try {
|
|
2410
|
+
fm = frameModelOf(s, helpers);
|
|
2411
|
+
} catch {
|
|
2412
|
+
return null;
|
|
2413
|
+
}
|
|
912
2414
|
if (!fm || fm.empty) return null;
|
|
913
2415
|
const solved = solveAll(fm);
|
|
914
2416
|
if (solved.error) return null;
|
|
915
|
-
const r = solved.results.reduce((p, q) => (q.spring.deflection.most > p.spring.deflection.most ? q : p)).spring,
|
|
916
|
-
|
|
917
|
-
const
|
|
2417
|
+
const r = solved.results.reduce((p, q) => (q.spring.deflection.most > p.spring.deflection.most ? q : p)).spring,
|
|
2418
|
+
most = r.deflection.most;
|
|
2419
|
+
const pts = Object.values(fm.nodes),
|
|
2420
|
+
size = Math.max(...[0, 1, 2].map((c) => Math.max(...pts.map((p) => p[c])) - Math.min(...pts.map((p) => p[c]))));
|
|
2421
|
+
const k = o.scale ?? (most > 0 ? size / 20 / most : 1);
|
|
918
2422
|
const beams = [...fm.beams.values()].map((b) => {
|
|
919
|
-
const els = r.elements.filter((e) => e.of === b.id),
|
|
920
|
-
|
|
2423
|
+
const els = r.elements.filter((e) => e.of === b.id),
|
|
2424
|
+
drawn = [],
|
|
2425
|
+
moved = [];
|
|
2426
|
+
for (const e of els) {
|
|
2427
|
+
const el = fm.model.elements.find((q) => q.id === e.id),
|
|
2428
|
+
A = fm.nodes[el.a],
|
|
2429
|
+
B = fm.nodes[el.b];
|
|
2430
|
+
e.along.x.forEach((x, i) => {
|
|
2431
|
+
const t = x / e.length,
|
|
2432
|
+
P = add(A, scale(sub(B, A), t));
|
|
2433
|
+
drawn.push(P);
|
|
2434
|
+
moved.push(add(P, scale(e.along.d[i], k)));
|
|
2435
|
+
});
|
|
2436
|
+
}
|
|
921
2437
|
return { id: b.id, drawn, moved };
|
|
922
2438
|
});
|
|
923
|
-
return {
|
|
2439
|
+
return {
|
|
2440
|
+
scale: k,
|
|
2441
|
+
most,
|
|
2442
|
+
beams,
|
|
2443
|
+
label: `deflection drawn ${fig(k)} times its size (scaled): ${n3(most)} mm at most, with the joins' springs`,
|
|
2444
|
+
};
|
|
924
2445
|
}
|
|
925
2446
|
|
|
926
2447
|
/**
|
|
@@ -928,10 +2449,16 @@ export function frameShape(s, helpers, o = {}) {
|
|
|
928
2449
|
* shape it takes in colour, and the scale written on it. @param {ReturnType<typeof frameShape>} sh @param {{ view?: 'front' | 'side' | 'top', title?: string }} [o] @returns {string}
|
|
929
2450
|
*/
|
|
930
2451
|
export function frameShapeSvg(sh, o = {}) {
|
|
931
|
-
const [i, j] = o.view === 'side' ? [1, 2] : o.view === 'top' ? [0, 1] : [0, 2],
|
|
932
|
-
|
|
933
|
-
const
|
|
934
|
-
|
|
2452
|
+
const [i, j] = o.view === 'side' ? [1, 2] : o.view === 'top' ? [0, 1] : [0, 2],
|
|
2453
|
+
all = sh.beams.flatMap((b) => [...b.drawn, ...b.moved]);
|
|
2454
|
+
const lo = [Math.min(...all.map((p) => p[i])), Math.min(...all.map((p) => p[j]))],
|
|
2455
|
+
hi = [Math.max(...all.map((p) => p[i])), Math.max(...all.map((p) => p[j]))];
|
|
2456
|
+
const W = 640,
|
|
2457
|
+
pad = 40,
|
|
2458
|
+
k = (W - 2 * pad) / Math.max(hi[0] - lo[0], hi[1] - lo[1], 1),
|
|
2459
|
+
H = Math.ceil((hi[1] - lo[1]) * k + 2 * pad + 56);
|
|
2460
|
+
const X = (p) => (pad + (p[i] - lo[0]) * k).toFixed(1),
|
|
2461
|
+
Y = (p) => (H - 56 - pad - (p[j] - lo[1]) * k).toFixed(1);
|
|
935
2462
|
const line = (ps, attrs) => `<polyline points="${ps.map((p) => `${X(p)},${Y(p)}`).join(' ')}" fill="none" ${attrs}/>`;
|
|
936
2463
|
const esc = (t) => String(t).replace(/&/g, '&').replace(/</g, '<');
|
|
937
2464
|
return `<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}" font-family="system-ui, sans-serif">
|
|
@@ -950,12 +2477,18 @@ ${o.title ? `<text x="${pad}" y="${H - 40}" font-size="13" font-weight="600">${e
|
|
|
950
2477
|
* @param {object} s a built assembly @returns {{ file: string, scale: number, most: number } | null}
|
|
951
2478
|
*/
|
|
952
2479
|
export function writeFrameShape(s) {
|
|
953
|
-
const sh = frameShape(s, { placeItems, jointValues, mul }),
|
|
2480
|
+
const sh = frameShape(s, { placeItems, jointValues, mul }),
|
|
2481
|
+
file = paths.exports(s.project, `${s.name}.frame-sag.svg`);
|
|
954
2482
|
if (fs.existsSync(file)) fs.rmSync(file);
|
|
955
2483
|
if (!sh) return null;
|
|
956
|
-
const front = frameShapeSvg(sh, { view: 'front', title: `${s.a.title || s.name}, from the front` }),
|
|
957
|
-
|
|
2484
|
+
const front = frameShapeSvg(sh, { view: 'front', title: `${s.a.title || s.name}, from the front` }),
|
|
2485
|
+
side = frameShapeSvg(sh, { view: 'side', title: 'from the side' });
|
|
2486
|
+
const h = (t) => Number(/height="(\d+)"/.exec(t)[1]),
|
|
2487
|
+
inner = (t) => t.replace(/^<svg[^>]*>\n?/, '').replace(/<\/svg>\s*$/, '');
|
|
958
2488
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
959
|
-
fs.writeFileSync(
|
|
2489
|
+
fs.writeFileSync(
|
|
2490
|
+
file,
|
|
2491
|
+
`<svg xmlns="http://www.w3.org/2000/svg" width="640" height="${h(front) + h(side)}" viewBox="0 0 640 ${h(front) + h(side)}" font-family="system-ui, sans-serif">\n${inner(front)}\n<g transform="translate(0 ${h(front)})">${inner(side)}</g>\n</svg>\n`,
|
|
2492
|
+
);
|
|
960
2493
|
return { file, scale: sh.scale, most: sh.most };
|
|
961
2494
|
}
|