From 7b38c2f51a0e1eb2fb00e6657129357292776a31 Mon Sep 17 00:00:00 2001 From: HorriblePerson555 <47578455+HorriblePerson555@users.noreply.github.com> Date: Tue, 21 Oct 2025 12:32:21 +0200 Subject: [PATCH] Refactor recirculation flow calculation to ensure non-negative flow rates and correct measurement position --- src/specificClass.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/specificClass.js b/src/specificClass.js index 44f41af..3f62914 100644 --- a/src/specificClass.js +++ b/src/specificClass.js @@ -76,9 +76,11 @@ class Reactor { 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").getCurrentValue(); - effluent[0].F -= recirculationFlow || 0; - effluent.push({ topic: "Fluent", payload: { inlet: 1, F: recirculationFlow, C: Cs }, timestamp: this.currentTime }); + const recirculationFlow = this.returnPump.measurements.type("flow").variant("measured").position("atequipment").getCurrentValue(); + const F_main = Math.max(effluent[0].payload.F - recirculationFlow, 0); + const F_side_constrained = effluent[0].payload.F < recirculationFlow ? effluent[0].payload.F : recirculationFlow; + effluent[0].payload.F = F_main; + effluent.push({ topic: "Fluent", payload: { inlet: 1, F: F_side_constrained, C: Cs }, timestamp: this.currentTime }); } return effluent; }