From 5d14e8120d77ba25185ab2cd6c6074ac050d066e Mon Sep 17 00:00:00 2001 From: Ian Bell <ian.bell@nist.gov> Date: Sat, 5 Nov 2022 10:34:00 -0400 Subject: [PATCH] More docs for multifluid things --- doc/source/models/multifluid.ipynb | 248 +++++++++++++++++++--- doc/source/models/multifluid_mutant.ipynb | 93 ++++++++ 2 files changed, 314 insertions(+), 27 deletions(-) create mode 100644 doc/source/models/multifluid_mutant.ipynb diff --git a/doc/source/models/multifluid.ipynb b/doc/source/models/multifluid.ipynb index 414fce8..0dbe1c9 100644 --- a/doc/source/models/multifluid.ipynb +++ b/doc/source/models/multifluid.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2022-07-06T18:40:06.606089Z", @@ -20,7 +20,18 @@ "shell.execute_reply": "2022-07-06T18:40:07.146669Z" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'0.13.0'" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import timeit, json\n", "import pandas\n", @@ -45,9 +56,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Densities are: 27357.335621492966 42.04100696197727 mol/m^3\n" + ] + } + ], "source": [ "model = teqp.build_multifluid_model([\"Methane\"], teqp.get_datapath())\n", "anc = model.build_ancillaries()\n", @@ -65,9 +84,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "VLE densities are: 27357.147019094467 42.047982278351704 mol/m^3\n" + ] + } + ], "source": [ "Niter = 10\n", "rhoLtrue, rhoVtrue = model.pure_VLE_T(T, rhoL, rhoV, Niter)\n", @@ -81,6 +108,36 @@ "And looking the densities, they are slightly different after the phase equilibrium calculation" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Ammonia-Water\n", + "\n", + "Tillner-Roth and Friend provided a hard-coded model that is in a form not compatible with the other multi-fluid models. It is available via the high-level factory function" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-0.09731055757504622" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "AW = teqp.AmmoniaWaterTillnerRoth()\n", + "AW.get_Ar01(300, 300, np.array([0.9, 0.0]))" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -90,7 +147,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": { "execution": { "iopub.execute_input": "2022-07-06T18:40:07.163785Z", @@ -99,7 +156,15 @@ "shell.execute_reply": "2022-07-06T18:40:17.278333Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "320 µs ± 1.2 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)\n" + ] + } + ], "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", @@ -108,7 +173,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": { "execution": { "iopub.execute_input": "2022-07-06T18:40:17.286031Z", @@ -117,7 +182,15 @@ "shell.execute_reply": "2022-07-06T18:40:27.299050Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "18.9 ms ± 72.2 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n" + ] + } + ], "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", @@ -134,7 +207,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "execution": { "iopub.execute_input": "2022-07-06T18:40:27.307115Z", @@ -143,7 +216,34 @@ "shell.execute_reply": "2022-07-06T18:40:34.875146Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "18.5 ms ± 65.1 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n" + ] + }, + { + "data": { + "text/plain": [ + "['1,2-DICHLOROETHANE',\n", + " '1,2-dichloroethane',\n", + " '1-BUTENE',\n", + " '1-Butene',\n", + " '100-41-4',\n", + " '10024-97-2',\n", + " '102687-65-0',\n", + " '106-42-3',\n", + " '106-97-8',\n", + " '106-98-9']" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "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", @@ -155,7 +255,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": { "execution": { "iopub.execute_input": "2022-07-06T18:40:34.879157Z", @@ -164,7 +264,15 @@ "shell.execute_reply": "2022-07-06T18:40:42.930079Z" } }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "317 µs ± 3.85 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)\n" + ] + } + ], "source": [ "# Then load the absolute paths from the alias map, \n", "# which will guarantee that you hit exactly what you were looking for,\n", @@ -182,7 +290,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": { "execution": { "iopub.execute_input": "2022-07-06T18:40:42.932720Z", @@ -206,7 +314,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "execution": { "iopub.execute_input": "2022-07-06T18:40:42.949975Z", @@ -223,7 +331,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": { "execution": { "iopub.execute_input": "2022-07-06T18:40:42.965595Z", @@ -232,7 +340,28 @@ "shell.execute_reply": "2022-07-06T18:40:42.977232Z" } }, - "outputs": [], + "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": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], "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", @@ -241,7 +370,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": { "execution": { "iopub.execute_input": "2022-07-06T18:40:42.981288Z", @@ -250,7 +379,28 @@ "shell.execute_reply": "2022-07-06T18:40:42.993281Z" } }, - "outputs": [], + "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": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Or also by CAS#\n", "params, swap_needed = teqp.get_BIPdep(BIP, ['74-82-8','74-84-0'])\n", @@ -259,7 +409,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": { "execution": { "iopub.execute_input": "2022-07-06T18:40:42.996338Z", @@ -271,7 +421,19 @@ "raises-exception" ] }, - "outputs": [], + "outputs": [ + { + "ename": "ValueError", + "evalue": "Can't match the binary pair for: 74-82-8/Ethane", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn [19], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# But mixing is not allowed\u001b[39;00m\n\u001b[0;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[1;32m 3\u001b[0m params\n", + "\u001b[0;31mValueError\u001b[0m: Can't match the binary pair for: 74-82-8/Ethane" + ] + } + ], "source": [ "# But mixing is not allowed\n", "params, swap_needed = teqp.get_BIPdep(BIP, ['74-82-8','Ethane'])\n", @@ -291,9 +453,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'F': 0.0, 'betaT': 1.0, 'betaV': 1.0, 'gammaT': 1.0, 'gammaV': 1.0}" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "params, swap_needed = teqp.get_BIPdep(BIP, ['74-82-8','74-84-0'], flags={'force-estimate':'yes', 'estimate': 'Lorentz-Berthelot'})\n", "params" @@ -301,9 +474,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "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": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# And without the force, the forcing is ignored\n", "params, swap_needed = teqp.get_BIPdep(BIP, ['74-82-8','74-84-0'], flags={'estimate': 'Lorentz-Berthelot'})\n", @@ -312,7 +506,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, "outputs": [], "source": [ diff --git a/doc/source/models/multifluid_mutant.ipynb b/doc/source/models/multifluid_mutant.ipynb new file mode 100644 index 0000000..2024c37 --- /dev/null +++ b/doc/source/models/multifluid_mutant.ipynb @@ -0,0 +1,93 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "d4e67406", + "metadata": {}, + "source": [ + "# Multfluid mutant\n", + "\n", + "These adapted multifluid models are used for fitting departure functions. The pure fluids remain fixed while you can adjust the mixture model, both the interaction parameters as well as the departure function terms" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3579cfa2", + "metadata": {}, + "outputs": [], + "source": [ + "import teqp, numpy as np\n", + "teqp.__version__" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ee024418", + "metadata": {}, + "outputs": [], + "source": [ + "basemodel = teqp.build_multifluid_model(['Nitrogen','Ethane'], teqp.get_datapath())\n", + "s = {\n", + " \"0\": {\n", + " \"1\": {\n", + " \"BIP\": {\n", + " \"betaT\": 1.1,\n", + " \"gammaT\": 0.9,\n", + " \"betaV\": 1.05,\n", + " \"gammaV\": 1.3,\n", + " \"Fij\": 1.0\n", + " },\n", + " \"departure\":{\n", + " \"type\": \"none\"\n", + " }\n", + " }\n", + " }\n", + "}\n", + "mutant = teqp.build_multifluid_mutant(basemodel, s)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1eeef8db", + "metadata": {}, + "outputs": [], + "source": [ + "%timeit teqp.build_multifluid_mutant(basemodel, s)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "53af2daf", + "metadata": {}, + "outputs": [], + "source": [ + "mutant.get_Ar01(300, 3.0, np.array([0.5, 0.5]))" + ] + } + ], + "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.10.6" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} -- GitLab