CoolProp  6.6.0
An open-source fluid property and humid air property database
Ancillaries.h
Go to the documentation of this file.
1 #ifndef ANCILLARIES_H
2 #define ANCILLARIES_H
3 
4 #include "Exceptions.h"
5 #include <vector>
6 #include "rapidjson_include.h"
7 #include "Eigen/Core"
8 #include "PolyMath.h"
9 
10 namespace CoolProp {
11 
25 {
26  public:
27  std::vector<CoolPropDbl> a,
28  n,
29  s;
31  std::size_t N;
32  std::string BibTeX;
33 
34  SurfaceTensionCorrelation() : Tc(_HUGE), N(0) {}
35  SurfaceTensionCorrelation(rapidjson::Value& json_code) {
36  a = cpjson::get_long_double_array(json_code["a"]);
37  n = cpjson::get_long_double_array(json_code["n"]);
38 
39  Tc = cpjson::get_double(json_code, "Tc");
40  BibTeX = cpjson::get_string(json_code, "BibTeX");
41 
42  this->N = n.size();
43  s = n;
44  };
47  if (a.empty()) {
48  throw NotImplementedError(format("surface tension curve not provided"));
49  }
50  if (T > Tc) {
51  throw ValueError(format("Must be saturated state : T <= Tc"));
52  }
53  CoolPropDbl THETA = 1 - T / Tc;
54  for (std::size_t i = 0; i < N; ++i) {
55  s[i] = a[i] * pow(THETA, n[i]);
56  }
57  return std::accumulate(s.begin(), s.end(), 0.0);
58  }
59 };
85 {
86  private:
87  Eigen::MatrixXd num_coeffs,
88  den_coeffs;
89  std::vector<double> n, t, s; // For TYPE_NOT_EXPONENTIAL & TYPE_EXPONENTIAL
90  union
91  {
93  struct
94  { // For TYPE_NOT_EXPONENTIAL & TYPE_EXPONENTIAL
95  bool using_tau_r;
97  T_r;
98  std::size_t N;
99  };
100  };
101  CoolPropDbl Tmax,
102  Tmin;
103  enum ancillaryfunctiontypes
104  {
105  TYPE_NOT_SET = 0,
106  TYPE_NOT_EXPONENTIAL,
107  TYPE_EXPONENTIAL,
108  TYPE_RATIONAL_POLYNOMIAL
109  };
110  ancillaryfunctiontypes type;
111  public:
113  type = TYPE_NOT_SET;
114  Tmin = _HUGE;
115  Tmax = _HUGE;
116  };
117  SaturationAncillaryFunction(rapidjson::Value& json_code);
118 
120  bool enabled(void) {
121  return type != TYPE_NOT_SET;
122  }
123 
127  return max_abs_error;
128  };
129 
133  double evaluate(double T);
134 
140  double invert(double value, double min_bound = -1, double max_bound = -1);
141 
143  double get_Tmin(void) {
144  return Tmin;
145  };
146 
148  double get_Tmax(void) {
149  return Tmax;
150  };
151 };
152 
153 // ****************************************************************************
154 // ****************************************************************************
155 // MELTING LINE
156 // ****************************************************************************
157 // ****************************************************************************
158 
160 {
162 };
164 {
165  std::vector<MeltingLinePiecewiseSimonSegment> parts;
166 };
167 
176 {
177  public:
178  std::vector<CoolPropDbl> a, t;
181  CoolPropDbl summer = 0;
182  for (std::size_t i = 0; i < a.size(); ++i) {
183  summer += a[i] * (pow(T / T_0, t[i]) - 1);
184  }
185  return p_0 * (1 + summer);
186  }
187 };
189 {
190  std::vector<MeltingLinePiecewisePolynomialInTrSegment> parts;
191 };
192 
201 {
202  public:
203  std::vector<CoolPropDbl> a, t;
205 
207  CoolPropDbl summer = 0;
208  for (std::size_t i = 0; i < a.size(); ++i) {
209  summer += a[i] * pow(T / T_0 - 1, t[i]);
210  }
211  return p_0 * (1 + summer);
212  }
213 };
215 {
216  std::vector<MeltingLinePiecewisePolynomialInThetaSegment> parts;
217 };
218 
220 {
221  public:
223  {
228  };
233 
234  std::string BibTeX;
241  int type;
242 
243  MeltingLineVariables() : Tmin(_HUGE), Tmax(_HUGE), pmin(_HUGE), pmax(_HUGE), T_m(_HUGE), type(MELTING_LINE_NOT_SET){};
244 
251  CoolPropDbl evaluate(int OF, int GIVEN, CoolPropDbl value);
252 
254  void set_limits();
255 
257  bool enabled() {
258  return type != MELTING_LINE_NOT_SET;
259  };
260 };
261 
262 } /* namespace CoolProp */
263 #endif