Refactor nodeClass to streamline configuration loading and reactor setup
This commit is contained in:
@@ -3,11 +3,11 @@ const { Reactor_CSTR, Reactor_PFR } = require('./reactor_class.js');
|
|||||||
|
|
||||||
class nodeClass {
|
class nodeClass {
|
||||||
/**
|
/**
|
||||||
* Create a ReactorNode.
|
* Create ReactorNode.
|
||||||
* @param {object} uiConfig - Node-RED node configuration.
|
* @param {object} uiConfig - Node-RED node configuration
|
||||||
* @param {object} RED - Node-RED runtime API.
|
* @param {object} RED - Node-RED runtime API
|
||||||
* @param {object} nodeInstance - The Node-RED node instance.
|
* @param {object} nodeInstance - Node-RED node instance
|
||||||
* @param {string} nameOfNode - The name of the node, used for
|
* @param {string} nameOfNode - Name of the node
|
||||||
*/
|
*/
|
||||||
constructor(uiConfig, RED, nodeInstance, nameOfNode) {
|
constructor(uiConfig, RED, nodeInstance, nameOfNode) {
|
||||||
// Preserve RED reference for HTTP endpoints if needed
|
// Preserve RED reference for HTTP endpoints if needed
|
||||||
@@ -15,14 +15,16 @@ class nodeClass {
|
|||||||
this.RED = RED;
|
this.RED = RED;
|
||||||
this.name = nameOfNode;
|
this.name = nameOfNode;
|
||||||
|
|
||||||
this._setupClass(uiConfig);
|
this._loadConfig(uiConfig)
|
||||||
|
|
||||||
|
this._setupClass();
|
||||||
|
|
||||||
this._attachInputHandler();
|
this._attachInputHandler();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_attachInputHandler() { // Handle input messages
|
_attachInputHandler() { // Handle input messages
|
||||||
this.node.on('input', function(msg, send, done) {
|
this.node.on('input', (msg, send, done) => {
|
||||||
let toggleUpdate = false;
|
let toggleUpdate = false;
|
||||||
|
|
||||||
switch (msg.topic) {
|
switch (msg.topic) {
|
||||||
@@ -56,54 +58,52 @@ class nodeClass {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_setupClass(uiConfig) {
|
_loadConfig(uiConfig) {
|
||||||
|
this.config = {
|
||||||
|
reactor_type: uiConfig.reactor_type,
|
||||||
|
volume: parseFloat(uiConfig.volume),
|
||||||
|
length: parseFloat(uiConfig.length),
|
||||||
|
resolution_L: parseInt(uiConfig.resolution_L),
|
||||||
|
n_inlets: parseInt(uiConfig.n_inlets),
|
||||||
|
kla: parseFloat(uiConfig.kla),
|
||||||
|
initialState: [
|
||||||
|
parseFloat(uiConfig.S_O_init),
|
||||||
|
parseFloat(uiConfig.S_I_init),
|
||||||
|
parseFloat(uiConfig.S_S_init),
|
||||||
|
parseFloat(uiConfig.S_NH_init),
|
||||||
|
parseFloat(uiConfig.S_N2_init),
|
||||||
|
parseFloat(uiConfig.S_NO_init),
|
||||||
|
parseFloat(uiConfig.S_HCO_init),
|
||||||
|
parseFloat(uiConfig.X_I_init),
|
||||||
|
parseFloat(uiConfig.X_S_init),
|
||||||
|
parseFloat(uiConfig.X_H_init),
|
||||||
|
parseFloat(uiConfig.X_STO_init),
|
||||||
|
parseFloat(uiConfig.X_A_init),
|
||||||
|
parseFloat(uiConfig.X_TS_init)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_setupClass() {
|
||||||
let new_reactor;
|
let new_reactor;
|
||||||
|
|
||||||
switch (uiConfig.reactor_type) {
|
switch (this.config.reactor_type) {
|
||||||
case "CSTR":
|
case "CSTR":
|
||||||
new_reactor = new Reactor_CSTR(
|
new_reactor = new Reactor_CSTR(
|
||||||
parseFloat(uiConfig.volume),
|
this.config.volume,
|
||||||
parseInt(uiConfig.n_inlets),
|
this.config.n_inlets,
|
||||||
parseFloat(uiConfig.kla),
|
this.config.kla,
|
||||||
[
|
this.config.initialState
|
||||||
parseFloat(uiConfig.S_O_init),
|
|
||||||
parseFloat(uiConfig.S_I_init),
|
|
||||||
parseFloat(uiConfig.S_S_init),
|
|
||||||
parseFloat(uiConfig.S_NH_init),
|
|
||||||
parseFloat(uiConfig.S_N2_init),
|
|
||||||
parseFloat(uiConfig.S_NO_init),
|
|
||||||
parseFloat(uiConfig.S_HCO_init),
|
|
||||||
parseFloat(uiConfig.X_I_init),
|
|
||||||
parseFloat(uiConfig.X_S_init),
|
|
||||||
parseFloat(uiConfig.X_H_init),
|
|
||||||
parseFloat(uiConfig.X_STO_init),
|
|
||||||
parseFloat(uiConfig.X_A_init),
|
|
||||||
parseFloat(uiConfig.X_TS_init)
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case "PFR":
|
case "PFR":
|
||||||
new_reactor = new Reactor_PFR(
|
new_reactor = new Reactor_PFR(
|
||||||
parseFloat(uiConfig.volume),
|
this.config.volume,
|
||||||
parseFloat(uiConfig.length),
|
this.config.length,
|
||||||
parseInt(uiConfig.resolution_L),
|
this.config.resolution_L,
|
||||||
parseInt(uiConfig.n_inlets),
|
this.config.n_inlets,
|
||||||
parseFloat(uiConfig.kla),
|
this.config.kla,
|
||||||
[
|
this.config.initialState
|
||||||
parseFloat(uiConfig.S_O_init),
|
|
||||||
parseFloat(uiConfig.S_I_init),
|
|
||||||
parseFloat(uiConfig.S_S_init),
|
|
||||||
parseFloat(uiConfig.S_NH_init),
|
|
||||||
parseFloat(uiConfig.S_N2_init),
|
|
||||||
parseFloat(uiConfig.S_NO_init),
|
|
||||||
parseFloat(uiConfig.S_HCO_init),
|
|
||||||
parseFloat(uiConfig.X_I_init),
|
|
||||||
parseFloat(uiConfig.X_S_init),
|
|
||||||
parseFloat(uiConfig.X_H_init),
|
|
||||||
parseFloat(uiConfig.X_STO_init),
|
|
||||||
parseFloat(uiConfig.X_A_init),
|
|
||||||
parseFloat(uiConfig.X_TS_init)
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user