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
fan.h
1 #include <nan.h>
2 #include <node.h>
3 #include <string>
4 #include <vector>
5 #include "fans/Planar.h"
6 #include "fans/Fan203.h"
7 #include "fans/FanShaftPower.h"
8 #include "fans/FanCurve.h"
9 #include "fans/FanEnergyIndex.h"
10 #include "results/Results.h"
11 #include "results/InputData.h"
12 #include "fans/CompressibilityFactor.h"
13 #include "calculator/util/Conversion.h"
14 
15 #include "calculator/pump/OptimalPumpShaftPower.h"
16 #include "calculator/motor/OptimalMotorShaftPower.h"
17 #include "calculator/motor/OptimalMotorPower.h"
18 
19 using namespace Nan;
20 using namespace v8;
21 
22 Local<Object> inp;
23 Local<Object> r;
24 
25 //NAN function for fetching DOUBLE value associated with provided key
26 double Get(std::string const &key, Local<Object> obj)
27 {
28  v8::Isolate *isolate = v8::Isolate::GetCurrent();
29  v8::Local<v8::Context> context = isolate->GetCurrentContext();
30  Local<String> getName = Nan::New<String>(key).ToLocalChecked();
31  Local<Value> rObj = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
32  if (rObj->IsUndefined())
33  {
34  ThrowTypeError(std::string("Get method in fan.h: " + key + " not present in object").c_str());
35  }
36  return Nan::To<double>(rObj).FromJust();
37 }
38 
39 //NAN function for fetching ENUM value associated with provided key
40 template <typename T>
41 T GetEnumVal(std::string const &key, Local<Object> obj)
42 {
43  Local<String> getName = Nan::New<String>(key).ToLocalChecked();
44  v8::Isolate *isolate = v8::Isolate::GetCurrent();
45  v8::Local<v8::Context> context = isolate->GetCurrentContext();
46  Local<Value> rObj = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
47  if (rObj->IsUndefined())
48  {
49  ThrowTypeError(std::string("GetEnumVal method in fan.h: " + key + " not present in object").c_str());
50  }
51  return static_cast<T>(Nan::To<int32_t>(rObj).FromJust());
52 }
53 
54 //NAN function for fetching BOOLEAN value associated with provided key
55 bool GetBool(std::string const &key, Local<Object> obj)
56 {
57  Local<String> getName = Nan::New<String>(key).ToLocalChecked();
58  v8::Isolate *isolate = v8::Isolate::GetCurrent();
59  v8::Local<v8::Context> context = isolate->GetCurrentContext();
60  Local<Value> rObj = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
61  if (rObj->IsUndefined())
62  {
63  ThrowTypeError(std::string("GetBool method in fan.h: Boolean value " + key + " not present in object").c_str());
64  }
65  return Nan::To<bool>(rObj).FromJust();
66 }
67 
68 //NAN function for fetching STRING value associated with provided key
69 std::string GetStr(std::string const &key, Local<Object> obj)
70 {
71  Local<String> getName = Nan::New<String>(key).ToLocalChecked();
72  v8::Isolate *isolate = v8::Isolate::GetCurrent();
73  v8::Local<v8::Context> context = isolate->GetCurrentContext();
74  Local<Value> rObj = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
75  if (rObj->IsUndefined())
76  {
77  ThrowTypeError(std::string("GetStr method in fan.h: String " + key + " not present in object").c_str());
78  }
79  v8::String::Utf8Value s(isolate, rObj);
80  return std::string(*s);
81 }
82 
83 //NAN function for checking if an object parameter has been defined with a value
84 bool isDefined(Local<Object> obj, std::string const &key)
85 {
86  Local<String> getName = Nan::New<String>(key).ToLocalChecked();
87  v8::Isolate *isolate = v8::Isolate::GetCurrent();
88  v8::Local<v8::Context> context = isolate->GetCurrentContext();
89  Local<Value> rObj = Nan::To<Object>(obj).ToLocalChecked()->Get(context, getName).ToLocalChecked();
90  return !rObj->IsUndefined();
91 }
92 
93 //NAN function for binding DOUBLE data to anonymous object
94 inline void SetR(const std::string &key, double val)
95 {
96  Nan::Set(r, Nan::New<String>(key).ToLocalChecked(), Nan::New<Number>(val));
97 }
98 
99 //helper functions for building nested array of objects via NAN
100 std::vector<std::vector<double>> getTraverseInputData(Local<Object> obj)
101 {
102  v8::Isolate *isolate = v8::Isolate::GetCurrent();
103  v8::Local<v8::Context> context = isolate->GetCurrentContext();
104 
105  v8::Local<v8::Value> arrayTmp = Nan::Get(Nan::To<v8::Object>(obj).ToLocalChecked(), Nan::New<String>("traverseData").ToLocalChecked()).ToLocalChecked();
106  Local<Array> array = v8::Local<v8::Array>::Cast(arrayTmp);
107  std::vector<std::vector<double>> traverseData(array->Length());
108 
109  for (std::size_t i = 0; i < array->Length(); i++)
110  {
111  Local<Array> const innerArray = v8::Local<v8::Array>::Cast(Nan::To<Object>(array->Get(context, i).ToLocalChecked()).ToLocalChecked());
112  traverseData.at(i).resize(innerArray->Length());
113  for (std::size_t j = 0; j < innerArray->Length(); j++)
114  {
115  traverseData.at(i).at(j) = Nan::To<double>(innerArray->Get(context, j).ToLocalChecked()).FromJust();
116  }
117  }
118  return traverseData;
119 }
120 
121 FlangePlane constructFlange(Local<Object> obj)
122 {
123  //NAN init data
124  const double area = Get("area", obj);
125  const double dryBulbTemp = Get("dryBulbTemp", obj);
126  const double barometricPressure = Get("barometricPressure", obj);
127 
128  //Create C++ obj and return
129  FlangePlane flangePlane(area, dryBulbTemp, barometricPressure);
130  return flangePlane;
131 }
132 
133 MstPlane constructMst(Local<Object> obj)
134 {
135  //NAN init data
136  const double area = Get("area", obj);
137  const double dryBulbTemp = Get("dryBulbTemp", obj);
138  const double barometricPressure = Get("barometricPressure", obj);
139  const double staticPressure = Get("staticPressure", obj);
140 
141  //Create C++ obj and return
142  MstPlane mstPlane(area, dryBulbTemp, barometricPressure, staticPressure);
143  return mstPlane;
144 }
145 
146 TraversePlane constructTraverse(Local<Object> obj)
147 {
148  //NAN init data
149  const double area = Get("area", obj);
150  const double dryBulbTemp = Get("dryBulbTemp", obj);
151  const double barometricPressure = Get("barometricPressure", obj);
152  const double staticPressure = Get("staticPressure", obj);
153  const double pitotTubeCoefficient = Get("pitotTubeCoefficient", obj);
154  const std::vector<std::vector<double>> traverseInputData = getTraverseInputData(obj);
155 
156  //Create C++ obj and return
157  TraversePlane traversePlane(area, dryBulbTemp, barometricPressure, staticPressure, pitotTubeCoefficient, traverseInputData);
158  return traversePlane;
159 }
160 
161 FanRatedInfo getFanRatedInfo()
162 {
163  //NAN init data
164  v8::Isolate *isolate = v8::Isolate::GetCurrent();
165  v8::Local<v8::Context> context = isolate->GetCurrentContext();
166  Local<String> fanRatedInfoStringV8 = Nan::New<String>("FanRatedInfo").ToLocalChecked();
167  Local<Object> fanRatedInfoV8 = Nan::To<Object>(Nan::To<Object>(inp).ToLocalChecked()->Get(context, fanRatedInfoStringV8).ToLocalChecked()).ToLocalChecked();
168 
169  const double fanSpeed = Get("fanSpeed", fanRatedInfoV8);
170  const double motorSpeed = Get("motorSpeed", fanRatedInfoV8);
171  const double fanSpeedCorrected = Get("fanSpeedCorrected", fanRatedInfoV8);
172  const double densityCorrected = Get("densityCorrected", fanRatedInfoV8);
173  const double pressureBarometricCorrected = Get("pressureBarometricCorrected", fanRatedInfoV8);
174 
175  //Create C++ obj and return
176  FanRatedInfo fanRatedInfo(fanSpeed, motorSpeed, fanSpeedCorrected, densityCorrected, pressureBarometricCorrected);
177  return fanRatedInfo;
178 }
179 
180 PlaneData getPlaneData()
181 {
182  //NAN init data
183  v8::Isolate *isolate = v8::Isolate::GetCurrent();
184  v8::Local<v8::Context> context = isolate->GetCurrentContext();
185  Local<String> planeDataStringV8 = Nan::New<String>("PlaneData").ToLocalChecked();
186  Local<Object> planeDataV8 = Nan::To<Object>(Nan::To<Object>(inp).ToLocalChecked()->Get(context, planeDataStringV8).ToLocalChecked()).ToLocalChecked();
187 
188  // Local<Value> const &addlTravTmp = planeDataV8->Get(Nan::New<String>("AddlTraversePlanes").ToLocalChecked());
189  Local<Value> const &addlTravTmp = Nan::Get(planeDataV8, Nan::New<String>("AddlTraversePlanes").ToLocalChecked()).ToLocalChecked();
190  Local<Array> const &addlTravArray = v8::Local<v8::Array>::Cast(addlTravTmp);
191  std::vector<TraversePlane> addlTravPlanes;
192  //loop to construct array of traverse planes
193  for (std::size_t i = 0; i < addlTravArray->Length(); i++)
194  {
195  addlTravPlanes.emplace_back(constructTraverse(Nan::To<Object>(addlTravArray->Get(context, i).ToLocalChecked()).ToLocalChecked()));
196  }
197  FlangePlane fanInletFlange = constructFlange(Nan::To<Object>(planeDataV8->Get(context, Nan::New<String>("FanInletFlange").ToLocalChecked()).ToLocalChecked()).ToLocalChecked());
198  FlangePlane fanEvaseOrOutletFlange = constructFlange(Nan::To<Object>(planeDataV8->Get(context, Nan::New<String>("FanEvaseOrOutletFlange").ToLocalChecked()).ToLocalChecked()).ToLocalChecked());
199  TraversePlane flowTraverse = constructTraverse(Nan::To<Object>(planeDataV8->Get(context, Nan::New<String>("FlowTraverse").ToLocalChecked()).ToLocalChecked()).ToLocalChecked());
200  MstPlane inletMstPlane = constructMst(Nan::To<Object>(planeDataV8->Get(context, Nan::New<String>("InletMstPlane").ToLocalChecked()).ToLocalChecked()).ToLocalChecked());
201  MstPlane outletMstPlane = constructMst(Nan::To<Object>(planeDataV8->Get(context, Nan::New<String>("OutletMstPlane").ToLocalChecked()).ToLocalChecked()).ToLocalChecked());
202  const double totalPressureLossBtwnPlanes1and4 = Get("totalPressureLossBtwnPlanes1and4", planeDataV8);
203  const double totalPressureLossBtwnPlanes2and5 = Get("totalPressureLossBtwnPlanes2and5", planeDataV8);
204  const bool plane5upstreamOfPlane2 = GetBool("plane5upstreamOfPlane2", planeDataV8);
205 
206  //Create C++ obj and return
207  PlaneData planeData(fanInletFlange, fanEvaseOrOutletFlange, flowTraverse, std::move(addlTravPlanes), inletMstPlane, outletMstPlane, totalPressureLossBtwnPlanes1and4, totalPressureLossBtwnPlanes2and5, plane5upstreamOfPlane2);
208  return planeData;
209 }
210 
211 BaseGasDensity::GasType getGasType(Local<Object> obj)
212 {
213  //NAN init data
214  std::string const &gasTypeStr = GetStr("gasType", obj);
215 
216  //perform logic and return C++ data
217  if (gasTypeStr == "AIR")
218  {
219  return BaseGasDensity::GasType::AIR;
220  }
221  else if (gasTypeStr == "STANDARDAIR")
222  {
223  return BaseGasDensity::GasType::STANDARDAIR;
224  }
225  return BaseGasDensity::GasType::OTHERGAS;
226 };
227 
228 BaseGasDensity::InputType getInputType(Local<Object> obj)
229 {
230  //NAN init data
231  std::string const &inputTypeStr = GetStr("inputType", obj);
232 
233  //perform logic and return C++ data
234  if (inputTypeStr == "relativeHumidity")
235  {
236  return BaseGasDensity::InputType::RelativeHumidity;
237  }
238  else if (inputTypeStr == "dewPoint")
239  {
240  return BaseGasDensity::InputType::DewPoint;
241  }
242  return BaseGasDensity::InputType::WetBulbTemp;
243 };
244 
245 NAN_METHOD(fanResultsExisting)
246 {
247  //NAN initialize data
248  inp = Nan::To<Object>(info[0]).ToLocalChecked();
249  r = Nan::New<Object>();
250  const double fanSpeed = Get("fanSpeed", inp);
251  const double airDensity = Get("airDensity", inp);
252  Motor::Drive drive1 = GetEnumVal<Motor::Drive>("drive", inp);
253  double specifiedDriveEfficiency;
254  if (drive1 == Motor::Drive::SPECIFIED)
255  {
256  specifiedDriveEfficiency = Get("specifiedDriveEfficiency", inp);
257  }
258  else
259  {
260  specifiedDriveEfficiency = 100.0;
261  }
262  Motor::LineFrequency const lineFrequency = GetEnumVal<Motor::LineFrequency>("lineFrequency", inp);
263  double const motorRatedPower = Get("motorRatedPower", inp);
264  double const motorRpm = Get("motorRpm", inp);
265  Motor::EfficiencyClass const efficiencyClass = GetEnumVal<Motor::EfficiencyClass>("efficiencyClass", inp);
266  double const specifiedEfficiency = Get("specifiedEfficiency", inp);
267  double const motorRatedVoltage = Get("motorRatedVoltage", inp);
268  double const fullLoadAmps = Get("fullLoadAmps", inp);
269  double const sizeMargin = Get("sizeMargin", inp);
270  double const measuredPower = Get("measuredPower", inp);
271  double const measuredVoltage = Get("measuredVoltage", inp);
272  double const measuredAmps = Get("measuredAmps", inp);
273  double const flowRate = Get("flowRate", inp);
274  double const inletPressure = Get("inletPressure", inp);
275  double const outletPressure = Get("outletPressure", inp);
276  double const compressibilityFactor = Get("compressibilityFactor", inp);
277  double const operatingHours = Get("operatingHours", inp);
278  double const unitCost = Get("unitCost", inp);
279  Motor::LoadEstimationMethod const loadEstimationMethod = GetEnumVal<Motor::LoadEstimationMethod>("loadEstimationMethod", inp);
280 
281  //Calculation procedure
282  specifiedDriveEfficiency = Conversion(specifiedDriveEfficiency).percentToFraction();
283  Fan::Input input(fanSpeed, airDensity, drive1, specifiedDriveEfficiency);
284  Motor motor(lineFrequency, motorRatedPower, motorRpm, efficiencyClass, specifiedEfficiency, motorRatedVoltage, fullLoadAmps, sizeMargin);
285  Fan::FieldDataBaseline fanFieldData(measuredPower, measuredVoltage, measuredAmps, flowRate, inletPressure, outletPressure,
286  compressibilityFactor, loadEstimationMethod);
287  FanResult result(input, motor, operatingHours, unitCost);
288  FanResult::Output output = result.calculateExisting(fanFieldData);
289  //perform conversions for return object
290  output.fanEfficiency = Conversion(output.fanEfficiency).fractionToPercent();
291  output.motorEfficiency = Conversion(output.motorEfficiency).fractionToPercent();
292  output.motorPowerFactor = Conversion(output.motorPowerFactor).fractionToPercent();
293  output.driveEfficiency = Conversion(output.driveEfficiency).fractionToPercent();
294 
295  //NAN create return obj
296  SetR("fanEfficiency", output.fanEfficiency);
297  SetR("motorRatedPower", output.motorRatedPower);
298  SetR("motorShaftPower", output.motorShaftPower);
299  SetR("fanShaftPower", output.fanShaftPower);
300  SetR("motorEfficiency", output.motorEfficiency);
301  SetR("motorPowerFactor", output.motorPowerFactor);
302  SetR("motorCurrent", output.motorCurrent);
303  SetR("motorPower", output.motorPower);
304  SetR("loadFactor", output.loadFactor);
305  SetR("driveEfficiency", output.driveEfficiency);
306  SetR("annualEnergy", output.annualEnergy);
307  SetR("annualCost", output.annualCost);
308  SetR("estimatedFLA", output.estimatedFLA);
309  SetR("fanEnergyIndex", output.fanEnergyIndex);
310  //NAN return obj
311  info.GetReturnValue().Set(r);
312 }
313 
314 NAN_METHOD(fanResultsModified)
315 {
316  inp = Nan::To<Object>(info[0]).ToLocalChecked();
317  r = Nan::New<Object>();
318  //NAN init data
319  const double fanSpeed = Get("fanSpeed", inp);
320  const double airDensity = Get("airDensity", inp);
321  Motor::Drive drive1 = GetEnumVal<Motor::Drive>("drive", inp);
322  double specifiedDriveEfficiency;
323  if (drive1 == Motor::Drive::SPECIFIED)
324  {
325  specifiedDriveEfficiency = Get("specifiedDriveEfficiency", inp);
326  }
327  else
328  {
329  specifiedDriveEfficiency = 100.0;
330  }
331  double const measuredVoltage = Get("measuredVoltage", inp);
332  double const measuredAmps = Get("measuredAmps", inp);
333  double const flowRate = Get("flowRate", inp);
334  double const inletPressure = Get("inletPressure", inp);
335  double const outletPressure = Get("outletPressure", inp);
336  double const compressibilityFactor = Get("compressibilityFactor", inp);
337  Motor::LineFrequency const lineFrequency = GetEnumVal<Motor::LineFrequency>("lineFrequency", inp);
338  double const motorRatedPower = Get("motorRatedPower", inp);
339  double const motorRpm = Get("motorRpm", inp);
340  Motor::EfficiencyClass const efficiencyClass = GetEnumVal<Motor::EfficiencyClass>("efficiencyClass", inp);
341  double const specifiedEfficiency = Get("specifiedEfficiency", inp);
342  double const motorRatedVoltage = Get("motorRatedVoltage", inp);
343  double const fullLoadAmps = Get("fullLoadAmps", inp);
344  double const sizeMargin = Get("sizeMargin", inp);
345  const double operatingHours = Get("operatingHours", inp);
346  const double unitCost = Get("unitCost", inp);
347  double fanEfficiency = Get("fanEfficiency", inp);
348 
349  //Calculation procedure
350  fanEfficiency = Conversion(fanEfficiency).percentToFraction();
351  specifiedDriveEfficiency = Conversion(specifiedDriveEfficiency).percentToFraction();
352  Fan::Input input(fanSpeed, airDensity, drive1, specifiedDriveEfficiency);
353  Fan::FieldDataModified fanFieldData(measuredVoltage, measuredAmps, flowRate, inletPressure,
354  outletPressure, compressibilityFactor);
355  Motor motor(lineFrequency, motorRatedPower, motorRpm, efficiencyClass, specifiedEfficiency, motorRatedVoltage, fullLoadAmps, sizeMargin);
356  FanResult result(input, motor, operatingHours, unitCost);
357  FanResult::Output output = result.calculateModified(fanFieldData, fanEfficiency);
358  //perform conversions for return object
359  output.fanEfficiency = Conversion(output.fanEfficiency).fractionToPercent();
360  output.motorEfficiency = Conversion(output.motorEfficiency).fractionToPercent();
361  output.motorPowerFactor = Conversion(output.motorPowerFactor).fractionToPercent();
362  output.driveEfficiency = Conversion(output.driveEfficiency).fractionToPercent();
363 
364  //NAN create return obj
365  SetR("fanEfficiency", output.fanEfficiency);
366  SetR("motorRatedPower", output.motorRatedPower);
367  SetR("motorShaftPower", output.motorShaftPower);
368  SetR("fanShaftPower", output.fanShaftPower);
369  SetR("motorEfficiency", output.motorEfficiency);
370  SetR("motorPowerFactor", output.motorPowerFactor);
371  SetR("motorCurrent", output.motorCurrent);
372  SetR("motorPower", output.motorPower);
373  SetR("loadFactor", output.loadFactor);
374  SetR("driveEfficiency", output.driveEfficiency);
375  SetR("annualEnergy", output.annualEnergy);
376  SetR("annualCost", output.annualCost);
377  SetR("estimatedFLA", output.estimatedFLA);
378  SetR("fanEnergyIndex", output.fanEnergyIndex);
379  //NAN return obj
380  info.GetReturnValue().Set(r);
381 }
382 
383 // NAN_METHOD(fanResultsOptimal) {
384 // inp = Nan::To<Object>(info[0]).ToLocalChecked();
385 // r = Nan::New<Object>();
386 
387 // Motor::Drive drive1 = GetEnumVal<Motor::Drive>("drive", inp);
388 
389 // double specifiedDriveEfficiency;
390 // if (drive1 == Motor::Drive::SPECIFIED) {
391 // specifiedDriveEfficiency = Get("specifiedDriveEfficiency", inp) / 100;
392 // }
393 // else {
394 // specifiedDriveEfficiency = 1;
395 // }
396 
397 // Fan::Input input = {Get("fanSpeed", inp), Get("airDensity", inp), drive1, specifiedDriveEfficiency};
398 
399 // double const measuredVoltage = Get("measuredVoltage", inp);
400 // double const measuredAmps = Get("measuredAmps", inp);
401 // double const flowRate = Get("flowRate", inp);
402 // double const inletPressure = Get("inletPressure", inp);
403 // double const outletPressure = Get("outletPressure", inp);
404 // double const compressibilityFactor = Get("compressibilityFactor", inp);
405 // Fan::FieldDataModified fanFieldData = {measuredVoltage, measuredAmps, flowRate, inletPressure,
406 // outletPressure, compressibilityFactor};
407 
408 // Motor::LineFrequency const lineFrequency = GetEnumVal<Motor::LineFrequency>("lineFrequency", inp);
409 // double const motorRatedPower = Get("motorRatedPower", inp);
410 // double const motorRpm = Get("motorRpm", inp);
411 // Motor::EfficiencyClass const efficiencyClass = GetEnumVal<Motor::EfficiencyClass>("efficiencyClass", inp);
412 // double const specifiedEfficiency = Get("specifiedEfficiency", inp);
413 // double const motorRatedVoltage = Get("motorRatedVoltage", inp);
414 // double const fullLoadAmps = Get("fullLoadAmps", inp);
415 // double const sizeMargin = Get("sizeMargin", inp);
416 
417 // Motor motor = {lineFrequency, motorRatedPower, motorRpm, efficiencyClass, specifiedEfficiency, motorRatedVoltage, fullLoadAmps, sizeMargin};
418 
419 // FanResult result = {input, motor, Get("operatingHours", inp), Get("unitCost", inp)};
420 
421 // auto const output = GetBool("isSpecified", inp) ? result.calculateOptimal(fanFieldData, Get("userInputFanEfficiency", inp) / 100)
422 // : result.calculateOptimal(fanFieldData, GetEnumVal<OptimalFanEfficiency::FanType>("fanType", inp));
423 
424 // SetR("fanEfficiency", output.fanEfficiency * 100);
425 // SetR("motorRatedPower", output.motorRatedPower);
426 // SetR("motorShaftPower", output.motorShaftPower);
427 // SetR("fanShaftPower", output.fanShaftPower);
428 // SetR("motorEfficiency", output.motorEfficiency * 100);
429 // SetR("motorPowerFactor", output.motorPowerFactor * 100);
430 // SetR("motorCurrent", output.motorCurrent);
431 // SetR("motorPower", output.motorPower);
432 // SetR("annualEnergy", output.annualEnergy);
433 // SetR("annualCost", output.annualCost);
434 // SetR("estimatedFLA", output.estimatedFLA);
435 // SetR("fanEnergyIndex", output.fanEnergyIndex);
436 // info.GetReturnValue().Set(r);
437 // }
438 
439 void SetBaseGasDensityData(Local<Object> & obj, const BaseGasDensity & bgd)
440 {
441  Local<String> gasDensity = Nan::New<String>("gasDensity").ToLocalChecked();
442  Local<String> absolutePressure = Nan::New<String>("absolutePressure").ToLocalChecked();
443  Local<String> saturatedHumidity = Nan::New<String>("saturatedHumidity").ToLocalChecked();
444  Local<String> saturationDegree = Nan::New<String>("saturationDegree").ToLocalChecked();
445  Local<String> humidityRatio = Nan::New<String>("humidityRatio").ToLocalChecked();
446  Local<String> specificVolume = Nan::New<String>("specificVolume").ToLocalChecked();
447  Local<String> enthalpy = Nan::New<String>("enthalpy").ToLocalChecked();
448  Local<String> dewPoint = Nan::New<String>("dewPoint").ToLocalChecked();
449  Local<String> relativeHumidity = Nan::New<String>("relativeHumidity").ToLocalChecked();
450  Local<String> saturationPressure = Nan::New<String>("saturationPressure").ToLocalChecked();
451  Local<String> wetBulbTemp = Nan::New<String>("wetBulbTemp").ToLocalChecked();
452 
453  Nan::Set(obj, gasDensity, Nan::New<Number>(bgd.getGasDensity()));
454  Nan::Set(obj, absolutePressure, Nan::New<Number>(bgd.getAbsolutePressureIn()));
455  Nan::Set(obj, saturatedHumidity, Nan::New<Number>(bgd.getSaturatedHumidityRatio()));
456  Nan::Set(obj, saturationDegree, Nan::New<Number>(bgd.getDegreeOfSaturation()));
457  Nan::Set(obj, humidityRatio, Nan::New<Number>(bgd.getHumidityRatio()));
458  Nan::Set(obj, specificVolume, Nan::New<Number>(bgd.getSpecificVolume()));
459  Nan::Set(obj, enthalpy, Nan::New<Number>(bgd.getEnthalpy()));
460  Nan::Set(obj, dewPoint, Nan::New<Number>(bgd.getDewPoint()));
461  Nan::Set(obj, relativeHumidity, Nan::New<Number>(bgd.getRelativeHumidity()));
462  Nan::Set(obj, saturationPressure, Nan::New<Number>(bgd.getSaturationPressure()));
463  Nan::Set(obj, wetBulbTemp, Nan::New<Number>(bgd.getWetBulbTemp()));
464 }
465 NAN_METHOD(getBaseGasDensityRelativeHumidity)
466 {
467  Local<Object> obj = Nan::New<Object>();
468 
469  inp = Nan::To<Object>(info[0]).ToLocalChecked();
470  r = Nan::New<Object>();
471  try
472  {
473  //NAN data init
474  const double dryBulbTemp = Get("dryBulbTemp", inp);
475  const double staticPressure = Get("staticPressure", inp);
476  const double barometricPressure = Get("barometricPressure", inp);
477  const double relativeHumidity = Get("relativeHumidity", inp);
478  BaseGasDensity::GasType gasType = getGasType(inp);
479  BaseGasDensity::InputType inputType = getInputType(inp);
480  const double specificGravity = Get("specificGravity", inp);
481 
482  //Calculation procedure
484  dryBulbTemp,
485  staticPressure,
486  barometricPressure,
487  relativeHumidity,
488  gasType,
489  inputType,
490  specificGravity);
491 
492  SetBaseGasDensityData(obj, bgd);
493 
494  //NAN return object
495  info.GetReturnValue().Set(obj);
496 
497  //NAN return single value
498  //info.GetReturnValue().Set(result);
499  }
500  catch (std::runtime_error const &e)
501  {
502  Local<Object> obj_err = Nan::New<Object>();
503  BaseGasDensity bgd_err = BaseGasDensity(0, 0, 0, 0, BaseGasDensity::GasType::OTHERGAS);
504  SetBaseGasDensityData(obj_err, bgd_err);
505  info.GetReturnValue().Set(obj_err);
506  std::string const what = e.what();
507  ThrowError(std::string("std::runtime_error thrown in getBaseGasDensityRelativeHumidity - fan.h: " + what).c_str());
508  }
509 }
510 
511 NAN_METHOD(getBaseGasDensityDewPoint)
512 {
513  Local<Object> obj = Nan::New<Object>();
514 
515  inp = Nan::To<Object>(info[0]).ToLocalChecked();
516  r = Nan::New<Object>();
517  try
518  {
519  //NAN data init
520  const double dryBulbTemp = Get("dryBulbTemp", inp);
521  const double staticPressure = Get("staticPressure", inp);
522  const double barometricPressure = Get("barometricPressure", inp);
523  const double dewPoint = Get("dewPoint", inp);
524  BaseGasDensity::GasType gasType = getGasType(inp);
525  BaseGasDensity::InputType inputType = getInputType(inp);
526  const double specificGravity = Get("specificGravity", inp);
527 
528  //Calculation procedure
530  dryBulbTemp,
531  staticPressure,
532  barometricPressure,
533  dewPoint,
534  gasType,
535  inputType,
536  specificGravity);
537 
538  SetBaseGasDensityData(obj, bgd);
539 
540  //NAN return object
541  info.GetReturnValue().Set(obj);
542 
543  //NAN return single value
544  //info.GetReturnValue().Set(result);
545  }
546  catch (std::runtime_error const &e)
547  {
548  Local<Object> obj_err = Nan::New<Object>();
549  BaseGasDensity bgd_err = BaseGasDensity(0, 0, 0, 0, BaseGasDensity::GasType::OTHERGAS);
550  SetBaseGasDensityData(obj_err, bgd_err);
551  info.GetReturnValue().Set(obj_err);
552  std::string const what = e.what();
553  ThrowError(std::string("std::runtime_error thrown in getBaseGasDensityDewPoint - fan.h: " + what).c_str());
554  }
555 }
556 
557 NAN_METHOD(getBaseGasDensityWetBulb)
558 {
559  Local<Object> obj = Nan::New<Object>();
560 
561  inp = Nan::To<Object>(info[0]).ToLocalChecked();
562  r = Nan::New<Object>();
563  try
564  {
565  //NAN data init
566  const double dryBulbTemp = Get("dryBulbTemp", inp);
567  const double staticPressure = Get("staticPressure", inp);
568  const double barometricPressure = Get("barometricPressure", inp);
569  const double wetBulbTemp = Get("wetBulbTemp", inp);
570  BaseGasDensity::GasType gasType = getGasType(inp);
571  BaseGasDensity::InputType inputType = getInputType(inp);
572  const double specificGravity = Get("specificGravity", inp);
573  const double specificHeatGas = Get("specificHeatGas", inp);
574 
575  //Calculation procedure
577  dryBulbTemp,
578  staticPressure,
579  barometricPressure,
580  wetBulbTemp,
581  gasType,
582  inputType,
583  specificGravity,
584  specificHeatGas);
585 
586  SetBaseGasDensityData(obj, bgd);
587 
588  //NAN return object
589  info.GetReturnValue().Set(obj);
590 
591  //NAN return single value
592  //info.GetReturnValue().Set(result);
593  }
594  catch (std::runtime_error const &e)
595  {
596  Local<Object> obj_err = Nan::New<Object>();
597  BaseGasDensity bgd_err = BaseGasDensity(0, 0, 0, 0, BaseGasDensity::GasType::OTHERGAS);
598  SetBaseGasDensityData(obj_err, bgd_err);
599  info.GetReturnValue().Set(obj_err);
600  std::string const what = e.what();
601  ThrowError(std::string("std::runtime_error thrown in getBaseGasDensityWetBulb - fan.h: " + what).c_str());
602  }
603 }
604 
605 BaseGasDensity getBaseGasDensity()
606 {
607  //NAN data init
608  v8::Isolate *isolate = v8::Isolate::GetCurrent();
609  v8::Local<v8::Context> context = isolate->GetCurrentContext();
610  Local<Object> baseGasDensityV8 = Nan::To<Object>(Nan::To<Object>(inp).ToLocalChecked()->Get(context, Nan::New<String>("BaseGasDensity").ToLocalChecked()).ToLocalChecked()).ToLocalChecked();
611  const double dryBulbTemp = Get("dryBulbTemp", baseGasDensityV8);
612  const double staticPressure = Get("staticPressure", baseGasDensityV8);
613  const double barometricPressure = Get("barometricPressure", baseGasDensityV8);
614  const double gasDensity = Get("gasDensity", baseGasDensityV8);
615  const BaseGasDensity::GasType gasType = getGasType(baseGasDensityV8);
616 
617  //Create C++ obj and return
618  BaseGasDensity baseGasDensity(dryBulbTemp, staticPressure, barometricPressure, gasDensity, gasType);
619  return baseGasDensity;
620 }
621 
622 FanShaftPower getFanShaftPower()
623 {
624  //NAN data init
625  v8::Isolate *isolate = v8::Isolate::GetCurrent();
626  v8::Local<v8::Context> context = isolate->GetCurrentContext();
627  Local<Object> fanShaftPowerV8 = Nan::To<Object>(Nan::To<Object>(inp).ToLocalChecked()->Get(context, Nan::New<String>("FanShaftPower").ToLocalChecked()).ToLocalChecked()).ToLocalChecked();
628  const double motorShaftPower = Get("motorShaftPower", fanShaftPowerV8);
629  const double efficiencyMotor = Get("efficiencyMotor", fanShaftPowerV8);
630  const double efficiencyVFD = Get("efficiencyVFD", fanShaftPowerV8);
631  const double efficiencyBelt = Get("efficiencyBelt", fanShaftPowerV8);
632  const double sumSEF = Get("sumSEF", fanShaftPowerV8);
633 
634  //Create C++ obj and return
635  FanShaftPower fanShaftPower(motorShaftPower, efficiencyMotor, efficiencyVFD, efficiencyBelt, sumSEF);
636  return fanShaftPower;
637 }
638 
639 NAN_METHOD(getVelocityPressureData)
640 {
641  //NAN init data
642  inp = Nan::To<Object>(info[0]).ToLocalChecked();
643  r = Nan::New<Object>();
644  TraversePlane const travPlane = constructTraverse(Nan::To<Object>(inp).ToLocalChecked());
645 
646  //Calculation procedure
647  double pv3 = travPlane.getPv3Value();
648  double percent75Rule = travPlane.get75percentRule();
649  percent75Rule = Conversion(percent75Rule).fractionToPercent();
650 
651  //NAN construct return obj
652  SetR("pv3", pv3);
653  SetR("percent75Rule", percent75Rule);
654 
655  //NAN return obj
656  info.GetReturnValue().Set(r);
657 }
658 
659 NAN_METHOD(getPlaneResults)
660 {
661  Local<Object> rv = Nan::New<Object>();
662  inp = Nan::To<Object>(info[0]).ToLocalChecked();
663 
664  try
665  {
666  //NAN fetching PlaneData data
667  PlaneData planeData = getPlaneData();
668  BaseGasDensity baseGasDensity = getBaseGasDensity();
669 
670  //assign output and perform C++ calculation
671  PlaneData::NodeBinding::Output const output = PlaneData::NodeBinding::calculate(planeData, baseGasDensity);
672 
673  //iterate through traverse planes and build data array to be injected in to return object
674  Local<Array> addlTravPlanes = Nan::New<v8::Array>(output.addlTravPlanes.size());
675 
676  std::size_t index = 0;
677 
678  auto const setData = [&rv, &addlTravPlanes, &index](const PlaneData::NodeBinding::Data &data, std::string const &name,
679  bool isArray = false, bool isStaticPressure = false, const double staticPressure = 0) {
680  //NAN assigning data to array of child-objects
681  r = Nan::New<Object>();
682  SetR("gasDensity", data.gasDensity);
683  SetR("gasVolumeFlowRate", data.gasVolumeFlowRate);
684  SetR("gasVelocity", data.gasVelocity);
685  SetR("gasVelocityPressure", data.gasVelocityPressure);
686  SetR("gasTotalPressure", data.gasTotalPressure);
687  if (isStaticPressure)
688  {
689  SetR("staticPressure", staticPressure);
690  }
691 
692  if (isArray)
693  {
694  Nan::Set(addlTravPlanes, index, r);
695  }
696  else
697  {
698  Nan::Set(rv, Nan::New<String>(name).ToLocalChecked(), r);
699  }
700  };
701 
702  for (PlaneData::NodeBinding::Data const &data : output.addlTravPlanes)
703  {
704  setData(data, "", true);
705  index++;
706  }
707  Nan::Set(rv, Nan::New<String>("AddlTraversePlanes").ToLocalChecked(), addlTravPlanes);
708  setData(output.fanInletFlange, "FanInletFlange", false, true, output.fanInletFlange.staticPressure);
709  setData(output.fanOrEvaseOutletFlange, "FanOrEvaseOutletFlange", false, true, output.fanOrEvaseOutletFlange.staticPressure);
710  setData(output.flowTraverse, "FlowTraverse");
711  setData(output.inletMstPlane, "InletMstPlane");
712  setData(output.outletMstPlane, "OutletMstPlane");
713  }
714  catch (std::runtime_error const &e)
715  {
716  std::string const what = e.what();
717  ThrowError(std::string("std::runtime_error thrown in getPlaneResults - fan.h: " + what).c_str());
718  }
719 
720  info.GetReturnValue().Set(rv);
721 }
722 
723 NAN_METHOD(fan203)
724 {
725  inp = Nan::To<Object>(info[0]).ToLocalChecked();
726  r = Nan::New<Object>();
727  try
728  {
729  //NAN init data
730  FanRatedInfo fanRatedInfo = getFanRatedInfo();
731  PlaneData planeData = getPlaneData();
732  BaseGasDensity baseGasDensity = getBaseGasDensity();
733  FanShaftPower fanShaftPower = getFanShaftPower();
734 
735  //Calculation procedure
736  Fan203::Output const rv = Fan203(fanRatedInfo, planeData, baseGasDensity, fanShaftPower).calculate();
737 
738  //NAN return resutls
739  SetR("fanEfficiencyTotalPressure", rv.fanEfficiencyTotalPressure);
740  SetR("fanEfficiencyStaticPressure", rv.fanEfficiencyStaticPressure);
741  SetR("fanEfficiencyStaticPressureRise", rv.fanEfficiencyStaticPressureRise);
742  SetR("flow", rv.asTested.flow);
743  SetR("pressureTotal", rv.asTested.pressureTotal);
744  SetR("pressureStatic", rv.asTested.pressureStatic);
745  SetR("staticPressureRise", rv.asTested.staticPressureRise);
746  SetR("power", rv.asTested.power);
747  SetR("kpc", rv.asTested.kpc);
748  SetR("flowCorrected", rv.converted.flow);
749  SetR("pressureTotalCorrected", rv.converted.pressureTotal);
750  SetR("pressureStaticCorrected", rv.converted.pressureStatic);
751  SetR("staticPressureRiseCorrected", rv.converted.staticPressureRise);
752  SetR("powerCorrected", rv.converted.power);
753  SetR("kpcCorrected", rv.converted.kpc);
754  }
755  catch (std::runtime_error const &e)
756  {
757  std::string const what = e.what();
758  ThrowError(std::string("std::runtime_error thrown in fan203 - fan.h: " + what).c_str());
759  }
760 
761  //NAN return obj
762  info.GetReturnValue().Set(r);
763 }
764 
765 FanCurveType getFanCurveType()
766 {
767  //NAN init data
768  std::string const curveTypeStr = GetStr("curveType", inp);
769 
770  //perform logic and return value
771  if (curveTypeStr == "StaticPressureRise")
772  {
773  return FanCurveType::StaticPressureRise;
774  }
775  else if (curveTypeStr == "FanTotalPressure")
776  {
777  return FanCurveType::FanTotalPressure;
778  }
779  return FanCurveType::FanStaticPressure;
780 }
781 
782 FanCurveData getFanBaseCurveData()
783 {
784  v8::Isolate *isolate = v8::Isolate::GetCurrent();
785  v8::Local<v8::Context> context = isolate->GetCurrentContext();
786  Local<Value> const &arrayTmp = Nan::To<Object>(inp).ToLocalChecked()->Get(context, Nan::New<String>("BaseCurveData").ToLocalChecked()).ToLocalChecked();
787  Local<Array> const &array = v8::Local<v8::Array>::Cast(arrayTmp);
788  std::vector<FanCurveData::BaseCurve> curveData;
789  for (std::size_t i = 0; i < array->Length(); i++)
790  {
791  Local<Value> const &innerArrayTmp = Nan::To<Object>(array->Get(context, i).ToLocalChecked()).ToLocalChecked();
792  Local<Array> const &innerArray = Local<Array>::Cast(innerArrayTmp);
793  curveData.emplace_back(FanCurveData::BaseCurve(Nan::To<double>(innerArray->Get(context, 0).ToLocalChecked()).FromJust(),
794  Nan::To<double>(innerArray->Get(context, 1).ToLocalChecked()).FromJust(),
795  Nan::To<double>(innerArray->Get(context, 2).ToLocalChecked()).FromJust()));
796  }
797  FanCurveType fanCurveType = getFanCurveType();
798 
799  //construct C++ obj and return
800  FanCurveData fanCurveData(fanCurveType, std::move(curveData));
801  return fanCurveData;
802 }
803 
804 FanCurveData getFanRatedPointCurveData()
805 {
806  v8::Isolate *isolate = v8::Isolate::GetCurrent();
807  v8::Local<v8::Context> context = isolate->GetCurrentContext();
808  Local<Value> const &arrayTmp = Nan::To<Object>(inp).ToLocalChecked()->Get(context, Nan::New<String>("RatedPointCurveData").ToLocalChecked()).ToLocalChecked();
809  Local<Array> const &array = v8::Local<v8::Array>::Cast(arrayTmp);
810  std::vector<FanCurveData::RatedPoint> curveData;
811  for (std::size_t i = 0; i < array->Length(); i++)
812  {
813  Local<Value> const &innerArrayTmp = Nan::To<Object>(array->Get(context, i).ToLocalChecked()).ToLocalChecked();
814  Local<Array> const &innerArray = Local<Array>::Cast(innerArrayTmp);
815  curveData.emplace_back(FanCurveData::RatedPoint(Nan::To<double>(innerArray->Get(context, 0).ToLocalChecked()).FromJust(),
816  Nan::To<double>(innerArray->Get(context, 1).ToLocalChecked()).FromJust(),
817  Nan::To<double>(innerArray->Get(context, 2).ToLocalChecked()).FromJust(),
818  Nan::To<double>(innerArray->Get(context, 3).ToLocalChecked()).FromJust(),
819  Nan::To<double>(innerArray->Get(context, 4).ToLocalChecked()).FromJust(),
820  Nan::To<double>(innerArray->Get(context, 5).ToLocalChecked()).FromJust()));
821  }
822 
823  FanCurveType fanCurveType = getFanCurveType();
824 
825  //construct C++ obj and return
826  FanCurveData fanCurveData(fanCurveType, std::move(curveData));
827  return fanCurveData;
828 }
829 
830 FanCurveData getFanBaseOperatingPointCurveData()
831 {
832  v8::Isolate *isolate = v8::Isolate::GetCurrent();
833  v8::Local<v8::Context> context = isolate->GetCurrentContext();
834  Local<Value> const &arrayTmp = Nan::To<Object>(inp).ToLocalChecked()->Get(context, Nan::New<String>("BaseOperatingPointCurveData").ToLocalChecked()).ToLocalChecked();
835  Local<Array> const &array = v8::Local<v8::Array>::Cast(arrayTmp);
836  std::vector<FanCurveData::BaseOperatingPoint> curveData;
837  for (std::size_t i = 0; i < array->Length(); i++)
838  {
839  Local<Value> const &innerArrayTmp = Nan::To<Object>(array->Get(context, i).ToLocalChecked()).ToLocalChecked();
840  Local<Array> const &innerArray = Local<Array>::Cast(innerArrayTmp);
841  curveData.emplace_back(FanCurveData::BaseOperatingPoint(Nan::To<double>(innerArray->Get(context, 0).ToLocalChecked()).FromJust(),
842  Nan::To<double>(innerArray->Get(context, 1).ToLocalChecked()).FromJust(),
843  Nan::To<double>(innerArray->Get(context, 2).ToLocalChecked()).FromJust(),
844  Nan::To<double>(innerArray->Get(context, 3).ToLocalChecked()).FromJust(),
845  Nan::To<double>(innerArray->Get(context, 4).ToLocalChecked()).FromJust(),
846  Nan::To<double>(innerArray->Get(context, 5).ToLocalChecked()).FromJust(),
847  Nan::To<double>(innerArray->Get(context, 6).ToLocalChecked()).FromJust(),
848  Nan::To<double>(innerArray->Get(context, 7).ToLocalChecked()).FromJust(),
849  Nan::To<double>(innerArray->Get(context, 8).ToLocalChecked()).FromJust()));
850  }
851  FanCurveType fanCurveType = getFanCurveType();
852 
853  //construct C++ obj and return
854  FanCurveData fanCurveData(fanCurveType, std::move(curveData));
855  return fanCurveData;
856 }
857 
858 void returnResultData(std::vector<ResultData> const &results)
859 {
860  v8::Isolate *isolate = v8::Isolate::GetCurrent();
861  v8::Local<v8::Context> context = isolate->GetCurrentContext();
862 
863  std::size_t index = 0;
864  Local<Array> outerArray = Nan::New<Array>(results.size());
865  for (ResultData const &row : results)
866  {
867  Local<Array> array = Nan::New<Array>(4);
868  Nan::Set(array, 0, Nan::New<Number>(row.flow));
869  Nan::Set(array, 1, Nan::New<Number>(row.pressure));
870  Nan::Set(array, 2, Nan::New<Number>(row.power));
871  Nan::Set(array, 3, Nan::New<Number>(row.efficiency));
872 
873  Nan::Set(outerArray, index, array);
874  index++;
875  }
876  Nan::Set(r, Nan::New<String>("ResultData").ToLocalChecked(), outerArray);
877 }
878 
879 // fan performance curves
880 NAN_METHOD(fanCurve)
881 {
882  //NAN init data
883  inp = Nan::To<Object>(info[0]).ToLocalChecked();
884  r = Nan::New<Object>();
885  //fetch bool values to check if defined objects were supplied
886  const bool baseCurveDataDefined = isDefined(inp, "BaseCurveData");
887  const bool ratedPointCurveDataDefined = isDefined(inp, "RatedPointCurveData");
888 
889  //NAN data fetching
890  const double density = Get("density", inp);
891  const double densityCorrected = Get("densityCorrected", inp);
892  const double speed = Get("speed", inp);
893  const double speedCorrected = Get("speedCorrected", inp);
894  const double pressureBarometric = Get("pressureBarometric", inp);
895  const double pressureBarometricCorrected = Get("pressureBarometricCorrected", inp);
896  const double pt1Factor = Get("pt1Factor", inp);
897  const double gamma = Get("gamma", inp);
898  const double gammaCorrected = Get("gammaCorrected", inp);
899  const double area1 = Get("area1", inp);
900  const double area2 = Get("area2", inp);
901 
902  if (baseCurveDataDefined)
903  {
904  FanCurveData fanCurveData = getFanBaseCurveData();
905  //Create C++ obj and calculate
906  std::vector<ResultData> const rv = FanCurve(density, densityCorrected, speed,
907  speedCorrected, pressureBarometric, pressureBarometricCorrected, pt1Factor,
908  gamma, gammaCorrected, area1, area2,
909  fanCurveData)
910  .calculate();
911 
912  //Construct return object
913  returnResultData(rv);
914  }
915  else if (ratedPointCurveDataDefined)
916  {
917  FanCurveData fanCurveData = getFanRatedPointCurveData();
918  //Create C++ obj and calculate
919  std::vector<ResultData> const rv = FanCurve(density, densityCorrected, speed,
920  speedCorrected, pressureBarometric, pressureBarometricCorrected, pt1Factor,
921  gamma, gammaCorrected, area1, area2,
922  fanCurveData)
923  .calculate();
924 
925  //Construct return object
926  returnResultData(rv);
927  }
928  else
929  {
930  FanCurveData fanCurveData = getFanBaseOperatingPointCurveData();
931  //Create C++ obj and calculate
932  std::vector<ResultData> const rv = FanCurve(density, densityCorrected, speed,
933  speedCorrected, pressureBarometric, pressureBarometricCorrected, pt1Factor,
934  gamma, gammaCorrected, area1, area2,
935  fanCurveData)
936  .calculate();
937 
938  //Construct return object
939  returnResultData(rv);
940  }
941  //NAN return obj
942  info.GetReturnValue().Set(r);
943 }
944 
945 NAN_METHOD(optimalFanEfficiency)
946 {
947  //NAN init data
948  inp = Nan::To<Object>(info[0]).ToLocalChecked();
949  OptimalFanEfficiency::FanType const fanType = GetEnumVal<OptimalFanEfficiency::FanType>("fanType", inp);
950  double const fanSpeed = Get("fanSpeed", inp);
951  double const flowRate = Get("flowRate", inp);
952  double const inletPressure = Get("inletPressure", inp);
953  double const outletPressure = Get("outletPressure", inp);
954  double const compressibility = Get("compressibility", inp);
955 
956  //Create C++ obj and calculate
957  double efficiency = OptimalFanEfficiency(fanType, fanSpeed, flowRate, inletPressure, outletPressure,
958  compressibility)
959  .calculate();
960  efficiency = Conversion(efficiency).fractionToPercent();
961 
962  //NAN returning single value
963  info.GetReturnValue().Set(efficiency);
964 }
965 
966 NAN_METHOD(compressibilityFactor)
967 {
968  //NAN init data
969  inp = Nan::To<Object>(info[0]).ToLocalChecked();
970  const double moverShaftPower = Get("moverShaftPower", inp);
971  const double inletPressure = Get("inletPressure", inp);
972  const double outletPressure = Get("outletPressure", inp);
973  const double barometricPressure = Get("barometricPressure", inp);
974  const double flowRate = Get("flowRate", inp);
975  const double specificHeatRatio = Get("specificHeatRatio", inp);
976 
977  //Create C++ obj and calculate
978  double const compressibilityFactor = CompressibilityFactor(
979  moverShaftPower, inletPressure, outletPressure,
980  barometricPressure, flowRate, specificHeatRatio)
981  .calculate();
982 
983  //NAN returning single value
984  info.GetReturnValue().Set(compressibilityFactor);
985 }
FanCurveType
Definition: FanCurve.h:15
Definition: Fan203.h:614
Contains InputData for both PSAT and Fan results.
Definition: InputData.h:15
Contains some of the Fan related classes.