@ferscloud/fers-calculation 0.2.75 → 0.2.77

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
@@ -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.
@@ -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
@@ -49,6 +49,57 @@ function calculate_from_json_with_token(json_data, solve_token) {
49
49
  }
50
50
  exports.calculate_from_json_with_token = calculate_from_json_with_token;
51
51
 
52
+ /**
53
+ * Free-tier solve of part `part_index` of `part_count` of the model's load
54
+ * combinations. Returns an envelope whose result only the merge reads.
55
+ * @param {string} json_data
56
+ * @param {number} part_index
57
+ * @param {number} part_count
58
+ * @returns {string}
59
+ */
60
+ function calculate_part_from_json(json_data, part_index, part_count) {
61
+ let deferred2_0;
62
+ let deferred2_1;
63
+ try {
64
+ const ptr0 = passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
65
+ const len0 = WASM_VECTOR_LEN;
66
+ const ret = wasm.calculate_part_from_json(ptr0, len0, part_index, part_count);
67
+ deferred2_0 = ret[0];
68
+ deferred2_1 = ret[1];
69
+ return getStringFromWasm0(ret[0], ret[1]);
70
+ } finally {
71
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
72
+ }
73
+ }
74
+ exports.calculate_part_from_json = calculate_part_from_json;
75
+
76
+ /**
77
+ * [`calculate_part_from_json`] at the tier `solve_token` grants, as
78
+ * [`calculate_from_json_with_token`] decides it.
79
+ * @param {string} json_data
80
+ * @param {string} solve_token
81
+ * @param {number} part_index
82
+ * @param {number} part_count
83
+ * @returns {string}
84
+ */
85
+ function calculate_part_from_json_with_token(json_data, solve_token, part_index, part_count) {
86
+ let deferred3_0;
87
+ let deferred3_1;
88
+ try {
89
+ const ptr0 = passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
90
+ const len0 = WASM_VECTOR_LEN;
91
+ const ptr1 = passStringToWasm0(solve_token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
92
+ const len1 = WASM_VECTOR_LEN;
93
+ const ret = wasm.calculate_part_from_json_with_token(ptr0, len0, ptr1, len1, part_index, part_count);
94
+ deferred3_0 = ret[0];
95
+ deferred3_1 = ret[1];
96
+ return getStringFromWasm0(ret[0], ret[1]);
97
+ } finally {
98
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
99
+ }
100
+ }
101
+ exports.calculate_part_from_json_with_token = calculate_part_from_json_with_token;
102
+
52
103
  /**
53
104
  * Parse (without solving) a model from a file path and return it as the JSON
54
105
  * envelope: `{"ok":true,"result": <FERS JSON> }` or an error envelope.
@@ -71,6 +122,58 @@ function load_fers_from_file(path) {
71
122
  }
72
123
  exports.load_fers_from_file = load_fers_from_file;
73
124
 
125
+ /**
126
+ * Merge free-tier parts into the result of one solve. `parts` are the strings
127
+ * the parts returned, in index order.
128
+ * @param {string} json_data
129
+ * @param {string[]} parts
130
+ * @returns {string}
131
+ */
132
+ function merge_parts_from_json(json_data, parts) {
133
+ let deferred3_0;
134
+ let deferred3_1;
135
+ try {
136
+ const ptr0 = passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
137
+ const len0 = WASM_VECTOR_LEN;
138
+ const ptr1 = passArrayJsValueToWasm0(parts, wasm.__wbindgen_malloc);
139
+ const len1 = WASM_VECTOR_LEN;
140
+ const ret = wasm.merge_parts_from_json(ptr0, len0, ptr1, len1);
141
+ deferred3_0 = ret[0];
142
+ deferred3_1 = ret[1];
143
+ return getStringFromWasm0(ret[0], ret[1]);
144
+ } finally {
145
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
146
+ }
147
+ }
148
+ exports.merge_parts_from_json = merge_parts_from_json;
149
+
150
+ /**
151
+ * Merge parts solved with `solve_token`; pass the token the parts were given.
152
+ * @param {string} json_data
153
+ * @param {string} solve_token
154
+ * @param {string[]} parts
155
+ * @returns {string}
156
+ */
157
+ function merge_parts_from_json_with_token(json_data, solve_token, parts) {
158
+ let deferred4_0;
159
+ let deferred4_1;
160
+ try {
161
+ const ptr0 = passStringToWasm0(json_data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
162
+ const len0 = WASM_VECTOR_LEN;
163
+ const ptr1 = passStringToWasm0(solve_token, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
164
+ const len1 = WASM_VECTOR_LEN;
165
+ const ptr2 = passArrayJsValueToWasm0(parts, wasm.__wbindgen_malloc);
166
+ const len2 = WASM_VECTOR_LEN;
167
+ const ret = wasm.merge_parts_from_json_with_token(ptr0, len0, ptr1, len1, ptr2, len2);
168
+ deferred4_0 = ret[0];
169
+ deferred4_1 = ret[1];
170
+ return getStringFromWasm0(ret[0], ret[1]);
171
+ } finally {
172
+ wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
173
+ }
174
+ }
175
+ exports.merge_parts_from_json_with_token = merge_parts_from_json_with_token;
176
+
74
177
  /**
75
178
  * Re-render unity-check reports from already-solved results (no re-solve). Fills
76
179
  * each `rendered_report` from its check's `report_template` and rebuilds
@@ -129,6 +232,14 @@ exports.wasm_init = wasm_init;
129
232
  function __wbg_get_imports() {
130
233
  const import0 = {
131
234
  __proto__: null,
235
+ __wbg___wbindgen_string_get_0380ccaa2f57f0d9: function(arg0, arg1) {
236
+ const obj = arg1;
237
+ const ret = typeof(obj) === 'string' ? obj : undefined;
238
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
239
+ var len1 = WASM_VECTOR_LEN;
240
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
241
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
242
+ },
132
243
  __wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
133
244
  throw new Error(getStringFromWasm0(arg0, arg1));
134
245
  },
@@ -174,6 +285,12 @@ function __wbg_get_imports() {
174
285
  };
175
286
  }
176
287
 
288
+ function addToExternrefTable0(obj) {
289
+ const idx = wasm.__externref_table_alloc();
290
+ wasm.__wbindgen_externrefs.set(idx, obj);
291
+ return idx;
292
+ }
293
+
177
294
  let cachedDataViewMemory0 = null;
178
295
  function getDataViewMemory0() {
179
296
  if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
@@ -194,6 +311,20 @@ function getUint8ArrayMemory0() {
194
311
  return cachedUint8ArrayMemory0;
195
312
  }
196
313
 
314
+ function isLikeNone(x) {
315
+ return x === undefined || x === null;
316
+ }
317
+
318
+ function passArrayJsValueToWasm0(array, malloc) {
319
+ const ptr = malloc(array.length * 4, 4) >>> 0;
320
+ for (let i = 0; i < array.length; i++) {
321
+ const add = addToExternrefTable0(array[i]);
322
+ getDataViewMemory0().setUint32(ptr + 4 * i, add, true);
323
+ }
324
+ WASM_VECTOR_LEN = array.length;
325
+ return ptr;
326
+ }
327
+
197
328
  function passStringToWasm0(arg, malloc, realloc) {
198
329
  if (realloc === undefined) {
199
330
  const buf = cachedTextEncoder.encode(arg);
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ferscloud/fers-calculation",
3
- "version": "0.2.75",
3
+ "version": "0.2.77",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "repository": {
6
6
  "type": "git",