diff-grok 1.0.8

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.
Files changed (136) hide show
  1. package/.eslintrc.json +45 -0
  2. package/.github/scripts/bump-js-api-version.sh +106 -0
  3. package/.github/scripts/check-output.sh +20 -0
  4. package/.github/scripts/iac-cfn-deploy.sh +90 -0
  5. package/.github/scripts/slack_api_request.sh +65 -0
  6. package/.github/scripts/test_package.sh +270 -0
  7. package/.github/workflows/libraries.yaml +305 -0
  8. package/LICENSE +21 -0
  9. package/README.MD +396 -0
  10. package/eslintrc.json +45 -0
  11. package/images/acid-prod.gif +0 -0
  12. package/index.js +6 -0
  13. package/index.js.map +1 -0
  14. package/index.ts +15 -0
  15. package/package.json +45 -0
  16. package/src/examples/basic-use.js +40 -0
  17. package/src/examples/basic-use.js.map +1 -0
  18. package/src/examples/basic-use.ts +44 -0
  19. package/src/examples/check-methods.js +45 -0
  20. package/src/examples/check-methods.js.map +1 -0
  21. package/src/examples/check-methods.ts +62 -0
  22. package/src/examples/corr-probs.js +130 -0
  23. package/src/examples/corr-probs.js.map +1 -0
  24. package/src/examples/corr-probs.ts +151 -0
  25. package/src/examples/cyclic-model.js +100 -0
  26. package/src/examples/cyclic-model.js.map +1 -0
  27. package/src/examples/cyclic-model.ts +110 -0
  28. package/src/examples/e5.js +30 -0
  29. package/src/examples/e5.js.map +1 -0
  30. package/src/examples/e5.ts +29 -0
  31. package/src/examples/hires.js +29 -0
  32. package/src/examples/hires.js.map +1 -0
  33. package/src/examples/hires.ts +29 -0
  34. package/src/examples/index.js +17 -0
  35. package/src/examples/index.js.map +1 -0
  36. package/src/examples/index.ts +18 -0
  37. package/src/examples/model-updates.js +112 -0
  38. package/src/examples/model-updates.js.map +1 -0
  39. package/src/examples/model-updates.ts +122 -0
  40. package/src/examples/orego.js +19 -0
  41. package/src/examples/orego.js.map +1 -0
  42. package/src/examples/orego.ts +19 -0
  43. package/src/examples/pipeline-use.js +87 -0
  44. package/src/examples/pipeline-use.js.map +1 -0
  45. package/src/examples/pipeline-use.ts +98 -0
  46. package/src/examples/pollution.js +110 -0
  47. package/src/examples/pollution.js.map +1 -0
  48. package/src/examples/pollution.ts +110 -0
  49. package/src/examples/robertson.js +14 -0
  50. package/src/examples/robertson.js.map +1 -0
  51. package/src/examples/robertson.ts +13 -0
  52. package/src/examples/scripting.js +31 -0
  53. package/src/examples/scripting.js.map +1 -0
  54. package/src/examples/scripting.ts +36 -0
  55. package/src/examples/vdpol.js +13 -0
  56. package/src/examples/vdpol.js.map +1 -0
  57. package/src/examples/vdpol.ts +12 -0
  58. package/src/pipeline/basic-pipeline-creator.js +21 -0
  59. package/src/pipeline/basic-pipeline-creator.js.map +1 -0
  60. package/src/pipeline/basic-pipeline-creator.ts +24 -0
  61. package/src/pipeline/constants.js +21 -0
  62. package/src/pipeline/constants.js.map +1 -0
  63. package/src/pipeline/constants.ts +21 -0
  64. package/src/pipeline/index.js +8 -0
  65. package/src/pipeline/index.js.map +1 -0
  66. package/src/pipeline/index.ts +7 -0
  67. package/src/pipeline/input.js +45 -0
  68. package/src/pipeline/input.js.map +1 -0
  69. package/src/pipeline/input.ts +55 -0
  70. package/src/pipeline/loops-pipeline-creator.js +107 -0
  71. package/src/pipeline/loops-pipeline-creator.js.map +1 -0
  72. package/src/pipeline/loops-pipeline-creator.ts +138 -0
  73. package/src/pipeline/output.js +146 -0
  74. package/src/pipeline/output.js.map +1 -0
  75. package/src/pipeline/output.ts +196 -0
  76. package/src/pipeline/pipeline-creator.js +10 -0
  77. package/src/pipeline/pipeline-creator.js.map +1 -0
  78. package/src/pipeline/pipeline-creator.ts +16 -0
  79. package/src/pipeline/pipeline.js +71 -0
  80. package/src/pipeline/pipeline.js.map +1 -0
  81. package/src/pipeline/pipeline.ts +104 -0
  82. package/src/pipeline/updates-pipeline-creator.js +98 -0
  83. package/src/pipeline/updates-pipeline-creator.js.map +1 -0
  84. package/src/pipeline/updates-pipeline-creator.ts +125 -0
  85. package/src/scripting-tools/constants.js +53 -0
  86. package/src/scripting-tools/constants.js.map +1 -0
  87. package/src/scripting-tools/constants.ts +51 -0
  88. package/src/scripting-tools/index.js +4 -0
  89. package/src/scripting-tools/index.js.map +1 -0
  90. package/src/scripting-tools/index.ts +7 -0
  91. package/src/scripting-tools/model-error.js +17 -0
  92. package/src/scripting-tools/model-error.js.map +1 -0
  93. package/src/scripting-tools/model-error.ts +19 -0
  94. package/src/scripting-tools/scripting-tools.js +1032 -0
  95. package/src/scripting-tools/scripting-tools.js.map +1 -0
  96. package/src/scripting-tools/scripting-tools.ts +1375 -0
  97. package/src/solver-tools/callbacks/callback-base.js +10 -0
  98. package/src/solver-tools/callbacks/callback-base.js.map +1 -0
  99. package/src/solver-tools/callbacks/callback-base.ts +8 -0
  100. package/src/solver-tools/callbacks/callback-tools.js +14 -0
  101. package/src/solver-tools/callbacks/callback-tools.js.map +1 -0
  102. package/src/solver-tools/callbacks/callback-tools.ts +20 -0
  103. package/src/solver-tools/callbacks/iter-checker-callback.js +16 -0
  104. package/src/solver-tools/callbacks/iter-checker-callback.js.map +1 -0
  105. package/src/solver-tools/callbacks/iter-checker-callback.ts +21 -0
  106. package/src/solver-tools/callbacks/time-checker-callback.js +17 -0
  107. package/src/solver-tools/callbacks/time-checker-callback.js.map +1 -0
  108. package/src/solver-tools/callbacks/time-checker-callback.ts +19 -0
  109. package/src/solver-tools/index.js +6 -0
  110. package/src/solver-tools/index.js.map +1 -0
  111. package/src/solver-tools/index.ts +6 -0
  112. package/src/solver-tools/lin-alg-tools.js +56 -0
  113. package/src/solver-tools/lin-alg-tools.js.map +1 -0
  114. package/src/solver-tools/lin-alg-tools.ts +75 -0
  115. package/src/solver-tools/mrt-method.js +210 -0
  116. package/src/solver-tools/mrt-method.js.map +1 -0
  117. package/src/solver-tools/mrt-method.ts +269 -0
  118. package/src/solver-tools/ros34prw-method.js +257 -0
  119. package/src/solver-tools/ros34prw-method.js.map +1 -0
  120. package/src/solver-tools/ros34prw-method.ts +335 -0
  121. package/src/solver-tools/ros3prw-method.js +233 -0
  122. package/src/solver-tools/ros3prw-method.js.map +1 -0
  123. package/src/solver-tools/ros3prw-method.ts +304 -0
  124. package/src/solver-tools/solver-defs.js +58 -0
  125. package/src/solver-tools/solver-defs.js.map +1 -0
  126. package/src/solver-tools/solver-defs.ts +100 -0
  127. package/src/worker-tools/index.js +3 -0
  128. package/src/worker-tools/index.js.map +1 -0
  129. package/src/worker-tools/index.ts +2 -0
  130. package/src/worker-tools/scripting.js +68 -0
  131. package/src/worker-tools/scripting.js.map +1 -0
  132. package/src/worker-tools/scripting.ts +95 -0
  133. package/src/worker-tools/solving.js +48 -0
  134. package/src/worker-tools/solving.js.map +1 -0
  135. package/src/worker-tools/solving.ts +60 -0
  136. package/tsconfig.json +71 -0
