diff-grok 1.0.9 → 1.1.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/.github/ISSUE_TEMPLATE/bug_report.md +29 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +22 -0
- package/.github/workflows/deploy-docs.yml +15 -0
- package/CLAUDE.md +98 -0
- package/CONTRIBUTING.md +74 -0
- package/README.MD +272 -18
- 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/POLL.png +0 -0
- package/images/ROBER.png +0 -0
- package/images/VDP0L.png +0 -0
- package/images/VDPOL.png +0 -0
- package/index.js +2 -2
- package/index.js.map +1 -1
- package/index.ts +7 -5
- package/jest.config.js +1 -0
- package/package.json +2 -1
- package/src/examples/bioreactor.js +125 -0
- package/src/examples/bioreactor.js.map +1 -0
- package/src/examples/bioreactor.ts +132 -0
- package/src/examples/check-methods.js +23 -9
- package/src/examples/check-methods.js.map +1 -1
- package/src/examples/check-methods.ts +28 -9
- package/src/examples/corr-probs.js +3 -1
- package/src/examples/corr-probs.js.map +1 -1
- package/src/examples/corr-probs.ts +7 -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/examples/e5.js +6 -0
- package/src/examples/e5.js.map +1 -1
- package/src/examples/e5.ts +7 -0
- package/src/examples/hires.js +10 -0
- package/src/examples/hires.js.map +1 -1
- package/src/examples/hires.ts +11 -0
- package/src/examples/index.js +21 -7
- package/src/examples/index.js.map +1 -1
- package/src/examples/index.ts +23 -7
- package/src/examples/orego.js +5 -0
- package/src/examples/orego.js.map +1 -1
- package/src/examples/orego.ts +6 -0
- package/src/examples/pollution.js +22 -0
- package/src/examples/pollution.js.map +1 -1
- package/src/examples/pollution.ts +23 -0
- package/src/examples/print-benchmark.js +581 -0
- package/src/examples/print-benchmark.js.map +1 -0
- package/src/examples/print-benchmark.ts +594 -0
- package/src/examples/robertson.js +6 -1
- package/src/examples/robertson.js.map +1 -1
- package/src/examples/robertson.ts +7 -1
- package/src/examples/scripting.js +1 -1
- package/src/examples/scripting.js.map +1 -1
- package/src/examples/scripting.ts +1 -1
- package/src/examples/vdpol.js +4 -0
- package/src/examples/vdpol.js.map +1 -1
- package/src/examples/vdpol.ts +5 -0
- package/src/pipeline/basic-pipeline-creator.js +96 -1
- package/src/pipeline/basic-pipeline-creator.js.map +1 -1
- package/src/pipeline/basic-pipeline-creator.ts +97 -1
- package/src/pipeline/loops-pipeline-creator.js +115 -2
- package/src/pipeline/loops-pipeline-creator.js.map +1 -1
- package/src/pipeline/loops-pipeline-creator.ts +116 -2
- package/src/pipeline/output.js +7 -2
- package/src/pipeline/output.js.map +1 -1
- package/src/pipeline/output.ts +7 -2
- package/src/pipeline/pipeline-creator.js.map +1 -1
- package/src/pipeline/pipeline-creator.ts +4 -0
- package/src/pipeline/pipeline.js +193 -2
- package/src/pipeline/pipeline.js.map +1 -1
- package/src/pipeline/pipeline.ts +206 -4
- package/src/pipeline/updates-pipeline-creator.js +130 -2
- package/src/pipeline/updates-pipeline-creator.js.map +1 -1
- package/src/pipeline/updates-pipeline-creator.ts +131 -2
- package/src/scripting-tools/constants.js +18 -4
- package/src/scripting-tools/constants.js.map +1 -1
- package/src/scripting-tools/constants.ts +22 -4
- package/src/scripting-tools/index.js.map +1 -1
- package/src/scripting-tools/index.ts +3 -2
- package/src/scripting-tools/model-error.js +3 -1
- package/src/scripting-tools/model-error.js.map +1 -1
- package/src/scripting-tools/model-error.ts +3 -1
- package/src/scripting-tools/scripting-tools.js +139 -9
- package/src/scripting-tools/scripting-tools.js.map +1 -1
- package/src/scripting-tools/scripting-tools.ts +228 -21
- 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/callbacks/callback-base.js +2 -0
- package/src/solver-tools/callbacks/callback-base.js.map +1 -1
- package/src/solver-tools/callbacks/callback-base.ts +4 -0
- package/src/solver-tools/callbacks/callback-tools.js +3 -1
- package/src/solver-tools/callbacks/callback-tools.js.map +1 -1
- package/src/solver-tools/callbacks/callback-tools.ts +3 -1
- package/src/solver-tools/callbacks/iter-checker-callback.js +4 -0
- package/src/solver-tools/callbacks/iter-checker-callback.js.map +1 -1
- package/src/solver-tools/callbacks/iter-checker-callback.ts +4 -0
- package/src/solver-tools/callbacks/time-checker-callback.js +4 -0
- package/src/solver-tools/callbacks/time-checker-callback.js.map +1 -1
- package/src/solver-tools/callbacks/time-checker-callback.ts +4 -0
- package/src/solver-tools/index.js +9 -0
- package/src/solver-tools/index.js.map +1 -1
- package/src/solver-tools/index.ts +9 -0
- package/src/solver-tools/lsoda/blas.js +246 -0
- package/src/solver-tools/lsoda/blas.js.map +1 -0
- package/src/solver-tools/lsoda/blas.ts +267 -0
- package/src/solver-tools/lsoda/cfode.js +73 -0
- package/src/solver-tools/lsoda/cfode.js.map +1 -0
- package/src/solver-tools/lsoda/cfode.ts +83 -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 +25 -0
- package/src/solver-tools/lsoda/corfailure.js.map +1 -0
- package/src/solver-tools/lsoda/corfailure.ts +30 -0
- package/src/solver-tools/lsoda/correction.js +101 -0
- package/src/solver-tools/lsoda/correction.js.map +1 -0
- package/src/solver-tools/lsoda/correction.ts +119 -0
- package/src/solver-tools/lsoda/dense.js +110 -0
- package/src/solver-tools/lsoda/dense.js.map +1 -0
- package/src/solver-tools/lsoda/dense.ts +129 -0
- package/src/solver-tools/lsoda/index.js +4 -0
- package/src/solver-tools/lsoda/index.js.map +1 -0
- package/src/solver-tools/lsoda/index.ts +5 -0
- package/src/solver-tools/lsoda/intdy.js +43 -0
- package/src/solver-tools/lsoda/intdy.js.map +1 -0
- package/src/solver-tools/lsoda/intdy.ts +50 -0
- package/src/solver-tools/lsoda/lsoda.js +567 -0
- package/src/solver-tools/lsoda/lsoda.js.map +1 -0
- package/src/solver-tools/lsoda/lsoda.ts +632 -0
- package/src/solver-tools/lsoda/methodswitch.js +97 -0
- package/src/solver-tools/lsoda/methodswitch.js.map +1 -0
- package/src/solver-tools/lsoda/methodswitch.ts +107 -0
- package/src/solver-tools/lsoda/orderswitch.js +86 -0
- package/src/solver-tools/lsoda/orderswitch.js.map +1 -0
- package/src/solver-tools/lsoda/orderswitch.ts +95 -0
- package/src/solver-tools/lsoda/prja.js +43 -0
- package/src/solver-tools/lsoda/prja.js.map +1 -0
- package/src/solver-tools/lsoda/prja.ts +49 -0
- package/src/solver-tools/lsoda/scaleh.js +30 -0
- package/src/solver-tools/lsoda/scaleh.js.map +1 -0
- package/src/solver-tools/lsoda/scaleh.ts +33 -0
- package/src/solver-tools/lsoda/solsy.js +14 -0
- package/src/solver-tools/lsoda/solsy.js.map +1 -0
- package/src/solver-tools/lsoda/solsy.ts +18 -0
- package/src/solver-tools/lsoda/stoda.js +259 -0
- package/src/solver-tools/lsoda/stoda.js.map +1 -0
- package/src/solver-tools/lsoda/stoda.ts +286 -0
- package/src/solver-tools/lsoda-method.js +120 -0
- package/src/solver-tools/lsoda-method.js.map +1 -0
- package/src/solver-tools/lsoda-method.ts +136 -0
- package/src/solver-tools/mrt-method.js +121 -19
- package/src/solver-tools/mrt-method.js.map +1 -1
- package/src/solver-tools/mrt-method.ts +151 -22
- 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 +40 -2
- package/src/solver-tools/ros34prw-method.js.map +1 -1
- package/src/solver-tools/ros34prw-method.ts +40 -2
- package/src/solver-tools/ros3prw-method.js +40 -2
- package/src/solver-tools/ros3prw-method.js.map +1 -1
- package/src/solver-tools/ros3prw-method.ts +40 -2
- package/src/solver-tools/solver-defs.js +15 -3
- package/src/solver-tools/solver-defs.js.map +1 -1
- package/src/solver-tools/solver-defs.ts +91 -7
- 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/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 +10 -8
- package/src/tests/performance.test.js.map +1 -1
- package/src/tests/performance.test.ts +10 -8
- package/src/tests/test-defs.js +14 -1
- package/src/tests/test-defs.js.map +1 -1
- package/src/tests/test-defs.ts +15 -1
- package/src/worker-tools/scripting.js +95 -1
- package/src/worker-tools/scripting.js.map +1 -1
- package/src/worker-tools/scripting.ts +104 -2
- package/src/worker-tools/solving.js +18 -2
- package/src/worker-tools/solving.js.map +1 -1
- package/src/worker-tools/solving.ts +25 -2
- package/typedoc.json +8 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Report a bug in diff-grok
|
|
4
|
+
title: "[BUG] "
|
|
5
|
+
labels: bug
|
|
6
|
+
assignees: ""
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**What happened?**
|
|
11
|
+
A clear and concise description of the problem.
|
|
12
|
+
|
|
13
|
+
**How to reproduce?**
|
|
14
|
+
Provide a minimal reproducible example (code snippet, inputs, parameters, Node/TS version, OS).
|
|
15
|
+
|
|
16
|
+
**What did you expect to happen?**
|
|
17
|
+
Describe the expected behavior.
|
|
18
|
+
|
|
19
|
+
**What actually happened?**
|
|
20
|
+
Describe the actual behavior, error messages, stack trace, wrong output, etc.
|
|
21
|
+
|
|
22
|
+
**Environment:**
|
|
23
|
+
- diff-grok version:
|
|
24
|
+
- Node / TypeScript version:
|
|
25
|
+
- OS / Platform:
|
|
26
|
+
- Additional context (e.g. dependency versions):
|
|
27
|
+
|
|
28
|
+
(optional) **Example / Test case:**
|
|
29
|
+
Provide a minimal code snippet or scenario where bug occurs.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Feature request
|
|
3
|
+
about: Suggest a new feature or improvement
|
|
4
|
+
title: "[FEATURE] "
|
|
5
|
+
labels: enhancement
|
|
6
|
+
assignees: ""
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
**What problem would this feature solve?**
|
|
11
|
+
Describe the motivation, use-cases, or scenarios.
|
|
12
|
+
|
|
13
|
+
**Proposed solution / API idea (if any):**
|
|
14
|
+
Give a rough idea how this could look (function signature, parameters, return type, etc.).
|
|
15
|
+
|
|
16
|
+
**Alternatives / Workarounds:**
|
|
17
|
+
Describe any existing workaround or alternative that motivated this.
|
|
18
|
+
|
|
19
|
+
**Additional context (optional):**
|
|
20
|
+
Remarks, performance considerations, backward-compatibility notes, etc.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
## Description
|
|
2
|
+
|
|
3
|
+
Please describe what this PR does and why it is needed.
|
|
4
|
+
|
|
5
|
+
## Related Issue(s) / Motivation
|
|
6
|
+
|
|
7
|
+
Closes / Addresses / References: #[issue number] (if applicable)
|
|
8
|
+
|
|
9
|
+
## Type of change
|
|
10
|
+
|
|
11
|
+
- [ ] Bug fix
|
|
12
|
+
- [ ] New feature
|
|
13
|
+
- [ ] Update / improvement
|
|
14
|
+
- [ ] Documentation / example update
|
|
15
|
+
|
|
16
|
+
## Checklist
|
|
17
|
+
|
|
18
|
+
- [ ] I have read CONTRIBUTING.md
|
|
19
|
+
- [ ] My code follows project style (lint + formatting)
|
|
20
|
+
- [ ] I added / updated tests or examples (if applicable)
|
|
21
|
+
- [ ] All existing tests pass
|
|
22
|
+
- [ ] I updated documentation / README (if applicable)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
name: Deploy Docs
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [ main ]
|
|
5
|
+
jobs:
|
|
6
|
+
build:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
steps:
|
|
9
|
+
- uses: actions/checkout@v4
|
|
10
|
+
- run: npm ci
|
|
11
|
+
- run: npx typedoc
|
|
12
|
+
- uses: peaceiris/actions-gh-pages@v3
|
|
13
|
+
with:
|
|
14
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
15
|
+
publish_dir: ./docs
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
**diff-grok** is a zero-dependency TypeScript library for solving initial value problems (IVPs) for ordinary differential equations (ODEs), focused on stiff equations. It implements Rosenbrock-Wanner type numerical methods and includes a declarative model scripting system.
|
|
8
|
+
|
|
9
|
+
## Build & Development Commands
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install # Install dev dependencies
|
|
13
|
+
npm run build # Compile TypeScript (tsc)
|
|
14
|
+
npm run lint # ESLint check: eslint "./src/**/*.ts"
|
|
15
|
+
npm run lint-fix # Auto-fix lint issues
|
|
16
|
+
npm test # Run Jest test suite
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Run a single test file:
|
|
20
|
+
```bash
|
|
21
|
+
npx jest src/tests/correctness.test.ts
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Architecture
|
|
25
|
+
|
|
26
|
+
### Module Structure
|
|
27
|
+
|
|
28
|
+
- **`index.ts`** — Single entry point; re-exports everything from the four modules below.
|
|
29
|
+
|
|
30
|
+
- **`src/solver-tools/`** — Core numerical solvers
|
|
31
|
+
- **Implicit methods** (for stiff ODEs): `mrt` (Modified Rosenbrock Triple), `ros3prw`, `ros34prw`
|
|
32
|
+
- Require Jacobian computation and linear system solves
|
|
33
|
+
- Use LU decomposition for solving W*k = b at each stage
|
|
34
|
+
- **Automatic methods** (stiffness-detecting): `lsoda` (variable-order Nordsieck Adams/BDF with automatic switching)
|
|
35
|
+
- Automatically switch between non-stiff (Adams) and stiff (BDF) modes
|
|
36
|
+
- Use consecutive rejection counting (Adams→BDF) and periodic trial steps (BDF→Adams)
|
|
37
|
+
- **Explicit methods** (for non-stiff ODEs): `rk3` (Bogacki-Shampine 3(2)), `rk4` (Runge-Kutta-Fehlberg 4(5)), `ab5` (Adams-Bashforth-Moulton 5), `ab4` (Adams-Bashforth-Moulton 4), `rkdp` (Dormand-Prince 5(4))
|
|
38
|
+
- Only require function evaluations (no Jacobian)
|
|
39
|
+
- Include `hMax` constraint to prevent poor interpolation
|
|
40
|
+
- `ab5` and `ab4` are multistep predictor-corrector methods bootstrapped with RKF45
|
|
41
|
+
- Key types: `ODEs` (problem definition), `Func` (RHS function signature), `SolverMethod`
|
|
42
|
+
- `solver-defs.ts` — Type definitions, adaptive step constants, Jacobian/derivative computation
|
|
43
|
+
- `lin-alg-tools.ts` — Linear algebra routines (LU decomposition, matrix ops)
|
|
44
|
+
- `callbacks/` — Flow control during solving (iteration limits, time limits)
|
|
45
|
+
|
|
46
|
+
- **`src/scripting-tools/`** — Declarative model parsing and JS code generation
|
|
47
|
+
- `scripting-tools.ts` — Main parser: converts model DSL text → `IVP` object → JavaScript code
|
|
48
|
+
- Model DSL uses `#name`, `#equations`, `#argument`, `#inits`, `#parameters`, `#constants`, `#expressions` blocks
|
|
49
|
+
- Entry functions: `getIVP()` (parse model string), `getJScode()` (generate JS from IVP)
|
|
50
|
+
|
|
51
|
+
- **`src/pipeline/`** — Multi-stage simulation orchestration
|
|
52
|
+
- Three pipeline creators for different model types:
|
|
53
|
+
- `BasicModelPipelineCreator` — Single-stage models
|
|
54
|
+
- `CyclicModelPipelineCreator` — Loop/dosing models (PK-PD)
|
|
55
|
+
- `UpdatesModelPipelineCreator` — Multi-stage models with state transitions
|
|
56
|
+
- `applyPipeline()` runs the full computation pipeline
|
|
57
|
+
|
|
58
|
+
- **`src/worker-tools/`** — WebWorker integration for browser parallel computation
|
|
59
|
+
- `getIvp2WebWorker()` serializes IVP for worker transfer; `solveIvp()` runs in worker
|
|
60
|
+
|
|
61
|
+
### Data Flow
|
|
62
|
+
|
|
63
|
+
1. Define problem as `ODEs` object (programmatic) or parse model string via `getIVP()`
|
|
64
|
+
2. Call solver method (`mrt`/`ros3prw`/`ros34prw`/`rk3`/`rk4`/`ab5`/`ab4`/`rkdp`/`lsoda`) → returns `Float64Array[]` (argument values + solution columns)
|
|
65
|
+
3. For complex models: create pipeline via `getPipelineCreator()` → `applyPipeline()`
|
|
66
|
+
|
|
67
|
+
### Performance Patterns
|
|
68
|
+
|
|
69
|
+
- Uses `Float64Array` throughout for memory efficiency
|
|
70
|
+
- Pre-allocated buffers to minimize GC pressure
|
|
71
|
+
- RHS function signature `(t, y, output) => void` writes to pre-allocated output array
|
|
72
|
+
|
|
73
|
+
## Code Style
|
|
74
|
+
|
|
75
|
+
- **ESLint config**: Google style base, 2-space indent, 120 char max line length
|
|
76
|
+
- **Curly braces**: `"multi-or-nest"` — single-statement bodies don't need braces, multi-line do
|
|
77
|
+
- **TypeScript strict mode** enabled
|
|
78
|
+
- Commit messages: `feat:`, `fix:`, `docs:` prefixes (conventional style)
|
|
79
|
+
|
|
80
|
+
## Testing
|
|
81
|
+
|
|
82
|
+
Tests are in `src/tests/` using Jest with ts-jest:
|
|
83
|
+
- `correctness.test.ts` — Validates solver accuracy against reference solutions (threshold: MAX_MAD = 0.1)
|
|
84
|
+
- Tests all methods (implicit + explicit + automatic) against 6 problems with known exact solutions (11 methods total)
|
|
85
|
+
- 3 non-stiff problems (1D, 2D, 3D) + 3 stiff problems (1D, 2D, 3D)
|
|
86
|
+
- `performance.test.ts` — Benchmarks solver speed on stiff problems (timeout: 10,000ms)
|
|
87
|
+
- Tests implicit and automatic methods (MRT, ROS3PRw, ROS34PRw, LSODA)
|
|
88
|
+
- Test problems: Robertson, HIRES, VDPOL, OREGO, E5, Pollution
|
|
89
|
+
- `pipeline.test.ts` — Pipeline integration tests (3 model types)
|
|
90
|
+
- Method definitions in `test-defs.ts`: `methods` map (all 11 solvers), `implicitMethods` map (stiff-capable only)
|
|
91
|
+
|
|
92
|
+
## Key Types
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
type Func = (t: number, y: Float64Array, output: Float64Array) => void;
|
|
96
|
+
type ODEs = { name, arg: {name, start, finish, step}, initial, func: Func, tolerance, solutionColNames };
|
|
97
|
+
type SolverMethod = (odes: ODEs, callback?: Callback) => Float64Array[];
|
|
98
|
+
```
|
package/CONTRIBUTING.md
ADDED
|
@@ -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! 🎉
|
package/README.MD
CHANGED
|
@@ -1,15 +1,31 @@
|
|
|
1
1
|
# Diff Grok
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://doi.org/10.5281/zenodo.17974378)
|
|
4
|
+
[](https://datagrok-ai.github.io/diff-grok/)
|
|
5
|
+
[](https://github.com/datagrok-ai/diff-grok/blob/main/LICENSE)
|
|
6
|
+
[](https://github.com/datagrok-ai/diff-grok/actions/workflows/libraries.yaml)
|
|
7
|
+
[](https://github.com/datagrok-ai/diff-grok/actions/workflows/test.yaml)
|
|
8
|
+
|
|
9
|
+
A lightweight TypeScript library for solving initial value problem ([IVP](https://en.wikipedia.org/wiki/Initial_value_problem)) for ordinary differential equations ([ODEs](https://en.wikipedia.org/wiki/Ordinary_differential_equation)) using numerical methods. The primary solver is [LSODA](https://doi.org/10.1137/0904010) — a variable-order method that automatically detects stiffness and switches between Adams (non-stiff) and BDF (stiff) formulations.
|
|
4
10
|
|
|
5
11
|
## Features
|
|
6
12
|
|
|
7
13
|
* Solving both [stiff](https://en.wikipedia.org/wiki/Stiff_equation) and non-stiff equations
|
|
8
14
|
* Fast computations
|
|
9
|
-
*
|
|
15
|
+
* Automatic stiffness-detecting method:
|
|
16
|
+
* [LSODA](https://doi.org/10.1137/0904010) - variable-order Nordsieck-based solver with automatic switching between Adams (non-stiff) and BDF (stiff) methods ([Petzold, 1983](https://doi.org/10.1137/0904010); [Hindmarsh, 1983](https://computing.llnl.gov/sites/default/files/ODEPACK_pub1_u88007.pdf)). Ported to TypeScript from the C library [liblsoda](https://github.com/sdwfrost/liblsoda)
|
|
17
|
+
* Implicit methods (for stiff ODEs) - Rosenbrock–Wanner type:
|
|
10
18
|
* The modified Rosenbrock triple ([MRT](https://doi.org/10.1137/S1064827594276424))
|
|
11
19
|
* The [ROS3PRw](https://doi.org/10.1016/j.cam.2015.03.010) method
|
|
12
20
|
* The [ROS34PRw](https://doi.org/10.1016/j.cam.2015.03.010) method
|
|
21
|
+
* Explicit methods (for non-stiff ODEs):
|
|
22
|
+
* Runge-Kutta type:
|
|
23
|
+
* The Bogacki-Shampine 3(2) method ([RK3](https://en.wikipedia.org/wiki/Bogacki%E2%80%93Shampine_method))
|
|
24
|
+
* The Runge-Kutta-Fehlberg method ([RK4](https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta%E2%80%93Fehlberg_method))
|
|
25
|
+
* The Dormand-Prince 5(4) method ([RKDP](https://en.wikipedia.org/wiki/Dormand%E2%80%93Prince_method))
|
|
26
|
+
* Adams-Bashforth type:
|
|
27
|
+
* The predictor-corrector method of order 4 ([AB4](https://en.wikipedia.org/wiki/Linear_multistep_method))
|
|
28
|
+
* The predictor-corrector method of order 5 ([AB5](https://en.wikipedia.org/wiki/Linear_multistep_method))
|
|
13
29
|
* Scripting:
|
|
14
30
|
* declarative specification of models
|
|
15
31
|
* auto-generated JavaScript code
|
|
@@ -18,8 +34,34 @@ A lightweight TypeScript library for solving initial value problem ([IVP](https:
|
|
|
18
34
|
|
|
19
35
|
## Installation
|
|
20
36
|
|
|
37
|
+
To install via npm:
|
|
38
|
+
|
|
21
39
|
```bash
|
|
22
|
-
npm
|
|
40
|
+
npm install diff-grok
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Minimal "Hello World" example:
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
// example.ts
|
|
47
|
+
|
|
48
|
+
import {ODEs, mrt} from 'diff-grok';
|
|
49
|
+
|
|
50
|
+
const task: ODEs = {
|
|
51
|
+
name: 'Example',
|
|
52
|
+
arg: {name: 't', start: 0, finish: 1, step: 0.1},
|
|
53
|
+
initial: [1, -1],
|
|
54
|
+
func: (t: number, y: Float64Array, output: Float64Array) => {
|
|
55
|
+
out[0] = y[0] - t;
|
|
56
|
+
},
|
|
57
|
+
tolerance: 1e-7,
|
|
58
|
+
solutionColNames: ['y(t)'],
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const solution = mrt(task);
|
|
62
|
+
|
|
63
|
+
console.log('t:', solution[0]);
|
|
64
|
+
console.log('y(t):', solution[1]);
|
|
23
65
|
```
|
|
24
66
|
|
|
25
67
|
## Solving
|
|
@@ -35,10 +77,23 @@ on the segment $[t_0, t_1]$ with the step $h$:
|
|
|
35
77
|
|
|
36
78
|
1. Import `ODEs` and a desired numerical method:
|
|
37
79
|
|
|
80
|
+
Automatic method:
|
|
81
|
+
* `lsoda` - [LSODA](https://doi.org/10.1137/0904010) variable-order solver with automatic switching between Adams (non-stiff) and BDF (stiff)
|
|
82
|
+
|
|
83
|
+
Implicit methods (for stiff ODEs):
|
|
38
84
|
* `mrt` - the [MRT](https://doi.org/10.1137/S1064827594276424) method
|
|
39
85
|
* `ros3prw`- the [ROS3PRw](https://doi.org/10.1016/j.cam.2015.03.010) method
|
|
40
86
|
* `ros34prw` - the [ROS34PRw](https://doi.org/10.1016/j.cam.2015.03.010) method
|
|
41
87
|
|
|
88
|
+
Explicit methods (for non-stiff ODEs) — Runge-Kutta type:
|
|
89
|
+
* `rk3` - the Bogacki-Shampine 3(2) method
|
|
90
|
+
* `rk4` - the Runge-Kutta-Fehlberg 4(5) method
|
|
91
|
+
* `rkdp` - the Dormand-Prince 5(4) method
|
|
92
|
+
|
|
93
|
+
Explicit methods (for non-stiff ODEs) — Adams-Bashforth type:
|
|
94
|
+
* `ab4` - the predictor-corrector method of order 4
|
|
95
|
+
* `ab5` - the predictor-corrector method of order 5
|
|
96
|
+
|
|
42
97
|
2. Specify `ODEs` object that defines a problem:
|
|
43
98
|
|
|
44
99
|
* `name` - name of a model
|
|
@@ -71,10 +126,10 @@ x(0) = 1 \\
|
|
|
71
126
|
y(0) = -1
|
|
72
127
|
\end{cases}$$
|
|
73
128
|
|
|
74
|
-
To solve it on the segment $[0, 2]$ with the step $0.01$ using
|
|
129
|
+
To solve it on the segment $[0, 2]$ with the step $0.01$ using [LSODA](https://doi.org/10.1137/0904010) with the tolerance $10^{-7}$, we start with imports:
|
|
75
130
|
|
|
76
131
|
```typescript
|
|
77
|
-
import {ODEs,
|
|
132
|
+
import {ODEs, lsoda} from 'diff-grok';
|
|
78
133
|
```
|
|
79
134
|
|
|
80
135
|
Next, we create
|
|
@@ -101,7 +156,7 @@ const task: ODEs = {
|
|
|
101
156
|
Finally, we call the specified numerical method to solve `task`:
|
|
102
157
|
|
|
103
158
|
```typescript
|
|
104
|
-
const solution =
|
|
159
|
+
const solution = lsoda(task);
|
|
105
160
|
```
|
|
106
161
|
|
|
107
162
|
Currently, `solution` contains:
|
|
@@ -141,18 +196,84 @@ The following [classic problems](https://archimede.uniba.it/~testset/testsetivps
|
|
|
141
196
|
* describes a chemical reaction part of the air pollution model designed at The Dutch National Institute of Public Health and Environmental Protection
|
|
142
197
|
* [pollution.ts](./src/examples/pollution.ts)
|
|
143
198
|
|
|
144
|
-
The MRT, ROS3PRw and ROS34PRw methods demonstrate the following time performance (AMD Ryzen 5 5600H 3.30 GHz CPU):
|
|
199
|
+
The LSODA, MRT, ROS3PRw and ROS34PRw methods demonstrate the following time performance (AMD Ryzen 5 5600H 3.30 GHz CPU):
|
|
200
|
+
|
|
201
|
+
|Problem|Segment|Points|Tolerance|LSODA, ms|MRT, ms|ROS3PRw, ms|ROS34PRw, ms|
|
|
202
|
+
|-|-|-|-|-|-|-|-|
|
|
203
|
+
|[Rober](https://archimede.uniba.it/~testset/report/rober.pdf)|[0, 10E+11]|40K|1E-7|67|175|446|285|
|
|
204
|
+
|[HIRES](https://archimede.uniba.it/~testset/report/hires.pdf)|[0, 321.8122]|32K|1E-10|125|122|362|215|
|
|
205
|
+
|[VDPOL](https://archimede.uniba.it/~testset/report/vdpol.pdf)|[0, 2000]|20K|1E-12|268|492|1576|760|
|
|
206
|
+
|[OREGO](https://archimede.uniba.it/~testset/report/orego.pdf)|[0, 360]|36K|1E-8|76|205|483|199|
|
|
207
|
+
|[E5](https://archimede.uniba.it/~testset/report/e5.pdf)|[0, 10E+13]|40K|1E-6|7|6|17|8|
|
|
208
|
+
|[Pollution](https://archimede.uniba.it/~testset/report/pollu.pdf)|[0, 60]|30K|1E-6|12|18|50|23|
|
|
209
|
+
|
|
210
|
+
Maximum absolute deviations (MADs) from the reference solutions obtained using SciPy (Radau) are summarized in the table below:
|
|
211
|
+
|
|
212
|
+
|Problem|LSODA|MRT|ROS3PRw|ROS34PRw|
|
|
213
|
+
|-|-|-|-|-|
|
|
214
|
+
|[Rober](https://archimede.uniba.it/~testset/report/rober.pdf)|1.87e-8|1.87e-8|1.88e-8|1.88e-8|
|
|
215
|
+
|[HIRES](https://archimede.uniba.it/~testset/report/hires.pdf)|1.51e-11|4.80e-11|1.05e-14|2.87e-14|
|
|
216
|
+
|[VDPOL](https://archimede.uniba.it/~testset/report/vdpol.pdf)|5.12e-4|5.12e-4|5.12e-4|5.12e-4|
|
|
217
|
+
|[OREGO](https://archimede.uniba.it/~testset/report/orego.pdf)|3.84e-6|3.05e-5|3.45e-7|2.31e-6|
|
|
218
|
+
|[E5](https://archimede.uniba.it/~testset/report/e5.pdf)|3.02e-19|1.12e-19| 1.33e-19|3.40e-17|
|
|
219
|
+
|[Pollution](https://archimede.uniba.it/~testset/report/pollu.pdf)|1.23e-10|4.06e-10|9.16e-12|1.58e-10|
|
|
220
|
+
|
|
221
|
+
Run [check-methods.ts](./src/examples/check-methods.ts) to reproduce these results (see [here](#examples) how to run scripts standalone).
|
|
222
|
+
|
|
223
|
+
The following charts compare the Diff Grok and Radau solutions for the **van der Pol** system:
|
|
224
|
+
|
|
225
|
+

|
|
226
|
+
|
|
227
|
+
The following graphs present a comparison of the Diff Grok and Radau solutions for the **Pollution** model, highlighting a portion of the functions:
|
|
228
|
+
|
|
229
|
+

|
|
230
|
+
|
|
231
|
+
<details>
|
|
232
|
+
<summary><strong>Gallery</strong></summary>
|
|
233
|
+
|
|
234
|
+
**VDPOL**
|
|
235
|
+
|
|
236
|
+

|
|
237
|
+
|
|
238
|
+
**HIRES**
|
|
239
|
+
|
|
240
|
+

|
|
241
|
+
|
|
242
|
+
**E5**
|
|
243
|
+
|
|
244
|
+

|
|
245
|
+
|
|
246
|
+
**POLL**
|
|
247
|
+
|
|
248
|
+

|
|
249
|
+
|
|
250
|
+
**OREGO**
|
|
251
|
+
|
|
252
|
+

|
|
253
|
+
|
|
254
|
+
**Rober**
|
|
255
|
+
|
|
256
|
+

|
|
257
|
+
|
|
258
|
+
</details>
|
|
259
|
+
|
|
260
|
+
<details>
|
|
261
|
+
<summary><strong>Run benchmarks</strong></summary>
|
|
262
|
+
|
|
263
|
+
Run benchmark models and find the reference solutions via the following links to the [Datagrok](https://public.datagrok.ai) platform:
|
|
264
|
+
|
|
265
|
+
|Problem|Diff Grok|Radau|
|
|
266
|
+
|-|-|-|
|
|
267
|
+
|Rober|[ROBER.ivp](https://public.datagrok.ai/file/System.AppData/DiffStudio/benchmarks/ROBER.ivp)|[ROBER.csv](https://public.datagrok.ai/file/System.AppData/DiffStudio/benchmarks/ROBER-using-Radau.csv?browse=files)|
|
|
268
|
+
|HIRES|[HIRES.ivp](https://public.datagrok.ai/file/System.AppData/DiffStudio/benchmarks/HIRES.ivp)|[HIRES.csv](https://public.datagrok.ai/file/System.AppData/DiffStudio/benchmarks/HIRES-using-Radau.csv?browse=files)|
|
|
269
|
+
|VDPOL|[VDPOL.ivp](https://public.datagrok.ai/file/System.AppData/DiffStudio/benchmarks/VDPOL.ivp)|[VDPOL.csv](https://public.datagrok.ai/file/System.AppData/DiffStudio/benchmarks/VANDERPOL-using-Radau.csv?browse=files)|
|
|
270
|
+
|OREGO|[OREGO.ivp](https://public.datagrok.ai/file/System.AppData/DiffStudio/benchmarks/OREGO.ivp)|[OREGO.csv](https://public.datagrok.ai/file/System.AppData/DiffStudio/benchmarks/OREGO-using-Radau.csv?browse=files)|
|
|
271
|
+
|E5|[E5.ivp](https://public.datagrok.ai/file/System.AppData/DiffStudio/benchmarks/E5.ivp)|[E5.csv](https://public.datagrok.ai/file/System.AppData/DiffStudio/benchmarks/E5-using-Radau.csv?browse=files)|
|
|
272
|
+
|Pollution|[POLL.ivp](https://public.datagrok.ai/file/System.AppData/DiffStudio/benchmarks/POLL.ivp)|[POLL.csv](https://public.datagrok.ai/file/System.AppData/DiffStudio/benchmarks/POLL-using-Radau.csv?browse=files)|
|
|
145
273
|
|
|
146
|
-
|
|
147
|
-
|-|-|-|-|-|-|-|
|
|
148
|
-
|[Rober](https://archimede.uniba.it/~testset/report/rober.pdf)|[0, 10E+11]|40K|1E-7|103|446|285|
|
|
149
|
-
|[HIRES](https://archimede.uniba.it/~testset/report/hires.pdf)|[0, 321.8122]|32K|1E-10|222|362|215|
|
|
150
|
-
|[VDPOL](https://archimede.uniba.it/~testset/report/vdpol.pdf)|[0, 2000]|20K|1E-12|963|1576|760|
|
|
151
|
-
|[OREGO](https://archimede.uniba.it/~testset/report/orego.pdf)|[0, 360]|36K|1E-8|381|483|199|
|
|
152
|
-
|[E5](https://archimede.uniba.it/~testset/report/e5.pdf)|[0, 10E+13]|40K|1E-6|14|17|8|
|
|
153
|
-
|[Pollution](https://archimede.uniba.it/~testset/report/pollu.pdf)|[0, 60]|30K|1E-6|36|50|23|
|
|
274
|
+
In the file [print-benchmark.ts](./src/examples/print-benchmark.ts), you can find standalone functions that print the solutions of these problems to the console, as well as Python scripts for computing the solutions using SciPy.
|
|
154
275
|
|
|
155
|
-
|
|
276
|
+
</details>
|
|
156
277
|
|
|
157
278
|
## Scripting
|
|
158
279
|
|
|
@@ -262,7 +383,7 @@ To transform any model to JavaScript code with an appropriate specification of `
|
|
|
262
383
|
1. Import the parsing and code generating tools:
|
|
263
384
|
|
|
264
385
|
```typescript
|
|
265
|
-
import {getIVP, getJScode} from '
|
|
386
|
+
import {getIVP, getJScode} from 'diff-grok';
|
|
266
387
|
```
|
|
267
388
|
|
|
268
389
|
2. Define a string with a model specification, use a simple [model syntax](#model-components-and-syntax):
|
|
@@ -302,7 +423,7 @@ Diff Grok **pipeline** is a powerful feature for complex process simulation and
|
|
|
302
423
|
1. Start with imports:
|
|
303
424
|
|
|
304
425
|
```typescript
|
|
305
|
-
import * as DGL from '
|
|
426
|
+
import * as DGL from 'diff-grok';
|
|
306
427
|
```
|
|
307
428
|
|
|
308
429
|
2. Define your model:
|
|
@@ -394,3 +515,136 @@ Learn more
|
|
|
394
515
|
* Diff Studio example [models](https://datagrok.ai/help/compute/models)
|
|
395
516
|
* [Parameters optimization](https://datagrok.ai/help/compute/function-analysis#parameter-optimization)
|
|
396
517
|
* [Sensitivity analysis](https://datagrok.ai/help/compute/function-analysis#sensitivity-analysis)
|
|
518
|
+
|
|
519
|
+
## Environment Requirements
|
|
520
|
+
|
|
521
|
+
### Development & Build
|
|
522
|
+
|
|
523
|
+
* **Node.js ≥ 19.3.0** (required for development and building the library)
|
|
524
|
+
* **npm** or **yarn** package manager
|
|
525
|
+
|
|
526
|
+
### Runtime Environments
|
|
527
|
+
|
|
528
|
+
#### Server-Side (Node.js)
|
|
529
|
+
|
|
530
|
+
* **Node.js ≥ 16.0.0** (for server-side usage)
|
|
531
|
+
* Requires support for ES modules
|
|
532
|
+
* `Float64Array` and typed arrays support (available since Node.js 0.10+)
|
|
533
|
+
|
|
534
|
+
#### Operating Systems
|
|
535
|
+
|
|
536
|
+
* Windows (x64, ARM64)
|
|
537
|
+
* macOS (Intel & Apple Silicon)
|
|
538
|
+
* Linux (most common distributions)
|
|
539
|
+
|
|
540
|
+
#### Browser Support
|
|
541
|
+
|
|
542
|
+
The library runs in all modern browsers with ES2015+ support. Key requirements:
|
|
543
|
+
|
|
544
|
+
* **ES Modules** (native `import`/`export`)
|
|
545
|
+
* **Typed Arrays** (`Float64Array`, `Uint8Array`)
|
|
546
|
+
* **WebWorkers** (for pipeline computations)
|
|
547
|
+
* **ArrayBuffer** support
|
|
548
|
+
|
|
549
|
+
| Browser | Minimum Version | Supported? | Notes |
|
|
550
|
+
| ---------------------- | --------------- | ---------- | ----------------------------------------------- |
|
|
551
|
+
| **Chrome** | 63+ | ✔️ Yes | Full ES2015+ and WebWorker support |
|
|
552
|
+
| **Firefox** | 60+ | ✔️ Yes | Full ES2015+ and WebWorker support |
|
|
553
|
+
| **Safari (macOS/iOS)** | 11.1+ | ✔️ Yes | Native ES module and WebWorker support |
|
|
554
|
+
| **Edge (Chromium)** | 79+ | ✔️ Yes | Same support level as Chrome |
|
|
555
|
+
| **Opera** | 50+ | ✔️ Yes | Chromium-based, full support |
|
|
556
|
+
| **Legacy Browsers** | - | ❌ No | IE 11, pre-Chromium Edge, old Android browsers |
|
|
557
|
+
|
|
558
|
+
**Browser Feature Requirements:**
|
|
559
|
+
* ES2015 (ES6) JavaScript support
|
|
560
|
+
* Native ES modules (`<script type="module">`)
|
|
561
|
+
* `Float64Array` and other typed arrays
|
|
562
|
+
* `WebWorker` API (for parallel computations)
|
|
563
|
+
* `Promise` support
|
|
564
|
+
* `Math` object with standard functions (`exp`, `sin`, `cos`, etc.)
|
|
565
|
+
|
|
566
|
+
**Notes:**
|
|
567
|
+
* For older browsers, consider using a transpiler (Babel) and bundler (Webpack/Rollup)
|
|
568
|
+
* TypeScript compilation target should be ES2015 or higher
|
|
569
|
+
* WebWorker support is required for pipeline computations; without it, computations run on the main thread
|
|
570
|
+
|
|
571
|
+
### Bundler Configuration
|
|
572
|
+
|
|
573
|
+
When bundling for browsers, ensure:
|
|
574
|
+
* ES module output format is preserved or properly transformed
|
|
575
|
+
* TypedArray polyfills are not included (not needed for target browsers)
|
|
576
|
+
* WebWorker files are properly handled by your bundler
|
|
577
|
+
|
|
578
|
+
### Polyfills
|
|
579
|
+
|
|
580
|
+
No polyfills required for target environments. All required features are natively supported in the minimum browser versions listed above.
|
|
581
|
+
|
|
582
|
+
## Examples
|
|
583
|
+
|
|
584
|
+
Diff Grok contains a set of examples located in the folder [src/examples](./src/examples/):
|
|
585
|
+
|
|
586
|
+
|File|Features|
|
|
587
|
+
|-|-|
|
|
588
|
+
|[basic-use.ts](./src/examples/basic-use.ts)|Minimal "Hello World" example. Illustrates the use of the [LSODA](https://doi.org/10.1137/0904010) method.|
|
|
589
|
+
|[check-methods.ts](./src/examples/check-methods.ts)| Checks the [performance](#performance) of numerical methods.|
|
|
590
|
+
|[corr-probs.ts](./src/examples/corr-probs.ts)|Solves a set of problems with exact solutions and evaluate the deviation.|
|
|
591
|
+
|[cyclic-model.ts](./src/examples/cyclic-model.ts)| Considers pharmacokinetic-pharmacodynamic (PK-PD) simulation and shows how to apply pipelines and cyclic models.|
|
|
592
|
+
|[model-updates.ts](./src/examples/model-updates.ts)|Considers gluconic acid (GA) production by Aspergillus niger modeling and shows how to apply pipelines and models with updates.|
|
|
593
|
+
|[pipeline-use.ts](./src/examples/pipeline-use.ts)|Considers modeling queues and shows shows how to apply pipelines and models with customized outputs.|
|
|
594
|
+
|[scripting.ts](./src/examples/scripting.ts)|Shows how to generate JS-script from Diff Grok model.|
|
|
595
|
+
|
|
596
|
+
<details>
|
|
597
|
+
<summary><strong>Run examples</strong></summary>
|
|
598
|
+
|
|
599
|
+
To run examples standalone:
|
|
600
|
+
|
|
601
|
+
1. Install TypeScript locally. If your project does not already include TypeScript:
|
|
602
|
+
```bash
|
|
603
|
+
npm install --save-dev typescript
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
2. Create a tsconfig.json. If you do not have one yet:
|
|
607
|
+
```bash
|
|
608
|
+
npx tsc --init
|
|
609
|
+
```
|
|
610
|
+
Recommended configuration:
|
|
611
|
+
```json
|
|
612
|
+
{
|
|
613
|
+
"compilerOptions": {
|
|
614
|
+
"target": "es6",
|
|
615
|
+
"lib": ["ES2022", "dom"],
|
|
616
|
+
"sourceMap": true,
|
|
617
|
+
"strict": true,
|
|
618
|
+
"moduleResolution": "node",
|
|
619
|
+
"types": ["jest", "node"],
|
|
620
|
+
"esModuleInterop": true,
|
|
621
|
+
"skipLibCheck": true,
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
```
|
|
625
|
+
|
|
626
|
+
3. Compile the TypeScript file:
|
|
627
|
+
```bash
|
|
628
|
+
tsc src/examples/basic-use.ts
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
4. Run:
|
|
632
|
+
```bash
|
|
633
|
+
node src/examples/basic-use.js
|
|
634
|
+
```
|
|
635
|
+
|
|
636
|
+
</details>
|
|
637
|
+
|
|
638
|
+
## References
|
|
639
|
+
|
|
640
|
+
* L. Petzold, "Automatic Selection of Methods for Solving Stiff and Nonstiff Systems of Ordinary Differential Equations," *SIAM J. Sci. Stat. Comput.*, 4(1), 136–148, 1983. [doi:10.1137/0904010](https://doi.org/10.1137/0904010)
|
|
641
|
+
* A. C. Hindmarsh, "ODEPACK, A Systematized Collection of ODE Solvers," *Scientific Computing*, R. S. Stepleman et al. (eds.), North-Holland, Amsterdam, pp. 55–64, 1983. [link](https://computing.llnl.gov/sites/default/files/ODEPACK_pub1_u88007.pdf)
|
|
642
|
+
* The LSODA solver is ported to TypeScript from the C library [liblsoda](https://github.com/sdwfrost/liblsoda)
|
|
643
|
+
* T. Rang and L. Angermann, "New Rosenbrock W-Methods of Order 3 for Partial Differential Algebraic Equations of Index 1," *BIT Numer. Math.*, 45, 761–787, 2005. [doi:10.1007/s10543-005-0035-y](https://doi.org/10.1016/j.cam.2015.03.010)
|
|
644
|
+
* E. Hairer and G. Wanner, *Solving Ordinary Differential Equations II: Stiff and Differential-Algebraic Problems*, Springer, 1996. [doi:10.1137/S1064827594276424](https://doi.org/10.1137/S1064827594276424)
|
|
645
|
+
|
|
646
|
+
## Contributing
|
|
647
|
+
|
|
648
|
+
We welcome contributions of all kinds - bug reports, feature requests, documentation updates, and pull requests.
|
|
649
|
+
|
|
650
|
+
Before contributing, please read our [Contributing Guidelines](./CONTRIBUTING.md).
|
package/images/E5.png
ADDED
|
Binary file
|
package/images/HIRES.png
ADDED
|
Binary file
|
package/images/OREGO.png
ADDED
|
Binary file
|
|
Binary file
|
package/images/POLL.png
ADDED
|
Binary file
|
package/images/ROBER.png
ADDED
|
Binary file
|
package/images/VDP0L.png
ADDED
|
Binary file
|
package/images/VDPOL.png
ADDED
|
Binary file
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { mrt, ros3prw, ros34prw, CallbackAction, DEFAULT_OPTIONS, getCallback } from './src/solver-tools';
|
|
2
|
-
export { perfProbs, corrProbs } from './src/examples';
|
|
1
|
+
export { mrt, ros3prw, ros34prw, rk4, ab5, ab4, rkdp, rk3, lsoda, CallbackAction, DEFAULT_OPTIONS, getCallback, Callback, IterCheckerCallback, TimeCheckerCallback } from './src/solver-tools';
|
|
2
|
+
export { perfProbs, corrProbs, refPoints, printRobertson, printHires, printOrego, printE5, printVdpol, printPollution } from './src/examples';
|
|
3
3
|
export { DF_NAME, CONTROL_EXPR, MAX_LINE_CHART, getIVP, getScriptLines, getScriptParams, getJScode, SCRIPTING, BRACE_OPEN, BRACE_CLOSE, BRACKET_OPEN, BRACKET_CLOSE, ANNOT_SEPAR, CONTROL_SEP, STAGE_COL_NAME, ARG_INPUT_KEYS, DEFAULT_SOLVER_SETTINGS, ModelError, getFunc4worker } from './src/scripting-tools';
|
|
4
4
|
export { getIvp2WebWorker, solveIvp } from './src/worker-tools';
|
|
5
5
|
export { applyPipeline, getOutputCode, getOutputNames, PipelineCreator, BasicModelPipelineCreator, getInputVector, getPipelineCreator, CyclicModelPipelineCreator, UpdatesModelPipelineCreator } from './src/pipeline';
|