@rulecad/fea 0.2.9 → 0.2.11

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/frame.d.mts ADDED
@@ -0,0 +1,569 @@
1
+ /**
2
+ * One beam element's matrices in its own axes, both ends rigid: 12 × 12, row by row, for [u, v, w, θx, θy, θz] at its
3
+ * start then its end. `k` is its stiffness (N/mm, N, N·mm), `kg` its geometric stiffness for a tension of 1 N, and
4
+ * `m` its consistent mass in kg (kg·mm for the cross terms, kg·mm² for rotations), with rotary inertia.
5
+ * @param {FrameSection} section @param {FrameMaterial} material @param {number} L length, mm
6
+ * @param {{ shear?: boolean }} [o] shear: false ignores the shear areas (Euler-Bernoulli)
7
+ * @returns {{ k: Float64Array, kg: Float64Array, m: Float64Array, phi: [number, number] }} phi: the shear parameters
8
+ * 12 E Iz / (G Asy L²) and 12 E Iy / (G Asz L²)
9
+ */
10
+ export function elementMatrices(section: FrameSection, material: FrameMaterial, L: number, { shear }?: {
11
+ shear?: boolean;
12
+ }): {
13
+ k: Float64Array;
14
+ kg: Float64Array;
15
+ m: Float64Array;
16
+ phi: [number, number];
17
+ };
18
+ /**
19
+ * A frame, read, checked and factorised once, ready for its solves. What is wrong with the model is said here, by
20
+ * name, before any solve: each refusal is an Error with a `code` ("fea.frame." then node, length, section, material,
21
+ * axes, join, support, load, mass, input, unheld or mechanism; buckling adds compression).
22
+ * @param {FrameModel} model
23
+ * @param {{ shear?: boolean }} [o] shear: false ignores the sections' shear areas (Euler-Bernoulli beams)
24
+ * @returns {{
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, tipped?: { node: string, freedom: string }[], rests?: { node: string, freedom: string }[] },
27
+ * modes: (o?: { count?: number, masses?: Record<string, number> }) => { frequencies: number[], modes: VibrationMode[] },
28
+ * freedoms: number, nodes: string[], loose: { node: string, freedom: string }[] }}
29
+ * statics, buckling and modes use the model's own loads, gravity and masses unless given others (another load case
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. 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.
39
+ */
40
+ export function frame(model: FrameModel, o?: {
41
+ shear?: boolean;
42
+ }): {
43
+ statics: (o?: {
44
+ loads?: FrameLoad[];
45
+ gravity?: Vec3;
46
+ masses?: Record<string, number>;
47
+ samples?: number;
48
+ }) => StaticResult;
49
+ buckling: (o?: {
50
+ count?: number;
51
+ loads?: FrameLoad[];
52
+ gravity?: Vec3;
53
+ masses?: Record<string, number>;
54
+ }) => {
55
+ factors: number[];
56
+ modes: BucklingMode[];
57
+ statics: StaticResult;
58
+ tipped?: {
59
+ node: string;
60
+ freedom: string;
61
+ }[];
62
+ rests?: {
63
+ node: string;
64
+ freedom: string;
65
+ }[];
66
+ };
67
+ modes: (o?: {
68
+ count?: number;
69
+ masses?: Record<string, number>;
70
+ }) => {
71
+ frequencies: number[];
72
+ modes: VibrationMode[];
73
+ };
74
+ freedoms: number;
75
+ nodes: string[];
76
+ loose: {
77
+ node: string;
78
+ freedom: string;
79
+ }[];
80
+ };
81
+ /**
82
+ * The same frame with every element cut into `pieces` equal lengths, for buckling and modes: one element cannot bow
83
+ * between its own ends, so a column's Euler load is 22% out with one element, 0.8% with two and 0.05% with four. New
84
+ * nodes are named "<element>/<k>" (or added to the end of a list of nodes), new elements "<element>/<k>" with `of`
85
+ * naming the element they came from; end joints stay at the member's own ends, and spread loads follow their pieces.
86
+ * @param {FrameModel} model @param {number} [pieces] 4
87
+ * @returns {FrameModel}
88
+ */
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
+ };
157
+ export function statics(model: FrameModel, o?: {
158
+ shear?: boolean;
159
+ samples?: number;
160
+ }): StaticResult;
161
+ export function buckling(model: FrameModel, o?: {
162
+ shear?: boolean;
163
+ count?: number;
164
+ }): {
165
+ factors: number[];
166
+ modes: BucklingMode[];
167
+ statics: StaticResult;
168
+ tipped?: {
169
+ node: string;
170
+ freedom: string;
171
+ }[];
172
+ rests?: {
173
+ node: string;
174
+ freedom: string;
175
+ }[];
176
+ };
177
+ export function modes(model: FrameModel, o?: {
178
+ shear?: boolean;
179
+ count?: number;
180
+ }): {
181
+ frequencies: number[];
182
+ modes: VibrationMode[];
183
+ };
184
+ export type Vec3 = [number, number, number];
185
+ /**
186
+ * A beam's cross-section, in its local axes
187
+ */
188
+ export type FrameSection = {
189
+ /**
190
+ * area, mm²
191
+ */
192
+ A: number;
193
+ /**
194
+ * second moment about local y, mm⁴ (bending that moves the beam along local z)
195
+ */
196
+ Iy: number;
197
+ /**
198
+ * second moment about local z, mm⁴ (bending that moves the beam along local y)
199
+ */
200
+ Iz: number;
201
+ /**
202
+ * torsion constant, mm⁴
203
+ */
204
+ J: number;
205
+ /**
206
+ * shear area for shear along local y, mm² (left out: no shear deformation that way)
207
+ */
208
+ Asy?: number;
209
+ /**
210
+ * shear area for shear along local z, mm²
211
+ */
212
+ Asz?: number;
213
+ /**
214
+ * distance from the centroid to the furthest fibre along local y, mm (for stress)
215
+ */
216
+ cy?: number;
217
+ /**
218
+ * distance to the furthest fibre along local z, mm
219
+ */
220
+ cz?: number;
221
+ /**
222
+ * section modulus for bending about y, mm³ (Iy / cz, if cz is not given)
223
+ */
224
+ Wy?: number;
225
+ /**
226
+ * section modulus for bending about z, mm³ (Iz / cy)
227
+ */
228
+ Wz?: number;
229
+ };
230
+ export type FrameMaterial = {
231
+ /**
232
+ * Young's modulus, MPa
233
+ */
234
+ E: number;
235
+ /**
236
+ * shear modulus, MPa (or give nu)
237
+ */
238
+ G?: number;
239
+ /**
240
+ * Poisson's ratio, for G = E / 2(1 + nu)
241
+ */
242
+ nu?: number;
243
+ /**
244
+ * g/cm³ (for gravity and modes; left out: weightless)
245
+ */
246
+ density?: number;
247
+ };
248
+ /**
249
+ * how one rotation at an element's end is joined to its node: rigidly, not at all (a hinge), or through a spring of that many N·mm/rad
250
+ */
251
+ export type Fixity = "rigid" | "free" | number;
252
+ /**
253
+ * 'pinned' frees both bending rotations (ry, rz) and carries twist; 'ball' frees all three; or say each, about the element's local axes
254
+ */
255
+ export type EndJoin = "rigid" | "pinned" | "ball" | {
256
+ rx?: Fixity;
257
+ ry?: Fixity;
258
+ rz?: Fixity;
259
+ };
260
+ export type FrameElement = {
261
+ /**
262
+ * its name in the results (its place in the list if left out)
263
+ */
264
+ id?: string | number;
265
+ /**
266
+ * the node it starts at
267
+ */
268
+ a: string | number;
269
+ /**
270
+ * the node it ends at
271
+ */
272
+ b: string | number;
273
+ /**
274
+ * the section, or its name in the model's `sections`
275
+ */
276
+ section: FrameSection | string;
277
+ /**
278
+ * the material, or its name in the model's `materials`
279
+ */
280
+ material: FrameMaterial | string;
281
+ /**
282
+ * degrees about its own axis, turning local y towards local z
283
+ */
284
+ roll?: number;
285
+ /**
286
+ * the direction local z leans towards (global +Z, or +X for an element along Z)
287
+ */
288
+ up?: Vec3;
289
+ /**
290
+ * how each end is joined to its node ('rigid' if left out)
291
+ */
292
+ ends?: {
293
+ a?: EndJoin;
294
+ b?: EndJoin;
295
+ };
296
+ /**
297
+ * the member this is a piece of (set by `subdivide`, handed back in the results)
298
+ */
299
+ of?: string | number;
300
+ };
301
+ /**
302
+ * one freedom of a support: held (true), free, or a spring to ground of that many N/mm (movements) or N·mm/rad (rotations)
303
+ */
304
+ export type Hold = boolean | number | "fixed" | "free";
305
+ /**
306
+ * 'fixed' holds all six freedoms, 'pinned' the three movements
307
+ */
308
+ export type FrameSupport = "fixed" | "pinned" | {
309
+ x?: Hold;
310
+ y?: Hold;
311
+ z?: Hold;
312
+ rx?: Hold;
313
+ ry?: Hold;
314
+ rz?: Hold;
315
+ };
316
+ /**
317
+ * a force (N) and moment (N·mm) at a node, in global axes; or a load spread evenly along an element, N per mm of its length, in global axes or its own
318
+ */
319
+ export type FrameLoad = {
320
+ node: string | number;
321
+ force?: Vec3;
322
+ moment?: Vec3;
323
+ } | {
324
+ element: string | number;
325
+ spread: Vec3;
326
+ axes?: "global" | "local";
327
+ };
328
+ export type FrameModel = {
329
+ /**
330
+ * each node's position in mm, by name (or a list, named by place: 0, 1, ...)
331
+ */
332
+ nodes: Record<string, Vec3> | Vec3[];
333
+ elements: FrameElement[];
334
+ /**
335
+ * sections by name
336
+ */
337
+ sections?: Record<string, FrameSection>;
338
+ /**
339
+ * materials by name
340
+ */
341
+ materials?: Record<string, FrameMaterial>;
342
+ /**
343
+ * by node
344
+ */
345
+ supports: Record<string, FrameSupport>;
346
+ loads?: FrameLoad[];
347
+ /**
348
+ * N/kg (m/s²), acting on every element's mass and every lumped mass: [0, 0, -9.81]
349
+ */
350
+ gravity?: Vec3;
351
+ /**
352
+ * lumped masses by node, kg (weight under gravity, and inertia in modes)
353
+ */
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";
362
+ };
363
+ /**
364
+ * x, y, z, then about x, y, z
365
+ */
366
+ export type Six = [number, number, number, number, number, number];
367
+ export type ElementResult = {
368
+ id: string | number;
369
+ /**
370
+ * the member it is a piece of, when the model came from `subdivide`
371
+ */
372
+ of?: string | number;
373
+ /**
374
+ * mm
375
+ */
376
+ length: number;
377
+ /**
378
+ * its local x, y and z in global axes
379
+ */
380
+ axes: [Vec3, Vec3, Vec3];
381
+ /**
382
+ * the forces (N) and moments (N·mm) its nodes put on each end, in local axes
383
+ */
384
+ ends: {
385
+ a: Six;
386
+ b: Six;
387
+ };
388
+ /**
389
+ * at each station x (mm from a): axial force (tension positive), shear along local y and z, torque, bending moments
390
+ * about local y and z (each as the part of the beam beyond x acts on the part before it, so at b they are the end
391
+ * forces), and the movement there in global axes (mm). The stations are evenly spaced, plus where each moment peaks.
392
+ */
393
+ along: {
394
+ x: number[];
395
+ N: number[];
396
+ Vy: number[];
397
+ Vz: number[];
398
+ T: number[];
399
+ My: number[];
400
+ Mz: number[];
401
+ d: Vec3[];
402
+ };
403
+ /**
404
+ * each one's largest value by size, signed, and where
405
+ */
406
+ peak: {
407
+ N: Peak;
408
+ Vy: Peak;
409
+ Vz: Peak;
410
+ T: Peak;
411
+ My: Peak;
412
+ Mz: Peak;
413
+ };
414
+ /**
415
+ * the mean axial force, N (tension positive): what buckling reads
416
+ */
417
+ axial: number;
418
+ /**
419
+ * MPa, when the section has cy and cz (or
420
+ * Wy and Wz): the largest |N|/A + |My|/Wy + |Mz|/Wz along the element and where; the largest bending part alone;
421
+ * and N/A at the peak
422
+ */
423
+ stress?: {
424
+ peak: number;
425
+ bending: number;
426
+ axial: number;
427
+ x: number;
428
+ };
429
+ };
430
+ export type Peak = {
431
+ value: number;
432
+ x: number;
433
+ };
434
+ export type StaticResult = {
435
+ /**
436
+ * each node's movement (mm) and rotation (rad), in global axes
437
+ */
438
+ displacements: Record<string, Six>;
439
+ /**
440
+ * at each supported node: the force (N) and moment (N·mm) its support gives the frame
441
+ */
442
+ reactions: Record<string, Six>;
443
+ /**
444
+ * in the model's order
445
+ */
446
+ elements: ElementResult[];
447
+ /**
448
+ * the largest movement of any node, and which
449
+ */
450
+ deflection: {
451
+ most: number;
452
+ node: string;
453
+ };
454
+ };
455
+ /**
456
+ * the loads times `factor` buckle the frame into `shape` (largest movement 1)
457
+ */
458
+ export type BucklingMode = {
459
+ factor: number;
460
+ shape: Record<string, Six>;
461
+ };
462
+ /**
463
+ * Hz, and the shape (largest movement 1); free: a mode of 0 Hz, the frame moving where nothing holds it (loose: 'hold')
464
+ */
465
+ export type VibrationMode = {
466
+ frequency: number;
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;
569
+ };