Temporary fix for undefined newTime value in updateState function

This commit is contained in:
2025-08-04 10:59:11 +02:00
parent 2c9db0fcea
commit fbbe5833b2
2 changed files with 26 additions and 29 deletions

20
package-lock.json generated
View File

@@ -14,9 +14,9 @@
} }
}, },
"node_modules/@babel/runtime": { "node_modules/@babel/runtime": {
"version": "7.27.6", "version": "7.28.2",
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.27.6.tgz", "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.28.2.tgz",
"integrity": "sha512-vbavdySgbTTrmFE+EsiqUTzlOr5bzlnJtUv9PynGCAKvfQqjIXbvFdumPM/GxMDfyuGMJaJAU6TO4zc1Jf1i8Q==", "integrity": "sha512-KHp2IflsnGywDjBWDkR9iEqiWSpc8GIi0lgTT3mOElT0PP1tG26P4tmFI2YvAdzgq9RGyoHZQEIEdZy6Ec5xCA==",
"license": "MIT", "license": "MIT",
"engines": { "engines": {
"node": ">=6.9.0" "node": ">=6.9.0"
@@ -36,9 +36,9 @@
} }
}, },
"node_modules/decimal.js": { "node_modules/decimal.js": {
"version": "10.5.0", "version": "10.6.0",
"resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.5.0.tgz", "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.6.0.tgz",
"integrity": "sha512-8vDa8Qxvr/+d94hSh5P3IJwI5t8/c0KsMp+g8bNw9cY2icONa5aPfvKeieW1WlG0WQYwwhJ7mjui2xtiePQSXw==", "integrity": "sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/escape-latex": { "node_modules/escape-latex": {
@@ -62,7 +62,7 @@
}, },
"node_modules/generalFunctions": { "node_modules/generalFunctions": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "git+https://gitea.centraal.wbd-rd.nl/p.vanderwilt/generalFunctions.git#950ca2b6b4e91b37479aee90bff74b02c16f130e", "resolved": "git+https://gitea.centraal.wbd-rd.nl/p.vanderwilt/generalFunctions.git#f13ee68938ea9d4b3a17ad90618c72634769c777",
"license": "SEE LICENSE" "license": "SEE LICENSE"
}, },
"node_modules/javascript-natural-sort": { "node_modules/javascript-natural-sort": {
@@ -72,9 +72,9 @@
"license": "MIT" "license": "MIT"
}, },
"node_modules/mathjs": { "node_modules/mathjs": {
"version": "14.5.2", "version": "14.6.0",
"resolved": "https://registry.npmjs.org/mathjs/-/mathjs-14.5.2.tgz", "resolved": "https://registry.npmjs.org/mathjs/-/mathjs-14.6.0.tgz",
"integrity": "sha512-51U6hp7j4M4Rj+l+q2KbmXAV9EhQVQzUdw1wE67RnUkKKq5ibxdrl9Ky2YkSUEIc2+VU8/IsThZNu6QSHUoyTA==", "integrity": "sha512-5vI2BLB5GKQmiSK9BH6hVkZ+GgqpdnOgEfmHl7mqVmdQObLynr63KueyYYLCQMzj66q69mV2XZZGQqqxeftQbA==",
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.26.10", "@babel/runtime": "^7.26.10",

View File

@@ -113,7 +113,7 @@ class Reactor {
* Update the reactor state based on the new time. * Update the reactor state based on the new time.
* @param {number} newTime - New time to update reactor state to, in milliseconds since epoch. * @param {number} newTime - New time to update reactor state to, in milliseconds since epoch.
*/ */
updateState(newTime) { // expect update with timestamp updateState(newTime = Date.now()) { // expect update with timestamp
const day2ms = 1000 * 60 * 60 * 24; const day2ms = 1000 * 60 * 60 * 24;
if (this.upstreamReactor) { if (this.upstreamReactor) {
@@ -128,7 +128,7 @@ class Reactor {
n += 1; n += 1;
} }
this.currentTime += n_iter * this.timeStep * day2ms / this.speedUpFactor; this.currentTime += n_iter * this.timeStep * day2ms / this.speedUpFactor;
this.emitter.emit("stateChange", newTime); this.emitter.emit("stateChange", this.currentTime);
} }
} }
} }
@@ -149,19 +149,19 @@ class Reactor_CSTR extends Reactor {
* @returns {Array} - New reactor state. * @returns {Array} - New reactor state.
*/ */
tick(time_step) { // tick reactor state using forward Euler method tick(time_step) { // tick reactor state using forward Euler method
const inflow = math.multiply(math.divide([this.Fs], this.volume), this.Cs_in)[0]; const inflow = math.multiply(math.divide([this.Fs], this.volume), this.Cs_in)[0];
const outflow = math.multiply(-1 * math.sum(this.Fs) / this.volume, this.state); const outflow = math.multiply(-1 * math.sum(this.Fs) / this.volume, this.state);
const reaction = this.asm.compute_dC(this.state, this.temperature); const reaction = this.asm.compute_dC(this.state, this.temperature);
const transfer = Array(NUM_SPECIES).fill(0.0); const transfer = Array(NUM_SPECIES).fill(0.0);
transfer[S_O_INDEX] = isNaN(this.kla) ? this.OTR : this._calcOTR(this.state[S_O_INDEX], this.temperature); // calculate OTR if kla is not NaN, otherwise use externaly calculated OTR transfer[S_O_INDEX] = isNaN(this.kla) ? this.OTR : this._calcOTR(this.state[S_O_INDEX], this.temperature); // calculate OTR if kla is not NaN, otherwise use externaly calculated OTR
const dC_total = math.multiply(math.add(inflow, outflow, reaction, transfer), time_step) const dC_total = math.multiply(math.add(inflow, outflow, reaction, transfer), time_step)
this.state = this._arrayClip2Zero(math.add(this.state, dC_total)); // clip value element-wise to avoid negative concentrations this.state = this._arrayClip2Zero(math.add(this.state, dC_total)); // clip value element-wise to avoid negative concentrations
if(DEBUG){ if(DEBUG){
assertNoNaN(dC_total, "change in state"); assertNoNaN(dC_total, "change in state");
assertNoNaN(this.state, "new state"); assertNoNaN(this.state, "new state");
} }
return this.state; return this.state;
} }
} }
@@ -183,9 +183,6 @@ class Reactor_PFR extends Reactor {
this.state = Array.from(Array(this.n_x), () => config.initialState.slice()) this.state = Array.from(Array(this.n_x), () => config.initialState.slice())
// console.log("Initial State: ")
// console.log(this.state)
this.D = 0.0; // axial dispersion [m2 d-1] this.D = 0.0; // axial dispersion [m2 d-1]
this.D_op = this._makeDoperator(true, true); this.D_op = this._makeDoperator(true, true);
@@ -208,8 +205,8 @@ class Reactor_PFR extends Reactor {
let Pe_local = this.d_x*math.sum(this.Fs)/(this.D*this.A) let Pe_local = this.d_x*math.sum(this.Fs)/(this.D*this.A)
let Co_D = this.D*this.timeStep/(this.d_x*this.d_x); let Co_D = this.D*this.timeStep/(this.d_x*this.d_x);
(Pe_local >= 2) && console.warn(`Local Péclet number (${Pe_local}) is too high! Increase reactor resolution.`); (Pe_local >= 2) && this.logger.warn(`Local Péclet number (${Pe_local}) is too high! Increase reactor resolution.`);
(Co_D >= 0.5) && console.warn(`Courant number (${Co_D}) is too high! Reduce time step size.`); (Co_D >= 0.5) && this.logger.warn(`Courant number (${Co_D}) is too high! Reduce time step size.`);
if(DEBUG) { if(DEBUG) {
console.log("Inlet state max " + math.max(this.state[0])) console.log("Inlet state max " + math.max(this.state[0]))