diff-grok 1.0.8

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.
Files changed (136) hide show
  1. package/.eslintrc.json +45 -0
  2. package/.github/scripts/bump-js-api-version.sh +106 -0
  3. package/.github/scripts/check-output.sh +20 -0
  4. package/.github/scripts/iac-cfn-deploy.sh +90 -0
  5. package/.github/scripts/slack_api_request.sh +65 -0
  6. package/.github/scripts/test_package.sh +270 -0
  7. package/.github/workflows/libraries.yaml +305 -0
  8. package/LICENSE +21 -0
  9. package/README.MD +396 -0
  10. package/eslintrc.json +45 -0
  11. package/images/acid-prod.gif +0 -0
  12. package/index.js +6 -0
  13. package/index.js.map +1 -0
  14. package/index.ts +15 -0
  15. package/package.json +45 -0
  16. package/src/examples/basic-use.js +40 -0
  17. package/src/examples/basic-use.js.map +1 -0
  18. package/src/examples/basic-use.ts +44 -0
  19. package/src/examples/check-methods.js +45 -0
  20. package/src/examples/check-methods.js.map +1 -0
  21. package/src/examples/check-methods.ts +62 -0
  22. package/src/examples/corr-probs.js +130 -0
  23. package/src/examples/corr-probs.js.map +1 -0
  24. package/src/examples/corr-probs.ts +151 -0
  25. package/src/examples/cyclic-model.js +100 -0
  26. package/src/examples/cyclic-model.js.map +1 -0
  27. package/src/examples/cyclic-model.ts +110 -0
  28. package/src/examples/e5.js +30 -0
  29. package/src/examples/e5.js.map +1 -0
  30. package/src/examples/e5.ts +29 -0
  31. package/src/examples/hires.js +29 -0
  32. package/src/examples/hires.js.map +1 -0
  33. package/src/examples/hires.ts +29 -0
  34. package/src/examples/index.js +17 -0
  35. package/src/examples/index.js.map +1 -0
  36. package/src/examples/index.ts +18 -0
  37. package/src/examples/model-updates.js +112 -0
  38. package/src/examples/model-updates.js.map +1 -0
  39. package/src/examples/model-updates.ts +122 -0
  40. package/src/examples/orego.js +19 -0
  41. package/src/examples/orego.js.map +1 -0
  42. package/src/examples/orego.ts +19 -0
  43. package/src/examples/pipeline-use.js +87 -0
  44. package/src/examples/pipeline-use.js.map +1 -0
  45. package/src/examples/pipeline-use.ts +98 -0
  46. package/src/examples/pollution.js +110 -0
  47. package/src/examples/pollution.js.map +1 -0
  48. package/src/examples/pollution.ts +110 -0
  49. package/src/examples/robertson.js +14 -0
  50. package/src/examples/robertson.js.map +1 -0
  51. package/src/examples/robertson.ts +13 -0
  52. package/src/examples/scripting.js +31 -0
  53. package/src/examples/scripting.js.map +1 -0
  54. package/src/examples/scripting.ts +36 -0
  55. package/src/examples/vdpol.js +13 -0
  56. package/src/examples/vdpol.js.map +1 -0
  57. package/src/examples/vdpol.ts +12 -0
  58. package/src/pipeline/basic-pipeline-creator.js +21 -0
  59. package/src/pipeline/basic-pipeline-creator.js.map +1 -0
  60. package/src/pipeline/basic-pipeline-creator.ts +24 -0
  61. package/src/pipeline/constants.js +21 -0
  62. package/src/pipeline/constants.js.map +1 -0
  63. package/src/pipeline/constants.ts +21 -0
  64. package/src/pipeline/index.js +8 -0
  65. package/src/pipeline/index.js.map +1 -0
  66. package/src/pipeline/index.ts +7 -0
  67. package/src/pipeline/input.js +45 -0
  68. package/src/pipeline/input.js.map +1 -0
  69. package/src/pipeline/input.ts +55 -0
  70. package/src/pipeline/loops-pipeline-creator.js +107 -0
  71. package/src/pipeline/loops-pipeline-creator.js.map +1 -0
  72. package/src/pipeline/loops-pipeline-creator.ts +138 -0
  73. package/src/pipeline/output.js +146 -0
  74. package/src/pipeline/output.js.map +1 -0
  75. package/src/pipeline/output.ts +196 -0
  76. package/src/pipeline/pipeline-creator.js +10 -0
  77. package/src/pipeline/pipeline-creator.js.map +1 -0
  78. package/src/pipeline/pipeline-creator.ts +16 -0
  79. package/src/pipeline/pipeline.js +71 -0
  80. package/src/pipeline/pipeline.js.map +1 -0
  81. package/src/pipeline/pipeline.ts +104 -0
  82. package/src/pipeline/updates-pipeline-creator.js +98 -0
  83. package/src/pipeline/updates-pipeline-creator.js.map +1 -0
  84. package/src/pipeline/updates-pipeline-creator.ts +125 -0
  85. package/src/scripting-tools/constants.js +53 -0
  86. package/src/scripting-tools/constants.js.map +1 -0
  87. package/src/scripting-tools/constants.ts +51 -0
  88. package/src/scripting-tools/index.js +4 -0
  89. package/src/scripting-tools/index.js.map +1 -0
  90. package/src/scripting-tools/index.ts +7 -0
  91. package/src/scripting-tools/model-error.js +17 -0
  92. package/src/scripting-tools/model-error.js.map +1 -0
  93. package/src/scripting-tools/model-error.ts +19 -0
  94. package/src/scripting-tools/scripting-tools.js +1032 -0
  95. package/src/scripting-tools/scripting-tools.js.map +1 -0
  96. package/src/scripting-tools/scripting-tools.ts +1375 -0
  97. package/src/solver-tools/callbacks/callback-base.js +10 -0
  98. package/src/solver-tools/callbacks/callback-base.js.map +1 -0
  99. package/src/solver-tools/callbacks/callback-base.ts +8 -0
  100. package/src/solver-tools/callbacks/callback-tools.js +14 -0
  101. package/src/solver-tools/callbacks/callback-tools.js.map +1 -0
  102. package/src/solver-tools/callbacks/callback-tools.ts +20 -0
  103. package/src/solver-tools/callbacks/iter-checker-callback.js +16 -0
  104. package/src/solver-tools/callbacks/iter-checker-callback.js.map +1 -0
  105. package/src/solver-tools/callbacks/iter-checker-callback.ts +21 -0
  106. package/src/solver-tools/callbacks/time-checker-callback.js +17 -0
  107. package/src/solver-tools/callbacks/time-checker-callback.js.map +1 -0
  108. package/src/solver-tools/callbacks/time-checker-callback.ts +19 -0
  109. package/src/solver-tools/index.js +6 -0
  110. package/src/solver-tools/index.js.map +1 -0
  111. package/src/solver-tools/index.ts +6 -0
  112. package/src/solver-tools/lin-alg-tools.js +56 -0
  113. package/src/solver-tools/lin-alg-tools.js.map +1 -0
  114. package/src/solver-tools/lin-alg-tools.ts +75 -0
  115. package/src/solver-tools/mrt-method.js +210 -0
  116. package/src/solver-tools/mrt-method.js.map +1 -0
  117. package/src/solver-tools/mrt-method.ts +269 -0
  118. package/src/solver-tools/ros34prw-method.js +257 -0
  119. package/src/solver-tools/ros34prw-method.js.map +1 -0
  120. package/src/solver-tools/ros34prw-method.ts +335 -0
  121. package/src/solver-tools/ros3prw-method.js +233 -0
  122. package/src/solver-tools/ros3prw-method.js.map +1 -0
  123. package/src/solver-tools/ros3prw-method.ts +304 -0
  124. package/src/solver-tools/solver-defs.js +58 -0
  125. package/src/solver-tools/solver-defs.js.map +1 -0
  126. package/src/solver-tools/solver-defs.ts +100 -0
  127. package/src/worker-tools/index.js +3 -0
  128. package/src/worker-tools/index.js.map +1 -0
  129. package/src/worker-tools/index.ts +2 -0
  130. package/src/worker-tools/scripting.js +68 -0
  131. package/src/worker-tools/scripting.js.map +1 -0
  132. package/src/worker-tools/scripting.ts +95 -0
  133. package/src/worker-tools/solving.js +48 -0
  134. package/src/worker-tools/solving.js.map +1 -0
  135. package/src/worker-tools/solving.ts +60 -0
  136. package/tsconfig.json +71 -0
