@rulecad/fea 0.2.8 → 0.2.9

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 CHANGED
@@ -42,7 +42,10 @@ r.thin; // { share, cells }: how much of the part is in members under
42
42
  symmetric Gauss-Seidel through those blocks.
43
43
  - **Threads:** `import { threadsBackend } from '@rulecad/fea/threads'` (Node only) shares each product over the
44
44
  machine's cores (`FEA_THREADS` to say how many), the rest as `jsBackend`. On a 134,000-unknown grid a product takes
45
- 6.8 ms on seven threads against 19 ms on one, and an optimisation step about a third of the time.
45
+ 6.8 ms on seven threads against 19 ms on one, and an optimisation step about a third of the time. It needs Node 22
46
+ or later: on Node 20 a product now and then came out wrong when the workers let go of an old operator's shared
47
+ memory (a few solves in sixty, more with more threads, none on Node 22 or 24), so there it is plain JavaScript
48
+ under another name (its `name` says so).
46
49
 
47
50
  Tested against beam theory: a cantilever's tip moves within 1% of `F L³ / 3 E I` in 2D, and within 2% in 3D.
48
51
  Multigrid is tested against the direct solver with stiffnesses a millionfold apart.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/fea",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
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.",
5
5
  "type": "module",
6
6
  "exports": {
package/threads.d.mts CHANGED
@@ -1,10 +1,10 @@
1
- export namespace threadsBackend {
2
- let name: string;
3
- let precision: number;
4
- function operator(g: any, ke: any, cellMatrices: any): {
5
- multiply(scale: any, x: any, y: any): void;
6
- diagonal(scale: any, d: any): void;
1
+ export const threadsBackend: {
2
+ name: string;
3
+ precision: number;
4
+ operator: (g: import("./fea.mjs").Grid, ke: Float64Array | null, cellMatrices?: Float64Array) => {
5
+ multiply: (scale: Float64Array | null, x: Float64Array, y: Float64Array) => void;
6
+ diagonal: (scale: Float64Array | null, d: Float64Array) => void;
7
7
  };
8
- let dot: (a: Float64Array, b: Float64Array) => number;
9
- let axpy: (a: number, x: Float64Array, y: Float64Array) => void;
10
- }
8
+ dot: (a: Float64Array, b: Float64Array) => number;
9
+ axpy: (a: number, x: Float64Array, y: Float64Array) => void;
10
+ };
package/threads.mjs CHANGED
@@ -48,7 +48,12 @@ function workers() {
48
48
  return pool;
49
49
  }
50
50
 
51
- export const threadsBackend = {
51
+ // On Node 20 and older the products came out wrong now and then (a few solves in sixty, more with more threads):
52
+ // letting go of an operator's shared memory there corrupts work still running on it, and Node 20 is past its end of
53
+ // life. There, this backend is plain JavaScript under another name: right, only slower. (Node 22 and later: threads)
54
+ const NODE = Number(process.versions.node.split('.')[0]), SHARED_OK = NODE >= 22;
55
+
56
+ export const threadsBackend = !SHARED_OK ? { ...jsBackend, name: `js (threads need Node 22; this is Node ${NODE})` } : {
52
57
  name: `threads (${THREADS})`,
53
58
  precision: 64,
54
59
  operator(g, ke, cellMatrices) {