@ferscloud/fers-calculation-web 0.2.74 → 0.2.76
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 +31 -0
- package/fers-models.d.ts +16 -3
- package/fers_calculations.d.ts +23 -0
- package/fers_calculations.js +1 -1
- package/fers_calculations_bg.js +127 -0
- package/fers_calculations_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -161,6 +161,37 @@ If the token is missing, expired, or invalid, the solver falls back to the free
|
|
|
161
161
|
| Requires token | No | Yes |
|
|
162
162
|
| Token TTL | — | 30 minutes |
|
|
163
163
|
|
|
164
|
+
## Several cores: solving in parts
|
|
165
|
+
|
|
166
|
+
One WASM instance solves on one thread. To spread a model's load combinations over several workers (Web Workers in a browser, `worker_threads` in Node), give every worker the same model string and its own part, and merge what they return:
|
|
167
|
+
|
|
168
|
+
```js
|
|
169
|
+
// worker.js: one per core
|
|
170
|
+
import { calculate_part_from_json } from "@ferscloud/fers-calculation-web";
|
|
171
|
+
|
|
172
|
+
self.onmessage = ({ data: { model, index, count } }) => {
|
|
173
|
+
self.postMessage(calculate_part_from_json(model, index, count));
|
|
174
|
+
};
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
```js
|
|
178
|
+
// main thread
|
|
179
|
+
import { merge_parts_from_json } from "@ferscloud/fers-calculation-web";
|
|
180
|
+
|
|
181
|
+
const model = JSON.stringify(myModel); // one string, the same bytes everywhere
|
|
182
|
+
const count = workers.length;
|
|
183
|
+
const parts = await Promise.all(
|
|
184
|
+
workers.map((worker, index) => solveIn(worker, { model, index, count })) // resolves with the worker's string
|
|
185
|
+
);
|
|
186
|
+
const res = JSON.parse(merge_parts_from_json(model, parts)); // what calculate_from_json returns
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
- The merged envelope is byte for byte what `calculate_from_json` returns for the same model. If a part failed, the merge returns that part's error envelope, the one a single solve would have stopped on.
|
|
190
|
+
- Pass the parts unopened and in index order. The merge reads them itself; parsing them in JavaScript only costs time.
|
|
191
|
+
- Only the combinations are divided. Every part reads the whole model and, whenever one solve would, solves the load cases, so each combination starts where it would in one solve; part 0 also reports the load cases and runs the modal, buckling and seismic analyses. Combinations that share a name always fall in the same part.
|
|
192
|
+
- Each worker holds its own copy of the model and of its solve, so memory grows with the number of workers.
|
|
193
|
+
- With a solve token, use `calculate_part_from_json_with_token(model, token, index, count)` in the workers and `merge_parts_from_json_with_token(model, token, parts)` to merge.
|
|
194
|
+
|
|
164
195
|
## Security note
|
|
165
196
|
|
|
166
197
|
Keep your `FERS_API_KEY` server-side only. The solve token it fetches is safe to pass to the browser — it is short-lived and cryptographically signed. Only FERS Cloud can issue valid tokens; the browser WASM can only verify them.
|
package/fers-models.d.ts
CHANGED
|
@@ -68,6 +68,9 @@ export interface components {
|
|
|
68
68
|
* self-weight load case (see `self_weight_load_case_id`). Cable members
|
|
69
69
|
* carry their weight intrinsically in the catenary formulation and are
|
|
70
70
|
* therefore excluded from the generated self-weight load.
|
|
71
|
+
* A load combination carries self-weight only if it includes that load
|
|
72
|
+
* case. When the model has combinations and none of them does, every
|
|
73
|
+
* combination carries the warning `self_weight_not_in_combinations`.
|
|
71
74
|
* @default false
|
|
72
75
|
*/
|
|
73
76
|
enable_self_weight: boolean;
|
|
@@ -204,7 +207,8 @@ export interface components {
|
|
|
204
207
|
* @description Target load case id that generated self-weight loads are injected into.
|
|
205
208
|
* When set, the loads are added to that (typically empty "G") load case so
|
|
206
209
|
* combinations can factor it (e.g. 1.35·G). When `None` and self-weight is
|
|
207
|
-
* enabled, a new load case is created
|
|
210
|
+
* enabled, a new "Self-weight" load case is created with the highest load
|
|
211
|
+
* case id + 1, and no combination includes it unless it lists that id.
|
|
208
212
|
*/
|
|
209
213
|
self_weight_load_case_id?: number | null;
|
|
210
214
|
solve_loadcases: boolean;
|
|
@@ -525,7 +529,7 @@ export interface components {
|
|
|
525
529
|
};
|
|
526
530
|
/**
|
|
527
531
|
* @description One line of the transparent hand-calc: a symbolic formula, the same formula
|
|
528
|
-
* with real numbers substituted, and the resulting value
|
|
532
|
+
* with real numbers substituted, and the resulting value (display units).
|
|
529
533
|
*/
|
|
530
534
|
CalcStep: {
|
|
531
535
|
/**
|
|
@@ -549,8 +553,17 @@ export interface components {
|
|
|
549
553
|
formula: string;
|
|
550
554
|
label: string;
|
|
551
555
|
substituted: string;
|
|
556
|
+
/**
|
|
557
|
+
* @description The unit of `demand` and `capacity` on a row that carries them — not of
|
|
558
|
+
* `value`, which is then a ratio. On any other row, the unit of `value`;
|
|
559
|
+
* empty when that is dimensionless.
|
|
560
|
+
*/
|
|
552
561
|
unit: string;
|
|
553
|
-
/**
|
|
562
|
+
/**
|
|
563
|
+
* Format: double
|
|
564
|
+
* @description The row's result. On a row with `demand` it is the utilization ratio,
|
|
565
|
+
* dimensionless whatever `unit` says.
|
|
566
|
+
*/
|
|
554
567
|
value: number;
|
|
555
568
|
};
|
|
556
569
|
/**
|
package/fers_calculations.d.ts
CHANGED
|
@@ -15,12 +15,35 @@ export function calculate_from_json(json_data: string): string;
|
|
|
15
15
|
*/
|
|
16
16
|
export function calculate_from_json_with_token(json_data: string, solve_token: string): string;
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Free-tier solve of part `part_index` of `part_count` of the model's load
|
|
20
|
+
* combinations. Returns an envelope whose result only the merge reads.
|
|
21
|
+
*/
|
|
22
|
+
export function calculate_part_from_json(json_data: string, part_index: number, part_count: number): string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* [`calculate_part_from_json`] at the tier `solve_token` grants, as
|
|
26
|
+
* [`calculate_from_json_with_token`] decides it.
|
|
27
|
+
*/
|
|
28
|
+
export function calculate_part_from_json_with_token(json_data: string, solve_token: string, part_index: number, part_count: number): string;
|
|
29
|
+
|
|
18
30
|
/**
|
|
19
31
|
* Parse (without solving) a model from a file path and return it as the JSON
|
|
20
32
|
* envelope: `{"ok":true,"result": <FERS JSON> }` or an error envelope.
|
|
21
33
|
*/
|
|
22
34
|
export function load_fers_from_file(path: string): string;
|
|
23
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Merge free-tier parts into the result of one solve. `parts` are the strings
|
|
38
|
+
* the parts returned, in index order.
|
|
39
|
+
*/
|
|
40
|
+
export function merge_parts_from_json(json_data: string, parts: string[]): string;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Merge parts solved with `solve_token`; pass the token the parts were given.
|
|
44
|
+
*/
|
|
45
|
+
export function merge_parts_from_json_with_token(json_data: string, solve_token: string, parts: string[]): string;
|
|
46
|
+
|
|
24
47
|
/**
|
|
25
48
|
* Re-render unity-check reports from already-solved results (no re-solve). Fills
|
|
26
49
|
* each `rendered_report` from its check's `report_template` and rebuilds
|
package/fers_calculations.js
CHANGED
|
@@ -5,5 +5,5 @@ import { __wbg_set_wasm } from "./fers_calculations_bg.js";
|
|
|
5
5
|
__wbg_set_wasm(wasm);
|
|
6
6
|
wasm.__wbindgen_start();
|
|
7
7
|
export {
|
|
8
|
-
calculate_from_json, calculate_from_json_with_token, load_fers_from_file, render_reports_from_json, version, wasm_init
|
|
8
|
+
calculate_from_json, calculate_from_json_with_token, calculate_part_from_json, calculate_part_from_json_with_token, load_fers_from_file, merge_parts_from_json, merge_parts_from_json_with_token, render_reports_from_json, version, wasm_init
|
|
9
9
|
} from "./fers_calculations_bg.js";
|
package/fers_calculations_bg.js
CHANGED
|
@@ -45,6 +45,55 @@ export function calculate_from_json_with_token(json_data, solve_token) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* Free-tier solve of part `part_index` of `part_count` of the model's load
|
|
50
|
+
* combinations. Returns an envelope whose result only the merge reads.
|
|
51
|
+
* @param {string} json_data
|
|
52
|
+
* @param {number} part_index
|
|
53
|
+
* @param {number} part_count
|
|
54
|
+
* @returns {string}
|
|
55
|
+
*/
|
|
56
|
+
export function calculate_part_from_json(json_data, part_index, part_count) {
|
|
57
|
+
let deferred2_0;
|
|
58
|
+
let deferred2_1;
|
|
59
|
+
try {
|
|
60
|
+
const ptr0 = passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
61
|
+
const len0 = WASM_VECTOR_LEN;
|
|
62
|
+
const ret = wasm.calculate_part_from_json(ptr0, len0, part_index, part_count);
|
|
63
|
+
deferred2_0 = ret[0];
|
|
64
|
+
deferred2_1 = ret[1];
|
|
65
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
66
|
+
} finally {
|
|
67
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* [`calculate_part_from_json`] at the tier `solve_token` grants, as
|
|
73
|
+
* [`calculate_from_json_with_token`] decides it.
|
|
74
|
+
* @param {string} json_data
|
|
75
|
+
* @param {string} solve_token
|
|
76
|
+
* @param {number} part_index
|
|
77
|
+
* @param {number} part_count
|
|
78
|
+
* @returns {string}
|
|
79
|
+
*/
|
|
80
|
+
export function calculate_part_from_json_with_token(json_data, solve_token, part_index, part_count) {
|
|
81
|
+
let deferred3_0;
|
|
82
|
+
let deferred3_1;
|
|
83
|
+
try {
|
|
84
|
+
const ptr0 = passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
85
|
+
const len0 = WASM_VECTOR_LEN;
|
|
86
|
+
const ptr1 = passStringToWasm0(solve_token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
87
|
+
const len1 = WASM_VECTOR_LEN;
|
|
88
|
+
const ret = wasm.calculate_part_from_json_with_token(ptr0, len0, ptr1, len1, part_index, part_count);
|
|
89
|
+
deferred3_0 = ret[0];
|
|
90
|
+
deferred3_1 = ret[1];
|
|
91
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
92
|
+
} finally {
|
|
93
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
48
97
|
/**
|
|
49
98
|
* Parse (without solving) a model from a file path and return it as the JSON
|
|
50
99
|
* envelope: `{"ok":true,"result": <FERS JSON> }` or an error envelope.
|
|
@@ -66,6 +115,56 @@ export function load_fers_from_file(path) {
|
|
|
66
115
|
}
|
|
67
116
|
}
|
|
68
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Merge free-tier parts into the result of one solve. `parts` are the strings
|
|
120
|
+
* the parts returned, in index order.
|
|
121
|
+
* @param {string} json_data
|
|
122
|
+
* @param {string[]} parts
|
|
123
|
+
* @returns {string}
|
|
124
|
+
*/
|
|
125
|
+
export function merge_parts_from_json(json_data, parts) {
|
|
126
|
+
let deferred3_0;
|
|
127
|
+
let deferred3_1;
|
|
128
|
+
try {
|
|
129
|
+
const ptr0 = passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
130
|
+
const len0 = WASM_VECTOR_LEN;
|
|
131
|
+
const ptr1 = passArrayJsValueToWasm0(parts, wasm.__wbindgen_malloc);
|
|
132
|
+
const len1 = WASM_VECTOR_LEN;
|
|
133
|
+
const ret = wasm.merge_parts_from_json(ptr0, len0, ptr1, len1);
|
|
134
|
+
deferred3_0 = ret[0];
|
|
135
|
+
deferred3_1 = ret[1];
|
|
136
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
137
|
+
} finally {
|
|
138
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Merge parts solved with `solve_token`; pass the token the parts were given.
|
|
144
|
+
* @param {string} json_data
|
|
145
|
+
* @param {string} solve_token
|
|
146
|
+
* @param {string[]} parts
|
|
147
|
+
* @returns {string}
|
|
148
|
+
*/
|
|
149
|
+
export function merge_parts_from_json_with_token(json_data, solve_token, parts) {
|
|
150
|
+
let deferred4_0;
|
|
151
|
+
let deferred4_1;
|
|
152
|
+
try {
|
|
153
|
+
const ptr0 = passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
154
|
+
const len0 = WASM_VECTOR_LEN;
|
|
155
|
+
const ptr1 = passStringToWasm0(solve_token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
156
|
+
const len1 = WASM_VECTOR_LEN;
|
|
157
|
+
const ptr2 = passArrayJsValueToWasm0(parts, wasm.__wbindgen_malloc);
|
|
158
|
+
const len2 = WASM_VECTOR_LEN;
|
|
159
|
+
const ret = wasm.merge_parts_from_json_with_token(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
160
|
+
deferred4_0 = ret[0];
|
|
161
|
+
deferred4_1 = ret[1];
|
|
162
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
163
|
+
} finally {
|
|
164
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
69
168
|
/**
|
|
70
169
|
* Re-render unity-check reports from already-solved results (no re-solve). Fills
|
|
71
170
|
* each `rendered_report` from its check's `report_template` and rebuilds
|
|
@@ -118,6 +217,14 @@ export function version() {
|
|
|
118
217
|
export function wasm_init() {
|
|
119
218
|
wasm.wasm_init();
|
|
120
219
|
}
|
|
220
|
+
export function __wbg___wbindgen_string_get_0380ccaa2f57f0d9(arg0, arg1) {
|
|
221
|
+
const obj = arg1;
|
|
222
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
223
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
224
|
+
var len1 = WASM_VECTOR_LEN;
|
|
225
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
226
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
227
|
+
}
|
|
121
228
|
export function __wbg___wbindgen_throw_41e9ee4f547fc59a(arg0, arg1) {
|
|
122
229
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
123
230
|
}
|
|
@@ -156,6 +263,12 @@ export function __wbindgen_init_externref_table() {
|
|
|
156
263
|
table.set(offset + 2, true);
|
|
157
264
|
table.set(offset + 3, false);
|
|
158
265
|
}
|
|
266
|
+
function addToExternrefTable0(obj) {
|
|
267
|
+
const idx = wasm.__externref_table_alloc();
|
|
268
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
269
|
+
return idx;
|
|
270
|
+
}
|
|
271
|
+
|
|
159
272
|
let cachedDataViewMemory0 = null;
|
|
160
273
|
function getDataViewMemory0() {
|
|
161
274
|
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
@@ -176,6 +289,20 @@ function getUint8ArrayMemory0() {
|
|
|
176
289
|
return cachedUint8ArrayMemory0;
|
|
177
290
|
}
|
|
178
291
|
|
|
292
|
+
function isLikeNone(x) {
|
|
293
|
+
return x === undefined || x === null;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function passArrayJsValueToWasm0(array, malloc) {
|
|
297
|
+
const ptr = malloc(array.length * 4, 4) >>> 0;
|
|
298
|
+
for (let i = 0; i < array.length; i++) {
|
|
299
|
+
const add = addToExternrefTable0(array[i]);
|
|
300
|
+
getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
|
|
301
|
+
}
|
|
302
|
+
WASM_VECTOR_LEN = array.length;
|
|
303
|
+
return ptr;
|
|
304
|
+
}
|
|
305
|
+
|
|
179
306
|
function passStringToWasm0(arg, malloc, realloc) {
|
|
180
307
|
if (realloc === undefined) {
|
|
181
308
|
const buf = cachedTextEncoder.encode(arg);
|
|
Binary file
|