@@ -0,0 +1,62 @@
1
+ // A script for checking performance
2
+
3
+ import {ODEs, corrProbs, CorrProblem, mrt, ros3prw, ros34prw, perfProbs} from '../../index';
4
+
5
+ /** Return numerical solution error: maximum absolute deviation between approximate & exact solutions */
6
+ function getError(method: (odes: ODEs) => Float64Array[], corProb: CorrProblem): number {
7
+ let error = 0;
8
+
9
+ // Get numerical solution
10
+ const approxSolution = method(corProb.odes);
11
+
12
+ const exact = corProb.exact;
13
+
14
+ const arg = approxSolution[0];
15
+
16
+ const pointsCount = arg.length;
17
+ const funcsCount = approxSolution.length - 1;
18
+
19
+ // Compute error
20
+ for (let i = 0; i < pointsCount; ++i) {
21
+ const exactSolution = exact(arg[i]);
22
+
23
+ for (let j = 0; j < funcsCount; ++j)
24
+ error = Math.max(error, Math.abs(exactSolution[j] - approxSolution[j + 1][i]));
25
+ }
26
+
27
+ return error;
28
+ }
29
+
30
+ const methods = new Map([
31
+ ['MRT', mrt],
32
+ ['ROS3PRw', ros3prw],
33
+ ['ROS34PRw', ros34prw],
34
+ ]);
35
+
36
+ console.log('Performance:\n');
37
+
38
+ methods.forEach((method, name) => {
39
+ console.log(' ', name);
40
+
41
+ perfProbs.forEach((odes) => {
42
+ const start = Date.now();
43
+ method(odes);
44
+ const finish = Date.now();
45
+ console.log(` ${odes.name}: ${finish - start} ms.`);
46
+ });
47
+
48
+ console.log();
49
+ });
50
+
51
+ console.log('Correctness (maximum absolute deviation):\n');
52
+
53
+ methods.forEach((method, name) => {
54
+ console.log(' ', name);
55
+
56
+ corrProbs.forEach((problem) => {
57
+ const error = getError(method, problem);
58
+ console.log(` ${problem.odes.name}: ${error}`);
59
+ });
60
+
61
+ console.log();
62
+ });
@@ -0,0 +1,130 @@
1
+ // Problems with known exact solution (for testing correctness)
2
+ /** Non-stiff 1D test problem: equation (see [1], p. 736) */
3
+ const nonStiff1D = {
4
+ name: 'non-stiff 1D',
5
+ arg: { name: 't', start: 0, finish: 4, step: 0.01 },
6
+ initial: [2],
7
+ func: (t, y, output) => {
8
+ output[0] = 4 * Math.exp(0.8 * t) - 0.5 * y[0];
9
+ },
10
+ tolerance: 0.00001,
11
+ solutionColNames: ['y'],
12
+ };
13
+ /** Non-stiff 1D test problem: exact solution (see [1], p. 736) */
14
+ const exactNonStiff1D = (t) => {
15
+ return new Float64Array([
16
+ (Math.exp(0.8 * t) - Math.exp(-0.5 * t)) * 4 / 1.3 + 2 * Math.exp(-0.5 * t),
17
+ ]);
18
+ };
19
+ /** Non-stiff 2D test problem: equation */
20
+ const nonStiff2D = {
21
+ name: 'non-stiff 2D',
22
+ arg: { name: 't', start: 0, finish: 4, step: 0.01 },
23
+ initial: [1, 1],
24
+ func: (t, y, output) => {
25
+ output[0] = y[0] + y[1];
26
+ output[1] = y[1] - y[0];
27
+ },
28
+ tolerance: 0.000000001,
29
+ solutionColNames: ['x', 'y'],
30
+ };
31
+ /** Non-stiff 2D test problem: exact solution */
32
+ const exactNonStiff2D = (t) => {
33
+ return new Float64Array([
34
+ Math.exp(t) * (Math.cos(t) + Math.sin(t)),
35
+ Math.exp(t) * (Math.cos(t) - Math.sin(t)),
36
+ ]);
37
+ };
38
+ /** Non-stiff 3D test problem: equations */
39
+ const nonStiff3D = {
40
+ name: 'non-stiff 3D',
41
+ arg: { name: 't', start: 0, finish: 2, step: 0.001 },
42
+ initial: [0.3, -0.8, 0],
43
+ func: (t, y, output) => {
44
+ output[0] = 5 * y[0] + 2 * y[1] + Math.sin(t);
45
+ output[1] = -4 * y[0] - y[1] + Math.exp(2 * t);
46
+ output[2] = 5 * Math.pow(t, 4) - 3 * Math.pow(t, 2) + 2 * t;
47
+ },
48
+ tolerance: 0.00000001,
49
+ solutionColNames: ['x', 'y', 'z'],
50
+ };
51
+ /** Non-stiff 3D test problem: exact solution */
52
+ const exactNonStiff3D = (t) => {
53
+ const e1 = Math.exp(t);
54
+ const e2 = Math.exp(2 * t);
55
+ const e3 = Math.exp(3 * t);
56
+ const c = Math.cos(t);
57
+ const s = Math.sin(t);
58
+ return new Float64Array([
59
+ e1 + e3 + 0.1 * (3 * c - s) - 2 * e2,
60
+ -2 * e1 - e3 - 0.2 * (2 * s + 4 * c) + 3 * e2,
61
+ Math.pow(t, 5) - Math.pow(t, 3) + Math.pow(t, 2),
62
+ ]);
63
+ };
64
+ /** Stiff 1D test problem: equation (see [1], p. 767) */
65
+ const stiff1D = {
66
+ name: 'stiff 1D',
67
+ arg: { name: 't', start: 0, finish: 4, step: 0.01 },
68
+ initial: [0],
69
+ func: (t, y, output) => {
70
+ output[0] = -1000 * y[0] + 3000 - 2000 * Math.exp(-t);
71
+ },
72
+ tolerance: 0.0000005,
73
+ solutionColNames: ['y'],
74
+ };
75
+ /** Stiff 1D test problem: exact solution (see [1], p. 767) */
76
+ const exactStiff1D = (t) => {
77
+ return new Float64Array([
78
+ 3 - 0.998 * Math.exp(-1000 * t) - 2.002 * Math.exp(-t),
79
+ ]);
80
+ };
81
+ /** Stiff 2D test problem: equations (see [1], p. 770) */
82
+ const stiff2D = {
83
+ name: 'stiff 2D',
84
+ arg: { name: 't', start: 0, finish: 4, step: 0.01 },
85
+ initial: [52.29, 83.82],
86
+ func: (t, y, output) => {
87
+ output[0] = -5 * y[0] + 3 * y[1];
88
+ output[1] = 100 * y[0] - 301 * y[1];
89
+ },
90
+ tolerance: 0.0000005,
91
+ solutionColNames: ['x', 'y'],
92
+ };
93
+ /** Stiff 2D test problem: exact solution (see [1], p. 770) */
94
+ const exactStiff2D = (t) => {
95
+ return new Float64Array([
96
+ 52.96 * Math.exp(-3.9899 * t) - 0.67 * Math.exp(-302.0101 * t),
97
+ 17.83 * Math.exp(-3.9899 * t) + 65.99 * Math.exp(-302.0101 * t),
98
+ ]);
99
+ };
100
+ /** Stiff 3D test problem: equations */
101
+ const stiff3D = {
102
+ name: 'stiff 3D',
103
+ arg: { name: 't', start: 0, finish: 4, step: 0.01 },
104
+ initial: [2, 1, 0],
105
+ func: (t, y, output) => {
106
+ output[0] = -100 * y[0] + 100 * y[1] + y[2];
107
+ output[1] = y[2];
108
+ output[2] = -y[1];
109
+ },
110
+ tolerance: 0.00000001,
111
+ solutionColNames: ['x', 'y', 'z'],
112
+ };
113
+ /** Stiff 3D test problem: exact solution */
114
+ const exactStiff3D = (t) => {
115
+ return new Float64Array([
116
+ Math.exp(-100 * t) + Math.cos(t),
117
+ Math.cos(t),
118
+ -Math.sin(t),
119
+ ]);
120
+ };
121
+ /** Problems for testing correctness */
122
+ export const corrProbs = [
123
+ { odes: nonStiff1D, exact: exactNonStiff1D },
124
+ { odes: nonStiff2D, exact: exactNonStiff2D },
125
+ { odes: nonStiff3D, exact: exactNonStiff3D },
126
+ { odes: stiff1D, exact: exactStiff1D },
127
+ { odes: stiff2D, exact: exactStiff2D },
128
+ { odes: stiff3D, exact: exactStiff3D },
129
+ ];
130
+ //# sourceMappingURL=corr-probs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"corr-probs.js","sourceRoot":"","sources":["corr-probs.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAI/D,4DAA4D;AAC5D,MAAM,UAAU,GAAS;IACvB,IAAI,EAAE,cAAc;IACpB,GAAG,EAAE,EAAC,IAAI,EAAE,G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AE,EAAE;IACjC,OAAO,IAAI,YAAY,CAAC;QACtB,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAChC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QACX,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;KACb,CAAC,CAAC;AACL,CAAC,CAAC;AAQF,uCAAuC;AACvC,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,EAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,eAAe,EAAC;IAC1C,EAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,eAAe,EAAC;IAC1C,EAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,eAAe,EAAC;IAC1C,EAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAC;IACpC,EAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAC;IACpC,EAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAC;CACrC,CAAC"}
@@ -0,0 +1,151 @@
1
+ // Problems with known exact solution (for testing correctness)
2
+
3
+ import {ODEs} from '../solver-tools/solver-defs';
4
+
5
+ /** Non-stiff 1D test problem: equation (see [1], p. 736) */
6
+ const nonStiff1D: ODEs = {
7
+ name: 'non-stiff 1D',
8
+ arg: {name: 't', start: 0, finish: 4, step: 0.01},
9
+ initial: [2],
10
+ func: (t: number, y: Float64Array, output: Float64Array) => {
11
+ output[0] = 4 * Math.exp(0.8 * t) - 0.5 * y[0];
12
+ },
13
+ tolerance: 0.00001,
14
+ solutionColNames: ['y'],
15
+ };
16
+
17
+ /** Non-stiff 1D test problem: exact solution (see [1], p. 736) */
18
+ const exactNonStiff1D = (t: number) => {
19
+ return new Float64Array([
20
+ (Math.exp(0.8 * t) - Math.exp(-0.5 * t)) * 4 / 1.3 + 2 * Math.exp(-0.5 * t),
21
+ ]);
22
+ };
23
+
24
+ /** Non-stiff 2D test problem: equation */
25
+ const nonStiff2D: ODEs = {
26
+ name: 'non-stiff 2D',
27
+ arg: {name: 't', start: 0, finish: 4, step: 0.01},
28
+ initial: [1, 1],
29
+ func: (t: number, y: Float64Array, output: Float64Array) => {
30
+ output[0] = y[0] + y[1];
31
+ output[1] = y[1] - y[0];
32
+ },
33
+ tolerance: 0.000000001,
34
+ solutionColNames: ['x', 'y'],
35
+ };
36
+
37
+ /** Non-stiff 2D test problem: exact solution */
38
+ const exactNonStiff2D = (t: number) => {
39
+ return new Float64Array([
40
+ Math.exp(t) * (Math.cos(t) + Math.sin(t)),
41
+ Math.exp(t) * (Math.cos(t) - Math.sin(t)),
42
+ ]);
43
+ };
44
+
45
+ /** Non-stiff 3D test problem: equations */
46
+ const nonStiff3D: ODEs = {
47
+ name: 'non-stiff 3D',
48
+ arg: {name: 't', start: 0, finish: 2, step: 0.001},
49
+ initial: [0.3, -0.8, 0],
50
+ func: (t: number, y: Float64Array, output: Float64Array) => {
51
+ output[0] = 5 * y[0] + 2 * y[1] + Math.sin(t);
52
+ output[1] = -4 * y[0] - y[1] + Math.exp(2 * t);
53
+ output[2] = 5 * t**4 - 3 * t**2 + 2 * t;
54
+ },
55
+ tolerance: 0.00000001,
56
+ solutionColNames: ['x', 'y', 'z'],
57
+ };
58
+
59
+ /** Non-stiff 3D test problem: exact solution */
60
+ const exactNonStiff3D = (t: number) => {
61
+ const e1 = Math.exp(t);
62
+ const e2 = Math.exp(2 * t);
63
+ const e3 = Math.exp(3 * t);
64
+ const c = Math.cos(t);
65
+ const s = Math.sin(t);
66
+
67
+ return new Float64Array([
68
+ e1 + e3 + 0.1 * (3 * c - s) - 2 * e2,
69
+ -2 * e1 - e3 - 0.2 * (2 * s + 4 * c) + 3 * e2,
70
+ t**5 - t**3 + t**2,
71
+ ]);
72
+ };
73
+
74
+ /** Stiff 1D test problem: equation (see [1], p. 767) */
75
+ const stiff1D: ODEs = {
76
+ name: 'stiff 1D',
77
+ arg: {name: 't', start: 0, finish: 4, step: 0.01},
78
+ initial: [0],
79
+ func: (t: number, y: Float64Array, output: Float64Array) => {
80
+ output[0] = -1000 * y[0] + 3000 - 2000 * Math.exp(-t);
81
+ },
82
+ tolerance: 0.0000005,
83
+ solutionColNames: ['y'],
84
+ };
85
+
86
+ /** Stiff 1D test problem: exact solution (see [1], p. 767) */
87
+ const exactStiff1D = (t: number) => {
88
+ return new Float64Array([
89
+ 3 - 0.998 * Math.exp(-1000 * t) - 2.002 * Math.exp(-t),
90
+ ]);
91
+ };
92
+
93
+ /** Stiff 2D test problem: equations (see [1], p. 770) */
94
+ const stiff2D: ODEs = {
95
+ name: 'stiff 2D',
96
+ arg: {name: 't', start: 0, finish: 4, step: 0.01},
97
+ initial: [52.29, 83.82],
98
+ func: (t: number, y: Float64Array, output: Float64Array) => {
99
+ output[0] = -5 * y[0] + 3 * y[1];
100
+ output[1] = 100 * y[0] - 301 * y[1];
101
+ },
102
+ tolerance: 0.0000005,
103
+ solutionColNames: ['x', 'y'],
104
+ };
105
+
106
+ /** Stiff 2D test problem: exact solution (see [1], p. 770) */
107
+ const exactStiff2D = (t: number) => {
108
+ return new Float64Array([
109
+ 52.96 * Math.exp(-3.9899 * t) - 0.67 * Math.exp(-302.0101 * t),
110
+ 17.83 * Math.exp(-3.9899 * t) + 65.99 * Math.exp(-302.0101 * t),
111
+ ]);
112
+ };
113
+
114
+ /** Stiff 3D test problem: equations */
115
+ const stiff3D: ODEs = {
116
+ name: 'stiff 3D',
117
+ arg: {name: 't', start: 0, finish: 4, step: 0.01},
118
+ initial: [2, 1, 0],
119
+ func: (t: number, y: Float64Array, output: Float64Array) => {
120
+ output[0] = -100 * y[0] + 100 * y[1] + y[2];
121
+ output[1] = y[2];
122
+ output[2] = -y[1];
123
+ },
124
+ tolerance: 0.00000001,
125
+ solutionColNames: ['x', 'y', 'z'],
126
+ };
127
+
128
+ /** Stiff 3D test problem: exact solution */
129
+ const exactStiff3D = (t: number) => {
130
+ return new Float64Array([
131
+ Math.exp(-100 * t) + Math.cos(t),
132
+ Math.cos(t),
133
+ -Math.sin(t),
134
+ ]);
135
+ };
136
+
137
+ /** Correctness problem */
138
+ export type CorrProblem = {
139
+ odes: ODEs,
140
+ exact: (t: number) => Float64Array,
141
+ };
142
+
143
+ /** Problems for testing correctness */
144
+ export const corrProbs = [
145
+ {odes: nonStiff1D, exact: exactNonStiff1D},
146
+ {odes: nonStiff2D, exact: exactNonStiff2D},
147
+ {odes: nonStiff3D, exact: exactNonStiff3D},
148
+ {odes: stiff1D, exact: exactStiff1D},
149
+ {odes: stiff2D, exact: exactStiff2D},
150
+ {odes: stiff3D, exact: exactStiff3D},
151
+ ];
@@ -0,0 +1,100 @@
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
+ /** 2. Generate IVP-objects: for the main thread & for computations in webworkers */
50
+ const ivp = DGL.getIVP(model);
51
+ const ivpWW = DGL.getIvp2WebWorker(ivp);
52
+ /** 3. Perform computations */
53
+ try {
54
+ // 3.1) Extract names of outputs
55
+ const outputNames = DGL.getOutputNames(ivp);
56
+ const outSize = outputNames.length;
57
+ // 3.2) Set model inputs
58
+ const inputs = {
59
+ _count: 10,
60
+ _t0: 0,
61
+ _t1: 16,
62
+ _h: 1,
63
+ depot: 0,
64
+ centr: 0,
65
+ peri: 0,
66
+ eff: 0.2,
67
+ dose: 10000,
68
+ KA: 0.63,
69
+ CL: 3.2,
70
+ V2: 6.58,
71
+ Q: 0.622,
72
+ V3: 35.6,
73
+ EC50: 5.41,
74
+ Kin: 0.272,
75
+ Kout: 0.276,
76
+ };
77
+ const inputVector = DGL.getInputVector(inputs, ivp);
78
+ // 3.3) Create a pipeline
79
+ const creator = DGL.getPipelineCreator(ivp);
80
+ const pipeline = creator.getPipeline(inputVector);
81
+ // 3.4) Apply pipeline to perform computations
82
+ const solution = DGL.applyPipeline(pipeline, ivpWW, inputVector);
83
+ // 3.5) Print results
84
+ // 3.5.1) Table header
85
+ let line = ' ';
86
+ outputNames.forEach((name) => line += name + ' ');
87
+ console.log(line);
88
+ // 3.5.2) Table with solution
89
+ const length = solution[0].length;
90
+ for (let i = 0; i < length; ++i) {
91
+ line = '';
92
+ for (let j = 0; j < outSize; ++j)
93
+ line += solution[j][i].toFixed(8) + ' ';
94
+ console.log(line);
95
+ }
96
+ }
97
+ catch (err) {
98
+ console.log('Simulation failed: ', err instanceof Error ? err.message : 'Unknown problem!');
99
+ }
100
+ //# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAuCG,CAAC;AAElB,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,CA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C,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,110 @@
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
+
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
+ /** 2. Generate IVP-objects: for the main thread & for computations in webworkers */
53
+ const ivp = DGL.getIVP(model);
54
+ const ivpWW = DGL.getIvp2WebWorker(ivp);
55
+
56
+ /** 3. Perform computations */
57
+ try {
58
+ // 3.1) Extract names of outputs
59
+ const outputNames = DGL.getOutputNames(ivp);
60
+ const outSize = outputNames.length;
61
+
62
+ // 3.2) Set model inputs
63
+ const inputs = {
64
+ _count: 10,
65
+ _t0: 0,
66
+ _t1: 16,
67
+ _h: 1,
68
+ depot: 0,
69
+ centr: 0,
70
+ peri: 0,
71
+ eff: 0.2,
72
+ dose: 10000,
73
+ KA: 0.63,
74
+ CL: 3.2,
75
+ V2: 6.58,
76
+ Q: 0.622,
77
+ V3: 35.6,
78
+ EC50: 5.41,
79
+ Kin: 0.272,
80
+ Kout: 0.276,
81
+ };
82
+ const inputVector = DGL.getInputVector(inputs, ivp);
83
+
84
+ // 3.3) Create a pipeline
85
+ const creator = DGL.getPipelineCreator(ivp);
86
+ const pipeline = creator.getPipeline(inputVector);
87
+
88
+ // 3.4) Apply pipeline to perform computations
89
+ const solution = DGL.applyPipeline(pipeline, ivpWW, inputVector);
90
+
91
+ // 3.5) Print results
92
+
93
+ // 3.5.1) Table header
94
+ let line = ' ';
95
+ outputNames.forEach((name) => line += name + ' ');
96
+ console.log(line);
97
+
98
+ // 3.5.2) Table with solution
99
+ const length = solution[0].length;
100
+ for (let i = 0; i < length; ++i) {
101
+ line = '';
102
+
103
+ for (let j = 0; j < outSize; ++j)
104
+ line += solution[j][i].toFixed(8) + ' ';
105
+
106
+ console.log(line);
107
+ }
108
+ } catch (err) {
109
+ console.log('Simulation failed: ', err instanceof Error ? err.message : 'Unknown problem!');
110
+ }
@@ -0,0 +1,30 @@
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
+ //# 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;I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,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;IAC3C,CAAC;IACD,SAAS,EAAE,IAAI;IACf,gBAAgB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;CAC3C,CAAC"}
@@ -0,0 +1,29 @@
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
+ };
@@ -0,0 +1,29 @@
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
+ //# sourceMappingURL=hires.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hires.js","sourceRoot":"","sources":["hires.ts"],"names":[],"mappings":"AAAA,mHAAmH;AACnH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,IAAI,EAAE,OAAO;IACb,GAAG,EAAE,EAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAC;IACxD,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACtC,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;QAChB,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACh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