Add typed input fields for reactor length and resolution in advanced-reactor, fixed NaN bug in reactor length
This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -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),
|
||||
|
||||
15
dependencies/reactor_class.js
vendored
15
dependencies/reactor_class.js
vendored
@@ -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};
|
||||
Reference in New Issue
Block a user