From 6b57a46aabd54511c7f3db31b9d480062bb18272 Mon Sep 17 00:00:00 2001
From: "p.vanderwilt"
Date: Tue, 24 Jun 2025 12:32:11 +0200
Subject: [PATCH] Add typed input fields for reactor length and resolution in
advanced-reactor, fixed NaN bug in reactor length
---
advanced-reactor.html | 8 ++++++++
advanced-reactor.js | 8 ++++----
dependencies/reactor_class.js | 15 +++++++++------
3 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/advanced-reactor.html b/advanced-reactor.html
index 5b4d41b..512f3dd 100644
--- a/advanced-reactor.html
+++ b/advanced-reactor.html
@@ -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"]
diff --git a/advanced-reactor.js b/advanced-reactor.js
index 68e9674..8348137 100644
--- a/advanced-reactor.js
+++ b/advanced-reactor.js
@@ -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),
diff --git a/dependencies/reactor_class.js b/dependencies/reactor_class.js
index af3289e..4027690 100644
--- a/dependencies/reactor_class.js
+++ b/dependencies/reactor_class.js
@@ -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;
\ No newline at end of file
+module.exports = {Reactor_CSTR, Reactor_PFR};
\ No newline at end of file