{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "*This notebook contains course material from [CBE20255](https://jckantor.github.io/CBE20255)\n", "by Jeffrey Kantor (jeff at nd.edu); the content is available [on Github](https://github.com/jckantor/CBE20255.git).\n", "The text is released under the [CC-BY-NC-ND-4.0 license](https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode),\n", "and code is released under the [MIT license](https://opensource.org/licenses/MIT).*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [Vapors and Gases](http://nbviewer.jupyter.org/github/jckantor/CBE20255/blob/master/notebooks/06.00-Vapors-and-Gases.ipynb) | [Contents](toc.ipynb) | [Hydrogen Storage in a Fuel Cell Vehicle](http://nbviewer.jupyter.org/github/jckantor/CBE20255/blob/master/notebooks/06.02-Hydrogen-Storage-for-a-Fuel-Cell-Vehicle.ipynb) >

\"Open" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "FkC6hCEvEFtr" }, "source": [ "# PVT Computations for Non-ideal Gases\n" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "IQj-Bi8V9WHY" }, "source": [ "## Problem Statement" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "w7FB79_BEYpu" }, "source": [ "Commerical $CO_2$ cartridges have a large number of uses including bicycle tire and life jacket inflators, soda dispensers, compressed gas cleaners for electronic devices, and gas powered guns. They can be purchased at low-cost from sports store and on-line.\n", "\n", "A popular size of $CO_2$ cartridge holds 12g in an internal volume of 17.6 cm$^3$. Estimate the pressure inside the cartridge under hot (40$^\\circ$C = 104$^\\circ$F = 313.15 K) conditions." ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 51 }, "colab_type": "code", "executionInfo": { "elapsed": 244, "status": "ok", "timestamp": 1538738465236, "user": { "displayName": "Jeffrey Kantor", "photoUrl": "", "userId": "09038942003589296665" }, "user_tz": 240 }, "id": "5EHq7-ddDtM3", "outputId": "d06e24b0-8369-426c-f231-25108ca76ea5" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "molar specific volume = 0.0645 liters/gmol\n", "molar density = 15.5 gmol/liter\n" ] } ], "source": [ "# problem data\n", "n = 12/44 # gram-moles\n", "V = 0.0176/n # specific volume in liters/gmol\n", "T = 40 + 273.15 # Kelvin\n", "\n", "# gas constant\n", "R = 0.08206 # gas constant liter-atm per kelvin-gmol\n", "\n", "# critical properties of CO2\n", "Tcritical = 304.25 # Kelvin\n", "Pcritical = 72.9 # atm\n", "acentric_factor = 0.225 # Pitzer acentric factor\n", "\n", "print('molar specific volume =', round(V,4), 'liters/gmol')\n", "print('molar density =', round(1/V, 2), 'gmol/liter')\n", "\n", "# a dictionary to store results\n", "predictions = {}" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "4tGARUGHieKm" }, "source": [ "## Estimating Pressure" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "uZ_y5CERHd9Q" }, "source": [ "### Ideal Gas Law\n", "\n", "Our first attempt at computing the cartridge pressure will use the ideal gas law. Written in terms of molar specific volume\n", "\n", "\\begin{equation}\n", "\\hat{V} = \\frac{V}{n}\n", "\\end{equation}\n", "\n", "the ideal gas law is given by\n", "\n", "\\begin{equation}\n", "P \\hat{V} = R T\n", "\\end{equation}\n", "\n", "Here we solve for $P$ using the problem data. Before going further, decide if the results of this calculation seem realistic to you." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 51 }, "colab_type": "code", "executionInfo": { "elapsed": 400, "status": "ok", "timestamp": 1538737043217, "user": { "displayName": "Jeffrey Kantor", "photoUrl": "", "userId": "09038942003589296665" }, "user_tz": 240 }, "id": "P5QaEtm6EYFc", "outputId": "f06a9e66-fd1c-4954-b824-c834864a62a6" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CO2 Pressure (Ideal Gas) = 398.2 atm\n", "CO2 Pressure (Ideal Gas) = 5851.9 psia\n" ] } ], "source": [ "P_ideal_gas = R*T/V\n", "\n", "predictions['Ideal Gas'] = P_ideal_gas\n", "\n", "print('CO2 Pressure (Ideal Gas) =', round(P_ideal_gas, 1), 'atm')\n", "print('CO2 Pressure (Ideal Gas) =', round(14.696*P_ideal_gas, 1), 'psia')\n" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "9wEkGuGMHsGa" }, "source": [ "### [Compressiblity Charts](http://eon.sdsu.edu/testhome/Test/solve/basics/tables/tablesRG/zNO.html)\n", "\n", "Compressibility is defined as\n", "\n", "\\begin{equation}\n", "z = \\frac{P\\hat{V}}{RT}\n", "\\end{equation}\n", "\n", "which, by definition, has a value $z=1$ for an ideal gas. Real gases display a significant deviation from 1, generally increasing with increasing pressure as the gas molecules get closer together, and decreasing with temperature.\n", "\n", "The [principle of corresponding states](https://pubs.acs.org/doi/abs/10.1021/ed081p142), developed by Johannes Diderik van der Waals in 1873, correlates the compressibility of real gases to the critical temperature $T_c$ and critical pressure $P_c$. For this purpose, the **reduced temperature** $T_r$ and **reduced pressure** $P_r$ are defined as\n", "\n", "\\begin{align*}\n", "T_r & = \\frac{T}{T_c}\\\\\n", "P_r & = \\frac{P}{P_c}\n", "\\end{align*}\n", "\n", "A [compressibility chart](http://eon.sdsu.edu/testhome/Test/solve/basics/tables/tablesRG/zNO.html) presents the averaged compressibility measured for a number of species. Given values of the reduced temperature and pressure, $T_r$ and $P_r$, one locates the value of compressibility factor $z$, then use the above relationship to compute molar volume $\\hat{V}$.\n", "\n", "![Generalized Compressibility Chart](http://eon.sdsu.edu/testhome/Test/solve/basics/tables/tablesRG/zNO7.png)\n", "\n", "For the case where $\\hat{V}$ is one of the known variables it is convenient to define an **ideal reduced volume**. The first step is to define an ideal critical volume\n", "\n", "\\begin{equation}\n", "\\hat{V}^{ideal}_c = \\frac{RT_c}{P_c}\n", "\\end{equation}\n", "\n", "The reason for the superscript 'ideal' is because this is a ficti\n", "\n", "Then the ideal reduced volume $\\hat{V}^{ideal}_r$ is \n", "\n", "\\begin{equation}\n", "\\hat{V}^{ideal}_r = \\frac{\\hat{V}}{\\hat{V}_c} = \\frac{P_c\\hat{V}}{RT_c}\n", "\\end{equation}\n", "\n", "The compressibility chart is augmented with contours of constant $\\hat{V}^{ideal}_r$. Given values for $\\hat{V}^{ideal}_r$ and either $P_r$ or $T_r$, a corresponding value of $z$ is located. The compressibility definition is then used to solve for the unknown variable." ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 51 }, "colab_type": "code", "executionInfo": { "elapsed": 255, "status": "ok", "timestamp": 1538747578616, "user": { "displayName": "Jeffrey Kantor", "photoUrl": "", "userId": "09038942003589296665" }, "user_tz": 240 }, "id": "6xJDrFEoHg56", "outputId": "4fb0c60b-5335-4c89-a14b-db61c047c7fd" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "reduced temperature = 1.03\n", "ideal reduced volume = 0.19\n" ] } ], "source": [ "Tr = T/Tcritical\n", "Vr = Pcritical*V/(R*Tcritical)\n", "\n", "print('reduced temperature =', round(Tr,2))\n", "print('ideal reduced volume =', round(Vr,2))" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 51 }, "colab_type": "code", "executionInfo": { "elapsed": 330, "status": "ok", "timestamp": 1538737044922, "user": { "displayName": "Jeffrey Kantor", "photoUrl": "", "userId": "09038942003589296665" }, "user_tz": 240 }, "id": "tMIiFLIGnXYb", "outputId": "23fdbe76-3afe-43f2-c300-5d112d6ac98a" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CO2 Pressure = 111.5 atm\n", "CO2 Pressure = 1638.54 psia\n" ] } ], "source": [ "# look up values (https://pubs.acs.org/doi/pdf/10.1021/ie50467a036)\n", "z = 0.28\n", "\n", "# compute pressure\n", "P_compressibility = z*R*T/V\n", "\n", "predictions['Compressibility'] = P_compressibility\n", "\n", "\n", "print('CO2 Pressure =', round(P_compressibility, 2), 'atm')\n", "print('CO2 Pressure =', round(14.696*P_compressibility, 2), 'psia')" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "lP53KKPsw0jP" }, "source": [ "While we still can't be sure this estimate is accurate, we can definitely see the estimate based on the ideal gas law is completley off-base. The reason is that the cartridge is filled to a point where the contents are close to the critical point on the phase diagram." ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "nnkELcQcHyW9" }, "source": [ "### Virial Model\n", "\n", "The virial expansion was first proposed by a Kamerlingh Onnes, a physicist who won the Nobel prize in 1911 for his work on superconductivity and liquid helium. (He also coined the work 'enthalpy'). The key idea is to create a infinite series approximation for compressibility in the form\n", "\n", "\\begin{equation}\n", "\\frac{P\\hat{V}}{RT} = A + \\frac{B}{\\hat{V}} + \\frac{C}{\\hat{V}^2} + \\frac{D}{\\hat{V}^3}\\cdots\n", "\\end{equation}\n", "\n", "where $A$, $B$, $C$ are temperature dependent and known as the first, second, and third virial coefficients, respectively. The case $A=1$ and $B=C=D=\\cdots = 0$ corresponds to an ideal gas. \n", "\n", "A commonly used version of this expansion is to assume $A=1$, $B(T)$, and $C=D=\\cdots = 0$, with the further approximation $\\hat{V} = \\frac{RT}{P}$. Then\n", "\n", "\\begin{equation}\n", "\\frac{P\\hat{V}}{RT} = 1 + \\frac{BP}{RT}\n", "\\end{equation}\n", "\n", "This can be simplified to read\n", "\n", "\\begin{equation}\n", "P= \\frac{RT}{\\hat{V}-B}\n", "\\end{equation}\n", "\n", "The temperature dependent value of $B$ is estimated by\n", "\n", "\\begin{align*}\n", "B_0 & = 0.083 - \\frac{0.422}{T_r^{1.6}} \\\\\n", "B_1 & = 0.139 - \\frac{0.172}{T_r^{4.2}} \\\\\n", "B & = \\frac{RT_c}{P_c}\\left(B_0 + \\omega B_1\\right)\n", "\\end{align*}\n", "\n", "$\\omega$ is the **Pitzer acentric factor**, values of which are tabulated in standard sources for chemical data.\n", "\n" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 68 }, "colab_type": "code", "executionInfo": { "elapsed": 427, "status": "ok", "timestamp": 1538737469115, "user": { "displayName": "Jeffrey Kantor", "photoUrl": "", "userId": "09038942003589296665" }, "user_tz": 240 }, "id": "Hqq26DDjD4Sf", "outputId": "14fcf135-6912-4635-d773-004ef37e3542" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "B = -0.11061596372197276\n", "CO2 Pressure = 146.72 atm\n", "CO2 Pressure = 2156.13 psia\n" ] } ], "source": [ "Tr = T/Tcritical\n", "B0 = 0.083 - 0.422/Tr**1.6\n", "B1 = 0.139 - 0.172/Tr**4.2\n", "B = (R*Tcritical/Pcritical)*(B0 + acentric_factor*B1)\n", "print('B =', B)\n", "\n", "P_virial = R*T/(V - B)\n", "\n", "predictions['Virial'] = P_virial\n", "\n", "print('CO2 Pressure =', round(P_virial, 2), 'atm')\n", "print('CO2 Pressure =', round(14.696*P_virial, 2), 'psia')" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "fCxUmTcWH49i" }, "source": [ "### van der Waals Equation of State\n", "\n", "The **van der Waals** equation of state has the form\n", "\n", "\\begin{equation}\n", "P = \\frac{RT}{\\hat{V} - b} - \\frac{a}{\\hat{V}^2}\n", "\\end{equation}\n", "\n", "where values for the coefficients $a$ and $b$ are determined by the critical point temperature and pressure\n", "\n", "\\begin{equation}\n", "a = \\frac{27 R^2 T_c^2}{64 P_c}\\qquad b = \\frac{RT_c}{8P_c}\n", "\\end{equation}\n", "\n", "The parameter $a$ accounts for long-range attractive forces acting between molecules, and $b$ for short-range repulsive forces." ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 68 }, "colab_type": "code", "executionInfo": { "elapsed": 270, "status": "ok", "timestamp": 1538737499545, "user": { "displayName": "Jeffrey Kantor", "photoUrl": "", "userId": "09038942003589296665" }, "user_tz": 240 }, "id": "u6Hdcm9eEVxR", "outputId": "395a6260-58e0-4c0c-92a8-b4e485386316" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "a = 3.6072850418404214 b = 0.042809936556927296\n", "CO2 Pressure = 316.73 atm\n", "CO2 Pressure = 4654.72 psia\n" ] } ], "source": [ "a = 27*R**2*Tcritical**2/(64*Pcritical)\n", "b = R*Tcritical/(8*Pcritical)\n", "print('a =', a, ' b =', b)\n", "\n", "P_vdw = R*T/(V-b) - a/V**2\n", "\n", "predictions['van der Waals'] = P_vdw\n", "\n", "print('CO2 Pressure =', round(P_vdw, 2), 'atm')\n", "print('CO2 Pressure =', round(14.696*P_vdw, 2), 'psia')" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "CEK9iOfMH8wn" }, "source": [ "### Soave-Redlich-Kwong Equation of State\n", "\n", "The Soave-Redlick-Kwong equation of state is one of most widely used equations of states, and proven to be applicable to a wide variety of systems. The general expression\n", "\n", "\\begin{equation}\n", "P = \\frac{RT}{\\hat{V}-b} - \\frac{\\alpha a}{\\hat{V}(\\hat{V}+b)}\n", "\\end{equation}\n", "\n", "where the parameters are given by\n", "\n", "\\begin{align*}\n", "a & = 0.42747 \\frac{(RT_c)^2}{P_c} \\\\\n", "b & = 0.08664 \\frac{RT_c}{P_c} \\\\\n", "m & = 0.48508 + 1.55171\\omega - 0.1561\\omega^2\\\\\n", "T_r & = \\frac{T}{T_c}\\\\\n", "\\alpha & = \\left[1 + m(1 - \\sqrt{T_r})\\right]^2\n", "\\end{align*}" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 51 }, "colab_type": "code", "executionInfo": { "elapsed": 262, "status": "ok", "timestamp": 1538737049697, "user": { "displayName": "Jeffrey Kantor", "photoUrl": "", "userId": "09038942003589296665" }, "user_tz": 240 }, "id": "Mu8QqJmoINiz", "outputId": "940a851f-f2ff-4c01-cf1a-34322c2714ec" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CO2 Pressure = 150.24 atm\n", "CO2 Pressure = 2207.97 psia\n" ] } ], "source": [ "from math import sqrt\n", "\n", "a = 0.42747*(R*Tcritical)**2/Pcritical\n", "b = 0.08664*R*Tcritical/Pcritical\n", "m = 0.48508 + 1.5517*acentric_factor - 0.1561*acentric_factor**2\n", "Tr = T/Tcritical\n", "alpha = (1 + m*(1-sqrt(Tr)))**2\n", "\n", "P_srk = R*T/(V-b) - alpha*a/V/(V+b)\n", "\n", "predictions['SRK'] = P_srk\n", "\n", "print('CO2 Pressure =', round(P_srk, 2), 'atm')\n", "print('CO2 Pressure =', round(14.696*P_srk, 2), 'psia')\n" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "7LvCb7TUIOOd" }, "source": [ "### Reference Data from NIST Webbook\n", "\n", "The National Institute of Standards and Technology (NIST) maintains a web site devoted to the distribution of standard reference data. The [NIST Chemistry WebBook](https://webbook.nist.gov/chemistry/) is an excellent source of carefully curated data on over 7000 organic and small inorganic compounds.\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "3yE6nSQ38wuy" }, "source": [ "[NIST Fluid Properties Data for $CO_2$](https://webbook.nist.gov/cgi/fluid.cgi?ID=C124389&Action=Page)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "colab_type": "code", "executionInfo": { "elapsed": 260, "status": "ok", "timestamp": 1538737051345, "user": { "displayName": "Jeffrey Kantor", "photoUrl": "", "userId": "09038942003589296665" }, "user_tz": 240 }, "id": "3-jialtrIRDy", "outputId": "d4df8b85-1845-4431-dc14-def7438a2521" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "density = 15.495867768595039 mol/liter\n" ] } ], "source": [ "print('density =', 1/V, 'mol/liter')" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 51 }, "colab_type": "code", "executionInfo": { "elapsed": 437, "status": "ok", "timestamp": 1538738405820, "user": { "displayName": "Jeffrey Kantor", "photoUrl": "", "userId": "09038942003589296665" }, "user_tz": 240 }, "id": "rVQLd-NR1sXa", "outputId": "9705aaa0-c305-4e19-fe98-c495b7673772" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CO2 Pressure = 108.13 atm\n", "CO2 Pressure = 1589.08 atm\n" ] } ], "source": [ "P_nist = 108.13 # atm\n", "\n", "predictions['NIST Webbook'] = P_nist\n", "\n", "print('CO2 Pressure =', round(P_nist, 2), 'atm')\n", "print('CO2 Pressure =', round(14.696*P_nist, 2), 'atm')" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "J4cuq0zBiJRL" }, "source": [ "### Comparison of Estimates" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 153 }, "colab_type": "code", "executionInfo": { "elapsed": 329, "status": "ok", "timestamp": 1538738409385, "user": { "displayName": "Jeffrey Kantor", "photoUrl": "", "userId": "09038942003589296665" }, "user_tz": 240 }, "id": "sre8l1aodr2r", "outputId": "4c2760e6-af31-49e1-a56f-82d2f34d52e9" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "EOS Pressure Error\n", "Ideal Gas 398.2 atm 268.3%\n", "Compressibility 111.5 atm 3.1%\n", "Virial 146.7 atm 35.7%\n", "van der Waals 316.7 atm 192.9%\n", "SRK 150.2 atm 38.9%\n", "NIST 108.1 atm 0.0%\n", "NIST Webbook 108.1 atm 0.0%\n" ] } ], "source": [ "print('{0:15s} {1:9s} {2:5s}'.format('EOS', 'Pressure', 'Error'))\n", "\n", "for key,val in predictions.items():\n", " err = 100*(val-P_nist)/P_nist\n", " print('{0:15s} {1:5.1f} atm {2:5.1f}%'.format(key, val, err))\n", " " ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "ol_vToxmYZoe" }, "source": [ "## Non-Ideal Behavior\n", "\n", "How does the $CO_2$ pressure depend on temperature in the range from 30C to 50C?\n" ] }, { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "GaXodmPb439T" }, "source": [ "## Discussion Points\n", "\n", "1. Why is the ideal gas law so wrong?\n", "2. Why do the compressibility charts work so well in this case? Do you expect them to work well in others?\n", "3. How would the calculations change if we were given pressure and temperature, and asked to compute molar volume?\n", "\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [Vapors and Gases](http://nbviewer.jupyter.org/github/jckantor/CBE20255/blob/master/notebooks/06.00-Vapors-and-Gases.ipynb) | [Contents](toc.ipynb) | [Hydrogen Storage in a Fuel Cell Vehicle](http://nbviewer.jupyter.org/github/jckantor/CBE20255/blob/master/notebooks/06.02-Hydrogen-Storage-for-a-Fuel-Cell-Vehicle.ipynb) >

\"Open" ] } ], "metadata": { "colab": { "collapsed_sections": [ "uZ_y5CERHd9Q" ], "name": "PVT_Calculations_Non-Ideal_Gases.ipynb", "provenance": [], "toc_visible": true, "version": "0.3.2" }, "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.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }