{ "cells": [ { "cell_type": "markdown", "id": "03058ac5", "metadata": {}, "source": [ "# Multifluid+Association\n", "\n", "Version 0.22 of teqp adds a new sort of hybrid model -- a combination of multifluid model plus an association model. Conceptually the pure fluid EOS consider the self-association implicitly, so you may want to consider the association model to only allow cross-assocation, which be enforced by supplying the \"self_assocation_mask\" logical mask in the \"options\" of the model. See below" ] }, { "cell_type": "code", "execution_count": 1, "id": "ae2f6b60", "metadata": { "execution": { "iopub.execute_input": "2024-10-29T15:24:20.442635Z", "iopub.status.busy": "2024-10-29T15:24:20.442138Z", "iopub.status.idle": "2024-10-29T15:24:21.272526Z", "shell.execute_reply": "2024-10-29T15:24:21.271853Z" } }, "outputs": [ { "ename": "ValueError", "evalue": "Don't understand \"kind\" of: multifluid-association", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[1], line 46\u001b[0m\n\u001b[1;32m 20\u001b[0m jassoc \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 21\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mkind\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDufal\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 22\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmodel\u001b[39m\u001b[38;5;124m\"\u001b[39m: {\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 35\u001b[0m }\n\u001b[1;32m 36\u001b[0m }\n\u001b[1;32m 38\u001b[0m j \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 39\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mkind\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmultifluid-association\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 40\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmodel\u001b[39m\u001b[38;5;124m'\u001b[39m: {\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 43\u001b[0m }\n\u001b[1;32m 44\u001b[0m }\n\u001b[0;32m---> 46\u001b[0m model \u001b[38;5;241m=\u001b[39m \u001b[43mteqp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmake_model\u001b[49m\u001b[43m(\u001b[49m\u001b[43mj\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/checkouts/readthedocs.org/user_builds/teqp/conda/stable/lib/python3.11/site-packages/teqp/__init__.py:47\u001b[0m, in \u001b[0;36mmake_model\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 42\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mmake_model\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 43\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 44\u001b[0m \u001b[38;5;124;03m This function is in two parts; first the make_model function (renamed to _make_model in the Python interface)\u001b[39;00m\n\u001b[1;32m 45\u001b[0m \u001b[38;5;124;03m is used to make the model and then the model-specific methods are attached to the instance\u001b[39;00m\n\u001b[1;32m 46\u001b[0m \u001b[38;5;124;03m \"\"\"\u001b[39;00m\n\u001b[0;32m---> 47\u001b[0m AS \u001b[38;5;241m=\u001b[39m \u001b[43m_make_model\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 48\u001b[0m attach_model_specific_methods(AS)\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m AS\n", "\u001b[0;31mValueError\u001b[0m: Don't understand \"kind\" of: multifluid-association" ] } ], "source": [ "import teqp, json, numpy as np\n", "import matplotlib.pyplot as plt\n", "import pandas \n", "\n", "BIP = [{\n", " \"Name1\": \"Water\",\n", " \"Name2\": \"Ammonia\",\n", " \"betaT\": 1.0,\n", " \"gammaT\": 1.0,\n", " \"betaV\": 1.0,\n", " \"gammaV\": 1.0,\n", " \"F\": 0.0\n", "}]\n", "jmf = {\n", " \"components\": [\"Water\", \"Ammonia\"],\n", " \"root\": teqp.get_datapath(),\n", " \"BIP\": BIP, \n", "}\n", "\n", "jassoc = {\n", " \"kind\": \"Dufal\",\n", " \"model\": {\n", " \"sigma / m\": [3.0555e-10, 3.3309e-10],\n", " \"epsilon / J/mol\": [3475.445374388054, 323.70*8.3124462618],\n", " \"lambda_r\": [35.823, 36.832],\n", " \n", " # Note the scaling factors of 0.2 on the bonding energy to yield more reasonable behavior\n", " \"epsilon_HB / J/mol\": [0.2*13303.140189045183, 0.2*1105.0*8.314462618], \n", " \n", " \"K_HB / m^3\": [496.66e-30, 560.73e-30],\n", " \"kmat\": [[0.0,0.0],[0.0, 0.0]],\n", " \"Delta_rule\": \"Dufal\",\n", " \"molecule_sites\": [[\"e\",\"e\",\"H\",\"H\"],[\"e\",\"H\",\"H\",\"H\"]],\n", " \"options\": {\"self_association_mask\": [False, False]}\n", " }\n", "}\n", " \n", "j = {\n", " 'kind': 'multifluid-association',\n", " 'model': {\n", " 'multifluid': jmf,\n", " 'association': jassoc\n", " }\n", "}\n", "\n", "model = teqp.make_model(j)" ] }, { "cell_type": "code", "execution_count": 2, "id": "469bdad6", "metadata": { "execution": { "iopub.execute_input": "2024-10-29T15:24:21.274823Z", "iopub.status.busy": "2024-10-29T15:24:21.274571Z", "iopub.status.idle": "2024-10-29T15:24:21.277462Z", "shell.execute_reply": "2024-10-29T15:24:21.276904Z" } }, "outputs": [], "source": [ "# model.get_assoc_calcs(300, 300, np.array([0.5, 0.5]))" ] }, { "cell_type": "code", "execution_count": 3, "id": "3d9a26b9", "metadata": { "execution": { "iopub.execute_input": "2024-10-29T15:24:21.279349Z", "iopub.status.busy": "2024-10-29T15:24:21.279125Z", "iopub.status.idle": "2024-10-29T15:24:21.336569Z", "shell.execute_reply": "2024-10-29T15:24:21.336020Z" } }, "outputs": [ { "ename": "NameError", "evalue": "name 'model' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[3], line 4\u001b[0m\n\u001b[1;32m 2\u001b[0m pure \u001b[38;5;241m=\u001b[39m teqp\u001b[38;5;241m.\u001b[39mbuild_multifluid_model([\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAmmonia\u001b[39m\u001b[38;5;124m\"\u001b[39m], teqp\u001b[38;5;241m.\u001b[39mget_datapath())\n\u001b[1;32m 3\u001b[0m anc \u001b[38;5;241m=\u001b[39m pure\u001b[38;5;241m.\u001b[39mbuild_ancillaries()\n\u001b[0;32m----> 4\u001b[0m j \u001b[38;5;241m=\u001b[39m \u001b[43mmodel\u001b[49m\u001b[38;5;241m.\u001b[39mtrace_VLE_isotherm_binary(T, np\u001b[38;5;241m.\u001b[39marray([\u001b[38;5;241m0\u001b[39m, anc\u001b[38;5;241m.\u001b[39mrhoL(T)]), np\u001b[38;5;241m.\u001b[39marray([\u001b[38;5;241m0\u001b[39m, anc\u001b[38;5;241m.\u001b[39mrhoV(T)]))\n\u001b[1;32m 5\u001b[0m df \u001b[38;5;241m=\u001b[39m pandas\u001b[38;5;241m.\u001b[39mDataFrame(j)\n", "\u001b[0;31mNameError\u001b[0m: name 'model' is not defined" ] } ], "source": [ "T = 293.15 # K\n", "pure = teqp.build_multifluid_model([\"Ammonia\"], teqp.get_datapath())\n", "anc = pure.build_ancillaries()\n", "j = model.trace_VLE_isotherm_binary(T, np.array([0, anc.rhoL(T)]), np.array([0, anc.rhoV(T)]))\n", "df = pandas.DataFrame(j)" ] }, { "cell_type": "code", "execution_count": 4, "id": "e9760392", "metadata": { "execution": { "iopub.execute_input": "2024-10-29T15:24:21.338789Z", "iopub.status.busy": "2024-10-29T15:24:21.338285Z", "iopub.status.idle": "2024-10-29T15:24:21.353298Z", "shell.execute_reply": "2024-10-29T15:24:21.352744Z" } }, "outputs": [ { "ename": "NameError", "evalue": "name 'df' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[4], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m plt\u001b[38;5;241m.\u001b[39mplot(\u001b[43mdf\u001b[49m[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mxL_0 / mole frac.\u001b[39m\u001b[38;5;124m'\u001b[39m], df[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mpL / Pa\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m/\u001b[39m\u001b[38;5;241m1e3\u001b[39m)\n\u001b[1;32m 2\u001b[0m plt\u001b[38;5;241m.\u001b[39mplot(df[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mxV_0 / mole frac.\u001b[39m\u001b[38;5;124m'\u001b[39m], df[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mpL / Pa\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m/\u001b[39m\u001b[38;5;241m1e3\u001b[39m)\n\u001b[1;32m 3\u001b[0m plt\u001b[38;5;241m.\u001b[39myscale(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlog\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", "\u001b[0;31mNameError\u001b[0m: name 'df' is not defined" ] } ], "source": [ "plt.plot(df['xL_0 / mole frac.'], df['pL / Pa']/1e3)\n", "plt.plot(df['xV_0 / mole frac.'], df['pL / Pa']/1e3)\n", "plt.yscale('log')\n", "plt.gca().set(xlabel='$x_1,y_1$ / mole frac.', ylabel='p / kPa')\n", "plt.title(f'Water(1) + Ammonia(2) @ {T} K')\n", "plt.show()" ] } ], "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.10" } }, "nbformat": 4, "nbformat_minor": 5 }