diff-grok 1.1.0 → 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.
- package/.claude/skills/license-updater/SKILL.md +149 -0
- package/.claude/skills/license-updater/references/compatibility.md +68 -0
- package/.claude/skills/license-updater/references/templates.md +151 -0
- package/.claude/skills/license-updater/scripts/generate_license_files.py +467 -0
- package/CLAUDE.md +10 -4
- package/LICENSE +1 -1
- package/README.MD +41 -23
- package/THIRD_PARTY_LICENSES +135 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +99 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1633 -0
- package/docs/classes/BasicModelPipelineCreator.html +10 -0
- package/docs/classes/Callback.html +7 -0
- package/docs/classes/CyclicModelPipelineCreator.html +10 -0
- package/docs/classes/IterCheckerCallback.html +8 -0
- package/docs/classes/PipelineCreator.html +6 -0
- package/docs/classes/TimeCheckerCallback.html +8 -0
- package/docs/classes/UpdatesModelPipelineCreator.html +10 -0
- package/docs/functions/ab4.html +8 -0
- package/docs/functions/ab5.html +8 -0
- package/docs/functions/applyPipeline.html +9 -0
- package/docs/functions/getCallback.html +3 -0
- package/docs/functions/getIVP.html +6 -0
- package/docs/functions/getInputVector.html +2 -0
- package/docs/functions/getIvp2WebWorker.html +6 -0
- package/docs/functions/getJScode.html +6 -0
- package/docs/functions/getOutputNames.html +4 -0
- package/docs/functions/getPipelineCreator.html +7 -0
- package/docs/functions/lsoda.html +8 -0
- package/docs/functions/mrt.html +11 -0
- package/docs/functions/printE5.html +76 -0
- package/docs/functions/printHires.html +76 -0
- package/docs/functions/printOrego.html +66 -0
- package/docs/functions/printPollution.html +163 -0
- package/docs/functions/printRobertson.html +60 -0
- package/docs/functions/printVdpol.html +66 -0
- package/docs/functions/rk3.html +8 -0
- package/docs/functions/rk4.html +8 -0
- package/docs/functions/rkdp.html +8 -0
- package/docs/functions/ros34prw.html +8 -0
- package/docs/functions/ros3prw.html +8 -0
- package/docs/functions/solveIvp.html +5 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +768 -0
- package/docs/media/CONTRIBUTING.md +74 -0
- package/docs/media/E5.png +0 -0
- package/docs/media/HIRES.png +0 -0
- package/docs/media/OREGO.png +0 -0
- package/docs/media/POLL-full.png +0 -0
- package/docs/media/POLL.png +0 -0
- package/docs/media/ROBER.png +0 -0
- package/docs/media/VDP0L.png +0 -0
- package/docs/media/VDPOL.png +0 -0
- package/docs/media/acid-prod.gif +0 -0
- package/docs/media/basic-use.js +40 -0
- package/docs/media/basic-use.js.map +1 -0
- package/docs/media/basic-use.ts +44 -0
- package/docs/media/check-methods.js +59 -0
- package/docs/media/check-methods.js.map +1 -0
- package/docs/media/check-methods.ts +81 -0
- package/docs/media/corr-probs.js +132 -0
- package/docs/media/corr-probs.js.map +1 -0
- package/docs/media/corr-probs.ts +155 -0
- package/docs/media/cyclic-model.js +102 -0
- package/docs/media/cyclic-model.js.map +1 -0
- package/docs/media/cyclic-model.ts +112 -0
- package/docs/media/e5.js +36 -0
- package/docs/media/e5.js.map +1 -0
- package/docs/media/e5.ts +36 -0
- package/docs/media/hires.js +39 -0
- package/docs/media/hires.js.map +1 -0
- package/docs/media/hires.ts +40 -0
- package/docs/media/model-updates.js +112 -0
- package/docs/media/model-updates.js.map +1 -0
- package/docs/media/model-updates.ts +122 -0
- package/docs/media/orego.js +24 -0
- package/docs/media/orego.js.map +1 -0
- package/docs/media/orego.ts +25 -0
- package/docs/media/pipeline-use.js +87 -0
- package/docs/media/pipeline-use.js.map +1 -0
- package/docs/media/pipeline-use.ts +98 -0
- package/docs/media/pollution.js +132 -0
- package/docs/media/pollution.js.map +1 -0
- package/docs/media/pollution.ts +133 -0
- package/docs/media/print-benchmark.js +581 -0
- package/docs/media/print-benchmark.js.map +1 -0
- package/docs/media/print-benchmark.ts +594 -0
- package/docs/media/robertson.js +19 -0
- package/docs/media/robertson.js.map +1 -0
- package/docs/media/robertson.ts +19 -0
- package/docs/media/scripting.js +30 -0
- package/docs/media/scripting.js.map +1 -0
- package/docs/media/scripting.ts +35 -0
- package/docs/media/vdpol.js +17 -0
- package/docs/media/vdpol.js.map +1 -0
- package/docs/media/vdpol.ts +17 -0
- package/docs/modules.html +1 -0
- package/docs/types/Arg.html +12 -0
- package/docs/types/DifEqs.html +8 -0
- package/docs/types/Func.html +7 -0
- package/docs/types/IVP.html +40 -0
- package/docs/types/IVP2WebWorker.html +12 -0
- package/docs/types/Input.html +8 -0
- package/docs/types/Loop.html +7 -0
- package/docs/types/ODEs.html +31 -0
- package/docs/types/Output.html +6 -0
- package/docs/types/Pipeline.html +6 -0
- package/docs/types/SolverOptions.html +8 -0
- package/docs/types/Update.html +9 -0
- package/docs/types/Wrapper.html +8 -0
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/index.ts +1 -1
- package/package.json +4 -2
- package/src/examples/check-methods.js +15 -3
- package/src/examples/check-methods.js.map +1 -1
- package/src/examples/check-methods.ts +18 -3
- package/src/solver-tools/cvode/common.js +487 -0
- package/src/solver-tools/cvode/common.js.map +1 -0
- package/src/solver-tools/cvode/common.ts +549 -0
- package/src/solver-tools/cvode/cvode.js +1062 -0
- package/src/solver-tools/cvode/cvode.js.map +1 -0
- package/src/solver-tools/cvode/cvode.ts +1226 -0
- package/src/solver-tools/cvode/cvode_adams.js +124 -0
- package/src/solver-tools/cvode/cvode_adams.js.map +1 -0
- package/src/solver-tools/cvode/cvode_adams.ts +142 -0
- package/src/solver-tools/cvode/cvode_bdf.js +153 -0
- package/src/solver-tools/cvode/cvode_bdf.js.map +1 -0
- package/src/solver-tools/cvode/cvode_bdf.ts +164 -0
- package/src/solver-tools/cvode/cvode_class.js +158 -0
- package/src/solver-tools/cvode/cvode_class.js.map +1 -0
- package/src/solver-tools/cvode/cvode_class.ts +271 -0
- package/src/solver-tools/cvode/cvode_hin.js +119 -0
- package/src/solver-tools/cvode/cvode_hin.js.map +1 -0
- package/src/solver-tools/cvode/cvode_hin.ts +150 -0
- package/src/solver-tools/cvode/cvode_io.js +203 -0
- package/src/solver-tools/cvode/cvode_io.js.map +1 -0
- package/src/solver-tools/cvode/cvode_io.ts +258 -0
- package/src/solver-tools/cvode/cvode_ls.js +210 -0
- package/src/solver-tools/cvode/cvode_ls.js.map +1 -0
- package/src/solver-tools/cvode/cvode_ls.ts +249 -0
- package/src/solver-tools/cvode/cvode_nls.js +220 -0
- package/src/solver-tools/cvode/cvode_nls.js.map +1 -0
- package/src/solver-tools/cvode/cvode_nls.ts +259 -0
- package/src/solver-tools/cvode/cvode_root.js +415 -0
- package/src/solver-tools/cvode/cvode_root.js.map +1 -0
- package/src/solver-tools/cvode/cvode_root.ts +503 -0
- package/src/solver-tools/cvode/dense_linalg.js +131 -0
- package/src/solver-tools/cvode/dense_linalg.js.map +1 -0
- package/src/solver-tools/cvode/dense_linalg.ts +144 -0
- package/src/solver-tools/cvode/index.js +26 -0
- package/src/solver-tools/cvode/index.js.map +1 -0
- package/src/solver-tools/cvode/index.ts +64 -0
- package/src/solver-tools/cvode-method.js +114 -0
- package/src/solver-tools/cvode-method.js.map +1 -0
- package/src/solver-tools/cvode-method.ts +129 -0
- package/src/solver-tools/index.js +1 -0
- package/src/solver-tools/index.js.map +1 -1
- package/src/solver-tools/index.ts +1 -0
- package/src/solver-tools/lsoda/blas.js +11 -0
- package/src/solver-tools/lsoda/blas.js.map +1 -1
- package/src/solver-tools/lsoda/blas.ts +12 -0
- package/src/solver-tools/lsoda/cfode.js +11 -0
- package/src/solver-tools/lsoda/cfode.js.map +1 -1
- package/src/solver-tools/lsoda/cfode.ts +12 -0
- package/src/solver-tools/lsoda/corfailure.js +11 -0
- package/src/solver-tools/lsoda/corfailure.js.map +1 -1
- package/src/solver-tools/lsoda/corfailure.ts +12 -0
- package/src/solver-tools/lsoda/correction.js +11 -0
- package/src/solver-tools/lsoda/correction.js.map +1 -1
- package/src/solver-tools/lsoda/correction.ts +12 -0
- package/src/solver-tools/lsoda/dense.js +11 -0
- package/src/solver-tools/lsoda/dense.js.map +1 -1
- package/src/solver-tools/lsoda/dense.ts +12 -0
- package/src/solver-tools/lsoda/index.js +11 -0
- package/src/solver-tools/lsoda/index.js.map +1 -1
- package/src/solver-tools/lsoda/index.ts +12 -0
- package/src/solver-tools/lsoda/intdy.js +11 -0
- package/src/solver-tools/lsoda/intdy.js.map +1 -1
- package/src/solver-tools/lsoda/intdy.ts +12 -0
- package/src/solver-tools/lsoda/lsoda.js +11 -0
- package/src/solver-tools/lsoda/lsoda.js.map +1 -1
- package/src/solver-tools/lsoda/lsoda.ts +12 -0
- package/src/solver-tools/lsoda/methodswitch.js +11 -0
- package/src/solver-tools/lsoda/methodswitch.js.map +1 -1
- package/src/solver-tools/lsoda/methodswitch.ts +12 -0
- package/src/solver-tools/lsoda/orderswitch.js +11 -0
- package/src/solver-tools/lsoda/orderswitch.js.map +1 -1
- package/src/solver-tools/lsoda/orderswitch.ts +12 -0
- package/src/solver-tools/lsoda/prja.js +11 -0
- package/src/solver-tools/lsoda/prja.js.map +1 -1
- package/src/solver-tools/lsoda/prja.ts +12 -0
- package/src/solver-tools/lsoda/scaleh.js +11 -0
- package/src/solver-tools/lsoda/scaleh.js.map +1 -1
- package/src/solver-tools/lsoda/scaleh.ts +12 -0
- package/src/solver-tools/lsoda/solsy.js +11 -0
- package/src/solver-tools/lsoda/solsy.js.map +1 -1
- package/src/solver-tools/lsoda/solsy.ts +12 -0
- package/src/solver-tools/lsoda/stoda.js +11 -0
- package/src/solver-tools/lsoda/stoda.js.map +1 -1
- package/src/solver-tools/lsoda/stoda.ts +12 -0
- package/src/solver-tools/lsoda-method.js +23 -9
- package/src/solver-tools/lsoda-method.js.map +1 -1
- package/src/solver-tools/lsoda-method.ts +27 -9
- package/src/solver-tools/solver-defs.js +1 -0
- package/src/solver-tools/solver-defs.js.map +1 -1
- package/src/solver-tools/solver-defs.ts +1 -0
- package/src/tests/cvode-lib-correctness.test.js +404 -0
- package/src/tests/cvode-lib-correctness.test.js.map +1 -0
- package/src/tests/cvode-lib-correctness.test.ts +505 -0
- package/src/tests/cvode-lib-performance.test.js +103 -0
- package/src/tests/cvode-lib-performance.test.js.map +1 -0
- package/src/tests/cvode-lib-performance.test.ts +128 -0
- package/src/tests/performance.test.js +4 -2
- package/src/tests/performance.test.js.map +1 -1
- package/src/tests/performance.test.ts +4 -2
- package/src/tests/test-defs.js +7 -1
- package/src/tests/test-defs.js.map +1 -1
- package/src/tests/test-defs.ts +8 -1
- package/src/worker-tools/solving.js +3 -1
- package/src/worker-tools/solving.js.map +1 -1
- package/src/worker-tools/solving.ts +4 -1
- package/src/examples/bioreactor.js +0 -125
- package/src/examples/bioreactor.js.map +0 -1
- package/src/examples/bioreactor.ts +0 -132
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript port of SUNDIALS CVODE v7.5.0 (https://github.com/LLNL/sundials)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025, Lawrence Livermore National Security, University of
|
|
5
|
+
* Maryland Baltimore County, and the SUNDIALS contributors.
|
|
6
|
+
* Copyright (c) 2013-2025, Lawrence Livermore National Security and
|
|
7
|
+
* Southern Methodist University.
|
|
8
|
+
* Copyright (c) 2002-2013, Lawrence Livermore National Security.
|
|
9
|
+
* Copyright (c) 2026 Datagrok.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the BSD-3-Clause License. See THIRD_PARTY_LICENSES
|
|
12
|
+
* for the full license text and provenance chain of the original code.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// CVODE TypeScript port - Initial step size estimation
|
|
16
|
+
// Ported from SUNDIALS CVODE cvode.c (cvHin, cvUpperBoundH0, cvYddNorm)
|
|
17
|
+
|
|
18
|
+
import {CvodeMem, wrmsNorm, vLinearSum, vScale, CV_SUCCESS,
|
|
19
|
+
CV_RHSFUNC_FAIL, RHSFUNC_RECVR, CV_TOO_CLOSE,
|
|
20
|
+
HLB_FACTOR, HUB_FACTOR, H_BIAS, MAX_ITERS, TINY} from './common';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* cvHin - Compute initial step size h0.
|
|
24
|
+
*
|
|
25
|
+
* The algorithm:
|
|
26
|
+
* 1. Compute a bound hub on |h| from ydot and tdist
|
|
27
|
+
* 2. Set hlb = HLB_FACTOR * tround (lower bound)
|
|
28
|
+
* 3. Iterate to estimate ||y''|| and compute h candidates
|
|
29
|
+
* 4. h0 = H_BIAS * geometric mean of hlb and hub candidates
|
|
30
|
+
*/
|
|
31
|
+
export function cvHin(mem: CvodeMem, tout: number): number {
|
|
32
|
+
const N = mem.cv_N;
|
|
33
|
+
const sign = (tout - mem.cv_tn >= 0.0) ? 1.0 : -1.0;
|
|
34
|
+
const tdist = Math.abs(tout - mem.cv_tn);
|
|
35
|
+
const tround = Math.max(Math.abs(mem.cv_tn), Math.abs(tout)) * 2.2204460492503131e-16;
|
|
36
|
+
|
|
37
|
+
if (tdist < 2.0 * tround) return CV_TOO_CLOSE;
|
|
38
|
+
|
|
39
|
+
// Set lower and upper bounds on h0, initial guess
|
|
40
|
+
const hlb = HLB_FACTOR * tround;
|
|
41
|
+
const hub = cvUpperBoundH0(mem, tdist);
|
|
42
|
+
|
|
43
|
+
// Initial guess - geometric mean
|
|
44
|
+
let hg = Math.sqrt(hlb * hub);
|
|
45
|
+
if (hub < 100.0 * hlb)
|
|
46
|
+
hg = 0.5 * hub;
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
// Iterate to estimate ydd norm
|
|
50
|
+
let hnew = hg;
|
|
51
|
+
let retval: number;
|
|
52
|
+
|
|
53
|
+
for (let count = 0; count < MAX_ITERS; count++) {
|
|
54
|
+
hg = hnew;
|
|
55
|
+
|
|
56
|
+
// Compute y''norm via finite difference
|
|
57
|
+
const result = cvYddNorm(mem, hg * sign);
|
|
58
|
+
retval = result.retval;
|
|
59
|
+
if (retval !== CV_SUCCESS) return retval;
|
|
60
|
+
|
|
61
|
+
const yddnrm = result.yddnrm;
|
|
62
|
+
|
|
63
|
+
// If yddnrm is zero, use current hg
|
|
64
|
+
if (yddnrm * hub * hub > 2.0)
|
|
65
|
+
hnew = Math.sqrt(2.0 / yddnrm);
|
|
66
|
+
else
|
|
67
|
+
hnew = Math.sqrt(hg * hub);
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
// Refine: make hnew be a geometric mean biased toward smaller
|
|
71
|
+
hnew = H_BIAS * hnew + (1.0 - H_BIAS) * hg;
|
|
72
|
+
|
|
73
|
+
// Check convergence
|
|
74
|
+
if (hnew / hg > 2.0 || hnew / hg < 0.5) continue;
|
|
75
|
+
// If converged, break
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Bound hnew
|
|
80
|
+
hnew = Math.min(hnew, hub);
|
|
81
|
+
hnew = Math.max(hnew, hlb);
|
|
82
|
+
|
|
83
|
+
// Apply bounds on step size
|
|
84
|
+
if (mem.cv_hmax_inv > 0.0)
|
|
85
|
+
hnew = Math.min(hnew, 1.0 / mem.cv_hmax_inv);
|
|
86
|
+
|
|
87
|
+
if (mem.cv_hmin > 0.0)
|
|
88
|
+
hnew = Math.max(hnew, mem.cv_hmin);
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
// Bound by tdist
|
|
92
|
+
hnew = Math.min(hnew, tdist);
|
|
93
|
+
|
|
94
|
+
mem.cv_h = sign * hnew;
|
|
95
|
+
mem.cv_next_h = mem.cv_h;
|
|
96
|
+
mem.cv_hscale = mem.cv_h;
|
|
97
|
+
|
|
98
|
+
// Scale zn[1] = h * y'(t0)
|
|
99
|
+
vScale(mem.cv_h, mem.cv_zn[1], mem.cv_zn[1], N);
|
|
100
|
+
|
|
101
|
+
return CV_SUCCESS;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* cvUpperBoundH0 - Compute upper bound on initial step size
|
|
106
|
+
* Based on ||y'|| weighted norm
|
|
107
|
+
*/
|
|
108
|
+
function cvUpperBoundH0(mem: CvodeMem, tdist: number): number {
|
|
109
|
+
const N = mem.cv_N;
|
|
110
|
+
|
|
111
|
+
// Get WRMS norm of y' (zn[1] = f(t0, y0) before scaling)
|
|
112
|
+
const hub_inv = wrmsNorm(N, mem.cv_zn[1], mem.cv_ewt);
|
|
113
|
+
|
|
114
|
+
// Bound based on tdist
|
|
115
|
+
let hub = HUB_FACTOR * tdist;
|
|
116
|
+
|
|
117
|
+
// Use smaller of two bounds
|
|
118
|
+
if (hub * hub_inv > 1.0)
|
|
119
|
+
hub = 1.0 / hub_inv;
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
return hub;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* cvYddNorm - Estimate ||y''|| via finite difference
|
|
127
|
+
* y(t0 + hg) ~ y0 + hg*y'0
|
|
128
|
+
* y'(t0 + hg) = f(t0 + hg, y(t0 + hg))
|
|
129
|
+
* y'' ~ (y'(t0+hg) - y'(t0)) / hg
|
|
130
|
+
*/
|
|
131
|
+
function cvYddNorm(mem: CvodeMem, hg: number): { retval: number; yddnrm: number } {
|
|
132
|
+
const N = mem.cv_N;
|
|
133
|
+
|
|
134
|
+
// y = zn[0] + hg * zn[1] (zn[1] still holds unscaled f at this point)
|
|
135
|
+
vLinearSum(hg, mem.cv_zn[1], 1.0, mem.cv_zn[0], mem.cv_y, N);
|
|
136
|
+
|
|
137
|
+
// Evaluate f(t0 + hg, y)
|
|
138
|
+
const retval = mem.cv_f!(mem.cv_tn + hg, mem.cv_y, mem.cv_tempv, mem.cv_user_data);
|
|
139
|
+
mem.cv_nfe++;
|
|
140
|
+
if (retval < 0) return {retval: CV_RHSFUNC_FAIL, yddnrm: 0};
|
|
141
|
+
if (retval > 0) return {retval: RHSFUNC_RECVR, yddnrm: 0};
|
|
142
|
+
|
|
143
|
+
// tempv = (f(t0+hg, y) - zn[1]) / hg (estimate of y'')
|
|
144
|
+
const hg_inv = 1.0 / hg;
|
|
145
|
+
vLinearSum(hg_inv, mem.cv_tempv, -hg_inv, mem.cv_zn[1], mem.cv_tempv, N);
|
|
146
|
+
|
|
147
|
+
const yddnrm = wrmsNorm(N, mem.cv_tempv, mem.cv_ewt);
|
|
148
|
+
|
|
149
|
+
return {retval: CV_SUCCESS, yddnrm};
|
|
150
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript port of SUNDIALS CVODE v7.5.0 (https://github.com/LLNL/sundials)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025, Lawrence Livermore National Security, University of
|
|
5
|
+
* Maryland Baltimore County, and the SUNDIALS contributors.
|
|
6
|
+
* Copyright (c) 2013-2025, Lawrence Livermore National Security and
|
|
7
|
+
* Southern Methodist University.
|
|
8
|
+
* Copyright (c) 2002-2013, Lawrence Livermore National Security.
|
|
9
|
+
* Copyright (c) 2026 Datagrok.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the BSD-3-Clause License. See THIRD_PARTY_LICENSES
|
|
12
|
+
* for the full license text and provenance chain of the original code.
|
|
13
|
+
*/
|
|
14
|
+
// CVODE TypeScript port - Configuration and statistics I/O functions
|
|
15
|
+
// Ported from SUNDIALS CVODE v7.5.0 (cvode_io.c)
|
|
16
|
+
import { CV_SUCCESS, CV_SS, CV_SV, ADAMS_Q_MAX, BDF_Q_MAX, CV_ADAMS, } from './common';
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// Tolerance functions
|
|
19
|
+
// ============================================================================
|
|
20
|
+
/**
|
|
21
|
+
* Set scalar relative and absolute tolerances.
|
|
22
|
+
* Requires rtol >= 0 and atol >= 0.
|
|
23
|
+
*/
|
|
24
|
+
export function cvodeSStolerances(mem, rtol, atol) {
|
|
25
|
+
if (rtol < 0) {
|
|
26
|
+
mem.cv_error = 'cvodeSStolerances: rtol must be >= 0';
|
|
27
|
+
return -1;
|
|
28
|
+
}
|
|
29
|
+
if (atol < 0) {
|
|
30
|
+
mem.cv_error = 'cvodeSStolerances: atol must be >= 0';
|
|
31
|
+
return -1;
|
|
32
|
+
}
|
|
33
|
+
mem.cv_reltol = rtol;
|
|
34
|
+
mem.cv_Sabstol = atol;
|
|
35
|
+
mem.cv_itol = CV_SS;
|
|
36
|
+
mem.cv_atolmin0 = (atol === 0);
|
|
37
|
+
return CV_SUCCESS;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Set scalar relative tolerance and vector absolute tolerance.
|
|
41
|
+
* Requires rtol >= 0 and all atol[i] >= 0.
|
|
42
|
+
*/
|
|
43
|
+
export function cvodeSVtolerances(mem, rtol, atol) {
|
|
44
|
+
if (rtol < 0) {
|
|
45
|
+
mem.cv_error = 'cvodeSVtolerances: rtol must be >= 0';
|
|
46
|
+
return -1;
|
|
47
|
+
}
|
|
48
|
+
for (let i = 0; i < atol.length; i++) {
|
|
49
|
+
if (atol[i] < 0) {
|
|
50
|
+
mem.cv_error = `cvodeSVtolerances: atol[${i}] must be >= 0`;
|
|
51
|
+
return -1;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
mem.cv_reltol = rtol;
|
|
55
|
+
mem.cv_Vabstol = new Float64Array(atol);
|
|
56
|
+
mem.cv_itol = CV_SV;
|
|
57
|
+
let minAtol = Infinity;
|
|
58
|
+
for (let i = 0; i < atol.length; i++)
|
|
59
|
+
if (atol[i] < minAtol)
|
|
60
|
+
minAtol = atol[i];
|
|
61
|
+
mem.cv_atolmin0 = (minAtol === 0);
|
|
62
|
+
mem.cv_VabstolMallocDone = true;
|
|
63
|
+
return CV_SUCCESS;
|
|
64
|
+
}
|
|
65
|
+
// ============================================================================
|
|
66
|
+
// Optional input functions
|
|
67
|
+
// ============================================================================
|
|
68
|
+
/**
|
|
69
|
+
* Set the maximum number of internal steps per call to CVode.
|
|
70
|
+
*/
|
|
71
|
+
export function cvodeSetMaxNumSteps(mem, mxstep) {
|
|
72
|
+
mem.cv_mxstep = mxstep;
|
|
73
|
+
return CV_SUCCESS;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Set the maximum method order. Clamped to [1, qmax] where qmax is
|
|
77
|
+
* ADAMS_Q_MAX or BDF_Q_MAX depending on the linear multistep method.
|
|
78
|
+
*/
|
|
79
|
+
export function cvodeSetMaxOrd(mem, maxord) {
|
|
80
|
+
const qmax = (mem.cv_lmm === CV_ADAMS) ? ADAMS_Q_MAX : BDF_Q_MAX;
|
|
81
|
+
if (maxord < 1)
|
|
82
|
+
maxord = 1;
|
|
83
|
+
if (maxord > qmax)
|
|
84
|
+
maxord = qmax;
|
|
85
|
+
mem.cv_qmax = maxord;
|
|
86
|
+
return CV_SUCCESS;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Set the maximum step size. If hmax <= 0, no upper limit is imposed
|
|
90
|
+
* (cv_hmax_inv = 0). Otherwise cv_hmax_inv = 1 / hmax.
|
|
91
|
+
*/
|
|
92
|
+
export function cvodeSetMaxStep(mem, hmax) {
|
|
93
|
+
if (hmax <= 0)
|
|
94
|
+
mem.cv_hmax_inv = 0;
|
|
95
|
+
else
|
|
96
|
+
mem.cv_hmax_inv = 1.0 / hmax;
|
|
97
|
+
return CV_SUCCESS;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Set the minimum step size (stored as absolute value).
|
|
101
|
+
*/
|
|
102
|
+
export function cvodeSetMinStep(mem, hmin) {
|
|
103
|
+
mem.cv_hmin = Math.abs(hmin);
|
|
104
|
+
return CV_SUCCESS;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Set the initial step size hint.
|
|
108
|
+
*/
|
|
109
|
+
export function cvodeSetInitStep(mem, hin) {
|
|
110
|
+
mem.cv_hin = hin;
|
|
111
|
+
return CV_SUCCESS;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Set a stop time. Integration will not proceed past tstop.
|
|
115
|
+
*/
|
|
116
|
+
export function cvodeSetStopTime(mem, tstop) {
|
|
117
|
+
mem.cv_tstop = tstop;
|
|
118
|
+
mem.cv_tstopset = true;
|
|
119
|
+
mem.cv_tstopinterp = true;
|
|
120
|
+
return CV_SUCCESS;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Attach user data that will be passed to the RHS, Jacobian, and root
|
|
124
|
+
* functions.
|
|
125
|
+
*/
|
|
126
|
+
export function cvodeSetUserData(mem, data) {
|
|
127
|
+
mem.cv_user_data = data;
|
|
128
|
+
return CV_SUCCESS;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Enable or disable BDF stability limit detection.
|
|
132
|
+
*/
|
|
133
|
+
export function cvodeSetStabLimDet(mem, on) {
|
|
134
|
+
mem.cv_sldeton = on;
|
|
135
|
+
return CV_SUCCESS;
|
|
136
|
+
}
|
|
137
|
+
// ============================================================================
|
|
138
|
+
// Statistics getters
|
|
139
|
+
// ============================================================================
|
|
140
|
+
/** Return the total number of internal steps taken. */
|
|
141
|
+
export function cvodeGetNumSteps(mem) {
|
|
142
|
+
return mem.cv_nst;
|
|
143
|
+
}
|
|
144
|
+
/** Return the total number of RHS evaluations. */
|
|
145
|
+
export function cvodeGetNumRhsEvals(mem) {
|
|
146
|
+
return mem.cv_nfe;
|
|
147
|
+
}
|
|
148
|
+
/** Return the number of linear solver setup calls. */
|
|
149
|
+
export function cvodeGetNumLinSolvSetups(mem) {
|
|
150
|
+
return mem.cv_nsetups;
|
|
151
|
+
}
|
|
152
|
+
/** Return the number of error test failures. */
|
|
153
|
+
export function cvodeGetNumErrTestFails(mem) {
|
|
154
|
+
return mem.cv_netf;
|
|
155
|
+
}
|
|
156
|
+
/** Return the number of nonlinear solver iterations. */
|
|
157
|
+
export function cvodeGetNumNonlinSolvIters(mem) {
|
|
158
|
+
return mem.cv_nni;
|
|
159
|
+
}
|
|
160
|
+
/** Return the number of nonlinear solver convergence failures. */
|
|
161
|
+
export function cvodeGetNumNonlinSolvConvFails(mem) {
|
|
162
|
+
return mem.cv_ncfn;
|
|
163
|
+
}
|
|
164
|
+
/** Return the number of Jacobian evaluations (from the linear solver). */
|
|
165
|
+
export function cvodeGetNumJacEvals(mem) {
|
|
166
|
+
var _a, _b;
|
|
167
|
+
return (_b = (_a = mem.cv_lmem) === null || _a === void 0 ? void 0 : _a.nje) !== null && _b !== void 0 ? _b : 0;
|
|
168
|
+
}
|
|
169
|
+
/** Return the total number of root-function evaluations. */
|
|
170
|
+
export function cvodeGetNumGEvals(mem) {
|
|
171
|
+
return mem.cv_nge;
|
|
172
|
+
}
|
|
173
|
+
/** Return the method order used on the last successful step. */
|
|
174
|
+
export function cvodeGetLastOrder(mem) {
|
|
175
|
+
return mem.cv_qu;
|
|
176
|
+
}
|
|
177
|
+
/** Return the step size used on the last successful step. */
|
|
178
|
+
export function cvodeGetLastStep(mem) {
|
|
179
|
+
return mem.cv_hu;
|
|
180
|
+
}
|
|
181
|
+
/** Return the current internal time reached by the solver. */
|
|
182
|
+
export function cvodeGetCurrentTime(mem) {
|
|
183
|
+
return mem.cv_tn;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Return a snapshot of all integrator statistics as a plain object.
|
|
187
|
+
*/
|
|
188
|
+
export function cvodeGetIntegratorStats(mem) {
|
|
189
|
+
return {
|
|
190
|
+
nSteps: cvodeGetNumSteps(mem),
|
|
191
|
+
nRhsEvals: cvodeGetNumRhsEvals(mem),
|
|
192
|
+
nLinSolvSetups: cvodeGetNumLinSolvSetups(mem),
|
|
193
|
+
nErrTestFails: cvodeGetNumErrTestFails(mem),
|
|
194
|
+
nNonlinSolvIters: cvodeGetNumNonlinSolvIters(mem),
|
|
195
|
+
nNonlinSolvConvFails: cvodeGetNumNonlinSolvConvFails(mem),
|
|
196
|
+
nJacEvals: cvodeGetNumJacEvals(mem),
|
|
197
|
+
nGEvals: cvodeGetNumGEvals(mem),
|
|
198
|
+
lastOrder: cvodeGetLastOrder(mem),
|
|
199
|
+
lastStep: cvodeGetLastStep(mem),
|
|
200
|
+
currentTime: cvodeGetCurrentTime(mem),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=cvode_io.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cvode_io.js","sourceRoot":"","sources":["cvode_io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,qEAAqE;AACrE,iDAAiD;AAEjD,OAAO,EAEL,UAAU,EACV,KAAK,EACL,KAAK,EACL,WAAW,EACX,SAAS,EACT,QAAQ,GACT,MAAM,UAAU,CAAC;AAoBlB,+EAA+E;AAC/E,sBAAsB;AACtB,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAa,EAAE,IAAY,EAAE,IAAY;IACzE,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QACb,GAAG,CAAC,QAAQ,GAAG,sCAAsC,CAAC;QACtD,OAAO,CAAC,CAAC,CAAC;IACZ,CAAC;IACD,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QACb,GAAG,CAAC,QAAQ,GAAG,sCAAsC,CAAC;QACtD,OAAO,CAAC,CAAC,CAAC;IACZ,CAAC;IAED,GAAG,CAAC,SAAS,GAAG,IAAI,CAAC;IACrB,GAAG,CAAC,UAAU,GAAG,IAAI,CAAC;IACtB,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IACpB,GAAG,CAAC,WAAW,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC;IAE/B,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,GAAa,EAAE,IAAY,EAAE,IAAkB;IAC/E,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC;QACb,GAAG,CAAC,QAAQ,GAAG,sCAAsC,CAAC;QACtD,OAAO,CAAC,CAAC,CAAC;IACZ,CAAC;IACD,K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,GAAG,CAAC;QAC7B,SAAS,EAAE,mBAAmB,CAAC,GAAG,CAAC;QACnC,cAAc,EAAE,wBAAwB,CAAC,GAAG,CAAC;QAC7C,aAAa,EAAE,uBAAuB,CAAC,GAAG,CAAC;QAC3C,gBAAgB,EAAE,0BAA0B,CAAC,GAAG,CAAC;QACjD,oBAAoB,EAAE,8BAA8B,CAAC,GAAG,CAAC;QACzD,SAAS,EAAE,mBAAmB,CAAC,GAAG,CAAC;QACnC,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC;QAC/B,SAAS,EAAE,iBAAiB,CAAC,GAAG,CAAC;QACjC,QAAQ,EAAE,gBAAgB,CAAC,GAAG,CAAC;QAC/B,WAAW,EAAE,mBAAmB,CAAC,GAAG,CAAC;KACtC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript port of SUNDIALS CVODE v7.5.0 (https://github.com/LLNL/sundials)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2025, Lawrence Livermore National Security, University of
|
|
5
|
+
* Maryland Baltimore County, and the SUNDIALS contributors.
|
|
6
|
+
* Copyright (c) 2013-2025, Lawrence Livermore National Security and
|
|
7
|
+
* Southern Methodist University.
|
|
8
|
+
* Copyright (c) 2002-2013, Lawrence Livermore National Security.
|
|
9
|
+
* Copyright (c) 2026 Datagrok.
|
|
10
|
+
*
|
|
11
|
+
* Licensed under the BSD-3-Clause License. See THIRD_PARTY_LICENSES
|
|
12
|
+
* for the full license text and provenance chain of the original code.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
// CVODE TypeScript port - Configuration and statistics I/O functions
|
|
16
|
+
// Ported from SUNDIALS CVODE v7.5.0 (cvode_io.c)
|
|
17
|
+
|
|
18
|
+
import {
|
|
19
|
+
CvodeMem,
|
|
20
|
+
CV_SUCCESS,
|
|
21
|
+
CV_SS,
|
|
22
|
+
CV_SV,
|
|
23
|
+
ADAMS_Q_MAX,
|
|
24
|
+
BDF_Q_MAX,
|
|
25
|
+
CV_ADAMS,
|
|
26
|
+
} from './common';
|
|
27
|
+
|
|
28
|
+
// ============================================================================
|
|
29
|
+
// Statistics interface
|
|
30
|
+
// ============================================================================
|
|
31
|
+
|
|
32
|
+
export interface CvodeStats {
|
|
33
|
+
nSteps: number;
|
|
34
|
+
nRhsEvals: number;
|
|
35
|
+
nLinSolvSetups: number;
|
|
36
|
+
nErrTestFails: number;
|
|
37
|
+
nNonlinSolvIters: number;
|
|
38
|
+
nNonlinSolvConvFails: number;
|
|
39
|
+
nJacEvals: number;
|
|
40
|
+
nGEvals: number;
|
|
41
|
+
lastOrder: number;
|
|
42
|
+
lastStep: number;
|
|
43
|
+
currentTime: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ============================================================================
|
|
47
|
+
// Tolerance functions
|
|
48
|
+
// ============================================================================
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Set scalar relative and absolute tolerances.
|
|
52
|
+
* Requires rtol >= 0 and atol >= 0.
|
|
53
|
+
*/
|
|
54
|
+
export function cvodeSStolerances(mem: CvodeMem, rtol: number, atol: number): number {
|
|
55
|
+
if (rtol < 0) {
|
|
56
|
+
mem.cv_error = 'cvodeSStolerances: rtol must be >= 0';
|
|
57
|
+
return -1;
|
|
58
|
+
}
|
|
59
|
+
if (atol < 0) {
|
|
60
|
+
mem.cv_error = 'cvodeSStolerances: atol must be >= 0';
|
|
61
|
+
return -1;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
mem.cv_reltol = rtol;
|
|
65
|
+
mem.cv_Sabstol = atol;
|
|
66
|
+
mem.cv_itol = CV_SS;
|
|
67
|
+
mem.cv_atolmin0 = (atol === 0);
|
|
68
|
+
|
|
69
|
+
return CV_SUCCESS;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Set scalar relative tolerance and vector absolute tolerance.
|
|
74
|
+
* Requires rtol >= 0 and all atol[i] >= 0.
|
|
75
|
+
*/
|
|
76
|
+
export function cvodeSVtolerances(mem: CvodeMem, rtol: number, atol: Float64Array): number {
|
|
77
|
+
if (rtol < 0) {
|
|
78
|
+
mem.cv_error = 'cvodeSVtolerances: rtol must be >= 0';
|
|
79
|
+
return -1;
|
|
80
|
+
}
|
|
81
|
+
for (let i = 0; i < atol.length; i++) {
|
|
82
|
+
if (atol[i] < 0) {
|
|
83
|
+
mem.cv_error = `cvodeSVtolerances: atol[${i}] must be >= 0`;
|
|
84
|
+
return -1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
mem.cv_reltol = rtol;
|
|
89
|
+
mem.cv_Vabstol = new Float64Array(atol);
|
|
90
|
+
mem.cv_itol = CV_SV;
|
|
91
|
+
|
|
92
|
+
let minAtol = Infinity;
|
|
93
|
+
for (let i = 0; i < atol.length; i++)
|
|
94
|
+
if (atol[i] < minAtol) minAtol = atol[i];
|
|
95
|
+
|
|
96
|
+
mem.cv_atolmin0 = (minAtol === 0);
|
|
97
|
+
mem.cv_VabstolMallocDone = true;
|
|
98
|
+
|
|
99
|
+
return CV_SUCCESS;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// ============================================================================
|
|
103
|
+
// Optional input functions
|
|
104
|
+
// ============================================================================
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Set the maximum number of internal steps per call to CVode.
|
|
108
|
+
*/
|
|
109
|
+
export function cvodeSetMaxNumSteps(mem: CvodeMem, mxstep: number): number {
|
|
110
|
+
mem.cv_mxstep = mxstep;
|
|
111
|
+
return CV_SUCCESS;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Set the maximum method order. Clamped to [1, qmax] where qmax is
|
|
116
|
+
* ADAMS_Q_MAX or BDF_Q_MAX depending on the linear multistep method.
|
|
117
|
+
*/
|
|
118
|
+
export function cvodeSetMaxOrd(mem: CvodeMem, maxord: number): number {
|
|
119
|
+
const qmax = (mem.cv_lmm === CV_ADAMS) ? ADAMS_Q_MAX : BDF_Q_MAX;
|
|
120
|
+
if (maxord < 1) maxord = 1;
|
|
121
|
+
if (maxord > qmax) maxord = qmax;
|
|
122
|
+
mem.cv_qmax = maxord;
|
|
123
|
+
return CV_SUCCESS;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Set the maximum step size. If hmax <= 0, no upper limit is imposed
|
|
128
|
+
* (cv_hmax_inv = 0). Otherwise cv_hmax_inv = 1 / hmax.
|
|
129
|
+
*/
|
|
130
|
+
export function cvodeSetMaxStep(mem: CvodeMem, hmax: number): number {
|
|
131
|
+
if (hmax <= 0)
|
|
132
|
+
mem.cv_hmax_inv = 0;
|
|
133
|
+
else
|
|
134
|
+
mem.cv_hmax_inv = 1.0 / hmax;
|
|
135
|
+
|
|
136
|
+
return CV_SUCCESS;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Set the minimum step size (stored as absolute value).
|
|
141
|
+
*/
|
|
142
|
+
export function cvodeSetMinStep(mem: CvodeMem, hmin: number): number {
|
|
143
|
+
mem.cv_hmin = Math.abs(hmin);
|
|
144
|
+
return CV_SUCCESS;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Set the initial step size hint.
|
|
149
|
+
*/
|
|
150
|
+
export function cvodeSetInitStep(mem: CvodeMem, hin: number): number {
|
|
151
|
+
mem.cv_hin = hin;
|
|
152
|
+
return CV_SUCCESS;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Set a stop time. Integration will not proceed past tstop.
|
|
157
|
+
*/
|
|
158
|
+
export function cvodeSetStopTime(mem: CvodeMem, tstop: number): number {
|
|
159
|
+
mem.cv_tstop = tstop;
|
|
160
|
+
mem.cv_tstopset = true;
|
|
161
|
+
mem.cv_tstopinterp = true;
|
|
162
|
+
return CV_SUCCESS;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Attach user data that will be passed to the RHS, Jacobian, and root
|
|
167
|
+
* functions.
|
|
168
|
+
*/
|
|
169
|
+
export function cvodeSetUserData(mem: CvodeMem, data: any): number {
|
|
170
|
+
mem.cv_user_data = data;
|
|
171
|
+
return CV_SUCCESS;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Enable or disable BDF stability limit detection.
|
|
176
|
+
*/
|
|
177
|
+
export function cvodeSetStabLimDet(mem: CvodeMem, on: boolean): number {
|
|
178
|
+
mem.cv_sldeton = on;
|
|
179
|
+
return CV_SUCCESS;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// ============================================================================
|
|
183
|
+
// Statistics getters
|
|
184
|
+
// ============================================================================
|
|
185
|
+
|
|
186
|
+
/** Return the total number of internal steps taken. */
|
|
187
|
+
export function cvodeGetNumSteps(mem: CvodeMem): number {
|
|
188
|
+
return mem.cv_nst;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Return the total number of RHS evaluations. */
|
|
192
|
+
export function cvodeGetNumRhsEvals(mem: CvodeMem): number {
|
|
193
|
+
return mem.cv_nfe;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/** Return the number of linear solver setup calls. */
|
|
197
|
+
export function cvodeGetNumLinSolvSetups(mem: CvodeMem): number {
|
|
198
|
+
return mem.cv_nsetups;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Return the number of error test failures. */
|
|
202
|
+
export function cvodeGetNumErrTestFails(mem: CvodeMem): number {
|
|
203
|
+
return mem.cv_netf;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** Return the number of nonlinear solver iterations. */
|
|
207
|
+
export function cvodeGetNumNonlinSolvIters(mem: CvodeMem): number {
|
|
208
|
+
return mem.cv_nni;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Return the number of nonlinear solver convergence failures. */
|
|
212
|
+
export function cvodeGetNumNonlinSolvConvFails(mem: CvodeMem): number {
|
|
213
|
+
return mem.cv_ncfn;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** Return the number of Jacobian evaluations (from the linear solver). */
|
|
217
|
+
export function cvodeGetNumJacEvals(mem: CvodeMem): number {
|
|
218
|
+
return mem.cv_lmem?.nje ?? 0;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** Return the total number of root-function evaluations. */
|
|
222
|
+
export function cvodeGetNumGEvals(mem: CvodeMem): number {
|
|
223
|
+
return mem.cv_nge;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Return the method order used on the last successful step. */
|
|
227
|
+
export function cvodeGetLastOrder(mem: CvodeMem): number {
|
|
228
|
+
return mem.cv_qu;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Return the step size used on the last successful step. */
|
|
232
|
+
export function cvodeGetLastStep(mem: CvodeMem): number {
|
|
233
|
+
return mem.cv_hu;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** Return the current internal time reached by the solver. */
|
|
237
|
+
export function cvodeGetCurrentTime(mem: CvodeMem): number {
|
|
238
|
+
return mem.cv_tn;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Return a snapshot of all integrator statistics as a plain object.
|
|
243
|
+
*/
|
|
244
|
+
export function cvodeGetIntegratorStats(mem: CvodeMem): CvodeStats {
|
|
245
|
+
return {
|
|
246
|
+
nSteps: cvodeGetNumSteps(mem),
|
|
247
|
+
nRhsEvals: cvodeGetNumRhsEvals(mem),
|
|
248
|
+
nLinSolvSetups: cvodeGetNumLinSolvSetups(mem),
|
|
249
|
+
nErrTestFails: cvodeGetNumErrTestFails(mem),
|
|
250
|
+
nNonlinSolvIters: cvodeGetNumNonlinSolvIters(mem),
|
|
251
|
+
nNonlinSolvConvFails: cvodeGetNumNonlinSolvConvFails(mem),
|
|
252
|
+
nJacEvals: cvodeGetNumJacEvals(mem),
|
|
253
|
+
nGEvals: cvodeGetNumGEvals(mem),
|
|
254
|
+
lastOrder: cvodeGetLastOrder(mem),
|
|
255
|
+
lastStep: cvodeGetLastStep(mem),
|
|
256
|
+
currentTime: cvodeGetCurrentTime(mem),
|
|
257
|
+
};
|
|
258
|
+
}
|