From fbbe5833b298f721d2f1fdbfc4a9827dbd2f7b74 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Mon, 4 Aug 2025 10:59:11 +0200 Subject: [PATCH] Temporary fix for undefined newTime value in updateState function --- package-lock.json | 20 ++++++++++---------- src/specificClass.js | 35 ++++++++++++++++------------------- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index 19b3188..ce38b02 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,9 +14,9 @@ } }, "node_modules/@babel/runtime": { - "version": "7.27.6", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.27.6.tgz", - "integrity": "sha512-vbavdySgbTTrmFE+EsiqUTzlOr5bzlnJtUv9PynGCAKvfQqjIXbvFdumPM/GxMDfyuGMJaJAU6TO4zc1Jf1i8Q==", + "version": "7.28.2", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.28.2.tgz", + "integrity": "sha512-KHp2IflsnGywDjBWDkR9iEqiWSpc8GIi0lgTT3mOElT0PP1tG26P4tmFI2YvAdzgq9RGyoHZQEIEdZy6Ec5xCA==", "license": "MIT", "engines": { "node": ">=6.9.0" @@ -36,9 +36,9 @@ } }, "node_modules/decimal.js": { - "version": "10.5.0", - "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.5.0.tgz", - "integrity": "sha512-8vDa8Qxvr/+d94hSh5P3IJwI5t8/c0KsMp+g8bNw9cY2icONa5aPfvKeieW1WlG0WQYwwhJ7mjui2xtiePQSXw==", + "version": "10.6.0", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.6.0.tgz", + "integrity": "sha512-YpgQiITW3JXGntzdUmyUR1V812Hn8T1YVXhCu+wO3OpS4eU9l4YdD3qjyiKdV6mvV29zapkMeD390UVEf2lkUg==", "license": "MIT" }, "node_modules/escape-latex": { @@ -62,7 +62,7 @@ }, "node_modules/generalFunctions": { "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" }, "node_modules/javascript-natural-sort": { @@ -72,9 +72,9 @@ "license": "MIT" }, "node_modules/mathjs": { - "version": "14.5.2", - "resolved": "https://registry.npmjs.org/mathjs/-/mathjs-14.5.2.tgz", - "integrity": "sha512-51U6hp7j4M4Rj+l+q2KbmXAV9EhQVQzUdw1wE67RnUkKKq5ibxdrl9Ky2YkSUEIc2+VU8/IsThZNu6QSHUoyTA==", + "version": "14.6.0", + "resolved": "https://registry.npmjs.org/mathjs/-/mathjs-14.6.0.tgz", + "integrity": "sha512-5vI2BLB5GKQmiSK9BH6hVkZ+GgqpdnOgEfmHl7mqVmdQObLynr63KueyYYLCQMzj66q69mV2XZZGQqqxeftQbA==", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.26.10", diff --git a/src/specificClass.js b/src/specificClass.js index 679e6d0..d875f16 100644 --- a/src/specificClass.js +++ b/src/specificClass.js @@ -113,7 +113,7 @@ class Reactor { * Update the reactor state based on the new time. * @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; if (this.upstreamReactor) { @@ -128,7 +128,7 @@ class Reactor { n += 1; } 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. */ 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 outflow = math.multiply(-1 * math.sum(this.Fs) / this.volume, this.state); - const reaction = this.asm.compute_dC(this.state, this.temperature); - 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 + 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 reaction = this.asm.compute_dC(this.state, this.temperature); + 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 - 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 - if(DEBUG){ - assertNoNaN(dC_total, "change in state"); - assertNoNaN(this.state, "new state"); - } - return this.state; + 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 + if(DEBUG){ + assertNoNaN(dC_total, "change in state"); + assertNoNaN(this.state, "new state"); + } + return this.state; } } @@ -183,9 +183,6 @@ class Reactor_PFR extends Reactor { 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_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 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.`); - (Co_D >= 0.5) && console.warn(`Courant number (${Co_D}) is too high! Reduce time step size.`); + (Pe_local >= 2) && this.logger.warn(`Local Péclet number (${Pe_local}) is too high! Increase reactor resolution.`); + (Co_D >= 0.5) && this.logger.warn(`Courant number (${Co_D}) is too high! Reduce time step size.`); if(DEBUG) { console.log("Inlet state max " + math.max(this.state[0]))