zmeri / PC-SAFT

Functions implementing the PC-SAFT equation of state, including association, electrolyte and dipole terms
GNU General Public License v3.0
49 stars 18 forks source link

======= PC-SAFT

.. image:: https://badge.fury.io/py/pcsaft.svg :target: https://badge.fury.io/py/pcsaft .. image:: https://img.shields.io/badge/License-GPLv3-blue.svg :target: /LICENSE .. image:: https://img.shields.io/pypi/dm/pcsaft :alt: PyPI - Downloads :target: https://pypistats.org/packages/pcsaft .. image:: https://readthedocs.org/projects/pcsaft/badge/?version=latest :target: http://pcsaft.readthedocs.io/?badge=latest

Status

This project is no longer actively maintained. In the past years, newer projects (such as Clapeyron.jl and teqp) have come out that also implement PC-SAFT. Some of these also include the electrolyte term. Additionally, these programs are also more sophisticated than the PC-SAFT code here. For instance, they allow a variety of different models to be used in addition to PC-SAFT, handle differentiation more elegantly, and appear to have more robust algorithms for handling different phases. Try out one of these newer projects instead.

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

.. code-block:: python

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.11np.exp(-0.01775t) - 1.417np.exp(-0.01146t)]) # 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.11np.exp(-0.01775t) - 1.417np.exp(-0.01146t)]) # 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.

Author

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

.. Clapeyron.jl: https://github.com/ClapeyronThermo/Clapeyron.jl .. teqp: https://github.com/usnistgov/teqp .. _Read the Docs: https://pcsaft.readthedocs.io/en/latest/ .. _Cython: http://cython.org/ .. _Eigen: https://github.com/eigenteam/eigen-git-mirror .. pcsaft: https://pypi.org/project/pcsaft/ .. Cython documentation: http://docs.cython.org/en/latest/src/quickstart/build.html .. _earlier version: https://github.com/zmeri/PC-SAFT/tree/b43bf568c4dc1907316422d5c3f7b809e9725848 .. _zmeri: https://github.com/zmeri