Add typed input fields for reactor length and resolution in advanced-reactor, fixed NaN bug in reactor length

This commit is contained in:
2025-06-24 12:32:11 +02:00
parent e5c9010093
commit 6b57a46aab
3 changed files with 21 additions and 10 deletions

View File

@@ -87,16 +87,19 @@ class Reactor_PFR {
this.A = volume / length; // crosssectional area [m2]
this.state = Array.from(Array(this.n_x), () => initial_state.slice())
// console.log("Initial State: ")
// console.log(this.state)
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.D = 0.0; // axial dispersion [m2 d-1]
this.D = 0.1; // axial dispersion [m2 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]
this.timeStep = 1/(24*60*60); // time step [d]
this.speedUpFactor = 1;
this.D_op = this.makeDoperator();
@@ -118,7 +121,7 @@ class Reactor_PFR {
}
get getEffluent() { // getter for Effluent, defaults to inlet 0
return {topic: "Fluent", payload: {inlet: 0, F: math.sum(this.Fs), C:this.state}, timestamp: this.currentTime};
return {topic: "Fluent", payload: {inlet: 0, F: math.sum(this.Fs), C:this.state.at(-1)}, timestamp: this.currentTime};
}
calcOTR(S_O, T=20.0) { // caculate the OTR using basic correlation, default to temperature: 20 C
@@ -145,10 +148,10 @@ class Reactor_PFR {
tick_fe(time_step) { // tick reactor state using forward Euler method
const dispersion = math.multiply(this.D / (this.d_x*this.d_x), this.D2_op, this.state);
const advection = math.multiply(math.sum(this.Fs)/(this.A*this.d_x), this.D_op, this.state);
const reaction = this.state.map((row) => this.asm.compute_dC(row));
const reaction = this.state.map((state_slice) => this.asm.compute_dC(state_slice));
reaction[0] = Array(13).fill(0.0);
const transfer = Array.from(Array(this.n_x), () => new Array(13).fill(0.0));
if (isNaN(this.kla)) { // calculate OTR if kla is not NaN, otherwise use externally calculated OTR
transfer.forEach((x) => { x[0] = this.OTR; });
} else {
@@ -202,4 +205,4 @@ class Reactor_PFR {
// N += 1;
// }
module.exports = Reactor_CSTR;
module.exports = {Reactor_CSTR, Reactor_PFR};