From 5bd094f4a695c586e37b0fbe5f2abc852341b362 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Wed, 18 Jun 2025 12:34:19 +0200 Subject: [PATCH] Prevent negative values in reactor state --- advanced-reactor.html | 2 +- dependencies/reactor_class.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced-reactor.html b/advanced-reactor.html index ff12949..73d66c2 100644 --- a/advanced-reactor.html +++ b/advanced-reactor.html @@ -19,7 +19,7 @@ X_H_init: { value: 30., required: true }, X_STO_init: { value: 0., required: true }, X_A_init: { value: 0.001, required: true }, - X_TS_init: { value: 125., required: true } + X_TS_init: { value: 125.0009, required: true } }, inputs: 1, outputs: 1, diff --git a/dependencies/reactor_class.js b/dependencies/reactor_class.js index dcc5cfd..f1695e7 100644 --- a/dependencies/reactor_class.js +++ b/dependencies/reactor_class.js @@ -65,7 +65,7 @@ class Reactor_CSTR { const dC_total = math.multiply(math.add(dC_in, dC_out, r, t_O), time_step); - this.state = math.add(this.state, dC_total); + this.state = math.abs(math.add(this.state, dC_total)); // make sure that concentrations do not go negative return this.state; } }