From 01380c309f757622c5ad194f42ee938cedde2bc7 Mon Sep 17 00:00:00 2001
From: "p.vanderwilt"
Date: Mon, 7 Jul 2025 14:47:50 +0200
Subject: [PATCH] Add boundary condition input and update reactor configuration
handling
---
advanced-reactor.html | 17 +++++++++++++++++
src/nodeClass.js | 1 +
src/specificClass.js | 27 ++++++++++++++++++++++-----
3 files changed, 40 insertions(+), 5 deletions(-)
diff --git a/advanced-reactor.html b/advanced-reactor.html
index 512f3dd..6594947 100644
--- a/advanced-reactor.html
+++ b/advanced-reactor.html
@@ -8,6 +8,7 @@
volume: { value: 0., required: true },
length: { value: 0.},
resolution_L: { value: 0.},
+ boundary_condition: {value: "Generalised"},
n_inlets: { value: 1, required: true},
kla: { value: null },
S_O_init: { value: 0., required: true },
@@ -75,6 +76,18 @@
$(".PFR").show();
}
});
+ $("#node-input-boundary_condition").typedInput({
+ types: [
+ {
+ value: "Generalised",
+ options: [
+ { value: "Generalised", label: "Generalised"},
+ { value: "Diriclet", label: "Diriclet"},
+ { value: "Danckwerts", label: "Danckwerts"}
+ ]
+ }
+ ]
+ })
// Set initial visibility on dialog open
const initialType = $("#node-input-reactor_type").typedInput("value");
if (initialType === "CSTR") {
@@ -117,6 +130,10 @@
+
+
+
+
diff --git a/src/nodeClass.js b/src/nodeClass.js
index 7919df2..e3c3fd6 100644
--- a/src/nodeClass.js
+++ b/src/nodeClass.js
@@ -70,6 +70,7 @@ class nodeClass {
volume: parseFloat(uiConfig.volume),
length: parseFloat(uiConfig.length),
resolution_L: parseInt(uiConfig.resolution_L),
+ boundary_condition: uiConfig.boundary_condition,
n_inlets: parseInt(uiConfig.n_inlets),
kla: parseFloat(uiConfig.kla),
initialState: [
diff --git a/src/specificClass.js b/src/specificClass.js
index 384aaf0..e670eb5 100644
--- a/src/specificClass.js
+++ b/src/specificClass.js
@@ -10,7 +10,7 @@ const math = create(all, config);
const S_O_INDEX = 0;
const NUM_SPECIES = 13;
-const DEBUG = false;
+const DEBUG = true;
class Reactor {
/**
@@ -30,7 +30,7 @@ class Reactor {
this.currentTime = Date.now(); // milliseconds since epoch [ms]
this.timeStep = 1 / (24*60*15); // time step [d]
- this.speedUpFactor = 60; // speed up factor for simulation, 60 means 1 minute per simulated second
+ this.speedUpFactor = 1; // speed up factor for simulation, 60 means 1 minute per simulated second
}
/**
@@ -149,6 +149,8 @@ class Reactor_PFR extends Reactor {
this.d_x = this.length / this.n_x;
this.A = this.volume / this.length; // crosssectional area [m2]
+ this.BC = config.boundary_condition;
+
this.state = Array.from(Array(this.n_x), () => config.initialState.slice())
// console.log("Initial State: ")
@@ -178,6 +180,7 @@ class Reactor_PFR extends Reactor {
set setInfluent(input) {
super.setInfluent = input;
if(DEBUG) {
+ console.log("Inlet state max " + math.max(this.state[0]))
console.log("Pe total " + this.length*math.sum(this.Fs)/(this.D*this.A));
console.log("Pe local " + this.d_x*math.sum(this.Fs)/(this.D*this.A));
console.log("Co ad " + math.sum(this.Fs)*this.timeStep/(this.A*this.d_x));
@@ -205,9 +208,23 @@ class Reactor_PFR extends Reactor {
const BC_gradient = Array(this.n_x).fill(0);
BC_gradient[0] = -1;
BC_gradient[1] = 1;
- let Pe = this.length * math.sum(this.Fs) / (this.D * this.A);
- let residence_time = this.volume/math.sum(this.Fs);
- const BC_dispersion = math.multiply((1 - (1 + 4*residence_time/Pe)^0.5) / (Pe*this.d_x), [BC_gradient], state)[0];
+ let BC_term = 0;
+ switch(this.BC) {
+ case "Diriclet":
+ BC_term = 0;
+ break;
+ case "Danckwerts":
+ BC_term = this.D*this.A / math.sum(this.Fs);
+ break;
+ case "Generalised":
+ let Pe = this.length * math.sum(this.Fs) / (this.D * this.A);
+ let residence_time = this.volume/math.sum(this.Fs);
+ BC_term = (1 - (1 + 4*residence_time/Pe)^0.5) / Pe
+ break;
+ default:
+ console.warn("Unknown boundary condition: " + this.BC);
+ }
+ const BC_dispersion = math.multiply(BC_term/this.d_x, [BC_gradient], state)[0];
state[0] = math.add(BC_C_in, BC_dispersion).map(val => val < 0 ? 0 : val);
} else { // Neumann BC (no flux)
state[0] = state[1];