Fix structure and improve comments in ASM3 and Reactor_CSTR classes
This commit is contained in:
4
dependencies/asm3_class.js
vendored
4
dependencies/asm3_class.js
vendored
@@ -65,7 +65,7 @@ class ASM3 {
|
|||||||
this.stoi_matrix = this._initialise_stoi_matrix()
|
this.stoi_matrix = this._initialise_stoi_matrix()
|
||||||
}
|
}
|
||||||
|
|
||||||
_initialise_stoi_matrix(){ // initialise stoichiometric matrix
|
_initialise_stoi_matrix() { // initialise stoichiometric matrix
|
||||||
const { f_SI, f_XI, Y_STO_O, Y_STO_NO, Y_H_O, Y_H_NO, Y_A, i_CODN, i_CODNO, i_NSI, i_NSS, i_NXI, i_NXS, i_NBM, i_TSXI, i_TSXS, i_TSBM, i_TSSTO, i_cNH, i_cNO } = this.stoi_params;
|
const { f_SI, f_XI, Y_STO_O, Y_STO_NO, Y_H_O, Y_H_NO, Y_A, i_CODN, i_CODNO, i_NSI, i_NSS, i_NXI, i_NXS, i_NBM, i_TSXI, i_TSXS, i_TSBM, i_TSSTO, i_cNH, i_cNO } = this.stoi_params;
|
||||||
|
|
||||||
const stoi_matrix = Array(12);
|
const stoi_matrix = Array(12);
|
||||||
@@ -121,7 +121,7 @@ class ASM3 {
|
|||||||
return rates;
|
return rates;
|
||||||
}
|
}
|
||||||
|
|
||||||
compute_dC(state){ // compute changes in concentrations
|
compute_dC(state) { // compute changes in concentrations
|
||||||
// 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
|
||||||
return math.multiply(this.stoi_matrix, this.compute_rates(state));
|
return math.multiply(this.stoi_matrix, this.compute_rates(state));
|
||||||
}
|
}
|
||||||
|
|||||||
22
dependencies/reactor_class.js
vendored
22
dependencies/reactor_class.js
vendored
@@ -3,17 +3,31 @@ const math = require('mathjs')
|
|||||||
|
|
||||||
class Reactor_CSTR {
|
class Reactor_CSTR {
|
||||||
|
|
||||||
constructor(initial_state){
|
constructor(initial_state) {
|
||||||
this.state = initial_state;
|
this.state = initial_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 = Array(13).fill(0.0); // composition influent
|
||||||
this.OTR = 1000.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.timeStep = 1/(24*60) // time step [d]
|
||||||
}
|
}
|
||||||
|
|
||||||
tick_fe(time_step){ // tick reactor state using forward Euler method
|
// expect update with timestamp
|
||||||
|
updateState(input) {
|
||||||
|
throw new Error("Not implemented yet");
|
||||||
|
|
||||||
|
let newTime = input.payload;
|
||||||
|
|
||||||
|
const day2ms = 1000 * 60 * 60 * 24;
|
||||||
|
|
||||||
|
let n_iter = (newTime - this.currentTime) % (this.timeStep * day2ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
tick_fe(time_step) { // tick reactor state using forward Euler method
|
||||||
const r = this.asm.compute_dC(this.state);
|
const r = this.asm.compute_dC(this.state);
|
||||||
const dC_in = math.multiply(this.C_in, this.F/this.Vl);
|
const dC_in = math.multiply(this.C_in, this.F/this.Vl);
|
||||||
const dC_out = math.multiply(this.state, this.F/this.Vl);
|
const dC_out = math.multiply(this.state, this.F/this.Vl);
|
||||||
@@ -33,7 +47,7 @@ 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,
|
|||||||
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 < 15) {
|
while (N < 500) {
|
||||||
console.log(Reactor.tick_fe(0.001));
|
console.log(Reactor.tick_fe(0.001));
|
||||||
N += 1;
|
N += 1;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user