From 445433a82973066e07833a34bdd232adeff97007 Mon Sep 17 00:00:00 2001
From: Ian Bell <ian.bell@nist.gov>
Date: Thu, 15 Sep 2022 10:08:38 -0600
Subject: [PATCH] Add example of multifluid ancillary + polish for VLE

---
 doc/source/models/multifluid.ipynb | 185 +++++++++++------------------
 1 file changed, 70 insertions(+), 115 deletions(-)

diff --git a/doc/source/models/multifluid.ipynb b/doc/source/models/multifluid.ipynb
index 1aa9451..f518f1d 100644
--- a/doc/source/models/multifluid.ipynb
+++ b/doc/source/models/multifluid.ipynb
@@ -11,7 +11,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 1,
+   "execution_count": null,
    "metadata": {
     "execution": {
      "iopub.execute_input": "2022-07-06T18:40:06.606089Z",
@@ -20,18 +20,7 @@
      "shell.execute_reply": "2022-07-06T18:40:07.146669Z"
     }
    },
-   "outputs": [
-    {
-     "data": {
-      "text/plain": [
-       "'0.9.2'"
-      ]
-     },
-     "execution_count": 1,
-     "metadata": {},
-     "output_type": "execute_result"
-    }
-   ],
+   "outputs": [],
    "source": [
     "import timeit, json\n",
     "import pandas\n",
@@ -40,6 +29,58 @@
     "teqp.__version__"
    ]
   },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "## Ancillary Equations"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "Ancillary equations are provided along with multiparameter equations of state. The give a good *approximation* to the phase equilibrium densities.  There are routines in teqp to use the ancillary equations provided with the EOS. First a class containing the ancillary equations is obtained, then methods on that class are called"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "model = teqp.build_multifluid_model([\"Methane\"], teqp.get_datapath())\n",
