{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# CHAPTER 21 - Gas turbines and jet propulsion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.1 PAGE 848"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Power developed = 250.22 kW/kg of air\n",
      "Thermal efficiency = 17.96 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Initialisation of Variables\n",
    "p1=1#.........#Pressure of air while entering the turbine in bar\n",
    "t1=293#........#Temperature of air entering the turbine in K\n",
    "p2=4#.........#Pressure of air after compression in bar\n",
    "etac=0.8#....#Efficiency of compressor\n",
    "etat=0.85#.....#Efficiency of turbine\n",
    "afr=90#........#Air fuel ratio\n",
    "ma=3#...........#Mass of air in kg/s\n",
    "ga=1.4#........#Ratio of specific heats\n",
    "cp=1#.............#Specific heat at constant pressure in kJ/kgK\n",
    "C=41800#.............#Calorific value of fuel in kJ/kg\n",
    "#Calculations\n",
    "t2=t1*((p2/p1)**((ga-1)/ga))#...............#Ideal temperature of air after compression in K\n",
    "t21=((t2-t1)/etac)+t1#..............#Actual temperature of air after compression in K\n",
    "t3=round((C/((afr+1)*cp))+t21)#..............#Temperature before expansion in turbine in K\n",
    "p4=p1#\n",
    "p3=p2#\n",
    "t4=t3*((p4/p3)**((ga-1)/ga))#............#Ideal temperature after expansion in turbine in K\n",
    "t41=t3-(etat*(t3-t4))#.................#Actual temperature after expansion in turbine in K\n",
    "wt=((afr+1)/afr)*cp*(t3-t41)#........#Work done by turbine  in kJ/kg of air\n",
    "wc=round(1*cp*(t21-t1))#.................#Work done by compression in kJ/kg of air\n",
    "wnet=wt-wc#..........#Net work done in kJ/kg\n",
    "P=wnet*ma#.................#Power developed in kW/kg of air\n",
    "print \"Power developed = %0.2f kW/kg of air\"%P\n",
    "qs=(1/afr)*C#................#Heat supplied in kJ/kg of air\n",
    "etath=wnet/qs#................#Thermal efficiency\n",
    "print \"Thermal efficiency = %0.2f %%\"%(etath*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.2 PAGE 848"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Power developed = 770.31 kW/kg of air\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Initialisation of Variables\n",
    "t1=288#........#Temperature of air entering the turbine in K\n",
    "t3=883#..............#Temperature before expansion in turbine in K\n",
    "etac=0.8#....#Efficiency of compressor\n",
    "etat=0.82#.....#Efficiency of turbine\n",
    "rp=6#...........#Pressure ratio\n",
    "ma=16#...........#Mass of air in kg/s\n",
    "gac=1.4#........#Ratio of specific heats for compression process\n",
    "gae=1.333#............#Ratio of specific heats for expansion process\n",
    "cpc=1.005#.............#Specific heat at constant pressure in kJ/kgK during compression process\n",
    "cpe=1.11#.............#Specific heat at constant pressure in kJ/kgK during expansion process\n",
    "C=41800#.............#Calorific value of fuel in kJ/kg\n",
    "#Calculations\n",
    "t2=t1*((rp)**((gac-1)/gac))#...............#Ideal temperature of air after compression in K\n",
    "t21=((t2-t1)/etac)+t1#..............#Actual temperature of air after compression in K\n",
    "t4=t3/((rp)**((gae-1)/gae))#............#Ideal temperature after expansion in turbine in K\n",
    "t41=t3-(etat*(t3-t4))#.................#Actual temperature after expansion in turbine in K\n",
    "wt=cpe*(t3-t41)#........#Work done by turbine  in kJ/kg of air\n",
    "wc=(1*cpc*(t21-t1))#.................#Work done by compression in kJ/kg of air\n",
    "wnet=wt-wc#..........#Net work done in kJ/kg\n",
    "P=wnet*ma#.................#Power developed in kW/kg of air\n",
    "print \"Power developed = %0.2f kW/kg of air\"%P"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.3 PAGE 849"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Thermal efficiency = 32.65 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Initialisation of Variables\n",
    "p1=1#.........#Pressure of air while entering the turbine in bar\n",
    "t1=300#........#Temperature of air entering the turbine in K\n",
    "p2=6.2#.........#Pressure of air after compression in bar\n",
    "etac=0.88#....#Efficiency of compressor\n",
    "etat=0.9#.....#Efficiency of turbine\n",
    "far=0.017#........#Fuel air ratio\n",
    "ga=1.4#........#Ratio of specific heats for compression\n",
    "gae=1.333#........#Ratio of specific heats for expansion\n",
    "cp=1.147#.............#Specific heat at constant pressure in kJ/kgK during expansion\n",
    "cpc=1.005#.............#Specific heat at constant pressure in kJ/kgK during compression\n",
    "C=44186#.............#Calorific value of fuel in kJ/kg\n",
    "#Calculations\n",
    "t2=t1*((p2/p1)**((ga-1)/ga))#...............#Ideal temperature of air after compression in K\n",
    "t21=((t2-t1)/etac)+t1#..............#Actual temperature of air after compression in K\n",
    "t3=(((C*far)/((far+1)*cpc))+t21)#..............#Temperature before expansion in turbine in K\n",
    "p4=p1#\n",
    "p3=p2#\n",
    "t4=t3*((p4/p3)**((gae-1)/gae))#............#Ideal temperature after expansion in turbine in K\n",
    "t41=t3-(etat*(t3-t4))#.................#Actual temperature after expansion in turbine in K\n",
    "wt=(cp*(t3-t41))#........#Work done by turbine  in kJ/kg of air\n",
    "wc=round(1*cpc*(t21-t1))#.................#Work done by compression in kJ/kg of air\n",
    "wnet=wt-wc#..........#Net work done in kJ/kg\n",
    "qs=(far)*C#................#Heat supplied in kJ/kg of air\n",
    "etath=wnet/qs#................#Thermal efficiency\n",
    "print \"Thermal efficiency = %0.2f %%\"%(etath*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.4 PAGE 850"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Air fuel ratio is 56:1\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Initialisation of Variables\n",
    "t1=300#........#Temperature of air entering the turbine in K\n",
    "t3=1148#..............#Temperature before expansion in turbine in K\n",
    "etac=0.8#....#Efficiency of compressor\n",
    "etat=0.852#.....#Efficiency of turbine\n",
    "rp=4#...........#Pressure ratio\n",
    "p1=1#...............#Pressure of air before entering compressor\n",
    "ga=1.4#........#Ratio of specific heats\n",
    "cp=1.0#.............#Specific heat at constant pressure in kJ/kgK \n",
    "C=42000#.............#Calorific value of fuel in kJ/kg\n",
    "perlcc=10#............#Percent loss of calorific value of fuel in combustion chamber\n",
    "#Calculations\n",
    "p2=p1*rp#.................#Pressure of air after compression in  bar\n",
    "etacc=(100-perlcc)/100#.......#Efficiency of combustion chamber\n",
    "t2=t1*((rp)**((ga-1)/ga))#...............#Ideal temperature of air after compression in K\n",
    "t21=((t2-t1)/etac)+t1#..............#Actual temperature of air after compression in K\n",
    "afr=((C*etacc)/(cp*(t3-t21)))-1#........#Air fuel ratio\n",
    "print \"Air fuel ratio is %d:1\"%round(afr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.5 PAGE 851"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Thermal efficiency = 15.92 %\n",
      "The work ratio is 0.259290\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Initialisation of Variables\n",
    "t1=300#........#Temperature of air entering the turbine in K\n",
    "t3=883#..............#Temperature before expansion in turbine in K\n",
    "etac=0.8#....#Efficiency of compressor\n",
    "etat=0.852#.....#Efficiency of turbine\n",
    "rp=4#...........#Pressure ratio\n",
    "p1=1#...............#Pressure of air before entering compressor\n",
    "ga=1.4#........#Ratio of specific heats\n",
    "cp=1.11#.............#Specific heat at constant pressure in kJ/kgK \n",
    "C=42000#.............#Calorific value of fuel in kJ/kg\n",
    "perlcc=10#............#Percent loss of calorific value of fuel in combustion chamber\n",
    "#Calculations\n",
    "p2=p1*rp#.................#Pressure of air after compression in  bar\n",
    "etacc=(100-perlcc)/100#.......#Efficiency of combustion chamber\n",
    "t2=t1*((rp)**((ga-1)/ga))#...............#Ideal temperature of air after compression in K\n",
    "t21=((t2-t1)/etac)+t1#..............#Actual temperature of air after compression in K\n",
    "qs=cp*(t3-t21)#...................#Heat supplied in kJ/kg\n",
    "t4=t3/((rp)**((ga-1)/ga))#............#Ideal temperature after expansion in turbine in K\n",
    "t41=t3-(etat*(t3-t4))#.................#Actual temperature after expansion in turbine in K\n",
    "wt=cp*(t3-t41)#........#Work done by turbine  in kJ/kg of air\n",
    "wc=(1*cp*(t21-t1))#.................#Work done by compression in kJ/kg of air\n",
    "wnet=wt-wc#..........#Net work done in kJ/kg\n",
    "etath=wnet/qs#................#Thermal efficiency\n",
    "print \"Thermal efficiency = %0.2f %%\"%(etath*100)\n",
    "wrr=wnet/wt#...................#Work ratio\n",
    "print \"The work ratio is %f\"%wrr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.6 PAGE 851"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Quantity of air in circulation = 13.49 kg\n",
      "Actual heat supplied per kg of air circulation = 552.66 kJ\n",
      "Thermal efficiency = 14.28 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Initialisation of Variables\n",
    "p1=1#.........#Pressure of air while entering the turbine in bar\n",
    "t1=293#........#Temperature of air entering the turbine in K\n",
    "p2=5#.........#Pressure of air after compression in bar\n",
    "plcc=0.1#.....#Pressure loss in combustion chamber in bar\n",
    "t3=953#............#Temperature before expansion in turbine in K\n",
    "etac=0.85#....#Efficiency of compressor\n",
    "etat=0.8#.....#Efficiency of turbine\n",
    "etacc=0.85#......#Efficiency of combustion chamber\n",
    "ga=1.4#........#Ratio of specific heats\n",
    "cp=1.024#.............#Specific heat at constant pressure in kJ/kgK \n",
    "P=1065#.............#Power developed by the plant in kW\n",
    "\n",
    "#Calculations\n",
    "p3=p2-plcc#........................#Pressure before expansion in turbine in bar\n",
    "p4=p1#\n",
    "t2=t1*((p2/p1)**((ga-1)/ga))#...............#Ideal temperature of air after compression in K\n",
    "t21=((t2-t1)/etac)+t1#..............#Actual temperature of air after compression in K\n",
    "t4=t3*((p4/p3)**((ga-1)/ga))#............#Ideal temperature after expansion in turbine in K\n",
    "t41=t3-(etat*(t3-t4))#.................#Actual temperature after expansion in turbine in K\n",
    "wt=(cp*(t3-t41))#........#Work done by turbine  in kJ/kg of air\n",
    "wc=round(1*cp*(t21-t1))#.................#Work done by compression in kJ/kg of air\n",
    "wnet=wt-wc#..........#Net work done in kJ/kg\n",
    "ma=P/wnet#.............#Quantity of air in circulation in kg\n",
    "print \"Quantity of air in circulation = %0.2f kg\"%(ma)\n",
    "qs=cp*(t3-t21)/etac#..................#Actual heat supplied per kg of air circulation in kJ\n",
    "print \"Actual heat supplied per kg of air circulation = %0.2f kJ\"%qs\n",
    "etath=wnet/qs#.............#Thermal efficiency\n",
    "print \"Thermal efficiency = %0.2f %%\"%(etath*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.7 PAGE 852"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Pressure ratio of low pressure turbine : 2.3042\n",
      "Temperature of the exhaust from the unit = 672.95 K\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Initialisation of Variables\n",
    "ma=20#..............#Air flow rate in kg/s\n",
    "t1=300#........#Temperature of air entering the turbine in K\n",
    "t3=1000#............#Temperature before expansion in turbine in K\n",
    "rp=4#...............#Pressure ratio\n",
    "cp=1#.............#Specific heat at constant pressure in kJ/kgK \n",
    "ga=1.4#........#Ratio of specific heats\n",
    "#Calculations\n",
    "t2=t1*((rp)**((ga-1)/ga))#...............#Temperature of air after compression in K\n",
    "t4=t3-t2+t1#............#Temperature after expansion in turbine in K\n",
    "prlp=rp/((t3/t4)**(ga/(ga-1)))#.............#Pressure ratio of low pressure turbine\n",
    "print \"Pressure ratio of low pressure turbine : %0.4f\"%prlp\n",
    "t5=t4/((prlp)**((ga-1)/ga))#............#Temperature of the exhaust from the unit in K\n",
    "print \"Temperature of the exhaust from the unit = %0.2f K\"%t5"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.8 PAGE 853"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cycle efficiency = 31.04 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Initialisation of Variables\n",
    "p1=1#.........#Pressure of air while entering the turbine in bar\n",
    "t1=300#........#Temperature of air entering the turbine in K\n",
    "t21=490#........#Actual temperature of air after compression in K\n",
    "t3=1000#............#Temperature before expansion in turbine in K\n",
    "rp=5#.............#Pressure ratio\n",
    "etac=0.8#....#Efficiency of compressor\n",
    "etat=0.8#.....#Efficiency of turbine\n",
    "ga=1.4#........#Ratio of specific heats\n",
    "cp=1.005#.............#Specific heat at constant pressure in kJ/kgK \n",
    "#Calculations\n",
    "t4=t3/((rp)**((ga-1)/ga))#............#Ideal temperature after expansion in turbine in K\n",
    "t41=t3-(etat*(t3-t4))#.................#Actual temperature after expansion in turbine in K\n",
    "t5=((t41-t21)*etac)+t21#...........#Temperature of the exhaust from the unit in K\n",
    "wc=cp*(t21-t1)#.............#Work consumed by compressor in kJ/kg\n",
    "wt=cp*(t3-t41)#........#Work done by turbine in kJ/kg\n",
    "qs=cp*(t3-t5)#..........#Heat supplied in kJ/kg\n",
    "etac=(wt-wc)/qs#.........#Cycle efficiency\n",
    "print \"Cycle efficiency = %0.2f %%\"%(etac*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.9 PAGE 853"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Thermal efficiency of power turbine = 21.73 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Initialisation of Variables\n",
    "p1=1#.........#Pressure of air while entering the turbine in bar\n",
    "t1=288#........#Temperature of air entering the turbine in K\n",
    "p2=8#.........#Pressure of air after compression in bar\n",
    "t3=1173#.............#Temperature before expansion in turbine in K\n",
    "etac=0.76#....#Efficiency of compressor\n",
    "etat=0.86#.....#Efficiency of turbine\n",
    "ma=23#.........#Quantity of air circulation in kg/s\n",
    "ga=1.4#........#Ratio of specific heats for compression\n",
    "gag=1.34#........#Ratio of specific heats for expansion\n",
    "cp=1.005#.............#Specific heat at constant pressure in kJ/kgK \n",
    "cpg=1.128#.............#Specific heat at constant pressure in kJ/kgK\n",
    "C=4200#.............#Calorific value of fuel in kJ/kg\n",
    "etamech=0.95#........#Mechanical efficiency\n",
    "etagen=0.96#.........#Generator efficiency\n",
    "#Calculations\n",
    "t2=t1*((p2/p1)**((ga-1)/ga))#...............#Ideal temperature of air after compression in K\n",
    "t21=((t2-t1)/etac)+t1#..............#Actual temperature of air after compression in K\n",
    "p4=p1#\n",
    "p3=p2#.............#Isobaric processes\n",
    "t4=t3*((p4/p3)**((gag-1)/gag))#............#Ideal temperature after expansion in turbine in K\n",
    "t41=t3-(etat*(t3-t4))#.................#Actual temperature after expansion in turbine in K\n",
    "wc=cp*(t21-t1)#................#Work dony by compressor\n",
    "m1=(wc)/(cpg*(t3-t41))#.............#Flow through compressor turbine in kg\n",
    "m2=1-m1#..............#Flow through power turbine in kg\n",
    "wpt=m2*(cpg*(t3-t41))#.........#turbine work in kJ/kg\n",
    "P=ma*wpt*etamech*etagen#.........#Power output in kW\n",
    "qi=cpg*t3-cp*t21#.............#Input heat in kJ/kg of air\n",
    "etath=wpt/qi#.............#Thermal efficiency of power turbine\n",
    "print \"Thermal efficiency of power turbine = %0.2f %%\"%(etath*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.10 PAGE 854"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Temperature of gasses entering the turbine = 654.75 K\n",
      "Pressure of gasses entering the power turbine = 1.65 bar\n",
      "Net power output = 73.95 kW\n",
      "Work ratio : 0.2198\n",
      "Thermal efficiency of the unit : 19.26 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Initialisation of Variables\n",
    "t1=288#........#Temperature of air entering the turbine in K\n",
    "t3=883#..............#Temperature before expansion in turbine in K\n",
    "etac=0.82#....#Efficiency of compressor\n",
    "etathp=0.85#.....#Efficiency of high pressure turbine\n",
    "etatlp=0.85#.....#Efficiency of low pressure turbine\n",
    "rp=7#...........#Pressure ratio\n",
    "p1=1.01#...............#Pressure of air before entering compressor\n",
    "ga=1.4#........#Ratio of specific heats for compression\n",
    "gag=1.333#........#Ratio of specific heats for expansion\n",
    "cp=1.005#.............#Specific heat at constant pressure in kJ/kgK \n",
    "cpg=1.15#.............#Specific heat at constant pressure in kJ/kgK in generator\n",
    "#Calculations\n",
    "p2=p1*rp#\n",
    "t2=t1*((p2/p1)**((ga-1)/ga))#...............#Ideal temperature of air after compression in K\n",
    "t21=((t2-t1)/etac)+t1#..............#Actual temperature of air after compression in K\n",
    "wc=cp*(t21-t1)#............#Compressor work in kJ/kg\n",
    "t41=t3-(wc/cpg)#..........#Temperature of gasses entering the turbine in K\n",
    "print \"Temperature of gasses entering the turbine = %0.2f K\"%t41\n",
    "t4=round(t3-((t3-t41)/etathp))#.........#Ideal temperature of gases entering the turbine in K\n",
    "p3=p2#.........#Isobaric processes\n",
    "p4=p3/((t3/t4)**(1/((gag-1)/gag)))#....#Pressure of gasses entering the power turbine in bar\n",
    "print \"Pressure of gasses entering the power turbine = %0.2f bar\"%p4\n",
    "t5=t41*((((t3/t4)**(1/((gag-1)/gag)))/(rp))**((gag-1)/gag))#\n",
    "t51=t41-(etatlp*(t41-t5))#\n",
    "wlp=cpg*(t41-t51)#............#Net power output in kW\n",
    "print \"Net power output = %0.2f kW\"%wlp\n",
    "wr=wlp/(wlp+wc)#............#Work ratio\n",
    "print \"Work ratio : %0.4f\"%wr\n",
    "qs=cpg*(t3-t21)#...........#Heat supplied in kJ/kg\n",
    "etath=wlp/qs#..........#Thermal efficiency\n",
    "print \"Thermal efficiency of the unit : %0.2f %%\"%(etath*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.11 PAGE 855"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Net work output = 173.98 kW\n",
      "Power plant efficiency = 25.00 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt\n",
    "# Initialisation of Variables\n",
    "rp=5.6#................#Pressure ratio\n",
    "t1=303#.............#Temperature of intake air in K\n",
    "p1=1#............#Pressure of intake air in bar\n",
    "t5=973#............#Highest temperature of the cycle in K\n",
    "etac=0.85#..........#Effeciency of compressor\n",
    "etat=0.9#..........#Efficiency of turbine\n",
    "ma=1.2#..........#Rate of air flow in kg/s\n",
    "cp=1.02#...........#Specific heat at constant volume in kJ/kgK\n",
    "ga=1.41#.............#Ratio of specific heats\n",
    "#Calculations\n",
    "t2=t1*((sqrt(rp))**((ga-1)/ga))#\n",
    "t21=((t2-t1)/etac)+t1#\n",
    "wc=2*ma*cp*(t21-t1)#............#Work input for the two stage compressor in kJ/s\n",
    "t6=t5/(rp**((ga-1)/ga))#\n",
    "t61=t5-etat*(t5-t6)#\n",
    "wt=ma*cp*(t5-t61)#...............#Work output from turbine in kJ/s\n",
    "wnet=wt-wc#....................#Net work available in kJ/s\n",
    "print \"Net work output = %0.2f kW\"%wnet\n",
    "qs=ma*cp*(t5-t21)#.................#Heat supplied in kJ/s\n",
    "etath=wnet/qs#\n",
    "print \"Power plant efficiency = %0.2f %%\"%(etath*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.13 PAGE 856"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cycle efficiency = 11.81 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Initialisation of Variables\n",
    "t1=288#.............#Temperature of intake air in K\n",
    "rp=4#.............#Pressure ratio\n",
    "etac=0.82#.........#Compressor efficiency\n",
    "etahe=0.78#...........#Efficiency of heat exchanger\n",
    "etat=0.7#...........#Turbine efficiency\n",
    "t3=873#............#Temperature before expansion in turbine in K\n",
    "R=0.287#............#Gas constant for air in kJ/kgK\n",
    "ga=1.4#...........#Ratio of specific heats\n",
    "#Calculations\n",
    "t2=t1*((rp)**((ga-1)/ga))#...............#Ideal temperature of air after compression in K\n",
    "t21=((t2-t1)/etac)+t1#...............#Actual temperature of air after compression in K\n",
    "t4=t3/(rp**((ga-1)/ga))#............#Ideal temperature after expansion in turbine in K\n",
    "t41=t3-etat*(t3-t4)#............#Actual temperature after expansion in turbine in K\n",
    "cp=R*(ga/(ga-1))#..............#Specific heat at constant pressure in kJ/kgK\n",
    "wc=cp*(t21-t1)#.............#Compressor work in kJ/kg\n",
    "wt=cp*(t3-t41)#....................#Turbine work in kJ/kg\n",
    "wnet=wt-wc#....................#Net work available in kJ/s\n",
    "t5=(etahe*(t41-t21))+t21#\n",
    "qs=cp*(t3-t5)#.................#Heat supplied in kJ/kg\n",
    "etac=wnet/qs#...............#Cycle efficiency\n",
    "print \"Cycle efficiency = %0.2f %%\"%(etac*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.14 PAGE 857"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Thermal efficiency in simple cycle = 23.25 %\n",
      "Thermal efficiency in heat exchanger cycle = 20.94 %\n",
      "Increase in thermal efficiency = -2.31 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Initialisation of Variables\n",
    "etahe=0.72#.................#Efficiency of heat exchanger\n",
    "p1=1.01#.........#Pressure of air while entering the turbine in bar\n",
    "t1=293#........#Temperature of air entering the turbine in K\n",
    "p2=4.04#.........#Pressure of air after compression in bar\n",
    "etat=0.85#..........#Turbine efficiency\n",
    "pdhe=0.05#............#Pressure drop on each side of heat exchanger in bar\n",
    "pdcc=0.14#...........#Pressure drop in combustion chamber in bar\n",
    "etac=0.8#...........#Compressor efficiency\n",
    "ga=1.4#.............#Ratio of specific heats\n",
    "C=41800#.............#Calorific value of fuel in kJ/kg\n",
    "cp=1.024#...........#Specific heat at constant pressure in kJ/kgK\n",
    "afrc=90#..............#Air fuel ratio for simple cycle\n",
    "#Calculations\n",
    "t2=(t1*((p2/p1)**((ga-1)/ga)))#...............#Ideal temperature of air after compression in K\n",
    "t21=round(((t2-t1)/etac)+t1)#...............#Actual temperature of air after compression in K\n",
    "t3=((1*C)/(cp*(afrc+1)))+t21#............#Temperature before expansion in turbine in K\n",
    "p4=p1#\n",
    "p3=p2-pdcc#\n",
    "t4=round(t3*((p4/p3)**((ga-1)/ga)))#............#Ideal temperature after expansion in turbine in K\n",
    "t41=t3-(etat*(t3-t4))#.................#Actual temperature after expansion in turbine in K\n",
    "etath=(t3-t41-t21+t1)/(t3-t21)#...........#Thermal efficiency in simple cycle\n",
    "print \"Thermal efficiency in simple cycle = %0.2f %%\"%(etath*100)\n",
    "p3he=p2-pdhe-pdcc#..........#Pressure before expansion in turbine in bar in heat exchanger cycle\n",
    "p4he=p1+pdhe#................#Pressure after expansion in turbine in bar in heat exchanger cycle\n",
    "t4he=t3*((p4he/p3he)**((ga-1)/ga))#............#Ideal temperature after expansion in turbine in K in heat exchanger cycle\n",
    "t41he=round(t3-(etat*(t3-t4he)))#.................#Actual temperature after expansion in turbine in K in heat exchanger cycle\n",
    "t5=(etahe*(t41he-t21))+t21#\n",
    "etathhe=(t3-t41he-t21+t1)/(t3-t5)#.............#Thermal efficiency for heat exchanger cycle\n",
    "print \"Thermal efficiency in heat exchanger cycle = %0.2f %%\"%(etathhe*100)\n",
    "inc=etathhe-etath#\n",
    "print \"Increase in thermal efficiency = %0.2f %%\"%(inc*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.15 PAGE 858"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Thermal efficiency = 23.44 %\n",
      "The workk ratio is 0.283\n",
      "Mass flow = 39.12 kg/s\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt\n",
    "# Initialisation of Variables\n",
    "t1=293#........#Temperature of air entering the turbine in K\n",
    "rp=9#............#Overall pressure ratio\n",
    "etac=0.8#........#Efficiency of compressor\n",
    "t6=898#..........#Reheat remperature\n",
    "t8=t6#\n",
    "etat=0.85#.......#Efficiency of turbine\n",
    "etamech=0.95#..........#Mechanical efficiency\n",
    "etahe=0.8#...............#Heat exchanger thermal efficiency\n",
    "cpg=1.15#.............#Specific heat capacity for gases in heat exchanger in kJ/kgK\n",
    "cpa=1.005#............#Specific heat capacity for normal air in kJ/kgK\n",
    "gag=1.333#.............#Ratio of specific heats for gases in heat exchanger \n",
    "ga=1.4#...............#Ratio of specific heats for normal gases\n",
    "P=4500#.................#Power output of turbine in kW\n",
    "#Calculations\n",
    "t2=t1*((sqrt(rp))**((ga-1)/ga))#\n",
    "t21=((t2-t1)/etac)+t1#\n",
    "wc=cpa*(t21-t1)#............#Work input per compressor stage\n",
    "whp=(2*wc)/etamech#.........#Work output of HP turbine in kJ/kg\n",
    "t71=t6-(whp/cpg)#\n",
    "t7=round(t6-((t6-t71)/etat))#\n",
    "k=(rp/((t6/t7)**((gag)/(gag-1))))**((gag-1)/gag)#\n",
    "k1=((round((k/2)*100))*2)/100#..............#Rounding off upto 2 decimals\n",
    "t9=t8/(k1)#\n",
    "t91=t8-((t8-t9)*etat)#\n",
    "wout=cpg*(t8-t91)*etamech#..............#Net work output in kJ/kg\n",
    "t5=etahe*(t91-t21)+t21#\n",
    "qs=cpg*(t6-t5)+cpg*(t8-t71)#...............#Heat supplied\n",
    "etath=wout/qs#.................#Thermal efficiency\n",
    "print \"Thermal efficiency = %0.2f %%\"%(etath*100)\n",
    "wgross=whp+(wout/etamech)#.........#Gross work output in kJ/kg\n",
    "wr=wout/wgross#................#Work ratio\n",
    "print \"The workk ratio is %0.3f\"%wr\n",
    "m1=P/wout#...............#Mass flow in kg/s\n",
    "print \"Mass flow = %0.2f kg/s\"%m1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.16 PAGE 859"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Thermal efficiency of the turbine without regenerator = 27.01 %\n",
      "Thermal efficiency of the turbine with regenerator = 38.96 %\n",
      "Mass of fluid circulated = 2.40 kg/s\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt\n",
    "# Initialisation of Variables\n",
    "#Conditions of the closed gas turbine\n",
    "t1=293#.............#Temperature at the inlet of first stage compressor in K\n",
    "t5=1023#.................#Maximum temperature in K\n",
    "p1=1.5#................#Inlet pressure in bar\n",
    "p2=6#.................#Pressure in bar\n",
    "etac=0.82#..............#Compressor efficiency\n",
    "etat=0.82#..............#Turbine efficiency\n",
    "etare=0.70#................#Regenerator efficiency\n",
    "P=350#....................#Power developed by the plant in kW\n",
    "ga=1.4#................#Ratio of specific heats\n",
    "cp=1.005#..............#Specific heat at constant pressure in kJ/kgK\n",
    "t3=t1#\n",
    "#Calculations\n",
    "t2=t1*((sqrt(p2/p1))**((ga-1)/ga))#\n",
    "t21=((t2-t1)/etac)+t1#t41=t21#\n",
    "t6=t5/((p2/sqrt(p1*p2))**((ga-1)/ga))#\n",
    "t61=t5-(etat*(t5-t6))#\n",
    "t81=t61#\n",
    "t7=t5#\n",
    "ta=(etare*(t81-t41))+t41#.......#Temperature of air coming out of regenerator in K\n",
    "wnet=2*cp*(t5-t61-t21+t1)#........#Net work done in kJ/kg of air\n",
    "qs=cp*(t5-t41+t7-t61)#...........#Heat supplied without regenerator in kJ/kg of air\n",
    "qsr=cp*(t5-ta+t7-t61)#............#Heat supplied with regenerator in kJ/kg of air\n",
    "etath=wnet/qs#.............#Thermal efficiency (without regenerator)\n",
    "etathr=wnet/qsr#.........#Thermal efficiency (with regenerator)\n",
    "mfl=P/wnet#..........#mass of fluid circulated in kg/s\n",
    "print \"Thermal efficiency of the turbine without regenerator = %0.2f %%\"%(etath*100)\n",
    "print \"Thermal efficiency of the turbine with regenerator = %0.2f %%\"%(etathr*100)\n",
    "print \"Mass of fluid circulated = %0.2f kg/s\"%mfl"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.17 PAGE 860"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Net power output = 2042.40 kW \n",
      "Thermal efficiency = 30.95 %\n",
      "Specific fuel consumption = 0.28 kg/kWh\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Initialisation of Variables\n",
    "t1=293#............#Temperature of inlet air into low pressure compressor in K\n",
    "p1=1.05#.........#Pressure of inlet air into low pressure compressor in bar\n",
    "t3=300#...........#Temperature of air after passing it through intercooler in K\n",
    "t6=1023#..........#temperature of air in combustion chamber in K\n",
    "rp=2#...........#Pressure ratio of each compressor \n",
    "etac=0.82#........#Compressor efficiency\n",
    "etat=0.82#..........#Turbine efficiency\n",
    "etaht=0.72#............#Heat exchanger efficiency\n",
    "ma=16#...........#Air flow in kg/s\n",
    "ga=1.4#...........#Ratio of specific heats for air\n",
    "gag=1.33#..........#Ratio of specific heats for gases\n",
    "cpa=1.0#...........#Specific heat at constant pressure in kJ/kgK for air\n",
    "cpg=1.15#.........#Specific heat at constant pressure in kJ/kgK for gases\n",
    "C=42000#.........#Calorific value of fuel in kJ/kg\n",
    "#Calculations\n",
    "t2=round(t1*(rp**((ga-1)/ga)))#\n",
    "t21=round(((t2-t1)/etac)+t1)#\n",
    "t4=t3*(rp**((ga-1)/ga))#\n",
    "t41=round(((t4-t3)/etac)+t3)#\n",
    "t71=round(((cpg*t6)-cpa*(t21-t1+t41-t3))/cpg)#\n",
    "t7=t6-((t6-t71)/etat)#\n",
    "p6=p1*rp*rp#\n",
    "p7=p6/((t6/t7)**((gag)/(gag-1)))#\n",
    "t8=round(t71/((p7/p1)**((gag-1)/gag)))#\n",
    "t81=round(t71-(etat*(t71-t8)))#\n",
    "P=cpg*(t71-t81)#...........#Net power output in kJ/kg\n",
    "print \"Net power output = %0.2f kW \"%(P*ma)\n",
    "t5=etaht*(t81-t41)+t41#\n",
    "qs=ma*cpg*(t6-t5)#......#Heat supplied in combustion chamber in kJ/s\n",
    "etath=P*ma/qs#.........#Thermal efficiency\n",
    "print \"Thermal efficiency = %0.2f %%\"%(etath*100)\n",
    "afr=C/(cpg*(t6-t5))#......#Air fuel ratio\n",
    "mf=ma*3600/afr#..............#Fuel supplied per hour in kg\n",
    "sfc=mf/(P*ma)#...........#Specific fuel consumption in kg/kWh\n",
    "print \"Specific fuel consumption = %0.2f kg/kWh\"%sfc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.18 PAGE 861"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Overall efficiency = 30.89 %\n",
      "Work ratio  = 0.363  Mass flow rate = 34.32 kg/s\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Initialisation of Variables\n",
    "t1=293#............#Temperature of inlet air into low pressure compressor in K\n",
    "p1=1.1#.........#Pressure of inlet air into low pressure compressor in bar\n",
    "p2=3.3#..........#Pressure of air in the low pressure compressor in bar\n",
    "t3=300#.............#Intercooled temperature in K\n",
    "pli=0.15#..........#Loss in pressure due to intercooling in bar\n",
    "p3=p2-pli#...........#Pressure after intercooling in bar\n",
    "p4=9.45#............#Pressure of air after high pressure compressor in bar\n",
    "p6=p4#\n",
    "t6=973#.........#Temperature of gases supplied to high pressure turbine in K\n",
    "t8=943#.........#Reheat temperature in K\n",
    "plr=0.12#...........#Loss of pressure after reheating in bar\n",
    "p7=3.62#............#Pressure of gases at the end of expansion in high pressure turbine in bar\n",
    "p8=p7-plr#...........#Pressure of outlet gases in bar\n",
    "ga=1.4#...........#Ratio of specific heats for air\n",
    "gag=1.33#..........#Ratio of specific heats for gases\n",
    "cpa=1.005#...........#Specific heat at constant pressure in kJ/kgK for air\n",
    "cpg=1.15#.........#Specific heat at constant pressure in kJ/kgK for gases\n",
    "etac=0.82#........#Compressor efficiency\n",
    "etat=0.85#..........#Turbine efficiency\n",
    "etaht=0.65#.........#Efficiency of heat exchanger\n",
    "P=6000#..................#Power generated in kW\n",
    "p9=p1#\n",
    "#Calculations\n",
    "t2=round(t1*((p2/p1)**((ga-1)/ga)))#\n",
    "t21=round(((t2-t1)/etac)+t1)#\n",
    "t4=round(t3*((p4/p3)**((ga-1)/ga)))#\n",
    "t41=round(((t4-t3)/etac)+t3)#\n",
    "t7=round(t6/((p6/p7)**((gag-1)/gag)))#\n",
    "t71=round(t6-(etat*(t6-t7)))#\n",
    "t9=round(t8/((p8/p9)**((gag-1)/gag)))#\n",
    "t91=round(t8-(etat*(t8-t9)))#\n",
    "t5=round(etaht*(t91-t41)+t41)#\n",
    "wthp=cpg*(t6-t71)#.......#Work done by high pressure turbine in kJ/kg of gas\n",
    "wtlp=cpg*(t8-t9)#.......#Work done by low pressure turbine in kJ/kg of gas\n",
    "wchp=cpg*(t21-t1)#.......#Work done by high pressure compressor in kJ/kg of gas\n",
    "wclp=cpg*(t41-t3)#.......#Work done by low pressure compressor in kJ/kg of gas\n",
    "qs=cpg*(t6-t5+t8-t71)#.........#Heat supplied in kJ/kg of gas\n",
    "etath=(wthp+wtlp-wchp-wclp)/qs#..#Overall efficiency\n",
    "print \"Overall efficiency = %0.2f %%\"%(etath*100)\n",
    "wr=(wthp+wtlp-wchp-wclp)/(wthp+wtlp)#......#Work ratio\n",
    "print \"Work ratio  = %0.3f \"%wr,\n",
    "m=P/(wthp+wtlp-wchp-wclp)#.....#Mass flow rate\n",
    "print \"Mass flow rate = %0.2f kg/s\"%m"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.19 PAGE 862"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Exit velocity of jet = 651.10 m/s\n",
      "Rate of fuel consumption = 0.86 kg/s\n",
      "Thrust specific fuel consumption = 0.00 kg/N\n",
      "Thermal efficiency = 31.41 %\n",
      "Propulsive power = 10437.94 kW\n",
      "Propulsive efficiency = 59.81 %\n",
      "Overall efficiency = 18.79 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt\n",
    "# Initialisation of Variables\n",
    "ma=60.2#...........#Rate of air consumption in kg/s\n",
    "delh=230#.......#Enthalpy change for nozzle in kJ/kg\n",
    "z=0.96#..........#Velocity co efficient \n",
    "afr=70#............#Air fuel ratio\n",
    "etaco=0.92#...............#Combustion eficiency\n",
    "CV=42000#..............#Calorific value of fuel in kJ/kg\n",
    "v=1000#............#Velocity of aircraft in km/h\n",
    "Ca=v*(5/18)#............#Aircraft velocity in m/s\n",
    "#Calculations\n",
    "Cj=z*sqrt(2*delh*v)#...........#Exit velocity of jet\n",
    "print \"Exit velocity of jet = %0.2f m/s\"%Cj\n",
    "mf=ma/afr#.........#Rate of fuel consumption\n",
    "print \"Rate of fuel consumption = %0.2f kg/s\"%mf\n",
    "tp=ma*(Cj-Ca)#......#Thrust produced in N\n",
    "tsfc=mf/tp#.........#Thrust specific fuel consumption in kg/N\n",
    "print \"Thrust specific fuel consumption = %0.2f kg/N\"%tsfc\n",
    "etath=((Cj**2)-(Ca**2))/(2*(1/afr)*CV*etaco*1000)#.........#Thermal efficiency\n",
    "print \"Thermal efficiency = %0.2f %%\"%(etath*100)\n",
    "pp=(ma/1000)*((Cj**2)-(Ca**2))/2#................#Propulsive power in kW\n",
    "print \"Propulsive power = %0.2f kW\"%pp\n",
    "etapp=(2*Ca)/(Cj+Ca)#......................#Propulsive efficiency\n",
    "print \"Propulsive efficiency = %0.2f %%\"%(etapp*100)\n",
    "etao=((Cj-Ca)*Ca)/((1/afr)*CV*etaco*1000)#............#Overall efficiency\n",
    "print \"Overall efficiency = %0.2f %%\"%(etao*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.20 PAGE 863"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Absolute velocity of jet = 363.64 m/s\n",
      "Volume of air compressed = 5920.59 kg/min\n",
      "Diameter of the jet = 463.09 mm\n",
      "Turbine output = 2464.65 kW\n",
      "\n",
      "Air fuel ratio is 53.225:1\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi,sqrt\n",
    "# Initialisation of Variables\n",
    "v=800#.............#Speed of the turbojet in km/h\n",
    "etapp=0.55#......#Propulsive efficiency\n",
    "etao=0.17#.........#Overall efficiency\n",
    "al=9500#...............#Altitude in m\n",
    "rhoa=0.17#............#Density of air at the given altitude in kg/m**3\n",
    "dr=6100#...........#Drag on the plane in N\n",
    "CV=46000#.........#Calorific value of fuel in kJ/kg\n",
    "#Calculations\n",
    "Ca=v*(1000/3600)#.........#Velocity of jet in m/s\n",
    "Cj=((2*Ca)/etapp)-Ca#........#Velocity of gases at nozzle exit relative to the aircraft in m/s\n",
    "print \"Absolute velocity of jet = %0.2f m/s\"%(Cj-Ca)\n",
    "ma=dr/(Cj-Ca)#............#Rate of air flow in kg/s\n",
    "Va=(ma/rhoa)*60#..........#Volume of air compresssed per min in kg\n",
    "print \"Volume of air compressed = %0.2f kg/min\"%Va\n",
    "d=sqrt((Va*4)/(60*pi*Cj))#..........#Diameter of the jet in m\n",
    "print \"Diameter of the jet = %0.2f mm\"%(d*1000)\n",
    "tp=dr*(Ca/1000)#...........#Thrust power in kW\n",
    "wt=tp/etapp#................#Turbine output in kW\n",
    "print \"Turbine output = %0.2f kW\"%wt\n",
    "mf=wt/(etao*CV)#...........#Rate of fuel consumption in kg/s\n",
    "afr=ma/mf#..........#Air fuel ratio\n",
    "print \"\\nAir fuel ratio is %0.3f:1\"%(afr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.21 PAGE 864"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Power required to drive the compressor = 171.46 kW\n",
      "\n",
      "\n",
      "Air fuel ratio 73.094:1\n",
      "\n",
      "Pressure of gases leaving the turbine = 1.74 bar\n",
      "Thrust per kg of air per second = 465.69 N\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi,sqrt\n",
    "# Initialisation of Variables\n",
    "t1=288#..........#Temperature of the inlet air into compressor in K\n",
    "p1=1.01#......#Pressure of the inlet air into compressor in bar\n",
    "t3=1023#.........#Maximum temperature in K\n",
    "p2=4.04#.........#Pressure of air at the end of compression in bar\n",
    "etac=0.82#.......#compressor efficiency\n",
    "etat=0.78#......#Turbine efficiency\n",
    "etan=0.88#........#Nozzle efficiency\n",
    "R=0.287#.........#Gas constant for air in kJ/kgK\n",
    "ga=1.4#............#Ratio of specific heats\n",
    "C=42000#..........#Calorific value of fuel in kJ/kg\n",
    "#Calculations\n",
    "t2=t1*((p2/p1)**((ga-1)/ga))#........#Ideal temperature at the end of compression in K\n",
    "t21=((t2-t1)/etac)+t1#...........#Actual temperature at the end of compression in K\n",
    "cp=R*(ga/(ga-1))#..............#Specific heat at constant pressure in kJ/kgK\n",
    "Pc=cp*(t21-t1)#.............#Power required to drive the compressor in kW\n",
    "print \"Power required to drive the compressor = %0.2f kW\"%Pc\n",
    "afr=((C)/(cp*(t3-t21)))-1#....#Air fuel ratio\n",
    "print \"\\n\\nAir fuel ratio %0.3f:1\\n\"%(afr)\n",
    "t41=t1+t3-t21#......#Actual temperatur of gases leaving the turbine in K\n",
    "t4=t3-((t3-t41)/etat)#......#Ideal temperature of gases leaving the turbine in K\n",
    "p3=p2#\n",
    "p4=p3*((t4/t3)**(ga/(ga-1)))#.......#Pressure of gases leaving the turbine in bar\n",
    "print \"Pressure of gases leaving the turbine = %0.2f bar\"%p4\n",
    "p5=p1#\n",
    "t5=t41/((p4/p5)**((ga-1)/ga))#\n",
    "t51=t41-(etan*(t41-t5))#\n",
    "Cj=sqrt(2*cp*(t41-t51)*1000)#..............#Jet velocity in m/s\n",
    "th=Cj*1#..................#Thrust per kg per second in N\n",
    "print \"Thrust per kg of air per second = %0.2f N\"%th"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.22 PAGE 865"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Air fuel ratio : 48.348\n",
      "Specific thrust = 822.74 N/kg\n",
      "Total thrust = 21805.03 N\n"
     ]
    }
   ],
   "source": [
    "from scipy import sqrt\n",
    "# Initialisation of Variables\n",
    "Ca=216#................#Speed of aircraft in m/s\n",
    "t1=265.8#...............#Intake air temperature in K\n",
    "p1=0.78#...............#Intake air pressure in bar\n",
    "rp=5.8#..................#Pressure ratio in compressor \n",
    "t4=1383#.................#Temperature of gases entering the gas turbine in K\n",
    "pd=0.168#...............#Pressure drop in combustion chamber in bar\n",
    "etad=0.9#..............#Diffuser efficiency\n",
    "etan=0.9#............#Nozzle efficiency\n",
    "etac=0.9#............#Compressor efficiency\n",
    "etat=0.8#.............#Turbine efficiency\n",
    "C=44150#............#Calorific value of fuel in kJ/kg\n",
    "cp=1.005#.............#Specific heat at constant pressure in kJ/kgK\n",
    "ga=1.4#...............#Ratio of specific heats\n",
    "cin=0.12#...............#Inlet cross sectio of the diffuser in m**3\n",
    "R=0.287#............#Gas constant in kJ/kgK\n",
    "#Calculations\n",
    "t2=t1+((Ca*Ca)/(2*cp*1000))#......#For ideal diffuser\n",
    "t21=t1+((Ca*Ca)/(2*cp*etad*1000))#......#For actual diffuser\n",
    "p2=p1*((t2/t1)**(ga/(ga-1)))#\n",
    "t3=t21*(rp**((ga-1)/ga))#\n",
    "t31=t21+((t3-t21)/etac)#\n",
    "afr=(C-(cp*t4))/(cp*(t4-t31))#............#Air fuel ratio\n",
    "print \"Air fuel ratio : %0.3f\"%afr\n",
    "p3=p2*rp#\n",
    "p4=p3-pd#...............#Pressure of gases entering the turbine in bar\n",
    "t51=t4-(t31-t21)#\n",
    "t5=round(t4-((t4-t51)/etat))#\n",
    "p5=p4/((t4/t5)**(ga/(ga-1)))#\n",
    "p6=p1#\n",
    "t6=t51/((p5/p6)**((ga-1)/ga))#\n",
    "t61=t51-(etac*(t51-t6))#\n",
    "Cj=44.72*sqrt(cp*(t51-t61))#........#Velocity at the exit of the nozzle in m/s\n",
    "st=(1+(1/afr))*Cj#............#Specific thrust in N/kg\n",
    "print \"Specific thrust = %0.2f N/kg\"%abs(st)\n",
    "v1=Ca*cin#...........#Volume of flowing air in m**3/s\n",
    "ma=(p1*v1*10**5)/(R*t1*1000)#.........#Mass flow of air\n",
    "tt=ma*st#..............#Total thrust in N\n",
    "print \"Total thrust = %0.2f N\"%abs(tt)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 21.23 PAGE 866"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Overall efficiency = 12.91 %\n",
      "Rate of air consumption = 9.23 kg/s\n",
      "Power developed by turbine = 1496.76 kW\n",
      "The outlet area of jet tube = 0.10 m**2\n",
      "Specific fuel consumption = 0.14 kg per kg of thrust\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt\n",
    "# Initialisation of Variables\n",
    "al=9000#..........#Altitude in m\n",
    "Ca=215#...........#Speed of aircraft in m/s\n",
    "TP=750#.............#Thrust power developed in kW\n",
    "p1=0.32#...........#Inlet pressure of air in bar\n",
    "t1=231#.............#Inlet temperature of air in K\n",
    "t3=963#.............#Temperature of gases leaving the combustion chamber in K\n",
    "rpc=5.2#............#Pressure ratio\n",
    "C=42500#..........#Calorific value of fuel in kJ/kg\n",
    "C41=195#.........#Velocity in ducts\n",
    "etac=0.86#..........#Compressor efficiency\n",
    "ga=1.4#............#Ratio of specific heats for air\n",
    "gag=1.33#............#Ratio of specific heats for gases\n",
    "etat=0.86#..........#Turbine efficiency\n",
    "etajt=0.9#..........#Jet tube efficiency\n",
    "cp=1.005#............#Specific heat at constant pressure in kJ/kgK for air\n",
    "cpg=1.087#............#Specific heat at constant pressure in kJ/kgK for gases\n",
    "R=0.29#..................#Gas constant for exhaust gases in kJ/kgK\n",
    "#Calculations\n",
    "t2=t1*(rpc**((ga-1)/ga))#\n",
    "t21=t1+((t2-t1)/etac)#\n",
    "mf=(cpg*(t3-t21))/(C-(cpg*(t3-t21)))#\n",
    "afr=1/mf#..........#Air fuel ratio\n",
    "t41=round(t3-((cp*(t21-t1))/(cpg*(1+mf))))#\n",
    "t4=t3-((t3-t41)/etat)#\n",
    "p4=rpc#\n",
    "rpt=(t3/t4)**(gag/(gag-1))#.............#Expansion pressure ratio in turbine\n",
    "rpj=p4/rpt#....................#Expansion pressure ratio in jet tube\n",
    "t5=t41/(rpj**((gag-1)/gag))#\n",
    "Cj=sqrt(etajt*2*((cpg*1000*(t41-t5))+((C41*C41)/2)))#\n",
    "etao=((((1+mf)*Cj)-Ca)*Ca)/(1000*mf*C)#......#Overall efficiency\n",
    "print \"Overall efficiency = %0.2f %%\"%(etao*100)\n",
    "ma=(TP*1000)/((((1+mf)*Cj)-Ca)*Ca)#........#Rate of air consumption in kg/s\n",
    "print \"Rate of air consumption = %0.2f kg/s\"%ma\n",
    "P=ma*(1+mf)*cpg*(t3-t41)#..............#Power developed by the turbine in kW\n",
    "print \"Power developed by turbine = %0.2f kW\"%P\n",
    "t51=t41-(((Cj**2)-(C41**2))/(2*1000*cpg))#\n",
    "rhoe=(p1*10**5)/(R*1000*t51)#..........#Density of exhaust gases\n",
    "Ajt=(ma*(1+mf))/(Cj*rhoe)#.......#Discharge of jet area in m**2\n",
    "print \"The outlet area of jet tube = %0.2f m**2\"%Ajt\n",
    "sfc=(mf*ma*3600)/(1000*(TP/Ca))#..........#Specific fuel consumption in kg/thrust-hour\n",
    "print \"Specific fuel consumption = %0.2f kg per kg of thrust\"%sfc"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
