From dd70b8c89040d4533d9ca8440fde3f311aaa968e Mon Sep 17 00:00:00 2001
From: "p.vanderwilt"
Date: Fri, 21 Nov 2025 11:02:40 +0100
Subject: [PATCH] Fix CSTR PFR distinctions
---
src/specificClass.js | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/src/specificClass.js b/src/specificClass.js
index e836197..fc31fdc 100644
--- a/src/specificClass.js
+++ b/src/specificClass.js
@@ -164,10 +164,6 @@ class Reactor {
this.logger.warn("Reactor children of reactors should always be upstream.");
}
- if (math.abs(reactorChild.d_x - this.d_x) / this.d_x < 0.025) {
- this.logger.warn("Significant grid sizing discrepancies between adjacent reactors! Change resolutions to match reactors grid step, or implement boundary value interpolation.");
- }
-
// set upstream and downstream reactor variable in current and child nodes respectively for easy access
this.upstreamReactor = reactorChild;
reactorChild.downstreamReactor = this;
@@ -245,6 +241,23 @@ class Reactor_CSTR extends Reactor {
this.state = config.initialState;
}
+ _updateMeasurement(measurementType, value, position, context) {
+
+ switch(measurementType) {
+ case "quantity (oxygen)":
+ this.state[ASM_CONSTANTS.S_O_INDEX] = value;
+ break;
+ case "quantity (ammonium)":
+ this.state[ASM_CONSTANTS.S_NH_INDEX] = value;
+ break;
+ case "quantity (nox)":
+ this.state[ASM_CONSTANTS.S_NO_INDEX] = value;
+ break;
+ default:
+ super._updateMeasurement(measurementType, value, position, context);
+ }
+ }
+
/**
* Tick the reactor state using the forward Euler method.
* @param {number} time_step - Time step for the simulation [d].
@@ -255,7 +268,7 @@ class Reactor_CSTR extends Reactor {
const outflow = math.multiply(-1 * math.sum(this.Fs) / this.volume, this.state);
const reaction = this.asm.compute_dC(this.state, this.temperature);
const transfer = Array(ASM_CONSTANTS.NUM_SPECIES).fill(0.0);
- transfer[ASM_CONSTANTS.S_O_INDEX] = isNaN(this.kla) ? this.OTR : this._calcOTR(this.state[S_O_INDEX], this.temperature); // calculate OTR if kla is not NaN, otherwise use externaly calculated OTR
+ transfer[ASM_CONSTANTS.S_O_INDEX] = isNaN(this.kla) ? this.OTR : this._calcOTR(this.state[ASM_CONSTANTS.S_O_INDEX], this.temperature); // calculate OTR if kla is not NaN, otherwise use externaly calculated OTR
const dC_total = math.multiply(math.add(inflow, outflow, reaction, transfer), time_step)
this.state = this._arrayClip2Zero(math.add(this.state, dC_total)); // clip value element-wise to avoid negative concentrations
@@ -304,6 +317,13 @@ class Reactor_PFR extends Reactor {
this.D = this._constrainDispersion(input.payload);
}
+ _connectReactor(reactorChild) {
+ if (math.abs(reactorChild.d_x - this.d_x) / this.d_x < 0.025) {
+ this.logger.warn("Significant grid sizing discrepancies between adjacent reactors! Change resolutions to match reactors grid step, or implement boundary value interpolation.");
+ }
+ super._connectReactor(reactorChild);
+ }
+
updateState(newTime) {
super.updateState(newTime);
// let Pe_local = this.d_x*math.sum(this.Fs)/(this.D*this.A)