Fixed bugs and hard coded config for now.
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
category: 'WWTP',
|
category: 'WWTP',
|
||||||
color: '#c4cce0',
|
color: '#c4cce0',
|
||||||
defaults: {
|
defaults: {
|
||||||
name: {value:""}
|
name: { value: "" },
|
||||||
},
|
},
|
||||||
inputs: 1,
|
inputs: 1,
|
||||||
outputs: 1,
|
outputs: 1,
|
||||||
|
|||||||
@@ -5,9 +5,18 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
let name = config.name;
|
let name = config.name;
|
||||||
|
|
||||||
node.on('input', function(msg) {
|
const Reactor = require('./dependencies/reactor_class');
|
||||||
msg.payload = msg.payload.toLowerCase();
|
|
||||||
node.send(msg);
|
const reactor = new Reactor(Array(13).fill(0.001));
|
||||||
|
|
||||||
|
node.on('input', function(msg, send, done) {
|
||||||
|
if (msg.topic == "clock") {
|
||||||
|
reactor.updateState(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (done) {
|
||||||
|
done();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("advanced-reactor", reactor);
|
RED.nodes.registerType("advanced-reactor", reactor);
|
||||||
|
|||||||
36
dependencies/reactor_class.js
vendored
36
dependencies/reactor_class.js
vendored
@@ -5,26 +5,34 @@ class Reactor_CSTR {
|
|||||||
|
|
||||||
constructor(initial_state) {
|
constructor(initial_state) {
|
||||||
this.state = initial_state;
|
this.state = initial_state;
|
||||||
|
console.log(this.state);
|
||||||
this.asm = new ASM3();
|
this.asm = new ASM3();
|
||||||
|
|
||||||
this.Vl = 10.0; // fluid volume reactor [m3]
|
this.Vl = 10.0; // fluid volume reactor [m3]
|
||||||
this.F = 1.0; // fluid debit [m3 d-1]
|
this.F = 1.0; // fluid debit [m3 d-1]
|
||||||
this.C_in = Array(13).fill(0.0); // composition influent
|
this.C_in = [0., 30., 100., 16., 0., 0., 5., 25., 75., 30., 0., 0., 125.]; // composition influent
|
||||||
this.OTR = 100.0; // oxygen transfer rate [g O2 d-1]
|
this.OTR = 100.0; // oxygen transfer rate [g O2 d-1]
|
||||||
|
|
||||||
this.currentTime = Date.now(); // milliseconds since epoch [ms]
|
this.currentTime = Date.now(); // milliseconds since epoch [ms]
|
||||||
this.timeStep = 1/(24*60) // time step [d]
|
this.timeStep = 1/(24*60*15) // time step [d]
|
||||||
}
|
}
|
||||||
|
|
||||||
// expect update with timestamp
|
// expect update with timestamp
|
||||||
updateState(input) {
|
updateState(input) {
|
||||||
throw new Error("Not implemented yet");
|
|
||||||
|
|
||||||
let newTime = input.payload;
|
let newTime = input.payload;
|
||||||
|
|
||||||
const day2ms = 1000 * 60 * 60 * 24;
|
const day2ms = 1000 * 60 * 60 * 24;
|
||||||
|
|
||||||
let n_iter = (newTime - this.currentTime) % (this.timeStep * day2ms);
|
let n_iter = Math.floor((newTime - this.currentTime) / (this.timeStep * day2ms));
|
||||||
|
if (n_iter > 0) {
|
||||||
|
let n = 0;
|
||||||
|
while (n < n_iter) {
|
||||||
|
console.log(this.tick_fe(this.timeStep));
|
||||||
|
n += 1;
|
||||||
|
}
|
||||||
|
this.currentTime += n_iter * this.timeStep * day2ms;
|
||||||
|
n_iter = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tick_fe(time_step) { // tick reactor state using forward Euler method
|
tick_fe(time_step) { // tick reactor state using forward Euler method
|
||||||
@@ -43,11 +51,13 @@ class Reactor_CSTR {
|
|||||||
|
|
||||||
// testing stuff
|
// testing stuff
|
||||||
// state: S_O, S_I, S_S, S_NH, S_N2, S_NO, S_HCO, X_I, X_S, X_H, X_STO, X_A, X_TS
|
// state: S_O, S_I, S_S, S_NH, S_N2, S_NO, S_HCO, X_I, X_S, X_H, X_STO, X_A, X_TS
|
||||||
let initial_state = [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1];
|
// let initial_state = [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1];
|
||||||
const Reactor = new Reactor_CSTR(initial_state);
|
// const Reactor = new Reactor_CSTR(initial_state);
|
||||||
Reactor.C_in = [0.0, 30., 100., 16., 0., 0., 5., 25., 75., 30., 0., 0., 125.];
|
// Reactor.C_in = [0.0, 30., 100., 16., 0., 0., 5., 25., 75., 30., 0., 0., 125.];
|
||||||
N = 0;
|
// N = 0;
|
||||||
while (N < 500) {
|
// while (N < 500) {
|
||||||
console.log(Reactor.tick_fe(0.001));
|
// console.log(Reactor.tick_fe(0.001));
|
||||||
N += 1;
|
// N += 1;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
module.exports = Reactor_CSTR;
|
||||||
Reference in New Issue
Block a user