From 333efcda5299d9520e7d68baedfed0fda6092bba Mon Sep 17 00:00:00 2001
From: "p.vanderwilt"
Date: Thu, 5 Jun 2025 17:23:51 +0200
Subject: [PATCH] Add optional state parameter to compute_rates, improve
comments, and implement compute_dC method
---
dependencies/asm3_class.js | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/dependencies/asm3_class.js b/dependencies/asm3_class.js
index 6aea036..1cf4ec0 100644
--- a/dependencies/asm3_class.js
+++ b/dependencies/asm3_class.js
@@ -1,3 +1,5 @@
+const math = require('mathjs')
+
class ASM3 {
kin_params = {
@@ -65,7 +67,7 @@ class ASM3 {
this.stoi_matrix = this._initialise_stoi_matrix()
}
- _initialise_stoi_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 stoi_matrix = Array(12);
@@ -94,9 +96,10 @@ class ASM3 {
return K / (K + c);
}
- compute_rates() {
+ compute_rates(state) { // computes reaction rates. state is optional, if not provided, use class state
+
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] = 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 || this.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
@@ -119,8 +122,13 @@ 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);
+ }
}
// 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())
\ No newline at end of file
+console.log(asm3.compute_rates())
+console.log(asm3.compute_dC(0.001))
\ No newline at end of file