CoolProp
Ancillaries.h
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;
30  CoolPropDbl Tc;
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  };
46  CoolPropDbl evaluate(CoolPropDbl T) {
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  {
92  CoolPropDbl max_abs_error;
93  struct
94  { // For TYPE_NOT_EXPONENTIAL & TYPE_EXPONENTIAL
95  bool using_tau_r;
96  CoolPropDbl reducing_value,
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 
126  CoolPropDbl get_max_abs_error() {
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 {
161  CoolPropDbl T_0, a, c, p_0, T_max, T_min, p_min, p_max;
162 };
164 {
165  std::vector<MeltingLinePiecewiseSimonSegment> parts;
166 };
167 
176 {
177  public:
178  std::vector<CoolPropDbl> a, t;
179  CoolPropDbl T_0, p_0, T_max, T_min, p_min, p_max;
180  CoolPropDbl evaluate(CoolPropDbl 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;
204  CoolPropDbl T_0, p_0, T_max, T_min, p_min, p_max;
205 
206  CoolPropDbl evaluate(CoolPropDbl T) {
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  {
224  MELTING_LINE_NOT_SET = 0,
228  };
229  CoolPropDbl Tmin,
230  Tmax,
231  pmin,
232  pmax;
233 
234  std::string BibTeX;
235  CoolPropDbl T_m;
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
CoolPropDbl Tmin
Minimum temperature in K.
Definition: Ancillaries.h:229
Definition: Ancillaries.h:159
CoolPropDbl T_r
The temperature in K used to reduce the temperature (usually the critical temperature) ...
Definition: Ancillaries.h:96
std::size_t N
number of a_i, n_i pairs
Definition: Ancillaries.h:31
a polynomial in is in use
Definition: Ancillaries.h:227
This is generalized class that can be used to manage an ancillary curve, here they are ancillary curv...
Definition: Ancillaries.h:84
CoolPropDbl max_abs_error
For TYPE_RATIONAL_POLYNOMIAL.
Definition: Ancillaries.h:92
The surface tension correlation class uses correlations for the surface tension that are all of the f...
Definition: Ancillaries.h:24
CoolPropDbl get_max_abs_error()
Get the maximum absolute error for this fit.
Definition: Ancillaries.h:126
int type
The data needed for a melting curve formed of segments that are polynomials in .
Definition: Ancillaries.h:241
Definition: Ancillaries.h:219
bool enabled(void)
Return true if the ancillary is enabled (type is not TYPE_NOT_SET)
Definition: Ancillaries.h:120
std::vector< CoolPropDbl > s
a summation buffer
Definition: Ancillaries.h:27
bool using_tau_r
Whether the term is included in the.
Definition: Ancillaries.h:95
std::vector< CoolPropDbl > a
the leading coefficients a_i
Definition: Ancillaries.h:27
MeltingLineVariablesEnum
Definition: Ancillaries.h:222
double get_Tmin(void)
Get the minimum temperature in K.
Definition: Ancillaries.h:143
Definition: Ancillaries.h:163
Definition: Exceptions.h:45
std::vector< CoolPropDbl > n
the powers n_i
Definition: Ancillaries.h:27
std::string BibTeX
BibTeX key for the melting curve in use.
Definition: Ancillaries.h:234
The evaluator class for a melting curve formed of segments in the form.
Definition: Ancillaries.h:175
CoolPropDbl T_m
Melting temperature at 1 atmosphere.
Definition: Ancillaries.h:235
A simon-type curve is in use.
Definition: Ancillaries.h:225
double get_Tmax(void)
Get the maximum temperature in K.
Definition: Ancillaries.h:148
MeltingLinePiecewisePolynomialInTrData polynomial_in_Tr
The data used for a Simon-style curve.
Definition: Ancillaries.h:238
std::size_t N
The number of values in the arrays.
Definition: Ancillaries.h:98
The evaluator class for a melting curve formed of segments in the form.
Definition: Ancillaries.h:200
CoolPropDbl evaluate(CoolPropDbl T)
Actually evaluate the surface tension equation.
Definition: Ancillaries.h:46
std::string BibTeX
The BiBTeX key for the surface tension curve in use.
Definition: Ancillaries.h:32
MeltingLinePiecewisePolynomialInThetaData polynomial_in_Theta
The data needed for a melting curve formed of segments that are polynomials in .
Definition: Ancillaries.h:240
CoolPropDbl Tc
critical temperature in K
Definition: Ancillaries.h:30
This file contains flash routines in which the state is unknown, and a solver of some kind must be us...
Definition: AbstractState.h:19
bool enabled()
Return true if the ancillary is enabled (type is not the default value of MELTING_LINE_NOT_SET) ...
Definition: Ancillaries.h:257
a polynomial in is in use
Definition: Ancillaries.h:226