diff-grok 1.0.10 → 1.2.0

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 (226) hide show
  1. package/.claude/settings.local.json +11 -0
  2. package/.claude/skills/license-updater/SKILL.md +149 -0
  3. package/.claude/skills/license-updater/references/compatibility.md +68 -0
  4. package/.claude/skills/license-updater/references/templates.md +151 -0
  5. package/.claude/skills/license-updater/scripts/generate_license_files.py +467 -0
  6. package/CLAUDE.md +104 -0
  7. package/LICENSE +1 -1
  8. package/README.MD +121 -27
  9. package/THIRD_PARTY_LICENSES +135 -0
  10. package/docs/assets/hierarchy.js +1 -1
  11. package/docs/assets/navigation.js +1 -1
  12. package/docs/assets/search.js +1 -1
  13. package/docs/classes/BasicModelPipelineCreator.html +4 -4
  14. package/docs/classes/Callback.html +5 -5
  15. package/docs/classes/CyclicModelPipelineCreator.html +4 -4
  16. package/docs/classes/IterCheckerCallback.html +5 -5
  17. package/docs/classes/PipelineCreator.html +4 -4
  18. package/docs/classes/TimeCheckerCallback.html +5 -5
  19. package/docs/classes/UpdatesModelPipelineCreator.html +4 -4
  20. package/docs/functions/ab4.html +8 -0
  21. package/docs/functions/ab5.html +8 -0
  22. package/docs/functions/applyPipeline.html +2 -2
  23. package/docs/functions/getCallback.html +2 -2
  24. package/docs/functions/getIVP.html +2 -2
  25. package/docs/functions/getInputVector.html +2 -2
  26. package/docs/functions/getIvp2WebWorker.html +2 -2
  27. package/docs/functions/getJScode.html +2 -2
  28. package/docs/functions/getOutputNames.html +2 -2
  29. package/docs/functions/getPipelineCreator.html +2 -2
  30. package/docs/functions/lsoda.html +8 -0
  31. package/docs/functions/mrt.html +2 -2
  32. package/docs/functions/printE5.html +2 -2
  33. package/docs/functions/printHires.html +2 -2
  34. package/docs/functions/printOrego.html +2 -2
  35. package/docs/functions/printPollution.html +2 -2
  36. package/docs/functions/printRobertson.html +2 -2
  37. package/docs/functions/printVdpol.html +2 -2
  38. package/docs/functions/rk3.html +8 -0
  39. package/docs/functions/rk4.html +8 -0
  40. package/docs/functions/rkdp.html +8 -0
  41. package/docs/functions/ros34prw.html +2 -2
  42. package/docs/functions/ros3prw.html +2 -2
  43. package/docs/functions/solveIvp.html +2 -2
  44. package/docs/hierarchy.html +1 -1
  45. package/docs/index.html +100 -15
  46. package/docs/media/E5.png +0 -0
  47. package/docs/media/HIRES.png +0 -0
  48. package/docs/media/OREGO.png +0 -0
  49. package/docs/media/POLL-full.png +0 -0
  50. package/docs/media/ROBER.png +0 -0
  51. package/docs/media/VDP0L.png +0 -0
  52. package/docs/media/cyclic-model.js +3 -1
  53. package/docs/media/cyclic-model.js.map +1 -1
  54. package/docs/media/cyclic-model.ts +3 -1
  55. package/docs/modules.html +1 -1
  56. package/docs/types/Arg.html +7 -7
  57. package/docs/types/DifEqs.html +4 -4
  58. package/docs/types/Func.html +2 -2
  59. package/docs/types/IVP.html +20 -20
  60. package/docs/types/IVP2WebWorker.html +7 -7
  61. package/docs/types/Input.html +4 -4
  62. package/docs/types/Loop.html +4 -4
  63. package/docs/types/ODEs.html +8 -8
  64. package/docs/types/Output.html +4 -4
  65. package/docs/types/Pipeline.html +4 -4
  66. package/docs/types/SolverOptions.html +5 -5
  67. package/docs/types/Update.html +5 -5
  68. package/docs/types/Wrapper.html +5 -5
  69. package/images/E5.png +0 -0
  70. package/images/HIRES.png +0 -0
  71. package/images/OREGO.png +0 -0
  72. package/images/POLL-full.png +0 -0
  73. package/images/ROBER.png +0 -0
  74. package/images/VDP0L.png +0 -0
  75. package/index.js +1 -1
  76. package/index.js.map +1 -1
  77. package/index.ts +2 -1
  78. package/jest.config.js +1 -0
  79. package/package.json +4 -2
  80. package/src/examples/check-methods.js +15 -3
  81. package/src/examples/check-methods.js.map +1 -1
  82. package/src/examples/check-methods.ts +18 -3
  83. package/src/examples/cyclic-model.js +3 -1
  84. package/src/examples/cyclic-model.js.map +1 -1
  85. package/src/examples/cyclic-model.ts +3 -1
  86. package/src/solver-tools/ab4-method.js +332 -0
  87. package/src/solver-tools/ab4-method.js.map +1 -0
  88. package/src/solver-tools/ab4-method.ts +395 -0
  89. package/src/solver-tools/ab5-method.js +334 -0
  90. package/src/solver-tools/ab5-method.js.map +1 -0
  91. package/src/solver-tools/ab5-method.ts +397 -0
  92. package/src/solver-tools/cvode/common.js +487 -0
  93. package/src/solver-tools/cvode/common.js.map +1 -0
  94. package/src/solver-tools/cvode/common.ts +549 -0
  95. package/src/solver-tools/cvode/cvode.js +1062 -0
  96. package/src/solver-tools/cvode/cvode.js.map +1 -0
  97. package/src/solver-tools/cvode/cvode.ts +1226 -0
  98. package/src/solver-tools/cvode/cvode_adams.js +124 -0
  99. package/src/solver-tools/cvode/cvode_adams.js.map +1 -0
  100. package/src/solver-tools/cvode/cvode_adams.ts +142 -0
  101. package/src/solver-tools/cvode/cvode_bdf.js +153 -0
  102. package/src/solver-tools/cvode/cvode_bdf.js.map +1 -0
  103. package/src/solver-tools/cvode/cvode_bdf.ts +164 -0
  104. package/src/solver-tools/cvode/cvode_class.js +158 -0
  105. package/src/solver-tools/cvode/cvode_class.js.map +1 -0
  106. package/src/solver-tools/cvode/cvode_class.ts +271 -0
  107. package/src/solver-tools/cvode/cvode_hin.js +119 -0
  108. package/src/solver-tools/cvode/cvode_hin.js.map +1 -0
  109. package/src/solver-tools/cvode/cvode_hin.ts +150 -0
  110. package/src/solver-tools/cvode/cvode_io.js +203 -0
  111. package/src/solver-tools/cvode/cvode_io.js.map +1 -0
  112. package/src/solver-tools/cvode/cvode_io.ts +258 -0
  113. package/src/solver-tools/cvode/cvode_ls.js +210 -0
  114. package/src/solver-tools/cvode/cvode_ls.js.map +1 -0
  115. package/src/solver-tools/cvode/cvode_ls.ts +249 -0
  116. package/src/solver-tools/cvode/cvode_nls.js +220 -0
  117. package/src/solver-tools/cvode/cvode_nls.js.map +1 -0
  118. package/src/solver-tools/cvode/cvode_nls.ts +259 -0
  119. package/src/solver-tools/cvode/cvode_root.js +415 -0
  120. package/src/solver-tools/cvode/cvode_root.js.map +1 -0
  121. package/src/solver-tools/cvode/cvode_root.ts +503 -0
  122. package/src/solver-tools/cvode/dense_linalg.js +131 -0
  123. package/src/solver-tools/cvode/dense_linalg.js.map +1 -0
  124. package/src/solver-tools/cvode/dense_linalg.ts +144 -0
  125. package/src/solver-tools/cvode/index.js +26 -0
  126. package/src/solver-tools/cvode/index.js.map +1 -0
  127. package/src/solver-tools/cvode/index.ts +64 -0
  128. package/src/solver-tools/cvode-method.js +114 -0
  129. package/src/solver-tools/cvode-method.js.map +1 -0
  130. package/src/solver-tools/cvode-method.ts +129 -0
  131. package/src/solver-tools/index.js +7 -0
  132. package/src/solver-tools/index.js.map +1 -1
  133. package/src/solver-tools/index.ts +7 -0
  134. package/src/solver-tools/lsoda/blas.js +257 -0
  135. package/src/solver-tools/lsoda/blas.js.map +1 -0
  136. package/src/solver-tools/lsoda/blas.ts +279 -0
  137. package/src/solver-tools/lsoda/cfode.js +84 -0
  138. package/src/solver-tools/lsoda/cfode.js.map +1 -0
  139. package/src/solver-tools/lsoda/cfode.ts +95 -0
  140. package/src/solver-tools/lsoda/common.js +94 -0
  141. package/src/solver-tools/lsoda/common.js.map +1 -0
  142. package/src/solver-tools/lsoda/common.ts +135 -0
  143. package/src/solver-tools/lsoda/corfailure.js +36 -0
  144. package/src/solver-tools/lsoda/corfailure.js.map +1 -0
  145. package/src/solver-tools/lsoda/corfailure.ts +42 -0
  146. package/src/solver-tools/lsoda/correction.js +112 -0
  147. package/src/solver-tools/lsoda/correction.js.map +1 -0
  148. package/src/solver-tools/lsoda/correction.ts +131 -0
  149. package/src/solver-tools/lsoda/dense.js +121 -0
  150. package/src/solver-tools/lsoda/dense.js.map +1 -0
  151. package/src/solver-tools/lsoda/dense.ts +141 -0
  152. package/src/solver-tools/lsoda/index.js +15 -0
  153. package/src/solver-tools/lsoda/index.js.map +1 -0
  154. package/src/solver-tools/lsoda/index.ts +17 -0
  155. package/src/solver-tools/lsoda/intdy.js +54 -0
  156. package/src/solver-tools/lsoda/intdy.js.map +1 -0
  157. package/src/solver-tools/lsoda/intdy.ts +62 -0
  158. package/src/solver-tools/lsoda/lsoda.js +578 -0
  159. package/src/solver-tools/lsoda/lsoda.js.map +1 -0
  160. package/src/solver-tools/lsoda/lsoda.ts +644 -0
  161. package/src/solver-tools/lsoda/methodswitch.js +108 -0
  162. package/src/solver-tools/lsoda/methodswitch.js.map +1 -0
  163. package/src/solver-tools/lsoda/methodswitch.ts +119 -0
  164. package/src/solver-tools/lsoda/orderswitch.js +97 -0
  165. package/src/solver-tools/lsoda/orderswitch.js.map +1 -0
  166. package/src/solver-tools/lsoda/orderswitch.ts +107 -0
  167. package/src/solver-tools/lsoda/prja.js +54 -0
  168. package/src/solver-tools/lsoda/prja.js.map +1 -0
  169. package/src/solver-tools/lsoda/prja.ts +61 -0
  170. package/src/solver-tools/lsoda/scaleh.js +41 -0
  171. package/src/solver-tools/lsoda/scaleh.js.map +1 -0
  172. package/src/solver-tools/lsoda/scaleh.ts +45 -0
  173. package/src/solver-tools/lsoda/solsy.js +25 -0
  174. package/src/solver-tools/lsoda/solsy.js.map +1 -0
  175. package/src/solver-tools/lsoda/solsy.ts +30 -0
  176. package/src/solver-tools/lsoda/stoda.js +270 -0
  177. package/src/solver-tools/lsoda/stoda.js.map +1 -0
  178. package/src/solver-tools/lsoda/stoda.ts +298 -0
  179. package/src/solver-tools/lsoda-method.js +134 -0
  180. package/src/solver-tools/lsoda-method.js.map +1 -0
  181. package/src/solver-tools/lsoda-method.ts +154 -0
  182. package/src/solver-tools/mrt-method.js +81 -18
  183. package/src/solver-tools/mrt-method.js.map +1 -1
  184. package/src/solver-tools/mrt-method.ts +111 -21
  185. package/src/solver-tools/rk3-method.js +210 -0
  186. package/src/solver-tools/rk3-method.js.map +1 -0
  187. package/src/solver-tools/rk3-method.ts +257 -0
  188. package/src/solver-tools/rk4-method.js +236 -0
  189. package/src/solver-tools/rk4-method.js.map +1 -0
  190. package/src/solver-tools/rk4-method.ts +286 -0
  191. package/src/solver-tools/rkdp-method.js +247 -0
  192. package/src/solver-tools/rkdp-method.js.map +1 -0
  193. package/src/solver-tools/rkdp-method.ts +300 -0
  194. package/src/solver-tools/ros34prw-method.js +1 -1
  195. package/src/solver-tools/ros34prw-method.js.map +1 -1
  196. package/src/solver-tools/ros34prw-method.ts +1 -1
  197. package/src/solver-tools/ros3prw-method.js +1 -1
  198. package/src/solver-tools/ros3prw-method.js.map +1 -1
  199. package/src/solver-tools/ros3prw-method.ts +1 -1
  200. package/src/solver-tools/solver-defs.js +7 -0
  201. package/src/solver-tools/solver-defs.js.map +1 -1
  202. package/src/solver-tools/solver-defs.ts +7 -0
  203. package/src/tests/correctness.test.js +6 -4
  204. package/src/tests/correctness.test.js.map +1 -1
  205. package/src/tests/correctness.test.ts +6 -4
  206. package/src/tests/cvode-lib-correctness.test.js +404 -0
  207. package/src/tests/cvode-lib-correctness.test.js.map +1 -0
  208. package/src/tests/cvode-lib-correctness.test.ts +505 -0
  209. package/src/tests/cvode-lib-performance.test.js +103 -0
  210. package/src/tests/cvode-lib-performance.test.js.map +1 -0
  211. package/src/tests/cvode-lib-performance.test.ts +128 -0
  212. package/src/tests/lsoda-lib-correctness.test.js +223 -0
  213. package/src/tests/lsoda-lib-correctness.test.js.map +1 -0
  214. package/src/tests/lsoda-lib-correctness.test.ts +283 -0
  215. package/src/tests/lsoda-lib-performance.test.js +95 -0
  216. package/src/tests/lsoda-lib-performance.test.js.map +1 -0
  217. package/src/tests/lsoda-lib-performance.test.ts +126 -0
  218. package/src/tests/performance.test.js +12 -8
  219. package/src/tests/performance.test.js.map +1 -1
  220. package/src/tests/performance.test.ts +12 -8
  221. package/src/tests/test-defs.js +20 -1
  222. package/src/tests/test-defs.js.map +1 -1
  223. package/src/tests/test-defs.ts +22 -1
  224. package/src/worker-tools/solving.js +15 -1
  225. package/src/worker-tools/solving.js.map +1 -1
  226. package/src/worker-tools/solving.ts +23 -1
