1 #ifndef AMO_TOOLS_SUITE_PSAT_BRIDGE_H 2 #define AMO_TOOLS_SUITE_PSAT_BRIDGE_H 7 #include <unordered_map> 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" 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());
43 return Nan::To<double>(rObj).FromJust();
47 void SetR(
const char *nm,
double n)
49 Local<String> getName = Nan::New<String>(nm).ToLocalChecked();
50 Local<Number> getNum = Nan::New<Number>(n);
51 Nan::Set(r, getName, getNum);
54 NAN_METHOD(headToolSuctionTank)
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");
71 auto rv =
HeadToolSuctionTank(specificGravity, flowRate, suctionPipeDiameter, suctionTankGasOverPressure,
72 suctionTankFluidSurfaceElevation, suctionLineLossCoefficients, dischargePipeDiameter,
73 dischargeGaugePressure, dischargeGaugeElevation, dischargeLineLossCoefficients)
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);
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");
103 auto rv =
HeadTool(specificGravity, flowRate, suctionPipeDiameter, suctionGaugePressure,
104 suctionGaugeElevation, suctionLineLossCoefficients, dischargePipeDiameter,
105 dischargeGaugePressure, dischargeGaugeElevation, dischargeLineLossCoefficients)
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);
120 Motor::LineFrequency line()
122 unsigned val =
static_cast<unsigned>(Get(
"line_frequency"));
123 return static_cast<Motor::LineFrequency
>(val);
125 Motor::EfficiencyClass effCls()
127 unsigned val =
static_cast<unsigned>(Get(
"efficiency_class"));
128 return static_cast<Motor::EfficiencyClass
>(val);
132 unsigned val =
static_cast<unsigned>(Get(
"drive"));
133 return static_cast<Motor::Drive
>(val);
137 unsigned val =
static_cast<unsigned>(Get(
"pump_style"));
138 return static_cast<Pump::Style
>(val);
140 Motor::LoadEstimationMethod loadEstimationMethod()
142 unsigned val =
static_cast<unsigned>(Get(
"load_estimation_method"));
143 return static_cast<Motor::LoadEstimationMethod
>(val);
145 Pump::SpecificSpeed speed()
147 unsigned val =
static_cast<unsigned>(Get(
"fixed_speed"));
148 return static_cast<Pump::SpecificSpeed
>(val);
151 NAN_METHOD(resultsExisting)
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)
166 specifiedDriveEfficiency = Get(
"specifiedDriveEfficiency");
170 specifiedDriveEfficiency = 100.0;
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");
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);
201 auto ex = psat.calculateExisting();
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);
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);
227 catch (std::runtime_error
const &e)
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);
235 NAN_METHOD(resultsModified)
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)
251 specifiedDriveEfficiency = Get(
"specifiedDriveEfficiency");
255 specifiedDriveEfficiency = 100.0;
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");
275 specifiedDriveEfficiency =
Conversion(specifiedDriveEfficiency).percentToFraction();
276 pumpSpecified =
Conversion(pumpSpecified).percentToFraction();
277 Pump::Input pump(style1, pumpSpecified, pumpRatedSpeed, drive1, kinematicViscosity,
278 specificGravity, stages, fixedSpeed, specifiedDriveEfficiency);
280 Motor motor(lineFrequency, motorRatedPower, motorRatedSpeed, efficiencyClass, specifiedMotorEfficiency,
281 motorRatedVoltage, motorRatedFLA, margin);
283 Pump::FieldData fd(flowRate, head, loadEstimationMethod1, motorFieldPower,
284 motorFieldCurrent, motorFieldVoltage);
286 PSATResult psat(pump, motor, fd, operatingHours, costKwHour);
289 auto mod = psat.calculateModified();
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);
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);
315 catch (std::runtime_error
const &e)
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);
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");
335 EstimateFLA fla(motor_rated_power, motor_rated_speed, l, e, efficiency, motor_rated_voltage);
339 info.GetReturnValue().Set(fla.getEstimatedFLA());
342 NAN_METHOD(motorPerformance)
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");
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,
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();
371 SetR(
"efficiency", motorEfficiencyResult);
372 SetR(
"motor_current", motorCurrentResult);
373 SetR(
"motor_power_factor", motorPowerFactorResult);
375 catch (std::runtime_error
const &e)
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);
382 info.GetReturnValue().Set(r);
385 NAN_METHOD(pumpEfficiency)
388 inp = Nan::To<Object>(info[0]).ToLocalChecked();
389 r = Nan::New<Object>();
390 Pump::Style s = style();
391 double flow = Get(
"flow_rate");
395 double v = pef.calculate();
397 double max = v * odf;
402 info.GetReturnValue().Set(r);
405 NAN_METHOD(achievableEfficiency)
408 inp = Nan::To<Object>(info[0]).ToLocalChecked();
409 double specificSpeed = Get(
"specific_speed");
410 Pump::Style s = style();
414 double optimalSpecificSpeedCorrectionResult =
Conversion(optimalSpecificSpeedCorrectionVal).fractionToPercent();
417 info.GetReturnValue().Set(optimalSpecificSpeedCorrectionResult);
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");
434 double motorEfficiencyVal =
MotorEfficiency(l, motorRatedSpeed, efficiencyClass, motorRatedPower).
calculate(loadFactor, efficiency);
435 double motorEfficiencyResult =
Conversion(motorEfficiencyVal).fractionToPercent();
438 info.GetReturnValue().Set(motorEfficiencyResult);
440 catch (std::runtime_error
const &e)
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);
448 NAN_METHOD(motorPowerFactor)
450 inp = Nan::To<Object>(info[0]).ToLocalChecked();
451 r = Nan::New<Object>();
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");
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);
466 NAN_METHOD(motorCurrent)
468 inp = Nan::To<Object>(info[0]).ToLocalChecked();
469 r = Nan::New<Object>();
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");
479 const double fullLoadAmps = Get(
"fullLoadAmps");
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);
488 #endif //AMO_TOOLS_SUITE_PSAT_BRIDGE_H EstimateFLA class. This contains the prototypes for the Estimate FLA calculator and 25% interval valu...
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...
Contains the declaration of MotorCurrent class including the getters and setters as well as the calcu...
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.
Contains the declaration of MotorEfficiency class including the getters and setters as well as the ca...
Header file for OptimalPrePumpEff class.