@rulecad/fea 0.2.10 → 0.2.13

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/CHANGELOG.md ADDED
@@ -0,0 +1,40 @@
1
+ # Changelog: @rulecad/fea
2
+
3
+ What changed in each release, for someone upgrading a workspace.
4
+
5
+ ## 0.2.13: frame layout optimisation
6
+ ### Added
7
+
8
+ - `@rulecad/fea/layout`, a new entry: `layout(problem)` finds the least-volume pin-jointed frame that carries the
9
+ loads to the supports, choosing members from every pair of candidate nodes (a ground structure) and giving each its
10
+ area. It solves the plastic layout programme by an interior point method and adds members a few at a time where
11
+ the solution's virtual strains say they would help (Gilbert and Tyas 2003), so it proves the least volume over
12
+ every candidate while holding a small share of them. Several load cases share one set of areas; strengths may
13
+ differ in tension and compression; a joint can be given a cost as a length of member (fewer, longer members);
14
+ balls can be kept clear of nodes and members, or of nodes only (`through`, a wheel the stays straddle). Flat
15
+ layouts (every node and load at z = 0) and layouts in space.
16
+ - `groundStructure(nodes)` (the candidates, less members through a third node) and `nodeGrid({ from, to, pitch })`.
17
+ - `layoutFrame(result, { material })`: the layout as a frame of beams with its load cases, for `sizing` to pick each
18
+ member from tubes that can be bought. `layoutJoints(result, { material })`: each joint as a problem file for the
19
+ voxel optimiser, the members as stubs carrying their forces in each case (the layout's, or the sized frame's).
20
+ - Refused by name (`fea.layout.input`, `node`, `support`, `load`, `strength`) before any maths, and
21
+ `fea.layout.unstable` when the programme has no answer. A load may name its node by number, as nodes given as a list
22
+ are named by place.
23
+ - The interior point method stops at a relative error of 1e-9 in equilibrium, the members' limits and the gap. Its
24
+ factorisation drops a pivot only when it has cancelled to a 1e-13 share of its own row's diagonal, not of the
25
+ largest: near the optimum the diagonal spans many orders, and the old test also dropped the sound small pivots of
26
+ lightly loaded joints, so equilibrium stalled short of 1e-9 and some solvable problems in space with several cases
27
+ were refused as unstable. As a last guard, a run that still stalls keeps its best point and answers if that point
28
+ is within 1e-6.
29
+
30
+ ## 0.2.11: frames held, sized and their modes said (Frames 3)
31
+
32
+ ### Added
33
+
34
+ - `frame(model, { loose: 'hold' })` holds each way a frame could move that nothing resists and its loads do not push,
35
+ names it in `frame().loose`, and refuses a solve whose loads would move the frame that way. The default is unchanged.
36
+ - Modes and buckling on a held frame count the held ways as free: a way the frame moves mass with nothing resisting is
37
+ a 0 Hz mode marked `free`, and a frame its squeezed members lean further over tips at factor 0 (`tipped`).
38
+ - `sizing()`: the lightest section for each group of members that meets limits on deflection, stress, buckling and
39
+ frequency in every load case, by trying every design where there are few, else by steps; each group says the limit
40
+ that set it.
package/README.md CHANGED
@@ -5,6 +5,8 @@ in their own plane (2D, plane stress, square cells) and solid parts (3D, cubes).
5
5
  and Node alike. Units are millimetres and newtons, so Young's modulus is in MPa and movement in mm.
6
6
 
