{
 "metadata": {
  "name": "",
  "signature": "sha256:4c5adc7ff722a4bfcaaad47e052db064cf85c767ab3f0fe6ba8aa04ddc1a515a"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 6: Thermodynamic Properties of Pure Substance"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2, page no. 182"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "p1 = 10 #Pressure at which steam is entering(in MPa):\n",
      "p2 = 0.05 #Pressure at which steam is coming out(in MPa):\n",
      "T = 100 #Temperature of the steam(inC):\n",
      "h2 = 2682.5 #Enthalpy of superheated steam at 0.05 MPa and 100 C(in kJ/kg): #From steam tables:\n",
      "hf10 = 1407.56\n",
      "hfg10 = 1317.1\n",
      "\n",
      "#Calculation:\n",
      "h1 = h2 #Due to throttling:\n",
      "x1 = (h1-hf10)/hfg10 #Dryness fraction:\n",
      "\n",
      "#Results:\n",
      "print \"Dryness fraction: \",round(x1,3)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Dryness fraction:  0.968\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3, page no. 183"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "p = 12 #Pressure(in MPa):\n",
      "v = 0.017 #Specific volume(in m**3/kg):\n",
      "h = 2848 #Enthaply(in kJ/kg):\n",
      "\n",
      "#Calculation:\n",
      "u = h-p*10**3*v #Internal energy(in kJ/kg):\n",
      "\n",
      "#Results:\n",
      "print \"Internal energy: \",round(u),\"KJ/Kg\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Internal energy:  2644.0 KJ/Kg\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4, page no. 183"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "  \n",
      "from math import log\n",
      "\n",
      "#Variable Declaration: \n",
      "m = 5      #Mass of steam(in kg):\n",
      "p = 2    #Pressure(in MPa):\n",
      "Tss = 300+273.15 #Temperature of superheated steam(in K):\n",
      "Cps = 2.1  #Specific heat of super heated steam(in kJ/kg.K):\n",
      "Cpw = 4.18  #Specific heat of water(in kJ/kg.K):\n",
      "hfg = 1890.7  #From steam tables:\n",
      "\n",
      "#Calculations:\n",
      "Tsat = 212.42+273.15  #Saturation temperature(in K):\n",
      "s = Cpw*log(Tsat/273.15)+hfg/Tsat+Cps*log(Tss/Tsat) #Entropy of unit mass of superheated steam with reference to absolute zero(in kJ/kg.K):\n",
      "S = m*s    #Entropy of 5 kg of steam(in kJ/K):\n",
      "\n",
      "#Result:\n",
      "print \"Entropy of steam: \",round(S,2),\"KJ/K\"\t"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Entropy of steam:  33.23 KJ/K\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5, page no. 183"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration:\n",
      "Tb = 110 #Boiling point(in\u00c2\u00b0C):\n",
      "p =  143.27 #Pressure at which it boils(in kPa): #From steam table:\n",
      "Tsat =  108.866 #From steam table this temperature(in \u00c2\u00b0C): #Boiling point at this depth  =  Tsat at 138.365\n",
      "\n",
      "#Calculation:\n",
      "p1 = p-9.81*0.50 #Pressure at 50 cm depth(in kPa):\n",
      "\n",
      "#Result:\n",
      "print \"Boiling point :\",round(Tsat,2),\"\u00b0C\"\t\t\t\t"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Boiling point : 108.87 \u00b0C\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 6, page no. 184"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "T = 100 #Temperature of the water vapor mixture(in \u00c2\u00b0C):\n",
      "V = 0.5 #Volume of the rigid vessel(in m**3):\n",
      "v2 = 0.003155 #Specific volume at state 2(in m**3/kg): #From steam tables:\n",
      "vf = 0.001044\n",
      "vg = 1.6729\n",
      "\n",
      "#Calculations:\n",
      "v1 = v2 #Specific volume at state 1(in m**3/kg):\n",
      "x1 = (v1-vf)/vg #Dryness fraction:\n",
      "m = V/v2 #Total mass of fluid(in kg):\n",
      "v = m*vf #Volume of water(in m**3):\n",
      "\n",
      "#Results:\n",
      "print \"Mass of water :\",round(m,2),\"Kg\" \n",
      "print \"Volume of water :\",round(v,4),\"m**3\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Mass of water : 158.48 Kg\n",
        "Volume of water : 0.1655 m**3\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7, page no. 184"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "p = 2 #Pressure(in MPa):\n",
      "T = 500+273.15 #Temperature(in K):\n",
      "\n",
      "#Calculation:\n",
      "s = T #Slope of isobar:(dh/ds)at constant pressure = T:\n",
      "\n",
      "#Result:\n",
      "print \"Slope :\",s"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Slope : 773.15\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8, page no. 185"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "x = 0.10 #Dryness fraction:\n",
      "p = 0.15 #Pressure(in MPa):\n",
      "hf  =  467.11 #From steam tables:(at 0.15 MPa):\n",
      "hg  =  2693.6\n",
      "vf  =  0.001053\n",
      "vg  =  1.1593\n",
      "sf  =  1.4336\n",
      "sg  =  7.2233\n",
      "\n",
      "#Calculations:\n",
      "h = hf+x*(hg-hf) #Enthalpy(in kJ/kg):\n",
      "v = vf+x*(vg-vf) #Specific volume(in m**3/kg):\n",
      "s = sf+x*(sg-sf) #Entropy(in kJ/kg.K):\n",
      "\n",
      "#Results:\n",
      "print \"Enthalpy :\",h,\"KJ/Kg\"\n",
      "print \"Specific volume :\",v,\"m**3/kg\"\n",
      "print \"Entropy :\",s,\"KJ/Kg.K\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enthalpy : 689.759 KJ/Kg\n",
        "Specific volume : 0.1168777 m**3/kg\n",
        "Entropy : 2.01257 KJ/Kg.K\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9, page no. 185"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "#Initial State:\n",
      "p1 = 1 #Pressure(in MPa):\n",
      "V1 = 0.05 #Volume(in m**3):\n",
      "x1 = 0.80 #Dryness fraction:\n",
      "#Final state:\n",
      "p2 = 1 #Pressure(in MPa):\n",
      "V2 = 0.2 #Volume(in m**3):\n",
      "\n",
      "#From steam table:(at state 1):\n",
      "vf  =  0.001127                 #(m3/kg) \n",
      "vg  =  0.19444                  #(m3/kg)\n",
      "uf  =  761.68                   #(kJ/kg)\n",
      "ufg  =  1822                    #(kJ/kg)\n",
      "\n",
      "#Calculations:\n",
      "W = p1*10**3*(V2-V1) #Work done(in kJ):\n",
      "v1 = vf+x1*(vg-vf) #Specific volume at state 1(in m**3/kg):\n",
      "m = V1/v1 #Mass of system(in kg):\n",
      "v2 = V2/m #Specific volume at state 2(in m**3/kg):\n",
      "Tf = 1077.61 #Temperature at final state(in C):\n",
      "u2 = 4209.6 #Internal energy at final state(at 1077.61 C):\n",
      "u1 = uf+x1*ufg #Internal energy at initial state(in kJ/kg):\n",
      "Q = m*(u2-u1)+W #Heat added(in kJ):\n",
      "\n",
      "#Results:\n",
      "print \"Heat added :\",round(Q,2),\"kJ\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat added : 788.83 kJ\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 10, page no. 186"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "p1 = 800 #Presure of the steam(in kPa):\n",
      "T = 200 #Temperature(in \u00b0C)\n",
      "Tsat = 170.43 #Saturation temp(in \u00b0C): \n",
      "#From steam tables:\n",
      "v1 = 0.2404 #Specific volume(in m**3/kg):\n",
      "vgI = 0.2168\n",
      "vgII = 0.2428\n",
      "TI = 175\n",
      "TII = 170\n",
      "PI = 892\n",
      "PII = 791.7\n",
      "\n",
      "#Calculations:\n",
      "T2 = TI - (TI-TII)*(v1-vgI)/(vgII-vgI) #Final temperature after interpolation (in \u00b0C):\n",
      "p2 = PI - (PI-PII)*(v1-vgI)/(vgII-vgI) #Final pressure after interpolation (in kPa):\n",
      "\n",
      "#Results:\n",
      "print \"Pressure :\",round(p2,2),\"kPa\"\n",
      "print \"Temperature :\",round(T2,2),\"\u00b0C\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Pressure : 800.96 kPa\n",
        "Temperature : 170.46 \u00b0C\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11, page no. 187"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "T = 30 #Temperature of water(in C):\n",
      "p = 200 #Pressure(in kPa):\n",
      "p1 = 4.25 #Corresponding pressure at 30 C(in kPa): #From steam tables:\n",
      "v1 = 0.001004 #Specific volume(in m**3):\n",
      "\n",
      "#Calculations:\n",
      "dh = v1*(p-p1) #Enthalpy change(in kJ/kg):\n",
      "\n",
      "#Result:\n",
      "print \"Enthalpy change :\",dh,\"KJ/Kg\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enthalpy change : 0.196533 KJ/Kg\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12, page no. 187"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "  \n",
      "#Variable Declaration: \n",
      "V1 = 3./5*2 #Volume occupied by water(in m**3):\n",
      "V2 = 2./5*2 #Volume occupied by steam(in m**3):\n",
      "#From steam table\n",
      "vf  =  0.001091 #(m**3/kg) \n",
      "vg  =  0.3928 #(m**3/kg)\n",
      "\n",
      "#Calculations:\n",
      "mf = V1/vf #Mass of water(in kg):\n",
      "mg = V2/vg #Mass of steam(in kg):\n",
      "mt = mf+mg #Total mass(in kg):\n",
      "x = mg/mt #Dryness fraction:\n",
      "\n",
      "#Results:\n",
      "print \"Mass :\",round(mt,2),\"kg\"\n",
      "print \"Quality :\",round(x,6)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Mass : 1101.95 kg\n",
        "Quality : 0.001848\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 13, page no. 188"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "p = 4 #Pressure of the steam(in MPa):\n",
      "T1 = 300  #Temperature of steam entering(in \u00b0C):\n",
      "T2 = 50  #Temperature of steam at turbine exit(in \u00b0C):\n",
      "#From steam tables:\n",
      "h1 = 2886.2                 #kJ/kg \n",
      "s1 = 6.2285                 #kJ/kg.K\n",
      "hf  =  209.33               #kJ/kg\n",
      "sf  =  0.7038               #kJ/kg.K\n",
      "hfg  =  2382.7              #kJ/kg\n",
      "sfg  =  7.3725              #kJ/kg.K\n",
      "\n",
      "#Calculation:\n",
      "s2 = s1  #Assumed\n",
      "x2 = round((s2-sf)/sfg,4)   #Dryness fraction:\n",
      "h2 = hf+x2*hfg #Enthalpy at state 2(in kJ/kg):\n",
      "W = h1-h2  #Turbine work(in kJ/kg):\n",
      "\n",
      "#Results:\n",
      "print \"Turbine output: \",round(W,2),\"kJ/kg\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Turbine output:  891.27 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 14, page no. 188"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "m1 = 100 #Mass of steam(in kg):\n",
      "p1 = 100 #Initial pressure(in kPa):\n",
      "p2 = 1000 #Final pressure(in kPa):\n",
      "x1 = 0.5 #Dryness fraction:\n",
      "p3 = 2000 #Pressure of dry saturated steam(in kPa):\n",
      "\n",
      "#From steam tables:\n",
      "hf100kPa  =  417.46                     #kJ/kg \n",
      "uf100kPa  =  417.36                     #kJ/kg\n",
      "vf100kPa  =  0.001043                   #m**3/kg\n",
      "hfg100kPa  =  2258                      #kJ/kg\n",
      "ufg100kPa  =  2088.7                    #kJ/kg\n",
      "vg100kPa  =  1.6940                     #m**3/kg\n",
      "vg2000kPa  =  0.09963                   #m**3/kg\n",
      "ug2000kPa  =  2600.3                    #kJ/kg\n",
      "hg2000kPa  =  2799.5                    #kJ/kg\n",
      "hf1000kPa  =  762.81                    #kJ/kg,\n",
      "hfg1000kPa  =  2015.3                   #kJ/kg \n",
      "vf1000kPa  =  0.001127                  #m3/kg\n",
      "vg1000kPa  =  0.19444                   #m3/kg\n",
      "\n",
      "#Calculations:\n",
      "v1 = vf100kPa+x1*(vg100kPa-vf100kPa) #Initial specific volume(in m**3/kg):\n",
      "h1 = hf100kPa+x1*hfg100kPa #Enthalpy at 1(in kJ/kg):\n",
      "V = m1*x1*v1 #Volume of vessel(in m**3):\n",
      "v2 = vg2000kPa*v1/(vg2000kPa+v1) #Final specific volume(in m**3/kg):\n",
      "x2 = (v2-vf1000kPa)/(vg1000kPa-vf1000kPa)#Final dryness fraction:\n",
      "h2 = hf1000kPa+x2*hfg1000kPa #Final enthalpy(in kJ/kg):\n",
      "m = m1*(h1-h2)/(h2-hg2000kPa) #Mass of dry steam at 2000kPa(in kg):\n",
      "U1 = m*(uf100kPa+x1*ufg100kPa) #Internal energy in the beginning(in kJ):\n",
      "\n",
      "#Results:\n",
      "print \"Mass of dry steam at 2000 kPa to be added: \",round(m,2),\"kg\" \n",
      "print \"Quality of final mixture: \",round(x2,3)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Mass of dry steam at 2000 kPa to be added:  11.97 kg\n",
        "Quality of final mixture:  0.455\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 15, page no. 190"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "r =  71.5  #Recorded condenser vacuum(cm of Mercury)\n",
      "br =  76.8 #Barometer reading(cm of Mercury) \n",
      "Tc =  35  #Temperature of condensation(\u00b0C)\n",
      "Thw =  27.6  #Temperature of hot well(\u00b0C)\n",
      "mc =  1930  #Mass of condensate per hour()Kg\n",
      "mcw =  62000    #Mass of cooling water per hour(Kg)\n",
      "Ti =  8.51 #Inlet temperature (\u00b0C)\n",
      "To =  26.24    #Outlet temperature(\u00b0C)\n",
      "#From steam tables:\n",
      "hf  =  146.68 #kJ/kg\n",
      "hfg  =  2418.6 #kJ/kg\n",
      "\n",
      "#Calculations:\n",
      "pc = (br-r)/73.55*101.325 #Condensor pressure(in kPa):\n",
      "ps =  5.628 #Partial pressure of steam corresponding to 35\u00c2\u00b0C from steam table(in kPa):\n",
      "x = (mcw*(To-Ti)*4.18-mc*hf+mc*4.18*To)/(mc*hfg) #Dryness fraction:\n",
      "\n",
      "#Results:\n",
      "print \"Dryness fraction of the steam entering:\",round(x,2) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Dryness fraction of the steam entering: 0.97\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16, page no. 191"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from math import pi\n",
      "#Variable Declaration: \n",
      "D = 0.2 #Diameter of the vessel(in m):\n",
      "d = 0.02 #Depth(in m):\n",
      "T = 150 #Temperature(in \u00b0C):\n",
      "F = 10 #Force applied(in kN):\n",
      "Q = 600 #Heat supplied(in kJ):\n",
      "#From steam tables:\n",
      "hf = 612.1 \n",
      "hfg = 2128.7\n",
      "vg = 0.4435\n",
      "h2 = 1582.8\n",
      "\n",
      "#Calculations:\n",
      "p = F/(pi*D**2)*4+101.3 #Pressure at which process is taking place(in kPa):\n",
      "V1 = pi*D**2*d/4 #Volume of water contained(in m**3):\n",
      "m = V1*1000 #Mass of water(in kg):\n",
      "x = (Q-hf*m+4.18*T*m)/(hfg*m) #Dryness fraction:\n",
      "U1 = m*4.18*T-p*V1 #Internal energy of water initially(in kJ):\n",
      "V2 = m*x*vg #Final volume(in m**3):\n",
      "U2 = m*h2-p*V2 #Internal energy at state 2(in kJ):\n",
      "dU = U2-U1 #Change in internal energy(in kJ):\n",
      "W = p*(V2-V1) #Work done(in kJ):\n",
      "\n",
      "#Results:\n",
      "print \"Dryness fraction of the steam produced: \"  ,round(x,3) \n",
      "print \"Change in internal energy: \",round(dU,2), \"kJ\"\n",
      "print \"Work done: \",round(W,2),\"kJ\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Dryness fraction of the steam produced:  0.456\n",
        "Change in internal energy:  547.54 kJ\n",
        "Work done:  53.01 kJ\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 17, page no. 192"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "ms = 40   #Mass of steam passed(in kg):\n",
      "mw = 2.2  #Mass of water passed(in kg):\n",
      "p1 = 1.47 #Initial pressure of steam(in MPa):\n",
      "T = 120  #Temperature after throttling(in C):\n",
      "p2 = 107.88 #Pressure after throttling(in kPa):\n",
      "s = 2.09 #Specific heat of superheated steam(in kJ/kg.K):\n",
      "hf = 840.513 #From steam tables:\n",
      "hfg = 1951.02\n",
      "h1 = 2673.95\n",
      "\n",
      "#Calculations:\n",
      "ds = T-101.8 #Degree of superheat(in C):\n",
      "h2 = h1+ds*s #Enthalpy of superheated steam(in kJ/kg):\n",
      "x2 = (h2-hf)/hfg #Dryness fraction after throttling:\n",
      "x1 = (ms-mw)/ms #Dryness fraction before throttling:\n",
      "x = x1*x2 #Overall dryness fraction:\n",
      "\n",
      "#Results:\n",
      "print \"Dryness fraction \",round(x,4)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Dryness fraction  0.9065\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 18, page no. 192"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "Va = 0.4 #Initial volume in part A(in m**3):\n",
      "pa = 10 #Pressure(in bar):\n",
      "V = 0.4 #Initial volume in part B(in m**3):\n",
      "p1 = 10 #Pressure in part B(in bar):\n",
      "p2 = 15 #Final pressure in part B(in bar):\n",
      "#From steam tables:\n",
      "hf = 762.83 \n",
      "hfg = 2015.3\n",
      "h2 = 2792.2\n",
      "\n",
      "#Calculations:\n",
      "Q = V*(p2-p1)*10**2 #Heat added(in kJ):\n",
      "x1 = (h2-Q-hf)/hfg #Dryness fraction:\n",
      "\n",
      "#Results:\n",
      "print \"Heat added: \",round(Q),\"kJ\" \n",
      "print \"Initial quality: \",round(x1,3)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat added:  200.0 kJ\n",
        "Initial quality:  0.908\n"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 19, page no. 193"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "m = 3 #Mass of wet steam(in kg):\n",
      "p1 = 1.4 #Initial pressure(in bar):\n",
      "V1 = 2.25 #Initial volume(in m**3):\n",
      "T = 400 #Final temperature of steam(in \u00b0C):\n",
      "V2 = 4.65 #At 400 \u00b0C,volume of steam(in m**3):\n",
      "#From steam tables:\n",
      "vg = 1.2455 \n",
      "hf = 457.99\n",
      "hfg = 2232.3\n",
      "h2 = 3276.6\n",
      "uf = 457.84\n",
      "ufg = 2059.34\n",
      "u2 = 2966.7\n",
      "\n",
      "#Calculations:\n",
      "v1 = V1/m #Specific volume of wer steam in cylinder(in m**3/kg):\n",
      "x1 = v1/vg #Dryness fraction of initial steam:\n",
      "h1 = hf+x1*hfg #Initial enthalpy of wet steam(in kJ/kg):\n",
      "v2 = V2/m #At 400\u00b0C specific volume of steam(in m**3/kg):\n",
      "p2 = 0.20 #Actual pressure(from steam table)(in MPa):\n",
      "ds = T-120.23 #Finally the degree of superheat(in \u00b0C): #Saturation temp at this pressure  =  120.23\u00c2\u00b0C\n",
      "Q = m*(h2-h1) #Heat added during the process(in kJ):\n",
      "u1 = uf+x1*ufg #Internal energy of initial wet steam(in kJ/kg):\n",
      "dU = m*(u2-u1) #Change in internal energy(in kJ):\n",
      "W = Q-dU #Work done(in kJ):\n",
      "\n",
      "#Results:\n",
      "print \"Heat transfer: \",round(Q,2),\"kJ\" \n",
      "print \"Work transfer : \",round(W,2),\"kJ\"\n",
      "print \"____Note: Please check the value of x1 calculated and used: (calculated is 0.602 and used is 0.607 hence there is a difference in answer)____\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Heat transfer:  4423.17 kJ\n",
        "Work transfer :  616.8 kJ\n",
        "____Note: Please check the value of x1 calculated and used: (calculated is 0.602 and used is 0.607 hence there is a difference in answer)____\n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 20, page no. 194"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "#Variable Declaration: \n",
      "p1 = 10 #Pressure of the steam(in bar):\n",
      "T = 500 #Temperature(in \u00b0C):\n",
      "p2 = 1 #Final pressure(in bar):\n",
      "#From steam tables:\n",
      "h10bar500  =  3478.5            #kJ/kg \n",
      "s10bar500  =  7.7622            #kJ/kg.K\n",
      "v10bar500  =  0.3541            #m**3/kg\n",
      "h1bar400  =  3278.2             #kJ/kg\n",
      "h1bar500  =  3488.1             #kJ/kg\n",
      "v1bar500  =  3.565              #m**3/kg\n",
      "v1bar400  =  3.103              #m**3/kg\n",
      "s1bar500  =  8.8342             #kJ/kg.K\n",
      "s1bar400  =  8.5435             #kJ/kg.K\n",
      "h2 = h10bar500\n",
      "\n",
      "#Calculations:\n",
      "T2 = (h2-h1bar400)*(T-400)/(h1bar500-h1bar400)+400 #Final temperature(in \u00b0C):\n",
      "s2 = s1bar400+(s1bar500-s1bar400)/(T-400)*(T2-400) #Final entropy(in kJ/kg.K):\n",
      "ds = s2-s10bar500  #Change in entropy(in kJ/kg.K):\n",
      "v2 = v1bar400+(v1bar500-v1bar400)/(T-400)*(T2-400) #Final specific volume(in m**3/kg):\n",
      "p = v10bar500/v2*100 #Percentage volume occupied by steam:\n",
      "\n",
      "#Results:\n",
      "print \"Final temperature: \",round(T2,2),\"\u00b0C\" \n",
      "print \"Change in entropy: \",round(ds,4),\"kJ/Kg K\"\n",
      "print \"Percentage of vessel volume initially occupied by steam: \",round(p,2),\"%\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Final temperature:  495.43 \u00b0C\n",
        "Change in entropy:  1.0587 kJ/Kg K\n",
        "Percentage of vessel volume initially occupied by steam:  9.99 %\n"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 21, page no. 195"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "#Steam entering:\n",
      "p1 = 2.5     #Pressure(in MPa): \n",
      "T1 = 350   #Temperature(in \u00b0C):\n",
      "#Steam rejected:\n",
      "p2 = 20   #Pressure(in kPa):\n",
      "x2 = 0.92  #Dryness fraction:\n",
      "p3 = 30  #Pressure of one quater of intial steam(in kPa):\n",
      "T0 = 30+273 #Temperature(in K):\n",
      "m1 = 1\n",
      "m2 = 0.25\n",
      "m3 = 0.75\n",
      "Q = -10 #Heat lost during expansion(in kJ):\n",
      "#From steam tables:\n",
      "h1 = 3126.3                 #kJ/kg\n",
      "s1 = 6.8403                 #kJ/kg.K\n",
      "h2 = 2878.6                 #kJ/kg\n",
      "s2 = 8.5309                 #kJ/kg.K\n",
      "h3  =  2421.04              #kJ/kg\n",
      "s3  =  7.3425               #kJ/kg.K\n",
      "hf  =  251.40               #kJ/kg\n",
      "hg  =  2609.7               #kJ/kg\n",
      "sf  =  0.8320               #kJ/kg.K\n",
      "sfg  =  7.0766              #kJ/kg.K\n",
      "h0 = 125.79 \n",
      "s0 = 0.4369\n",
      "\n",
      "#Calculations:\n",
      "A1 = (h1-h0)-T0*(s1-s0)     #Availability of steam entering turbine(in kJ/kg):\n",
      "A2 = (h2-h0)-T0*(s2-s0)     #Availability of steam leaving turbine at state 2(in kJ/kg):\n",
      "A3 = (h3-h0)-T0*(s3-s0)     #Availability of steam leaving turbine at state 3(in kJ/kg):\n",
      "Wmax = m1*A1-m2*A2-m3*A3    #Maximum work per kg of steam entering turbine(in kJ/kg):\n",
      "I = T0*(m2*s2+m3*s3-m1*s1)-Q#Irreversibilty(in kJ/s):\n",
      "\n",
      "#Results:\n",
      "print \"Maximum work\",round(Wmax,2),\"kJ/kg\" \n",
      "print \"Irreversibility\",round(I,2),\"kJ/s\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Maximum work 833.06 kJ/kg\n",
        "Irreversibility 252.19 kJ/s\n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22, page no. 196"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration: \n",
      "p1 = 6 #Initial pressure(in MPa):\n",
      "p2 = 5 #Final pressure(in MPa):\n",
      "T1 = 400 #Initial temperature(in \u00b0C):\n",
      "patm = 100 #Atmospheric pressure(in kPa):\n",
      "Ta = 20+273 #Atmospheric temperature(in \u00b0K):\n",
      "#From steam tables:\n",
      "h1 = 3177.2             #kJ/kg \n",
      "s1 = 6.5408             #kJ/kg.K\n",
      "h2 = h1\n",
      "T2 = 392.7              #\u00b0C(by interpolation)\n",
      "s2 = 6.6172             #kJ/kg.K(#By interpolation Entropy)\n",
      "h0 = 83.96              #kJ/kg\n",
      "s0  =  0.2966           #kJ/kg\n",
      "\n",
      "#Calculations:\n",
      "A1 = (h1-h0)-Ta*(s1-s0) #Availability at state 1(in kJ/kg):\n",
      "A2 = (h2-h0)-Ta*(s2-s0) #Availability at state 2(in kJ/kg):\n",
      "dA = A2-A1 #Change in availibilty(in kJ/kg):\n",
      "\n",
      "print \"Change in availability: \",round(-dA,1),\"kJ/kg decrease\","
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in availability:  22.4 kJ/kg decrease\n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 23, page no. 198"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Variable Declaration:\n",
      "TH1 =  95 #Temperature of the hot water entering(in \u00c2\u00b0C):\n",
      "TH2 =  50 #Temperature of the hot water at exit(in \u00c2\u00b0C): \n",
      "mH  =  0.8 #Mass flow rate(in kg/s):\n",
      "TC1 =  15+273 #Temperature of cooling water entering(in \u00c2\u00b0K):\n",
      "TC2 =  45+273 #Temperature of cooling water at exit(in \u00c2\u00b0K):\n",
      "T0 = 25+273 #Temperature of dead state(in K):\n",
      "#From steam tables:\n",
      "h0 = 104.89                     #kJ/kg\n",
      "s0 = 0.3674                     #kJ/kg.K\n",
      "hH1 = 397.96                    #kJ/kg\n",
      "sH1 = 1.2500                    #kJ/kg.K\n",
      "hH2 = 209.33                    #kJ/kg.K\n",
      "sH2 = 0.7038                    #kJ/kg.K\n",
      "hC2 = 188.45                    #kJ/kg.K\n",
      "sC2 = 0.6387                    #kJ/kg.K\n",
      "hC1 = 62.99                     #kJ/kg.K\n",
      "sC1 = 0.2245                    #kJ/kg.K\n",
      "\n",
      "#Calculations:\n",
      "mC = mH*(TH1-TH2)/(TC2-TC1)\t#Mass flow rate of cooling water(in kg/s):\n",
      "AH1 = mH*((hH1-h0)-T0*(sH1-s0))\t#Exergy entering through hot water stream(in kJ/s):\n",
      "dAc = mC*((hC2-hC1)-T0*(sC2-sC1))#Rate of exergy increase in cold stream(in kJ/s):\n",
      "n = dAc/AH1*100 #Second law efficiency:\n",
      "dAh = mH*((hH1-hH2)-T0*(sH1-sH2))#Rate of exergy loss in hot stream(in kJ/s):\n",
      "dA = dAh-dAc #Exergy destruction(in kJ/s):\n",
      "\n",
      "#Results:\n",
      "print \"Second law efficincy: \",round(n,2),\"%\"  \n",
      "print \"Exergy destruction: \",round(dA,2),\"kJ/s\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Second law efficincy:  10.12 %\n",
        "Exergy destruction:  18.26 kJ/s\n"
       ]
      }
     ],
     "prompt_number": 27
    }
   ],
   "metadata": {}
  }
 ]
}