Refactor Reactor class structure and include inheritance for CSTR and PFR
This commit is contained in:
@@ -7,43 +7,56 @@ const config = {
|
||||
|
||||
const math = create(all, config)
|
||||
|
||||
class Reactor_CSTR {
|
||||
|
||||
constructor(volume, n_inlets, kla, initial_state) {
|
||||
this.state = initial_state;
|
||||
class Reactor {
|
||||
|
||||
constructor(volume, n_inlets, kla){
|
||||
this.asm = new ASM3();
|
||||
|
||||
this.Vl = volume; // fluid volume reactor [m3]
|
||||
|
||||
this.Fs = Array(n_inlets).fill(0.0); // fluid debits per inlet [m3 d-1]
|
||||
this.Cs_in = Array.from(Array(n_inlets), () => new Array(13).fill(0.0)); // composition influents
|
||||
this.OTR = 0.0; // oxygen transfer rate [g O2 d-1]
|
||||
|
||||
|
||||
this.kla = kla; // if NaN, use external OTR [d-1]
|
||||
|
||||
this.currentTime = Date.now(); // milliseconds since epoch [ms]
|
||||
this.timeStep = 1/(24*60*15); // time step [d]
|
||||
this.speedUpFactor = 1;
|
||||
this.speedUpFactor = 60;
|
||||
}
|
||||
|
||||
set setInfluent(input) { // setter for C_in (WIP)
|
||||
let index_in = input.payload.inlet;
|
||||
this.Fs[index_in] = input.payload.F;
|
||||
this.Cs_in[index_in] = input.payload.C;
|
||||
// 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));
|
||||
// console.log("Co D " + this.D*this.timeStep/(this.d_x*this.d_x));
|
||||
}
|
||||
|
||||
set setOTR(input) { // setter for OTR (WIP) [g O2 d-1]
|
||||
this.OTR = input.payload;
|
||||
}
|
||||
|
||||
get getEffluent() { // getter for Effluent, defaults to inlet 0
|
||||
return {topic: "Fluent", payload: {inlet: 0, F: math.sum(this.Fs), C:this.state}, timestamp: this.currentTime};
|
||||
}
|
||||
|
||||
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;
|
||||
return this.kla * (S_O_sat - S_O);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Reactor_CSTR extends Reactor {
|
||||
|
||||
constructor(volume, n_inlets, kla, initial_state) {
|
||||
super(volume, n_inlets, kla);
|
||||
this.state = initial_state;
|
||||
}
|
||||
|
||||
get getEffluent() { // getter for Effluent, defaults to inlet 0
|
||||
return {topic: "Fluent", payload: {inlet: 0, F: math.sum(this.Fs), C:this.state}, timestamp: this.currentTime};
|
||||
}
|
||||
|
||||
// expect update with timestamp
|
||||
updateState(newTime) {
|
||||
|
||||
@@ -75,12 +88,11 @@ class Reactor_CSTR {
|
||||
}
|
||||
}
|
||||
|
||||
class Reactor_PFR {
|
||||
class Reactor_PFR extends Reactor {
|
||||
|
||||
constructor(volume, length, resolution_L, n_inlets, kla, initial_state) {
|
||||
this.asm = new ASM3();
|
||||
super(volume, n_inlets, kla);
|
||||
|
||||
this.Vl = volume; // fluid volume reactor [m3]
|
||||
this.length = length; // reactor length [m]
|
||||
this.n_x = resolution_L; // number of slices
|
||||
this.d_x = length / resolution_L;
|
||||
@@ -92,35 +104,12 @@ class Reactor_PFR {
|
||||
// console.log("Initial State: ")
|
||||
// console.log(this.state)
|
||||
|
||||
this.Fs = Array(n_inlets).fill(0.0); // fluid debits per inlet [m3 d-1]
|
||||
this.Cs_in = Array.from(Array(n_inlets), () => new Array(13).fill(0.0)); // composition influents
|
||||
this.OTR = 0.0; // oxygen transfer rate [g O2 d-1]
|
||||
this.D = 0.0; // axial dispersion [m2 d-1]
|
||||
|
||||
this.kla = kla; // if NaN, use external OTR [d-1]
|
||||
|
||||
this.currentTime = Date.now(); // milliseconds since epoch [ms]
|
||||
this.timeStep = 1/(24*60*15); // time step [d]
|
||||
this.speedUpFactor = 60;
|
||||
|
||||
this.D_op = this.makeDoperator(true, true);
|
||||
this.D2_op = this.makeD2operator();
|
||||
}
|
||||
|
||||
set setInfluent(input) { // setter for C_in (WIP)
|
||||
let index_in = input.payload.inlet;
|
||||
this.Fs[index_in] = input.payload.F;
|
||||
this.Cs_in[index_in] = input.payload.C;
|
||||
// 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));
|
||||
// console.log("Co D " + this.D*this.timeStep/(this.d_x*this.d_x));
|
||||
}
|
||||
|
||||
set setOTR(input) { // setter for OTR (WIP) [g O2 d-1]
|
||||
this.OTR = input.payload;
|
||||
}
|
||||
|
||||
set setDispersion(input) { // setter for Axial dispersion [m2 d-1]
|
||||
this.D = input.payload;
|
||||
}
|
||||
@@ -129,11 +118,6 @@ class Reactor_PFR {
|
||||
return {topic: "Fluent", payload: {inlet: 0, F: math.sum(this.Fs), C:this.state.at(-1)}, timestamp: this.currentTime};
|
||||
}
|
||||
|
||||
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;
|
||||
return this.kla * (S_O_sat - S_O);
|
||||
}
|
||||
|
||||
// expect update with timestamp
|
||||
updateState(newTime) {
|
||||
const day2ms = 1000 * 60 * 60 * 24;
|
||||
|
||||
Reference in New Issue
Block a user