7
7
  Frames of beams joined at nodes have their own solver, `@rulecad/fea/frame`: see [Frames of beams](#frames-of-beams).
8
+ Which members such a frame should have, and how thick, is found by `@rulecad/fea/layout`: see
9
+ [Frame layout](#frame-layout-which-members-and-how-thick).
8
10
 
9
11
  ```js
10
12
  import { grid, analyse } from '@rulecad/fea';
@@ -125,8 +127,19 @@ result carries its `axes`, so nothing has to be guessed.
125
127
  **What each solve returns.**
126
128
 
127
129
  - `frame(model, { shear })` reads and checks the model, assembles and factorises it, and returns `{ statics,
128
- buckling, modes, freedoms, nodes }`. `shear: false` ignores the shear areas. `statics(model)`, `buckling(model)`
129
- and `modes(model)` do it in one call.
130
+ buckling, modes, freedoms, nodes, loose }`. `shear: false` ignores the shear areas. `statics(model)`, `buckling(model)`
131
+ and `modes(model)` do it in one call. A model with `loose: 'hold'` is solved even where part of it can move with
132
+ nothing resisting (a frame in one plane on pinned feet sways out of that plane; a beam pinned at both ends spins on
133
+ its axis): each such freedom is held, `loose` names it by node, and a solve whose loads would do work moving the
134
+ frame that way is refused (`fea.frame.mechanism`, with `driven: true`). The modes count those freedoms free:
135
+ each way that moves mass unresisted comes back as a mode of 0 Hz, marked `free: true`, and the rest are the
136
+ frame's own, whichever freedom was held. They are the modes of `K + s M` (s the held frame's lowest eigenvalue),
137
+ which has the same shapes as `K` against `M` with every eigenvalue raised by s. Buckling gives a factor of 0 when
138
+ the loads lean the frame the way it is free (its squeezed members turning with it, `vᵀ B v > 0` for that way v,
139
+ B the geometric stiffness's negative): the frame tips over under any share of its loads before anything buckles,
140
+ and `tipped` names the freedoms. When the loads pull it back (a frame hanging from its pins), the factors are of
141
+ the frame held there, so they can only be higher than the true ones, and `rests` names the freedoms. When the
142
+ loads leave that way alone (a strut spinning on its axis), the factors are exact.
130
143
  - `statics({ loads, gravity, masses, samples })`: `displacements` and `reactions` by node, each `[x, y, z, rx, ry,
131
144
  rz]` in global axes; `deflection: { most, node }`; and `elements`, each with its `length`, `axes`, the `ends`
132
145
  forces its nodes put on it (local axes), `axial` (its mean axial force, tension positive), and `along`: at each
@@ -138,7 +151,10 @@ result carries its `axes`, so nothing has to be guessed.
138
151
  - `buckling({ count })`: `factors`, lowest first, and `modes`, each `{ factor, shape }`: the loads times the factor
139
152
  buckle the frame into the shape (by node, largest movement 1). `statics` is the solve it came from. The first
140
153
  factor is always quick; more of them cost more when slender members are in tension.
141
- - `modes({ count })`: `frequencies` in Hz, lowest first, and `modes`, each `{ frequency, shape }`.
154
+ - `modes({ count })`: `frequencies` in Hz, lowest first, and `modes`, each `{ frequency, shape }` (and `free: true`
155
+ on a mode of 0 Hz where the frame moves with nothing resisting).
156
+ - `sizing(model, o)`: each group of members given the lightest section from a list that meets limits on
157
+ deflection, stress, buckling and frequency (below).
142
158
  - `subdivide(model, pieces)` cuts every element into equal pieces. One element cannot bow between its own ends, so
143
159
  buckling and modes want members in pieces: a pinned column's Euler load is 22% out with one element, 0.8% with
144
160
  two and 0.05% with four. Statics is exact with one.
@@ -208,6 +224,161 @@ A braced box of 50 beams (108 unknowns) solves statically in about 3 ms on a lap
208
224
  - Behind a spring or a release, mass and geometric stiffness are reduced as at rest (Guyan's reduction), which
209
225
  is why buckling and modes want members cut into pieces.
210
226
 
227
+ ### Sizing: the lightest sections that meet the limits
228
+
229
+ `sizing(model, o)` chooses a section for each group of members (members that must match: a pair of rails, four
230
+ posts) from a list, so the frame meets its limits for the least mass, or the least cost where every choice gives
231
+ one. Each design is the same frame with its groups' sections, materials and rolls changed, solved under every load
232
+ case. A frame of tubes from a layout optimiser and a frame of extrusions from an assembly go through the same solver
233
+ and the same limits.
234
+
235
+ ```js
236
+ import { sizing } from '@rulecad/fea/frame';
237
+
238
+ const bar = (b) => ({ name: `bar ${b}`, section: { A: b * b, Iy: b ** 4 / 12, Iz: b ** 4 / 12, J: 0.141 * b ** 4, cy: b / 2, cz: b / 2 },
239
+ material: { E: 70000, nu: 0.33, density: 2.7, strength: 205 } });
240
+ // model: a table, four 700 mm legs on pinned feet and a ring of rails 600 x 400 mm joined rigidly, its own weight
241
+ // and 20 kg at the middle of each long rail (nodes m1 and m2)
242
+ const r = sizing(model, {
243
+ groups: { legs: ['z1', 'z2', 'z3', 'z4'], rails: ['x1', 'x2'], ends: ['y1', 'y2'] }, // by element id, or by `of`
244
+ choices: [10, 15, 20, 25, 30].map(bar),
245
+ limits: { deflection: [{ node: 'm1', limit: 1.7 }, { node: 'm2', limit: 1.7 }], stress: { margin: 2 }, buckling: { factor: 2, euler: 1 } },
246
+ });
247
+ r.groups[1]; // { name: 'rails', choice: 'bar 20', mass: 1.296, lighter: 'bar 15',
248
+ // governs: { limit: 'deflection', where: 'm1', value: 0.92, allowed: 1.7, broken: 1.51 }, margin: 1.84 }
249
+ r.groups[0]; // { name: 'legs', choice: 'bar 10', lighter: null, governs: null }: the lightest in the list meets them
250
+ ```
251
+
252
+ | Part | Shape | Notes |
253
+ |---|---|---|
254
+ | `groups` | `{ name: [members] }` | Each member an element's `id`, or the member its pieces came from (`of`). Members in no group keep their sections |
255
+ | `choices` | `[{ name, section, material, mass, cost, roll }]` | `material` its own (the member's if left out), with `strength` in MPa for the stress limit; `mass` and `cost` per metre (mass from the area and density if left out); `roll` degrees added to the member's roll, the same section turned (a 20 x 40 on edge) |
256
+ | `only` | `{ group: [choice names] }` | The choices a group may take (all of them if left out) |
257
+ | `limits.deflection` | `[{ node, limit, along }]` or `[{ member, limit, from, to, along }]` | mm, along `along` (gravity's direction, else the whole movement); a member between two distances from its start |
258
+ | `limits.stress` | `{ margin }` | Each member's peak `abs(N)/A + abs(My)/Wy + abs(Mz)/Wz`, times the margin, under its material's strength |
259
+ | `limits.buckling` | `{ factor, euler }` | The whole frame's first buckling factor at least `factor` (members cut into `pieces`, 4); with `euler` (the effective length factor K) each grouped member in compression also carries `factor` times its force under `π² E I / (K L)²`, I the lesser second moment |
260
+ | `limits.frequency` | `{ Hz }` | The lowest mode at least this |
261
+ | `cases` | `[{ label, loads, masses, inertia }]` | Load cases: `loads` and `masses` as `statics` takes them; `inertia` masses whose weight is already in `loads` and which ring in the modes only |
262
+ | a model list | `[frame, ...others]` | The others are the same frame joined other ways (its joins rigid), same elements in the same order: each is held to the stress limit too |
263
+
264
+ **The search.** With few designs (`every`, 512, or `search: 'every'`), every design is ranked by mass and solved in
265
+ that order until one meets every limit, which makes it the lightest; a design is dropped at the first stage
266
+ (statics, then buckling, then modes) that breaks a limit. With more, `search: 'steps'`: from every group at its
267
+ lightest, each group looks up its list for the lightest heavier choice that cuts the worst limit's use (passing over
268
+ one that is heavier but weaker this way, a 30 x 30 after a 20 x 40 on edge), and the group that cuts it most for its
269
+ added mass steps up to it, until the limits are met; then each group, the heaviest first, steps down as far as the limits allow, until nothing moves. Steps
270
+ solve far fewer designs and land near the lightest, not always on it (a table in the tests: within a fifth).
271
+
272
+ **What set each choice.** A group's `governs` is the limit its next lighter choice breaks with the other groups as
273
+ chosen, the worst there by `broken` (its use of the limit, over 1). A choice of the same weight (the same section
274
+ turned) is not lighter. `margin` is how many times inside that limit the chosen design is. A group at the lightest
275
+ choice has no `governs`, and its margin is its own members' nearest check. Where no design meets the limits, `ok` is
276
+ false and the result is the design that came nearest, with `worst` saying which limit it breaks and by how much.
277
+
278
+ **Limits of sizing.** The geometry stays as drawn: a deeper section moves no node, so joints that hang off a
279
+ member's face by its width keep their drawn offsets. The search is over the list given; it does not invent a section.
280
+
281
+
282
+ ## Frame layout: which members, and how thick
283
+
284
+ `@rulecad/fea/layout` designs a frame of tubes or bars from nothing but its loads and supports: given a cloud of
285
+ candidate nodes, it chooses which members to put between them, and how thick each must be, so the frame carries
286
+ every load case to its supports with the least material. A bike frame, a roll cage or a space frame is mostly empty,
287
+ so it is better designed as members joined at nodes than as millions of voxels. The members are pin-jointed and each
288
+ is as thick as its worst case's force over the strength (fully stressed); the frame that comes out is then sized
289
+ from tubes that can be bought (`layoutFrame` and `sizing`), and its joints shaped by the voxel optimiser
290
+ (`layoutJoints`).
291
+
292
+ ```js
293
+ import { layout, layoutFrame, layoutJoints } from '@rulecad/fea/layout';
294
+ import { sizing } from '@rulecad/fea/frame';
295
+
296
+ const r = layout({
297
+ nodes: { A: [0, 300], B: [0, -300], C: [400, 0] }, // mm; or a grid: { from, to, pitch }, or both
298
+ supports: { A: 'pinned', B: 'pinned' }, // or { x: true, y: true, z: false }
299
+ loads: [{ node: 'C', force: [0, -1000] }], // N; or cases: [{ label, loads }, ...]
300
+ strength: 100, // MPa; or { tension, compression }
301
+ });
302
+ r.volume; // 8333.3 mm³: two bars of 8.33 mm², 833 N each
303
+ r.members[0]; // { id: 'B-C', a: 'B', b: 'C', length: 500, area: 8.333, forces: [-833.3], kind: 'compression' }
304
+ const f = layoutFrame(r, { material: { E: 200000, nu: 0.3, density: 7.85, strength: 275 } });
305
+ const sized = sizing(f.model, { groups: { bars: f.members }, choices: tubes, cases: f.cases, limits: { stress: { margin: 2 }, buckling: { factor: 2, euler: 1 } } });
306
+ const joints = layoutJoints(r, { material: 's275' }); // [{ node: 'C', members, problem }]: a problem file for each joint
307
+ ```
308
+
309
+ | Part of the problem | Shape | Notes |
310
+ |---|---|---|
311
+ | `nodes` | `{ name: [x, y] or [x, y, z] }` | Candidate nodes, mm (a list is named by place) |
312
+ | `grid` | `{ from, to, pitch }` | More candidates, every `pitch` mm across a box, named `"i,j"` or `"i,j,k"` by place; one within a hundredth of the pitch of a named node gives way to it |
313
+ | `supports` | `{ node: 'pinned' or { x, y, z } }` | Which movements are held at each |
314
+ | `loads` or `cases` | `[{ node, force }]` or `[{ label, loads }]` | One load case, or several, each carried alone with the same areas |
315
+ | `strength` | MPa, or `{ tension, compression }` | Each member's force over its area stays within it: give the material's strength over your margin |
316
+ | `density` | g/cm³ | For the mass, kg |
317
+ | `joint` | mm | A joint's cost as a length of member (0): above 0, fewer and longer members |
318
+ | `reach` | mm | The longest candidate member |
319
+ | `avoid` | `[{ at, r, through }]` | Balls (circles, flat) no node or member enters; with `through: true` members may pass and only nodes are kept out |
320
+ | `plane` | `true` or `false` | A flat layout in x and y; left out, flat when every node and load is at z = 0 |
321
+
322
+ Options: `keep` (members thinner than this share of the thickest are left out of `members`, 1e-4; the volume counts
323
+ them), `start` (each node's nearest candidates in the first programme: 8 flat, 18 in space), `add` (most members
324
+ added a round), `adding: false` (every candidate in one programme), `tolerance` (1e-5).
325
+
326
+ **What comes back.** `volume` (mm³), `mass` (kg, with a density), `members` (thickest first: area, each case's force,
327
+ tension positive, and `kind`), `nodes` (those the members meet at, with the loaded and supported ones), `candidates`
328
+ (the ground structure's members), `programme` (how many the last programme held), `rounds`, `strain` (the largest
329
+ virtual strain of any candidate over its limit: 1 at most, which proves no left-out member would lower the volume),
330
+ `left` (the volume share under `keep`) and `virtual` (each case's virtual displacements by node, the programme's
331
+ dual). With several cases the areas are unique but the forces in a case may not be (a member thicker than one case
332
+ needs can carry more or less in it): `members[].forces` is one set the strengths allow. For the forces the built frame
333
+ will carry, solve it (`layoutFrame`, then `frame().statics`) and give them to `layoutJoints`.
334
+
335
+ **Handing it on.** `layoutFrame(result, { material, section, ends })` is the layout as a frame model, each member a
336
+ solid round bar of its area (or `section`), joints `'rigid'` (welded, the default) or `'pinned'`, a flat layout held
337
+ out of its plane at its supports, and `cases` as `sizing` takes them. `layoutJoints(result, { material, diameters,
338
+ forces, stub, cell, volume, nodes })` gives each joint (every node where two members or more meet, or those named) as
339
+ a problem file in the form `cad optimise` reads: a space round the node, each member a stub `stub` mm long (twice the
340
+ widest diameter), the stub carrying the most held (the frame beyond it) and the others loaded with their forces in
341
+ each case, plus any outside load at the node. A flat layout's joints are flat problems as thick as the widest tube.
342
+
343
+ **How it works.** Every pair of candidate nodes is a member unless it passes through a third node (two shorter ones
344
+ do the same), is longer than `reach` or enters an avoided ball. The least volume is a linear programme in the areas
345
+ and the forces; it is solved by a primal-dual interior point method, the normal equations' members' rows eliminated
346
+ first so the dense matrix is only the equilibrium rows (free freedoms times cases). The first programme holds each
347
+ node's nearest candidates. Its dual is a virtual displacement field; any left-out member it would strain past its
348
+ limit would lower the volume, so the most strained are added and the programme solved again, until none is. The
349
+ answer is then the least over every candidate (the `strain` figure is the proof), while the programme holds a few
350
+ percent of them.
351
+
352
+ | What | Formula | Source |
353
+ |---|---|---|
354
+ | The least volume | Least `Σ (l_i + s) a_i` such that `B q_k = f_k` and `−σc a_i ≤ q_ik ≤ σt a_i` in every case k | Dorn, Gomory and Greenberg; Hemp (several cases); Parkes (the joint cost s) |
355
+ | Equilibrium | Member i from node a to b, unit direction e: column `−e` at a and `+e` at b, so `B q = f` with tension positive | Statics |
356
+ | Standard form | `q = p − n` with p and n ≥ 0, and a slack per member and case: `a_i σt = p_ik + (σt / σc) n_ik + s_ik` (forces scaled by the largest load, lengths by the longest candidate) | Linear programming |
357
+ | The solver | Primal-dual interior point, Mehrotra's predictor and corrector; a pivot that has cancelled to a 1e-13 share of its own row's diagonal is made huge, so its direction solves as 0 (tested against its own row, as the diagonal spans many orders near the optimum). It stops when equilibrium, the members' limits and the gap between the primal and dual values are each within 1e-9 relative; a run that rounding still stalls short of that takes its best point if within 1e-6 | Mehrotra; Nocedal and Wright, chapter 14; Zhang (LIPSOL) |
358
+ | Adding members | A left-out member would lower the volume if `Σ_k max(0, σt b_i·u_k, −σc b_i·u_k) > l_i + s`, u_k the dual of case k's equilibrium | Gilbert and Tyas |
359
+ | Members through a node | From each node, only the nearest node in each direction | Gilbert and Tyas |
360
+
361
+ **Tested** against hand calculations, each to rounding: two bars to two pins (8333.3 mm³, 833.3 N each), the same
362
+ weaker in compression (12500 mm³), a tripod in space (5625 mm³, 375 N a leg), two load cases sharing areas (3000 mm³,
363
+ not the 4000 of each alone); and against Michell's closed form for a couple carried between two circles (Michell
364
+ 1904: `V = 2 M ln(R / r) / σ`): never under it, 2.6% over with 16 nodes to a ring and 0.65% with 32, the excess
365
+ falling fourfold as the step halves (straight members where his spirals curve). Member adding gives the same volume
366
+ as every candidate in one programme, alone and with two cases. The 32-to-a-ring wheel (224 nodes, 23728
367
+ candidates) takes about half a second on a laptop; the bicycle frame example (`examples/bicycle-frame`, 61 nodes and 1242 candidates,
368
+ three cases) about 4 seconds.
369
+
370
+ **Limits.**
371
+
372
+ - Pin-jointed and plastic: each member is as thick as its force needs, with nothing for buckling or bending. Size the
373
+ result (`layoutFrame` and `sizing`), which checks both.
374
+ - The node positions are fixed: a finer grid gives a better layout, slowly (the dense matrix grows with the free
375
+ freedoms times the cases: a few thousand rows is the practical most).
376
+ - With several cases, the forces within a case may not be unique (above), and members of equal merit may share a
377
+ load: a joint cost (`joint`) settles on fewer.
378
+ - A flat layout's members may cross without meeting (a node is needed where they cross to join them).
379
+ - The joints' problems carry the members' forces as point loads at the stubs' ends, held at one stub: the joint's own
380
+ stiffness against the frame's is not modelled.
381
+
211
382
  ## Sources
212
383
 
213
384
  - Amir, Aage, Lazarov (2014). On multigrid-CG for efficient topology optimization. *Structural and Multidisciplinary
@@ -219,10 +390,21 @@ A braced box of 50 beams (108 unknowns) solves statically in about 3 ms on a lap
219
390
  - Cook, Malkus, Plesha, Witt (2002). *Concepts and Applications of Finite Element Analysis*, 4th ed. Wiley.
220
391
  - Cuthill, McKee (1969). Reducing the bandwidth of sparse symmetric matrices. *Proceedings of the 24th National
221
392
  Conference of the ACM*, 157–172.
393
+ - Dorn, Gomory, Greenberg (1964). Automatic design of optimal structures. *Journal de Mécanique* 3, 25–52.
222
394
  - Friedman, Kosmatka (1993). An improved two-node Timoshenko beam finite element. *Computers and Structures* 47,
223
395
  473–481.
396
+ - Gilbert, Tyas (2003). Layout optimization of large-scale pin-jointed frames. *Engineering Computations* 20,
397
+ 1044–1064.
224
398
  - Guyan (1965). Reduction of stiffness and mass matrices. *AIAA Journal* 3, 380.
399
+ - Hemp (1973). *Optimum Structures*. Clarendon Press, Oxford.
225
400
  - McGuire, Gallagher, Ziemian (2000). *Matrix Structural Analysis*, 2nd ed. Wiley.
401
+ - Mehrotra (1992). On the implementation of a primal-dual interior point method. *SIAM Journal on Optimization* 2,
402
+ 575–601.
403
+ - Michell (1904). The limits of economy of material in frame-structures. *Philosophical Magazine* 8, 589–597.
404
+ - Nocedal, Wright (2006). *Numerical Optimization*, 2nd ed. Springer.
405
+ - Parkes (1975). Joints in optimum frameworks. *International Journal of Solids and Structures* 11, 1017–1022.
226
406
  - Przemieniecki (1968). *Theory of Matrix Structural Analysis*. McGraw-Hill.
227
407
  - Timoshenko, Gere (1961). *Theory of Elastic Stability*, 2nd ed. McGraw-Hill.
228
408
  - Young, Budynas (2002). *Roark's Formulas for Stress and Strain*, 7th ed. McGraw-Hill.
409
+ - Zhang (1998). Solving large-scale linear programs by interior-point methods under the MATLAB environment.
410
+ *Optimization Methods and Software* 10, 1–31.
package/frame.d.mts CHANGED
@@ -23,12 +23,19 @@ export function elementMatrices(section: FrameSection, material: FrameMaterial,
23
23
  * @param {{ shear?: boolean }} [o] shear: false ignores the sections' shear areas (Euler-Bernoulli beams)
24
24
  * @returns {{
25
25
  * statics: (o?: { loads?: FrameLoad[], gravity?: Vec3, masses?: Record<string, number>, samples?: number }) => StaticResult,
26
- * buckling: (o?: { count?: number, loads?: FrameLoad[], gravity?: Vec3, masses?: Record<string, number> }) => { factors: number[], modes: BucklingMode[], statics: StaticResult },
26
+ * buckling: (o?: { count?: number, loads?: FrameLoad[], gravity?: Vec3, masses?: Record<string, number> }) => { factors: number[], modes: BucklingMode[], statics: StaticResult, tipped?: { node: string, freedom: string }[], rests?: { node: string, freedom: string }[] },
27
27
  * modes: (o?: { count?: number, masses?: Record<string, number> }) => { frequencies: number[], modes: VibrationMode[] },
28
- * freedoms: number, nodes: string[] }}
28
+ * freedoms: number, nodes: string[], loose: { node: string, freedom: string }[] }}
29
29
  * statics, buckling and modes use the model's own loads, gravity and masses unless given others (another load case
30
30
  * on the same factorisation). samples: stations along each element (11). count: how many modes (1 for buckling, 6
31
- * for vibration; fewer come back if the frame has fewer). freedoms: how many unknowns were solved for.
31
+ * for vibration; fewer come back if the frame has fewer). freedoms: how many unknowns were solved for. loose: the
32
+ * freedoms held where nothing resists them (the model's loose: 'hold'), by node; none otherwise. The statics stand
33
+ * with them held, as the loads do no work there. The modes count them free: each way that moves mass unresisted
34
+ * is a mode of 0 Hz (marked free), and the rest are the frame's own, whatever freedom was held. Buckling where the
35
+ * loads lean the frame that way (its squeezed members turning with it) gives a factor of 0, the frame tipping over
36
+ * before anything buckles, with the ways named as `tipped`; where the loads pull it back (a frame hanging from its
37
+ * pins), the factors are of the frame held there, so at most the true ones, and the ways are named as `rests`;
38
+ * where the loads leave it alone (a strut spinning on its axis), the factors are exact.
32
39
  */
33
40
  export function frame(model: FrameModel, o?: {
34
41
  shear?: boolean;
@@ -48,6 +55,14 @@ export function frame(model: FrameModel, o?: {
48
55
  factors: number[];
49
56
  modes: BucklingMode[];
50
57
  statics: StaticResult;
58
+ tipped?: {
59
+ node: string;
60
+ freedom: string;
61
+ }[];
62
+ rests?: {
63
+ node: string;
64
+ freedom: string;
65
+ }[];
51
66
  };
52
67
  modes: (o?: {
53
68
  count?: number;
@@ -58,6 +73,10 @@ export function frame(model: FrameModel, o?: {
58
73
  };
59
74
  freedoms: number;
60
75
  nodes: string[];
76
+ loose: {
77
+ node: string;
78
+ freedom: string;
79
+ }[];
61
80
  };
62
81
  /**
63
82
  * The same frame with every element cut into `pieces` equal lengths, for buckling and modes: one element cannot bow
@@ -68,6 +87,73 @@ export function frame(model: FrameModel, o?: {
68
87
  * @returns {FrameModel}
69
88
  */
70
89
  export function subdivide(model: FrameModel, pieces?: number): FrameModel;
90
+ /**
91
+ * The lightest section for each group of members that meets the limits: each group (members that must match, a pair
92
+ * of rails, four posts) is given one of the choices, and the frame is solved under each load case for every design
93
+ * tried. With few designs (every, 512) every one is ranked by mass and the first that meets the limits is the
94
+ * lightest; with more, the lightest is found by steps (each group up to its lightest heavier choice that helps, the one that helps most for its mass, until
95
+ * the limits are met, then each down as far as the limits allow), which is near the lightest but not proven so. Each
96
+ * group's result names the limit that set it: the one its next lighter choice would break, with the other groups as
97
+ * chosen. The geometry stays as drawn: only sections, materials and rolls change, and members outside every group
98
+ * keep theirs. Refused by name: unknown options, a member in no element or in two groups, a choice with no section,
99
+ * a limit that is not above 0, and sizing by cost where a choice has none.
100
+ * @param {FrameModel | FrameModel[]} model the frame; or a list, the first the frame and the rest the same frame
101
+ * joined other ways (its joins rigid), whose stress is checked too, as a join's moment grows as it stiffens
102
+ * @param {{ groups: Record<string, (string | number)[]>, choices: SizingChoice[], only?: Record<string, string[]>,
103
+ * limits: SizingLimits, cases?: { label?: string, loads?: FrameLoad[], masses?: Record<string, number>, inertia?: Record<string, number> }[],
104
+ * by?: 'mass' | 'cost', pieces?: number, search?: 'every' | 'steps', every?: number }} o
105
+ * groups: members by group name, each an element's id or the member its pieces came from (`of`); only: the
106
+ * choices a group may take, by name (all of them if left out); cases: load cases (the model's own if left out),
107
+ * loads and masses as statics takes them, and inertia: masses whose weight is already in loads, which ring in the
108
+ * modes only; by: what is least (mass); pieces: each member cut into this many for buckling and modes (4)
109
+ * @returns {{ ok: boolean, by: 'mass' | 'cost', search: 'every' | 'steps', tried: number, total: number,
110
+ * groups: { name: string, members: (string | number)[], choice: string, length: number, mass: number, cost: number | null,
111
+ * lighter: string | null, governs: (SizingCheck & { lighter: string, broken: number }) | null, margin: number | null }[],
112
+ * checks: SizingCheck[], worst: SizingCheck | null, model: FrameModel }}
113
+ * ok: the limits are met (else the design that came nearest, and its checks say by how much); total: kg (or cost) of
114
+ * the grouped members; tried: designs solved; each group's length (mm), mass (kg) and cost; lighter: the next choice
115
+ * that weighs (or costs) less; governs: the limit that lighter choice breaks, its ratio there as `broken`; margin: how many times inside
116
+ * that limit the design is, as chosen; model: the frame with the chosen sections
117
+ */
118
+ export function sizing(model: FrameModel | FrameModel[], o?: {
119
+ groups: Record<string, (string | number)[]>;
120
+ choices: SizingChoice[];
121
+ only?: Record<string, string[]>;
122
+ limits: SizingLimits;
123
+ cases?: {
124
+ label?: string;
125
+ loads?: FrameLoad[];
126
+ masses?: Record<string, number>;
127
+ inertia?: Record<string, number>;
128
+ }[];
129
+ by?: "mass" | "cost";
130
+ pieces?: number;
131
+ search?: "every" | "steps";
132
+ every?: number;
133
+ }): {
134
+ ok: boolean;
135
+ by: "mass" | "cost";
136
+ search: "every" | "steps";
137
+ tried: number;
138
+ total: number;
139
+ groups: {
140
+ name: string;
141
+ members: (string | number)[];
142
+ choice: string;
143
+ length: number;
144
+ mass: number;
145
+ cost: number | null;
146
+ lighter: string | null;
147
+ governs: (SizingCheck & {
148
+ lighter: string;
149
+ broken: number;
150
+ }) | null;
151
+ margin: number | null;
152
+ }[];
153
+ checks: SizingCheck[];
154
+ worst: SizingCheck | null;
155
+ model: FrameModel;
156
+ };
71
157
  export function statics(model: FrameModel, o?: {
72
158
  shear?: boolean;
73
159
  samples?: number;
@@ -79,6 +165,14 @@ export function buckling(model: FrameModel, o?: {
79
165
  factors: number[];
80
166
  modes: BucklingMode[];
81
167
  statics: StaticResult;
168
+ tipped?: {
169
+ node: string;
170
+ freedom: string;
171
+ }[];
172
+ rests?: {
173
+ node: string;
174
+ freedom: string;
175
+ }[];
82
176
  };
83
177
  export function modes(model: FrameModel, o?: {
84
178
  shear?: boolean;
@@ -258,6 +352,13 @@ export type FrameModel = {
258
352
  * lumped masses by node, kg (weight under gravity, and inertia in modes)
259
353
  */
260
354
  masses?: Record<string, number>;
355
+ /**
356
+ * what a mechanism does: 'refuse' (left out) refuses the model; 'hold' holds
357
+ * each freedom nothing resists and solves on, so long as the loads of each solve do no work moving it that way (a
358
+ * frame in one plane on pinned feet, free to sway out of it, under loads in its plane): the frame's `loose` names
359
+ * them, and a solve whose loads would move one is refused
360
+ */
361
+ loose?: "refuse" | "hold";
261
362
  };
262
363
  /**
263
364
  * x, y, z, then about x, y, z
@@ -359,9 +460,110 @@ export type BucklingMode = {
359
460
  shape: Record<string, Six>;
360
461
  };
361
462
  /**
362
- * Hz, and the shape (largest movement 1)
463
+ * Hz, and the shape (largest movement 1); free: a mode of 0 Hz, the frame moving where nothing holds it (loose: 'hold')
363
464
  */
364
465
  export type VibrationMode = {
365
466
  frequency: number;
366
467
  shape: Record<string, Six>;
468
+ free?: true;
469
+ };
470
+ /**
471
+ * One section a group of members may be given
472
+ */
473
+ export type SizingChoice = {
474
+ /**
475
+ * its name in the results (a profile's, a tube's size)
476
+ */
477
+ name: string;
478
+ /**
479
+ * in the member's own axes, as drawn
480
+ */
481
+ section: FrameSection;
482
+ /**
483
+ * its own material (the member's if left out); strength
484
+ * in MPa, for the stress limit
485
+ */
486
+ material?: FrameMaterial & {
487
+ strength?: number;
488
+ };
489
+ /**
490
+ * kg per metre (else the section's area times the material's density)
491
+ */
492
+ mass?: number;
493
+ /**
494
+ * per metre, in any one currency, for sizing by cost
495
+ */
496
+ cost?: number;
497
+ /**
498
+ * degrees added to the member's roll: the same section turned about its length (a 20 x 40
499
+ * standing on edge in place of lying flat)
500
+ */
501
+ roll?: number;
502
+ };
503
+ /**
504
+ * What every design must meet; leave one out and it sets nothing
505
+ */
506
+ export type SizingLimits = {
507
+ /**
508
+ * a node, or a member between two distances from its start (mm, its whole length if left out), moves no more than
509
+ * limit mm along `along` (gravity's direction, else the whole movement)
510
+ */
511
+ deflection?: ({
512
+ node: string | number;
513
+ limit: number;
514
+ along?: Vec3;
515
+ } | {
516
+ member: string | number;
517
+ limit: number;
518
+ from?: number;
519
+ to?: number;
520
+ along?: Vec3;
521
+ })[];
522
+ /**
523
+ * each member's peak stress times margin stays under its material's strength
524
+ */
525
+ stress?: {
526
+ margin: number;
527
+ };
528
+ /**
529
+ * the whole frame's first buckling factor is at least
530
+ * factor; with euler (the effective length factor K), each member in compression also carries factor times its
531
+ * force under Euler's load π² E I / (K L)², I the lesser second moment (the grouped members only)
532
+ */
533
+ buckling?: {
534
+ factor: number;
535
+ euler?: number;
536
+ };
537
+ /**
538
+ * the lowest mode is at least this
539
+ */
540
+ frequency?: {
541
+ Hz: number;
542
+ };
543
+ };
544
+ /**
545
+ * one limit's figure in one design
546
+ */
547
+ export type SizingCheck = {
548
+ limit: "deflection" | "stress" | "buckling" | "frequency";
549
+ /**
550
+ * the node, member or 'frame' it is about
551
+ */
552
+ where: string;
553
+ /**
554
+ * the figure: mm, MPa, a factor or Hz
555
+ */
556
+ value: number;
557
+ /**
558
+ * what the limit allows of it
559
+ */
560
+ allowed: number;
561
+ /**
562
+ * how much of the limit it uses (1 is at the limit; over 1 fails)
563
+ */
564
+ ratio: number;
565
+ /**
566
+ * the load case it is worst in
567
+ */
568
+ case?: string;
367
569
  };