'use strict'; const { BaseReactorEngine, math, S_O_INDEX, NUM_SPECIES } = require('./baseEngine.js'); class Reactor_CSTR extends BaseReactorEngine { constructor(config) { super(config); this.state = config.initialState; } // Forward Euler step over `time_step` days. tick(time_step) { const inflow = math.multiply(math.divide([this.Fs], this.volume), this.Cs_in)[0]; const outflow = math.multiply(-1 * math.sum(this.Fs) / this.volume, this.state); const reaction = this.asm.compute_dC(this.state, this.temperature); const transfer = Array(NUM_SPECIES).fill(0.0); transfer[S_O_INDEX] = isNaN(this.kla) ? this.OTR : this._calcOTR(this.state[S_O_INDEX], this.temperature); const dC_total = math.multiply(math.add(inflow, outflow, reaction, transfer), time_step); this.state = this._capDissolvedOxygen(this._arrayClip2Zero(math.add(this.state, dC_total))); return this.state; } } module.exports = Reactor_CSTR;