Files
reactor/src/kinetics/cstr.js
znetsixe 7bf464b467 P6: convert reactor to platform infrastructure
Refactor of reactor to use BaseNodeAdapter + commandRegistry + statusBadge.
reactor follows the platform refactor plan in .claude/refactor/MODULE_SPLIT.md.
Tests stay green; CONTRACT.md generated; legacy aliases preserved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 22:23:43 +02:00

28 lines
975 B
JavaScript

'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;