Compare commits

...

4 Commits

2 changed files with 25 additions and 14 deletions

View File

@@ -34,17 +34,14 @@ class nodeClass {
switch (msg.topic) { switch (msg.topic) {
case "clock": case "clock":
this.source.updateState(msg.timestamp); this.source.updateState(msg.timestamp);
send([msg, null, null]);
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;
break; break;
case "Temperature":
this.source.setTemperature = msg;
break;
case "Dispersion": case "Dispersion":
this.source.setDispersion = msg; this.source.setDispersion = msg;
break; break;

View File

@@ -42,7 +42,7 @@ class Reactor {
this.kla = config.kla; // if NaN, use externaly provided OTR [d-1] this.kla = config.kla; // if NaN, use externaly provided OTR [d-1]
this.currentTime = Date.now(); // milliseconds since epoch [ms] this.currentTime = null; // milliseconds since epoch [ms]
this.timeStep = 1 / (24*60*60) * this.config.timeStep; // time step in seconds, converted to days. this.timeStep = 1 / (24*60*60) * this.config.timeStep; // time step in seconds, converted to days.
this.speedUpFactor = 100; // speed up factor for simulation, 60 means 1 minute per simulated second this.speedUpFactor = 100; // speed up factor for simulation, 60 means 1 minute per simulated second
} }
@@ -204,19 +204,33 @@ class Reactor {
* @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) { // expect update with timestamp
if (!this.currentTime) {
this.currentTime = newTime;
return;
}
if (this.upstreamReactor) { if (this.upstreamReactor) {
this.setInfluent = this.upstreamReactor.getEffluent[0]; // grab main effluent upstream reactor // grab main effluent upstream reactor
this.setInfluent = this.upstreamReactor.getEffluent[0];
} }
const n_iter = Math.floor(this.speedUpFactor * (newTime-this.currentTime) / (this.timeStep*DAY2MS)); const n_iter = Math.floor(this.speedUpFactor * (newTime-this.currentTime) / (this.timeStep*DAY2MS));
if (n_iter) {
let n = 0; if (n_iter == 0) {
while (n < n_iter) { // no update required
this.tick(this.timeStep); return;
n += 1; }
}
this.currentTime += n_iter * this.timeStep * DAY2MS / this.speedUpFactor; let n = 0;
this.emitter.emit("stateChange", this.currentTime); 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();
} }
} }
} }