Expand reactor class to build a simple CSTR model. Moved some functionality from asm3_class to reactor.
This commit is contained in:
4
dependencies/asm3_class.js
vendored
4
dependencies/asm3_class.js
vendored
@@ -62,7 +62,6 @@ class ASM3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// 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
|
|
||||||
this.stoi_matrix = this._initialise_stoi_matrix()
|
this.stoi_matrix = this._initialise_stoi_matrix()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +95,7 @@ class ASM3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compute_rates(state) { // computes reaction rates. state is optional
|
compute_rates(state) { // computes reaction rates. state is optional
|
||||||
|
// 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
|
||||||
const rates = Array(12);
|
const rates = Array(12);
|
||||||
const [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;
|
const [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;
|
||||||
const { k_H, K_X, k_STO, nu_NO, K_O, K_NO, K_S, K_STO, mu_H_max, K_NH, K_HCO, b_H_O, b_H_NO, b_STO_O, b_STO_NO, mu_A_max, K_A_NH, K_A_O, K_A_HCO, b_A_O, b_A_NO } = this.kin_params;
|
const { k_H, K_X, k_STO, nu_NO, K_O, K_NO, K_S, K_STO, mu_H_max, K_NH, K_HCO, b_H_O, b_H_NO, b_STO_O, b_STO_NO, mu_A_max, K_A_NH, K_A_O, K_A_HCO, b_A_O, b_A_NO } = this.kin_params;
|
||||||
@@ -123,6 +122,7 @@ class ASM3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
return math.multiply(this.stoi_matrix, this.compute_rates(state));
|
return math.multiply(this.stoi_matrix, this.compute_rates(state));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
dependencies/reactor_class.js
vendored
26
dependencies/reactor_class.js
vendored
@@ -6,16 +6,34 @@ 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.F = 1.0; // fluid debit [m3 d-1]
|
||||||
|
this.C_in = Array(13).fill(0.0); // composition influent
|
||||||
|
this.OTR = 1000.0; // oxygen transfer rate [g O2 d-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
tick_fe(time_step){ // tick reactor state using forward Euler method
|
tick_fe(time_step){ // tick reactor state using forward Euler method
|
||||||
const delta = this.asm.compute_dC(this.state);
|
const r = this.asm.compute_dC(this.state);
|
||||||
this.state = math.add(this.state, math.multiply(delta, time_step));
|
const dC_in = math.multiply(this.C_in, this.F/this.Vl);
|
||||||
|
const dC_out = math.multiply(this.state, this.F/this.Vl);
|
||||||
|
const T_O = Array(13).fill(0.0);
|
||||||
|
T_O[0] = this.OTR;
|
||||||
|
|
||||||
|
const dC_total = math.multiply(math.add(dC_in, dC_out, r, T_O), time_step);
|
||||||
|
|
||||||
|
this.state = math.add(this.state, dC_total);
|
||||||
return this.state;
|
return this.state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// testing stuff
|
// testing stuff
|
||||||
let 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];
|
// 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
|
||||||
const Reactor = new Reactor_CSTR(state);
|
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);
|
||||||
|
Reactor.C_in = [0.0, 30., 100., 16., 0., 0., 5., 25., 75., 30., 0., 0., 125.];
|
||||||
|
N = 0;
|
||||||
|
while (N < 15) {
|
||||||
console.log(Reactor.tick_fe(0.001));
|
console.log(Reactor.tick_fe(0.001));
|
||||||
|
N += 1;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user