{
 "metadata": {
  "name": "",
  "signature": "sha256:f569d6ccce789a93a823a5990b85a631168b660aee672ad7f9fe51c0887b2c5a"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 9: Gas Power Cycles "
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1, page no. 365"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "  \n",
      "from math import log\n",
      "#Variable Declaration: \n",
      "r = 6 #Compression ratio:\n",
      "v = 0.15 #Swept volume(in m**3):\n",
      "p1 = 98 #Pressure at the beginning of compression(in kPa):\n",
      "T1 = 60+273.15 #Temperature at the beginning of compression(in K):\n",
      "Q23 = 150 #Heat supplied(in kJ/kg):\n",
      "Cp = 1 #Value of Cp(in kJ/kg):\n",
      "Cv = 0.71 #Value of Cv(in kJ/kg):\n",
      "\n",
      "#Calculations:\n",
      "n = round(Cp/Cv,1) #Adiabatic compression factor:\n",
      "R = Cp-Cv #Gas constant(in kJ/kg.K):\n",
      "v2 = v/(r-1) #Volume at point 2(in m**3):\n",
      "v1 = r*v2 #Total cylinder volume(in m**3):\n",
      "m = p1*v1/(R*T1) #Mass(in kg):\n",
      "p2 = p1*(v1/v2)**n #Pressure at point 2(in kPa):\n",
      "T2 = p2*v2*T1/(p1*v1) #Temperature at state 2(in K):\n",
      "T3 = Q23/(m*Cv)+T2 #Temperature at state 3(in K):\n",
      "v3 = v2\n",
      "p3 = p2*v2*T3/(v3*T2) #Pressure at point 3(in kPa):\n",
      "v4 = v1\n",
      "p4 = p3*(v3/v4)**n #Pressure at point 4(in kPa):\n",
      "T4 = p4*v4*T3/(p3*v3) #Temperature at point 4(in K):\n",
      "dS = m*Cv*log(T4/T1) #Entropy change(in kJ/K):\n",
      "Q41 = m*Cv*(T4-T1) #Heat rejected(in kJ):\n",
      "W = Q23-Q41 #Net work done(in kJ):\n",
      "e = W/Q23 #Efficiency:\n",
      "mep = W/v #Mean effective pressure(in kPa):\n",
      "\n",
      "#Results:\n",
      "print \"Thermal efficiency: \",round(e*100,2),\"%\" \n",
      "print \"Mean effective pressure: \",round(mep,2),\"kPa\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Thermal efficiency:  51.16 %\n",
        "Mean effective pressure:  511.64 kPa\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2, page no. 367"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "  \n",
      "#Variable Declaration: \n",
      "pa = 138 #Pressure at A(in kPa):\n",
      "pb = 1380 #Pressure at B(in kPa):\n",
      "nt = 0.5 #Thermal efficiency:\n",
      "nm = 0.8 #Mechanical efficiency:\n",
      "c = 41800 #Calorific value of fuel(in kJ/kg):\n",
      "n = 1.4 #Adiabatic compressive index:\n",
      "\n",
      "#Calculations:\n",
      "r1 = (pb/pa)**(1/n)   #Ratio of va to vb:\n",
      "r = (7/8*r1-1/8)/(7/8-r1/8) #Compression ratio:\n",
      "p = (r-1)/15+1 #Cut off ratio:\n",
      "nd = 1-1/(r**(n-1)*n)*(p**n-1)/(p-1) #Air standard efficiency for Diesel cycle:\n",
      "no = nd*nt*nm #Overall efficiency:\n",
      "fc = 75*60*60/(no*c*10**2) #Fuel consumption,bhp/hr(in kg):\n",
      "\n",
      "#Results:\n",
      "print \"Compression ratio: \",round(r,2)\n",
      "print \"Air standard efficiency: \",round(nd*100,2),\"%\"\n",
      "print \"Fuel consumption,bhp/hr: \",round(fc,3),\"kg\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Compression ratio:  19.37\n",
        "Air standard efficiency:  63.22 %\n",
        "Fuel consumption,bhp/hr:  0.255 kg\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3, page no. 369"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "\n",
      "#Variable Declaration: \n",
      "Q = 1700 #Total heat added(in kJ/kg):\n",
      "p3 = 5000 #Maximum pressure(in kPa):\n",
      "T1 = 100+273.15 #Temperature at the beginning of compression(in K):\n",
      "p1 = 103 #Pressureat beginning of compression(in kPa):\n",
      "Cp = 1.005 #Value of Cp(in kJ/kg.K):\n",
      "Cv = 0.71 #Value of Cv(in kJ/kg.K):\n",
      "n = 1.4 #Adiabatic index of compression: #For Otto cycle:\n",
      "R = Cp-Cv #Gas constant(in kJ/kg.K):\n",
      "m = 1 #Considernig 1 kg of air, volume at 1(in m**3):\n",
      "\n",
      "#Calculations:\n",
      "V1 = m*R*T1/p1\n",
      "V2 = 0.18 #By solving, volume at 2(in m**3):\n",
      "r = V1/V2 #Compression ratio:\n",
      "no = 1-1/(r**(n-1)) #Otto cycle efficiency:\n",
      "V21 = 0.122 #By calculating, volume at state 2': #For mixed cycle:\n",
      "p21  =  2124.75                         #kPa \n",
      "T31  =  2082                            #K\n",
      "T21  =  884.8                           #K\n",
      "T41  =  2929.5                          #K\n",
      "V31 = V21\n",
      "V41 = V31*T41/T31 #Volume at state 4(in m**3):\n",
      "T5 = T41*(V41/V1)**(n-1) #Temperature at state 5(in K):\n",
      "Q51 = Cv*(T5-T1) #Heat rejected in the process 5-1(in kJ):\n",
      "nm = (Q-Q51)/Q #Efficiency of mixed cycle:\n",
      "\n",
      "#Results:\n",
      "print \"Efficiency of Otto cycle: \",round(no*100,2),\"%\"\n",
      "print \"Efficiency of mixed cycle: \",round(nm*100,2),\"%\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Efficiency of Otto cycle:  50.96 %\n",
        "Efficiency of mixed cycle:  56.71 %\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4, page no. 372"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "   \n",
      "\n",
      "#Variable Declaration: \n",
      "T3  =  1200 #Maximum temperature(in K):\n",
      "T1  =  300 #Minimum temperature(in K):\n",
      "n = 1.4 #Adiabatic compression ratio:\n",
      "Cp = 1.005 #Value of Cp(in kJ/kg.K):\n",
      "\n",
      "#Calculation:\n",
      "rp = (T3/T1)**(n/(2*(n-1))) #Optimum pressure ratio for maximum work output:\n",
      "T2 = T1*rp**((n-1)/n) #Temperature at state 2(in K):\n",
      "T4 = T3*rp**((1-n)/n) #Temperature at state 4(in K):\n",
      "Q23 = Cp*(T3-T2) #Heat supplied(in kJ/kg):\n",
      "Wc = Cp*(T2-T1) #Compressor work(in kJ/kg):\n",
      "Wt = Cp*(T3-T4) #Turbine work(in kJ/kg):\n",
      "nth = (Wt-Wc)/Q23*100 #Thermal efficiency:\n",
      "\n",
      "#Results:\n",
      "print \"Compressor work: \",round(Wc,2),\"kJ/kg\" \n",
      "print \"Turbine work: \",round(Wt,2),\"kJ/kg\"\n",
      "print \"Thermal efficiency: \",round(nth,2),\"%\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Compressor work:  301.5 kJ/kg\n",
        "Turbine work:  603.0 kJ/kg\n",
        "Thermal efficiency:  50.0 %\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 5, page no. 373"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "\n",
      "#Variable Declaration: \n",
      "p1 = 1 #Pressure at state 1(in bar):\n",
      "p2 = 6.2 #Pressure at state 2(in bar):\n",
      "p3 = 6.2 #Pressure at state 3(in bar):\n",
      "p4 = 1 #Pressure at state 4(in bar):\n",
      "T1 = 300 #Temperature at state 1(in K):\n",
      "r = 0.017 #Fuel by air ratio:\n",
      "nc = 0.88 #Compressor effeciency:\n",
      "nt = 0.90  #Turbine internal efficiency:\n",
      "H = 44186 #Heating value of fuel(in kJ/kg):\n",
      "n = 1.4 #Adiabatic index of compression:\n",
      "n1 = 1.33\n",
      "Cpc = 1.147 #Value of Cp for combination(in kJ/kg.K):\n",
      "Cpa = 1.005 #Value of Cp for air(in kJ/kg.K):\n",
      "\n",
      "#Calculations:\n",
      "T2 = T1*(p2/p1)**((n-1)/n) #Temperature at state 2(in K):\n",
      "T21 = (T2-T1)/nc+T1 #Actual temperature after compression(in K):\n",
      "T3 = (r*H+Cpa*T21)/((1+r)*Cpc) #Temperature at state 3(in K):\n",
      "T4 = T3*(p4/p3)**((n1-1)/n1) #Temperature at state 4(in K):\n",
      "T41 = T3-nt*(T3-T4) #Actual temperature at turbine inlet considering internal efficiency of turbine(in K):\n",
      "Wc = Cpa*(T21-T1) #Compressor work, per kg of air compressed(in kJ/kg):\n",
      "Wt = Cpc*(T3-T41) #Turbine work, per kg of air compressed(in K):\n",
      "Wnet = Wt-Wc #Net work(in kJ/kg):\n",
      "Q = r*H #Heat supplied(in kJ/kg):\n",
      "nth = Wnet/Q*100 #Thermal effeciency:\n",
      "\n",
      "#Results:\n",
      "print \"Compressor work: \",round(Wc,2),\"kJ/kg\" \n",
      "print \"Turbine work: \",round(Wt,2),\"kJ/kg\"\n",
      "print \"Thermal efficiency: \",round(nth,2),\"%\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Compressor work:  234.42 kJ/kg\n",
        "Turbine work:  414.71 kJ/kg\n",
        "Thermal efficiency:  24.0 %\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 6, page no. 374"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "  \n",
      "\n",
      "#Variable Declaration: \n",
      "T5 = 1200 #Maximum temperature(in K):\n",
      "T1 = 300 #Minimum temperature(in K):\n",
      "T3 = 300\n",
      "ni = 0.85 #Isentropic efficiency:\n",
      "nt = 0.9 #Turbine efficiency:\n",
      "n = 1.4 #Adiabatic index of compression:\n",
      "\n",
      "#Calculations:\n",
      "rpopt = (T1/(T5*ni*nt))**(2*n/(3*(1-n)))#Overall optimum pressure ratio:\n",
      "\n",
      "#Results:\n",
      "print \"Overall optimum pressure ratio: \",round(rpopt,1)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Overall optimum pressure ratio:  13.6\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7, page no. 377"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "from math import log\n",
      "\n",
      "#Variable Declaration: \n",
      "rp = 1.35 #Ratio of pressure:\n",
      "m = 50   #Flow rate through compressor(in kg/s):\n",
      "no = 0.90 #Overall efficiency:\n",
      "p1 = 1  #Initial pressure(in bar):\n",
      "T1 = 313 #Initial temperature(in K):\n",
      "r = 1.4 #Adiabatic index of compression:\n",
      "R = 0.287 #Gas constant(in kJ/kg.K):\n",
      "\n",
      "#Calculation:\n",
      "p9 = p1*rp**8 #Exit pressure(in bar):\n",
      "T9 = T1*(p9/p1)**((r-1)/r) #Temperature at exit(in K):\n",
      "T9a = (T9-T1)/0.82+T1 #Considerinf efficiency, actual temperature at exit(in K):\n",
      "n = log(p9/p1)/(log(p9/p1)-log(T9a/T1)) #Actual index of compression:\n",
      "np = ((r-1)/r)*(n/(n-1)) #Polytropic efficiency:\n",
      "T2 = T1*rp**((r-1)/r) #Temperature at state 2(in K):\n",
      "T2a = T1*(rp)**((n-1)/n) #Actual temperature at state 2(in K):\n",
      "ns1 = (T2-T1)/(T2a-T1) #Stage efficiency:\n",
      "Wc = (n/(n-1))*m*R*T1*((p9/p1)**((n-1)/n)-1) #Work done by compressor(in kJ/s):\n",
      "Wca = Wc/no #Actual compressor work(in kJ/s):\n",
      "\n",
      "#Results:\n",
      "print \"Pressure at exit of comppressor: \",round(p9,2),\"bar\"\n",
      "print \"Temperature at the exit of compressor: \",round(T9a,2),\"K\"\n",
      "print \"Polytropic efficiency: \",round(np*100,2),\"%\"\n",
      "print \"Stage efficiency: \",round(ns1*100,1),\"%\"\n",
      "print \"Power required to drive compressor: \",round(Wca,2),\"kJ/s\","
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Pressure at exit of comppressor:  11.03 bar\n",
        "Temperature at the exit of compressor:  689.24 K\n",
        "Polytropic efficiency:  86.9 %\n",
        "Stage efficiency:  86.3 %\n",
        "Power required to drive compressor:  18245.07 kJ/s\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9, page no. 381"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      " \n",
      "\n",
      "#Variable Declaration: \n",
      "T1 = 27+273 #Temperature at which air is supplied(in K):\n",
      "p2 = 8 #Initial pressure(in bar):\n",
      "T3 = 1100 #Temperature of air leaving the combustion chamber(in K):\n",
      "p4 = 1 #Pressure at state 4(in bar):\n",
      "E = 0.8 #Effectiveness of heat exchanger:\n",
      "npc = 0.85 #Polytropic efficiency of the compressor:\n",
      "npt = 0.90 #Polytropic efficinency of the turbnie:\n",
      "r = 1.4 #Adiabatic index of compression:\n",
      "Cp = 1.0032 #Value of Cp(in kJ/kg.K):\n",
      "\n",
      "#Calculations:\n",
      "p3 = p2\n",
      "p1 = p4\n",
      "nc = r*npc/(r*npc-(r-1)) #Compression index:\n",
      "nt = r/(r-npt*(r-1)) #Expansion index:\n",
      "T2 = T1*(p2/p1)**((nc-1)/nc) #Temperature at state 2:\n",
      "T4 = T3*(p4/p3)**((nt-1)/nt) #Temperature at state 4(in K):\n",
      "T5 = (T4-T2)*E+T2 #Using heat exchanger effectiveness, temperature at state 5(in K):\n",
      "qa = Cp*(T3-T5) #Heat added in combustion chambers(in kJ/kg):\n",
      "Wc = Cp*(T2-T1) #Compressor work(in kJ/kg):\n",
      "Wt = Cp*(T3-T4) #Turbine work(in kJ/kg):\n",
      "ncycle = (Wt-Wc)/qa #Cycle efficiency:\n",
      "Wr = (Wt-Wc)/Wt #Work ratio:\n",
      "swo = Wt-Wc #Specific work output(in kJ/kg):\n",
      "\n",
      "#Results:\n",
      "print \"Cycle efficiency: \",round(ncycle*100,2),\"%\"  \n",
      "print \"Work ratio: \",round(Wr,3)\n",
      "print \"Specific work output: \",round(swo,2),\"kJ/kg\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Cycle efficiency:  32.79 %\n",
        "Work ratio:  0.334\n",
        "Specific work output:  152.56 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 10, page no. 382"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "\n",
      "#Variable Declaration: \n",
      "p1 = 1  #Initial pressure(in bar):\n",
      "T1 = 27+273 #Initial temperature(in K):\n",
      "p2 = 5  #Pressure at state 2(in bar):\n",
      "nc = 0.85 #Isentropic efficiency:\n",
      "T3 = 1000 #Temperature at state 3(in K):\n",
      "p3 = p2-0.2 #Pressure at state 3(in bar):\n",
      "p4 = p1  #Pressure at state 4(in bar):\n",
      "nth = 0.20 #Thermal efficiency of plant:\n",
      "r = 1.4    #Adiabatic index of compression:\n",
      "Cp = 1.0032 #Value of Cp(in kJ/kg.K):\n",
      "\n",
      "#Calculations:\n",
      "T21 = T1*(p2/p1)**((r-1)/r) #Temperature at state 2'(in K):\n",
      "T2 = (T21-T1)/nc+T1 #Temperature at state 2(in K):\n",
      "T41 = T3*(p4/p3)**((r-1)/r) #Temperature at state 4'(in K):\n",
      "Wc = Cp*(T2-T1) #Compressor work per kg(in kJ/kg): \n",
      "qa = Cp*(T3-T2) #Heat added(in kJ/kg):\n",
      "T4 = T3-(qa*(-nth)+Wc)/Cp #Temperature at state 4(in K):\n",
      "nt = (T3-T4)/(T3-T41) #Isentropic efficiency of turbine:\n",
      "\n",
      "#Results:\n",
      "print \"Turbine isentropic efficiency: \",round(nt*100,3),\"%\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Turbine isentropic efficiency:  29.696 %\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 11, page no. 383"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "\n",
      "from math import sqrt\n",
      "#Variable Declaration: \n",
      "p1 = 1  #Pressure at which air is supplied(in bar):\n",
      "T1 = 27+273 #Temperature at which air is supplied(in K):\n",
      "T5 = 1000 #Maximum temperature in the cycle(in K):\n",
      "p6 = 3  #Pressure at state 6(in bar):\n",
      "p3 = 3\n",
      "T7 = 995 #Temperature at state 7(in K):\n",
      "c = 42000 #Calorific value of fuel(in kJ/kg):\n",
      "Cp = 1.0032 #Value of Cp(in kJ/kg):\n",
      "m = 30 #Air flow in compressor(in kg/s):\n",
      "nc = 0.85 #Isentropic efficiency of compression:\n",
      "ne = 0.90 #Isebtropic efficiency of expansion:\n",
      "r = 1.4    #Adiabatic index of compression:\n",
      "\n",
      "#Calculations:\n",
      "p8 = p1\n",
      "p7 = p6\n",
      "p4 = 10\n",
      "p5 = p4\n",
      "rp = round(sqrt(10),2) #Pressure ratio for perfect intercooling:\n",
      "T21 = round(T1*rp**((r-1)/r),2) #Temperature at state 2'(in K):\n",
      "T3 = T1    #For perfect intercooling:\n",
      "T2 = round((T21-T1)/nc+T1,2) #Temperature at state 2(in K):\n",
      "T41 = round(T3*(rp)**((r-1)/r),2) #Temperature at state 4'(in K):\n",
      "T4 = round((T41-T3)/nc+T3,2) #Temperature at state 4(in K):\n",
      "Wc = round(2*Cp*(T2-T1),2) #Total compressor work(in kJ/kg):\n",
      "T61 = round(T5*(p6/p5)**((r-1)/r),2) #Temperature at state 6'(in K):\n",
      "T6 = round(T5-(T5-T61)*ne,2) #Temperature at state 6(in K):\n",
      "T81 = round(T7*(p8/p7)**((r-1)/r),2) #Temperature at state 8'(in K):\n",
      "T8 = round(T7-(T7-T81)*ne,2) #Temperature at state 8(in K):\n",
      "Wt = Cp*(T5-T6+T7-T8) #Expansion work output per kg air(in kJ/kg):\n",
      "qa = Cp*(T5-T4+T7-T6) #Heat added per kg air(in kJ/kg):\n",
      "mf = qa/ #Fuel required per kg of air:\n",
      "afr = 1/mf #Air-fuel ratio:\n",
      "Wnet = (Wt-Wc)*m #Net output(in kW):\n",
      "nth = (Wt-Wc)/qa #Thermal efficiency:\n",
      "print T21\n",
      "#Results:\n",
      "print \"Thermal efficiency: \",round(nth*100,2),\"%\" \n",
      "print \"Net output: \",round(Wnet,2),\"kW\"\n",
      "print \"A/F ratio: \",round(afr,2)\n",
      "print \"___There is a calculation mistake in calculating Wt, in the book hence answer varies____\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "416.76\n",
        "Thermal efficiency:  27.88 %\n",
        "Net output:  6876.61 kW\n",
        "A/F ratio:  51.08\n",
        "___There is a calculation mistake in calculating Wt, in the book hence answer varies____\n"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 12, page no. 385"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "\n",
      "#Variable Declaration: \n",
      "p1 = 1    #Pressure of air at each state(in bar):\n",
      "p2 = 4\n",
      "p3 = 4\n",
      "p4 = 8\n",
      "p6 = p4\n",
      "p7 = 4\n",
      "p8 = 4\n",
      "p9 = 1\n",
      "T1 = 300    #Temperature at each state(in K):\n",
      "T3 = 290\n",
      "T6 = 1300\n",
      "T8 = 1300\n",
      "E = 0.80    #Effectiveness:\n",
      "c = 42000   #Heating value of fuel(in kJ/kg):\n",
      "r = 1.4  #Adiabatic index of combustion:\n",
      "Cp = 1.0032   #Value of Cp(in kJ/kg):\n",
      "\n",
      "#Calculations:\n",
      "T2 = T1*(p2/p1)**((r-1)/r)    #Temperature at state 2(in K):\n",
      "T4 = T3*(p4/p3)**((r-1)/r)    #Temperature at state 4(in K):\n",
      "T7 = T6*(p7/p6)**((r-1)/r)    #Temperature at state 7(in K):\n",
      "T9 = T8*(p9/p8)**((r-1)/r)    #Temperature at state 9(in K):\n",
      "T5 = (T9-T4)*E+T4     #Temperature at state 5(in K):\n",
      "Wc = Cp*(T2-T1+T4-T3)    #Compressor work per kg of air(in kJ/kg):\n",
      "Wt = Cp*(T6-T7+T8-T9)    #Turbine work per kg of air(in kJ/kg):\n",
      "qa = Cp*(T6-T5+T8-T7)    #Heat added per kg air(in kJ/kg):\n",
      "mf = qa/c    #Total fuel per kg of air:\n",
      "Wnet = Wt-Wc    #Net work(in kJ/kg):\n",
      "n = Wnet/qa*100   #Cycle thermal efficiency:\n",
      "afr1 = Cp*(T6-T5)/c  #Fuel per kg air in combustion chamber 1:\n",
      "afr2 = Cp*(T8-T7)/c  #Fuel per kg air in combustion chamber 2:\n",
      "\n",
      "#Results:\n",
      "print \"A/F ratio in the two combustion chambers: \",round(afr1,4),round(afr2,4)\n",
      "print \"Total turbine work\",round(Wt,2),\"kJ/kg\"\n",
      "print \"Cycle thermal efficiency\",round(n,2),\"%\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "A/F ratio in the two combustion chambers:  0.0126 0.0056\n",
        "Total turbine work 660.84 kJ/kg\n",
        "Cycle thermal efficiency 58.9 %\n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 13, page no. 387"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "\n",
      "from math import log\n",
      "\n",
      "#Variable Declaration: \n",
      "T2 = 700 #Maximum temperature(in K):\n",
      "T1 = 300 #Minimum temperature(in K):\n",
      "r = 3   #Compression ratio:\n",
      "qa = 30  #Total heat added(in kJ/s):\n",
      "E = 0.90 #Regenerator efficiency:\n",
      "p = 1     #Pressure at the beginning of compression(in bar):\n",
      "n = 100 #Number of cycles:\n",
      "Cv = 0.72 #Value of Cv:\n",
      "R = 29.27 #Gas constant(in kJ/kg.K):\n",
      "\n",
      "#Calculations:\n",
      "W = R*(T2-T1)*log(r) #Work done per kg of air(in kJ/kg):\n",
      "q = R*T2*log(r)+(1-E)*Cv*(T2-T1) #Heat added per kg of air(in kJ/kg):\n",
      "m = qa/q #Mass of air for 30 kJ/s of heat supplied(in kg/s):\n",
      "mc = m/n #Mass of air per cycle(in kg/cycle):\n",
      "BP = W*m #Brake output(in kW):\n",
      "V = mc*R*T1/(p*10**2) #Stroke volume(in m**3):\n",
      "\n",
      "#Results:\n",
      "print \"Brake output: \",round(BP,2),\"kW\" \n",
      "print \"Stroke volume: \",round(V,5),\"m**3\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Brake output:  17.12 kW\n",
        "Stroke volume:  0.00117 m**3\n"
       ]
      }
     ],
     "prompt_number": 28
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 15, page no. 392"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "\n",
      "#Variable Declaration: \n",
      "T1 = 17+273 #Ambient temperature(in K):\n",
      "T3 = 1400 #Temperature at state 3(in K):\n",
      "T5 = 420                                #Temperature at state 5(in K):\n",
      "p1 = 1    #Ambient pressure(in bar):\n",
      "p2 = 10  #As pressure ratio is 10, pressure at state 2(in bar):\n",
      "p3 = 10\n",
      "p4 = 1\n",
      "ph = 6000 #Pressure in HSRG(in kPa):\n",
      "pc = 15    #Condensor pressure(in kPa):\n",
      "O = 37.3 #Combined cycle output(in MW):\n",
      "r = 1.4    #Adiabatic index of compression:\n",
      "Cp = 1.0032 #Value of Cp(in kJ/kg.K):\n",
      "#From steam tables:\n",
      "ha = 3177.2                             #kJ/kg \n",
      "sa = 6.5408                             #kJ/kg.K \n",
      "sb = sa\n",
      "x = 0.7976\n",
      "hb = 2118.72                            #kJ/kg\n",
      "hc = 225.94                             #kJ/kg\n",
      "vc = 0.001014                           #m**3/kg\n",
      "\n",
      "#Calculations:\n",
      "T2 = T1*(p2/p1)**((r-1)/r) #Temperature at state 2(in K):\n",
      "T4 = T3*(p4/p3)**((r-1)/r) #Temperature at state 4(in K):\n",
      "Wc = Cp*(T2-T1) #Compressor work per kg(in kJ/kg):\n",
      "Wt = Cp*(T3-T4) #Turbine work per kg(in kJ/kg):\n",
      "qa = Cp*(T3-T2) #Heat added in combustion chamber(in kJ/kg):\n",
      "WnetGT = Wt-Wc #Net gas turbine output(in kJ/kg air):\n",
      "qHSRG = Cp*(T4-T5) #Heat recovered in HSRG for steam generation(in kJ/kg):\n",
      "hd = vc*(ph-pc)*10**2 #Enthalpy at exit of feed pump(in kJ/kg):\n",
      "had = ha-hd #Heat added per kg of steam(in kJ/kg):\n",
      "m = qHSRG/had #Mass of steam generated per kg of air:\n",
      "WnetST = ha-hb-(hd-hc) #Net steam turbine cycle output(in kJ/kg):\n",
      "sco = WnetST*m #Steam cycle output per kg(in kJ/kg air):\n",
      "tco = WnetGT+sco #Total combined output(in kJ/kg air):\n",
      "ncc = tco/qa #Combined cycle efficiency:\n",
      "ngt = WnetGT/qa #Gas turbine efficiency:\n",
      "\n",
      "#Results:\n",
      "print \"Overall efficiency\",round(ncc*100,2),\"%\" \n",
      "print \"Steam per kg of air\",round(m,3),\"kg steam/kg air\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Overall efficiency 57.78 %\n",
        "Steam per kg of air 0.119 kg steam/kg air\n"
       ]
      }
     ],
     "prompt_number": 32
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16, page no. 394"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from __future__ import division\n",
      "\n",
      "\n",
      "#Variable Declaration: \n",
      "T1 = 27+273 #Temperature of working fuel at the beginning of compression(in K):\n",
      "rp = 70 #Pressure ratio:\n",
      "rv = 15 #Compression ratio:\n",
      "r = 1.4 #Adiabatic index of compression:\n",
      "\n",
      "#Calculations:\n",
      "T2 = T1*(rv)**(r-1) #Temperature at state 2(in K):\n",
      "T3 = T2*rp/(rv**r) #Temperature at state 3(in K):\n",
      "T4 = T3+(T3-T2)/r #Temperature at state 4(in K):\n",
      "T5 = T4*(T3/T4*rv)**(1-r) #Temperature at state 5(in K):\n",
      "n = 1-(T5-T1)/(r*(T4-T3)+(T3-T2))#Air standard thermal efficiency:\n",
      "\n",
      "#Results:\n",
      "print \"Air standard thermal efficiency\",round(n*100,2),\"%\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Air standard thermal efficiency 65.3 %\n"
       ]
      }
     ],
     "prompt_number": 34
    }
   ],
   "metadata": {}
  }
 ]
}