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