Refactor reactor constructors to accept a config object for improved clarity and maintainability
This commit is contained in:
@@ -99,22 +99,10 @@ class nodeClass {
|
|||||||
|
|
||||||
switch (this.config.reactor_type) {
|
switch (this.config.reactor_type) {
|
||||||
case "CSTR":
|
case "CSTR":
|
||||||
new_reactor = new Reactor_CSTR(
|
new_reactor = new Reactor_CSTR(this.config);
|
||||||
this.config.volume,
|
|
||||||
this.config.n_inlets,
|
|
||||||
this.config.kla,
|
|
||||||
this.config.initialState
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
case "PFR":
|
case "PFR":
|
||||||
new_reactor = new Reactor_PFR(
|
new_reactor = new Reactor_PFR(this.config);
|
||||||
this.config.volume,
|
|
||||||
this.config.length,
|
|
||||||
this.config.resolution_L,
|
|
||||||
this.config.n_inlets,
|
|
||||||
this.config.kla,
|
|
||||||
this.config.initialState
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.warn("Unknown reactor type: " + uiConfig.reactor_type);
|
console.warn("Unknown reactor type: " + uiConfig.reactor_type);
|
||||||
|
|||||||
@@ -9,16 +9,16 @@ const math = create(all, config)
|
|||||||
|
|
||||||
class Reactor {
|
class Reactor {
|
||||||
|
|
||||||
constructor(volume, n_inlets, kla){
|
constructor(config){
|
||||||
this.asm = new ASM3();
|
this.asm = new ASM3();
|
||||||
|
|
||||||
this.Vl = volume; // fluid volume reactor [m3]
|
this.Vl = config.volume; // fluid volume reactor [m3]
|
||||||
|
|
||||||
this.Fs = Array(n_inlets).fill(0.0); // fluid debits per inlet [m3 d-1]
|
this.Fs = Array(config.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.Cs_in = Array.from(Array(config.n_inlets), () => new Array(13).fill(0.0)); // composition influents
|
||||||
this.OTR = 0.0; // oxygen transfer rate [g O2 d-1]
|
this.OTR = 0.0; // oxygen transfer rate [g O2 d-1]
|
||||||
|
|
||||||
this.kla = kla; // if NaN, use external OTR [d-1]
|
this.kla = config.kla; // if NaN, use external OTR [d-1]
|
||||||
|
|
||||||
this.currentTime = Date.now(); // milliseconds since epoch [ms]
|
this.currentTime = Date.now(); // milliseconds since epoch [ms]
|
||||||
this.timeStep = 1/(24*60*15); // time step [d]
|
this.timeStep = 1/(24*60*15); // time step [d]
|
||||||
@@ -48,9 +48,9 @@ class Reactor {
|
|||||||
|
|
||||||
class Reactor_CSTR extends Reactor {
|
class Reactor_CSTR extends Reactor {
|
||||||
|
|
||||||
constructor(volume, n_inlets, kla, initial_state) {
|
constructor(config) {
|
||||||
super(volume, n_inlets, kla);
|
super(config);
|
||||||
this.state = initial_state;
|
this.state = config.initialState;
|
||||||
}
|
}
|
||||||
|
|
||||||
get getEffluent() { // getter for Effluent, defaults to inlet 0
|
get getEffluent() { // getter for Effluent, defaults to inlet 0
|
||||||
@@ -90,16 +90,16 @@ class Reactor_CSTR extends Reactor {
|
|||||||
|
|
||||||
class Reactor_PFR extends Reactor {
|
class Reactor_PFR extends Reactor {
|
||||||
|
|
||||||
constructor(volume, length, resolution_L, n_inlets, kla, initial_state) {
|
constructor(config) {
|
||||||
super(volume, n_inlets, kla);
|
super(config);
|
||||||
|
|
||||||
this.length = length; // reactor length [m]
|
this.length = config.length; // reactor length [m]
|
||||||
this.n_x = resolution_L; // number of slices
|
this.n_x = config.resolution_L; // number of slices
|
||||||
this.d_x = length / resolution_L;
|
|
||||||
|
|
||||||
this.A = volume / length; // crosssectional area [m2]
|
this.d_x = this.length / this.n_x;
|
||||||
|
this.A = this.Vl / this.length; // crosssectional area [m2]
|
||||||
|
|
||||||
this.state = Array.from(Array(this.n_x), () => initial_state.slice())
|
this.state = Array.from(Array(this.n_x), () => config.initialState.slice())
|
||||||
|
|
||||||
// console.log("Initial State: ")
|
// console.log("Initial State: ")
|
||||||
// console.log(this.state)
|
// console.log(this.state)
|
||||||
|
|||||||
Reference in New Issue
Block a user