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  {
37  a = cpjson::get_long_double_array(json_code["a"]);
38  n = cpjson::get_long_double_array(json_code["n"]);
39 
40  Tc = cpjson::get_double(json_code,"Tc");
41  BibTeX = cpjson::get_string(json_code,"BibTeX");
42 
43  this->N = n.size();
44  s = n;
45  };
47  CoolPropDbl evaluate(CoolPropDbl T)
48  {
49  if (a.empty()){ throw NotImplementedError(format("surface tension curve not provided"));}
50  if (T > Tc) { throw ValueError(format("Must be saturated state : T <= Tc")); }
51  CoolPropDbl THETA = 1-T/Tc;
52  for (std::size_t i = 0; i < N; ++i)
53  {
54  s[i] = a[i]*pow(THETA, n[i]);
55  }
56  return std::accumulate(s.begin(), s.end(), 0.0);
57  }
58 };
84 {
85 private:
86  Eigen::MatrixXd num_coeffs,
87  den_coeffs;
88  std::vector<double> n, t, s; // For TYPE_NOT_EXPONENTIAL & TYPE_EXPONENTIAL
89  union{
90  CoolPropDbl max_abs_error;
91  struct{ // For TYPE_NOT_EXPONENTIAL & TYPE_EXPONENTIAL
92  bool using_tau_r;
93  CoolPropDbl reducing_value,
94  T_r;
95  std::size_t N;
96  };
97  };
98  CoolPropDbl Tmax,
99  Tmin;
100  enum ancillaryfunctiontypes{TYPE_NOT_SET = 0,
101  TYPE_NOT_EXPONENTIAL,
102  TYPE_EXPONENTIAL,
103  TYPE_RATIONAL_POLYNOMIAL
104  };
105  ancillaryfunctiontypes type;
106 public:
107 
108  SaturationAncillaryFunction(){type = TYPE_NOT_SET; Tmin = _HUGE; Tmax = _HUGE;};
109  SaturationAncillaryFunction(rapidjson::Value &json_code);
110 
112  bool enabled(void){return type != TYPE_NOT_SET;}
113 
116  CoolPropDbl get_max_abs_error(){return max_abs_error;};
117 
121  double evaluate(double T);
122 
128  double invert(double value, double min_bound = -1, double max_bound = -1);
129 
131  double get_Tmin(void){return Tmin;};
132 
134  double get_Tmax(void){return Tmax;};
135 };
136 
137 // ****************************************************************************
138 // ****************************************************************************
139 // MELTING LINE
140 // ****************************************************************************
141 // ****************************************************************************
142 
144 {
145  CoolPropDbl T_0, a, c, p_0, T_max, T_min, p_min, p_max;
146 };
148 {
149  std::vector<MeltingLinePiecewiseSimonSegment> parts;
150 };
151 
160 {
161 public:
162  std::vector<CoolPropDbl> a, t;
163  CoolPropDbl T_0, p_0, T_max, T_min, p_min, p_max;
164  CoolPropDbl evaluate(CoolPropDbl T)
165  {
166  CoolPropDbl summer = 0;
167  for (std::size_t i = 0; i < a.size(); ++i){
168  summer += a[i]*(pow(T/T_0,t[i])-1);
169  }
170  return p_0*(1+summer);
171  }
172 };
174 {
175  std::vector<MeltingLinePiecewisePolynomialInTrSegment> parts;
176 };
177 
186 {
187 public:
188  std::vector<CoolPropDbl> a, t;
189  CoolPropDbl T_0, p_0, T_max, T_min, p_min, p_max;
190 
191  CoolPropDbl evaluate(CoolPropDbl T)
192  {
193  CoolPropDbl summer = 0;
194  for (std::size_t i =0; i < a.size(); ++i){
195  summer += a[i]*pow(T/T_0-1,t[i]);
196  }
197  return p_0*(1+summer);
198  }
199 };
201 {
202  std::vector<MeltingLinePiecewisePolynomialInThetaSegment> parts;
203 };
204 
206 {
207 public:
209  MELTING_LINE_NOT_SET = 0,
213  };
214  CoolPropDbl Tmin,
215  Tmax,
216  pmin,
217  pmax;
218 
219  std::string BibTeX;
220  CoolPropDbl T_m;
224  int type;
225 
226  MeltingLineVariables() :Tmin(_HUGE), Tmax(_HUGE), pmin(_HUGE), pmax(_HUGE), T_m(_HUGE), type(MELTING_LINE_NOT_SET){};
227 
234  CoolPropDbl evaluate(int OF, int GIVEN, CoolPropDbl value);
235 
237  void set_limits();
238 
240  bool enabled(){return type != MELTING_LINE_NOT_SET;};
241 };
242 
243 } /* namespace CoolProp */
244 #endif
CoolPropDbl Tmin
Minimum temperature in K.
Definition: Ancillaries.h:214
Definition: Ancillaries.h:143
CoolPropDbl T_r
The temperature in K used to reduce the temperature (usually the critical temperature) ...
Definition: Ancillaries.h:93
std::size_t N
number of a_i, n_i pairs
Definition: Ancillaries.h:31
a polynomial in is in use
Definition: Ancillaries.h:212
This is generalized class that can be used to manage an ancillary curve, here they are ancillary curv...
Definition: Ancillaries.h:83
CoolPropDbl max_abs_error
For TYPE_RATIONAL_POLYNOMIAL.
Definition: Ancillaries.h:90
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:116
int type
The data needed for a melting curve formed of segments that are polynomials in .
Definition: Ancillaries.h:224
Definition: Ancillaries.h:205
bool enabled(void)
Return true if the ancillary is enabled (type is not TYPE_NOT_SET)
Definition: Ancillaries.h:112
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:92
std::vector< CoolPropDbl > a
the leading coefficients a_i
Definition: Ancillaries.h:27
MeltingLineVariablesEnum
Definition: Ancillaries.h:208
double get_Tmin(void)
Get the minimum temperature in K.
Definition: Ancillaries.h:131
Definition: Ancillaries.h:147
Definition: Exceptions.h:26
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:219
The evaluator class for a melting curve formed of segments in the form.
Definition: Ancillaries.h:159
CoolPropDbl T_m
Melting temperature at 1 atmosphere.
Definition: Ancillaries.h:220
A simon-type curve is in use.
Definition: Ancillaries.h:210
double get_Tmax(void)
Get the maximum temperature in K.
Definition: Ancillaries.h:134
MeltingLinePiecewisePolynomialInTrData polynomial_in_Tr
The data used for a Simon-style curve.
Definition: Ancillaries.h:222
std::size_t N
The number of values in the arrays.
Definition: Ancillaries.h:95
The evaluator class for a melting curve formed of segments in the form.
Definition: Ancillaries.h:185
CoolPropDbl evaluate(CoolPropDbl T)
Actually evaluate the surface tension equation.
Definition: Ancillaries.h:47
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:223
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:240
a polynomial in is in use
Definition: Ancillaries.h:211