From 0f912b05e4060029afa53a90e1c223186588f707 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Wed, 9 Jul 2025 10:29:54 +0200 Subject: [PATCH] Add temperature handling --- src/nodeClass.js | 3 +++ src/specificClass.js | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/nodeClass.js b/src/nodeClass.js index 7ec81d3..2e00ced 100644 --- a/src/nodeClass.js +++ b/src/nodeClass.js @@ -42,6 +42,9 @@ class nodeClass { case "OTR": this.reactor.setOTR = msg; break; + case "Temperature": + this.reactor.setTemperature = msg; + break; case "Dispersion": this.reactor.setDispersion = msg; break; diff --git a/src/specificClass.js b/src/specificClass.js index a41acec..efe0f1d 100644 --- a/src/specificClass.js +++ b/src/specificClass.js @@ -25,6 +25,7 @@ class Reactor { this.Fs = Array(config.n_inlets).fill(0); // fluid debits per inlet [m3 d-1] this.Cs_in = Array.from(Array(config.n_inlets), () => new Array(NUM_SPECIES).fill(0)); // composition influents this.OTR = 0.0; // oxygen transfer rate [g O2 d-1] + this.temperature = 20; // temperature [C] this.kla = config.kla; // if NaN, use externaly provided OTR [d-1] @@ -51,6 +52,14 @@ class Reactor { this.OTR = input.payload; } + /** + * Setter for temperature. + * @param {object} input - Input object (msg) containing payload with temperature value [C]. + */ + set setTemperature(input) { + this.temperature = input.payload; + } + /** * Calculate the oxygen transfer rate (OTR) based on the dissolved oxygen concentration and temperature. * @param {number} S_O - Dissolved oxygen concentration [g O2 m-3]. @@ -121,9 +130,9 @@ class Reactor_CSTR extends Reactor { tick(time_step) { // tick reactor state using forward Euler method const inflow = math.multiply(math.divide([this.Fs], this.volume), this.Cs_in)[0]; const outflow = math.multiply(-1 * math.sum(this.Fs) / this.volume, this.state); - const reaction = this.asm.compute_dC(this.state); + const reaction = this.asm.compute_dC(this.state, this.temperature); const transfer = Array(NUM_SPECIES).fill(0.0); - transfer[S_O_INDEX] = isNaN(this.kla) ? this.OTR : this._calcOTR(this.state[S_O_INDEX]); // calculate OTR if kla is not NaN, otherwise use externaly calculated OTR + transfer[S_O_INDEX] = isNaN(this.kla) ? this.OTR : this._calcOTR(this.state[S_O_INDEX], this.temperature); // calculate OTR if kla is not NaN, otherwise use externaly calculated OTR const dC_total = math.multiply(math.add(inflow, outflow, reaction, transfer), time_step) this.state = this._arrayClip2Zero(math.add(this.state, dC_total)); // clip value element-wise to avoid negative concentrations @@ -204,13 +213,13 @@ class Reactor_PFR extends Reactor { tick(time_step) { const dispersion = math.multiply(this.D / (this.d_x*this.d_x), this.D2_op, this.state); const advection = math.multiply(-1 * math.sum(this.Fs) / (this.A*this.d_x), this.D_op, this.state); - const reaction = this.state.map((state_slice) => this.asm.compute_dC(state_slice)); + const reaction = this.state.map((state_slice) => this.asm.compute_dC(state_slice, this.temperature)); const transfer = Array.from(Array(this.n_x), () => new Array(NUM_SPECIES).fill(0)); if (isNaN(this.kla)) { // calculate OTR if kla is not NaN, otherwise use externally calculated OTR transfer.forEach((x) => { x[S_O_INDEX] = this.OTR; }); } else { - transfer.forEach((x, i) => { x[S_O_INDEX] = this._calcOTR(this.state[i][S_O_INDEX]); }); + transfer.forEach((x, i) => { x[S_O_INDEX] = this._calcOTR(this.state[i][S_O_INDEX], this.temperature); }); } const dC_total = math.multiply(math.add(dispersion, advection, reaction, transfer), time_step);