AMO-Tools-Suite  v.0.9.0
Set of tools for calculating energy efficiency in industrial equipment
All Classes Namespaces Files Functions Variables Enumerations Friends Macros Pages
psat.h
1 #ifndef AMO_TOOLS_SUITE_PSAT_BRIDGE_H
2 #define AMO_TOOLS_SUITE_PSAT_BRIDGE_H
3 
4 #include <iostream>
5 
6 #include <map>
7 #include <unordered_map>
8 #include <nan.h>
9 #include <node.h>
10 #include <vector>
11 #include <array>
12 #include "results/Results.h"
13 #include "results/InputData.h"
14 #include "calculator/motor/EstimateFLA.h"
15 #include "calculator/motor/MotorCurrent.h"
16 #include "calculator/motor/MotorEfficiency.h"
17 #include "calculator/motor/MotorPowerFactor.h"
18 #include "calculator/pump/OptimalPrePumpEff.h"
19 #include "calculator/pump/OptimalSpecificSpeedCorrection.h"
20 #include "calculator/pump/OptimalDeviationFactor.h"
21 #include "calculator/pump/HeadTool.h"
22 #include "calculator/util/Conversion.h"
23 
24 using namespace Nan;
25 using namespace v8;
26 
27 //
29 //
30 //Isolate* iso;
31 Local<Object> inp;
32 Local<Object> r;
33 
34 //NAN function for fetching value associated with provided key
35 double Get(std::string const & nm) {
36  Local<String> getName = Nan::New<String>(nm).ToLocalChecked();
37  v8::Isolate *isolate = v8::Isolate::GetCurrent();
38  v8::Local<v8::Context> context = isolate->GetCurrentContext();
39  Local<Value> rObj = Nan::To<Object>(inp).ToLocalChecked()->Get(context, getName).ToLocalChecked();
40  if (rObj->IsUndefined()) {
41  ThrowTypeError(std::string("Get method in psat.h: " + nm + " not present in object").c_str());
42  }
43  return Nan::To<double>(rObj).FromJust();
44 }
45 
46 //NAN function for binding data to anonymous object
47 void SetR(const char *nm, double n)
48 {
49  Local<String> getName = Nan::New<String>(nm).ToLocalChecked();
50  Local<Number> getNum = Nan::New<Number>(n);
51  Nan::Set(r, getName, getNum);
52 }
53 
54 NAN_METHOD(headToolSuctionTank)
55 {
56  //NAN initialize data
57  inp = Nan::To<Object>(info[0]).ToLocalChecked();
58  r = Nan::New<Object>();
59  const double specificGravity = Get("specificGravity");
60  const double flowRate = Get("flowRate");
61  const double suctionPipeDiameter = Get("suctionPipeDiameter");
62  const double suctionTankGasOverPressure = Get("suctionTankGasOverPressure");
63  const double suctionTankFluidSurfaceElevation = Get("suctionTankFluidSurfaceElevation");
64  const double suctionLineLossCoefficients = Get("suctionLineLossCoefficients");
65  const double dischargePipeDiameter = Get("dischargePipeDiameter");
66  const double dischargeGaugePressure = Get("dischargeGaugePressure");
67  const double dischargeGaugeElevation = Get("dischargeGaugeElevation");
68  const double dischargeLineLossCoefficients = Get("dischargeLineLossCoefficients");
69 
70  //Calculation procedure
71  auto rv = HeadToolSuctionTank(specificGravity, flowRate, suctionPipeDiameter, suctionTankGasOverPressure,
72  suctionTankFluidSurfaceElevation, suctionLineLossCoefficients, dischargePipeDiameter,
73  dischargeGaugePressure, dischargeGaugeElevation, dischargeLineLossCoefficients)
74  .calculate();
75 
76  //NAN return data
77  SetR("differentialElevationHead", rv.elevationHead);
78  SetR("differentialPressureHead", rv.pressureHead);
79  SetR("differentialVelocityHead", rv.velocityHeadDifferential);
80  SetR("estimatedSuctionFrictionHead", rv.suctionHead);
81  SetR("estimatedDischargeFrictionHead", rv.dischargeHead);
82  SetR("pumpHead", rv.pumpHead);
83  info.GetReturnValue().Set(r);
84 }
85 
86 NAN_METHOD(headTool)
87 {
88  //NAN initialize data
89  inp = Nan::To<Object>(info[0]).ToLocalChecked();
90  r = Nan::New<Object>();
91  const double specificGravity = Get("specificGravity");
92  const double flowRate = Get("flowRate");
93  const double suctionPipeDiameter = Get("suctionPipeDiameter");
94  const double suctionGaugePressure = Get("suctionGaugePressure");
95  const double suctionGaugeElevation = Get("suctionGaugeElevation");
96  const double suctionLineLossCoefficients = Get("suctionLineLossCoefficients");
97  const double dischargePipeDiameter = Get("dischargePipeDiameter");
98  const double dischargeGaugePressure = Get("dischargeGaugePressure");
99  const double dischargeGaugeElevation = Get("dischargeGaugeElevation");
100  const double dischargeLineLossCoefficients = Get("dischargeLineLossCoefficients");
101 
102  //Calculation procedure
103  auto rv = HeadTool(specificGravity, flowRate, suctionPipeDiameter, suctionGaugePressure,
104  suctionGaugeElevation, suctionLineLossCoefficients, dischargePipeDiameter,
105  dischargeGaugePressure, dischargeGaugeElevation, dischargeLineLossCoefficients)
106  .calculate();
107 
108  //NAN return data
109  SetR("differentialElevationHead", rv.elevationHead);
110  SetR("differentialPressureHead", rv.pressureHead);
111  SetR("differentialVelocityHead", rv.velocityHeadDifferential);
112  SetR("estimatedSuctionFrictionHead", rv.suctionHead);
113  SetR("estimatedDischargeFrictionHead", rv.dischargeHead);
114  SetR("pumpHead", rv.pumpHead);
115  info.GetReturnValue().Set(r);
116 }
117 
118 // Fields
119 
120 Motor::LineFrequency line()
121 {
122  unsigned val = static_cast<unsigned>(Get("line_frequency"));
123  return static_cast<Motor::LineFrequency>(val);
124 }
125 Motor::EfficiencyClass effCls()
126 {
127  unsigned val = static_cast<unsigned>(Get("efficiency_class"));
128  return static_cast<Motor::EfficiencyClass>(val);
129 }
130 Motor::Drive drive()
131 {
132  unsigned val = static_cast<unsigned>(Get("drive"));
133  return static_cast<Motor::Drive>(val);
134 }
135 Pump::Style style()
136 {
137  unsigned val = static_cast<unsigned>(Get("pump_style"));
138  return static_cast<Pump::Style>(val);
139 }
140 Motor::LoadEstimationMethod loadEstimationMethod()
141 {
142  unsigned val = static_cast<unsigned>(Get("load_estimation_method"));
143  return static_cast<Motor::LoadEstimationMethod>(val);
144 }
145 Pump::SpecificSpeed speed()
146 {
147  unsigned val = static_cast<unsigned>(Get("fixed_speed"));
148  return static_cast<Pump::SpecificSpeed>(val);
149 }
150 
151 NAN_METHOD(resultsExisting)
152 {
153  //NAN initialize data
154  inp = Nan::To<Object>(info[0]).ToLocalChecked();
155  r = Nan::New<Object>();
156  Pump::Style style1 = style();
157  double pumpSpecified = Get("pump_specified");
158  double pumpRatedSpeed = Get("pump_rated_speed");
159  Motor::Drive drive1 = drive();
160  double kinematicViscosity = 0;
161  double specificGravity = Get("specific_gravity");
162  int stages = static_cast<int>(Get("stages"));
163  double specifiedDriveEfficiency;
164  if (drive1 == Motor::Drive::SPECIFIED)
165  {
166  specifiedDriveEfficiency = Get("specifiedDriveEfficiency");
167  }
168  else
169  {
170  specifiedDriveEfficiency = 100.0;
171  }
172  Motor::LineFrequency lineFrequency = line();
173  double motorRatedPower = Get("motor_rated_power");
174  double motorRatedSpeed = Get("motor_rated_speed");
175  Motor::EfficiencyClass efficiencyClass = effCls();
176  double specifiedMotorEfficiency = Get("efficiency");
177  double motorRatedVoltage = Get("motor_rated_voltage");
178  double motorRatedFLA = Get("motor_rated_fla");
179  double flowRate = Get("flow_rate");
180  double head = Get("head");
181  Motor::LoadEstimationMethod loadEstimationMethod1 = loadEstimationMethod();
182  double motorFieldPower = Get("motor_field_power");
183  double motorFieldCurrent = Get("motor_field_current");
184  double motorFieldVoltage = Get("motor_field_voltage");
185  double operatingHours = Get("operating_hours");
186  double costKwHour = Get("cost_kw_hour");
187 
188  //Calculation procedure
189  pumpSpecified = Conversion(pumpSpecified).percentToFraction();
190  specifiedDriveEfficiency = Conversion(specifiedDriveEfficiency).percentToFraction();
191  Pump::Input pump(style1, pumpSpecified, pumpRatedSpeed, drive1, kinematicViscosity,
192  specificGravity, stages, Pump::SpecificSpeed::FIXED_SPEED, specifiedDriveEfficiency);
193  Motor motor(lineFrequency, motorRatedPower, motorRatedSpeed, efficiencyClass, specifiedMotorEfficiency,
194  motorRatedVoltage, motorRatedFLA);
195  Pump::FieldData fd(flowRate, head, loadEstimationMethod1, motorFieldPower,
196  motorFieldCurrent, motorFieldVoltage);
197  PSATResult psat(pump, motor, fd, operatingHours, costKwHour);
198 
199  try
200  {
201  auto ex = psat.calculateExisting();
202  //perform conversions for return object
203  ex.pumpEfficiency = Conversion(ex.pumpEfficiency).fractionToPercent();
204  ex.motorEfficiency = Conversion(ex.motorEfficiency).fractionToPercent();
205  ex.motorPowerFactor = Conversion(ex.motorPowerFactor).fractionToPercent();
206  ex.driveEfficiency = Conversion(ex.driveEfficiency).fractionToPercent();
207  ex.annualCost = Conversion(ex.annualCost).manualConversion(1000.0);
208  double annualSavingsPotentialResult = Conversion(psat.getAnnualSavingsPotential()).manualConversion(1000.0);
209 
210  //NAN return data
211  SetR("pump_efficiency", ex.pumpEfficiency);
212  SetR("motor_rated_power", ex.motorRatedPower);
213  SetR("motor_shaft_power", ex.motorShaftPower);
214  SetR("pump_shaft_power", ex.pumpShaftPower);
215  SetR("motor_efficiency", ex.motorEfficiency);
216  SetR("motor_power_factor", ex.motorPowerFactor);
217  SetR("motor_current", ex.motorCurrent);
218  SetR("motor_power", ex.motorPower);
219  SetR("load_factor", ex.loadFactor);
220  SetR("drive_efficiency", ex.driveEfficiency);
221  SetR("annual_energy", ex.annualEnergy);
222  SetR("annual_cost", ex.annualCost);
223  SetR("annual_savings_potential", annualSavingsPotentialResult);
224  SetR("optimization_rating", psat.getOptimizationRating());
225  info.GetReturnValue().Set(r);
226  }
227  catch (std::runtime_error const &e)
228  {
229  std::string const what = e.what();
230  ThrowError(std::string("std::runtime_error thrown in resultsExisting - psat.h: " + what).c_str());
231  info.GetReturnValue().Set(r);
232  }
233 }
234 
235 NAN_METHOD(resultsModified)
236 {
237  //NAN initialize data
238  inp = Nan::To<Object>(info[0]).ToLocalChecked();
239  r = Nan::New<Object>();
240  Pump::SpecificSpeed fixedSpeed = speed();
241  Pump::Style style1 = style();
242  double pumpSpecified = Get("pump_specified");
243  double pumpRatedSpeed = Get("pump_rated_speed");
244  Motor::Drive drive1 = drive();
245  double kinematicViscosity = Get("kinematic_viscosity");
246  double specificGravity = Get("specific_gravity");
247  int stages = static_cast<int>(Get("stages"));
248  double specifiedDriveEfficiency;
249  if (drive1 == Motor::Drive::SPECIFIED)
250  {
251  specifiedDriveEfficiency = Get("specifiedDriveEfficiency");
252  }
253  else
254  {
255  specifiedDriveEfficiency = 100.0;
256  }
257  Motor::LineFrequency lineFrequency = line();
258  double motorRatedPower = Get("motor_rated_power");
259  double motorRatedSpeed = Get("motor_rated_speed");
260  Motor::EfficiencyClass efficiencyClass = effCls();
261  double specifiedMotorEfficiency = Get("efficiency");
262  double motorRatedVoltage = Get("motor_rated_voltage");
263  double motorRatedFLA = Get("motor_rated_fla");
264  double margin = Get("margin");
265  double flowRate = Get("flow_rate");
266  double head = Get("head");
267  Motor::LoadEstimationMethod loadEstimationMethod1 = loadEstimationMethod();
268  double motorFieldPower = Get("motor_field_power");
269  double motorFieldCurrent = Get("motor_field_current");
270  double motorFieldVoltage = Get("motor_field_voltage");
271  double operatingHours = Get("operating_hours");
272  double costKwHour = Get("cost_kw_hour");
273 
274  //Calculation procedure
275  specifiedDriveEfficiency = Conversion(specifiedDriveEfficiency).percentToFraction();
276  pumpSpecified = Conversion(pumpSpecified).percentToFraction();
277  Pump::Input pump(style1, pumpSpecified, pumpRatedSpeed, drive1, kinematicViscosity,
278  specificGravity, stages, fixedSpeed, specifiedDriveEfficiency);
279 
280  Motor motor(lineFrequency, motorRatedPower, motorRatedSpeed, efficiencyClass, specifiedMotorEfficiency,
281  motorRatedVoltage, motorRatedFLA, margin);
282 
283  Pump::FieldData fd(flowRate, head, loadEstimationMethod1, motorFieldPower,
284  motorFieldCurrent, motorFieldVoltage);
285 
286  PSATResult psat(pump, motor, fd, operatingHours, costKwHour);
287  try
288  {
289  auto mod = psat.calculateModified();
290  //perform conversions for return object
291  mod.pumpEfficiency = Conversion(mod.pumpEfficiency).fractionToPercent();
292  mod.motorEfficiency = Conversion(mod.motorEfficiency).fractionToPercent();
293  mod.motorPowerFactor = Conversion(mod.motorPowerFactor).fractionToPercent();
294  mod.driveEfficiency = Conversion(mod.driveEfficiency).fractionToPercent();
295  mod.annualCost = Conversion(mod.annualCost).manualConversion(1000.0);
296  double annualSavingsPotential = Conversion(psat.getAnnualSavingsPotential()).manualConversion(1000.0);
297 
298  //NAN return data
299  SetR("pump_efficiency", mod.pumpEfficiency);
300  SetR("motor_rated_power", mod.motorRatedPower);
301  SetR("motor_shaft_power", mod.motorShaftPower);
302  SetR("pump_shaft_power", mod.pumpShaftPower);
303  SetR("motor_efficiency", mod.motorEfficiency);
304  SetR("motor_power_factor", mod.motorPowerFactor);
305  SetR("motor_current", mod.motorCurrent);
306  SetR("motor_power", mod.motorPower);
307  SetR("load_factor", mod.loadFactor);
308  SetR("drive_efficiency", mod.driveEfficiency);
309  SetR("annual_energy", mod.annualEnergy);
310  SetR("annual_cost", mod.annualCost);
311  SetR("annual_savings_potential", annualSavingsPotential);
312  SetR("optimization_rating", psat.getOptimizationRating());
313  info.GetReturnValue().Set(r);
314  }
315  catch (std::runtime_error const &e)
316  {
317  std::string const what = e.what();
318  ThrowError(std::string("std::runtime_error thrown in resultsModified - psat.h: " + what).c_str());
319  info.GetReturnValue().Set(r);
320  }
321 }
322 
323 NAN_METHOD(estFLA)
324 {
325  //NAN initialize data
326  inp = Nan::To<Object>(info[0]).ToLocalChecked();
327  double motor_rated_power = Get("motor_rated_power");
328  double motor_rated_speed = Get("motor_rated_speed");
329  Motor::LineFrequency l = line();
330  Motor::EfficiencyClass e = effCls();
331  double efficiency = Get("efficiency");
332  double motor_rated_voltage = Get("motor_rated_voltage");
333 
334  //Calculation procedure
335  EstimateFLA fla(motor_rated_power, motor_rated_speed, l, e, efficiency, motor_rated_voltage);
336  fla.calculate();
337 
338  //NAN return data
339  info.GetReturnValue().Set(fla.getEstimatedFLA());
340 }
341 
342 NAN_METHOD(motorPerformance)
343 {
344  //NAN initialize data
345  inp = Nan::To<Object>(info[0]).ToLocalChecked();
346  r = Nan::New<Object>();
347  Motor::LineFrequency l = line();
348  double motorRatedSpeed = Get("motor_rated_speed");
349  Motor::EfficiencyClass efficiencyClass = effCls();
350  double efficiency = Get("efficiency");
351  double motorRatedPower = Get("motor_rated_power");
352  double loadFactor = Get("load_factor");
353  double motorRatedVoltage = Get("motor_rated_voltage");
354  double motorRatedFLA = Get("motor_rated_fla");
355 
356  try
357  {
358  //Calculation procedure
359  MotorEfficiency mef(l, motorRatedSpeed, efficiencyClass, motorRatedPower);
360  double motorEfficiencyVal = mef.calculate(loadFactor, efficiency);
361  double motorEfficiencyResult = Conversion(motorEfficiencyVal).fractionToPercent();
362  MotorCurrent mc(motorRatedPower, motorRatedSpeed, l, efficiencyClass, efficiency, loadFactor,
363  motorRatedVoltage);
364  double motorCurrentVal = mc.calculateCurrent(motorRatedFLA);
365  double motorCurrentResult = Conversion(motorCurrentVal / motorRatedFLA).fractionToPercent();
366  MotorPowerFactor motorPowerFactor(motorRatedPower, loadFactor, motorCurrentVal, motorEfficiencyVal, motorRatedVoltage);
367  double motorPowerFactorVal = motorPowerFactor.calculate();
368  double motorPowerFactorResult = Conversion(motorPowerFactorVal).fractionToPercent();
369 
370  //NAN return data
371  SetR("efficiency", motorEfficiencyResult);
372  SetR("motor_current", motorCurrentResult);
373  SetR("motor_power_factor", motorPowerFactorResult);
374  }
375  catch (std::runtime_error const &e)
376  {
377  std::string const what = e.what();
378  ThrowError(std::string("std::runtime_error thrown in motorPerformance - psat.h: " + what).c_str());
379  info.GetReturnValue().Set(0);
380  }
381 
382  info.GetReturnValue().Set(r);
383 }
384 
385 NAN_METHOD(pumpEfficiency)
386 {
387  //NAN initialize data
388  inp = Nan::To<Object>(info[0]).ToLocalChecked();
389  r = Nan::New<Object>();
390  Pump::Style s = style();
391  double flow = Get("flow_rate");
392 
393  //Calculation procedure
394  OptimalPrePumpEff pef(s, flow);
395  double v = pef.calculate();
396  double odf = OptimalDeviationFactor(flow).calculate();
397  double max = v * odf;
398 
399  //NAN return data
400  SetR("average", v);
401  SetR("max", max);
402  info.GetReturnValue().Set(r);
403 }
404 
405 NAN_METHOD(achievableEfficiency)
406 {
407  //NAN initialize data
408  inp = Nan::To<Object>(info[0]).ToLocalChecked();
409  double specificSpeed = Get("specific_speed");
410  Pump::Style s = style();
411 
412  //Calculation procedure
413  double optimalSpecificSpeedCorrectionVal = OptimalSpecificSpeedCorrection(s, specificSpeed).calculate();
414  double optimalSpecificSpeedCorrectionResult = Conversion(optimalSpecificSpeedCorrectionVal).fractionToPercent();
415 
416  //NAN return data
417  info.GetReturnValue().Set(optimalSpecificSpeedCorrectionResult);
418 }
419 
420 NAN_METHOD(nema)
421 {
422  //NAN initialize data
423  // inp = Nan::To<Object>(info[0]).ToLocalChecked();
424  inp = Nan::To<Object>(info[0]).ToLocalChecked();
425  Motor::LineFrequency l = line();
426  double motorRatedSpeed = Get("motor_rated_speed");
427  Motor::EfficiencyClass efficiencyClass = effCls();
428  double efficiency = Get("efficiency");
429  double motorRatedPower = Get("motor_rated_power");
430  double loadFactor = Get("load_factor");
431  try
432  {
433  //Calculation procedure
434  double motorEfficiencyVal = MotorEfficiency(l, motorRatedSpeed, efficiencyClass, motorRatedPower).calculate(loadFactor, efficiency);
435  double motorEfficiencyResult = Conversion(motorEfficiencyVal).fractionToPercent();
436 
437  //NAN return data
438  info.GetReturnValue().Set(motorEfficiencyResult);
439  }
440  catch (std::runtime_error const &e)
441  {
442  std::string const what = e.what();
443  ThrowError(std::string("std::runtime_error thrown in nema - psat.h: " + what).c_str());
444  info.GetReturnValue().Set(0);
445  }
446 }
447 
448 NAN_METHOD(motorPowerFactor)
449 {
450  inp = Nan::To<Object>(info[0]).ToLocalChecked();
451  r = Nan::New<Object>();
452 
453  const double motorRatedPower = Get("motorRatedPower");
454  const double loadFactor = Get("loadFactor");
455  const double motorCurrent = Get("motorCurrent");
456  const double motorEfficiency = Get("motorEfficiency");
457  const double ratedVoltage = Get("ratedVoltage");
458 
459  MotorPowerFactor motorPowerFactor(motorRatedPower, loadFactor, motorCurrent, motorEfficiency, ratedVoltage);
460  double motorPowerFactorVal = motorPowerFactor.calculate();
461  double motorPowerFactorResult = Conversion(motorPowerFactorVal).fractionToPercent();
462  Local<Number> retval = Nan::New(motorPowerFactorResult);
463  info.GetReturnValue().Set(retval);
464 }
465 
466 NAN_METHOD(motorCurrent)
467 {
468  inp = Nan::To<Object>(info[0]).ToLocalChecked();
469  r = Nan::New<Object>();
470 
471  const double motorRatedPower = Get("motorRatedPower");
472  const double motorRPM = Get("motorRPM");
473  Motor::LineFrequency lineFrequency = line();
474  Motor::EfficiencyClass efficiencyClass = effCls();
475  const double specifiedEfficiency = Get("specifiedEfficiency");
476  const double loadFactor = Get("loadFactor");
477  const double ratedVoltage = Get("ratedVoltage");
478 
479  const double fullLoadAmps = Get("fullLoadAmps");
480 
481  MotorCurrent motorCurrent(motorRatedPower, motorRPM, lineFrequency, efficiencyClass, specifiedEfficiency, loadFactor, ratedVoltage);
482  double motorCurrentVal = motorCurrent.calculateCurrent(fullLoadAmps);
483  Local<Number> retval = Nan::New(motorCurrentVal);
484  info.GetReturnValue().Set(retval);
485 }
486 
487 
488 #endif //AMO_TOOLS_SUITE_PSAT_BRIDGE_H
EstimateFLA class. This contains the prototypes for the Estimate FLA calculator and 25% interval valu...
Definition: EstimateFLA.h:16
HeadToolBase::Output calculate() override
Definition: HeadTool.cpp:43
Header file for OptimalDeviationFactor class.
double calculate()
Contains the definition of functions of OptimalDeviationFactor class. calculate(): Calculates the Opt...
double calculate(double loadFactor, double specifiedEfficiency=-1)
Contains the definition of functions of MotorEfficiency class. calculate(): Calculates the motor effi...
HeadToolBase::Output calculate() override
Definition: HeadTool.cpp:20
Contains the declaration of MotorCurrent class including the getters and setters as well as the calcu...
Definition: MotorCurrent.h:15
Contains the declaration of MotorPowerFactor class including the getters and setters as well as the c...
Header file for OptimalSpecificSpeedCorrection class.
Contains InputData for both PSAT and Fan results.
Definition: InputData.h:15
Contains the declaration of MotorEfficiency class including the getters and setters as well as the ca...
Header file for OptimalPrePumpEff class.