{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "4a58e423",
   "metadata": {},
   "source": [
    "# Extended Corresponding States\n",
    "\n",
    "This implements the method of Huber and Ely: https://doi.org/10.1016/0140-7007(94)90083-3\n",
    "\n",
    "It does not include the undocumented temperature and density terms that are included in REFPROP"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d09377d7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-03-15T22:40:00.317639Z",
     "iopub.status.busy": "2024-03-15T22:40:00.317019Z",
     "iopub.status.idle": "2024-03-15T22:40:00.330671Z",
     "shell.execute_reply": "2024-03-15T22:40:00.330247Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'0.19.1'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import teqp\n",
    "teqp.__version__"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5b38c18c",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-03-15T22:40:00.332579Z",
     "iopub.status.busy": "2024-03-15T22:40:00.332418Z",
     "iopub.status.idle": "2024-03-15T22:40:00.425272Z",
     "shell.execute_reply": "2024-03-15T22:40:00.424747Z"
    }
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import CoolProp.CoolProp as CP"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6a2b76b0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2024-03-15T22:40:00.428805Z",
     "iopub.status.busy": "2024-03-15T22:40:00.427846Z",
     "iopub.status.idle": "2024-03-15T22:40:00.442620Z",
     "shell.execute_reply": "2024-03-15T22:40:00.442183Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'pressure from ECS:'"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "5556329.442047298"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "'pressure from EOS:'"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "5478978.746656995"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# These parameters are from Huber & Ely\n",
    "j = {\n",
    "    \"kind\": \"multifluid-ECS-HuberEly1994\",\n",
    "    \"model\": {\n",
    "      \"reference_fluid\": {\n",
    "            \"name\": teqp.get_datapath() + \"/dev/fluids/R134a.json\",\n",
    "            \"acentric\": 0.326680,\n",
    "            \"Z_crit\": 4.056e6/(5030.8*8.314471*374.179),\n",
    "            \"T_crit / K\": 374.179,\n",
    "            \"rhomolar_crit / mol/m^3\": 5030.8\n",
    "      },\n",
    "      \"fluid\": {\n",
    "            \"name\": \"R143a\",\n",
    "            \"f_T_coeffs\": [ -0.22807e-1, -0.64746],\n",
    "            \"h_T_coeffs\": [ 0.36563, -0.26004e-1],\n",
    "            \"acentric\": 0.25540,\n",
    "            \"T_crit / K\": 346.3,\n",
    "            \"rhomolar_crit / mol/m^3\": (1/0.194*1000),\n",
    "            \"Z_crit\": 3.76e6/(346.3*8.314471*(1/0.194*1000))\n",
    "      }\n",
    "    }\n",
    "}\n",
    "\n",
    "model = teqp.make_model(j)\n",
    "z = np.array([1.0])\n",
    "R = model.get_R(z)\n",
    "T, rho = 400, 2600\n",
    "p = rho*R*T*(1+model.get_Ar01(T, rho, z))\n",
    "display('pressure from ECS:', p)\n",
    "\n",
    "display('pressure from EOS:', CP.PropsSI('P','T',T,'Dmolar',rho,'R143a'))"
   ]
  }
 ],
 "metadata": {
  "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.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}