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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
|
|
1
3
|
import {IVP} from '../scripting-tools';
|
|
2
4
|
import {MATH_CONSTS, MATH_FUNCS, POW_IDX} from '../scripting-tools/scripting-tools';
|
|
3
5
|
import {getOutputCode} from './output';
|
|
@@ -6,8 +8,133 @@ import {PipelineCreator} from './pipeline-creator';
|
|
|
6
8
|
|
|
7
9
|
import {argName2IdxMap, ARG, ARG_COL_IDX, CORRECTION_FACTOR, DEFAULT_CORRECTION} from './constants';
|
|
8
10
|
|
|
9
|
-
/** Pipeline creator for model with updates
|
|
11
|
+
/** Pipeline creator for model with updates
|
|
12
|
+
* @example
|
|
13
|
+
* // This example shows how to apply pipelines and models with updates.
|
|
14
|
+
* // This approach can be used for in-webworkers analysis of models.
|
|
15
|
+
* // Here, we consider gluconic acid (GA) production by Aspergillus niger modeling.
|
|
16
|
+
*
|
|
17
|
+
* import * as DGL from 'diff-grok';
|
|
18
|
+
*
|
|
19
|
+
* // 1. Model specification
|
|
20
|
+
* const model = `#name: GA-production
|
|
21
|
+
* #tags: model
|
|
22
|
+
* #description: Gluconic acid (GA) production by Aspergillus niger modeling
|
|
23
|
+
*
|
|
24
|
+
* #equations:
|
|
25
|
+
* dX/dt = rX
|
|
26
|
+
* dS/dt = -gamma * rX - lambda * X
|
|
27
|
+
* dO/dt = Kla * (Cod - O) - delta * rX - phi * X
|
|
28
|
+
* dP/dt = alpha * rX + beta * X
|
|
29
|
+
*
|
|
30
|
+
* #expressions:
|
|
31
|
+
* mu = muM * S / (Ks + S) * O / (Ko + O)
|
|
32
|
+
* rX = mu * X
|
|
33
|
+
*
|
|
34
|
+
* #argument: t, 1-st stage
|
|
35
|
+
* _t0 = 0 {units: h; caption: initial; category: Misc} [Start of the process]
|
|
36
|
+
* _t1 = 60 {units: h; caption: 1-st stage; category: Durations; min: 20; max: 80} [Duration of the 1-st stage]
|
|
37
|
+
* step = 0.1 {units: h; caption: step; category: Misc; min: 0.01; max: 1} [Time step of simulation]
|
|
38
|
+
*
|
|
39
|
+
* #update: 2-nd stage
|
|
40
|
+
* duration = overall - _t1
|
|
41
|
+
* S += 70
|
|
42
|
+
*
|
|
43
|
+
* #inits:
|
|
44
|
+
* X = 5 {units: kg/m³; caption: biomass; category: Initial concentrations; min: 1; max: 10} [Aspergillus niger biomass]
|
|
45
|
+
* S = 150 {units: kg/m³; caption: glucose; category: Initial concentrations; min: 50; max: 200} [Glucose]
|
|
46
|
+
* O = 7 {units: kg/m³; caption: oxygen; category: Initial concentrations; min: 1; max: 10} [Dissolved oxygen]
|
|
47
|
+
* P = 0 {units: kg/m³; caption: acid; category: Initial concentrations; min: 0; max: 0.1} [Gluconic acid]
|
|
48
|
+
*
|
|
49
|
+
* #output:
|
|
50
|
+
* t {caption: time}
|
|
51
|
+
* X {caption: biomass}
|
|
52
|
+
* S {caption: glucose}
|
|
53
|
+
* O {caption: oxygen}
|
|
54
|
+
* P {caption: acid}
|
|
55
|
+
*
|
|
56
|
+
* #parameters:
|
|
57
|
+
* overall = 100 {units: h; category: Durations; min: 100; max: 140} [Overall duration]
|
|
58
|
+
* muM = 0.668 {units: 1/h; category: Parameters} [Monod type model parameter]
|
|
59
|
+
* alpha = 2.92 {category: Parameters} [Monod type model parameter]
|
|
60
|
+
* beta = 0.131 {units: 1/h; category: Parameters} [Monod type model parameter]
|
|
61
|
+
* gamma = 2.12 {category: Parameters} [Monod type model parameter]
|
|
62
|
+
* lambda = 0.232 {units: 1/h; category: Parameters} [Monod type model parameter]
|
|
63
|
+
* delta = 0.278 {category: Parameters} [Monod type model parameter]
|
|
64
|
+
* phi = 4.87e-3 {units: 1/h; category: Parameters} [Monod type model parameter]
|
|
65
|
+
* Ks = 1.309e2 {units: g/L; category: Parameters} [Monod type model parameter]
|
|
66
|
+
* Ko = 3.63e-4 {units: g/L; category: Parameters} [Monod type model parameter]
|
|
67
|
+
* Kla = 1.7e-2 {units: 1/s; category: Parameters} [Volumetric mass transfer coefficient]
|
|
68
|
+
* Cod = 15 {units: kg/m³; category: Parameters} [Liquid phase dissolved oxygen saturation concentration]
|
|
69
|
+
*
|
|
70
|
+
* #tolerance: 1e-9`;
|
|
71
|
+
*
|
|
72
|
+
* // 2. Generate IVP-objects: for the main thread & for computations in webworkers
|
|
73
|
+
* const ivp = DGL.getIVP(model);
|
|
74
|
+
* const ivpWW = DGL.getIvp2WebWorker(ivp);
|
|
75
|
+
*
|
|
76
|
+
* // 3. Perform computations
|
|
77
|
+
* try {
|
|
78
|
+
* // 3.1) Extract names of outputs
|
|
79
|
+
* const outputNames = DGL.getOutputNames(ivp);
|
|
80
|
+
* const outSize = outputNames.length;
|
|
81
|
+
*
|
|
82
|
+
* // 3.2) Set model inputs
|
|
83
|
+
* const inputs = {
|
|
84
|
+
* _t0: 0,
|
|
85
|
+
* _t1: 60,
|
|
86
|
+
* _h: 1,
|
|
87
|
+
* X: 5,
|
|
88
|
+
* S: 150,
|
|
89
|
+
* O: 7,
|
|
90
|
+
* P: 0,
|
|
91
|
+
* overall: 100,
|
|
92
|
+
* muM: 0.668,
|
|
93
|
+
* alpha: 2.92,
|
|
94
|
+
* beta: 0.131,
|
|
95
|
+
* gamma: 2.12,
|
|
96
|
+
* lambda: 0.232,
|
|
97
|
+
* delta: 0.278,
|
|
98
|
+
* phi: 4.87e-3,
|
|
99
|
+
* Ks: 1.309e2,
|
|
100
|
+
* Ko: 3.63e-4,
|
|
101
|
+
* Kla: 1.7e-2,
|
|
102
|
+
* Cod: 15,
|
|
103
|
+
* };
|
|
104
|
+
*
|
|
105
|
+
* const inputVector = DGL.getInputVector(inputs, ivp);
|
|
106
|
+
*
|
|
107
|
+
* // 3.3) Create a pipeline
|
|
108
|
+
* const creator = DGL.getPipelineCreator(ivp);
|
|
109
|
+
* const pipeline = creator.getPipeline(inputVector);
|
|
110
|
+
*
|
|
111
|
+
* // 3.4) Apply pipeline to perform computations
|
|
112
|
+
* const solution = DGL.applyPipeline(pipeline, ivpWW, inputVector);
|
|
113
|
+
*
|
|
114
|
+
* // 3.5) Print results
|
|
115
|
+
*
|
|
116
|
+
* // 3.5.1) Table header
|
|
117
|
+
* let line = ' ';
|
|
118
|
+
* outputNames.forEach((name) => line += name + ' ');
|
|
119
|
+
* console.log(line);
|
|
120
|
+
*
|
|
121
|
+
* // 3.5.2) Table with solution const length = solution[0].length;
|
|
122
|
+
* for (let i = 0; i < length; ++i) {
|
|
123
|
+
* line = '';
|
|
124
|
+
*
|
|
125
|
+
* for (let j = 0; j < outSize; ++j)
|
|
126
|
+
* line += solution[j][i].toFixed(8) + ' ';
|
|
127
|
+
*
|
|
128
|
+
* console.log(line);
|
|
129
|
+
* }
|
|
130
|
+
* } catch (err) {
|
|
131
|
+
* console.log('Simulation failed: ', err instanceof Error ? err.message : 'Unknown problem!');
|
|
132
|
+
* }
|
|
133
|
+
*/
|
|
10
134
|
export class UpdatesModelPipelineCreator extends PipelineCreator {
|
|
135
|
+
/**
|
|
136
|
+
* @param ivp - initial value problem to be solved
|
|
137
|
+
*/
|
|
11
138
|
constructor(ivp: IVP) {
|
|
12
139
|
super(ivp);
|
|
13
140
|
|
|
@@ -15,7 +142,9 @@ export class UpdatesModelPipelineCreator extends PipelineCreator {
|
|
|
15
142
|
throw new Error('Incorrect use of UpdatesModelPipelineCreator: model has no updates');
|
|
16
143
|
}
|
|
17
144
|
|
|
18
|
-
/** Return computations pipeline
|
|
145
|
+
/** Return computations pipeline corresponding to the given input vector
|
|
146
|
+
* @param inputs - input vector of the model
|
|
147
|
+
*/
|
|
19
148
|
public getPipeline(inputs: Float64Array): Pipeline {
|
|
20
149
|
if (this.ivp.updates === null)
|
|
21
150
|
throw new Error('Incorrect use of UpdatesModelPipelineCreator: model has no updates');
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
// Control constants
|
|
2
|
+
/** @internal */
|
|
2
3
|
export const CONTROL_TAG = '#';
|
|
4
|
+
/** @internal */
|
|
3
5
|
export const CONTROL_TAG_LEN = CONTROL_TAG.length;
|
|
6
|
+
/** @internal */
|
|
4
7
|
export const DF_NAME = 'df';
|
|
8
|
+
/** @internal */
|
|
5
9
|
export const MAX_LINE_CHART = 4;
|
|
6
|
-
/** Control expressions for the problem specifying
|
|
10
|
+
/** Control expressions for the problem specifying
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
7
13
|
export var CONTROL_EXPR;
|
|
8
14
|
(function (CONTROL_EXPR) {
|
|
9
15
|
CONTROL_EXPR["NAME"] = "#name";
|
|
@@ -26,7 +32,9 @@ export var CONTROL_EXPR;
|
|
|
26
32
|
CONTROL_EXPR["INPUTS"] = "#meta.inputs";
|
|
27
33
|
})(CONTROL_EXPR || (CONTROL_EXPR = {}));
|
|
28
34
|
;
|
|
29
|
-
/** Loop consts
|
|
35
|
+
/** Loop consts
|
|
36
|
+
* @internal
|
|
37
|
+
* */
|
|
30
38
|
export var LOOP;
|
|
31
39
|
(function (LOOP) {
|
|
32
40
|
LOOP[LOOP["MIN_LINES_COUNT"] = 1] = "MIN_LINES_COUNT";
|
|
@@ -35,7 +43,9 @@ export var LOOP;
|
|
|
35
43
|
LOOP[LOOP["MIN_COUNT"] = 1] = "MIN_COUNT";
|
|
36
44
|
})(LOOP || (LOOP = {}));
|
|
37
45
|
;
|
|
38
|
-
/** UPDATE consts
|
|
46
|
+
/** UPDATE consts
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
39
49
|
export var UPDATE;
|
|
40
50
|
(function (UPDATE) {
|
|
41
51
|
UPDATE[UPDATE["MIN_LINES_COUNT"] = 1] = "MIN_LINES_COUNT";
|
|
@@ -43,11 +53,15 @@ export var UPDATE;
|
|
|
43
53
|
UPDATE["DURATION"] = "_duration";
|
|
44
54
|
})(UPDATE || (UPDATE = {}));
|
|
45
55
|
;
|
|
46
|
-
/** Ranges of the solver options
|
|
56
|
+
/** Ranges of the solver options
|
|
57
|
+
* @internal
|
|
58
|
+
*/
|
|
47
59
|
export const SOLVER_OPTIONS_RANGES = new Map([
|
|
48
60
|
['maxTime', { min: 1, max: 10000 }],
|
|
49
61
|
['scale', { min: 0.5, max: 1 }],
|
|
50
62
|
]);
|
|
63
|
+
/** @internal */
|
|
51
64
|
export const TINY = 0.0001;
|
|
65
|
+
/** @internal */
|
|
52
66
|
export const STEP_RATIO = 0.5;
|
|
53
67
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["constants.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["constants.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,gBAAgB;AAChB,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC;AAE/B,gBAAgB;AAChB,MAAM,CAAC,MAAM,eAAe,GAAG,WAAW,CAAC,MAAM,CAAC;AAElD,gBAAgB;AAChB,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CAAC;AAE5B,gBAAgB;AAChB,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC;AAEhC;;EAEE;AACF,MAAM,CAAN,IAAY,YAmBX;AAnBD,WAAY,YAAY;IACpB,8BAAc,CAAA;IACd,8BAAc,CAAA;IACd,sCAAsB,CAAA;IACtB,qCAAqB,CAAA;IACrB,qCAAqB,CAAA;IACrB,iCAAiB,CAAA;IACjB,gCAAgB,CAAA;IAChB,qCAAqB,CAAA;IACrB,sCAAsB,CAAA;IACtB,kCAAkB,CAAA;IAClB,8BAAc,CAAA;IACd,kCAAkB,CAAA;IAClB,+CAA+B,CAAA;IAC/B,iDAAiC,CAAA;IACjC,kCAAkB,CAAA;IAClB,oCAAoB,CAAA;IACpB,uCAAuB,CAAA;IACvB,uCAAuB,CAAA;AAC3B,CAAC,EAnBW,YAAY,KAAZ,YAAY,QAmBvB;AAAA,CAAC;AAEF;;KAEK;AACL,MAAM,CAAN,IAAY,IAKX;AALD,WAAY,IAAI;IACd,qDAAmB,CAAA;IACnB,yCAAa,CAAA;IACb,6BAAqB,CAAA;IACrB,yCAAa,CAAA;AACf,CAAC,EALW,IAAI,KAAJ,IAAI,QAKf;AAAA,CAAC;AAEF;;GAEG;AACH,MAAM,CAAN,IAAY,MAIX;AAJD,WAAY,MAAM;IAChB,yDAAmB,CAAA;IACnB,mDAAgB,CAAA;IAChB,gCAAsB,CAAA;AACxB,CAAC,EAJW,MAAM,KAAN,MAAM,QAIjB;AAAA,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IAC3C,CAAC,SAAS,EAAE,EAAC,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,KAAK,EAAC,CAAC;IACjC,CAAC,OAAO,EAAE,EAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAC,CAAC;CAC9B,CAAC,CAAC;AAEH,gBAAgB;AAChB,MAAM,CAAC,MAAM,IAAI,GAAG,MAAM,CAAC;AAE3B,gBAAgB;AAChB,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAC"}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
// Control constants
|
|
2
|
+
/** @internal */
|
|
2
3
|
export const CONTROL_TAG = '#';
|
|
4
|
+
|
|
5
|
+
/** @internal */
|
|
3
6
|
export const CONTROL_TAG_LEN = CONTROL_TAG.length;
|
|
7
|
+
|
|
8
|
+
/** @internal */
|
|
4
9
|
export const DF_NAME = 'df';
|
|
10
|
+
|
|
11
|
+
/** @internal */
|
|
5
12
|
export const MAX_LINE_CHART = 4;
|
|
6
13
|
|
|
7
|
-
/** Control expressions for the problem specifying
|
|
14
|
+
/** Control expressions for the problem specifying
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
8
17
|
export enum CONTROL_EXPR {
|
|
9
18
|
NAME = '#name',
|
|
10
19
|
TAGS = '#tags',
|
|
@@ -26,7 +35,9 @@ export enum CONTROL_EXPR {
|
|
|
26
35
|
INPUTS = '#meta.inputs',
|
|
27
36
|
};
|
|
28
37
|
|
|
29
|
-
/** Loop consts
|
|
38
|
+
/** Loop consts
|
|
39
|
+
* @internal
|
|
40
|
+
* */
|
|
30
41
|
export enum LOOP {
|
|
31
42
|
MIN_LINES_COUNT = 1,
|
|
32
43
|
COUNT_IDX = 0,
|
|
@@ -34,18 +45,25 @@ export enum LOOP {
|
|
|
34
45
|
MIN_COUNT = 1,
|
|
35
46
|
};
|
|
36
47
|
|
|
37
|
-
/** UPDATE consts
|
|
48
|
+
/** UPDATE consts
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
38
51
|
export enum UPDATE {
|
|
39
52
|
MIN_LINES_COUNT = 1,
|
|
40
53
|
DURATION_IDX = 0,
|
|
41
54
|
DURATION = '_duration',
|
|
42
55
|
};
|
|
43
56
|
|
|
44
|
-
/** Ranges of the solver options
|
|
57
|
+
/** Ranges of the solver options
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
45
60
|
export const SOLVER_OPTIONS_RANGES = new Map([
|
|
46
61
|
['maxTime', {min: 1, max: 10000}],
|
|
47
62
|
['scale', {min: 0.5, max: 1}],
|
|
48
63
|
]);
|
|
49
64
|
|
|
65
|
+
/** @internal */
|
|
50
66
|
export const TINY = 0.0001;
|
|
67
|
+
|
|
68
|
+
/** @internal */
|
|
51
69
|
export const STEP_RATIO = 0.5;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAC,MAAM,aAAa,CAAC;AAElE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAC,MAAM,aAAa,CAAC;AAElE,OAAO,EAAS,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAc,SAAS,EACvF,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAC9E,cAAc,EAAE,cAAc,EAAE,uBAAuB,EAAE,cAAc,EAC3D,MAAM,mBAAmB,CAAC;AAExC,OAAO,EAAC,UAAU,EAAC,MAAM,eAAe,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export {DF_NAME, CONTROL_EXPR, MAX_LINE_CHART} from './constants';
|
|
2
2
|
|
|
3
|
-
export {getIVP, getScriptLines, getScriptParams, getJScode, IVP, Input, SCRIPTING,
|
|
3
|
+
export {DifEqs, getIVP, getScriptLines, getScriptParams, getJScode, IVP, Input, SCRIPTING,
|
|
4
4
|
BRACE_OPEN, BRACE_CLOSE, BRACKET_OPEN, BRACKET_CLOSE, ANNOT_SEPAR, CONTROL_SEP,
|
|
5
|
-
STAGE_COL_NAME, ARG_INPUT_KEYS, DEFAULT_SOLVER_SETTINGS, getFunc4worker
|
|
5
|
+
STAGE_COL_NAME, ARG_INPUT_KEYS, DEFAULT_SOLVER_SETTINGS, getFunc4worker, Loop, Update,
|
|
6
|
+
Output, Arg} from './scripting-tools';
|
|
6
7
|
|
|
7
8
|
export {ModelError} from './model-error';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"model-error.js","sourceRoot":"","sources":["model-error.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"model-error.js","sourceRoot":"","sources":["model-error.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,KAAK;IAInC,YAAY,OAAe,EAAE,OAAe,EAAE,WAAoB;QAChE,KAAK,CAAC,OAAO,CAAC,CAAC;QAHT,gBAAW,GAAuB,SAAS,CAAC;QAIlD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAEM,UAAU;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEM,cAAc;QACnB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF;AAAA,CAAC,CAAC,aAAa"}
|
|
@@ -10,32 +10,48 @@
|
|
|
10
10
|
import { CONTROL_TAG, CONTROL_TAG_LEN, CONTROL_EXPR, LOOP, UPDATE, MAX_LINE_CHART, SOLVER_OPTIONS_RANGES, TINY, STEP_RATIO } from './constants';
|
|
11
11
|
import { ModelError } from './model-error';
|
|
12
12
|
// Scripting specific constants
|
|
13
|
+
/** @internal */
|
|
13
14
|
export const CONTROL_SEP = ':';
|
|
14
15
|
const COMMA = ',';
|
|
15
16
|
const EQUAL_SIGN = '=';
|
|
16
17
|
const DIV_SIGN = '/';
|
|
17
18
|
const SERVICE = '_';
|
|
19
|
+
/** @internal */
|
|
18
20
|
export const BRACE_OPEN = '{';
|
|
21
|
+
/** @internal */
|
|
19
22
|
export const BRACE_CLOSE = '}';
|
|
23
|
+
/** @internal */
|
|
20
24
|
export const BRACKET_OPEN = '[';
|
|
25
|
+
/** @internal */
|
|
21
26
|
export const BRACKET_CLOSE = ']';
|
|
27
|
+
/** @internal */
|
|
22
28
|
export const ANNOT_SEPAR = ';';
|
|
23
29
|
const DEFAULT_TOL = '0.00005';
|
|
30
|
+
/** @internal */
|
|
24
31
|
export const DEFAULT_SOLVER_SETTINGS = '{}';
|
|
25
32
|
const COMMENT_SEQ = '//';
|
|
33
|
+
/** @internal */
|
|
26
34
|
export const STAGE_COL_NAME = `_Stage`;
|
|
27
35
|
const INCEPTION = 'Inception';
|
|
28
|
-
/** Elementary math tools
|
|
36
|
+
/** Elementary math tools
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
29
39
|
export const MATH_FUNCS = ['pow', 'sin', 'cos', 'tan', 'asin', 'acos', 'atan', 'sqrt', 'exp', 'log', 'sinh', 'cosh', 'tanh'];
|
|
40
|
+
/** @internal */
|
|
30
41
|
export const POW_IDX = MATH_FUNCS.indexOf('pow');
|
|
42
|
+
/** @internal */
|
|
31
43
|
export const MATH_CONSTS = ['PI', 'E'];
|
|
32
44
|
/** Default meta */
|
|
33
45
|
const defaultMetas = `//meta.runOnOpen: true
|
|
34
46
|
//meta.runOnInput: true
|
|
35
47
|
//meta.features: {"sens-analysis": true, "fitting": true}`;
|
|
36
|
-
/** Input keys of Arg
|
|
48
|
+
/** Input keys of Arg
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
37
51
|
export const ARG_INPUT_KEYS = ['initial', 'final', 'step'];
|
|
38
|
-
/** Scripting specific constants
|
|
52
|
+
/** Scripting specific constants
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
39
55
|
export var SCRIPTING;
|
|
40
56
|
(function (SCRIPTING) {
|
|
41
57
|
SCRIPTING["ARG_NAME"] = "name";
|
|
@@ -379,7 +395,100 @@ function getOutput(lines, begin, end) {
|
|
|
379
395
|
} // for i
|
|
380
396
|
return res;
|
|
381
397
|
} // getOutput
|
|
382
|
-
/**
|
|
398
|
+
/** Return initial value problem specification given in the text
|
|
399
|
+
* @param text - declarative specification of initial value problem
|
|
400
|
+
* @example
|
|
401
|
+
* // Here, we consider modeling queues: https://en.wikipedia.org/wiki/M/M/c_queue
|
|
402
|
+
* import * as DGL from 'diff-grok';
|
|
403
|
+
*
|
|
404
|
+
* // 1. Model specification: the M|M|2|2 model
|
|
405
|
+
* const model = `#name: M|M|2|2
|
|
406
|
+
* #description: Modelling the system with two servers & two waiting places (EXPLAINED)
|
|
407
|
+
*
|
|
408
|
+
* #equations:
|
|
409
|
+
* dp0/dt = -la * p0 + mu * p1
|
|
410
|
+
* dp1/dt = la * p0 - (la + mu) * p1 + 2 * mu * p2
|
|
411
|
+
* dp2/dt = la * p1 - (la + 2 * mu) * p2 + 2 * mu * p3
|
|
412
|
+
* dp3/dt = la * p2 - (la + 2 * mu) * p3 + 2 * mu * p4
|
|
413
|
+
*
|
|
414
|
+
* #expressions:
|
|
415
|
+
* la = 1 / arrival
|
|
416
|
+
* mu = 1 / service
|
|
417
|
+
* p4 = 1 - p0 - p1 - p2 - p3
|
|
418
|
+
* busy = 1 - p0 - p1
|
|
419
|
+
* queue = p3 + 2 * p4
|
|
420
|
+
*
|
|
421
|
+
* #argument: t
|
|
422
|
+
* _t0 = 0 {min: 0; max: 10; caption: start; category: Time; units: min} [Initial time of simulation]
|
|
423
|
+
* _t1 = 60 {min: 20; max: 100; caption: finish; category: Time; units: min} [Final time of simulation]
|
|
424
|
+
* _h = 1 {min: 0.01; max: 0.1; caption: step; category: Time; units: min} [Time step of simulation]
|
|
425
|
+
*
|
|
426
|
+
* #inits:
|
|
427
|
+
* p0 = 1 {min: 0; max: 1; category: Initial state; caption: empty} [Probability that initially there are NO customers]
|
|
428
|
+
* p1 = 0 {min: 0; max: 1; category: Initial state; caption: single} [Probability that initially there is ONE customer]
|
|
429
|
+
* p2 = 0 {min: 0; max: 1; category: Initial state; caption: two} [Probability that initially there are TWO customers]
|
|
430
|
+
* p3 = 0 {min: 0; max: 1; category: Initial state; caption: three} [Probability that initially there are THREE customers]
|
|
431
|
+
*
|
|
432
|
+
* #output:
|
|
433
|
+
* t {caption: Time, min}
|
|
434
|
+
* p0 {caption: P(Empty)}
|
|
435
|
+
* busy {caption: P(Full load)}
|
|
436
|
+
* queue {caption: E(Queue)}
|
|
437
|
+
*
|
|
438
|
+
* #parameters:
|
|
439
|
+
* arrival = 10 {min: 1; max: 100; category: Means; caption: arrival; units: min} [Mean arrival time]
|
|
440
|
+
* service = 100 {min: 1; max: 100; category: Means; caption: service; units: min} [Mean service time]`;
|
|
441
|
+
*
|
|
442
|
+
* // 2. Generate IVP-objects: for the main thread & for computations in webworkers
|
|
443
|
+
* const ivp = DGL.getIVP(model);
|
|
444
|
+
* const ivpWW = DGL.getIvp2WebWorker(ivp);
|
|
445
|
+
*
|
|
446
|
+
* // 3. Perform computations
|
|
447
|
+
* try {
|
|
448
|
+
* // 3.1) Extract names of outputs
|
|
449
|
+
* const outputNames = DGL.getOutputNames(ivp);
|
|
450
|
+
* const outSize = outputNames.length;
|
|
451
|
+
*
|
|
452
|
+
* // 3.2) Set model inputs
|
|
453
|
+
* const inputs = {
|
|
454
|
+
* _t0: 0, // Initial time of simulation
|
|
455
|
+
* _t1: 60, // Final time of simulation
|
|
456
|
+
* _h: 1, // Time step of simulation
|
|
457
|
+
* p0: 1, // Probability that initially there are NO customers
|
|
458
|
+
* p1: 0, // Probability that initially there is ONE customer
|
|
459
|
+
* p2: 0, // Probability that initially there are TWO customers
|
|
460
|
+
* p3: 0, // Probability that initially there are THREE customers
|
|
461
|
+
* arrival: 10, // Mean arrival time
|
|
462
|
+
* service: 100, // Mean service time
|
|
463
|
+
* };
|
|
464
|
+
* const inputVector = DGL.getInputVector(inputs, ivp);
|
|
465
|
+
*
|
|
466
|
+
* // 3.3) Create a pipeline
|
|
467
|
+
* const creator = DGL.getPipelineCreator(ivp);
|
|
468
|
+
* const pipeline = creator.getPipeline(inputVector);
|
|
469
|
+
*
|
|
470
|
+
* // 3.4) Apply pipeline to perform computations
|
|
471
|
+
* const solution = DGL.applyPipeline(pipeline, ivpWW, inputVector);
|
|
472
|
+
* // 3.5) Print results
|
|
473
|
+
*
|
|
474
|
+
* // 3.5.1) Table header
|
|
475
|
+
* let line = '';
|
|
476
|
+
* outputNames.forEach((name) => line += name + ' ');
|
|
477
|
+
* console.log(line);
|
|
478
|
+
*
|
|
479
|
+
* // 3.5.2) Table with solution
|
|
480
|
+
* const length = solution[0].length;
|
|
481
|
+
* for (let i = 0; i < length; ++i) {
|
|
482
|
+
* line = '';
|
|
483
|
+
*
|
|
484
|
+
* for (let j = 0; j < outSize; ++j)
|
|
485
|
+
* line += solution[j][i].toFixed(8) + ' ';
|
|
486
|
+
* console.log(line);
|
|
487
|
+
* }
|
|
488
|
+
* } catch (err) {
|
|
489
|
+
* console.log('Simulation failed: ', err instanceof Error ? err.message : 'Unknown problem!');
|
|
490
|
+
* }
|
|
491
|
+
*/
|
|
383
492
|
export function getIVP(text) {
|
|
384
493
|
// The current Initial Value Problem (IVP) specification
|
|
385
494
|
let name;
|
|
@@ -549,7 +658,9 @@ function getAnnot(ivp, toAddViewers = true, toAddEditor = false) {
|
|
|
549
658
|
res.push(defaultMetas);
|
|
550
659
|
return res;
|
|
551
660
|
} // getAnnot
|
|
552
|
-
/** Returns math functions arguments string
|
|
661
|
+
/** Returns math functions arguments string
|
|
662
|
+
* @internal
|
|
663
|
+
*/
|
|
553
664
|
function getMathArg(funcIdx) {
|
|
554
665
|
return (funcIdx > POW_IDX) ? '(x)' : '(x, y)';
|
|
555
666
|
}
|
|
@@ -835,14 +946,18 @@ function getScriptMainBody(ivp) {
|
|
|
835
946
|
return getScriptMainBodyUpdateCase(ivp);
|
|
836
947
|
return getScriptMainBodyBasic(ivp);
|
|
837
948
|
}
|
|
838
|
-
/** Return JS-script lines
|
|
949
|
+
/** Return JS-script lines
|
|
950
|
+
* @internal
|
|
951
|
+
*/
|
|
839
952
|
export function getScriptLines(ivp, toAddViewers = true, toAddEditor = false) {
|
|
840
953
|
const res = getAnnot(ivp, toAddViewers, toAddEditor).concat(getScriptMainBody(ivp));
|
|
841
954
|
if (ivp.outputs)
|
|
842
955
|
return res.concat(getCustomOutputLines(ivp));
|
|
843
956
|
return res;
|
|
844
957
|
}
|
|
845
|
-
/** Return parameters of JS-script
|
|
958
|
+
/** Return parameters of JS-script
|
|
959
|
+
* @internal
|
|
960
|
+
*/
|
|
846
961
|
export function getScriptParams(ivp) {
|
|
847
962
|
const res = {};
|
|
848
963
|
if (ivp.loop)
|
|
@@ -975,7 +1090,22 @@ function checkCorrectness(ivp) {
|
|
|
975
1090
|
// 5. Check solver settings
|
|
976
1091
|
checkSolverSettings(ivp.solverSettings);
|
|
977
1092
|
} // checkCorrectness
|
|
978
|
-
/**
|
|
1093
|
+
/** Return JavaScript code that solves the given initial value problem
|
|
1094
|
+
* @param ivp - initial value problem to be solved
|
|
1095
|
+
* @example
|
|
1096
|
+
* import {getIVP, getJScode} from 'diff-grok';
|
|
1097
|
+
*
|
|
1098
|
+
* const model = `
|
|
1099
|
+
* #name: Example
|
|
1100
|
+
* #equations:
|
|
1101
|
+
* dx/dt = x + y - cos(t)
|
|
1102
|
+
* dy/dt = x - y + sin(t)
|
|
1103
|
+
* ...
|
|
1104
|
+
* `;
|
|
1105
|
+
*
|
|
1106
|
+
* const ivp = getIVP(model);
|
|
1107
|
+
* const lines = getJScode(ivp);
|
|
1108
|
+
*/
|
|
979
1109
|
export function getJScode(ivp) {
|
|
980
1110
|
const res = [];
|
|
981
1111
|
// 1. Math functions
|
|
@@ -1027,6 +1157,6 @@ export function getJScode(ivp) {
|
|
|
1027
1157
|
res.push('};');
|
|
1028
1158
|
return res;
|
|
1029
1159
|
} // getJScode
|
|
1030
|
-
/** */
|
|
1160
|
+
/** @internal */
|
|
1031
1161
|
export function getFunc4worker(ivp) { }
|
|
1032
1162
|
//# sourceMappingURL=scripting-tools.js.map
|