|
|
|
@@ -1,6 +1,6 @@
|
|
|
|
//load local dependencies
|
|
|
|
//load local dependencies
|
|
|
|
const EventEmitter = require("events");
|
|
|
|
const EventEmitter = require("events");
|
|
|
|
const {logger,configUtils,configManager, MeasurementContainer, interpolation , childRegistrationUtils} = require('generalFunctions');
|
|
|
|
const {logger,configUtils,configManager, MeasurementContainer, interpolation , childRegistrationUtils, POSITIONS} = require('generalFunctions');
|
|
|
|
|
|
|
|
|
|
|
|
class MachineGroup {
|
|
|
|
class MachineGroup {
|
|
|
|
constructor(machineGroupConfig = {}) {
|
|
|
|
constructor(machineGroupConfig = {}) {
|
|
|
|
@@ -75,7 +75,7 @@ class MachineGroup {
|
|
|
|
Object.values(this.machines).forEach(machine => {
|
|
|
|
Object.values(this.machines).forEach(machine => {
|
|
|
|
const totals = { flow: { min: Infinity, max: 0 }, power: { min: Infinity, max: 0 } };
|
|
|
|
const totals = { flow: { min: Infinity, max: 0 }, power: { min: Infinity, max: 0 } };
|
|
|
|
//fetch min flow ever seen over all machines
|
|
|
|
//fetch min flow ever seen over all machines
|
|
|
|
Object.entries(machine.predictFlow.inputCurve).forEach(([pressure, xyCurve], index) => {
|
|
|
|
Object.entries(machine.predictFlow.inputCurve).forEach(([pressure, xyCurve], _index) => {
|
|
|
|
const minFlow = Math.min(...xyCurve.y);
|
|
|
|
const minFlow = Math.min(...xyCurve.y);
|
|
|
|
const maxFlow = Math.max(...xyCurve.y);
|
|
|
|
const maxFlow = Math.max(...xyCurve.y);
|
|
|
|
|
|
|
|
|
|
|
|
@@ -140,8 +140,8 @@ class MachineGroup {
|
|
|
|
const maxFlow = machine.predictFlow.currentFxyYMax;
|
|
|
|
const maxFlow = machine.predictFlow.currentFxyYMax;
|
|
|
|
const minPower = machine.predictPower.currentFxyYMin;
|
|
|
|
const minPower = machine.predictPower.currentFxyYMin;
|
|
|
|
const maxPower = machine.predictPower.currentFxyYMax;
|
|
|
|
const maxPower = machine.predictPower.currentFxyYMax;
|
|
|
|
const actFlow = machine.measurements.type("flow").variant("predicted").position("downstream").getCurrentValue();
|
|
|
|
const actFlow = machine.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).getCurrentValue();
|
|
|
|
const actPower = machine.measurements.type("power").variant("predicted").position("atEquipment").getCurrentValue();
|
|
|
|
const actPower = machine.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).getCurrentValue();
|
|
|
|
|
|
|
|
|
|
|
|
this.logger.debug(`Machine ${machine.config.general.id} - Min Flow: ${minFlow}, Max Flow: ${maxFlow}, Min Power: ${minPower}, Max Power: ${maxPower}, NCog: ${machine.NCog}`);
|
|
|
|
this.logger.debug(`Machine ${machine.config.general.id} - Min Flow: ${minFlow}, Max Flow: ${maxFlow}, Min Power: ${minPower}, Max Power: ${maxPower}, NCog: ${machine.NCog}`);
|
|
|
|
|
|
|
|
|
|
|
|
@@ -195,11 +195,11 @@ class MachineGroup {
|
|
|
|
const { flow, power } = this.calcDynamicTotals();
|
|
|
|
const { flow, power } = this.calcDynamicTotals();
|
|
|
|
|
|
|
|
|
|
|
|
this.logger.debug(`Dynamic Totals after pressure change - Flow: Min ${flow.min}, Max ${flow.max}, Act ${flow.act} | Power: Min ${power.min}, Max ${power.max}, Act ${power.act}`);
|
|
|
|
this.logger.debug(`Dynamic Totals after pressure change - Flow: Min ${flow.min}, Max ${flow.max}, Act ${flow.act} | Power: Min ${power.min}, Max ${power.max}, Act ${power.act}`);
|
|
|
|
this.measurements.type("flow").variant("predicted").position("downstream").value(flow.act);
|
|
|
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(flow.act);
|
|
|
|
this.measurements.type("power").variant("predicted").position("atEquipment").value(power.act);
|
|
|
|
this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(power.act);
|
|
|
|
|
|
|
|
|
|
|
|
const { maxEfficiency, lowestEfficiency } = this.calcGroupEfficiency(this.machines);
|
|
|
|
const { maxEfficiency, lowestEfficiency } = this.calcGroupEfficiency(this.machines);
|
|
|
|
const efficiency = this.measurements.type("efficiency").variant("predicted").position("atEquipment").getCurrentValue();
|
|
|
|
const efficiency = this.measurements.type("efficiency").variant("predicted").position(POSITIONS.AT_EQUIPMENT).getCurrentValue();
|
|
|
|
this.calcDistanceBEP(efficiency,maxEfficiency,lowestEfficiency);
|
|
|
|
this.calcDistanceBEP(efficiency,maxEfficiency,lowestEfficiency);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -235,11 +235,11 @@ class MachineGroup {
|
|
|
|
//add special cases
|
|
|
|
//add special cases
|
|
|
|
if( state === "operational" && ( mode == "virtualControl" || mode === "fysicalControl") ){
|
|
|
|
if( state === "operational" && ( mode == "virtualControl" || mode === "fysicalControl") ){
|
|
|
|
let flow = 0;
|
|
|
|
let flow = 0;
|
|
|
|
if(machine.measurements.type("flow").variant("measured").position("downstream").getCurrentValue()){
|
|
|
|
if(machine.measurements.type("flow").variant("measured").position(POSITIONS.DOWNSTREAM).getCurrentValue()){
|
|
|
|
flow = machine.measurements.type("flow").variant("measured").position("downstream").getCurrentValue();
|
|
|
|
flow = machine.measurements.type("flow").variant("measured").position(POSITIONS.DOWNSTREAM).getCurrentValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(machine.measurements.type("flow").variant("predicted").position("downstream").getCurrentValue()){
|
|
|
|
else if(machine.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).getCurrentValue()){
|
|
|
|
flow = machine.measurements.type("flow").variant("predicted").position("downstream").getCurrentValue();
|
|
|
|
flow = machine.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).getCurrentValue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else{
|
|
|
|
this.logger.error("Dont perform calculation at all seeing that there is a machine working but we dont know the flow its producing");
|
|
|
|
this.logger.error("Dont perform calculation at all seeing that there is a machine working but we dont know the flow its producing");
|
|
|
|
@@ -389,10 +389,10 @@ class MachineGroup {
|
|
|
|
try{
|
|
|
|
try{
|
|
|
|
//we need to force the pressures of all machines to be equal to the highest pressure measured in the group
|
|
|
|
//we need to force the pressures of all machines to be equal to the highest pressure measured in the group
|
|
|
|
// this is to ensure a correct evaluation of the flow and power consumption
|
|
|
|
// this is to ensure a correct evaluation of the flow and power consumption
|
|
|
|
const pressures = Object.entries(this.machines).map(([machineId, machine]) => {
|
|
|
|
const pressures = Object.entries(this.machines).map(([_machineId, machine]) => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
downstream: machine.measurements.type("pressure").variant("measured").position("downstream").getCurrentValue(),
|
|
|
|
downstream: machine.measurements.type("pressure").variant("measured").position(POSITIONS.DOWNSTREAM).getCurrentValue(),
|
|
|
|
upstream: machine.measurements.type("pressure").variant("measured").position("upstream").getCurrentValue()
|
|
|
|
upstream: machine.measurements.type("pressure").variant("measured").position(POSITIONS.UPSTREAM).getCurrentValue()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
@@ -402,12 +402,12 @@ class MachineGroup {
|
|
|
|
this.logger.debug(`Max downstream pressure: ${maxDownstream}, Min upstream pressure: ${minUpstream}`);
|
|
|
|
this.logger.debug(`Max downstream pressure: ${maxDownstream}, Min upstream pressure: ${minUpstream}`);
|
|
|
|
|
|
|
|
|
|
|
|
//set the pressures
|
|
|
|
//set the pressures
|
|
|
|
Object.entries(this.machines).forEach(([machineId, machine]) => {
|
|
|
|
Object.entries(this.machines).forEach(([_machineId, machine]) => {
|
|
|
|
if(machine.state.getCurrentState() !== "operational" && machine.state.getCurrentState() !== "accelerating" && machine.state.getCurrentState() !== "decelerating"){
|
|
|
|
if(machine.state.getCurrentState() !== "operational" && machine.state.getCurrentState() !== "accelerating" && machine.state.getCurrentState() !== "decelerating"){
|
|
|
|
|
|
|
|
|
|
|
|
//Equilize pressures over all machines so we can make a proper calculation
|
|
|
|
//Equilize pressures over all machines so we can make a proper calculation
|
|
|
|
machine.measurements.type("pressure").variant("measured").position("downstream").value(maxDownstream);
|
|
|
|
machine.measurements.type("pressure").variant("measured").position(POSITIONS.DOWNSTREAM).value(maxDownstream);
|
|
|
|
machine.measurements.type("pressure").variant("measured").position("upstream").value(minUpstream);
|
|
|
|
machine.measurements.type("pressure").variant("measured").position(POSITIONS.UPSTREAM).value(minUpstream);
|
|
|
|
|
|
|
|
|
|
|
|
// after updating the measurement directly we need to force the update of the value OLIFANT this is not so clear now in the code
|
|
|
|
// after updating the measurement directly we need to force the update of the value OLIFANT this is not so clear now in the code
|
|
|
|
// we need to find a better way to do this but for now it works
|
|
|
|
// we need to find a better way to do this but for now it works
|
|
|
|
@@ -451,10 +451,10 @@ class MachineGroup {
|
|
|
|
this.logger.debug(`Moving to demand: ${Qd.toFixed(2)} -> Pumps: [${debugInfo}] => Total Power: ${bestResult.bestPower.toFixed(2)}`);
|
|
|
|
this.logger.debug(`Moving to demand: ${Qd.toFixed(2)} -> Pumps: [${debugInfo}] => Total Power: ${bestResult.bestPower.toFixed(2)}`);
|
|
|
|
|
|
|
|
|
|
|
|
//store the total delivered power
|
|
|
|
//store the total delivered power
|
|
|
|
this.measurements.type("power").variant("predicted").position("atEquipment").value(bestResult.bestPower);
|
|
|
|
this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(bestResult.bestPower);
|
|
|
|
this.measurements.type("flow").variant("predicted").position("downstream").value(bestResult.bestFlow);
|
|
|
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(bestResult.bestFlow);
|
|
|
|
this.measurements.type("efficiency").variant("predicted").position("atEquipment").value(bestResult.bestFlow / bestResult.bestPower);
|
|
|
|
this.measurements.type("efficiency").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(bestResult.bestFlow / bestResult.bestPower);
|
|
|
|
this.measurements.type("Ncog").variant("predicted").position("atEquipment").value(bestResult.bestCog);
|
|
|
|
this.measurements.type("Ncog").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(bestResult.bestCog);
|
|
|
|
|
|
|
|
|
|
|
|
await Promise.all(Object.entries(this.machines).map(async ([machineId, machine]) => {
|
|
|
|
await Promise.all(Object.entries(this.machines).map(async ([machineId, machine]) => {
|
|
|
|
// Find the flow for this machine in the best combination
|
|
|
|
// Find the flow for this machine in the best combination
|
|
|
|
@@ -490,10 +490,10 @@ class MachineGroup {
|
|
|
|
// Equalize pressure across all machines for machines that are not running. This is needed to ensure accurate flow and power predictions.
|
|
|
|
// Equalize pressure across all machines for machines that are not running. This is needed to ensure accurate flow and power predictions.
|
|
|
|
equalizePressure(){
|
|
|
|
equalizePressure(){
|
|
|
|
// Get current pressures from all machines
|
|
|
|
// Get current pressures from all machines
|
|
|
|
const pressures = Object.entries(this.machines).map(([machineId, machine]) => {
|
|
|
|
const pressures = Object.entries(this.machines).map(([_machineId, machine]) => {
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
downstream: machine.measurements.type("pressure").variant("measured").position("downstream").getCurrentValue(),
|
|
|
|
downstream: machine.measurements.type("pressure").variant("measured").position(POSITIONS.DOWNSTREAM).getCurrentValue(),
|
|
|
|
upstream: machine.measurements.type("pressure").variant("measured").position("upstream").getCurrentValue()
|
|
|
|
upstream: machine.measurements.type("pressure").variant("measured").position(POSITIONS.UPSTREAM).getCurrentValue()
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
@@ -504,8 +504,8 @@ class MachineGroup {
|
|
|
|
// Set consistent pressures across machines
|
|
|
|
// Set consistent pressures across machines
|
|
|
|
Object.entries(this.machines).forEach(([machineId, machine]) => {
|
|
|
|
Object.entries(this.machines).forEach(([machineId, machine]) => {
|
|
|
|
if(!this.isMachineActive(machineId)){
|
|
|
|
if(!this.isMachineActive(machineId)){
|
|
|
|
machine.measurements.type("pressure").variant("measured").position("downstream").value(maxDownstream);
|
|
|
|
machine.measurements.type("pressure").variant("measured").position(POSITIONS.DOWNSTREAM).value(maxDownstream);
|
|
|
|
machine.measurements.type("pressure").variant("measured").position("upstream").value(minUpstream);
|
|
|
|
machine.measurements.type("pressure").variant("measured").position(POSITIONS.UPSTREAM).value(minUpstream);
|
|
|
|
// Update the measured pressure value
|
|
|
|
// Update the measured pressure value
|
|
|
|
const pressure = machine.getMeasuredPressure();
|
|
|
|
const pressure = machine.getMeasuredPressure();
|
|
|
|
this.logger.debug(`Setting pressure for machine ${machineId} to ${pressure}`);
|
|
|
|
this.logger.debug(`Setting pressure for machine ${machineId} to ${pressure}`);
|
|
|
|
@@ -549,7 +549,7 @@ class MachineGroup {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
filterOutUnavailableMachines(list) {
|
|
|
|
filterOutUnavailableMachines(list) {
|
|
|
|
const newList = list.filter(({ id, machine }) => {
|
|
|
|
const newList = list.filter(({ machine }) => {
|
|
|
|
const state = machine.state.getCurrentState();
|
|
|
|
const state = machine.state.getCurrentState();
|
|
|
|
const validActionForMode = machine.isValidActionForMode("execSequence", "auto");
|
|
|
|
const validActionForMode = machine.isValidActionForMode("execSequence", "auto");
|
|
|
|
|
|
|
|
|
|
|
|
@@ -564,7 +564,7 @@ class MachineGroup {
|
|
|
|
let lowestEfficiency = Infinity;
|
|
|
|
let lowestEfficiency = Infinity;
|
|
|
|
|
|
|
|
|
|
|
|
// Calculate the average efficiency of all machines -> peak is the average of them all
|
|
|
|
// Calculate the average efficiency of all machines -> peak is the average of them all
|
|
|
|
Object.entries(machines).forEach(([machineId, machine]) => {
|
|
|
|
Object.entries(machines).forEach(([_machineId, machine]) => {
|
|
|
|
cumEfficiency += machine.cog;
|
|
|
|
cumEfficiency += machine.cog;
|
|
|
|
if(machine.cog < lowestEfficiency){
|
|
|
|
if(machine.cog < lowestEfficiency){
|
|
|
|
lowestEfficiency = machine.cog;
|
|
|
|
lowestEfficiency = machine.cog;
|
|
|
|
@@ -579,7 +579,7 @@ class MachineGroup {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//move machines assuming equal control in flow and a priority list
|
|
|
|
//move machines assuming equal control in flow and a priority list
|
|
|
|
async equalFlowControl(Qd, powerCap = Infinity, priorityList = null) {
|
|
|
|
async equalFlowControl(Qd, _powerCap = Infinity, priorityList = null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
|
|
// equalize pressure across all machines
|
|
|
|
// equalize pressure across all machines
|
|
|
|
@@ -634,7 +634,7 @@ class MachineGroup {
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case (Qd > activeTotals.flow.max):
|
|
|
|
case (Qd > activeTotals.flow.max): {
|
|
|
|
// Case 2: Demand is above the maximum available flow.
|
|
|
|
// Case 2: Demand is above the maximum available flow.
|
|
|
|
// Start the non-active machine with the highest priority and distribute Qd over all available machines.
|
|
|
|
// Start the non-active machine with the highest priority and distribute Qd over all available machines.
|
|
|
|
let i = 1;
|
|
|
|
let i = 1;
|
|
|
|
@@ -654,9 +654,10 @@ class MachineGroup {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
default: {
|
|
|
|
// Default case: Demand is within the active range.
|
|
|
|
// Default case: Demand is within the active range.
|
|
|
|
const countActiveMachines = machinesInPriorityOrder.filter(({ id }) => this.isMachineActive(id)).length;
|
|
|
|
const countActiveMachines = machinesInPriorityOrder.filter(({ id }) => this.isMachineActive(id)).length;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -671,6 +672,7 @@ class MachineGroup {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Log information about flow distribution
|
|
|
|
// Log information about flow distribution
|
|
|
|
const debugInfo = flowDistribution
|
|
|
|
const debugInfo = flowDistribution
|
|
|
|
@@ -681,10 +683,10 @@ class MachineGroup {
|
|
|
|
this.logger.debug(`Priority control for demand: ${totalFlow.toFixed(2)} -> Active pumps: [${debugInfo}] => Total Power: ${totalPower.toFixed(2)}`);
|
|
|
|
this.logger.debug(`Priority control for demand: ${totalFlow.toFixed(2)} -> Active pumps: [${debugInfo}] => Total Power: ${totalPower.toFixed(2)}`);
|
|
|
|
|
|
|
|
|
|
|
|
// Store measurements
|
|
|
|
// Store measurements
|
|
|
|
this.measurements.type("power").variant("predicted").position("atEquipment").value(totalPower);
|
|
|
|
this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(totalPower);
|
|
|
|
this.measurements.type("flow").variant("predicted").position("downstream").value(totalFlow);
|
|
|
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(totalFlow);
|
|
|
|
this.measurements.type("efficiency").variant("predicted").position("atEquipment").value(totalFlow / totalPower);
|
|
|
|
this.measurements.type("efficiency").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(totalFlow / totalPower);
|
|
|
|
this.measurements.type("Ncog").variant("predicted").position("atEquipment").value(totalCog);
|
|
|
|
this.measurements.type("Ncog").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(totalCog);
|
|
|
|
|
|
|
|
|
|
|
|
this.logger.debug(`Flow distribution: ${JSON.stringify(flowDistribution)}`);
|
|
|
|
this.logger.debug(`Flow distribution: ${JSON.stringify(flowDistribution)}`);
|
|
|
|
// Apply the flow distribution to machines
|
|
|
|
// Apply the flow distribution to machines
|
|
|
|
@@ -722,7 +724,7 @@ class MachineGroup {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//capp input to 100
|
|
|
|
//capp input to 100
|
|
|
|
input > 100 ? input = 100 : input = input;
|
|
|
|
if (input > 100) { input = 100; }
|
|
|
|
|
|
|
|
|
|
|
|
const numOfMachines = Object.keys(this.machines).length;
|
|
|
|
const numOfMachines = Object.keys(this.machines).length;
|
|
|
|
const procentTotal = numOfMachines * input;
|
|
|
|
const procentTotal = numOfMachines * input;
|
|
|
|
@@ -736,7 +738,7 @@ class MachineGroup {
|
|
|
|
if(machinesNeeded > machinesActive){
|
|
|
|
if(machinesNeeded > machinesActive){
|
|
|
|
|
|
|
|
|
|
|
|
//start extra machine and put all active machines at min control
|
|
|
|
//start extra machine and put all active machines at min control
|
|
|
|
machinesInPriorityOrder.forEach(({ id, machine }, index) => {
|
|
|
|
machinesInPriorityOrder.forEach(({ id }, index) => {
|
|
|
|
if(index < machinesNeeded){
|
|
|
|
if(index < machinesNeeded){
|
|
|
|
ctrlDistribution.push({machineId : id, ctrl : 0});
|
|
|
|
ctrlDistribution.push({machineId : id, ctrl : 0});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -745,7 +747,7 @@ class MachineGroup {
|
|
|
|
|
|
|
|
|
|
|
|
if(machinesNeeded < machinesActive){
|
|
|
|
if(machinesNeeded < machinesActive){
|
|
|
|
|
|
|
|
|
|
|
|
machinesInPriorityOrder.forEach(({ id, machine }, index) => {
|
|
|
|
machinesInPriorityOrder.forEach(({ id }, index) => {
|
|
|
|
if(this.isMachineActive(id)){
|
|
|
|
if(this.isMachineActive(id)){
|
|
|
|
if(index < machinesNeeded){
|
|
|
|
if(index < machinesNeeded){
|
|
|
|
ctrlDistribution.push({machineId : id, ctrl : 100});
|
|
|
|
ctrlDistribution.push({machineId : id, ctrl : 100});
|
|
|
|
@@ -762,7 +764,7 @@ class MachineGroup {
|
|
|
|
// distribute input equally among active machines (0 - 100%)
|
|
|
|
// distribute input equally among active machines (0 - 100%)
|
|
|
|
const ctrlPerMachine = procentTotal / machinesActive;
|
|
|
|
const ctrlPerMachine = procentTotal / machinesActive;
|
|
|
|
|
|
|
|
|
|
|
|
machinesInPriorityOrder.forEach(({ id, machine }) => {
|
|
|
|
machinesInPriorityOrder.forEach(({ id }) => {
|
|
|
|
if (this.isMachineActive(id)) {
|
|
|
|
if (this.isMachineActive(id)) {
|
|
|
|
// ensure ctrl is capped between 0 and 100%
|
|
|
|
// ensure ctrl is capped between 0 and 100%
|
|
|
|
const ctrlValue = Math.max(0, Math.min(ctrlPerMachine, 100));
|
|
|
|
const ctrlValue = Math.max(0, Math.min(ctrlPerMachine, 100));
|
|
|
|
@@ -794,10 +796,10 @@ class MachineGroup {
|
|
|
|
const totalFlow = [];
|
|
|
|
const totalFlow = [];
|
|
|
|
|
|
|
|
|
|
|
|
// fetch and store measurements
|
|
|
|
// fetch and store measurements
|
|
|
|
Object.entries(this.machines).forEach(([machineId, machine]) => {
|
|
|
|
Object.entries(this.machines).forEach(([_machineId, machine]) => {
|
|
|
|
|
|
|
|
|
|
|
|
const powerValue = machine.measurements.type("power").variant("predicted").position("atEquipment").getCurrentValue();
|
|
|
|
const powerValue = machine.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).getCurrentValue();
|
|
|
|
const flowValue = machine.measurements.type("flow").variant("predicted").position("downstream").getCurrentValue();
|
|
|
|
const flowValue = machine.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).getCurrentValue();
|
|
|
|
|
|
|
|
|
|
|
|
if (powerValue !== null) {
|
|
|
|
if (powerValue !== null) {
|
|
|
|
totalPower.push(powerValue);
|
|
|
|
totalPower.push(powerValue);
|
|
|
|
@@ -807,11 +809,11 @@ class MachineGroup {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
this.measurements.type("power").variant("predicted").position("atEquipment").value(totalPower.reduce((a, b) => a + b, 0));
|
|
|
|
this.measurements.type("power").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(totalPower.reduce((a, b) => a + b, 0));
|
|
|
|
this.measurements.type("flow").variant("predicted").position("downstream").value(totalFlow.reduce((a, b) => a + b, 0));
|
|
|
|
this.measurements.type("flow").variant("predicted").position(POSITIONS.DOWNSTREAM).value(totalFlow.reduce((a, b) => a + b, 0));
|
|
|
|
|
|
|
|
|
|
|
|
if(totalPower.reduce((a, b) => a + b, 0) > 0){
|
|
|
|
if(totalPower.reduce((a, b) => a + b, 0) > 0){
|
|
|
|
this.measurements.type("efficiency").variant("predicted").position("atEquipment").value(totalFlow.reduce((a, b) => a + b, 0) / totalPower.reduce((a, b) => a + b, 0));
|
|
|
|
this.measurements.type("efficiency").variant("predicted").position(POSITIONS.AT_EQUIPMENT).value(totalFlow.reduce((a, b) => a + b, 0) / totalPower.reduce((a, b) => a + b, 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -841,12 +843,12 @@ class MachineGroup {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (demandQ < absoluteTotals.flow.min) {
|
|
|
|
if (demandQ < this.absoluteTotals.flow.min) {
|
|
|
|
this.logger.warn(`Flow demand ${demandQ} is below minimum possible flow ${absoluteTotals.flow.min}. Capping to minimum flow.`);
|
|
|
|
this.logger.warn(`Flow demand ${demandQ} is below minimum possible flow ${this.absoluteTotals.flow.min}. Capping to minimum flow.`);
|
|
|
|
demandQout = this.absoluteTotals.flow.min;
|
|
|
|
demandQout = this.absoluteTotals.flow.min;
|
|
|
|
} else if (demandQout > absoluteTotals.flow.max) {
|
|
|
|
} else if (demandQout > this.absoluteTotals.flow.max) {
|
|
|
|
this.logger.warn(`Flow demand ${demandQ} is above maximum possible flow ${absoluteTotals.flow.max}. Capping to maximum flow.`);
|
|
|
|
this.logger.warn(`Flow demand ${demandQ} is above maximum possible flow ${this.absoluteTotals.flow.max}. Capping to maximum flow.`);
|
|
|
|
demandQout = absoluteTotals.flow.max;
|
|
|
|
demandQout = this.absoluteTotals.flow.max;
|
|
|
|
}else if(demandQout <= 0){
|
|
|
|
}else if(demandQout <= 0){
|
|
|
|
this.logger.debug(`Turning machines off`);
|
|
|
|
this.logger.debug(`Turning machines off`);
|
|
|
|
demandQout = 0;
|
|
|
|
demandQout = 0;
|
|
|
|
@@ -904,7 +906,7 @@ class MachineGroup {
|
|
|
|
|
|
|
|
|
|
|
|
//recalc distance from BEP
|
|
|
|
//recalc distance from BEP
|
|
|
|
const { maxEfficiency, lowestEfficiency } = this.calcGroupEfficiency(this.machines);
|
|
|
|
const { maxEfficiency, lowestEfficiency } = this.calcGroupEfficiency(this.machines);
|
|
|
|
const efficiency = this.measurements.type("efficiency").variant("predicted").position("downstream").getCurrentValue();
|
|
|
|
const efficiency = this.measurements.type("efficiency").variant("predicted").position(POSITIONS.DOWNSTREAM).getCurrentValue();
|
|
|
|
this.calcDistanceBEP(efficiency,maxEfficiency,lowestEfficiency);
|
|
|
|
this.calcDistanceBEP(efficiency,maxEfficiency,lowestEfficiency);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -928,9 +930,9 @@ class MachineGroup {
|
|
|
|
this.measurements.getTypes().forEach(type => {
|
|
|
|
this.measurements.getTypes().forEach(type => {
|
|
|
|
this.measurements.getVariants(type).forEach(variant => {
|
|
|
|
this.measurements.getVariants(type).forEach(variant => {
|
|
|
|
|
|
|
|
|
|
|
|
const downstreamVal = this.measurements.type(type).variant(variant).position("downstream").getCurrentValue();
|
|
|
|
const downstreamVal = this.measurements.type(type).variant(variant).position(POSITIONS.DOWNSTREAM).getCurrentValue();
|
|
|
|
const atEquipmentVal = this.measurements.type(type).variant(variant).position("atEquipment").getCurrentValue();
|
|
|
|
const atEquipmentVal = this.measurements.type(type).variant(variant).position(POSITIONS.AT_EQUIPMENT).getCurrentValue();
|
|
|
|
const upstreamVal = this.measurements.type(type).variant(variant).position("upstream").getCurrentValue();
|
|
|
|
const upstreamVal = this.measurements.type(type).variant(variant).position(POSITIONS.UPSTREAM).getCurrentValue();
|
|
|
|
|
|
|
|
|
|
|
|
if (downstreamVal != null) {
|
|
|
|
if (downstreamVal != null) {
|
|
|
|
output[`downstream_${variant}_${type}`] = downstreamVal;
|
|
|
|
output[`downstream_${variant}_${type}`] = downstreamVal;
|
|
|
|
@@ -1087,11 +1089,11 @@ async function makeMachines(){
|
|
|
|
for(let i = 1; i <= numofMachines; i++){
|
|
|
|
for(let i = 1; i <= numofMachines; i++){
|
|
|
|
const machine = new Machine(machineConfigs[i],stateConfigs[i]);
|
|
|
|
const machine = new Machine(machineConfigs[i],stateConfigs[i]);
|
|
|
|
//mg.machines[i] = machine;
|
|
|
|
//mg.machines[i] = machine;
|
|
|
|
mg.childRegistrationUtils.registerChild(machine, "downstream");
|
|
|
|
mg.childRegistrationUtils.registerChild(machine, POSITIONS.DOWNSTREAM);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Object.keys(mg.machines).forEach(machineId => {
|
|
|
|
Object.keys(mg.machines).forEach(machineId => {
|
|
|
|
mg.machines[machineId].childRegistrationUtils.registerChild(pt1, "downstream");
|
|
|
|
mg.machines[machineId].childRegistrationUtils.registerChild(pt1, POSITIONS.DOWNSTREAM);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
mg.setMode("prioritycontrol");
|
|
|
|
mg.setMode("prioritycontrol");
|
|
|
|
|