CoolProp 8.0.0
An open-source fluid property and humid air property database
PhaseEnvelope.h
Go to the documentation of this file.
1#ifndef PHASE_ENVELOPE_H
2#define PHASE_ENVELOPE_H
3
5#include "CoolProp/detail/tools.h" // for CoolPropDbl, used throughout the signatures below
6
7#define PHASE_ENVELOPE_MATRICES X(K) X(lnK) X(x) X(y)
8#define PHASE_ENVELOPE_VECTORS \
9 X(T) \
10 X(p) \
11 X(lnT) \
12 X(lnp) \
13 X(rhomolar_liq) \
14 X(rhomolar_vap) \
15 X(lnrhomolar_liq) \
16 X(lnrhomolar_vap) \
17 X(hmolar_liq) \
18 X(hmolar_vap) \
19 X(smolar_liq) \
20 X(smolar_vap) \
21 X(Q) \
22 X(cpmolar_liq) \
23 X(cpmolar_vap) \
24 X(cvmolar_liq) \
25 X(cvmolar_vap) \
26 X(viscosity_liq) \
27 X(viscosity_vap) \
28 X(conductivity_liq) \
29 X(conductivity_vap) \
30 X(speed_sound_vap)
31
32namespace CoolProp {
33
38{
39 public:
40 bool TypeI;
41 bool built;
42 bool closed;
43 std::size_t iTsat_max,
46
47// Use X macros to auto-generate the variables;
48// each will look something like: std::vector<double> T;
49#define X(name) std::vector<double> name;
51#undef X
52
53// Use X macros to auto-generate the variables;
54// each will look something like: std::vector<std::vector<double> > K;
55#define X(name) std::vector<std::vector<double>> name;
57#undef X
58
59 PhaseEnvelopeData() : TypeI(false), built(false), closed(false), iTsat_max(-1), ipsat_max(-1), icrit(-1) {}
60
61 void resize(std::size_t N) {
62 K.resize(N);
63 lnK.resize(N);
64 x.resize(N);
65 y.resize(N);
66 }
67 void clear() {
68/* Use X macros to auto-generate the clearing code; each will look something like: T.clear(); */
69#define X(name) name.clear();
71#undef X
72#define X(name) name.clear();
74#undef X
75 }
76 void insert_variables(const CoolPropDbl T, const CoolPropDbl p, const CoolPropDbl rhomolar_liq, const CoolPropDbl rhomolar_vap,
77 const CoolPropDbl hmolar_liq, const CoolPropDbl hmolar_vap, const CoolPropDbl smolar_liq, const CoolPropDbl smolar_vap,
78 const std::vector<CoolPropDbl>& x, const std::vector<CoolPropDbl>& y, std::size_t i) {
79 std::size_t N = K.size();
80 if (N == 0) {
81 throw CoolProp::ValueError("Cannot insert variables in phase envelope since resize() function has not been called");
82 }
83 this->p.insert(this->p.begin() + i, p);
84 this->T.insert(this->T.begin() + i, T);
85 this->lnT.insert(this->lnT.begin() + i, log(T));
86 this->lnp.insert(this->lnp.begin() + i, log(p));
87 this->rhomolar_liq.insert(this->rhomolar_liq.begin() + i, rhomolar_liq);
88 this->rhomolar_vap.insert(this->rhomolar_vap.begin() + i, rhomolar_vap);
89 this->hmolar_liq.insert(this->hmolar_liq.begin() + i, hmolar_liq);
90 this->hmolar_vap.insert(this->hmolar_vap.begin() + i, hmolar_vap);
91 this->smolar_liq.insert(this->smolar_liq.begin() + i, smolar_liq);
92 this->smolar_vap.insert(this->smolar_vap.begin() + i, smolar_vap);
93 this->lnrhomolar_liq.insert(this->lnrhomolar_liq.begin() + i, log(rhomolar_liq));
94 this->lnrhomolar_vap.insert(this->lnrhomolar_vap.begin() + i, log(rhomolar_vap));
95 for (unsigned int j = 0; j < N; j++) {
96 this->K[j].insert(this->K[j].begin() + i, y[j] / x[j]);
97 this->lnK[j].insert(this->lnK[j].begin() + i, log(y[j] / x[j]));
98 this->x[j].insert(this->x[j].begin() + i, x[j]);
99 this->y[j].insert(this->y[j].begin() + i, y[j]);
100 }
101 if (rhomolar_liq > rhomolar_vap) {
102 this->Q.insert(this->Q.begin() + i, 1);
103 } else {
104 this->Q.insert(this->Q.begin() + i, 0);
105 }
106 };
107 void store_variables(const CoolPropDbl T, const CoolPropDbl p, const CoolPropDbl rhomolar_liq, const CoolPropDbl rhomolar_vap,
108 const CoolPropDbl hmolar_liq, const CoolPropDbl hmolar_vap, const CoolPropDbl smolar_liq, const CoolPropDbl smolar_vap,
109 const std::vector<CoolPropDbl>& x, const std::vector<CoolPropDbl>& y) {
110 std::size_t N = K.size();
111 if (N == 0) {
112 throw CoolProp::ValueError("Cannot store variables in phase envelope since resize() function has not been called");
113 }
114 this->p.push_back(p);
115 this->T.push_back(T);
116 this->lnT.push_back(log(T));
117 this->lnp.push_back(log(p));
118 this->rhomolar_liq.push_back(rhomolar_liq);
119 this->rhomolar_vap.push_back(rhomolar_vap);
120 this->hmolar_liq.push_back(hmolar_liq);
121 this->hmolar_vap.push_back(hmolar_vap);
122 this->smolar_liq.push_back(smolar_liq);
123 this->smolar_vap.push_back(smolar_vap);
124 this->lnrhomolar_liq.push_back(log(rhomolar_liq));
125 this->lnrhomolar_vap.push_back(log(rhomolar_vap));
126 for (unsigned int i = 0; i < N; i++) {
127 this->K[i].push_back(y[i] / x[i]);
128 this->lnK[i].push_back(log(y[i] / x[i]));
129 this->x[i].push_back(x[i]);
130 this->y[i].push_back(y[i]);
131 }
132 if (rhomolar_liq > rhomolar_vap) {
133 this->Q.push_back(1);
134 } else {
135 this->Q.push_back(0);
136 }
137 };
138};
139
140} /* namespace CoolProp */
141
142#endif