Add optional kLa input and calculation to advanced-reactor node

This commit is contained in:
2025-06-17 11:13:38 +02:00
parent c8c588600c
commit 1da7a9f602
3 changed files with 22 additions and 4 deletions

View File

@@ -6,6 +6,7 @@
name: { value: "" },
volume: { value: 0., required: true},
n_inlets: { value: 1, required: true},
kla: { value: null },
S_O_init: { value: 0., required: true },
S_I_init: { value: 30., required: true },
S_S_init: { value: 100., required: true },
@@ -36,6 +37,10 @@
type:"num",
types:["num"]
});
$("#node-input-kla").typedInput({
type:"num",
types:["num"]
});
$(".concentrations").typedInput({
type:"num",
types:["num"]
@@ -68,6 +73,11 @@
<label for="node-input-n_inlets"><i class="fa fa-tag"></i> Number of inlets</label>
<input type="text" id="node-input-n_inlets" placeholder="#">
</div>
<h3> Internal mass transfer calculation (optional) </h3>
<div class="form-row">
<label for="node-input-kla"><i class="fa fa-tag"></i> kLa [d-1]</label>
<input type="text" id="node-input-kla" placeholder="d-1">
</div>
<h2> Dissolved components </h2>
<div class="form-row">
<label for="node-input-S_O_init"><i class="fa fa-tag"></i> Initial dissolved oxygen [g O2 m-3]</label>

View File

@@ -10,6 +10,7 @@ module.exports = function(RED) {
const reactor = new Reactor(
parseFloat(config.volume),
parseInt(config.n_inlets),
parseFloat(config.kla),
[
parseFloat(config.S_O_init),
parseFloat(config.S_I_init),

View File

@@ -3,7 +3,7 @@ const math = require('mathjs')
class Reactor_CSTR {
constructor(volume, n_inlets, initial_state) {
constructor(volume, n_inlets, kla, initial_state) {
this.state = initial_state;
console.log(this.state);
this.asm = new ASM3();
@@ -13,6 +13,8 @@ class Reactor_CSTR {
this.Cs_in = Array.from(Array(n_inlets), () => new Array(13).fill(0.0)); // composition influents
this.OTR = 0.0; // oxygen transfer rate [g O2 d-1]
this.kla = kla; // if NaN, use external OTR [d-1]
this.currentTime = Date.now(); // milliseconds since epoch [ms]
this.timeStep = 1/(24*60*15) // time step [d]
}
@@ -31,6 +33,11 @@ class Reactor_CSTR {
return {topic: "Fluent", payload: {inlet: 0, F: math.sum(this.Fs), C:this.state}, timestamp: this.currentTime};
}
calcOTR(S_O, T=20.0) { // caculate the OTR using basic correlation, default to temperature: 20 C
let S_O_sat = 14.652 - 4.1022e-1*T + 7.9910e-3*T*T + 7.7774e-5*T*T*T;
return this.kla * (S_O_sat - S_O);
}
// expect update with timestamp
updateState(timestamp) {
let newTime = timestamp;
@@ -53,10 +60,10 @@ class Reactor_CSTR {
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 T_O = Array(13).fill(0.0);
T_O[0] = this.OTR;
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
const dC_total = math.multiply(math.add(dC_in, dC_out, r, T_O), time_step);
const dC_total = math.multiply(math.add(dC_in, dC_out, r, t_O), time_step);
this.state = math.add(this.state, dC_total);
return this.state;