updates
This commit is contained in:
@@ -62,6 +62,24 @@ class Reactor {
|
||||
this.OTR = input.payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for reactor temperature [C].
|
||||
* Accepts either a direct numeric payload or { value } object payload.
|
||||
* @param {object} input - Input object (msg)
|
||||
*/
|
||||
set setTemperature(input) {
|
||||
const payload = input?.payload;
|
||||
const rawValue = (payload && typeof payload === 'object' && payload.value !== undefined)
|
||||
? payload.value
|
||||
: payload;
|
||||
const parsedValue = Number(rawValue);
|
||||
if (!Number.isFinite(parsedValue)) {
|
||||
this.logger.warn(`Invalid temperature input: ${rawValue}`);
|
||||
return;
|
||||
}
|
||||
this.temperature = parsedValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for effluent data.
|
||||
* @returns {object} Effluent data object (msg), defaults to inlet 0.
|
||||
@@ -323,8 +341,16 @@ class Reactor_PFR extends Reactor {
|
||||
_updateMeasurement(measurementType, value, position, context) {
|
||||
switch(measurementType) {
|
||||
case "quantity (oxygen)":
|
||||
let grid_pos = Math.round(position / this.config.length * this.n_x);
|
||||
this.state[grid_pos][S_O_INDEX] = value; // naive approach for reconciling measurements and simulation
|
||||
if (!Number.isFinite(position) || !Number.isFinite(value) || this.config.length <= 0) {
|
||||
this.logger.warn(`Ignoring oxygen measurement update with invalid data (position=${position}, value=${value}).`);
|
||||
break;
|
||||
}
|
||||
{
|
||||
// Clamp sensor-derived position to valid PFR grid bounds.
|
||||
const rawIndex = Math.round(position / this.config.length * this.n_x);
|
||||
const grid_pos = Math.max(0, Math.min(this.n_x - 1, rawIndex));
|
||||
this.state[grid_pos][S_O_INDEX] = value; // reconcile measured oxygen concentration into nearest grid cell
|
||||
}
|
||||
break;
|
||||
default:
|
||||
super._updateMeasurement(measurementType, value, position, context);
|
||||
@@ -416,4 +442,4 @@ module.exports = { Reactor_CSTR, Reactor_PFR };
|
||||
// while (N < 5000) {
|
||||
// console.log(Reactor.tick(0.001));
|
||||
// N += 1;
|
||||
// }
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user