Update state handling in reactor class and optimize time iteration logic
This commit is contained in:
@@ -37,6 +37,7 @@ class nodeClass {
|
|||||||
break;
|
break;
|
||||||
case "Fluent":
|
case "Fluent":
|
||||||
this.source.setInfluent = msg;
|
this.source.setInfluent = msg;
|
||||||
|
this.source.updateState(msg.timestamp);
|
||||||
break;
|
break;
|
||||||
case "OTR":
|
case "OTR":
|
||||||
this.source.setOTR = msg;
|
this.source.setOTR = msg;
|
||||||
|
|||||||
@@ -214,24 +214,23 @@ class Reactor {
|
|||||||
this.setInfluent = this.upstreamReactor.getEffluent[0];
|
this.setInfluent = this.upstreamReactor.getEffluent[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newTime === this.currentTime) {
|
const n_iter = Math.floor(this.speedUpFactor * (newTime-this.currentTime) / (this.timeStep*DAY2MS));
|
||||||
// no update necessary
|
|
||||||
|
if (n_iter == 0) {
|
||||||
|
// no update required
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const n_iter = Math.floor(this.speedUpFactor * (newTime-this.currentTime) / (this.timeStep*DAY2MS));
|
let n = 0;
|
||||||
if (n_iter) {
|
while (n < n_iter) {
|
||||||
let n = 0;
|
this.tick(this.timeStep);
|
||||||
while (n < n_iter) {
|
n += 1;
|
||||||
this.tick(this.timeStep);
|
}
|
||||||
n += 1;
|
this.currentTime += n_iter * this.timeStep * DAY2MS / this.speedUpFactor;
|
||||||
}
|
this.emitter.emit("stateChange", this.currentTime);
|
||||||
this.currentTime += n_iter * this.timeStep * DAY2MS / this.speedUpFactor;
|
|
||||||
this.emitter.emit("stateChange", this.currentTime);
|
|
||||||
|
|
||||||
if (this.returnPump) {
|
if (this.returnPump) {
|
||||||
this.returnPump.updateSourceSink();
|
this.returnPump.updateSourceSink();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user