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