Skip to content

Thermopack is a thermodynamic model library for fluid properties and PVT calculations

License

Notifications You must be signed in to change notification settings

ailoa/thermopack-thermotools

 
 

Repository files navigation

Thermopack

Thermopack is a thermodynamics library for multi-component and multi-phase thermodynamics developed at SINTEF Energy Research and NTNU Department of Chemistry. Through decades of research, we have developed a software that performs thermodynamic calculations. A large selection of equations of state has been implemented in this software. Most of these equations of state have been developed by other research groups around the world, but some of them have been developed by us. Thermopack has been a much-appreciated in-house powerhouse.

Thermopack is available for everybody, free of charge under the MIT/Apache 2.0 open-source licenses. Thermopack is written in FORTRAN to handle heavy numerical computations associated with process and computational fluid dynamics (CFD) simulations. The thermodynamic framework is easily interfaced from C/C++ and also contains a flexible Python wrapper to make scripting easy. The Python interface is also a building block for the Thermopack graphical user interface, where it is possible to plot thermodynamic phase diagrams with the most frequently used equations of state. The graphical user interface is currently running on the Windows and Linux operating systems.

Table of contents

Please cite

Thermopack has been developed through many projects, and have produced many articles. If you are writing academic publications, please cite one or more of the following articles:

Authors and contact persons

Morten Hammer ([email protected], [email protected])
Ailo Aasen ([email protected])
Øivind Wilhelmsen ([email protected])
Vegard Gjeldvik Jervell ([email protected])

License

Thermopack is distributed under the MIT license and Apache 2.0.

Acknowledgments

A number of colleagues at SINTEF Energy Research and NTNU have contributed to the development of thermopack. We gratefully acknowledge their contributions.

Program structure

Each EoS in thermopack is a class, which inherits from the thermopack class found in thermo.py. The primary documentation for the thermopack python wrapper consists of the docstrings of the thermopack class. This class contains all generic methods used to compute thermodynamic properties, phase equilibria, etc. The inheriting classes simply ensure that the correct part of the Fortran-module is linked when performing calculations, and provide some extended functionality for handling EoS parameters and such. See the wiki for more information on this.

Fluid parameters are compiled into the Fortran-module, and are not directly accessible through the Python-wrapper. The entire fluid parameter database used by thermopack may be found in the /fluids directory in the GitHub repo. In order to model fluids not currently supported in the module available through pip, thermopack must be compiled from source with the new parameters. See the wiki for information on how to add new fluids, and the GitHub README for a guide on how to compile from source. Please feel free to leave a PR for new parameter sets such that these can be included in future releases of thermopack.

File System

Brief description of file structure:

  • thermopack/: Main library folder containing make scripts etc.
  • thermopack/src/: Main path for Fortran source code
  • thermopack/unittest/: Test files written for pFUunit
  • thermopack/bin/: Compiled binaries and libraries
  • thermopack/doc/: Memos and doxygen documentation
  • thermopack/fluids/: Pure fluid files
  • thermopack/binaries/: Files containing binary interaction parameters etc.
  • thermopack/MSVStudio/: Microsoft Visual Studio project and solution files
  • thermopack/include/: C/C++ include file
  • thermopack/pyplot/: Example plot-scripts (Plotting text files generated by Thermopack)
  • thermopack/addon/: Add-on functionality
  • thermopack/addon/pycThermopack/: Python interface
  • thermopack/addon/pyUtils/: Python utilities for generating fortran code and makefile input.
  • thermopack/addon/trend_interface/: Interface for working with the TREND/EOSCG library developed by Roland Span and Ruhr-Universität Bochum

Building from source

The following sections show how to fetch, compile and install Thermopack and the Python frontend pycThermopack. When things are properly installed, it may be useful to look into the examples provided in the addon/pyExamples.

pypi

Thermopack has been compiled for Windows, Linux and macOS and made available on the Python Package Index (pypi), and can be installed using pip.

pip3 install --user thermopack

Prerequisites

Thermopack source code can be compiled with the GNU Fortran compiler or Intel FORTRAN and is dependent on the LAPACK and BLAS libraries. On the Windows OS the code can be compiled using Microsoft Visual Studio. A solution file is found in thermopack/MSVStudio, assuming that the Intel Fortran compiler is integrated with Microsoft Visual Studio.

Linux setup

The Thermopack source code is downloaded by cloning the library to your local computer. The following commands assume that you have a local installation of Git, gfortran and Python 3 with pip. To compile using Intel FORTRAN, use make optim_ifort.

# Fetch and compile
git clone https://github.com/thermotools/thermopack.git
cd thermopack
make optim

# Prepare and install pycThermopack, aka "thermopack"
# Remark: On some systems, Python 3 is installed as python, not python3. If so,
# you can replace "python3" with "python" and perhaps also "pip3" with "pip" in
# the below.
cd addon/pycThermopack
python3 makescript.py optim
pip3 install --user .

If you are working actively with the Thermopack code, either the Fortran backend or the Python frontend, then it may be useful to install in editable mode (aka develop mode). This will install a link to the develop files instead of copying the files when installing. This can be done with the -e option, i.e.:

pip3 install -e --user .

See also addon/pycThermopack/README.md for more details on pycThermopack.

