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.
- package/.claude/settings.local.json +11 -0
- 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 +104 -0
- package/LICENSE +1 -1
- package/README.MD +121 -27
- package/THIRD_PARTY_LICENSES +135 -0
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/BasicModelPipelineCreator.html +4 -4
- package/docs/classes/Callback.html +5 -5
- package/docs/classes/CyclicModelPipelineCreator.html +4 -4
- package/docs/classes/IterCheckerCallback.html +5 -5
- package/docs/classes/PipelineCreator.html +4 -4
- package/docs/classes/TimeCheckerCallback.html +5 -5
- package/docs/classes/UpdatesModelPipelineCreator.html +4 -4
- package/docs/functions/ab4.html +8 -0
- package/docs/functions/ab5.html +8 -0
- package/docs/functions/applyPipeline.html +2 -2
- package/docs/functions/getCallback.html +2 -2
- package/docs/functions/getIVP.html +2 -2
- package/docs/functions/getInputVector.html +2 -2
- package/docs/functions/getIvp2WebWorker.html +2 -2
- package/docs/functions/getJScode.html +2 -2
- package/docs/functions/getOutputNames.html +2 -2
- package/docs/functions/getPipelineCreator.html +2 -2
- package/docs/functions/lsoda.html +8 -0
- package/docs/functions/mrt.html +2 -2
- package/docs/functions/printE5.html +2 -2
- package/docs/functions/printHires.html +2 -2
- package/docs/functions/printOrego.html +2 -2
- package/docs/functions/printPollution.html +2 -2
- package/docs/functions/printRobertson.html +2 -2
- package/docs/functions/printVdpol.html +2 -2
- 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 +2 -2
- package/docs/functions/ros3prw.html +2 -2
- package/docs/functions/solveIvp.html +2 -2
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +100 -15
- 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/ROBER.png +0 -0
- package/docs/media/VDP0L.png +0 -0
- package/docs/media/cyclic-model.js +3 -1
- package/docs/media/cyclic-model.js.map +1 -1
- package/docs/media/cyclic-model.ts +3 -1
- package/docs/modules.html +1 -1
- package/docs/types/Arg.html +7 -7
- package/docs/types/DifEqs.html +4 -4
- package/docs/types/Func.html +2 -2
- package/docs/types/IVP.html +20 -20
- package/docs/types/IVP2WebWorker.html +7 -7
- package/docs/types/Input.html +4 -4
- package/docs/types/Loop.html +4 -4
- package/docs/types/ODEs.html +8 -8
- package/docs/types/Output.html +4 -4
- package/docs/types/Pipeline.html +4 -4
- package/docs/types/SolverOptions.html +5 -5
- package/docs/types/Update.html +5 -5
- package/docs/types/Wrapper.html +5 -5
- package/images/E5.png +0 -0
- package/images/HIRES.png +0 -0
- package/images/OREGO.png +0 -0
- package/images/POLL-full.png +0 -0
- package/images/ROBER.png +0 -0
- package/images/VDP0L.png +0 -0
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/index.ts +2 -1
- package/jest.config.js +1 -0
- 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/examples/cyclic-model.js +3 -1
- package/src/examples/cyclic-model.js.map +1 -1
- package/src/examples/cyclic-model.ts +3 -1
- package/src/solver-tools/ab4-method.js +332 -0
- package/src/solver-tools/ab4-method.js.map +1 -0
- package/src/solver-tools/ab4-method.ts +395 -0
- package/src/solver-tools/ab5-method.js +334 -0
- package/src/solver-tools/ab5-method.js.map +1 -0
- package/src/solver-tools/ab5-method.ts +397 -0
- 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 +7 -0
- package/src/solver-tools/index.js.map +1 -1
- package/src/solver-tools/index.ts +7 -0
- package/src/solver-tools/lsoda/blas.js +257 -0
- package/src/solver-tools/lsoda/blas.js.map +1 -0
- package/src/solver-tools/lsoda/blas.ts +279 -0
- package/src/solver-tools/lsoda/cfode.js +84 -0
- package/src/solver-tools/lsoda/cfode.js.map +1 -0
- package/src/solver-tools/lsoda/cfode.ts +95 -0
- package/src/solver-tools/lsoda/common.js +94 -0
- package/src/solver-tools/lsoda/common.js.map +1 -0
- package/src/solver-tools/lsoda/common.ts +135 -0
- package/src/solver-tools/lsoda/corfailure.js +36 -0
- package/src/solver-tools/lsoda/corfailure.js.map +1 -0
- package/src/solver-tools/lsoda/corfailure.ts +42 -0
- package/src/solver-tools/lsoda/correction.js +112 -0
- package/src/solver-tools/lsoda/correction.js.map +1 -0
- package/src/solver-tools/lsoda/correction.ts +131 -0
- package/src/solver-tools/lsoda/dense.js +121 -0
- package/src/solver-tools/lsoda/dense.js.map +1 -0
- package/src/solver-tools/lsoda/dense.ts +141 -0
- package/src/solver-tools/lsoda/index.js +15 -0
- package/src/solver-tools/lsoda/index.js.map +1 -0
- package/src/solver-tools/lsoda/index.ts +17 -0
- package/src/solver-tools/lsoda/intdy.js +54 -0
- package/src/solver-tools/lsoda/intdy.js.map +1 -0
- package/src/solver-tools/lsoda/intdy.ts +62 -0
- package/src/solver-tools/lsoda/lsoda.js +578 -0
- package/src/solver-tools/lsoda/lsoda.js.map +1 -0
- package/src/solver-tools/lsoda/lsoda.ts +644 -0
- package/src/solver-tools/lsoda/methodswitch.js +108 -0
- package/src/solver-tools/lsoda/methodswitch.js.map +1 -0
- package/src/solver-tools/lsoda/methodswitch.ts +119 -0
- package/src/solver-tools/lsoda/orderswitch.js +97 -0
- package/src/solver-tools/lsoda/orderswitch.js.map +1 -0
- package/src/solver-tools/lsoda/orderswitch.ts +107 -0
- package/src/solver-tools/lsoda/prja.js +54 -0
- package/src/solver-tools/lsoda/prja.js.map +1 -0
- package/src/solver-tools/lsoda/prja.ts +61 -0
- package/src/solver-tools/lsoda/scaleh.js +41 -0
- package/src/solver-tools/lsoda/scaleh.js.map +1 -0
- package/src/solver-tools/lsoda/scaleh.ts +45 -0
- package/src/solver-tools/lsoda/solsy.js +25 -0
- package/src/solver-tools/lsoda/solsy.js.map +1 -0
- package/src/solver-tools/lsoda/solsy.ts +30 -0
- package/src/solver-tools/lsoda/stoda.js +270 -0
- package/src/solver-tools/lsoda/stoda.js.map +1 -0
- package/src/solver-tools/lsoda/stoda.ts +298 -0
- package/src/solver-tools/lsoda-method.js +134 -0
- package/src/solver-tools/lsoda-method.js.map +1 -0
- package/src/solver-tools/lsoda-method.ts +154 -0
- package/src/solver-tools/mrt-method.js +81 -18
- package/src/solver-tools/mrt-method.js.map +1 -1
- package/src/solver-tools/mrt-method.ts +111 -21
- package/src/solver-tools/rk3-method.js +210 -0
- package/src/solver-tools/rk3-method.js.map +1 -0
- package/src/solver-tools/rk3-method.ts +257 -0
- package/src/solver-tools/rk4-method.js +236 -0
- package/src/solver-tools/rk4-method.js.map +1 -0
- package/src/solver-tools/rk4-method.ts +286 -0
- package/src/solver-tools/rkdp-method.js +247 -0
- package/src/solver-tools/rkdp-method.js.map +1 -0
- package/src/solver-tools/rkdp-method.ts +300 -0
- package/src/solver-tools/ros34prw-method.js +1 -1
- package/src/solver-tools/ros34prw-method.js.map +1 -1
- package/src/solver-tools/ros34prw-method.ts +1 -1
- package/src/solver-tools/ros3prw-method.js +1 -1
- package/src/solver-tools/ros3prw-method.js.map +1 -1
- package/src/solver-tools/ros3prw-method.ts +1 -1
- package/src/solver-tools/solver-defs.js +7 -0
- package/src/solver-tools/solver-defs.js.map +1 -1
- package/src/solver-tools/solver-defs.ts +7 -0
- package/src/tests/correctness.test.js +6 -4
- package/src/tests/correctness.test.js.map +1 -1
- package/src/tests/correctness.test.ts +6 -4
- 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/lsoda-lib-correctness.test.js +223 -0
- package/src/tests/lsoda-lib-correctness.test.js.map +1 -0
- package/src/tests/lsoda-lib-correctness.test.ts +283 -0
- package/src/tests/lsoda-lib-performance.test.js +95 -0
- package/src/tests/lsoda-lib-performance.test.js.map +1 -0
- package/src/tests/lsoda-lib-performance.test.ts +126 -0
- package/src/tests/performance.test.js +12 -8
- package/src/tests/performance.test.js.map +1 -1
- package/src/tests/performance.test.ts +12 -8
- package/src/tests/test-defs.js +20 -1
- package/src/tests/test-defs.js.map +1 -1
- package/src/tests/test-defs.ts +22 -1
- package/src/worker-tools/solving.js +15 -1
- package/src/worker-tools/solving.js.map +1 -1
- package/src/worker-tools/solving.ts +23 -1
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Cvode, cvodeCreate, cvodeInit, cvode, cvodeSStolerances, cvodeSVtolerances,
|
|
3
|
+
cvodeSetLinearSolver, cvodeGetDky,
|
|
4
|
+
CV_BDF, CV_NORMAL,
|
|
5
|
+
CV_SUCCESS, CV_ROOT_RETURN, CV_TOO_MUCH_WORK,
|
|
6
|
+
} from '../solver-tools/cvode';
|
|
7
|
+
import type {OdeFunction, CvodeSolveResult, CvodeRhsFn} from '../solver-tools/cvode';
|
|
8
|
+
import {ODEs} from '../../index';
|
|
9
|
+
import {corrProbs} from '../examples/corr-probs';
|
|
10
|
+
|
|
11
|
+
// ─── Robertson chemical kinetics (original test) ────────────────────────────
|
|
12
|
+
|
|
13
|
+
function robertsonRhs(t: number, y: Float64Array, ydot: Float64Array): void {
|
|
14
|
+
ydot[0] = 1.0e4 * y[1] * y[2] - 0.04 * y[0];
|
|
15
|
+
ydot[2] = 3.0e7 * y[1] * y[1];
|
|
16
|
+
ydot[1] = -(ydot[0] + ydot[2]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Low-level RHS for Robertson (returns int). */
|
|
20
|
+
function robertsonRhsLowLevel(t: number, y: Float64Array, ydot: Float64Array, _userData: any): number {
|
|
21
|
+
robertsonRhs(t, y, ydot);
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const robertsonExpected = [
|
|
26
|
+
{t: 4.0000e-01, y: [9.851712e-01, 3.386380e-05, 1.479493e-02]},
|
|
27
|
+
{t: 4.0000e+00, y: [9.055333e-01, 2.240655e-05, 9.444430e-02]},
|
|
28
|
+
{t: 4.0000e+01, y: [7.158403e-01, 9.186334e-06, 2.841505e-01]},
|
|
29
|
+
{t: 4.0000e+02, y: [4.505250e-01, 3.222964e-06, 5.494717e-01]},
|
|
30
|
+
{t: 4.0000e+03, y: [1.831976e-01, 8.941773e-07, 8.168015e-01]},
|
|
31
|
+
{t: 4.0000e+04, y: [3.898729e-02, 1.621940e-07, 9.610125e-01]},
|
|
32
|
+
{t: 4.0000e+05, y: [4.936362e-03, 1.984221e-08, 9.950636e-01]},
|
|
33
|
+
{t: 4.0000e+06, y: [5.161833e-04, 2.065787e-09, 9.994838e-01]},
|
|
34
|
+
{t: 4.0000e+07, y: [5.179804e-05, 2.072027e-10, 9.999482e-01]},
|
|
35
|
+
{t: 4.0000e+08, y: [5.283675e-06, 2.113481e-11, 9.999947e-01]},
|
|
36
|
+
{t: 4.0000e+09, y: [4.658667e-07, 1.863468e-12, 9.999995e-01]},
|
|
37
|
+
{t: 4.0000e+10, y: [1.431100e-08, 5.724404e-14, 1.000000e+00]},
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
// Robertson solver tolerances for CVODE.
|
|
41
|
+
const ROBERTSON_SOLVER_RTOL = 1e-8;
|
|
42
|
+
const ROBERTSON_SOLVER_ATOL = new Float64Array([1e-10, 1e-14, 1e-10]);
|
|
43
|
+
|
|
44
|
+
// Number of Robertson output points to check with strict relative tolerance.
|
|
45
|
+
// At very late times (t>=4e8) the solution components become extremely small
|
|
46
|
+
// (y1~1e-5, y2~1e-10) and accumulated integration error over many orders of
|
|
47
|
+
// magnitude of time makes pure relative error checks impractical. We check
|
|
48
|
+
// the first 9 points (up to t=4e7) with strict tolerance and use qualitative
|
|
49
|
+
// checks for the remaining points.
|
|
50
|
+
const ROBERTSON_STRICT_POINTS = 9;
|
|
51
|
+
const ROBERTSON_CHECK_TOL = 5e-3;
|
|
52
|
+
|
|
53
|
+
// ─── Helpers ─────────────────────────────────────────────────────────────────
|
|
54
|
+
|
|
55
|
+
function relError(computed: number, reference: number): number {
|
|
56
|
+
if (reference === 0) return Math.abs(computed);
|
|
57
|
+
return Math.abs((computed - reference) / reference);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Solves an ODE with the Cvode class and checks against exact solution at the final time.
|
|
62
|
+
* Uses combined absolute + relative tolerance: |computed - exact| < checkTol * |exact| + checkAbsTol.
|
|
63
|
+
*/
|
|
64
|
+
function solveAndCheck(
|
|
65
|
+
ode: ODEs,
|
|
66
|
+
exactSolution: (t: number) => Float64Array,
|
|
67
|
+
lmm: 'adams' | 'bdf',
|
|
68
|
+
checkTol: number = 1e-3,
|
|
69
|
+
checkAbsTol: number = 1e-6,
|
|
70
|
+
) {
|
|
71
|
+
const neq = ode.initial.length;
|
|
72
|
+
const tol = ode.tolerance;
|
|
73
|
+
|
|
74
|
+
const solver = new Cvode(ode.func, neq, ode.arg.start, Float64Array.from(ode.initial), {
|
|
75
|
+
lmm,
|
|
76
|
+
rtol: tol,
|
|
77
|
+
atol: tol,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
let t = ode.arg.start;
|
|
81
|
+
const step = ode.arg.step;
|
|
82
|
+
const finish = ode.arg.finish;
|
|
83
|
+
let result: CvodeSolveResult;
|
|
84
|
+
|
|
85
|
+
let tout = t + step;
|
|
86
|
+
while (tout <= finish + step / 2) {
|
|
87
|
+
result = solver.solve(tout);
|
|
88
|
+
expect(result.flag).toBe(CV_SUCCESS);
|
|
89
|
+
t = result.t;
|
|
90
|
+
tout += step;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Check final solution against exact
|
|
94
|
+
const exact = exactSolution(t);
|
|
95
|
+
const y = result!.y;
|
|
96
|
+
for (let j = 0; j < neq; j++) {
|
|
97
|
+
const absErr = Math.abs(y[j] - exact[j]);
|
|
98
|
+
const allowed = checkTol * Math.abs(exact[j]) + checkAbsTol;
|
|
99
|
+
expect(absErr).toBeLessThan(allowed);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Dense output helper: solve an ODE to evenly spaced output points, then use getDky
|
|
105
|
+
* to verify the interpolation matches the exact solution.
|
|
106
|
+
*/
|
|
107
|
+
function denseExactCheck(
|
|
108
|
+
ode: ODEs,
|
|
109
|
+
exactSolution: (t: number) => Float64Array,
|
|
110
|
+
lmm: 'adams' | 'bdf',
|
|
111
|
+
checkTol: number = 1e-3,
|
|
112
|
+
checkAbsTol: number = 1e-6,
|
|
113
|
+
) {
|
|
114
|
+
const neq = ode.initial.length;
|
|
115
|
+
const tol = ode.tolerance;
|
|
116
|
+
|
|
117
|
+
const solver = new Cvode(ode.func, neq, ode.arg.start, Float64Array.from(ode.initial), {
|
|
118
|
+
lmm,
|
|
119
|
+
rtol: tol,
|
|
120
|
+
atol: tol,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
const start = ode.arg.start;
|
|
124
|
+
const finish = ode.arg.finish;
|
|
125
|
+
const nOutputPts = 100;
|
|
126
|
+
let nChecked = 0;
|
|
127
|
+
|
|
128
|
+
for (let i = 1; i <= nOutputPts; i++) {
|
|
129
|
+
const tout = start + (finish - start) * i / nOutputPts;
|
|
130
|
+
const result = solver.solve(tout);
|
|
131
|
+
expect(result.flag).toBe(CV_SUCCESS);
|
|
132
|
+
|
|
133
|
+
// getDky at the output time should match the solve result
|
|
134
|
+
const dky = solver.getDky(result.t, 0);
|
|
135
|
+
const exact = exactSolution(result.t);
|
|
136
|
+
|
|
137
|
+
for (let j = 0; j < neq; j++) {
|
|
138
|
+
// Dense output should match the direct solve result
|
|
139
|
+
expect(Math.abs(dky[j] - result.y[j])).toBeLessThan(1e-12);
|
|
140
|
+
|
|
141
|
+
// Dense output should match the exact solution
|
|
142
|
+
const absErr = Math.abs(dky[j] - exact[j]);
|
|
143
|
+
const allowed = checkTol * Math.abs(exact[j]) + checkAbsTol;
|
|
144
|
+
expect(absErr).toBeLessThan(allowed);
|
|
145
|
+
}
|
|
146
|
+
nChecked++;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Ensure we actually checked points
|
|
150
|
+
expect(nChecked).toBe(nOutputPts);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// ─── Tests ───────────────────────────────────────────────────────────────────
|
|
154
|
+
|
|
155
|
+
const nonStiffProbs = corrProbs.filter((p) => p.odes.name.startsWith('non-stiff'));
|
|
156
|
+
const stiffProbs = corrProbs.filter((p) => p.odes.name.startsWith('stiff'));
|
|
157
|
+
|
|
158
|
+
describe('CVODE LIB', () => {
|
|
159
|
+
it('should solve Robertson chemical kinetics with Cvode class', () => {
|
|
160
|
+
const neq = 3;
|
|
161
|
+
const solver = new Cvode(robertsonRhs, neq, 0.0, Float64Array.from([1.0, 0.0, 0.0]), {
|
|
162
|
+
lmm: 'bdf',
|
|
163
|
+
rtol: ROBERTSON_SOLVER_RTOL,
|
|
164
|
+
atol: ROBERTSON_SOLVER_ATOL,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
let tout = 0.4;
|
|
168
|
+
for (let iout = 0; iout < 12; iout++) {
|
|
169
|
+
const result = solver.solve(tout);
|
|
170
|
+
expect(result.flag).toBe(CV_SUCCESS);
|
|
171
|
+
|
|
172
|
+
const exp = robertsonExpected[iout];
|
|
173
|
+
if (iout < ROBERTSON_STRICT_POINTS) {
|
|
174
|
+
for (let j = 0; j < 3; j++) {
|
|
175
|
+
const err = relError(result.y[j], exp.y[j]);
|
|
176
|
+
expect(err).toBeLessThanOrEqual(ROBERTSON_CHECK_TOL);
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
const sum = result.y[0] + result.y[1] + result.y[2];
|
|
180
|
+
expect(Math.abs(sum - 1.0)).toBeLessThan(1e-4);
|
|
181
|
+
expect(result.y[2]).toBeGreaterThan(0.999);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
tout *= 10.0;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('should solve Robertson chemical kinetics with the low-level API', () => {
|
|
189
|
+
const neq = 3;
|
|
190
|
+
const y0 = Float64Array.from([1.0, 0.0, 0.0]);
|
|
191
|
+
|
|
192
|
+
const mem = cvodeCreate(CV_BDF);
|
|
193
|
+
cvodeInit(mem, robertsonRhsLowLevel, 0.0, y0);
|
|
194
|
+
cvodeSVtolerances(mem, ROBERTSON_SOLVER_RTOL, ROBERTSON_SOLVER_ATOL);
|
|
195
|
+
cvodeSetLinearSolver(mem);
|
|
196
|
+
|
|
197
|
+
const yout = new Float64Array(neq);
|
|
198
|
+
let tout = 0.4;
|
|
199
|
+
|
|
200
|
+
for (let iout = 0; iout < 12; iout++) {
|
|
201
|
+
const {flag, t} = cvode(mem, tout, yout, CV_NORMAL);
|
|
202
|
+
expect(flag).toBe(CV_SUCCESS);
|
|
203
|
+
|
|
204
|
+
const exp = robertsonExpected[iout];
|
|
205
|
+
if (iout < ROBERTSON_STRICT_POINTS) {
|
|
206
|
+
for (let j = 0; j < 3; j++) {
|
|
207
|
+
const err = relError(yout[j], exp.y[j]);
|
|
208
|
+
expect(err).toBeLessThanOrEqual(ROBERTSON_CHECK_TOL);
|
|
209
|
+
}
|
|
210
|
+
} else {
|
|
211
|
+
const sum = yout[0] + yout[1] + yout[2];
|
|
212
|
+
expect(Math.abs(sum - 1.0)).toBeLessThan(1e-4);
|
|
213
|
+
expect(yout[2]).toBeGreaterThan(0.999);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
tout *= 10.0;
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
describe('non-stiff problems (Adams)', () => {
|
|
221
|
+
nonStiffProbs.forEach(({odes, exact}) => {
|
|
222
|
+
it(`should solve ${odes.name} problem`, () => {
|
|
223
|
+
solveAndCheck(odes, exact, 'adams');
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe('stiff problems (BDF)', () => {
|
|
229
|
+
stiffProbs.forEach(({odes, exact}) => {
|
|
230
|
+
it(`should solve ${odes.name} problem`, () => {
|
|
231
|
+
solveAndCheck(odes, exact, 'bdf');
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
// ─── Rootfinding ─────────────────────────────────────────────────────────
|
|
237
|
+
|
|
238
|
+
describe('rootfinding', () => {
|
|
239
|
+
it('should detect roots in Robertson system', () => {
|
|
240
|
+
const neq = 3;
|
|
241
|
+
|
|
242
|
+
// Root functions: g1 = y1 - 1e-4, g2 = y3 - 0.01
|
|
243
|
+
const rootFn = (t: number, y: Float64Array, gout: Float64Array): void => {
|
|
244
|
+
gout[0] = y[0] - 1e-4;
|
|
245
|
+
gout[1] = y[2] - 0.01;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const solver = new Cvode(robertsonRhs, neq, 0.0, Float64Array.from([1.0, 0.0, 0.0]), {
|
|
249
|
+
lmm: 'bdf',
|
|
250
|
+
rtol: ROBERTSON_SOLVER_RTOL,
|
|
251
|
+
atol: ROBERTSON_SOLVER_ATOL,
|
|
252
|
+
rootFn,
|
|
253
|
+
nRootFns: 2,
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
const rootTimes: number[] = [];
|
|
257
|
+
const rootIndices: Int32Array[] = [];
|
|
258
|
+
|
|
259
|
+
// Advance through the problem, collecting root returns
|
|
260
|
+
let tout = 0.4;
|
|
261
|
+
const tEnd = 4e10;
|
|
262
|
+
|
|
263
|
+
while (tout <= tEnd) {
|
|
264
|
+
const result = solver.solve(tout);
|
|
265
|
+
|
|
266
|
+
if (result.flag === CV_ROOT_RETURN) {
|
|
267
|
+
rootTimes.push(result.t);
|
|
268
|
+
rootIndices.push(result.rootsFound!);
|
|
269
|
+
// Continue from the root time; do not advance tout yet
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
expect(result.flag).toBe(CV_SUCCESS);
|
|
274
|
+
tout *= 10.0;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Expect at least 2 roots: y3 reaches 0.01 first, then y1 drops to 1e-4
|
|
278
|
+
expect(rootTimes.length).toBeGreaterThanOrEqual(2);
|
|
279
|
+
|
|
280
|
+
// First root: y3 = 0.01, near t ~ 2.6391e-1
|
|
281
|
+
const tRoot1 = rootTimes[0];
|
|
282
|
+
expect(relError(tRoot1, 2.6391e-1)).toBeLessThan(2e-2);
|
|
283
|
+
// rootsFound should indicate root function index 1 (g2)
|
|
284
|
+
expect(rootIndices[0][1]).not.toBe(0);
|
|
285
|
+
|
|
286
|
+
// Second root: y1 = 1e-4, near t ~ 2.0790e+7
|
|
287
|
+
const tRoot2 = rootTimes[1];
|
|
288
|
+
expect(relError(tRoot2, 2.0790e7)).toBeLessThan(2e-2);
|
|
289
|
+
// rootsFound should indicate root function index 0 (g1)
|
|
290
|
+
expect(rootIndices[1][0]).not.toBe(0);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
// ─── Dense output tests ─────────────────────────────────────────────────
|
|
295
|
+
|
|
296
|
+
describe('dense output (getDky)', () => {
|
|
297
|
+
it('consistency: getDky at output points should match solve results (Robertson)', () => {
|
|
298
|
+
const neq = 3;
|
|
299
|
+
const solver = new Cvode(robertsonRhs, neq, 0.0, Float64Array.from([1.0, 0.0, 0.0]), {
|
|
300
|
+
lmm: 'bdf',
|
|
301
|
+
rtol: ROBERTSON_SOLVER_RTOL,
|
|
302
|
+
atol: ROBERTSON_SOLVER_ATOL,
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
let tout = 0.4;
|
|
306
|
+
for (let iout = 0; iout < 12; iout++) {
|
|
307
|
+
const result = solver.solve(tout);
|
|
308
|
+
expect(result.flag).toBe(CV_SUCCESS);
|
|
309
|
+
|
|
310
|
+
// getDky at the output time should match the solve result
|
|
311
|
+
const dky = solver.getDky(result.t, 0);
|
|
312
|
+
for (let j = 0; j < neq; j++)
|
|
313
|
+
expect(Math.abs(dky[j] - result.y[j])).toBeLessThan(1e-12);
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
tout *= 10.0;
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('monotonicity: getDky at successive output points should produce finite values', () => {
|
|
321
|
+
const neq = 3;
|
|
322
|
+
const solver = new Cvode(robertsonRhs, neq, 0.0, Float64Array.from([1.0, 0.0, 0.0]), {
|
|
323
|
+
lmm: 'bdf',
|
|
324
|
+
rtol: ROBERTSON_SOLVER_RTOL,
|
|
325
|
+
atol: ROBERTSON_SOLVER_ATOL,
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// Solve to 1000 uniformly spaced points across [0.01, 1.0]
|
|
329
|
+
const n = 1000;
|
|
330
|
+
const tMin = 0.01;
|
|
331
|
+
const tMax = 1.0;
|
|
332
|
+
let prevT = 0.0;
|
|
333
|
+
|
|
334
|
+
for (let i = 0; i < n; i++) {
|
|
335
|
+
const tout = tMin + (tMax - tMin) * i / (n - 1);
|
|
336
|
+
const result = solver.solve(tout);
|
|
337
|
+
expect(result.flag).toBe(CV_SUCCESS);
|
|
338
|
+
|
|
339
|
+
// Time should advance monotonically
|
|
340
|
+
expect(result.t).toBeGreaterThan(prevT);
|
|
341
|
+
prevT = result.t;
|
|
342
|
+
|
|
343
|
+
// getDky at the output point should return finite values
|
|
344
|
+
const dky = solver.getDky(result.t, 0);
|
|
345
|
+
for (let j = 0; j < neq; j++)
|
|
346
|
+
expect(Number.isFinite(dky[j])).toBe(true);
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it('boundary: getDky at endpoints of the current step interval', () => {
|
|
351
|
+
const neq = 3;
|
|
352
|
+
const solver = new Cvode(robertsonRhs, neq, 0.0, Float64Array.from([1.0, 0.0, 0.0]), {
|
|
353
|
+
lmm: 'bdf',
|
|
354
|
+
rtol: ROBERTSON_SOLVER_RTOL,
|
|
355
|
+
atol: ROBERTSON_SOLVER_ATOL,
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
// Advance to a point to establish state
|
|
359
|
+
const result = solver.solve(0.4);
|
|
360
|
+
expect(result.flag).toBe(CV_SUCCESS);
|
|
361
|
+
|
|
362
|
+
// getDky at the last output time should succeed
|
|
363
|
+
const dkyEnd = solver.getDky(result.t, 0);
|
|
364
|
+
for (let j = 0; j < neq; j++)
|
|
365
|
+
expect(Number.isFinite(dkyEnd[j])).toBe(true);
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
// Query derivative (k=1) - first derivative at output time
|
|
369
|
+
const dkyDeriv = solver.getDky(result.t, 1);
|
|
370
|
+
for (let j = 0; j < neq; j++)
|
|
371
|
+
expect(Number.isFinite(dkyDeriv[j])).toBe(true);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
corrProbs.forEach(({odes, exact}) => {
|
|
375
|
+
const lmm = odes.name.startsWith('stiff') ? 'bdf' as const : 'adams' as const;
|
|
376
|
+
it(`dense output on ${odes.name} problem should match exact solution`, () => {
|
|
377
|
+
denseExactCheck(odes, exact, lmm);
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
// ─── Error handling ─────────────────────────────────────────────────────
|
|
383
|
+
|
|
384
|
+
describe('error handling', () => {
|
|
385
|
+
it('should return error for negative tolerances (low-level API)', () => {
|
|
386
|
+
const mem = cvodeCreate(CV_BDF);
|
|
387
|
+
cvodeInit(mem, robertsonRhsLowLevel, 0.0, Float64Array.from([1.0, 0.0, 0.0]));
|
|
388
|
+
|
|
389
|
+
const flag = cvodeSStolerances(mem, -1e-4, 1e-6);
|
|
390
|
+
expect(flag).toBeLessThan(0);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it('should return CV_TOO_MUCH_WORK with maxSteps: 1', () => {
|
|
394
|
+
const neq = 3;
|
|
395
|
+
const solver = new Cvode(robertsonRhs, neq, 0.0, Float64Array.from([1.0, 0.0, 0.0]), {
|
|
396
|
+
lmm: 'bdf',
|
|
397
|
+
rtol: ROBERTSON_SOLVER_RTOL,
|
|
398
|
+
atol: ROBERTSON_SOLVER_ATOL,
|
|
399
|
+
maxSteps: 1,
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
const result = solver.solve(4e10);
|
|
403
|
+
expect(result.flag).toBe(CV_TOO_MUCH_WORK);
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it('should return error flag when RHS function fails', () => {
|
|
407
|
+
const failingRhs: OdeFunction = (_t, _y, ydot) => {
|
|
408
|
+
ydot[0] = NaN;
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
const solver = new Cvode(failingRhs, 1, 0.0, Float64Array.from([1.0]), {
|
|
412
|
+
lmm: 'bdf',
|
|
413
|
+
rtol: 1e-4,
|
|
414
|
+
atol: 1e-6,
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
const result = solver.solve(1.0);
|
|
418
|
+
expect(result.flag).toBeLessThan(0);
|
|
419
|
+
});
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
// ─── Cvode class features ──────────────────────────────────────────────
|
|
423
|
+
|
|
424
|
+
describe('Cvode class features', () => {
|
|
425
|
+
it('getStats should return valid integrator statistics', () => {
|
|
426
|
+
const neq = 3;
|
|
427
|
+
const solver = new Cvode(robertsonRhs, neq, 0.0, Float64Array.from([1.0, 0.0, 0.0]), {
|
|
428
|
+
lmm: 'bdf',
|
|
429
|
+
rtol: ROBERTSON_SOLVER_RTOL,
|
|
430
|
+
atol: ROBERTSON_SOLVER_ATOL,
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
// Solve to first output point
|
|
434
|
+
solver.solve(0.4);
|
|
435
|
+
|
|
436
|
+
const stats = solver.getStats();
|
|
437
|
+
expect(stats.nSteps).toBeGreaterThan(0);
|
|
438
|
+
expect(stats.nRhsEvals).toBeGreaterThan(0);
|
|
439
|
+
expect(stats.nLinSolvSetups).toBeGreaterThanOrEqual(0);
|
|
440
|
+
expect(stats.nErrTestFails).toBeGreaterThanOrEqual(0);
|
|
441
|
+
expect(stats.nNonlinSolvIters).toBeGreaterThan(0);
|
|
442
|
+
expect(stats.nNonlinSolvConvFails).toBeGreaterThanOrEqual(0);
|
|
443
|
+
expect(stats.nJacEvals).toBeGreaterThanOrEqual(0);
|
|
444
|
+
expect(stats.lastOrder).toBeGreaterThanOrEqual(1);
|
|
445
|
+
expect(stats.lastStep).toBeGreaterThan(0);
|
|
446
|
+
expect(stats.currentTime).toBeGreaterThan(0);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
it('reInit should allow solving with new initial conditions', () => {
|
|
450
|
+
const neq = 3;
|
|
451
|
+
const solver = new Cvode(robertsonRhs, neq, 0.0, Float64Array.from([1.0, 0.0, 0.0]), {
|
|
452
|
+
lmm: 'bdf',
|
|
453
|
+
rtol: ROBERTSON_SOLVER_RTOL,
|
|
454
|
+
atol: ROBERTSON_SOLVER_ATOL,
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
// Solve to first output point
|
|
458
|
+
const result1 = solver.solve(0.4);
|
|
459
|
+
expect(result1.flag).toBe(CV_SUCCESS);
|
|
460
|
+
const y1 = new Float64Array(result1.y);
|
|
461
|
+
|
|
462
|
+
// Re-initialize with the same initial conditions and solve again
|
|
463
|
+
solver.reInit(0.0, Float64Array.from([1.0, 0.0, 0.0]));
|
|
464
|
+
const result2 = solver.solve(0.4);
|
|
465
|
+
expect(result2.flag).toBe(CV_SUCCESS);
|
|
466
|
+
|
|
467
|
+
// Results should match closely
|
|
468
|
+
for (let j = 0; j < neq; j++) {
|
|
469
|
+
const err = relError(result2.y[j], y1[j]);
|
|
470
|
+
expect(err).toBeLessThanOrEqual(1e-6);
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
it('reInit with different initial conditions should produce different results', () => {
|
|
475
|
+
const neq = 1;
|
|
476
|
+
const simpleRhs: OdeFunction = (_t, y, ydot) => {
|
|
477
|
+
ydot[0] = -y[0]; // y' = -y, solution: y(t) = y0 * exp(-t)
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
const solver = new Cvode(simpleRhs, neq, 0.0, Float64Array.from([1.0]), {
|
|
481
|
+
lmm: 'adams',
|
|
482
|
+
rtol: 1e-10,
|
|
483
|
+
atol: 1e-12,
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
// Solve with y0 = 1
|
|
487
|
+
const result1 = solver.solve(1.0);
|
|
488
|
+
expect(result1.flag).toBe(CV_SUCCESS);
|
|
489
|
+
const y1 = result1.y[0]; // should be ~ exp(-1) ~ 0.3679
|
|
490
|
+
|
|
491
|
+
// Re-initialize with y0 = 2
|
|
492
|
+
solver.reInit(0.0, Float64Array.from([2.0]));
|
|
493
|
+
const result2 = solver.solve(1.0);
|
|
494
|
+
expect(result2.flag).toBe(CV_SUCCESS);
|
|
495
|
+
const y2 = result2.y[0]; // should be ~ 2*exp(-1) ~ 0.7358
|
|
496
|
+
|
|
497
|
+
// y2 should be approximately 2 * y1
|
|
498
|
+
expect(relError(y2, 2 * y1)).toBeLessThan(1e-6);
|
|
499
|
+
|
|
500
|
+
// Check against exact solutions
|
|
501
|
+
expect(relError(y1, Math.exp(-1))).toBeLessThan(1e-6);
|
|
502
|
+
expect(relError(y2, 2 * Math.exp(-1))).toBeLessThan(1e-6);
|
|
503
|
+
});
|
|
504
|
+
});
|
|
505
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Cvode } from '../solver-tools/cvode';
|
|
2
|
+
import { robertson, robertsonReferencePoint } from '../examples/robertson';
|
|
3
|
+
import { hires, hiresReferencePoint } from '../examples/hires';
|
|
4
|
+
import { vdpol, vdpolReferencePoint } from '../examples/vdpol';
|
|
5
|
+
import { orego, oregoReferencePoint } from '../examples/orego';
|
|
6
|
+
import { e5, e5ReferencePoint } from '../examples/e5';
|
|
7
|
+
import { pollution, pollutionReferencePoint } from '../examples/pollution';
|
|
8
|
+
/** Solves a benchmark problem using CVODE, checks accuracy against the reference point. */
|
|
9
|
+
function solveBenchmarkAndCheck(ode, referencePoint, relTol, absTol, opts) {
|
|
10
|
+
var _a;
|
|
11
|
+
const neq = ode.initial.length;
|
|
12
|
+
const tol = ode.tolerance;
|
|
13
|
+
// Build CvodeOptions
|
|
14
|
+
const cvodeOpts = { lmm: 'bdf' };
|
|
15
|
+
// Handle tolerances
|
|
16
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.rtol) && (opts === null || opts === void 0 ? void 0 : opts.atol)) {
|
|
17
|
+
cvodeOpts.rtol = opts.rtol[0];
|
|
18
|
+
cvodeOpts.atol = opts.atol;
|
|
19
|
+
}
|
|
20
|
+
else if (opts === null || opts === void 0 ? void 0 : opts.rtol)
|
|
21
|
+
cvodeOpts.rtol = opts.rtol[0];
|
|
22
|
+
else if (opts === null || opts === void 0 ? void 0 : opts.atol)
|
|
23
|
+
cvodeOpts.atol = opts.atol;
|
|
24
|
+
else {
|
|
25
|
+
cvodeOpts.rtol = tol;
|
|
26
|
+
cvodeOpts.atol = tol;
|
|
27
|
+
}
|
|
28
|
+
if (opts === null || opts === void 0 ? void 0 : opts.mxstep)
|
|
29
|
+
cvodeOpts.maxSteps = opts.mxstep;
|
|
30
|
+
if (opts === null || opts === void 0 ? void 0 : opts.hmax)
|
|
31
|
+
cvodeOpts.maxStep = opts.hmax;
|
|
32
|
+
const y0 = Float64Array.from(ode.initial);
|
|
33
|
+
const solver = new Cvode(ode.func, neq, ode.arg.start, y0, cvodeOpts);
|
|
34
|
+
// Warmup phase: bootstrap very stiff problems with a small initial tout
|
|
35
|
+
if ((opts === null || opts === void 0 ? void 0 : opts.warmupTout) !== undefined) {
|
|
36
|
+
const result = solver.solve(opts.warmupTout);
|
|
37
|
+
expect(result.flag).toBeGreaterThanOrEqual(0);
|
|
38
|
+
}
|
|
39
|
+
const t = (_a = opts === null || opts === void 0 ? void 0 : opts.warmupTout) !== null && _a !== void 0 ? _a : ode.arg.start;
|
|
40
|
+
let tout = t + ode.arg.step;
|
|
41
|
+
const finish = ode.arg.finish;
|
|
42
|
+
let lastResult;
|
|
43
|
+
while (tout <= finish + ode.arg.step / 2) {
|
|
44
|
+
lastResult = solver.solve(tout);
|
|
45
|
+
if (lastResult.flag < 0)
|
|
46
|
+
throw new Error(`${ode.name}: solver failed at t=${lastResult.t} with flag=${lastResult.flag}`);
|
|
47
|
+
tout += ode.arg.step;
|
|
48
|
+
}
|
|
49
|
+
// Check final solution against reference point
|
|
50
|
+
const y = lastResult.y;
|
|
51
|
+
for (let j = 0; j < neq; j++) {
|
|
52
|
+
const absErr = Math.abs(y[j] - referencePoint[j]);
|
|
53
|
+
const allowed = relTol * Math.abs(referencePoint[j]) + absTol;
|
|
54
|
+
expect(absErr).toBeLessThan(allowed);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// ─── Performance tests ──────────────────────────────────────────────────────
|
|
58
|
+
// Robertson: components span many orders of magnitude; use component-wise atol
|
|
59
|
+
describe('Robertson', () => {
|
|
60
|
+
it('should solve correctly', () => {
|
|
61
|
+
solveBenchmarkAndCheck(robertson, robertsonReferencePoint, 1e-2, 1e-7, {
|
|
62
|
+
mxstep: 50000,
|
|
63
|
+
atol: new Float64Array([1e-8, 1e-14, 1e-8]),
|
|
64
|
+
rtol: new Float64Array([1e-7, 1e-7, 1e-7]),
|
|
65
|
+
});
|
|
66
|
+
}, 60000);
|
|
67
|
+
});
|
|
68
|
+
describe('HIRES', () => {
|
|
69
|
+
it('should solve correctly', () => {
|
|
70
|
+
solveBenchmarkAndCheck(hires, hiresReferencePoint, 1e-3, 1e-12);
|
|
71
|
+
}, 60000);
|
|
72
|
+
});
|
|
73
|
+
// Van der Pol (mu=1000): very stiff, needs many internal steps
|
|
74
|
+
describe('van der Pol', () => {
|
|
75
|
+
it('should solve correctly', () => {
|
|
76
|
+
solveBenchmarkAndCheck(vdpol, vdpolReferencePoint, 1e-3, 1e-6, {
|
|
77
|
+
mxstep: 50000,
|
|
78
|
+
});
|
|
79
|
+
}, 60000);
|
|
80
|
+
});
|
|
81
|
+
describe('OREGO', () => {
|
|
82
|
+
it('should solve correctly', () => {
|
|
83
|
+
solveBenchmarkAndCheck(orego, oregoReferencePoint, 1e-2, 1e-6);
|
|
84
|
+
}, 60000);
|
|
85
|
+
});
|
|
86
|
+
// E5: extremely stiff (rate constants span 20 orders of magnitude).
|
|
87
|
+
// Known limitation: CVODE BDF with dense direct solver hits convergence failures
|
|
88
|
+
// on this extreme problem. LSODA handles it via automatic stiff/non-stiff switching.
|
|
89
|
+
// TODO: revisit when band/iterative solvers or preconditioners are added.
|
|
90
|
+
describe('E5', () => {
|
|
91
|
+
it.skip('should solve correctly (known limitation: CV_CONV_FAILURE)', () => {
|
|
92
|
+
solveBenchmarkAndCheck(e5, e5ReferencePoint, 1, 1e-6, {
|
|
93
|
+
mxstep: 50000,
|
|
94
|
+
warmupTout: 1e-5,
|
|
95
|
+
});
|
|
96
|
+
}, 60000);
|
|
97
|
+
});
|
|
98
|
+
describe('Pollution', () => {
|
|
99
|
+
it('should solve correctly', () => {
|
|
100
|
+
solveBenchmarkAndCheck(pollution, pollutionReferencePoint, 1e-2, 1e-10);
|
|
101
|
+
}, 60000);
|
|
102
|
+
});
|
|
103
|
+
//# sourceMappingURL=cvode-lib-performance.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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