From 5c03dddb7923066f705edbd490afd49388c511bf Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Tue, 8 Jul 2025 10:03:03 +0200 Subject: [PATCH] Refactor boundary condition handling to use adjustable parameter alpha in advanced-reactor and specificClass --- advanced-reactor.html | 25 ++++++++++--------------- src/nodeClass.js | 2 +- src/specificClass.js | 20 ++------------------ 3 files changed, 13 insertions(+), 34 deletions(-) diff --git a/advanced-reactor.html b/advanced-reactor.html index 9ea7e23..40ea4f6 100644 --- a/advanced-reactor.html +++ b/advanced-reactor.html @@ -8,7 +8,7 @@ volume: { value: 0., required: true }, length: { value: 0.}, resolution_L: { value: 0.}, - boundary_condition: {value: "Generalised"}, + alpha: {value: 0}, n_inlets: { value: 1, required: true}, kla: { value: null }, S_O_init: { value: 0., required: true }, @@ -76,17 +76,9 @@ $(".PFR").show(); } }); - $("#node-input-boundary_condition").typedInput({ - types: [ - { - value: "Generalised", - options: [ - { value: "Generalised", label: "Generalised"}, - { value: "Dirichlet", label: "Dirichlet"}, - { value: "Danckwerts", label: "Danckwerts"} - ] - } - ] + $("#node-input-alpha").typedInput({ + type:"num", + types:["num"] }) // Set initial visibility on dialog open const initialType = $("#node-input-reactor_type").typedInput("value"); @@ -131,9 +123,12 @@ -
- - +
+

Inlet boundary condition parameter α (α = 0: Danckwerts BC / α = 1: Dirichlet BC)

+
+ + +
diff --git a/src/nodeClass.js b/src/nodeClass.js index e3c3fd6..7ec81d3 100644 --- a/src/nodeClass.js +++ b/src/nodeClass.js @@ -70,7 +70,7 @@ class nodeClass { volume: parseFloat(uiConfig.volume), length: parseFloat(uiConfig.length), resolution_L: parseInt(uiConfig.resolution_L), - boundary_condition: uiConfig.boundary_condition, + alpha: parseFloat(uiConfig.alpha), n_inlets: parseInt(uiConfig.n_inlets), kla: parseFloat(uiConfig.kla), initialState: [ diff --git a/src/specificClass.js b/src/specificClass.js index 1124b0d..18af512 100644 --- a/src/specificClass.js +++ b/src/specificClass.js @@ -149,7 +149,7 @@ 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.alpha = config.alpha; this.state = Array.from(Array(this.n_x), () => config.initialState.slice()) @@ -208,23 +208,7 @@ class Reactor_PFR extends Reactor { const BC_gradient = Array(this.n_x).fill(0); BC_gradient[0] = -1; BC_gradient[1] = 1; - let BC_term = 0; - switch(this.BC) { - case "Dirichlet": - 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]; + const BC_dispersion = math.multiply((1 - this.alpha) * this.D*this.A / (math.sum(this.Fs) * 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];