{
 "metadata": {
  "name": "",
  "signature": "sha256:698d37f412d89d016a22fab7149569fc8652a8ce9fa170122f874fd8734f1895"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 7: Thermodynamics Processes"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.1, page no. 124"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#initialization\n",
      "\n",
      "P1 = 160.0                        #lb/in^2\n",
      "T1 = 100.0                        #F\n",
      "P2 = 140.0                        #lb/in^2\n",
      "T2 = 550.0                        #F\n",
      "\n",
      "#From steam tables\n",
      "h1 = 67.97                        #B/lbm\n",
      "h2 = 1299.3                       #B/lbm\n",
      "s1 = 0.1295                       #B/lbm R\n",
      "s2 = 1.6785                       #B/lbm R\n",
      "\n",
      "#calculation\n",
      "dh = h2-h1\n",
      "ds = s2-s1\n",
      "\n",
      "#result\n",
      "print \"Change in enthalpy = %.1f B/lbm\" %dh\n",
      "print \"Change in entropy = %.4f B/lbm R\" %ds"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in enthalpy = 1231.3 B/lbm\n",
        "Change in entropy = 1.5490 B/lbm R\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.2, page no. 125"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#initialization\n",
      "P1 = 160.0                      #lb/in^2\n",
      "T1 = 100.0                      #F\n",
      "P2 = 140.0                      #lb/in^2\n",
      "T2 = 550.0                      #F\n",
      "\n",
      "#From steam tables\n",
      "h1 = 67.97 \n",
      "s1 = 0.1295\n",
      "h2 = 1300.9\n",
      "s2 = 1.6945\n",
      "\n",
      "#calculation\n",
      "dh = h2-h1\n",
      "ds = s2-s1\n",
      "\n",
      "#result\n",
      "print \"Change in enthalpy = %.1f B/lbm\" %dh\n",
      "print \"Change in entropy = %.4f B/lbm R\" %ds\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in enthalpy = 1232.9 B/lbm\n",
        "Change in entropy = 1.5650 B/lbm R\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.3, page no. 126"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import scipy.integrate\n",
      "\n",
      "#initialization\n",
      "P1 = 30.0                           #lb/in^2\n",
      "T1 = 300+460.0                      #R\n",
      "T2 = 60 +460.0                      #R\n",
      "cp = 0.25                           #B/lbm F\n",
      "R = 53.3                            #ft-lb/lbm R\n",
      "\n",
      "#calculation\n",
      "Q = cp*(T2-T1)\n",
      "du = (cp-R/778)*(T2-T1)\n",
      "W = 778*(Q-du)\n",
      "def c(T):\n",
      "    ds = cp/T\n",
      "    return ds\n",
      "S = scipy.integrate.quadrature(c, T1, T2)[0]\n",
      "\n",
      "#result\n",
      "print \"Heat flow\", Q, \" B/lbm\"\n",
      "print \"change in internal energy\", round(du, 1), \" B/lbm\"\n",
      "print \"the work done is \", W, \" ft-lb/lbm\" #mistake in book for calculation of W\n",
      "print \"Change in entropy = %.3f B/lbm R\" %S"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat flow -60.0  B/lbm\n",
        "change in internal energy -43.6  B/lbm\n",
        "the work done is  -12792.0  ft-lb/lbm\n",
        "Change in entropy = -0.095 B/lbm R\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.4, page no. 129"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#initialization\n",
      "\n",
      "T1 = 300.0                   #F\n",
      "# From steam tables\n",
      "\n",
      "h1 = 269.59                 #B/lbm\n",
      "h2 = 1179.7                 #B/lbm\n",
      "s1 = 0.4369                 #B/lbm R\n",
      "s2 = 1.6350                 #B/lbm R\n",
      "\n",
      "#calculation\n",
      "dh = h2-h1\n",
      "ds = s2-s1\n",
      "\n",
      "#result\n",
      "print \"Change in enthalpy = %.1f B/lbm\" %dh\n",
      "print \"Change in entropy = %.4f B/lbm R\" %ds"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in enthalpy = 910.1 B/lbm\n",
        "Change in entropy = 1.1981 B/lbm R\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.5, page no. 129"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "#initialization\n",
      "v = 12.8                        #ft^3\n",
      "T = 80+460.0                    #R\n",
      "P = 14.0                        #lb/in^2\n",
      "Pf = 500.0                      #lb/in^2\n",
      "\n",
      "#calculation\n",
      "Q = -53.3*T*math.log(Pf/P)/778.0\n",
      "v2 = 53.3*T/(144*Pf)\n",
      "w = v/v2\n",
      "Qdot = w*Q\n",
      "Wdot = w*W\n",
      "ds = Q/T\n",
      "dsbar = ds*w\n",
      "\n",
      "#result\n",
      "print \"Work required = %d ft-lb\" %Wdot\n",
      "print \"Heat transfer = %d B\" %Qdot\n",
      "print \"Change in entropy = %.3f B/lbm \" %dsbar\n",
      "print \"Change in internal energy is 0 cause this is a constant temperature process\"\n",
      "\n",
      "#answers will differ due to roundin offs"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work required = -3295227 ft-lb\n",
        "Heat transfer = -4235 B\n",
        "Change in entropy = -7.844 B/lbm \n",
        "Change in internal energy is 0 cause this is a constant temperature process\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.6, page no. 131"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#initialization\n",
      "P1 = 14.7                       #lb/in^2\n",
      "P2 = 20.0                       #lb/in^2\n",
      "w = 1.0                         #lbm\n",
      "\n",
      "#calculation\n",
      "# From table 3 of appendix\n",
      "v1 = 26.8\n",
      "h1 = 1150.4\n",
      "s1 = 1.7566\n",
      "u1 = h1- 144*P1*v1/778\n",
      "print \"Internal energy 1 = %.1f B/lbm\" %u1\n",
      "\n",
      "\n",
      "# For pressure of 20 lb/in^2 , from table 2\n",
      "v2 = 26.8\n",
      "h2 = 1260.9\n",
      "s2 = 1.8637\n",
      "u2 = h2-144*P2*v2/778\n",
      "du = u2-u1\n",
      "ds = s2-s1\n",
      "\n",
      "#result\n",
      "print \"Change in internal energy = %.1f B/lbm\" %du\n",
      "print \"CHange in entropy = %.4f B/lbm R\" %ds"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Internal energy 1 = 1077.5 B/lbm\n",
        "Change in internal energy = 84.2 B/lbm\n",
        "CHange in entropy = 0.1071 B/lbm R\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.7, page no. 133"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import scipy.integrate\n",
      "import math\n",
      "\n",
      "#initialization\n",
      "P1 = 100.0                      #lb/in^2\n",
      "T1 = 240+460.0                  #R\n",
      "T2 = 740+460.0                  #R\n",
      "cp = 0.171                      #B?lbm F\n",
      "\n",
      "#calculation\n",
      "dq = cp*(T2-T1)\n",
      "def s(T):\n",
      "    ds = cp/T\n",
      "    return ds\n",
      "ds = scipy.integrate.quadrature(s, T1, T2)[0]\n",
      "cpm = 0.247\n",
      "cv = cpm-53.3/778\n",
      "Q = cv*(T2-T1)\n",
      "ds2 = cv*math.log(T2/T1)\n",
      "v1 = 53.3*T1/(144*P1)\n",
      "P2 = P1*(T2/T1)\n",
      "\n",
      "# from table 6\n",
      "h1 = 167.56\n",
      "phi1 = 0.66321\n",
      "u1 = h1-144*P1*v1/778.0\n",
      "h2 = 291.30\n",
      "phi2 = 0.79628\n",
      "u2 = h2-144*P2*v1/778.0\n",
      "Q3 = u2-u1\n",
      "ds3 = phi2-phi1-53.3*math.log(P2/P1)/778.0\n",
      "\n",
      "print \"Part a\"\n",
      "print \"work is zero\"\n",
      "print \"Heat = %.1f B/lbm\" %dq\n",
      "print \"Change in entropy = %.4f B/lbm R\" %ds\n",
      "\n",
      "print \"part b\"\n",
      "print \"Heat = %.1f B/lbm\" %Q\n",
      "print \"Change in entropy = %.4f B/lbm R\" %ds2\n",
      "\n",
      "print \"Part c\"\n",
      "print \"Heat low = %.1f B/lbm\" %Q3\n",
      "print \"Change in entropy = %.5f B/lbm R\" %ds3"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part a\n",
        "work is zero\n",
        "Heat = 85.5 B/lbm\n",
        "Change in entropy = 0.0922 B/lbm R\n",
        "part b\n",
        "Heat = 89.2 B/lbm\n",
        "Change in entropy = 0.0962 B/lbm R\n",
        "Part c\n",
        "Heat low = 89.5 B/lbm\n",
        "Change in entropy = 0.09614 B/lbm R\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.8, page no. 136"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#initialization\n",
      "P1 = 100.0                       #lb/in^2\n",
      "T1 = 500+460.0                   #R\n",
      "P2 = 16.0                        #lb/in^2\n",
      "\n",
      "#calculation\n",
      "# From table 4 of appendix, initial conditions are\n",
      "ht1 = 1279.1\n",
      "st1 = 1.7085\n",
      "hg = 1152.0\n",
      "sg = 1.7549\n",
      "hfg = 969.7\n",
      "sfg = 1.4415\n",
      "st1 = 1.7085\n",
      "Xdash = (sg-st1)/sfg\n",
      "ht2 = hg-(Xdash)*hfg\n",
      "hdiff = ht1-ht2\n",
      "W = hdiff*778\n",
      "\n",
      "#result\n",
      "print \"Change in entropy is zero\"\n",
      "print \"heat trasnfer is zero since adiabatic\"\n",
      "print \"Work done = %d ft-lb/lbm\" %W\n",
      "print \"Change in enthalpy = %.1f B/lbm\" %hdiff"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in entropy is zero\n",
        "heat trasnfer is zero since adiabatic\n",
        "Work done = 123167 ft-lb/lbm\n",
        "Change in enthalpy = 158.3 B/lbm\n"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.9, page no. 137"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#initialization\n",
      "g = 1.4\n",
      "cv = 0.171                  #B/lbm \n",
      "P1 = 14.7                   #lb/in^2\n",
      "P2 = 100                    #lb/in^2\n",
      "T1 = 60+460                 #R\n",
      "w = 1                         #lbm\n",
      "\n",
      "#calculation\n",
      "Tratio = (P2/P1)**((g-1)/g)\n",
      "T2 = T1*Tratio\n",
      "WbyJ = cv*(T1-T2)\n",
      "W = WbyJ*778.0\n",
      "\n",
      "#result\n",
      "print \"Work done = %.1f B/lbm\" %W\n",
      "print \"CHange in internal energy = %d ft-lb/lbm\" %WbyJ\n",
      "\n",
      "#difference in answers due to rounding offs"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work done = -50463.5 B/lbm\n",
        "CHange in internal energy = -64 ft-lb/lbm\n"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.10, page no. 137"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "#initialization\n",
      "P1 = 25.0                       #lb/in^2\n",
      "T1 = 840+460.0                  #R\n",
      "P2 = 14.7                       #lb/in^2\n",
      "\n",
      "#calculation\n",
      "# from table 6 of appendix\n",
      "ht1 = 316.94\n",
      "Prt1 = 32.39\n",
      "Pratio = P1/P2\n",
      "Pr2 = Prt1/Pratio\n",
      "h2 = 272.4\n",
      "V2 = math.sqrt(2*32.2*778.0*(ht1-h2))\n",
      "\n",
      "#result\n",
      "print \"Nozzle exit velocity = %d ft/sec\" %V2\n",
      "\n",
      "#difference in the answers is due to internal rounding off in Python."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Nozzle exit velocity = 1493 ft/sec\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.11, page no. 139"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#initialization\n",
      "P1 = 100.0                      #lb/in^2\n",
      "P2 = 16.0                       #lb/in^2\n",
      "T1 = 500+460.0                  #R\n",
      "eta = 0.996\n",
      "\n",
      "#calculation\n",
      "# from appendix table 4\n",
      "ht1 = 1279.1\n",
      "st1 = 1.7085\n",
      "hg = 1152\n",
      "sg = 1.7549\n",
      "hfg = 969.7\n",
      "sfg = 1.4415\n",
      "ht2 = hg-(1-eta)*hfg\n",
      "st2 = sg-(1-eta)*sfg\n",
      "WbyJ = ht1-ht2\n",
      "W = WbyJ*778\n",
      "ds = st2-st1\n",
      "\n",
      "#result\n",
      "print \"Work done = %d ft-lb/lbm\" %W #difference due to rounding off\n",
      "print \"Change in enrtropy = %.4f B/lbm R\" %ds"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work done = 101901 ft-lb/lbm\n",
        "Change in enrtropy = 0.0406 B/lbm R\n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.12, page no. 140"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "#initialization\n",
      "P1 = 14.7                       #lb/in^2\n",
      "T1 = 60+460.0                   #R\n",
      "P2 = 100.0                      #lb/in^2\n",
      "T2 = 470+460.0                  #R\n",
      "cv = 0.171                      #B/lbm F\n",
      "cp = 0.24                       #B/lbm F\n",
      "\n",
      "#calculation\n",
      "WbyJ=cv*(T1-T2)\n",
      "W=778*WbyJ\n",
      "ds=cp*math.log(T2/T1) - 53.3*math.log(P2/P1)/778.0\n",
      "\n",
      "#result\n",
      "print \"Work done = %d ft-lb/lbm\" %W\n",
      "print \"Change in entropy = %.4f B/lbm R\" %ds"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work done = -54545 ft-lb/lbm\n",
        "Change in entropy = 0.0082 B/lbm R\n"
       ]
      }
     ],
     "prompt_number": 12
    }
   ],
   "metadata": {}
  }
 ]
}