CoolProp
IncompressibleFluid.h
1 /*
2  * CoolPropFluid.h
3  *
4  * Created on: 20 Dec 2013
5  * Author: jowr
6  */
7 
8 #ifndef INCOMPRESSIBLEFLUID_H_
9 #define INCOMPRESSIBLEFLUID_H_
10 
11 #include "DataStructures.h"
12 #include "Helmholtz.h"
13 #include "Solvers.h"
14 
15 #include <numeric>
16 #include <string>
17 #include <vector>
18 #include <map>
19 #include <cassert>
20 #include <iterator>
21 
22 #include <Eigen/Core>
23 #include "PolyMath.h"
24 #include "MatrixMath.h"
25 
26 namespace CoolProp {
27 
29  enum IncompressibleTypeEnum {
30  INCOMPRESSIBLE_NOT_SET,
31  INCOMPRESSIBLE_POLYNOMIAL,
32  INCOMPRESSIBLE_EXPPOLYNOMIAL,
33  INCOMPRESSIBLE_EXPONENTIAL,
34  INCOMPRESSIBLE_LOGEXPONENTIAL,
35  INCOMPRESSIBLE_POLYOFFSET
36  };
37  IncompressibleTypeEnum type;
38  Eigen::MatrixXd coeffs; //TODO: Can we store the Eigen::Matrix objects more efficiently?
39  //std::vector<std::vector<double> > coeffs;
41  type = INCOMPRESSIBLE_NOT_SET;
42  };
43 };
44 
46 
50 
51 protected:
52  bool strict;
53 
54  std::string name;
55  std::string description;
56  std::string reference;
57 
58  double Tmin, Tmax;
59  double xmin, xmax;
61 
62  double TminPsat;
63  double xbase, Tbase;
64 
66 
75 
81 
88 
93 
98 
103 
107 
109 
114 
119 
123 
124 
125  Polynomial2DFrac poly;
126 
127  // Forward declaration of the some internal functions
128  //double h_u(double T, double p, double x);
129  //double u_h(double T, double p, double x);
130 
131 public:
132  IncompressibleFluid() : Tmin(_HUGE), Tmax(_HUGE), xmin(_HUGE), xmax(_HUGE), TminPsat(_HUGE), xbase(_HUGE), Tbase(_HUGE)
133  {strict = true; xid = IFRAC_UNDEFINED;};
134  virtual ~IncompressibleFluid(){};
135 
136  std::string getName() const {return name;}
137  std::string get_name() const {return getName();}// For backwards-compatibility.
138  std::string getDescription() const {return description;}
139  std::string getReference() const {return reference;}
140 
141  double getTmax() const {return Tmax;}
142  double getTmin() const {return Tmin;}
143  double getxmax() const {return xmax;}
144  double getxmin() const {return xmin;}
145  composition_types getxid() const {return xid;}
146  double getTminPsat() const {return TminPsat;}
147  double getTbase() const {return Tbase;}
148  double getxbase() const {return xbase;}
149 
150  void setName(const std::string &name) {this->name = name;}
151  void setDescription(const std::string &description) {this->description = description;}
152  void setReference(const std::string &reference) {this->reference = reference;}
153  void setTmax(double Tmax) {this->Tmax = Tmax;}
154  void setTmin(double Tmin) {this->Tmin = Tmin;}
155  void setxmax(double xmax) {this->xmax = xmax;}
156  void setxmin(double xmin) {this->xmin = xmin;}
157  void setxid(composition_types xid) {this->xid = xid;}
158  void setTminPsat(double TminPsat) {this->TminPsat = TminPsat;}
159  void setTbase(double Tbase) {this->Tbase = Tbase;}
160  void setxbase(double xbase) {this->xbase = xbase;}
161 
163  void setDensity(IncompressibleData density){this->density = density;}
164  void setSpecificHeat(IncompressibleData specific_heat){this->specific_heat = specific_heat;}
165  void setViscosity(IncompressibleData viscosity){this->viscosity = viscosity;}
166  void setConductivity(IncompressibleData conductivity){this->conductivity = conductivity;}
167  void setPsat(IncompressibleData p_sat){this->p_sat = p_sat;}
168  void setTfreeze(IncompressibleData T_freeze){this->T_freeze = T_freeze;}
169 
171  void setMass2input(IncompressibleData mass2input){this->mass2input = mass2input;}
172  void setVolume2input(IncompressibleData volume2input){this->volume2input = volume2input;}
173  void setMole2input(IncompressibleData mole2input){this->mole2input = mole2input;}
174 
176  void validate();
178  bool is_pure();
179 
180 
181 protected:
183  double baseExponential(IncompressibleData data, double y, double ybase);
184  double baseLogexponential(IncompressibleData data, double y, double ybase);
185  double baseExponentialOffset(IncompressibleData data, double y);
186  double basePolyOffset(IncompressibleData data, double y, double z=0.0);
187 
188 public:
189 
190  /* All functions need T and p as input. Might not
191  * be necessary, but gives a clearer structure.
192  */
194  double rho (double T, double p, double x);
196  double c (double T, double p, double x);
197  double cp (double T, double p, double x){throw ValueError(format("%s (%d): Please use the c-function instead.",__FILE__,__LINE__));}
198  double cv (double T, double p, double x){throw ValueError(format("%s (%d): Please use the c-function instead.",__FILE__,__LINE__));}
200  double s (double T, double p, double x){throw ValueError(format("%s (%d): The internal calculations have changed, use the backend to calculate entropy from the partial derivatives.",__FILE__,__LINE__));}
202  double u (double T, double p, double x){throw ValueError(format("%s (%d): The internal calculations have changed, use the backend to calculate internal energy from enthalpy.",__FILE__,__LINE__));}
204  double h (double T, double p, double x){throw ValueError(format("%s (%d): The internal calculations have changed, use the backend to calculate enthalpy from the partial derivatives.",__FILE__,__LINE__));}
206  double visc(double T, double p, double x);
208  double cond(double T, double p, double x);
210  double psat(double T, double x);
212  double Tfreeze( double p, double x);
213 
214  /* Below are direct calculations of the derivatives. Nothing
215  * special is going on, we simply use the polynomial class to
216  * derive the different functions with respect to temperature.
217  */
219  // with respect to temperature at constant pressure and composition
220  double drhodTatPx(double T, double p, double x);
223  //double dsdTatPx (double T, double p, double x){return c(T,p,x)/T;};
226  //double dhdTatPx (double T, double p, double x){return c(T,p,x);};
228  // with respect to temperature at constant pressure and composition
229  // integrated in temperature
230  double dsdTatPxdT(double T, double p, double x);
232  // with respect to temperature at constant pressure and composition
233  // integrated in temperature
234  double dhdTatPxdT(double T, double p, double x);
235 
236 
238 
240  double inputFromMass (double T, double x);
242 
244  double inputFromVolume (double T, double x);
246 
248  double inputFromMole (double T, double x);
249 
250 
251  /* Some functions can be inverted directly, those are listed
252  * here. It is also possible to solve for other quantities, but
253  * that involves some more sophisticated processing and is not
254  * done here, but in the backend, T(h,p) for example.
255  */
257  double T_rho (double Dmass, double p, double x);
259  double T_c (double Cmass, double p, double x);
261  double T_s (double Smass, double p, double x){throw NotImplementedError(format("%s (%d): T from entropy is not implemented in the fluid, use the backend.",__FILE__,__LINE__));}
263  double T_u (double Umass, double p, double x){throw NotImplementedError(format("%s (%d): T from internal energy is not implemented in the fluid, use the backend.",__FILE__,__LINE__));}
265  double T_h (double Hmass, double p, double x){throw NotImplementedError(format("%s (%d): T from enthalpy is not implemented in the fluid, use the backend.",__FILE__,__LINE__));}
267  double T_visc(double visc, double p, double x){throw NotImplementedError(format("%s (%d): T from viscosity is not implemented.",__FILE__,__LINE__));}
269  double T_cond(double cond, double p, double x){throw NotImplementedError(format("%s (%d): T from conductivity is not implemented.",__FILE__,__LINE__));}
271  double T_psat(double psat, double x){throw NotImplementedError(format("%s (%d): T from psat is not implemented.",__FILE__,__LINE__));}
273  double x_Tfreeze( double Tfreeze, double p){throw NotImplementedError(format("%s (%d): x from T_freeze is not implemented.",__FILE__,__LINE__));}
274 
275 
276 protected:
277 
278  /* Define internal energy and enthalpy as functions of the
279  * other properties to provide data in case there are no
280  * coefficients.
281  */
283 
286  double h_u(double T, double p, double x) {
287  return u(T,p,x)+p/rho(T,p,x);
288  };
289 
291 
294  double u_h(double T, double p, double x) {
295  return h(T,p,x)-p/rho(T,p,x);
296  };
297 
298 
299  /*
300  * Some more functions to provide a single implementation
301  * of important routines.
302  * We start with the check functions that can validate input
303  * in terms of pressure p, temperature T and composition x.
304  */
306 
309  bool checkT(double T, double p, double x);
310 
312 
318  bool checkP(double T, double p, double x);
319 
320 public:
322 
325  bool checkX(double x);
326 
328  bool checkTPX(double T, double p, double x){
329  return (checkT(T,p,x) && checkP(T,p,x) && checkX(x));
330  };
331 };
332 
333 } /* namespace CoolProp */
334 #endif /* INCOMPRESSIBLEFLUID_H_ */
IncompressibleData p_sat
Saturation pressure coefficients.
Definition: IncompressibleFluid.h:101
double s(double T, double p, double x)
Entropy as a function of temperature, pressure and composition.
Definition: IncompressibleFluid.h:200
double T_cond(double cond, double p, double x)
Thermal conductivity as a function of temperature, pressure and composition.
Definition: IncompressibleFluid.h:269
IncompressibleData conductivity
Conductivity coefficients.
Definition: IncompressibleFluid.h:96
double T_u(double Umass, double p, double x)
Temperature as a function of internal energy as a function of temperature, pressure and composition...
Definition: IncompressibleFluid.h:263
void setDensity(IncompressibleData density)
Setters for the coefficients.
Definition: IncompressibleFluid.h:163
double T_psat(double psat, double x)
Saturation pressure as a function of temperature and composition.
Definition: IncompressibleFluid.h:271
void setMass2input(IncompressibleData mass2input)
Setters for the concentration conversion coefficients.
Definition: IncompressibleFluid.h:171
A property provider for incompressible solutions and pure fluids.
Definition: IncompressibleFluid.h:49
double x_Tfreeze(double Tfreeze, double p)
Composition as a function of freezing temperature and pressure.
Definition: IncompressibleFluid.h:273
A class for polynomials starting at an arbitrary degree.
Definition: PolyMath.h:206
double T_visc(double visc, double p, double x)
Viscosity as a function of temperature, pressure and composition.
Definition: IncompressibleFluid.h:267
Definition: IncompressibleFluid.h:28
composition_types
These are constants for the compositions.
Definition: DataStructures.h:209
bool checkTPX(double T, double p, double x)
Check validity of temperature, pressure and composition input.
Definition: IncompressibleFluid.h:328
double T_h(double Hmass, double p, double x)
Temperature as a function of enthalpy, pressure and composition.
Definition: IncompressibleFluid.h:265
double u_h(double T, double p, double x)
Internal energy from h, p and rho.
Definition: IncompressibleFluid.h:294
Definition: Exceptions.h:26
IncompressibleData mole2input
Mole fraction conversion coefficients.
Definition: IncompressibleFluid.h:122
double T_s(double Smass, double p, double x)
Temperature as a function of entropy as a function of temperature, pressure and composition.
Definition: IncompressibleFluid.h:261
double h_u(double T, double p, double x)
Enthalpy from u, p and rho.
Definition: IncompressibleFluid.h:286
IncompressibleData viscosity
Viscosity coefficients.
Definition: IncompressibleFluid.h:91
double h(double T, double p, double x)
Enthalpy as a function of temperature, pressure and composition.
Definition: IncompressibleFluid.h:204
IncompressibleData specific_heat
Specific heat coefficients.
Definition: IncompressibleFluid.h:86
IncompressibleData volume2input
Volume fraction conversion coefficients.
Definition: IncompressibleFluid.h:117
This file contains flash routines in which the state is unknown, and a solver of some kind must be us...
Definition: AbstractState.h:19
double u(double T, double p, double x)
Internal energy as a function of temperature, pressure and composition.
Definition: IncompressibleFluid.h:202
IncompressibleData T_freeze
Freezing temperature coefficients.
Definition: IncompressibleFluid.h:106
IncompressibleData density
These are the objects that hold the coefficients.
Definition: IncompressibleFluid.h:79
IncompressibleData mass2input
Mass fraction conversion coefficients.
Definition: IncompressibleFluid.h:112