Add optional kLa input and calculation to advanced-reactor node
This commit is contained in:
15
dependencies/reactor_class.js
vendored
15
dependencies/reactor_class.js
vendored
@@ -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();
|
||||
@@ -12,6 +12,8 @@ class Reactor_CSTR {
|
||||
this.Fs = Array(n_inlets).fill(0.0); // fluid debits per inlet [m3 d-1]
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user