From cc89833530f3b4ce8284d863b1103eab84a68bd6 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Fri, 14 Nov 2025 13:11:09 +0100 Subject: [PATCH] Update state handling in reactor class and optimize time iteration logic --- src/nodeClass.js | 1 + src/specificClass.js | 27 +++++++++++++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/nodeClass.js b/src/nodeClass.js index f98b5fe..946d696 100644 --- a/src/nodeClass.js +++ b/src/nodeClass.js @@ -37,6 +37,7 @@ class nodeClass { break; case "Fluent": this.source.setInfluent = msg; + this.source.updateState(msg.timestamp); break; case "OTR": this.source.setOTR = msg; diff --git a/src/specificClass.js b/src/specificClass.js index ead9800..e836197 100644 --- a/src/specificClass.js +++ b/src/specificClass.js @@ -214,24 +214,23 @@ class Reactor { this.setInfluent = this.upstreamReactor.getEffluent[0]; } - if (newTime === this.currentTime) { - // no update necessary + const n_iter = Math.floor(this.speedUpFactor * (newTime-this.currentTime) / (this.timeStep*DAY2MS)); + + if (n_iter == 0) { + // no update required return; } - const n_iter = Math.floor(this.speedUpFactor * (newTime-this.currentTime) / (this.timeStep*DAY2MS)); - if (n_iter) { - let n = 0; - while (n < n_iter) { - this.tick(this.timeStep); - n += 1; - } - this.currentTime += n_iter * this.timeStep * DAY2MS / this.speedUpFactor; - this.emitter.emit("stateChange", this.currentTime); + let n = 0; + while (n < n_iter) { + this.tick(this.timeStep); + n += 1; + } + this.currentTime += n_iter * this.timeStep * DAY2MS / this.speedUpFactor; + this.emitter.emit("stateChange", this.currentTime); - if (this.returnPump) { - this.returnPump.updateSourceSink(); - } + if (this.returnPump) { + this.returnPump.updateSourceSink(); } } }