92 lines
2.6 KiB
JavaScript
92 lines
2.6 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
|
|
const { Reactor_CSTR, Reactor_PFR } = require('../../src/specificClass');
|
|
const { makeReactorConfig } = require('../helpers/factories');
|
|
|
|
const NUM_SPECIES = 13;
|
|
|
|
test('CSTR uses external OTR when kla is NaN', () => {
|
|
const reactor = new Reactor_CSTR(
|
|
makeReactorConfig({ reactor_type: 'CSTR', kla: NaN, n_inlets: 1 }),
|
|
);
|
|
|
|
reactor.asm = {
|
|
compute_dC: () => Array(NUM_SPECIES).fill(0),
|
|
};
|
|
reactor.Fs[0] = 0;
|
|
reactor.OTR = 4;
|
|
reactor.state = Array(NUM_SPECIES).fill(0);
|
|
|
|
reactor.tick(1);
|
|
|
|
assert.equal(reactor.state[0], 4);
|
|
});
|
|
|
|
test('CSTR uses kla-based oxygen transfer when kla is finite', () => {
|
|
const reactor = new Reactor_CSTR(
|
|
makeReactorConfig({ reactor_type: 'CSTR', kla: 2, n_inlets: 1 }),
|
|
);
|
|
|
|
reactor.asm = {
|
|
compute_dC: () => Array(NUM_SPECIES).fill(0),
|
|
};
|
|
reactor.Fs[0] = 0;
|
|
reactor.OTR = 1;
|
|
reactor.state = Array(NUM_SPECIES).fill(0);
|
|
|
|
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);
|
|
});
|
|
|
|
test('PFR uses external OTR branch when kla is NaN', () => {
|
|
const reactor = new Reactor_PFR(
|
|
makeReactorConfig({ reactor_type: 'PFR', kla: NaN, n_inlets: 1, length: 8, resolution_L: 6, volume: 40 }),
|
|
);
|
|
|
|
reactor.asm = {
|
|
compute_dC: () => Array(NUM_SPECIES).fill(0),
|
|
};
|
|
reactor.Fs[0] = 0;
|
|
reactor.D = 0;
|
|
reactor.OTR = 3;
|
|
reactor.state = Array.from({ length: reactor.n_x }, () => Array(NUM_SPECIES).fill(0));
|
|
|
|
reactor.tick(1);
|
|
|
|
assert.equal(reactor.state[1][0], 4.5);
|
|
assert.equal(reactor.state[2][0], 4.5);
|
|
assert.equal(reactor.state[3][0], 4.5);
|
|
assert.equal(reactor.state[4][0], 4.5);
|
|
});
|
|
|
|
test('PFR uses kla-based transfer branch when kla is finite', () => {
|
|
const reactor = new Reactor_PFR(
|
|
makeReactorConfig({ reactor_type: 'PFR', kla: 1, n_inlets: 1, length: 8, resolution_L: 6, volume: 40 }),
|
|
);
|
|
|
|
reactor.asm = {
|
|
compute_dC: () => Array(NUM_SPECIES).fill(0),
|
|
};
|
|
reactor.Fs[0] = 0;
|
|
reactor.D = 0;
|
|
reactor.OTR = 0;
|
|
reactor.state = Array.from({ length: reactor.n_x }, () => Array(NUM_SPECIES).fill(0));
|
|
|
|
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);
|
|
assert.ok(Math.abs(reactor.state[2][0] - expected) < 1e-9);
|
|
assert.ok(Math.abs(reactor.state[3][0] - expected) < 1e-9);
|
|
assert.ok(Math.abs(reactor.state[4][0] - expected) < 1e-9);
|
|
});
|