const { Reactor_CSTR, Reactor_PFR } = require('./reactor_class.js'); class nodeClass { /** * Create a ReactorNode. * @param {object} uiConfig - Node-RED node configuration. * @param {object} RED - Node-RED runtime API. * @param {object} nodeInstance - The Node-RED node instance. * @param {string} nameOfNode - The name of the node, used for */ constructor(uiConfig, RED, nodeInstance, nameOfNode) { // Preserve RED reference for HTTP endpoints if needed this.node = nodeInstance; this.RED = RED; this.name = nameOfNode; this._setupClass(uiConfig, this.node); this._attachInputHandler(); } _attachInputHandler() { // Handle input messages this.node.on('input', function(msg, send, done) { let toggleUpdate = false; switch (msg.topic) { case "clock": toggleUpdate = true; break; case "Fluent": this.reactor.setInfluent = msg; if (msg.payload.inlet == 0) { toggleUpdate = true; } break; case "OTR": this.reactor.setOTR = msg; break; case "Dispersion": this.reactor.setDispersion = msg; break; default: console.log("Unknown topic: " + msg.topic); } if (toggleUpdate) { this.reactor.updateState(msg.timestamp); send(this.reactor.getEffluent); } if (done) { done(); } }); } _setupClass(uiConfig, node) { let new_reactor; switch (uiConfig.reactor_type) { case "CSTR": new_reactor = new Reactor_CSTR( parseFloat(uiConfig.volume), parseInt(uiConfig.n_inlets), parseFloat(uiConfig.kla), [ 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; case "PFR": new_reactor = new Reactor_PFR( parseFloat(uiConfig.volume), parseFloat(uiConfig.length), parseInt(uiConfig.resolution_L), parseInt(uiConfig.n_inlets), parseFloat(uiConfig.kla), [ 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; default: console.warn("Unknown reactor type: " + uiConfig.reactor_type); } node.reactor = new_reactor; // protect from reassignment } } module.exports = nodeClass;