@@ -0,0 +1,95 @@
1
+ /**
2
+ * TypeScript port of liblsoda (https://github.com/sdwfrost/liblsoda)
3
+ * Original LSODA algorithm by Linda Petzold & Alan Hindmarsh (1983)
4
+ *
5
+ * Copyright (c) 2011 Yu Feng, McWilliam Cosmology Center, Carnegie Mellon University
6
+ * Copyright (c) 2016 Simon Frost
7
+ * Copyright (c) 2026 Datagrok
8
+ *
9
+ * Licensed under the MIT License. See THIRD_PARTY_LICENSES for the full
10
+ * license text and provenance chain of the original code.
11
+ */
12
+
13
+ import {LsodaContext} from './common';
14
+
15
+ /**
16
+ * Set coefficients for the current method.
17
+ * Computes elco and tesco arrays for all orders.
18
+ * meth=1: Adams (orders 1-12), meth=2: BDF (orders 1-5).
19
+ */
20
+ export function cfode(ctx: LsodaContext, meth: number): void {
21
+ const c = ctx.common!;
22
+ const pc = new Float64Array(13);
23
+
24
+ if (meth === 1) {
25
+ c.elco[1][1] = 1.;
26
+ c.elco[1][2] = 1.;
27
+ c.tesco[1][1] = 0.;
28
+ c.tesco[1][2] = 2.;
29
+ c.tesco[2][1] = 1.;
30
+ c.tesco[12][3] = 0.;
31
+ pc[1] = 1.;
32
+ let rqfac = 1.;
33
+
34
+ for (let nq = 2; nq <= 12; nq++) {
35
+ const rq1fac = rqfac;
36
+ rqfac = rqfac / nq;
37
+ const nqm1 = nq - 1;
38
+ const fnqm1 = nqm1;
39
+ const nqp1 = nq + 1;
40
+
41
+ // Form coefficients of p(x)*(x+nq-1)
42
+ pc[nq] = 0.;
43
+ for (let i = nq; i >= 2; i--)
44
+ pc[i] = pc[i - 1] + fnqm1 * pc[i];
45
+ pc[1] = fnqm1 * pc[1];
46
+
47
+ // Compute integral, -1 to 0, of p(x) and x*p(x)
48
+ let pint = pc[1];
49
+ let xpin = pc[1] / 2.;
50
+ let tsign = 1.;
51
+ for (let i = 2; i <= nq; i++) {
52
+ tsign = -tsign;
53
+ pint += tsign * pc[i] / i;
54
+ xpin += tsign * pc[i] / (i + 1);
55
+ }
56
+
57
+ // Store coefficients in elco and tesco
58
+ c.elco[nq][1] = pint * rq1fac;
59
+ c.elco[nq][2] = 1.;
60
+ for (let i = 2; i <= nq; i++)
61
+ c.elco[nq][i + 1] = rq1fac * pc[i] / i;
62
+ const agamq = rqfac * xpin;
63
+ const ragq = 1. / agamq;
64
+ c.tesco[nq][2] = ragq;
65
+ if (nq < 12)
66
+ c.tesco[nqp1][1] = ragq * rqfac / nqp1;
67
+ c.tesco[nqm1][3] = ragq;
68
+ }
69
+ return;
70
+ }
71
+
72
+ // meth = 2 (BDF)
73
+ pc[1] = 1.;
74
+ let rq1fac = 1.;
75
+
76
+ for (let nq = 1; nq <= 5; nq++) {
77
+ const fnq = nq;
78
+ const nqp1 = nq + 1;
79
+
80
+ // Form coefficients of p(x)*(x+nq)
81
+ pc[nqp1] = 0.;
82
+ for (let i = nq + 1; i >= 2; i--)
83
+ pc[i] = pc[i - 1] + fnq * pc[i];
84
+ pc[1] *= fnq;
85
+
86
+ // Store coefficients in elco and tesco
87
+ for (let i = 1; i <= nqp1; i++)
88
+ c.elco[nq][i] = pc[i] / pc[2];
89
+ c.elco[nq][2] = 1.;
90
+ c.tesco[nq][1] = rq1fac;
91
+ c.tesco[nq][2] = nqp1 / c.elco[nq][1];
92
+ c.tesco[nq][3] = (nq + 2) / c.elco[nq][1];
93
+ rq1fac /= fnq;
94
+ }
95
+ }
@@ -0,0 +1,94 @@
1
+ // Constants from common.h
2
+ export const ETA = 2.2204460492503131e-16;
3
+ export const SQRTETA = 1.4901161193847656e-08;
4
+ export const CCMAX = 0.3;
5
+ export const MAXCOR = 3;
6
+ export const MSBP = 20;
7
+ export const MXNCF = 10;
8
+ export const RATIO = 5.0;
9
+ // Stability region limits for Adams method (from common.c)
10
+ export const sm1 = [
11
+ 0., 0.5, 0.575, 0.55, 0.45, 0.35, 0.25, 0.2, 0.15, 0.1, 0.075, 0.05, 0.025,
12
+ ];
13
+ // Method switch coefficients (from methodswitch.c)
14
+ // cm1 and cm2 are calculated from tesco/elco 1 and 2 formula in cfode.c
15
+ export const cm1 = [
16
+ 0, 2.0, 5.999999999999998, 4.0,
17
+ 1.5780346820809881, 0.44444444444444464, 0.09712509625876042, 0.017636684303350972,
18
+ 0.002666977809498494, 0.00033760591160674403, 0.000035714285714285924, 3.1001984126984256e-06,
19
+ 2.1543369643350994e-07,
20
+ ];
21
+ export const cm2 = [
22
+ 0, 2.0, 1.5, 0.6666666666666667,
23
+ 0.20833333333333348, 0.04999999999999998, 0.09712509625876042, 0.017636684303350972,
24
+ 0.002666977809498494, 0.00033760591160674403, 0.000035714285714285924, 3.1001984126984256e-06,
25
+ 2.1543369643350994e-07,
26
+ ];
27
+ // Internal solver state (mirrors lsoda_common_t)
28
+ export class LsodaCommon {
29
+ constructor() {
30
+ // Solution history (2D: yh[j][i], 1-indexed)
31
+ this.yh = [];
32
+ // Working matrix for Jacobian/LU (2D: wm[i][j], 1-indexed)
33
+ this.wm = [];
34
+ // Error weights (1-indexed)
35
+ this.ewt = new Float64Array(0);
36
+ // Saved function values (1-indexed)
37
+ this.savf = new Float64Array(0);
38
+ // Accumulated corrections (1-indexed)
39
+ this.acor = new Float64Array(0);
40
+ // Pivot indices for LU (1-indexed)
41
+ this.ipvt = new Int32Array(0);
42
+ // Step size
43
+ this.h = 0;
44
+ this.hu = 0;
45
+ this.rc = 0;
46
+ this.tn = 0;
47
+ this.tsw = 0;
48
+ this.pdnorm = 0;
49
+ // Convergence
50
+ this.crate = 0;
51
+ this.el = new Float64Array(14);
52
+ this.hold = 0;
53
+ this.rmax = 0;
54
+ this.pdest = 0;
55
+ this.pdlast = 0;
56
+ // Method coefficients (2D arrays, 1-indexed)
57
+ this.elco = [];
58
+ this.tesco = [];
59
+ // Counters and flags
60
+ this.ialth = 0;
61
+ this.ipup = 0;
62
+ this.nslp = 0;
63
+ this.icount = 0;
64
+ this.irflag = 0;
65
+ this.imxer = 0;
66
+ this.illin = 0;
67
+ this.nhnil = 0;
68
+ this.nslast = 0;
69
+ this.jcur = 0;
70
+ this.meth = 0;
71
+ this.mused = 0;
72
+ this.nq = 0;
73
+ this.nst = 0;
74
+ this.ncf = 0;
75
+ this.nfe = 0;
76
+ this.nje = 0;
77
+ this.nqu = 0;
78
+ this.miter = 0;
79
+ }
80
+ }
81
+ // Solver context
82
+ export class LsodaContext {
83
+ constructor(func, neq, data) {
84
+ this.error = null;
85
+ this.common = null;
86
+ this.opt = null;
87
+ this.snapshots = null;
88
+ this.func = func;
89
+ this.neq = neq;
90
+ this.data = data !== null && data !== void 0 ? data : null;
91
+ this.state = 1;
92
+ }
93
+ }
94
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["common.ts"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,MAAM,CAAC,MAAM,GAAG,GAAG,sBAAsB,CAAC;AAC1C,MAAM,CAAC,MAAM,OAAO,GAAG,sBAAsB,CAAC;AAC9C,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,CAAC;AACzB,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAC;AACxB,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;AACvB,MAAM,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;AACxB,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,CAAC;AAEzB,2DAA2D;AAC3D,MAAM,CAAC,MAAM,GAAG,GAAa;IAC3B,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK;CAC3E,CAAC;AAEF,mDAAmD;AACnD,wEAAwE;AACxE,MAAM,CAAC,MAAM,GAAG,GAAa;IAC3B,CAAC,EAAE,GAAG,EAAE,iBAAiB,EAAE,GAAG;IAC9B,kBAAkB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,oBAAoB;IAClF,oBAAoB,EAAE,sBAAsB,EA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AAC;QAClB,SAAI,GAAW,CAAC,CAAC;QACjB,SAAI,GAAW,CAAC,CAAC;QACjB,WAAM,GAAW,CAAC,CAAC;QACnB,WAAM,GAAW,CAAC,CAAC;QACnB,UAAK,GAAW,CAAC,CAAC;QAClB,UAAK,GAAW,CAAC,CAAC;QAClB,UAAK,GAAW,CAAC,CAAC;QAClB,WAAM,GAAW,CAAC,CAAC;QACnB,SAAI,GAAW,CAAC,CAAC;QACjB,SAAI,GAAW,CAAC,CAAC;QACjB,UAAK,GAAW,CAAC,CAAC;QAClB,OAAE,GAAW,CAAC,CAAC;QACf,QAAG,GAAW,CAAC,CAAC;QAChB,QAAG,GAAW,CAAC,CAAC;QAChB,QAAG,GAAW,CAAC,CAAC;QAChB,QAAG,GAAW,CAAC,CAAC;QAChB,QAAG,GAAW,CAAC,CAAC;QAChB,UAAK,GAAW,CAAC,CAAC;IACpB,CAAC;CAAA;AAWD,iBAAiB;AACjB,MAAM,OAAO,YAAY;IAUvB,YAAY,IAAe,EAAE,GAAW,EAAE,IAAU;QALpD,UAAK,GAAkB,IAAI,CAAC;QAC5B,WAAM,GAAuB,IAAI,CAAC;QAClC,QAAG,GAAoB,IAAI,CAAC;QAC5B,cAAS,GAA+B,IAAI,CAAC;QAG3C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,aAAJ,IAAI,cAAJ,IAAI,GAAI,IAAI,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC;IACjB,CAAC;CACF"}
@@ -0,0 +1,135 @@
1
+ // Constants from common.h
2
+ export const ETA = 2.2204460492503131e-16;
3
+ export const SQRTETA = 1.4901161193847656e-08;
4
+ export const CCMAX = 0.3;
5
+ export const MAXCOR = 3;
6
+ export const MSBP = 20;
7
+ export const MXNCF = 10;
8
+ export const RATIO = 5.0;
9
+
10
+ // Stability region limits for Adams method (from common.c)
11
+ export const sm1: number[] = [
12
+ 0., 0.5, 0.575, 0.55, 0.45, 0.35, 0.25, 0.2, 0.15, 0.1, 0.075, 0.05, 0.025,
13
+ ];
14
+
15
+ // Method switch coefficients (from methodswitch.c)
16
+ // cm1 and cm2 are calculated from tesco/elco 1 and 2 formula in cfode.c
17
+ export const cm1: number[] = [
18
+ 0, 2.0, 5.999999999999998, 4.0,
19
+ 1.5780346820809881, 0.44444444444444464, 0.09712509625876042, 0.017636684303350972,
20
+ 0.002666977809498494, 0.00033760591160674403, 0.000035714285714285924, 3.1001984126984256e-06,
21
+ 2.1543369643350994e-07,
22
+ ];
23
+
24
+ export const cm2: number[] = [
25
+ 0, 2.0, 1.5, 0.6666666666666667,
26
+ 0.20833333333333348, 0.04999999999999998, 0.09712509625876042, 0.017636684303350972,
27
+ 0.002666977809498494, 0.00033760591160674403, 0.000035714285714285924, 3.1001984126984256e-06,
28
+ 2.1543369643350994e-07,
29
+ ];
30
+
31
+ // User-provided ODE function type
32
+ // t: current time, y: state vector (0-based), ydot: output derivatives (0-based), data: user data
33
+ export type LsodaFunc = (t: number, y: Float64Array, ydot: Float64Array, data: any) => number;
34
+
35
+ // Solver options
36
+ export interface LsodaOpt {
37
+ ixpr: number; // print flag
38
+ mxstep: number; // max internal steps per call
39
+ mxhnil: number; // max step size warnings
40
+ mxordn: number; // max Adams order (1-12)
41
+ mxords: number; // max BDF order (1-5)
42
+ tcrit: number; // critical time for itask 4,5
43
+ h0: number; // initial step size (0 = auto)
44
+ hmax: number; // max absolute step size
45
+ hmin: number; // min absolute step size
46
+ hmxi: number; // 1/hmax (computed)
47
+ itask: number; // integration task (1-5)
48
+ rtol: Float64Array; // relative tolerance (1-indexed)
49
+ atol: Float64Array; // absolute tolerance (1-indexed)
50
+ }
51
+
52
+ // Internal solver state (mirrors lsoda_common_t)
53
+ export class LsodaCommon {
54
+ // Solution history (2D: yh[j][i], 1-indexed)
55
+ yh: Float64Array[] = [];
56
+ // Working matrix for Jacobian/LU (2D: wm[i][j], 1-indexed)
57
+ wm: Float64Array[] = [];
58
+ // Error weights (1-indexed)
59
+ ewt: Float64Array = new Float64Array(0);
60
+ // Saved function values (1-indexed)
61
+ savf: Float64Array = new Float64Array(0);
62
+ // Accumulated corrections (1-indexed)
63
+ acor: Float64Array = new Float64Array(0);
64
+ // Pivot indices for LU (1-indexed)
65
+ ipvt: Int32Array = new Int32Array(0);
66
+
67
+ // Step size
68
+ h: number = 0;
69
+ hu: number = 0;
70
+ rc: number = 0;
71
+ tn: number = 0;
72
+ tsw: number = 0;
73
+ pdnorm: number = 0;
74
+
75
+ // Convergence
76
+ crate: number = 0;
77
+ el: Float64Array = new Float64Array(14);
78
+ hold: number = 0;
79
+ rmax: number = 0;
80
+ pdest: number = 0;
81
+ pdlast: number = 0;
82
+
83
+ // Method coefficients (2D arrays, 1-indexed)
84
+ elco: Float64Array[] = [];
85
+ tesco: Float64Array[] = [];
86
+
87
+ // Counters and flags
88
+ ialth: number = 0;
89
+ ipup: number = 0;
90
+ nslp: number = 0;
91
+ icount: number = 0;
92
+ irflag: number = 0;
93
+ imxer: number = 0;
94
+ illin: number = 0;
95
+ nhnil: number = 0;
96
+ nslast: number = 0;
97
+ jcur: number = 0;
98
+ meth: number = 0;
99
+ mused: number = 0;
100
+ nq: number = 0;
101
+ nst: number = 0;
102
+ ncf: number = 0;
103
+ nfe: number = 0;
104
+ nje: number = 0;
105
+ nqu: number = 0;
106
+ miter: number = 0;
107
+ }
108
+
109
+ // Snapshot of the Nordsieck array at a successful step (0-based arrays)
110
+ export interface NordsieckSnapshot {
111
+ tn: number; // right edge of the step
112
+ h: number; // step size used
113
+ hu: number; // last successful step size (for range check)
114
+ nq: number; // method order
115
+ yh: Float64Array[]; // yh[0..nq], each of length neq (0-based copies)
116
+ }
117
+
118
+ // Solver context
119
+ export class LsodaContext {
120
+ func: LsodaFunc;
121
+ data: any;
122
+ neq: number;
123
+ state: number;
124
+ error: string | null = null;
125
+ common: LsodaCommon | null = null;
126
+ opt: LsodaOpt | null = null;
127
+ snapshots: NordsieckSnapshot[] | null = null;
128
+
129
+ constructor(func: LsodaFunc, neq: number, data?: any) {
130
+ this.func = func;
131
+ this.neq = neq;
132
+ this.data = data ?? null;
133
+ this.state = 1;
134
+ }
135
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * TypeScript port of liblsoda (https://github.com/sdwfrost/liblsoda)
3
+ * Original LSODA algorithm by Linda Petzold & Alan Hindmarsh (1983)
4
+ *
5
+ * Copyright (c) 2011 Yu Feng, McWilliam Cosmology Center, Carnegie Mellon University
6
+ * Copyright (c) 2016 Simon Frost
7
+ * Copyright (c) 2026 Datagrok
8
+ *
9
+ * Licensed under the MIT License. See THIRD_PARTY_LICENSES for the full
10
+ * license text and provenance chain of the original code.
11
+ */
12
+ import { MXNCF } from './common';
13
+ /**
14
+ * Handle corrector convergence failure.
15
+ * Retracts yh array and increments ncf.
16
+ * Returns 2 if unrecoverable, 1 if step can be retried.
17
+ */
18
+ export function corfailure(ctx, told) {
19
+ const c = ctx.common;
20
+ const neq = ctx.neq;
21
+ const hmin = ctx.opt.hmin;
22
+ c.ncf++;
23
+ c.rmax = 2.;
24
+ c.tn = told;
25
+ for (let j = c.nq; j >= 1; j--) {
26
+ for (let i1 = j; i1 <= c.nq; i1++) {
27
+ for (let i = 1; i <= neq; i++)
28
+ c.yh[i1][i] -= c.yh[i1 + 1][i];
29
+ }
30
+ }
31
+ if (Math.abs(c.h) <= hmin * 1.00001 || c.ncf === MXNCF)
32
+ return 2;
33
+ c.ipup = c.miter;
34
+ return 1;
35
+ }
36
+ //# sourceMappingURL=corfailure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"corfailure.js","sourceRoot":"","sources":["corfailure.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAe,KAAK,EAAC,MAAM,UAAU,CAAC;AAE7C;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,GAAiB,EAAE,IAAY;IACxD,MAAM,CAAC,GAAG,GAAG,CAAC,MAAO,CAAC;IACtB,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;IACpB,MAAM,IAAI,GAAG,GAAG,CAAC,GAAI,CAAC,IAAI,CAAC;IAE3B,CAAC,CAAC,GAAG,EAAE,CAAC;IACR,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC;IACZ,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC;IAEZ,KAAK,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/B,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;YAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,EAAE;gBAC3B,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,GAAG,OAAO,IAAI,CAAC,CAAC,GAAG,KAAK,KAAK;QACpD,OAAO,CAAC,CAAC;IAGX,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC;IACjB,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * TypeScript port of liblsoda (https://github.com/sdwfrost/liblsoda)
3
+ * Original LSODA algorithm by Linda Petzold & Alan Hindmarsh (1983)
4
+ *
5
+ * Copyright (c) 2011 Yu Feng, McWilliam Cosmology Center, Carnegie Mellon University
6
+ * Copyright (c) 2016 Simon Frost
7
+ * Copyright (c) 2026 Datagrok
8
+ *
9
+ * Licensed under the MIT License. See THIRD_PARTY_LICENSES for the full
10
+ * license text and provenance chain of the original code.
11
+ */
12
+
13
+ import {LsodaContext, MXNCF} from './common';
14
+
15
+ /**
16
+ * Handle corrector convergence failure.
17
+ * Retracts yh array and increments ncf.
18
+ * Returns 2 if unrecoverable, 1 if step can be retried.
19
+ */
20
+ export function corfailure(ctx: LsodaContext, told: number): number {
21
+ const c = ctx.common!;
22
+ const neq = ctx.neq;
23
+ const hmin = ctx.opt!.hmin;
24
+
25
+ c.ncf++;
26
+ c.rmax = 2.;
27
+ c.tn = told;
28
+
29
+ for (let j = c.nq; j >= 1; j--) {
30
+ for (let i1 = j; i1 <= c.nq; i1++) {
31
+ for (let i = 1; i <= neq; i++)
32
+ c.yh[i1][i] -= c.yh[i1 + 1][i];
33
+ }
34
+ }
35
+
36
+ if (Math.abs(c.h) <= hmin * 1.00001 || c.ncf === MXNCF)
37
+ return 2;
38
+
39
+
40
+ c.ipup = c.miter;
41
+ return 1;
42
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * TypeScript port of liblsoda (https://github.com/sdwfrost/liblsoda)
3
+ * Original LSODA algorithm by Linda Petzold & Alan Hindmarsh (1983)
4
+ *
5
+ * Copyright (c) 2011 Yu Feng, McWilliam Cosmology Center, Carnegie Mellon University
6
+ * Copyright (c) 2016 Simon Frost
7
+ * Copyright (c) 2026 Datagrok
8
+ *
9
+ * Licensed under the MIT License. See THIRD_PARTY_LICENSES for the full
10
+ * license text and provenance chain of the original code.
11
+ */
12
+ import { ETA, MAXCOR } from './common';
13
+ import { vmnorm } from './blas';
14
+ import { prja } from './prja';
15
+ import { solsy } from './solsy';
16
+ import { corfailure } from './corfailure';
17
+ /**
18
+ * Corrector iteration.
19
+ * Returns corflag: 0 = converged, 1 = reduce step & redo prediction, 2 = failure.
20
+ */
21
+ export function correction(ctx, y, pnorm, cs, told) {
22
+ const c = ctx.common;
23
+ const neq = ctx.neq;
24
+ cs.m = 0;
25
+ let rate = 0.;
26
+ cs.del = 0.;
27
+ for (let i = 1; i <= neq; i++)
28
+ y[i] = c.yh[1][i];
29
+ ctx.func(c.tn, y.subarray(1), c.savf.subarray(1), ctx.data);
30
+ c.nfe++;
31
+ while (true) {
32
+ if (cs.m === 0) {
33
+ if (c.ipup > 0) {
34
+ const ierpj = prja(ctx, y);
35
+ c.jcur = 1;
36
+ c.ipup = 0;
37
+ c.rc = 1.;
38
+ c.nslp = c.nst;
39
+ c.crate = 0.7;
40
+ if (!ierpj)
41
+ return corfailure(ctx, told);
42
+ }
43
+ for (let i = 1; i <= neq; i++)
44
+ c.acor[i] = 0.;
45
+ }
46
+ if (c.miter === 0) {
47
+ // Functional iteration
48
+ for (let i = 1; i <= neq; i++) {
49
+ c.savf[i] = c.h * c.savf[i] - c.yh[2][i];
50
+ y[i] = c.savf[i] - c.acor[i];
51
+ }
52
+ cs.del = vmnorm(neq, y, c.ewt);
53
+ for (let i = 1; i <= neq; i++) {
54
+ y[i] = c.yh[1][i] + c.el[1] * c.savf[i];
55
+ c.acor[i] = c.savf[i];
56
+ }
57
+ }
58
+ else {
59
+ // Chord method
60
+ for (let i = 1; i <= neq; i++)
61
+ y[i] = c.h * c.savf[i] - (c.yh[2][i] + c.acor[i]);
62
+ solsy(ctx, y);
63
+ cs.del = vmnorm(neq, y, c.ewt);
64
+ for (let i = 1; i <= neq; i++) {
65
+ c.acor[i] += y[i];
66
+ y[i] = c.yh[1][i] + c.el[1] * c.acor[i];
67
+ }
68
+ }
69
+ // Test for convergence
70
+ if (cs.del <= 100. * pnorm * ETA)
71
+ break;
72
+ if (cs.m !== 0 || c.meth !== 1) {
73
+ if (cs.m !== 0) {
74
+ let rm = 1024.0;
75
+ if (cs.del <= 1024. * cs.delp)
76
+ rm = cs.del / cs.delp;
77
+ rate = Math.max(rate, rm);
78
+ c.crate = Math.max(0.2 * c.crate, rm);
79
+ }
80
+ const conit = 0.5 / (c.nq + 2);
81
+ const dcon = cs.del * Math.min(1., 1.5 * c.crate) / (c.tesco[c.nq][2] * conit);
82
+ if (dcon <= 1.) {
83
+ c.pdest = Math.max(c.pdest, rate / Math.abs(c.h * c.el[1]));
84
+ if (c.pdest !== 0.)
85
+ c.pdlast = c.pdest;
86
+ break;
87
+ }
88
+ }
89
+ // Corrector iteration failed to converge
90
+ cs.m++;
91
+ if (cs.m === MAXCOR || (cs.m >= 2 && cs.del > 2. * cs.delp)) {
92
+ if (c.miter === 0 || c.jcur === 1)
93
+ return corfailure(ctx, told);
94
+ c.ipup = c.miter;
95
+ // Restart corrector if Jacobian is recomputed
96
+ cs.m = 0;
97
+ rate = 0.;
98
+ cs.del = 0.;
99
+ for (let i = 1; i <= neq; i++)
100
+ y[i] = c.yh[1][i];
101
+ ctx.func(c.tn, y.subarray(1), c.savf.subarray(1), ctx.data);
102
+ c.nfe++;
103
+ }
104
+ else {
105
+ cs.delp = cs.del;
106
+ ctx.func(c.tn, y.subarray(1), c.savf.subarray(1), ctx.data);
107
+ c.nfe++;
108
+ }
109
+ }
110
+ return 0;
111
+ }
112
+ //# sourceMappingURL=correction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"correction.js","sourceRoot":"","sources":["correction.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAe,GAAG,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AACnD,OAAO,EAAC,MAAM,EAAC,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAC,IAAI,EAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAC,KAAK,EAAC,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AASxC;;;GAGG;AACH,MAAM,UAAU,UAAU,CACxB,GAAiB,EAAE,CAAe,EAAE,KAAa,EACjD,EAAmB,EAAE,IAAY;IAEjC,MAAM,CAAC,GAAG,GAAG,CAAC,MAAO,CAAC;IACtB,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC;IAEpB,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;IACT,I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G,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;YAC5D,CAAC,CAAC,GAAG,EAAE,CAAC;QACV,CAAC;aAAM,CAAC;YACN,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,GAAG,CAAC;YACjB,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;YAC5D,CAAC,CAAC,GAAG,EAAE,CAAC;QACV,CAAC;IACH,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,131 @@
1
+ /**
2
+ * TypeScript port of liblsoda (https://github.com/sdwfrost/liblsoda)
3
+ * Original LSODA algorithm by Linda Petzold & Alan Hindmarsh (1983)
4
+ *
5
+ * Copyright (c) 2011 Yu Feng, McWilliam Cosmology Center, Carnegie Mellon University
6
+ * Copyright (c) 2016 Simon Frost
7
+ * Copyright (c) 2026 Datagrok
8
+ *
9
+ * Licensed under the MIT License. See THIRD_PARTY_LICENSES for the full
10
+ * license text and provenance chain of the original code.
11
+ */
12
+
13
+ import {LsodaContext, ETA, MAXCOR} from './common';
14
+ import {vmnorm} from './blas';
15
+ import {prja} from './prja';
16
+ import {solsy} from './solsy';
17
+ import {corfailure} from './corfailure';
18
+
19
+ /** Mutable state passed between correction and stoda */
20
+ export interface CorrectionState {
21
+ del: number;
22
+ delp: number;
23
+ m: number;
24
+ }
25
+
26
+ /**
27
+ * Corrector iteration.
28
+ * Returns corflag: 0 = converged, 1 = reduce step & redo prediction, 2 = failure.
29
+ */
30
+ export function correction(
31
+ ctx: LsodaContext, y: Float64Array, pnorm: number,
32
+ cs: CorrectionState, told: number,
33
+ ): number {
34
+ const c = ctx.common!;
35
+ const neq = ctx.neq;
36
+
37
+ cs.m = 0;
38
+ let rate = 0.;
39
+ cs.del = 0.;
40
+
41
+ for (let i = 1; i <= neq; i++)
42
+ y[i] = c.yh[1][i];
43
+
44
+ ctx.func(c.tn, y.subarray(1), c.savf.subarray(1), ctx.data);
45
+ c.nfe++;
46
+
47
+ while (true) {
48
+ if (cs.m === 0) {
49
+ if (c.ipup > 0) {
50
+ const ierpj = prja(ctx, y);
51
+ c.jcur = 1;
52
+ c.ipup = 0;
53
+ c.rc = 1.;
54
+ c.nslp = c.nst;
55
+ c.crate = 0.7;
56
+ if (!ierpj)
57
+ return corfailure(ctx, told);
58
+ }
59
+ for (let i = 1; i <= neq; i++)
60
+ c.acor[i] = 0.;
61
+ }
62
+
63
+ if (c.miter === 0) {
64
+ // Functional iteration
65
+ for (let i = 1; i <= neq; i++) {
66
+ c.savf[i] = c.h * c.savf[i] - c.yh[2][i];
67
+ y[i] = c.savf[i] - c.acor[i];
68
+ }
69
+ cs.del = vmnorm(neq, y, c.ewt);
70
+ for (let i = 1; i <= neq; i++) {
71
+ y[i] = c.yh[1][i] + c.el[1] * c.savf[i];
72
+ c.acor[i] = c.savf[i];
73
+ }
74
+ } else {
75
+ // Chord method
76
+ for (let i = 1; i <= neq; i++)
77
+ y[i] = c.h * c.savf[i] - (c.yh[2][i] + c.acor[i]);
78
+ solsy(ctx, y);
79
+ cs.del = vmnorm(neq, y, c.ewt);
80
+ for (let i = 1; i <= neq; i++) {
81
+ c.acor[i] += y[i];
82
+ y[i] = c.yh[1][i] + c.el[1] * c.acor[i];
83
+ }
84
+ }
85
+
86
+ // Test for convergence
87
+ if (cs.del <= 100. * pnorm * ETA)
88
+ break;
89
+
90
+ if (cs.m !== 0 || c.meth !== 1) {
91
+ if (cs.m !== 0) {
92
+ let rm = 1024.0;
93
+ if (cs.del <= 1024. * cs.delp)
94
+ rm = cs.del / cs.delp;
95
+ rate = Math.max(rate, rm);
96
+ c.crate = Math.max(0.2 * c.crate, rm);
97
+ }
98
+ const conit = 0.5 / (c.nq + 2);
99
+ const dcon = cs.del * Math.min(1., 1.5 * c.crate) / (c.tesco[c.nq][2] * conit);
100
+ if (dcon <= 1.) {
101
+ c.pdest = Math.max(c.pdest, rate / Math.abs(c.h * c.el[1]));
102
+ if (c.pdest !== 0.)
103
+ c.pdlast = c.pdest;
104
+ break;
105
+ }
106
+ }
107
+
108
+ // Corrector iteration failed to converge
109
+ cs.m++;
110
+ if (cs.m === MAXCOR || (cs.m >= 2 && cs.del > 2. * cs.delp)) {
111
+ if (c.miter === 0 || c.jcur === 1)
112
+ return corfailure(ctx, told);
113
+
114
+ c.ipup = c.miter;
115
+ // Restart corrector if Jacobian is recomputed
116
+ cs.m = 0;
117
+ rate = 0.;
118
+ cs.del = 0.;
119
+ for (let i = 1; i <= neq; i++)
120
+ y[i] = c.yh[1][i];
121
+ ctx.func(c.tn, y.subarray(1), c.savf.subarray(1), ctx.data);
122
+ c.nfe++;
123
+ } else {
124
+ cs.delp = cs.del;
125
+ ctx.func(c.tn, y.subarray(1), c.savf.subarray(1), ctx.data);
126
+ c.nfe++;
127
+ }
128
+ }
129
+
130
+ return 0;
131
+ }