Added handles for influent change emitter
This commit is contained in:
@@ -32,12 +32,11 @@ class nodeClass {
|
||||
switch (msg.topic) {
|
||||
case "clock":
|
||||
toggleUpdate = true;
|
||||
this.reactor.updateState(msg.timestamp);
|
||||
send([this.reactor.getEffluent, null, null]);
|
||||
break;
|
||||
case "Fluent":
|
||||
this.reactor.setInfluent = msg;
|
||||
if (msg.payload.inlet == 0) {
|
||||
toggleUpdate = true;
|
||||
}
|
||||
break;
|
||||
case "OTR":
|
||||
this.reactor.setOTR = msg;
|
||||
@@ -58,11 +57,6 @@ class nodeClass {
|
||||
console.log("Unknown topic: " + msg.topic);
|
||||
}
|
||||
|
||||
if (toggleUpdate) {
|
||||
this.reactor.updateState(msg.timestamp);
|
||||
send([this.reactor.getEffluent, null, null]);
|
||||
}
|
||||
|
||||
if (done) {
|
||||
done();
|
||||
}
|
||||
@@ -75,6 +69,14 @@ class nodeClass {
|
||||
*/
|
||||
_loadConfig(uiConfig) {
|
||||
this.config = {
|
||||
general: {
|
||||
name: uiConfig.name || this.name,
|
||||
id: this.node.id,
|
||||
unit: null
|
||||
},
|
||||
functionality: {
|
||||
softwareType: null // should be set in config manager
|
||||
},
|
||||
reactor_type: uiConfig.reactor_type,
|
||||
volume: parseFloat(uiConfig.volume),
|
||||
length: parseFloat(uiConfig.length),
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
const ASM3 = require('./reaction_modules/asm3_class.js');
|
||||
const { create, all } = require('mathjs');
|
||||
const { create, all, isArray } = require('mathjs');
|
||||
const { assertNoNaN } = require('./utils.js');
|
||||
const { childRegistrationUtils, logger, MeasurementContainer } = require('generalFunctions');
|
||||
const EventEmitter = require('events');
|
||||
|
||||
const config = {
|
||||
const mathConfig = {
|
||||
matrix: 'Array' // use Array as the matrix type
|
||||
};
|
||||
|
||||
const math = create(all, config);
|
||||
const math = create(all, mathConfig);
|
||||
|
||||
const S_O_INDEX = 0;
|
||||
const NUM_SPECIES = 13;
|
||||
@@ -20,7 +21,8 @@ class Reactor {
|
||||
*/
|
||||
constructor(config) {
|
||||
// EVOLV stuff
|
||||
this.logger = new logger(); //TODO: attach config
|
||||
this.logger = new logger(undefined, undefined, config.general.name);
|
||||
this.emitter = new EventEmitter();
|
||||
this.measurements = new MeasurementContainer();
|
||||
this.childRegistrationUtils = new childRegistrationUtils(this); // Child registration utility
|
||||
|
||||
@@ -70,6 +72,17 @@ class Reactor {
|
||||
this.OTR = input.payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for effluent data.
|
||||
* @returns {object} Effluent data object (msg), defaults to inlet 0.
|
||||
*/
|
||||
get getEffluent() { // getter for Effluent, defaults to inlet 0
|
||||
if (isArray(this.state.at(-1))) {
|
||||
return { topic: "Fluent", payload: { inlet: 0, F: math.sum(this.Fs), C: this.state.at(-1) }, timestamp: this.currentTime };
|
||||
}
|
||||
return { topic: "Fluent", payload: { inlet: 0, F: math.sum(this.Fs), C: this.state }, timestamp: this.currentTime };
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the oxygen transfer rate (OTR) based on the dissolved oxygen concentration and temperature.
|
||||
* @param {number} S_O - Dissolved oxygen concentration [g O2 m-3].
|
||||
@@ -109,6 +122,7 @@ class Reactor {
|
||||
n += 1;
|
||||
}
|
||||
this.currentTime += n_iter * this.timeStep * day2ms / this.speedUpFactor;
|
||||
this.emitter.emit("stateChanges", this.getEffluent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -123,14 +137,6 @@ class Reactor_CSTR extends Reactor {
|
||||
this.state = config.initialState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for effluent data.
|
||||
* @returns {object} Effluent data object (msg), defaults to inlet 0.
|
||||
*/
|
||||
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 };
|
||||
}
|
||||
|
||||
/**
|
||||
* Tick the reactor state using the forward Euler method.
|
||||
* @param {number} time_step - Time step for the simulation [d].
|
||||
@@ -191,14 +197,6 @@ class Reactor_PFR extends Reactor {
|
||||
this.D = input.payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for effluent data.
|
||||
* @returns {object} Effluent data object (msg), defaults to inlet 0.
|
||||
*/
|
||||
get getEffluent() {
|
||||
return { topic: "Fluent", payload: { inlet: 0, F: math.sum(this.Fs), C: this.state.at(-1) }, timestamp: this.currentTime };
|
||||
}
|
||||
|
||||
updateState(newTime) {
|
||||
super.updateState(newTime);
|
||||
let Pe_local = this.d_x*math.sum(this.Fs)/(this.D*this.A)
|
||||
|
||||
Reference in New Issue
Block a user