{ "cells": [ { "cell_type": "markdown", "id": "cell-00", "metadata": {}, "source": [ "# Methane–ethane phase equilibrium\n", "\n", "\n", "**Evidence: numerical verification.** A bubble point fixes liquid composition\n", "and solves pressure; a flash fixes temperature, pressure and total feed and\n", "solves phase amounts and compositions.\n", "\n", "Read `gross-2001-methane-ethane/3`, based on Gross and Sadowski (2001), Table 2\n", "([paper](https://doi.org/10.1021/ie0003887)). Retain the packet's mixture inputs.\n", "The bubble calculation uses 200 K and liquid mole fractions 0.3/0.7.\n", "The flash uses 250 K, 3.75 MPa and 0.3 mol methane + 0.7 mol ethane.\n" ] }, { "cell_type": "markdown", "id": "cell-01", "metadata": {}, "source": [ "## Read the inputs\n", "\n", "Use a repository checkout with the environment described in the installation\n", "guide. The wheel alone does not contain these data. All density, association,\n", "equilibrium and parameter-fit iterations below run in the native Engine.\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "cell-02", "metadata": { "execution": { "iopub.execute_input": "2026-10-20T20:17:33.249097Z", "iopub.status.busy": "2026-10-20T20:17:33.248925Z", "iopub.status.idle": "2026-10-20T20:17:33.574671Z", "shell.execute_reply": "2026-10-20T20:17:33.573852Z" } }, "outputs": [], "source": [ "from pathlib import Path\n", "import pandas as pd\n", "from IPython.display import display\n", "from epcsaft import (\n", " Parameters,\n", " Mixture,\n", ")\n", "from epcsaft import equilibrium as eq\n", "\n", "pd.set_option(\"display.max_columns\", None)\n", "pd.set_option(\"display.max_colwidth\", None)\n", "\n", "ROOT = next(\n", " folder\n", " for folder in (Path.cwd(), *Path.cwd().parents)\n", " if (folder / \"ARCHITECTURE.yaml\").is_file()\n", ")\n", "PACKETS = ROOT / \"data\" / \"packets\"\n", "\n", "\n", "def equilibrium_values(solved):\n", " \"\"\"Keep the returned physical state and the equation residuals together.\"\"\"\n", " assert solved.success, solved.message\n", " assert solved.requested_tolerance_met\n", " assert solved.classified_residuals\n", " residual = max(map(abs, solved.classified_residuals), default=0)\n", " assert residual <= 1e-10\n", " return dict(\n", " temperature_K=solved.temperature,\n", " pressure_Pa=solved.pressure,\n", " amounts_mol=solved.amounts,\n", " mole_fractions=solved.mole_fractions,\n", " molar_densities_mol_m3=solved.molar_densities,\n", " residual=residual,\n", " linear_solver=solved.linear_solver,\n", " )\n" ] }, { "cell_type": "markdown", "id": "cell-03", "metadata": {}, "source": [ "## Declare both equilibrium problems\n", "\n", "The incipient vapor in the bubble declaration has zero amount. In the flash,\n", "both phase amounts are unknown. Arrays are phase-major: two component values\n", "for vapor followed by two for liquid, in methane/ethane order.\n", "\n", "Check bubble pressure and flash vapor amount against the retained numerical\n", "baselines at 10⁻¹⁰ relative, and each component balance within 10⁻¹⁰ mol.\n", "Classified equation residuals must also be at most 10⁻¹⁰.\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "cell-04", "metadata": { "execution": { "iopub.execute_input": "2026-10-20T20:17:33.576718Z", "iopub.status.busy": "2026-10-20T20:17:33.576510Z", "iopub.status.idle": "2026-10-20T20:17:33.592937Z", "shell.execute_reply": "2026-10-20T20:17:33.592068Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
PhaseAmount / molx methane / 1x ethane / 1
0Vapor0.1646590.5915500.408450
1Liquid0.8353410.2425310.757469
\n", "
" ], "text/plain": [ " Phase Amount / mol x methane / 1 x ethane / 1\n", "0 Vapor 0.164659 0.591550 0.408450\n", "1 Liquid 0.835341 0.242531 0.757469" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "model = Mixture(\n", " Parameters.from_json(\n", " PACKETS / \"gross-2001-methane-ethane/3/parameters/parameters.json\",\n", " components=[\"methane\", \"ethane\"],\n", " )\n", ")\n", "bubble = eq.solve_equilibrium(\n", " model,\n", " eq.bubble_point(\n", " liquid=eq.Phase(\"L\", kind=\"liquid\"),\n", " T=200,\n", " feed=eq.MoleFractions({\"methane\": 0.3, \"ethane\": 0.7}),\n", " ),\n", ")\n", "flash = eq.solve_equilibrium(\n", " model,\n", " eq.Problem(\n", " phases=[eq.Phase(\"V\", kind=\"vapor\"), eq.Phase(\"L\", kind=\"liquid\")],\n", " T=250,\n", " P=3750000.0,\n", " feed=eq.Amounts({\"methane\": 0.3, \"ethane\": 0.7}),\n", " ),\n", ")\n", "closure = [\n", " sum((flash.amounts[j] * flash.mole_fractions[2 * j + i] for j in range(2))) - v\n", " for i, v in enumerate((0.3, 0.7))\n", "]\n", "assert max(map(abs, closure)) < 1e-10\n", "assert abs(bubble.pressure / 1695742.8953910777 - 1) < 1e-10\n", "assert abs(flash.amounts[0] / 0.16465931077561355 - 1) < 1e-10\n", "values = dict(\n", " bubble=equilibrium_values(bubble),\n", " flash=equilibrium_values(flash),\n", " component_balance_mol=closure,\n", ")\n", "display(\n", " pd.DataFrame(\n", " {\n", " \"Phase\": [\"Vapor\", \"Liquid\"],\n", " \"Amount / mol\": flash.amounts,\n", " \"x methane / 1\": flash.mole_fractions[::2],\n", " \"x ethane / 1\": flash.mole_fractions[1::2],\n", " }\n", " )\n", ")\n" ] }, { "cell_type": "code", "execution_count": 3, "id": "cell-06", "metadata": { "execution": { "iopub.execute_input": "2026-10-20T20:17:33.594741Z", "iopub.status.busy": "2026-10-20T20:17:33.594521Z", "iopub.status.idle": "2026-10-20T20:17:33.602777Z", "shell.execute_reply": "2026-10-20T20:17:33.600855Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Temperature / KPressure / PaPhase amounts / molMole fractions / 1Phase densities / mol m^-3Maximum classified residual / 1Linear solver
Bubble200.01.695743e+06[1.0, 0.0][0.3, 0.7, 0.8673216367151354, 0.13267836328486465][18178.421861210227, 1205.1400298939852]1.776357e-15
Flash250.03.750000e+06[0.16465931077561355, 0.8353406892243862][0.591550247299066, 0.4084497527009339, 0.24253067832563274, 0.7574693216743672][2561.9512915879263, 14724.75225013111]2.038041e-15
\n", "
" ], "text/plain": [ " Temperature / K Pressure / Pa \\\n", "Bubble 200.0 1.695743e+06 \n", "Flash 250.0 3.750000e+06 \n", "\n", " Phase amounts / mol \\\n", "Bubble [1.0, 0.0] \n", "Flash [0.16465931077561355, 0.8353406892243862] \n", "\n", " Mole fractions / 1 \\\n", "Bubble [0.3, 0.7, 0.8673216367151354, 0.13267836328486465] \n", "Flash [0.591550247299066, 0.4084497527009339, 0.24253067832563274, 0.7574693216743672] \n", "\n", " Phase densities / mol m^-3 \\\n", "Bubble [18178.421861210227, 1205.1400298939852] \n", "Flash [2561.9512915879263, 14724.75225013111] \n", "\n", " Maximum classified residual / 1 Linear solver \n", "Bubble 1.776357e-15 \n", "Flash 2.038041e-15 " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
ComponentFlash component balance error / mol
0methane-5.551115e-17
1ethane-2.220446e-16
\n", "
" ], "text/plain": [ " Component Flash component balance error / mol\n", "0 methane -5.551115e-17\n", "1 ethane -2.220446e-16" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "display(pd.DataFrame(\n", " [values[\"bubble\"], values[\"flash\"]], index=[\"Bubble\", \"Flash\"]\n", ").rename(columns={\n", " \"temperature_K\": \"Temperature / K\",\n", " \"pressure_Pa\": \"Pressure / Pa\",\n", " \"amounts_mol\": \"Phase amounts / mol\",\n", " \"mole_fractions\": \"Mole fractions / 1\",\n", " \"molar_densities_mol_m3\": \"Phase densities / mol m^-3\",\n", " \"residual\": \"Maximum classified residual / 1\",\n", " \"linear_solver\": \"Linear solver\",\n", " }))\n", "display(pd.DataFrame({\n", " \"Component\": [\"methane\", \"ethane\"],\n", " \"Flash component balance error / mol\": closure,\n", "}))\n" ] }, { "cell_type": "markdown", "id": "cell-05", "metadata": {}, "source": [ "## Meaning and limits\n", "\n", "\n", "The bubble pressure and flash split are source-parameter predictions with\n", "unquantified model uncertainty. Agreement with the retained Engine baseline\n", "is numerical verification. No measured mixture data or global phase-stability\n", "certificate is used in this example.\n" ] } ], "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.13.14" } }, "nbformat": 4, "nbformat_minor": 5 }