{
 "metadata": {
  "name": "",
  "signature": "sha256:1fcefba58d1aff268f075c74fd2cddb1b329d45775f950b8a0c675f9e594fddf"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 9:GAS CYCLES"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.1, Page No:425"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "r=8; # Compression ratio of an engine\n",
      "p1=100; # Pressure of air before compression in lPa\n",
      "T1=300; # Temperature air before compression in kelvin\n",
      "qH=1800; # Heat added to the air in kJ/kg\n",
      "k=1.4; # Index of reversible adiabatic process\n",
      "Cvo=0.7165; # Specific heat at constant volume in kJ/kg K\n",
      "Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K\n",
      "R=0.287; # characteristic gas constant of air in kJ/kg K\n",
      "\n",
      "#Calculation for (1)\n",
      "# Otto cycle\n",
      "#  (1) state 2\n",
      "p2=p1*(r)**k; # Pressure at the end of compression\n",
      "T2=T1*(p2/p1)**((k-1)/k);# Temperature at the end of compression\n",
      "# state 3\n",
      "T3=(qH/Cvo)+T2; # Temperatue after heat addition\n",
      "p3=p2*(T3/T2); # Pressure after heat addition\n",
      "# state 4\n",
      "p4=p3*(1/r)**k; # Pressure after expansion\n",
      "T4=T3*(p4/p3)**((k-1)/k);# Temperature after expansion\n",
      "\n",
      "#Result for (1)\n",
      "print \"(1).state 1\",\"\\n    Pressure of air before compression = \",p1,\"kPa\",\"\\n    Temperature air before compression =\",T1,\"K\"\n",
      "print \"state 2\",\"\\n    Pressure of air at the end of compression = \",round(p2,0),\"kPa\"\n",
      "print \"    Temperature at the end of compression =\",round(T2,1),\"K\"\n",
      "print \"state 3\",\"\\n    Pressure after heat addition = \",round(p3,0),\"kPa   (round off error)\"\n",
      "print \"    Temperature after heat addition =\",round(T3,1),\"K   (round off error)\"\n",
      "print \"state 4\",\"\\n    Pressure after expansion = \",round(p4,1),\"kPa   (round off error)\"\n",
      "print \"    Temperature after expansion =\",round(T4,1),\"K   (round off error)\"\n",
      "\n",
      "#Calculation for (2)\n",
      "#  (2).Thermal efficiency\n",
      "qL=Cvo*(T4-T1); # Heat rejected\n",
      "eff_th=1-qL/qH; # thermal efficiency\n",
      "\n",
      "#Result for (2)\n",
      "print \"\\n(2).Thermal efficienvy = \",round(eff_th*100,2),\"%   (round off error)\"\n",
      "\n",
      "#Calculation for (3)\n",
      "#   (3). Mean effective pressure\n",
      "wnet=qH-qL; # net work\n",
      "v1=R*T1/p1; # Specific volume at state 1\n",
      "v2=v1/r; # Specific volume at state 2\n",
      "pm=wnet/(v1-v2); # Mean effective pressure\n",
      "\n",
      "#Result for (3)\n",
      "print \"\\n(3).Mean effective pressure = \",round(pm,0),\"kPa\"\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(1).state 1 \n",
        "    Pressure of air before compression =  100 kPa \n",
        "    Temperature air before compression = 300 K\n",
        "state 2 \n",
        "    Pressure of air at the end of compression =  1838.0 kPa\n",
        "    Temperature at the end of compression = 689.2 K\n",
        "state 3 \n",
        "    Pressure after heat addition =  8537.0 kPa   (round off error)\n",
        "    Temperature after heat addition = 3201.4 K   (round off error)\n",
        "state 4 \n",
        "    Pressure after expansion =  464.5 kPa   (round off error)\n",
        "    Temperature after expansion = 1393.5 K   (round off error)\n",
        "\n",
        "(2).Thermal efficienvy =  56.47 %   (round off error)\n",
        "\n",
        "(3).Mean effective pressure =  1349.0 kPa\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.2, Page No:430"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "r=18; # Compression ratio of an engine\n",
      "p1=100; # Pressure of air before compression in lPa\n",
      "T1=300; # Temperature air before compression in kelvin\n",
      "qH=1800; # Heat added to the air in kJ/kg\n",
      "k=1.4; # Index of reversible adiabatic process\n",
      "Cvo=0.7165; # Specific heat at constant volume in kJ/kg K\n",
      "Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K\n",
      "R=0.287; # characteristic gas constant of air in kJ/kg K\n",
      "\n",
      "#Calculation\n",
      "#   Diesel cycle\n",
      "# state 2\n",
      "T2=T1*(r)**(k-1); # Temperature at the end of compression\n",
      "p2=p1*(r)**k; # Pressure at the end of compression\n",
      "# state 3\n",
      "T3=(qH/Cpo)+T2; # Temperatue after heat addition\n",
      "p3=p2; #constant pressure\n",
      "Tmax=T3; # maximum temperature\n",
      "Pmax=p3; # Maximum pressure\n",
      "# state 4\n",
      "v3=R*T3/p3; # Specific volume at state 3\n",
      "v4=R*T1/p1; # Specific volume at state 4\n",
      "T4=T3*(v3/v4)**(k-1); # Temperature after expansion\n",
      "p4=p3*(v3/v4)**k; # Pressure after expansion\n",
      "qL=Cvo*(T4-T1); # Heat rejected\n",
      "wnet=qH-qL; # net work\n",
      "eff_th=wnet/qH; # thermal efficiency\n",
      "v1=R*T1/p1; # Specific volume at state 1\n",
      "v2=v1/r; # Specific volume at state 2\n",
      "pm=wnet/(v1-v2); # Mean effective pressure\n",
      "\n",
      "#Results\n",
      "print \"Maximum pressure = \",Pmax,\"kPa\",\"Maximum Temperature = \",Tmax,\"K\"\n",
      "print \"Thermal efficienvy = \",round(eff_th*100,1),\"%\"\n",
      "print \"Mean effective pressure =  \",round(pm,0),\"kPa    (Error in textbook)\"\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Maximum pressure =  5719.80874166 kPa Maximum Temperature =  2747.02343004 K\n",
        "Thermal efficienvy =  59.4 %\n",
        "Mean effective pressure =   1315.0 kPa    (Error in textbook)\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.3, Page No: 440"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "p1=0.1; # Pressure of air at inlet in MPa\n",
      "T1=300; # Temperature of air at inlet in kelvin\n",
      "p2=0.6; # Pressure of air at exit in MPa\n",
      "T3=1200; # Maximun temperature of air in kelvin\n",
      "k=1.4; # Index of reversible adiabatic process\n",
      "Cvo=0.7165; # Specific heat at constant volume in kJ/kg K\n",
      "Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K\n",
      "R=0.287; # characteristic gas constant of air in kJ/kg K\n",
      "\n",
      "#Calculation\n",
      "# Brayton cycle\n",
      "rp=p2/p1; # pressure ratio\n",
      "T2=T1*(p2/p1)**((k-1)/k);# Temperature at the end of compression\n",
      "wc=Cpo*(T2-T1); # compressor work\n",
      "T4=T3*(p1/p2)**((k-1)/k);# Temperature at the end of expansion\n",
      "wT=Cpo*(T3-T4); # Turbine work\n",
      "qH=Cpo*(T3-T2); # heat addition\n",
      "wnet=wT-wc; # net work\n",
      "eff_th=wnet/qH; # thermal efficiency\n",
      "rw=wnet/wT; # worh ratio\n",
      "\n",
      "#Result \n",
      "print \"Thermal Efficiency = \",round(eff_th*100,1),\"%\"\n",
      "print \"Work Ratio = \",round(rw,3)\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Thermal Efficiency =  40.1 %\n",
        "Work Ratio =  0.583\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.4, Page No: 441"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "p1=0.1; # Pressure of air at inlet in MPa\n",
      "T1=300; # Temperature of air at inlet in kelvin\n",
      "p2=0.6; # Pressure of air at exit in MPa\n",
      "T3=1200; # Maximun temperature of air in kelvin\n",
      "k=1.4; # Index of reversible adiabatic process\n",
      "Cvo=0.7165; # Specific heat at constant volume in kJ/kg K\n",
      "Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K\n",
      "R=0.287; # characteristic gas constant of air in kJ/kg K\n",
      "eff_t=0.85; # Turbine efficiency\n",
      "eff_c=0.8; # Compressor efficienct\n",
      "\n",
      "#Calculation\n",
      "# Brayton cycle\n",
      "rp=p2/p1; # pressure ratio\n",
      "T2s=T1*(p2/p1)**((k-1)/k);# Isentropic Temperature at the end of compression\n",
      "T2=((T2s-T1)/eff_c)+T1; # Actual Temperature at the end of compression\n",
      "p3=0.585; # as per given in MPa\n",
      "p4s=0.11; # As per given in MPa\n",
      "T4s=T3*(p4s/p3)**((k-1)/k); # Isentropic temperature after reversible adiabatic expansion\n",
      "T4=T3-(eff_t*(T3-T4s));# Actual temperature at state 4\n",
      "wc=Cpo*(T2-T1); # compressor work\n",
      "wT=Cpo*(T3-T4); # Turbine work\n",
      "qH=Cpo*(T3-T2); # heat addition\n",
      "wnet=wT-wc; # net work\n",
      "eff_th=wnet/qH; # thermal efficiency\n",
      "rw=wnet/wT; # worh ratio\n",
      "\n",
      "#Result \n",
      "print \"Thermal Efficiency = \",round(eff_th*100,0),\"%\"\n",
      "print \"Work Ratio = \",round(rw,3)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Thermal Efficiency =  21.0 %\n",
        "Work Ratio =  0.353\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.5, Page No: 448"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "p1=0.1; # Pressure of air at inlet in MPa\n",
      "T1=300; # Temperature of air at inlet in kelvin\n",
      "p2=0.6; # Pressure of air at exit in MPa\n",
      "T3=1200; # Maximun temperature of air in kelvin\n",
      "k=1.4; # Index of reversible adiabatic process\n",
      "Cvo=0.7165; # Specific heat at constant volume in kJ/kg K\n",
      "Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K\n",
      "R=0.287; # characteristic gas constant of air in kJ/kg K\n",
      "\n",
      "#Calculation\n",
      "# Brayton cycle\n",
      "rp=p2/p1; # pressure ratio\n",
      "T2=T1*(p2/p1)**((k-1)/k);# Temperature at the end of compression\n",
      "T4=T3*(p1/p2)**((k-1)/k);# Temperature at state 4\n",
      "Tx=T4; Ty=T2; # regenerator temperatures\n",
      "qH=Cpo*(T3-Tx); # Heat added in the cycle with regenerator\n",
      "qL=Cpo*(Ty-T1);# Heat rejected in the cycle with regenerator\n",
      "eff_th=1-qL/qH; # Thermal efficiency\n",
      "\n",
      "#Result\n",
      "print \"Thermal efficiency with regenerator = \",round(eff_th*100,1),\"%\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Thermal efficiency with regenerator =  58.3 %\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.6, Page No: 453"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "V1=250; # Velocoty of jet aircraft in m/s\n",
      "p1=60; # Atmospheric pressure in kPa\n",
      "T1=260; # Atmospheric temperature in kelvin\n",
      "rp=8; # Pressure ratio of compressor\n",
      "T4=1350; # Temperature of gas at turbine inlet in kelvin\n",
      "k=1.4; # Index of reversible adiabatic process\n",
      "Cvo=0.7165; # Specific heat at constant volume in kJ/kg K\n",
      "Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K\n",
      "R=0.287; # characteristic gas constant of air in kJ/kg K\n",
      "\n",
      "#Calculation for (a)\n",
      "# (a).The pressure and temperature at each point of the cycle\n",
      "# process 1-2 isentropic diffusion\n",
      "T2=T1+(V1**2)/(2*Cpo*10**3); # Temperature at state 2\n",
      "p2=p1*(T2/T1)**(k/(k-1)); # Pressure at state 2\n",
      "# process 2-3 isentropic compression\n",
      "p3=rp*p2; # perssure at state 3\n",
      "T3=T2*(p3/p2)**((k-1)/k); # Temperature at state 3\n",
      "wc=Cpo*(T3-T2); # compressor work\n",
      "# process 3-4 Constant pressur heat addition\n",
      "qH=Cpo*(T4-T3); # heat addition\n",
      "p4=p3; # constant pressure\n",
      "# process 4-5 isentropic expansion in turbine\n",
      "wT=wc;\n",
      "T5=T4-(wT/Cpo); # Temperature at state 5\n",
      "p5=p4*(T5/T4)**(k/(k-1)); # Pressure at state 5\n",
      "# process 5-6 Isentropic expansion in nozzle\n",
      "p6=p1;\n",
      "T6=T5*(p6/p5)**((k-1)/k); # Temperature at state 6\n",
      "\n",
      "#Result for (a)\n",
      "print \"(a).The pressure and temperature at each point of the cycle\",\"\\n  State 1\",\"\\n     p1 =\",p1,\"kPa\",\"\\n     T1 =\",T1,\"K\"\n",
      "print \"\\n  State 2\",\"\\n     p2 =\",round(p2,1),\"kPa\",\"\\n     T2 =\",round(T2,1),\"K\",\n",
      "print \"\\n  State 3\",\"\\n     p3 =\",round(p3,0),\"kPa\",\"\\n     T3 =\",round(T3,1),\"K\"\n",
      "print \"\\n  State 4\",\"\\n     p4 =\",round(p4,0),\"kPa\",\"\\n     T4 =\",T4,\"K\"\n",
      "print \"\\n  State 5\",\"\\n     p5 =\",round(p5,0),\"kPa   (roundoff error)\",\"\\n     T5 =\",round(T5,1),\"K    (roundoff error)\"\n",
      "print \"  State 6\",\"\\n     p6 =\",p6,\"kPa\",\"\\n     T6 =\",round(T6,0),\"K\"\n",
      "\n",
      "#Calculation for (b)\n",
      "# (b).Exit velocity of jet\n",
      "V6=math.sqrt (2*Cpo*10**3*(T5-T6)); # Exit velocity of jet\n",
      "\n",
      "#Result for (b)\n",
      "print \"\\n\\n(b).Exit velocity of jet =\",round(V6,0),\"m/s   (roundoff error)\"\n",
      "\n",
      "#Calculation for (c)\n",
      "#   (c).Specific thrust and work output\n",
      "F_mair=(V6-V1); # Specific thrust \n",
      "w=F_mair*V1/1000; # Work output\n",
      "\n",
      "#Result for (c)\n",
      "print \"\\n\\n(c).Specific thrust and work output\",\"\\nSpecific thrust =\",round(F_mair,0),\"N   (roundoff error)\"\n",
      "print \"Work output = \",round(w,1),\"kJ/kg\"\n",
      "\n",
      "#Calculation for (d)\n",
      "#   (d).Propulsion efficiency\n",
      "eff_p=w/(w+(V6**2-V1**2)/2000);# Propulsion efficiency\n",
      "\n",
      "#Result for (d)\n",
      "print \"\\n\\n(d).Propulsion efficiency =\",round(eff_p*100,1),\"%\"\n",
      "\n",
      "#Calculation for (e)\n",
      "#    (e).Overall thermal efficiency\n",
      "eff_th=w/qH; # Overall thermal efficiency\n",
      "\n",
      "#Result for (e)\n",
      "print \"(e).Overall thermal efficiency =\",round(eff_th*100,1),\"%\"\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a).The pressure and temperature at each point of the cycle \n",
        "  State 1 \n",
        "     p1 = 60 kPa \n",
        "     T1 = 260 K\n",
        "\n",
        "  State 2 \n",
        "     p2 = 89.1 kPa \n",
        "     T2 = 291.1 K \n",
        "  State 3 \n",
        "     p3 = 713.0 kPa \n",
        "     T3 = 527.4 K\n",
        "\n",
        "  State 4 \n",
        "     p4 = 713.0 kPa \n",
        "     T4 = 1350 K\n",
        "\n",
        "  State 5 \n",
        "     p5 = 364.0 kPa   (roundoff error) \n",
        "     T5 = 1113.8 K    (roundoff error)\n",
        "  State 6 \n",
        "     p6 = 60 kPa \n",
        "     T6 = 666.0 K\n",
        "\n",
        "\n",
        "(b).Exit velocity of jet = 948.0 m/s   (roundoff error)\n",
        "\n",
        "\n",
        "(c).Specific thrust and work output \n",
        "Specific thrust = 698.0 N   (roundoff error)\n",
        "Work output =  174.6 kJ/kg\n",
        "\n",
        "\n",
        "(d).Propulsion efficiency = 29.4 %\n",
        "(e).Overall thermal efficiency = 21.2 %\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.7, Page No:458"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "p1=100; # Pressure of air at inlet in kPa\n",
      "T1=288; # Temperature of air at inlet in kelvin\n",
      "rp=12; # Pressure ratio of the compressor\n",
      "k=1.4; # Index of reversible adiabatic process\n",
      "Cvo=0.7165; # Specific heat at constant volume in kJ/kg K\n",
      "Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K\n",
      "R=0.287; # characteristic gas constant of air in kJ/kg K\n",
      "T3=T1; # From figure\n",
      "\n",
      "#Calculation\n",
      "# process 1-2\n",
      "p2=12*p1; # Pressure at state 2\n",
      "T2=T1*(p2/p1)**((k-1)/k); # Temperature at state 2\n",
      "wc=Cpo*(T2-T1); # Compressor work\n",
      "# process 2-3\n",
      "qH=Cpo*(T2-T3); # Heat added\n",
      "# process 3-4\n",
      "T4=T3*(1/rp)**((k-1)/k); # Temperature at state 4\n",
      "# process 4-1 Refrigerating coil\n",
      "qL=Cpo*(T1-T4); # heat rejected\n",
      "wnet=qH-qL; # net work\n",
      "cop=qL/wnet; # Cop of plant\n",
      "pc=wnet/qL; # Power consumption per kW of refrigeration\n",
      "\n",
      "#Result\n",
      "print \"COP of the cycle =\",round(cop,3),\"\\nPower consumption per kW of refrigeration =\",round(pc,3),\"kW/kW\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "COP of the cycle = 0.967 \n",
        "Power consumption per kW of refrigeration = 1.034 kW/kW\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 9.8, Page No:459"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "p1=100; # Pressure of air at inlet in kPa\n",
      "T1=288; # Temperature of air at inlet in kelvin\n",
      "rp=12; # Pressure ratio of the compressor\n",
      "T4=223; # Temperature at state 4\n",
      "k=1.4; # Index of reversible adiabatic process\n",
      "Cvo=0.7165; # Specific heat at constant volume in kJ/kg K\n",
      "Cpo=1.0035; # Specific heat at constant pressure in kJ/kg K\n",
      "R=0.287; # characteristic gas constant of air in kJ/kg K\n",
      "T3=T1; # From figure\n",
      "\n",
      "#Calculation\n",
      "# process 1-2\n",
      "p2=12*p1; # Pressure at state 2\n",
      "T2=T1*(p2/p1)**((k-1)/k); # Temperature at state 2\n",
      "wc=Cpo*(T2-T1); # Compressor work\n",
      "# process 2-3\n",
      "qH=Cpo*(T2-T3); # Heat added\n",
      "# process 3-4 cooling in regenerative heat exchanger\n",
      "qregen=Cpo*(T3-T4); # cooling in regenerative heat exchanger\n",
      "# process 4-5 Expander\n",
      "T5=T4*(1/rp)**((k-1)/k); # Temperature at state 5\n",
      "wE=Cpo*(T4-T5); # Expander work\n",
      "# process 5-6 Refrigerating coil\n",
      "T6=T4; # From figure 9.32\n",
      "qL=Cpo*(T6-T5); # Heat rejected\n",
      "# process 6-1 Heating in regenerative heat exchanger\n",
      "qregen=Cpo*(T1-T6); # Heat supplied\n",
      "wnet=qH-qL; # net work\n",
      "cop=qL/wnet; # Cop of plant\n",
      "\n",
      "#Result\n",
      "print \"COP of the modified cycle =\",round(cop,3)\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "COP of the modified cycle = 0.615\n"
       ]
      }
     ],
     "prompt_number": 8
    }
   ],
   "metadata": {}
  }
 ]
}