From c239b71ad87b9ee9243a858ab4483e0a803cb19d Mon Sep 17 00:00:00 2001
From: "p.vanderwilt"
Date: Fri, 4 Jul 2025 13:16:49 +0200
Subject: [PATCH] Refactor reactor constructors to accept a config object for
improved clarity and maintainability
---
src/nodeClass.js | 16 ++--------------
src/reactor_class.js | 30 +++++++++++++++---------------
2 files changed, 17 insertions(+), 29 deletions(-)
diff --git a/src/nodeClass.js b/src/nodeClass.js
index 62a6226..15a959b 100644
--- a/src/nodeClass.js
+++ b/src/nodeClass.js
@@ -99,22 +99,10 @@ class nodeClass {
switch (this.config.reactor_type) {
case "CSTR":
- new_reactor = new Reactor_CSTR(
- this.config.volume,
- this.config.n_inlets,
- this.config.kla,
- this.config.initialState
- );
+ new_reactor = new Reactor_CSTR(this.config);
break;
case "PFR":
- new_reactor = new Reactor_PFR(
- this.config.volume,
- this.config.length,
- this.config.resolution_L,
- this.config.n_inlets,
- this.config.kla,
- this.config.initialState
- );
+ new_reactor = new Reactor_PFR(this.config);
break;
default:
console.warn("Unknown reactor type: " + uiConfig.reactor_type);
diff --git a/src/reactor_class.js b/src/reactor_class.js
index a81ff7f..220fbf9 100644
--- a/src/reactor_class.js
+++ b/src/reactor_class.js
@@ -9,16 +9,16 @@ const math = create(all, config)
class Reactor {
- constructor(volume, n_inlets, kla){
+ constructor(config){
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.Cs_in = Array.from(Array(n_inlets), () => new Array(13).fill(0.0)); // composition influents
+ this.Fs = Array(config.n_inlets).fill(0.0); // fluid debits per inlet [m3 d-1]
+ 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.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.timeStep = 1/(24*60*15); // time step [d]
@@ -48,9 +48,9 @@ class Reactor {
class Reactor_CSTR extends Reactor {
- constructor(volume, n_inlets, kla, initial_state) {
- super(volume, n_inlets, kla);
- this.state = initial_state;
+ constructor(config) {
+ super(config);
+ this.state = config.initialState;
}
get getEffluent() { // getter for Effluent, defaults to inlet 0
@@ -90,16 +90,16 @@ class Reactor_CSTR extends Reactor {
class Reactor_PFR extends Reactor {
- constructor(volume, length, resolution_L, n_inlets, kla, initial_state) {
- super(volume, n_inlets, kla);
+ constructor(config) {
+ super(config);
- this.length = length; // reactor length [m]
- this.n_x = resolution_L; // number of slices
- this.d_x = length / resolution_L;
+ this.length = config.length; // reactor length [m]
+ this.n_x = config.resolution_L; // number of slices
- 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(this.state)