Compare commits

15 Commits

Author SHA1 Message Date
Rene De Ren
bb986c2dc8 refactor: adopt POSITIONS constants and fix ESLint warnings
Replace hardcoded position strings with POSITIONS.* constants.
Prefix unused variables with _ to resolve no-unused-vars warnings.
Fix no-prototype-builtins where applicable.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 15:35:28 +01:00
Rene De Ren
46dd2ca37a Migrate _loadConfig to use ConfigManager.buildConfig()
Replaces manual base config construction with shared buildConfig() method.
Node now only specifies domain-specific config sections.

Part of #1: Extract base config schema

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 14:59:35 +01:00
Rene De Ren
ccfa90394b Fix ESLint errors and bugs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 13:39:57 +01:00
znetsixe
e236cccfd6 Merge branch 'dev-Rene' 2025-12-19 10:23:25 +01:00
p.vanderwilt
99b45c87e4 Rename _updateSourceSink to updateSourceSink for outside access 2025-11-14 12:55:11 +01:00
p.vanderwilt
0a98b12224 Merge pull request 'Implement reactor recirculation' (#4) from dev-Pieter into main
Reviewed-on: https://gitea.centraal.wbd-rd.nl/RnD/rotatingMachine/pulls/4
2025-11-06 13:58:25 +00:00
p.vanderwilt
b6d268659a Refactor flow handling: rename reactor references to source and sink and fix config minor bug 2025-11-06 14:50:40 +01:00
p.vanderwilt
303dfc477d Add flow number configuration and UI input for rotating machine 2025-10-31 14:16:00 +01:00
p.vanderwilt
ac40a93ef1 Simplify child registration error handling 2025-10-31 13:07:52 +01:00
p.vanderwilt
a8fb56bfb8 Add upstream and downstream reactor handling; improve error logging 2025-10-22 14:41:35 +02:00
HorriblePerson555
d7cc6a4a8b Enhance child registration logging and add validation for measurement child 2025-10-17 13:38:05 +02:00
HorriblePerson555
37e6523c55 Refactor child registration to use dedicated connection methods for measurement and reactor types 2025-10-16 16:32:20 +02:00
5a14f44fdd Merge pull request 'dev-Rene' (#2) from dev-Rene into main
Reviewed-on: https://gitea.centraal.wbd-rd.nl/RnD/rotatingMachine/pulls/2
2025-10-16 13:21:38 +00:00
p.vanderwilt
c081acae4e Remove non-implemented temperature handling function 2025-10-10 13:27:31 +02:00
08185243bc Merge pull request 'dev-Rene' (#1) from dev-Rene into main
Reviewed-on: https://gitea.centraal.wbd-rd.nl/RnD/rotatingMachine/pulls/1
2025-10-06 14:16:18 +00:00
2 changed files with 154 additions and 134 deletions

View File

@@ -41,30 +41,12 @@ class nodeClass {
* @param {object} uiConfig - Raw config from Node-RED UI. * @param {object} uiConfig - Raw config from Node-RED UI.
*/ */
_loadConfig(uiConfig,node) { _loadConfig(uiConfig,node) {
const cfgMgr = new configManager();
// Merge UI config over defaults // Build config: base sections + rotatingMachine-specific domain config
this.config = { this.config = cfgMgr.buildConfig(this.name, uiConfig, node.id, {
general: { flowNumber: uiConfig.flowNumber
id: node.id, // node.id is for the child registration process });
unit: uiConfig.unit, // add converter options later to convert to default units (need like a model that defines this which units we are going to use and then conver to those standards)
logging: {
enabled: uiConfig.enableLog,
logLevel: uiConfig.logLevel
}
},
asset: {
uuid: uiConfig.assetUuid, //need to add this later to the asset model
tagCode: uiConfig.assetTagCode, //need to add this later to the asset model
supplier: uiConfig.supplier,
category: uiConfig.category, //add later to define as the software type
type: uiConfig.assetType,
model: uiConfig.model,
unit: uiConfig.unit
},
functionality: {
positionVsParent: uiConfig.positionVsParent
}
};
// Utility for formatting outputs // Utility for formatting outputs
this._output = new outputUtils(); this._output = new outputUtils();
@@ -189,7 +171,7 @@ class nodeClass {
} }
return status; return status;
} catch (error) { } catch (error) {
node.error("Error in updateNodeStatus: " + error.message); this.node.error("Error in updateNodeStatus: " + error.message);
return { fill: "red", shape: "ring", text: "Status Error" }; return { fill: "red", shape: "ring", text: "Status Error" };
} }
} }
@@ -241,36 +223,40 @@ class nodeClass {
* Attach the node's input handler, routing control messages to the class. * Attach the node's input handler, routing control messages to the class.
*/ */
_attachInputHandler() { _attachInputHandler() {
this.node.on('input', (msg, send, done) => { this.node.on('input', (msg, send, _done) => {
/* Update to complete event based node by putting the tick function after an input event */ /* Update to complete event based node by putting the tick function after an input event */
const m = this.source; const m = this.source;
switch(msg.topic) { switch(msg.topic) {
case 'registerChild': case 'registerChild': {
// Register this node as a child of the parent node // Register this node as a child of the parent node
const childId = msg.payload; const childId = msg.payload;
const childObj = this.RED.nodes.getNode(childId); const childObj = this.RED.nodes.getNode(childId);
m.childRegistrationUtils.registerChild(childObj.source ,msg.positionVsParent); m.childRegistrationUtils.registerChild(childObj.source ,msg.positionVsParent);
break; break;
}
case 'setMode': case 'setMode':
m.setMode(msg.payload); m.setMode(msg.payload);
break; break;
case 'execSequence': case 'execSequence': {
const { source, action, parameter } = msg.payload; const { source, action, parameter } = msg.payload;
m.handleInput(source, action, parameter); m.handleInput(source, action, parameter);
break; break;
case 'execMovement': }
case 'execMovement': {
const { source: mvSource, action: mvAction, setpoint } = msg.payload; const { source: mvSource, action: mvAction, setpoint } = msg.payload;
m.handleInput(mvSource, mvAction, Number(setpoint)); m.handleInput(mvSource, mvAction, Number(setpoint));
break; break;
case 'flowMovement': }
case 'flowMovement': {
const { source: fmSource, action: fmAction, setpoint: fmSetpoint } = msg.payload; const { source: fmSource, action: fmAction, setpoint: fmSetpoint } = msg.payload;
m.handleInput(fmSource, fmAction, Number(fmSetpoint)); m.handleInput(fmSource, fmAction, Number(fmSetpoint));
break; break;
case 'emergencystop': }
case 'emergencystop': {
const { source: esSource, action: esAction } = msg.payload; const { source: esSource, action: esAction } = msg.payload;
m.handleInput(esSource, esAction); m.handleInput(esSource, esAction);
break; break;
}
case 'showWorkingCurves': case 'showWorkingCurves':
m.showWorkingCurves(); m.showWorkingCurves();
send({ topic : "Showing curve" , payload: m.showWorkingCurves() }); send({ topic : "Showing curve" , payload: m.showWorkingCurves() });

View File

@@ -1,5 +1,5 @@
const EventEmitter = require('events'); const EventEmitter = require('events');
const {loadCurve,gravity,logger,configUtils,configManager,state, nrmse, MeasurementContainer, predict, interpolation , childRegistrationUtils,coolprop} = require('generalFunctions'); const {loadCurve,gravity,logger,configUtils,configManager,state, nrmse, MeasurementContainer, predict, interpolation , childRegistrationUtils,coolprop, POSITIONS} = require('generalFunctions');
class Machine { class Machine {
@@ -85,6 +85,10 @@ class Machine {
//perform init for certain values //perform init for certain values
this._init(); this._init();
// used for holding the source and sink unit operations or other object with setInfluent / getEffluent method for e.g. recirculation.
this.upstreamSource = null;
this.downstreamSink = null;
this.child = {}; // object to hold child information so we know on what to subscribe this.child = {}; // object to hold child information so we know on what to subscribe
this.childRegistrationUtils = new childRegistrationUtils(this); // Child registration utility this.childRegistrationUtils = new childRegistrationUtils(this); // Child registration utility
@@ -93,43 +97,58 @@ class Machine {
_init(){ _init(){
//assume standard temperature is 20degrees //assume standard temperature is 20degrees
this.measurements.type('temperature').variant('measured').position('atEquipment').value(15).unit('C'); this.measurements.type('temperature').variant('measured').position(POSITIONS.AT_EQUIPMENT).value(15).unit('C');
//assume standard atm pressure is at sea level //assume standard atm pressure is at sea level
this.measurements.type('atmPressure').variant('measured').position('atEquipment').value(101325).unit('Pa'); this.measurements.type('atmPressure').variant('measured').position(POSITIONS.AT_EQUIPMENT).value(101325).unit('Pa');
//populate min and max //populate min and max
if (this.predictFlow) {
const flowunit = this.config.general.unit; const flowunit = this.config.general.unit;
this.measurements.type('flow').variant('predicted').position('max').value(this.predictFlow.currentFxyYMax, Date.now() , flowunit) this.measurements.type('flow').variant('predicted').position('max').value(this.predictFlow.currentFxyYMax, Date.now() , flowunit);
this.measurements.type('flow').variant('predicted').position('min').value(this.predictFlow.currentFxyYMin).unit(this.config.general.unit); this.measurements.type('flow').variant('predicted').position('min').value(this.predictFlow.currentFxyYMin).unit(this.config.general.unit);
} }
}
_updateState(){ _updateState(){
const isOperational = this._isOperationalState(); const isOperational = this._isOperationalState();
if(!isOperational){ if(!isOperational){
//overrule the last prediction this should be 0 now //overrule the last prediction this should be 0 now
this.measurements.type("flow").variant("predicted").position("downstream").value(0,Date.now(),this.config.general.unit); this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(0,Date.now(),this.config.general.unit);
this.measurements.type("flow").variant("predicted").position("atEquipment").value(0,Date.now(),this.config.general.unit); this.measurements.type("flow").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(0,Date.now(),this.config.general.unit);
} }
} }
/*------------------- Register child events -------------------*/ /*------------------- Register child events -------------------*/
registerChild(child, softwareType) { registerChild(child, softwareType) {
this.logger.debug('Setting up child event for softwaretype ' + softwareType); if(!child) {
this.logger.error(`Invalid ${softwareType} child provided.`);
return;
}
if(softwareType === "measurement"){ switch (softwareType) {
const position = child.config.functionality.positionVsParent; case "measurement":
const distance = child.config.functionality.distanceVsParent || 0; this.logger.debug(`Registering measurement child...`);
const measurementType = child.config.asset.type; this._connectMeasurement(child);
const key = `${measurementType}_${position}`; break;
case "reactor":
this.logger.debug(`Registering reactor child...`);
this._connectReactor(child);
break;
default:
this.logger.error(`Unrecognized softwareType: ${softwareType}`);
}
}
_connectMeasurement(measurementChild) {
const position = measurementChild.config.functionality.positionVsParent;
const measurementType = measurementChild.config.asset.type;
//rebuild to measurementype.variant no position and then switch based on values not strings or names. //rebuild to measurementype.variant no position and then switch based on values not strings or names.
const eventName = `${measurementType}.measured.${position}`; const eventName = `${measurementType}.measured.${position}`;
this.logger.debug(`Setting up listener for ${eventName} from child ${child.config.general.name}`); this.logger.debug(`Setting up listener for ${eventName} from child ${measurementChild.config.general.name}`);
// Register event listener for measurement updates // Register event listener for measurement updates
child.measurements.emitter.on(eventName, (eventData) => { measurementChild.measurements.emitter.on(eventName, (eventData) => {
this.logger.debug(`🔄 ${position} ${measurementType} from ${eventData.childName}: ${eventData.value} ${eventData.unit}`); this.logger.debug(`🔄 ${position} ${measurementType} from ${eventData.childName}: ${eventData.value} ${eventData.unit}`);
this.logger.debug(` Emitting... ${eventName} with data:`);
// Store directly in parent's measurement container // Store directly in parent's measurement container
this.measurements this.measurements
.type(measurementType) .type(measurementType)
@@ -141,10 +160,9 @@ class Machine {
this._callMeasurementHandler(measurementType, eventData.value, position, eventData); this._callMeasurementHandler(measurementType, eventData.value, position, eventData);
}); });
} }
}
// Centralized handler dispatcher // Centralized handler dispatcher
_callMeasurementHandler(measurementType, value, position, context) { _callMeasurementHandler(measurementType, value, position, context) {
switch (measurementType) { switch (measurementType) {
case 'pressure': case 'pressure':
this.updateMeasuredPressure(value, position, context); this.updateMeasuredPressure(value, position, context);
@@ -164,15 +182,19 @@ _callMeasurementHandler(measurementType, value, position, context) {
this.updatePosition(); this.updatePosition();
break; break;
} }
} }
//---------------- END child stuff -------------// _connectReactor(reactorChild) {
this.downstreamSink = reactorChild; // downstream from the pumps perpective
}
//---------------- END child stuff -------------//
// Method to assess drift using errorMetrics // Method to assess drift using errorMetrics
assessDrift(measurement, processMin, processMax) { assessDrift(measurement, processMin, processMax) {
this.logger.debug(`Assessing drift for measurement: ${measurement} processMin: ${processMin} processMax: ${processMax}`); this.logger.debug(`Assessing drift for measurement: ${measurement} processMin: ${processMin} processMax: ${processMax}`);
const predictedMeasurement = this.measurements.type(measurement).variant("predicted").position("downstream").getAllValues().values; const predictedMeasurement = this.measurements.type(measurement).variant("predicted").position(POSITIONS.DOWNSTREAM).getAllValues().values;
const measuredMeasurement = this.measurements.type(measurement).variant("measured").position("downstream").getAllValues().values; const measuredMeasurement = this.measurements.type(measurement).variant("measured").position(POSITIONS.DOWNSTREAM).getAllValues().values;
if (!predictedMeasurement || !measuredMeasurement) return null; if (!predictedMeasurement || !measuredMeasurement) return null;
@@ -251,11 +273,12 @@ _callMeasurementHandler(measurementType, value, position, context) {
case "exitmaintenance": case "exitmaintenance":
return await this.executeSequence(parameter); return await this.executeSequence(parameter);
case "flowmovement": case "flowmovement": {
// Calculate the control value for a desired flow // Calculate the control value for a desired flow
const pos = this.calcCtrl(parameter); const pos = this.calcCtrl(parameter);
// Move to the desired setpoint // Move to the desired setpoint
return await this.setpoint(pos); return await this.setpoint(pos);
}
case "emergencystop": case "emergencystop":
this.logger.warn(`Emergency stop activated by '${source}'.`); this.logger.warn(`Emergency stop activated by '${source}'.`);
@@ -348,23 +371,23 @@ _callMeasurementHandler(measurementType, value, position, context) {
calcFlow(x) { calcFlow(x) {
if(this.hasCurve) { if(this.hasCurve) {
if (!this._isOperationalState()) { if (!this._isOperationalState()) {
this.measurements.type("flow").variant("predicted").position("downstream").value(0,Date.now(),this.config.general.unit); this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(0,Date.now(),this.config.general.unit);
this.measurements.type("flow").variant("predicted").position("atEquipment").value(0,Date.now(),this.config.general.unit); this.measurements.type("flow").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(0,Date.now(),this.config.general.unit);
this.logger.debug(`Machine is not operational. Setting predicted flow to 0.`); this.logger.debug(`Machine is not operational. Setting predicted flow to 0.`);
return 0; return 0;
} }
const cFlow = this.predictFlow.y(x); const cFlow = this.predictFlow.y(x);
this.measurements.type("flow").variant("predicted").position("downstream").value(cFlow,Date.now(),this.config.general.unit); this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(cFlow,Date.now(),this.config.general.unit);
this.measurements.type("flow").variant("predicted").position("atEquipment").value(cFlow,Date.now(),this.config.general.unit); this.measurements.type("flow").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(cFlow,Date.now(),this.config.general.unit);
//this.logger.debug(`Calculated flow: ${cFlow} for pressure: ${this.getMeasuredPressure()} and position: ${x}`); //this.logger.debug(`Calculated flow: ${cFlow} for pressure: ${this.getMeasuredPressure()} and position: ${x}`);
return cFlow; return cFlow;
} }
// If no curve data is available, log a warning and return 0 // If no curve data is available, log a warning and return 0
this.logger.warn(`No curve data available for flow calculation. Returning 0.`); this.logger.warn(`No curve data available for flow calculation. Returning 0.`);
this.measurements.type("flow").variant("predicted").position("downstream").value(0, Date.now(),this.config.general.unit); this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(0, Date.now(),this.config.general.unit);
this.measurements.type("flow").variant("predicted").position("atEquipment").value(0, Date.now(),this.config.general.unit); this.measurements.type("flow").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(0, Date.now(),this.config.general.unit);
return 0; return 0;
} }
@@ -373,20 +396,20 @@ _callMeasurementHandler(measurementType, value, position, context) {
calcPower(x) { calcPower(x) {
if(this.hasCurve) { if(this.hasCurve) {
if (!this._isOperationalState()) { if (!this._isOperationalState()) {
this.measurements.type("power").variant("predicted").position('atEquipment').value(0); this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(0);
this.logger.debug(`Machine is not operational. Setting predicted power to 0.`); this.logger.debug(`Machine is not operational. Setting predicted power to 0.`);
return 0; return 0;
} }
//this.predictPower.currentX = x; Decrepated //this.predictPower.currentX = x; Decrepated
const cPower = this.predictPower.y(x); const cPower = this.predictPower.y(x);
this.measurements.type("power").variant("predicted").position('atEquipment').value(cPower); this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(cPower);
//this.logger.debug(`Calculated power: ${cPower} for pressure: ${this.getMeasuredPressure()} and position: ${x}`); //this.logger.debug(`Calculated power: ${cPower} for pressure: ${this.getMeasuredPressure()} and position: ${x}`);
return cPower; return cPower;
} }
// If no curve data is available, log a warning and return 0 // If no curve data is available, log a warning and return 0
this.logger.warn(`No curve data available for power calculation. Returning 0.`); this.logger.warn(`No curve data available for power calculation. Returning 0.`);
this.measurements.type("power").variant("predicted").position('atEquipment').value(0); this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(0);
return 0; return 0;
} }
@@ -404,7 +427,7 @@ _callMeasurementHandler(measurementType, value, position, context) {
// If no curve data is available, log a warning and return 0 // If no curve data is available, log a warning and return 0
this.logger.warn(`No curve data available for power calculation. Returning 0.`); this.logger.warn(`No curve data available for power calculation. Returning 0.`);
this.measurements.type("power").variant("predicted").position('atEquipment').value(0); this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(0);
return 0; return 0;
} }
@@ -414,14 +437,14 @@ _callMeasurementHandler(measurementType, value, position, context) {
if(this.hasCurve) { if(this.hasCurve) {
this.predictCtrl.currentX = x; this.predictCtrl.currentX = x;
const cCtrl = this.predictCtrl.y(x); const cCtrl = this.predictCtrl.y(x);
this.measurements.type("ctrl").variant("predicted").position('atEquipment').value(cCtrl); this.measurements.type("ctrl").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(cCtrl);
//this.logger.debug(`Calculated ctrl: ${cCtrl} for pressure: ${this.getMeasuredPressure()} and position: ${x}`); //this.logger.debug(`Calculated ctrl: ${cCtrl} for pressure: ${this.getMeasuredPressure()} and position: ${x}`);
return cCtrl; return cCtrl;
} }
// If no curve data is available, log a warning and return 0 // If no curve data is available, log a warning and return 0
this.logger.warn(`No curve data available for control calculation. Returning 0.`); this.logger.warn(`No curve data available for control calculation. Returning 0.`);
this.measurements.type("ctrl").variant("predicted").position('atEquipment').value(0); this.measurements.type("ctrl").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(0);
return 0; return 0;
} }
@@ -453,7 +476,7 @@ _callMeasurementHandler(measurementType, value, position, context) {
} }
// get downstream // get downstream
const downstreamPressure = this.measurements.type('pressure').variant('measured').position('downstream').getCurrentValue(); const downstreamPressure = this.measurements.type('pressure').variant('measured').position(POSITIONS.DOWNSTREAM).getCurrentValue();
// Only downstream => use it, warn that it's partial // Only downstream => use it, warn that it's partial
if (downstreamPressure != null) { if (downstreamPressure != null) {
@@ -507,7 +530,7 @@ _callMeasurementHandler(measurementType, value, position, context) {
} }
// get // get
const upstreamFlow = this.measurements.type('flow').variant('measured').position('upstream').getCurrentValue(); const upstreamFlow = this.measurements.type('flow').variant('measured').position(POSITIONS.UPSTREAM).getCurrentValue();
// Only upstream => might still accept it, but warn // Only upstream => might still accept it, but warn
if (upstreamFlow != null) { if (upstreamFlow != null) {
@@ -516,7 +539,7 @@ _callMeasurementHandler(measurementType, value, position, context) {
} }
// get // get
const downstreamFlow = this.measurements.type('flow').variant('measured').position('downstream').getCurrentValue(); const downstreamFlow = this.measurements.type('flow').variant('measured').position(POSITIONS.DOWNSTREAM).getCurrentValue();
// Only downstream => might still accept it, but warn // Only downstream => might still accept it, but warn
if (downstreamFlow != null) { if (downstreamFlow != null) {
@@ -530,7 +553,7 @@ _callMeasurementHandler(measurementType, value, position, context) {
} }
handleMeasuredPower() { handleMeasuredPower() {
const power = this.measurements.type("power").variant("measured").position("atEquipment").getCurrentValue(); const power = this.measurements.type("power").variant("measured").position(POSITIONS.AT_EQUIPMENT).getCurrentValue();
// If your system calls it "upstream" or just a single "value", adjust accordingly // If your system calls it "upstream" or just a single "value", adjust accordingly
if (power != null) { if (power != null) {
@@ -559,6 +582,7 @@ _callMeasurementHandler(measurementType, value, position, context) {
// NEW: Flow handler // NEW: Flow handler
updateMeasuredFlow(value, position, context = {}) { updateMeasuredFlow(value, position, context = {}) {
if (!this._isOperationalState()) { if (!this._isOperationalState()) {
this.logger.warn(`Machine not operational, skipping flow update from ${context.childName || 'unknown'}`); this.logger.warn(`Machine not operational, skipping flow update from ${context.childName || 'unknown'}`);
return; return;
@@ -566,16 +590,26 @@ _callMeasurementHandler(measurementType, value, position, context) {
this.logger.debug(`Flow update: ${value} at ${position} from ${context.childName || 'child'}`); this.logger.debug(`Flow update: ${value} at ${position} from ${context.childName || 'child'}`);
if (this.upstreamSource && this.downstreamSink) {
this.updateSourceSink();
}
// Store in parent's measurement container // Store in parent's measurement container
this.measurements.type("flow").variant("measured").position(position).value(value, context.timestamp, context.unit); this.measurements.type("flow").variant("measured").position(position).value(value, context.timestamp, context.unit);
// Update predicted flow if you have prediction capability // Update predicted flow if you have prediction capability
if (this.predictFlow) { if (this.predictFlow) {
this.measurements.type("flow").variant("predicted").position("downstream").value(this.predictFlow.outputY || 0); this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(this.predictFlow.outputY || 0);
this.measurements.type("flow").variant("predicted").position("atEquipment").value(this.predictFlow.outputY || 0); this.measurements.type("flow").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(this.predictFlow.outputY || 0);
} }
} }
updateSourceSink() {
// Handles flow according to the configured "flow number"
this.logger.debug(`Updating source-sink pair: ${this.upstreamSource.config.functionality.softwareType} - ${this.downstreamSink.config.functionality.softwareType}`);
this.downstreamSink.setInfluent = this.upstreamSource.getEffluent[this.config.flowNumber];
}
// Helper method for operational state check // Helper method for operational state check
_isOperationalState() { _isOperationalState() {
const state = this.state.getCurrentState(); const state = this.state.getCurrentState();
@@ -697,35 +731,35 @@ _callMeasurementHandler(measurementType, value, position, context) {
const pressureDiff = this.measurements.type('pressure').variant('measured').difference('Pa'); const pressureDiff = this.measurements.type('pressure').variant('measured').difference('Pa');
const g = gravity.getStandardGravity(); const g = gravity.getStandardGravity();
const temp = this.measurements.type('temperature').variant('measured').position('atEquipment').getCurrentValue('K'); const temp = this.measurements.type('temperature').variant('measured').position(POSITIONS.AT_EQUIPMENT).getCurrentValue('K');
const atmPressure = this.measurements.type('atmPressure').variant('measured').position('atEquipment').getCurrentValue('Pa'); const atmPressure = this.measurements.type('atmPressure').variant('measured').position(POSITIONS.AT_EQUIPMENT).getCurrentValue('Pa');
console.log(`--------------------calc efficiency : Pressure diff:${pressureDiff},${temp}, ${g} `); console.log(`--------------------calc efficiency : Pressure diff:${pressureDiff},${temp}, ${g} `);
const rho = coolprop.PropsSI('D', 'T', temp, 'P', atmPressure, 'WasteWater'); const rho = coolprop.PropsSI('D', 'T', temp, 'P', atmPressure, 'WasteWater');
this.logger.debug(`temp: ${temp} atmPressure : ${atmPressure} rho : ${rho} pressureDiff: ${pressureDiff?.value || 0}`); this.logger.debug(`temp: ${temp} atmPressure : ${atmPressure} rho : ${rho} pressureDiff: ${pressureDiff?.value || 0}`);
const flowM3s = this.measurements.type('flow').variant('predicted').position('atEquipment').getCurrentValue('m3/s'); const flowM3s = this.measurements.type('flow').variant('predicted').position(POSITIONS.AT_EQUIPMENT).getCurrentValue('m3/s');
const powerWatt = this.measurements.type('power').variant('predicted').position('atEquipment').getCurrentValue('W'); const powerWatt = this.measurements.type('power').variant('predicted').position(POSITIONS.AT_EQUIPMENT).getCurrentValue('W');
this.logger.debug(`Flow : ${flowM3s} power: ${powerWatt}`); this.logger.debug(`Flow : ${flowM3s} power: ${powerWatt}`);
if (power != 0 && flow != 0) { if (power != 0 && flow != 0) {
const specificFlow = flow / power; const specificFlow = flow / power;
const specificEnergyConsumption = power / flow; const specificEnergyConsumption = power / flow;
this.measurements.type("efficiency").variant(variant).position('atEquipment').value(specificFlow); this.measurements.type("efficiency").variant(variant).position(POSITIONS.AT_EQUIPMENT).value(specificFlow);
this.measurements.type("specificEnergyConsumption").variant(variant).position('atEquipment').value(specificEnergyConsumption); this.measurements.type("specificEnergyConsumption").variant(variant).position(POSITIONS.AT_EQUIPMENT).value(specificEnergyConsumption);
if(pressureDiff?.value != null && flowM3s != null && powerWatt != null){ if(pressureDiff?.value != null && flowM3s != null && powerWatt != null){
const meterPerBar = pressureDiff.value / rho * g; const meterPerBar = pressureDiff.value / rho * g;
const nHydraulicEfficiency = rho * g * flowM3s * (pressureDiff.value * meterPerBar ) / powerWatt; const nHydraulicEfficiency = rho * g * flowM3s * (pressureDiff.value * meterPerBar ) / powerWatt;
this.measurements.type("nHydraulicEfficiency").variant(variant).position('atEquipment').value(nHydraulicEfficiency); this.measurements.type("nHydraulicEfficiency").variant(variant).position(POSITIONS.AT_EQUIPMENT).value(nHydraulicEfficiency);
} }
} }
//change this to nhydrefficiency ? //change this to nhydrefficiency ?
return this.measurements.type("efficiency").variant(variant).position('atEquipment').getCurrentValue(); return this.measurements.type("efficiency").variant(variant).position(POSITIONS.AT_EQUIPMENT).getCurrentValue();
} }
@@ -825,7 +859,7 @@ const PT1 = new Child(config={
}, },
functionality:{ functionality:{
softwareType:"measurement", softwareType:"measurement",
positionVsParent:"upstream", positionVsParent: POSITIONS.UPSTREAM,
}, },
asset:{ asset:{
supplier:"Vega", supplier:"Vega",
@@ -847,7 +881,7 @@ const PT2 = new Child(config={
}, },
functionality:{ functionality:{
softwareType:"measurement", softwareType:"measurement",
positionVsParent:"upstream", positionVsParent: POSITIONS.UPSTREAM,
}, },
asset:{ asset:{
supplier:"Vega", supplier:"Vega",
@@ -901,8 +935,8 @@ const machine = new Machine(machineConfig, stateConfig);
//machine.logger.info(JSON.stringify(curve["machineCurves"]["Hydrostal"]["H05K-S03R+HGM1X-X280KO"])); //machine.logger.info(JSON.stringify(curve["machineCurves"]["Hydrostal"]["H05K-S03R+HGM1X-X280KO"]));
machine.logger.info(`Registering child...`); machine.logger.info(`Registering child...`);
machine.childRegistrationUtils.registerChild(PT1, "upstream"); machine.childRegistrationUtils.registerChild(PT1, POSITIONS.UPSTREAM);
machine.childRegistrationUtils.registerChild(PT2, "downstream"); machine.childRegistrationUtils.registerChild(PT2, POSITIONS.DOWNSTREAM);
//feed curve to the machine class //feed curve to the machine class
//machine.updateCurve(curve["machineCurves"]["Hydrostal"]["H05K-S03R+HGM1X-X280KO"]); //machine.updateCurve(curve["machineCurves"]["Hydrostal"]["H05K-S03R+HGM1X-X280KO"]);
@@ -915,8 +949,8 @@ machine.getOutput();
//manual test //manual test
//machine.handleInput("parent", "execSequence", "startup"); //machine.handleInput("parent", "execSequence", "startup");
machine.measurements.type("pressure").variant("measured").position('upstream').value(-200); machine.measurements.type("pressure").variant("measured").position(POSITIONS.UPSTREAM).value(-200);
machine.measurements.type("pressure").variant("measured").position('downstream').value(1000); machine.measurements.type("pressure").variant("measured").position(POSITIONS.DOWNSTREAM).value(1000);
testingSequences(); testingSequences();