From 6c79d0ef9bf00ee8273ce3d5b1afcdce357fb752 Mon Sep 17 00:00:00 2001
From: "p.vanderwilt"
Date: Mon, 29 Sep 2025 15:34:54 +0200
Subject: [PATCH] Use improved boundary conditions for upstream and downstream
reactors
---
src/specificClass.js | 32 +++++++++++++++++++++-----------
1 file changed, 21 insertions(+), 11 deletions(-)
diff --git a/src/specificClass.js b/src/specificClass.js
index 636f678..fe580bf 100644
--- a/src/specificClass.js
+++ b/src/specificClass.js
@@ -27,6 +27,7 @@ class Reactor {
this.measurements = new MeasurementContainer();
this.upstreamReactor = null;
this.childRegistrationUtils = new childRegistrationUtils(this); // Child registration utility
+ this.parent = null; // Gets assigned via child registration
this.asm = new ASM3();
@@ -126,7 +127,6 @@ class Reactor {
position = measurement.config.functionality.positionVsParent;
}
const measurementType = measurement.config.asset.type;
- const key = `${measurementType}_${position}`;
const eventName = `${measurementType}.measured.${position}`;
// Register event listener for measurement updates
@@ -145,13 +145,13 @@ class Reactor {
}
- _connectReactor(reactor) {
- if (!reactor) {
+ _connectReactor(reactorChild) {
+ if (!reactorChild) {
this.logger.warn("Invalid reactor provided.");
return;
}
- this.upstreamReactor = reactor;
+ this.upstreamReactor = reactorChild;
reactor.emitter.on("stateChange", (data) => {
this.logger.debug(`State change of upstream reactor detected.`);
@@ -338,15 +338,25 @@ class Reactor_PFR extends Reactor {
* @param {Array} state - Current reactor state without enforced BCs.
*/
_applyBoundaryConditions(state) {
- if (math.sum(this.Fs) > 0) { // Danckwerts BC
- const BC_C_in = math.multiply(1 / math.sum(this.Fs), [this.Fs], this.Cs_in)[0];
- const BC_dispersion_term = (1-this.alpha)*this.D*this.A/(math.sum(this.Fs)*this.d_x);
- state[0] = math.multiply(1/(1+BC_dispersion_term), math.add(BC_C_in, math.multiply(BC_dispersion_term, state[1])));
+ if (this.upstreamReactor) {
+ state[0] = this.upstreamReactor.state[this.n_x-1];
} else {
- state[0] = state[1];
+ if (math.sum(this.Fs) > 0) { // Danckwerts BC
+ const BC_C_in = math.multiply(1 / math.sum(this.Fs), [this.Fs], this.Cs_in)[0];
+ const BC_dispersion_term = (1-this.alpha)*this.D*this.A/(math.sum(this.Fs)*this.d_x);
+ state[0] = math.multiply(1/(1+BC_dispersion_term), math.add(BC_C_in, math.multiply(BC_dispersion_term, state[1])));
+ } else {
+ state[0] = state[1];
+ }
+ }
+
+ const downstreamReactor = this.parent;
+ if (downstreamReactor) {
+ state[this.n_x-1] = downstreamReactor.state[0];
+ } else {
+ // Neumann BC (no flux)
+ state[this.n_x-1] = state[this.n_x-2];
}
- // Neumann BC (no flux)
- state[this.n_x-1] = state[this.n_x-2];
}
/**