{
 "metadata": {
  "name": "",
  "signature": "sha256:4f8260f1b2df9e05157c56dfea1a72ed7a44f559ce07767048b00c505967ad51"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 7: Availability and General Thermodynamic Relations"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1, page no. 230"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "\n",
      "#Variable Declaration: \n",
      "p1 = 1.6 #Pressure of entering steam(in MPa):\n",
      "T1 = 300+273 #Temperature of entering steam(in K):\n",
      "p2 = 0.1 #Pressure of leaving steam(in MPa):\n",
      "T2 = 150+273 #Temperature of leaving steam(in K):\n",
      "c2 = 150 #Velocity of the leaving steam(in m/s):\n",
      "m = 2.5 #Mass flow rate(in kg/s):\n",
      "#From steam tables:\n",
      "h1 = 3034.8                             #kJ/kg\n",
      "s1 = 6.8844                             #kJ/kg.K\n",
      "h2 = 2776.4                             #kJ/kg\n",
      "s2 = 7.6134                             #kJ/kg.K\n",
      "\n",
      "#Calculations:\n",
      "T0 = 15+273 #Surrounding temperature(in K):\n",
      "Wmax = (h1-h2)-T0*(s1-s2)-(c2**2)/2*10**(-3) #Maxiimum work possible(in kW):\n",
      "\n",
      "#Results:\n",
      "print \"Maximum work possible: \",round(m*Wmax,2),\"kW\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Maximum work possible:  1142.76 kW\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2, page no. 231"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "from math import log\n",
      "\n",
      "#Variable Declaration: \n",
      "pa = 1 #Pressure of air(in bar) for tank A:\n",
      "m = 1 #Mass of air(in kg):\n",
      "Cv = 0.717 #Value of Cv(in kJ/kg.K):\n",
      "T = 50+273 #Temperature(in K):\n",
      "R = 0.287 #Gas costant(in kJ/kg.K):\n",
      "p0 = 1 #Atmospheric pressure(in bar):\n",
      "T0 = 15+273 #Atmosphere temperature(in K):\n",
      "Cp = 1.004 #Value of Cp(in kJ/kg.K):\n",
      "pb = 3 #Pressure(in bar) for tank B:\n",
      "\n",
      "#Calculations:\n",
      "AA = m*(Cv*(T-T0)+R*(p0/pa*T-T0)-T0*Cp*log(T/T0)+T0*R*log(pa/p0)) #Availability of air in tank A(in kJ):\n",
      "AB = m*(Cv*(T-T0)+R*(p0/pb*T-T0)-T0*Cp*log(T/T0)+T0*R*log(pb/p0)) #Availability of air in tank B(in kJ):\n",
      "\n",
      "#Results:\n",
      "print \"Availabiltiy of air in tank A: \",round(AA,2),\"kJ\"\n",
      "print \"Availability of air in tank B: \",round(AB,2),\"kJ\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Availabiltiy of air in tank A:  1.98 kJ\n",
        "Availability of air in tank B:  30.98 kJ\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3, page no. 232"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "\n",
      "#Variable Declaration: \n",
      "m = 15 #Mass of steam(in kg):\n",
      "p1 = 10 #Pressure of entering steam(in bar):\n",
      "T1 = 300+273 #Temperature(in K):\n",
      "p2 = 0.05 #Pressure of leaving steam(in bar): \n",
      "x = 0.95 #Dryness fraction:\n",
      "v2 = 160 #Velocity(in m/s):\n",
      "p0 = 1 #Atmosheric pressure(in bar):\n",
      "T0 = 15+273 #Atmospheric temperature(in K):\n",
      "#From steam tables:\n",
      "h1 = 3051.2                     #kJ/kg\n",
      "s1 = 7.1229                     #kJ/kg.K\n",
      "sf = 0.4764                     #kJ/kg.K\n",
      "sfg = 7.9187                    #kJ/kg.K\n",
      "hf = 137.82                     #kJ/kg\n",
      "hfg = 2423.7                    #kJ/kg\n",
      "h0 = 62.99                      #kJ/kg\n",
      "s0 = 0.2245                     #kJ/kg.K\n",
      "\n",
      "#Calculations:\n",
      "h2 = hf+x*hfg #Enthalpy at exit of turbine(in kJ/kg):\n",
      "s2 = sf+x*sfg #Entropy at exit of turbine(in kJ/kg.K):\n",
      "W = (h1-h2)-v2**2/2*10**(-3) #Work output(in kJ/kg):\n",
      "pW = m*W #Power output(in kW):\n",
      "Wmax = (h1-T0*s1)-(h2+v2**2/2*10**(-3)-T0*s2) #Maximum work given end states(in kW):\n",
      "Ae = (h2-h0)+v2**2/2*10**(-3)-T0*(s2-s0) #Maximum wor kavailable from exhaust steam(in kJ/kg):\n",
      "Wme = m*Ae #Maximum power that could be obtained from exhaust steam(in kW):\n",
      "\n",
      "#Results:\n",
      "print \"Power output: \",round(pW,1), \"kW\" \n",
      "print \"Maximum power output: \" ,round(m*Wmax,1), \"kW\"\n",
      "print \"Maximum power from exhaust steam: \",round(Wme,1), \"kW\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Power output:  8971.0 kW\n",
        "Maximum power output:  12756.4 kW\n",
        "Maximum power from exhaust steam:  2265.6 kW\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4, page no. 234"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "   \n",
      "#Variable Declaration: \n",
      "m = 5  #Mass of steam(in kg):\n",
      "z1 = 10   #Initial elevation(in m):\n",
      "V1 = 25   #Initial velocity(in m/s):\n",
      "z2 = 2    #Final elevation(in m):\n",
      "V2 = 10  #Final velocity(in m/s):\n",
      "#Dead state of water\n",
      "u0 = 104.86         #kJ/kg \n",
      "v0 = 1.0029*10**(-3)#m3/kg\n",
      "s0 = 0.3673         #kJ/kg\u00b7K\n",
      "p0 = 100            #kPa\n",
      "T0 = 25+273         #K\n",
      "#Initial state\n",
      "u1  =  2550         #kJ/kg \n",
      "v1  =  0.5089       #m3/kg\n",
      "s1  =  6.93         #kJ/kg\u00b7K\n",
      "#Final state\n",
      "u2 = 83.94          #kJ/kg \n",
      "v2 = 1.0018*10**(-3)#m3/kg\n",
      "s2 = 0.2966         #kJ/kg\u00b7K\n",
      "g = 9.81    #Acceleration due to gravity(in m/s**2):\n",
      "\n",
      "#Calculation:\n",
      "A1 = m*((u1-u0)*10**3+p0*10**3*(v1-v0)-T0*(s1-s0)*10**3+V1**2/2+g*z1)#Availability at initial state(in kJ):\n",
      "A2 = m*((u2-u0)*10**3+p0*10**3*(v2-v0)-T0*(s2-s0)*10**3+V2**2/2+g*z2)#Availability at final state(in kJ):\n",
      "dA = A2-A1    #Change in availability(in kJ)\n",
      "\n",
      "#Results:\n",
      "print \"Initial availabilty: \",round(A1/10**3,2), \"kJ\"\n",
      "print \"Final availabilty:\",round(A2/10**3,2),\"kJ\"\n",
      "print \"Availability decreases by: \",round(-dA/10**3,2),  \"kJ\"\t\t\t"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Initial availabilty:  2703.28 kJ\n",
        "Final availabilty: 1.09 kJ\n",
        "Availability decreases by:  2702.19 kJ\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 6, page no. 235"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "\n",
      "#Variable Declaration: \n",
      "T1 = 800+273 #Temperature of IC engine(in K):\n",
      "W = 1050 #Work per kg of gas in engine(in kJ/kg):\n",
      "Cp = 1.1 #Cp of gas(in kJ/kg.K):\n",
      "\n",
      "#Calculations:\n",
      "T0 = 30+273 #Temperature of the surroundings(in K):\n",
      "dSsys = W/T1 #Change in entropy of system(in kJ/kg.K):\n",
      "dSsurr = -Cp*(T1-T0)/T0 #Change in entropy of surroundings(in kJ/kg.K):\n",
      "L = -T0*(dSsys+dSsurr) #Loss of available energy(in kJ/kg):\n",
      "r = L/W #Ratio of lost available exhaust energy to engine work:\n",
      "\n",
      "#Results:\n",
      "print \"Ratio of available exhaust energy to engine work: \",round(r,3)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Ratio of available exhaust energy to engine work:  0.524\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7, page no. 236"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "\n",
      "#Variable Declaration: \n",
      "m = 10 #Mass of water(in kg):\n",
      "T1 = 150+273   #Initial temperature(in K):\n",
      "V1 = 25  #Initial velocity(in m/s):\n",
      "z1 = 10 #Initial elevation(in m):\n",
      "T2 = 20+273   #Final temperature(in K):\n",
      "V2 = 10         #Final velocity(in m/s):\n",
      "z2 = 3   #Final elevation(in m):\n",
      "p0 = 0.1  #Pressure of environment(in MPa):\n",
      "T0 = 25+273.13   #Temperature of environment(in K):\n",
      "g = 9.8   #Acceleration due to gravity(in m/s**2):\n",
      "#Dead state of water, From steam tables:\n",
      "u0 = 104.88         #kJ/kg\n",
      "v0 = 1.003*10**(-3) #m3/kg\n",
      "s0 = 0.3674         #kJ/kg\u00b7K\n",
      "u1 = 2559.5         #kJ/kg\n",
      "v1 = 0.3928         #m3/kg\n",
      "s1 = 6.8379         #kJ/kg\u00b7K\n",
      "u2 = 83.95          #kJ/kg\n",
      "v2 = 0.001002       #m3/kg\n",
      "s2 = 0.2966         #kJ/kg\u00b7K\n",
      "A1 = m*((u1-u0)+p0*10**3*(v1-v0)-T0*(s1-s0)+(V1**2/2+g*z1)*10**-3)#Availability at initial state(in kJ):\n",
      "A2 = m*((u2-u0)+p0*10**3*(v2-v0)-T0*(s2-s0)+(V2**2/2+g*z2)*10**-3)#Availability at final state(in kJ):\n",
      "dA = A2-A1  #Change in availability(in kJ):\n",
      "\n",
      "#Results:\n",
      "print \"Initial availabilty: \",round(A1,2),\"kJ\"\n",
      "print \"Final availabilty: \",round(A2,2),\"kJ\"\n",
      "print \"Availability decreases: \",round(-dA,2),\"kJ\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Initial availabilty:  5651.6 kJ\n",
        "Final availabilty:  2.57 kJ\n",
        "Availability decreases:  5649.03 kJ\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8, page no. 237"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "\n",
      "#Variable Declaration: \n",
      "m = 5      #Mass flow rate(in kg/s):\n",
      "#At inlet to turbine,\n",
      "p1 = 5                          #MPa \n",
      "T1 = 500+273.15                 #K\n",
      "h1 = 3433.8                     #kJ/kg\n",
      "s1 = 6.9759                     #kJ/kg.K\n",
      "#At exit from turbine.\n",
      "p2 = 0.2                        #MPa\n",
      "T2 = 140+273.15                 #K\n",
      "h2 = 2748                       #kJ/kg\n",
      "s2 = 7.228                      #kJ/kg\u00b7K\n",
      "#At dead state,\n",
      "p0 = 101.3                      #kPa\n",
      "T0 = 25+273.15                  #K\n",
      "h0 = 104.96                     #kJ/kg\n",
      "s0 = 0.3673                     #kJ/kg\u00b7K\n",
      "Q = 600 #Heat loss(in kJ/s):\n",
      "\n",
      "#Calculation:\n",
      "A1 = m*((h1-h0)-T0*(s1-s0))\t#Availablity of steam at inlet(in kJ):\n",
      "W = m*(h1-h2)-Q #Turbine output(in kW):\n",
      "Wmax = m*((h1-h2)-T0*(s1-s2)) #Maximum output(in kW):\n",
      "I = Wmax-W #Irreversibilty(in kW):\n",
      "\n",
      "#Results:\n",
      "print \"Availability of steam at inlet: \",round(A1,2),\"kJ\"\n",
      "print \"Turbine output: \",round(W),\"kW\"\n",
      "print \"Maximum output: \",round(Wmax,2),\"kW\"\n",
      "print \"Irreversibility: \",round(I,2),\"kW\"\n",
      "print \"_____Please Check there is a calculation mistake in Wmax hence answer differs_____\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Availability of steam at inlet:  6792.43 kJ\n",
        "Turbine output:  2829.0 kW\n",
        "Maximum output:  3804.82 kW\n",
        "Irreversibility:  975.82 kW\n",
        "_____Please Check there is a calculation mistake in Wmax hence answer differs_____\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11, page no. 239"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "\n",
      "#Variable Declaration: \n",
      "Q = 500 #Heat removed(in kJ):\n",
      "T1 = 835 #Temperature of the heat reservoir(in K):\n",
      "T2 = 720 #Temperature of the system(in K):\n",
      "T0 = 280 #Temperature of surroundings(in K):\n",
      "\n",
      "#Calculation:\n",
      "A1 = T0*Q/T1 #Availability for heat reservoir(in kJ/kg.K):\n",
      "A2 = T0*Q/T2 #Availability for system(in kJ/kg.K):\n",
      "Anet = A1-A2 #Net loss of available energy(in kJ/kg.K):\n",
      "\n",
      "#Results:\n",
      "print \"Loss of available energy: \",round(-Anet,2),\"kJ/kg.K\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Loss of available energy:  26.78 kJ/kg.K\n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12, page no. 240"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "\n",
      "#Variable Declaration: \n",
      "h1 = 4142 #Enthalpy at entrance(in kJ/kg):\n",
      "h2 = 2585 #Enthalpy at exit(in kJ/kg):\n",
      "A1 = 1787 #Availability of steam at entrance(in kJ/kg):\n",
      "A2 = 140  #Availability of steam at exit(in kJ):\n",
      "\n",
      "#Calculation:\n",
      "Wmax = A1-A2 #Maximum work possible(in kJ/kg):\n",
      "Wact = h1-h2 #Actual work from turbine(in kJ/kg):\n",
      "\n",
      "#Results:\n",
      "print \"Actual work: \",round(Wact),\"kJ/kg\" \n",
      "print \"Maximum possible work: \",round(Wmax),\"kJ/kg\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Actual work:  1557.0 kJ/kg\n",
        "Maximum possible work:  1647.0 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 28
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 13, page no. 240"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "  \n",
      "#Variable Declaration: \n",
      "Tmin = 20+273 #Minimum temperature(in K):\n",
      "Tmax = 500+273 #Maximum temperature(in K):\n",
      "n = 0.25 #Efficiency of heat engine:\n",
      "\n",
      "#Calculations:\n",
      "nrev = 1-Tmin/Tmax #Reversible engine efficiency:\n",
      "n2 = n/nrev #Second law efficiency:\n",
      "\n",
      "#Result:\n",
      "print \"Second law efficiency: \",round(n2*100,2),\"%\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Second law efficiency:  40.26 %\n"
       ]
      }
     ],
     "prompt_number": 30
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 14, page no. 240"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "\n",
      "from math import log\n",
      "#Variable Declaration: \n",
      "Va = 6 #Volume of compartment A(in m**3):\n",
      "Vb = 4 #Volume of compartment B(in m**3):\n",
      "p1 = 6 #Pressure in compartment A(in bar):\n",
      "T1 = 600 #Temperature in compartment A(in K):\n",
      "p0 = 1 #Atmosheric pressure(in bar):\n",
      "T0 = 300 #Atmosheric temperature(in K):\n",
      "r = 1.4 #Adiabatic index of compression:\n",
      "R = 0.287 #Gas constant(in J/kg.K):\n",
      "Cv = 0.718 #Value of Cv(in kJ/kg.K):\n",
      "\n",
      "#Calculation:\n",
      "V2 = Va+Vb #Final volume(in m**3):\n",
      "T2 = T1*(Va/V2)**(r-1) #Final temperature(in K):\n",
      "m = p1*10**5*Va/(R*10**3*T1) #Mass of air(in kg):\n",
      "dSs = round(m*(Cv*log(T2/T1)+R*log(V2/Va)),3)#Change in entropy of control system(in kJ/kg.K):\n",
      "I = T0*dSs #Loss of available energy or irreversibilty(in kJ):\n",
      "\n",
      "#Results:\n",
      "print \"Loss of available energy: \",round(-I,3),\"kJ\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Loss of available energy:  0.6 kJ\n"
       ]
      }
     ],
     "prompt_number": 33
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16, page no. 242"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      " \n",
      "#Variable Declaration: \n",
      "Tmin = 30+273  #Minimum temperature(in K):\n",
      "Tmax = 700+273 #Maximum temperature(in K):\n",
      "T0 = 17+273   #Temperature of surroundings(in K):\n",
      "Q1 = 2*10**4 #Rate at which engine receives heat(in kJ/min):\n",
      "Wu = 0.13*10**3   #Measured output of the engine(in kW):\n",
      "\n",
      "#Calculation:\n",
      "nrev = 1-Tmin/Tmax  #Efficiency:\n",
      "Wrev = nrev*Q1/60   #Availability or reversible work(in kJ/s):\n",
      "I = Wrev-Wu    #Rate of irreversibility(in kJ/s):\n",
      "n2 = Wu/Wrev  #Second law efficiency:\n",
      "\n",
      "#Results:\n",
      "print \"Availability: \",round(Wrev*60/10**4,2),\" x 10^4 kJ/min\"\n",
      "print \"Rate of irreversibility: \",round(I,2),\"kW\"\n",
      "print \"Second Law Efficiency: \",round(n2*100,2),\"%\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Availability:  1.38  x 10^4 kJ/min\n",
        "Rate of irreversibility:  99.53 kW\n",
        "Second Law Efficiency:  56.64 %\n"
       ]
      }
     ],
     "prompt_number": 37
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17, page no. 242"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      " \n",
      "#Variable Declaration: \n",
      "p1 = 1.5 #Initial pressure(in bar):\n",
      "T1 = 60+273 #Initial temperature(in K):\n",
      "p2 = 2.5 #Final pressure(in bar):\n",
      "Tres = 400+273\t    \t#Temperature of the reservoir(in K):\n",
      "T0 = 27+273\t\t#Temperature of surroundings(in K):\n",
      "Cp = 1.005\t\t#Cp of air(in kJ/kg.K):\n",
      "\n",
      "#Calculations:\n",
      "T2 = T1*p2/p1\t\t#Final temperature(in K):\n",
      "Q = Cp*(T2-T1)\t\t#Heat addition to air in the tank(in kJ/kg):\n",
      "dSs = Q/T1\t\t#Change in entropy of the system(in kJ/kg.K):\n",
      "dSe = -Q/Tres\t\t#Change in entropy of environment(in kJ/kg.K):\n",
      "dS = dSs+dSe\t\t#Total change in entropy(in kJ/kg.K):\n",
      "L = T0*dS\t\t#Loss of available energy(in kJ/kg):\n",
      "\n",
      "#Results:\n",
      "print \"Loss of available energy:\",round(L,1),\"kJ/kg.K\"\t\t\t\t"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Loss of available energy: 101.5 kJ/kg.K\n"
       ]
      }
     ],
     "prompt_number": 39
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 19, page no. 244"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "  \n",
      "\n",
      "#Variable Declaration: \n",
      "#From steam tables:\n",
      "vg = 0.12736\t\t\t\t\n",
      "vf = 0.001157\n",
      "p205 = 1.7230\n",
      "p195 = 1.3978\n",
      "T = 200+273\n",
      "hfga = 1940.7\n",
      "\n",
      "#Calculation:\n",
      "vfg = vg-vf\t\t\t\t#Value of vfg(in m**3/kg):\n",
      "r = (p205-p195)/(205-195)\t\t#Value of dp/dT(in MPa/K):\n",
      "hfg = T*vfg*r*10**3\t\t\t#By Clapeyron equation(in kJ/kg):\n",
      "\n",
      "#Results:\n",
      "print \"Calculated enthalpy of vaporization: \",round(hfg,2),\"kJ/kg\"\t\t\t\t\n",
      "print \"Enthalpy of vaporization from steam table:\",round(hfga,1),\"kJ/kg\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Calculated enthalpy of vaporization:  1941.25 kJ/kg\n",
        "Enthalpy of vaporization from steam table: 1940.7 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 45
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 20, page no. 244"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "  \n",
      "from math import log\n",
      "#Variable Declaration: \n",
      "#From steam tables:\n",
      "p5 = 260.96         #kPa\t\t\t\t\n",
      "p15 = 182.60        #kPa\n",
      "vg10 = 0.07665      #m**3/kg\n",
      "vf10 = 0.00070      #m**3/kg\n",
      "R = 0.06876         #kJ/kg.K\n",
      "hfg10 = 156.3       #kJ/kg\n",
      "\n",
      "#Calculation:\n",
      "T = -5+273\n",
      "T1 = -15+273\n",
      "T2 = -5+273\n",
      "hfg = T*(vg10-vf10)*(p5-p15)/(15-5)\t#Value of hfg, by Clapeyron equation:\n",
      "hfg1 = log(p5/p15)*R*(T1*T2)/((T2-T1))\t#By Clapeyron-Clausius equation:\n",
      "d = (hfg1-hfg)/hfg*100\t\t\t#Deviation:\n",
      "\n",
      "#Results:\n",
      "print \"hfg by Clapeyron equation: \",round(hfg,2),\"kJ/kg\"\t\t\t\t\n",
      "print \"hfg by Clapeyron-Clausius equation: \",round(hfg1,2),\"kJ/kg\"\n",
      "print \"Percentage deviation in hfg value by Clapeyron-Clausius equation compared to the value from Clapeyron equation: \",round(d,2),\"%\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "hfg by Clapeyron equation:  159.5 kJ/kg\n",
        "hfg by Clapeyron-Clausius equation:  169.76 kJ/kg\n",
        "Percentage deviation in hfg value by Clapeyron-Clausius equation compared to the value from Clapeyron equation:  6.44 %\n"
       ]
      }
     ],
     "prompt_number": 48
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21, page no. 245"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "\n",
      "#Variable Declaration: \n",
      "#From steam tables:\n",
      "v350 = 0.9534\t    \n",
      "v250 = 0.7964\n",
      "v300 = 0.8753\n",
      "v350kPa = 0.76505\n",
      "v250kPa = 1.09575\n",
      "\n",
      "#Calculation:\n",
      "ve = (v350-v250)/(v300*(350-250))\t#Volume expansivity(in 1/K):\n",
      "ic = -(v350kPa-v250kPa)/(v300*(350-250))#Isothermal compressibility(in 1/kPa):\n",
      "\n",
      "#Results:\n",
      "print \"Volume expansivity: \",round(ve*10**3,4),\"x 10^-3 K^-1\"\t\t\t\t\n",
      "print \"Isothermal compressibility: \",round(ic*10**3,3),\"x 10^-3 kPa^-1\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Volume expansivity:  1.7937 x 10^-3 K^-1\n",
        "Isothermal compressibility:  3.778 x 10^-3 kPa^-1\n"
       ]
      }
     ],
     "prompt_number": 51
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22, page no. 246"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "from math import log\n",
      "#Variable Declaration: \n",
      "V = 0.5\t\t\t\t#Volume of tank(in m**3):\n",
      "p0 = 1\t\t\t\t#Atmospheric pressure(in bar):\n",
      "T0 = 25+273\t\t\t#Atmospheric temperature(in K):\n",
      "Cp = 1.005\t\t\t#Cp of gas(in kJ/kg.K):\n",
      "Cv = 0.718\t\t\t#Cv of gas(in kJ/kg.K):\n",
      "Ti = T0\t\t\t\t#Initial temperature(in K):\n",
      "\n",
      "#Calculations:\n",
      "Tf = Cp/Cv*Ti\t\t\t#Inside final temperature(in K):\n",
      "dSgen = Cp*log(Tf/Ti)\t\t#Change in entropy(in kJ/kg.K):\n",
      "I = T0*dSgen\t\t\t#Irreversibility(in kJ/kg):\n",
      "\n",
      "#Results:\n",
      "print \"Inside final temperature\",round(Tf,2),\"K\"\t\t\t\t\n",
      "print \"Change in entropy: \",round(dSgen,4),\"kJ/kg.K\"\n",
      "print \"Irreversibility\",round(I,2),\"kJ/kg\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Inside final temperature 417.12 K\n",
        "Change in entropy:  0.338 kJ/kg.K\n",
        "Irreversibility 100.71 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 53
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 23, page no. 246"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "from math import log\n",
      "#Variable Declaration: \n",
      "m = 75\t\t\t\t#Mass of water(in kg):\n",
      "T1 = 400+273\t\t\t#Temperature of hot water(in K):\n",
      "T2 = 300\t\t\t#Final temperature(in K):\n",
      "T0 = 27+273\t\t\t#Temperature of the environment(in K):\n",
      "Cp = 4.18\t\t\t#Specific heat of water(in kJ/kg.K):\n",
      "\n",
      "#Calculation:\n",
      "Wmax = m*Cp*(T1-T2-T0*log(T1/T2))#Maximum work(in kJ):\n",
      "\n",
      "#Results:\n",
      "print \"Maximum work: \",round(Wmax,1),\"kJ\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Maximum work:  40946.6 kJ\n"
       ]
      }
     ],
     "prompt_number": 57
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 24, page no. 247"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "\n",
      "#Variable Declaration: \n",
      "p1 = 50\t\t    #Pressure at which steam enters(in bar):\n",
      "T1 = 600+273\t    #Temperature at which steam enters(in K):\n",
      "c1 = 150\t    #Velocity at which steam enters(in m/s):\n",
      "p2 = 0.1\t    #Pressure at which steam leaves(in bar):\n",
      "c2 = 50\t\t    #Velocity at which steam leaves(in m/s):\n",
      "W = 1000\t    #Work delivered(in kJ/kg):\n",
      "T0 = 25+273\t    #Dead state temperature(in K):\n",
      "#From steam tables:\n",
      "h1 = 3666.5         #kJ/kg\t\t\t\t\n",
      "s1 = 7.2589         #kJ/kg.K\n",
      "h2 = 2584.7         #kJ/kg\n",
      "s2 = 8.1502         #kJ/kg.K\n",
      "\n",
      "#Calculations:\n",
      "A1 = h1+c1**2/2*10**(-3)-T0*s1\t#Inlet stream availability(in kJ/kg):\n",
      "A2 = h2+c2**2/2*10**(-3)-T0*s2\t#Exit stream availability(in kJ/kg):\n",
      "Wrev = A1-A2\t\t\t#Reversible work(in kJ/kg):\n",
      "I = Wrev-W\t\t\t#Irreversibility(in kJ/kg):\n",
      "\n",
      "#Results:\n",
      "print \"Inlet stream availability: \",round(A1,2),\"kJ/kg\"\t\t\t\t\n",
      "print \"Exit stream availability: \",round(A2,2),\"kJ/kg\"\n",
      "print \"Irreversibility: \",round(I,1),\"kJ/kg\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Inlet stream availability:  1514.6 kJ/kg\n",
        "Exit stream availability:  157.19 kJ/kg\n",
        "Irreversibility:  357.4 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 59
    }
   ],
   "metadata": {}
  }
 ]
}