From 288cf905d1acb096ca9b1a8919158b0ade930601 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Wed, 18 Jun 2025 10:25:40 +0200 Subject: [PATCH 1/3] Close volume balance and minor fixes --- additional_nodes/recirculation-pump.html | 2 +- additional_nodes/recirculation-pump.js | 8 ++++---- additional_nodes/settling-basin.html | 14 +++++++------- additional_nodes/settling-basin.js | 14 ++++++++------ 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/additional_nodes/recirculation-pump.html b/additional_nodes/recirculation-pump.html index 52f94a6..39a3753 100644 --- a/additional_nodes/recirculation-pump.html +++ b/additional_nodes/recirculation-pump.html @@ -43,7 +43,7 @@
- +
diff --git a/additional_nodes/recirculation-pump.js b/additional_nodes/recirculation-pump.js index 489df01..cd9fc21 100644 --- a/additional_nodes/recirculation-pump.js +++ b/additional_nodes/recirculation-pump.js @@ -11,12 +11,12 @@ module.exports = function(RED) { switch (msg.topic) { case "Fluent": // conserve volume flow debit - let F1 = msg.payload.F; - let F_diff = Math.max(F1 - F2, 0); - let F2_corr = F1 < F2 ? F1 : F2; + let F_in = msg.payload.F; + let F1 = Math.max(F_in - F2, 0); + let F2_corr = F_in < F2 ? F_in : F2; let msg_F1 = structuredClone(msg); - msg_F1.payload.F = F_diff; + msg_F1.payload.F = F1; let msg_F2 = {...msg}; msg_F2.payload.F = F2_corr; diff --git a/additional_nodes/settling-basin.html b/additional_nodes/settling-basin.html index da614bc..e8e8e8d 100644 --- a/additional_nodes/settling-basin.html +++ b/additional_nodes/settling-basin.html @@ -4,7 +4,7 @@ color: "#e4a363", defaults: { name: { value: "" }, - SVI: { value: 0.1, required: true }, + TS_set: { value: 0.1, required: true }, inlet: { value: 1, required: true } }, inputs: 1, @@ -15,7 +15,7 @@ return this.name || "Settling basin"; }, oneditprepare: function() { - $("#node-input-SVI").typedInput({ + $("#node-input-TS_set").typedInput({ type:"num", types:["num"] }); @@ -25,9 +25,9 @@ }); }, oneditsave: function() { - let SVI = parseFloat($("#node-input-SVI").typedInput("value")); - if (isNaN(SVI) || SVI < 0) { - RED.notify("SVI is not set correctly", {type: "error"}); + let TS_set = parseFloat($("#node-input-TS_set").typedInput("value")); + if (isNaN(TS_set) || TS_set < 0) { + RED.notify("TS is not set correctly", {type: "error"}); } let inlet = parseInt($("#node-input-n_inlets").typedInput("value")); if (inlet < 1) { @@ -43,8 +43,8 @@
- - + +
diff --git a/additional_nodes/settling-basin.js b/additional_nodes/settling-basin.js index f012b81..e19457a 100644 --- a/additional_nodes/settling-basin.js +++ b/additional_nodes/settling-basin.js @@ -4,7 +4,7 @@ module.exports = function(RED) { var node = this; let name = config.name; - let SVI = parseFloat(config.SVI); + let TS_set = parseFloat(config.TS_set); const inlet_sludge = parseInt(config.inlet); node.on('input', function(msg, send, done) { @@ -13,11 +13,13 @@ module.exports = function(RED) { // conserve volume flow debit let F_in = msg.payload.F; let C_in = msg.payload.C; - let X_in = (C_in[7] + C_in[8] + C_in[9] + C_in[10] + C_in[11] + C_in[12]); - let F2 = (F_in * X_in) / (SVI*1000*1000); + let F2 = (F_in * C_in[12]) / TS_set; + + let F1 = Math.max(F_in - F2, 0); + let F2_corr = F_in < F2 ? F_in : F2; let msg_F1 = structuredClone(msg); - msg_F1.payload.F = F_in - F2; + msg_F1.payload.F = F1; msg_F1.payload.C[7] = 0; msg_F1.payload.C[8] = 0; msg_F1.payload.C[9] = 0; @@ -26,8 +28,8 @@ module.exports = function(RED) { msg_F1.payload.C[12] = 0; let msg_F2 = {...msg}; - msg_F2.payload.F = F2; - if (F2 != 0) { + msg_F2.payload.F = F2_corr; + if (F2_corr > 0) { msg_F2.payload.C[7] = F_in * C_in[7] / F2; msg_F2.payload.C[8] = F_in * C_in[8] / F2; msg_F2.payload.C[9] = F_in * C_in[9] / F2; From 5bd094f4a695c586e37b0fbe5f2abc852341b362 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Wed, 18 Jun 2025 12:34:19 +0200 Subject: [PATCH 2/3] Prevent negative values in reactor state --- advanced-reactor.html | 2 +- dependencies/reactor_class.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced-reactor.html b/advanced-reactor.html index ff12949..73d66c2 100644 --- a/advanced-reactor.html +++ b/advanced-reactor.html @@ -19,7 +19,7 @@ X_H_init: { value: 30., required: true }, X_STO_init: { value: 0., required: true }, X_A_init: { value: 0.001, required: true }, - X_TS_init: { value: 125., required: true } + X_TS_init: { value: 125.0009, required: true } }, inputs: 1, outputs: 1, diff --git a/dependencies/reactor_class.js b/dependencies/reactor_class.js index dcc5cfd..f1695e7 100644 --- a/dependencies/reactor_class.js +++ b/dependencies/reactor_class.js @@ -65,7 +65,7 @@ class Reactor_CSTR { const dC_total = math.multiply(math.add(dC_in, dC_out, r, t_O), time_step); - this.state = math.add(this.state, dC_total); + this.state = math.abs(math.add(this.state, dC_total)); // make sure that concentrations do not go negative return this.state; } } From 85df04e2156f2e35625557354c2924d2e7938fc3 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Thu, 19 Jun 2025 00:16:54 +0200 Subject: [PATCH 3/3] Fix major bug in calculation of dC_out in tick_fe method to account for outflow --- dependencies/reactor_class.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies/reactor_class.js b/dependencies/reactor_class.js index f1695e7..db8b3bb 100644 --- a/dependencies/reactor_class.js +++ b/dependencies/reactor_class.js @@ -59,7 +59,7 @@ class Reactor_CSTR { tick_fe(time_step) { // tick reactor state using forward Euler method const r = this.asm.compute_dC(this.state); const dC_in = math.multiply(math.divide([this.Fs], this.Vl), this.Cs_in)[0]; - const dC_out = math.multiply(math.sum(this.Fs)/this.Vl, this.state); + const dC_out = math.multiply(-1*math.sum(this.Fs)/this.Vl, this.state); const t_O = Array(13).fill(0.0); t_O[0] = isNaN(this.kla) ? this.OTR : this.calcOTR(this.state[0]); // calculate OTR if kla is not NaN, otherwise use externaly calculated OTR