{
 "metadata": {
  "name": "",
  "signature": "sha256:dfc2bc36e1576488bcd07ee5435a22145b28c649187a0989b470c7cdd7161f42"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 5: Single-Phase Systems"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.1-1, page no. 190"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "#Initialization of variables\n",
      "import math\n",
      "import numpy\n",
      "from numpy import linalg\n",
      "import scipy\n",
      "from scipy import integrate\n",
      "\n",
      "wtperct=0.5\n",
      "Dwater=0.998 #g/cm^3\n",
      "Dsulfuric=1.834 #g/cm^3\n",
      "\n",
      "\n",
      "#Calculations and printing :\n",
      "\n",
      "invPbar=wtperct/Dwater + (1-wtperct)/Dsulfuric\n",
      "print '%s %.3f' %(\"Density calculated using volume additvity (g/cm^3) =\",1/invPbar)\n",
      "Pbar=wtperct*Dwater + (1-wtperct)*Dsulfuric\n",
      "print '%s %.3f' %(\" \\n Density calculated using mass additivity (g/cm^3) =\",Pbar)\n",
      "raw_input('press enter key to exit')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Density calculated using volume additvity (g/cm^3) = 1.293\n",
        " \n",
        " Density calculated using mass additivity (g/cm^3) = 1.416\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "press enter key to exit\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 1,
       "text": [
        "''"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.2-1, page no. 192"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "#Initialization of variables\n",
      "import math\n",
      "import numpy\n",
      "from numpy import linalg\n",
      "import scipy\n",
      "from scipy import integrate\n",
      "\n",
      "T=23.0+273 #kelvin\n",
      "P=3.0+14.7 #psi \n",
      "#conversion of pressure from psig to psi requires addition of 14.67 which is 1 atm\n",
      "R=0.08206 #lt-atm\n",
      "MN2=28.0 #molecular wt.\n",
      "weight=100.0 #grams\n",
      "\n",
      "#Calculations and printing :\n",
      "\n",
      "n=weight/MN2 #mol\n",
      "V=n*R*T*14.7/P #lt\n",
      "print '%s %.3f' %(\"assuming ideal gas behaviour, volume (litres) = \",V)\n",
      "Vcap=V/n\n",
      "if(Vcap>5):\n",
      "    print(\"ideal gas equation yields error less than 1 percent for diatomic gas\")\n",
      "else:\n",
      "    print(\"ideal gas equation yields error greater than 1 percent for diatomic gases\")\n",
      "\n",
      "raw_input('press enter key to exit')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "assuming ideal gas behaviour, volume (litres) =  72.046\n",
        "ideal gas equation yields error less than 1 percent for diatomic gas\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "press enter key to exit\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 2,
       "text": [
        "''"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.2-2, page no. 195"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "#Initialization of variables\n",
      "import math\n",
      "import numpy\n",
      "from numpy import linalg\n",
      "import scipy\n",
      "from scipy import integrate\n",
      "\n",
      "T=360.0+273 #Kelvin\n",
      "P=3.0 #atm\n",
      "Vdot=1100.0 #kg/h\n",
      "M=58.1 \n",
      "\n",
      "#Calculations and printing :\n",
      "\n",
      "ndot=Vdot/M #kmol/h\n",
      "vdot=ndot*22.4*T/(273*P)\n",
      "print '%s %.3f' %(\"The volumetric flow rate of the stream (m^3/h) = \",vdot)\n",
      "raw_input('press enter key to exit')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The volumetric flow rate of the stream (m^3/h) =  327.781\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "press enter key to exit\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 3,
       "text": [
        "''"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.2-3, page no. 195"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "#Initialization of variables\n",
      "import math\n",
      "import numpy\n",
      "from numpy import linalg\n",
      "import scipy\n",
      "from scipy import integrate\n",
      "\n",
      "V1=10.0 #ft^3\n",
      "T1=70.0+460 #R\n",
      "P1=1.0 #atm\n",
      "P2=2.5 #atm\n",
      "T2=610.0+460 #R\n",
      "\n",
      "#Calculations and printing :\n",
      "\n",
      "V2=V1*P1*T2/(P2*T1)\n",
      "print '%s %.3f' %(\"Volume in final state (ft^3) = \",V2)\n",
      "raw_input('press enter key to exit')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Volume in final state (ft^3) =  8.075\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "press enter key to exit\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 4,
       "text": [
        "''"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.2-4, page no. 196"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "#Initialization of variables\n",
      "import math\n",
      "import numpy\n",
      "from numpy import linalg\n",
      "import scipy\n",
      "from scipy import integrate\n",
      "\n",
      "#all the calculations are done in R scale\n",
      "T2=285.0+460 #R\n",
      "T1=32.0+460 #R\n",
      "P2=1.30 #atm\n",
      "P1=1.0 #atm\n",
      "V1dot=3.95*100000. #ft^3/h\n",
      "\n",
      "\n",
      "#Calculations and printing :\n",
      "\n",
      "#SCFH means ft^3(STP/h)\n",
      "ndot=3.95*math.pow(10,5)/359.\n",
      "print '%s %.3f' %(\" Molar flowrate (lb-moles/hr) = \",ndot)\n",
      "V2dot=V1dot*T2*P1/(T1*P2)\n",
      "print '%s %.3E' %(\" \\n True volumetric flowrate (ft^3/h) = \",V2dot)\n",
      "raw_input('press enter key to exit')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Molar flowrate (lb-moles/hr) =  1100.279\n",
        " \n",
        " True volumetric flowrate (ft^3/h) =  4.601E+05\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "press enter key to exit\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 5,
       "text": [
        "''"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.2-5, page no. 197"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "#Initialization of variables\n",
      "import math\n",
      "import numpy\n",
      "from numpy import linalg\n",
      "import scipy\n",
      "from scipy import integrate\n",
      "\n",
      "flowinA=400.0 #L/min\n",
      "flowinN=419.0 # m^3   STP /min\n",
      "Pfinal=6.3 #gauge\n",
      "Tfinal=325.0 # C\n",
      "Pacetone=501.0 #mm of Hg\n",
      "Dacetone=791.0  #g/L\n",
      "Macetone=58.08  #g\n",
      "T1=300.0 #k\n",
      "P1=1238.0 #mm Hg original\n",
      "\n",
      "#Calculations and printing :\n",
      "\n",
      "print(\"All the values in the textbook are Approximated hence the values in this code differ from those of Textbook\")\n",
      "n2cap=flowinA*Dacetone/Macetone\n",
      "print '%s %.3f' %(\" \\n Molar flowrate of Acetone (mol Acetone/min) = \",n2cap)\n",
      "P=Pfinal*760 + 763\n",
      "y4=Pacetone/P\n",
      "print '%s %.3f' %(\" \\n Mole fraction of Acetone in the final flow (mol Acetone/mol) = \",y4)\n",
      "print '%s %.3f' %(\" \\n Mole fraction of Nitrogen in the final flow (mol Nitrogen/mol) = \",1-y4)\n",
      "n3cap=flowinN/0.0224\n",
      "n4cap=n2cap/y4\n",
      "print(\"By using Overall Molar balance,\")\n",
      "n1cap=n4cap-n2cap-n3cap\n",
      "V1cap=n1cap*0.0224*T1*760/(1*273*P1)\n",
      "print '%s %.3f' %(\"Volumetric Flowrate of Nitrogen (Nitrogen/min) = \",V1cap)\n",
      "raw_input('press enter key to exit')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "All the values in the textbook are Approximated hence the values in this code differ from those of Textbook\n",
        " \n",
        " Molar flowrate of Acetone (mol Acetone/min) =  5447.658\n",
        " \n",
        " Mole fraction of Acetone in the final flow (mol Acetone/mol) =  0.090\n",
        " \n",
        " Mole fraction of Nitrogen in the final flow (mol Nitrogen/mol) =  0.910\n",
        "By using Overall Molar balance,\n",
        "Volumetric Flowrate of Nitrogen (Nitrogen/min) =  547.119\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "press enter key to exit\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 6,
       "text": [
        "''"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.3-1, page no. 202"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "#Initialization of variables\n",
      "import math\n",
      "import numpy\n",
      "from numpy import linalg\n",
      "import scipy\n",
      "from scipy import integrate\n",
      "\n",
      "T= -150.8 + 273.2  #k\n",
      "Vcap= 3./2. #L/mol\n",
      "Tc=126.2 #k\n",
      "Pc=33.5 #atm\n",
      "w=0.040\n",
      "\n",
      "#Calculations and printing :\n",
      "\n",
      "print(\"All the values in the textbook are Approximated hence the values in this code differ from those of Textbook\")\n",
      "Pideal=0.08206*T/Vcap\n",
      "print '%s %.3f' %(\" \\n The value of pressure as per Ideal gas equation (atm) = \",Pideal)\n",
      "Tr=T/Tc\n",
      "B0=0.083 - (0.422/math.pow(Tr,1.6))\n",
      "B1=0.139 - (0.172/math.pow(Tr,4.2))\n",
      "B=0.08206*Tc*(B0+w*B1)/Pc\n",
      "Pvirial=0.08206*T*(1+ B/Vcap)/Vcap\n",
      "print '%s %.3f' %(\"\\n The value of pressure as per Virial gas equation (atm) = \",Pvirial)\n",
      "e=(Pideal-Pvirial)*100/Pvirial\n",
      "print '%s %.3f' %(\" \\n Percentage error due to Ideal gas Equation =\",e)\n",
      "raw_input('press enter key to exit')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "All the values in the textbook are Approximated hence the values in this code differ from those of Textbook\n",
        " \n",
        " The value of pressure as per Ideal gas equation (atm) =  6.696\n",
        "\n",
        " The value of pressure as per Virial gas equation (atm) =  6.196\n",
        " \n",
        " Percentage error due to Ideal gas Equation = 8.072\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "press enter key to exit\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 7,
       "text": [
        "''"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.3-2, page no. 203"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "#Initialization of variables\n",
      "import math\n",
      "import numpy\n",
      "from numpy import linalg\n",
      "import scipy\n",
      "from scipy import integrate\n",
      "\n",
      "V=2.5 #m^3\n",
      "n=1.00 #Kmol\n",
      "T= 300 #K\n",
      "Tc=304.2 #K\n",
      "Pc=72.9 #atm\n",
      "w=0.225\n",
      "R=0.08206\n",
      "\n",
      "#Calculations and printing :\n",
      "\n",
      "print(\"All the values in the textbook are Approximated hence the values in this code differ from those of Textbook\")\n",
      "Vcap=V/n\n",
      "a=0.42747*math.pow(R*Tc,2) /Pc\n",
      "b=0.08664*R*Tc/Pc\n",
      "m=0.48508+ 1.5171*w -0.1561*w*w\n",
      "Tr=T/Tc\n",
      "alpha=math.pow(1+ m*(1-math.sqrt(Tr)),2)\n",
      "P=(R*T/(Vcap-b))-(alpha*a/(Vcap*(Vcap+b)))\n",
      "print '%s %.3f' %(\" \\n Pressure of gas calculated using SRK equation (atm) = \",P)\n",
      "raw_input('press enter key to exit')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "All the values in the textbook are Approximated hence the values in this code differ from those of Textbook\n",
        " \n",
        " Pressure of gas calculated using SRK equation (atm) =  9.381\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "press enter key to exit\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 9,
       "text": [
        "''"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.4-1, page no. 206"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Initialization of variables\n",
      "import math\n",
      "import numpy\n",
      "from numpy import linalg\n",
      "import scipy\n",
      "from scipy import integrate\n",
      "\n",
      "Vcap=50.0 #M^3/hr\n",
      "P=40.0 #bar\n",
      "T=300.0 #K\n",
      "R=8.314\n",
      "M=16.04 #kg/kmol\n",
      "\n",
      "#Calculations and printing :\n",
      "\n",
      "print(\"All the values in the textbook are Approximated hence the values in this code differ from those of Textbook\")\n",
      "z=0.934\n",
      "print '%s %.3f' %(\" \\n From the Table, z= \",z)\n",
      "ncap=P*Vcap*101.325/(z*R*T*1.01325)\n",
      "mcap=ncap*M\n",
      "print '%s %.3f' %(\" \\n Mass flow rate of Methane (Kg/hr) = \",mcap)\n",
      "raw_input('press enter key to exit')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "All the values in the textbook are Approximated hence the values in this code differ from those of Textbook\n",
        " \n",
        " From the Table, z=  0.934\n",
        " \n",
        " Mass flow rate of Methane (Kg/hr) =  1377.071\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "press enter key to exit\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 10,
       "text": [
        "''"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.4-2, page no. 209"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "#Initialization of variables\n",
      "import math\n",
      "import numpy\n",
      "from numpy import linalg\n",
      "import scipy\n",
      "from scipy import integrate\n",
      "\n",
      "n=100.0 #gm-moles\n",
      "V=5.0 #ltr\n",
      "T= -20.6 + 273.2 #K\n",
      "Tc=126.2 #K\n",
      "Pc=33.5 #atm\n",
      "R=0.08206\n",
      "\n",
      "#Calculations and printing :\n",
      "\n",
      "print(\"All the values in the textbook are Approximated hence the values in this code differ from those of Textbook\")\n",
      "Tr=T/Tc\n",
      "Vrideal=V*Pc/(n*R*Tc)\n",
      "print '%s %.3f' %(\" \\n Tr= \",Tr)\n",
      "print '%s %.3f' %(\"\\n Vrideal=\",Vrideal)\n",
      "z=1.77\n",
      "print '%s %.3f' %(\"\\n From the graphs, z=\",z)\n",
      "P=z*R*T*n/V\n",
      "Pr=P/Pc\n",
      "print '%s %.3f' %(\" \\n Pr= \",Pr)\n",
      "print '%s %.3f' %(\" \\n Pressure in the cylinder (atm) = \",P)\n",
      "raw_input('press enter key to exit')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "All the values in the textbook are Approximated hence the values in this code differ from those of Textbook\n",
        " \n",
        " Tr=  2.002\n",
        "\n",
        " Vrideal= 0.162\n",
        "\n",
        " From the graphs, z= 1.770\n",
        " \n",
        " Pr=  21.904\n",
        " \n",
        " Pressure in the cylinder (atm) =  733.784\n"
       ]
      },
      {
       "name": "stdout",
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "press enter key to exit\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 11,
       "text": [
        "''"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5.4-3, page no. 212"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "#Initialization of variables\n",
      "import math\n",
      "import numpy\n",
      "from numpy import linalg\n",
      "import scipy\n",
      "from scipy import integrate\n",
      "\n",
      "yN2=0.25\n",
      "yH2=1.0-yN2\n",
      "P=800.0 #atm\n",
      "T= -70+273.2 #K\n",
      "TcH2=33.0 #K\n",
      "TcN2=126.2 #K\n",
      "PcH2=12.8 #atm\n",
      "PcN2=33.5 #atm\n",
      "R=0.0083\n",
      "#Calculations and printing :\n",
      "\n",
      "print(\"All the values in the textbook are Approximated hence the values in this code differ from those of Textbook\")\n",
      "print(\"Applying newton corrections for Hydrogen,\")\n",
      "TcaH2=TcH2+8.\n",
      "PcaH2=PcH2+8.\n",
      "Tcbar=yH2*TcaH2 + yN2*TcN2\n",
      "Pcbar=yH2*PcaH2 + yN2*PcN2\n",
      "Trbar=T/Tcbar\n",
      "Prbar=P/Pcbar\n",
      "print '%s %.3f' %(\" \\n Trbar = \",Trbar)\n",
      "print '%s %.3f' %(\" \\n Prbar = \",Prbar)\n",
      "Zm=1.86\n",
      "print '%s %.4f' %(\" \\n From the graph, Zm = \",Zm)\n",
      "Vcap=Zm*R*T/P\n",
      "print '%s %.5f' %(\" \\n Specific Volume of Mixture (L/mol) = \",Vcap)\n",
      "raw_input('press enter key to exit')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "All the values in the textbook are Approximated hence the values in this code differ from those of Textbook\n",
        "Applying newton corrections for Hydrogen,\n",
        " \n",
        " Trbar =  3.262\n",
        " \n",
        " Prbar =  33.368\n",
        " \n",
        " From the graph, Zm =  1.8600\n",
        " \n",
        " Specific Volume of Mixture (L/mol) =  0.00392\n"
       ]
      }
     ]
    }
   ],
   "metadata": {}
  }
 ]
}