In [1]: import CoolProp as CP
In [2]: print CP.__version__
4.2.5
In [3]: print CP.__gitrevision__
7fd51d2f3821338fb4c27d2cd1ffad52d3efc23e
#Import the things you need
In [4]: from CoolProp.CoolProp import Props
In [5]: import timeit
#Specific heat (kJ/kg/K) of 20% ethylene glycol as a function of T
In [6]: Props('C','T',298.15,'P',101.325,'EG-20%')
Out[6]: 3.9052706242925868
#Density of Air at standard atmosphere in kg/m^3
In [7]: Props('D','T',298.15,'P',101.325,'Air')
Out[7]: 1.1843184839089664
#Saturation temperature of Water at 1 atm
In [8]: Props('T','P',101.325,'Q',0,'Water')
Out[8]: 373.12429584768677
#Saturated vapor density of R134a at 0C
In [9]: Props('H','T',273.15,'Q',1,'R134a')
Out[9]: 398.60345362765497
#Using properties from REFPROP to get R410A density
In [10]: Props('D','T',300,'P',100,'REFPROP-MIX:R32[0.697615]&R125[0.302385]')
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-10-d10cd21b2630> in <module>()
----> 1 Props('D','T',300,'P',100,'REFPROP-MIX:R32[0.697615]&R125[0.302385]')
C:\Miniconda\envs\coolpropv4docs\lib\site-packages\CoolProp\CoolProp.pyd in CoolProp.CoolProp.Props (build\temp.win-amd64-2.7\Release\pyrex\CoolProp\CoolProp.cpp:10955)()
C:\Miniconda\envs\coolpropv4docs\lib\site-packages\CoolProp\CoolProp.pyd in CoolProp.CoolProp.Props (build\temp.win-amd64-2.7\Release\pyrex\CoolProp\CoolProp.cpp:10350)()
C:\Miniconda\envs\coolpropv4docs\lib\site-packages\CoolProp\CoolProp.pyd in CoolProp.CoolProp.__Props_err2 (build\temp.win-amd64-2.7\Release\pyrex\CoolProp\CoolProp.cpp:9875)()
ValueError: CoolProp error: REFPROP: The REFPROP DLL you are using has expired (Dec. 30, 2014). Please return to the Refprop website and download the latest. 37709.56631258091, "pmax": 60000000.0, "rho_hsatVmax": 276.8708342196202, "s_hsatVmax": 156.117608199971`l :: inputs were:"D","T",3.0000000000000000e+02,"P",1.0000000000000000e+02,"REFPROP-MIX:R32[0.697615]&R125[0.302385]"
#Check that the same as using pseudo-pure
In [11]: Props('D','T',300,'P',100,'R410A')
Out[11]: 2.947304301269727
The documentation of the CoolProp.CoolProp module, or the CoolProp.State module are also available.
Nearly all the fluids modeling in CoolProp are based on Helmholtz energy formulations. This is a convenient construction of the equation of state because all the thermodynamic properties of interest can be obtained directly from partial derivatives of the Helmholtz energy.
It should be noted that the EOS are typically valid over the entire range of the fluid, from subcooled liquid to superheated vapor, to supercritical fluid.
Annoyingly, different authors have selected different sets of nomenclature for the Helmholtz energy. For consistency, the nomenclature of Lemmon will be used here. Also, some authors present results on a mole-basis or mass-basis, further complicating comparisons.
In general, the EOS are based on non-dimensional terms δ and τ, where these terms are defined by
where ρc and Tc are the critical density of the fluid if it is a pure fluid. For pseudo-pure mixtures, the critical point is typically not used as the reducing state point, and often the maximum condensing temperature on the saturation curve is used instead.
The non-dimensional Helmholtz energy of the fluid is given by
where α0 is the ideal-gas contribution to the Helmholtz energy, and αr is the residual Helmholtz energy contribution which accounts for non-ideal behavior. For a given set of δ and τ, each of the terms α0 and αr are known. The exact form of the Helmholtz energy terms is fluid dependent, but a relatively simple example is that of Nitrogen, which has the ideal-gas Helmholtz energy of
and the non-dimensional residual Helmholtz energy of
and all the terms other than δ and τ are fluid-dependent correlation parameters.
The other thermodynamic parameters can then be obtained through analytic derivatives of the Helmholtz energy terms. For instance, the pressure is given by
and the specific internal energy by
and the specific enthalpy by
which can also be written as
The specific entropy is given by
and the specific heats at constant volume and constant pressure respectively are given by
The EOS is set up with temperature and density as the two independent properties, but often other inputs are known, most often temperature and pressure because they can be directly measured. As a result, if the density is desired for a known temperature and pressure, it can be obtained iteratively. The following algorithm is used to obtain a reasonable guess for the initial value for the iterative solver:
If the fluid is somewhere in the two-phase region, or saturation state properties are desired, saturated liquid and vapor properties can be obtained. At equilibrium, the Gibbs function of the liquid and vapor are equal, as are the pressures of the saturated liquid and vapor. For nearly all pure fluids, ancillary equations for the density of saturated liquid and saturated vapor as a function of temperature are provided, given by ρ′ and ρ″ respectively. Thus for pure fluids, for a given temperature, initial guesses for the densities of saturated liquid and vapor are given by \rho' and \rho''. Using one of the densities, a guess for the saturation pressure can be obtained. Then, the saturation pressure is iteratively altered using a numerical method. For each saturation pressure, the saturated liquid and vapor densities are updated using the full EOS to match the imposed temperature and guessed pressure. Because the density is known explicitly from the EOS, Newton’s method can be used to update the densities. For Newton’s method, the derivative \partial \rho/\partial p is needed, which can be given explicitly as
and the value for \rho is updated by employing
until \left|p(T,\rho_{old})-p_{guess}\right| is sufficiently small. Then the numerical method calculates the Gibbs function for saturated liquid and saturated vapor, and uses the difference in Gibbs functions to update the guess for the saturation pressure. Then the densities are calculated again. At convergence, the set of \rho', \rho'', and p_{sat} are known for a given saturation temperature. If the fluid is not a pure fluid, the best that you can do is to use the ancillary equations to calculate the saturation densities and saturation pressure.
As you might imagine, doing all this work to calculate the saturation state for pure fluids is computationally very expensive, so a lookup table method has been implemented for the saturation densities and saturation pressure. From Python, you can turn on the saturation lookup table with:
UseSaturationLUT(True)
or use the full EOS by calling:
UseSaturationLUT(False)
As a reminder, the EOS is typically set up as a function of \tau=T_c/T and \delta=\rho/\rho_c. Thus, if you know pressure and enthalpy, you can set up a system of residuals in terms of \delta and \tau in order to yield back the given pressure and enthalpy. Of course you still need a good guess value to start from. See below for that. The system of equations can be given by:
where the partials can be given by
and the jacobian is then
For a limited selection of fluids, correlations are provided for the viscosity and the thermal conductivity. But for many fluids, no correlations are available, and therefore other methods must be employed. The extended corresponding states is a method of estimating the transport properties of a fluid by analogy with the transport properties of a fluid that are well defined.
Implementing the ECS method is quite a challenge, but CoolProp is one of the only fluid property databases that properly implements it. And the onlyopen-source package that does. A multi-step method is required, which is hopefully clearly laid out here.
To begin with, the reference fluid must be selected that the fluid of interest will be compared with. Ideally the shape of the molecules should be similar, but in practice, most fluids use R134a as the reference fluid since its thermodynamic and transport properties are well quantified with reference-quality correlations.
Once the reference fluid has been selected, the conformal state of the reference fluid must be determined. The conformal state is the state at which the transport properties of the reference fluid and the fluid of interest are (in theory) the same. In practice, at low densities the shape factors are assumed to be unity, and the conformal temperature and molar density are obtained from
Exact solution for the conformal temperature
If you have Helmholtz EOS for both the fluid and the reference fluid, you need to find a conformal temperature for the reference fluid that will yield the same compressibility factor and the residual Helmholtz energy
where “j” is for the fluid of interest, and the subscript “0” is for the reference fluid. The left side of each equation is already known from the equation of state. Literature suggests that solving for T_0 and \rho_0 directly is quite challenging. See McLinden 2000 or Klein 1997.
Alternatively, if the shape factors \theta and \phi are known, either from correlation or otherwise, the conformal temperature and density can be calculated directly.
Much of the time the coefficients for the ideal-gas part of the Helmholtz energy are given directly, but sometimes only the gas-specific heat is provided. Therefore you need to be able to go from specific heat to ideal-gas Helmholtz Energy. The ideal-gas Helmholtz energy is given by Equation 23 from Lemmon, 2004, Equations of State for Mixtures of R-32, R-125, R-134a, R-143a, and R-152a, J. Phys. Chem. Ref. Data, Vol. 33, No. 2, 2004 or
non-dimensionalizing
Now we might want to do a change of variable in the integrals. If so, do a u-substitution in the integrals.
where
Simplifying and factoring the \tau term yields
which finally yields the solution as of Equation 3 from Lemmon, 2003 (and others)
The specific-heat contribution can then be taken as a sum of the contributions
for a term of the form
the contribution is found from
Factor out a B, First two terms cancel, leaving
or in terms of \tau
for a term of the form
the contribution is found from
or in terms of \tau
for a term of the form
the contribution is found from
or in terms of \tau
These terms can be summarized by the following table:
If the reference enthalpy is known, you can determine the constants from
For the specific heat The two integral terms are
First derivative
Second Derivative
If the EOS is of the form
To convert to standard power form in CoolProp, use
The left-hand-side is the derivative of the residual Helmholtz energy with respect to delta times the reduced density since
where
In the Bender EOS, for the exponential part you have terms that can be converted to reduced form
which yields the terms in the following table (from Span, 2000)
Warning
If the terms in the EOS are in terms of T and \rho rather than \tau and \delta, make sure to multiply appropriately by the critical densities in the exponential term. For instance in Polt paper, the first constant should be n_{14}\rho_c^2/(2\gamma)+n_{17}\rho_c^4/(2\gamma^2)/T_c^3 Be careful!