diff --git a/dependencies/asm3_class.js b/dependencies/asm3_class.js index 1cf4ec0..93c7364 100644 --- a/dependencies/asm3_class.js +++ b/dependencies/asm3_class.js @@ -61,9 +61,8 @@ class ASM3 { 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 - this.state = state; this.stoi_matrix = this._initialise_stoi_matrix() } @@ -96,10 +95,10 @@ class ASM3 { 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 [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; // Hydrolysis @@ -123,12 +122,9 @@ class ASM3 { return rates; } - compute_dC(dt){ // compute change in concentration over time step dt - return math.multiply(math.multiply(this.stoi_matrix, this.compute_rates()), dt); + compute_dC(state){ // compute changes in concentrations + return math.multiply(this.stoi_matrix, this.compute_rates(state)); } } -// testing stuff -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)) \ No newline at end of file +module.exports = ASM3; \ No newline at end of file diff --git a/dependencies/reactor_class.js b/dependencies/reactor_class.js new file mode 100644 index 0000000..04527e8 --- /dev/null +++ b/dependencies/reactor_class.js @@ -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)); \ No newline at end of file