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,594 @@
|
|
|
1
|
+
import {robertson} from './robertson';
|
|
2
|
+
import {hires} from './hires';
|
|
3
|
+
import {vdpol} from './vdpol';
|
|
4
|
+
import {orego} from './orego';
|
|
5
|
+
import {e5} from './e5';
|
|
6
|
+
import {pollution} from './pollution';
|
|
7
|
+
import {ODEs, SolverMethod, mrt, ros34prw} from '../../index';
|
|
8
|
+
|
|
9
|
+
/** Solve the given problem and output to console the solution */
|
|
10
|
+
export function printSolution(task: ODEs, method: SolverMethod, separator: string): void {
|
|
11
|
+
try {
|
|
12
|
+
// Solve the problem
|
|
13
|
+
const solution = method(task);
|
|
14
|
+
|
|
15
|
+
// Output results
|
|
16
|
+
|
|
17
|
+
console.log(task.name);
|
|
18
|
+
|
|
19
|
+
let line: string = [task.arg.name].concat(task.solutionColNames).join(separator);
|
|
20
|
+
|
|
21
|
+
console.log(line);
|
|
22
|
+
|
|
23
|
+
const length = solution[0].length;
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i < length; ++i) {
|
|
26
|
+
line = solution.map((col) => col[i].toString()).join(separator);
|
|
27
|
+
console.log(line);
|
|
28
|
+
}
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.log('Solver failed: ', err instanceof Error ? err.message : 'Unknown problem!');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
const SEPARATOR = ' '; // use ',' to get csv
|
|
36
|
+
|
|
37
|
+
/** Print solution of the ROBER benchmark problem
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* // TypeScript usage example
|
|
41
|
+
* import {printRobertson} from 'diff-grok';
|
|
42
|
+
*
|
|
43
|
+
* printRobertson();
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* ```python
|
|
47
|
+
* # Python reference calculation for comparison
|
|
48
|
+
* import numpy as np
|
|
49
|
+
import pandas as pd
|
|
50
|
+
from scipy.integrate import solve_ivp
|
|
51
|
+
|
|
52
|
+
METHOD = "Radau" # "BDF" or "LSODA"
|
|
53
|
+
|
|
54
|
+
# -------------------------
|
|
55
|
+
# 1. Define Robertson ODE
|
|
56
|
+
# -------------------------
|
|
57
|
+
def robertson(t, y):
|
|
58
|
+
A, B, C = y
|
|
59
|
+
dA = -0.04 * A + 1e4 * B * C
|
|
60
|
+
dB = 0.04 * A - 1e4 * B * C - 3e7 * B**2
|
|
61
|
+
dC = 3e7 * B**2
|
|
62
|
+
return [dA, dB, dC]
|
|
63
|
+
|
|
64
|
+
# -------------------------
|
|
65
|
+
# 2. Initial conditions
|
|
66
|
+
# -------------------------
|
|
67
|
+
y0 = [1.0, 0.0, 0.0]
|
|
68
|
+
t_start = 0.0
|
|
69
|
+
t_end = 1e11
|
|
70
|
+
t_step = 2.5e6
|
|
71
|
+
t_span = (t_start, t_end)
|
|
72
|
+
|
|
73
|
+
# Output points
|
|
74
|
+
t_eval = np.arange(t_start, t_end + t_step, t_step)
|
|
75
|
+
|
|
76
|
+
# -------------------------
|
|
77
|
+
# 3. Solve ODE
|
|
78
|
+
# -------------------------
|
|
79
|
+
sol = solve_ivp(
|
|
80
|
+
robertson,
|
|
81
|
+
t_span,
|
|
82
|
+
y0,
|
|
83
|
+
method=METHOD,
|
|
84
|
+
t_eval=t_eval,
|
|
85
|
+
rtol=1e-7,
|
|
86
|
+
atol=1e-7
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
print("Success:", sol.success)
|
|
90
|
+
print("Message:", sol.message)
|
|
91
|
+
|
|
92
|
+
# sol.t → time array, sol.y.T → concentrations (n_points, 3)
|
|
93
|
+
data = np.column_stack((sol.t, sol.y.T))
|
|
94
|
+
|
|
95
|
+
# Create DataFrame with headers
|
|
96
|
+
df = pd.DataFrame(data, columns=['time', 'A', 'B', 'C'])
|
|
97
|
+
|
|
98
|
+
# Save to CSV
|
|
99
|
+
df.to_csv(f'ROBER-using-{METHOD}.csv', index=False)
|
|
100
|
+
```
|
|
101
|
+
*/
|
|
102
|
+
export function printRobertson(): void {
|
|
103
|
+
printSolution(robertson, mrt, SEPARATOR);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Print solution of the HIRES benchmark problem
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* // TypeScript usage example
|
|
110
|
+
* import {printHires} from 'diff-grok';
|
|
111
|
+
*
|
|
112
|
+
* printHires();
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* ```python
|
|
116
|
+
* # Python reference calculation for comparison
|
|
117
|
+
* import numpy as np
|
|
118
|
+
import pandas as pd
|
|
119
|
+
from scipy.integrate import solve_ivp
|
|
120
|
+
|
|
121
|
+
# -------------------------
|
|
122
|
+
# 0. Solver method
|
|
123
|
+
# -------------------------
|
|
124
|
+
METHOD = "Radau" # stiff solver suitable for HIRES
|
|
125
|
+
|
|
126
|
+
# -------------------------
|
|
127
|
+
# 1. Define HIRES ODE
|
|
128
|
+
# -------------------------
|
|
129
|
+
def hires(t, y):
|
|
130
|
+
y1, y2, y3, y4, y5, y6, y7, y8 = y
|
|
131
|
+
dy = np.zeros(8)
|
|
132
|
+
dy[0] = -1.71 * y1 + 0.43 * y2 + 8.32 * y3 + 0.0007
|
|
133
|
+
dy[1] = 1.71 * y1 - 8.75 * y2
|
|
134
|
+
dy[2] = -10.03 * y3 + 0.43 * y4 + 0.035 * y5
|
|
135
|
+
dy[3] = 8.32 * y2 + 1.71 * y3 - 1.12 * y4
|
|
136
|
+
dy[4] = -1.745 * y5 + 0.43 * y6 + 0.43 * y7
|
|
137
|
+
dy[5] = -280 * y6 * y8 + 0.69 * y4 + 1.71 * y5 - 0.43 * y6 + 0.69 * y7
|
|
138
|
+
dy[6] = 280 * y6 * y8 - 1.81 * y7
|
|
139
|
+
dy[7] = -280 * y6 * y8 + 1.81 * y7
|
|
140
|
+
return dy
|
|
141
|
+
|
|
142
|
+
# -------------------------
|
|
143
|
+
# 2. Initial conditions and time
|
|
144
|
+
# -------------------------
|
|
145
|
+
y0 = [1, 0, 0, 0, 0, 0, 0, 0.0057]
|
|
146
|
+
|
|
147
|
+
t_start = 0.0
|
|
148
|
+
t_end = 321.8122
|
|
149
|
+
t_step = 0.01
|
|
150
|
+
n_points = int(np.ceil((t_end - t_start) / t_step)) + 1
|
|
151
|
+
t_eval = np.linspace(t_start, t_end, n_points)
|
|
152
|
+
|
|
153
|
+
# -------------------------
|
|
154
|
+
# 3. Solve ODE
|
|
155
|
+
# -------------------------
|
|
156
|
+
sol = solve_ivp(
|
|
157
|
+
hires,
|
|
158
|
+
t_span,
|
|
159
|
+
y0,
|
|
160
|
+
method=METHOD,
|
|
161
|
+
t_eval=t_eval,
|
|
162
|
+
rtol=1e-10,
|
|
163
|
+
atol=1e-10
|
|
164
|
+
)
|
|
165
|
+
|
|
166
|
+
print("Success:", sol.success)
|
|
167
|
+
print("Message:", sol.message)
|
|
168
|
+
|
|
169
|
+
# -------------------------
|
|
170
|
+
# 4. Save solution to CSV
|
|
171
|
+
# -------------------------
|
|
172
|
+
# Combine time + concentrations
|
|
173
|
+
data = np.column_stack((sol.t, sol.y.T))
|
|
174
|
+
|
|
175
|
+
# Column names
|
|
176
|
+
col_names = ['t'] + ['y1','y2','y3','y4','y5','y6','y7','y8']
|
|
177
|
+
|
|
178
|
+
# Create DataFrame and save
|
|
179
|
+
df = pd.DataFrame(data, columns=col_names)
|
|
180
|
+
filename = f'HIRES-using-{METHOD}.csv'
|
|
181
|
+
df.to_csv(filename, index=False)
|
|
182
|
+
|
|
183
|
+
print(f"Solution saved to '{filename}'")
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
*/
|
|
187
|
+
export function printHires(): void {
|
|
188
|
+
printSolution(hires, ros34prw, SEPARATOR);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Print solution of the VDPOL benchmark problem
|
|
192
|
+
* @example
|
|
193
|
+
* ```ts
|
|
194
|
+
* // TypeScript usage example
|
|
195
|
+
* import {printVdpol} from 'diff-grok';
|
|
196
|
+
*
|
|
197
|
+
* printVdpol();
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
200
|
+
* ```python
|
|
201
|
+
* # Python reference calculation for comparison
|
|
202
|
+
* import numpy as np
|
|
203
|
+
import pandas as pd
|
|
204
|
+
from scipy.integrate import solve_ivp
|
|
205
|
+
|
|
206
|
+
# -------------------------
|
|
207
|
+
# 0. Solver method
|
|
208
|
+
# -------------------------
|
|
209
|
+
METHOD = "Radau" # stiff solver recommended for van der Pol with large mu
|
|
210
|
+
|
|
211
|
+
# -------------------------
|
|
212
|
+
# 1. Define van der Pol ODE (stiff)
|
|
213
|
+
# -------------------------
|
|
214
|
+
def vdpol(t, y):
|
|
215
|
+
x1, x2 = y
|
|
216
|
+
dx1 = x2
|
|
217
|
+
dx2 = -x1 + 1000 * (1 - x1**2) * x2 # mu = 1000
|
|
218
|
+
return [dx1, dx2]
|
|
219
|
+
|
|
220
|
+
# -------------------------
|
|
221
|
+
# 2. Initial conditions and time
|
|
222
|
+
# -------------------------
|
|
223
|
+
y0 = [-1, 1]
|
|
224
|
+
t_start = 0.0
|
|
225
|
+
t_end = 2000.0
|
|
226
|
+
t_step = 0.1
|
|
227
|
+
|
|
228
|
+
# Use linspace to avoid "t_eval not in t_span" error
|
|
229
|
+
n_points = int(np.ceil((t_end - t_start) / t_step)) + 1
|
|
230
|
+
t_eval = np.linspace(t_start, t_end, n_points)
|
|
231
|
+
|
|
232
|
+
# -------------------------
|
|
233
|
+
# 3. Solve ODE
|
|
234
|
+
# -------------------------
|
|
235
|
+
sol = solve_ivp(
|
|
236
|
+
vdpol,
|
|
237
|
+
(t_start, t_end),
|
|
238
|
+
y0,
|
|
239
|
+
method=METHOD,
|
|
240
|
+
t_eval=t_eval,
|
|
241
|
+
rtol=1e-12,
|
|
242
|
+
atol=1e-12
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
print("Success:", sol.success)
|
|
246
|
+
print("Message:", sol.message)
|
|
247
|
+
|
|
248
|
+
# -------------------------
|
|
249
|
+
# 4. Save solution to CSV
|
|
250
|
+
# -------------------------
|
|
251
|
+
data = np.column_stack((sol.t, sol.y.T))
|
|
252
|
+
col_names = ['t', 'x1', 'x2']
|
|
253
|
+
|
|
254
|
+
df = pd.DataFrame(data, columns=col_names)
|
|
255
|
+
filename = f"VANDERPOL-using-{METHOD}.csv"
|
|
256
|
+
df.to_csv(filename, index=False)
|
|
257
|
+
|
|
258
|
+
print(f"Solution saved to '{filename}'")
|
|
259
|
+
|
|
260
|
+
```
|
|
261
|
+
*/
|
|
262
|
+
export function printVdpol(): void {
|
|
263
|
+
printSolution(vdpol, ros34prw, SEPARATOR);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/** Print solution of the OREGO benchmark problem
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* // TypeScript usage example
|
|
270
|
+
* import {printOrego} from 'diff-grok';
|
|
271
|
+
*
|
|
272
|
+
* printOrego();
|
|
273
|
+
* ```
|
|
274
|
+
*
|
|
275
|
+
* ```python
|
|
276
|
+
* # Python reference calculation for comparison
|
|
277
|
+
* import numpy as np
|
|
278
|
+
import pandas as pd
|
|
279
|
+
from scipy.integrate import solve_ivp
|
|
280
|
+
|
|
281
|
+
# -------------------------
|
|
282
|
+
# 0. Solver method
|
|
283
|
+
# -------------------------
|
|
284
|
+
METHOD = "Radau" # stiff solver recommended
|
|
285
|
+
|
|
286
|
+
# -------------------------
|
|
287
|
+
# 1. Define OREGO ODE
|
|
288
|
+
# -------------------------
|
|
289
|
+
def orego(t, y):
|
|
290
|
+
y1, y2, y3 = y
|
|
291
|
+
dy1 = 77.27 * (y2 - y1 * y2 + y1 - 0.000008375 * y1**2)
|
|
292
|
+
dy2 = ( -y2 - y1 * y2 + y3 ) / 77.27
|
|
293
|
+
dy3 = 0.161 * (y1 - y3)
|
|
294
|
+
return [dy1, dy2, dy3]
|
|
295
|
+
|
|
296
|
+
# -------------------------
|
|
297
|
+
# 2. Initial conditions and time
|
|
298
|
+
# -------------------------
|
|
299
|
+
y0 = [1, 2, 3]
|
|
300
|
+
t_start = 0.0
|
|
301
|
+
t_end = 360.0
|
|
302
|
+
t_step = 0.01
|
|
303
|
+
|
|
304
|
+
# Use linspace to ensure t_eval within t_span
|
|
305
|
+
n_points = int(np.ceil((t_end - t_start) / t_step)) + 1
|
|
306
|
+
t_eval = np.linspace(t_start, t_end, n_points)
|
|
307
|
+
|
|
308
|
+
# -------------------------
|
|
309
|
+
# 3. Solve ODE
|
|
310
|
+
# -------------------------
|
|
311
|
+
sol = solve_ivp(
|
|
312
|
+
orego,
|
|
313
|
+
(t_start, t_end),
|
|
314
|
+
y0,
|
|
315
|
+
method=METHOD,
|
|
316
|
+
t_eval=t_eval,
|
|
317
|
+
rtol=1e-8,
|
|
318
|
+
atol=1e-8
|
|
319
|
+
)
|
|
320
|
+
|
|
321
|
+
print("Success:", sol.success)
|
|
322
|
+
print("Message:", sol.message)
|
|
323
|
+
|
|
324
|
+
# -------------------------
|
|
325
|
+
# 4. Save solution to CSV
|
|
326
|
+
# -------------------------
|
|
327
|
+
data = np.column_stack((sol.t, sol.y.T))
|
|
328
|
+
col_names = ['t', 'y1', 'y2', 'y3']
|
|
329
|
+
|
|
330
|
+
df = pd.DataFrame(data, columns=col_names)
|
|
331
|
+
filename = f"OREGO-using-{METHOD}.csv"
|
|
332
|
+
df.to_csv(filename, index=False)
|
|
333
|
+
|
|
334
|
+
print(f"Solution saved to '{filename}'")
|
|
335
|
+
```
|
|
336
|
+
*/
|
|
337
|
+
export function printOrego(): void {
|
|
338
|
+
printSolution(orego, ros34prw, SEPARATOR);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/** Print solution of the E5 benchmark problem
|
|
342
|
+
* @example
|
|
343
|
+
* ```ts
|
|
344
|
+
* // TypeScript usage example
|
|
345
|
+
* import {printE5} from 'diff-grok';
|
|
346
|
+
*
|
|
347
|
+
* printE5();
|
|
348
|
+
* ```
|
|
349
|
+
*
|
|
350
|
+
* ```python
|
|
351
|
+
* # Python reference calculation for comparison
|
|
352
|
+
* import numpy as np
|
|
353
|
+
import pandas as pd
|
|
354
|
+
from scipy.integrate import solve_ivp
|
|
355
|
+
|
|
356
|
+
# -------------------------
|
|
357
|
+
# 0. Solver method
|
|
358
|
+
# -------------------------
|
|
359
|
+
METHOD = "Radau" # stiff solver recommended
|
|
360
|
+
|
|
361
|
+
# -------------------------
|
|
362
|
+
# 1. Define E5 constants
|
|
363
|
+
# -------------------------
|
|
364
|
+
K1 = 7.89e-10
|
|
365
|
+
K2 = 1.13e9
|
|
366
|
+
K3 = 1.1e7
|
|
367
|
+
K4 = 1.13e3
|
|
368
|
+
|
|
369
|
+
# -------------------------
|
|
370
|
+
# 2. Define E5 ODE
|
|
371
|
+
# -------------------------
|
|
372
|
+
def e5(t, y):
|
|
373
|
+
y1, y2, y3, y4 = y
|
|
374
|
+
dy = np.zeros(4)
|
|
375
|
+
dy[0] = -K1 * y1 - K3 * y1 * y3
|
|
376
|
+
dy[1] = K1 * y1 - K2 * y2 * y3
|
|
377
|
+
dy[2] = K1 * y1 - K2 * y2 * y3 - K3 * y1 * y3 + K4 * y4
|
|
378
|
+
dy[3] = K3 * y1 * y3 - K4 * y4
|
|
379
|
+
return dy
|
|
380
|
+
|
|
381
|
+
# -------------------------
|
|
382
|
+
# 3. Initial conditions and time
|
|
383
|
+
# -------------------------
|
|
384
|
+
y0 = [0.00176, 0, 0, 0]
|
|
385
|
+
t_start = 0.0
|
|
386
|
+
t_end = 1e6
|
|
387
|
+
t_step = 2.5e3
|
|
388
|
+
|
|
389
|
+
# Ensure t_eval is within t_span
|
|
390
|
+
n_points = int(np.ceil((t_end - t_start) / t_step)) + 1
|
|
391
|
+
t_eval = np.linspace(t_start, t_end, n_points)
|
|
392
|
+
|
|
393
|
+
# -------------------------
|
|
394
|
+
# 4. Solve ODE
|
|
395
|
+
# -------------------------
|
|
396
|
+
sol = solve_ivp(
|
|
397
|
+
e5,
|
|
398
|
+
(t_start, t_end),
|
|
399
|
+
y0,
|
|
400
|
+
method=METHOD,
|
|
401
|
+
t_eval=t_eval,
|
|
402
|
+
rtol=1e-6,
|
|
403
|
+
atol=1e-6
|
|
404
|
+
)
|
|
405
|
+
|
|
406
|
+
print("Success:", sol.success)
|
|
407
|
+
print("Message:", sol.message)
|
|
408
|
+
|
|
409
|
+
# -------------------------
|
|
410
|
+
# 5. Save solution to CSV
|
|
411
|
+
# -------------------------
|
|
412
|
+
data = np.column_stack((sol.t, sol.y.T))
|
|
413
|
+
col_names = ['t', 'y1', 'y2', 'y3', 'y4']
|
|
414
|
+
|
|
415
|
+
df = pd.DataFrame(data, columns=col_names)
|
|
416
|
+
filename = f"E5-using-{METHOD}.csv"
|
|
417
|
+
df.to_csv(filename, index=False)
|
|
418
|
+
|
|
419
|
+
print(f"Solution saved to '{filename}'")
|
|
420
|
+
*/
|
|
421
|
+
export function printE5(): void {
|
|
422
|
+
printSolution(e5, ros34prw, SEPARATOR);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** Print solution of the POLL benchmark problem
|
|
426
|
+
* @example
|
|
427
|
+
* ```ts
|
|
428
|
+
* // TypeScript usage example
|
|
429
|
+
* import {printPollution} from 'diff-grok';
|
|
430
|
+
*
|
|
431
|
+
* printPollution();
|
|
432
|
+
* ```
|
|
433
|
+
*
|
|
434
|
+
* ```python
|
|
435
|
+
* # Python reference calculation for comparisonimport numpy as np
|
|
436
|
+
import pandas as pd
|
|
437
|
+
from scipy.integrate import solve_ivp
|
|
438
|
+
|
|
439
|
+
# -------------------------
|
|
440
|
+
# 0. Solver method and tolerance
|
|
441
|
+
# -------------------------
|
|
442
|
+
METHOD = "Radau" # stiff solver
|
|
443
|
+
RTOL = 1e-6
|
|
444
|
+
ATOL = 1e-6
|
|
445
|
+
|
|
446
|
+
# -------------------------
|
|
447
|
+
# 1. Reaction constants
|
|
448
|
+
# -------------------------
|
|
449
|
+
k1 = 0.35
|
|
450
|
+
k2 = 26.6
|
|
451
|
+
k3 = 1.23e4
|
|
452
|
+
k4 = 8.6e-4
|
|
453
|
+
k5 = 8.2e-4
|
|
454
|
+
k6 = 1.5e4
|
|
455
|
+
k7 = 1.3e-4
|
|
456
|
+
k8 = 2.4e4
|
|
457
|
+
k9 = 1.65e4
|
|
458
|
+
k10 = 9e3
|
|
459
|
+
k11 = 0.022
|
|
460
|
+
k12 = 1.2e4
|
|
461
|
+
k13 = 1.88
|
|
462
|
+
k14 = 1.63e4
|
|
463
|
+
k15 = 4.8e6
|
|
464
|
+
k16 = 3.5e-4
|
|
465
|
+
k17 = 0.0175
|
|
466
|
+
k18 = 1e8
|
|
467
|
+
k19 = 4.44e11
|
|
468
|
+
k20 = 1240
|
|
469
|
+
k21 = 2.1
|
|
470
|
+
k22 = 5.78
|
|
471
|
+
k23 = 0.0474
|
|
472
|
+
k24 = 1780
|
|
473
|
+
k25 = 3.12
|
|
474
|
+
|
|
475
|
+
# -------------------------
|
|
476
|
+
# 2. Initial conditions
|
|
477
|
+
# -------------------------
|
|
478
|
+
y0 = [
|
|
479
|
+
0, # y1 NO2
|
|
480
|
+
0.2, # y2 NO
|
|
481
|
+
0, # y3 O3P
|
|
482
|
+
0.04, # y4 O3
|
|
483
|
+
0, # y5 HO2
|
|
484
|
+
0, # y6 OH
|
|
485
|
+
0.1, # y7 HCHO
|
|
486
|
+
0.3, # y8 CO
|
|
487
|
+
0.01, # y9 ALD
|
|
488
|
+
0, # y10 MEO2
|
|
489
|
+
0, # y11 C2O3
|
|
490
|
+
0, # y12 CO2
|
|
491
|
+
0, # y13 PAN
|
|
492
|
+
0, # y14 CH3O
|
|
493
|
+
0, # y15 HNO3
|
|
494
|
+
0, # y16 O1D
|
|
495
|
+
0.007, # y17 SO2
|
|
496
|
+
0, # y18 SO4
|
|
497
|
+
0, # y19 NO3
|
|
498
|
+
0 # y20 N2O5
|
|
499
|
+
]
|
|
500
|
+
|
|
501
|
+
# -------------------------
|
|
502
|
+
# 3. Define POLL ODE system
|
|
503
|
+
# -------------------------
|
|
504
|
+
def poll(t, y):
|
|
505
|
+
y = np.array(y)
|
|
506
|
+
r1 = k1*y[0]
|
|
507
|
+
r2 = k2*y[1]*y[3]
|
|
508
|
+
r3 = k3*y[4]*y[1]
|
|
509
|
+
r4 = k4*y[6]
|
|
510
|
+
r5 = k5*y[6]
|
|
511
|
+
r6 = k6*y[6]*y[5]
|
|
512
|
+
r7 = k7*y[8]
|
|
513
|
+
r8 = k8*y[8]*y[5]
|
|
514
|
+
r9 = k9*y[10]*y[1]
|
|
515
|
+
r10 = k10*y[10]*y[0]
|
|
516
|
+
r11 = k11*y[12]
|
|
517
|
+
r12 = k12*y[9]*y[1]
|
|
518
|
+
r13 = k13*y[13]
|
|
519
|
+
r14 = k14*y[0]*y[5]
|
|
520
|
+
r15 = k15*y[2]
|
|
521
|
+
r16 = k16*y[3]
|
|
522
|
+
r17 = k17*y[3]
|
|
523
|
+
r18 = k18*y[15]
|
|
524
|
+
r19 = k19*y[15]
|
|
525
|
+
r20 = k20*y[16]*y[5]
|
|
526
|
+
r21 = k21*y[18]
|
|
527
|
+
r22 = k22*y[18]
|
|
528
|
+
r23 = k23*y[0]*y[3]
|
|
529
|
+
r24 = k24*y[18]*y[0]
|
|
530
|
+
r25 = k25*y[19]
|
|
531
|
+
|
|
532
|
+
dy = np.zeros(20)
|
|
533
|
+
dy[0] = -(r1 + r10 + r14 + r23 + r24) + (r2 + r3 + r9 + r11 + r12 + r22 + r25)
|
|
534
|
+
dy[1] = -r2 - r3 - r9 - r12 + r1 + r21
|
|
535
|
+
dy[2] = -r15 + r1 + r17 + r19 + r22
|
|
536
|
+
dy[3] = -r2 - r16 - r17 - r23 + r15
|
|
537
|
+
dy[4] = -r3 + 2*r4 + r6 + r7 + r13 + r20
|
|
538
|
+
dy[5] = -r6 - r8 - r14 - r20 + r3 + 2*r18
|
|
539
|
+
dy[6] = -r4 - r5 - r6 + r13
|
|
540
|
+
dy[7] = r4 + r5 + r6 + r7
|
|
541
|
+
dy[8] = -r7 - r8
|
|
542
|
+
dy[9] = -r12 + r7 + r9
|
|
543
|
+
dy[10] = -r9 - r10 + r8 + r11
|
|
544
|
+
dy[11] = r9
|
|
545
|
+
dy[12] = -r11 + r10
|
|
546
|
+
dy[13] = -r13 + r12
|
|
547
|
+
dy[14] = r14
|
|
548
|
+
dy[15] = -r18 - r19 + r16
|
|
549
|
+
dy[16] = -r20
|
|
550
|
+
dy[17] = r20
|
|
551
|
+
dy[18] = -r21 - r22 - r24 + r23 + r25
|
|
552
|
+
dy[19] = -r25 + r24
|
|
553
|
+
|
|
554
|
+
return dy
|
|
555
|
+
|
|
556
|
+
# -------------------------
|
|
557
|
+
# 4. Time array
|
|
558
|
+
# -------------------------
|
|
559
|
+
t_start = 0
|
|
560
|
+
t_end = 60 # final time
|
|
561
|
+
t_step = 0.002
|
|
562
|
+
n_points = int(np.ceil((t_end - t_start)/t_step)) + 1
|
|
563
|
+
t_eval = np.linspace(t_start, t_end, n_points)
|
|
564
|
+
|
|
565
|
+
# -------------------------
|
|
566
|
+
# 5. Solve ODE
|
|
567
|
+
# -------------------------
|
|
568
|
+
sol = solve_ivp(
|
|
569
|
+
poll,
|
|
570
|
+
(t_start, t_end),
|
|
571
|
+
y0,
|
|
572
|
+
method=METHOD,
|
|
573
|
+
t_eval=t_eval,
|
|
574
|
+
rtol=RTOL,
|
|
575
|
+
atol=ATOL
|
|
576
|
+
)
|
|
577
|
+
|
|
578
|
+
print("Success:", sol.success)
|
|
579
|
+
print("Message:", sol.message)
|
|
580
|
+
|
|
581
|
+
# -------------------------
|
|
582
|
+
# 6. Save solution to CSV
|
|
583
|
+
# -------------------------
|
|
584
|
+
col_names = ['t'] + [f'y{i+1}' for i in range(20)]
|
|
585
|
+
data = np.column_stack((sol.t, sol.y.T))
|
|
586
|
+
df = pd.DataFrame(data, columns=col_names)
|
|
587
|
+
filename = f"POLL-using-{METHOD}.csv"
|
|
588
|
+
df.to_csv(filename, index=False)
|
|
589
|
+
|
|
590
|
+
print(f"Solution saved to '{filename}'")
|
|
591
|
+
*/
|
|
592
|
+
export function printPollution(): void {
|
|
593
|
+
printSolution(pollution, ros34prw, SEPARATOR);
|
|
594
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Robertson chemical reaction, updated version (see https://archimede.uniba.it/~testset/problems/rober.php) */
|
|
2
|
+
export const robertson = {
|
|
3
|
+
name: 'Robertson',
|
|
4
|
+
arg: { name: 't', start: 0, finish: 10e11, step: 2.5e6 },
|
|
5
|
+
initial: [1, 0, 0],
|
|
6
|
+
func: (t, y, output) => {
|
|
7
|
+
output[0] = -0.04 * y[0] + 1e4 * y[1] * y[2];
|
|
8
|
+
output[1] = 0.04 * y[0] - 1e4 * y[1] * y[2] - 3e7 * Math.pow(y[1], 2);
|
|
9
|
+
output[2] = 3e7 * Math.pow(y[1], 2);
|
|
10
|
+
},
|
|
11
|
+
tolerance: 1e-7,
|
|
12
|
+
solutionColNames: ['A', 'B', 'C'],
|
|
13
|
+
};
|
|
14
|
+
export const robertsonReferencePoint = new Float64Array([
|
|
15
|
+
0.2083340149701255E-7,
|
|
16
|
+
0.8333360770334713E-13,
|
|
17
|
+
0.9999999791665050,
|
|
18
|
+
]);
|
|
19
|
+
//# sourceMappingURL=robertson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"robertson.js","sourceRoot":"","sources":["robertson.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,GAAG,EAAE,EAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAC;IACtD,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAClB,IAAI,EAAE,CAAC,CAAS,EAAE,CAAe,EAAE,MAAoB,EAAE,EAAE;QACzD,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC7C,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,SAAA,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA,CAAC;QAC5D,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,SAAA,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA,CAAC;IAC5B,CAAC;IACD,SAAS,EAAE,IAAI;IACf,gBAAgB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;CAClC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,YAAY,CAAC;IACtD,qBAAqB;IACrB,sBAAsB;IACtB,kBAAkB;CACnB,CAAC,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Robertson chemical reaction, updated version (see https://archimede.uniba.it/~testset/problems/rober.php) */
|
|
2
|
+
export const robertson = {
|
|
3
|
+
name: 'Robertson',
|
|
4
|
+
arg: {name: 't', start: 0, finish: 10e11, step: 2.5e6},
|
|
5
|
+
initial: [1, 0, 0],
|
|
6
|
+
func: (t: number, y: Float64Array, output: Float64Array) => {
|
|
7
|
+
output[0] = -0.04 * y[0] + 1e4 * y[1] * y[2];
|
|
8
|
+
output[1] = 0.04 * y[0] - 1e4 * y[1] * y[2] - 3e7 * y[1]**2;
|
|
9
|
+
output[2] = 3e7 * y[1]**2;
|
|
10
|
+
},
|
|
11
|
+
tolerance: 1e-7,
|
|
12
|
+
solutionColNames: ['A', 'B', 'C'],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const robertsonReferencePoint = new Float64Array([
|
|
16
|
+
0.2083340149701255E-7,
|
|
17
|
+
0.8333360770334713E-13,
|
|
18
|
+
0.9999999791665050,
|
|
19
|
+
]);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getIVP, getJScode } from '../../index';
|
|
2
|
+
/** Example. Solve the following initial value problem
|
|
3
|
+
dx / dt = x + y - cos(t)
|
|
4
|
+
dy / dt = x - y + sin(t)
|
|
5
|
+
x(0) = 1
|
|
6
|
+
y(0) = 0
|
|
7
|
+
|
|
8
|
+
on [0, 1] with the step 0.01.
|
|
9
|
+
*/
|
|
10
|
+
/** Diff Grok model specifying the given problem */
|
|
11
|
+
const model = `#name: Example
|
|
12
|
+
#equations:
|
|
13
|
+
dx/dt = x + y - cos(t)
|
|
14
|
+
dy/dt = x - y + sin(t)
|
|
15
|
+
|
|
16
|
+
#inits:
|
|
17
|
+
x = 1
|
|
18
|
+
y = 0
|
|
19
|
+
|
|
20
|
+
#argument: t
|
|
21
|
+
start = 0
|
|
22
|
+
finish = 1
|
|
23
|
+
step = 0.01`;
|
|
24
|
+
// Get parsed formulas
|
|
25
|
+
const ivp = getIVP(model);
|
|
26
|
+
console.log(ivp);
|
|
27
|
+
// Get lines of JS-code specifying ODEs object
|
|
28
|
+
const lines = getJScode(ivp);
|
|
29
|
+
console.log(lines);
|
|
30
|
+
//# sourceMappingURL=scripting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scripting.js","sourceRoot":"","sources":["scripting.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,SAAS,EAAC,MAAM,aAAa,CAAC;AAE9C;;;;;;;GAOG;AAEH,mDAAmD;AACnD,MAAM,KAAK,GAAG;;;;;;;;;;;;cAYA,CAAC;AAEf,sBAAsB;AACtB,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AAE1B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAEjB,8CAA8C;AAC9C,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;AAE7B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {getIVP, getJScode} from '../../index';
|
|
2
|
+
|
|
3
|
+
/** Example. Solve the following initial value problem
|
|
4
|
+
dx / dt = x + y - cos(t)
|
|
5
|
+
dy / dt = x - y + sin(t)
|
|
6
|
+
x(0) = 1
|
|
7
|
+
y(0) = 0
|
|
8
|
+
|
|
9
|
+
on [0, 1] with the step 0.01.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** Diff Grok model specifying the given problem */
|
|
13
|
+
const model = `#name: Example
|
|
14
|
+
#equations:
|
|
15
|
+
dx/dt = x + y - cos(t)
|
|
16
|
+
dy/dt = x - y + sin(t)
|
|
17
|
+
|
|
18
|
+
#inits:
|
|
19
|
+
x = 1
|
|
20
|
+
y = 0
|
|
21
|
+
|
|
22
|
+
#argument: t
|
|
23
|
+
start = 0
|
|
24
|
+
finish = 1
|
|
25
|
+
step = 0.01`;
|
|
26
|
+
|
|
27
|
+
// Get parsed formulas
|
|
28
|
+
const ivp = getIVP(model);
|
|
29
|
+
|
|
30
|
+
console.log(ivp);
|
|
31
|
+
|
|
32
|
+
// Get lines of JS-code specifying ODEs object
|
|
33
|
+
const lines = getJScode(ivp);
|
|
34
|
+
|
|
35
|
+
console.log(lines);
|