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
HeatExchanger.h
1 #ifndef AMO_TOOLS_SUITE_HEATEXCHANGER_H
2 #define AMO_TOOLS_SUITE_HEATEXCHANGER_H
3 
4 #include <stdexcept>
5 #include "SteamProperties.h"
6 #include "Header.h"
7 
8 class HeatExchanger {
9 public:
10  struct Output {
12  : hotOutlet(hotOutlet), coldOutlet(coldOutlet)
13  {}
14  SteamSystemModelerTool::FluidProperties hotOutlet, coldOutlet;
15  };
16 
17  friend std::ostream &operator<<(std::ostream &stream, const HeatExchanger::Output &output) {
18  stream << "HeatExchanger::Output["
19  << "hotOutlet=" << output.hotOutlet
20  << ", coldOutlet=" << output.coldOutlet
21  << "]";
22  return stream;
23  }
24 
25  friend std::ostream &operator<<(std::ostream &stream, const std::shared_ptr<HeatExchanger::Output> &turbine) {
26  if (turbine == nullptr) {
27  stream << "HeatExchanger::Output[nullptr]";
28  } else {
29  stream << *turbine;
30  }
31  return stream;
32  }
33 
42  const double approachTemp = 20
43  )
44  : hotInlet(hotInlet), coldInlet(coldInlet), approachTemp(approachTemp)
45  {}
46 
47  Output calculate() {
48  auto sp = SteamProperties(
49  hotInlet.pressure, SteamProperties::ThermodynamicQuantity::TEMPERATURE,
50  coldInlet.temperature + approachTemp
51  ).calculate();
52 
53  auto hotOutletTest = SteamSystemModelerTool::FluidProperties(
54  hotInlet.massFlow, hotInlet.massFlow * sp.specificEnthalpy, sp
55  );
56 
57  double heatExchanged = hotInlet.energyFlow - hotOutletTest.energyFlow;
58  // TODO this should be rearranged to not perform a useless calculation
59  sp = SteamProperties(
60  coldInlet.pressure, SteamProperties::ThermodynamicQuantity::ENTHALPY,
61  (coldInlet.energyFlow + heatExchanged) / coldInlet.massFlow
62  ).calculate();
63 
64  auto coldOutletTest = SteamSystemModelerTool::FluidProperties(
65  coldInlet.massFlow, coldInlet.massFlow * sp.specificEnthalpy, sp
66  );
67 
68  if (fabs((hotOutletTest.temperature - coldInlet.temperature) - approachTemp) > .0001) {
69  sp = SteamProperties(
70  coldInlet.pressure, SteamProperties::ThermodynamicQuantity::TEMPERATURE,
71  hotInlet.temperature - approachTemp
72  ).calculate();
73 
75  coldInlet.massFlow, coldInlet.massFlow * sp.specificEnthalpy, sp
76  );
77 
78  heatExchanged = coldOutletTest.energyFlow - coldInlet.energyFlow;
79  sp = SteamProperties(
80  hotInlet.pressure, SteamProperties::ThermodynamicQuantity::ENTHALPY,
81  (hotInlet.energyFlow - heatExchanged) / hotInlet.massFlow
82  ).calculate();
83 
85  hotInlet.massFlow, hotInlet.massFlow * sp.specificEnthalpy, sp
86  );
87  }
88  return {hotOutletTest, coldOutletTest};
89  }
90 private:
91  SteamSystemModelerTool::FluidProperties hotInlet, coldInlet;
92  const double approachTemp;
93 };
94 
95 #endif //AMO_TOOLS_SUITE_HEATEXCHANGER_H
HeatExchanger(const SteamSystemModelerTool::FluidProperties hotInlet, const SteamSystemModelerTool::FluidProperties coldInlet, const double approachTemp=20)
Definition: HeatExchanger.h:40
SteamSystemModelerTool::SteamPropertiesOutput calculate()