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
ssmt.h
1 #ifndef AMO_TOOLS_SUITE_SSMT_H
2 #define AMO_TOOLS_SUITE_SSMT_H
3 
4 #include "NanDataConverters.h"
5 
6 #include "ssmt/SaturatedProperties.h"
7 #include "ssmt/SteamSystemModelerTool.h"
8 #include "ssmt/SteamProperties.h"
9 #include "ssmt/HeatLoss.h"
10 #include "ssmt/Boiler.h"
11 #include "ssmt/HeatLoss.h"
12 #include "ssmt/FlashTank.h"
13 #include "ssmt/PRV.h"
14 #include "ssmt/Deaerator.h"
15 #include "ssmt/Header.h"
16 #include "ssmt/Turbine.h"
17 #include "ssmt/HeatExchanger.h"
18 #include "ssmt/api/SteamModeler.h"
19 #include "steam/SteamModelerInputDataMapper.h"
20 #include "steam/SteamModelerOutputDataMapper.h"
21 #include <string>
22 #include <stdexcept>
23 #include <array>
24 #include <cmath>
25 
26 SteamProperties::ThermodynamicQuantity thermodynamicQuantity() {
27  unsigned val = static_cast<unsigned>(getDouble("thermodynamicQuantity"));
28  return static_cast<SteamProperties::ThermodynamicQuantity>(val);
29 }
30 
31 SteamProperties::ThermodynamicQuantity feedwaterThermodynamicQuantity() {
32  unsigned val = static_cast<unsigned>(getDouble("feedwaterThermodynamicQuantity"));
33  return static_cast<SteamProperties::ThermodynamicQuantity>(val);
34 }
35 
36 SteamProperties::ThermodynamicQuantity waterThermodynamicQuantity() {
37  unsigned val = static_cast<unsigned>(getDouble("waterThermodynamicQuantity"));
38  return static_cast<SteamProperties::ThermodynamicQuantity>(val);
39 }
40 
41 SteamProperties::ThermodynamicQuantity steamThermodynamicQuantity() {
42  unsigned val = static_cast<unsigned>(getDouble("steamThermodynamicQuantity"));
43  return static_cast<SteamProperties::ThermodynamicQuantity>(val);
44 }
45 
46 NAN_METHOD(saturatedPressure) {
47  inp = Nan::To<Object>(info[0]).ToLocalChecked();
48  r = Nan::New<Object>();
49 
50  const double saturatedTemperature = getDouble("saturatedTemperature");
51 
52  SaturatedPressure sp(saturatedTemperature);
53  setR("saturatedPressure", sp.calculate());
54  info.GetReturnValue().Set(r);
55 }
56 
57 NAN_METHOD(saturatedTemperature) {
58  inp = Nan::To<Object>(info[0]).ToLocalChecked();
59  r = Nan::New<Object>();
60 
61  const double saturatedPressure = getDouble("saturatedPressure");
62 
63  SaturatedTemperature st(saturatedPressure);
64  setR("saturatedTemperature", st.calculate());
65  info.GetReturnValue().Set(r);
66 }
67 
68 NAN_METHOD(saturatedPropertiesGivenTemperature) {
69  inp = Nan::To<Object>(info[0]).ToLocalChecked();
70  r = Nan::New<Object>();
71 
72  const double saturatedTemperature = getDouble("saturatedTemperature");
73  double const pressure = SaturatedPressure(saturatedTemperature).calculate();
74  SteamSystemModelerTool::SaturatedPropertiesOutput const results = SaturatedProperties(pressure, saturatedTemperature).calculate();
75 
76  setR("saturatedPressure", results.pressure);
77  setR("saturatedTemperature", results.temperature);
78  setR("liquidEnthalpy", results.liquidSpecificEnthalpy);
79  setR("gasEnthalpy", results.gasSpecificEnthalpy);
80  setR("evaporationEnthalpy", results.evaporationSpecificEnthalpy);
81  setR("liquidEntropy", results.liquidSpecificEntropy);
82  setR("gasEntropy", results.gasSpecificEntropy);
83  setR("evaporationEntropy", results.evaporationSpecificEntropy);
84  setR("liquidVolume", results.liquidSpecificVolume);
85  setR("gasVolume", results.gasSpecificVolume);
86  setR("evaporationVolume", results.evaporationSpecificVolume);
87  info.GetReturnValue().Set(r);
88 }
89 
90 NAN_METHOD(saturatedPropertiesGivenPressure) {
91 
92  inp = Nan::To<Object>(info[0]).ToLocalChecked();
93  r = Nan::New<Object>();
94 
95  const double saturatedPressure = getDouble("saturatedPressure");
96  double const temperature = SaturatedTemperature(saturatedPressure).calculate();
97  SteamSystemModelerTool::SaturatedPropertiesOutput const results = SaturatedProperties(saturatedPressure, temperature).calculate();
98 
99  setR("saturatedPressure", results.pressure);
100  setR("saturatedTemperature", results.temperature);
101  setR("liquidEnthalpy", results.liquidSpecificEnthalpy);
102  setR("gasEnthalpy", results.gasSpecificEnthalpy);
103  setR("evaporationEnthalpy", results.evaporationSpecificEnthalpy);
104  setR("liquidEntropy", results.liquidSpecificEntropy);
105  setR("gasEntropy", results.gasSpecificEntropy);
106  setR("evaporationEntropy", results.evaporationSpecificEntropy);
107  setR("liquidVolume", results.liquidSpecificVolume);
108  setR("gasVolume", results.gasSpecificVolume);
109  setR("evaporationVolume", results.evaporationSpecificVolume);
110  info.GetReturnValue().Set(r);
111 }
112 
113 NAN_METHOD(steamProperties) {
114  inp = Nan::To<Object>(info[0]).ToLocalChecked();
115  r = Nan::New<Object>();
116 
117  const double pressure = getDouble("pressure");
118  const double quantityValue = getDouble("quantityValue");
119 
120  try {
121  SteamProperties::ThermodynamicQuantity quantity = thermodynamicQuantity();
122  SteamSystemModelerTool::SteamPropertiesOutput const results = SteamProperties(pressure, quantity, quantityValue).calculate();
123 
124  setR("pressure", results.pressure);
125  setR("temperature", results.temperature);
126  setR("specificEnthalpy", results.specificEnthalpy);
127  setR("specificEntropy", results.specificEntropy);
128  setR("quality", results.quality);
129  setR("specificVolume", results.specificVolume);
130  } catch (std::runtime_error const &e) {
131  std::string const what = e.what();
132  ThrowError(std::string("std::runtime_error thrown in steamProperties - ssmt.h: " + what).c_str());
133  }
134  info.GetReturnValue().Set(r);
135 }
136 
137 NAN_METHOD(boiler) {
138  inp = Nan::To<Object>(info[0]).ToLocalChecked();
139  r = Nan::New<Object>();
140 
141  const double deaeratorPressure = getDouble("deaeratorPressure");
142  const double combustionEfficiency = getDouble("combustionEfficiency");
143  const double blowdownRate = getDouble("blowdownRate");
144  const double steamPressure = getDouble("steamPressure");
145  const double quantityValue = getDouble("quantityValue");
146  const double steamMassFlow = getDouble("steamMassFlow");
147  try {
148  SteamProperties::ThermodynamicQuantity quantityType = thermodynamicQuantity();
149 
150  Boiler const b = Boiler(deaeratorPressure, combustionEfficiency,
151  blowdownRate, steamPressure, quantityType, quantityValue,
152  steamMassFlow);
153 
154  SteamSystemModelerTool::FluidProperties const results = b.getSteamProperties();
155  setR("steamPressure", results.pressure);
156  setR("steamTemperature", results.temperature);
157  setR("steamSpecificEnthalpy", results.specificEnthalpy);
158  setR("steamSpecificEntropy", results.specificEntropy);
159  setR("steamQuality", results.quality);
160  setR("steamMassFlow", results.massFlow);
161  setR("steamEnergyFlow", results.energyFlow);
162 
163  SteamSystemModelerTool::FluidProperties const results2 = b.getBlowdownProperties();
164  setR("blowdownPressure", results2.pressure);
165  setR("blowdownTemperature", results2.temperature);
166  setR("blowdownSpecificEnthalpy", results2.specificEnthalpy);
167  setR("blowdownSpecificEntropy", results2.specificEntropy);
168  setR("blowdownQuality", results2.quality);
169  setR("blowdownMassFlow", results2.massFlow);
170  setR("blowdownEnergyFlow", results2.energyFlow);
171 
172  SteamSystemModelerTool::FluidProperties const results3 = b.getFeedwaterProperties();
173  setR("feedwaterPressure", results3.pressure);
174  setR("feedwaterTemperature", results3.temperature);
175  setR("feedwaterSpecificEnthalpy", results3.specificEnthalpy);
176  setR("feedwaterSpecificEntropy", results3.specificEntropy);
177  setR("feedwaterQuality", results3.quality);
178  setR("feedwaterMassFlow", results3.massFlow);
179  setR("feedwaterEnergyFlow", results3.energyFlow);
180  setR("boilerEnergy", b.getBoilerEnergy());
181  setR("fuelEnergy", b.getFuelEnergy());
182  } catch (std::runtime_error const &e) {
183  std::string const what = e.what();
184  ThrowError(std::string("std::runtime_error thrown in boiler - ssmt.h: " + what).c_str());
185  }
186 
187  info.GetReturnValue().Set(r);
188 }
189 
190 NAN_METHOD(heatLoss) {
191  inp = Nan::To<Object>(info[0]).ToLocalChecked();
192  r = Nan::New<Object>();
193 
194  const double inletPressure = getDouble("inletPressure");
195  const double quantityValue = getDouble("quantityValue");
196  const double inletMassFlow = getDouble("inletMassFlow");
197  const double percentHeatLoss = getDouble("percentHeatLoss");
198  try {
199  SteamProperties::ThermodynamicQuantity quantityType = thermodynamicQuantity();
200  HeatLoss const hl = HeatLoss(inletPressure, quantityType, quantityValue,
201  inletMassFlow, percentHeatLoss);
202 
204 
205  setR("inletPressure", results.pressure);
206  setR("inletTemperature", results.temperature);
207  setR("inletSpecificEnthalpy", results.specificEnthalpy);
208  setR("inletSpecificEntropy", results.specificEntropy);
209  setR("inletQuality", results.quality);
210  setR("inletMassFlow", results.massFlow);
211  setR("inletEnergyFlow", results.energyFlow);
212 
214  setR("outletPressure", results2.pressure);
215  setR("outletTemperature", results2.temperature);
216  setR("outletSpecificEnthalpy", results2.specificEnthalpy);
217  setR("outletSpecificEntropy", results2.specificEntropy);
218  setR("outletQuality", results2.quality);
219  setR("outletMassFlow", results2.massFlow);
220  setR("outletEnergyFlow", results2.energyFlow);
221  setR("heatLoss", hl.getHeatLoss());
222  } catch (std::runtime_error const &e) {
223  std::string const what = e.what();
224  ThrowError(std::string("std::runtime_error thrown in heatLoss - ssmt.h: " + what).c_str());
225  }
226 
227  info.GetReturnValue().Set(r);
228 }
229 
230 NAN_METHOD(flashTank) {
231  inp = Nan::To<Object>(info[0]).ToLocalChecked();
232  r = Nan::New<Object>();
233 
234  const double inletWaterPressure = getDouble("inletWaterPressure");
235  const double quantityValue = getDouble("quantityValue");
236  const double inletWaterMassFlow = getDouble("inletWaterMassFlow");
237  const double tankPressure = getDouble("tankPressure");
238 
239  try {
240  SteamProperties::ThermodynamicQuantity quantityType = thermodynamicQuantity();
241 
242  FlashTank const ft = FlashTank(inletWaterPressure, quantityType, quantityValue,
243  inletWaterMassFlow, tankPressure);
244 
246  setR("inletWaterPressure", results.pressure);
247  setR("inletWaterTemperature", results.temperature);
248  setR("inletWaterSpecificEnthalpy", results.specificEnthalpy);
249  setR("inletWaterSpecificEntropy", results.specificEntropy);
250  setR("inletWaterQuality", results.quality);
251  setR("inletWaterMassFlow", results.massFlow);
252  setR("inletWaterEnergyFlow", results.energyFlow);
253 
255  setR("outletGasPressure", results2.pressure);
256  setR("outletGasTemperature", results2.temperature);
257  setR("outletGasSpecificEnthalpy", results2.specificEnthalpy);
258  setR("outletGasSpecificEntropy", results2.specificEntropy);
259  setR("outletGasQuality", 1);
260  setR("outletGasMassFlow", results2.massFlow);
261  setR("outletGasEnergyFlow", results2.energyFlow);
262 
263  SteamSystemModelerTool::FluidProperties const results3 = ft.getOutletLiquidSaturatedProperties();
264  setR("outletLiquidPressure", results3.pressure);
265  setR("outletLiquidTemperature", results3.temperature);
266  setR("outletLiquidSpecificEnthalpy", results3.specificEnthalpy);
267  setR("outletLiquidSpecificEntropy", results3.specificEntropy);
268  setR("outletLiquidQuality", 0);
269  setR("outletLiquidMassFlow", results3.massFlow);
270  setR("outletLiquidEnergyFlow", results3.energyFlow);
271  } catch (std::runtime_error const &e) {
272  std::string const what = e.what();
273  ThrowError(std::string("std::runtime_error thrown in flashTank - ssmt.h: " + what).c_str());
274  }
275 
276  info.GetReturnValue().Set(r);
277 }
278 
279 NAN_METHOD(prvWithoutDesuperheating) {
280  inp = Nan::To<Object>(info[0]).ToLocalChecked();
281  r = Nan::New<Object>();
282 
283  const double inletPressure = getDouble("inletPressure");
284  const double quantityValue = getDouble("quantityValue");
285  const double inletMassFlow = getDouble("inletMassFlow");
286  const double outletPressure = getDouble("outletPressure");
287 
288  try {
289  SteamProperties::ThermodynamicQuantity quantityType = thermodynamicQuantity();
290  PrvWithoutDesuperheating const pwod = PrvWithoutDesuperheating(inletPressure, quantityType, quantityValue,
291  inletMassFlow, outletPressure);
292 
294  setR("inletPressure", results.pressure);
295  setR("inletTemperature", results.temperature);
296  setR("inletSpecificEnthalpy", results.specificEnthalpy);
297  setR("inletSpecificEntropy", results.specificEntropy);
298  setR("inletQuality", results.quality);
299  setR("inletMassFlow", pwod.getInletMassFlow());
300  setR("inletEnergyFlow", pwod.getInletEnergyFlow());
301 
303  setR("outletPressure", results2.pressure);
304  setR("outletTemperature", results2.temperature);
305  setR("outletSpecificEnthalpy", results2.specificEnthalpy);
306  setR("outletSpecificEntropy", results2.specificEntropy);
307  setR("outletQuality", results2.quality);
308  setR("outletMassFlow", pwod.getOutletMassFlow());
309  setR("outletEnergyFlow", pwod.getOutletEnergyFlow());
310  } catch (std::runtime_error const &e) {
311  std::string const what = e.what();
312  ThrowError(std::string("std::runtime_error thrown in prvWithoutDesuperheating - ssmt.h: " + what).c_str());
313  }
314 
315  info.GetReturnValue().Set(r);
316 }
317 
318 NAN_METHOD(prvWithDesuperheating) {
319  inp = Nan::To<Object>(info[0]).ToLocalChecked();
320  r = Nan::New<Object>();
321 
322  const double inletPressure = getDouble("inletPressure");
323  const double quantityValue = getDouble("quantityValue");
324  const double inletMassFlow = getDouble("inletMassFlow");
325  const double outletPressure = getDouble("outletPressure");
326  const double feedwaterPressure = getDouble("feedwaterPressure");
327  const double feedwaterQuantityValue = getDouble("feedwaterQuantityValue");
328  const double desuperheatingTemp = getDouble("desuperheatingTemp");
329 
330  try {
331  SteamProperties::ThermodynamicQuantity quantityType = thermodynamicQuantity();
332  SteamProperties::ThermodynamicQuantity feedwaterQuantityType = feedwaterThermodynamicQuantity();
333 
334  PrvWithDesuperheating const pwd = PrvWithDesuperheating(inletPressure, quantityType, quantityValue,
335  inletMassFlow, outletPressure, feedwaterPressure,
336  feedwaterQuantityType, feedwaterQuantityValue, desuperheatingTemp);
337 
339  setR("inletPressure", results.pressure);
340  setR("inletTemperature", results.temperature);
341  setR("inletSpecificEnthalpy", results.specificEnthalpy);
342  setR("inletSpecificEntropy", results.specificEntropy);
343  setR("inletQuality", results.quality);
344  setR("inletMassFlow", pwd.getInletMassFlow());
345  setR("inletEnergyFlow", pwd.getInletEnergyFlow());
346 
348  setR("outletPressure", results2.pressure);
349  setR("outletTemperature", results2.temperature);
350  setR("outletSpecificEnthalpy", results2.specificEnthalpy);
351  setR("outletSpecificEntropy", results2.specificEntropy);
352  setR("outletQuality", results2.quality);
353  setR("outletMassFlow", pwd.getOutletMassFlow());
354  setR("outletEnergyFlow", pwd.getOutletEnergyFlow());
355 
357  setR("feedwaterPressure", results3.pressure);
358  setR("feedwaterTemperature", results3.temperature);
359  setR("feedwaterSpecificEnthalpy", results3.specificEnthalpy);
360  setR("feedwaterSpecificEntropy", results3.specificEntropy);
361  setR("feedwaterQuality", results3.quality);
362  setR("feedwaterMassFlow", pwd.getFeedwaterMassFlow());
363  setR("feedwaterEnergyFlow", pwd.getFeedwaterEnergyFlow());
364  } catch (std::runtime_error const &e) {
365  std::string const what = e.what();
366  ThrowError(std::string("std::runtime_error thrown in prvWithDesuperheating - ssmt.h: " + what).c_str());
367  }
368 
369  info.GetReturnValue().Set(r);
370 }
371 
372 NAN_METHOD(deaerator) {
373  inp = Nan::To<Object>(info[0]).ToLocalChecked();
374  r = Nan::New<Object>();
375 
376  const double deaeratorPressure = getDouble("deaeratorPressure");
377  const double ventRate = getDouble("ventRate");
378  const double feedwaterMassFlow = getDouble("feedwaterMassFlow");
379  const double waterPressure = getDouble("waterPressure");
380  const double waterQuantityValue = getDouble("waterQuantityValue");
381  const double steamPressure = getDouble("steamPressure");
382  const double steamQuantityValue = getDouble("steamQuantityValue");
383  try {
384  SteamProperties::ThermodynamicQuantity waterQuantityType = waterThermodynamicQuantity();
385  SteamProperties::ThermodynamicQuantity steamQuantityType = steamThermodynamicQuantity();
386 
387  Deaerator d(deaeratorPressure, ventRate, feedwaterMassFlow,
388  waterPressure, waterQuantityType, waterQuantityValue,
389  steamPressure, steamQuantityType,
390  steamQuantityValue);
391 
392  SteamSystemModelerTool::FluidProperties const results = d.getFeedwaterProperties();
393  setR("feedwaterPressure", results.pressure);
394  setR("feedwaterTemperature", results.temperature);
395  setR("feedwaterSpecificEnthalpy", results.specificEnthalpy);
396  setR("feedwaterSpecificEntropy", results.specificEntropy);
397  setR("feedwaterQuality", results.quality);
398  setR("feedwaterMassFlow", results.massFlow);
399  setR("feedwaterEnergyFlow", results.energyFlow);
400 
401  SteamSystemModelerTool::FluidProperties const results2 = d.getVentedSteamProperties();
402  setR("ventedSteamPressure", results2.pressure);
403  setR("ventedSteamTemperature", results2.temperature);
404  setR("ventedSteamSpecificEnthalpy", results2.specificEnthalpy);
405  setR("ventedSteamSpecificEntropy", results2.specificEntropy);
406  setR("ventedSteamQuality", results2.quality);
407  setR("ventedSteamMassFlow", results2.massFlow);
408  setR("ventedSteamEnergyFlow", results2.energyFlow);
409 
410  SteamSystemModelerTool::FluidProperties const results3 = d.getInletWaterProperties();
411  setR("inletWaterPressure", results3.pressure);
412  setR("inletWaterTemperature", results3.temperature);
413  setR("inletWaterSpecificEnthalpy", results3.specificEnthalpy);
414  setR("inletWaterSpecificEntropy", results3.specificEntropy);
415  setR("inletWaterQuality", results3.quality);
416  setR("inletWaterMassFlow", results3.massFlow);
417  setR("inletWaterEnergyFlow", results3.energyFlow);
418 
419  SteamSystemModelerTool::FluidProperties const results4 = d.getInletSteamProperties();
420  setR("inletSteamPressure", results4.pressure);
421  setR("inletSteamTemperature", results4.temperature);
422  setR("inletSteamSpecificEnthalpy", results4.specificEnthalpy);
423  setR("inletSteamSpecificEntropy", results4.specificEntropy);
424  setR("inletSteamQuality", results4.quality);
425  setR("inletSteamMassFlow", results4.massFlow);
426  setR("inletSteamEnergyFlow", results4.energyFlow);
427  } catch (std::runtime_error const &e) {
428  std::string const what = e.what();
429  ThrowError(std::string("std::runtime_error thrown in deaerator - ssmt.h: " + what).c_str());
430  }
431 
432  info.GetReturnValue().Set(r);
433 }
434 
435 NAN_METHOD(header) {
436  inp = Nan::To<Object>(info[0]).ToLocalChecked();
437  r = Nan::New<Object>();
438 
439  double const headerPressure = getDouble("headerPressure");
440 
441  Local<String> arrayStr = Nan::New<String>("inlets").ToLocalChecked();
442  v8::Local<v8::Value> arrayTmp = Nan::Get(Nan::To<v8::Object>(inp).ToLocalChecked(), arrayStr).ToLocalChecked();
443  v8::Local<v8::Array> arr = v8::Local<v8::Array>::Cast(arrayTmp);
444 
445  Local<String> pressureStr = Nan::New<String>("pressure").ToLocalChecked();
446  Local<String> temperatureStr = Nan::New<String>("temperature").ToLocalChecked();
447  Local<String> qualityStr = Nan::New<String>("quality").ToLocalChecked();
448  Local<String> massFlowStr = Nan::New<String>("massFlow").ToLocalChecked();
449  Local<String> specificEnthalpyStr = Nan::New<String>("specificEnthalpy").ToLocalChecked();
450  Local<String> specificEntropyStr = Nan::New<String>("specificEntropy").ToLocalChecked();
451  Local<String> energyFlowStr = Nan::New<String>("energyFlow").ToLocalChecked();
452 
453  std::vector<Inlet> inlets;
454 
455  v8::Isolate *isolate = v8::Isolate::GetCurrent();
456  v8::Local<v8::Context> context = isolate->GetCurrentContext();
457 
458  for (std::size_t i = 0; i < arr->Length(); i++) {
459  double const pressure = Nan::To<double>(Nan::Get(Nan::To<v8::Object>(arr->Get(context, i).ToLocalChecked()).ToLocalChecked(), pressureStr).ToLocalChecked()).FromJust();
460  unsigned val = static_cast<unsigned>(Nan::To<double>(Nan::Get(Nan::To<v8::Object>(arr->Get(context, i).ToLocalChecked()).ToLocalChecked(), Nan::New<String>("thermodynamicQuantity").ToLocalChecked()).ToLocalChecked()).FromJust());
462  double const quantityValue = Nan::To<double>(Nan::Get(Nan::To<v8::Object>(arr->Get(context, i).ToLocalChecked()).ToLocalChecked(), Nan::New<String>("quantityValue").ToLocalChecked()).ToLocalChecked()).FromJust();
463  double const massFlow = Nan::To<double>(Nan::Get(Nan::To<v8::Object>(arr->Get(context, i).ToLocalChecked()).ToLocalChecked(), massFlowStr).ToLocalChecked()).FromJust();
464 
465  inlets.emplace_back(Inlet(pressure, quantity, quantityValue, massFlow));
466 
467  Local<Object> obj = Nan::New<Object>();
468  Local<String> inletNum = Nan::New<String>("inlet" + std::to_string(i + 1)).ToLocalChecked();
469  SteamSystemModelerTool::SteamPropertiesOutput const inletProps = inlets[i].getInletProperties();
470 
471  Nan::Set(obj, pressureStr, Nan::New<Number>(inletProps.pressure));
472  Nan::Set(obj, temperatureStr, Nan::New<Number>(inletProps.temperature));
473  Nan::Set(obj, qualityStr, Nan::New<Number>(inletProps.quality));
474  Nan::Set(obj, specificEnthalpyStr, Nan::New<Number>(inletProps.specificEnthalpy));
475  Nan::Set(obj, specificEntropyStr, Nan::New<Number>(inletProps.specificEntropy));
476  Nan::Set(obj, energyFlowStr, Nan::New<Number>(inlets[i].getInletEnergyFlow()));
477  Nan::Set(obj, massFlowStr, Nan::New<Number>(inlets[i].getMassFlow()));
478 
479  Nan::Set(r, inletNum, obj);
480  }
481 
482  try {
483  Header header = Header(headerPressure, inlets);
484  Local<String> headerStr = Nan::New<String>("header").ToLocalChecked();
485 
487 
488  Local<Object> obj = Nan::New<Object>();
489 
490  Nan::Set(obj, pressureStr, Nan::New<Number>(header.getHeaderPressure()));
491  Nan::Set(obj, temperatureStr, Nan::New<Number>(headerProps.temperature));
492  Nan::Set(obj, qualityStr, Nan::New<Number>(headerProps.quality));
493  Nan::Set(obj, specificEnthalpyStr, Nan::New<Number>(headerProps.specificEnthalpy));
494  Nan::Set(obj, specificEntropyStr, Nan::New<Number>(headerProps.specificEntropy));
495  Nan::Set(obj, energyFlowStr, Nan::New<Number>(header.getInletEnergyFlow()));
496  Nan::Set(obj, massFlowStr, Nan::New<Number>(header.getInletMassFlow()));
497 
498  Nan::Set(r, headerStr, obj);
499  } catch (std::runtime_error const &e) {
500  std::string const what = e.what();
501  ThrowError(std::string("std::runtime_error thrown in header - ssmt.h: " + what).c_str());
502  }
503  info.GetReturnValue().Set(r);
504 }
505 
506 NAN_METHOD(turbine) {
507  inp = Nan::To<Object>(info[0]).ToLocalChecked();
508  r = Nan::New<Object>();
509 
510  const double inletPressure = getDouble("inletPressure");
511  const double inletQuantityValue = getDouble("inletQuantityValue");
512  const double generatorEfficiency = getDouble("generatorEfficiency");
513  const double massFlowOrPowerOut = getDouble("massFlowOrPowerOut");
514  const double outletSteamPressure = getDouble("outletSteamPressure");
515 
516  unsigned val = static_cast<unsigned>(Nan::To<double>(Nan::Get(Nan::To<v8::Object>(inp).ToLocalChecked(), Nan::New<String>("solveFor").ToLocalChecked()).ToLocalChecked()).FromJust());
517 
518  Turbine::Solve solveFor = static_cast<Turbine::Solve>(val);
519  val = static_cast<unsigned>(Nan::To<double>(Nan::Get(Nan::To<v8::Object>(inp).ToLocalChecked(), Nan::New<String>("turbineProperty").ToLocalChecked()).ToLocalChecked()).FromJust());
520 
521  Turbine::TurbineProperty turbineProperty = static_cast<Turbine::TurbineProperty>(val);
522  val = static_cast<unsigned>(Nan::To<double>(Nan::Get(Nan::To<v8::Object>(inp).ToLocalChecked(), Nan::New<String>("inletQuantity").ToLocalChecked()).ToLocalChecked()).FromJust());
523 
525  std::shared_ptr<Turbine> t;
526 
527  try {
528  if (solveFor == Turbine::Solve::OutletProperties) {
529 
530  const double isentropicEfficiency = getDouble("isentropicEfficiency");
531 
532  t = std::shared_ptr<Turbine>(
533  new Turbine(solveFor, inletPressure, inletQuantity, inletQuantityValue,
534  turbineProperty, isentropicEfficiency, generatorEfficiency,
535  massFlowOrPowerOut, outletSteamPressure));
536  } else {
537 
538  const double outletQuantityValue = getDouble("outletQuantityValue");
539  v8::Isolate *isolate = v8::Isolate::GetCurrent();
540  v8::Local<v8::Context> context = isolate->GetCurrentContext();
541  unsigned val = static_cast<unsigned>(Nan::To<double>(Nan::Get(Nan::To<v8::Object>(inp).ToLocalChecked(), Nan::New<String>("outletQuantity").ToLocalChecked()).ToLocalChecked()).FromJust());
543  t = std::shared_ptr<Turbine>(
544  new Turbine(solveFor, inletPressure, inletQuantity, inletQuantityValue,
545  turbineProperty, generatorEfficiency, massFlowOrPowerOut,
546  outletSteamPressure, outletQuantity, outletQuantityValue));
547  }
548  } catch (std::runtime_error const &e) {
549  std::string const what = e.what();
550  ThrowError(std::string("std::runtime_error thrown in turbine - ssmt.h: " + what).c_str());
551  }
552 
553  SteamSystemModelerTool::SteamPropertiesOutput results = t->getInletProperties();
554  setR("inletPressure", results.pressure);
555  setR("inletTemperature", results.temperature);
556  setR("inletSpecificEnthalpy", results.specificEnthalpy);
557  setR("inletSpecificEntropy", results.specificEntropy);
558  setR("inletQuality", results.quality);
559  setR("inletEnergyFlow", t->getInletEnergyFlow());
560 
561  results = t->getOutletProperties();
562  setR("outletPressure", results.pressure);
563  setR("outletTemperature", results.temperature);
564  setR("outletSpecificEnthalpy", results.specificEnthalpy);
565  setR("outletSpecificEntropy", results.specificEntropy);
566  setR("outletQuality", results.quality);
567  setR("outletEnergyFlow", t->getOutletEnergyFlow());
568 
569  setR("massFlow", t->getMassFlow());
570  setR("isentropicEfficiency", t->getIsentropicEfficiency());
571  setR("energyOut", t->getEnergyOut());
572  setR("powerOut", t->getPowerOut());
573  setR("generatorEfficiency", t->getGeneratorEfficiency());
574  info.GetReturnValue().Set(r);
575 }
576 
577 NAN_METHOD(heatExchanger) {
578  inp = Nan::To<Object>(info[0]).ToLocalChecked();
579  r = Nan::New<Object>();
580 
581  const double hotInletMassFlow = getDouble("hotInletMassFlow");
582  const double hotInletEnergyFlow = getDouble("hotInletEnergyFlow");
583  const double hotInletTemperature = getDouble("hotInletTemperature");
584  const double hotInletPressure = getDouble("hotInletPressure");
585  const double hotInletQuality = getDouble("hotInletQuality");
586  const double hotInletSpecificVolume = getDouble("hotInletSpecificVolume");
587  const double hotInletDensity = getDouble("hotInletDensity");
588  const double hotInletSpecificEnthalpy = getDouble("hotInletSpecificEnthalpy");
589  const double hotInletSpecificEntropy = getDouble("hotInletSpecificEntropy");
590 
591  const double coldInletMassFlow = getDouble("coldInletMassFlow");
592  const double coldInletEnergyFlow = getDouble("coldInletEnergyFlow");
593  const double coldInletTemperature = getDouble("coldInletTemperature");
594  const double coldInletPressure = getDouble("coldInletPressure");
595  const double coldInletQuality = getDouble("coldInletQuality");
596  const double coldInletSpecificVolume = getDouble("coldInletSpecificVolume");
597  const double coldInletDensity = getDouble("coldInletDensity");
598  const double coldInletSpecificEnthalpy = getDouble("coldInletSpecificEnthalpy");
599  const double coldInletSpecificEntropy = getDouble("coldInletSpecificEntropy");
600 
601  const double approachTemp = getDouble("approachTemp");
602 
603  const SteamSystemModelerTool::FluidProperties hotInlet(hotInletMassFlow, hotInletEnergyFlow, hotInletTemperature,
604  hotInletPressure, hotInletQuality, hotInletSpecificVolume, hotInletDensity, hotInletSpecificEnthalpy,
605  hotInletSpecificEntropy);
606 
607  const SteamSystemModelerTool::FluidProperties coldInlet(coldInletMassFlow, coldInletEnergyFlow, coldInletTemperature,
608  coldInletPressure, coldInletQuality, coldInletSpecificVolume, coldInletDensity, coldInletSpecificEnthalpy,
609  coldInletSpecificEntropy);
610 
611  HeatExchanger::Output const output = HeatExchanger(hotInlet, coldInlet, approachTemp).calculate();
612 
613  setR("hotOutletMassFlow", output.hotOutlet.massFlow);
614  setR("hotOutletEnergyFlow", output.hotOutlet.energyFlow);
615  setR("hotOutletTemperature", output.hotOutlet.temperature);
616  setR("hotOutletPressure", output.hotOutlet.pressure);
617  setR("hotOutletQuality", output.hotOutlet.quality);
618  setR("hotOutletSpecificVolume", output.hotOutlet.specificVolume);
619  setR("hotOutletDensity", output.hotOutlet.density);
620  setR("hotOutletSpecificEnthalpy", output.hotOutlet.specificEnthalpy);
621  setR("hotOutletSpecificEntropy", output.hotOutlet.specificEntropy);
622 
623  setR("coldOutletMassFlow", output.coldOutlet.massFlow);
624  setR("coldOutletEnergyFlow", output.coldOutlet.energyFlow);
625  setR("coldOutletTemperature", output.coldOutlet.temperature);
626  setR("coldOutletPressure", output.coldOutlet.pressure);
627  setR("coldOutletQuality", output.coldOutlet.quality);
628  setR("coldOutletSpecificVolume", output.coldOutlet.specificVolume);
629  setR("coldOutletDensity", output.coldOutlet.density);
630  setR("coldOutletSpecificEnthalpy", output.coldOutlet.specificEnthalpy);
631  setR("coldOutletSpecificEntropy", output.coldOutlet.specificEntropy);
632 
633  info.GetReturnValue().Set(r);
634 }
635 
636 NAN_METHOD(steamModeler) {
637  const std::string methodName = std::string("SteamModeler::") + std::string(__func__) + ": ";
638 
639  // std::cout << methodName << "begin: steam modeler" << std::endl;
640 
641  inp = Nan::To<Object>(info[0]).ToLocalChecked();
642  r = Nan::New<Object>();
643  info.GetReturnValue().Set(r);
644 
646  SteamModeler steamModeler = SteamModeler();
648 
649  // std::cout << methodName << "begin: input mapping" << std::endl;
650  SteamModelerInput steamModelerInput = inputDataMapper.map();
651 
652  // catch C++ error and throw as JS error
653  try {
654  // std::cout << methodName << "begin: modeling" << std::endl;
655  SteamModelerOutput steamModelerOutput = steamModeler.model(steamModelerInput);
656  // std::cout << methodName << "begin: output mapping" << std::endl;
657  outputDataMapper.map(steamModelerOutput);
658  } catch (const std::runtime_error &e) {
659  const std::string what = e.what();
660 
661  const HeaderInput &headerInput = steamModelerInput.getHeaderInput();
662  const int headerCount = headerInput.getHeaderCount();
663 
664  const std::string failMsg =
665  "ERROR calling SteamModeler: " + what + "; headerCount=" + std::to_string(headerCount);
666  std::cout << methodName << failMsg << std::endl;
667 
668  Local<String> failMsgLocal = Nan::New<String>(failMsg).ToLocalChecked();
669  ThrowError(failMsgLocal);
670  }
671 
672  // std::cout << methodName << "end: steam modeler" << std::endl;
673 }
674 
675 #endif //AMO_TOOLS_SUITE_SSMT_H
SteamSystemModelerTool::FluidProperties const & getInletProperties() const
Definition: HeatLoss.h:43
SteamSystemModelerTool::SteamPropertiesOutput const & getInletProperties() const
Definition: PRV.h:88
virtual double getOutletEnergyFlow() const
Definition: PRV.h:114
SteamSystemModelerTool::FluidProperties const & getOutletGasSaturatedProperties() const
Definition: FlashTank.h:51
virtual double getOutletMassFlow() const
Definition: PRV.h:107
SteamModelerOutput model(const SteamModelerInput &steamModelerInput)
Definition: SteamModeler.cpp:3
double getHeaderPressure() const
Definition: Header.h:58
TurbineProperty
enum class for TurbineProperty
Definition: Turbine.h:31
SteamSystemModelerTool::FluidProperties const & getOutletProperties() const
Definition: HeatLoss.h:49
double getHeatLoss() const
Definition: HeatLoss.h:55
double getInletEnergyFlow() const
Definition: PRV.h:100
Definition: Boiler.h:24
SteamSystemModelerTool::FluidProperties const & getInletWaterProperties() const
Definition: FlashTank.h:45
SteamSystemModelerTool::SteamPropertiesOutput const & getOutletProperties() const
Definition: PRV.h:94
double getOutletEnergyFlow() const override
Definition: PRV.h:301
Definition: Header.h:9
Solve
enum class for Solve
Definition: Turbine.h:26
double getInletMassFlow() const
Definition: PRV.h:71
SteamSystemModelerTool::SteamPropertiesOutput const & getHeaderProperties() const
Definition: Header.h:83
double getFuelEnergy() const
Definition: Boiler.h:144
double getFeedwaterMassFlow() const
Definition: PRV.h:307
double getBoilerEnergy() const
Definition: Boiler.h:138
SteamSystemModelerTool::SteamPropertiesOutput calculate()
ThermodynamicQuantity
enum class for ThermodynamicQuantity
Definition: Header.h:44
double getFeedwaterEnergyFlow() const
Definition: PRV.h:313
double getOutletMassFlow() const override
Definition: PRV.h:295
SteamSystemModelerTool::SteamPropertiesOutput const & getFeedwaterProperties() const
Definition: PRV.h:288
double getInletMassFlow() const
Definition: Header.h:73
double getInletEnergyFlow() const
Definition: Header.h:68
double calculate() const