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

@@ -40,6 +40,14 @@
type:"num",
types:["num"]
});
$("#node-input-length").typedInput({
type:"num",
types:["num"]
});
$("#node-input-resolution_L").typedInput({
type:"num",
types:["num"]
});
$("#node-input-kla").typedInput({
type:"num",
types:["num"]

View File

@@ -5,13 +5,13 @@ module.exports = function(RED) {
let name = config.name;
const Reactor = require('./dependencies/reactor_class');
const { Reactor_CSTR, Reactor_PFR } = require('./dependencies/reactor_class');
let new_reactor;
switch (config.reactor_type) {
case "CSTR":
new_reactor = new Reactor(
new_reactor = new Reactor_CSTR(
parseFloat(config.volume),
parseInt(config.n_inlets),
parseFloat(config.kla),
@@ -33,9 +33,9 @@ module.exports = function(RED) {
);
break;
case "PFR":
new_reactor = new Reactor(
new_reactor = new Reactor_PFR(
parseFloat(config.volume),
parseFloat(config.L),
parseFloat(config.length),
parseInt(config.resolution_L),
parseInt(config.n_inlets),
parseFloat(config.kla),

View File

@@ -88,15 +88,18 @@ class Reactor_PFR {
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,7 +148,7 @@ 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));
@@ -202,4 +205,4 @@ class Reactor_PFR {
// N += 1;
// }
module.exports = Reactor_CSTR;
module.exports = {Reactor_CSTR, Reactor_PFR};