Expand reactor demo telemetry and stability handling

This commit is contained in:
root
2026-03-31 14:26:10 +02:00
parent 2c69a5a0c1
commit 2e3ba8a9bf
21 changed files with 4030 additions and 3916 deletions

View File

@@ -35,7 +35,10 @@ test('CSTR uses kla-based oxygen transfer when kla is finite', () => {
reactor.OTR = 1;
reactor.state = Array(NUM_SPECIES).fill(0);
const expected = reactor._calcOTR(0, reactor.temperature);
const expected = Math.min(
reactor._calcOTR(0, reactor.temperature),
reactor._calcOxygenSaturation(reactor.temperature),
);
reactor.tick(1);
assert.ok(Math.abs(reactor.state[0] - expected) < 1e-9);
@@ -75,7 +78,10 @@ test('PFR uses kla-based transfer branch when kla is finite', () => {
reactor.OTR = 0;
reactor.state = Array.from({ length: reactor.n_x }, () => Array(NUM_SPECIES).fill(0));
const expected = reactor._calcOTR(0, reactor.temperature) * (reactor.n_x / (reactor.n_x - 2));
const expected = Math.min(
reactor._calcOTR(0, reactor.temperature) * (reactor.n_x / (reactor.n_x - 2)),
reactor._calcOxygenSaturation(reactor.temperature),
);
reactor.tick(1);
assert.ok(Math.abs(reactor.state[1][0] - expected) < 1e-9);

View File

@@ -9,6 +9,7 @@ test('_tick emits source effluent on process output', () => {
const node = makeNodeStub();
inst.node = node;
inst._output = { formatMsg() { return null; } };
inst.source = {
get getEffluent() {
return { topic: 'Fluent', payload: { inlet: 0, F: 1, C: [] }, timestamp: 1 };
@@ -23,6 +24,50 @@ test('_tick emits source effluent on process output', () => {
assert.equal(node._sent[0][2], null);
});
test('_tick emits reactor telemetry on influx output', () => {
const inst = Object.create(NodeClass.prototype);
const node = makeNodeStub();
let captured = null;
inst.node = node;
inst.config = { functionality: { softwareType: 'reactor' }, general: { id: 'reactor-node-1' } };
inst._output = {
formatMsg(output, config, format) {
captured = { output, config, format };
return { topic: 'reactor_reactor-node-1', payload: { measurement: 'reactor_reactor-node-1', fields: output } };
}
};
inst.source = {
temperature: 19.5,
get getGridProfile() {
return null;
},
get getEffluent() {
return {
topic: 'Fluent',
payload: {
inlet: 0,
F: 42,
C: [2.1, 30, 100, 16, 0, 1, 8, 25, 75, 1500, 0, 15, 2500]
},
timestamp: 1
};
},
};
inst._tick();
assert.equal(node._sent.length, 1);
assert.equal(node._sent[0][0].topic, 'Fluent');
assert.equal(node._sent[0][1].topic, 'reactor_reactor-node-1');
assert.equal(captured.format, 'influxdb');
assert.equal(captured.output.flow_total, 42);
assert.equal(captured.output.temperature, 19.5);
assert.equal(captured.output.S_O, 2.1);
assert.equal(captured.output.S_NH, 16);
assert.equal(captured.output.X_TS, 2500);
});
test('_startTickLoop schedules periodic tick after startup delay', () => {
const inst = Object.create(NodeClass.prototype);
const delays = [];