@rulecad/cad 0.7.56 → 0.7.58
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 +103 -1
- package/CHANGELOG.md +241 -0
- package/EXAMPLES.md +782 -2
- package/README.md +719 -8
- package/TUTORIAL.md +2 -0
- package/bin/cad.mjs +135 -29
- package/lib/assembly.mjs +83 -17
- package/lib/beams.mjs +46 -13
- package/lib/bought.mjs +41 -5
- package/lib/buildpage.mjs +8 -3
- package/lib/edit.mjs +10 -4
- package/lib/fasten.mjs +279 -47
- package/lib/fittings.mjs +313 -0
- package/lib/framebuild.mjs +463 -0
- package/lib/framecheck.mjs +831 -0
- package/lib/framegen.mjs +111 -0
- package/lib/frameheat.mjs +94 -0
- package/lib/frameprint.mjs +277 -0
- package/lib/frames.mjs +5 -3
- package/lib/framesize.mjs +261 -0
- package/lib/guides.mjs +354 -0
- package/lib/jigs.mjs +240 -0
- package/lib/joins.mjs +263 -0
- package/lib/kit.mjs +190 -0
- package/lib/links.mjs +11 -3
- package/lib/list.mjs +28 -8
- package/lib/loads.mjs +12 -4
- package/lib/measured.mjs +86 -17
- package/lib/motors.mjs +7 -3
- package/lib/optimise.mjs +18 -3
- package/lib/order.mjs +28 -14
- package/lib/panels.mjs +220 -0
- package/lib/plates.mjs +37 -16
- package/lib/services.mjs +132 -0
- package/lib/sheet.mjs +15 -1
- package/lib/slotnuts.mjs +159 -0
- package/lib/task.mjs +43 -3
- package/lib/wires.mjs +2 -1
- package/package.json +6 -6
- package/schemas/assembly.schema.json +34 -9
|
@@ -0,0 +1,831 @@
|
|
|
1
|
+
// A frame's own checks (@rulecad/fea/frame): the assembly's beams and joins become beam elements joined at nodes, and
|
|
2
|
+
// the frame is solved under its weight and what it carries.
|
|
3
|
+
//
|
|
4
|
+
// The model. Each beam that is placed and still (no moving joint carries it) is cut into elements at every place
|
|
5
|
+
// something meets it: its ends, each join that lands on it, each item mounted on it, each load and named point, each
|
|
6
|
+
// support. A join puts a's end on a node at b's axis through a rigid link (a's end stands half b's width off b's
|
|
7
|
+
// axis), with the join's spring (its bending and twist, @rulecad/frames' joinStiffness, an estimate until the joint
|
|
8
|
+
// rig measures it) at a's element end. Supports are the assembly's "frame": { "supports" } where given, else its feet
|
|
9
|
+
// (the beam ends a foot, a levelling foot, a castor plate or a stacking foot is fitted to), else its lowest beam ends:
|
|
10
|
+
// each held from moving and free to turn (pinned), as a foot on a floor is.
|
|
11
|
+
//
|
|
12
|
+
// The loads. Gravity on every beam (its sheet's mass per metre, else its section and alloy), on every item mounted on
|
|
13
|
+
// a beam (its mass at its centre, as a force and a moment at the node where its chain of mounts meets the beam), and
|
|
14
|
+
// the assembly's "loads" that are masses. A mass carried by a moving joint mounted on a beam (a carriage on a guide, a
|
|
15
|
+
// door on its hinge) is solved at each pose: the joint at each end of its travel, every named pose, and as drawn; the
|
|
16
|
+
// worst is named.
|
|
17
|
+
//
|
|
18
|
+
// Every figure is worked out twice: with the joins' springs, and with the joins rigid. The springs are the honest
|
|
19
|
+
// estimate; rigid joins bound it from the stiff side. Each finding gives both and says which joins it rests on.
|
|
20
|
+
// Units: mm, N, N·mm, MPa, kg.
|
|
21
|
+
import fs from 'node:fs';
|
|
22
|
+
import path from 'node:path';
|
|
23
|
+
import { frame as solveFrame, subdivide } from '@rulecad/fea/frame';
|
|
24
|
+
import { placeItems, jointValues, mul } from '@rulecad/model-link';
|
|
25
|
+
import { paths } from './workspace.mjs';
|
|
26
|
+
import { massesOf } from './loads.mjs';
|
|
27
|
+
import { axisOf, workingSpeed } from './motors.mjs';
|
|
28
|
+
import { joinStiffness, PANEL_DEFAULTS } from '@rulecad/frames';
|
|
29
|
+
import { printableCheck, couponChecks, printedOption } from './frameprint.mjs';
|
|
30
|
+
|
|
31
|
+
const G = 9.80665;
|
|
32
|
+
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], sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
34
|
+
const add = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]], scale = (a, k) => [a[0] * k, a[1] * k, a[2] * k];
|
|
35
|
+
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) => [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]);
|
|
37
|
+
const n3 = (x, d = 3) => String(+Number(x).toFixed(d)), r3 = (x) => +Number(x).toFixed(3), r4 = (p) => p.map(r3);
|
|
38
|
+
const fig = (x) => String(+Number(x).toPrecision(3));
|
|
39
|
+
// 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
|
+
// frame's micrometres are still figures
|
|
41
|
+
const small = (x) => x && Math.abs(x) < 0.1;
|
|
42
|
+
const sagN = (x) => (small(x) ? fig(x) : n3(x)), sagR = (x) => (small(x) ? +Number(x).toPrecision(3) : r3(x));
|
|
43
|
+
const shown = (v) => (v === undefined ? 'nothing' : JSON.stringify(v));
|
|
44
|
+
|
|
45
|
+
/** The working figures of the frame checks, each with what it rests on. */
|
|
46
|
+
export const FRAME_CHECK = {
|
|
47
|
+
sag: { value: 360, unit: 'span per mm', 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', kind: 'default', source: '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', checked: '2026-11-17' },
|
|
48
|
+
margin: { value: 2, unit: '×', 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', kind: 'default', source: 'The kit\'s standard of sizing from the load with about twice the margin (issue 240)', checked: '2026-11-17' },
|
|
49
|
+
link: { value: 1000, unit: '×', 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', kind: 'default', source: 'A working figure of @rulecad/cad: doubles keep about 16 digits, and a ratio of 1000 costs 3 of them', checked: '2026-11-17' },
|
|
50
|
+
euler: { value: 1, unit: '', 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', kind: 'default', source: '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)', checked: '2026-11-17' },
|
|
51
|
+
push: { value: 20, unit: 'N', 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', kind: 'estimate', source: 'A working figure of @rulecad/cad, with no measurement behind it', checked: '2026-11-17' },
|
|
52
|
+
sway: { value: 400, unit: 'height per mm', 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', kind: 'default', source: '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', checked: '2026-11-17' },
|
|
53
|
+
order: { value: ['gusset', 'brace', 'panel'], unit: '', 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', kind: 'default', source: 'A working order of @rulecad/cad, by the parts each needs; cad list prices them', checked: '2026-11-17' },
|
|
54
|
+
clip: { value: 200, unit: 'N/mm', 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', kind: 'estimate', source: 'A working guess of @rulecad/cad, with no measurement behind it: a panel on the joint rig would measure it', checked: '2026-11-17' },
|
|
55
|
+
band: { value: 0.2, unit: '', 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', kind: 'estimate', source: 'A working figure of @rulecad/cad: a lightly damped mode amplifies a forcing within about ±20% of it several times over', checked: '2026-11-17' },
|
|
56
|
+
ramp: { value: 500, unit: 'mm/s²', 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', kind: 'default', source: 'The same default as cad machine\'s task.accel (lib/machine.mjs)', checked: '2026-11-17' },
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** The sheets a panel is cut from as a shear web: each one's modulus and Poisson's ratio, with what each rests on. */
|
|
60
|
+
export const SHEET_STIFFNESS = {
|
|
61
|
+
acrylic: { E: 3300, nu: 0.37, kind: 'spec', source: 'Evonik PLEXIGLAS GS technical information (2025): modulus of elasticity 3300 MPa (ISO 527-2, short-term), Poisson\'s ratio 0.37 (ISO 527-1)' },
|
|
62
|
+
polycarbonate: { E: 2400, nu: 0.38, kind: 'community', source: 'Typical figures for solid polycarbonate sheet, not checked against one maker\'s data sheet' },
|
|
63
|
+
aluminium: { E: 70000, nu: 0.33, kind: 'community', source: 'Typical figures for wrought aluminium alloys, not checked against a 5754 data sheet' },
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// A web's bar is of a made-up material this stiff, its area chosen to give the stiffness wanted along it
|
|
67
|
+
const WEB_E = 1000;
|
|
68
|
+
const unitv = (v) => { const l = Math.hypot(...v); return v.map((c) => c / l); };
|
|
69
|
+
|
|
70
|
+
// The bays of a frame: four beams round a rectangle in one plane, two each way, each neighbouring pair joined to each
|
|
71
|
+
// other or both joined to one beam at one place (the top of a corner-post box: its rails join the posts, not each
|
|
72
|
+
// other). Each corner is the node nearest where two neighbouring beams' axes cross, on either of them or on the beam
|
|
73
|
+
// both join (a join puts a station on the beam it lands on there).
|
|
74
|
+
function baysOf(beams, joins, nodes, nodeAt) {
|
|
75
|
+
const direct = (p, q) => joins.some((x) => (x.A.id === p && x.B.id === q) || (x.A.id === q && x.B.id === p));
|
|
76
|
+
const reachOf = (id) => { const m = beams.get(id).m.profile; return Math.max(m.width, m.height); };
|
|
77
|
+
// 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
|
|
78
|
+
const memo = new Map(), via = (p, q) => { const key = `${p}|${q}`; if (!memo.has(key)) memo.set(key, through(p, q)); return memo.get(key); };
|
|
79
|
+
const through = (p, q) => { const out = new Set(); for (const x of joins) for (const y of joins) { if (x === y) continue; const [xo, xr, xz] = x.A.id === p ? [p, x.B.id, x.zb] : x.B.id === p ? [p, x.A.id, x.za] : [];
|
|
80
|
+
const [yo, yr, yz] = y.A.id === q ? [q, y.B.id, y.zb] : y.B.id === q ? [q, y.A.id, y.za] : []; if (xo && yo && xr === yr && xr !== p && xr !== q && Math.abs(xz - yz) <= reachOf(xr)) out.add(xr); } return [...out]; };
|
|
81
|
+
const linked = (p, q) => direct(p, q) || via(p, q).length > 0;
|
|
82
|
+
const ids = [...beams.keys()], out = [], seen = new Set();
|
|
83
|
+
const par = (p, q) => Math.abs(Math.abs(dot(p.u, q.u)) - 1) < 1e-3, square = (p, q) => Math.abs(dot(p.u, q.u)) < 1e-3;
|
|
84
|
+
for (const a of ids) for (const b of ids) if (b !== a && linked(a, b)) for (const c of ids) if (c !== a && c !== b && linked(b, c)) for (const d of ids) {
|
|
85
|
+
if ([a, b, c].includes(d) || !linked(c, d) || !linked(d, a)) continue;
|
|
86
|
+
const key = [a, b, c, d].sort().join(',');
|
|
87
|
+
if (seen.has(key)) continue;
|
|
88
|
+
const B = [a, b, c, d].map((id) => beams.get(id));
|
|
89
|
+
if (!(par(B[0], B[2]) && par(B[1], B[3]) && square(B[0], B[1]))) continue;
|
|
90
|
+
const n = unitv(cross(B[0].u, B[1].u));
|
|
91
|
+
if (B.some((q) => Math.abs(dot(sub(q.A, B[0].A), n)) > 1)) continue;
|
|
92
|
+
const reach = Math.max(...B.map((q) => Math.max(q.m.profile.width, q.m.profile.height)));
|
|
93
|
+
const corners = B.map((p, i) => {
|
|
94
|
+
const q = B[(i + 1) % 4], X = add(p.A, scale(p.u, dot(sub(q.A, p.A), p.u)));
|
|
95
|
+
let best = null, gap = Infinity;
|
|
96
|
+
for (const r of [p, q, ...via(p.id, q.id).map((id) => beams.get(id))]) for (const z of r.stations) { const nm = nodeAt(r, z), g = Math.hypot(...sub(nodes[nm], X)); if (g < gap) { gap = g; best = nm; } }
|
|
97
|
+
return gap <= reach ? best : null;
|
|
98
|
+
});
|
|
99
|
+
if (corners.some((x) => !x) || new Set(corners).size < 4) continue;
|
|
100
|
+
seen.add(key);
|
|
101
|
+
const P = corners.map((x) => nodes[x]);
|
|
102
|
+
out.push({ beams: [a, b, c, d], n, corners, size: [Math.hypot(...sub(P[1], P[0])), Math.hypot(...sub(P[2], P[1]))], name: [a, b, c, d].join('-') });
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* A panel on a bay as a shear web: one diagonal bar across the bay, free to bend at both ends, as stiff along it as the sheet
|
|
109
|
+
* in shear in series with its clips' grip. Racked along a side of the bay (width a, height h, diagonal d), a bar of
|
|
110
|
+
* stiffness k along it gives k (a/d)²; the sheet in shear gives G t a / h, so the sheet's bar is G t d² / (a h). The
|
|
111
|
+
* clips: shear flow q = F/a round all four edges, each of n clips (k_c each, at a pitch 2(a + h)/n) carrying q times
|
|
112
|
+
* its pitch; their strain energy equal to F δ / 2 gives d² n k_c / (4 (a + h)²) for the clips' bar. The two in series.
|
|
113
|
+
* Its ends: a ball at one corner and pinned at the other. Both free to bend, so it carries only its pull or push; the
|
|
114
|
+
* pinned end holds its spin, so a solve that splits it into pieces (modes, buckling) finds no free twist at the inner
|
|
115
|
+
* nodes. It carries no twist into the frame either, as the ball end lets it turn freely about its own length.
|
|
116
|
+
* @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
|
|
117
|
+
*/
|
|
118
|
+
function webOf(bay, sheet, t, clips, id) {
|
|
119
|
+
const m = SHEET_STIFFNESS[sheet] ?? SHEET_STIFFNESS.acrylic, [a, h] = bay.size, d = Math.hypot(a, h), Gs = m.E / (2 * (1 + m.nu));
|
|
120
|
+
const n = clips > 0 ? clips : 2 * (Math.max(2, Math.ceil(a / PANEL_DEFAULTS.pitch.value) + 1) + Math.max(2, Math.ceil(h / PANEL_DEFAULTS.pitch.value) + 1));
|
|
121
|
+
const sheetBar = (Gs * t * d * d) / (a * h), clipBar = (d * d * n * FRAME_CHECK.clip.value) / (4 * (a + h) ** 2), k = 1 / (1 / sheetBar + 1 / clipBar), A = (k * d) / WEB_E;
|
|
122
|
+
return { id, sheet, thickness: t, clips: n, sheetBar, clipBar, k, rests: [{ name: `${sheet} sheet`, E: m.E, nu: m.nu, kind: m.kind, source: m.source }, { name: 'frame.clip', value: FRAME_CHECK.clip.value, kind: FRAME_CHECK.clip.kind }],
|
|
123
|
+
element: { id: `panel ${id}`, a: bay.corners[0], b: bay.corners[2], section: { A, Iy: A * (d / 10) ** 2, Iz: A * (d / 10) ** 2, J: A * (d / 10) ** 2 }, material: { E: WEB_E, G: WEB_E / 2.6, density: 0 }, ends: { a: 'ball', b: 'pinned' } } };
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// what a join's spring rests on, in a few words
|
|
127
|
+
const restsWord = (k) => (k.measured?.bending && k.measured?.twist ? 'measured' : k.fitting ? 'a printed fitting by finite elements' : k.bought?.own ? `${k.bought.set}'s own figures, ${k.kind}` : 'an estimate');
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The frame of a built assembly as @rulecad/fea/frame's model, with what it rests on: the beams it holds, its nodes and
|
|
131
|
+
* elements (with the joins' springs, and a copy with the joins rigid), its supports, and each load case. Null where the
|
|
132
|
+
* assembly has no beams. Refused by name: frame.supports that name no beam or say neither pinned nor fixed.
|
|
133
|
+
* @param {object} s a built assembly @param {{ placeItems: Function, jointValues: Function, mul: Function }} helpers
|
|
134
|
+
*/
|
|
135
|
+
export function frameModelOf(s, helpers) {
|
|
136
|
+
const motion = s.motion;
|
|
137
|
+
if (!motion || !s.objects.some((o) => o.beam && !o.unplaced)) return null;
|
|
138
|
+
// beams with no joins and nothing said of their supports are parts held by other means (fastened to a plate, a lone
|
|
139
|
+
// upright on a printed base): not a frame to solve
|
|
140
|
+
if (!s.joins?.length && !['supports', 'limit', 'points', 'rack', 'printed', 'size'].some((k) => s.a.frame?.[k] != null)) return null;
|
|
141
|
+
const { placeItems, jointValues, mul } = helpers, ids = motion.items.map((x) => x[0]), base = jointValues(motion, motion.pose ?? undefined), worlds = placeItems(motion, base);
|
|
142
|
+
const opts = s.a.frame ?? {};
|
|
143
|
+
if (typeof opts !== 'object' || Array.isArray(opts)) throw new Error(`frame is { "supports", "limit", "points", "rack", "cut", "heat", "printed", "size" } (got ${shown(opts)})`);
|
|
144
|
+
for (const k of Object.keys(opts)) if (!['supports', 'limit', 'points', 'rack', 'cut', 'heat', 'printed', 'size'].includes(k)) throw new Error(`frame has no "${k}": it takes supports, limit, points, rack, cut, heat, printed, size`);
|
|
145
|
+
printedOption(opts.printed);
|
|
146
|
+
if (opts.rack != null) {
|
|
147
|
+
if (typeof opts.rack !== 'object' || Array.isArray(opts.rack)) throw new Error(`frame.rack is { "load": 20, "limit": 1 }: the side push in N and the sway allowed in mm (got ${shown(opts.rack)})`);
|
|
148
|
+
for (const k of Object.keys(opts.rack)) if (!['load', 'limit'].includes(k)) throw new Error(`frame.rack has no "${k}": it takes load (N) and limit (mm)`);
|
|
149
|
+
for (const k of ['load', 'limit']) if (opts.rack[k] != null && !(s.num(opts.rack[k]) > 0)) throw new Error(`frame.rack.${k} is ${k === 'load' ? 'the side push in N' : 'the sway allowed in mm'}, above 0 (got ${shown(opts.rack[k])})`);
|
|
150
|
+
}
|
|
151
|
+
const byChild = new Map(motion.joints.map((j) => [j.child, j])), moving = (j) => !j.at && j.type !== 'fixed';
|
|
152
|
+
const movesWith = (k) => { for (let i = k, n = 0; n < 99; n++) { const j = byChild.get(i); if (!j) return false; if (moving(j)) return true; i = j.parent; } return false; };
|
|
153
|
+
const down = (() => { const g = motion.gravity || [0, 0, -1], l = Math.hypot(...g) || 1; return g.map((c) => c / l); })();
|
|
154
|
+
// the beams: still ones only (a beam on a carriage is a load, not the frame: its weight is carried below)
|
|
155
|
+
const beams = new Map(), left = [], riding = [];
|
|
156
|
+
for (const o of s.objects) {
|
|
157
|
+
if (!o.beam || o.unplaced) continue;
|
|
158
|
+
const k = ids.indexOf(o.id);
|
|
159
|
+
if (k < 0) continue;
|
|
160
|
+
if (movesWith(k)) { riding.push({ o, k }); continue; }
|
|
161
|
+
const W = worlds[k], m = o.beam, L = m.length, A = rowsAt(W, [0, 0, 0]), u = [W[2], W[6], W[10]], top = [W[1], W[5], W[9]];
|
|
162
|
+
const mat = m.profile.material, F = m.figures, E = m.material?.modulus ?? mat?.modulus, nu = mat?.poisson ?? mat?.figures?.poisson?.value;
|
|
163
|
+
const Gs = mat?.figures?.shear_modulus?.value ?? (E && nu != null ? E / (2 * (1 + nu)) : null), grams = m.weight?.sheet ?? m.mass ?? 0;
|
|
164
|
+
// a printed beam's strength is the plastic's for its pose: along its layers lying down, across them standing up
|
|
165
|
+
const strength = m.printed?.strength ?? mat?.strength ?? mat?.figures?.strength?.value ?? null;
|
|
166
|
+
beams.set(o.id, { id: o.id, k, m, L, W, A, u, top, E, G: Gs, strength, alloy: m.material?.name ?? mat?.name ?? null, grams,
|
|
167
|
+
section: { A: F.area.value, Iy: F.inertiaX.value, Iz: F.inertiaY.value, J: F.torsion.value, Wy: F.modulusX.value, Wz: F.modulusY.value }, stations: new Set([0, L]) });
|
|
168
|
+
}
|
|
169
|
+
const missing = [...beams.values()].filter((b) => !(b.E > 0 && b.G > 0 && b.section.Iy > 0 && b.section.J > 0)).map((b) => b.id);
|
|
170
|
+
for (const id of missing) { beams.delete(id); left.push(id); }
|
|
171
|
+
if (!beams.size) return { beams, left, missing, empty: true };
|
|
172
|
+
const at = (b, z) => add(b.A, scale(b.u, z)), station = (b, P) => Math.max(0, Math.min(b.L, dot(sub(P, b.A), b.u)));
|
|
173
|
+
const snap = (b, z) => { for (const q of b.stations) if (Math.abs(q - z) < 0.05) return q; b.stations.add(z); return z; };
|
|
174
|
+
// where an item's chain of mounts meets a still beam: that joint, and whether anything on the way moves
|
|
175
|
+
const mountOf = (k) => { let mover = null; for (let i = k, n = 0; n < 99; n++) { const j = byChild.get(i); if (!j) return null; if (moving(j)) mover = mover ?? j; if (beams.has(ids[j.parent])) return { beam: beams.get(ids[j.parent]), joint: j, mover }; i = j.parent; } return null; };
|
|
176
|
+
// a mount's station on its beam at a set of joint values: a slide along the beam moves it
|
|
177
|
+
// (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)
|
|
178
|
+
const mountStation = (mt, values) => { const j = mt.joint, z = j.a[11], v = j.type === 'prismatic' ? (values[j.id]?.[0] ?? 0) : 0; return Math.max(0, Math.min(mt.beam.L, (mt.shift ?? 0) + (mt.sign ?? 1) * (z + v * j.a[10]))); };
|
|
179
|
+
|
|
180
|
+
// 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
|
|
181
|
+
// 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.
|
|
182
|
+
// Each takes the share of o's weight the lever rule gives (o's weight at its middle); null where there is no other
|
|
183
|
+
// such beam, more than one, or o's middle is not between them (then its joint's beam carries it all)
|
|
184
|
+
const restsOn = (o, k, mt) => {
|
|
185
|
+
const W = worlds[k], u = [W[2], W[6], W[10]], O = rowsAt(W, [0, 0, 0]), L = o.beam.length, T = mt.beam;
|
|
186
|
+
if (Math.abs(dot(u, T.u)) > 1e-3) return null;
|
|
187
|
+
const s1 = mt.joint.b[11], P1 = rowsAt(W, [0, 0, s1]), drop = dot(sub(add(T.A, scale(T.u, dot(sub(P1, T.A), T.u))), P1), down);
|
|
188
|
+
const others = [...beams.values()].filter((b) => b !== T && Math.abs(Math.abs(dot(b.u, T.u)) - 1) < 1e-6).map((b) => {
|
|
189
|
+
const s2 = dot(sub(b.A, O), u), P2 = add(O, scale(u, s2)), foot = add(b.A, scale(b.u, dot(sub(P2, b.A), b.u)));
|
|
190
|
+
return { b, s2, gap: Math.hypot(...sub(sub(foot, P2), scale(down, dot(sub(foot, P2), down)))), drop: dot(sub(foot, P2), down) };
|
|
191
|
+
}).filter((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);
|
|
192
|
+
if (others.length !== 1) return null;
|
|
193
|
+
const { b, s2 } = others[0], c = L / 2, p1 = (s2 - c) / (s2 - s1);
|
|
194
|
+
if (!(p1 >= 0 && p1 <= 1)) return null;
|
|
195
|
+
const sign = Math.sign(dot(b.u, T.u)), shift = dot(sub(T.A, b.A), b.u);
|
|
196
|
+
return [{ mount: mt, part: p1, s: s1 }, { mount: { ...mt, beam: b, sign, shift }, part: 1 - p1, s: s2 }];
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
// the poses: as drawn, each named pose, and each moving joint mounted on a beam at either end of its travel (a slide in
|
|
200
|
+
// its middle too)
|
|
201
|
+
const cases = [{ label: 'as drawn', values: base }];
|
|
202
|
+
for (const p of Object.keys(motion.poses || {})) cases.push({ label: `pose ${p}`, values: jointValues(motion, p) });
|
|
203
|
+
const movers = motion.joints.filter((j) => moving(j) && beams.has(ids[j.parent]) && j.dofs?.length === 1);
|
|
204
|
+
// (a slide also at the middle of its travel, where a carriage between two supports bends its beam most, unless drawn there)
|
|
205
|
+
for (const j of movers) {
|
|
206
|
+
const [lo, hi] = j.dofs[0], mid = (lo + hi) / 2, drawn = base[j.id]?.[0];
|
|
207
|
+
for (const v of [lo, hi, ...(j.type === 'prismatic' && !(drawn != null && Math.abs(drawn - mid) < 1e-6) ? [mid] : [])]) cases.push({ label: `${j.id} at ${n3(v, 1)}`, values: { ...base, [j.id]: [v] } });
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// what weighs on the frame: items (beams' own weight is the elements'), and the masses of "loads"
|
|
211
|
+
const masses = massesOf(s, { placeItems, jointValues }), carried = [], loose = [], unknown = [];
|
|
212
|
+
// 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
|
|
213
|
+
// beams that make no bay, its weight is spread along those of the frame
|
|
214
|
+
const sheets = (s.panels ?? []).filter((p) => !p.door && p.bay?.some((id) => beams.has(id))).map((p) => ({ ...p, kg: (p.model?.grams ?? 0) / 1000 }));
|
|
215
|
+
for (const q of masses) {
|
|
216
|
+
if (beams.has(q.id) || left.includes(q.id) || riding.some((x) => x.o.id === q.id) || sheets.some((p) => p.id === q.id)) continue;
|
|
217
|
+
if (!q.known) { unknown.push(q.id); continue; }
|
|
218
|
+
if (!(q.kg > 0)) continue;
|
|
219
|
+
const mt = mountOf(q.item);
|
|
220
|
+
if (!mt) { loose.push(q.id); continue; }
|
|
221
|
+
carried.push({ id: q.id, item: q.item, kg: q.kg, centre: q.centre, mount: mt });
|
|
222
|
+
}
|
|
223
|
+
// a beam riding a moving joint (a gantry's cross beam on its carriages): its sheet's weight at its middle, carried
|
|
224
|
+
// where its chain of mounts meets a still beam, like any mounted item
|
|
225
|
+
// A riding beam lying across two parallel beams at one level (a gantry's beam on its two side beams) rests on both,
|
|
226
|
+
// though its joint is on one: its weight is shared between them by the lever rule, as a beam on two supports
|
|
227
|
+
const rides = [];
|
|
228
|
+
for (const { o, k } of riding) {
|
|
229
|
+
const kg = (o.beam.weight?.sheet ?? o.beam.mass ?? 0) / 1000, mt = mountOf(k), on = byChild.get(k);
|
|
230
|
+
if (!(kg > 0)) { unknown.push(o.id); continue; }
|
|
231
|
+
if (!mt) { loose.push(o.id); continue; }
|
|
232
|
+
const share = mt.joint.child === k ? restsOn(o, k, mt) : null;
|
|
233
|
+
if (share) for (const x of share) carried.push({ id: o.id, item: k, kg: kg * x.part, centre: [0, 0, x.s], mount: x.mount });
|
|
234
|
+
else carried.push({ id: o.id, item: k, kg, centre: [0, 0, o.beam.length / 2], mount: mt });
|
|
235
|
+
rides.push({ id: o.id, joint: (mt.mover ?? on)?.id ?? null, kg, on: share ? share.map((x) => ({ beam: x.mount.beam.id, share: x.part })) : [{ beam: mt.beam.id, share: 1 }] });
|
|
236
|
+
}
|
|
237
|
+
const loads = [];
|
|
238
|
+
(motion.loads || []).forEach((l, i) => {
|
|
239
|
+
if (l.mass == null) return;
|
|
240
|
+
const said = s.a.loads?.[i]?.at, where = typeof said === 'string' ? said : said?.item ? `${said.item}${said.at ? ` at (${said.at.map((x) => n3(s.num(x), 1)).join(', ')})` : ''}` : ids[l.item], point = [l.frame[3], l.frame[7], l.frame[11]];
|
|
241
|
+
if (beams.has(ids[l.item])) { const b = beams.get(ids[l.item]); loads.push({ index: i, kg: l.mass, where, item: l.item, point, beam: b, z: snap(b, Math.max(0, Math.min(b.L, point[2]))), note: l.note }); return; }
|
|
242
|
+
const mt = mountOf(l.item);
|
|
243
|
+
if (!mt) { loose.push(`load ${i + 1} (${where})`); return; }
|
|
244
|
+
loads.push({ index: i, kg: l.mass, where, item: l.item, point, mount: mt, note: l.note });
|
|
245
|
+
});
|
|
246
|
+
for (const c of [...carried, ...loads.filter((l) => l.mount)]) for (const cs of cases) snap(c.mount.beam, mountStation(c.mount, cs.values));
|
|
247
|
+
// named points, and every guide's travel
|
|
248
|
+
const points = (opts.points ?? []).map((p, i) => {
|
|
249
|
+
const t = String(p), id = t.split('.')[0], b = beams.get(id);
|
|
250
|
+
if (!b) throw new Error(`frame.points ${i + 1}: ${shown(p)} is on a beam of the frame, as x1.top@50% (beams: ${[...beams.keys()].join(', ')})`);
|
|
251
|
+
const r = motion.address(t, `frame.points ${i + 1}`);
|
|
252
|
+
return { where: t, beam: b, z: snap(b, Math.max(0, Math.min(b.L, r.frame[11]))) };
|
|
253
|
+
});
|
|
254
|
+
const guides = (s.guides || []).filter((g) => beams.has(g.beam)).map((g) => {
|
|
255
|
+
const b = beams.get(g.beam), from = Math.max(0, g.from), to = Math.min(b.L, g.from + g.length);
|
|
256
|
+
snap(b, from); snap(b, to); snap(b, (from + to) / 2);
|
|
257
|
+
return { id: g.id, kind: g.kind, beam: b, from, to, tolerance: (g.terms ?? g.model?.terms ?? []).find((x) => x.term === 'rail parallelism') ?? null };
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
// supports
|
|
261
|
+
const supports = [];
|
|
262
|
+
if (opts.supports != null) {
|
|
263
|
+
if (typeof opts.supports !== 'object' || Array.isArray(opts.supports)) throw new Error(`frame.supports is { "z1.a": "pinned", "z2.a": "fixed" } (got ${shown(opts.supports)})`);
|
|
264
|
+
for (const [addr, how] of Object.entries(opts.supports)) {
|
|
265
|
+
const id = addr.split('.')[0], b = beams.get(id);
|
|
266
|
+
if (!b) throw new Error(`frame.supports: "${addr}" is on a beam of the frame, as z1.a or x1.bottom@50% (beams: ${[...beams.keys()].join(', ')})`);
|
|
267
|
+
if (!['pinned', 'fixed', 'resting'].includes(how)) throw new Error(`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)})`);
|
|
268
|
+
const k = b.u.findIndex((c) => Math.abs(Math.abs(c) - 1) < 1e-6);
|
|
269
|
+
if (how === 'resting' && k < 0) throw new Error(`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`);
|
|
270
|
+
const r = motion.address(addr, 'frame.supports');
|
|
271
|
+
supports.push({ where: addr, beam: b, z: snap(b, Math.max(0, Math.min(b.L, r.frame[11]))), how, why: 'frame.supports', said: true, ...(how === 'resting' ? { twist: `r${'xyz'[k]}` } : {}) });
|
|
272
|
+
}
|
|
273
|
+
} else {
|
|
274
|
+
for (const it of s.a.items || []) {
|
|
275
|
+
const kind = it.fitting?.kind ?? (it.bought && /foot|castor/i.test(it.bought) ? 'foot' : null), m = typeof it.at === 'string' ? /^([\w-]+)\.([ab])(\.\d+)?$/.exec(it.at.trim()) : null;
|
|
276
|
+
if (!m || !FEET.includes(kind) || !beams.has(m[1])) continue;
|
|
277
|
+
const b = beams.get(m[1]);
|
|
278
|
+
if (!supports.some((x) => x.beam === b && x.z === (m[2] === 'a' ? 0 : b.L))) supports.push({ where: `${m[1]}.${m[2]}`, beam: b, z: m[2] === 'a' ? 0 : b.L, how: 'pinned', why: `${it.id}, a ${kind}` });
|
|
279
|
+
}
|
|
280
|
+
if (!supports.length) {
|
|
281
|
+
const ends = [...beams.values()].flatMap((b) => [['a', 0], ['b', b.L]].map(([e, z]) => ({ b, e, z, h: -dot(at(b, z), down) })));
|
|
282
|
+
const low = Math.min(...ends.map((x) => x.h));
|
|
283
|
+
for (const x of ends) if (x.h <= low + 1) supports.push({ where: `${x.b.id}.${x.e}`, beam: x.b, z: x.z, how: 'pinned', why: 'a lowest end' });
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// joins between beams of the frame
|
|
288
|
+
const joins = [];
|
|
289
|
+
for (const j of s.joins || []) {
|
|
290
|
+
const [ai, bi] = j.items, A = beams.get(ai), B = beams.get(bi);
|
|
291
|
+
if (!A || !B) continue;
|
|
292
|
+
const e = j.end[0], zb = j.model.b.end != null ? (j.model.b.end === 'a' ? 0 : B.L) : j.model.b.distance;
|
|
293
|
+
joins.push({ j, A, B, e, za: e === 'a' ? 0 : A.L, zb: snap(B, zb), k: j.model.stiffness });
|
|
294
|
+
}
|
|
295
|
+
// only what a support holds through joins: the rest is left out, by name
|
|
296
|
+
const group = new Map([...beams.keys()].map((id) => [id, id])), root = (x) => { while (group.get(x) !== x) x = group.get(x); return x; };
|
|
297
|
+
for (const x of joins) group.set(root(x.A.id), root(x.B.id));
|
|
298
|
+
const held = new Set(supports.map((x) => root(x.beam.id)));
|
|
299
|
+
for (const id of [...beams.keys()]) if (!held.has(root(id))) { left.push(id); beams.delete(id); }
|
|
300
|
+
const keep = (x) => beams.has(x.beam?.id ?? x.mount?.beam.id);
|
|
301
|
+
|
|
302
|
+
// nodes and elements
|
|
303
|
+
const nodes = {}, elements = [], sections = {}, materials = {}, nameAt = new Map();
|
|
304
|
+
const nodeName = (b, z) => (z === 0 ? `${b.id}.a` : z === b.L ? `${b.id}.b` : `${b.id}@${n3(z)}`);
|
|
305
|
+
let stiffest = 0;
|
|
306
|
+
for (const b of beams.values()) {
|
|
307
|
+
const zs = [...b.stations].sort((p, q) => p - q);
|
|
308
|
+
for (const z of zs) { const n = nodeName(b, z); nodes[n] = at(b, z); nameAt.set(`${b.id}|${z}`, n); }
|
|
309
|
+
sections[b.id] = b.section;
|
|
310
|
+
materials[b.id] = { E: b.E, G: b.G, density: b.grams > 0 ? (b.grams / 1000 / b.L) / (b.section.A * 1e-6) : 0 };
|
|
311
|
+
stiffest = Math.max(stiffest, b.E * Math.max(b.section.Iy, b.section.Iz), b.E * b.section.A);
|
|
312
|
+
for (let i = 0; i + 1 < zs.length; i++) elements.push({ id: `${b.id}#${i + 1}`, of: b.id, a: nodeName(b, zs[i]), b: nodeName(b, zs[i + 1]), section: b.id, material: b.id, up: b.top });
|
|
313
|
+
}
|
|
314
|
+
const nodeAt = (b, z) => { for (const q of b.stations) if (Math.abs(q - z) < 0.05) return nameAt.get(`${b.id}|${q}`); return undefined; };
|
|
315
|
+
const big = FRAME_CHECK.link.value, rigidE = stiffest * big / 1e6;
|
|
316
|
+
materials.link = { E: rigidE, G: rigidE / 2.6 };
|
|
317
|
+
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)
|
|
318
|
+
const springs = [];
|
|
319
|
+
for (const x of joins) {
|
|
320
|
+
if (!beams.has(x.A.id)) continue;
|
|
321
|
+
const an = nodeAt(x.A, x.za), bn = nodeAt(x.B, x.zb), gap = Math.hypot(...sub(nodes[an], nodes[bn]));
|
|
322
|
+
if (gap > 1e-6) elements.push({ id: `join ${x.j.index + 1}`, a: bn, b: an, section: 'link', material: 'link' });
|
|
323
|
+
const el = elements.find((q) => q.of === x.A.id && (x.e === 'a' ? q.a === an : q.b === an));
|
|
324
|
+
springs.push({ x, el, end: x.e === 'a' ? 'a' : 'b' });
|
|
325
|
+
}
|
|
326
|
+
// bays: four beams joined round a rectangle in one plane, two each way; each corner the node where two of their axes
|
|
327
|
+
// cross (the station a join put on the beam it lands on)
|
|
328
|
+
const bays = baysOf(beams, joins.filter((x) => beams.has(x.A.id) && beams.has(x.B.id)), nodes, nodeAt);
|
|
329
|
+
// 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
|
|
330
|
+
// series with its clips' grip
|
|
331
|
+
// a panel whose beams make no bay (not joined round it) is no web, but it lies on its beams: its weight is spread
|
|
332
|
+
// along each of them, a quarter each
|
|
333
|
+
const webs = [], heldSheets = [], laid = [];
|
|
334
|
+
for (const p of sheets) {
|
|
335
|
+
const bay = bays.find((b) => b.beams.length === p.bay.length && p.bay.every((id) => b.beams.includes(id)));
|
|
336
|
+
if (!bay) { const on = p.bay.filter((id) => beams.has(id)); if (p.kg > 0 && on.length) laid.push({ id: p.id, kg: p.kg, beams: on }); else if (!on.length) loose.push(p.id); continue; }
|
|
337
|
+
const w = webOf(bay, p.sheet, p.thickness, p.items.length, p.id);
|
|
338
|
+
webs.push(w); heldSheets.push({ ...p, bay: bays.indexOf(bay) }); elements.push(w.element);
|
|
339
|
+
}
|
|
340
|
+
const supportMap = {}, mapSupports = () => { for (const sp of supports.filter(keep)) supportMap[nodeAt(sp.beam, sp.z)] = sp.how === 'fixed' ? 'fixed' : { x: true, y: true, z: true, ...(sp.twist ? { [sp.twist]: true } : {}) }; };
|
|
341
|
+
mapSupports();
|
|
342
|
+
// (a freedom nothing holds, which the loads do not move, is held for the solve and named in frame.solve: a frame in
|
|
343
|
+
// one plane on pinned feet sways out of it, a beam pinned at both ends spins on its axis)
|
|
344
|
+
const withSprings = (rigid) => ({ nodes, sections, materials, supports: supportMap, gravity: scale(down, G), loose: 'hold',
|
|
345
|
+
elements: elements.map((q) => { const sp = rigid ? [] : springs.filter((p) => p.el === q); return sp.length ? { ...q, ends: Object.fromEntries(sp.map((p) => [p.end, { rx: p.x.k.twist, ry: p.x.k.bending, rz: p.x.k.bending }])) } : q; }) });
|
|
346
|
+
|
|
347
|
+
// Supports guessed at the lowest ends are pinned. Where that leaves the frame free to move (two posts and a rail
|
|
348
|
+
// leaning over out of their plane, a beam on the floor rolling on its axis with a post on it), the guess takes
|
|
349
|
+
// what a beam on the floor has: a beam with both ends lowest lies on its face and rests (held from twisting about
|
|
350
|
+
// its length, as "resting" holds it), and a beam standing on its lowest end stands on its end face, held from
|
|
351
|
+
// turning (fixed). Supports said in "frame": { "supports" } or by feet are never changed.
|
|
352
|
+
const axisOfBeam = (b) => b.u.findIndex((c) => Math.abs(Math.abs(c) - 1) < 1e-6);
|
|
353
|
+
// (the guess is said: frame.solve warns that the frame would be free on pinned feet, so every figure rests on ends
|
|
354
|
+
// held that nobody gave, and frame.rack, frame.buckling and frame.frequency say they rest on it: fm.guess)
|
|
355
|
+
const guessed = supports.filter((x) => x.why === 'a lowest end' && keep(x));
|
|
356
|
+
let guess = null;
|
|
357
|
+
if (guessed.length && supports.every((x) => x.why === 'a lowest end')) {
|
|
358
|
+
let free = [];
|
|
359
|
+
// (in the model as solved and in the pieces modes and buckling are solved in, where a freedom can show that
|
|
360
|
+
// rounding hid in the whole: either says the frame is free)
|
|
361
|
+
for (const rigid of [false, true]) for (const m of [withSprings(rigid), subdivide(withSprings(rigid), 4)]) try { free.push(...solveFrame(m).loose); } catch { /* refused: said by the solve itself */ }
|
|
362
|
+
if (free.length) {
|
|
363
|
+
for (const x of guessed) {
|
|
364
|
+
const lies = supports.some((y) => y !== x && y.beam === x.beam) && axisOfBeam(x.beam) >= 0, stands = Math.abs(dot(x.beam.u, down)) > 1 - 1e-6;
|
|
365
|
+
if (lies) Object.assign(x, { how: 'resting', why: 'a lowest end of a beam lying on its face', twist: `r${'xyz'[axisOfBeam(x.beam)]}` });
|
|
366
|
+
else if (stands) Object.assign(x, { how: 'fixed', why: 'a lowest end, standing on its end face' });
|
|
367
|
+
}
|
|
368
|
+
mapSupports();
|
|
369
|
+
const seen = new Set();
|
|
370
|
+
guess = { free: free.filter((l) => { const k = `${l.node} ${l.freedom}`; return !seen.has(k) && seen.add(k); }).map(({ node, freedom }) => ({ node, freedom })),
|
|
371
|
+
supports: guessed.filter((x) => x.why !== 'a lowest end').map((x) => ({ where: x.where, how: x.how, why: x.why })) };
|
|
372
|
+
if (!guess.supports.length) guess = null; // (nothing changed: the guess stays pinned, and the solve says what is free)
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
// the loads at each pose: every carried item's and load's weight as a force and a moment at its node
|
|
376
|
+
const nodeLoads = (values, only) => {
|
|
377
|
+
const W = placeItems(motion, values), out = [];
|
|
378
|
+
const put = (b, z, C, kg) => { const n = nodeAt(b, z); if (!n) throw new Error(`frame: no node on ${b.id} at ${n3(z)} mm for a load (a pose this check did not foresee)`); const F = scale(down, kg * G); out.push({ node: n, force: F, moment: cross(sub(C, nodes[n]), F) }); };
|
|
379
|
+
for (const c of only ? [] : carried.filter(keep)) put(c.mount.beam, mountStation(c.mount, values), rowsAt(W[c.item], c.centre), c.kg);
|
|
380
|
+
for (const l of loads.filter(keep)) { if (only && only !== l) continue; const C = rowsAt(W[l.item], l.point); if (l.beam) put(l.beam, l.z, C, l.kg); else put(l.mount.beam, mountStation(l.mount, values), C, l.kg); }
|
|
381
|
+
for (const p of only ? [] : heldSheets) for (const n of bays[p.bay].corners) out.push({ node: n, force: scale(down, (p.kg / 4) * G), moment: [0, 0, 0] });
|
|
382
|
+
for (const p of only ? [] : laid) for (const id of p.beams) { const b = beams.get(id), w = scale(down, ((p.kg / p.beams.length) * G) / b.L); for (const q of elements) if (q.of === id) out.push({ element: q.id, spread: w }); }
|
|
383
|
+
return out;
|
|
384
|
+
};
|
|
385
|
+
// the same masses for a modal solve: each at the node it is carried at, in kg (its offset's rotary inertia left out)
|
|
386
|
+
const nodeMasses = (values) => {
|
|
387
|
+
const out = {}, put = (b, z, kg) => { const n = nodeAt(b, z); out[n] = (out[n] ?? 0) + kg; };
|
|
388
|
+
for (const c of carried.filter(keep)) put(c.mount.beam, mountStation(c.mount, values), c.kg);
|
|
389
|
+
for (const l of loads.filter(keep)) { if (l.beam) put(l.beam, l.z, l.kg); else put(l.mount.beam, mountStation(l.mount, values), l.kg); }
|
|
390
|
+
for (const p of heldSheets) for (const n of bays[p.bay].corners) out[n] = (out[n] ?? 0) + p.kg / 4;
|
|
391
|
+
// (a panel laid on its beams: each beam's share at its elements' ends, half an element's length each)
|
|
392
|
+
for (const p of laid) for (const id of p.beams) { const b = beams.get(id); for (const q of elements) if (q.of === id) { const share = (p.kg / p.beams.length) * Math.hypot(...sub(nodes[q.b], nodes[q.a])) / b.L / 2; out[q.a] = (out[q.a] ?? 0) + share; out[q.b] = (out[q.b] ?? 0) + share; } }
|
|
393
|
+
return out;
|
|
394
|
+
};
|
|
395
|
+
const kept = new Set(carried.filter(keep).map((c) => c.id));
|
|
396
|
+
// what is mounted only on beams left out (not held by a support through joins): not weighed, and named
|
|
397
|
+
const off = [...new Map([...carried, ...loads].filter((c) => !keep(c) && !kept.has(c.id)).map((c) => [c.id ?? `load ${c.index + 1} at ${c.where}`, (c.mount?.beam ?? c.beam).id]))].map(([id, on]) => ({ id, on }));
|
|
398
|
+
return { beams, left, missing, loose, unknown, off, riding: rides.filter((x) => kept.has(x.id)), carried: carried.filter(keep), loads: loads.filter(keep), points, guides: guides.filter(keep), supports: supports.filter(keep), joins: joins.filter((x) => beams.has(x.A.id)),
|
|
399
|
+
cases, down, nodes, nodeAt, guess, model: withSprings(false), rigid: withSprings(true), nodeLoads, nodeMasses, bays, webs, sheets: heldSheets, laid, elements, mountStation, worlds, axisOf: (j) => axisOf(motion, worlds, j, mul) };
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// the downward movement of a node, and along a beam between two stations (the worst of the element stations there)
|
|
403
|
+
const sagAt = (r, node, down) => dot(r.displacements[node].slice(0, 3), down);
|
|
404
|
+
function sagAlong(r, beam, from, to, down) {
|
|
405
|
+
let most = -Infinity, where = from;
|
|
406
|
+
for (const e of r.elements) if (e.of === beam.id) e.along.x.forEach((x, i) => { const z = (e._from ?? 0) + x, v = dot(e.along.d[i], down); if (z >= from - 1e-6 && z <= to + 1e-6 && v > most) { most = v; where = z; } });
|
|
407
|
+
return { sag: most, z: where };
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* frame.deflection, frame.stress and frame.buckling on a built assembly, and frame.solve saying what the frame's model
|
|
412
|
+
* holds and what it leaves out. @param {object} s a built assembly @param {Function} f the findings' sink
|
|
413
|
+
* @param {{ placeItems: Function, jointValues: Function, mul: Function }} helpers
|
|
414
|
+
*/
|
|
415
|
+
export function frameChecks(s, f, helpers) {
|
|
416
|
+
let fm;
|
|
417
|
+
try { fm = frameModelOf(s, helpers); } catch (e) { f('fail', `frame: ${e.message}`, 'frame: refused', { code: 'frame.solve' }); return null; }
|
|
418
|
+
if (!fm) return null;
|
|
419
|
+
if (fm.empty) { if (fm.missing.length) f('info', `the frame is not solved: ${fm.missing.join(', ')} ${fm.missing.length > 1 ? 'give' : 'gives'} no modulus, shear modulus or second moments`, null, { code: 'frame.solve', refs: { beams: fm.missing } }); return null; }
|
|
420
|
+
const solved = solveAll(fm);
|
|
421
|
+
if (solved.error) { const guessed = fm.supports.every((x) => x.why.startsWith('a lowest end')); f(guessed ? 'info' : 'warn', `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' : ''}`, guessed ? null : 'frame: not solved', { code: 'frame.solve', refs: { supports: fm.supports.map((x) => x.where), code: solved.code } }); return null; }
|
|
422
|
+
const { results } = solved, down = fm.down, margin = FRAME_CHECK.margin.value, held = solved.loose ?? [];
|
|
423
|
+
const heldList = [...held.reduce((m, l) => m.set(l.node, [...(m.get(l.node) ?? []), l.freedom]), new Map())].map(([n, fr]) => `${n} (${fr.join(', ')})`).join(', ');
|
|
424
|
+
// what the joins rest on, counted by kind
|
|
425
|
+
const kinds = new Map();
|
|
426
|
+
for (const x of fm.joins) { const key = `${x.j.kind}${x.j.fitting ? ` (${x.j.fitting})` : ''}: ${restsWord(x.k)}`; kinds.set(key, (kinds.get(key) ?? 0) + 1); }
|
|
427
|
+
const estimates = fm.joins.filter((x) => !(x.k.measured?.bending && x.k.measured?.twist)).length;
|
|
428
|
+
const restsJoins = fm.joins.length ? `${fm.joins.length} join${fm.joins.length > 1 ? 's' : ''}' springs (${[...kinds].map(([k, n]) => `${n} ${k}`).join('; ')})` : 'no joins';
|
|
429
|
+
// what every figure rests on: the joins' springs are an estimate while any is, whether or not they move a figure
|
|
430
|
+
const restsOn = estimates ? 'estimate' : fm.joins.length ? 'measured' : 'beams';
|
|
431
|
+
const rests = fm.joins.map((x) => ({ join: x.j.index, kind: x.j.kind, bending: x.k.bending, twist: x.k.twist, value: restsWord(x.k) }));
|
|
432
|
+
// supports guessed and changed from pinned (fm.guess): the solve warns, and racking, buckling and the modes say they rest on it
|
|
433
|
+
const guess = fm.guess, listFree = (ls) => [...ls.reduce((m, l) => m.set(l.node, [...(m.get(l.node) ?? []), l.freedom]), new Map())].map(([n, fr]) => `${n} (${fr.join(', ')})`).join(', ');
|
|
434
|
+
const and = (xs) => (xs.length > 1 ? `${xs.slice(0, -1).join(', ')} and ${xs[xs.length - 1]}` : xs[0] ?? '');
|
|
435
|
+
const posts = guess ? guess.supports.filter((x) => x.how === 'fixed').map((x) => x.where) : [], lying = guess ? guess.supports.filter((x) => x.how !== 'fixed').map((x) => x.where) : [];
|
|
436
|
+
const guessHeld = [posts.length ? `${and(posts)} fixed, standing on ${posts.length > 1 ? 'their end faces' : 'its end face'}` : null, lying.length ? `${and(lying)} resting, held from twisting as ${lying.length > 1 ? 'ends of beams' : 'an end of a beam'} lying on its face` : null].filter(Boolean).join(', and ');
|
|
437
|
+
const guessFree = guess ? listFree(guess.free) : '';
|
|
438
|
+
if (guess) {
|
|
439
|
+
const said = f;
|
|
440
|
+
f = (level, text, card, extra = {}) => (['frame.rack', 'frame.buckling', 'frame.frequency'].includes(extra.code)
|
|
441
|
+
? said(level, `${text}. This rests on supports guessed, not given: ${guessHeld}, where pinned feet would leave the frame free at ${guessFree}`, card, { ...extra, refs: { ...extra.refs, guessed: guess.supports.map((x) => x.where) } })
|
|
442
|
+
: said(level, text, card, extra));
|
|
443
|
+
}
|
|
444
|
+
f(guess ? 'warn' : 'info', `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' : ''}` : ''}, in ${fm.cases.length} pose${fm.cases.length > 1 ? 's' : ''}; ${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 at ${heldList}: it can move there with nothing resisting (a frame in one plane on pinned feet sways out of that plane; a beam pinned at both ends spins on its own axis). 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, it would be free at ${guessFree}. So it is solved with ${guessHeld}, 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" }` : ''}`, guess ? 'frame: supports guessed' : null,
|
|
445
|
+
{ code: 'frame.solve', values: { beams: fm.beams.size, nodes: Object.keys(fm.nodes).length, cases: fm.cases.length, joins: fm.joins.length, estimates }, refs: { supports: fm.supports.map((x) => x.where), ...(guess ? { guessed: guess.supports.map((x) => x.where), free: guess.free } : {}), left: fm.left, off: fm.off, held, laid: fm.laid.map((p) => ({ id: p.id, kg: r3(p.kg), beams: p.beams })), riding: fm.riding.map((x) => ({ ...x, kg: r3(x.kg) })), loose: fm.loose, rests } });
|
|
446
|
+
|
|
447
|
+
// ---- frame.deflection: each load's point, each named point, every guide ----
|
|
448
|
+
const worst = (fn) => { let w = null; for (const r of results) { const v = fn(r.spring, r), v0 = fn(r.rigid, r); if (!w || v.sag > w.sag) w = { ...v, rigid: v0.sag, case: { ...r.case, alone: r.alone } }; } return w; };
|
|
449
|
+
const limitFor = (b, own) => {
|
|
450
|
+
if (own) return { value: own.value, from: `${own.from}` };
|
|
451
|
+
if (s.a.frame?.limit != null) return { value: s.num(s.a.frame.limit), from: 'the assembly\'s frame.limit' };
|
|
452
|
+
if (s.task?.accuracy != null) return { value: s.task.accuracy, from: 'the task\'s accuracy' };
|
|
453
|
+
return { value: b.L / FRAME_CHECK.sag.value, from: `${b.id}'s span, ${n3(b.L, 1)} mm, over ${FRAME_CHECK.sag.value} (frame.sag)` };
|
|
454
|
+
};
|
|
455
|
+
const report = (what, where, b, w, own, alone, P) => {
|
|
456
|
+
const lim = limitFor(b, own), level = w.sag > lim.value ? 'fail' : 'pass', soft = estimates && w.sag > w.rigid * 1.001;
|
|
457
|
+
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)` : ''}. ${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(w.sag / lim.value, 2)} times over. Stiffen the beam (a deeper profile), shorten its span, or stiffen its joins` : ''}`;
|
|
458
|
+
f(level, text, level === 'fail' ? `${where}: sags ${n3(w.sag, 2)} mm` : null, { code: 'frame.deflection', at: r4(P), values: { sag: sagR(w.sag), rigid: sagR(w.rigid), limit: r3(lim.value), ...(alone ? { alone: sagR(alone.sag), aloneRigid: sagR(alone.rigid) } : {}) },
|
|
459
|
+
refs: { beam: b.id, where, pose: w.case.label, limit: lim.from, rests, restsOn } });
|
|
460
|
+
};
|
|
461
|
+
for (const l of fm.loads) {
|
|
462
|
+
const b = l.beam ?? l.mount.beam, zOf = (values) => (l.beam ? l.z : fm.mountStation(l.mount, values));
|
|
463
|
+
const w = worst((res, r) => ({ sag: sagAt(res, fm.nodeAt(b, zOf(r.values)), down) }));
|
|
464
|
+
const one = w.case.alone?.get(l);
|
|
465
|
+
report(`${b.id} at ${l.where}`, l.where, b, w, null, one ? { ...one, what: `the ${n3(l.kg, 3)} kg there` } : null, fm.nodes[fm.nodeAt(b, zOf(w.case.values))]);
|
|
466
|
+
}
|
|
467
|
+
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]); }
|
|
468
|
+
for (const g of fm.guides) {
|
|
469
|
+
const w = worst((r) => sagAlong(r, g.beam, g.from, g.to, down)), own = g.tolerance ? { value: g.tolerance.value, from: `the rail's own parallelism over its length (${g.tolerance.note ?? g.tolerance.term})` } : null;
|
|
470
|
+
report(`${g.beam.id} under guide ${g.id}, between ${n3(g.from, 1)} and ${n3(g.to, 1)} mm`, `${g.id}`, g.beam, w, own, null, add(g.beam.A, scale(g.beam.u, w.z)));
|
|
471
|
+
// kept for the error budget: the task's terms take the beam's sag along the guide from here (lib/task.mjs terms)
|
|
472
|
+
(s.frameGuideSag ??= new Map()).set(g.id, { sag: sagR(w.sag), rigid: sagR(w.rigid), pose: w.case.label, restsOn, beam: g.beam.id });
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// ---- frame.stress: the worst in each beam against its alloy; the moment at each join against its fitting ----
|
|
476
|
+
const beamRows = [];
|
|
477
|
+
for (const b of fm.beams.values()) {
|
|
478
|
+
let w = null;
|
|
479
|
+
for (const r of results) for (const [model, res] of [['springs', r.spring], ['rigid', r.rigid]]) for (const e of res.elements) if (e.of === b.id && e.stress && (!w || e.stress.peak > w.peak)) w = { ...e.stress, case: r.case, model, e };
|
|
480
|
+
if (!w) continue;
|
|
481
|
+
const m = b.strength ? b.strength / w.peak : Infinity;
|
|
482
|
+
beamRows.push({ b, w, margin: m });
|
|
483
|
+
}
|
|
484
|
+
for (const { b, w, margin: m } of beamRows) {
|
|
485
|
+
if (!b.strength) { f('info', `${b.id}: ${n3(w.peak, 2)} MPa at worst, and ${b.alloy ?? 'its alloy'} gives no strength to check it against`, null, { code: 'frame.stress', values: { stress: r3(w.peak) }, refs: { beam: b.id } }); continue; }
|
|
486
|
+
const level = m < 1 ? 'fail' : m < margin ? 'warn' : 'pass';
|
|
487
|
+
if (level === 'pass' && beamRows.length > 1) continue;
|
|
488
|
+
const P = add(b.A, scale(b.u, (w.e._from ?? 0) + w.x));
|
|
489
|
+
f(level, `${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` : ''}`, level === 'pass' ? null : `${b.id}: stress ${n3(m, 1)}×`,
|
|
490
|
+
{ code: 'frame.stress', at: r4(P), between: [r4(b.A), r4(add(b.A, scale(b.u, b.L)))], values: { stress: r3(w.peak), bending: r3(w.bending), strength: b.strength, margin: r3(m) }, refs: { beam: b.id, pose: w.case.label, joins: w.model } });
|
|
491
|
+
}
|
|
492
|
+
const passing = beamRows.filter((x) => x.b.strength && x.margin >= margin);
|
|
493
|
+
if (beamRows.length > 1 && passing.length) {
|
|
494
|
+
const low = passing.reduce((p, q) => (q.margin < p.margin ? q : p));
|
|
495
|
+
f('pass', `${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`, null,
|
|
496
|
+
{ code: 'frame.stress', at: r4(add(low.b.A, scale(low.b.u, low.b.L / 2))), values: { stress: r3(low.w.peak), strength: low.b.strength, margin: r3(low.margin), beams: passing.length }, refs: { beam: low.b.id, beams: passing.map((x) => x.b.id) } });
|
|
497
|
+
}
|
|
498
|
+
const rated = [], unrated = [];
|
|
499
|
+
for (const x of fm.joins) {
|
|
500
|
+
let M = 0, T = 0, at = null;
|
|
501
|
+
for (const r of results) for (const [model, res] of [['springs', r.spring], ['rigid', r.rigid]]) {
|
|
502
|
+
const mine = res.elements.filter((q) => q.of === x.A.id), e = x.e === 'a' ? mine[0] : mine[mine.length - 1]; if (!e) continue;
|
|
503
|
+
const end = x.e === 'a' ? e.ends.a : e.ends.b, m = Math.hypot(end[4], end[5]);
|
|
504
|
+
if (!at || m > M) { M = m; T = Math.abs(end[3]); at = { case: r.case, model }; }
|
|
505
|
+
}
|
|
506
|
+
const fit = x.j.fitted?.model, cap = fit?.load?.force && fit.margin && Array.isArray(fit.load.at) ? fit.load.force * Math.hypot(...fit.load.at) * fit.margin : null;
|
|
507
|
+
(cap ? rated : unrated).push({ x, M, T, at, fit, cap, margin: cap ? cap / (M || 1e-9) : null, P: fm.nodes[fm.nodeAt(x.A, x.za)], refs: { join: x.j.index, kind: x.j.kind, a: x.j.a, b: x.j.b } });
|
|
508
|
+
}
|
|
509
|
+
for (const q of rated) {
|
|
510
|
+
const level = q.margin < 1 ? 'fail' : q.margin < margin ? 'warn' : 'pass';
|
|
511
|
+
if (level === 'pass' && rated.length > 1) continue;
|
|
512
|
+
f(level, `${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` : ''}`, level === 'pass' ? null : `${q.x.j.label}: ${n3(q.margin, 1)}×`,
|
|
513
|
+
{ code: 'frame.stress', at: r4(q.P), values: { moment: r3(q.M), twist: r3(q.T), strength: r3(q.cap), margin: r3(q.margin) }, refs: { ...q.refs, item: q.x.j.fitted.item } });
|
|
514
|
+
}
|
|
515
|
+
const okRated = rated.filter((q) => q.margin >= margin);
|
|
516
|
+
if (rated.length > 1 && okRated.length) {
|
|
517
|
+
const low = okRated.reduce((p, q) => (q.margin < p.margin ? q : p));
|
|
518
|
+
f('pass', `${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`, null,
|
|
519
|
+
{ code: 'frame.stress', at: r4(low.P), values: { moment: r3(low.M), strength: r3(low.cap), margin: r3(low.margin), joins: okRated.length }, refs: { ...low.refs, item: low.x.j.fitted.item } });
|
|
520
|
+
}
|
|
521
|
+
if (unrated.length) {
|
|
522
|
+
const most = unrated.reduce((p, q) => (q.M > p.M ? q : p)), kindsOf = [...new Set(unrated.map((q) => q.x.j.kind))];
|
|
523
|
+
f('info', `${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}`, null,
|
|
524
|
+
{ code: 'frame.stress', at: r4(most.P), values: { moment: r3(most.M), twist: r3(most.T), joins: unrated.length }, refs: { ...most.refs, moments: unrated.map((q) => ({ join: q.x.j.index, moment: r3(q.M), twist: r3(q.T) })) } });
|
|
525
|
+
}
|
|
526
|
+
// ---- frame.buckling: each beam in compression against Euler's load, and the frame's own first factor ----
|
|
527
|
+
const squeezed = [];
|
|
528
|
+
for (const b of fm.beams.values()) {
|
|
529
|
+
let N = 0, w = null;
|
|
530
|
+
for (const r of results) for (const res of [r.spring, r.rigid]) for (const e of res.elements) if (e.of === b.id && e.axial < N) { N = e.axial; w = r.case; }
|
|
531
|
+
if (N >= 0) continue;
|
|
532
|
+
const I = Math.min(b.section.Iy, b.section.Iz), Pcr = (Math.PI ** 2 * b.E * I) / (FRAME_CHECK.euler.value * b.L) ** 2;
|
|
533
|
+
squeezed.push({ b, N: -N, Pcr, margin: Pcr / -N, case: w });
|
|
534
|
+
}
|
|
535
|
+
for (const q of squeezed) {
|
|
536
|
+
const level = q.margin < 1 ? 'fail' : q.margin < margin ? 'warn' : 'pass';
|
|
537
|
+
if (level === 'pass' && squeezed.length > 1) continue;
|
|
538
|
+
f(level, `${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`, level === 'pass' ? null : `${q.b.id}: buckles ${n3(q.margin, 1)}×`,
|
|
539
|
+
{ code: 'frame.buckling', at: r4(add(q.b.A, scale(q.b.u, q.b.L / 2))), between: [r4(q.b.A), r4(add(q.b.A, scale(q.b.u, q.b.L)))], values: { compression: r3(q.N), euler: r3(q.Pcr), margin: r3(q.margin) }, refs: { beam: q.b.id, pose: q.case?.label } });
|
|
540
|
+
}
|
|
541
|
+
const okSq = squeezed.filter((q) => q.margin >= margin);
|
|
542
|
+
if (squeezed.length > 1 && okSq.length) {
|
|
543
|
+
const low = okSq.reduce((p, q) => (q.margin < p.margin ? q : p));
|
|
544
|
+
f('pass', `${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`, null,
|
|
545
|
+
{ code: 'frame.buckling', at: r4(add(low.b.A, scale(low.b.u, low.b.L / 2))), values: { compression: r3(low.N), euler: r3(low.Pcr), margin: r3(low.margin), beams: okSq.length }, refs: { beam: low.b.id } });
|
|
546
|
+
}
|
|
547
|
+
try {
|
|
548
|
+
const drawn = results[0], bk = solveFrame(subdivide(fm.model, 4)).buckling({ loads: drawn.loads, count: 1 }), factor = bk.factors[0];
|
|
549
|
+
const shape = bk.modes[0].shape, lead = Object.entries(shape).reduce((p, q) => (Math.hypot(...q[1].slice(0, 3)) > Math.hypot(...p[1].slice(0, 3)) ? q : p)), beam = lead[0].split(/[.@#/]/)[0];
|
|
550
|
+
const listed = (ls) => [...ls.reduce((m, l) => m.set(l.node, [...(m.get(l.node) ?? []), l.freedom]), new Map())].map(([n, fr]) => `${n} (${fr.join(', ')})`).join(', ');
|
|
551
|
+
if (bk.tipped) {
|
|
552
|
+
// nothing holds the frame where it is free, and its loads as drawn lean it further that way: it tips over before anything buckles
|
|
553
|
+
f('fail', `the whole frame tips over under its load as drawn before anything buckles: nothing holds it at ${listed(bk.tipped)}, and its squeezed beams lean it further that way (a frame in one plane on pinned feet leans over out of that plane), ${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`, 'frame tips over',
|
|
554
|
+
{ code: 'frame.buckling', at: r4(fm.nodes[lead[0]] ?? fm.nodes[Object.keys(fm.nodes)[0]]), values: { factor: 0 }, refs: { beam, restsOn, tipped: bk.tipped } });
|
|
555
|
+
} else {
|
|
556
|
+
const level = factor < 1 ? 'fail' : factor < margin ? 'warn' : 'pass', rests = bk.rests ?? [];
|
|
557
|
+
f(level, `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` : ''}`, level === 'pass' ? null : `frame buckles at ${n3(factor, 1)}×`,
|
|
558
|
+
{ code: 'frame.buckling', at: r4(fm.nodes[lead[0]] ?? fm.nodes[Object.keys(fm.nodes)[0]]), values: { factor: r3(factor) }, refs: { beam, restsOn, ...(rests.length ? { rests } : {}) } });
|
|
559
|
+
}
|
|
560
|
+
} catch (e) { if (e.code !== 'fea.frame.compression') f('info', `the frame's own buckling factor is not found: ${e.message}`, null, { code: 'frame.buckling' }); }
|
|
561
|
+
try { rackCheck(s, fm, f, { restsJoins, restsOn }); } catch (e) { f('info', `the frame's racking is not found: ${e.message}`, null, { code: 'frame.rack' }); }
|
|
562
|
+
try { frequencyCheck(s, fm, f, { restsJoins, restsOn, heldList }); } catch (e) { f('info', `the frame's modes are not found: ${e.message}`, null, { code: 'frame.frequency' }); }
|
|
563
|
+
const ctx = { results, limitFor, sagAt, sagAlong, excitesOf, restsJoins, restsOn, margin };
|
|
564
|
+
try { couponChecks(s, fm, f, ctx); } catch (e) { f('info', `the beam coupon's figures are not predicted: ${e.message}`, null, { code: 'beam.coupon' }); }
|
|
565
|
+
if (s.a.frame?.printed != null) try { printableCheck(s, fm, f, ctx); } catch (e) { f('info', `which beams can be printed is not found: ${e.message}`, null, { code: 'beam.printable' }); }
|
|
566
|
+
return { model: fm, results };
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
// the two directions across "down" a frame is racked in, each named by the world axis it is nearest
|
|
570
|
+
function sideways(down) {
|
|
571
|
+
const flat = (v) => sub(v, scale(down, dot(v, down))), x = flat([1, 0, 0]), e1 = Math.hypot(...x) > 0.5 ? unitv(x) : unitv(flat([0, 1, 0])), e2 = unitv(cross(down, e1));
|
|
572
|
+
const name = (v) => { const k = [0, 1, 2].reduce((p, q) => (Math.abs(v[q]) > Math.abs(v[p]) ? q : p), 0); return `along ${'xyz'[k]}`; };
|
|
573
|
+
return [e1, e2].map((v) => ({ dir: v, name: name(v) }));
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// The panel a rack check tries in an open bay: a common sheet and thickness (both in SHEETS' stocked lists)
|
|
577
|
+
const RACK_PANEL = { sheet: 'acrylic', thickness: 3 };
|
|
578
|
+
|
|
579
|
+
/**
|
|
580
|
+
* frame.rack: each way across, a side push at the frame's top shared among its top corners, the sway it causes and the
|
|
581
|
+
* stiffness that is; then each change the order names (gussets at a bay's corners, one diagonal brace, a panel), in the
|
|
582
|
+
* best bay that way alone and in every open bay that way, each solved, with its gain; the cheapest that brings the sway
|
|
583
|
+
* under the limit advised.
|
|
584
|
+
*/
|
|
585
|
+
function rackCheck(s, fm, f, { restsJoins, restsOn }) {
|
|
586
|
+
const opts = s.a.frame?.rack ?? {}, F = opts.load != null ? s.num(opts.load) : FRAME_CHECK.push.value, down = fm.down, height = (n) => -dot(fm.nodes[n], down);
|
|
587
|
+
const feet = fm.supports.map((sp) => fm.nodeAt(sp.beam, sp.z)).filter(Boolean);
|
|
588
|
+
const pool = fm.bays.length ? [...new Set(fm.bays.flatMap((b) => b.corners))] : Object.keys(fm.nodes), topH = Math.max(...pool.map(height)), top = pool.filter((n) => height(n) > topH - 1);
|
|
589
|
+
const H = topH - Math.min(...feet.map(height));
|
|
590
|
+
if (!(H > 1) || !top.length) return;
|
|
591
|
+
const lim = opts.limit != null ? { value: s.num(opts.limit), from: 'the assembly\'s frame.rack.limit' } : s.task?.accuracy != null ? { value: s.task.accuracy, from: 'the task\'s accuracy' } : { value: H / FRAME_CHECK.sway.value, from: `its height, ${n3(H, 1)} mm, over ${FRAME_CHECK.sway.value} (frame.sway)` };
|
|
592
|
+
const loadFrom = opts.load != null ? 'frame.rack.load' : `frame.push, an estimate`;
|
|
593
|
+
const swayOf = (model, dir) => { const r = solveFrame(model).statics({ loads: top.map((n) => ({ node: n, force: scale(dir, F / top.length) })), gravity: [0, 0, 0] }); return top.reduce((t, n) => t + dot(r.displacements[n].slice(0, 3), dir), 0) / top.length; };
|
|
594
|
+
const base = fm.model, els = base.elements;
|
|
595
|
+
// the changes, each as the model's elements with it made
|
|
596
|
+
const brace = (bay) => { const lightest = bay.beams.map((id) => fm.beams.get(id)).reduce((p, q) => (q.section.Iy < p.section.Iy ? q : p)); return [{ id: `brace ${bay.name}`, a: bay.corners[0], b: bay.corners[2], section: lightest.section, material: { E: lightest.E, G: lightest.G, density: 0 }, ends: { a: 'ball', b: 'ball' } }]; };
|
|
597
|
+
const panel = (bay) => [webOf(bay, RACK_PANEL.sheet, RACK_PANEL.thickness, 0, bay.name).element];
|
|
598
|
+
const gussetOn = (bays, list) => list.map((q) => {
|
|
599
|
+
if (!q.ends || q.of == null) return q;
|
|
600
|
+
let ends = q.ends;
|
|
601
|
+
for (const x of fm.joins) {
|
|
602
|
+
const bay = bays.find((b) => b.beams.includes(x.A.id) && b.beams.includes(x.B.id));
|
|
603
|
+
if (!bay || x.A.id !== q.of) continue;
|
|
604
|
+
const key = x.e === 'a' ? 'a' : 'b', mine = list.filter((e) => e.of === x.A.id), el = x.e === 'a' ? mine[0] : mine[mine.length - 1];
|
|
605
|
+
if (el !== q || !ends[key] || typeof ends[key] !== 'object') continue;
|
|
606
|
+
const axis = Math.abs(dot(bay.n, x.A.top)) > 0.7 ? 'rz' : 'ry', g = joinStiffness('gusset', x.A.m).bending;
|
|
607
|
+
ends = { ...ends, [key]: { ...ends[key], [axis]: ends[key][axis] + g } };
|
|
608
|
+
}
|
|
609
|
+
return ends === q.ends ? q : { ...q, ends };
|
|
610
|
+
});
|
|
611
|
+
const made = (kind, bays) => ({ ...base, elements: kind === 'gusset' ? gussetOn(bays, els) : [...els, ...bays.flatMap(kind === 'brace' ? brace : panel)] });
|
|
612
|
+
const what = { gusset: 'gussets at the corners of', brace: 'one diagonal brace in', panel: `a ${RACK_PANEL.thickness} mm ${RACK_PANEL.sheet} panel on` };
|
|
613
|
+
for (const { dir, name } of sideways(down)) {
|
|
614
|
+
let sway, rigid;
|
|
615
|
+
try { sway = swayOf(base, dir); rigid = swayOf(fm.rigid, dir); } catch (e) {
|
|
616
|
+
if (e.code !== 'fea.frame.mechanism' || !e.driven) throw e;
|
|
617
|
+
// a frame free to move this way (one plane on pinned feet, pushed across it): the push finds nothing to hold it
|
|
618
|
+
const at = e.loose.map((l) => `${l.node} (${l.freedom})`).join(', ');
|
|
619
|
+
f('warn', `racked ${name}: nothing holds the frame that way, so ${n3(F, 1)} N pushed at the top (${loadFrom}) moves it with nothing resisting, free at ${at}. Fix its feet ("frame": { "supports" } fixed), or join beams across it to make a bay that way and brace it`, `racks ${name}: nothing holds it`,
|
|
620
|
+
{ code: 'frame.rack', at: r4(fm.nodes[top[0]]), values: { load: r3(F), limit: r3(lim.value), height: r3(H) }, refs: { direction: name, dir: r4(dir), top, free: e.loose, limit: lim.from, load: loadFrom, restsOn, advise: null } });
|
|
621
|
+
continue;
|
|
622
|
+
}
|
|
623
|
+
const k = F / sway, k0 = F / rigid;
|
|
624
|
+
const open = fm.bays.filter((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));
|
|
625
|
+
const options = [];
|
|
626
|
+
for (const kind of FRAME_CHECK.order.value) {
|
|
627
|
+
if (!open.length) break;
|
|
628
|
+
const one = open.map((b) => ({ bays: [b], sway: swayOf(made(kind, [b]), dir) })).reduce((p, q) => (q.sway < p.sway ? q : p));
|
|
629
|
+
options.push({ kind, ...one, every: false });
|
|
630
|
+
if (open.length > 1) options.push({ kind, bays: open, sway: swayOf(made(kind, open), dir), every: true });
|
|
631
|
+
}
|
|
632
|
+
for (const o of options) { o.stiffness = F / o.sway; o.gain = sway / o.sway; }
|
|
633
|
+
// open bays that hold the push by their joins' bending alone: a brace in each makes it many times stiffer
|
|
634
|
+
const braced = options.find((o) => o.kind === 'brace' && (o.every || open.length === 1)), loose = braced && braced.gain >= 10;
|
|
635
|
+
const over = sway > lim.value, singles = options.filter((o) => !o.every), pick = options.filter((o) => !o.every).concat(options.filter((o) => o.every)).find((o) => o.sway <= lim.value);
|
|
636
|
+
const say = (o) => `${o.every ? `${what[o.kind].replace(/^one /, 'a ')} each of ${o.bays.map((b) => b.name).join(', ')}` : `${what[o.kind]} ${o.bays[0].name}`}`;
|
|
637
|
+
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` : ''}. ${open.length
|
|
638
|
+
? `Solved with each change: ${singles.map((o) => `${say(o)} makes it ${fig(o.stiffness)} N/mm (${n3(o.gain, 1)} times)`).join('; ')}${options.some((o) => o.every) ? `; in every open bay ${name} (${open.length}): ${options.filter((o) => o.every).map((o) => `${o.kind}s ${n3(o.gain, 1)} times`).join(', ')}` : ''}. ${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'}`
|
|
639
|
+
: `There is no open bay of four joined beams ${name} to brace${over ? ': join beams round the sides to make one, then brace it' : ''}`}`;
|
|
640
|
+
f(over ? 'warn' : 'pass', text, over ? `racks ${name}: ${n3(sway, 2)} mm` : null, { code: 'frame.rack', at: r4(fm.nodes[top[0]]),
|
|
641
|
+
values: { load: r3(F), sway: r3(sway), stiffness: r3(k), rigid: r3(rigid), rigidStiffness: r3(k0), limit: r3(lim.value), height: r3(H), options: options.map((o) => ({ kind: o.kind, bays: o.bays.map((b) => b.name), every: o.every, sway: r3(o.sway), stiffness: r3(o.stiffness), gain: r3(o.gain) })) },
|
|
642
|
+
refs: { direction: name, dir: r4(dir), top, low: !!loose, limit: lim.from, load: loadFrom, restsOn, advise: over && pick ? { kind: pick.kind, bays: pick.bays.map((b) => b.name) } : null, panels: fm.webs.map((w) => ({ id: w.id, sheet: w.sheet, clips: w.clips, rests: w.rests })) } });
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* What the machine shakes its frame at: each stepper drive's full-step rate at its working speed, and the task's moves
|
|
648
|
+
* (a move ramping in t seconds shakes the frame at about 1/t).
|
|
649
|
+
* @param {object} s a built assembly
|
|
650
|
+
* @returns {{ kind: 'step' | 'move', what: string, Hz: number, from: string }[]}
|
|
651
|
+
*/
|
|
652
|
+
export function excitesOf(s) {
|
|
653
|
+
const excites = [];
|
|
654
|
+
for (const d of s.motion.drives ?? []) if (d.model?.stepAngle) { const rpm = workingSpeed(d.model, d.spec), at = (rpm / 60) * (360 / d.model.stepAngle); excites.push({ kind: 'step', what: `${d.id}'s full steps at ${n3(rpm, 1)} rpm`, Hz: at, from: d.spec.speed != null ? 'the motor item\'s speed' : `the working speed of a ${d.model.name}` }); }
|
|
655
|
+
if (s.task?.speed) { const acc = s.task.accel ?? FRAME_CHECK.ramp.value, t = s.task.speed / acc; excites.push({ kind: 'move', what: `the task's moves, ramping to ${n3(s.task.speed, 1)} mm/s in ${n3(t, 3)} s`, Hz: 1 / t, from: s.task.accel != null ? 'the task\'s speed and accel' : 'the task\'s speed and frame.ramp' }); }
|
|
656
|
+
return excites;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* frame.frequency: the frame's lowest modes in each pose, with its beams' own mass and every carried item's and load's
|
|
661
|
+
* mass lumped where it is carried, against what the machine excites: each stepper's full-step rate at its working
|
|
662
|
+
* speed (a mode near it rings while the motor runs at that speed), and the task's moves (a move ramping in t seconds
|
|
663
|
+
* shakes the frame at about 1/t, and the lowest mode should stand twice that clear).
|
|
664
|
+
*/
|
|
665
|
+
function frequencyCheck(s, fm, f, { restsJoins, restsOn, heldList }) {
|
|
666
|
+
const solveIn = (model, values, count) => solveFrame(subdivide({ ...model, masses: fm.nodeMasses(values) }, 4)).modes({ count });
|
|
667
|
+
let worst = null;
|
|
668
|
+
for (const c of fm.cases) { const r = solveIn(fm.model, c.values, 3); if (!worst || r.frequencies[0] < worst.r.frequencies[0]) worst = { c, r }; }
|
|
669
|
+
const hz = worst.r.frequencies, low = hz[0], rigid = solveIn(fm.rigid, worst.c.values, 1).frequencies[0];
|
|
670
|
+
const shape = worst.r.modes[0].shape, lead = Object.entries(shape).reduce((p, q) => (Math.hypot(...q[1].slice(0, 3)) > Math.hypot(...p[1].slice(0, 3)) ? q : p)), beam = lead[0].split(/[.@#/]/)[0];
|
|
671
|
+
const carried = Object.values(fm.nodeMasses(worst.c.values)).reduce((t, x) => t + x, 0), own = [...fm.beams.values()].reduce((t, b) => t + b.grams / 1000, 0);
|
|
672
|
+
const excites = excitesOf(s);
|
|
673
|
+
const margin = FRAME_CHECK.margin.value, band = FRAME_CHECK.band.value;
|
|
674
|
+
const moves = excites.filter((x) => x.kind === 'move'), steps = excites.filter((x) => x.kind === 'step');
|
|
675
|
+
const need = moves.length ? Math.max(...moves.map((x) => x.Hz)) * margin : 0, near = steps.map((x) => ({ ...x, modes: [...new Set(hz.filter((h) => Math.abs(h - x.Hz) <= band * x.Hz).map((h) => n3(h, 1)))] })).filter((x) => x.modes.length);
|
|
676
|
+
// a mode of 0 Hz is the frame moving where nothing holds it (fea's modes count a held freedom free): never a pass
|
|
677
|
+
const free = worst.r.modes.filter((m) => m.free).length;
|
|
678
|
+
const level0 = !excites.length ? 'info' : (moves.length && low < need / margin) ? 'fail' : (low < need || near.length) ? 'warn' : 'pass', level = free && (level0 === 'info' || level0 === 'pass') ? 'warn' : level0;
|
|
679
|
+
const target = Math.max(need, ...near.map((x) => x.Hz * (1 + band)));
|
|
680
|
+
const advice = free ? `. Hold it there with "frame": { "supports" } fixed, brace it, or join it into a box: then it has a mode to lift` : level === 'warn' || level === 'fail' ? `. 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` : '';
|
|
681
|
+
const text = `the lowest mode is ${n3(low, 1)} Hz${free ? `: nothing holds the frame${heldList ? ` at ${heldList}` : ''}, so it moves that way with nothing resisting${free > 1 ? ` (${free} such modes)` : ''}` : ''}${fm.cases.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.slice(1).map((h) => `${n3(h, 1)} Hz`).join(', ')}. 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}. ${excites.length
|
|
682
|
+
? `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`) : ''}`
|
|
683
|
+
: 'Nothing named excites it: no stepper drives a joint and the assembly has no task'}${advice}`;
|
|
684
|
+
f(level, text.replace(/\. $/, ''), level === 'warn' || level === 'fail' ? `frame mode ${n3(low, 1)} Hz` : null, { code: 'frame.frequency', at: r4(fm.nodes[lead[0]] ?? fm.nodes[Object.keys(fm.nodes)[0]]),
|
|
685
|
+
values: { Hz: r3(low), rigid: r3(rigid), modes: hz.map(r3), ...(free ? { free } : {}), beams: r3(own), carried: r3(carried), ...(excites.length ? { excites: excites.map((x) => ({ what: x.what, Hz: r3(x.Hz), kind: x.kind })) } : {}) },
|
|
686
|
+
refs: { pose: worst.c.label, beam, restsOn, excites: excites.map((x) => ({ what: x.what, from: x.from })) } });
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* The frame's lowest mode for a check view: the subdivided model's elements as drawn and as the mode moves them, its
|
|
691
|
+
* largest movement shown as a tenth of the frame's size, in the pose where it is lowest. Never part of the model.
|
|
692
|
+
* @param {object} s a built assembly @param {{ placeItems: Function, jointValues: Function, mul: Function }} helpers
|
|
693
|
+
* @returns {{ Hz: number, pose: string, beam: string, lines: { id: string, a: number[], b: number[], da: number[], db: number[] }[], scale: number, label: string } | null}
|
|
694
|
+
*/
|
|
695
|
+
export function frameMode(s, helpers) {
|
|
696
|
+
let fm;
|
|
697
|
+
try { fm = frameModelOf(s, helpers); } catch { return null; }
|
|
698
|
+
if (!fm || fm.empty) return null;
|
|
699
|
+
try {
|
|
700
|
+
let worst = null;
|
|
701
|
+
for (const c of fm.cases) { const m = subdivide({ ...fm.model, masses: fm.nodeMasses(c.values) }, 4), r = solveFrame(m).modes({ count: 1 }); if (!worst || r.frequencies[0] < worst.r.frequencies[0]) worst = { c, r, m }; }
|
|
702
|
+
const shape = worst.r.modes[0].shape, pts = Object.values(worst.m.nodes), size = Math.max(...[0, 1, 2].map((k) => Math.max(...pts.map((p) => p[k])) - Math.min(...pts.map((p) => p[k])))), k = size / 10;
|
|
703
|
+
const move = (n) => scale((shape[n] ?? [0, 0, 0]).slice(0, 3), k);
|
|
704
|
+
const lines = worst.m.elements.map((e) => ({ id: String(e.id), a: worst.m.nodes[e.a], b: worst.m.nodes[e.b], da: move(e.a), db: move(e.b) }));
|
|
705
|
+
const lead = Object.entries(shape).reduce((p, q) => (Math.hypot(...q[1].slice(0, 3)) > Math.hypot(...p[1].slice(0, 3)) ? q : p)), beam = lead[0].split(/[.@#/]/)[0];
|
|
706
|
+
const Hz = worst.r.frequencies[0];
|
|
707
|
+
return { Hz, pose: worst.c.label, beam, lines, scale: k, label: `lowest mode ${n3(Hz, 1)} Hz${fm.cases.length > 1 ? `, ${worst.c.label}` : ''}, ${beam} moving most; its movement drawn as a tenth of the frame's size (scaled)` };
|
|
708
|
+
} catch { return null; }
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* The mode as an animated SVG: the frame swinging through the mode's shape and back, seen from the front (x across, z
|
|
713
|
+
* 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}
|
|
714
|
+
*/
|
|
715
|
+
export function frameModeSvg(md, o = {}) {
|
|
716
|
+
const [i, j] = o.view === 'side' ? [1, 2] : o.view === 'top' ? [0, 1] : [0, 2], 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)]);
|
|
717
|
+
const lo = [Math.min(...all.map((p) => p[i])), Math.min(...all.map((p) => p[j]))], hi = [Math.max(...all.map((p) => p[i])), Math.max(...all.map((p) => p[j]))];
|
|
718
|
+
const W = 640, pad = 40, k = (W - 2 * pad) / Math.max(hi[0] - lo[0], hi[1] - lo[1], 1), H = Math.ceil((hi[1] - lo[1]) * k + 2 * pad + 56);
|
|
719
|
+
const X = (p) => (pad + (p[i] - lo[0]) * k).toFixed(1), Y = (p) => (H - 56 - pad - (p[j] - lo[1]) * k).toFixed(1), pts = (a, b) => `${X(a)},${Y(a)} ${X(b)},${Y(b)}`;
|
|
720
|
+
const esc = (t) => String(t).replace(/&/g, '&').replace(/</g, '<');
|
|
721
|
+
// (from one extreme: a viewer that shows no animation shows the mode at its largest)
|
|
722
|
+
const swing = (l) => [pts(add(l.a, l.da), add(l.b, l.db)), pts(l.a, l.b), pts(sub(l.a, l.da), sub(l.b, l.db)), pts(l.a, l.b), pts(add(l.a, l.da), add(l.b, l.db))].join(';');
|
|
723
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}" font-family="system-ui, sans-serif">
|
|
724
|
+
<rect width="100%" height="100%" fill="#fff"/>
|
|
725
|
+
${md.lines.map((l) => `<polyline points="${pts(l.a, l.b)}" fill="none" stroke="#ddd" stroke-width="6" stroke-linecap="round"/>`).join('\n')}
|
|
726
|
+
${md.lines.map((l) => `<polyline points="${pts(add(l.a, l.da), add(l.b, l.db))}" fill="none" stroke="#2c6fbb" stroke-width="2" stroke-linecap="round"><animate attributeName="points" values="${swing(l)}" dur="1.6s" repeatCount="indefinite"/></polyline>`).join('\n')}
|
|
727
|
+
${o.title ? `<text x="${pad}" y="${H - 40}" font-size="13" font-weight="600">${esc(o.title)}</text>` : ''}
|
|
728
|
+
<text x="${pad}" y="${H - 23}" font-size="12">${esc(md.label)}</text>
|
|
729
|
+
<text x="${pad}" y="${H - 6}" font-size="11" fill="#666">grey: as drawn; blue: the mode, swinging (slowed down, scaled). A check view only, not the model</text>
|
|
730
|
+
</svg>`;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* The check view cad beams writes beside the sag: the frame's lowest mode, animated, from the front and the side, as
|
|
735
|
+
* exports/<project>/<assembly>.frame-mode.svg, in the two views that hold its largest movement. Null where the frame is not solved.
|
|
736
|
+
* @param {object} s a built assembly @returns {{ file: string, Hz: number, beam: string } | null}
|
|
737
|
+
*/
|
|
738
|
+
export function writeFrameMode(s) {
|
|
739
|
+
const md = frameMode(s, { placeItems, jointValues, mul }), file = paths.exports(s.project, `${s.name}.frame-mode.svg`);
|
|
740
|
+
if (fs.existsSync(file)) fs.rmSync(file);
|
|
741
|
+
if (!md) return null;
|
|
742
|
+
// the two views that hold the mode's largest movement, the one across the frame's larger extent first
|
|
743
|
+
const move = [0, 1, 2].map((k) => md.lines.reduce((t, l) => t + Math.abs(l.da[k]) + Math.abs(l.db[k]), 0)), most = move.indexOf(Math.max(...move));
|
|
744
|
+
const extent = [0, 1, 2].map((k) => Math.max(...md.lines.flatMap((l) => [l.a[k], l.b[k]])) - Math.min(...md.lines.flatMap((l) => [l.a[k], l.b[k]])));
|
|
745
|
+
const VIEWS = { front: [0, 2], side: [1, 2], top: [0, 1] }, names = { front: 'from the front', side: 'from the side', top: 'from above' };
|
|
746
|
+
const [v1, v2] = Object.keys(VIEWS).filter((v) => VIEWS[v].includes(most)).sort((p, q) => extent[VIEWS[q].find((k) => k !== most)] - extent[VIEWS[p].find((k) => k !== most)]);
|
|
747
|
+
const front = frameModeSvg(md, { view: v1, title: `${s.a.title || s.name}, ${names[v1]}` }), side = frameModeSvg(md, { view: v2, title: names[v2] });
|
|
748
|
+
const h = (t) => Number(/height="(\d+)"/.exec(t)[1]), inner = (t) => t.replace(/^<svg[^>]*>\n?/, '').replace(/<\/svg>\s*$/, '');
|
|
749
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
750
|
+
fs.writeFileSync(file, `<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`);
|
|
751
|
+
return { file, Hz: md.Hz, beam: md.beam };
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// every pose's solve, with the springs and rigid; and, as drawn, each load alone
|
|
755
|
+
function solveAll(fm) {
|
|
756
|
+
let fs, fr, results;
|
|
757
|
+
try { fs = solveFrame(fm.model); fr = solveFrame(fm.rigid); } catch (e) { return { error: e.message, code: e.code }; }
|
|
758
|
+
try { results = solveCases(fm, fs, fr); } catch (e) { if (e.code !== 'fea.frame.mechanism') throw e; return { error: e.message, code: e.code }; }
|
|
759
|
+
// each element's start along its beam, for sagAlong
|
|
760
|
+
for (const r of results) for (const res of [r.spring, r.rigid]) for (const e of res.elements) if (e.of != null) { const b = fm.beams.get(e.of), el = fm.model.elements.find((q) => q.id === e.id); e._from = dot(sub(fm.nodes[el.a], b.A), b.u); }
|
|
761
|
+
return { results, loose: fs.loose };
|
|
762
|
+
}
|
|
763
|
+
function solveCases(fm, fs, fr) {
|
|
764
|
+
const results = fm.cases.map((c) => {
|
|
765
|
+
const loads = fm.nodeLoads(c.values), spring = fs.statics({ loads }), rigid = fr.statics({ loads }), out = { case: c, loads, spring, rigid, values: c.values };
|
|
766
|
+
{ out.alone = new Map(); for (const l of fm.loads) { const ll = fm.nodeLoads(c.values, l), n = ll[0]?.node; if (!n) continue; out.alone.set(l, { sag: sagAt(fs.statics({ loads: ll, gravity: [0, 0, 0] }), n, fm.down), rigid: sagAt(fr.statics({ loads: ll, gravity: [0, 0, 0] }), n, fm.down) }); } }
|
|
767
|
+
return out;
|
|
768
|
+
});
|
|
769
|
+
return results;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* The frame's deflected shape for a check view: each beam as a line of points, as drawn and moved by its sag times
|
|
774
|
+
* `scale` (chosen so the largest movement shows as about a twentieth of the frame's size where left out), in the
|
|
775
|
+
* worst pose of the joins' springs. Never part of the model: a picture of the solve.
|
|
776
|
+
* @param {object} s a built assembly @param {{ placeItems: Function, jointValues: Function, mul: Function }} helpers @param {{ scale?: number }} [o]
|
|
777
|
+
* @returns {{ scale: number, most: number, beams: { id: string, drawn: number[][], moved: number[][] }[], label: string } | null}
|
|
778
|
+
*/
|
|
779
|
+
export function frameShape(s, helpers, o = {}) {
|
|
780
|
+
let fm;
|
|
781
|
+
try { fm = frameModelOf(s, helpers); } catch { return null; }
|
|
782
|
+
if (!fm || fm.empty) return null;
|
|
783
|
+
const solved = solveAll(fm);
|
|
784
|
+
if (solved.error) return null;
|
|
785
|
+
const r = solved.results.reduce((p, q) => (q.spring.deflection.most > p.spring.deflection.most ? q : p)).spring, most = r.deflection.most;
|
|
786
|
+
const pts = Object.values(fm.nodes), size = Math.max(...[0, 1, 2].map((c) => Math.max(...pts.map((p) => p[c])) - Math.min(...pts.map((p) => p[c]))));
|
|
787
|
+
const k = o.scale ?? (most > 0 ? (size / 20) / most : 1);
|
|
788
|
+
const beams = [...fm.beams.values()].map((b) => {
|
|
789
|
+
const els = r.elements.filter((e) => e.of === b.id), drawn = [], moved = [];
|
|
790
|
+
for (const e of els) { const el = fm.model.elements.find((q) => q.id === e.id), A = fm.nodes[el.a], B = fm.nodes[el.b]; e.along.x.forEach((x, i) => { const t = x / e.length, P = add(A, scale(sub(B, A), t)); drawn.push(P); moved.push(add(P, scale(e.along.d[i], k))); }); }
|
|
791
|
+
return { id: b.id, drawn, moved };
|
|
792
|
+
});
|
|
793
|
+
return { scale: k, most, beams, label: `deflection drawn ${fig(k)} times its size (scaled): ${n3(most)} mm at most, with the joins' springs` };
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* The deflected shape as an SVG, seen from the front (x across, z up) or another side: the frame as drawn in grey, the
|
|
798
|
+
* 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}
|
|
799
|
+
*/
|
|
800
|
+
export function frameShapeSvg(sh, o = {}) {
|
|
801
|
+
const [i, j] = o.view === 'side' ? [1, 2] : o.view === 'top' ? [0, 1] : [0, 2], all = sh.beams.flatMap((b) => [...b.drawn, ...b.moved]);
|
|
802
|
+
const lo = [Math.min(...all.map((p) => p[i])), Math.min(...all.map((p) => p[j]))], hi = [Math.max(...all.map((p) => p[i])), Math.max(...all.map((p) => p[j]))];
|
|
803
|
+
const W = 640, pad = 40, k = (W - 2 * pad) / Math.max(hi[0] - lo[0], hi[1] - lo[1], 1), H = Math.ceil((hi[1] - lo[1]) * k + 2 * pad + 56);
|
|
804
|
+
const X = (p) => (pad + (p[i] - lo[0]) * k).toFixed(1), Y = (p) => (H - 56 - pad - (p[j] - lo[1]) * k).toFixed(1);
|
|
805
|
+
const line = (ps, attrs) => `<polyline points="${ps.map((p) => `${X(p)},${Y(p)}`).join(' ')}" fill="none" ${attrs}/>`;
|
|
806
|
+
const esc = (t) => String(t).replace(/&/g, '&').replace(/</g, '<');
|
|
807
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}" font-family="system-ui, sans-serif">
|
|
808
|
+
<rect width="100%" height="100%" fill="#fff"/>
|
|
809
|
+
${sh.beams.map((b) => line(b.drawn, 'stroke="#bbb" stroke-width="6" stroke-linecap="round"')).join('\n')}
|
|
810
|
+
${sh.beams.map((b) => line(b.moved, 'stroke="#c0392b" stroke-width="2"')).join('\n')}
|
|
811
|
+
${o.title ? `<text x="${pad}" y="${H - 40}" font-size="13" font-weight="600">${esc(o.title)}</text>` : ''}
|
|
812
|
+
<text x="${pad}" y="${H - 23}" font-size="12">${esc(sh.label)}</text>
|
|
813
|
+
<text x="${pad}" y="${H - 6}" font-size="11" fill="#666">grey: as drawn; red: the shape it takes, scaled. A check view only, not the model</text>
|
|
814
|
+
</svg>`;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* The check view cad beams writes beside the beams' sheets: the frame's deflected shape seen from the front and from the
|
|
819
|
+
* side, scaled and saying so, as exports/<project>/<assembly>.frame-sag.svg. Null where the frame is not solved.
|
|
820
|
+
* @param {object} s a built assembly @returns {{ file: string, scale: number, most: number } | null}
|
|
821
|
+
*/
|
|
822
|
+
export function writeFrameShape(s) {
|
|
823
|
+
const sh = frameShape(s, { placeItems, jointValues, mul }), file = paths.exports(s.project, `${s.name}.frame-sag.svg`);
|
|
824
|
+
if (fs.existsSync(file)) fs.rmSync(file);
|
|
825
|
+
if (!sh) return null;
|
|
826
|
+
const front = frameShapeSvg(sh, { view: 'front', title: `${s.a.title || s.name}, from the front` }), side = frameShapeSvg(sh, { view: 'side', title: 'from the side' });
|
|
827
|
+
const h = (t) => Number(/height="(\d+)"/.exec(t)[1]), inner = (t) => t.replace(/^<svg[^>]*>\n?/, '').replace(/<\/svg>\s*$/, '');
|
|
828
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
829
|
+
fs.writeFileSync(file, `<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`);
|
|
830
|
+
return { file, scale: sh.scale, most: sh.most };
|
|
831
|
+
}
|