{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Check Cubic EOS\n",
    "\n",
    "The values will not be precisely the same because Bell and Jager, JRN, 2016 used the conventional truncated values for $\\Omega_a$ and $\\Omega_b$ while teqp uses the exact values from Bell and Deiters, IECR, 2021"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt, numpy as np\n",
    "import matplotlib as mpl\n",
    "mpl.rcParams['figure.dpi']= 100\n",
    "import teqp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Values taken from http://dx.doi.org/10.6028/jres.121.011\n",
    "Tc_K = [190.564, 154.581, 150.687]\n",
    "pc_Pa = [4599200, 5042800, 4863000]\n",
    "acentric = [0.011, 0.022, -0.002]\n",
    "z = np.array([0.5, 0.3, 0.2]) # mole fractions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.0960116460031759 0.096019116018396\n",
      "0.02360946208541689 0.023611667278971\n",
      "0.0017427456394558435 0.0017433108161805\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'Delta1': 2.414213562373095,\n",
       " 'Delta2': -0.41421356237309515,\n",
       " 'OmegaA': 0.4572355289213822,\n",
       " 'OmegaB': 0.07779607390388846,\n",
       " 'kind': 'Peng-Robinson'}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model = teqp.canonical_PR(Tc_K, pc_Pa, acentric)\n",
    "\n",
    "T = 800 # K\n",
    "rho = 5000 # mol/m^3\n",
    "print(model.get_Ar01(T, rho, z), 9.6019116018396e-002)\n",
    "print(model.get_Ar02n(T, rho, z)[2], 2.3611667278971e-002)\n",
    "print(model.get_Ar03n(T, rho, z)[3], 1.7433108161805e-003)\n",
    "model.get_meta()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.12741589269633935 0.12741566551477\n",
      "0.024896233252879204 0.024895937945147\n",
      "0.006098736292510815 0.006098653825619\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'Delta1': 1.0,\n",
       " 'Delta2': 0.0,\n",
       " 'OmegaA': 0.4274802335403417,\n",
       " 'OmegaB': 0.08664034996495766,\n",
       " 'kind': 'Soave-Redlich-Kwong'}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model = teqp.canonical_SRK(Tc_K, pc_Pa, acentric)\n",
    "\n",
    "T = 800 # K\n",
    "rho = 5000 # mol/m^3\n",
    "print(model.get_Ar01(T, rho, z), 1.2741566551477e-001)\n",
    "print(model.get_Ar02n(T, rho, z)[2], 2.4895937945147e-002)\n",
    "print(model.get_Ar03n(T, rho, z)[3], 6.0986538256190e-003)\n",
    "model.get_meta()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'Delta1': 2.414213562373095, 'Delta2': -0.41421356237309515, 'OmegaA': 0.4572355289213822, 'OmegaB': 0.07779607390388846, 'kind': 'Peng-Robinson'}\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "([24221.746187758014, 1030.361868803444],\n",
       " [24222.536725733073, 1029.779329419418])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model = teqp.canonical_PR([Tc_K[0]], [pc_Pa[0]], [acentric[0]])\n",
    "print(model.get_meta())\n",
    "[rhoL, rhoV ] = model.superanc_rhoLV(150)\n",
    "\n",
    "import CoolProp.CoolProp as CP\n",
    "[rhoL, rhoV], CP.PropsSI('Dmolar','T',150,'Q',[0,1],'PR::METHANE').tolist()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}