summaryrefslogtreecommitdiff
path: root/Chemical_Engineering_Thermodynamics_by_P_Ahuja/ch2_2.ipynb
diff options
context:
space:
mode:
authorThomas Stephen Lee2015-09-04 22:04:10 +0530
committerThomas Stephen Lee2015-09-04 22:04:10 +0530
commit41f1f72e9502f5c3de6ca16b303803dfcf1df594 (patch)
treef4bf726a3e3ce5d7d9ee3781cbacfe3116115a2c /Chemical_Engineering_Thermodynamics_by_P_Ahuja/ch2_2.ipynb
parent9c9779ba21b9bedde88e1e8216f9e3b4f8650b0e (diff)
downloadPython-Textbook-Companions-41f1f72e9502f5c3de6ca16b303803dfcf1df594.tar.gz
Python-Textbook-Companions-41f1f72e9502f5c3de6ca16b303803dfcf1df594.tar.bz2
Python-Textbook-Companions-41f1f72e9502f5c3de6ca16b303803dfcf1df594.zip
add/remove/update books
Diffstat (limited to 'Chemical_Engineering_Thermodynamics_by_P_Ahuja/ch2_2.ipynb')
-rwxr-xr-xChemical_Engineering_Thermodynamics_by_P_Ahuja/ch2_2.ipynb1276
1 files changed, 1276 insertions, 0 deletions
diff --git a/Chemical_Engineering_Thermodynamics_by_P_Ahuja/ch2_2.ipynb b/Chemical_Engineering_Thermodynamics_by_P_Ahuja/ch2_2.ipynb
new file mode 100755
index 00000000..c009ac76
--- /dev/null
+++ b/Chemical_Engineering_Thermodynamics_by_P_Ahuja/ch2_2.ipynb
@@ -0,0 +1,1276 @@
+{
+ "metadata": {
+ "name": "ch2_2",
+ "signature": "sha256:6aa23fb1475338cf467e7afb5732b8b9e456bbb3ad63c14224d73232d920457e"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "\n",
+ "Chapter 2 : Equations of state"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example - 2.2 Page number - 42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "import math\n",
+ "\n",
+ "# Variables\n",
+ "Tc = 647.1;\t\t\t#[K] - Critical temperature\n",
+ "Pc = 220.55;\t\t#[bar] - Critical pressure\n",
+ "Tr = 0.7;\t\t\t# Reduced temperature\n",
+ "\n",
+ "# Calculations\n",
+ "T = Tr*Tc;\t\t\t#[K]\n",
+ "\t\t\t#From steam table%vapour pressure of H2O at T is 10.02 [bar]% as reported in the book\n",
+ "P = 10.02;\t\t\t#[bar]\n",
+ "w = -1-math.log10((P/Pc))\n",
+ "\n",
+ "# Results\n",
+ "print \" The acentric factor (w) of water at given condition is %f \"%w\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The acentric factor (w) of water at given condition is 0.342639 \n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example - 2.3 Page number - 42"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "# Variables\n",
+ "\t\t\t#math.log10(Psat)=8.1122-(1592.864/(t+226.184))\t\t\t# 'Psat' in [mm Hg] and 't' in [c]\n",
+ "Tc = 513.9;\t\t\t#[K] - Critical temperature\n",
+ "Pc = 61.48;\t\t\t#[bar] - Critical pressure\n",
+ "Pc = Pc*10**(5)\t\t\t#[N/m**(2)]\n",
+ "Tr = 0.7;\t\t\t# Reduced temperature\n",
+ "\n",
+ "# Calculations\n",
+ "T = Tr*Tc;\t\t\t#[K] - Temperature\n",
+ "T = T - 273.15;\t\t\t#[C]\n",
+ "P_sat = 10**(8.1122 - (1592.864/(T + 226.184)))\t\t\t#[mm Hg]\n",
+ "P_sat = (P_sat/760)*101325;\t\t\t#[N/m**(2)]\n",
+ "Pr_sat = P_sat/Pc;\n",
+ "w = -1-math.log10(Pr_sat)\t\t\t# Acentric factor\n",
+ "\n",
+ "# Results\n",
+ "print \" The acentric factor (w) for ethanol at given condition is %f\"%w\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The acentric factor (w) for ethanol at given condition is 0.644493\n"
+ ]
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example - 2.4 Page number - 45"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "# Variables\n",
+ "T = 380;\t\t\t#[K] - Temperature\n",
+ "Tc = 562.1;\t\t\t#[K] - Critical temperature\n",
+ "P = 7;\t\t\t#[atm] - Pressure\n",
+ "P = P*101325;\t\t\t#[N/m**(2)]\n",
+ "Pc = 48.3;\t\t\t#[atm] - Critical pressure\n",
+ "Pc = Pc*101325;\t\t\t#[N/m**(2)]\n",
+ "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
+ "w = 0.212;\t\t\t# acentric factor\n",
+ "Tr = T/Tc;\t\t\t# Reduced temperature\n",
+ "\n",
+ "# Calculations and Results\n",
+ "B_0 = 0.083-(0.422/(Tr)**(1.6))\n",
+ "B_1 = 0.139-(0.172/(Tr)**(4.2))\n",
+ "\n",
+ "\t\t\t#We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+ "B = ((B_0+(w*B_1))*(R*Tc))/Pc;\t\t\t#[m**(3)/mol]\n",
+ "print \" The second virial coefficient for benzene is %e m**(3)/mol\"%B\n",
+ "\n",
+ "\t\t\t#Compressibility factor is given by\n",
+ "Z = 1 + ((B*P)/(R*T))\n",
+ "print \" The compressibility factor at 380 K is %f\"%Z\n",
+ "\n",
+ "\t\t\t#We know thar Z=(P*V)/(R/*T)%therfore\n",
+ "V = (Z*R*T)/P;\t\t\t#[m**(3)/mol]\n",
+ "print \" The molar volume is %e m**(3)/mol\"%V\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The second virial coefficient for benzene is -8.267963e-04 m**(3)/mol\n",
+ " The compressibility factor at 380 K is 0.814382\n",
+ " The molar volume is 3.627499e-03 m**(3)/mol\n"
+ ]
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example - 2.5 Page number - 46"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "# Variables\n",
+ "V_1 = 0.3;\t\t\t#[m**(3)]\t\t\t#volume of cylinder\n",
+ "T = 60+273.15;\t\t\t#[K] - Temperature\n",
+ "P = 130*10**(5)\t\t\t#[N/m**(2)] - Pressure\n",
+ "Tc = 305.3;\t\t\t#[K] - Critical temperature\n",
+ "Pc = 48.72*10**(5)\t\t\t#[N/m**(2)] - Critical pressure\n",
+ "w = 0.100;\t\t\t#acentric factor\n",
+ "M = 30.07;\t\t\t#molecular weight of ethane\n",
+ "Tr = T/Tc;\t\t\t# Reduced temperature\n",
+ "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
+ "\n",
+ "# Calculations and Results\n",
+ "B_0 = 0.083-(0.422/(Tr)**(1.6))\n",
+ "B_1 = 0.139-(0.172/(Tr)**(4.2))\n",
+ "\n",
+ "\t\t\t#We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+ "B = ((B_0 + (w*B_1))*(R*Tc))/Pc;\t\t\t#[m**(3)/mol] - Second virial coefficient\n",
+ "Z = 1 + ((B*P)/(R*T))\t\t\t#Compressibility factor\n",
+ "V = (Z*R*T)/P;\t\t\t#[m**(3)/mol] - Molar volume\n",
+ "\n",
+ "\t\t\t#No.of moles in 0.3 m**(3) cylinder is given by\n",
+ "n1 = V_1/V;\t\t\t#[mol]\n",
+ "\n",
+ "\t\t\t#Mass of gas in cylinder is given by \n",
+ "m1 = (n1*M)/1000.;\t\t\t#[kg]\n",
+ "print \" Under actual conditions, the mass of ethane is, %f kg\"%m1\n",
+ "\n",
+ "\t\t\t#Under ideal condition% taking Z = 1%\n",
+ "V_ideal = (R*T)/P;\t\t\t#[m**(3)/mol]\n",
+ "n2 = V_1/V_ideal;\t\t\t#[mol]\n",
+ "m2 = (n2*M)/1000;\t\t\t#[kg]\n",
+ "print \" Under ideal conditions,the mass of ethane is, %f kg\"%m2\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " Under actual conditions, the mass of ethane is, 136.395203 kg\n",
+ " Under ideal conditions,the mass of ethane is, 42.339741 kg\n"
+ ]
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example - 2.6 Page number - 47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "# Variables\n",
+ "T = 373.15;\t\t\t#[K] - Temperature\n",
+ "P = 101325;\t\t\t#[N/m**(2)] - Pressure\n",
+ "Tc = 647.1;\t\t\t#[K] - Critical temperature\n",
+ "Pc = 220.55*10**(5)\t#[N/m**(2)] - Critical pressure\n",
+ "w = 0.345;\t\t\t#acentric factor\n",
+ "Tr = T/Tc;\t\t\t# Reduced temperature\n",
+ "R = 8.314;\t\t\t#[J/mol*K] - UNiversal gas constant\n",
+ "\n",
+ "# Calculations\n",
+ "B_0 = 0.083-(0.422/(Tr)**(1.6))\n",
+ "B_1 = 0.139-(0.172/(Tr)**(4.2))\n",
+ "\n",
+ "\t\t\t#We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+ "B = ((B_0+(w*B_1))*(R*Tc))/Pc;\t\t\t#[m**(3)/mol] - Second virial coefficient\n",
+ "\n",
+ "\t\t\t#We have% Z = 1+(B/V) and Z = (P*V)/(R*T). Substituting the value of Z%we get\n",
+ "\t\t\t# V**(2)-((R*T)/P)*V-((B*R*T)/P)=0 .Solving the quadratic equation by shreedharcharya rule\n",
+ "V1 = (((R*T)/P) + (((R*T)/P)**(2) + 4*1*((B*R*T)/P))**(1./2))/2*1;\n",
+ "\n",
+ "# Results\n",
+ "print \" The molar volume of water vapour is %f m**(3)/mol\"%V1\n",
+ "\n",
+ "\t\t\t#The roots are%V1 = 0.0003670 [m**(3)/mol] and V2 = 0.0302510 [m**(3)/mol].\n",
+ "\t\t\t#As 'V2' is near to ideal volume (0.030618 [m**(3)/mol])%it is taken as the molar volume\n",
+ "\t\t\t#The other root 'V1' hss no physical significance\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The molar volume of water vapour is 0.030251 m**(3)/mol\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example - 2.7 Page number - 47"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "# Variables\n",
+ "T = 50+273.15;\t\t\t#[K] - Temperature\n",
+ "P = 15*10**(5)\t\t\t#[N/m**(2)] - Pressure\n",
+ "Tc = 305.3;\t\t\t#[K] - Critical temperature\n",
+ "Pc = 48.72*10**(5)\t\t\t#[N/m**(2)] - Critical pressure\n",
+ "w = 0.100;\t\t\t# Acentric factor\n",
+ "B = -157.31;\t\t\t#[cm**(3)/mol] - second virial coefficient\n",
+ "B = B*10**(-6)\t\t\t#[m**(3)/mol]\n",
+ "C = 9650;\t\t\t#[cm**(6)/mol**(2)] - third virial coefficient\n",
+ "C = C*10**(-12)\t\t\t#[cm**(6)/mol**(2)]\n",
+ "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
+ "\n",
+ "# Calculations and Results\n",
+ "\t\t\t# (1)\n",
+ "V_1 = (R*T)/P;\t\t\t#[m**(3)/mol] - Molar volume\n",
+ "print \" (1).The molar volume for ideal equation of state is %e m**(3)/mol\"%V_1\n",
+ "\n",
+ "\t\t\t# (2)\n",
+ "Tr = T/Tc;\t\t\t# Reduced temperature\n",
+ "\t\t\t# At this temperature\n",
+ "B_0 = 0.083-(0.422/(Tr)**(1.6))\n",
+ "B_1 = 0.139-(0.172/(Tr)**(4.2))\n",
+ "\n",
+ "\t\t\t# We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+ "B_2 = ((B_0 + (w*B_1))*(R*Tc))/Pc;\t\t\t#[m**(3)/mol]\t\t\t#second virial coefficient\n",
+ "print \" (2).The second virial coefficent using Pitzer correlation is \\\n",
+ "found to be %e m**(3)/mol which is same as given value\"%B_2\n",
+ "\n",
+ "\t\t\t# (3)\n",
+ "\t\t\t# Given (virial equation)%Z=1+(B/V)\n",
+ "V_3 = B + (R*T)/P;\t\t\t#[m**(3)/mol] - Molar volume\n",
+ "print \" (3).The molar volume using virial equation of state is %e m**(3)/mol\"%V_3\n",
+ "\n",
+ "\t\t\t# (4)\n",
+ "\t\t\t# Given (virial equation)%Z = 1 + ((B*P)/(R*T)) + ((C - B**(2))/(R*T)**(2))*P**(2)\n",
+ "V_4 = B + (R*T)/P + ((C - B**(2))/(R*T))*P;\t\t\t# [m**(3)/mol]\n",
+ "print \" (4).The molar volume using given virial equation of state is %e m**(3)/mol\"%V_4\n",
+ "\n",
+ "\t\t\t# (5)\n",
+ "\t\t\t# Given%Z = 1 + (B/V)\n",
+ "\t\t\t# Also%Z = (P*V)/(R*T). Substituting the value of Z%we get\n",
+ "\t\t\t# V**(2)-((R*T)/P)*V-((B*R*T)/P)=0.Solving the quadratic equation\n",
+ "from scipy.optimize import fsolve\n",
+ "def f(V):\n",
+ " global R,T,P,B\n",
+ " return V**(2)-((R*T)/P)*V-((B*R*T)/P)\n",
+ "V_5_1 = fsolve(f,0)\n",
+ "V_5_2 = fsolve(f,1)\n",
+ "\n",
+ "print \" (5).The molar volume using given virial equation of state is %e m**(3)/mol\"%V_5_2\n",
+ "\n",
+ "\t\t\t# The roots are%V_5_1=0.0001743 [m**(3)/mol] and V_5_2=0.0016168 [m**(3)/mol].\n",
+ "\t\t\t# As 'V_2' is near to ideal volume (0.0017911 [m**(3)/mol])%it is taken as the molar volume\n",
+ "\n",
+ "\t\t\t# (6)\n",
+ "\t\t\t# Given%Z = 1 + (B/V) + (C/V**(2))\n",
+ "\t\t\t# Also%Z = (P*V)/(R*T). Substituting the value of Z%we get\n",
+ "\t\t\t# V**(3)-((R*T)/P)*V**(2)-((B*R*T)/P)*V-((C*R*T)/P)=0. Solving the cubic equation\n",
+ "def f1(V):\n",
+ " global P,R,T,B,C\n",
+ " return V**(3)-((R*T)/P)*V**(2)-((B*R*T)/P)*V-((C*R*T)/P)\n",
+ " \n",
+ "V_6_3=fsolve(f1,-1)\n",
+ "V_6_4=fsolve(f1,0)\n",
+ "V_6_5=fsolve(f1,1)\n",
+ "\t\t\t#The above equation has 1 real and 2 imaginary roots. We consider only real root.\n",
+ "print \" (6).The molar volume using given virial equation of state is %e m**(3)/mol\"%V_6_5\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (1).The molar volume for ideal equation of state is 1.791113e-03 m**(3)/mol\n",
+ " (2).The second virial coefficent using Pitzer correlation is found to be -1.573258e-04 m**(3)/mol which is same as given value\n",
+ " (3).The molar volume using virial equation of state is 1.633803e-03 m**(3)/mol\n",
+ " (4).The molar volume using given virial equation of state is 1.625374e-03 m**(3)/mol\n",
+ " (5).The molar volume using given virial equation of state is 1.616848e-03 m**(3)/mol"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "\n",
+ " (6).The molar volume using given virial equation of state is 1.624187e-03 m**(3)/mol\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stderr",
+ "text": [
+ "/home/jovina/virtualenvs/scipy/local/lib/python2.7/site-packages/scipy/optimize/minpack.py:236: RuntimeWarning: The iteration is not making good progress, as measured by the \n",
+ " improvement from the last ten iterations.\n",
+ " warnings.warn(msg, RuntimeWarning)\n"
+ ]
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example - 2.8 Page number - 49"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "T = 0 + 273.15;\t\t\t#[K] - Temperature\n",
+ "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
+ "from numpy import linalg,array\n",
+ "from scipy.stats import linregress\n",
+ "\t\t\t#Virial equation of state% Z=1+(B/V)+(C/V**(2))\n",
+ "\t\t\t#From above equation we get (Z-1)*V=B+(C/V)\n",
+ "\n",
+ "P=[50,100,200,400,600,1000];\n",
+ "Z=[0.9846,1.0000,1.0365,1.2557,1.7559,2.0645];\n",
+ "V=[0,0,0,0,0,0]\n",
+ "k= []\n",
+ "t=array([0,0,0,0,0,0])\n",
+ "\n",
+ "# Calculations\n",
+ "for i in range(6):\n",
+ " V[i]=(Z[i]*R*T)/(P[i]*101325.)\t\t\t#[m**(3)/mol]\n",
+ " k.append((Z[i]-1.)*V[i])\n",
+ " t[i]=1./V[i]\n",
+ " \n",
+ "k = array(k)\n",
+ "\n",
+ "\t\t\t#w = linalg.lstsq(t.T,k.T)\n",
+ "\t\t\t#[C,B,sig]=reglin(t',k')\n",
+ "C,B,c,d,e = linregress(t.T,k.T)\n",
+ "\n",
+ "# Results\n",
+ "#From the regression% we get intercept=B and slope=C%and thus%\n",
+ "print \" The value of second virial coefficient (B) is %e m**(3)/mol\"%B\n",
+ "print \" The value of third virial coefficient (C) is %e m**(6)/mol**(2)\"%C\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The value of second virial coefficient (B) is -1.563305e-05 m**(3)/mol\n",
+ " The value of third virial coefficient (C) is 3.133359e-09 m**(6)/mol**(2)\n"
+ ]
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example - 2.9 Page number - 51"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "T = 444.3;\t\t\t#[K] - Temperature\n",
+ "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
+ "B_11 = -8.1;\t\t\t#[cm**(3)/mol]\n",
+ "B_11 = -8.1*10**(-6)\t\t\t#[m**(3)/mol]\n",
+ "B_22 = -293.4*10**(-6)\t\t\t#[m**(3)/mol]\n",
+ "y1 = 0.5;\t\t\t# mole fraction \t\t\t# equimolar mixture\n",
+ "y2 = 0.5;\n",
+ "\n",
+ "# For component 1 (methane)\n",
+ "Tc_1 = 190.6;\t\t\t#[K] - cricitical temperature\n",
+ "Vc_1 = 99.2;\t\t\t#[cm**(3)/mol] - cricitical molar volume\n",
+ "Zc_1 = 0.288;\t\t\t# critical compressibility factor\n",
+ "w_1 = 0.012;\t\t\t# acentric factor\n",
+ "\n",
+ "# For component 2 (n-butane)\n",
+ "Tc_2 = 425.2;\t\t\t#[K]\n",
+ "Vc_2 = 255.0;\t\t\t#[cm**(3)/mol]\n",
+ "Zc_2 = 0.274;\n",
+ "w_2 = 0.199;\n",
+ "\n",
+ "# Calculations\n",
+ "#Using virial mixing rule%we get\n",
+ "Tc_12 = (Tc_1*Tc_2)**(1./2)\t\t\t#[K]\n",
+ "w_12 = (w_1 + w_2)/2.;\n",
+ "Zc_12 = (Zc_1+Zc_2)/2.;\n",
+ "Vc_12 = (((Vc_1)**(1./3) + (Vc_2)**(1./3))/2.)**(3)\t\t\t#[cm**(3)/mol]\n",
+ "Vc_12 = Vc_12*10**(-6)\t\t\t#[cm**(3)/mol]\n",
+ "Pc_12 = (Zc_12*R*Tc_12)/Vc_12;\t\t\t#[N/m**(2)]\n",
+ "Tr_12 = T/Tc_12;\t\t\t#Reduced temperature\n",
+ "B_0 = 0.083 - (0.422/(Tr_12)**(1.6))\n",
+ "B_1 = 0.139 - (0.172/(Tr_12)**(4.2))\n",
+ "\n",
+ "\t\t\t#We know%(B_12*Pc_12)/(R*Tc_12) = B_0 + (w_12*B_1)\n",
+ "B_12 = ((B_0+(w_12*B_1))*(R*Tc_12))/Pc_12;\t\t\t#[m**(3)/mol] - Cross coefficient\n",
+ "B = y1**(2)*B_11+2*y1*y2*B_12+y2**(2)*B_22;\t\t\t#[m**(3)/mol] - Second virial coefficient for mixture\n",
+ "B = B*10**(6)\t\t\t#[cm**(3)/mol]\n",
+ "\n",
+ "# Results\n",
+ "print \" The second virial coefficient,(B) for the mixture of gas is %f cm**(3)/mol\"%B\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The second virial coefficient,(B) for the mixture of gas is -108.309380 cm**(3)/mol\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ "Example - 2.10 Page number - 52"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "T = 71+273.15;\t\t\t#[K] - Temperature\n",
+ "P = 69*10**(5)\t\t\t#[N/m**(2)] - Pressure\n",
+ "y1 = 0.5;\t\t\t#[mol] - mole fraction of equimolar mixture\n",
+ "y2 = 0.5;\n",
+ "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
+ "\n",
+ "\t\t\t#For component 1 (methane)\n",
+ "Tc_1 =190.6;\t\t\t#[K] - Critical temperature\n",
+ "Pc_1 = 45.99*10**(5)\t\t\t#[N/m**(2)] - Critical pressure\n",
+ "Vc_1 = 98.6;\t\t\t#[cm**(3)/mol] - Critical volume\n",
+ "Zc_1 = 0.286;\t\t\t# Critical compressibility factor\n",
+ "w_1 = 0.012;\t\t\t# acentric factor\n",
+ "\n",
+ "\t\t\t#For component 2 (hydrogen sulphide)\n",
+ "Tc_2 = 373.5;\t\t\t#[K]\n",
+ "Pc_2 = 89.63*10**(5)\t\t\t#[N/m**(2)]\n",
+ "Vc_2 = 98.5;\t\t\t#[cm**(3)/mol]\n",
+ "Zc_2 = 0.284;\n",
+ "w_2 = 0.094;\n",
+ "\n",
+ "# Calculations\n",
+ "\t\t\t#For component 1\n",
+ "Tr_1 = T/Tc_1;\t\t\t#Reduced temperature\n",
+ "\t\t\t#At reduced temperature\n",
+ "B1_0 = 0.083-(0.422/(Tr_1)**(1.6))\n",
+ "B1_1 = 0.139-(0.172/(Tr_1)**(4.2))\n",
+ "\t\t\t#We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+ "B_11 = ((B1_0+(w_1*B1_1))*(R*Tc_1))/Pc_1;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ "\t\t\t#Similarly for component 2\n",
+ "Tr_2 = T/Tc_2;\t\t\t#Reduced temperature\n",
+ "\t\t\t#At reduced temperature Tr_2%\n",
+ "B2_0 = 0.083 - (0.422/(Tr_2)**(1.6))\n",
+ "B2_1 = 0.139 - (0.172/(Tr_2)**(4.2))\n",
+ "B_22 = ((B2_0+(w_2*B2_1))*(R*Tc_2))/Pc_2;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ "\t\t\t#For cross coeffcient\n",
+ "Tc_12 = (Tc_1*Tc_2)**(1./2)\t\t\t#[K]\n",
+ "w_12 = (w_1 + w_2)/2;\n",
+ "Zc_12 = (Zc_1 + Zc_2)/2;\n",
+ "Vc_12 = (((Vc_1)**(1./3) + (Vc_2)**(1./3))/2)**(3)\t\t\t#[cm**(3)/mol]\n",
+ "Vc_12 = Vc_12*10**(-6)\t\t\t#[m**(3)/mol]\n",
+ "Pc_12 = (Zc_12*R*Tc_12)/Vc_12;\t\t\t#[N/m**(2)]\n",
+ "\n",
+ "\t\t\t#Now we have%(B_12*Pc_12)/(R*Tc_12) = B_0+(w_12*B_1)\n",
+ "\t\t\t#where B_0 and B_1 are to be evaluated at Tr_12\n",
+ "Tr_12 = T/Tc_12;\n",
+ "\t\t\t#At reduced temperature Tr_12\n",
+ "B_0 = 0.083 - (0.422/(Tr_12)**(1.6))\n",
+ "B_1 = 0.139 - (0.172/(Tr_12)**(4.2))\n",
+ "B_12=((B_0 + (w_12*B_1))*R*Tc_12)/Pc_12;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ "\t\t\t#For the mixture\n",
+ "B = y1**(2)*B_11+2*y1*y2*B_12 + y2**(2)*B_22;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ "\t\t\t#Now given virial equation is% Z=1+(B*P)/(R*T)\n",
+ "Z = 1 + (B*P)/(R*T)\n",
+ "\n",
+ "\t\t\t#Also Z = (P*V)/(R*T).Therefore%\n",
+ "V = (Z*R*T)/P;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ "# Results\n",
+ "print \" The molar volume of the mixture is %e m**(3)/mol\"%V\n",
+ "\t\t\t#The value obtained is near the math.experimental value of V_math.exp = 3.38*10**(-4) m**(3)/mol\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The molar volume of the mixture is 3.390411e-04 m**(3)/mol\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example - 2.11 Page number - 53"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "P = 6.*10**(6)\t\t\t# [Pa] - Pressure\n",
+ "P_max = 12.*10**(6)\t\t\t# [Pa] - Max pressure to which cylinder may be math.exposed\n",
+ "T = 280.;\t\t\t#[K] - Temperature\n",
+ "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
+ "\n",
+ "# Calculations and Results\n",
+ "\t\t\t#(1).Assuming ideal gas behaviour%\n",
+ "V_ideal = (R*T)/P;\t\t\t#[m**(3)/mol]\n",
+ "\t\t\t#Now when temperature and pressure are increased%the molar volume remains same%as total volume and number of moles are same.\n",
+ "\t\t\t#For max pressure of 12 MPa%temperature is\n",
+ "T_max_ideal = (P_max*V_ideal)/R;\n",
+ "print \" (1).The maximum temperature assuming ideal behaviour is %f K\"%T_max_ideal\n",
+ "\n",
+ "\t\t\t# (2).Assuming virial equation of state\n",
+ "\t\t\t# For component 1 (methane)%at 280 K\n",
+ "Tc_1 = 190.6;\t\t\t#[K]\n",
+ "Pc_1 = 45.99*10**(5)\t\t\t#[N/m**(2)]\n",
+ "Vc_1 = 98.6;\t\t\t#[cm**(3)/mol]\n",
+ "Zc_1 = 0.286;\n",
+ "w_1 = 0.012;\n",
+ "Tr_1 = T/Tc_1;\t\t\t#Reduced temperature\n",
+ "B1_0 = 0.083 - (0.422/(Tr_1)**(1.6))\n",
+ "B1_1 = 0.139 - (0.172/(Tr_1)**(4.2))\n",
+ "\n",
+ "\t\t\t#We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+ "B_11 = ((B1_0 + (w_1*B1_1))*(R*Tc_1))/Pc_1;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ "\t\t\t#For component 2 (Propane)\n",
+ "Tc_2 = 369.8;\t\t\t#[K]\n",
+ "Pc_2 = 42.48*10**(5)\t\t\t#[N/m**(2)]\n",
+ "Vc_2 = 200;\t\t\t#[cm**(3)/mol]\n",
+ "Zc_2 = 0.276;\n",
+ "w_2 = 0.152;\n",
+ "Tr_2 = T/Tc_2;\t\t\t# Reduced temperature\n",
+ "B2_0 = 0.083 - (0.422/(Tr_2)**(1.6))\n",
+ "B2_1 = 0.139 - (0.172/(Tr_2)**(4.2))\n",
+ "B_22 = ((B2_0 + (w_2*B2_1))*(R*Tc_2))/Pc_2;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ "\t\t\t#For cross coeffcient\n",
+ "y1 = 0.8;\t\t\t#mole fraction of component 1\n",
+ "y2 = 0.2;\t\t\t#mole fraction of component 2\n",
+ "Tc_12 = (Tc_1*Tc_2)**(1/2.)\t\t\t#[K]\n",
+ "w_12 = (w_1 + w_2)/2;\n",
+ "Zc_12 = (Zc_1 + Zc_2)/2;\n",
+ "Vc_12 = (((Vc_1)**(1./3) + (Vc_2)**(1./3))/2)**(3)\t\t\t#[cm**(3)/mol]\n",
+ "Vc_12 = Vc_12*10**(-6)\t\t\t#[m**(3)/mol]\n",
+ "Pc_12 = (Zc_12*R*Tc_12)/Vc_12;\t\t\t#[N/m**(2)]\n",
+ "Tr_12 = T/Tc_12;\n",
+ "\n",
+ "\t\t\t#At reduced temperature%Tr_12%\n",
+ "B_0 = 0.083 - (0.422/(Tr_12)**(1.6))\n",
+ "B_1 = 0.139 - (0.172/(Tr_12)**(4.2))\n",
+ "B_12 = ((B_0 + (w_12*B_1))*R*Tc_12)/Pc_12;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ "\t\t\t#For the mixture\n",
+ "B = y1**(2)*B_11+2*y1*y2*B_12 + y2**(2)*B_22;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ "\t\t\t#Now given virial equation is% Z=1+(B*P)/(R*T)\n",
+ "Z = 1 + (B*P)/(R*T)\n",
+ "\t\t\t#Also Z = (P*V)/(R*T).Therefore%\n",
+ "V_real = (Z*R*T)/P;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ "\t\t\t\n",
+ "\n",
+ "T_prime = 560.;\t\t\t#[K]\n",
+ "fault = 10.;\n",
+ "\n",
+ "while(fault > 1):\n",
+ " T_prime_r1 = T_prime/Tc_1;\n",
+ " B_prime1_0 = 7.7674*10**(-3)\n",
+ " B_prime1_1 = 0.13714;\n",
+ " B_prime_11 = ((B_prime1_0 + (w_1*B_prime1_1))*(R*Tc_1))/Pc_1;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ " \t\t\t#Similarly for component 2%\n",
+ " T_prime_r2 = T_prime/Tc_2;\n",
+ " B_prime2_0 = -0.1343;\n",
+ " B_prime2_1 = 0.10887;\n",
+ " B_prime_22 = ((B_prime2_0 + (w_2*B_prime2_1))*(R*Tc_2))/Pc_2;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ " \t\t\t#For cross coefficient (assuming k12=0)\n",
+ " \t\t\t#Tc_12 % w_12 % Zc_12 % Vc_12 and Pc_12 have already been calculated above%now\n",
+ " T_prime_r12 = T_prime/Tc_12;\t\t\t#\n",
+ " \t\t\t#At reduced temperature%T_prime_r12%\n",
+ " B_prime_0 = 0.083 - (0.422/(T_prime_r12)**(1.6))\n",
+ " B_prime_1 = 0.139 - (0.172/(T_prime_r12)**(4.2))\n",
+ " B_prime_12 = ((B_prime_0+(w_12*B_prime_1))*R*Tc_12)/Pc_12;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ " \t\t\t#For the mixture\n",
+ " B_prime = y1**(2)*B_prime_11 + 2*y1*y2*B_prime_12 + y2**(2)*B_prime_22;\t\t\t#[m**(3)/mol]\n",
+ " Z_prime = 1 + (B_prime*P_max)/(R*T_prime)\n",
+ " T_new = (P_max*V_real)/(Z_prime*R)\n",
+ " fault = abs(T_prime - T_new)\n",
+ " T_prime = T_new;\n",
+ "\n",
+ "print \" (2).The maximum temperature assuming the gas to follow virial equation of state is %f K\"%T_new\n",
+ "\n",
+ "# Note : Answers varies because of rounding error. Please check it manually."
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (1).The maximum temperature assuming ideal behaviour is 560.000000 K\n",
+ " (2).The maximum temperature assuming the gas to follow virial equation of state is 440.112497 K\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example - 2.12 Page number - 64"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "V_vessel = 0.1;\t\t\t#[m**(3)]\t\t\t# Volume of vessel\n",
+ "T = 25 + 273.15;\t\t#[K] - Temperature\n",
+ "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
+ "m = 25*1000;\t\t\t#[g]\t\t\t# Mass of ethylene\n",
+ "Tc = 282.3;\t\t\t#[K] - Critical temperature\n",
+ "Pc = 50.40;\t\t\t#[bar] - Critical pressure\n",
+ "Pc = Pc*10**(5)\t\t\t#[N/m**(2)]\n",
+ "Zc = 0.281;\t\t\t# Critical compressibility factor\n",
+ "Vc = 131;\t\t\t#[cm**(3)/mol] - Critical volume\n",
+ "Vc = Vc*10**(-6)\t\t\t#[m**(3)/mol]\n",
+ "w = 0.087;\t\t\t# Acentric factor\n",
+ "M = 28.054;\t\t\t# Molecular weight of ethylene\n",
+ "\n",
+ "# Calculations\n",
+ "n = m/M;\t\t\t#[mole] - No. of moles of ethylene\n",
+ "V = V_vessel/n;\t\t#[m**(3)/mol] - Molar volume\n",
+ "\n",
+ "\t\t\t#Under Redlich Kwong equation of state% we have\n",
+ "a = (0.42748*(R**(2))*(Tc**(2.5)))/Pc;\t\t\t#[Pa*m**(6)*K**(1/2)/mol]\n",
+ "b = (0.08664*R*Tc)/Pc;\t\t\t#[m**(3)/mol]\n",
+ "P = ((R*T)/(V-b))-(a/(T**(1./2)*V*(V+b)))\t\t\t#[N/m**(2)]\n",
+ "\n",
+ "# Results\n",
+ "print \" The required pressure using Redlich Kwong equation of state is %e N/m**(2)\"%P\n",
+ "\n",
+ "\t\t\t#For ideal gas equation of state%\n",
+ "P_ideal = (R*T)/V;\t\t\t#[N/m**(2)]\n",
+ "print \" For ideal gas equation of state,the required pressure is %e N/m**(2)\"%P_ideal\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The required pressure using Redlich Kwong equation of state is 7.934745e+06 N/m**(2)\n",
+ " For ideal gas equation of state,the required pressure is 2.208971e+07 N/m**(2)\n"
+ ]
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example - 2.13 Page number - 65"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "\n",
+ "V_vessel = 360*10**(-3)\t\t\t#[m**(3)] - volume of vessel\n",
+ "T = 62+273.15;\t\t\t#[K] - Temperature\n",
+ "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
+ "m = 70.*1000;\t\t\t#[g]/ - Mass of carbon dioxide\n",
+ "\n",
+ "\t\t\t#For carbon dioxide\n",
+ "Tc = 304.2;\t\t\t#[K] - Cricitical temperature\n",
+ "Pc = 73.83;\t\t\t#[bar] - Cricitical pressure\n",
+ "Pc = Pc*10**(5)\t\t\t# [N/m**(2)]\n",
+ "Zc = 0.274;\t\t\t# Critical compressibility factor\n",
+ "Vc = 94.0;\t\t\t#[cm**(3)/mol]\n",
+ "Vc = Vc*10**(-6)\t\t\t#[m**(3)/mol]\n",
+ "w = 0.224;\t\t\t# Acentric factor\n",
+ "M = 44.01;\t\t\t# Molecular weight of carbon dioxide\n",
+ "\n",
+ "# Calculations and Results\n",
+ "n = m/M;\t\t\t#[mol] - No. of moles\n",
+ "V = V_vessel/n;\t\t\t#[m**(3)/mol]\t\t\t#molar volume\n",
+ "\n",
+ "\t\t\t# (1)\n",
+ "\t\t\t# Ideal gas behaviour\n",
+ "P_1 = (R*T)/V;\t\t\t#[N/m**(2)]\n",
+ "print \" (1).The required pressure using ideal equation of state is %e N/m**(2)\"%P_1\n",
+ "\n",
+ "\t\t\t# (2)\n",
+ "\t\t\t# Virial equation of state% Z = 1 + (B*P)/(R*T)\n",
+ "\t\t\t# (P*V)/(R*T) = 1 + (B*P)/(R*T)% and thus P = (R*T)/(V - B). Now\n",
+ "Tr = T/Tc;\t\t\t#Reduced temperature\n",
+ "\t\t\t# At reduced temperature Tr%\n",
+ "B_0 = 0.083 - (0.422/(Tr)**(1.6))\n",
+ "B_1 = 0.139 - (0.172/(Tr)**(4.2))\n",
+ "B = ((B_0 + (w*B_1))*(R*Tc))/Pc;\t\t\t#[m**(3)/mol]\n",
+ "P_2 = (R*T)/(V - B)\t\t\t#[N/m**(2)]\n",
+ "print \" (2).The required pressure using given virial equation of state is %e N/m**(2)\"%P_2\n",
+ "\n",
+ "\t\t\t# (3)\n",
+ "\t\t\t# Virial equation of state% Z = 1 + (B/V)\n",
+ "\t\t\t# (P*V)/(R*T) = 1 + (B/V)\n",
+ "P_3 = ((R*T)/V) + (B*R*T)/(V**(2))\t\t\t#[N/m**(2)]\n",
+ "print \" (3).The required pressure using given virial equation of state is %e N/m**(2)\"%P_3\n",
+ "\n",
+ "\t\t\t# (4)\n",
+ "\t\t\t# Van der Walls equation of state%P = ((R*T)/(V-b)) - a/(V**(2))\n",
+ "a = (27*(R**(2))*(Tc**(2)))/(64*Pc)\t\t\t#[Pa*m**(6)/mol**(2)]\n",
+ "b = (R*Tc)/(8*Pc)\t\t\t#[m**(3)/mol]\n",
+ "P_4 = ((R*T)/(V-b)) - a/(V**(2))\t\t\t#[N/m**(2)]\n",
+ "print \" (4).The required pressure using van der Walls equation of state is %e N/m**(2)\"%P_4\n",
+ "\n",
+ "\t\t\t#(5)\n",
+ "\t\t\t# Redlich Kwong equation of state%\n",
+ "a_1 = (0.42748*(R**(2))*(Tc**(2.5)))/Pc;\t\t\t#[Pa*m**(6)*K**(1/2)/mol]\n",
+ "b_1 = (0.08664*R*Tc)/Pc;\t\t\t#[m**(3)/mol]\n",
+ "P_5 = ((R*T)/(V - b_1)) - (a_1/(T**(1./2)*V*(V + b_1)))\t\t\t#[N/m**(2)]\n",
+ "print \" (5).The required pressure using Redlich Kwong equation of state is %e N/m**(2)\"%P_5\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (1).The required pressure using ideal equation of state is 1.231100e+07 N/m**(2)\n",
+ " (2).The required pressure using given virial equation of state is 8.712394e+06 N/m**(2)\n",
+ " (3).The required pressure using given virial equation of state is 7.226009e+06 N/m**(2)\n",
+ " (4).The required pressure using van der Walls equation of state is 8.048790e+06 N/m**(2)\n",
+ " (5).The required pressure using Redlich Kwong equation of state is 8.079803e+06 N/m**(2)\n"
+ ]
+ }
+ ],
+ "prompt_number": 12
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example - 2.14 Page number - 66"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "T = 500+273.15;\t\t\t#[K] - Temperature\n",
+ "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
+ "P = 325*1000;\t\t\t#[Pa] - Pressure\n",
+ "Tc = 647.1;\t\t\t#[K] - Cricitical temperature\n",
+ "Pc = 220.55;\t\t\t#[bar] - Cricitical pressure\n",
+ "Pc = Pc*10**(5)\t\t\t#[N/m**(2)]\n",
+ "\n",
+ "# Calculations and Results\n",
+ "\t\t\t#(1)\n",
+ "\t\t\t# Van der Walls equation of state%\n",
+ "a = (27*(R**(2))*(Tc**(2)))/(64*Pc)\t\t\t#[Pa*m**(6)/mol**(2)]\n",
+ "b = (R*Tc)/(8*Pc)\t\t\t#[m**(3)/mol]\n",
+ "\t\t\t# The cubic form of van der Walls equation of state is given by%\n",
+ "\t\t\t# V**(3)-(b+(R*T)/P)*V**(2)+(a/P)*V-(a*b)/P=0\n",
+ "\t\t\t# Solving the cubic equation\n",
+ "def f(V):\n",
+ " global b,R,T,P,a\n",
+ " return V**(3)-(b+(R*T)/P)*V**(2)+(a/P)*V-(a*b)/P\n",
+ "from scipy.optimize import fsolve\n",
+ "V_1 = fsolve(f,1)\n",
+ "V_2 = fsolve(f,10)\n",
+ "V_3 = fsolve(f,100)\n",
+ "\t\t\t# The above equation has 1 real and 2 imaginary roots. We consider only real root%\n",
+ "Z_1 = (P*V_1)/(R*T)\t\t\t#compressibility factor\n",
+ "print \" (1).The compressibility factor of steam using van der Walls equation of state is %f\"%Z_1\n",
+ "\n",
+ "\t\t\t#(2)\n",
+ "\n",
+ "\t\t\t#Redlich Kwong equation of state%\n",
+ "a_1 = (0.42748*(R**(2))*(Tc**(2.5)))/Pc;\t\t\t#[Pa*m**(6)*K**(1/2)/mol]\n",
+ "b_1 = (0.08664*R*Tc)/Pc;\t\t\t#[m**(3)/mol]\n",
+ "\t\t\t# The cubic form of Redlich Kwong equation of state is given by%\n",
+ "\t\t\t# V**(3)-((R*T)/P)*V**(2)-((b_1**(2))+((b_1*R*T)/P)-(a/(T**(1/2)*P))*V-(a*b)/(T**(1/2)*P)=0\n",
+ "\t\t\t#Solving the cubic equation\n",
+ "def f1(V):\n",
+ " return V**(3)-((R*T)/P)*V**(2)-((b_1**(2))+((b_1*R*T)/P)-(a_1/(T**(1./2)*P)))*V-(a_1*b_1)/(T**(1./2)*P)\n",
+ " \n",
+ "V_4=fsolve(f1,1)\n",
+ "V_5=fsolve(f1,10)\n",
+ "V_6=fsolve(f1,100)\n",
+ "\t\t\t# The above equation has 1 real and 2 imaginary roots. We consider only real root%\n",
+ "\t\t\t# Thus compressibility factor is\n",
+ "Z_2 = (P*V_4)/(R*T)\t\t\t#compressibility factor\n",
+ "print \" (2).The compressibility factor of steam using Redlich Kwong equation of state is %f\"%Z_2\n",
+ "\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (1).The compressibility factor of steam using van der Walls equation of state is 0.997181\n",
+ " (2).The compressibility factor of steam using Redlich Kwong equation of state is 0.997028\n"
+ ]
+ }
+ ],
+ "prompt_number": 13
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example - 2.15 Page number - 67"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "from scipy.optimize import fsolve\n",
+ "\n",
+ "\n",
+ "# Variables\n",
+ "T = 250+273.15;\t\t\t#[K]\n",
+ "R = 8.314;\t\t\t#[J/mol*K]\n",
+ "P = 39.76;\t\t\t#[bar] Vapour pressure of water at T\n",
+ "P = P*10**(5)\t\t\t#[N/m**(2)]\n",
+ "Tc = 647.1;\t\t\t#[K] - Cricitical temperature\n",
+ "Pc = 220.55*10**(5)\t\t\t#[N/m**(2)] - Cricitical pressure\n",
+ "w = 0.345;\t\t\t#Acentric factor\n",
+ "M = 18.015;\t\t\t# Molecular weight of water\n",
+ "\n",
+ "# Calculations and Results\n",
+ "\t\t\t# Using peng-Robinson equation of stste \n",
+ "m = 0.37464 + 1.54226*w - 0.26992*w**(2)\n",
+ "Tr = T/Tc;\n",
+ "alpha = (1 + m*(1 - Tr**(1./2)))**(2)\n",
+ "a = ((0.45724*(R*Tc)**(2))/Pc)*alpha;\t\t\t#[Pa*m**(6)/mol**(2)]\n",
+ "b = (0.07780*R*Tc)/Pc;\t\t\t#[m**(3)/mol]\n",
+ "\t\t\t# Cubuc form of Peng-Robinson equation of stste is given by\n",
+ "\t\t\t# V**(3) + (b-(R*T)/P)*V**(2) - ((3*b**(2)) + ((2*R*T*b)/P) - (a/P))*V+b**(3) + ((R*T*(b**(2))/P) - ((a*b)/P) = 0;\n",
+ "\t\t\t# Solving the cubic equation\n",
+ "def f(V):\n",
+ " global b,R,T,P,a\n",
+ " return V**(3)+(b-(R*T)/P)*V**(2)-((3*b**(2))+((2*R*T*b)/P)-(a/P))*V+b**(3)+((R*T*(b**(2)))/P)-((a*b)/P)\n",
+ "V_1 = fsolve(f,-1)\n",
+ "V_2 = fsolve(f,0)\n",
+ "V_3 = fsolve(f,1)\n",
+ "\t\t\t#The largest root is for vapour phase%\n",
+ "V_vap = V_3;\t\t\t#[m**(3)/mol] - Molar volume (saturated vapour)\n",
+ "V_vap = V_vap*10**(6)/M;\t\t\t#[cm**(3)/g]\n",
+ "\n",
+ "print \" The moar volume of saturated water in the vapour phase (V_vap) is %f cm**(3)/g\"%V_vap\n",
+ "\n",
+ "\t\t\t#The smallest root is for liquid phase%\n",
+ "V_liq = V_1;\t\t\t#[m**(3)/mol] - molar volume (saturated liquid)\n",
+ "V_liq = V_liq*10**(6)/M;\t\t\t#[cm**(3)/g]\n",
+ "print \" The moar volume of saturated water in the liquid phase (V_liq) is %f cm**(3)/g\"%V_liq\n",
+ "\n",
+ "\t\t\t#From steam table at 250 C% V_vap = 50.13 [cm**(3)/g] and V_liq = 1.251 [cm**(3)/g].\n",
+ "print \" From steam table at 250 C, V_vap = 50.13 [cm**(3)/g] and V_liq = 1.251 [cm**(3)/g]\"\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " The moar volume of saturated water in the vapour phase (V_vap) is 51.757097 cm**(3)/g\n",
+ " The moar volume of saturated water in the liquid phase (V_liq) is 1.554560 cm**(3)/g\n",
+ " From steam table at 250 C, V_vap = 50.13 [cm**(3)/g] and V_liq = 1.251 [cm**(3)/g]\n"
+ ]
+ }
+ ],
+ "prompt_number": 14
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example - 2.16 Page number - 68"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "# Variables\n",
+ "T = 500+273.15;\t\t\t#[K] - Temperature\n",
+ "P = 15.;\t\t\t#[atm] - Pressure\n",
+ "P = P*101325;\t\t\t#[N/m**(2)]\n",
+ "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
+ "Tc = 190.6;\t\t\t#[K] - Cricitical temperature\n",
+ "Pc = 45.99*10**(5)\t\t\t#[N/m**(2)] - Cricitical pressure\n",
+ "Vc = 98.6;\t\t\t#[cm**(3)/mol] - Cricitical molar volume\n",
+ "Zc = 0.286;\t\t\t# Critical compressibility factor\n",
+ "w = 0.012;\t\t\t# Acentric factor\n",
+ "\n",
+ "# Calculations and Results\n",
+ "\t\t\t#(1)\n",
+ "\t\t\t#Virial equation of state%Z = 1 + (B*P)/(R*T)\n",
+ "Tr_1 = T/Tc;\t\t\t#Reduced temperature\n",
+ "B_0 = 0.083-(0.422/(Tr_1)**(1.6))\n",
+ "B_1 = 0.139-(0.172/(Tr_1)**(4.2)) \t\t\t# We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+ "B = ((B_0+(w*B_1))*(R*Tc))/Pc;\t\t\t#[m**(3)/mol]\t\t\t#second virial coefficient\n",
+ "Z = 1 + (B*P)/(R*T)\t\t\t#compressibility factor\n",
+ "\t\t\t#(P*V)/(R*T)=1+(B*P)/(R*T)%and thus%\n",
+ "V_1 = (Z*R*T)/P;\t\t\t#[m**(3)/mol]\n",
+ "print \" (1).The molar volume of methane using given virial equation is %e m**(3)/mol\"%V_1\n",
+ "\n",
+ "\t\t\t#(2).\n",
+ "\t\t\t#Virial equation of state%Z = 1 + (B/V)\n",
+ "\t\t\t#Also%Z = (P*V)/(R*T). Substituting the value of Z%we get\n",
+ "\t\t\t# V**(2) - ((R*T)/P)*V - ((B*R*T)/P) = 0.Solving the quadratic equation\n",
+ "def f(V):\n",
+ " global R,T,P,B\n",
+ " return V**(2)-((R*T)/P)*V-((B*R*T)/P)\n",
+ "V2_1=fsolve(f,0)\n",
+ "V2_2=fsolve(f,1)\n",
+ "\t\t\t# Out of two roots%we will consider only positive root\n",
+ "print \" (2).The molar volume of methane using given virial equation is %e m**(3)/mol\"%V2_2\n",
+ "\n",
+ "\t\t\t# (3)\n",
+ "\t\t\t# Van der Walls equation of state%\n",
+ "\t\t\t# (P + (a/V**(2)))*(V - b) = R*T\n",
+ "a_3 = (27*(R**(2))*(Tc**(2)))/(64*Pc)\t\t\t#[Pa*m**(6)/mol**(2)]\n",
+ "b_3 = (R*Tc)/(8*Pc)\t\t\t#[m**(3)/mol]\n",
+ "\t\t\t# The cubic form of van der Walls equation of state is given by%\n",
+ "\t\t\t# V**(3) - (b + (R*T)/P)*V**(2) + (a/P)*V - (a*b)/P = 0\n",
+ "\t\t\t# Solving the cubic equation\n",
+ "def f1(V):\n",
+ " global b,R,T,P,a_3\n",
+ " return V**(3)-(b_3+(R*T)/P)*V**(2)+(a_3/P)*V-(a_3*b_3)/P\n",
+ "V3_1=fsolve(f1,1)\n",
+ "V3_2=fsolve(f1,10)\n",
+ "V3_3=fsolve(f1,100)\n",
+ "\t\t\t# The above equation has 1 real and 2 imaginary roots. We consider only real root.\n",
+ "print \" (3).The molar volume of methane using van der Walls equation of state is %e m**(3)/mol\"%V3_1\n",
+ "\n",
+ "\t\t\t# (4)\n",
+ "\t\t\t# Redlich Kwong equation of state\n",
+ "a_4 = (0.42748*(R**(2))*(Tc**(2.5)))/Pc;\t\t\t#[Pa*m**(6)*K**(1/2)/mol]\n",
+ "b_4 = (0.08664*R*Tc)/Pc;\t\t\t#[m**(3)/mol]\n",
+ "\t\t\t# The cubic form of Redlich Kwong equation of state is given by%\n",
+ "\t\t\t# V**(3) - ((R*T)/P)*V**(2) - ((b_1**(2)) + ((b_1*R*T)/P) - (a/(T**(1/2)*P))*V - (a*b)/(T**(1/2)*P) = 0\n",
+ "\t\t\t# Solving the cubic equation\n",
+ "def f2(V):\n",
+ " global R,T,P,b_4,a_4\n",
+ " return V**(3)-((R*T)/P)*V**(2)-((b_4**(2))+((b_4*R*T)/P)-(a_4/(T**(1./2)*P)))*V-(a_4*b_4)/(T**(1./2)*P)\n",
+ "V4_1=fsolve(f2,1)\n",
+ "V4_2=fsolve(f2,10)\n",
+ "V4_3=fsolve(f2,100)\n",
+ "\t\t\t#The above equation has 1 real and 2 imaginary roots. We consider only real root.\n",
+ "print \" (4).The molar volume of methane using Redlich Kwong equation of state is %e m**(3)/mol\"%V4_1\n",
+ "\n",
+ "\t\t\t# (5)\n",
+ "\t\t\t# Using Peng-Robinson equation of state \n",
+ "m = 0.37464 + 1.54226*w - 0.26992*w**(2)\n",
+ "Tr_5 = T/Tc;\n",
+ "alpha = (1 + m*(1 - Tr_5**(1./2)))**(2)\n",
+ "a = ((0.45724*(R*Tc)**(2))/Pc)*alpha;\t\t\t#[Pa*m**(6)/mol**(2)]\n",
+ "b = (0.07780*R*Tc)/Pc;\t\t\t#[m**(3)/mol]\n",
+ "\t\t\t# Cubic form of Peng-Robinson equation of stste is given by\n",
+ "\t\t\t# V**(3)+(b-(R*T)/P)*V**(2)-((3*b**(2))+((2*R*T*b)/P)-(a/P))*V+b**(3)+((R*T*(b**(2))/P)-((a*b)/P)=0;\n",
+ "\t\t\t# Solving the cubic equation\n",
+ "def f3(V):\n",
+ " global b,R,T,P,a\n",
+ " return V**(3)+(b-(R*T)/P)*V**(2)-((3*b**(2))+((2*R*T*b)/P)-(a/P))*V+b**(3)+((R*T*(b**(2)))/P)-((a*b)/P)\n",
+ "V5_1=fsolve(f3,-1)\n",
+ "V5_2=fsolve(f3,0)\n",
+ "V5_3=fsolve(f3,1)\n",
+ "\t\t\t#The largest root is for vapour phase%\n",
+ "\t\t\t#The largest root is only considered as the systemis gas\n",
+ "print \" (5).The molar volume of methane using Peng-Robinson equation of state is %e m**(3)/mol\"%V5_3\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (1).The molar volume of methane using given virial equation is 4.242974e-03 m**(3)/mol\n",
+ " (2).The molar volume of methane using given virial equation is 4.242930e-03 m**(3)/mol\n",
+ " (3).The molar volume of methane using van der Walls equation of state is 4.236938e-03 m**(3)/mol\n",
+ " (4).The molar volume of methane using Redlich Kwong equation of state is 4.241402e-03 m**(3)/mol\n",
+ " (5).The molar volume of methane using Peng-Robinson equation of state is 4.242341e-03 m**(3)/mol\n"
+ ]
+ }
+ ],
+ "prompt_number": 15
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": [
+ " Example - 2.17 Page number - 70"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ " \n",
+ "# Variables\n",
+ "T = 310.93;\t\t\t#[K] - Temperature\n",
+ "P = 2.76*10**(6)\t\t\t#[N/m**(2)] - Pressure\n",
+ "R = 8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
+ "y1 = 0.8942;\t\t\t# Mole fraction of component 1 (methane)\n",
+ "y2 = 1-y1;\t\t\t# Mole fraction of component 2 (n-butane)\n",
+ "\n",
+ "#For component 1 (methane)\n",
+ "Tc_1 = 190.58;\t\t\t#[K] - Cricitical temperature\n",
+ "Pc_1 = 46.05;\t\t\t#[bar] - Cricitical pressure\n",
+ "Pc_1 = Pc_1*10**(5)\t\t\t#[N/m**(2)]\n",
+ "Zc_1 = 0.288;\t\t\t# Critical compressibility factor\n",
+ "Vc_1 = 99.1;\t\t\t#[cm**(3)/mol]\n",
+ "Vc_1 = Vc_1*10**(-6)\t\t\t#[m**(3)/mol]\n",
+ "w_1 = 0.011;\t\t\t# Acentric factor\n",
+ "\n",
+ "\t\t\t#For component 2 (n-butane)\n",
+ "Tc_2 = 425.18;\t\t\t#[K] - Cricitical temperature\n",
+ "Pc_2 = 37.97;\t\t\t#[bar] - Cricitical pressure\n",
+ "Pc_2 = Pc_2*10**(5)\t\t\t# [N/m**(2)]\n",
+ "Zc_2 = 0.274;\t\t\t# Critical compressibility factor\n",
+ "Vc_2 = 255.1;\t\t\t# [cm**(3)/mol]\n",
+ "Vc_2 = Vc_2*10**(-6)\t\t\t# [m**(3)/mol]\n",
+ "w_2 = 0.193;\t\t\t# Acentric factor\n",
+ "\n",
+ "# Calculations and Results\n",
+ "\t\t\t# (1)\n",
+ "\t\t\t# Virial equation of state% Z = 1 + (B*P)/(R*T)\n",
+ "\t\t\t# For component 1 (methane)\n",
+ "Tr_1 = T/Tc_1;\t\t\t#Reduced temperature\n",
+ "\t\t\t# At reduced temperature\n",
+ "B1_0 = 0.083 - (0.422/(Tr_1)**(1.6))\n",
+ "B1_1 = 0.139 - (0.172/(Tr_1)**(4.2))\n",
+ "\t\t\t# We know%(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
+ "B_11 = ((B1_0+(w_1*B1_1))*(R*Tc_1))/Pc_1;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ "\t\t\t#Similarly for component 2\n",
+ "Tr_2 = T/Tc_2;\t\t\t#Reduced temperature\n",
+ "\t\t\t#At reduced temperature Tr_2%\n",
+ "B2_0 = 0.083 - (0.422/(Tr_2)**(1.6))\n",
+ "B2_1 = 0.139 - (0.172/(Tr_2)**(4.2))\n",
+ "B_22 = ((B2_0 + (w_2*B2_1))*(R*Tc_2))/Pc_2;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ "\t\t\t#For cross coeffcient\n",
+ "Tc_12 = (Tc_1*Tc_2)**(1./2)\t\t\t#[K]\n",
+ "w_12 = (w_1 + w_2)/2;\n",
+ "Zc_12 = (Zc_1 + Zc_2)/2;\n",
+ "Vc_12 = (((Vc_1)**(1./3)+(Vc_2)**(1./3))/2)**(3)\t\t\t#[m**(3)/mol]\n",
+ "Pc_12 =(Zc_12*R*Tc_12)/Vc_12;\t\t\t#[N/m**(2)]\n",
+ "\n",
+ "\t\t\t#Now we have%(B_12*Pc_12)/(R*Tc_12) = B_0+(w_12*B_1)\n",
+ "\t\t\t#where B_0 and B_1 are to be evaluated at Tr_12\n",
+ "Tr_12 = T/Tc_12;\n",
+ "\t\t\t#At reduced temperature Tr_12\n",
+ "B_0 = 0.083 - (0.422/(Tr_12)**(1.6))\n",
+ "B_1 = 0.139 - (0.172/(Tr_12)**(4.2))\n",
+ "B_12 = ((B_0+(w_12*B_1))*R*Tc_12)/Pc_12;\t\t\t#[m**(3)/mol]\n",
+ "\n",
+ "\t\t\t#For the mixture\n",
+ "B = y1**(2)*B_11+2*y1*y2*B_12+y2**(2)*B_22;\t\t\t#[m**(3)/mol]\n",
+ "Z_1 = 1+(B*P)/(R*T)\t\t\t#compressibility factor\n",
+ "print \" (1).The compressibility factor of mixture using Virial equation of state is %f\"%Z_1\n",
+ "\n",
+ "\t\t\t# (2)\n",
+ "\t\t\t# Pseudo reduced method.\n",
+ "T_pc = (y1*Tc_1)+(y2*Tc_2)\t\t\t#[K] - Cricitical temperature\n",
+ "P_pc = (y1*Pc_1)+(y2*Pc_2)\t\t\t#[N/m**(2)] - Cricitical pressure\n",
+ "w = (y1*w_1)+(y2*w_2)\t\t\t# Acentric factor\n",
+ "T_pr = T/T_pc;\t\t\t# Reduced temperature\n",
+ "P_pr = P/P_pc;\t\t\t# Reduced pressure\n",
+ "\t\t\t#At this value of Tpr%\n",
+ "B0 = 0.083 - (0.422/(T_pr)**(1.6))\n",
+ "B1 = 0.139 - (0.172/(T_pr)**(4.2))\n",
+ "Z0 = 1 + B0*(P_pr/T_pr)\n",
+ "Z1 = B1*(P_pr/T_pr)\n",
+ "Z = Z0 + w*Z1;\n",
+ "print \" (2).The compressibility factor of mixture using pseudo reduced method is %f\"%Z\n",
+ "\n",
+ "\t\t\t# (3)\n",
+ "\t\t\t# Redlich Kwong equation of state is given by\n",
+ "\t\t\t# P = ((R*T)/(V-b)) - (a/(T**(1/2)*V*(V+b)))\n",
+ "\t\t\t# For methane%component 1\n",
+ "a_1 = (0.42748*(R**(2))*(Tc_1**(2.5)))/Pc_1;\t\t\t#[Pa*m**(6)*K**(1/2)/mol]\n",
+ "b_1 = (0.08664*R*Tc_1)/Pc_1;\t\t\t#[m**(3)/mol]\n",
+ "\t\t\t#For n-butane%component 2\n",
+ "a_2 = (0.42748*(R**(2))*(Tc_2**(2.5)))/Pc_2;\t\t\t#[Pa*m**(6)*K**(1/2)/mol]\n",
+ "b_2 = (0.08664*R*Tc_2)/Pc_2;\t\t\t#[m**(3)/mol]\n",
+ "\t\t\t#For the mixture\n",
+ "a_12 = (a_1*a_2)**(1./2)\t\t\t#[Pa*m**(6)*K**(1/2)/mol]\n",
+ "a = y1**(2)*a_1 + 2*y1*y2*a_12 + y2**(2)*a_2;\t\t\t#[Pa*m**(6)*K**(1/2)/mol]\n",
+ "b = (y1*b_1) + (y2*b_2)\t\t\t#[m**(3)/mol]\n",
+ "\t\t\t# The cubic form of Redlich Kwong equation of state is given by%\n",
+ "\t\t\t# V**(3) - ((R*T)/P)*V**(2) - ((b_1**(2)) + ((b_1*R*T)/P) - (a/(T**(1/2)*P))*V - (a*b)/(T**(1/2)*P) = 0\n",
+ "\t\t\t# Solving the cubic equation\n",
+ "def f(V):\n",
+ " global R,T,P,b,a\n",
+ " return V**(3)-((R*T)/P)*V**(2)-((b**(2))+((b*R*T)/P)-(a/(T**(1./2)*P)))*V-(a*b)/(T**(1./2)*P)\n",
+ "V_1=fsolve(f,1)\n",
+ "V_2=fsolve(f,10)\n",
+ "V_3=fsolve(f,100)\n",
+ "\t\t\t# Thus compressibility factor is\n",
+ "Z_3 = (P*V_1)/(R*T)\t\t\t#compressibility factor\n",
+ "print \" (3).The compressibility factor of mixture using Redlich Kwong equation of state is %f\"%Z_3\n",
+ "\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ " (1).The compressibility factor of mixture using Virial equation of state is 0.926842\n",
+ " (2).The compressibility factor of mixture using pseudo reduced method is 0.937191\n",
+ " (3).The compressibility factor of mixture using Redlich Kwong equation of state is 0.927540\n"
+ ]
+ }
+ ],
+ "prompt_number": 16
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file