A Brief Introduction to Coolprop for Python

 In thermodynamics, we often need to find the thermodynamic properties of fluids or gases. It can be found from interpolation via some traditional charts and real ideal gas relationships. But, the process is tedious. Moreover, if we want to simulate any thermodynamic cycle via coding, we definitely will need some kind of digital library of these properties which can be easily accessible. 

In MATLAB there is a library called REFPROP. Like this REFPROP package there is a similar kind of open-source library called CoolProp. CoolProp is a C++ library that implements Pure and pseudo-pure fluid equations of state and transport properties for 122 components. It can be accessed in various programming languages.

In this blog implementation of CoolProp in the python programming language will be discussed.

It is to be mentioned that, CoolProp has two interfaces, high-level interface, and low-level interfaces. The former is for general use and the later is for advanced use. In this blog, only high level interface will be discussed.

Installation

To install CoolProp, pip or conda installer can be used. You will need visual studio if you don't have it in your system. The command line for pip installer is as follows

pip install CoolProp

Working with high level interface

PropsSI() Function

1. Vapor, Liquid and Saturated State (without mentioning):

Coolprop represents the state values in SI unit. To get the values first import the PropsSI function

 from CoolProp.CoolProp import PropsSI  

We know that, generally in order to fix a state, at least two properties of the state are necessary. Suppose, we want to get the temperature of liquid water at its saturated condition at 1 atm. So here the pressure is 101325Pa and the vapor quality is 0. So,two properties are known and the state is fixed.  From high school physics class we know that temperature at this state is 100 degree C or 373K. Now to get this temperature at this state from CoolProp, following code can be written:

 PropsSI('T','P',101325,'Q',0,'Water')  

which yields the result : 373.1242958476844

Notice that ,the format is, the unknown property is stated first, then two known properties with their values, and finally the fluid.

Lets look into another example. Suppose you want to know the density of water at this state. Then the code will be:

 PropsSI('D','P',101325,'Q',0,'Water')  

Which will yield the value : 958.3674968154652 kg/m3

In this link, you can find all the properties and their string format to be used inside the PropsSI function.

Also, in this link, you can find all the listed fluid and their string to be used in the PropsSI function.

2. Vapor, Liquid and Saturated State (by mentioning):

PropsSI works in iteration method and thereby determine the phase of the fluid. It takes the two known properties into account, initially guess in which phase the fluid can be, and then calculate the viability of the guess. So, if the initial guess isn't right, extra calculation time may be required. This time can be minimized by setting the phase manually (if it is known) in PropsSI by the following code.

let,we know the phase of water(liquid) at 461.1K and 5e6 Pa pressure. To find the density,following code will be used:

 PropsSI('D','T|liquid',461.1,'P',5e6,'Water')  

Notice that here a | sign has been used after one of the input property string.So, to specify the phase to be used, add the “|” delimiter to one (and only one) of the input key strings followed by one of the known phase strings in the table below:


On each call to PropsSI(), the imposed phase is reset to “not_imposed” as long as no imposed phase strings are used. A phase string must be appended to an Input key string on each and every call to PropsSI().

3. Trivial inputs:

We know that critical temperature, pressure etc is independent of the state property. So, we don't need to specify two input properties here. These type of states are called trivial state. To get property at trivial state, following code is used:

 PropsSI("Tcrit","Water")  

  which yields 647.096

PhaseSI() Function

Suppose we want to know the phase of water at 373K and 2e6 Pa. We can know it by PhaseSI() function:

 PhaseSI('T',373,'P',2e6,'Water')  

which yields: 'liquid'

You can also get this state as a floating index number. For the above example to get an index number type the following code:

 PropsSI('Phase','T',373,'P',2e6,'Water')  

which yields : 0.0

To know which phase is related to which index,use this code:

 get_phase_index('phase_twophase')  


Additional Function of CoolProp

This blog is a brief introduction to CoolProp usage. Apart from the mentioned functions,there are some other functions of Coolprop. The necessary links are listed below:


This blog is limited to describe the high level interface of CoolProp only. In order to know about low level interface, tabular interpretation and some additional features, please visit the following link:

http://www.coolprop.org/index.html

Code of this blog can be found in the following github repository

https://github.com/Rafezayed/Coolprop-Thermodynamics/blob/main/Coolprop%20simple%20example.ipynb








Comments