{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h1>Chapter 4: Evaluating Properties</h1>"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h2>Example 4.01, page: 68</h2>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "\n",
      "#  Initialization  of  Variable\n",
      "V = 0.5 #volume in m3\n",
      "P1 = 1  #pressure bar\n",
      "P2 = 1.5 #pressure bar\n",
      "vf1 = 1.0432/1000 # m3/kg\n",
      "vf2=1.0528/1000 # m3/kg\n",
      "vg1 = 1.694 # in m3/kg\n",
      "vg2 = 1.159 # in m3/kg\n",
      "x1 = 0.5\n",
      "\n",
      "# calculations:\n",
      "#The specific volume at state 1 and 2\n",
      "v1 = vf1 + x1*(1.694-vf1)\n",
      "v2 = v1\n",
      "#from  table T-3\n",
      "T1 = 99.63; # in deg C\n",
      "T2 = 111.4\n",
      "# the total mass, m\n",
      "m = V/v1\n",
      "# the mass of vapor at state 1 and 2\n",
      "mg1 = x1*m\n",
      "x2 = (v1-vf2)/(vg2-vf2)\n",
      "mg2 = x2*m\n",
      "#if heating continued, from table:\n",
      "vg3 = 0.8475 #m3/kg\n",
      "p3 = 2.11 # bar \n",
      "\n",
      "#Results\n",
      "print  \"a) temperature = \", round(T1,2),\"degC at stage 1 and \", round(T2,2),\"degC at stage 2\"\n",
      "print  \"b) mass  of  vapor =\", round(mg1,3),\" kg at stage 1 and\",round(mg2,3),\"kg at stage 2\"\n",
      "print  \"c) If heating continued, when the container holds only saturated vapor then pressure =\", round(p3,2),\"bar\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "a) temperature =  99.63 degC at stage 1 and  111.4 degC at stage 2\n",
        "b) mass  of  vapor = 0.295  kg at stage 1 and 0.431 kg at stage 2\n",
        "c) If heating continued, when the container holds only saturated vapor then pressure = 2.11 bar\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h2>Example 4.02, page: 69</h2>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "\n",
      "# Initialization  of  Variable\n",
      "m = 0.1; # mass in lb\n",
      "P2=20 #pressure in lbf/in2\n",
      "T2 = 65 # in deg F\n",
      "\n",
      "# calculations:\n",
      "# from table, specific volumes\n",
      "vg1=2.2661\n",
      "v1 = vg1\n",
      "#volumes occupied by the refrigerant at states 1 and 2\n",
      "V1 = m*v1\n",
      "# from table, specific volume at stage 2\n",
      "v2=2.6704;\n",
      "V2 =m*v2\n",
      "\n",
      "# work\n",
      "W = P2*(V2-V1)*144/778 # in Btu\n",
      "\n",
      "#Results\n",
      "print  \"a) volumes occupied by the refrigerant at states 1 and 2 are\", round(V1,4),\"ft3 and \", round(V2,4),\"ft3 respectively\"\n",
      "print  \"b) work for the process is\", round(W,4),\"Btu\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "a) volumes occupied by the refrigerant at states 1 and 2 are 0.2266 ft3 and  0.267 ft3 respectively\n",
        "b) work for the process is 0.1497 Btu\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h2>Example 4.03, page: 73</h2>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "\n",
      "# Initialization  of  Variable\n",
      "V=10.0# volume ft3\n",
      "T1 = 212 # indeg F\n",
      "P2 = 20 # pressure in lbf/in2\n",
      "\n",
      "#calculations:\n",
      "# from table, specific volume\n",
      "v1 = 26.8 # in ft3/lb\n",
      "u1=1077.6 #btu/lb\n",
      "v2 = v1\n",
      "# therefore\n",
      "u2 = 1161.6 # in Btu/lb\n",
      "T2 = 445 # deg F\n",
      "# work\n",
      "m = V/v1\n",
      "W = -1*m*(u2-u1)\n",
      "\n",
      "#Results\n",
      "print  \"a) Temperature is\", T2,\" deg F\"\n",
      "print \"b) work during the process is\", round(W,1),\" Btu\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "a) Temperature is 445  deg F\n",
        "b) work during the process is -31.3  Btu\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h2>Example 4.04, page: 74</h2>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "\n",
      "# Initialization  of  Variable\n",
      "P1 = 10  #pressure bar\n",
      "T1 = 400 # temp in deg C\n",
      "T2 = 150 #  temp in deg C\n",
      "vf3 = 1.0905E-3 # in m3/kg\n",
      "vg3 = 0.3928 # in m3/kg\n",
      "\n",
      "# calculations:\n",
      "#From Table, specific volume at state 1 and 2\n",
      "v1 = 0.3066 #in m3/kg\n",
      "u1 = 2957.3 # in kJ/kg\n",
      "v2 = 0.1944 # m3/kg\n",
      "#work\n",
      "Wm = P1*(v2-v1)*10**2\n",
      "\n",
      "#heat transfer\n",
      "v3 = v2\n",
      "x3 = (v3 - vf3)/(vg3 - vf3)\n",
      "#from Table\n",
      "uf3 = 631.68 # kJ/kg\n",
      "ug3 = 2559.5 #kJ/kg\n",
      "u3 = uf3 + x3*(ug3-uf3)\n",
      "\n",
      "Qm = u3 - u1 + Wm\n",
      "\n",
      "#Results\n",
      "print  \"b)Work =\",round(Wm,1),\"kJ/kg\"\n",
      "print  \"c)Heat Transfer =\",round(Qm,1),\"kJ/kg\"\n",
      "#answer approximated in book"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "b)Work = -112.2 kJ/kg\n",
        "c)Heat Transfer = -1486.4 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h2>Example 4.06, page: 80</h2>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "\n",
      "# Initialization  of  Variable\n",
      "P1 = 20E6 # pressure pa\n",
      "T1 = 520 # temp in deg C\n",
      "T2 = 400  #temp deg C\n",
      "M = 18.02 #molar mass in kg/kmol\n",
      "Rbar = 8314 #in Nm/kmol-K\n",
      "\n",
      "#calculations:\n",
      "R = Rbar/M\n",
      "#From Table T-1\n",
      "Tc = 647.3 #in K\n",
      "Pc = 22.09E6 # in Pa\n",
      "#reduced Temp\n",
      "Tr1 = (T1 + 273)/Tc\n",
      "#reduced Pressure\n",
      "Pr1 = P1/Pc\n",
      "#compressibility factor\n",
      "Z = 0.83\n",
      "#specific volume\n",
      "v1 = Z*Rbar*(T1+273)/(M*P1)\n",
      "\n",
      "#Constant refuced value of spec vol\n",
      "vr = v1*Pc/(R*Tc)\n",
      "#at state 2, reduced Temp\n",
      "Tr2 = (T2+273)/Tc\n",
      "# from compressibility chart\n",
      "Pr2 = 0.69\n",
      "\n",
      "P2 = Pc*Pr2\n",
      "\n",
      "#Results\n",
      "print  \"a) specific volume of the water vapor at initial stage is\", round(v1,4),\"m3/kg\"\n",
      "print  \"b) Pressure at final stage is\", round(P2/1E6,2),\"Mpa\" \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "a) specific volume of the water vapor at initial stage is 0.0152 m3/kg\n",
        "b) Pressure at final stage is 15.24 Mpa\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h2>Example 4.07, page: 82</h2>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "\n",
      "# Initialization  of  Variable\n",
      "m = 1 #mass in lb\n",
      "P1 = 1 # atm\n",
      "T1 = 540 # in deg R\n",
      "P2 = 2 # in Atm\n",
      "R = 1545/28.97\n",
      "\n",
      "#calculations:\n",
      "#Using pv=RT, the temperature at state 2 is\n",
      "T2 = P2*T1/P1\n",
      "\n",
      "#Since pv=RT, the specific volume at state 3 is\n",
      "v3 = R*T2/(P1*14.7*144)\n",
      "\n",
      "#Results\n",
      "print  \"b)temperature  at state 2 is\", round(T2,0),\"degR\"\n",
      "print  \"c)specific  volume at state 3 is \", round(v3,1) ,\"ft3/lb\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "b)temperature  at state 2 is 1080.0 degR\n",
        "c)specific  volume at state 3 is  27.2 ft3/lb\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h2>Example 4.08, page: 86</h2>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "\n",
      "# Initialization  of  Variable\n",
      "m = 2 # mass lb\n",
      "T1 = 540 #in degR\n",
      "P1 = 1 # in atm\n",
      "T2 = 840 #in degR\n",
      "P2 = 6 # in atm\n",
      "Q = -20 # in Btu\n",
      "\n",
      "# calculations:\n",
      "#From Table T-9E\n",
      "u1 = 92.04 # in Btu/lb\n",
      "u2 = 143.98 # in Btu/lb\n",
      "#work\n",
      "W = Q - m*(u2-u1)\n",
      "\n",
      "#Results\n",
      "print  \"work  done  during the process is\", round(W,1),\"Btu\" \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "work  done  during the process is -123.9 Btu\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h2>Example 4.10, page: 87</h2>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "\n",
      "# Initialization  of  Variable\n",
      "m1co = 2 #kg\n",
      "T1co = 77 # degC\n",
      "P1co = 0.7 #bar\n",
      "\n",
      "m2co = 8 #kg\n",
      "T2co = 27 # degC\n",
      "P2co = 1.2 #bar\n",
      "\n",
      "Tf = 42 # degC\n",
      "Cv = 0.745 #kJ/kg-K\n",
      "\n",
      "#calculations:\n",
      "#final pressure\n",
      "Pf = (m1co + m2co)*Tf/((m1co*T1co/P1co) + (m2co*T2co/P2co))\n",
      "\n",
      "#heat\n",
      "Q = m1co*Cv*(Tf-T1co) + m2co*Cv*(Tf-T2co)\n",
      "\n",
      "#Results\n",
      "print  \"a)final  pressure is\", round(Pf,2),\"bar\"\n",
      "print  \"b)heat  transfer  for the process is\", round(Q,2),\"kJ\" \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "a)final  pressure is 1.05 bar\n",
        "b)heat  transfer  for the process is 37.25 kJ\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h2>Example 4.11, page: 90</h2>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "import math\n",
      "\n",
      "# Initialization  of  Variable\n",
      "P1 = 1 #atm\n",
      "T1 = 70 # degF\n",
      "P2 = 5 #atm\n",
      "n = 1.3\n",
      "R = 1.986/28.97 #Btu/lb-degR\n",
      "\n",
      "#calculations:\n",
      "#Temp at 1 in rankine\n",
      "T1r = (((T1 - 32)*5/9)+273)*1.8\n",
      "#temp at 2 in Rankine\n",
      "T2r = T1r*(P2/P1)**((n-1)/n)\n",
      "\n",
      "#work per unit mass\n",
      "Wm = R*(T2r-T1r)/(1-n)\n",
      "#heat per unit mass\n",
      "#from table T-9E\n",
      "u2 = 131.88 #Btu/lb\n",
      "u1 = 90.33 #Btu/lb\n",
      "Qm = Wm + (u2-u1)\n",
      "\n",
      "#Results\n",
      "print  \"Work per  unit mass is\", round(Wm,2),\"Btu/lb\"\n",
      "print  \"heat transfer per unit mass is\",round(Qm,2),\"Btu/lb\"\n",
      "# answer wrong in book\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work per  unit mass is -54.41 Btu/lb\n",
        "heat transfer per unit mass is -12.86 Btu/lb\n"
       ]
      }
     ],
     "prompt_number": 14
    }
   ],
   "metadata": {}
  }
 ]
}