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,74 @@
|
|
|
1
|
+
# Contributing to diff-grok 🚀
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to diff-grok!
|
|
4
|
+
We welcome bug reports, documentation improvements, new features, and help with tests or examples.
|
|
5
|
+
|
|
6
|
+
## ✅ How to contribute
|
|
7
|
+
|
|
8
|
+
### Reporting issues
|
|
9
|
+
|
|
10
|
+
- Please search existing issues before creating a new one — your problem or idea may already be discussed or solved.
|
|
11
|
+
- When reporting a bug, include as much information as possible: error messages, minimal reproducible example, environment (Node version, OS, TypeScript version), and expected vs actual behavior.
|
|
12
|
+
- For feature requests — describe the motivation, proposed API (if relevant), and possible use-cases.
|
|
13
|
+
|
|
14
|
+
### Submitting pull requests (PR)
|
|
15
|
+
|
|
16
|
+
1. Fork the repository and create a branch:
|
|
17
|
+
`feat/your-feature` or `fix/bug-description` or `docs/update-readme`
|
|
18
|
+
2. Make sure your code follows the existing style (TypeScript, ESLint, Prettier — as used in the repo).
|
|
19
|
+
3. Add or update tests/examples if applicable.
|
|
20
|
+
4. Run linter and tests before committing:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install
|
|
24
|
+
npm run lint
|
|
25
|
+
npm test
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
5. Commit with a clear message. Prefer descriptive messages, e.g.:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
feat: add new Rosenbrock method,
|
|
32
|
+
fix: correct edge behaviour in solver,
|
|
33
|
+
docs: improve README example for ODE usage.
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
6. Rebase or merge main upstream if needed; make sure no conflicts remain.
|
|
37
|
+
|
|
38
|
+
7. Create a PR, describing what you’ve changed and referencing related issues (if any).
|
|
39
|
+
|
|
40
|
+
## 🧑💻 Code style & conventions
|
|
41
|
+
|
|
42
|
+
Project uses TypeScript.
|
|
43
|
+
|
|
44
|
+
Follow the existing coding conventions and folder structure.
|
|
45
|
+
|
|
46
|
+
Keep changes focused and minimal — avoid mixing unrelated changes (e.g. code + formatting + docs) in one PR.
|
|
47
|
+
|
|
48
|
+
Write clear, self-contained commits.
|
|
49
|
+
|
|
50
|
+
## 📚 Documentation & Examples
|
|
51
|
+
|
|
52
|
+
If you fix or add public API — update README or add an example.
|
|
53
|
+
|
|
54
|
+
For new features — prefer adding minimal examples or tests demonstrating usage.
|
|
55
|
+
|
|
56
|
+
If you change behavior in edge cases — mention it clearly in docs/README.
|
|
57
|
+
|
|
58
|
+
## 🗣 Communication & Etiquette
|
|
59
|
+
|
|
60
|
+
Use GitHub Issues and Pull Requests for all discussions.
|
|
61
|
+
|
|
62
|
+
Be respectful and patient: contributors and maintainers may be in different timezones or busy.
|
|
63
|
+
|
|
64
|
+
Before opening an Issue or PR — read existing content (README, issues, pull requests) to avoid duplicates.
|
|
65
|
+
|
|
66
|
+
## 🔧 CI, Tests, and Quality
|
|
67
|
+
|
|
68
|
+
Ensure all existing tests pass; add new tests if adding functionality.
|
|
69
|
+
|
|
70
|
+
Code should pass linting/formatting checks.
|
|
71
|
+
|
|
72
|
+
If your change is substantial — consider adding a test or example illustrating it.
|
|
73
|
+
|
|
74
|
+
Thank you for helping make diff-grok better! 🎉
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** Example. Solve the following initial value problem
|
|
2
|
+
|
|
3
|
+
dx / dt = x + y - t
|
|
4
|
+
dy / dt = x * y + t
|
|
5
|
+
x(0) = 1
|
|
6
|
+
y(0) = -1
|
|
7
|
+
|
|
8
|
+
on [0, 2] with the step 0.01.
|
|
9
|
+
*/
|
|
10
|
+
import { mrt } from '../../index';
|
|
11
|
+
// Declare the problem
|
|
12
|
+
const task = {
|
|
13
|
+
name: 'Example', // name of your model
|
|
14
|
+
arg: {
|
|
15
|
+
name: 't', // name of the argument
|
|
16
|
+
start: 0, // initial value of the argument
|
|
17
|
+
finish: 2, // final value of the argument
|
|
18
|
+
step: 0.01, // solution grid step
|
|
19
|
+
},
|
|
20
|
+
initial: [1, -1], // initial values
|
|
21
|
+
func: (t, y, output) => {
|
|
22
|
+
output[0] = y[0] + y[1] - t; // 1-st equation
|
|
23
|
+
output[1] = y[0] * y[1] + t; // 2-nd equation
|
|
24
|
+
},
|
|
25
|
+
tolerance: 1e-7, // tolerance
|
|
26
|
+
solutionColNames: ['x', 'y'], // names of solution functions
|
|
27
|
+
};
|
|
28
|
+
try {
|
|
29
|
+
// Solve the problem
|
|
30
|
+
const solution = mrt(task);
|
|
31
|
+
// Output results
|
|
32
|
+
console.log(task.arg.name, ' ', task.solutionColNames[0], ' ', task.solutionColNames[1]);
|
|
33
|
+
const length = solution[0].length;
|
|
34
|
+
for (let i = 0; i < length; ++i)
|
|
35
|
+
console.log(solution[0][i], ' ', solution[1][i], ' ', solution[2][i]);
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
console.log('Solver failed: ', err instanceof Error ? err.message : 'Unknown problem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,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC;IAE7F,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAElC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC;QAC7B,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9E,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC;AAC1F,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Example. Solve the following initial value problem
|
|
2
|
+
|
|
3
|
+
dx / dt = x + y - t
|
|
4
|
+
dy / dt = x * y + t
|
|
5
|
+
x(0) = 1
|
|
6
|
+
y(0) = -1
|
|
7
|
+
|
|
8
|
+
on [0, 2] with the step 0.01.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {ODEs, mrt} from '../../index';
|
|
12
|
+
|
|
13
|
+
// Declare the problem
|
|
14
|
+
const task: ODEs = {
|
|
15
|
+
name: 'Example', // name of your model
|
|
16
|
+
arg: {
|
|
17
|
+
name: 't', // name of the argument
|
|
18
|
+
start: 0, // initial value of the argument
|
|
19
|
+
finish: 2, // final value of the argument
|
|
20
|
+
step: 0.01, // solution grid step
|
|
21
|
+
},
|
|
22
|
+
initial: [1, -1], // initial values
|
|
23
|
+
func: (t: number, y: Float64Array, output: Float64Array) => { // right-hand side of the system
|
|
24
|
+
output[0] = y[0] + y[1] - t; // 1-st equation
|
|
25
|
+
output[1] = y[0] * y[1] + t; // 2-nd equation
|
|
26
|
+
},
|
|
27
|
+
tolerance: 1e-7, // tolerance
|
|
28
|
+
solutionColNames: ['x', 'y'], // names of solution functions
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
// Solve the problem
|
|
33
|
+
const solution = mrt(task);
|
|
34
|
+
|
|
35
|
+
// Output results
|
|
36
|
+
console.log(task.arg.name, ' ', task.solutionColNames[0], ' ', task.solutionColNames[1]);
|
|
37
|
+
|
|
38
|
+
const length = solution[0].length;
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < length; ++i)
|
|
41
|
+
console.log(solution[0][i], ' ', solution[1][i], ' ', solution[2][i]);
|
|
42
|
+
} catch (err) {
|
|
43
|
+
console.log('Solver failed: ', err instanceof Error ? err.message : 'Unknown problem!');
|
|
44
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// A script for checking performance
|
|
2
|
+
import { corrProbs, mrt, ros3prw, ros34prw, perfProbs, refPoints } from '../../index';
|
|
3
|
+
/** Return numerical solution error: maximum absolute deviation between approximate & exact solutions */
|
|
4
|
+
function getError(method, corProb) {
|
|
5
|
+
let error = 0;
|
|
6
|
+
// Get numerical solution
|
|
7
|
+
const approxSolution = method(corProb.odes);
|
|
8
|
+
const exact = corProb.exact;
|
|
9
|
+
const arg = approxSolution[0];
|
|
10
|
+
const pointsCount = arg.length;
|
|
11
|
+
const funcsCount = approxSolution.length - 1;
|
|
12
|
+
// Compute error
|
|
13
|
+
for (let i = 0; i < pointsCount; ++i) {
|
|
14
|
+
const exactSolution = exact(arg[i]);
|
|
15
|
+
for (let j = 0; j < funcsCount; ++j)
|
|
16
|
+
error = Math.max(error, Math.abs(exactSolution[j] - approxSolution[j + 1][i]));
|
|
17
|
+
}
|
|
18
|
+
return error;
|
|
19
|
+
} // getError
|
|
20
|
+
function getDeviationFromReferencePoint(solution, refPoint) {
|
|
21
|
+
let absolute = 0;
|
|
22
|
+
const lastIdx = solution[0].length - 1;
|
|
23
|
+
let cur = 0;
|
|
24
|
+
for (let k = 0; k < solution.length; ++k) {
|
|
25
|
+
cur = Math.abs(solution[k][lastIdx] - refPoint[k]);
|
|
26
|
+
absolute = Math.max(cur, absolute);
|
|
27
|
+
}
|
|
28
|
+
return absolute;
|
|
29
|
+
} // getDeviationFromReferencePoint
|
|
30
|
+
const methods = new Map([
|
|
31
|
+
['MRT', mrt],
|
|
32
|
+
['ROS3PRw', ros3prw],
|
|
33
|
+
['ROS34PRw', ros34prw],
|
|
34
|
+
]);
|
|
35
|
+
console.log('Performance\n');
|
|
36
|
+
methods.forEach((method, name) => {
|
|
37
|
+
console.log(' ', name);
|
|
38
|
+
console.log(' PROBLEM TIME,MS ERR*');
|
|
39
|
+
perfProbs.forEach((odes, idx) => {
|
|
40
|
+
const start = Date.now();
|
|
41
|
+
const solution = method(odes);
|
|
42
|
+
const absErr = getDeviationFromReferencePoint(solution.slice(1), refPoints[idx]).toExponential(2);
|
|
43
|
+
const finish = Date.now();
|
|
44
|
+
console.log(` ${odes.name} ${finish - start} ${absErr}`.padStart(37));
|
|
45
|
+
});
|
|
46
|
+
console.log();
|
|
47
|
+
});
|
|
48
|
+
console.log('* approximate vs. reference (also, numerical)\n\n');
|
|
49
|
+
console.log('Correctness (maximum absolute deviation): approximate vs. exact\n');
|
|
50
|
+
methods.forEach((method, name) => {
|
|
51
|
+
console.log(' ', name);
|
|
52
|
+
console.log(' PROBLEM ERR');
|
|
53
|
+
corrProbs.forEach((problem) => {
|
|
54
|
+
const error = getError(method, problem);
|
|
55
|
+
console.log(` ${problem.odes.name} ${error.toExponential(2)}`.padStart(28));
|
|
56
|
+
});
|
|
57
|
+
console.log();
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=check-methods.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-methods.js","sourceRoot":"","sources":["check-methods.ts"],"names":[],"mappings":"AAAA,oCAAoC;AAEpC,OAAO,EAAO,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CAAC,CAAC;IACjF,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,EAAE,CAAC;AAChB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,GAAG,CAAC,mDAAmD,CAAC,CAAC;AAEjE,OAAO,CAAC,GAAG,CAAC,mEAAmE,CAAC,CAAC;AAEjF,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;IAC/B,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACxB,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IAEvC,SAAS,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC5B,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,QAAQ,OAAO,CAAC,IAAI,CAAC,IAAI,OAAO,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;IACrF,CAAC,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,EAAE,CAAC;AAChB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// A script for checking performance
|
|
2
|
+
|
|
3
|
+
import {ODEs, corrProbs, CorrProblem, mrt, ros3prw, ros34prw, perfProbs, refPoints} from '../../index';
|
|
4
|
+
|
|
5
|
+
/** Return numerical solution error: maximum absolute deviation between approximate & exact solutions */
|
|
6
|
+
function getError(method: (odes: ODEs) => Float64Array[], corProb: CorrProblem): number {
|
|
7
|
+
let error = 0;
|
|
8
|
+
|
|
9
|
+
// Get numerical solution
|
|
10
|
+
const approxSolution = method(corProb.odes);
|
|
11
|
+
|
|
12
|
+
const exact = corProb.exact;
|
|
13
|
+
|
|
14
|
+
const arg = approxSolution[0];
|
|
15
|
+
|
|
16
|
+
const pointsCount = arg.length;
|
|
17
|
+
const funcsCount = approxSolution.length - 1;
|
|
18
|
+
|
|
19
|
+
// Compute error
|
|
20
|
+
for (let i = 0; i < pointsCount; ++i) {
|
|
21
|
+
const exactSolution = exact(arg[i]);
|
|
22
|
+
|
|
23
|
+
for (let j = 0; j < funcsCount; ++j)
|
|
24
|
+
error = Math.max(error, Math.abs(exactSolution[j] - approxSolution[j + 1][i]));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return error;
|
|
28
|
+
} // getError
|
|
29
|
+
|
|
30
|
+
function getDeviationFromReferencePoint(solution: Float64Array[], refPoint: Float64Array): number {
|
|
31
|
+
let absolute = 0;
|
|
32
|
+
const lastIdx = solution[0].length - 1;
|
|
33
|
+
let cur = 0;
|
|
34
|
+
|
|
35
|
+
for (let k = 0; k < solution.length; ++k) {
|
|
36
|
+
cur = Math.abs(solution[k][lastIdx] - refPoint[k]);
|
|
37
|
+
absolute = Math.max(cur, absolute);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return absolute;
|
|
41
|
+
} // getDeviationFromReferencePoint
|
|
42
|
+
|
|
43
|
+
const methods = new Map([
|
|
44
|
+
['MRT', mrt],
|
|
45
|
+
['ROS3PRw', ros3prw],
|
|
46
|
+
['ROS34PRw', ros34prw],
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
console.log('Performance\n');
|
|
50
|
+
|
|
51
|
+
methods.forEach((method, name) => {
|
|
52
|
+
console.log(' ', name);
|
|
53
|
+
|
|
54
|
+
console.log(' PROBLEM TIME,MS ERR*');
|
|
55
|
+
|
|
56
|
+
perfProbs.forEach((odes, idx) => {
|
|
57
|
+
const start = Date.now();
|
|
58
|
+
const solution = method(odes);
|
|
59
|
+
const absErr = getDeviationFromReferencePoint(solution.slice(1), refPoints[idx]).toExponential(2);
|
|
60
|
+
const finish = Date.now();
|
|
61
|
+
console.log(` ${odes.name} ${finish - start} ${absErr}`.padStart(37));
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
console.log();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
console.log('* approximate vs. reference (also, numerical)\n\n');
|
|
68
|
+
|
|
69
|
+
console.log('Correctness (maximum absolute deviation): approximate vs. exact\n');
|
|
70
|
+
|
|
71
|
+
methods.forEach((method, name) => {
|
|
72
|
+
console.log(' ', name);
|
|
73
|
+
console.log(' PROBLEM ERR');
|
|
74
|
+
|
|
75
|
+
corrProbs.forEach((problem) => {
|
|
76
|
+
const error = getError(method, problem);
|
|
77
|
+
console.log(` ${problem.odes.name} ${error.toExponential(2)}`.padStart(28));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
console.log();
|
|
81
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Problems with known exact solution (for testing correctness)
|
|
2
|
+
/** Non-stiff 1D test problem: equation (see [1], p. 736) */
|
|
3
|
+
const nonStiff1D = {
|
|
4
|
+
name: 'non-stiff 1D',
|
|
5
|
+
arg: { name: 't', start: 0, finish: 4, step: 0.01 },
|
|
6
|
+
initial: [2],
|
|
7
|
+
func: (t, y, output) => {
|
|
8
|
+
output[0] = 4 * Math.exp(0.8 * t) - 0.5 * y[0];
|
|
9
|
+
},
|
|
10
|
+
tolerance: 0.00001,
|
|
11
|
+
solutionColNames: ['y'],
|
|
12
|
+
};
|
|
13
|
+
/** Non-stiff 1D test problem: exact solution (see [1], p. 736) */
|
|
14
|
+
const exactNonStiff1D = (t) => {
|
|
15
|
+
return new Float64Array([
|
|
16
|
+
(Math.exp(0.8 * t) - Math.exp(-0.5 * t)) * 4 / 1.3 + 2 * Math.exp(-0.5 * t),
|
|
17
|
+
]);
|
|
18
|
+
};
|
|
19
|
+
/** Non-stiff 2D test problem: equation */
|
|
20
|
+
const nonStiff2D = {
|
|
21
|
+
name: 'non-stiff 2D',
|
|
22
|
+
arg: { name: 't', start: 0, finish: 4, step: 0.01 },
|
|
23
|
+
initial: [1, 1],
|
|
24
|
+
func: (t, y, output) => {
|
|
25
|
+
output[0] = y[0] + y[1];
|
|
26
|
+
output[1] = y[1] - y[0];
|
|
27
|
+
},
|
|
28
|
+
tolerance: 0.000000001,
|
|
29
|
+
solutionColNames: ['x', 'y'],
|
|
30
|
+
};
|
|
31
|
+
/** Non-stiff 2D test problem: exact solution */
|
|
32
|
+
const exactNonStiff2D = (t) => {
|
|
33
|
+
return new Float64Array([
|
|
34
|
+
Math.exp(t) * (Math.cos(t) + Math.sin(t)),
|
|
35
|
+
Math.exp(t) * (Math.cos(t) - Math.sin(t)),
|
|
36
|
+
]);
|
|
37
|
+
};
|
|
38
|
+
/** Non-stiff 3D test problem: equations */
|
|
39
|
+
const nonStiff3D = {
|
|
40
|
+
name: 'non-stiff 3D',
|
|
41
|
+
arg: { name: 't', start: 0, finish: 2, step: 0.001 },
|
|
42
|
+
initial: [0.3, -0.8, 0],
|
|
43
|
+
func: (t, y, output) => {
|
|
44
|
+
output[0] = 5 * y[0] + 2 * y[1] + Math.sin(t);
|
|
45
|
+
output[1] = -4 * y[0] - y[1] + Math.exp(2 * t);
|
|
46
|
+
output[2] = 5 * Math.pow(t, 4) - 3 * Math.pow(t, 2) + 2 * t;
|
|
47
|
+
},
|
|
48
|
+
tolerance: 0.00000001,
|
|
49
|
+
solutionColNames: ['x', 'y', 'z'],
|
|
50
|
+
};
|
|
51
|
+
/** Non-stiff 3D test problem: exact solution */
|
|
52
|
+
const exactNonStiff3D = (t) => {
|
|
53
|
+
const e1 = Math.exp(t);
|
|
54
|
+
const e2 = Math.exp(2 * t);
|
|
55
|
+
const e3 = Math.exp(3 * t);
|
|
56
|
+
const c = Math.cos(t);
|
|
57
|
+
const s = Math.sin(t);
|
|
58
|
+
return new Float64Array([
|
|
59
|
+
e1 + e3 + 0.1 * (3 * c - s) - 2 * e2,
|
|
60
|
+
-2 * e1 - e3 - 0.2 * (2 * s + 4 * c) + 3 * e2,
|
|
61
|
+
Math.pow(t, 5) - Math.pow(t, 3) + Math.pow(t, 2),
|
|
62
|
+
]);
|
|
63
|
+
};
|
|
64
|
+
/** Stiff 1D test problem: equation (see [1], p. 767) */
|
|
65
|
+
const stiff1D = {
|
|
66
|
+
name: 'stiff 1D',
|
|
67
|
+
arg: { name: 't', start: 0, finish: 4, step: 0.01 },
|
|
68
|
+
initial: [0],
|
|
69
|
+
func: (t, y, output) => {
|
|
70
|
+
output[0] = -1000 * y[0] + 3000 - 2000 * Math.exp(-t);
|
|
71
|
+
},
|
|
72
|
+
tolerance: 0.0000005,
|
|
73
|
+
solutionColNames: ['y'],
|
|
74
|
+
};
|
|
75
|
+
/** Stiff 1D test problem: exact solution (see [1], p. 767) */
|
|
76
|
+
const exactStiff1D = (t) => {
|
|
77
|
+
return new Float64Array([
|
|
78
|
+
3 - 0.998 * Math.exp(-1000 * t) - 2.002 * Math.exp(-t),
|
|
79
|
+
]);
|
|
80
|
+
};
|
|
81
|
+
/** Stiff 2D test problem: equations (see [1], p. 770) */
|
|
82
|
+
const stiff2D = {
|
|
83
|
+
name: 'stiff 2D',
|
|
84
|
+
arg: { name: 't', start: 0, finish: 4, step: 0.01 },
|
|
85
|
+
initial: [52.29, 83.82],
|
|
86
|
+
func: (t, y, output) => {
|
|
87
|
+
output[0] = -5 * y[0] + 3 * y[1];
|
|
88
|
+
output[1] = 100 * y[0] - 301 * y[1];
|
|
89
|
+
},
|
|
90
|
+
tolerance: 0.0000005,
|
|
91
|
+
solutionColNames: ['x', 'y'],
|
|
92
|
+
};
|
|
93
|
+
/** Stiff 2D test problem: exact solution (see [1], p. 770) */
|
|
94
|
+
const exactStiff2D = (t) => {
|
|
95
|
+
return new Float64Array([
|
|
96
|
+
52.96 * Math.exp(-3.9899 * t) - 0.67 * Math.exp(-302.0101 * t),
|
|
97
|
+
17.83 * Math.exp(-3.9899 * t) + 65.99 * Math.exp(-302.0101 * t),
|
|
98
|
+
]);
|
|
99
|
+
};
|
|
100
|
+
/** Stiff 3D test problem: equations */
|
|
101
|
+
const stiff3D = {
|
|
102
|
+
name: 'stiff 3D',
|
|
103
|
+
arg: { name: 't', start: 0, finish: 4, step: 0.01 },
|
|
104
|
+
initial: [2, 1, 0],
|
|
105
|
+
func: (t, y, output) => {
|
|
106
|
+
output[0] = -100 * y[0] + 100 * y[1] + y[2];
|
|
107
|
+
output[1] = y[2];
|
|
108
|
+
output[2] = -y[1];
|
|
109
|
+
},
|
|
110
|
+
tolerance: 0.00000001,
|
|
111
|
+
solutionColNames: ['x', 'y', 'z'],
|
|
112
|
+
};
|
|
113
|
+
/** Stiff 3D test problem: exact solution */
|
|
114
|
+
const exactStiff3D = (t) => {
|
|
115
|
+
return new Float64Array([
|
|
116
|
+
Math.exp(-100 * t) + Math.cos(t),
|
|
117
|
+
Math.cos(t),
|
|
118
|
+
-Math.sin(t),
|
|
119
|
+
]);
|
|
120
|
+
};
|
|
121
|
+
/** Problems for testing correctness
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
export const corrProbs = [
|
|
125
|
+
{ odes: nonStiff1D, exact: exactNonStiff1D },
|
|
126
|
+
{ odes: nonStiff2D, exact: exactNonStiff2D },
|
|
127
|
+
{ odes: nonStiff3D, exact: exactNonStiff3D },
|
|
128
|
+
{ odes: stiff1D, exact: exactStiff1D },
|
|
129
|
+
{ odes: stiff2D, exact: exactStiff2D },
|
|
130
|
+
{ odes: stiff3D, exact: exactStiff3D },
|
|
131
|
+
];
|
|
132
|
+
//# sourceMappingURL=corr-probs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"corr-probs.js","sourceRoot":"","sources":["corr-probs.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAI/D,4DAA4D;AAC5D,MAAM,UAAU,GAAS;IACvB,IAAI,EAAE,cAAc;IACpB,GAAG,EAAE,EAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAC;IACjD,OAAO,EAAE,CAAC,CAAC,CAAC;IACZ,IAAI,EAAE,CAAC,CAAS,EAAE,CAAe,EAAE,MA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C,CAAC,CAAC;QACX,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;KACb,CAAC,CAAC;AACL,CAAC,CAAC;AAUF;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,EAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,eAAe,EAAC;IAC1C,EAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,eAAe,EAAC;IAC1C,EAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,eAAe,EAAC;IAC1C,EAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAC;IACpC,EAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAC;IACpC,EAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAC;CACrC,CAAC"}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// Problems with known exact solution (for testing correctness)
|
|
2
|
+
|
|
3
|
+
import {ODEs} from '../../index';
|
|
4
|
+
|
|
5
|
+
/** Non-stiff 1D test problem: equation (see [1], p. 736) */
|
|
6
|
+
const nonStiff1D: ODEs = {
|
|
7
|
+
name: 'non-stiff 1D',
|
|
8
|
+
arg: {name: 't', start: 0, finish: 4, step: 0.01},
|
|
9
|
+
initial: [2],
|
|
10
|
+
func: (t: number, y: Float64Array, output: Float64Array) => {
|
|
11
|
+
output[0] = 4 * Math.exp(0.8 * t) - 0.5 * y[0];
|
|
12
|
+
},
|
|
13
|
+
tolerance: 0.00001,
|
|
14
|
+
solutionColNames: ['y'],
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** Non-stiff 1D test problem: exact solution (see [1], p. 736) */
|
|
18
|
+
const exactNonStiff1D = (t: number) => {
|
|
19
|
+
return new Float64Array([
|
|
20
|
+
(Math.exp(0.8 * t) - Math.exp(-0.5 * t)) * 4 / 1.3 + 2 * Math.exp(-0.5 * t),
|
|
21
|
+
]);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/** Non-stiff 2D test problem: equation */
|
|
25
|
+
const nonStiff2D: ODEs = {
|
|
26
|
+
name: 'non-stiff 2D',
|
|
27
|
+
arg: {name: 't', start: 0, finish: 4, step: 0.01},
|
|
28
|
+
initial: [1, 1],
|
|
29
|
+
func: (t: number, y: Float64Array, output: Float64Array) => {
|
|
30
|
+
output[0] = y[0] + y[1];
|
|
31
|
+
output[1] = y[1] - y[0];
|
|
32
|
+
},
|
|
33
|
+
tolerance: 0.000000001,
|
|
34
|
+
solutionColNames: ['x', 'y'],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/** Non-stiff 2D test problem: exact solution */
|
|
38
|
+
const exactNonStiff2D = (t: number) => {
|
|
39
|
+
return new Float64Array([
|
|
40
|
+
Math.exp(t) * (Math.cos(t) + Math.sin(t)),
|
|
41
|
+
Math.exp(t) * (Math.cos(t) - Math.sin(t)),
|
|
42
|
+
]);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** Non-stiff 3D test problem: equations */
|
|
46
|
+
const nonStiff3D: ODEs = {
|
|
47
|
+
name: 'non-stiff 3D',
|
|
48
|
+
arg: {name: 't', start: 0, finish: 2, step: 0.001},
|
|
49
|
+
initial: [0.3, -0.8, 0],
|
|
50
|
+
func: (t: number, y: Float64Array, output: Float64Array) => {
|
|
51
|
+
output[0] = 5 * y[0] + 2 * y[1] + Math.sin(t);
|
|
52
|
+
output[1] = -4 * y[0] - y[1] + Math.exp(2 * t);
|
|
53
|
+
output[2] = 5 * t**4 - 3 * t**2 + 2 * t;
|
|
54
|
+
},
|
|
55
|
+
tolerance: 0.00000001,
|
|
56
|
+
solutionColNames: ['x', 'y', 'z'],
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** Non-stiff 3D test problem: exact solution */
|
|
60
|
+
const exactNonStiff3D = (t: number) => {
|
|
61
|
+
const e1 = Math.exp(t);
|
|
62
|
+
const e2 = Math.exp(2 * t);
|
|
63
|
+
const e3 = Math.exp(3 * t);
|
|
64
|
+
const c = Math.cos(t);
|
|
65
|
+
const s = Math.sin(t);
|
|
66
|
+
|
|
67
|
+
return new Float64Array([
|
|
68
|
+
e1 + e3 + 0.1 * (3 * c - s) - 2 * e2,
|
|
69
|
+
-2 * e1 - e3 - 0.2 * (2 * s + 4 * c) + 3 * e2,
|
|
70
|
+
t**5 - t**3 + t**2,
|
|
71
|
+
]);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** Stiff 1D test problem: equation (see [1], p. 767) */
|
|
75
|
+
const stiff1D: ODEs = {
|
|
76
|
+
name: 'stiff 1D',
|
|
77
|
+
arg: {name: 't', start: 0, finish: 4, step: 0.01},
|
|
78
|
+
initial: [0],
|
|
79
|
+
func: (t: number, y: Float64Array, output: Float64Array) => {
|
|
80
|
+
output[0] = -1000 * y[0] + 3000 - 2000 * Math.exp(-t);
|
|
81
|
+
},
|
|
82
|
+
tolerance: 0.0000005,
|
|
83
|
+
solutionColNames: ['y'],
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** Stiff 1D test problem: exact solution (see [1], p. 767) */
|
|
87
|
+
const exactStiff1D = (t: number) => {
|
|
88
|
+
return new Float64Array([
|
|
89
|
+
3 - 0.998 * Math.exp(-1000 * t) - 2.002 * Math.exp(-t),
|
|
90
|
+
]);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/** Stiff 2D test problem: equations (see [1], p. 770) */
|
|
94
|
+
const stiff2D: ODEs = {
|
|
95
|
+
name: 'stiff 2D',
|
|
96
|
+
arg: {name: 't', start: 0, finish: 4, step: 0.01},
|
|
97
|
+
initial: [52.29, 83.82],
|
|
98
|
+
func: (t: number, y: Float64Array, output: Float64Array) => {
|
|
99
|
+
output[0] = -5 * y[0] + 3 * y[1];
|
|
100
|
+
output[1] = 100 * y[0] - 301 * y[1];
|
|
101
|
+
},
|
|
102
|
+
tolerance: 0.0000005,
|
|
103
|
+
solutionColNames: ['x', 'y'],
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/** Stiff 2D test problem: exact solution (see [1], p. 770) */
|
|
107
|
+
const exactStiff2D = (t: number) => {
|
|
108
|
+
return new Float64Array([
|
|
109
|
+
52.96 * Math.exp(-3.9899 * t) - 0.67 * Math.exp(-302.0101 * t),
|
|
110
|
+
17.83 * Math.exp(-3.9899 * t) + 65.99 * Math.exp(-302.0101 * t),
|
|
111
|
+
]);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/** Stiff 3D test problem: equations */
|
|
115
|
+
const stiff3D: ODEs = {
|
|
116
|
+
name: 'stiff 3D',
|
|
117
|
+
arg: {name: 't', start: 0, finish: 4, step: 0.01},
|
|
118
|
+
initial: [2, 1, 0],
|
|
119
|
+
func: (t: number, y: Float64Array, output: Float64Array) => {
|
|
120
|
+
output[0] = -100 * y[0] + 100 * y[1] + y[2];
|
|
121
|
+
output[1] = y[2];
|
|
122
|
+
output[2] = -y[1];
|
|
123
|
+
},
|
|
124
|
+
tolerance: 0.00000001,
|
|
125
|
+
solutionColNames: ['x', 'y', 'z'],
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/** Stiff 3D test problem: exact solution */
|
|
129
|
+
const exactStiff3D = (t: number) => {
|
|
130
|
+
return new Float64Array([
|
|
131
|
+
Math.exp(-100 * t) + Math.cos(t),
|
|
132
|
+
Math.cos(t),
|
|
133
|
+
-Math.sin(t),
|
|
134
|
+
]);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
/** Correctness problem
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
140
|
+
export type CorrProblem = {
|
|
141
|
+
odes: ODEs,
|
|
142
|
+
exact: (t: number) => Float64Array,
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/** Problems for testing correctness
|
|
146
|
+
* @internal
|
|
147
|
+
*/
|
|
148
|
+
export const corrProbs = [
|
|
149
|
+
{odes: nonStiff1D, exact: exactNonStiff1D},
|
|
150
|
+
{odes: nonStiff2D, exact: exactNonStiff2D},
|
|
151
|
+
{odes: nonStiff3D, exact: exactNonStiff3D},
|
|
152
|
+
{odes: stiff1D, exact: exactStiff1D},
|
|
153
|
+
{odes: stiff2D, exact: exactStiff2D},
|
|
154
|
+
{odes: stiff3D, exact: exactStiff3D},
|
|
155
|
+
];
|