Skip to content
Snippets Groups Projects
PCSAFT.ipynb 6.15 KiB
Newer Older
  • Learn to ignore specific revisions
  • Ian Bell's avatar
    Ian Bell committed
    {
     "cells": [
      {
       "cell_type": "markdown",
    
    Ian Bell's avatar
    Ian Bell committed
       "id": "f406bbb5",
    
    Ian Bell's avatar
    Ian Bell committed
       "metadata": {},
       "source": [
    
    Ian Bell's avatar
    Ian Bell committed
        "# PC-SAFT\n",
    
    Ian Bell's avatar
    Ian Bell committed
        "\n",
    
    Ian Bell's avatar
    Ian Bell committed
        "The PC-SAFT implementation in teqp is based on the implementation of Gross and Sadowski (https://doi.org/10.1021/ie0003887), with the typo from their paper fixed.  It does NOT include the association contribution, only the dispersive contributions.\n",
        "\n",
        "The model in teqp requires the user to specify the values of ``sigma``, ``epsilon/kB``, and ``m`` for each substance.  A very few substances are hardcoded in teqp, for testing purposes.  "
    
    Ian Bell's avatar
    Ian Bell committed
       ]
      },
    
      {
       "cell_type": "raw",
       "id": "d9efd027",
       "metadata": {
        "raw_mimetype": "text/restructuredtext"
       },
       "source": [
        "The Python class is here: :py:class:`PCSAFTEOS <teqp.teqp.PCSAFTEOS>`"
       ]
      },
    
    Ian Bell's avatar
    Ian Bell committed
      {
       "cell_type": "code",
    
    Ian Bell's avatar
    Ian Bell committed
       "execution_count": null,
       "id": "984925ce",
    
    Ian Bell's avatar
    Ian Bell committed
       "metadata": {},
       "outputs": [],
    
    Ian Bell's avatar
    Ian Bell committed
       "source": [
        "import teqp\n",
    
    Ian Bell's avatar
    Ian Bell committed
        "import numpy as np\n",
        "teqp.__version__"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "id": "7bbd7129",
       "metadata": {},
       "outputs": [],
       "source": [
    
    Ian Bell's avatar
    Ian Bell committed
        "TeXkey = 'Gross-IECR-2001'\n",
        "ms = [1.0, 1.6069, 2.0020]\n",
        "eoverk = [150.03, 191.42, 208.11]\n",
        "sigmas = [3.7039, 3.5206, 3.6184]\n",
        "\n",
        "coeffs = []\n",
        "for i in range(len(ms)):\n",
        "    c = teqp.SAFTCoeffs()\n",
        "    c.m = ms[i]\n",
        "    c.epsilon_over_k = eoverk[i]\n",
        "    c.sigma_Angstrom = sigmas[i]\n",
        "    coeffs.append(c)\n",
        "    \n",
        "model = teqp.PCSAFTEOS(coeffs)"
       ]
      },
    
      {
       "cell_type": "code",
       "execution_count": null,
       "id": "19ec9bfb",
       "metadata": {},
       "outputs": [],
       "source": [
        "# Here are some rudimentary timing results\n",
        "T = 300.0\n",
        "rhovec = np.array([3.0, 4.0, 5.0])\n",
        "rho = rhovec.sum()\n",
        "x = rhovec/np.sum(rhovec)\n",
        "%timeit model.get_fugacity_coefficients(T,rhovec)\n",
        "%timeit (-1.0)*model.get_Ar20(T, rho, x)\n",
        "%timeit model.get_partial_molar_volumes(T, rhovec)"
       ]
      },
    
    Ian Bell's avatar
    Ian Bell committed
      {
       "cell_type": "markdown",
       "id": "578630c8",
       "metadata": {},
       "source": [
        "The model parameters can be queried:"
       ]
      },
      {
       "cell_type": "code",
    
    Ian Bell's avatar
    Ian Bell committed
       "execution_count": null,
    
    Ian Bell's avatar
    Ian Bell committed
       "id": "d4e47e54",
       "metadata": {},
    
    Ian Bell's avatar
    Ian Bell committed
       "outputs": [],
    
    Ian Bell's avatar
    Ian Bell committed
       "source": [
        "model.get_m(), model.get_epsilon_over_k_K(), model.get_sigma_Angstrom()"
       ]
      },
    
    Ian Bell's avatar
    Ian Bell committed
      {
       "cell_type": "markdown",
       "id": "5cbb382d",
       "metadata": {},
       "source": [
        "## Adjusting k_ij\n",
        "\n",
    
    Ian Bell's avatar
    Ian Bell committed
        "Fine-tuned values of $k_{ij}$ can be provided when instantiating the model.  A complete matrix of all the $k_{ij}$ values must be provided. This allows for asymmetric mixing models in which $k_{ij}\\neq k_{ji}$."
    
    Ian Bell's avatar
    Ian Bell committed
       ]
      },
      {
       "cell_type": "code",
    
    Ian Bell's avatar
    Ian Bell committed
       "execution_count": null,
    
    Ian Bell's avatar
    Ian Bell committed
       "id": "a32c41b5",
       "metadata": {},
    
    Ian Bell's avatar
    Ian Bell committed
       "outputs": [],
    
    Ian Bell's avatar
    Ian Bell committed
       "source": [
        "k_01 = 0.01; k_10 = k_01\n",
    
    Ian Bell's avatar
    Ian Bell committed
        "kmat = [[0,k_01,0],[k_10,0,0],[0,0,0]]\n",
    
    Ian Bell's avatar
    Ian Bell committed
        "teqp.PCSAFTEOS(coeffs, kmat)"
       ]
      },
    
    Ian Bell's avatar
    Ian Bell committed
      {
       "cell_type": "markdown",
       "id": "ca52e844",
       "metadata": {},
       "source": [
        "## Superancillary\n",
        "\n",
    
        "The superancillary equation for PC-SAFT has been developed, and is much more involved than that of the cubic EOS. As a consequence, the superancillary equation has been provided as a separate package rather than integrating it into to teqp to minimize the binary size of teqp. It can be installed from PYPI with: ``pip install PCSAFTsuperanc``\n",
        "\n",
        "The scaling in the superancillaries uses reduced variables:\n",
        "\n",
        "$$ \\tilde T = T/(\\epsilon/k_{\\rm B}) $$\n",
        "$$ \\tilde\\rho = \\rho_{\\rm N}\\sigma^3 $$\n",
        "\n",
        "where $\\rho_{\\rm N}$ is the number density, and the other parameters are from the PC-SAFT model"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "id": "f6e3b8d2",
       "metadata": {},
       "outputs": [],
       "source": [
        "import PCSAFTsuperanc\n",
        "\n",
        "sigma_m = 3e-10 # [meter]\n",
        "e_over_k = 150.0 # [K]\n",
        "m = 5\n",
        "\n",
        "# The saturation temperature\n",
        "T = 300\n",
        "\n",
        "[Ttilde_crit, Ttilde_min] = PCSAFTsuperanc.get_Ttilde_crit_min(m=m)\n",
        "print('Ttilde crit:', Ttilde_crit)\n",
        "\n",
        "# Get the scaled densities for liquid and vapor phases\n",
        "[tilderhoL, tilderhoV] = PCSAFTsuperanc.PCSAFTsuperanc_rhoLV(Ttilde=T/e_over_k, m=m)\n",
        "# Convert back to molar densities\n",
        "N_A = PCSAFTsuperanc.N_A # The value of Avogadro's constant used in superancillaries\n",
        "rhoL, rhoV = [tilderho/(N_A*sigma_m**3) for tilderho in [tilderhoL, tilderhoV]]\n",
        "\n",
        "# As a sanity check, confirm that we got the same pressure in both phases\n",
        "c = teqp.SAFTCoeffs()\n",
        "c.sigma_Angstrom = sigma_m*1e10\n",
        "c.epsilon_over_k = e_over_k \n",
        "c.m = m\n",
        "model = teqp.PCSAFTEOS([c])\n",
        "z = np.array([1.0])\n",
        "pL = rhoL*model.get_R(z)*T*(1+model.get_Ar01(T, rhoL, z))\n",
        "pV = rhoV*model.get_R(z)*T*(1+model.get_Ar01(T, rhoV, z))\n",
        "print('Pressures are:', pL, pV, 'Pa')"
    
    Ian Bell's avatar
    Ian Bell committed
       ]
      },
      {
       "cell_type": "markdown",
       "id": "0bdf568f",
       "metadata": {},
       "source": [
        "## Maximum density\n",
        "\n",
        "The maximum number density allowed by the EOS is defined based on the packing fraction. To get a molar density, divide by Avogadro's number. The function is conveniently exposed in Python:"
       ]
      },
      {
       "cell_type": "code",
       "execution_count": null,
       "id": "3c8491a9",
       "metadata": {},
       "outputs": [],
       "source": [
        "max_rhoN = teqp.PCSAFTEOS(coeffs).max_rhoN(130.0, np.array([0.3, 0.3, 0.4]))\n",
        "display(max_rhoN)\n",
        "max_rhoN/6.022e23 # the maximum molar density in mol/m^3"
    
    Ian Bell's avatar
    Ian Bell committed
       ]
    
    Ian Bell's avatar
    Ian Bell committed
      }
     ],
     "metadata": {
    
      "celltoolbar": "Raw Cell Format",
    
    Ian Bell's avatar
    Ian Bell committed
      "kernelspec": {
       "display_name": "Python 3 (ipykernel)",
       "language": "python",
       "name": "python3"
      },
      "language_info": {
       "codemirror_mode": {
        "name": "ipython",
        "version": 3
       },
       "file_extension": ".py",
       "mimetype": "text/x-python",
       "name": "python",
       "nbconvert_exporter": "python",
       "pygments_lexer": "ipython3",
    
       "version": "3.10.6"
    
    Ian Bell's avatar
    Ian Bell committed
      }
     },
     "nbformat": 4,
     "nbformat_minor": 5
    }