@@ -0,0 +1,304 @@
1
+ /* The ROS3PRw method implementation
2
+
3
+ References:
4
+ [1] https://doi.org/10.1016/j.cam.2015.03.010 */
5
+
6
+ import {ODEs, max, abs, SAFETY, PSHRNK, PSGROW, REDUCE_COEF, GROW_COEF,
7
+ ERR_CONTR, TINY, EPS, tDerivative, jacobian, ERROR_MSG} from './solver-defs';
8
+ import {Callback} from './callbacks/callback-base';
9
+ import {luDecomp, luSolve, solve1d2d} from './lin-alg-tools';
10
+
11
+ // The method specific constants (see Table 2 [1])
12
+ const GAMMA = 0.78867513459481287;
13
+
14
+ const GAMMA_21 = -2.3660254037844388;
15
+ const GAMMA_21_SCALED = GAMMA_21 / GAMMA;
16
+ const GAMMA_2 = GAMMA_21 + GAMMA;
17
+
18
+ const GAMMA_31 = -0.86791218280355165;
19
+ const GAMMA_31_SCALED = GAMMA_31 / GAMMA;
20
+ const GAMMA_32 = -0.87306695894642317;
21
+ const GAMMA_32_SCALED = GAMMA_32 / GAMMA;
22
+ const GAMMA_3 = GAMMA_31 + GAMMA_32 + GAMMA;
23
+
24
+ const ALPHA_21 = 2.3660254037844388;
25
+ const ALPHA_2 = ALPHA_21;
26
+ const ALPHA_31 = 0.5;
27
+ const ALPHA_32 = 0.76794919243112270;
28
+ const ALPHA_3 = ALPHA_31 + ALPHA_32;
29
+
30
+ const B_1 = 0.50544867840851759;
31
+ const B_2 = -0.11571687603637559;
32
+ const B_3 = 0.610268197627858;
33
+
34
+ const B_HAT_1 = 0.28973180237214197;
35
+ const B_HAT_2 = 0.10000000000000001;
36
+ const B_HAT_3 = 0.610268197627858;
37
+
38
+ const R_1 = B_1 - B_HAT_1;
39
+ const R_2 = B_2 - B_HAT_2;
40
+ const R_3 = B_3 - B_HAT_3;
41
+
42
+
43
+ /** Solve initial value problem using the ROS3Pw method [1]
44
+ * @param odes initial value problem for ordinary differential equations
45
+ * @param callback computations control callback
46
+ * @returns solution of the problem
47
+ */
48
+ export function ros3prw(odes: ODEs, callback?: Callback): Float64Array[] {
49
+ /** right-hand side of the IVP solved */
50
+ const f = odes.func;
51
+
52
+ // operating variables
53
+ const t0 = odes.arg.start;
54
+ const t1 = odes.arg.finish;
55
+ let h = odes.arg.step;
56
+ const hDataframe = h;
57
+ const tolerance = odes.tolerance;
58
+
59
+ /** number of solution dataframe rows */
60
+ const rowCount = Math.trunc((t1 - t0) / h) + 1;
61
+
62
+ /** dimension of the problem */
63
+ const dim = odes.initial.length;
64
+ const dimSquared = dim * dim;
65
+
66
+ /** independent variable values */
67
+ const tArr = new Float64Array(rowCount);
68
+
69
+ /** arrays of solution values */
70
+ const yArrs = Array<Float64Array>(dim);
71
+
72
+ for (let i = 0; i < dim; ++i)
73
+ yArrs[i] = new Float64Array(rowCount);
74
+
75
+ // method routine
76
+ let timeDataframe = t0 + hDataframe;
77
+ let t = t0;
78
+ let tPrev = t0;
79
+ let flag = true;
80
+ let index = 1;
81
+ let errmax = 0;
82
+ let hTemp = 0;
83
+ let tNew = 0;
84
+ let hNext = 0.0;
85
+
86
+ // 0 BUFFERS & TEMP STRUCTURES
87
+
88
+ /** identity matrix */
89
+ const I = new Float64Array(dim * dim);
90
+
91
+ // compute identity matrix
92
+ for (let i = 0; i < dim; ++i) {
93
+ for (let j = 0; j < dim; ++j)
94
+ I[j + i * dim] = (i === j) ? 1 : 0;
95
+ }
96
+
97
+ const y = new Float64Array(odes.initial);
98
+ const yPrev = new Float64Array(odes.initial);
99
+ const dydt = new Float64Array(dim);
100
+ const yScale = new Float64Array(dim);
101
+ const yTemp = new Float64Array(dim);
102
+ const yErr = new Float64Array(dim);
103
+
104
+ const W = new Float64Array(dimSquared);
105
+
106
+ const k1 = new Float64Array(dim);
107
+ const k2 = new Float64Array(dim);
108
+ const k3 = new Float64Array(dim);
109
+ const HT = new Float64Array(dim);
110
+
111
+ const f0Buf = new Float64Array(dim);
112
+ const f1Buf = new Float64Array(dim);
113
+
114
+ let hByGamma = 0;
115
+ const fBuf = new Float64Array(dim);
116
+ const kBuf = new Float64Array(dim);
117
+
118
+ const L = new Float64Array(dimSquared);
119
+ const U = new Float64Array(dimSquared);
120
+ const luBuf = new Float64Array(dim);
121
+ const bBuf = new Float64Array(dim);
122
+ const toUseLU = dim > 2;
123
+
124
+ // 1. SOLUTION AT THE POINT t0
125
+ tArr[0] = t0;
126
+ for (let i = 0; i < dim; ++i)
127
+ yArrs[i][0] = y[i];
128
+
129
+ // 2. COMPUTE NUMERICAL SOLUTION FOR THE POINTS FROM THE INTERVAL (t0, t1)
130
+ while (flag) {
131
+ // compute derivative
132
+ f(t, y, dydt);
133
+
134
+ // check whether to go on computations
135
+ if (callback)
136
+ callback.onIterationStart();
137
+
138
+ // compute scale vector
139
+ for (let i = 0; i < dim; ++i)
140
+ yScale[i] = abs(y[i]) + h * abs(dydt[i]) + TINY;
141
+
142
+ // check end point
143
+ if (t + h > t1) {
144
+ h = t1 - t;
145
+ flag = false;
146
+ }
147
+
148
+ // call of adaptive step the ROS3Pw [1] method
149
+ // computation of solution (y), time (t) and next step (hNext)
150
+ while (true) {
151
+ hByGamma = h * GAMMA;
152
+
153
+ // one stage of the ROS3Pw method
154
+
155
+ // 1) Jacobian & dF/dt matrices
156
+ jacobian(t, y, f, EPS, f0Buf, f1Buf, W);
157
+ tDerivative(t, y, f, EPS, f0Buf, f1Buf, HT);
158
+
159
+ // 2) W & LU-decomposition
160
+ for (let i = 0; i < dimSquared; ++i)
161
+ W[i] = I[i] - hByGamma * W[i];
162
+
163
+ if (toUseLU)
164
+ luDecomp(W, L, U, dim);
165
+
166
+ // 3) Scale dF/dt: HT = j * T
167
+ for (let i = 0; i < dim; ++i)
168
+ HT[i] *= h;
169
+
170
+ // 4) F1 = F(t, y) <-- Fbuf
171
+ f(t, y, fBuf);
172
+
173
+ // 5) k1 = W_inv * (F1 + gamma * HT)
174
+ for (let i = 0; i < dim; ++i)
175
+ bBuf[i] = fBuf[i] + GAMMA * HT[i];
176
+
177
+ if (toUseLU)
178
+ luSolve(L, U, bBuf, luBuf, k1, dim);
179
+ else
180
+ solve1d2d(W, bBuf, k1);
181
+
182
+ // 6) F2 = F(t + alpha2 * h, y + alpha21 * k1) <-- Fbuf
183
+ for (let i = 0; i < dim; ++i)
184
+ kBuf[i] = y[i] + ALPHA_21 * h * k1[i];
185
+
186
+ f(t + ALPHA_2 * h, kBuf, fBuf);
187
+
188
+ // 7) kBuf = gamma21 / gamma * k1
189
+ for (let i = 0; i < dim; ++i)
190
+ kBuf[i] = GAMMA_21_SCALED * k1[i];
191
+
192
+ // 8) k2 = W_inv * [Fbuf + kBuf + gamma2 * HT] - kBuf
193
+ for (let i = 0; i < dim; ++i)
194
+ bBuf[i] = fBuf[i] + kBuf[i] + GAMMA_2 * HT[i];
195
+
196
+ if (toUseLU)
197
+ luSolve(L, U, bBuf, luBuf, k2, dim);
198
+ else
199
+ solve1d2d(W, bBuf, k2);
200
+
201
+ for (let i = 0; i < dim; ++i)
202
+ k2[i] -= kBuf[i];
203
+
204
+ // 9) F3 = F(t + alpha3 * h, y + h * (alpha31 * k1 + alpha32 * k2)) <-- Fbuf
205
+ for (let i = 0; i < dim; ++i)
206
+ kBuf[i] = y[i] + h * (ALPHA_31 * k1[i] + ALPHA_32 * k2[i]);
207
+
208
+ f(t + ALPHA_3 * h, kBuf, fBuf);
209
+
210
+ // 10) kBuf = gamma31 / gamma * k1 + gamma32 / gamma * k2
211
+ for (let i = 0; i < dim; ++i)
212
+ kBuf[i] = GAMMA_31_SCALED * k1[i] + GAMMA_32_SCALED * k2[i];
213
+
214
+ // 11) k3 = W_inv * (F3 + kBuf + gamma3 * HT) - kBuf
215
+ for (let i = 0; i < dim; ++i)
216
+ bBuf[i] = fBuf[i] + kBuf[i] + GAMMA_3 * HT[i];
217
+
218
+ if (toUseLU)
219
+ luSolve(L, U, bBuf, luBuf, k3, dim);
220
+ else
221
+ solve1d2d(W, bBuf, k3);
222
+
223
+ for (let i = 0; i < dim; ++i)
224
+ k3[i] -= kBuf[i];
225
+
226
+ // 12) yNext = y + h * (b1 * k1 + b2 * k2 + b3 * k3) <-- yTemp
227
+ for (let i = 0; i < dim; ++i)
228
+ yTemp[i] = y[i] + h * (B_1 * k1[i] + B_2 * k2[i] + B_3 * k3[i]);
229
+
230
+ // 13) yErr = h * (r1 * k1 + r2 * k2 + r3 * k3)
231
+ for (let i = 0; i < dim; ++i)
232
+ yErr[i] = h * (R_1 * k1[i] + R_2 * k2[i] + R_3 * k3[i]);
233
+
234
+ // estimating error
235
+ errmax = 0;
236
+ for (let i = 0; i < dim; ++i)
237
+ errmax = max(errmax, abs(yErr[i] / yScale[i]));
238
+ errmax /= tolerance;
239
+
240
+ // processing the error obtained
241
+ if (errmax > 1) {
242
+ hTemp = SAFETY * h * errmax**PSHRNK;
243
+ h = max(hTemp, REDUCE_COEF * h);
244
+ tNew = t + h;
245
+ if (tNew == t)
246
+ throw new Error(ERROR_MSG.ROS3PRW_FAILS);
247
+ } else {
248
+ if (errmax > ERR_CONTR)
249
+ hNext = SAFETY * h * errmax**PSGROW;
250
+ else
251
+ hNext = GROW_COEF * h;
252
+ t = t + h;
253
+
254
+ for (let i = 0; i < dim; ++i)
255
+ y[i] = yTemp[i];
256
+
257
+ break;
258
+ }
259
+ } // while (true)
260
+
261
+ // compute lineraly interpolated results and store them in dataframe
262
+ while (timeDataframe < t) {
263
+ const cLeft = (t - timeDataframe) / (t - tPrev);
264
+ const cRight = 1.0 - cLeft;
265
+
266
+ tArr[index] = timeDataframe;
267
+
268
+ for (let j = 0; j < dim; ++j)
269
+ yArrs[j][index] = cRight * y[j] + cLeft * yPrev[j];
270
+
271
+ timeDataframe += hDataframe;
272
+ ++index;
273
+ }
274
+
275
+ h = hNext;
276
+ tPrev = t;
277
+
278
+ for (let i = 0; i < dim; ++i)
279
+ yPrev[i] = y[i];
280
+ } // while (flag)
281
+
282
+ // perform final callback actions
283
+ if (callback)
284
+ callback.onComputationsCompleted();
285
+
286
+ // 3. solution at the point t1
287
+ tArr[rowCount - 1] = t1;
288
+
289
+ for (let i = 0; i < dim; ++i)
290
+ yArrs[i][rowCount - 1] = y[i];
291
+
292
+ // 4. prepare output
293
+ const solution = Array<Float64Array>(dim);
294
+
295
+ // independent variable
296
+ solution[0] = tArr;
297
+
298
+ // functions
299
+ for (let i = 0; i < dim; ++i)
300
+ solution[i + 1] = yArrs[i];
301
+
302
+ return solution;
303
+ //return [tArr].concat(yArrs);
304
+ } // ros3prw
@@ -0,0 +1,58 @@
1
+ // Solver definitions
2
+ /** The abs function */
3
+ export const abs = (x) => (x > 0) ? x : -x;
4
+ /** The max function */
5
+ export const max = (x, y) => (x > y) ? x : y;
6
+ /** The max function */
7
+ export const min = (x, y) => (x < y) ? x : y;
8
+ /** Routine constants of adaptive step method */
9
+ export const SAFETY = 0.9;
10
+ export const PSHRNK = -0.25;
11
+ export const PSGROW = -0.2;
12
+ export const REDUCE_COEF = 0.25;
13
+ export const GROW_COEF = 4.0;
14
+ export const ERR_CONTR = 1.89e-4;
15
+ /** Misc */
16
+ export const TINY = 1e-20;
17
+ export const EPS = 1.0e-10;
18
+ /** Returns derivative with respect to t. */
19
+ export function tDerivative(t, y, f, eps, f0Buf, f1Buf, output) {
20
+ const size = y.length;
21
+ f(t, y, f0Buf);
22
+ f(t + eps, y, f1Buf);
23
+ for (let i = 0; i < size; ++i)
24
+ output[i] = (f1Buf[i] - f0Buf[i]) / eps;
25
+ }
26
+ /** Returns Jacobian. */
27
+ export function jacobian(t, y, f, eps, f0Buf, f1Buf, output) {
28
+ const size = y.length;
29
+ f(t, y, f0Buf);
30
+ for (let j = 0; j < size; ++j) {
31
+ y[j] += eps;
32
+ f(t, y, f1Buf);
33
+ for (let i = 0; i < size; ++i)
34
+ output[j + i * size] = (f1Buf[i] - f0Buf[i]) / eps;
35
+ y[j] -= eps;
36
+ }
37
+ }
38
+ /** Error messeges */
39
+ export var ERROR_MSG;
40
+ (function (ERROR_MSG) {
41
+ ERROR_MSG["MRT_FAILS"] = "The modified Rosenbrock triple method fails";
42
+ ERROR_MSG["ROS3PRW_FAILS"] = "The ROS3PRw method fails";
43
+ ERROR_MSG["ROS34PRW_FAILS"] = "The ROS34PRw method fails";
44
+ })(ERROR_MSG || (ERROR_MSG = {}));
45
+ ;
46
+ /** Callback action */
47
+ export class CallbackAction extends Error {
48
+ constructor(msg) {
49
+ super(msg);
50
+ }
51
+ }
52
+ /** Default options of the solver */
53
+ export var DEFAULT_OPTIONS;
54
+ (function (DEFAULT_OPTIONS) {
55
+ DEFAULT_OPTIONS["SCRIPTING"] = "{maxIterations: 1}";
56
+ DEFAULT_OPTIONS["NO_CHECKS"] = "{ }";
57
+ })(DEFAULT_OPTIONS || (DEFAULT_OPTIONS = {}));
58
+ //# sourceMappingURL=solver-defs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solver-defs.js","sourceRoot":"","sources":["solver-defs.ts"],"names":[],"mappings":"AAAA,qBAAqB;AA6BrB,uBAAuB;AACvB,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEnD,uBAAuB;AAC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G1B"}
@@ -0,0 +1,100 @@
1
+ // Solver definitions
2
+
3
+ import {Callback} from './callbacks/callback-base';
4
+
5
+ /** Right-hand side of IVP */
6
+ export type Func = (t: number, y: Float64Array, output: Float64Array) => void;
7
+
8
+ /** Solver optional settings */
9
+ export type SolverOptions = {
10
+ maxIterations: number,
11
+ maxTimeMs: number,
12
+ method: string,
13
+ };
14
+
15
+ /** Initial Value Problem (IVP) type */
16
+ export type ODEs = {
17
+ name: string,
18
+ arg: {
19
+ name: string,
20
+ start: number,
21
+ finish: number,
22
+ step: number
23
+ },
24
+ initial: number[] | Float32Array | Float64Array | Int32Array,
25
+ func: Func,
26
+ tolerance: number,
27
+ solutionColNames: string[],
28
+ };
29
+
30
+ /** The abs function */
31
+ export const abs = (x: number) => (x > 0) ? x : -x;
32
+
33
+ /** The max function */
34
+ export const max = (x: number, y: number) => (x > y) ? x : y;
35
+
36
+ /** The max function */
37
+ export const min = (x: number, y: number) => (x < y) ? x : y;
38
+
39
+ /** Routine constants of adaptive step method */
40
+ export const SAFETY = 0.9;
41
+ export const PSHRNK = -0.25;
42
+ export const PSGROW = -0.2;
43
+ export const REDUCE_COEF = 0.25;
44
+ export const GROW_COEF = 4.0;
45
+ export const ERR_CONTR = 1.89e-4;
46
+
47
+ /** Misc */
48
+ export const TINY = 1e-20;
49
+ export const EPS = 1.0e-10;
50
+
51
+ /** Returns derivative with respect to t. */
52
+ export function tDerivative(t: number, y: Float64Array, f: Func, eps: number,
53
+ f0Buf: Float64Array, f1Buf: Float64Array, output: Float64Array): void {
54
+ const size = y.length;
55
+ f(t, y, f0Buf);
56
+ f(t + eps, y, f1Buf);
57
+
58
+ for (let i = 0; i < size; ++i)
59
+ output[i] = (f1Buf[i] - f0Buf[i]) / eps;
60
+ }
61
+
62
+ /** Returns Jacobian. */
63
+ export function jacobian(t: number, y: Float64Array, f: Func, eps: number,
64
+ f0Buf: Float64Array, f1Buf: Float64Array, output: Float64Array): void {
65
+ const size = y.length;
66
+ f(t, y, f0Buf);
67
+
68
+ for (let j = 0; j < size; ++j) {
69
+ y[j] += eps;
70
+ f(t, y, f1Buf);
71
+
72
+ for (let i = 0; i < size; ++i)
73
+ output[j + i * size] = (f1Buf[i] - f0Buf[i]) / eps;
74
+
75
+ y[j] -= eps;
76
+ }
77
+ }
78
+
79
+ /** Error messeges */
80
+ export enum ERROR_MSG {
81
+ MRT_FAILS = 'The modified Rosenbrock triple method fails',
82
+ ROS3PRW_FAILS = 'The ROS3PRw method fails',
83
+ ROS34PRW_FAILS = 'The ROS34PRw method fails',
84
+ };
85
+
86
+ /** Callback action */
87
+ export class CallbackAction extends Error {
88
+ constructor(msg: string) {
89
+ super(msg);
90
+ }
91
+ }
92
+
93
+ /** Default options of the solver */
94
+ export enum DEFAULT_OPTIONS {
95
+ SCRIPTING = '{maxIterations: 1}',
96
+ NO_CHECKS = '{ }',
97
+ }
98
+
99
+ /** IVP solving method */
100
+ export type SolverMethod = (odes: ODEs, callback?: Callback) => Float64Array[];
@@ -0,0 +1,3 @@
1
+ export { getIvp2WebWorker } from './scripting';
2
+ export { solveIvp } from './solving';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,gBAAgB,EAAC,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAC,QAAQ,EAAC,MAAM,WAAW,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {IVP2WebWorker, getIvp2WebWorker} from './scripting';
2
+ export {solveIvp} from './solving';
@@ -0,0 +1,68 @@
1
+ // Scripting tools for solving IVPs in web-workers
2
+ import { MATH_CONSTS, POW_IDX, MATH_FUNCS } from '../scripting-tools/scripting-tools';
3
+ const DEFAULT_METHOD = 'ros34prw';
4
+ const DEFAULT_MAX_TIME_MS = 50000;
5
+ /** Return solver options */
6
+ function getSolverOpts(opts) {
7
+ try {
8
+ const json = JSON.parse(opts
9
+ .replaceAll(`'`, `"`)
10
+ .replace('method', '"method"')
11
+ .replace('maxTimeMs', '"maxTimeMs"')
12
+ .replace('maxIterations', '"maxIterations"')
13
+ .replace(';', ','));
14
+ return json;
15
+ }
16
+ catch (e) {
17
+ return {
18
+ method: DEFAULT_METHOD,
19
+ maxTimeMs: DEFAULT_MAX_TIME_MS,
20
+ };
21
+ }
22
+ }
23
+ /** Return main body of a right-hand side function of IVP */
24
+ function getFuncMainBody(ivp) {
25
+ const lines = [];
26
+ // Used math funcs
27
+ ivp.usedMathFuncs.forEach((idx) => {
28
+ if (idx !== POW_IDX)
29
+ lines.push(`const ${MATH_FUNCS[idx]} = (x) => Math.${MATH_FUNCS[idx]}(x);`);
30
+ else
31
+ lines.push(`const pow = (x, y) => Math.pow(x, y);`);
32
+ });
33
+ // Used math consts
34
+ ivp.usedMathConsts.forEach((idx) => lines.push(`const ${MATH_CONSTS[idx]} = Math.${MATH_CONSTS[idx]};`));
35
+ // Model constants
36
+ if (ivp.consts !== null)
37
+ ivp.consts.forEach((input, name) => lines.push(`const ${name} = ${input.value};`));
38
+ // extract arg & function values
39
+ lines.push(`const ${ivp.arg.name} = arguments[0];`);
40
+ ivp.deqs.solutionNames.forEach((name, idx) => lines.push(`const ${name} = arguments[1][${idx}];`));
41
+ // evaluate expressions
42
+ if (ivp.exprs !== null)
43
+ ivp.exprs.forEach(((expr, name) => lines.push(`const ${name} = ${expr};`)));
44
+ // compute output
45
+ ivp.deqs.solutionNames.forEach((name, idx) => lines.push(`arguments[2][${idx}] = ${ivp.deqs.equations.get(name)};`));
46
+ return lines.join('\n');
47
+ }
48
+ /** Return IVP-structure to be passed to web-worker */
49
+ export function getIvp2WebWorker(ivp) {
50
+ const paramNames = [];
51
+ if (ivp.params !== null)
52
+ ivp.params.forEach((_, name) => paramNames.push(name));
53
+ const ivpWW = {
54
+ tolerance: Number(ivp.tolerance),
55
+ solverOpts: getSolverOpts(ivp.solverSettings),
56
+ funcMainBody: getFuncMainBody(ivp),
57
+ paramNames: paramNames,
58
+ deqsCount: ivp.deqs.solutionNames.length,
59
+ };
60
+ return ivpWW;
61
+ }
62
+ /** Return a right-hand side function of IVP with the specified values of parameters */
63
+ export function getFunc(ivp, paramVals) {
64
+ const lines = [];
65
+ ivp.paramNames.forEach((name, idx) => lines.push(`const ${name} = ${paramVals[idx]};`));
66
+ return lines.concat(ivp.funcMainBody).join('\n');
67
+ }
68
+ //# sourceMappingURL=scripting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scripting.js","sourceRoot":"","sources":["scripting.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAElD,OAAO,EAAM,WAAW,EAAE,OAAO,EAAE,UAAU,EAAC,MAAM,oCAAoC,CAAC;AAYzF,MAAM,cAAc,GAAG,UAAU,CAAC;AAClC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAElC,4BAA4B;AAC5B,SAAS,aAAa,CAAC,IAAY;IACjC,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI;aACzB,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC;aACpB,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC;aAC7B,OAAO,CAAC,WAAW,EAAE,aAAa,CAAC;aACnC,OAAO,CAAC,eAAe,EAAE,iBAAiB,CAAC;aAC3C,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CACnB,CAAC;QAEF,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO;YACL,MAAM,EAAE,cAAc;YACtB,SAAS,EAAE,mBAAmB;SAC/B,CAAC;IACJ,CAAC;AACH,CAAC;AAED,4DAA4D;AAC5D,SAAS,eAAe,CAAC,GAAQ;IAC/B,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,kBAAkB;IAClB,GAAG,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAChC,IAAI,GAAG,KAAK,OAAO;YACjB,KAAK,CAAC,IA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scripting-tools';
4
+ import {SolverOptions} from '../solver-tools/solver-defs';
5
+
6
+ /** Initial value problem structure to be passed to web-worker */
7
+ export type IVP2WebWorker = {
8
+ tolerance: number,
9
+ solverOpts: Partial<SolverOptions>,
10
+ funcMainBody: string,
11
+ paramNames: string[],
12
+ deqsCount: number,
13
+ };
14
+
15
+ const DEFAULT_METHOD = 'ros34prw';
16
+ const DEFAULT_MAX_TIME_MS = 50000;
17
+
18
+ /** Return solver options */
19
+ function getSolverOpts(opts: string): Partial<SolverOptions> {
20
+ try {
21
+ const json = JSON.parse(opts
22
+ .replaceAll(`'`, `"`)
23
+ .replace('method', '"method"')
24
+ .replace('maxTimeMs', '"maxTimeMs"')
25
+ .replace('maxIterations', '"maxIterations"')
26
+ .replace(';', ','),
27
+ );
28
+
29
+ return json;
30
+ } catch (e) {
31
+ return {
32
+ method: DEFAULT_METHOD,
33
+ maxTimeMs: DEFAULT_MAX_TIME_MS,
34
+ };
35
+ }
36
+ }
37
+
38
+ /** Return main body of a right-hand side function of IVP */
39
+ function getFuncMainBody(ivp: IVP): string {
40
+ const lines: string[] = [];
41
+
42
+ // Used math funcs
43
+ ivp.usedMathFuncs.forEach((idx) => {
44
+ if (idx !== POW_IDX)
45
+ lines.push(`const ${MATH_FUNCS[idx]} = (x) => Math.${MATH_FUNCS[idx]}(x);`);
46
+ else
47
+ lines.push(`const pow = (x, y) => Math.pow(x, y);`);
48
+ });
49
+
50
+ // Used math consts
51
+ ivp.usedMathConsts.forEach((idx) => lines.push(`const ${MATH_CONSTS[idx]} = Math.${MATH_CONSTS[idx]};`));
52
+
53
+ // Model constants
54
+ if (ivp.consts !== null)
55
+ ivp.consts.forEach((input, name) => lines.push(`const ${name} = ${input.value};`));
56
+
57
+ // extract arg & function values
58
+ lines.push(`const ${ivp.arg.name} = arguments[0];`);
59
+ ivp.deqs.solutionNames.forEach((name, idx) => lines.push(`const ${name} = arguments[1][${idx}];`));
60
+
61
+ // evaluate expressions
62
+ if (ivp.exprs !== null)
63
+ ivp.exprs.forEach(((expr, name) => lines.push(`const ${name} = ${expr};`)));
64
+
65
+ // compute output
66
+ ivp.deqs.solutionNames.forEach((name, idx) => lines.push(`arguments[2][${idx}] = ${ivp.deqs.equations.get(name)};`));
67
+
68
+ return lines.join('\n');
69
+ }
70
+
71
+ /** Return IVP-structure to be passed to web-worker */
72
+ export function getIvp2WebWorker(ivp: IVP): IVP2WebWorker {
73
+ const paramNames: string[] = [];
74
+ if (ivp.params !== null)
75
+ ivp.params.forEach((_, name) => paramNames.push(name));
76
+
77
+ const ivpWW: IVP2WebWorker = {
78
+ tolerance: Number(ivp.tolerance),
79
+ solverOpts: getSolverOpts(ivp.solverSettings),
80
+ funcMainBody: getFuncMainBody(ivp),
81
+ paramNames: paramNames,
82
+ deqsCount: ivp.deqs.solutionNames.length,
83
+ };
84
+
85
+ return ivpWW;
86
+ }
87
+
88
+ /** Return a right-hand side function of IVP with the specified values of parameters */
89
+ export function getFunc(ivp: IVP2WebWorker, paramVals: Float64Array): string {
90
+ const lines: string[] = [];
91
+
92
+ ivp.paramNames.forEach((name, idx) => lines.push(`const ${name} = ${paramVals[idx]};`));
93
+
94
+ return lines.concat(ivp.funcMainBody).join('\n');
95
+ }