From 3a820df7f2ef37499347fdca842acec40c5ec765 Mon Sep 17 00:00:00 2001 From: HorriblePerson555 <47578455+HorriblePerson555@users.noreply.github.com> Date: Mon, 20 Oct 2025 16:45:53 +0200 Subject: [PATCH] Non-functioning prototype with partial rotating machine integration --- src/specificClass.js | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/src/specificClass.js b/src/specificClass.js index bd5af1b..ebd08bf 100644 --- a/src/specificClass.js +++ b/src/specificClass.js @@ -32,6 +32,7 @@ class Reactor { this.upstreamReactor = null; this.downstreamReactor = null; + this.returnPump = null; this.asm = new ASM3(); @@ -72,10 +73,14 @@ class Reactor { * @returns {object} Effluent data object (msg), defaults to inlet 0. */ get getEffluent() { // getter for Effluent, defaults to inlet 0 - if (isArray(this.state.at(-1))) { - return { topic: "Fluent", payload: { inlet: 0, F: math.sum(this.Fs), C: this.state.at(-1) }, timestamp: this.currentTime }; + const Cs = isArray(this.state.at(-1)) ? this.state.at(-1) : this.state; + const effluent = [{ topic: "Fluent", payload: { inlet: 0, F: math.sum(this.Fs), C: Cs }, timestamp: this.currentTime }]; + if (this.returnPump) { + const recirculationFlow = this.returnPump.measurements.type("flow").variant("measured").position("atEquipement").getValue(); + effluent[0].F -= recirculationFlow; + effluent.push({ topic: "Fluent", payload: { inlet: 1, F: recirculationFlow, C: Cs }, timestamp: this.currentTime }); } - return { topic: "Fluent", payload: { inlet: 0, F: math.sum(this.Fs), C: this.state }, timestamp: this.currentTime }; + return effluent; } /** @@ -105,13 +110,17 @@ class Reactor { registerChild(child, softwareType) { switch (softwareType) { case "measurement": - this.logger.debug(`Registering measurement child.`); + this.logger.debug(`Registering measurement child...`); this._connectMeasurement(child); break; case "reactor": - this.logger.debug(`Registering reactor child.`); + this.logger.debug(`Registering reactor child...`); this._connectReactor(child); break; + case "machine": + this.logger.debug(`Registering rotating machine child...`); + this._connectRotatingMachine(child); + break; default: this.logger.error(`Unrecognized softwareType: ${softwareType}`); @@ -150,7 +159,7 @@ class Reactor { return; } - if (reactorChild.functionality.positionVsParent != "upstream") { + if (reactorChild.config.functionality.positionVsParent != "upstream") { this.logger.warn("Reactor children of reactors should always be upstream."); } @@ -158,6 +167,7 @@ class Reactor { this.logger.warn("Significant grid sizing discrepancies between adjacent reactors! Change resolutions to match reactors grid step, or implement boundary value interpolation."); } + // set upstream and downstream reactor variable in current and child nodes respectively for easy access this.upstreamReactor = reactorChild; reactorChild.downstreamReactor = this; @@ -167,6 +177,16 @@ class Reactor { }); } + _connectRotatingMachine(rotatingMachineChild) { + if (!rotatingMachineChild) { + this.logger.warn("Invalid rotating machine provided."); + return; + } + + if (rotatingMachineChild.config.functionality.positionVsParent == "downstream") { + this.returnPump = rotatingMachineChild; + } + } _updateMeasurement(measurementType, value, position, context) { this.logger.debug(`---------------------- updating ${measurementType} ------------------ `); @@ -190,7 +210,7 @@ class Reactor { const day2ms = 1000 * 60 * 60 * 24; if (this.upstreamReactor) { - this.setInfluent = this.upstreamReactor.getEffluent; + this.setInfluent = this.upstreamReactor.getEffluent[0]; // grab main effluent upstream reactor } let n_iter = Math.floor(this.speedUpFactor * (newTime-this.currentTime) / (this.timeStep*day2ms));