@rulecad/fea 0.2.9 → 0.2.10
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/README.md +155 -0
- package/frame.d.mts +367 -0
- package/frame.mjs +660 -0
- package/package.json +14 -4
package/README.md
CHANGED
|
@@ -4,6 +4,8 @@ How far a part bends under load. Finite elements on a grid of cells, each with i
|
|
|
4
4
|
in their own plane (2D, plane stress, square cells) and solid parts (3D, cubes). Plain JavaScript in typed arrays, no dependencies: it runs in browsers
|
|
5
5
|
and Node alike. Units are millimetres and newtons, so Young's modulus is in MPa and movement in mm.
|
|
6
6
|
|
|
7
|
+
Frames of beams joined at nodes have their own solver, `@rulecad/fea/frame`: see [Frames of beams](#frames-of-beams).
|
|
8
|
+
|
|
7
9
|
```js
|
|
8
10
|
import { grid, analyse } from '@rulecad/fea';
|
|
9
11
|
|
|
@@ -64,10 +66,163 @@ So give every member that bends at least four cells, and check a final shape on
|
|
|
64
66
|
stiffness moves by more than a few percent, the grid was too coarse. (Measured on cantilevers and a simply supported
|
|
65
67
|
beam, in 2D and 3D.)
|
|
66
68
|
|
|
69
|
+
## Frames of beams
|
|
70
|
+
|
|
71
|
+
`@rulecad/fea/frame` solves a frame as beams joined at nodes: how far it moves under load, what each beam carries,
|
|
72
|
+
the load at which it buckles and the frequencies it rings at. A frame of aluminium extrusion or tube would need
|
|
73
|
+
millions of cubes, nearly all of them empty; as beams it has a few hundred unknowns and solves in milliseconds, so a
|
|
74
|
+
machine's frame can be checked at every pose. It is its own entry of the package, with no dependencies, and runs in
|
|
75
|
+
browsers and Node alike.
|
|
76
|
+
|
|
77
|
+
```js
|
|
78
|
+
import { frame, subdivide } from '@rulecad/fea/frame';
|
|
79
|
+
|
|
80
|
+
const model = {
|
|
81
|
+
nodes: { footA: [0, 0, 0], topA: [0, 0, 400], topB: [600, 0, 400], footB: [600, 0, 0] }, // mm
|
|
82
|
+
sections: { bar2020: { A: 400, Iy: 13333, Iz: 13333, J: 22500, Asy: 333, Asz: 333, cy: 10, cz: 10 } },
|
|
83
|
+
materials: { aluminium: { E: 69000, nu: 0.33, density: 2.7 } },
|
|
84
|
+
elements: [
|
|
85
|
+
{ id: 'legA', a: 'footA', b: 'topA', section: 'bar2020', material: 'aluminium' },
|
|
86
|
+
{ id: 'beam', a: 'topA', b: 'topB', section: 'bar2020', material: 'aluminium', ends: { a: { ry: 2e6, rz: 2e6 }, b: { ry: 2e6, rz: 2e6 } } },
|
|
87
|
+
{ id: 'legB', a: 'footB', b: 'topB', section: 'bar2020', material: 'aluminium' },
|
|
88
|
+
],
|
|
89
|
+
supports: { footA: 'fixed', footB: 'fixed' },
|
|
90
|
+
loads: [{ node: 'topA', force: [50, 0, 0] }, { element: 'beam', spread: [0, 0, -0.2] }],
|
|
91
|
+
gravity: [0, 0, -9.81],
|
|
92
|
+
masses: { topB: 1.5 },
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const f = frame(model); // read, checked and factorised once
|
|
96
|
+
const s = f.statics();
|
|
97
|
+
s.displacements.topA; // [x, y, z, rx, ry, rz]: 0.40 mm sideways
|
|
98
|
+
s.reactions.footA; // the force (N) and moment (N·mm) the support gives the frame
|
|
99
|
+
s.elements[1].peak.My; // { value, x }: the beam's largest moment about its own y, and where along it
|
|
100
|
+
s.elements[1].stress.peak; // 5.6 MPa
|
|
101
|
+
const fine = frame(subdivide(model, 4)); // every member in four pieces, for buckling and modes
|
|
102
|
+
fine.buckling().factors[0]; // 181: the loads times this buckle the frame
|
|
103
|
+
fine.modes({ count: 3 }).frequencies; // [26.7, 36.6, 66.9] Hz
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**The model** is plain data, so an assembly can write it and a file can hold it.
|
|
107
|
+
|
|
108
|
+
| Part | Shape | Notes |
|
|
109
|
+
|---|---|---|
|
|
110
|
+
| `nodes` | `{ name: [x, y, z] }`, or a list of positions named by place | mm |
|
|
111
|
+
| `elements` | `[{ id, a, b, section, material, roll, up, ends }]` | From node `a` to node `b`. `section` and `material` are objects, or names in the model's `sections` and `materials` |
|
|
112
|
+
| a section | `{ A, Iy, Iz, J, Asy, Asz, cy, cz }` | Area (mm²); second moments about the element's own y and z, and the torsion constant (mm⁴); shear areas (mm², leave out for no shear deformation); the distances to the furthest fibre along y and z (mm), or the section moduli `Wy` and `Wz` (mm³), for stress |
|
|
113
|
+
| a material | `{ E, nu, density }` | MPa; Poisson's ratio (or `G` in MPa); g/cm³, as the kit's material rule sets give it |
|
|
114
|
+
| `ends` | `{ a, b }`, each `'rigid'`, `'pinned'`, `'ball'` or `{ rx, ry, rz }` | How each end is joined to its node: each rotation `'rigid'`, `'free'`, or a spring's stiffness in N·mm/rad, about the element's own axes. `'pinned'` frees both bending rotations and still carries twist; `'ball'` frees all three |
|
|
115
|
+
| `supports` | `{ node: 'fixed' }`, `'pinned'`, or `{ x, y, z, rx, ry, rz }` | Each freedom `true` (held), left out (free), or a spring to ground in N/mm or N·mm/rad |
|
|
116
|
+
| `loads` | `{ node, force, moment }` or `{ element, spread, axes }` | N and N·mm in global axes; a spread load is N per mm of the element's length, in `'global'` axes or the element's `'local'` ones |
|
|
117
|
+
| `gravity` | `[0, 0, -9.81]` | N/kg, the same number as m/s². It acts on every element's mass and every lumped mass |
|
|
118
|
+
| `masses` | `{ node: kg }` | Lumped masses: weight under gravity, inertia in modes |
|
|
119
|
+
|
|
120
|
+
**An element's own axes.** x runs from `a` to `b`. z is the part of `up` square to the element, and `up` is global
|
|
121
|
+
+Z unless the element gives another (for an element along Z it is global +X). y = z × x. `roll`, in degrees, then
|
|
122
|
+
turns y and z about x. `Iy` resists bending that moves the beam along its z, `Iz` along its y. Every element's
|
|
123
|
+
result carries its `axes`, so nothing has to be guessed.
|
|
124
|
+
|
|
125
|
+
**What each solve returns.**
|
|
126
|
+
|
|
127
|
+
- `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
|
+
- `statics({ loads, gravity, masses, samples })`: `displacements` and `reactions` by node, each `[x, y, z, rx, ry,
|
|
131
|
+
rz]` in global axes; `deflection: { most, node }`; and `elements`, each with its `length`, `axes`, the `ends`
|
|
132
|
+
forces its nodes put on it (local axes), `axial` (its mean axial force, tension positive), and `along`: at each
|
|
133
|
+
station `x`, the axial force `N`, shears `Vy` and `Vz`, torque `T`, moments `My` and `Mz`, and the movement `d`
|
|
134
|
+
in global axes. The stations are `samples` evenly spaced (11) plus the points where each moment peaks, so `peak`
|
|
135
|
+
(each quantity's largest value and where) is exact for the loads supported. `stress` is the largest
|
|
136
|
+
`|N|/A + |My|/Wy + |Mz|/Wz` along the element, in MPa, where it is, and the bending part alone. Given other
|
|
137
|
+
loads, it solves another load case on the same factorisation.
|
|
138
|
+
- `buckling({ count })`: `factors`, lowest first, and `modes`, each `{ factor, shape }`: the loads times the factor
|
|
139
|
+
buckle the frame into the shape (by node, largest movement 1). `statics` is the solve it came from. The first
|
|
140
|
+
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 }`.
|
|
142
|
+
- `subdivide(model, pieces)` cuts every element into equal pieces. One element cannot bow between its own ends, so
|
|
143
|
+
buckling and modes want members in pieces: a pinned column's Euler load is 22% out with one element, 0.8% with
|
|
144
|
+
two and 0.05% with four. Statics is exact with one.
|
|
145
|
+
|
|
146
|
+
**Refusals.** What is wrong with a model is said by name before any solve, as an `Error` with a `code`: a node
|
|
147
|
+
that does not exist (`fea.frame.node`), an element of no length (`fea.frame.length`), a section property that is
|
|
148
|
+
not above 0 (`fea.frame.section`), a material (`fea.frame.material`), an `up` along the element
|
|
149
|
+
(`fea.frame.axes`), a joint or support it cannot read (`fea.frame.join`, `fea.frame.support`), a load or mass
|
|
150
|
+
(`fea.frame.load`, `fea.frame.mass`), nothing held (`fea.frame.unheld`), a mechanism (`fea.frame.mechanism`, with
|
|
151
|
+
`loose`: the freedoms nothing resists, by node), and buckling with nothing in compression
|
|
152
|
+
(`fea.frame.compression`). A node that every element end is pinned to has rotations nothing turns: they are held
|
|
153
|
+
still and reported as 0, and a moment put on one is refused.
|
|
154
|
+
|
|
155
|
+
**Units.** mm, N, MPa, rad, N·mm; springs in N/mm and N·mm/rad; masses in kg, densities in g/cm³, gravity in N/kg;
|
|
156
|
+
frequencies in Hz. In the modal solve stiffness is N/mm and mass kg. A newton is a kg·m/s² and lengths are mm, so
|
|
157
|
+
N/mm ÷ kg = 1000 s⁻²: the frequency is `√(1000 λ) / 2π`, with λ the eigenvalue of the stiffness against the mass
|
|
158
|
+
in kg. A test holds this against the textbook formula worked in SI units.
|
|
159
|
+
|
|
160
|
+
**Formulas.** Each bending plane of an element has the freedoms `[v1, θ1, v2, θ2]`, with L its length and ξ = x/L.
|
|
161
|
+
|
|
162
|
+
| What | Formula | Source |
|
|
163
|
+
|---|---|---|
|
|
164
|
+
| Shear parameter | `Φ = 12 E I / (G As L²)`, one for each bending plane; 0 with no shear area, which is Euler-Bernoulli's beam | Przemieniecki, eq. 5.116 |
|
|
165
|
+
| Bending stiffness | `E I / ((1 + Φ) L³) × [[12, 6L, −12, 6L], [6L, (4 + Φ) L², −6L, (2 − Φ) L²], [−12, −6L, 12, −6L], [6L, (2 − Φ) L², −6L, (4 + Φ) L²]]` | Przemieniecki, eq. 5.116 |
|
|
166
|
+
| Stretch and twist | `(E A / L) × [[1, −1], [−1, 1]]` and `(G J / L) × [[1, −1], [−1, 1]]` | Przemieniecki, chapter 5 |
|
|
167
|
+
| Shape functions | Deflection `N = [2ξ³ − 3ξ² − Φξ + 1 + Φ, L (ξ³ − (2 + Φ/2) ξ² + (1 + Φ/2) ξ), −(2ξ³ − 3ξ² − Φξ), L (ξ³ − (1 − Φ/2) ξ² − (Φ/2) ξ)] / (1 + Φ)`; the section's rotation `R = [6 (ξ² − ξ) / L, 3ξ² − (4 + Φ) ξ + 1 + Φ, −6 (ξ² − ξ) / L, 3ξ² − (2 − Φ) ξ] / (1 + Φ)` | Friedman and Kosmatka |
|
|
168
|
+
| Geometric stiffness | `P ∫ N′ᵀ N′ dx` for an axial force P, tension positive. With Φ = 0: `(P / 30 L) × [[36, 3L, −36, 3L], [3L, 4L², −3L, −L²], [−36, −3L, 36, −3L], [3L, −L², −3L, 4L²]]` | McGuire, Gallagher and Ziemian, chapter 9; Cook et al. |
|
|
169
|
+
| Consistent mass | `ρ A ∫ Nᵀ N dx + ρ I ∫ Rᵀ R dx` (the second term is rotary inertia). With Φ = 0 the first is `(ρ A L / 420) × [[156, 22L, 54, −13L], [22L, 4L², 13L, −3L²], [54, 13L, 156, −22L], [−13L, −3L², −22L, 4L²]]`; stretch and twist are `(ρ A L / 6) × [[2, 1], [1, 2]]` and the same with `Iy + Iz` for A | Przemieniecki, chapter 11; Cook et al. |
|
|
170
|
+
| A spread load w | End forces `w L / 2` and end moments `± w L² / 12`; the deflection between the ends adds `w x² (L − x)² / 24 E I + w x (L − x) / 2 G As` | Roark's, table 8.1 |
|
|
171
|
+
| A spring k or a release (k = 0) at an end | With s the sprung rotations: `K − K_s (K_ss + k)⁻¹ K_sᵀ`, and loads `f − K_s (K_ss + k)⁻¹ f_s`. Exact, and nothing is subtracted from a large number however stiff the spring | Static condensation: Cook et al.; member releases and semi-rigid joints: McGuire, Gallagher and Ziemian |
|
|
172
|
+
| Mass and geometric stiffness behind a spring or release | `Tᵀ M T` with `T = I − E_s (K_ss + k)⁻¹ K_sᵀ`: the beam's end follows its nodes as it would at rest | Guyan |
|
|
173
|
+
| Buckling | `(K + λ Kg) φ = 0`, Kg from each element's mean axial force in the static solve | McGuire, Gallagher and Ziemian, chapter 9 |
|
|
174
|
+
| Modes | `K φ = ω² M φ`, frequency `ω / 2π` | Przemieniecki, chapter 12; Bathe, chapter 11 (subspace iteration) |
|
|
175
|
+
| Forces along an element | From the forces F on end a and the spread load w: `N = −(Fx + wx x)`, `Vy = −(Fy + wy x)`, `My = −(My_a + Fz x + wz x² / 2)`, `Mz = −Mz_a + Fy x + wy x² / 2`: the part of the beam beyond x acting on the part before it | Statics |
|
|
176
|
+
| Stress | `abs(N) / A + abs(My) / Wy + abs(Mz) / Wz`, with `Wy = Iy / cz` and `Wz = Iz / cy` | Roark's, chapter 8 |
|
|
177
|
+
|
|
178
|
+
The matrix is stored row by row from each row's first non-zero to its diagonal, with the nodes ordered to keep
|
|
179
|
+
rows short (reverse Cuthill-McKee), and factorised by Cholesky. Buckling and modes use subspace iteration with the
|
|
180
|
+
small problems solved by Jacobi rotations; buckling first brackets its lowest factor between a shift that
|
|
181
|
+
factorises and one that does not, so factors of the loads reversed are never taken for it.
|
|
182
|
+
|
|
183
|
+
**Tested** against closed forms, each within 1%, most to rounding: a cantilever's tip deflection and rotation
|
|
184
|
+
with and without shear; a simply supported and a fixed-fixed beam under a spread load; a portal frame's sway and
|
|
185
|
+
foot moments by slope-deflection; a bar's twist; Euler's load for pinned-pinned and fixed-free columns (0.003% with
|
|
186
|
+
eight elements), and Engesser's with shear; the first frequencies of a cantilever and a simply supported beam
|
|
187
|
+
(0.02% and 0.04%); a heavy tip mass as one mass on a spring; a cantilever on a sprung joint, `P L³ / 3 E I + P L²
|
|
188
|
+
/ k`, a stiff spring against rigid and a soft one against pinned; the same cantilever along every axis and rolled;
|
|
189
|
+
a two-bar truss. Against this package's voxel solver on a cantilever three times as long as deep, the tip agrees
|
|
190
|
+
within 2.7% (the voxels are the stiffer: eight cubes through the depth, and a root clamped over its whole face).
|
|
191
|
+
A braced box of 50 beams (108 unknowns) solves statically in about 3 ms on a laptop.
|
|
192
|
+
|
|
193
|
+
**Limits.**
|
|
194
|
+
|
|
195
|
+
- Linear and small-displacement: stiffness does not change as the frame moves, and buckling is the linear
|
|
196
|
+
(eigenvalue) kind, an upper bound on what a real, imperfect frame carries.
|
|
197
|
+
- Prismatic, straight members joined at their centroids: no tapers, no curved members, no offsets or rigid ends at
|
|
198
|
+
joints.
|
|
199
|
+
- Torsion is St Venant's only: no warping stiffness, so an open thin-walled section twists more here than it
|
|
200
|
+
would. No shear lag.
|
|
201
|
+
- Buckling is by bending under axial force: no torsional or lateral-torsional buckling, and bending moments do not
|
|
202
|
+
enter the geometric stiffness.
|
|
203
|
+
- Joint springs are rotational and linear, at element ends; a joint's play, slip and preload are outside it.
|
|
204
|
+
- Stress is axial plus bending at the extreme corner, right for rectangular sections and extrusions and on the
|
|
205
|
+
safe side for round ones; shear and torsion stresses are left out, as is anything local to a joint or a hole.
|
|
206
|
+
- Loads spread along an element are even along it; a load part-way along needs a node there. No temperature loads
|
|
207
|
+
and no moved supports.
|
|
208
|
+
- Behind a spring or a release, mass and geometric stiffness are reduced as at rest (Guyan's reduction), which
|
|
209
|
+
is why buckling and modes want members cut into pieces.
|
|
210
|
+
|
|
67
211
|
## Sources
|
|
68
212
|
|
|
69
213
|
- Amir, Aage, Lazarov (2014). On multigrid-CG for efficient topology optimization. *Structural and Multidisciplinary
|
|
70
214
|
Optimization* 49, 815–829.
|
|
71
215
|
- Andreassen, Clausen, Schevenels, Lazarov, Sigmund (2011). Efficient topology optimization in MATLAB using 88 lines
|
|
72
216
|
of code. *Structural and Multidisciplinary Optimization* 43, 1–16.
|
|
217
|
+
- Bathe (2014). *Finite Element Procedures*, 2nd ed. K. J. Bathe, Watertown.
|
|
218
|
+
- Blevins (1979). *Formulas for Natural Frequency and Mode Shape*. Van Nostrand Reinhold.
|
|
73
219
|
- Cook, Malkus, Plesha, Witt (2002). *Concepts and Applications of Finite Element Analysis*, 4th ed. Wiley.
|
|
220
|
+
- Cuthill, McKee (1969). Reducing the bandwidth of sparse symmetric matrices. *Proceedings of the 24th National
|
|
221
|
+
Conference of the ACM*, 157–172.
|
|
222
|
+
- Friedman, Kosmatka (1993). An improved two-node Timoshenko beam finite element. *Computers and Structures* 47,
|
|
223
|
+
473–481.
|
|
224
|
+
- Guyan (1965). Reduction of stiffness and mass matrices. *AIAA Journal* 3, 380.
|
|
225
|
+
- McGuire, Gallagher, Ziemian (2000). *Matrix Structural Analysis*, 2nd ed. Wiley.
|
|
226
|
+
- Przemieniecki (1968). *Theory of Matrix Structural Analysis*. McGraw-Hill.
|
|
227
|
+
- Timoshenko, Gere (1961). *Theory of Elastic Stability*, 2nd ed. McGraw-Hill.
|
|
228
|
+
- Young, Budynas (2002). *Roark's Formulas for Stress and Strain*, 7th ed. McGraw-Hill.
|
package/frame.d.mts
ADDED
|
@@ -0,0 +1,367 @@
|
|
|
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 },
|
|
27
|
+
* modes: (o?: { count?: number, masses?: Record<string, number> }) => { frequencies: number[], modes: VibrationMode[] },
|
|
28
|
+
* freedoms: number, nodes: 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.
|
|
32
|
+
*/
|
|
33
|
+
export function frame(model: FrameModel, o?: {
|
|
34
|
+
shear?: boolean;
|
|
35
|
+
}): {
|
|
36
|
+
statics: (o?: {
|
|
37
|
+
loads?: FrameLoad[];
|
|
38
|
+
gravity?: Vec3;
|
|
39
|
+
masses?: Record<string, number>;
|
|
40
|
+
samples?: number;
|
|
41
|
+
}) => StaticResult;
|
|
42
|
+
buckling: (o?: {
|
|
43
|
+
count?: number;
|
|
44
|
+
loads?: FrameLoad[];
|
|
45
|
+
gravity?: Vec3;
|
|
46
|
+
masses?: Record<string, number>;
|
|
47
|
+
}) => {
|
|
48
|
+
factors: number[];
|
|
49
|
+
modes: BucklingMode[];
|
|
50
|
+
statics: StaticResult;
|
|
51
|
+
};
|
|
52
|
+
modes: (o?: {
|
|
53
|
+
count?: number;
|
|
54
|
+
masses?: Record<string, number>;
|
|
55
|
+
}) => {
|
|
56
|
+
frequencies: number[];
|
|
57
|
+
modes: VibrationMode[];
|
|
58
|
+
};
|
|
59
|
+
freedoms: number;
|
|
60
|
+
nodes: string[];
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* The same frame with every element cut into `pieces` equal lengths, for buckling and modes: one element cannot bow
|
|
64
|
+
* 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
|
|
65
|
+
* nodes are named "<element>/<k>" (or added to the end of a list of nodes), new elements "<element>/<k>" with `of`
|
|
66
|
+
* naming the element they came from; end joints stay at the member's own ends, and spread loads follow their pieces.
|
|
67
|
+
* @param {FrameModel} model @param {number} [pieces] 4
|
|
68
|
+
* @returns {FrameModel}
|
|
69
|
+
*/
|
|
70
|
+
export function subdivide(model: FrameModel, pieces?: number): FrameModel;
|
|
71
|
+
export function statics(model: FrameModel, o?: {
|
|
72
|
+
shear?: boolean;
|
|
73
|
+
samples?: number;
|
|
74
|
+
}): StaticResult;
|
|
75
|
+
export function buckling(model: FrameModel, o?: {
|
|
76
|
+
shear?: boolean;
|
|
77
|
+
count?: number;
|
|
78
|
+
}): {
|
|
79
|
+
factors: number[];
|
|
80
|
+
modes: BucklingMode[];
|
|
81
|
+
statics: StaticResult;
|
|
82
|
+
};
|
|
83
|
+
export function modes(model: FrameModel, o?: {
|
|
84
|
+
shear?: boolean;
|
|
85
|
+
count?: number;
|
|
86
|
+
}): {
|
|
87
|
+
frequencies: number[];
|
|
88
|
+
modes: VibrationMode[];
|
|
89
|
+
};
|
|
90
|
+
export type Vec3 = [number, number, number];
|
|
91
|
+
/**
|
|
92
|
+
* A beam's cross-section, in its local axes
|
|
93
|
+
*/
|
|
94
|
+
export type FrameSection = {
|
|
95
|
+
/**
|
|
96
|
+
* area, mm²
|
|
97
|
+
*/
|
|
98
|
+
A: number;
|
|
99
|
+
/**
|
|
100
|
+
* second moment about local y, mm⁴ (bending that moves the beam along local z)
|
|
101
|
+
*/
|
|
102
|
+
Iy: number;
|
|
103
|
+
/**
|
|
104
|
+
* second moment about local z, mm⁴ (bending that moves the beam along local y)
|
|
105
|
+
*/
|
|
106
|
+
Iz: number;
|
|
107
|
+
/**
|
|
108
|
+
* torsion constant, mm⁴
|
|
109
|
+
*/
|
|
110
|
+
J: number;
|
|
111
|
+
/**
|
|
112
|
+
* shear area for shear along local y, mm² (left out: no shear deformation that way)
|
|
113
|
+
*/
|
|
114
|
+
Asy?: number;
|
|
115
|
+
/**
|
|
116
|
+
* shear area for shear along local z, mm²
|
|
117
|
+
*/
|
|
118
|
+
Asz?: number;
|
|
119
|
+
/**
|
|
120
|
+
* distance from the centroid to the furthest fibre along local y, mm (for stress)
|
|
121
|
+
*/
|
|
122
|
+
cy?: number;
|
|
123
|
+
/**
|
|
124
|
+
* distance to the furthest fibre along local z, mm
|
|
125
|
+
*/
|
|
126
|
+
cz?: number;
|
|
127
|
+
/**
|
|
128
|
+
* section modulus for bending about y, mm³ (Iy / cz, if cz is not given)
|
|
129
|
+
*/
|
|
130
|
+
Wy?: number;
|
|
131
|
+
/**
|
|
132
|
+
* section modulus for bending about z, mm³ (Iz / cy)
|
|
133
|
+
*/
|
|
134
|
+
Wz?: number;
|
|
135
|
+
};
|
|
136
|
+
export type FrameMaterial = {
|
|
137
|
+
/**
|
|
138
|
+
* Young's modulus, MPa
|
|
139
|
+
*/
|
|
140
|
+
E: number;
|
|
141
|
+
/**
|
|
142
|
+
* shear modulus, MPa (or give nu)
|
|
143
|
+
*/
|
|
144
|
+
G?: number;
|
|
145
|
+
/**
|
|
146
|
+
* Poisson's ratio, for G = E / 2(1 + nu)
|
|
147
|
+
*/
|
|
148
|
+
nu?: number;
|
|
149
|
+
/**
|
|
150
|
+
* g/cm³ (for gravity and modes; left out: weightless)
|
|
151
|
+
*/
|
|
152
|
+
density?: number;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* 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
|
|
156
|
+
*/
|
|
157
|
+
export type Fixity = "rigid" | "free" | number;
|
|
158
|
+
/**
|
|
159
|
+
* 'pinned' frees both bending rotations (ry, rz) and carries twist; 'ball' frees all three; or say each, about the element's local axes
|
|
160
|
+
*/
|
|
161
|
+
export type EndJoin = "rigid" | "pinned" | "ball" | {
|
|
162
|
+
rx?: Fixity;
|
|
163
|
+
ry?: Fixity;
|
|
164
|
+
rz?: Fixity;
|
|
165
|
+
};
|
|
166
|
+
export type FrameElement = {
|
|
167
|
+
/**
|
|
168
|
+
* its name in the results (its place in the list if left out)
|
|
169
|
+
*/
|
|
170
|
+
id?: string | number;
|
|
171
|
+
/**
|
|
172
|
+
* the node it starts at
|
|
173
|
+
*/
|
|
174
|
+
a: string | number;
|
|
175
|
+
/**
|
|
176
|
+
* the node it ends at
|
|
177
|
+
*/
|
|
178
|
+
b: string | number;
|
|
179
|
+
/**
|
|
180
|
+
* the section, or its name in the model's `sections`
|
|
181
|
+
*/
|
|
182
|
+
section: FrameSection | string;
|
|
183
|
+
/**
|
|
184
|
+
* the material, or its name in the model's `materials`
|
|
185
|
+
*/
|
|
186
|
+
material: FrameMaterial | string;
|
|
187
|
+
/**
|
|
188
|
+
* degrees about its own axis, turning local y towards local z
|
|
189
|
+
*/
|
|
190
|
+
roll?: number;
|
|
191
|
+
/**
|
|
192
|
+
* the direction local z leans towards (global +Z, or +X for an element along Z)
|
|
193
|
+
*/
|
|
194
|
+
up?: Vec3;
|
|
195
|
+
/**
|
|
196
|
+
* how each end is joined to its node ('rigid' if left out)
|
|
197
|
+
*/
|
|
198
|
+
ends?: {
|
|
199
|
+
a?: EndJoin;
|
|
200
|
+
b?: EndJoin;
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* the member this is a piece of (set by `subdivide`, handed back in the results)
|
|
204
|
+
*/
|
|
205
|
+
of?: string | number;
|
|
206
|
+
};
|
|
207
|
+
/**
|
|
208
|
+
* one freedom of a support: held (true), free, or a spring to ground of that many N/mm (movements) or N·mm/rad (rotations)
|
|
209
|
+
*/
|
|
210
|
+
export type Hold = boolean | number | "fixed" | "free";
|
|
211
|
+
/**
|
|
212
|
+
* 'fixed' holds all six freedoms, 'pinned' the three movements
|
|
213
|
+
*/
|
|
214
|
+
export type FrameSupport = "fixed" | "pinned" | {
|
|
215
|
+
x?: Hold;
|
|
216
|
+
y?: Hold;
|
|
217
|
+
z?: Hold;
|
|
218
|
+
rx?: Hold;
|
|
219
|
+
ry?: Hold;
|
|
220
|
+
rz?: Hold;
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* 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
|
|
224
|
+
*/
|
|
225
|
+
export type FrameLoad = {
|
|
226
|
+
node: string | number;
|
|
227
|
+
force?: Vec3;
|
|
228
|
+
moment?: Vec3;
|
|
229
|
+
} | {
|
|
230
|
+
element: string | number;
|
|
231
|
+
spread: Vec3;
|
|
232
|
+
axes?: "global" | "local";
|
|
233
|
+
};
|
|
234
|
+
export type FrameModel = {
|
|
235
|
+
/**
|
|
236
|
+
* each node's position in mm, by name (or a list, named by place: 0, 1, ...)
|
|
237
|
+
*/
|
|
238
|
+
nodes: Record<string, Vec3> | Vec3[];
|
|
239
|
+
elements: FrameElement[];
|
|
240
|
+
/**
|
|
241
|
+
* sections by name
|
|
242
|
+
*/
|
|
243
|
+
sections?: Record<string, FrameSection>;
|
|
244
|
+
/**
|
|
245
|
+
* materials by name
|
|
246
|
+
*/
|
|
247
|
+
materials?: Record<string, FrameMaterial>;
|
|
248
|
+
/**
|
|
249
|
+
* by node
|
|
250
|
+
*/
|
|
251
|
+
supports: Record<string, FrameSupport>;
|
|
252
|
+
loads?: FrameLoad[];
|
|
253
|
+
/**
|
|
254
|
+
* N/kg (m/s²), acting on every element's mass and every lumped mass: [0, 0, -9.81]
|
|
255
|
+
*/
|
|
256
|
+
gravity?: Vec3;
|
|
257
|
+
/**
|
|
258
|
+
* lumped masses by node, kg (weight under gravity, and inertia in modes)
|
|
259
|
+
*/
|
|
260
|
+
masses?: Record<string, number>;
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* x, y, z, then about x, y, z
|
|
264
|
+
*/
|
|
265
|
+
export type Six = [number, number, number, number, number, number];
|
|
266
|
+
export type ElementResult = {
|
|
267
|
+
id: string | number;
|
|
268
|
+
/**
|
|
269
|
+
* the member it is a piece of, when the model came from `subdivide`
|
|
270
|
+
*/
|
|
271
|
+
of?: string | number;
|
|
272
|
+
/**
|
|
273
|
+
* mm
|
|
274
|
+
*/
|
|
275
|
+
length: number;
|
|
276
|
+
/**
|
|
277
|
+
* its local x, y and z in global axes
|
|
278
|
+
*/
|
|
279
|
+
axes: [Vec3, Vec3, Vec3];
|
|
280
|
+
/**
|
|
281
|
+
* the forces (N) and moments (N·mm) its nodes put on each end, in local axes
|
|
282
|
+
*/
|
|
283
|
+
ends: {
|
|
284
|
+
a: Six;
|
|
285
|
+
b: Six;
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* at each station x (mm from a): axial force (tension positive), shear along local y and z, torque, bending moments
|
|
289
|
+
* 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
|
|
290
|
+
* forces), and the movement there in global axes (mm). The stations are evenly spaced, plus where each moment peaks.
|
|
291
|
+
*/
|
|
292
|
+
along: {
|
|
293
|
+
x: number[];
|
|
294
|
+
N: number[];
|
|
295
|
+
Vy: number[];
|
|
296
|
+
Vz: number[];
|
|
297
|
+
T: number[];
|
|
298
|
+
My: number[];
|
|
299
|
+
Mz: number[];
|
|
300
|
+
d: Vec3[];
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* each one's largest value by size, signed, and where
|
|
304
|
+
*/
|
|
305
|
+
peak: {
|
|
306
|
+
N: Peak;
|
|
307
|
+
Vy: Peak;
|
|
308
|
+
Vz: Peak;
|
|
309
|
+
T: Peak;
|
|
310
|
+
My: Peak;
|
|
311
|
+
Mz: Peak;
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* the mean axial force, N (tension positive): what buckling reads
|
|
315
|
+
*/
|
|
316
|
+
axial: number;
|
|
317
|
+
/**
|
|
318
|
+
* MPa, when the section has cy and cz (or
|
|
319
|
+
* Wy and Wz): the largest |N|/A + |My|/Wy + |Mz|/Wz along the element and where; the largest bending part alone;
|
|
320
|
+
* and N/A at the peak
|
|
321
|
+
*/
|
|
322
|
+
stress?: {
|
|
323
|
+
peak: number;
|
|
324
|
+
bending: number;
|
|
325
|
+
axial: number;
|
|
326
|
+
x: number;
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
export type Peak = {
|
|
330
|
+
value: number;
|
|
331
|
+
x: number;
|
|
332
|
+
};
|
|
333
|
+
export type StaticResult = {
|
|
334
|
+
/**
|
|
335
|
+
* each node's movement (mm) and rotation (rad), in global axes
|
|
336
|
+
*/
|
|
337
|
+
displacements: Record<string, Six>;
|
|
338
|
+
/**
|
|
339
|
+
* at each supported node: the force (N) and moment (N·mm) its support gives the frame
|
|
340
|
+
*/
|
|
341
|
+
reactions: Record<string, Six>;
|
|
342
|
+
/**
|
|
343
|
+
* in the model's order
|
|
344
|
+
*/
|
|
345
|
+
elements: ElementResult[];
|
|
346
|
+
/**
|
|
347
|
+
* the largest movement of any node, and which
|
|
348
|
+
*/
|
|
349
|
+
deflection: {
|
|
350
|
+
most: number;
|
|
351
|
+
node: string;
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
/**
|
|
355
|
+
* the loads times `factor` buckle the frame into `shape` (largest movement 1)
|
|
356
|
+
*/
|
|
357
|
+
export type BucklingMode = {
|
|
358
|
+
factor: number;
|
|
359
|
+
shape: Record<string, Six>;
|
|
360
|
+
};
|
|
361
|
+
/**
|
|
362
|
+
* Hz, and the shape (largest movement 1)
|
|
363
|
+
*/
|
|
364
|
+
export type VibrationMode = {
|
|
365
|
+
frequency: number;
|
|
366
|
+
shape: Record<string, Six>;
|
|
367
|
+
};
|
package/frame.mjs
ADDED
|
@@ -0,0 +1,660 @@
|
|
|
1
|
+
// Frames of beams joined at nodes: how far a frame moves under load, what each beam carries, the load at which it
|
|
2
|
+
// buckles and the frequencies it rings at. Three-dimensional beam elements with six freedoms a node (three movements,
|
|
3
|
+
// three rotations) and shear deformation (Timoshenko's beam, which becomes Euler-Bernoulli's when shear is stiff).
|
|
4
|
+
// Plain numbers in typed arrays, no dependencies: it runs in browsers and Node alike.
|
|
5
|
+
//
|
|
6
|
+
// Units: millimetres, newtons, MPa (N/mm²), radians for rotations, N·mm for moments, N/mm and N·mm/rad for springs.
|
|
7
|
+
// Masses are in kg, densities in g/cm³ (as the kit's material rule sets give them) and gravity in N/kg (the same
|
|
8
|
+
// number as m/s²: [0, 0, -9.81]), so a mass times gravity is newtons with no factor. In the modal solve stiffness is
|
|
9
|
+
// N/mm and mass kg, and N/mm ÷ kg = 1000 s⁻² (a newton is a kg·m/s² and the lengths are mm), so the angular
|
|
10
|
+
// frequency squared is 1000 times the eigenvalue of K against M in kg: frequency = √(1000 λ) / 2π, in Hz.
|
|
11
|
+
//
|
|
12
|
+
// An element's local axes: x runs from its node `a` to its node `b`; z is the part of `up` square to x (`up` is
|
|
13
|
+
// global +Z, or global +X for an element along Z, unless the element gives one); y = z × x. `roll` then turns y and z
|
|
14
|
+
// about x, right-handed, in degrees. Iy is the second moment about local y (it resists bending that moves the beam
|
|
15
|
+
// along z) and Iz about local z.
|
|
16
|
+
//
|
|
17
|
+
// Matrices (sources in the README): the stiffness with the shear parameter Φ = 12 E I / (G As L²) is
|
|
18
|
+
// Przemieniecki's (1968, eq. 5.116); the geometric stiffness and the consistent mass are integrals of the same
|
|
19
|
+
// element's shape functions (Friedman and Kosmatka 1993), which for Φ = 0 are the familiar 6/5, L/10, 2L²/15 and
|
|
20
|
+
// 156, 22L, 4L² tables. An end's rotational spring or release is condensed out of the element, K − K_s (K_ss + k)⁻¹
|
|
21
|
+
// K_sᵀ, which is exact for the stiffness and the loads; the mass and geometric stiffness are carried through the same
|
|
22
|
+
// reduction (Guyan's), so buckling and modes want each member cut into several elements (`subdivide`).
|
|
23
|
+
|
|
24
|
+
/** @typedef {[number, number, number]} Vec3 */
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {object} FrameSection A beam's cross-section, in its local axes
|
|
27
|
+
* @property {number} A area, mm²
|
|
28
|
+
* @property {number} Iy second moment about local y, mm⁴ (bending that moves the beam along local z)
|
|
29
|
+
* @property {number} Iz second moment about local z, mm⁴ (bending that moves the beam along local y)
|
|
30
|
+
* @property {number} J torsion constant, mm⁴
|
|
31
|
+
* @property {number} [Asy] shear area for shear along local y, mm² (left out: no shear deformation that way)
|
|
32
|
+
* @property {number} [Asz] shear area for shear along local z, mm²
|
|
33
|
+
* @property {number} [cy] distance from the centroid to the furthest fibre along local y, mm (for stress)
|
|
34
|
+
* @property {number} [cz] distance to the furthest fibre along local z, mm
|
|
35
|
+
* @property {number} [Wy] section modulus for bending about y, mm³ (Iy / cz, if cz is not given)
|
|
36
|
+
* @property {number} [Wz] section modulus for bending about z, mm³ (Iz / cy)
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* @typedef {object} FrameMaterial
|
|
40
|
+
* @property {number} E Young's modulus, MPa
|
|
41
|
+
* @property {number} [G] shear modulus, MPa (or give nu)
|
|
42
|
+
* @property {number} [nu] Poisson's ratio, for G = E / 2(1 + nu)
|
|
43
|
+
* @property {number} [density] g/cm³ (for gravity and modes; left out: weightless)
|
|
44
|
+
*/
|
|
45
|
+
/** @typedef {'rigid' | 'free' | number} Fixity 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 */
|
|
46
|
+
/** @typedef {'rigid' | 'pinned' | 'ball' | { rx?: Fixity, ry?: Fixity, rz?: Fixity }} EndJoin 'pinned' frees both bending rotations (ry, rz) and carries twist; 'ball' frees all three; or say each, about the element's local axes */
|
|
47
|
+
/**
|
|
48
|
+
* @typedef {object} FrameElement
|
|
49
|
+
* @property {string | number} [id] its name in the results (its place in the list if left out)
|
|
50
|
+
* @property {string | number} a the node it starts at
|
|
51
|
+
* @property {string | number} b the node it ends at
|
|
52
|
+
* @property {FrameSection | string} section the section, or its name in the model's `sections`
|
|
53
|
+
* @property {FrameMaterial | string} material the material, or its name in the model's `materials`
|
|
54
|
+
* @property {number} [roll] degrees about its own axis, turning local y towards local z
|
|
55
|
+
* @property {Vec3} [up] the direction local z leans towards (global +Z, or +X for an element along Z)
|
|
56
|
+
* @property {{ a?: EndJoin, b?: EndJoin }} [ends] how each end is joined to its node ('rigid' if left out)
|
|
57
|
+
* @property {string | number} [of] the member this is a piece of (set by `subdivide`, handed back in the results)
|
|
58
|
+
*/
|
|
59
|
+
/** @typedef {boolean | number | 'fixed' | 'free'} Hold one freedom of a support: held (true), free, or a spring to ground of that many N/mm (movements) or N·mm/rad (rotations) */
|
|
60
|
+
/** @typedef {'fixed' | 'pinned' | { x?: Hold, y?: Hold, z?: Hold, rx?: Hold, ry?: Hold, rz?: Hold }} FrameSupport 'fixed' holds all six freedoms, 'pinned' the three movements */
|
|
61
|
+
/** @typedef {{ node: string | number, force?: Vec3, moment?: Vec3 } | { element: string | number, spread: Vec3, axes?: 'global' | 'local' }} FrameLoad 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 */
|
|
62
|
+
/**
|
|
63
|
+
* @typedef {object} FrameModel
|
|
64
|
+
* @property {Record<string, Vec3> | Vec3[]} nodes each node's position in mm, by name (or a list, named by place: 0, 1, ...)
|
|
65
|
+
* @property {FrameElement[]} elements
|
|
66
|
+
* @property {Record<string, FrameSection>} [sections] sections by name
|
|
67
|
+
* @property {Record<string, FrameMaterial>} [materials] materials by name
|
|
68
|
+
* @property {Record<string, FrameSupport>} supports by node
|
|
69
|
+
* @property {FrameLoad[]} [loads]
|
|
70
|
+
* @property {Vec3} [gravity] N/kg (m/s²), acting on every element's mass and every lumped mass: [0, 0, -9.81]
|
|
71
|
+
* @property {Record<string, number>} [masses] lumped masses by node, kg (weight under gravity, and inertia in modes)
|
|
72
|
+
*/
|
|
73
|
+
/** @typedef {[number, number, number, number, number, number]} Six x, y, z, then about x, y, z */
|
|
74
|
+
/**
|
|
75
|
+
* @typedef {object} ElementResult
|
|
76
|
+
* @property {string | number} id
|
|
77
|
+
* @property {string | number} [of] the member it is a piece of, when the model came from `subdivide`
|
|
78
|
+
* @property {number} length mm
|
|
79
|
+
* @property {[Vec3, Vec3, Vec3]} axes its local x, y and z in global axes
|
|
80
|
+
* @property {{ a: Six, b: Six }} ends the forces (N) and moments (N·mm) its nodes put on each end, in local axes
|
|
81
|
+
* @property {{ x: number[], N: number[], Vy: number[], Vz: number[], T: number[], My: number[], Mz: number[], d: Vec3[] }} along
|
|
82
|
+
* at each station x (mm from a): axial force (tension positive), shear along local y and z, torque, bending moments
|
|
83
|
+
* 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
|
|
84
|
+
* forces), and the movement there in global axes (mm). The stations are evenly spaced, plus where each moment peaks.
|
|
85
|
+
* @property {{ N: Peak, Vy: Peak, Vz: Peak, T: Peak, My: Peak, Mz: Peak }} peak each one's largest value by size, signed, and where
|
|
86
|
+
* @property {number} axial the mean axial force, N (tension positive): what buckling reads
|
|
87
|
+
* @property {{ peak: number, bending: number, axial: number, x: number }} [stress] MPa, when the section has cy and cz (or
|
|
88
|
+
* Wy and Wz): the largest |N|/A + |My|/Wy + |Mz|/Wz along the element and where; the largest bending part alone;
|
|
89
|
+
* and N/A at the peak
|
|
90
|
+
*/
|
|
91
|
+
/** @typedef {{ value: number, x: number }} Peak */
|
|
92
|
+
/**
|
|
93
|
+
* @typedef {object} StaticResult
|
|
94
|
+
* @property {Record<string, Six>} displacements each node's movement (mm) and rotation (rad), in global axes
|
|
95
|
+
* @property {Record<string, Six>} reactions at each supported node: the force (N) and moment (N·mm) its support gives the frame
|
|
96
|
+
* @property {ElementResult[]} elements in the model's order
|
|
97
|
+
* @property {{ most: number, node: string }} deflection the largest movement of any node, and which
|
|
98
|
+
*/
|
|
99
|
+
/** @typedef {{ factor: number, shape: Record<string, Six> }} BucklingMode the loads times `factor` buckle the frame into `shape` (largest movement 1) */
|
|
100
|
+
/** @typedef {{ frequency: number, shape: Record<string, Six> }} VibrationMode Hz, and the shape (largest movement 1) */
|
|
101
|
+
|
|
102
|
+
const FREEDOMS = ['x', 'y', 'z', 'rx', 'ry', 'rz'];
|
|
103
|
+
/** @returns {never} */
|
|
104
|
+
const refuse = (code, text, more) => { throw Object.assign(new Error(text), { code: `fea.frame.${code}`, ...more }); };
|
|
105
|
+
const isVec3 = (v) => (Array.isArray(v) || ArrayBuffer.isView(v)) && v.length === 3 && Number.isFinite(v[0]) && Number.isFinite(v[1]) && Number.isFinite(v[2]);
|
|
106
|
+
const said = (v) => (typeof v === 'string' ? `"${v}"` : JSON.stringify(v) ?? String(v));
|
|
107
|
+
|
|
108
|
+
// ---- one element, in its own axes: [u, v, w, θx, θy, θz] at a, then the same at b ----
|
|
109
|
+
|
|
110
|
+
// 4-point Gauss on 0..1: exact to degree 7 (the mass matrix's integrand is degree 6)
|
|
111
|
+
const GAUSS = [[0.5 - 0.4305681557970263, 0.1739274225687269], [0.5 - 0.16999052179242816, 0.3260725774312731], [0.5 + 0.16999052179242816, 0.3260725774312731], [0.5 + 0.4305681557970263, 0.1739274225687269]];
|
|
112
|
+
const XY = [1, 5, 7, 11], XZ = [2, 4, 8, 10], FLIP = [1, -1, 1, -1]; // bending in the x-y plane (v, θz) and in x-z (w, θy = −dw/dx: its rotations change sign)
|
|
113
|
+
|
|
114
|
+
// The Timoshenko element's shape functions in one bending plane at ξ = x / L, for [v1, θ1, v2, θ2]: the deflection N,
|
|
115
|
+
// and with `all` its slope D and the section's rotation R (Friedman and Kosmatka 1993). Φ = 0 gives the Hermite cubics.
|
|
116
|
+
function shape(xi, L, phi, all) {
|
|
117
|
+
const f = 1 / (1 + phi), x2 = xi * xi, x3 = x2 * xi;
|
|
118
|
+
const N = [f * (2 * x3 - 3 * x2 - phi * xi + 1 + phi), f * L * (x3 - (2 + phi / 2) * x2 + (1 + phi / 2) * xi), -f * (2 * x3 - 3 * x2 - phi * xi), f * L * (x3 - (1 - phi / 2) * x2 - (phi / 2) * xi)];
|
|
119
|
+
if (!all) return { N };
|
|
120
|
+
const D = [f * (6 * x2 - 6 * xi - phi) / L, f * (3 * x2 - (4 + phi) * xi + 1 + phi / 2), -f * (6 * x2 - 6 * xi - phi) / L, f * (3 * x2 - (2 - phi) * xi - phi / 2)];
|
|
121
|
+
const R = [f * 6 * (x2 - xi) / L, f * (3 * x2 - (4 + phi) * xi + 1 + phi), -f * 6 * (x2 - xi) / L, f * (3 * x2 - (2 - phi) * xi)];
|
|
122
|
+
return { N, D, R };
|
|
123
|
+
}
|
|
124
|
+
// ∫ DᵀD (geometric stiffness for a tension of 1), ∫ NᵀN (mass, for 1 a length) and ∫ RᵀR (rotary inertia), each 4 × 4
|
|
125
|
+
function planeForms(L, phi) {
|
|
126
|
+
const g = new Float64Array(16), m = new Float64Array(16), r = new Float64Array(16);
|
|
127
|
+
for (const [xi, wt] of GAUSS) {
|
|
128
|
+
const { N, D, R } = shape(xi, L, phi, true), w = wt * L;
|
|
129
|
+
for (let i = 0; i < 4; i++) for (let j = 0; j < 4; j++) { g[4 * i + j] += w * D[i] * D[j]; m[4 * i + j] += w * N[i] * N[j]; r[4 * i + j] += w * R[i] * R[j]; }
|
|
130
|
+
}
|
|
131
|
+
return { g, m, r };
|
|
132
|
+
}
|
|
133
|
+
// One bending plane's stiffness for [v1, θ1, v2, θ2]: Przemieniecki (1968) eq. 5.116
|
|
134
|
+
function planeStiffness(EI, L, phi) {
|
|
135
|
+
const c = EI / ((1 + phi) * L ** 3), a = 12 * c, b = 6 * L * c, d = (4 + phi) * L * L * c, e = (2 - phi) * L * L * c;
|
|
136
|
+
return [a, b, -a, b, b, d, -b, e, -a, -b, a, -b, b, e, -b, d];
|
|
137
|
+
}
|
|
138
|
+
const put = (K, m4, idx, flip, scale) => { for (let i = 0; i < 4; i++) for (let j = 0; j < 4; j++) K[idx[i] * 12 + idx[j]] += scale * m4[4 * i + j] * (flip ? FLIP[i] * FLIP[j] : 1); };
|
|
139
|
+
const bar = (K, i, j, s, t = -s) => { K[i * 12 + i] += s; K[j * 12 + j] += s; K[i * 12 + j] += t; K[j * 12 + i] += t; };
|
|
140
|
+
const shearModulus = (material) => material.G ?? material.E / (2 * (1 + material.nu));
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 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
|
|
144
|
+
* start then its end. `k` is its stiffness (N/mm, N, N·mm), `kg` its geometric stiffness for a tension of 1 N, and
|
|
145
|
+
* `m` its consistent mass in kg (kg·mm for the cross terms, kg·mm² for rotations), with rotary inertia.
|
|
146
|
+
* @param {FrameSection} section @param {FrameMaterial} material @param {number} L length, mm
|
|
147
|
+
* @param {{ shear?: boolean }} [o] shear: false ignores the shear areas (Euler-Bernoulli)
|
|
148
|
+
* @returns {{ k: Float64Array, kg: Float64Array, m: Float64Array, phi: [number, number] }} phi: the shear parameters
|
|
149
|
+
* 12 E Iz / (G Asy L²) and 12 E Iy / (G Asz L²)
|
|
150
|
+
*/
|
|
151
|
+
export function elementMatrices(section, material, L, { shear = true } = {}) {
|
|
152
|
+
const { A, Iy, Iz, J } = section, { E } = material, G = shearModulus(material), rho = (material.density || 0) * 1e-6; // kg/mm³
|
|
153
|
+
const phiY = shear && section.Asy ? (12 * E * Iz) / (G * section.Asy * L * L) : 0, phiZ = shear && section.Asz ? (12 * E * Iy) / (G * section.Asz * L * L) : 0;
|
|
154
|
+
const k = new Float64Array(144), kg = new Float64Array(144), m = new Float64Array(144), fy = planeForms(L, phiY), fz = planeForms(L, phiZ);
|
|
155
|
+
bar(k, 0, 6, (E * A) / L); bar(k, 3, 9, (G * J) / L);
|
|
156
|
+
put(k, planeStiffness(E * Iz, L, phiY), XY, false, 1); put(k, planeStiffness(E * Iy, L, phiZ), XZ, true, 1);
|
|
157
|
+
put(kg, fy.g, XY, false, 1); put(kg, fz.g, XZ, true, 1);
|
|
158
|
+
bar(m, 0, 6, (rho * A * L) / 3, (rho * A * L) / 6); bar(m, 3, 9, (rho * (Iy + Iz) * L) / 3, (rho * (Iy + Iz) * L) / 6);
|
|
159
|
+
put(m, fy.m, XY, false, rho * A); put(m, fy.r, XY, false, rho * Iz); put(m, fz.m, XZ, true, rho * A); put(m, fz.r, XZ, true, rho * Iy);
|
|
160
|
+
return { k, kg, m, phi: [phiY, phiZ] };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// The inverse of a small matrix (n ≤ 6) by Gauss-Jordan with pivoting; null if it has none
|
|
164
|
+
function invert(A, n) {
|
|
165
|
+
const a = Float64Array.from(A), inv = new Float64Array(n * n);
|
|
166
|
+
let big = 0;
|
|
167
|
+
for (let i = 0; i < n; i++) { inv[i * n + i] = 1; big = Math.max(big, Math.abs(a[i * n + i])); }
|
|
168
|
+
for (let c = 0; c < n; c++) {
|
|
169
|
+
let p = c;
|
|
170
|
+
for (let r = c + 1; r < n; r++) if (Math.abs(a[r * n + c]) > Math.abs(a[p * n + c])) p = r;
|
|
171
|
+
if (!(Math.abs(a[p * n + c]) > 1e-12 * big)) return null;
|
|
172
|
+
if (p !== c) for (let j = 0; j < n; j++) { let t = a[c * n + j]; a[c * n + j] = a[p * n + j]; a[p * n + j] = t; t = inv[c * n + j]; inv[c * n + j] = inv[p * n + j]; inv[p * n + j] = t; }
|
|
173
|
+
const d = a[c * n + c];
|
|
174
|
+
for (let j = 0; j < n; j++) { a[c * n + j] /= d; inv[c * n + j] /= d; }
|
|
175
|
+
for (let r = 0; r < n; r++) if (r !== c) { const f = a[r * n + c]; if (f) for (let j = 0; j < n; j++) { a[r * n + j] -= f * a[c * n + j]; inv[r * n + j] -= f * inv[c * n + j]; } }
|
|
176
|
+
}
|
|
177
|
+
return inv;
|
|
178
|
+
}
|
|
179
|
+
const mul12 = (A, B) => { const C = new Float64Array(144); for (let i = 0; i < 12; i++) for (let k = 0; k < 12; k++) { const a = A[i * 12 + k]; if (a) for (let j = 0; j < 12; j++) C[i * 12 + j] += a * B[k * 12 + j]; } return C; };
|
|
180
|
+
const transpose12 = (A) => { const C = new Float64Array(144); for (let i = 0; i < 12; i++) for (let j = 0; j < 12; j++) C[j * 12 + i] = A[i * 12 + j]; return C; };
|
|
181
|
+
const symmetric12 = (A) => { for (let i = 0; i < 12; i++) for (let j = 0; j < i; j++) A[i * 12 + j] = A[j * 12 + i] = (A[i * 12 + j] + A[j * 12 + i]) / 2; return A; };
|
|
182
|
+
|
|
183
|
+
// Springs and releases at an element's ends, condensed out. `springs` has a stiffness for each of the 12 freedoms:
|
|
184
|
+
// Infinity where the end is rigid, 0 where it is released. With s the sprung freedoms and H = (K_ss + k)⁻¹, the
|
|
185
|
+
// beam's own end freedoms follow its nodes' as d_beam = T d + H f_s, with T = I − E_s H K[s, :], and the condensed
|
|
186
|
+
// stiffness is K T = K − K_s H K_sᵀ: nothing is subtracted from a large number however stiff the spring.
|
|
187
|
+
function condense({ k, kg, m }, springs) {
|
|
188
|
+
const s = [];
|
|
189
|
+
for (let i = 0; i < 12; i++) if (springs[i] !== Infinity) s.push(i);
|
|
190
|
+
if (!s.length) return { k, kg, m, T: null, H: null, s };
|
|
191
|
+
const n = s.length, A = new Float64Array(n * n);
|
|
192
|
+
for (let p = 0; p < n; p++) for (let q = 0; q < n; q++) A[p * n + q] = k[s[p] * 12 + s[q]] + (p === q ? springs[s[p]] : 0);
|
|
193
|
+
const H = invert(A, n);
|
|
194
|
+
if (!H) return null;
|
|
195
|
+
const T = new Float64Array(144);
|
|
196
|
+
for (let i = 0; i < 12; i++) T[i * 13] = 1;
|
|
197
|
+
for (let p = 0; p < n; p++) for (let j = 0; j < 12; j++) { let sum = 0; for (let q = 0; q < n; q++) sum += H[p * n + q] * k[s[q] * 12 + j]; T[s[p] * 12 + j] -= sum; }
|
|
198
|
+
const Tt = transpose12(T);
|
|
199
|
+
return { k: symmetric12(mul12(k, T)), kg: symmetric12(mul12(Tt, mul12(kg, T))), m: symmetric12(mul12(Tt, mul12(m, T))), T, H, s };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Λᵀ K Λ: a 12 × 12 matrix from local to global axes, R's rows being the local axes
|
|
203
|
+
function toGlobal(K, R) {
|
|
204
|
+
const t = new Float64Array(144), out = new Float64Array(144);
|
|
205
|
+
for (let i = 0; i < 12; i++) for (let q = 0; q < 12; q += 3) for (let c = 0; c < 3; c++) t[i * 12 + q + c] = K[i * 12 + q] * R[c] + K[i * 12 + q + 1] * R[3 + c] + K[i * 12 + q + 2] * R[6 + c];
|
|
206
|
+
for (let p = 0; p < 12; p += 3) for (let r = 0; r < 3; r++) for (let j = 0; j < 12; j++) out[(p + r) * 12 + j] = R[r] * t[p * 12 + j] + R[3 + r] * t[(p + 1) * 12 + j] + R[6 + r] * t[(p + 2) * 12 + j];
|
|
207
|
+
return out;
|
|
208
|
+
}
|
|
209
|
+
const toLocal3 = (R, v, o = 0) => [R[0] * v[o] + R[1] * v[o + 1] + R[2] * v[o + 2], R[3] * v[o] + R[4] * v[o + 1] + R[5] * v[o + 2], R[6] * v[o] + R[7] * v[o + 1] + R[8] * v[o + 2]];
|
|
210
|
+
const toGlobal3 = (R, v, o = 0) => [R[0] * v[o] + R[3] * v[o + 1] + R[6] * v[o + 2], R[1] * v[o] + R[4] * v[o + 1] + R[7] * v[o + 2], R[2] * v[o] + R[5] * v[o + 1] + R[8] * v[o + 2]];
|
|
211
|
+
|
|
212
|
+
// ---- the frame's matrix: symmetric, each row kept from its first non-zero column to the diagonal ----
|
|
213
|
+
|
|
214
|
+
// Nodes in an order that keeps joined nodes close (reverse Cuthill-McKee), so rows are short
|
|
215
|
+
function ordering(n, pairs) {
|
|
216
|
+
const adj = Array.from({ length: n }, () => []);
|
|
217
|
+
for (const [a, b] of pairs) { adj[a].push(b); adj[b].push(a); }
|
|
218
|
+
const seen = new Uint8Array(n), out = [];
|
|
219
|
+
const sweep = (start, mark) => { const q = [start]; mark[start] = 1; for (let h = 0; h < q.length; h++) for (const m of adj[q[h]].filter((v) => !mark[v]).sort((a, b) => adj[a].length - adj[b].length)) { mark[m] = 1; q.push(m); } return q; };
|
|
220
|
+
for (const s of [...adj.keys()].sort((a, b) => adj[a].length - adj[b].length)) {
|
|
221
|
+
if (seen[s]) continue;
|
|
222
|
+
const far = sweep(s, new Uint8Array(n)).at(-1); // start from an end of the frame, not its middle
|
|
223
|
+
out.push(...sweep(far, seen));
|
|
224
|
+
}
|
|
225
|
+
return out.reverse();
|
|
226
|
+
}
|
|
227
|
+
function profile(first) {
|
|
228
|
+
const n = first.length, start = new Int32Array(n + 1);
|
|
229
|
+
for (let i = 0; i < n; i++) start[i + 1] = start[i] + i - first[i] + 1;
|
|
230
|
+
return { n, first, start, v: new Float64Array(start[n]) };
|
|
231
|
+
}
|
|
232
|
+
const multiply = (P, x, y = new Float64Array(P.n)) => {
|
|
233
|
+
const { n, first, start, v } = P;
|
|
234
|
+
y.fill(0);
|
|
235
|
+
for (let i = 0; i < n; i++) { const o = start[i] - first[i], xi = x[i]; let s = 0; for (let j = first[i]; j < i; j++) { s += v[o + j] * x[j]; y[j] += v[o + j] * xi; } y[i] += s + v[o + i] * xi; }
|
|
236
|
+
return y;
|
|
237
|
+
};
|
|
238
|
+
// Cholesky, L Lᵀ, in the same rows. A pivot that all but vanishes is a freedom nothing holds: it is noted, held,
|
|
239
|
+
// and the factorisation goes on, so every loose freedom is found in one pass.
|
|
240
|
+
function factorise(P) {
|
|
241
|
+
const { n, first, start } = P, v = Float64Array.from(P.v), loose = [];
|
|
242
|
+
for (let i = 0; i < n; i++) {
|
|
243
|
+
const fi = first[i], ri = start[i] - fi;
|
|
244
|
+
for (let j = fi; j < i; j++) {
|
|
245
|
+
const fj = first[j], rj = start[j] - fj;
|
|
246
|
+
let s = v[ri + j];
|
|
247
|
+
for (let k = fi > fj ? fi : fj; k < j; k++) s -= v[ri + k] * v[rj + k];
|
|
248
|
+
v[ri + j] = s / v[rj + j];
|
|
249
|
+
}
|
|
250
|
+
const a = v[ri + i];
|
|
251
|
+
let d = a;
|
|
252
|
+
for (let k = fi; k < i; k++) d -= v[ri + k] * v[ri + k];
|
|
253
|
+
if (!(d > 1e-11 * a)) { loose.push(i); d = Math.max(a, 1) * 1e20; }
|
|
254
|
+
v[ri + i] = Math.sqrt(d);
|
|
255
|
+
}
|
|
256
|
+
const solve = (b, x = new Float64Array(n)) => {
|
|
257
|
+
for (let i = 0; i < n; i++) { const fi = first[i], ri = start[i] - fi; let s = b[i]; for (let k = fi; k < i; k++) s -= v[ri + k] * x[k]; x[i] = s / v[ri + i]; }
|
|
258
|
+
for (let i = n - 1; i >= 0; i--) { const fi = first[i], ri = start[i] - fi, xi = (x[i] /= v[ri + i]); for (let k = fi; k < i; k++) x[k] -= v[ri + k] * xi; }
|
|
259
|
+
return x;
|
|
260
|
+
};
|
|
261
|
+
return { solve, loose };
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Eigenvalues and vectors of a small symmetric matrix by Jacobi rotations (A is used up): values[i] goes with column i of V
|
|
265
|
+
function jacobi(A, n) {
|
|
266
|
+
const V = new Float64Array(n * n);
|
|
267
|
+
for (let i = 0; i < n; i++) V[i * n + i] = 1;
|
|
268
|
+
for (let sweep = 0; sweep < 80; sweep++) {
|
|
269
|
+
let off = 0, all = 0;
|
|
270
|
+
for (let i = 0; i < n; i++) for (let j = 0; j < n; j++) { const a = A[i * n + j] * A[i * n + j]; all += a; if (i !== j) off += a; }
|
|
271
|
+
if (!(off > 1e-26 * all)) break; // (the off-diagonal part is under 1e-13 of the whole)
|
|
272
|
+
for (let p = 0; p < n - 1; p++) for (let q = p + 1; q < n; q++) {
|
|
273
|
+
const apq = A[p * n + q];
|
|
274
|
+
if (apq === 0) continue;
|
|
275
|
+
const theta = (A[q * n + q] - A[p * n + p]) / (2 * apq), t = (theta < 0 ? -1 : 1) / (Math.abs(theta) + Math.sqrt(theta * theta + 1)), c = 1 / Math.sqrt(t * t + 1), s = t * c;
|
|
276
|
+
for (let k = 0; k < n; k++) { const kp = A[k * n + p], kq = A[k * n + q]; A[k * n + p] = c * kp - s * kq; A[k * n + q] = s * kp + c * kq; }
|
|
277
|
+
for (let k = 0; k < n; k++) { const pk = A[p * n + k], qk = A[q * n + k]; A[p * n + k] = c * pk - s * qk; A[q * n + k] = s * pk + c * qk; }
|
|
278
|
+
for (let k = 0; k < n; k++) { const kp = V[k * n + p], kq = V[k * n + q]; V[k * n + p] = c * kp - s * kq; V[k * n + q] = s * kp + c * kq; }
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return { values: Float64Array.from({ length: n }, (_, i) => A[i * n + i]), V };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// The largest μ of B x = μ K x (K positive definite and factorised, B symmetric: the mass, or minus the geometric
|
|
285
|
+
// stiffness) and their vectors, by subspace iteration (Bathe 2014, chapter 11): a block of vectors is put through
|
|
286
|
+
// K⁻¹ B again and again, and the small problem in the block (Rayleigh-Ritz) is solved by Jacobi rotations. The block
|
|
287
|
+
// is made orthonormal in K, not in B, so a B of low rank (one lumped mass, one beam in compression) is no trouble:
|
|
288
|
+
// vectors the block cannot tell apart are dropped. Only positive μ are wanted, `want` of them; if the block settles
|
|
289
|
+
// with fewer (negative ones crowd it: the frame would buckle more readily with its loads reversed), or has not
|
|
290
|
+
// settled in 30 steps, it doubles, up to the whole problem, where one step is exact. Buckling starts with a wider
|
|
291
|
+
// block than modes do: a frame's columns buckle at loads close together, and close values settle slowly in a
|
|
292
|
+
// block that holds only some of them.
|
|
293
|
+
function lowest(solveK, B, want, block = Math.max(2 * want, want + 8), tol = 1e-9, limit = 400) {
|
|
294
|
+
const n = B.n;
|
|
295
|
+
let seed = 12345;
|
|
296
|
+
const random = () => { let t = (seed += 0x6D2B79F5); t = Math.imul(t ^ (t >>> 15), t | 1); t ^= t + Math.imul(t ^ (t >>> 7), t | 61); return ((t ^ (t >>> 14)) >>> 0) / 2147483648 - 1; };
|
|
297
|
+
const fresh = () => multiply(B, Float64Array.from({ length: n }, random));
|
|
298
|
+
let q = Math.min(n, block), Y = Array.from({ length: q }, fresh), last = null, exhausted = false;
|
|
299
|
+
for (let step = 0, since = 1; ; step++, since++) {
|
|
300
|
+
const offered = Y.length;
|
|
301
|
+
let Z = Y.map((y) => solveK(y)), BZ = Z.map((z) => multiply(B, z));
|
|
302
|
+
// each vector's size in K (zᵀ K z = zᵀ y): scaled to 1, or dropped if B gave it nothing
|
|
303
|
+
const keep = [];
|
|
304
|
+
Z.forEach((z, i) => { let e = 0; for (let k = 0; k < n; k++) e += z[k] * Y[i][k]; if (e > 0 && Number.isFinite(e)) { const s = 1 / Math.sqrt(e); for (let k = 0; k < n; k++) { z[k] *= s; BZ[i][k] *= s; Y[i][k] *= s; } keep.push(i); } });
|
|
305
|
+
Z = keep.map((i) => Z[i]); BZ = keep.map((i) => BZ[i]); Y = keep.map((i) => Y[i]);
|
|
306
|
+
const m = Z.length;
|
|
307
|
+
if (!m) return { values: [], vectors: [] };
|
|
308
|
+
const Kr = new Float64Array(m * m), Br = new Float64Array(m * m);
|
|
309
|
+
for (let i = 0; i < m; i++) for (let j = i; j < m; j++) { let a = 0, b = 0; const zi = Z[i], yj = Y[j], bj = BZ[j]; for (let k = 0; k < n; k++) { a += zi[k] * yj[k]; b += zi[k] * bj[k]; } Kr[i * m + j] = Kr[j * m + i] = a; Br[i * m + j] = Br[j * m + i] = b; }
|
|
310
|
+
// an orthonormal basis of the block in K: Kr = V Λ Vᵀ, W = V Λ^-½, leaving out directions the block repeats
|
|
311
|
+
const kr = jacobi(Kr, m), top = Math.max(...kr.values), cols = [...kr.values.keys()].filter((i) => kr.values[i] > 1e-12 * top), r = cols.length;
|
|
312
|
+
const W = new Float64Array(m * r), BW = new Float64Array(m * r), C = new Float64Array(r * r);
|
|
313
|
+
cols.forEach((c, j) => { const s = 1 / Math.sqrt(kr.values[c]); for (let i = 0; i < m; i++) W[i * r + j] = kr.V[i * m + c] * s; });
|
|
314
|
+
for (let i = 0; i < m; i++) for (let j = 0; j < r; j++) { let s = 0; for (let k = 0; k < m; k++) s += Br[i * m + k] * W[k * r + j]; BW[i * r + j] = s; }
|
|
315
|
+
for (let i = 0; i < r; i++) for (let j = 0; j < r; j++) { let s = 0; for (let k = 0; k < m; k++) s += W[k * r + i] * BW[k * r + j]; C[i * r + j] = s; }
|
|
316
|
+
const ritz = jacobi(C, r), by = [...ritz.values.keys()].sort((a, b) => ritz.values[b] - ritz.values[a]);
|
|
317
|
+
// the Ritz vectors (or their B products) from the block: column c = Σ_i S_i (W U)[i][c]
|
|
318
|
+
const mix = (S, count = r) => by.slice(0, count).map((c) => { const x = new Float64Array(n); for (let i = 0; i < m; i++) { let w = 0; for (let j = 0; j < r; j++) w += W[i * r + j] * ritz.V[j * r + c]; if (w) { const si = S[i]; for (let k = 0; k < n; k++) x[k] += w * si[k]; } } return x; });
|
|
319
|
+
const values = by.map((c) => ritz.values[c]), size = Math.max(Math.abs(values[0]), Math.abs(values[r - 1])), wanted = values.filter((v) => v > 1e-12 * size).slice(0, want);
|
|
320
|
+
if (since === 1 && r < offered) exhausted = true; // fresh vectors added nothing new: the block already holds all B can reach
|
|
321
|
+
const settled = !!last && last.length === wanted.length && wanted.every((v, i) => Math.abs(v - last[i]) <= tol * v);
|
|
322
|
+
if (r >= n || (settled && (wanted.length >= want || exhausted || q >= n)) || step + 1 >= limit) return { values: wanted, vectors: mix(Z, wanted.length) };
|
|
323
|
+
last = wanted;
|
|
324
|
+
Y = mix(BZ);
|
|
325
|
+
if ((settled || since >= 30) && q < n) { const more = Math.min(n, 2 * q) - q; for (let i = 0; i < more; i++) Y.push(fresh()); q += more; since = 0; last = null; }
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// ---- the model, read and refused by name ----
|
|
330
|
+
|
|
331
|
+
function read(model, { shear = true } = {}) {
|
|
332
|
+
if (!model || typeof model !== 'object') refuse('input', 'a frame is { nodes, elements, supports, loads }: got ' + said(model));
|
|
333
|
+
const { nodes, elements } = model;
|
|
334
|
+
if (!nodes || typeof nodes !== 'object') refuse('input', 'a frame needs nodes: positions in mm by name, { a: [0, 0, 0], b: [0, 0, 300] }, or a list of positions');
|
|
335
|
+
const ids = Array.isArray(nodes) ? nodes.map((_, i) => String(i)) : Object.keys(nodes), at = Array.isArray(nodes) ? nodes : Object.values(nodes), index = new Map(ids.map((id, i) => [id, i]));
|
|
336
|
+
if (!ids.length) refuse('input', 'a frame needs nodes: positions in mm by name, { a: [0, 0, 0], b: [0, 0, 300] }, or a list of positions');
|
|
337
|
+
at.forEach((p, i) => { if (!isVec3(p)) refuse('node', `node ${said(ids[i])} is at ${said(p)}: a node needs a position [x, y, z] in mm`, { node: ids[i] }); });
|
|
338
|
+
if (!Array.isArray(elements) || !elements.length) refuse('input', 'a frame needs elements: a list of { a, b, section, material }, each between two nodes');
|
|
339
|
+
const nodeOf = (name, what) => index.get(String(name)) ?? refuse('node', `${what} names node ${said(name)}, which is not in nodes (there ${ids.length === 1 ? 'is' : 'are'} ${ids.slice(0, 12).join(', ')}${ids.length > 12 ? ', ...' : ''})`, { node: name });
|
|
340
|
+
const named = (v, table, what, whose) => (typeof v === 'string' ? table?.[v] ?? refuse(what, `${whose} names ${what} "${v}", which is not in the model's ${what}s${table ? ` (there ${Object.keys(table).length === 1 ? 'is' : 'are'} ${Object.keys(table).join(', ')})` : ''}`) : v);
|
|
341
|
+
const N = ids.length, elementIds = new Map();
|
|
342
|
+
const els = elements.map((e, i) => {
|
|
343
|
+
const id = e?.id ?? i, whose = `element ${said(id)}`;
|
|
344
|
+
if (!e || typeof e !== 'object') refuse('input', `element ${i} is ${said(e)}: an element is { a, b, section, material }`);
|
|
345
|
+
if (elementIds.has(String(id))) refuse('input', `two elements are called ${said(id)}: each needs its own id`);
|
|
346
|
+
elementIds.set(String(id), i);
|
|
347
|
+
const a = nodeOf(e.a, whose), b = nodeOf(e.b, whose), pa = at[a], pb = at[b], dx = [pb[0] - pa[0], pb[1] - pa[1], pb[2] - pa[2]], L = Math.hypot(...dx);
|
|
348
|
+
if (a === b || !(L > 1e-9)) refuse('length', `${whose} has no length: it runs from node ${said(e.a)} to node ${said(e.b)}${a === b ? '' : ', which are at the same place'}. An element joins two nodes some way apart`, { element: id });
|
|
349
|
+
const section = named(e.section, model.sections, 'section', whose), material = named(e.material, model.materials, 'material', whose);
|
|
350
|
+
if (!section || typeof section !== 'object') refuse('section', `${whose} needs a section: { A, Iy, Iz, J } in mm² and mm⁴`, { element: id });
|
|
351
|
+
for (const key of ['A', 'Iy', 'Iz', 'J']) if (!(section[key] > 0) || !Number.isFinite(section[key])) refuse('section', `${whose}'s section has ${key} = ${said(section[key])}: it needs ${key} above 0 (A in mm²; Iy, Iz and J in mm⁴)`, { element: id, property: key });
|
|
352
|
+
for (const key of ['Asy', 'Asz', 'cy', 'cz', 'Wy', 'Wz']) if (section[key] !== undefined && (!(section[key] > 0) || !Number.isFinite(section[key]))) refuse('section', `${whose}'s section has ${key} = ${said(section[key])}: leave it out, or give it above 0`, { element: id, property: key });
|
|
353
|
+
if (!material || typeof material !== 'object') refuse('material', `${whose} needs a material: { E, nu or G, density }`, { element: id });
|
|
354
|
+
if (!(material.E > 0) || !Number.isFinite(material.E)) refuse('material', `${whose}'s material has E = ${said(material.E)}: it needs a Young's modulus above 0, in MPa`, { element: id, property: 'E' });
|
|
355
|
+
if (material.G !== undefined ? !(material.G > 0 && Number.isFinite(material.G)) : !(material.nu > -1 && material.nu < 0.5)) refuse('material', `${whose}'s material has G = ${said(material.G)} and nu = ${said(material.nu)}: it needs a shear modulus G above 0 in MPa, or a Poisson's ratio nu between -1 and 0.5`, { element: id, property: 'G' });
|
|
356
|
+
if (material.density !== undefined && !(material.density >= 0 && Number.isFinite(material.density))) refuse('material', `${whose}'s material has density = ${said(material.density)}: leave it out (weightless), or give it in g/cm³, 0 or more`, { element: id, property: 'density' });
|
|
357
|
+
// local axes
|
|
358
|
+
const x = dx.map((c) => c / L);
|
|
359
|
+
if (e.up !== undefined && !isVec3(e.up)) refuse('axes', `${whose}'s up is ${said(e.up)}: it is a direction [x, y, z] that local z leans towards`, { element: id });
|
|
360
|
+
if (e.roll !== undefined && !Number.isFinite(e.roll)) refuse('axes', `${whose}'s roll is ${said(e.roll)}: it is an angle in degrees about the element's own axis`, { element: id });
|
|
361
|
+
const up = e.up ?? (Math.abs(x[2]) > 0.999 ? [1, 0, 0] : [0, 0, 1]), along = up[0] * x[0] + up[1] * x[1] + up[2] * x[2];
|
|
362
|
+
let z = [up[0] - along * x[0], up[1] - along * x[1], up[2] - along * x[2]];
|
|
363
|
+
const zl = Math.hypot(...z);
|
|
364
|
+
if (!(zl > 1e-6 * Math.hypot(...up))) refuse('axes', `${whose}'s up, ${said(Array.from(up))}, runs along the element, so it does not say which way local z points: give a direction across it`, { element: id });
|
|
365
|
+
z = z.map((c) => c / zl);
|
|
366
|
+
let y = [z[1] * x[2] - z[2] * x[1], z[2] * x[0] - z[0] * x[2], z[0] * x[1] - z[1] * x[0]];
|
|
367
|
+
if (e.roll) { const c = Math.cos((e.roll * Math.PI) / 180), s = Math.sin((e.roll * Math.PI) / 180), y0 = y, z0 = z; y = y0.map((v, k) => c * v + s * z0[k]); z = z0.map((v, k) => c * z0[k] - s * y0[k]); }
|
|
368
|
+
// how each end is joined
|
|
369
|
+
const springs = new Float64Array(12).fill(Infinity);
|
|
370
|
+
for (const [end, o] of [['a', 3], ['b', 9]]) {
|
|
371
|
+
const j = e.ends?.[end] ?? 'rigid', each = j === 'rigid' ? {} : j === 'pinned' ? { ry: 'free', rz: 'free' } : j === 'ball' ? { rx: 'free', ry: 'free', rz: 'free' } : j;
|
|
372
|
+
if (!each || typeof each !== 'object') refuse('join', `${whose}'s end ${end} is joined ${said(j)}: 'rigid', 'pinned' (both bending rotations free), 'ball' (all three free), or { rx, ry, rz } each 'rigid', 'free' or a spring in N·mm/rad`, { element: id });
|
|
373
|
+
for (const [key, f] of Object.entries(each)) {
|
|
374
|
+
const d = ['rx', 'ry', 'rz'].indexOf(key);
|
|
375
|
+
if (d < 0) refuse('join', `${whose}'s end ${end} has "${key}": an end's rotations are rx (twist), ry and rz, about the element's own axes`, { element: id });
|
|
376
|
+
if (f === 'rigid' || f === Infinity || f === undefined) continue;
|
|
377
|
+
if (f !== 'free' && !(f >= 0)) refuse('join', `${whose}'s end ${end} has ${key} = ${said(f)}: 'rigid', 'free', or a spring's stiffness in N·mm/rad, 0 or more`, { element: id });
|
|
378
|
+
springs[o + d] = f === 'free' ? 0 : f;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
const R = Float64Array.of(...x, ...y, ...z), raw = elementMatrices(section, material, L, { shear });
|
|
382
|
+
// free to twist at both ends (a strut on two ball joints): it carries no torque, and its own spin is nobody's business
|
|
383
|
+
if (springs[3] === 0 && springs[9] === 0) { springs[3] = springs[9] = Infinity; for (const i of [3, 9]) for (const j of [3, 9]) raw.k[i * 12 + j] = raw.m[i * 12 + j] = 0; }
|
|
384
|
+
const c = condense(raw, springs);
|
|
385
|
+
if (!c) refuse('join', `${whose}'s end joints leave it loose: carry more of its rotations`, { element: id });
|
|
386
|
+
const G = shearModulus(material), Wy = section.Wy ?? (section.cz ? section.Iy / section.cz : undefined), Wz = section.Wz ?? (section.cy ? section.Iz / section.cy : undefined);
|
|
387
|
+
return { id, of: e.of, a, b, L, R, raw, ...c, phi: raw.phi, EA: material.E * section.A, EIy: material.E * section.Iy, EIz: material.E * section.Iz, GAy: shear && section.Asy ? G * section.Asy : 0, GAz: shear && section.Asz ? G * section.Asz : 0,
|
|
388
|
+
A: section.A, Wy, Wz, perLength: (material.density || 0) * 1e-6 * section.A, K: toGlobal(c.k, R) };
|
|
389
|
+
});
|
|
390
|
+
// supports
|
|
391
|
+
const held = new Uint8Array(6 * N), ground = new Float64Array(6 * N), supported = [];
|
|
392
|
+
if (model.supports !== undefined && (typeof model.supports !== 'object' || !model.supports)) refuse('support', `supports is ${said(model.supports)}: give each supported node 'fixed', 'pinned' or { x, y, z, rx, ry, rz }`);
|
|
393
|
+
for (const [name, s] of Object.entries(model.supports || {})) {
|
|
394
|
+
const n = nodeOf(name, 'a support'), each = s === 'fixed' ? Object.fromEntries(FREEDOMS.map((f) => [f, true])) : s === 'pinned' ? { x: true, y: true, z: true } : s;
|
|
395
|
+
if (!each || typeof each !== 'object') refuse('support', `node ${said(name)}'s support is ${said(s)}: 'fixed' (all six freedoms), 'pinned' (its three movements), or { x, y, z, rx, ry, rz } each true (held), false, or a spring to ground in N/mm or N·mm/rad`, { node: name });
|
|
396
|
+
let any = false;
|
|
397
|
+
for (const [key, h] of Object.entries(each)) {
|
|
398
|
+
const d = FREEDOMS.indexOf(key);
|
|
399
|
+
if (d < 0) refuse('support', `node ${said(name)}'s support has "${key}": a node's freedoms are ${FREEDOMS.join(', ')}`, { node: name });
|
|
400
|
+
if (h === true || h === 'fixed' || h === Infinity) { held[6 * n + d] = 1; any = true; } else if (typeof h === 'number' && h > 0) { ground[6 * n + d] = h; any = true; } else if (!(h === false || h === 'free' || h === 0 || h === undefined)) refuse('support', `node ${said(name)}'s support has ${key} = ${said(h)}: true (held), false (free), or a spring to ground of 0 or more`, { node: name });
|
|
401
|
+
}
|
|
402
|
+
if (any) supported.push(n);
|
|
403
|
+
}
|
|
404
|
+
if (!supported.length) refuse('unheld', 'nothing is held: give at least one node a support (supports: { a: \'fixed\' }), or the frame just moves');
|
|
405
|
+
const span = Math.max(...[0, 1, 2].map((c) => Math.max(...at.map((p) => p[c])) - Math.min(...at.map((p) => p[c]))));
|
|
406
|
+
return { ids, at, index, N, els, elementIds, held, ground, supported, nodeOf, span };
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// The loads of one case: forces on every freedom, and each element's spread load in its own axes
|
|
410
|
+
function loadCase(f, { loads = [], gravity, masses = {} }) {
|
|
411
|
+
const { N, els, elementIds, nodeOf } = f, nodal = new Float64Array(6 * N), spread = new Float64Array(3 * els.length), lumped = new Float64Array(N);
|
|
412
|
+
if (!Array.isArray(loads)) refuse('load', `loads is ${said(loads)}: a list of { node, force, moment } and { element, spread }`);
|
|
413
|
+
if (gravity !== undefined && !isVec3(gravity)) refuse('load', `gravity is ${said(gravity)}: a direction and size [x, y, z] in N/kg (m/s²), [0, 0, -9.81] for down`);
|
|
414
|
+
if (!masses || typeof masses !== 'object') refuse('mass', `masses is ${said(masses)}: lumped masses in kg by node, { head: 0.4 }`);
|
|
415
|
+
for (const [name, kg] of Object.entries(masses)) {
|
|
416
|
+
const n = nodeOf(name, 'a lumped mass');
|
|
417
|
+
if (!(kg >= 0) || !Number.isFinite(kg)) refuse('mass', `the lumped mass at node ${said(name)} is ${said(kg)}: a mass in kg, 0 or more`, { node: name });
|
|
418
|
+
lumped[n] += kg;
|
|
419
|
+
if (gravity) for (let c = 0; c < 3; c++) nodal[6 * n + c] += kg * gravity[c];
|
|
420
|
+
}
|
|
421
|
+
loads.forEach((l, i) => {
|
|
422
|
+
if (l && l.node !== undefined) {
|
|
423
|
+
const n = nodeOf(l.node, `load ${i + 1}`);
|
|
424
|
+
for (const [key, o] of [['force', 0], ['moment', 3]]) if (l[key] !== undefined) { if (!isVec3(l[key])) refuse('load', `load ${i + 1}'s ${key} is ${said(l[key])}: [x, y, z] in ${o ? 'N·mm' : 'N'}, in global axes`); for (let c = 0; c < 3; c++) nodal[6 * n + o + c] += l[key][c]; }
|
|
425
|
+
if (l.force === undefined && l.moment === undefined) refuse('load', `load ${i + 1}, at node ${said(l.node)}, has neither a force nor a moment`);
|
|
426
|
+
} else if (l && l.element !== undefined) {
|
|
427
|
+
const e = elementIds.get(String(l.element)) ?? refuse('load', `load ${i + 1} names element ${said(l.element)}, which is not in elements`);
|
|
428
|
+
if (!isVec3(l.spread)) refuse('load', `load ${i + 1}'s spread is ${said(l.spread)}: [x, y, z] in N per mm of the element's length`);
|
|
429
|
+
if (l.axes !== undefined && l.axes !== 'global' && l.axes !== 'local') refuse('load', `load ${i + 1}'s axes is ${said(l.axes)}: 'global' or 'local' (the element's own)`);
|
|
430
|
+
const w = l.axes === 'local' ? l.spread : toLocal3(els[e].R, l.spread);
|
|
431
|
+
for (let c = 0; c < 3; c++) spread[3 * e + c] += w[c];
|
|
432
|
+
} else refuse('load', `load ${i + 1} is ${said(l)}: { node, force, moment } or { element, spread }`);
|
|
433
|
+
});
|
|
434
|
+
if (gravity) els.forEach((el, e) => { const w = toLocal3(el.R, gravity); for (let c = 0; c < 3; c++) spread[3 * e + c] += el.perLength * w[c]; });
|
|
435
|
+
return { nodal, spread, lumped };
|
|
436
|
+
}
|
|
437
|
+
// A spread load's forces at the element's (rigid) ends, in its own axes: w L / 2 each, and moments of w L² / 12
|
|
438
|
+
function spreadEnds(L, wx, wy, wz) {
|
|
439
|
+
const fb = new Float64Array(12), h = L / 2, m = (L * L) / 12;
|
|
440
|
+
fb[0] = fb[6] = wx * h; fb[1] = fb[7] = wy * h; fb[2] = fb[8] = wz * h; fb[5] = wy * m; fb[11] = -wy * m; fb[4] = -wz * m; fb[10] = wz * m;
|
|
441
|
+
return fb;
|
|
442
|
+
}
|
|
443
|
+
const condensedLoad = (el, fb) => { if (!el.T) return fb; const fc = new Float64Array(12); for (let i = 0; i < 12; i++) { const v = fb[i]; if (v) for (let j = 0; j < 12; j++) fc[j] += el.T[i * 12 + j] * v; } return fc; };
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* A frame, read, checked and factorised once, ready for its solves. What is wrong with the model is said here, by
|
|
447
|
+
* name, before any solve: each refusal is an Error with a `code` ("fea.frame." then node, length, section, material,
|
|
448
|
+
* axes, join, support, load, mass, input, unheld or mechanism; buckling adds compression).
|
|
449
|
+
* @param {FrameModel} model
|
|
450
|
+
* @param {{ shear?: boolean }} [o] shear: false ignores the sections' shear areas (Euler-Bernoulli beams)
|
|
451
|
+
* @returns {{
|
|
452
|
+
* statics: (o?: { loads?: FrameLoad[], gravity?: Vec3, masses?: Record<string, number>, samples?: number }) => StaticResult,
|
|
453
|
+
* buckling: (o?: { count?: number, loads?: FrameLoad[], gravity?: Vec3, masses?: Record<string, number> }) => { factors: number[], modes: BucklingMode[], statics: StaticResult },
|
|
454
|
+
* modes: (o?: { count?: number, masses?: Record<string, number> }) => { frequencies: number[], modes: VibrationMode[] },
|
|
455
|
+
* freedoms: number, nodes: string[] }}
|
|
456
|
+
* statics, buckling and modes use the model's own loads, gravity and masses unless given others (another load case
|
|
457
|
+
* on the same factorisation). samples: stations along each element (11). count: how many modes (1 for buckling, 6
|
|
458
|
+
* for vibration; fewer come back if the frame has fewer). freedoms: how many unknowns were solved for.
|
|
459
|
+
*/
|
|
460
|
+
export function frame(model, o = {}) {
|
|
461
|
+
const f = read(model, o), { ids, N, els, held, ground } = f;
|
|
462
|
+
// free freedoms, numbered node by node in an order that keeps the matrix's rows short
|
|
463
|
+
const free = new Int32Array(6 * N).fill(-1), back = [];
|
|
464
|
+
for (const n of ordering(N, els.map((e) => [e.a, e.b]))) for (let d = 0; d < 6; d++) if (!held[6 * n + d]) { free[6 * n + d] = back.length; back.push(6 * n + d); }
|
|
465
|
+
const n = back.length, first = Int32Array.from({ length: n }, (_, i) => i);
|
|
466
|
+
for (const el of els) {
|
|
467
|
+
el.dofs = Int32Array.from({ length: 12 }, (_, i) => free[6 * (i < 6 ? el.a : el.b) + (i % 6)]);
|
|
468
|
+
let lo = n;
|
|
469
|
+
for (const d of el.dofs) if (d >= 0 && d < lo) lo = d;
|
|
470
|
+
for (const d of el.dofs) if (d >= 0 && lo < first[d]) first[d] = lo;
|
|
471
|
+
}
|
|
472
|
+
const assemble = (matrix, scale) => {
|
|
473
|
+
const P = profile(first), { start, v } = P;
|
|
474
|
+
els.forEach((el, e) => { const s = scale ? scale[e] : 1, G = matrix(el), dofs = el.dofs; if (s) for (let i = 0; i < 12; i++) { const di = dofs[i]; if (di >= 0) for (let j = 0; j < 12; j++) { const dj = dofs[j]; if (dj >= 0 && dj <= di) v[start[di] + dj - first[di]] += s * G[i * 12 + j]; } } });
|
|
475
|
+
return P;
|
|
476
|
+
};
|
|
477
|
+
const diagonal = (P, i) => P.start[i] + i - P.first[i];
|
|
478
|
+
const K = assemble((el) => el.K);
|
|
479
|
+
for (let i = 0; i < n; i++) K.v[diagonal(K, i)] += ground[back[i]];
|
|
480
|
+
// A rotation of a node that no element end there carries (every end at it pinned that way) leaves the matrix
|
|
481
|
+
// singular though nothing is wrong with the frame: nothing turns the node, and nothing depends on it. Such a
|
|
482
|
+
// rotation is held still (and reported as 0); a moment put on it is refused, as nothing would carry it.
|
|
483
|
+
const idle = [], turn = new Float64Array(9 * N), stiff = new Float64Array(N);
|
|
484
|
+
for (const el of els) for (const [p, o] of [[el.a, 3], [el.b, 9]]) for (let i = 0; i < 3; i++) { stiff[p] = Math.max(stiff[p], el.raw.k[(o + i) * 13]); for (let j = 0; j < 3; j++) turn[9 * p + 3 * i + j] += el.K[(o + i) * 12 + o + j]; }
|
|
485
|
+
for (let p = 0; p < N; p++) {
|
|
486
|
+
const fr = [3, 4, 5].filter((d) => !held[6 * p + d]), m = fr.length;
|
|
487
|
+
if (!m || !(stiff[p] > 0)) continue;
|
|
488
|
+
const S = Float64Array.from({ length: m * m }, (_, q) => { const i = Math.floor(q / m), j = q % m; return turn[9 * p + 3 * (fr[i] - 3) + fr[j] - 3] + (i === j ? ground[6 * p + fr[i]] : 0); }), { values, V } = jacobi(S, m);
|
|
489
|
+
for (let c = 0; c < m; c++) if (values[c] < 1e-9 * stiff[p]) {
|
|
490
|
+
const v = [0, 0, 0];
|
|
491
|
+
fr.forEach((d, i) => { v[d - 3] = V[i * m + c]; });
|
|
492
|
+
idle.push({ node: p, v });
|
|
493
|
+
for (const di of fr) for (const dj of fr) { const a = free[6 * p + di], b = free[6 * p + dj]; if (b <= a) K.v[K.start[a] + b - first[a]] += stiff[p] * v[di - 3] * v[dj - 3]; }
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
const factor = n ? factorise(K) : { solve: (b) => new Float64Array(0), loose: [] };
|
|
497
|
+
if (factor.loose.length) {
|
|
498
|
+
const loose = factor.loose.map((i) => ({ node: ids[Math.floor(back[i] / 6)], freedom: FREEDOMS[back[i] % 6] }));
|
|
499
|
+
const by = new Map(); for (const l of loose) by.set(l.node, [...(by.get(l.node) || []), l.freedom]);
|
|
500
|
+
const list = [...by].slice(0, 8).map(([node, fr]) => `node ${said(node)} (${fr.join(', ')})`).join('; ');
|
|
501
|
+
refuse('mechanism', `the frame is a mechanism: it can still move with nothing resisting, at ${list}${by.size > 8 ? `, and ${by.size - 8} more nodes` : ''}. Hold those freedoms with a support, or join the elements there more stiffly (a pinned end frees its bending rotations and still carries twist, so a strut pinned at both ends can spin: make one end 'ball')`, { loose });
|
|
502
|
+
}
|
|
503
|
+
const shapeOf = (x) => { // a vector over the free freedoms as each node's six: its largest movement 1, and that one positive
|
|
504
|
+
const u = new Float64Array(6 * N);
|
|
505
|
+
for (let i = 0; i < n; i++) u[back[i]] = x[i];
|
|
506
|
+
let most = 0, lead = 0;
|
|
507
|
+
for (let p = 0; p < N; p++) most = Math.max(most, Math.hypot(u[6 * p], u[6 * p + 1], u[6 * p + 2]));
|
|
508
|
+
const moves = most > 0; // (a shape that only turns, such as a shaft's twist, is scaled by its largest rotation)
|
|
509
|
+
for (let i = 0; i < 6 * N; i++) if ((!moves || i % 6 < 3) && Math.abs(u[i]) > Math.abs(lead) * (1 + 1e-9)) lead = u[i];
|
|
510
|
+
const scale = (lead < 0 ? -1 : 1) / ((moves ? most : Math.abs(lead)) || 1);
|
|
511
|
+
return Object.fromEntries(ids.map((id, p) => [id, /** @type {Six} */ (Array.from(u.subarray(6 * p, 6 * p + 6), (v) => v * scale))]));
|
|
512
|
+
};
|
|
513
|
+
const caseOf = (c = {}) => ({ loads: c.loads ?? model.loads, gravity: c.gravity ?? model.gravity, masses: c.masses ?? model.masses });
|
|
514
|
+
|
|
515
|
+
function statics(c = {}) {
|
|
516
|
+
const samples = c.samples ?? 11;
|
|
517
|
+
if (!(Number.isInteger(samples) && samples >= 2)) refuse('input', `samples is ${said(samples)}: a whole number of stations along each element, 2 or more`);
|
|
518
|
+
const { nodal, spread } = loadCase(f, caseOf(c)), p = Float64Array.from(nodal);
|
|
519
|
+
for (const { node, v } of idle) { const m = [nodal[6 * node + 3], nodal[6 * node + 4], nodal[6 * node + 5]]; if (Math.abs(m[0] * v[0] + m[1] * v[1] + m[2] * v[2]) > 1e-9 * Math.hypot(...m)) refuse('load', `a moment is put on node ${said(ids[node])} about a direction no element there carries (every end at it is pinned that way): join an end to it rigidly or through a spring, or hold that rotation with a support`, { node: ids[node] }); }
|
|
520
|
+
const ends = els.map((el, e) => {
|
|
521
|
+
const fb = spreadEnds(el.L, spread[3 * e], spread[3 * e + 1], spread[3 * e + 2]), fc = condensedLoad(el, fb);
|
|
522
|
+
for (let q = 0; q < 4; q++) { const g = toGlobal3(el.R, fc, 3 * q), at = 6 * (q < 2 ? el.a : el.b) + 3 * (q % 2); for (let k = 0; k < 3; k++) p[at + k] += g[k]; }
|
|
523
|
+
return { fb, fc };
|
|
524
|
+
});
|
|
525
|
+
const x = factor.solve(Float64Array.from(back, (d) => p[d])), u = new Float64Array(6 * N), residual = Float64Array.from(nodal, (v) => -v);
|
|
526
|
+
for (let i = 0; i < n; i++) u[back[i]] = x[i];
|
|
527
|
+
for (const { node, v } of idle) { const o = 6 * node + 3, along = u[o] * v[0] + u[o + 1] * v[1] + u[o + 2] * v[2]; for (let c = 0; c < 3; c++) u[o + c] = held[o + c] || Math.abs(v[c]) === 1 ? 0 : u[o + c] - along * v[c]; }
|
|
528
|
+
let most = 0, mostAt = 0;
|
|
529
|
+
for (let q = 0; q < N; q++) { const d = Math.hypot(u[6 * q], u[6 * q + 1], u[6 * q + 2]); if (d > most) { most = d; mostAt = q; } }
|
|
530
|
+
if (!x.every(Number.isFinite) || most > 1e6 * (f.span || 1)) refuse('mechanism', 'the frame is barely held: under this load it moves many times its own size. Add supports, or join its elements more stiffly', { loose: [] });
|
|
531
|
+
const elements = els.map((el, e) => {
|
|
532
|
+
const { L, R } = el, { fb, fc } = ends[e], w = [spread[3 * e], spread[3 * e + 1], spread[3 * e + 2]], d = new Float64Array(12), F = new Float64Array(12);
|
|
533
|
+
for (let q = 0; q < 4; q++) d.set(toLocal3(R, u, 6 * (q < 2 ? el.a : el.b) + 3 * (q % 2)), 3 * q);
|
|
534
|
+
for (let i = 0; i < 12; i++) { let s = -fc[i]; for (let j = 0; j < 12; j++) s += el.k[i * 12 + j] * d[j]; F[i] = s; }
|
|
535
|
+
for (let q = 0; q < 4; q++) { const g = toGlobal3(R, F, 3 * q), at = 6 * (q < 2 ? el.a : el.b) + 3 * (q % 2); for (let k = 0; k < 3; k++) residual[at + k] += g[k]; }
|
|
536
|
+
// the beam's own end freedoms, behind any springs: d_beam = T d + H f_s
|
|
537
|
+
let db = d;
|
|
538
|
+
if (el.T) { db = new Float64Array(12); for (let i = 0; i < 12; i++) { let s = 0; for (let j = 0; j < 12; j++) s += el.T[i * 12 + j] * d[j]; db[i] = s; } el.s.forEach((sp, a) => { el.s.forEach((sq, b) => { db[sp] += el.H[a * el.s.length + b] * fb[sq]; }); }); }
|
|
539
|
+
// N, V and M as polynomials in x, from the forces on end a and the spread load between
|
|
540
|
+
const poly = { N: [-F[0], -w[0], 0], Vy: [-F[1], -w[1], 0], Vz: [-F[2], -w[2], 0], T: [-F[3], 0, 0], My: [-F[4], -F[2], -w[2] / 2], Mz: [-F[5], F[1], w[1] / 2] };
|
|
541
|
+
const value = (c, s) => c[0] + s * (c[1] + s * c[2]), inside = (s) => s > 1e-9 * L && s < L * (1 - 1e-9);
|
|
542
|
+
const xs = Array.from({ length: samples }, (_, i) => (L * i) / (samples - 1));
|
|
543
|
+
for (const c of [poly.My, poly.Mz]) if (c[2] !== 0 && inside(-c[1] / (2 * c[2]))) xs.push(-c[1] / (2 * c[2]));
|
|
544
|
+
xs.sort((a, b) => a - b);
|
|
545
|
+
const along = { x: xs, N: [], Vy: [], Vz: [], T: [], My: [], Mz: [], d: [] }, peak = {};
|
|
546
|
+
for (const key of ['N', 'Vy', 'Vz', 'T', 'My', 'Mz']) { along[key] = xs.map((s) => value(poly[key], s)); let b = 0; along[key].forEach((v, i) => { if (Math.abs(v) > Math.abs(along[key][b])) b = i; }); peak[key] = { value: along[key][b], x: xs[b] }; }
|
|
547
|
+
along.d = xs.map((s) => {
|
|
548
|
+
const xi = s / L, ny = shape(xi, L, el.phi[0]).N, nz = shape(xi, L, el.phi[1]).N, bend = (s * s * (L - s) * (L - s)) / 24, sh = (s * (L - s)) / 2;
|
|
549
|
+
const local = [(1 - xi) * db[0] + xi * db[6] + (w[0] * sh) / el.EA,
|
|
550
|
+
ny[0] * db[1] + ny[1] * db[5] + ny[2] * db[7] + ny[3] * db[11] + (w[1] * bend) / el.EIz + (el.GAy ? (w[1] * sh) / el.GAy : 0),
|
|
551
|
+
nz[0] * db[2] - nz[1] * db[4] + nz[2] * db[8] - nz[3] * db[10] + (w[2] * bend) / el.EIy + (el.GAz ? (w[2] * sh) / el.GAz : 0)];
|
|
552
|
+
return /** @type {Vec3} */ (toGlobal3(R, local));
|
|
553
|
+
});
|
|
554
|
+
const result = { id: el.id, ...(el.of !== undefined ? { of: el.of } : {}), length: L, axes: /** @type {[Vec3, Vec3, Vec3]} */ ([0, 3, 6].map((o) => Array.from(R.subarray(o, o + 3)))),
|
|
555
|
+
ends: { a: /** @type {Six} */ (Array.from(F.subarray(0, 6))), b: /** @type {Six} */ (Array.from(F.subarray(6, 12))) }, along, peak: /** @type {ElementResult['peak']} */ (peak), axial: value(poly.N, L / 2) };
|
|
556
|
+
if (el.Wy && el.Wz) {
|
|
557
|
+
// |N|/A + |My|/Wy + |Mz|/Wz is a quadratic wherever no term changes sign: its peak is at an end, where a
|
|
558
|
+
// moment peaks (both already stations), or where one of the signed sums is level
|
|
559
|
+
const terms = [[poly.N, 1 / el.A], [poly.My, 1 / el.Wy], [poly.Mz, 1 / el.Wz]], at = (s) => terms.reduce((sum, [c, k]) => sum + Math.abs(value(c, s)) * k, 0), tries = [...xs];
|
|
560
|
+
for (const sy of [1, -1]) for (const sz of [1, -1]) { const c1 = poly.N[1] / el.A + (sy * poly.My[1]) / el.Wy + (sz * poly.Mz[1]) / el.Wz, c2 = (sy * poly.My[2]) / el.Wy + (sz * poly.Mz[2]) / el.Wz; if (c2 !== 0 && inside(-c1 / (2 * c2))) tries.push(-c1 / (2 * c2)); }
|
|
561
|
+
let best = 0, bending = 0;
|
|
562
|
+
for (const s of tries) { if (at(s) > at(best)) best = s; bending = Math.max(bending, Math.abs(value(poly.My, s)) / el.Wy + Math.abs(value(poly.Mz, s)) / el.Wz); }
|
|
563
|
+
result.stress = { peak: at(best), bending, axial: value(poly.N, best) / el.A, x: best };
|
|
564
|
+
}
|
|
565
|
+
return result;
|
|
566
|
+
});
|
|
567
|
+
const six = (v, q) => /** @type {Six} */ (Array.from(v.subarray(6 * q, 6 * q + 6)));
|
|
568
|
+
return { displacements: Object.fromEntries(ids.map((id, q) => [id, six(u, q)])), reactions: Object.fromEntries(f.supported.map((q) => [ids[q], six(residual, q).map((v, d) => (held[6 * q + d] || ground[6 * q + d] ? v : 0))])),
|
|
569
|
+
elements, deflection: { most, node: ids[mostAt] } };
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
function buckling(c = {}) {
|
|
573
|
+
const count = c.count ?? 1;
|
|
574
|
+
if (!(Number.isInteger(count) && count >= 1)) refuse('input', `count is ${said(count)}: how many buckling modes, a whole number from 1`);
|
|
575
|
+
const s = statics(c), axial = s.elements.map((e) => e.axial), size = Math.max(...axial.map(Math.abs));
|
|
576
|
+
if (!axial.some((a) => a < -1e-9 * Math.max(size, 1e-300))) refuse('compression', 'no element is in compression under these loads, so nothing can buckle: buckling needs a load that squeezes at least one element along its length');
|
|
577
|
+
const B = assemble((el) => toGlobal(el.kg, el.R), axial.map((a) => -a)), block = 2 * count + 16;
|
|
578
|
+
// K φ = λ B φ, B = −Kg, for the smallest λ above 0. B is indefinite: with the loads reversed, whatever is in
|
|
579
|
+
// tension would buckle, and those (negative) factors can be far smaller in size and crowd the iteration. So it
|
|
580
|
+
// is shifted to just under the first factor: K − σ B has a Cholesky factor exactly when σ is under it (and over
|
|
581
|
+
// the first negative one), which brackets it between a σ that factorises and one that does not, and the
|
|
582
|
+
// iteration on (K − σ B)⁻¹ B then finds 1 / (λ − σ), where the first factor leads every negative one at least
|
|
583
|
+
// fourfold. (Factors more than about twice the first still have to outlast the negative ones, by a wider block:
|
|
584
|
+
// the first is always quick, the rest only when little is in tension.)
|
|
585
|
+
let high = Infinity, low = 0, shifted = factor;
|
|
586
|
+
for (let i = 0; i < n; i++) { const b = B.v[diagonal(B, i)]; if (b > 0) high = Math.min(high, K.v[diagonal(K, i)] / b); } // one freedom moved alone: no frame buckles later than that
|
|
587
|
+
const rough = lowest(factor.solve, B, 1, block, 1e-3, 4);
|
|
588
|
+
if (rough.values.length) high = Math.min(high, 1 / rough.values[0]); // (a Ritz value is never under the true one)
|
|
589
|
+
if (Number.isFinite(high)) for (let tries = 0, sigma = 0.9 * high; tries < 60 && low < 0.8 * high; tries++, sigma = low ? (low + high) / 2 : high / 2) {
|
|
590
|
+
const A = profile(first);
|
|
591
|
+
for (let i = 0; i < A.v.length; i++) A.v[i] = K.v[i] - sigma * B.v[i];
|
|
592
|
+
const fa = factorise(A);
|
|
593
|
+
if (fa.loose.length) high = sigma; else { low = sigma; shifted = fa; }
|
|
594
|
+
}
|
|
595
|
+
const { values, vectors } = lowest(shifted.solve, B, count, block);
|
|
596
|
+
const modes = values.map((mu, i) => ({ factor: low + 1 / mu, shape: shapeOf(vectors[i]) }));
|
|
597
|
+
return { factors: modes.map((m) => m.factor), modes, statics: s };
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
function modes(c = {}) {
|
|
601
|
+
const count = c.count ?? 6;
|
|
602
|
+
if (!(Number.isInteger(count) && count >= 1)) refuse('input', `count is ${said(count)}: how many modes, a whole number from 1`);
|
|
603
|
+
const { lumped } = loadCase(f, { masses: c.masses ?? model.masses });
|
|
604
|
+
if (!els.some((el) => el.perLength > 0) && !lumped.some((m) => m > 0)) refuse('mass', 'nothing in the frame has mass, so it has no frequencies: give the materials a density (g/cm³), or lump masses (kg) at nodes');
|
|
605
|
+
const M = assemble((el) => toGlobal(el.m, el.R));
|
|
606
|
+
for (let i = 0; i < n; i++) if (back[i] % 6 < 3) M.v[diagonal(M, i)] += lumped[Math.floor(back[i] / 6)];
|
|
607
|
+
const { values, vectors } = lowest(factor.solve, M, count);
|
|
608
|
+
// K in N/mm against M in kg: ω² = 1000 / μ (a newton is a kg·m/s², and the lengths are mm)
|
|
609
|
+
const found = values.map((mu, i) => ({ frequency: Math.sqrt(1000 / mu) / (2 * Math.PI), shape: shapeOf(vectors[i]) }));
|
|
610
|
+
return { frequencies: found.map((m) => m.frequency), modes: found };
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return { statics, buckling, modes, freedoms: n, nodes: ids };
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* How far a frame moves under its loads, and what each element carries. The same as `frame(model).statics()`.
|
|
618
|
+
* @param {FrameModel} model @param {{ shear?: boolean, samples?: number }} [o]
|
|
619
|
+
* @returns {StaticResult}
|
|
620
|
+
*/
|
|
621
|
+
export const statics = (model, o = {}) => frame(model, o).statics(o);
|
|
622
|
+
/**
|
|
623
|
+
* The factors by which a frame's loads must grow to buckle it, lowest first, and the shapes it buckles into: linear
|
|
624
|
+
* buckling, from the geometric stiffness of each element's axial force in the static solve. The first factor is
|
|
625
|
+
* always quick to find; asking for more costs more where slender members are in tension.
|
|
626
|
+
* @param {FrameModel} model @param {{ shear?: boolean, count?: number }} [o] count: how many modes (1)
|
|
627
|
+
* @returns {{ factors: number[], modes: BucklingMode[], statics: StaticResult }}
|
|
628
|
+
*/
|
|
629
|
+
export const buckling = (model, o = {}) => frame(model, o).buckling(o);
|
|
630
|
+
/**
|
|
631
|
+
* A frame's lowest natural frequencies, in Hz, and their shapes, from the elements' consistent mass and the lumped masses.
|
|
632
|
+
* @param {FrameModel} model @param {{ shear?: boolean, count?: number }} [o] count: how many modes (6)
|
|
633
|
+
* @returns {{ frequencies: number[], modes: VibrationMode[] }}
|
|
634
|
+
*/
|
|
635
|
+
export const modes = (model, o = {}) => frame(model, o).modes(o);
|
|
636
|
+
|
|
637
|
+
/**
|
|
638
|
+
* The same frame with every element cut into `pieces` equal lengths, for buckling and modes: one element cannot bow
|
|
639
|
+
* 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
|
|
640
|
+
* nodes are named "<element>/<k>" (or added to the end of a list of nodes), new elements "<element>/<k>" with `of`
|
|
641
|
+
* naming the element they came from; end joints stay at the member's own ends, and spread loads follow their pieces.
|
|
642
|
+
* @param {FrameModel} model @param {number} [pieces] 4
|
|
643
|
+
* @returns {FrameModel}
|
|
644
|
+
*/
|
|
645
|
+
export function subdivide(model, pieces = 4) {
|
|
646
|
+
if (!(Number.isInteger(pieces) && pieces >= 1)) refuse('input', `pieces is ${said(pieces)}: a whole number of pieces for each element, 1 or more`);
|
|
647
|
+
if (!model || typeof model !== 'object' || !model.nodes || !Array.isArray(model.elements)) refuse('input', 'a frame is { nodes, elements, supports, loads }');
|
|
648
|
+
const list = Array.isArray(model.nodes), nodes = list ? [...model.nodes] : { ...model.nodes }, parts = new Map();
|
|
649
|
+
const elements = model.elements.flatMap((e, i) => {
|
|
650
|
+
const id = e.id ?? i, pa = model.nodes[e.a], pb = model.nodes[e.b];
|
|
651
|
+
for (const [end, p] of [[e.a, pa], [e.b, pb]]) if (!isVec3(p)) refuse('node', `element ${said(id)} names node ${said(end)}, which is not in nodes`, { node: end });
|
|
652
|
+
const mid = Array.from({ length: pieces - 1 }, (_, k) => { const t = (k + 1) / pieces, p = /** @type {Vec3} */ (pa.map((v, c) => v + t * (pb[c] - v))); if (list) return nodes.push(p) - 1; nodes[`${id}/${k + 1}`] = p; return `${id}/${k + 1}`; });
|
|
653
|
+
const made = Array.from({ length: pieces }, (_, k) => ({ ...e, id: pieces === 1 ? id : `${id}/${k + 1}`, of: e.of ?? id, a: k ? mid[k - 1] : e.a, b: k < pieces - 1 ? mid[k] : e.b,
|
|
654
|
+
ends: { a: k ? 'rigid' : e.ends?.a ?? 'rigid', b: k < pieces - 1 ? 'rigid' : e.ends?.b ?? 'rigid' } }));
|
|
655
|
+
parts.set(String(id), made.map((m) => m.id));
|
|
656
|
+
return made;
|
|
657
|
+
});
|
|
658
|
+
const loads = (model.loads || []).flatMap((l) => (l && 'element' in l && parts.has(String(l.element)) ? parts.get(String(l.element)).map((element) => ({ ...l, element })) : [l]));
|
|
659
|
+
return { ...model, nodes, elements, ...(model.loads ? { loads } : {}) };
|
|
660
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rulecad/fea",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "How far a part bends under load: finite elements on a grid of squares (2D) or cubes (3D), with a multigrid solver, in plain JavaScript.",
|
|
3
|
+
"version": "0.2.10",
|
|
4
|
+
"description": "How far a part bends under load: finite elements on a grid of squares (2D) or cubes (3D), with a multigrid solver, and frames of beams (static, buckling and modes), in plain JavaScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
"./threads": {
|
|
12
12
|
"types": "./threads.d.mts",
|
|
13
13
|
"default": "./threads.mjs"
|
|
14
|
+
},
|
|
15
|
+
"./frame": {
|
|
16
|
+
"types": "./frame.d.mts",
|
|
17
|
+
"default": "./frame.mjs"
|
|
14
18
|
}
|
|
15
19
|
},
|
|
16
20
|
"files": [
|
|
@@ -19,7 +23,9 @@
|
|
|
19
23
|
"README.md",
|
|
20
24
|
"LICENSE",
|
|
21
25
|
"threads.mjs",
|
|
22
|
-
"threads.d.mts"
|
|
26
|
+
"threads.d.mts",
|
|
27
|
+
"frame.mjs",
|
|
28
|
+
"frame.d.mts"
|
|
23
29
|
],
|
|
24
30
|
"license": "MIT",
|
|
25
31
|
"keywords": [
|
|
@@ -27,7 +33,11 @@
|
|
|
27
33
|
"finite-elements",
|
|
28
34
|
"stiffness",
|
|
29
35
|
"stress",
|
|
30
|
-
"plane-stress"
|
|
36
|
+
"plane-stress",
|
|
37
|
+
"frames",
|
|
38
|
+
"beams",
|
|
39
|
+
"buckling",
|
|
40
|
+
"modal-analysis"
|
|
31
41
|
],
|
|
32
42
|
"engines": {
|
|
33
43
|
"node": ">=20"
|