Add boundary condition input and update reactor configuration handling

This commit is contained in:
2025-07-07 14:47:50 +02:00
parent c89d5b0024
commit 01380c309f
3 changed files with 40 additions and 5 deletions

View File

@@ -8,6 +8,7 @@
volume: { value: 0., required: true }, volume: { value: 0., required: true },
length: { value: 0.}, length: { value: 0.},
resolution_L: { value: 0.}, resolution_L: { value: 0.},
boundary_condition: {value: "Generalised"},
n_inlets: { value: 1, required: true}, n_inlets: { value: 1, required: true},
kla: { value: null }, kla: { value: null },
S_O_init: { value: 0., required: true }, S_O_init: { value: 0., required: true },
@@ -75,6 +76,18 @@
$(".PFR").show(); $(".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 // Set initial visibility on dialog open
const initialType = $("#node-input-reactor_type").typedInput("value"); const initialType = $("#node-input-reactor_type").typedInput("value");
if (initialType === "CSTR") { if (initialType === "CSTR") {
@@ -117,6 +130,10 @@
<div class="form-row PFR"> <div class="form-row PFR">
<label for="node-input-resolution_L"><i class="fa fa-tag"></i> Resolution</label> <label for="node-input-resolution_L"><i class="fa fa-tag"></i> Resolution</label>
<input type="text" id="node-input-resolution_L" placeholder="#"> <input type="text" id="node-input-resolution_L" placeholder="#">
</div>
<div class="form-row PFR">
<label for="node-input-boundary_condition"><i class="fa fa-tag"></i>Inlet boundary condition</label>
<input type="text" id="node-input-boundary_condition">
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-input-n_inlets"><i class="fa fa-tag"></i> Number of inlets</label> <label for="node-input-n_inlets"><i class="fa fa-tag"></i> Number of inlets</label>

View File

@@ -70,6 +70,7 @@ class nodeClass {
volume: parseFloat(uiConfig.volume), volume: parseFloat(uiConfig.volume),
length: parseFloat(uiConfig.length), length: parseFloat(uiConfig.length),
resolution_L: parseInt(uiConfig.resolution_L), resolution_L: parseInt(uiConfig.resolution_L),
boundary_condition: uiConfig.boundary_condition,
n_inlets: parseInt(uiConfig.n_inlets), n_inlets: parseInt(uiConfig.n_inlets),
kla: parseFloat(uiConfig.kla), kla: parseFloat(uiConfig.kla),
initialState: [ initialState: [

View File

@@ -10,7 +10,7 @@ const math = create(all, config);
const S_O_INDEX = 0; const S_O_INDEX = 0;
const NUM_SPECIES = 13; const NUM_SPECIES = 13;
const DEBUG = false; const DEBUG = true;
class Reactor { class Reactor {
/** /**
@@ -30,7 +30,7 @@ class Reactor {
this.currentTime = Date.now(); // milliseconds since epoch [ms] this.currentTime = Date.now(); // milliseconds since epoch [ms]
this.timeStep = 1 / (24*60*15); // time step [d] 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.d_x = this.length / this.n_x;
this.A = this.volume / this.length; // crosssectional area [m2] 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()) this.state = Array.from(Array(this.n_x), () => config.initialState.slice())
// console.log("Initial State: ") // console.log("Initial State: ")
@@ -178,6 +180,7 @@ class Reactor_PFR extends Reactor {
set setInfluent(input) { set setInfluent(input) {
super.setInfluent = input; super.setInfluent = input;
if(DEBUG) { 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 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("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)); 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); const BC_gradient = Array(this.n_x).fill(0);
BC_gradient[0] = -1; BC_gradient[0] = -1;
BC_gradient[1] = 1; BC_gradient[1] = 1;
let Pe = this.length * math.sum(this.Fs) / (this.D * this.A); let BC_term = 0;
let residence_time = this.volume/math.sum(this.Fs); switch(this.BC) {
const BC_dispersion = math.multiply((1 - (1 + 4*residence_time/Pe)^0.5) / (Pe*this.d_x), [BC_gradient], state)[0]; 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); state[0] = math.add(BC_C_in, BC_dispersion).map(val => val < 0 ? 0 : val);
} else { // Neumann BC (no flux) } else { // Neumann BC (no flux)
state[0] = state[1]; state[0] = state[1];