MEASUR-Tools-Suite v1.0.11
The MEASUR Tools Suite is a collection of industrial efficiency calculations written in C++ and with bindings for compilation to WebAssembly.
Loading...
Searching...
No Matches
HeatExchanger.h
1#ifndef TOOLS_SUITE_HEATEXCHANGER_H
2#define TOOLS_SUITE_HEATEXCHANGER_H
3
4#include <stdexcept>
5
6#include "Header.h"
7#include "SteamProperties.h"
8
10 public:
11 struct Output {
13 : hotOutlet(hotOutlet), coldOutlet(coldOutlet) {}
14 SteamSystemModelerTool::FluidProperties hotOutlet, coldOutlet;
15 };
16
17 friend std::ostream& operator<<(std::ostream& stream, const HeatExchanger::Output& output) {
18 stream << "HeatExchanger::Output[" << "hotOutlet=" << output.hotOutlet << ", coldOutlet=" << output.coldOutlet
19 << "]";
20 return stream;
21 }
22
23 friend std::ostream& operator<<(std::ostream& stream, const std::shared_ptr<HeatExchanger::Output>& turbine) {
24 if (turbine == nullptr) {
25 stream << "HeatExchanger::Output[nullptr]";
26 }
27 else {
28 stream << *turbine;
29 }
30 return stream;
31 }
32
40 const SteamSystemModelerTool::FluidProperties coldInlet, const double approachTemp = 20)
41 : hotInlet(hotInlet), coldInlet(coldInlet), approachTemp(approachTemp) {}
42
43 Output calculate() {
44 auto sp = SteamProperties(hotInlet.pressure, SteamProperties::ThermodynamicQuantity::TEMPERATURE,
45 coldInlet.temperature + approachTemp)
46 .calculate();
47
48 auto hotOutletTest =
49 SteamSystemModelerTool::FluidProperties(hotInlet.massFlow, hotInlet.massFlow * sp.specificEnthalpy, sp);
50
51 double heatExchanged = hotInlet.energyFlow - hotOutletTest.energyFlow;
52 // TODO this should be rearranged to not perform a useless calculation
53 sp = SteamProperties(coldInlet.pressure, SteamProperties::ThermodynamicQuantity::ENTHALPY,
54 (coldInlet.energyFlow + heatExchanged) / coldInlet.massFlow)
55 .calculate();
56
57 auto coldOutletTest =
58 SteamSystemModelerTool::FluidProperties(coldInlet.massFlow, coldInlet.massFlow * sp.specificEnthalpy, sp);
59
60 if (fabs((hotOutletTest.temperature - coldInlet.temperature) - approachTemp) > .0001) {
61 sp = SteamProperties(coldInlet.pressure, SteamProperties::ThermodynamicQuantity::TEMPERATURE,
62 hotInlet.temperature - approachTemp)
63 .calculate();
64
65 coldOutletTest = SteamSystemModelerTool::FluidProperties(coldInlet.massFlow,
66 coldInlet.massFlow * sp.specificEnthalpy, sp);
67
68 heatExchanged = coldOutletTest.energyFlow - coldInlet.energyFlow;
69 sp = SteamProperties(hotInlet.pressure, SteamProperties::ThermodynamicQuantity::ENTHALPY,
70 (hotInlet.energyFlow - heatExchanged) / hotInlet.massFlow)
71 .calculate();
72
73 hotOutletTest =
74 SteamSystemModelerTool::FluidProperties(hotInlet.massFlow, hotInlet.massFlow * sp.specificEnthalpy, sp);
75 }
76 return {hotOutletTest, coldOutletTest};
77 }
78
79 private:
81 const double approachTemp;
82};
83
84#endif // TOOLS_SUITE_HEATEXCHANGER_H
HeatExchanger(const SteamSystemModelerTool::FluidProperties hotInlet, const SteamSystemModelerTool::FluidProperties coldInlet, const double approachTemp=20)
SteamSystemModelerTool::SteamPropertiesOutput calculate()