Refactor ASM3 constructor to remove state parameter and update compute_dC method to use state directly; add Reactor_CSTR class for reactor simulation with forward Euler method
This commit is contained in:
16
dependencies/asm3_class.js
vendored
16
dependencies/asm3_class.js
vendored
@@ -61,9 +61,8 @@ class ASM3 {
|
|||||||
i_cNO: -1/14 // charge per S_NO [mole H+ g-1 NO3-N]
|
i_cNO: -1/14 // charge per S_NO [mole H+ g-1 NO3-N]
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(state) {
|
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
|
// 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.state = state;
|
|
||||||
this.stoi_matrix = this._initialise_stoi_matrix()
|
this.stoi_matrix = this._initialise_stoi_matrix()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,10 +95,10 @@ class ASM3 {
|
|||||||
return K / (K + c);
|
return K / (K + c);
|
||||||
}
|
}
|
||||||
|
|
||||||
compute_rates(state) { // computes reaction rates. state is optional, if not provided, use class state
|
compute_rates(state) { // computes reaction rates. state is optional
|
||||||
|
|
||||||
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 || this.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;
|
||||||
|
|
||||||
// Hydrolysis
|
// Hydrolysis
|
||||||
@@ -123,12 +122,9 @@ class ASM3 {
|
|||||||
return rates;
|
return rates;
|
||||||
}
|
}
|
||||||
|
|
||||||
compute_dC(dt){ // compute change in concentration over time step dt
|
compute_dC(state){ // compute changes in concentrations
|
||||||
return math.multiply(math.multiply(this.stoi_matrix, this.compute_rates()), dt);
|
return math.multiply(this.stoi_matrix, this.compute_rates(state));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// testing stuff
|
module.exports = ASM3;
|
||||||
const asm3 = new ASM3([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])
|
|
||||||
console.log(asm3.compute_rates())
|
|
||||||
console.log(asm3.compute_dC(0.001))
|
|
||||||
21
dependencies/reactor_class.js
vendored
Normal file
21
dependencies/reactor_class.js
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
const ASM3 = require('./asm3_class')
|
||||||
|
const math = require('mathjs')
|
||||||
|
|
||||||
|
class Reactor_CSTR {
|
||||||
|
|
||||||
|
constructor(initial_state){
|
||||||
|
this.state = initial_state;
|
||||||
|
this.asm = new ASM3();
|
||||||
|
}
|
||||||
|
|
||||||
|
tick_fe(time_step){ // tick reactor state using forward Euler method
|
||||||
|
const delta = this.asm.compute_dC(this.state);
|
||||||
|
this.state = math.add(this.state, math.multiply(delta, time_step));
|
||||||
|
return this.state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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];
|
||||||
|
const Reactor = new Reactor_CSTR(state);
|
||||||
|
console.log(Reactor.tick_fe(0.001));
|
||||||
Reference in New Issue
Block a user