Minor optimisations in code and clarification
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const { ASM3, ASM_CONSTANTS } = require('./reaction_modules/asm3_class.js');
|
||||
const { create, all, isArray, i } = require('mathjs');
|
||||
const { create, all, isArray } = require('mathjs');
|
||||
const { assertNoNaN } = require('./utils.js');
|
||||
const { childRegistrationUtils, logger, MeasurementContainer } = require('generalFunctions');
|
||||
const EventEmitter = require('events');
|
||||
@@ -96,7 +96,7 @@ class Reactor {
|
||||
* @returns {number} - Calculated OTR [g O2 d-1 m-3].
|
||||
*/
|
||||
_calcOTR(S_O, T = 20.0) { // caculate the OTR using basic correlation, default to temperature: 20 C
|
||||
let S_O_sat = 14.652 - 4.1022e-1 * T + 7.9910e-3 * T*T + 7.7774e-5 * T*T*T;
|
||||
const S_O_sat = 14.652 - 4.1022e-1 * T + 7.9910e-3 * T*T + 7.7774e-5 * T*T*T;
|
||||
return this.kla * (S_O_sat - S_O);
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ class Reactor {
|
||||
this.setInfluent = this.upstreamReactor.getEffluent[0]; // grab main effluent upstream reactor
|
||||
}
|
||||
|
||||
let n_iter = Math.floor(this.speedUpFactor * (newTime-this.currentTime) / (this.timeStep*DAY2MS));
|
||||
const n_iter = Math.floor(this.speedUpFactor * (newTime-this.currentTime) / (this.timeStep*DAY2MS));
|
||||
if (n_iter) {
|
||||
let n = 0;
|
||||
while (n < n_iter) {
|
||||
@@ -294,7 +294,7 @@ class Reactor_PFR extends Reactor {
|
||||
super.updateState(newTime);
|
||||
// let Pe_local = this.d_x*math.sum(this.Fs)/(this.D*this.A)
|
||||
this.D = this._constrainDispersion(this.D);
|
||||
let Co_D = this.D*this.timeStep/(this.d_x*this.d_x);
|
||||
const Co_D = this.D*this.timeStep/(this.d_x*this.d_x);
|
||||
|
||||
// (Pe_local >= 2) && this.logger.warn(`Local Péclet number (${Pe_local}) is too high! Increase reactor resolution.`);
|
||||
(Co_D >= 0.5) && this.logger.warn(`Courant number (${Co_D}) is too high! Reduce time step size.`);
|
||||
@@ -351,7 +351,7 @@ class Reactor_PFR extends Reactor {
|
||||
_updateMeasurement(measurementType, value, position, context) {
|
||||
switch(measurementType) {
|
||||
case "quantity (oxygen)":
|
||||
let grid_pos = Math.round(context.distance / this.config.length * this.n_x);
|
||||
const grid_pos = Math.round(context.distance / this.config.length * this.n_x);
|
||||
this.state[grid_pos][0] = value; // naive approach for reconciling measurements and simulation
|
||||
break;
|
||||
default:
|
||||
@@ -366,31 +366,31 @@ class Reactor_PFR extends Reactor {
|
||||
*/
|
||||
_applyBoundaryConditions() {
|
||||
if (this.upstreamReactor) {
|
||||
// Open boundary
|
||||
for (let i = 0; i < BC_PADDING; i++) {
|
||||
this.extendedState[i] = this.upstreamReactor.state.at(i-BC_PADDING);
|
||||
}
|
||||
} else {
|
||||
if (math.sum(this.Fs) > 0) { // Danckwerts BC
|
||||
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 = this.D*this.A/(math.sum(this.Fs)*this.d_x);
|
||||
this.extendedState[BC_PADDING] = math.multiply(1/(1+BC_dispersion_term), math.add(BC_C_in, math.multiply(BC_dispersion_term, this.extendedState[BC_PADDING+1])));
|
||||
this.extendedState[BC_PADDING-1] = math.add(math.multiply(2, this.extendedState[BC_PADDING]), math.multiply(-2, this.extendedState[BC_PADDING+2]), this.extendedState[BC_PADDING+3]);
|
||||
} else {
|
||||
for (let i = 0; i < BC_PADDING; i++) {
|
||||
this.extendedState[i] = this.extendedState[BC_PADDING];
|
||||
}
|
||||
// Neumann BC (no flux)
|
||||
this.extendedState.fill(this.extendedState[BC_PADDING], 0, BC_PADDING);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.downstreamReactor) {
|
||||
// Open boundary
|
||||
for (let i = 0; i < BC_PADDING; i++) {
|
||||
this.extendedState[this.n_x+BC_PADDING+i] = this.downstreamReactor.state[i];
|
||||
}
|
||||
} else {
|
||||
// Neumann BC (no flux)
|
||||
for (let i = 0; i < BC_PADDING; i++) {
|
||||
this.extendedState[BC_PADDING+this.n_x+i] = this.extendedState.at(-1-BC_PADDING);
|
||||
}
|
||||
this.extendedState.fill(this.extendedState.at(-1-BC_PADDING), BC_PADDING+this.n_x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user