+    "anc = model.build_ancillaries()\n",
+    "T = 100.0 # [K]\n",
+    "rhoL, rhoV = anc.rhoL(T), anc.rhoV(T)\n",
+    "print('Densities are:', rhoL, rhoV, 'mol/m^3')"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "But those densities do not correspond to the *true* phase equilibrium solution, so we need to polish the solution:"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "Niter = 10\n",
+    "rhoLtrue, rhoVtrue = model.pure_VLE_T(T, rhoL, rhoV, Niter)\n",
+    "print('VLE densities are:', rhoLtrue, rhoVtrue, 'mol/m^3')"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "And looking the densities, they are slightly different after the phase equilibrium calculation"
+   ]
+  },
   {
    "cell_type": "markdown",
    "metadata": {},
@@ -49,7 +90,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 2,
+   "execution_count": null,
    "metadata": {
     "execution": {
      "iopub.execute_input": "2022-07-06T18:40:07.163785Z",
@@ -58,15 +99,7 @@
      "shell.execute_reply": "2022-07-06T18:40:17.278333Z"
     }
    },
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "12.9 ms ± 4.32 ms per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "# By default teqp looks for fluids relative to the set of fluids in ROOT/dev/fluids\n",
     "# The name (case-sensitive) should match the .json file, without the json extension.\n",
@@ -75,7 +108,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 3,
+   "execution_count": null,
    "metadata": {
     "execution": {
      "iopub.execute_input": "2022-07-06T18:40:17.286031Z",
@@ -84,15 +117,7 @@
      "shell.execute_reply": "2022-07-06T18:40:27.299050Z"
     }
    },
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "120 ms ± 19.9 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "# And if you provide valid aliases, alias lookup will be used to resolve the name\n",
     "# But beware, this is rather a lot slower than the above because all fluid files need to be read\n",
@@ -109,7 +134,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 4,
+   "execution_count": null,
    "metadata": {
     "execution": {
      "iopub.execute_input": "2022-07-06T18:40:27.307115Z",
@@ -118,15 +143,7 @@
      "shell.execute_reply": "2022-07-06T18:40:34.875146Z"
     }
    },
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "85.4 ms ± 12.3 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "# Here is the set of possible aliases to absolute paths of files\n",
     "# Building this map takes a little while (somewhat faster in C++) due to all the file reads\n",
@@ -137,7 +154,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 5,
+   "execution_count": null,
    "metadata": {
     "execution": {
      "iopub.execute_input": "2022-07-06T18:40:34.879157Z",
@@ -146,15 +163,7 @@
      "shell.execute_reply": "2022-07-06T18:40:42.930079Z"
     }
    },
-   "outputs": [
-    {
-     "name": "stdout",
-     "output_type": "stream",
-     "text": [
-      "9.9 ms ± 164 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "# Then load the absolute paths from the alias map, \n",
     "# which will guarantee that you hit exactly what you were looking for,\n",
@@ -172,7 +181,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 6,
+   "execution_count": null,
    "metadata": {
     "execution": {
      "iopub.execute_input": "2022-07-06T18:40:42.932720Z",
@@ -196,7 +205,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 7,
+   "execution_count": null,
    "metadata": {
     "execution": {
      "iopub.execute_input": "2022-07-06T18:40:42.949975Z",
@@ -213,7 +222,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 8,
+   "execution_count": null,
    "metadata": {
     "execution": {
      "iopub.execute_input": "2022-07-06T18:40:42.965595Z",
@@ -222,28 +231,7 @@
      "shell.execute_reply": "2022-07-06T18:40:42.977232Z"
     }
    },
-   "outputs": [
-    {
-     "data": {
-      "text/plain": [
-       "{'BibTeX': 'Kunz-JCED-2012',\n",
-       " 'CAS1': '74-82-8',\n",
-       " 'CAS2': '74-84-0',\n",
-       " 'F': 1.0,\n",
-       " 'Name1': 'Methane',\n",
-       " 'Name2': 'Ethane',\n",
-       " 'betaT': 0.996336508,\n",
-       " 'betaV': 0.997547866,\n",
-       " 'function': 'Methane-Ethane',\n",
-       " 'gammaT': 1.049707697,\n",
-       " 'gammaV': 1.006617867}"
-      ]
-     },
-     "execution_count": 8,
-     "metadata": {},
-     "output_type": "execute_result"
-    }
-   ],
+   "outputs": [],
    "source": [
     "# You can obtain interaction parameters either by pairs of names, where name is the name that teqp uses, the [\"INFO\"][\"NAME\"] field\n",
     "params, swap_needed = teqp.get_BIPdep(BIP, ['Methane','Ethane'])\n",
@@ -252,7 +240,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 9,
+   "execution_count": null,
    "metadata": {
     "execution": {
      "iopub.execute_input": "2022-07-06T18:40:42.981288Z",
@@ -261,28 +249,7 @@
      "shell.execute_reply": "2022-07-06T18:40:42.993281Z"
     }
    },
-   "outputs": [
-    {
-     "data": {
-      "text/plain": [
-       "{'BibTeX': 'Kunz-JCED-2012',\n",
-       " 'CAS1': '74-82-8',\n",
-       " 'CAS2': '74-84-0',\n",
-       " 'F': 1.0,\n",
-       " 'Name1': 'Methane',\n",
-       " 'Name2': 'Ethane',\n",
-       " 'betaT': 0.996336508,\n",
-       " 'betaV': 0.997547866,\n",
-       " 'function': 'Methane-Ethane',\n",
-       " 'gammaT': 1.049707697,\n",
-       " 'gammaV': 1.006617867}"
-      ]
-     },
-     "execution_count": 9,
-     "metadata": {},
-     "output_type": "execute_result"
-    }
-   ],
+   "outputs": [],
    "source": [
     "# Or also by CAS#\n",
     "params, swap_needed = teqp.get_BIPdep(BIP, ['74-82-8','74-84-0'])\n",
@@ -291,7 +258,7 @@
   },
   {
    "cell_type": "code",
-   "execution_count": 10,
+   "execution_count": null,
    "metadata": {
     "execution": {
      "iopub.execute_input": "2022-07-06T18:40:42.996338Z",
@@ -303,19 +270,7 @@
      "raises-exception"
     ]
    },
-   "outputs": [
-    {
-     "ename": "ValueError",
-     "evalue": "Can't match the binary pair for: 74-82-8/Ethane",
-     "output_type": "error",
-     "traceback": [
-      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
-      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
-      "Input \u001b[1;32mIn [10]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# But mixing is not allowed\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m params, swap_needed \u001b[38;5;241m=\u001b[39m \u001b[43mteqp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_BIPdep\u001b[49m\u001b[43m(\u001b[49m\u001b[43mBIP\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m74-82-8\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mEthane\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m      3\u001b[0m params\n",
-      "\u001b[1;31mValueError\u001b[0m: Can't match the binary pair for: 74-82-8/Ethane"
-     ]
-    }
-   ],
+   "outputs": [],
    "source": [
     "# But mixing is not allowed\n",
     "params, swap_needed = teqp.get_BIPdep(BIP, ['74-82-8','Ethane'])\n",
-- 
GitLab