MacOS setup

The easiest way to get started is via Homebrew. After following the instructions on their website to set it up, install gcc and make. Open a terminal (e.g. the default Terminal.app), and type:

brew install gcc make

Then follow the Linux instructions above, just replace make with gmake. Some additional packages like git and python can also be installed via Homebrew before you start, but if you use a recent version of MacOS (e.g. Catalina), then the versions installed by default should be sufficient.

MacOS with arm64 architecture (M1, M2 etc.)

Use the alternative Makefile_arm64 and Makefile_arm64.code by renaming the files

Makefile => Makefile_x86
Makefile.code => Makefile_x86.code
Makefile_arm64 => Makefile
Makefile_arm64.code => Makefile.code

then follow the steps under MacOS setup. Please feel free to leave an issue if you have build problems, the build system for MacOS on Apple Silicon has not been as thouroughly tested as other build systems, and is still somewhat a work in progress.

Windows setup

Download and compile LAPACK and BLAS libraries (you will need CMake and a working compiler).

To be compatible with the current settings, you need to compile using Intel Fortran with Visual Studio, and configure as follows:

- Fortran/Data/Default Real KIND = 8
- Fortran/External Procedures/Calling Convention = cref
- Fortran/External Procedures/Name Case Interpretation = lowercase
- Fortran/External Procedures/String Length Argument Parsing = After All Arguments
- Fortran/External Procedures/Append Underscore to External Names = Yes
- Fortran/Floating Point/Floating Point Model = precise

Copy LAPACK and BLAS libraries to the paths:

  • thermopack\lapack\lib\Debug
  • thermopack\lapack\lib\Release

Open thermopack\MSVStudio\thermopack.sln using Visual Studio, and compile the wanted configuration.

See addon/pycThermopack/README.md for how to install pycThermopack.

MSYS2/Mingw-W64 setup

Thermopack can also be compiled using gfortran in the MSYS2 environment. Download MSYS2 from https://www.msys2.org, and install and update the package system following the instructions given. Avoid having spaces in the MSYS2 installation directory path, as the Makefile might not work. Having a working MSYS2 installation, thermopack can be compiled after installing the following packages:

pacman -S git
pacman -S mingw-w64-x86_64-gcc-fortran
pacman -S mingw-w64-x86_64-openblas
pacman -S mingw-w64-x86_64-make
pacman -S mingw-w64-x86_64-dlfcn

Open the MSYS2 MinGW 64-bit application, and enter the following in the terminal:

git clone https://github.com/thermotools/thermopack.git
cd thermopack
mingw32-make.exe optim

See addon/pycThermopack/README.md for how to install pycThermopack for the MSYS2 environment.

Docker setup

See addon/docker/README.md for available Dockerfiles to run Thermopack with docker.

CMake setup

See thermopack_cmake for prototype CMake scripts to compile Thermopack.

Getting started - Python

This is a short introduction to thermopack. Once you've gotten started, we recommend a look at the Examples in the GitHub repo. Comprehensive documentation for the methods available through the python interface can also be found in the wiki. For more advanced users, a look at the more advanced page in the wiki may also be useful.

