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,102 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
/** This example shows how to apply pipelines and cyclic models.
|
|
3
|
+
This approach can be used for in-webworkers analysis of models.
|
|
4
|
+
|
|
5
|
+
Here, we consider pharmacokinetic-pharmacodynamic (PK-PD) simulation: two-compartment model.
|
|
6
|
+
*/
|
|
7
|
+
import * as DGL from '../../index';
|
|
8
|
+
/** 1. Model specification */
|
|
9
|
+
const model = `#name: PK-PD
|
|
10
|
+
#tags: model
|
|
11
|
+
#description: Pharmacokinetic-pharmacodynamic (PK-PD) simulation: two-compartment model
|
|
12
|
+
#equations:
|
|
13
|
+
d(depot)/dt = -KA * depot
|
|
14
|
+
d(centr)/dt = KA * depot - CL * C2 - Q * C2 + Q * C3
|
|
15
|
+
d(peri)/dt = Q * C2 - Q * C3
|
|
16
|
+
d(eff)/dt = Kin - Kout * (1 - C2/(EC50 + C2)) * eff
|
|
17
|
+
|
|
18
|
+
#expressions:
|
|
19
|
+
C2 = centr / V2
|
|
20
|
+
C3 = peri / V3
|
|
21
|
+
|
|
22
|
+
#loop:
|
|
23
|
+
_count = 10 {caption: count; category: Dosing; min: 1; max: 20} [Number of doses]
|
|
24
|
+
depot += dose
|
|
25
|
+
|
|
26
|
+
#argument: t
|
|
27
|
+
_t0 = 0 {units: h; caption: begin; category: Dosing; min: 0; max: 1} [Begin of dosing interval]
|
|
28
|
+
_t1 = 12 {units: h; caption: end; category: Dosing; min: 5; max: 15} [End of dosing interval]
|
|
29
|
+
_h = 1 {units: h; caption: step; category: Dosing; min: 0.01; max: 0.1} [Time step of simulation]
|
|
30
|
+
|
|
31
|
+
#inits:
|
|
32
|
+
depot = 0 {category: Initial values}
|
|
33
|
+
centr = 0 {category: Initial values} [Central]
|
|
34
|
+
peri = 0 {category: Initial values} [Peripheral]
|
|
35
|
+
eff = 0.2 {category: Initial values} [Effective compartment rate]
|
|
36
|
+
|
|
37
|
+
#parameters:
|
|
38
|
+
dose = 1e4 {category: Dosing; min: 1e3; max: 2e4; step: 1e3} [Dosage]
|
|
39
|
+
KA = 0.3 {caption: rate constant; category: Parameters; min: 0.1; max: 1}
|
|
40
|
+
CL = 2 {caption: clearance; category: Parameters; min: 1; max: 5}
|
|
41
|
+
V2 = 4 {caption: central volume; category: Parameters; min: 1; max: 10} [Central compartment volume]
|
|
42
|
+
Q = 1 {caption: inter rate; category: Parameters; min: 0.1; max: 1} [Intercompartmental rate]
|
|
43
|
+
V3 = 30 {caption: peri volume; category: Parameters; min: 20; max: 40} [Peripheral compartment volume]
|
|
44
|
+
EC50 = 8 {caption: effect; category: Parameters; min: 1; max: 10}
|
|
45
|
+
Kin = 0.2 {caption: Kin; category: Parameters; min: 0.1; max: 0.5} [The first-order production constant]
|
|
46
|
+
Kout = 0.2 {caption: Kout; category: Parameters; min: 0.1; max: 0.5} [The first-order dissipation rate constant]
|
|
47
|
+
|
|
48
|
+
#tolerance: 1e-9
|
|
49
|
+
|
|
50
|
+
#meta.solver: {method: 'rkdp'; maxTimeMs: 5000}`;
|
|
51
|
+
/** 2. Generate IVP-objects: for the main thread & for computations in webworkers */
|
|
52
|
+
const ivp = DGL.getIVP(model);
|
|
53
|
+
const ivpWW = DGL.getIvp2WebWorker(ivp);
|
|
54
|
+
/** 3. Perform computations */
|
|
55
|
+
try {
|
|
56
|
+
// 3.1) Extract names of outputs
|
|
57
|
+
const outputNames = DGL.getOutputNames(ivp);
|
|
58
|
+
const outSize = outputNames.length;
|
|
59
|
+
// 3.2) Set model inputs
|
|
60
|
+
const inputs = {
|
|
61
|
+
_count: 10,
|
|
62
|
+
_t0: 0,
|
|
63
|
+
_t1: 16,
|
|
64
|
+
_h: 1,
|
|
65
|
+
depot: 0,
|
|
66
|
+
centr: 0,
|
|
67
|
+
peri: 0,
|
|
68
|
+
eff: 0.2,
|
|
69
|
+
dose: 10000,
|
|
70
|
+
KA: 0.63,
|
|
71
|
+
CL: 3.2,
|
|
72
|
+
V2: 6.58,
|
|
73
|
+
Q: 0.622,
|
|
74
|
+
V3: 35.6,
|
|
75
|
+
EC50: 5.41,
|
|
76
|
+
Kin: 0.272,
|
|
77
|
+
Kout: 0.276,
|
|
78
|
+
};
|
|
79
|
+
const inputVector = DGL.getInputVector(inputs, ivp);
|
|
80
|
+
// 3.3) Create a pipeline
|
|
81
|
+
const creator = DGL.getPipelineCreator(ivp);
|
|
82
|
+
const pipeline = creator.getPipeline(inputVector);
|
|
83
|
+
// 3.4) Apply pipeline to perform computations
|
|
84
|
+
const solution = DGL.applyPipeline(pipeline, ivpWW, inputVector);
|
|
85
|
+
// 3.5) Print results
|
|
86
|
+
// 3.5.1) Table header
|
|
87
|
+
let line = ' ';
|
|
88
|
+
outputNames.forEach((name) => line += name + ' ');
|
|
89
|
+
console.log(line);
|
|
90
|
+
// 3.5.2) Table with solution
|
|
91
|
+
const length = solution[0].length;
|
|
92
|
+
for (let i = 0; i < length; ++i) {
|
|
93
|
+
line = '';
|
|
94
|
+
for (let j = 0; j < outSize; ++j)
|
|
95
|
+
line += solution[j][i].toFixed(8) + ' ';
|
|
96
|
+
console.log(line);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
console.log('Simulation failed: ', err instanceof Error ? err.message : 'Unknown problem!');
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=cyclic-model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cyclic-model.js","sourceRoot":"","sources":["cyclic-model.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B;;;;EAIE;AAEF,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAEnC,6BAA6B;AAC7B,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gDAyCkC,CAAC;AAEjD,oFAAoF;AACpF,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9B,MAAM,KAAK,GAAG,GAAG,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;AAExC,8BAA8B;AAC9B,IAAI,CAAC;IACH,gCAAgC;IAChC,MAAM,WAAW,GAAG,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC;IAEnC,wBAAwB;IACxB,MAAM,MAAM,GAAG;QACb,MAAM,EAAE,EAAE;QACV,GAAG,EAAE,CAAC;QACN,GAAG,EAAE,EAAE;QACP,EAAE,EAAE,CAAC;QACL,KAAK,EAAE,CAAC;QACR,KAAK,EAAE,CAAC;QACR,IAAI,EAAE,CAAC;QACP,GAAG,EAAE,GAAG;QACR,IAAI,EAAE,KAAK;QACX,EAAE,EAAE,IAAI;QACR,EAAE,EAAE,GAAG;QACP,EAAE,EAAE,IAAI;QACR,CAAC,EAAE,KAAK;QACR,EAAE,EAAE,IAAI;QACR,IAAI,EAAE,IAAI;QACV,GAAG,EAAE,KAAK;QACV,IAAI,EAAE,KAAK;KACZ,CAAC;IACF,MAAM,WAAW,GAAG,GAA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|
2
|
+
/** This example shows how to apply pipelines and cyclic models.
|
|
3
|
+
This approach can be used for in-webworkers analysis of models.
|
|
4
|
+
|
|
5
|
+
Here, we consider pharmacokinetic-pharmacodynamic (PK-PD) simulation: two-compartment model.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as DGL from '../../index';
|
|
9
|
+
|
|
10
|
+
/** 1. Model specification */
|
|
11
|
+
const model = `#name: PK-PD
|
|
12
|
+
#tags: model
|
|
13
|
+
#description: Pharmacokinetic-pharmacodynamic (PK-PD) simulation: two-compartment model
|
|
14
|
+
#equations:
|
|
15
|
+
d(depot)/dt = -KA * depot
|
|
16
|
+
d(centr)/dt = KA * depot - CL * C2 - Q * C2 + Q * C3
|
|
17
|
+
d(peri)/dt = Q * C2 - Q * C3
|
|
18
|
+
d(eff)/dt = Kin - Kout * (1 - C2/(EC50 + C2)) * eff
|
|
19
|
+
|
|
20
|
+
#expressions:
|
|
21
|
+
C2 = centr / V2
|
|
22
|
+
C3 = peri / V3
|
|
23
|
+
|
|
24
|
+
#loop:
|
|
25
|
+
_count = 10 {caption: count; category: Dosing; min: 1; max: 20} [Number of doses]
|
|
26
|
+
depot += dose
|
|
27
|
+
|
|
28
|
+
#argument: t
|
|
29
|
+
_t0 = 0 {units: h; caption: begin; category: Dosing; min: 0; max: 1} [Begin of dosing interval]
|
|
30
|
+
_t1 = 12 {units: h; caption: end; category: Dosing; min: 5; max: 15} [End of dosing interval]
|
|
31
|
+
_h = 1 {units: h; caption: step; category: Dosing; min: 0.01; max: 0.1} [Time step of simulation]
|
|
32
|
+
|
|
33
|
+
#inits:
|
|
34
|
+
depot = 0 {category: Initial values}
|
|
35
|
+
centr = 0 {category: Initial values} [Central]
|
|
36
|
+
peri = 0 {category: Initial values} [Peripheral]
|
|
37
|
+
eff = 0.2 {category: Initial values} [Effective compartment rate]
|
|
38
|
+
|
|
39
|
+
#parameters:
|
|
40
|
+
dose = 1e4 {category: Dosing; min: 1e3; max: 2e4; step: 1e3} [Dosage]
|
|
41
|
+
KA = 0.3 {caption: rate constant; category: Parameters; min: 0.1; max: 1}
|
|
42
|
+
CL = 2 {caption: clearance; category: Parameters; min: 1; max: 5}
|
|
43
|
+
V2 = 4 {caption: central volume; category: Parameters; min: 1; max: 10} [Central compartment volume]
|
|
44
|
+
Q = 1 {caption: inter rate; category: Parameters; min: 0.1; max: 1} [Intercompartmental rate]
|
|
45
|
+
V3 = 30 {caption: peri volume; category: Parameters; min: 20; max: 40} [Peripheral compartment volume]
|
|
46
|
+
EC50 = 8 {caption: effect; category: Parameters; min: 1; max: 10}
|
|
47
|
+
Kin = 0.2 {caption: Kin; category: Parameters; min: 0.1; max: 0.5} [The first-order production constant]
|
|
48
|
+
Kout = 0.2 {caption: Kout; category: Parameters; min: 0.1; max: 0.5} [The first-order dissipation rate constant]
|
|
49
|
+
|
|
50
|
+
#tolerance: 1e-9
|
|
51
|
+
|
|
52
|
+
#meta.solver: {method: 'rkdp'; maxTimeMs: 5000}`;
|
|
53
|
+
|
|
54
|
+
/** 2. Generate IVP-objects: for the main thread & for computations in webworkers */
|
|
55
|
+
const ivp = DGL.getIVP(model);
|
|
56
|
+
const ivpWW = DGL.getIvp2WebWorker(ivp);
|
|
57
|
+
|
|
58
|
+
/** 3. Perform computations */
|
|
59
|
+
try {
|
|
60
|
+
// 3.1) Extract names of outputs
|
|
61
|
+
const outputNames = DGL.getOutputNames(ivp);
|
|
62
|
+
const outSize = outputNames.length;
|
|
63
|
+
|
|
64
|
+
// 3.2) Set model inputs
|
|
65
|
+
const inputs = {
|
|
66
|
+
_count: 10,
|
|
67
|
+
_t0: 0,
|
|
68
|
+
_t1: 16,
|
|
69
|
+
_h: 1,
|
|
70
|
+
depot: 0,
|
|
71
|
+
centr: 0,
|
|
72
|
+
peri: 0,
|
|
73
|
+
eff: 0.2,
|
|
74
|
+
dose: 10000,
|
|
75
|
+
KA: 0.63,
|
|
76
|
+
CL: 3.2,
|
|
77
|
+
V2: 6.58,
|
|
78
|
+
Q: 0.622,
|
|
79
|
+
V3: 35.6,
|
|
80
|
+
EC50: 5.41,
|
|
81
|
+
Kin: 0.272,
|
|
82
|
+
Kout: 0.276,
|
|
83
|
+
};
|
|
84
|
+
const inputVector = DGL.getInputVector(inputs, ivp);
|
|
85
|
+
|
|
86
|
+
// 3.3) Create a pipeline
|
|
87
|
+
const creator = DGL.getPipelineCreator(ivp);
|
|
88
|
+
const pipeline = creator.getPipeline(inputVector);
|
|
89
|
+
|
|
90
|
+
// 3.4) Apply pipeline to perform computations
|
|
91
|
+
const solution = DGL.applyPipeline(pipeline, ivpWW, inputVector);
|
|
92
|
+
|
|
93
|
+
// 3.5) Print results
|
|
94
|
+
|
|
95
|
+
// 3.5.1) Table header
|
|
96
|
+
let line = ' ';
|
|
97
|
+
outputNames.forEach((name) => line += name + ' ');
|
|
98
|
+
console.log(line);
|
|
99
|
+
|
|
100
|
+
// 3.5.2) Table with solution
|
|
101
|
+
const length = solution[0].length;
|
|
102
|
+
for (let i = 0; i < length; ++i) {
|
|
103
|
+
line = '';
|
|
104
|
+
|
|
105
|
+
for (let j = 0; j < outSize; ++j)
|
|
106
|
+
line += solution[j][i].toFixed(8) + ' ';
|
|
107
|
+
|
|
108
|
+
console.log(line);
|
|
109
|
+
}
|
|
110
|
+
} catch (err) {
|
|
111
|
+
console.log('Simulation failed: ', err instanceof Error ? err.message : 'Unknown problem!');
|
|
112
|
+
}
|
package/docs/media/e5.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Kintetic constants for the E5 model */
|
|
2
|
+
var E5;
|
|
3
|
+
(function (E5) {
|
|
4
|
+
E5[E5["K1"] = 7.89e-10] = "K1";
|
|
5
|
+
E5[E5["K2"] = 1130000000] = "K2";
|
|
6
|
+
E5[E5["K3"] = 11000000] = "K3";
|
|
7
|
+
E5[E5["K4"] = 1130] = "K4";
|
|
8
|
+
})(E5 || (E5 = {}));
|
|
9
|
+
;
|
|
10
|
+
/** The E5 model (chemical pyrolysis: https://archimede.uniba.it/~testset/report/e5.pdf) */
|
|
11
|
+
export const e5 = {
|
|
12
|
+
name: 'E5',
|
|
13
|
+
arg: { name: 't', start: 0, finish: 1e13, step: 2.5e8 },
|
|
14
|
+
initial: [0.00176, 0, 0, 0],
|
|
15
|
+
func: (t, y, output) => {
|
|
16
|
+
// extract function values
|
|
17
|
+
const y1 = y[0];
|
|
18
|
+
const y2 = y[1];
|
|
19
|
+
const y3 = y[2];
|
|
20
|
+
const y4 = y[3];
|
|
21
|
+
// compute output
|
|
22
|
+
output[0] = -E5.K1 * y1 - E5.K3 * y1 * y3;
|
|
23
|
+
output[1] = E5.K1 * y1 - E5.K2 * y2 * y3;
|
|
24
|
+
output[2] = E5.K1 * y1 - E5.K2 * y2 * y3 - E5.K3 * y1 * y3 + E5.K4 * y4;
|
|
25
|
+
output[3] = E5.K3 * y1 * y3 - E5.K4 * y4;
|
|
26
|
+
},
|
|
27
|
+
tolerance: 1e-6,
|
|
28
|
+
solutionColNames: ['y1', 'y2', 'y3', 'y4'],
|
|
29
|
+
};
|
|
30
|
+
export const e5ReferencePoint = new Float64Array([
|
|
31
|
+
0.1152903278711829E-290,
|
|
32
|
+
0.8867655517642120E-22,
|
|
33
|
+
0.8854814626268838E-22,
|
|
34
|
+
0,
|
|
35
|
+
]);
|
|
36
|
+
//# sourceMappingURL=e5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"e5.js","sourceRoot":"","sources":["e5.ts"],"names":[],"mappings":"AAAC,0CAA0C;AAC1C,IAAK,EAKH;AALF,WAAK,EAAE;IACJ,8BAAa,CAAA;IACb,gCAAW,CAAA;IACX,8BAAU,CAAA;IACV,0BAAW,CAAA;AACb,CAAC,EALG,EAAE,KAAF,EAAE,QAKL;AAAA,CAAC;AAEJ,2FAA2F;AAC3F,MAAM,CAAC,MAAM,EAAE,GAAG;IAChB,IAAI,EAAE,IAAI;IACV,GAAG,EAAE,EAAC,IAAI,EAAE,GAAG,EAAE,KAAK,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AsB;IACtB,sBAAsB;IACtB,CAAC;CACF,CAAC,CAAC"}
|
package/docs/media/e5.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Kintetic constants for the E5 model */
|
|
2
|
+
enum E5 {
|
|
3
|
+
K1 = 7.89e-10,
|
|
4
|
+
K2 = 1.13e9,
|
|
5
|
+
K3 = 1.1e7,
|
|
6
|
+
K4 = 1.13e3,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/** The E5 model (chemical pyrolysis: https://archimede.uniba.it/~testset/report/e5.pdf) */
|
|
10
|
+
export const e5 = {
|
|
11
|
+
name: 'E5',
|
|
12
|
+
arg: {name: 't', start: 0, finish: 1e13, step: 2.5e8},
|
|
13
|
+
initial: [0.00176, 0, 0, 0],
|
|
14
|
+
func: (t: number, y: Float64Array, output: Float64Array) => {
|
|
15
|
+
// extract function values
|
|
16
|
+
const y1 = y[0];
|
|
17
|
+
const y2 = y[1];
|
|
18
|
+
const y3 = y[2];
|
|
19
|
+
const y4 = y[3];
|
|
20
|
+
|
|
21
|
+
// compute output
|
|
22
|
+
output[0] = -E5.K1 * y1 - E5.K3 * y1 * y3;
|
|
23
|
+
output[1] = E5.K1 * y1 - E5.K2 * y2 * y3;
|
|
24
|
+
output[2] = E5.K1 * y1 - E5.K2 * y2 * y3 - E5.K3 * y1 * y3 + E5.K4 * y4;
|
|
25
|
+
output[3] = E5.K3 * y1 * y3 - E5.K4 * y4;
|
|
26
|
+
},
|
|
27
|
+
tolerance: 1e-6,
|
|
28
|
+
solutionColNames: ['y1', 'y2', 'y3', 'y4'],
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const e5ReferencePoint = new Float64Array([
|
|
32
|
+
0.1152903278711829E-290,
|
|
33
|
+
0.8867655517642120E-22,
|
|
34
|
+
0.8854814626268838E-22,
|
|
35
|
+
0,
|
|
36
|
+
]);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** High Irradiance Responses of photomorphogenesis (see https://archimede.uniba.it/~testset/problems/hires.php) */
|
|
2
|
+
export const hires = {
|
|
3
|
+
name: 'HIRES',
|
|
4
|
+
arg: { name: 't', start: 0, finish: 321.8122, step: 0.01 },
|
|
5
|
+
initial: [1, 0, 0, 0, 0, 0, 0, 0.0057],
|
|
6
|
+
func: (t, y, output) => {
|
|
7
|
+
// extract function values
|
|
8
|
+
const y1 = y[0];
|
|
9
|
+
const y2 = y[1];
|
|
10
|
+
const y3 = y[2];
|
|
11
|
+
const y4 = y[3];
|
|
12
|
+
const y5 = y[4];
|
|
13
|
+
const y6 = y[5];
|
|
14
|
+
const y7 = y[6];
|
|
15
|
+
const y8 = y[7];
|
|
16
|
+
// compute output
|
|
17
|
+
output[0] = -1.71 * y1 + 0.43 * y2 + 8.32 * y3 + 0.0007;
|
|
18
|
+
output[1] = 1.71 * y1 - 8.75 * y2;
|
|
19
|
+
output[2] = -10.03 * y3 + 0.43 * y4 + 0.035 * y5;
|
|
20
|
+
output[3] = 8.32 * y2 + 1.71 * y3 - 1.12 * y4;
|
|
21
|
+
output[4] = -1.745 * y5 + 0.43 * y6 + 0.43 * y7;
|
|
22
|
+
output[5] = -280 * y6 * y8 + 0.69 * y4 + 1.71 * y5 - 0.43 * y6 + 0.69 * y7;
|
|
23
|
+
output[6] = 280 * y6 * y8 - 1.81 * y7;
|
|
24
|
+
output[7] = -280 * y6 * y8 + 1.81 * y7;
|
|
25
|
+
},
|
|
26
|
+
tolerance: 1e-10,
|
|
27
|
+
solutionColNames: ['y1', 'y2', 'y3', 'y4', 'y5', 'y6', 'y7', 'y8'],
|
|
28
|
+
}; // hires
|
|
29
|
+
export const hiresReferencePoint = new Float64Array([
|
|
30
|
+
0.7371312573325668E-3,
|
|
31
|
+
0.1442485726316185E-3,
|
|
32
|
+
0.5888729740967575E-4,
|
|
33
|
+
0.1175651343283149E-2,
|
|
34
|
+
0.2386356198831331E-2,
|
|
35
|
+
0.6238968252742796E-2,
|
|
36
|
+
0.2849998395185769E-2,
|
|
37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CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,KAAK,GAAG,EAAE,CAAC;QACjD,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,CAAC;QAC9C,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,CAAC;QAChD,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3E,MAAM,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,CAAC;QACtC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,CAAC;IACzC,CAAC;IACD,SAAS,EAAE,KAAK;IAChB,gBAAgB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;CACnE,CAAC,CAAC,QAAQ;AAEX,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,YAAY,CAAC;IAClD,qBAAqB;IACrB,qBAAqB;IACrB,qBAAqB;IACrB,qBAAqB;IACrB,qBAAqB;IACrB,qBAAqB;IACrB,qBAAqB;IACrB,qBAAqB;CACtB,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** High Irradiance Responses of photomorphogenesis (see https://archimede.uniba.it/~testset/problems/hires.php) */
|
|
2
|
+
export const hires = {
|
|
3
|
+
name: 'HIRES',
|
|
4
|
+
arg: {name: 't', start: 0, finish: 321.8122, step: 0.01},
|
|
5
|
+
initial: [1, 0, 0, 0, 0, 0, 0, 0.0057],
|
|
6
|
+
func: (t: number, y: Float64Array, output: Float64Array) => {
|
|
7
|
+
// extract function values
|
|
8
|
+
const y1 = y[0];
|
|
9
|
+
const y2 = y[1];
|
|
10
|
+
const y3 = y[2];
|
|
11
|
+
const y4 = y[3];
|
|
12
|
+
const y5 = y[4];
|
|
13
|
+
const y6 = y[5];
|
|
14
|
+
const y7 = y[6];
|
|
15
|
+
const y8 = y[7];
|
|
16
|
+
|
|
17
|
+
// compute output
|
|
18
|
+
output[0] = -1.71 * y1 + 0.43 * y2 + 8.32 * y3 + 0.0007;
|
|
19
|
+
output[1] = 1.71 * y1 - 8.75 * y2;
|
|
20
|
+
output[2] = -10.03 * y3 + 0.43 * y4 + 0.035 * y5;
|
|
21
|
+
output[3] = 8.32 * y2 + 1.71 * y3 - 1.12 * y4;
|
|
22
|
+
output[4] = -1.745 * y5 + 0.43 * y6 + 0.43 * y7;
|
|
23
|
+
output[5] = -280 * y6 * y8 + 0.69 * y4 + 1.71 * y5 - 0.43 * y6 + 0.69 * y7;
|
|
24
|
+
output[6] = 280 * y6 * y8 - 1.81 * y7;
|
|
25
|
+
output[7] = -280 * y6 * y8 + 1.81 * y7;
|
|
26
|
+
},
|
|
27
|
+
tolerance: 1e-10,
|
|
28
|
+
solutionColNames: ['y1', 'y2', 'y3', 'y4', 'y5', 'y6', 'y7', 'y8'],
|
|
29
|
+
}; // hires
|
|
30
|
+
|
|
31
|
+
export const hiresReferencePoint = new Float64Array([
|
|
32
|
+
0.7371312573325668E-3,
|
|
33
|
+
0.1442485726316185E-3,
|
|
34
|
+
0.5888729740967575E-4,
|
|
35
|
+
0.1175651343283149E-2,
|
|
36
|
+
0.2386356198831331E-2,
|
|
37
|
+
0.6238968252742796E-2,
|
|
38
|
+
0.2849998395185769E-2,
|
|
39
|
+
0.2850001604814231E-2,
|
|
40
|
+
]);
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
/** This example shows how to apply pipelines and models with updates.
|
|
3
|
+
This approach can be used for in-webworkers analysis of models.
|
|
4
|
+
|
|
5
|
+
Here, we consider gluconic acid (GA) production by Aspergillus niger modeling.
|
|
6
|
+
*/
|
|
7
|
+
import * as DGL from '../../index';
|
|
8
|
+
/** 1. Model specification */
|
|
9
|
+
const model = `#name: GA-production
|
|
10
|
+
#tags: model
|
|
11
|
+
#description: Gluconic acid (GA) production by Aspergillus niger modeling
|
|
12
|
+
#equations:
|
|
13
|
+
dX/dt = rX
|
|
14
|
+
dS/dt = -gamma * rX - lambda * X
|
|
15
|
+
dO/dt = Kla * (Cod - O) - delta * rX - phi * X
|
|
16
|
+
dP/dt = alpha * rX + beta * X
|
|
17
|
+
|
|
18
|
+
#expressions:
|
|
19
|
+
mu = muM * S / (Ks + S) * O / (Ko + O)
|
|
20
|
+
rX = mu * X
|
|
21
|
+
|
|
22
|
+
#argument: t, 1-st stage
|
|
23
|
+
_t0 = 0 {units: h; caption: initial; category: Misc} [Start of the process]
|
|
24
|
+
_t1 = 60 {units: h; caption: 1-st stage; category: Durations; min: 20; max: 80} [Duration of the 1-st stage]
|
|
25
|
+
step = 0.1 {units: h; caption: step; category: Misc; min: 0.01; max: 1} [Time step of simulation]
|
|
26
|
+
|
|
27
|
+
#update: 2-nd stage
|
|
28
|
+
duration = overall - _t1
|
|
29
|
+
S += 70
|
|
30
|
+
|
|
31
|
+
#inits:
|
|
32
|
+
X = 5 {units: kg/m³; caption: biomass; category: Initial concentrations; min: 1; max: 10} [Aspergillus niger biomass]
|
|
33
|
+
S = 150 {units: kg/m³; caption: glucose; category: Initial concentrations; min: 50; max: 200} [Glucose]
|
|
34
|
+
O = 7 {units: kg/m³; caption: oxygen; category: Initial concentrations; min: 1; max: 10} [Dissolved oxygen]
|
|
35
|
+
P = 0 {units: kg/m³; caption: acid; category: Initial concentrations; min: 0; max: 0.1} [Gluconic acid]
|
|
36
|
+
|
|
37
|
+
#output:
|
|
38
|
+
t {caption: time}
|
|
39
|
+
X {caption: biomass}
|
|
40
|
+
S {caption: glucose}
|
|
41
|
+
O {caption: oxygen}
|
|
42
|
+
P {caption: acid}
|
|
43
|
+
|
|
44
|
+
#parameters:
|
|
45
|
+
overall = 100 {units: h; category: Durations; min: 100; max: 140} [Overall duration]
|
|
46
|
+
muM = 0.668 {units: 1/h; category: Parameters} [Monod type model parameter]
|
|
47
|
+
alpha = 2.92 {category: Parameters} [Monod type model parameter]
|
|
48
|
+
beta = 0.131 {units: 1/h; category: Parameters} [Monod type model parameter]
|
|
49
|
+
gamma = 2.12 {category: Parameters} [Monod type model parameter]
|
|
50
|
+
lambda = 0.232 {units: 1/h; category: Parameters} [Monod type model parameter]
|
|
51
|
+
delta = 0.278 {category: Parameters} [Monod type model parameter]
|
|
52
|
+
phi = 4.87e-3 {units: 1/h; category: Parameters} [Monod type model parameter]
|
|
53
|
+
Ks = 1.309e2 {units: g/L; category: Parameters} [Monod type model parameter]
|
|
54
|
+
Ko = 3.63e-4 {units: g/L; category: Parameters} [Monod type model parameter]
|
|
55
|
+
Kla = 1.7e-2 {units: 1/s; category: Parameters} [Volumetric mass transfer coefficient]
|
|
56
|
+
Cod = 15 {units: kg/m³; category: Parameters} [Liquid phase dissolved oxygen saturation concentration]
|
|
57
|
+
|
|
58
|
+
#tolerance: 1e-9`;
|
|
59
|
+
/** 2. Generate IVP-objects: for the main thread & for computations in webworkers */
|
|
60
|
+
const ivp = DGL.getIVP(model);
|
|
61
|
+
const ivpWW = DGL.getIvp2WebWorker(ivp);
|
|
62
|
+
/** 3. Perform computations */
|
|
63
|
+
try {
|
|
64
|
+
// 3.1) Extract names of outputs
|
|
65
|
+
const outputNames = DGL.getOutputNames(ivp);
|
|
66
|
+
const outSize = outputNames.length;
|
|
67
|
+
// 3.2) Set model inputs
|
|
68
|
+
const inputs = {
|
|
69
|
+
_t0: 0,
|
|
70
|
+
_t1: 60,
|
|
71
|
+
_h: 1,
|
|
72
|
+
X: 5,
|
|
73
|
+
S: 150,
|
|
74
|
+
O: 7,
|
|
75
|
+
P: 0,
|
|
76
|
+
overall: 100,
|
|
77
|
+
muM: 0.668,
|
|
78
|
+
alpha: 2.92,
|
|
79
|
+
beta: 0.131,
|
|
80
|
+
gamma: 2.12,
|
|
81
|
+
lambda: 0.232,
|
|
82
|
+
delta: 0.278,
|
|
83
|
+
phi: 4.87e-3,
|
|
84
|
+
Ks: 1.309e2,
|
|
85
|
+
Ko: 3.63e-4,
|
|
86
|
+
Kla: 1.7e-2,
|
|
87
|
+
Cod: 15,
|
|
88
|
+
};
|
|
89
|
+
const inputVector = DGL.getInputVector(inputs, ivp);
|
|
90
|
+
// 3.3) Create a pipeline
|
|
91
|
+
const creator = DGL.getPipelineCreator(ivp);
|
|
92
|
+
const pipeline = creator.getPipeline(inputVector);
|
|
93
|
+
// 3.4) Apply pipeline to perform computations
|
|
94
|
+
const solution = DGL.applyPipeline(pipeline, ivpWW, inputVector);
|
|
95
|
+
// 3.5) Print results
|
|
96
|
+
// 3.5.1) Table header
|
|
97
|
+
let line = ' ';
|
|
98
|
+
outputNames.forEach((name) => line += name + ' ');
|
|
99
|
+
console.log(line);
|
|
100
|
+
// 3.5.2) Table with solution
|
|
101
|
+
const length = solution[0].length;
|
|
102
|
+
for (let i = 0; i < length; ++i) {
|
|
103
|
+
line = '';
|
|
104
|
+
for (let j = 0; j < outSize; ++j)
|
|
105
|
+
line += solution[j][i].toFixed(8) + ' ';
|
|
106
|
+
console.log(line);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
console.log('Simulation failed: ', err instanceof Error ? err.message : 'Unknown problem!');
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=model-updates.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-updates.js","sourceRoot":"","sources":["model-updates.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC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AAQ,GAAG,GAAG,CAAC,aAAa,CAAC,QAAQ,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;IAEjE,qBAAqB;IAErB,sBAAsB;IACtB,IAAI,IAAI,GAAG,OAAO,CAAC;IACnB,WAAW,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI,GAAG,WAAW,CAAC,CAAC;IAC1D,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAElB,6BAA6B;IAC7B,MAAM,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;QAChC,IAAI,GAAG,EAAE,CAAC;QAEV,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,EAAE,CAAC;YAC9B,IAAI,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;QAE9C,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;AACH,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACb,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC;AAC9F,CAAC"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
/** This example shows how to apply pipelines and models with updates.
|
|
3
|
+
This approach can be used for in-webworkers analysis of models.
|
|
4
|
+
|
|
5
|
+
Here, we consider gluconic acid (GA) production by Aspergillus niger modeling.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as DGL from '../../index';
|
|
9
|
+
|
|
10
|
+
/** 1. Model specification */
|
|
11
|
+
const model = `#name: GA-production
|
|
12
|
+
#tags: model
|
|
13
|
+
#description: Gluconic acid (GA) production by Aspergillus niger modeling
|
|
14
|
+
#equations:
|
|
15
|
+
dX/dt = rX
|
|
16
|
+
dS/dt = -gamma * rX - lambda * X
|
|
17
|
+
dO/dt = Kla * (Cod - O) - delta * rX - phi * X
|
|
18
|
+
dP/dt = alpha * rX + beta * X
|
|
19
|
+
|
|
20
|
+
#expressions:
|
|
21
|
+
mu = muM * S / (Ks + S) * O / (Ko + O)
|
|
22
|
+
rX = mu * X
|
|
23
|
+
|
|
24
|
+
#argument: t, 1-st stage
|
|
25
|
+
_t0 = 0 {units: h; caption: initial; category: Misc} [Start of the process]
|
|
26
|
+
_t1 = 60 {units: h; caption: 1-st stage; category: Durations; min: 20; max: 80} [Duration of the 1-st stage]
|
|
27
|
+
step = 0.1 {units: h; caption: step; category: Misc; min: 0.01; max: 1} [Time step of simulation]
|
|
28
|
+
|
|
29
|
+
#update: 2-nd stage
|
|
30
|
+
duration = overall - _t1
|
|
31
|
+
S += 70
|
|
32
|
+
|
|
33
|
+
#inits:
|
|
34
|
+
X = 5 {units: kg/m³; caption: biomass; category: Initial concentrations; min: 1; max: 10} [Aspergillus niger biomass]
|
|
35
|
+
S = 150 {units: kg/m³; caption: glucose; category: Initial concentrations; min: 50; max: 200} [Glucose]
|
|
36
|
+
O = 7 {units: kg/m³; caption: oxygen; category: Initial concentrations; min: 1; max: 10} [Dissolved oxygen]
|
|
37
|
+
P = 0 {units: kg/m³; caption: acid; category: Initial concentrations; min: 0; max: 0.1} [Gluconic acid]
|
|
38
|
+
|
|
39
|
+
#output:
|
|
40
|
+
t {caption: time}
|
|
41
|
+
X {caption: biomass}
|
|
42
|
+
S {caption: glucose}
|
|
43
|
+
O {caption: oxygen}
|
|
44
|
+
P {caption: acid}
|
|
45
|
+
|
|
46
|
+
#parameters:
|
|
47
|
+
overall = 100 {units: h; category: Durations; min: 100; max: 140} [Overall duration]
|
|
48
|
+
muM = 0.668 {units: 1/h; category: Parameters} [Monod type model parameter]
|
|
49
|
+
alpha = 2.92 {category: Parameters} [Monod type model parameter]
|
|
50
|
+
beta = 0.131 {units: 1/h; category: Parameters} [Monod type model parameter]
|
|
51
|
+
gamma = 2.12 {category: Parameters} [Monod type model parameter]
|
|
52
|
+
lambda = 0.232 {units: 1/h; category: Parameters} [Monod type model parameter]
|
|
53
|
+
delta = 0.278 {category: Parameters} [Monod type model parameter]
|
|
54
|
+
phi = 4.87e-3 {units: 1/h; category: Parameters} [Monod type model parameter]
|
|
55
|
+
Ks = 1.309e2 {units: g/L; category: Parameters} [Monod type model parameter]
|
|
56
|
+
Ko = 3.63e-4 {units: g/L; category: Parameters} [Monod type model parameter]
|
|
57
|
+
Kla = 1.7e-2 {units: 1/s; category: Parameters} [Volumetric mass transfer coefficient]
|
|
58
|
+
Cod = 15 {units: kg/m³; category: Parameters} [Liquid phase dissolved oxygen saturation concentration]
|
|
59
|
+
|
|
60
|
+
#tolerance: 1e-9`;
|
|
61
|
+
|
|
62
|
+
/** 2. Generate IVP-objects: for the main thread & for computations in webworkers */
|
|
63
|
+
const ivp = DGL.getIVP(model);
|
|
64
|
+
const ivpWW = DGL.getIvp2WebWorker(ivp);
|
|
65
|
+
|
|
66
|
+
/** 3. Perform computations */
|
|
67
|
+
try {
|
|
68
|
+
// 3.1) Extract names of outputs
|
|
69
|
+
const outputNames = DGL.getOutputNames(ivp);
|
|
70
|
+
const outSize = outputNames.length;
|
|
71
|
+
|
|
72
|
+
// 3.2) Set model inputs
|
|
73
|
+
const inputs = {
|
|
74
|
+
_t0: 0,
|
|
75
|
+
_t1: 60,
|
|
76
|
+
_h: 1,
|
|
77
|
+
X: 5,
|
|
78
|
+
S: 150,
|
|
79
|
+
O: 7,
|
|
80
|
+
P: 0,
|
|
81
|
+
overall: 100,
|
|
82
|
+
muM: 0.668,
|
|
83
|
+
alpha: 2.92,
|
|
84
|
+
beta: 0.131,
|
|
85
|
+
gamma: 2.12,
|
|
86
|
+
lambda: 0.232,
|
|
87
|
+
delta: 0.278,
|
|
88
|
+
phi: 4.87e-3,
|
|
89
|
+
Ks: 1.309e2,
|
|
90
|
+
Ko: 3.63e-4,
|
|
91
|
+
Kla: 1.7e-2,
|
|
92
|
+
Cod: 15,
|
|
93
|
+
};
|
|
94
|
+
const inputVector = DGL.getInputVector(inputs, ivp);
|
|
95
|
+
|
|
96
|
+
// 3.3) Create a pipeline
|
|
97
|
+
const creator = DGL.getPipelineCreator(ivp);
|
|
98
|
+
const pipeline = creator.getPipeline(inputVector);
|
|
99
|
+
|
|
100
|
+
// 3.4) Apply pipeline to perform computations
|
|
101
|
+
const solution = DGL.applyPipeline(pipeline, ivpWW, inputVector);
|
|
102
|
+
|
|
103
|
+
// 3.5) Print results
|
|
104
|
+
|
|
105
|
+
// 3.5.1) Table header
|
|
106
|
+
let line = ' ';
|
|
107
|
+
outputNames.forEach((name) => line += name + ' ');
|
|
108
|
+
console.log(line);
|
|
109
|
+
|
|
110
|
+
// 3.5.2) Table with solution
|
|
111
|
+
const length = solution[0].length;
|
|
112
|
+
for (let i = 0; i < length; ++i) {
|
|
113
|
+
line = '';
|
|
114
|
+
|
|
115
|
+
for (let j = 0; j < outSize; ++j)
|
|
116
|
+
line += solution[j][i].toFixed(8) + ' ';
|
|
117
|
+
|
|
118
|
+
console.log(line);
|
|
119
|
+
}
|
|
120
|
+
} catch (err) {
|
|
121
|
+
console.log('Simulation failed: ', err instanceof Error ? err.message : 'Unknown problem!');
|
|
122
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** The OREGO model (see https://archimede.uniba.it/~testset/report/orego.pdf) */
|
|
2
|
+
export const orego = {
|
|
3
|
+
name: 'OREGO',
|
|
4
|
+
arg: { name: 't', start: 0, finish: 360, step: 0.01 },
|
|
5
|
+
initial: [1, 2, 3],
|
|
6
|
+
func: (t, y, output) => {
|
|
7
|
+
// extract function values
|
|
8
|
+
const y1 = y[0];
|
|
9
|
+
const y2 = y[1];
|
|
10
|
+
const y3 = y[2];
|
|
11
|
+
// compute output
|
|
12
|
+
output[0] = 77.27 * (y2 - y1 * y2 + y1 - 0.000008375 * y1 * y1);
|
|
13
|
+
output[1] = 1 / 77.27 * (-y2 - y1 * y2 + y3);
|
|
14
|
+
output[2] = 0.161 * (y1 - y3);
|
|
15
|
+
},
|
|
16
|
+
tolerance: 1e-8,
|
|
17
|
+
solutionColNames: ['y1', 'y2', 'y3'],
|
|
18
|
+
};
|
|
19
|
+
export const oregoReferencePoint = new Float64Array([
|
|
20
|
+
1.000814870318523,
|
|
21
|
+
1228.178521549917,
|
|
22
|
+
132.0554942846706,
|
|
23
|
+
]);
|
|
24
|
+
//# sourceMappingURL=orego.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orego.js","sourceRoot":"","sources":["orego.ts"],"names":[],"mappings":"AAAA,iFAAiF;AACjF,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,IAAI,EAAE,OAAO;IACb,GAAG,EAAE,EAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAC;IACnD,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAClB,IAAI,EAAE,CAAC,CAAS,EAAE,CAAe,EAAE,MAAoB,EAAE,EAAE;QACzD,0BAA0B;QAC1B,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAChB,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAChB,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAEhB,iBAAiB;QACjB,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,WAAW,GAAG,EAAE,GAAG,EAAE,CAAE,CAAC;QACjE,MAAM,CAAC,CAAC,CAAC,GAAG,C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