{
 "metadata": {
  "name": "",
  "signature": "sha256:8647345ba179ef2ea9d3fa7f02f9c39fe17f9932a98d0fe8ec5f061488b5ae2f"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 5 : Some Applications of the Laws of Thermodynamics"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.1"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math\n",
      "\n",
      "# Variables\n",
      "#Given:\n",
      "u1 = 1; \t\t\t    #entering velocity of water (m/s)\n",
      "d_ent = 0.2; \t\t\t#entrance diameter of reducer (m)\n",
      "d_exit = 0.1; \t\t\t#exit diameter of reducer (m)\n",
      "P_ent = 105; \t\t\t#pressure at entrance (kPa)\n",
      "z = 5; \t\t\t        #distance between entrance and exit (m)\n",
      "g = 9.81; \t\t\t    #acceleration due to gravity \n",
      "den = 1000; \t\t\t#density of water (kg/m**3)\n",
      "\n",
      "# Calculations\n",
      "#To calculate the pressure at exit\n",
      "A1 = (math.pi/4)*d_ent**2; \t\t\t    #cross section area of entrance (m**2)\n",
      "A2 = (math.pi/4)*d_exit**2; \t\t\t#cross section area of exit (m**2)\n",
      "\n",
      "#By the equation of continuity and since density of water remains constant\n",
      "u2 = (A1*u1)/A2;\n",
      "\n",
      "#By Bernoulli's equation between section 1 and 2 (Eq 5.20 Page no. 118)\n",
      "P_exit = (-((u2**2-u1**2)/2)-(g*z)+(P_ent*10**3/den))*(den/10**3)\n",
      "\n",
      "# Results\n",
      "print 'The pressure at exit is %f kPa'%P_exit\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The pressure at exit is 48.450000 kPa\n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.2"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "P = 1000.; \t\t\t#pressure of saturated steam (kPa)\n",
      "T = 398.; \t\t\t#temperature of escaping steam (K)\n",
      "\n",
      "#Referring steam tables\n",
      "H_vap = 2778.; \t\t\t#enthalpy of saturated vapour at 1000 kPa (kJ/kg)\n",
      "H_liq = 763.; \t\t\t#enthalpy of saturated liquid at 1000 kPa (kJ/kg)\n",
      "H_steam = 2726.; \t\t#enthalpy of superheated steam at 398 K (kJ/kg)\n",
      "H2 = 2726; \t\t\t    #[kJ/kg]\n",
      "\n",
      "# Calculations\n",
      "#No work is done and no heat is exchanged between section 1 and 2\n",
      "#S0% H1 = H2\n",
      "x = (H2-H_vap)/(H_liq-H_vap)\n",
      "\n",
      "# Results\n",
      "print 'The steam contains %f percent liquid'%(x*100)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The steam contains 2.580645 percent liquid\n"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.3, Page no:123"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "m = 10.; \t\t\t#mass flow rate of steam (kg/s)\n",
      "H1 = 3062.; \t\t\t#enthalpy of entering steam (kJ/kg)\n",
      "H2 = 2875.; \t\t\t#enthalpy of discharged steam (kJ/kg)\n",
      "Q = -100./m; \t\t\t#heat loss to the surrounding (kJ/kg)\n",
      "u1 = 0.; \t\t\t#entering velocity of steam\n",
      "\n",
      "# Calculations\n",
      "import math\n",
      "H = H2-H1;\n",
      "u2 = math.sqrt((Q-H)*1000*2)\n",
      "\n",
      "# Results\n",
      "print 'The discharge velocity is %i m/s'%u2\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The discharge velocity is 594 m/s\n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.4, Page no:125"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "To = 600.; \t\t\t#temperature of air (K)\n",
      "Po = 2000.; \t\t\t#pressure of air (kPa)\n",
      "gama = 1.4;\n",
      "M = 0.8; \t\t\t#Mach number at throat\n",
      "m = 29.; \t\t\t#molecular mass of air\n",
      "R = 8.314; \t\t\t#ideal gas constant\n",
      "\n",
      "#To determine thermodynamical properties at throat and critical pressure\n",
      "import math\n",
      "\n",
      "# Calculations and Results\n",
      "#(a)\n",
      "#Using equation 5.40 (Page no 123).. u**2 = (M**2)*gama*P*V\n",
      "#Substituting this in eq. 5.39 (Page no. 123) and on rearranging we get\n",
      "P = Po/((1+(((gama-1)/2)*M**2))**(gama/(gama-1)))\n",
      "#Using eq. 5.39 and the relation PoVo = RTo/m\n",
      "u = math.sqrt((2*gama*R*To*1000)/(m*(gama-1))*(1-(P/Po)**((gama-1)/gama)))\n",
      "#Using eq. 3.23 (Page no. 49)\n",
      "T = To*(P/Po)**((gama-1)/gama)\n",
      "#Let d be the density\n",
      "d_o = (Po*m)/(R*To)\n",
      "#Since P*(V**gama) = P/(den**gama) = constant...so\n",
      "d = d_o*((P/Po)**(1/gama))\n",
      "print '(a). At throat'\n",
      "print 'Pressure = %i kPa'%P\n",
      "print 'Temperature = %i K'%T\n",
      "print 'Velocity = %f m/s'%u\n",
      "print 'Density = %f kg/cubic m'%d\n",
      "\n",
      "#(b)\n",
      "#Using eq. 5.42 (Page no.124)\n",
      "Pc = Po*((2/(gama+1))**(gama/(gama-1))) \t\t\t#critical pressure\n",
      "print '(b).'\n",
      "print 'The critical pressure is %f kPa'%Pc\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a). At throat\n",
        "Pressure = 1312 kPa\n",
        "Temperature = 531 K\n",
        "Velocity = 369.641813 m/s\n",
        "Density = 8.603873 kg/cubic m\n",
        "(b).\n",
        "The critical pressure is 1056.563575 kPa\n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.7"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "P1 = 1.; \t\t\t#initial pressure (bar)\n",
      "T1 = 300.; \t\t\t#initial temperature (K)\n",
      "P2 = 10.; \t\t\t#final pressure (bar)\n",
      "gama = 1.3; \t\t\t#gama for CO2\n",
      "V_rate = 100.; \t\t\t#volumetric flow rate (m**3/h)\n",
      "\n",
      "# Calculations and Results\n",
      "#To calculate work required and temperature after compression\n",
      "Ws = (gama/(gama-1))*P1*10**5*(V_rate/3600)*(1-(P2/P1)**((gama-1)/gama))\n",
      "print 'The work required is %f kW'%(-Ws/1000)\n",
      "\n",
      "#Using equation 3.23 (Page no.49)\n",
      "T2 = T1*((P2/P1)**((gama-1)/gama))\n",
      "print 'Temperature of gas after compression is %f K'%T2\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The work required is 8.441024 kW\n",
        "Temperature of gas after compression is 510.376284 K\n"
       ]
      }
     ],
     "prompt_number": 27
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.8"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "P1 = 100.; \t\t\t#initial pressure of saturated steam (kPa)\n",
      "P2 = 500.; \t\t\t#final pressure (kPa)\n",
      "eff = 0.8; \t\t\t#compression efficiency\n",
      "\n",
      "#Referring steam tables\n",
      "#Properties of steam entering the compressor\n",
      "H1 = 2675.5; \t\t\t#enthalpy (kJ/kg)\n",
      "S1 = 7.3594; \t\t\t#entropy (kJ/kg K)\n",
      "\n",
      "#Properties of compressed steam\n",
      "H2 = 3008.; \t\t\t#enthalpy (kJ/kg)\n",
      "S2 = S1; \t\t\t#isentropic compression\n",
      "\n",
      "\n",
      "# Calculations and Results\n",
      "#To calculate work required and temperature\n",
      "\n",
      "Hs = H2-H1;\n",
      "#Using eq. 5.44 (Page no. 128)\n",
      "W_isentropic = -Hs;\n",
      "W_act = W_isentropic/eff;\n",
      "print 'The work required for compression is %f kJ/kg'%-W_act\n",
      "\n",
      "H = Hs/eff; \t\t\t#actual change in enthalpy\n",
      "H_act = H1+H; \t\t\t#actual enthalpy of steam leaving the compressor\n",
      "#From steam tables for superheated steam at 500 kPa and enthalpy of H_act\n",
      "T = 586; \t\t\t#temperature (K)\n",
      "print 'Temperature of exhaust steam is %i K'%T\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The work required for compression is 415.625000 kJ/kg\n",
        "Temperature of exhaust steam is 586 K\n"
       ]
      }
     ],
     "prompt_number": 28
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.9"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "T1 = 288.; \t\t\t#temperature of surrounding (K)\n",
      "T2 = 261.; \t\t\t#temperature of solution (K)\n",
      "Q2 = 1000.; \t\t\t#heat removed (kJ/min)\n",
      "\n",
      "# Calculations\n",
      "#To determine the least amount of power\n",
      "#Using eq. 5.57 (Page no. 137)\n",
      "W = Q2*((T1-T2)/T2 )\t\t\t#power in kJ/min\n",
      "P = (W*1000)/(746.*60) \t\t\t#power in hp\n",
      "\n",
      "# Results\n",
      "print 'Least amount of power necessary is %f hp'%P"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Least amount of power necessary is 2.311177 hp\n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.10"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "T = 290.; \t\t\t#operating temperature (K)\n",
      "W = 1000.; \t\t\t#work (J)\n",
      "tof = 3516.67; \t\t\t#ton of refrigeration (W)\n",
      "\n",
      "# Calculations and Results\n",
      "#To determine COP, heat rejected and lowest temperature\n",
      "#(a)\n",
      "Q2 = tof;\n",
      "COP = Q2/W; \t\t\t#coeffecient of performance\n",
      "print '(a). COP is %f'%COP\n",
      "\n",
      "#(b)\n",
      "Q1 = Q2+W; \t\t\t#heat rejected\n",
      "print ' (b). Heat rejected is %f kW'%(Q1/1000.)\n",
      "\n",
      "#(c)\n",
      "#Let T2 be the lowest temperature\n",
      "T2 = T*(Q2/Q1);\n",
      "print ' (c). Lowest possible temperature in refrigerator is %f K'%T2\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a). COP is 3.516670\n",
        " (b). Heat rejected is 4.516670 kW\n",
        " (c). Lowest possible temperature in refrigerator is 225.793405 K\n"
       ]
      }
     ],
     "prompt_number": 30
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.11"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "T2 = 266.;\n",
      "T1 = 300.; \t\t\t#operating temperatures of vapour compression refrigeration cycle(K)\n",
      "\n",
      "#To determine COP at given conditions\n",
      "#(a)\n",
      "Ha = 656.; \t\t\t#(kJ/kg)\n",
      "Hb = 724.; \t\t\t#(kJ/kg)\n",
      "Hd = 144.; \t\t\t#(kJ/kg)\n",
      "Hc = Hd;\n",
      "\n",
      "# Calculations and Results\n",
      "#Using eq. 5.61 (Page no. 139)\n",
      "COP = (Ha-Hd)/(Hb-Ha);\n",
      "print '(a). COP = %f'%COP\n",
      "\n",
      "#(b)\n",
      "Ha = 652.; \t\t\t#(kJ/kg)\n",
      "Hb = 758.; \t\t\t#(kJ/kg)\n",
      "Hd = 159.; \t\t\t#(kJ/kg)\n",
      "Hc = Hd;\n",
      "eff = 0.75; \t\t\t#efficiency of compressor\n",
      "COP = (Ha-Hd)/((Hb-Ha)*(1./eff));\n",
      "print ' (b). COP = %f'%COP\n",
      "\n",
      "#(c). Ideal Carnot refrigerator\n",
      "COP = T2/(T1-T2);\n",
      "print ' (c). COP = %f'%COP\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a). COP = 7.529412\n",
        " (b). COP = 3.488208\n",
        " (c). COP = 7.823529\n"
       ]
      }
     ],
     "prompt_number": 31
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.12 "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "# Variables\n",
      "#Given:\n",
      "Tin_cool = 288.; \t\t\t#entering temperature of cooling water (K)\n",
      "Tout_cool = 300.; \t\t\t#discharge temperature of cooling water (K)\n",
      "m_c = 0.25; \t\t\t#mass flow rate of coling water (kg/s)\n",
      "m = 0.5; \t\t\t#mass flow rate of ammonia (kg/min)\n",
      "Ha = 1426.; \t\t\t#enthalpy of saturated ammonia vapour at 258 K (kJ/kg)\n",
      "Hd = 281.5; \t\t\t#enthalpy of liquid ammonia at 294 K (kJ/kg)\n",
      "eff = 0.9; \t\t\t#compressor efficiency\n",
      "Cp = 4.2; \t\t\t#specific heat of water (kJ/kg K)\n",
      "tof = 12660.; \t\t\t#ton of refrigeration (kJ/h)\n",
      "\n",
      "# Calculations and Results\n",
      "#To determine the power requirement and refrigeration capacity in tons\n",
      "Q1 = m_c*Cp*(Tout_cool-Tin_cool); \t\t\t#heat rejected by compressor at constant pressure (kJ/s)\n",
      "Q2 = (m/60.)*(Ha-Hd); \t\t\t#heat absorbed (kJ/s)\n",
      "W = Q1-Q2; \t\t\t#work required (kJ/s)\n",
      "P = (W*1000)/(eff*746); \t\t\t#power requirement of compressor (hp)\n",
      "print 'Power requirement of the compressor is %f hp'%P\n",
      "\n",
      "rc = Q2*3600/tof; \t\t\t#refrigeration capacity (ton)\n",
      "print ' Refrigeration capacity is %f ton'%rc\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Power requirement of the compressor is 4.561364 hp\n",
        " Refrigeration capacity is 2.712085 ton\n"
       ]
      }
     ],
     "prompt_number": 32
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.13"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "m1 = 10.; \t\t\t#machine rating (ton)\n",
      "#Since 5 K approach is necessary\n",
      "T1 = 293.+5; \t\t\t#temperature of cooling water (K)\n",
      "T2 = 261.-5; \t\t\t#temperature of cold storage (K)\n",
      "Ha = 181.; \t\t\t#enthalpy of saturated vapour at 256 K (kJ/kg)\n",
      "Sa = 0.714; \t\t\t#entropy of saturated vapour at 256K (kJ/kg K)\n",
      "Hc = 62.; \t\t\t#enthalpy of saturated liquid at 298 K (kJ/kg)\n",
      "Sc = 0.231; \t\t\t#entropy of saturated liquid at 298 K (kJ/kg K)\n",
      "Hb = 206.; \t\t\t#enthalpy of superheated vapour (kJ/kg)\n",
      "Sb = 0.714; \t\t\t#entropy of superheated vapour (kJ/kg)\n",
      "\n",
      "# Calculations and Results\n",
      "#Combining the three relations, we get\n",
      "Sd = Sc; \t\t\t#isentropic process\n",
      "Hd = Ha-(T2*(Sa-Sd));\n",
      "\n",
      "#Using eq. 5.64 (Page no. 141)\n",
      "COP = (Ha-Hd)/((Hb-Hc)-(Ha-Hd));\n",
      "print 'COP = %f'%COP\n",
      "\n",
      "#Using equation 5.63 (Page no. 140)\n",
      "m = (12660*m1)/(Ha-Hd); \t\t\t#refrigerant circulation rate (kg/h)\n",
      "print ' Refrigerant circulation rate is %f kg/h'%m\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "COP = 6.075472\n",
        " Refrigerant circulation rate is 1023.874224 kg/h\n"
       ]
      }
     ],
     "prompt_number": 33
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.14"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "m1 = 10.; \t\t\t#machine rating (ton)\n",
      "#Assuming 5 K approach in refrigerator and cooler\n",
      "Ta = 261.-5; \t\t\t#temperature of air leaving the refrigerator (K)\n",
      "Tc = 293.+5; \t\t\t#temperature of air leaving the cooler (K)\n",
      "gama = 1.4;\n",
      "Cp = 1.008; \t\t\t#sp. heat of air (kJ/kg K)\n",
      "P1 = 4.052;\n",
      "P2 = 1.013; \t\t\t#operating pressures in bar\n",
      "\n",
      "# Calculations and Results\n",
      "#To determine the COP and air circulation rate\n",
      "#Using eq. 5.66 (Page no. 145)\n",
      "Tb = Ta*(P1/P2)**((gama-1)/gama)\n",
      "Td = (Tc*Ta)/Tb;\n",
      "\n",
      "#Using equation 5.68 (PAge no. 146)\n",
      "COP = Ta/(Tb-Ta)\n",
      "print 'COP = %f'%COP\n",
      "\n",
      "#Considering energy balance in refrigerator [m*Cp*(Ta-Td) = m1*12660]\n",
      "m = (m1*12660)/(Cp*(Ta-Td)) \t\t\t#air circulation rate (kg/h)\n",
      "print ' Air circulation rate is %i kg/h'%m\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "COP = 2.057637\n",
        " Air circulation rate is 2264 kg/h\n"
       ]
      }
     ],
     "prompt_number": 34
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.15"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "T1 = 300.; \t\t\t#indoor temperatur (K)\n",
      "T2 = 290.; \t\t\t#outside temperature (K)\n",
      "W_input = 1.; \t\t\t#1 kW heat pump\n",
      "W_output = 30.; \t\t\t#given output (kW)\n",
      "\n",
      "# Calculations and Results\n",
      "#To verify that given heat pump is equivalent to 30 kW heater\n",
      "Q2 = (T2/(T1-T2))*W_input; \t\t\t#heat absorbed\n",
      "Q1 = Q2 + W_input; \t\t\t#heat rejected\n",
      "\n",
      "if(Q1==W_output):\n",
      "     print '1 kW pump if operated reversibly% is equivalent to a 30 kW heater'\n",
      "else:\n",
      "     print 'The given heat pump is not equivalent to a 30 kW heater'\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "1 kW pump if operated reversibly% is equivalent to a 30 kW heater\n"
       ]
      }
     ],
     "prompt_number": 35
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.16"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "T1 = 295.; \t\t\t#temperature inside building (K)\n",
      "T2 = 275.; \t\t\t#temperature of outside air (K)\n",
      "eff = 0.25; \t\t\t#overall efficiency of unit\n",
      "Hc = 890.9; \t\t\t#heat of combustion of fuel (kJ/mol)\n",
      "conv = 0.33; \t\t\t#efficiency of conversion of heat of combustion to electricity\n",
      "Q1 = 10**6; \t\t\t#amount of heat to be delivered\n",
      "\n",
      "# Calculations\n",
      "#To determine the amount of fuel burned\n",
      "COP = T1/(T1-T2)\n",
      "W = Q1/COP; \t\t\t#work required to deliver Q1 kJ of heat\n",
      "W_act = W/eff; \t\t\t#actual amount of electrical energy to be supplied\n",
      "W_heat = W_act/conv; \t\t\t#heat energy required as heat of combustion\n",
      "n = W_heat/Hc; \t\t\t#number of moles of fuel burned\n",
      "\n",
      "# Results\n",
      "print 'The amount of fuel burned is %f kmol'%(n/1000)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The amount of fuel burned is 0.922412 kmol\n"
       ]
      }
     ],
     "prompt_number": 36
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.17"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "#Referring steam tables at 2.54 bar\n",
      "H1 = 2717.; \t\t\t#enthalpy of saturated vapour (kJ/kg)\n",
      "H2 = 538.; \t\t\t#enthalpy of saturated liquid (kJ/kg)\n",
      "S1 = 7.05; \t\t\t#entropy of saturated vapour (kJ/kg K)\n",
      "S2 = 1.61; \t\t\t#entropy of saturated liquid (kJ/kg K)\n",
      "\n",
      "H = 2700.; \t\t\t#enthalpy of superheated steam at 1 bar and 385 K (kJ/kg)\n",
      "S = 7.42; \t\t\t#entropy of superheated steam at 1 bar and 385 K (kJ/kg K)\n",
      "\n",
      "# Calculations and Results\n",
      "x = (H-H1)/(H2-H1)\n",
      "#From steam tables\n",
      "T = 401.; \t\t\t#temperature of steam (K)\n",
      "print '(a). For isenthalpic math.expansion'\n",
      "print ' The fraction of liquid in inlet stream is %f'%x\n",
      "print ' The temperature of stream is %i K'%T\n",
      "\n",
      "#(b)..The math.expansion is isentropic\n",
      "#Since entropy of saturated vapour at inlet pressure (S1) is less than entropy of steam leaving the turbine (S)\n",
      "#So% the inlet stream is superheated% therefore\n",
      "x = 0;\n",
      "#From steam tales\n",
      "T = 478.; \t\t\t#temperature of superheated steam having entropy of 7.42 kJ/kg K\n",
      "print '(b). For isentropic math.expansion'\n",
      "print ' The fraction of liquid in inlet stream is %i'%x\n",
      "print ' The temperature of stream is %i K'%T\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a). For isenthalpic math.expansion\n",
        " The fraction of liquid in inlet stream is 0.007802\n",
        " The temperature of stream is 401 K\n",
        "(b). For isentropic math.expansion\n",
        " The fraction of liquid in inlet stream is 0\n",
        " The temperature of stream is 478 K\n"
       ]
      }
     ],
     "prompt_number": 37
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.18"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "#Referring Fig. 5.15 (Page no. 151)\n",
      "Hc = 516.; \t\t\t#enthalpy of high pressure gas at 120 bar and 306 K (kJ/kg)\n",
      "Ha = 526.; \t\t\t#enthalpy of low pressure gas at 2 bar and 292 K (kJ/kg)\n",
      "Hf = 121.; \t\t\t#entalpy of saturated liquid at 2 bar (kJ/kg)\n",
      "Hg = 314.; \t\t\t#enthalpy of saturated vapour at 2 bar (kJ/kg)\n",
      "\n",
      "#To determine the fraction of air liquified and temperature of air\n",
      "\n",
      "# Calculations and Results\n",
      "#(a)..\n",
      "#Using equation 5.73 (Page no. 152)\n",
      "x = (Hc-Ha)/(Hf-Ha) \t\t\t#fraction of air liquified\n",
      "print '(a). The fraction of liquified air is %f'%x\n",
      "\n",
      "#(b)..\n",
      "#Taking enthalpy balance around heat exchanger\n",
      "Hd = Hc - (1-x)*(Ha-Hg)\n",
      "#At enthalpy of Hd kJ/kg% from T-S diagram for air\n",
      "T = 167.; \t\t\t#temperature in K\n",
      "print ' (b). Temperature of air on high pressure side of throttle valve is %i K'%T\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a). The fraction of liquified air is 0.024691\n",
        " (b). Temperature of air on high pressure side of throttle valve is 167 K\n"
       ]
      }
     ],
     "prompt_number": 38
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.19"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "P2 = 2800.; \t\t\t#pressure of superheated steam (kPa)\n",
      "P1 = 5.; \t\t\t#pressure after math.expansion (kPa)\n",
      "e_turbine = 0.85; \t\t\t#isentropic turbine efficiency\n",
      "e_pump = 0.8; \t\t\t#isentropic pump efficiency\n",
      "V = 1.005*10**-3; \t\t\t#specific volume of saturated liquid at 5 kPaHl = \n",
      "\n",
      "#From steam tables:\n",
      "Hl = 138.; \t\t\t#enthalpy of saturated liquid at 5 kPa (kJ/kg)\n",
      "Hv = 2562.; \t\t\t#enthalpy of saturated vapour at 5 kPa (kJ/kg)\n",
      "H3 = 3063.; \t\t\t#enthalpy of superheated steam at 2800 kPa and 598 K (kJ/kg)\n",
      "Sl = 0.4764; \t\t\t#entropy of saturated liquid at 5 kPa (kJ/kg K)\n",
      "Sv = 8.3951; \t\t\t#entropy of saturated vapour at 5 kPa (kJ/kg K)\n",
      "S3 = 6.6875; \t\t\t#entropy of superheated steam at 2800 kPa and 598 K (kJ/kg K)\n",
      " \n",
      "\n",
      "# Calculations and Results\n",
      "#To determine the ideal Rankine cycle efficiency% thermal efficiency and rate of steam production\n",
      "\n",
      "#(a)..The ideal Rankine cycle efficiency for the stated conditions\n",
      "#Referring fig 5.19(b) (Page no. 155) and considering feed water pump\n",
      "Ws = V*(P2-P1) \t\t\t#work done by pump (kJ/kg)\n",
      "H2 = Hl+Ws;\n",
      "#Considering isentropic math.expansion in turbine\n",
      "S4 = S3;\n",
      "x = (S4-Sl)/(Sv-Sl) \t\t\t#fraction of steam that is vapour\n",
      "H4 = Hl + x*(Hv-Hl)\n",
      "\t\t\t#Using eq. 5.80 (Page no. 155)\n",
      "e_r = ((H3-H2)-(H4-Hl))/(H3-H2)\n",
      "print '(a). The ideal Rankine cycle efficiency for the stated conditions is %i percent'%(e_r*100)\n",
      "\n",
      "#(b)..The thermal efficiency of plant\n",
      "W_act = Ws/e_pump; \t\t\t#actual work requirement in pump\n",
      "H_2 = Hl + W_act; \t\t\t#enthalpy of water leaving the feed water pump\n",
      "W_out = e_turbine*(H3-H4) \t\t\t#actual work output\n",
      "H_4 = H3-W_out; \t\t\t#actual enthalpy of steam leaving the turbine\n",
      "e_act = ((H3-H_2)-(H_4-Hl))/(H3-H_2)\n",
      "print ' (b). The actual efficiency is %f percent'%(e_act*100)\n",
      "\n",
      "#(c)..The rate of steam production\n",
      "W_net = e_act*(H3-H_2) \t\t\t#net work output (kJ/kg)\n",
      "rate = (3.6*10**6)/W_net; \t\t\t#steam produced in boiler (kg/h)\n",
      "print ' (c). The rate of steam production is %f kg/h'%(rate)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a). The ideal Rankine cycle efficiency for the stated conditions is 34 percent\n",
        " (b). The actual efficiency is 29.664548 percent\n",
        " (c). The rate of steam production is 4153.943111 kg/h\n"
       ]
      }
     ],
     "prompt_number": 39
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.20"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "P2 = 7600.; \t\t\t#pressure of superheated steam (kPa)\n",
      "P1 = 5.; \t\t\t#pressure after math.expansion (kPa)\n",
      "V = 1.005*10**-3; \t\t\t#specific volume of saturated liquid (m**3/kg)\n",
      "\n",
      "#From steam tables:\n",
      "H_l1 = 138.; \t\t\t#enthalpy of saturated liquid at 5 kPa (kJ/kg)\n",
      "S_l1 = 0.4764; \t\t\t#entropy of saturated liquid at 5 kPa (kJ/kg K)\n",
      "H_v1 = 2562.; \t\t\t#enthalpy of saturated vapour at 5 kPa (kJ/kg)\n",
      "S_v1 = 8.3951; \t\t\t#entropy of saturated vapour at 5 kPa (kJ/kg K)\n",
      "H_l2 = 830.; \t\t\t#enthalpy of saturated liquid at 1400 kPa(kJ/kg)\n",
      "S_l2 = 2.2842; \t\t\t#entropy of saturated liquid at 1400 kPa (kJ/kg K)\n",
      "H_v2 = 2790.; \t\t\t#enthalpy of saturated vapour at 1400 kPa (kJ/kg)\n",
      "S_v2 = 6.4693; \t\t\t#entropy of saturated vapour at 1400 kPa (kJ/kg K)\n",
      "H5 = 3226.; \t\t\t#enthalpy of superheated steam at 1400 kPa and 658 K\n",
      "S5 = 7.2558; \t\t\t#entropy of superheated steam at 1400 kPa and 658 K\n",
      "H3 = 3150.; \t\t\t#enthalpy of superheated steam at 7600 kPa and 673 K\n",
      "S3 = 6.4022; \t\t\t#entropy of superheated steam at 1400 kPa and 673 K\n",
      "\n",
      "# Calculations and Results\n",
      "#Let the fraction of steam in vapour state be x\n",
      "S4 = S3; \t\t\t#as the math.expansion process is isentropic\n",
      "x = (S4-S_l2)/(S_v2-S_l2)\n",
      "H4 = H_l2 + x*(H_v2-H_l2)\n",
      "W_high = H3-H4;\n",
      "\n",
      "#For low pressure turbine\n",
      "S6 = S5; \t\t\t#isentropic math.expansion\n",
      "x = (S6-S_l1)/(S_v1-S_l1)\n",
      "H6 = H_l1 + x*(H_v1-H_l1)\n",
      "W_low = H5-H6;\n",
      "\n",
      "print '(a)'\n",
      "print ' The work output of high pressure turbine is %i kJ/kg'%W_high\n",
      "print ' The work output of low pressure turbine is %i kJ/kg'%W_low\n",
      "\n",
      "#(b)\n",
      "#Work output of feed pump is [-Ws = intg(VdP)]\n",
      "Ws = V*(P2-P1)\n",
      "H2 = H_l1+Ws;\n",
      "#Using eq. 5.82 (Page no. 159)\n",
      "eff = ((H3-H2)+(H5-H4)-(H6-H_l1))/((H3-H2)+(H5-H4))\n",
      "print ' (b)'\n",
      "print ' Thermal efficiency is %f percent'%(eff*100)\n",
      "\n",
      "#(c)\n",
      "#The numerator of eq. 5.82 gives net work output\n",
      "W_net = (H3-H2)+(H5-H4)-(H6-H_l1)\n",
      "#For 1000 kW of net work output\n",
      "rate = 3.6*10**6/W_net;\n",
      "print ' (c)'\n",
      "print ' The rate of steam circulation is %f kg/h'%rate\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)\n",
        " The work output of high pressure turbine is 391 kJ/kg\n",
        " The work output of low pressure turbine is 1012 kJ/kg\n",
        " (b)\n",
        " Thermal efficiency is 40.225451 percent\n",
        " (c)\n",
        " The rate of steam circulation is 2577.792156 kg/h\n"
       ]
      }
     ],
     "prompt_number": 40
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.21"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "P2 = 2800.; \t\t\t#pressure of superheated steam (kPa)\n",
      "P1 = 275.; \t\t\t#pressure of withdrawn steam (kPa)\n",
      "V = 1.070*10**-3; \t\t\t#specific volume of saturated liquid at 275 kPa\n",
      "\n",
      "#From steam tables:\n",
      "H6 = 138.; \t\t    \t#enthalpy of saturated liquid at 5 kPa\n",
      "S6 = 0.4764; \t\t\t#entropy of saturated liquid at 5 kPa\n",
      "H_v1 = 2562.; \t\t\t#enthalpy of saturated vapour at 5 kPa\n",
      "S_v1 = 8.3951; \t\t\t#entropy of saturated vapour at 5 kPa\n",
      "H1 = 549.; \t\t\t    #enthalpy of saturated liquid at 275 kPa\n",
      "S1 = 1.6408; \t\t\t#entropy of saturated liquid at 275 kPa\n",
      "H_v2 = 2721.; \t\t\t#enthalpy of saturated vapour at 275 kPa\n",
      "S_v2 = 7.0209; \t\t\t#entropy of saturated vapour at 275 kPa\n",
      "H3 = 3063.; \t\t\t#enthalpy of superheated steam at 2800 kPa and 598 K\n",
      "S3 = 6.6875; \t\t\t#entropy of superheated steam at 2800 kPa and 598 K\n",
      "\n",
      "# Calculations and Results\n",
      "#To determine the fraction of steam withdrawn and thermal efficiency of cycle\n",
      "#Referring fig. 5.23 (Page no.161)\n",
      "S4 = S3;            \t\t\t#isentropic math.expansion\n",
      "x = (S4-S1)/(S_v2-S1) \t\t\t#quality of steam\n",
      "H4 = H1 + x*(H_v2-H1)\n",
      "H7 = H6; \t\t\t            #as the power input to the condensate pump is neglegible\n",
      "\n",
      "#Applying energy balance around feed water heater\n",
      "m = (H1-H7)/(H4-H7 )\t\t\t#fraction of steam extracted\n",
      "print 'Fraction of steam withdrawn is %f'%m\n",
      "\n",
      "W_in = V*(P2-P1) \t\t\t#work input to the feed water pump\n",
      "H2 = H1+W_in;\n",
      "#Considering isentropic math.expansion in turbine\n",
      "S5 = S3;\n",
      "x = (S5-S6)/(S_v1-S6)\n",
      "H5 = H6 + x*(H_v1-H6)\n",
      "#Using eq. 5.85 (Page no.162)\n",
      "eff = ((H3-H2)-(1-m)*(H5-H6))/(H3-H2)\n",
      "print ' Thermal efficiency is %f percent'%(eff*100)\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Fraction of steam withdrawn is 0.167865\n",
        " Thermal efficiency is 36.999645 percent\n"
       ]
      }
     ],
     "prompt_number": 41
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.22"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "r = 8.; \t\t\t#compression ratio\n",
      "T1 = 290.; \t\t\t#temperature at beginning (K)\n",
      "P1 = 100.; \t\t\t#pressure at the beginning (kPa)\n",
      "Q1 = 450.; \t\t\t#heat transferred per cycle (kJ/kg K)\n",
      "Cp = 1.005; \t\t\t#specific heat of air (kJ/kg K)\n",
      "Cv = 0.718; \t\t\t#specific heat of air (kJ/kg K)\n",
      "R = 8.314; \t\t\t#ideal gas constant\n",
      "M = 29.; \t\t\t#molecular wt of air\n",
      "\n",
      "#To determine mean effective pressure\n",
      "#Basis:\n",
      "m = 1.; \t\t\t#mass of air (kg)\n",
      "\n",
      "# Calculations and Results\n",
      "#(a)\n",
      "#Referring fig. 5.24 (Page no. 164)\n",
      "V1 = (m*R*1000*T1)/(M*P1*10**3)\n",
      "\n",
      "#Conditions at state 2\n",
      "V2 = V1/r;\n",
      "gama = Cp/Cv;\n",
      "T2 = T1*(r**(gama-1))\n",
      "P2 = P1*(r**gama )\n",
      "print '(a)'\n",
      "print ' At the end of first process'\n",
      "print ' Temperature = %f K'%T2\n",
      "print ' Pressure = %f kPa'%P2\n",
      "\n",
      "#Conditions at state 3\n",
      "#Constant volume process\n",
      "V3 = V2;\n",
      "T3 = Q1/Cv + T2;\n",
      "P3 = (T3/T2)*P2;\n",
      "print ' At the end of second process'\n",
      "print ' Temperature = %f K'%T3\n",
      "print ' Pressure = %f kPa'%P3\n",
      "\n",
      "#Conditions at state 4\n",
      "T4 = T3/(r**(gama-1))\n",
      "P4 = P3/(r**gama)\n",
      "print ' At the end of third process'\n",
      "print ' Temperature = %f K'%T4\n",
      "print ' Pressure = %f kPa'%P4\n",
      "Q2 = Cv*(T4-T1) \t\t\t#heat rejected during the constant volume process\n",
      "\n",
      "#(b)\n",
      "#Using eq. 5.88 (Page no. 165)\n",
      "eff = 1 - ((1./r)**(gama-1))\n",
      "print ' (b)'\n",
      "print ' Thermal efficiency is %f'%eff\n",
      "\n",
      "#(c)\n",
      "W = Q1-Q2; \t\t\t#work done\n",
      "print ' (c)'\n",
      "print ' Work done is %f kJ/kg'%W\n",
      "\n",
      "#(d)\n",
      "Pm = W/(V1-V2)\n",
      "print ' (d)'\n",
      "print ' Mean effective pressure is %f kPa'%Pm\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)\n",
        " At the end of first process\n",
        " Temperature = 665.859247 K\n",
        " Pressure = 1836.853096 kPa\n",
        " At the end of second process\n",
        " Temperature = 1292.600195 K\n",
        " Pressure = 3565.793640 kPa\n",
        " At the end of third process\n",
        " Temperature = 562.962905 K\n",
        " Pressure = 194.125140 kPa\n",
        " (b)\n",
        " Thermal efficiency is 0.564473\n",
        " (c)\n",
        " Work done is 254.012634 kJ/kg\n",
        " (d)\n",
        " Mean effective pressure is 349.170259 kPa\n"
       ]
      }
     ],
     "prompt_number": 42
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.23"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "r = 15.; \t\t\t#compression ratio\n",
      "P1 = 100.; \t\t\t#pressure in the beginning (kPa)\n",
      "T1 = 300.; \t\t\t#temperature in thebeginning (K)\n",
      "Q1 = 500.; \t\t\t#heat transfer rate (kJ/kg)\n",
      "M = 29.; \t\t\t#molecular wt of air\n",
      "R = 8.314; \t\t\t#ideal gas constant\n",
      "gama = 1.3997214\n",
      "#Specific heats of air (kJ/kg K)\n",
      "Cp = 1.005;\n",
      "Cv = 0.718;\n",
      "\n",
      "# Calculations and Results\n",
      "#To determine work done thermal efficiency and mean effective pressure\n",
      "#(a)\n",
      "#Isentropic compression 1-2\n",
      "V1 = (R*1000*T1)/(M*P1*10**3)\n",
      "T2 = T1*r**(gama-1)\n",
      "P2 = P1*r**gama;\n",
      "V2 = V1/r;\n",
      "print '(a)'\n",
      "print ' At the end of first process'\n",
      "print ' Temperature = %f K'%T2\n",
      "print ' Pressure = %f kPa'%P2\n",
      "\n",
      "#Consatnt pressure heat addition 2-3\n",
      "T3 = Q1/Cp + T2;\n",
      "V3 = (T3/T2)*V2;\n",
      "P3 = P2;\n",
      "print ' At the end of second process'\n",
      "print ' Temperature = %f k'%T3\n",
      "print ' Pressure = %f kPa'%P3\n",
      "\n",
      "#Isentropic math.expansion 3-4\n",
      "V4 = V1;\n",
      "T4 = T3/((V4/V3)**(gama-1))\n",
      "P4 = P3*((V3/V4)**gama)\n",
      "print ' At the end of third process'\n",
      "print ' Temperature = %f K'%T4\n",
      "print ' Pressure = %f kPa'%P4\n",
      "Q2 = Cv*(T4-T1) \t\t\t#heat rejected 4-1\n",
      "\n",
      "#(b)\n",
      "Wnet = Q1-Q2;\n",
      "print ' (b)'\n",
      "print ' Net work done per cycle per kg air is %f kJ/kg'%Wnet\n",
      "\n",
      "#(c)\n",
      "eff = Wnet/Q1; \t\t\t#thermal efficiency\n",
      "print ' (c)'\n",
      "print ' Thermal efficiency is %f'%eff\n",
      "\n",
      "#(d)\n",
      "Pm = Wnet/(V1-V2) \t\t\t#mean effective pressure\n",
      "print ' (d)'\n",
      "print ' Mean effective pressure is %f kPa'%Pm\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)\n",
        " At the end of first process\n",
        " Temperature = 885.584689 K\n",
        " Pressure = 4427.923445 kPa\n",
        " At the end of second process\n",
        " Temperature = 1383.097127 k\n",
        " Pressure = 4427.923445 kPa\n",
        " At the end of third process\n",
        " Temperature = 559.936687 K\n",
        " Pressure = 186.645562 kPa\n",
        " (b)\n",
        " Net work done per cycle per kg air is 313.365459 kJ/kg\n",
        " (c)\n",
        " Thermal efficiency is 0.626731\n",
        " (d)\n",
        " Mean effective pressure is 390.374167 kPa\n"
       ]
      }
     ],
     "prompt_number": 43
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 5.24"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#Given:\n",
      "T1 = 300.; \t\t\t#initial temperature (K)\n",
      "P1 = 100.; \t\t\t#initial pressure (kPa)\n",
      "T3 = 1200.; \t\t\t#max temperature (K)\n",
      "P3 = 500.; \t\t\t#max pressure (kPa)\n",
      "Cp = 1.005; \t\t\t#(kJ/kg K)\n",
      "Cv = 0.718; \t\t\t#(kJ/kg K)\n",
      "\n",
      "# Calculations and Results\n",
      "#To determine pressure and temperature work and thermal efficiency\n",
      "gama = Cp/Cv;\n",
      "\n",
      "#(a)\n",
      "P4 = P1;\n",
      "P2 = P3;\n",
      "#Isentropic compression 1-2\n",
      "T2 = T1*((P2/P1)**((gama-1)/gama))\n",
      "print '(a)'\n",
      "print ' At the end of first process'\n",
      "print ' Temperature = %f K'%T2\n",
      "print ' Pressure = %f kPa'%P2\n",
      "\n",
      "#Process 2-3\n",
      "print ' At the end of second process'\n",
      "print ' Temperature = %f K'%T3\n",
      "print ' Pressure = %f kPa'%P3\n",
      "\n",
      "#Isentropic math.expansion 3-4\n",
      "T4 = T3/((P3/P4)**((gama-1)/gama))\n",
      "print ' At the end of third process'\n",
      "print ' Temperature = %f K'%T4\n",
      "print ' Pressure = %f kPa'%P4\n",
      "\n",
      "#(b)\n",
      "W_comp = Cp*(T2-T1) \t\t\t#work required by compressor\n",
      "print ' (b)'\n",
      "print ' Work required by compressor is %f kJ/kg'%W_comp\n",
      "\n",
      "#(c)\n",
      "W_turb = Cp*(T3-T4 )\t\t\t#work done by turbine\n",
      "print ' (c)'\n",
      "print ' Work done by turbine is %f kJ/kg'%W_turb\n",
      "\n",
      "#(d)\n",
      "eff = 1-(P1/P2)**((gama-1)/gama)\n",
      "print ' (d)'\n",
      "print ' Thermal efficiency is %f'%eff\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)\n",
        " At the end of first process\n",
        " Temperature = 475.037193 K\n",
        " Pressure = 500.000000 kPa\n",
        " At the end of second process\n",
        " Temperature = 1200.000000 K\n",
        " Pressure = 500.000000 kPa\n",
        " At the end of third process\n",
        " Temperature = 757.835397 K\n",
        " Pressure = 100.000000 kPa\n",
        " (b)\n",
        " Work required by compressor is 175.912379 kJ/kg\n",
        " (c)\n",
        " Work done by turbine is 444.375426 kJ/kg\n",
        " (d)\n",
        " Thermal efficiency is 0.368471\n"
       ]
      }
     ],
     "prompt_number": 44
    }
   ],
   "metadata": {}
  }
 ]
}