Equations of State (EoS's) in ThermoPack are classes. To do calculations for a given mixture an EoS object must first be initialized for that mixture, as demonstrated in the Initializing an EoS section. Then, a wide variety of thermodynamic computations can be done, as demonstrated in the remaining sections.

Initialising an equation of state

An EoS is initialized by passing in the fluid identifiers of the mixture, for example

from thermopack.saftvrmie import saftvrmie
eos = saftvrmie('C1,CO2')

will initialize a SAFT-VR Mie EoS for a mixture of methane and CO2. The complete list of component identifiers is in the Fluid identifiers section of the wiki. PC-SAFT, SAFT-VRQ Mie and Lee-Kesler EoS are initialized in the same way, as

from thermopack import saftvrmie, saftvrqmie, pcsaft, lee_kesler
svrm = saftvrmie.saftvrmie('AR,KR') # SAFT-VR Mie EoS for Ar/Kr mixture
svrqm = saftvrqmie.saftvrqmie('HE') # SAFT-VRQ Mie EoS for pure He
pcs = pcsaft.pcsaft('BENZENE,NC6,NC12') # PC-SAFT EoS for ternary benzene/hexane/dodecane mixture
lk = lee_kesler.lee_kesler('N2,O2') # Lee-Kesler EoS for nitrogen/oxygen mixture 

The cubic equations of state are all interfaced through the cubic class. Available cubic EoS's can are SRK, PR, VdW, SW, PT and tcPR. More information on the individual cubics, mixing rules, etc. can be found in the wiki. The specific cubic EoS to initialize is specified with a string as

from thermopack.cubic import cubic
srk = cubic('NH3,C2', 'SRK') # SRK EoS for ammonia/ethane mixture
pr = cubic('IC4,NC10', 'PR') # PR EoS for isobutane/decane mixture
vdw = cubic('C1,C2,C3,N2,O2', 'VdW') # VdW EoS for methane/ethane/propane/nitrogen/oxygen mixture
sw = cubic('R11,R12', 'SW') # Schmidt-Wensel EoS for FCl3C/F2Cl2C mixture
pt = cubic('PRLN', 'PT') # Patel-Teja EoS for pure propylene
tcpr = cubic('F6S,SO2', 'tcPR') # Translated-Consistent PR EoS for SF6/SO2 mixture

Cubic-plus association EoS's are available for the SRK and PR EoS through the cpa class as

from thermopack.cpa import cpa
srk_cpa = cpa('H2O,ETOH,PROP1OL', 'SRK') # SRK-CPA EoS for water/ethanol/propanol mixture
pr_cpa = cpa('ACETONE,HEX1OL,CYCLOHEX', 'PR') # PR-CPA EoS for acetone/hexanol/cyclohexane mixture

Several multiparameter EoS's can interfaced through the multiparameter.multiparam class. The available multiparameter EoS's are NIST-MEOS, MBWR16 and MBWR32. These are initialized as

from thermopack.multiparameter import multiparam
nist = multiparam('C3', 'NIST_MEOS') # NIST-MEOS EoS for propane
mbwr16 = multiparam('C1', 'MBWR16') # MBWR16 EoS for methane
mbwr32 = multiparam('C2', 'MBWR32') # MBWR32 EoS for ethane

please note that not all fluids are supported for multiparameter equations of state, depending on what parameters are available in the fluid database.

Finally, the Extended-corresponding state EoS is available through the extended_csp.ext_csp class as

from thermopack.extended_csp import ext_csp
eos = ext_csp('C1,C2,C3,NC4', sh_eos='SRK', sh_alpha='Classic',
              sh_mixing='vdW', ref_eos='NIST_MEOS', ref_comp='C3')

For more information on the extended-csp EoS please see the Examples and the wiki.

Doing calculations

Now that we have an EoS initialized we can start computing stuff. The primary source on how to use individual methods in thermopack are the specific documentation of the thermo class. Here, a small subset of the functionality is demonstrated.

Note that all input is in SI units (moles/kelvin/pascal/cubic meters/joule)

pVT-properties

Specific volume, given temperature, pressure and composition is computed as

from thermopack.saftvrmie import saftvrmie
eos = saftvrmie('NC6,NC12') # Hexane/dodecane mixture
T = 300 # Kelvin
p = 1e5 # Pascal
x = [0.2, 0.8] # Molar composition
vg, = eos.specific_volume(T, p, x, eos.VAPPH) # Molar volume of gas phase (NB: Notice the comma)
vl, = eos.specific_volume(T, p, x, eos.LIQPH) # Molar volume of liquid phase (NB: Notice the comma)

where eos.VAPPH and eos.LIQPH are phase flags used to identify different phases. The commas are necessary because all output from thermopack methods are as tuples.

Similarly, pressure, internal energy, enthalpy, entropy, etc. and associated differentials can be computed via the methods chemical_potential_tv(T, V, n), internal_energy_tv(T, V, n), enthalpy_tv(T, V, n), helmholtz_tv(T, V, n), entropy_tv(T, V, n). For a full overview of the available property calculations see the TV-property interfaces and the Tp-property interfaces of the thermo class.

Differentials

If we want volume differentials, we use the same method, but set the flags to calculate differentials to True:

# Continued 
vg, dvdp = eos.specific_volume(T, p, x, eos.VAPPH, dvdp=True) # Vapour phase molar volume and pressure differential
vl, dvdT = eos.specific_volume(T, p, x, eos.LIQPH, dvdt=True) # Liquid phase molar volume and temperature differential
_, dvdn = eos.specific_volume(T, p, x, eos.LIQPH, dvdn=True) # Liquid phase partial molar volumes

Differentials can be computed as functions of $(T, V, n)$ or as functions of $(T, p, n)$. For an overview of the different methods, see Advanced usage: Different property interfaces. A short example is given here as:

# Continued
H, dHdn_TV = eos.enthalpy_tv(T, vg, n, dhdn=True) # Compute enthalpy and derivative of enthalpy wrt. mole numbers at constant (T, V)
h_vap, dhvap_dn_Tp = eos.enthalpy(T, p, x, eos.VAPPH, dhdn=True) # Compute molar vapour phase enthalpy and derivative of molar vapour phase enthalpy wrt. mole numbers at constant (T, p)
h_liq, dliq_dn_Tp = eos.enthalpy(T, p, x, eos.LIQPH, dhdn=True) # Compute molar liquid phase enthalpy and derivative of molar liquid phase enthalpy wrt. mole numbers at constant (T, p)
H, dHdn_Tp = eos.enthalpy_tvp(T, vg, n, dhdn=True) # Compute enthalpy and derivative of enthalpy wrt. mole numbers at constant (T, p)

Please note that heat capacities are not available directly, but must be computed as derivatives of enthalpy and internal energy, as

from thermopack.cubic import cubic
eos = cubic('C1,C3,NC6', 'SRK') # SRK EoS for a mixture of methane, propane and n-hexane

T = 300 # Kelvin
p = 1e5 # Pascal
x = [0.2, 0.1, 0.7] # Molar composition
_, Cp_vap = eos.enthalpy(T, p, x, eos.VAPPH, dhdt=True) # Vapour phase heat capacity at constant pressure, computed as (dH/dT)_{p,n}
_, Cp_liq = eos.enthalpy(T, p, x, eos.LIQPH, dhdt=True) # Liquid phase heat capacity at constant pressure, computed as (dH/dT)_{p,n}

vg, = eos.specific_volume(T, p, x, eos.VAPPH) # Computing vapour phase specific volume
vl, = eos.specific_volume(T, p, x, eos.LIQPH) # Liquid phase specific volume

_, Cv_vap = eos.internal_energy_tv(T, vg, x, dedt=True) # Vapour phase heat capacity at constant volume, computed as (dU/dT)_{V,n}
_, Cv_liq = eos.internal_energy_tv(T, vl, x, dedt=True) # Liquid phase heat capacity at constant volume, computed as (dU/dT)_{V,n}

Phase diagrams and Equilibria

As with other calculations, the primary source on how available methods for flash- and equilibria calculations and how to use them are the docstrings in thermo.py. Here we give a short introduction, for more extensive examples see the pyExamples directory.

Flash calculations

Flash calculations of several kinds are handled by the methods twophase_tpflash(), twophase_psflash(), twophase_phflash() and twophase_uvflash().

See the Flash interfaces in the documentation of the thermo class for the specifics on the different flash routines.

An example calculation using twophase_tpflash() may be done as

from thermopack.saftvrqmie import saftvrqmie
# SAFT-VRQ Mie for Hydrogen/Helium/Neon mixture 
eos = saftvrqmie('H2,HE,NE', minimum_temperature=20) # NB: Set minimum temperature low enough when working at very low temperatures
T = 35 # Kelvin
p = 3e6 # Pascal (30 bar)
z = [0.1, 0.25, 0.65] # Molar composition
flsh = eos.two_phase_tpflash(T, p, x) # flsh is a FlashResult object
print(flsh)
### Output: ###
# FlashResult object for Tp-flash
# Containing the attributes (description, name, value):
#   	Flash type                     flash_type : Tp  
#   	Total composition              z     : [0.1, 0.25, 0.65]  
#   	Temperature [K]                T     : 35  
#   	pressure [Pa]                  p     : 3000000.0  
#   	Liquid phase composition       x     : [0.05407302 0.03859287 0.90733411]  
#   	Vapour phase composition       y     : [0.14642524 0.46370066 0.3898741 ]  
#   	Vapour fraction                betaV : 0.497302408174766  
#   	Liquid fraction                betaL : 0.5026975918252341  
#   	Phase indentifier index        phase : 0  

the result of the flash is accessed from the attributes of the FlashResult object, found in utils.py, as

# Continued
x = flsh.x # Liquid composition
y = flsh.y # Vapour composition
betaL = flsh.betaL # 
# ... etc

The FlashResult object returned by the different flash routines all contain the same attributes.

Phase envelopes

ThermoPack has interfaces to trace (T,p)-, (T,v)- and (p,x,y)-phase envelopes. For the full documentation, see the docs of the thermo class. For more comprehensive examples, see the Examples.

Tp- and Tv- phase envelopes

Phase envelopes can be generated directly with the method get_envelope_twophase() as

# Continued
T, p = eos.get_envelope_twophase(1e5, x) # arrays of temperature and pressure for phase envelope, starting at 1 bar.
plt.plot(p, T) # Tp-projection of phase envelope

T, p, v = eos.get_envelope_twophase(1e5, x, calc_v=True) # Also return the specific volume at each point along the phase envelope
plt.plot(1 / v, T) # rho-T projection of the phase envelope

pxy-phase envelopes

To compute pxy-type phase envelopes, we use the get_binary_pxy() method. The pxy-phase diagram trace method assumes that there can be up to three phases present, two liquid and one vapour. The method get_binary_pxy therefore returns three tuples, that we call LLE, L1VE and L2VE. Each of these tuples corresponds to a phase boundary: The LLE tuple corresponds to the (Liquid 1 - Liquid 2) phase boundary, the L1VE tuple corresponds to the (Liquid 1 - Vapour) phase boundary, and the L2VE tuple corresponds to the (Liquid 2 - Vapour) phase boundary.

Each of these tuples contains three arrays (x, y, p): The first array (x) is the liquid composition along the phase boundary (Liquid 1 for LLE), the second array (y) is the vapour composition along the phase boundary (Liquid 2 for LLE), the third array (p) is the pressure along the phase boundary.

Note: If one or more of the phase boundaries does not exist, the corresponding tuple will be (None, None, None).

Note: The compositions returned by get_binary_pxy refer to the mole fraction of component 1.

Note: The minimum and maximum pressure of the phase envelope trace can be set with the kwargs minimum_pressure and maximum_pressure. For the full details, see the docs for the thermo class.

For a mixture with a Liquid-Liquid equilibrium and two Liquid-Vapour equilibria, we can plot the entire pxy-phase diagram as:

import matplotlib.pyplot as plt
from thermopack.cpa import cpa

eos = cpa('NC12,H2O', 'SRK')  # CPA-SRK eos for Dodecane/water mixture
T = 350  # kelvin
LLE, L1VE, L2VE = eos.get_binary_pxy(T)  # Returns three tuples containing three arrays each

# Liquid-liquid phase boundaries
# LLE[2] is the pressure along the liquid-liquid phase boundary
plt.plot(LLE[0], LLE[2], label='Liquid 1 composition') # LLE[0] is the mole fraction of component 1 (NC12) in Liquid 1 along the phase boundary
plt.plot(LLE[1], LLE[2], label='Liquid 2 composition') # LLE[1] is the mole fraction of component 1 (NC12) in Liquid 2 along the phase boundary

# Liquid 1-vapour phase boundaries
# L1VE[2] is the pressure along the Liquid 1 - Vapour phase boundary
plt.plot(L1VE[0], L1VE[2], label='Liquid 1 bubble line') # L1VE[0] is the mole fraction of component 1 (NC12) in Liquid 1 along the Liquid 1 - Vapour phase boundary
plt.plot(L1VE[1], L1VE[2], label='Liquid 1 dew line') # L1VE[1] is the mole fraction of component 1 (NC12) in the Vapour phase along the Liquid 1 - Vapour phase boundary

# Liquid 2-vapour phase boundaries
# L2VE[2] is the pressure along the Liquid 2 - Vapour phase boundary
plt.plot(L2VE[0], L2VE[2], label='Liquid 2 bubble line') # L2VE[0] is the mole fraction of component 1 (NC12) in Liquid 2 along the Liquid 2 - Vapour phase boundary
plt.plot(L2VE[1], L2VE[2], label='Liquid 2 dew line') # L2VE[1] is the mole fraction of component 1 (NC12) in the Vapour phase along the Liquid 2 - Vapour phase boundary

plt.ylabel('Pressure [Pa]') # The third element in each tuple is the pressure along the phase boundary
plt.xlabel('Molar composition')

If we are unsure whether one or more of the equilibria exists, we need to check whether the corresponding tuple contains None, as:

import matplotlib.pyplot as plt
from thermopack.cubic import cubic

eos = cubic('C3,NC6', 'PR') # PR EoS for propane/n-hexane mixture

T = 300 # Kelvin

LLE, L1VE, L2VE = eos.get_binary_pxy(T)

if LLE[0] is None: # If there are fewer than two liquid phases, LLE = (None, None, None)
    print('There are fewer than two liquid phases at all evaluated pressures!')
else:
    plt.plot(LLE[0], LLE[2], label='Liquid 1 composition') # LLE[0] is the mole fraction of component 1 (C3) in Liquid 1 along the phase boundary
    plt.plot(LLE[1], LLE[2], label='Liquid 2 composition') # LLE[1] is the mole fraction of component 1 (C3) in Liquid 2 along the phase boundary

if L1VE[0] is None: # If no phase boundaries are found, L1VE = (None, None, None)
    print('There is no Liquid - Vapour equilibria at any of the evaluated pressures!')
else:
    plt.plot(L1VE[0], L1VE[2], label='Liquid 1 bubble line') # L1VE[0] is the mole fraction of component 1 (C3) in Liquid 1 along the Liquid 1 - Vapour phase boundary
    plt.plot(L1VE[1], L1VE[2], label='Liquid 1 dew line') # L1VE[1] is the mole fraction of component 1 (C3) in the Vapour phase along the Liquid 1 - Vapour phase boundary

if L2VE[0] is None: # If LLE = (None, None, None) then L2VE will also be L2VE = (None, None, None), because there is no Liquid 2
    print('There are fewer than two liquid phases at all evaluated pressures!')
else:
    plt.plot(L2VE[0], L2VE[2], label='Liquid 2 bubble line') # L2VE[0] is the mole fraction of component 1 (C3) in Liquid 2 along the Liquid 2 - Vapour phase boundary
    plt.plot(L2VE[1], L2VE[2], label='Liquid 2 dew line') # L2VE[1] is the mole fraction of component 1 (C3) in the Vapour phase along the Liquid 2 - Vapour phase boundary

plt.ylabel('Pressure [Pa]') # The third element in each tuple is the pressure along the phase boundary
plt.xlabel('Molar composition')

Dew- and bubble points

We can also compute the bubble-temperature, pressure etc. directly using the methods bubble_temperature(p, z), bubble_pressure(T, z), dew_temperature(p, z) and dew_pressure(T, z), where z is the composition of the mixture, as

eos = cubic('CO2,CH4', 'SRK')
x = [0.5, 0.5] # Total composition of the mixture
p_dew, y_dew = eos.dew_pressure(273, x) # Calculates dew pressure and dew composition at 273 K
T_dew, y_dew = eos.dew_temperature(1e5, x) # Calculates dew temperature and dew composition at 1 bar
p_bub, x_bub = eos.bubble_pressure(273, x) # Calculates bubble pressure and bubble composition at 273 K
T_bub, x_bub = eos.bubble_temperature(1e5, x) # Calculates bubble temperature and bubble composition at 1 bar

Isolines

Various isolines can be computed using the methods get_isotherm, get_isobar, get_isentrope and get_isenthalp. In the following code snippet, the default values of the keyword arguments are indicated.

eos = pcsaft('NC6,NC12')
x = [0.2, 0.8]

# Calculate pressure, specific volume, specific entropy and specific enthalpy along the isotherm at 300 K
# from p = minimum_pressure to p = maximum_pressure. Compute at most nmax points.
p_iso_T, v_iso_T, s_iso_T, h_iso_T = eos.get_isotherm(300, x, minimum_pressure=1e5, maximum_pressure=1.5e7, nmax=100)

# Calculate temperature, specific volume, specific entropy and specific enthalpy along the isobar at 1 bar
# from T = minimum_temperature to T = maximum_temperature. Compute at most nmax points.
T_iso_p, v_iso_p, s_iso_p, h_iso_p = eos.get_isobar(1e5, x, minimum_temperature=200, maximum_temperature=500, nmax=100)

# Calculate temperature, pressure, specific volume and specific entropy along the isenthalp at 1 kJ / mol
# Start at the upper of (minimum_pressure, minimum_temperature)
# End at the lower of (maximum_pressure, maximum_temperature)
T_iso_h, p_iso_h, v_iso_h, s_iso_h = eos.get_isenthalp(1e3, x, minimum_pressure=1e5, maximum_pressure=1.5e7,
                                                            minimum_temperature=200, maximum_temperature=500,
                                                            nmax=100)

# Calculate temperature, pressure, specific volume and specific enthalpy along the isentrope at 5 J / mol K
# Start at the upper of (minimum_pressure, minimum_temperature)
# End at the lower of (maximum_pressure, maximum_temperature)
T_iso_s, p_iso_s, v_iso_s, h_iso_s = eos.get_isentrope(5, x, minimum_pressure=1e5, maximum_pressure=1.5e7,
                                                            minimum_temperature=200, maximum_temperature=500,
                                                            nmax=100)

Critical point

Thermopack has a critical point solver, which is called as

eos = saftvrqmie('HE,NE') # Use FH-corrected Mie potentials for Helium calculations!
n = [5, 10]
Tc, Vc, pc = eos.critical(n) # Compute the critical temperature, pressure and volume given mole numbers
vc = Vc / sum(n) # Critical specific volume computed from critical volume and mole numbers.

The solver accepts initial guesses for the critical values through the kwargs temp, and v. The error tolerance can be set via the tol kwarg (default is tol=1e-7).

More advanced usage - Python

Interaction parameters

In thermopack we're able to both set and get a wide array of coefficients and parameters depending on the models we are utilizing.

Cubic equations of state

Setting and getting the attractive energy interaction parameter $k_{ij}$ and co-volume interaction parameter $l_{ij}$

Starting with the attractive energy interaction parameter (kij). The parameter can be set using the function set_kij after intialising the equation and state. The function requires that you first write in the number of the components and subsequently the new interaction parameter i.e. (component number 1, component number 2, new kij value). If we're curious as to what parameter the EOS is already using we can see this by using the function get_kij which returns the value as a float given the component numbers as input i.e. (component number 1, component number 2).

cs = cubic('CO2,N2',"SRK","Classic","Classic")
#We set the interaction parameter to be -0.032
cs.set_kij(1,2,-0.032)
#We want to see what the interaction parameter is which returns that kij = -0.032
kij = cs.get_kij(1,2)

The procedure for setting and getting co-volume interaction parameters is analogous to the getting and setting of attractive energy parameters. Simply use the functions set_lij and get_lij instead.

#We set the parameter to be -0.032
cs.set_lij(1,2,-0.032)
#We want to see what the parameter is which returns that lij = -0.032
lij = cs.get_lij(1,2)

The different property interfaces (TV-) (Tp-) and (TVp-)

Property calculations in ThermoPack can be done either through the TV-interfaces, the Tp-interfaces or the TVp-interfaces.

The difference between the TV- and Tp- interface is only what variables the properties are computed as functions of, and what variables are held constant in the derivatives. TV-interface methods compute properties as functions of $(T, V, n)$, while Tp-interface methods compute properties as functions of $(T, p, n)$.

The TVp-interface methods on the other hand take $(T, V, n)$ as arguments, and evaluate derivatives as functions of $(T, p, n)$. To demonstrate with an example:

import numpy as np
from thermopack.cubic import cubic

eos = cubic('O2,N2', 'PR') # PR EoS for O2/N2 mixture

T = 300 # Kelvin
p = 1e5 # Pascal
x = np.array([0.21, 0.79]) # Molar composition (of air)
n_tot = 10 # Total number of moles
n = n_tot * x # Vector of mole numbers

v, = eos.specific_volume(T, p, x, eos.VAPPH) # Compute specific volume of vapour phase
V = v * n_tot # Total volume


# Computing the TOTAL Enthalpy (J), given (T, V, n)
# The differentials are computed for H = H(T, V, n), with 
# "subscripts" indicating the variables held constant
H_tvn, dHdT_Vn, dHdn_TV = eos.enthalpy_tv(T, V, n, dhdt=True, dhdn=True) 

# Computing the SPECIFIC VAPOUR phase enthalpy (J / mol), given (T, p, n) 
# The differentials are computed for h_vap = h_vap(T, p, n), with the 
# "subscripts" indicating the variables held constant
h_vap_tpn, dh_vap_dt_pn, dh_vap_dn_Tp = eos.enthalpy(T, p, n, eos.VAPPH, dhdt=True, dhdn=True)

# Computing the SPECIFIC LIQUID phase enthalpy (J / mol), given (T, p, n) 
# The differentials are computed for h_liq = h_liq(T, p, n), with the 
# "subscripts" indicating the variables held constant
h_liq_tpn, dh_liq_dt_pn, dh_liq_dn_Tp = eos.enthalpy(T, p, n, eos.LIQPH, dhdt=True, dhdn=True)

# Computing the TOTAL Enthalpy (J), given (T, V, n)
# NOTE : The differentials are computed for H = H(T, p, n)
#        NOT for H = H(T, V, n)
H_tpn, dHdt_pn, dHdn_Tp = eos.enthalpy_tvp(T, V, n, dhdt=True, dhdn=True)

Besides enthalpy_tvp, there are currently available TVp-interfaces for entropy_tvp and thermo_tvp (logarithm of fugacity coefficients).

Adding new fluids

The fluid database consists of a set of .json-files in the fluids directory. These files are are used to auto-generate the FORTRAN-files compdatadb.f90 and saftvrmie_datadb.f90 by running the respective python scripts compdata.py and saftvrmie.py found in the directory addon/pyUtils/datadb/. The files are generated in the current working directory and must be copied to the src-directory before recompiling ThermoPack to make the fluids available.

A <fluid\>.json file must contain a minimal set of data to be valid. This includes the critical point, accentric factor, mole weight and ideal gas heat capacity.

Ideal gas heat capacity

Several different correlations for the heat capacity are available, selected by the "correlation"-key in the "ideal-heat-capacity-1" field of the fluid files. These are summarized in the table below.

Ideal gas heat capacity correlations, and the corresponding keys used in the fluid-database.
Key Correlation Equation Unit
1  Sherwood, Reid & Prausnitz(a) A+BT+CT^2 +DT^3  cal g−^1 mol−^1 K−^1
 2  API-Project  44  -
 3  Hypothetic components  -  -
 4  Sherwood, Reid & Prausniz(b) A+BT+CT^2 +DT^3 J mol−^1 K−^1
 5  Ici (Krister Strøm) A+BT+CT^2 +DT^3 +ET−^2 J g−^1 K−^1
 6  Chen, Bender (Petter Nekså)  A+BT+CT^2 +DT^3 +ET^4 J g−^1 K−^1
 7  Aiche, Daubert & Danner(c)  A+B [ (C / T) sinh(C/T) ]^2 + D[ (E / T) cosh(E / T) ]^2  J kmol−^1 K−^1
8 Poling, Prausnitz & O’Connel(d)  R ( A+BT+CT^2 +DT^3 +ET^4 ) J mol−^1 K−^1
9  Linear function and fraction  A+BT+TC+D J mol−^1 K−^1
 10  Leachman & Valenta for H2 - -
 11  Use TREND model - -
 12 Shomate equation∗ A+BTs+CTs^2 +DTs^3 +ETs−^2 J mol−^1 K−^1

(a)3rd ed.(c)DIPPR-database

(b)4th ed.(d)5th ed.

∗Note:Ts= 10− (^3) T

Melting and sublimation curve correlations

$T_{\rm{reducing}} (K), p_{\rm{reducing}} (Pa), \mathbf{a}, \mathbf{c}, n, n_1, n_2$ and $n_3$ are read from the <fluid\>.json file, while $n_4 = n-n_1- n_2-n_3$. Currently a maximum of 6 paramaters can be given, $n \leq 6$. The correlation type is defined by a four character string with the format XX-X, where ML-X and SL-X are the default melting curve ($\sigma_{\rm{melt}}$) and sublimation curve ($\sigma_{\rm{sub}}$) correlations, respectively. See the Methane.json file for an working example of both the melting_curve and sublimation_curve parameters.

The reduced temperature used in the correlations is defined as

$$ \tau = \frac{T}{T_{\rm{reducing}}}. $$

The last character in the correlation string defines how the reducing pressure combines with $\sigma$ to give the melting/sublimation pressure,

$$ p(\sigma) = p_{\rm{reducing}} \times \begin{cases} \sigma & \text{correlation is XX-1} \\\ \exp(\sigma) & \text{correlation is XX-2}\\\ \exp(\frac{\sigma}{\tau}) & \text{correlation is XX-3} \end{cases}$$

For the melting curve calculation $\sigma$ is calculated from

$$ \sigma_{\rm{melt}} = \sum_{i=1}^{n_1} a_i \tau^{c_i} + \sum_{j=1}^{n_2} a_j (\tau-1)^{c_j} + \sum_{k=1}^{n_3} a_k (\ln \tau)^{c_k} + \sum_{l=1}^{n_4} a_l (\tau^{c_l} - 1) $$

For the sublimation curve calculation $\sigma$ is calculated from

$$ \sigma_{\rm{sub}} = \sum_{i=1}^{n_1} a_i \tau^{c_i} + \sum_{j=1}^{n_2} a_j (1-\tau)^{c_j} + \sum_{k=1}^{n_3} a_k (\ln \tau)^{c_k} + \sum_{l=1}^{n_4} a_l (\tau^{c_l} - 1) $$

The melting/sublimation curves can be scaled to match the saturation pressure at the triple temperature, $p_{\rm{sat}}(T_{\rm{triple}})$. The scaled pressure, $\tilde{p}(\sigma)$, is then calculated as

$$ \tilde{p}(\sigma) = \frac{p_{\rm{sat}}(T_{\rm{triple}}) }{p(\sigma(T_{\rm{triple}}))} p(\sigma)$$

Fluid name to fluid identifyer mapping

 

In order to specify fluids in Thermopack you need to use fluid identifiers as shown in the table below. The 'SAFT-VR', 'PC-SAFT' and 'CPA' columns indicate which fluids SAFT-EoS and CPA parameters are available for.

 

Fluid name Fluid identifyer SAFT-VR PC-SAFT CPA
1,1,1,2-Tetrafluoroethane R134a
1,1,1-Trifluoroethane R143a
1,1-Difluoroethane R152a
1,1-Difluoroethylene R1132a
1,2-Dichlorotetrafluoroethane R114
1,3-Butadiene 13BD
1-Butanol BUT1OL ✔️ ✔️
1-Chloro-1,1,2,2-tetrafluoroethane R124a
1-Chloro-1,1-difluoroethane R142b
1-Hexanol HEX1OL ✔️ ✔️
1-Pentanol PENT1OL ✔️ ✔️
1-Propanol PROP1OL ✔️ ✔️
2,3,3,3-Tetrafluoropropene R1234yf
2-Chloro-1,1,1,2-tetrafluoroethane R124
2-Methylhexane 2MHX
3-Methylpentane 3MP
Acetone ACETONE ✔️
Acetylen ACETYLEN ✔️
Ammonia NH3 ✔️ ✔️ ✔️
Argon AR ✔️ ✔️
Benzene BENZENE ✔️
Butanal BUTANAL ✔️
Carbon dioxide CO2 ✔️ ✔️ ✔️
Carbon monoxide CO
Carbon tetrafluoride R14
Chlorine CL2 ✔️
Chlorodifluoromethane R22
Chloropentafluoroethane R115
Chlorotrifluoromethane R13
Chlorotrifluorosilane ClF3Si
Cyclohexane CYCLOHEX ✔️
Cyclopropane C3_1
Deuterium D2 ✔️
Di-methyl ether DME ✔️
Di-n-hexyl ether S434
Dichlorodifluoromethane R12
Dichlorofluoromethane R21
Difluoromethane R32
Dinitrogen tetroxide N2O4
Equilibrium-hydrogen E-H2
Ethane C2 ✔️ ✔️
Ethanol ETOH ✔️ ✔️ ✔️
Ethylbenzene EBZN
Ethylene glycol MEG
Ethylene C2_1 ✔️
Helium-4 HE ✔️
Hexafluoroethane R116
Hydrazine N2H4 ✔️
Hydrogen peroxide H2O2
Hydrogen sulfide H2S ✔️ ✔️
Hydrogen H2 ✔️
Isobutane IC4 ✔️
Isopentane IC5 ✔️
Krypton KR ✔️
Lennard-jones_fluid LJF ✔️
Methane C1 ✔️ ✔️
Methanol MEOH ✔️ ✔️ ✔️
Methyl fluoride R41
Methylcyclopentane MTC5
Neon NE ✔️
Nitric oxide NO
Nitrogen N2 ✔️ ✔️
Nitrous oxide N2O
Octafluoropropane R218
Ortho-hydrogen O-H2 ✔️
Oxygen O2 ✔️ ✔️
Para-hydrogen P-H2 ✔️
Pentafluoroethane R125
Propadiene ALLENE
Propane C3 ✔️ ✔️ ✔️
Propylene PRLN
Sulfur dioxide SO2
Sulfur hexafluoride F6S
Tetrafluoroethylene R1114
Tetrafluorohydrazine F4N2
Toluene TOLU ✔️
Trans-1,3,3,3-tetrafluoropropene R1234ze
Trichlorofluoromethane R11
Trifluoroamineoxide F3NO
Trifluoromethane R23
Water H2O ✔️ ✔️ ✔️
Xenon XE ✔️
m-Xylene MXYL
n-Butane NC4 ✔️ ✔️ ✔️
n-Decane NC10 ✔️ ✔️ ✔️
n-Docosane NC22 ✔️ ✔️
n-Dodecane NC12 ✔️
n-Eicosane NC20 ✔️ ✔️
n-Heneicosane NC21 ✔️
n-Heptadecane NC17 ✔️
n-Heptane NC7 ✔️ ✔️ ✔️
n-Hexadecane NC16 ✔️
n-Hexane NC6 ✔️ ✔️ ✔️
n-Hydrogen N-H2
n-Nonadecane NC19 ✔️
n-Nonane NC9 ✔️ ✔️ ✔️
n-Octadecane NC18 ✔️
n-Octane NC8 ✔️ ✔️ ✔️
n-Pentacosane NC25 ✔️
n-Pentadecane NC15 ✔️ ✔️
n-Pentan NC5 ✔️ ✔️ ✔️
n-Tetracosane NC24 ✔️
n-Tetradecane NC14 ✔️
n-Tricosane NC23 ✔️
n-Tridecane NC13 ✔️
n-Undecane NC11 ✔️
o-Xylene OXYL
p-Xylene PXYL

About

Thermopack is a thermodynamic model library for fluid properties and PVT calculations

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Fortran 68.0%
  • Jupyter Notebook 20.4%
  • Python 10.9%
  • C++ 0.5%
  • Makefile 0.1%
  • C 0.1%