Documentation for pcsaft¶
PC-SAFT¶
Introduction¶
This package implements the PC-SAFT equation of state. In addition to the hard chain and dispersion terms, these functions also include dipole, association and ion terms for use with these types of compounds. When the ion term is included it is also called electrolyte PC-SAFT (ePC-SAFT).
Documentation¶
Documentation for the package is available on Read the Docs.
Example¶
import numpy as np
from pcsaft import pcsaft_den
# Toluene
x = np.asarray([1.])
m = np.asarray([2.8149])
s = np.asarray([3.7169])
e = np.asarray([285.69])
pyargs = {'m':m, 's':s, 'e':e}
t = 320 # K
p = 101325 # Pa
den = pcsaft_den(t, p, x, pyargs, phase='liq')
print('Density of toluene at {} K: {} mol m^-3'.format(t, den))
# Water using default 2B association scheme
x = np.asarray([1.])
m = np.asarray([1.2047])
e = np.asarray([353.95])
volAB = np.asarray([0.0451])
eAB = np.asarray([2425.67])
t = 274
p = 101325
s = np.asarray([2.7927 + 10.11*np.exp(-0.01775*t) - 1.417*np.exp(-0.01146*t)]) # temperature dependent sigma is used for better accuracy
pyargs = {'m':m, 's':s, 'e':e, 'e_assoc':eAB, 'vol_a':volAB}
den = pcsaft_den(t, p, x, pyargs, phase='liq')
print('Density of water at {} K: {} mol m^-3'.format(t, den))
# Water using 4C association scheme
x = np.asarray([1.])
m = np.asarray([1.2047])
e = np.asarray([353.95])
volAB = np.asarray([0.0451])
eAB = np.asarray([2425.67])
assoc_schemes = ['4c']
t = 274
p = 101325
s = np.asarray([2.7927 + 10.11*np.exp(-0.01775*t) - 1.417*np.exp(-0.01146*t)]) # temperature dependent sigma is used for better accuracy
pyargs = {'m':m, 's':s, 'e':e, 'e_assoc':eAB, 'vol_a':volAB, 'assoc_scheme':assoc_schemes}
den = pcsaft_den(t, p, x, pyargs, phase='liq')
print('Density of water at {} K: {} mol m^-3'.format(t, den))
Dependencies¶
The Numpy and Scipy packages are required. The core functions have been written in C++ to improve calculation speed, so Cython is needed, along with the Eigen package for linear algebra. For unit testing pytest is used.
Python package¶
To make it easier to use this code, it has been added as a package to PyPi (pcsaft), which means it can be installed using pip. This allows you to use the code without needing to compile the Cython code yourself. Binaries might not be available for all platforms or Python versions.
Compiling with Cython¶
To speed up the original Python code the core functions have been rewritten in C++. These are then connected with the remaining Python code using Cython. This gave a significant improvement in speed. The Cython code needs to be compiled before use. To do so install Cython. Then run the following command from the directory containing the PC-SAFT code
python setup.py build_ext --inplace
Make sure that the Eigen header files are somewhere on your path. More about the Cython build process can be found from the Cython documentation.
The original Python-only code has been removed from the repository. If you still want to use the original Python-only functions, go back to an earlier version of the repository. Note that the Python-only code is no longer maintained, so it may not be as reliable as the Cython code.
License¶
This project is licensed under the GNU General Public License v3.0
Acknowledgments¶
When developing these functions the code from two other groups was used as references
- Code from Joachim Gross (https://www.th.bci.tu-dortmund.de/cms/de/Forschung/PC-SAFT/Download/index.html)
- The MATLAB/Octave program written by Angel Martin and others (http://hpp.uva.es/open-source-software-eos/)
Functions¶
flashTQ |
Calculate the pressure of the system where vapor and liquid phases are in equilibrium. |
flashPQ |
Calculate the temperature of the system where vapor and liquid phases are in equilibrium. |
pcsaft_Hvap |
Calculate the enthalpy of vaporization. |
pcsaft_osmoticC |
Calculate the osmotic coefficient. |
pcsaft_cp |
Calculate the specific molar isobaric heat capacity. |
pcsaft_den |
Calculate the molar density. |
pcsaft_p |
Calculate pressure. |
pcsaft_hres |
Calculate the residual enthalpy for one phase of the system. |
pcsaft_sres |
Calculate the residual entropy (constant volume) for one phase of the system. |
pcsaft_gres |
Calculate the residual Gibbs energy for one phase of the system. |
pcsaft_fugcoef |
Calculate the fugacity coefficients for one phase of the system. |
pcsaft_Z |
Calculate the compressibility factor. |
pcsaft_ares |
Calculate the residual Helmholtz energy. |
pcsaft_dadt |
Calculate the temperature derivative of the residual Helmholtz energy. |
aly_lee |
Calculate the ideal gas isobaric heat capacity using the Aly-Lee equation. |
dielc_water |
Return the dielectric constant of water at the given temperature. |
References¶
- Gross and G. Sadowski, “Perturbed-Chain SAFT: An Equation of State Based on a Perturbation Theory for Chain Molecules,” Ind. Eng. Chem. Res., vol. 40, no. 4, pp. 1244–1260, Feb. 2001.
- Kleiner and G. Sadowski, “Modeling of Polar Systems Using PCP-SAFT: An Approach to Account for Induced-Association Interactions,” J. Phys. Chem. C, vol. 111, no. 43, pp. 15544–15553, Nov. 2007.
- Gross Joachim and J. Vrabec, “An equation‐of‐state contribution for polar components: Dipolar molecules,” AIChE J., vol. 52, no. 3, pp. 1194–1204, Feb. 2006.
- de Villiers, C. E. Schwarz, and A. J. Burger, “Improving vapour–liquid-equilibria predictions for mixtures with non-associating polar components using sPC-SAFT extended with two dipolar terms,” Fluid Phase Equilibria, vol. 305, no. 2, pp. 174–184, Jun. 2011.
- Huang and M. Radosz, “Equation of state for small, large, polydisperse, and associating molecules,” Ind. Eng. Chem. Res., vol. 29, no. 11, pp. 2284–2294, Nov. 1990.
- Huang and M. Radosz, “Equation of state for small, large, polydisperse, and associating molecules: extension to fluid mixtures,” Ind. Eng. Chem. Res., vol. 30, no. 8, pp. 1994–2005, Aug. 1991.
- Huang and M. Radosz, “Equation of state for small, large, polydisperse, and associating molecules: extension to fluid mixtures. [Erratum to document cited in CA115(8):79950j],” Ind. Eng. Chem. Res., vol. 32, no. 4, pp. 762–762, Apr. 1993.
- Gross and G. Sadowski, “Application of the Perturbed-Chain SAFT Equation of State to Associating Systems,” Ind. Eng. Chem. Res., vol. 41, no. 22, pp. 5510–5515, Oct. 2002.
- Cameretti, G. Sadowski, and J. M. Mollerup, “Modeling of Aqueous Electrolyte Solutions with Perturbed-Chain Statistical Associated Fluid Theory,” Ind. Eng. Chem. Res., vol. 44, no. 9, pp. 3355–3362, Apr. 2005.
- Cameretti, G. Sadowski, and J. M. Mollerup, “Modeling of Aqueous Electrolyte Solutions with Perturbed-Chain Statistical Association Fluid Theory,” Ind. Eng. Chem. Res., vol. 44, no. 23, pp. 8944–8944, Nov. 2005.
- Held, L. F. Cameretti, and G. Sadowski, “Modeling aqueous electrolyte solutions: Part 1. Fully dissociated electrolytes,” Fluid Phase Equilibria, vol. 270, no. 1, pp. 87–96, Aug. 2008.
- Held, T. Reschke, S. Mohammad, A. Luza, and G. Sadowski, “ePC-SAFT revised,” Chem. Eng. Res. Des., vol. 92, no. 12, pp. 2884–2897, Dec. 2014.
- Watson, M. Vikse, T. Gundersen, and P. I. Barton, “Reliable Flash Calculations: Part 1. Nonsmooth Inside-Out Algorithms,” Ind. Eng. Chem. Res., vol. 56, no. 4, pp. 960–973, Feb. 2017.