{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# CHAPTER 20 - Air Compressors"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.1 PAGE 750"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated power = 4.24 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Initialisation of Variables\n",
    "v1=1#.........#Volume of air taken in m**3/min\n",
    "p1=1.013#...............#Intake pressure in bar\n",
    "t1=288#...............#Intake temperature in K\n",
    "p2=7#......................#Delivery pressure in bar\n",
    "n=1.35#..............#Adiabatic index\n",
    "R=287#..............#Gas constant in kJ/kgK\n",
    "#Calculations\n",
    "m=(p1*v1*10**5)/(R*t1)#..............#Mass of air delivered per min in kg\n",
    "t2=t1*((p2/p1)**((n-1)/n))#...........#Delivery temperature in K\n",
    "iw=(n/(n-1))*m*R*(t2-t1)#............#Indicated work in kJ/min\n",
    "IP=iw/(60*1000)#....................#Indicated power\n",
    "print \"Indicated power = %0.2f kW\"%IP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.2 PAGE 750"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Cylinder bore = 141.44 mm\n",
      "Motor power = 5.54 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "N=300#............#Compressor rpm\n",
    "afr=15#.........#Air fuel ratio\n",
    "etamech=0.85#....#Mechanical efficiency\n",
    "etamt=0.9#.......#Motor transmission efficiency\n",
    "v=1#............#Volume dealt with per min at inlet in m**3/min\n",
    "rld=1.5#........#Ratio of stroke to diameter\n",
    "v1=1#.........#Volume of air taken in m**3/min\n",
    "p1=1.013#...............#Intake pressure in bar\n",
    "t1=288#...............#Intake temperature in K\n",
    "p2=7#......................#Delivery pressure in bar\n",
    "n=1.35#..............#Adiabatic index\n",
    "R=287#..............#Gas constant in kJ/kgK\n",
    "#Calculations\n",
    "m=(p1*v1*10**5)/(R*t1)#..............#Mass of air delivered per min in kg\n",
    "t2=t1*((p2/p1)**((n-1)/n))#...........#Delivery temperature in K\n",
    "iw=(n/(n-1))*m*R*(t2-t1)#............#Indicated work in kJ/min\n",
    "IP=iw/(60*1000)#....................#Indicated power in kW\n",
    "vdc=v/N#........#Volume drawn in per cycle in m**3\n",
    "D=(vdc/((pi/4)*rld))**(1/3)#..........#Cylinder bore in m\n",
    "print \"Cylinder bore = %0.2f mm\"%(D*1000)\n",
    "pc=IP/etamech#.........#Power input to the compressor in kW\n",
    "mp=pc/etamt#..........#Motor power in kW\n",
    "print \"Motor power = %0.2f kW\"%mp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.3 PAGE 751"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Temperature at the end of compression = 430.07 K\n",
      "Work done during compression per kg of air = 236.03 kJ\n",
      "Heat transferred during compression per kg of air = -98.28 kJ\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "p1=1#......#Suction pressure in bar\n",
    "t1=293#.....#Suction temperature in K\n",
    "n=1.2#......#Compression index\n",
    "p2=10#......#Delivery pressure in bar\n",
    "R=0.287#....#Gas constant in kJ/kgK\n",
    "cv=0.718#...#Specific heat at constant volume in kJ/kgK\n",
    "#Calculations\n",
    "t2=t1*((p2/p1)**((n-1)/n))#.....#Temperature at the end of compression in K\n",
    "print \"Temperature at the end of compression = %0.2f K\"%t2\n",
    "W=1*R*t1*(n/(n-1))*(((p2/p1)**((n-1)/n))-1)#.......#Work done during compression of air in kJ\n",
    "print \"Work done during compression per kg of air = %0.2f kJ\"%W\n",
    "Q=(t2-t1)*(cv-((R)/(n-1)))#..........#Heat transferred during compression of air in kJ/kg\n",
    "print \"Heat transferred during compression per kg of air = %0.2f kJ\"%Q"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.4 PAGE 752"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Volumetric Efficiency = 77.39 %\n",
      "Indicated power = 5.35 kW\n",
      "Isothermal efficiency = 79.79 %\n",
      "Mechanical efficiency = 85.60 %\n",
      "Overall efficiency = 68.30 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt,log\n",
    "# Initialisation of Variables\n",
    "p1=1#........#Suction pressure in bar\n",
    "t1=293#.......#Suction temperature in K\n",
    "p2=6#..........#Discharge pressure in bar\n",
    "t2=453#.......#Discharge temperature in K\n",
    "N=1200#.........#Compressor rpm\n",
    "Ps=6.25#........#Shaft power in kW\n",
    "ma=1.7#........#Mass of air delivered in kg/min\n",
    "D=0.14#......#Engine bore in m\n",
    "L=0.10#.......#Engine stroke in m\n",
    "R=287#..........#Gas constant in kJ/kgK\n",
    "#Calculations\n",
    "Vd=(pi/4)*D*D*L*N#.........#Displlacement volume in m**3/min\n",
    "FAD=ma*R*t1/(p1*10**5)#........#Free air delivered\n",
    "etav=FAD/Vd#.....#Volumetric efficiency \n",
    "print \"Volumetric Efficiency = %0.2f %%\"%(etav*100)\n",
    "n=1/(1-((log(t2/t1))/(log(p2/p1))))#........#Index of compression\n",
    "IP=(n/(n-1))*(ma/60)*(R/1000)*t1*(((p2/p1)**((n-1)/n))-1)#..........#Indicated power in kW\n",
    "print \"Indicated power = %0.2f kW\"%IP\n",
    "Piso=((ma/60)*(R/1000)*t1*(log(p2/p1)))#..........#Isothermal power\n",
    "etaiso=Piso/IP#..............#Isothermal efficiency\n",
    "print \"Isothermal efficiency = %0.2f %%\"%(etaiso*100)\n",
    "etamech=IP/Ps#...........#Mechanical efficiency\n",
    "print \"Mechanical efficiency = %0.2f %%\"%(etamech*100)\n",
    "etao=Piso/Ps#........#Overall efficiency\n",
    "print \"Overall efficiency = %0.2f %%\"%(etao*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.5 PAGE 753"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Work output = 148.95 kW\n",
      "Mass of cooling water = 2.12 kg/min\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "ma=6.75#.........#Mass of air compressed in kg/min\n",
    "p1=1#............#Initial pressure in atm\n",
    "cp=1.003#.........#Specifc heat at constant vpressure in kJ/kgK\n",
    "t1=21#...........#Initial temperature in Celsius\n",
    "t2=43#..........#Final temperature in Celsius\n",
    "rp=1.35#.........#Pressure ratio\n",
    "ga=1.4#.........#Ratio os specific heats\n",
    "delt=3.3#.......#Change in temperature \n",
    "cpw=4.18#.......#Specific heat for water in kJ/kgK\n",
    "#Calculations\n",
    "W=ma*cp*(t2-t1)#............#Work output in kJ\n",
    "print \"Work output = %0.2f kW\"%W\n",
    "t21=(t1+273)*(rp**((ga-1)/ga))#...........#Final temperature if the compression had been isentropic\n",
    "Qr=ma*cp*(t21-(t2+273))#............#Heat rejected in kJ\n",
    "mw=Qr/(cpw*delt)#........#Mass of cooling water in kg/min\n",
    "print \"Mass of cooling water = %0.2f kg/min\"%mw"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.6 PAGE 754"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Swept volume = 0.03 m**3\n",
      "Delivery temperature = 449.90 K\n",
      "Indicated Power = 57.58 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "ma=14#........#Quantity of air delivered in kg/min\n",
    "p1=1.013#......#Intake pressure in bar\n",
    "t1=288#.........#Intake temperature in K\n",
    "p2=7#...........#Delivery pressure in bar\n",
    "N=300#..........#Compressor rpm\n",
    "pervc=0.05#.......#Percentage of clearance volume in the total stroke volume\n",
    "n=1.3#............#Compressor and expansion index\n",
    "#Calculations\n",
    "V1byVs=pervc+1#\n",
    "v1minv4=ma/(N*2)#\n",
    "v4byv3=((p2/p1)**(1/n))#\n",
    "v4byvs=v4byv3*pervc#\n",
    "Vs=v1minv4/(V1byVs-v4byvs)#.....#Swept volume in m**3\n",
    "print \"Swept volume = %0.2f m**3\"%Vs\n",
    "t2=t1*((p2/p1)**((n-1)/n))#........#Delivery Temperature in K\n",
    "print \"Delivery temperature = %0.2f K\"%t2\n",
    "IP=((n)/(n-1))*p1*(10**5)*((ma)/(60*1000))*(((p2/p1)**((n-1)/n))-1)#\n",
    "print \"Indicated Power = %0.2f kW\"%IP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.7 PAGE 754"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated power = 63.51 kW\n",
      "Volumetric efficiency = 2.07 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "FAD=14#...........#Free air delivered in m**3/min\n",
    "p1=0.95#.........#Induction pressure in bar\n",
    "t1=305#........#Induction temperature in K\n",
    "p2=7#...........#Delivery pressure in bar\n",
    "n=1.3#...........#Adiabatic index\n",
    "VcbyVs=0.05#........#Ratio of clearance volume and swept volume\n",
    "R=287#...........#Gas constant in J/kgK\n",
    "t=288#...........#free air temperature in K\n",
    "p=1.013#.........#free air pressure in bar\n",
    "#Calculations\n",
    "m=(p*100000*FAD)/(R*t)#..........#Mass delivered per min in kg\n",
    "t2=t1*((p2/p1)**((n-1)/n))#\n",
    "IP=((n/(n-1))*m*(R/1000)*(t2-t1))/60#.........#Indicated power in kW\n",
    "print \"Indicated power = %0.2f kW\"%IP\n",
    "v4byv3=(p2/p1)**(1/n)#v4byvs=v4byv3*VcbyVs#v1minv4=(1+VcbyVs)-v4byvs#\n",
    "Vbyvs=v1minv4*(t/t1)*(p1/p)#\n",
    "etav=Vbyvs/1#.............#Volumetric efficiency\n",
    "print \"Volumetric efficiency = %0.2f %%\"%(etav*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.8 PAGE 755"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Power input to compressor = 83.65 kW\n",
      "Compressor stroke = 300.00 mm\n",
      "Compressor bore = 291.43 mm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "FAD=16#.......#Free air delivered in m**3/min\n",
    "p1=0.96#......#Suction pressure in bar\n",
    "t1=303#.......#Suction temperature in K\n",
    "n=1.3#........#Compression index\n",
    "k=0.04#........#Clearance ratio\n",
    "p2=6#.........#Delivery pressure in bar\n",
    "etamech=0.9#...#Mechanical efficiency\n",
    "vp=300#.......#Piston speed in m/min\n",
    "N=500#........#Compressor rpm\n",
    "p=1#.....#Ambient pressure in bar\n",
    "t=288#.....#Ambient temperature in K\n",
    "etac=0.85#...#Compressor efficiency\n",
    "R=0.287#......#Universal gas constant\n",
    "#Calculations\n",
    "m=(p*10**5*FAD)/(R*1000*t)#...........#Mass flow rate of compressor in kg/min\n",
    "t2=t1*((p2/p1)**((n-1)/n))#.....#Temperature at the end of compression in K\n",
    "P=(n/(n-1))*(m/60)*R*(t2-t1)*(1/etamech)*(1/etac)#..........#Power input to compressor in kW\n",
    "print \"Power input to compressor = %0.2f kW\"%P\n",
    "L=vp/(2*N)#.........#Stroke in m\n",
    "print \"Compressor stroke = %0.2f mm\"%(L*1000)\n",
    "etav=((t/t1)*(p1/p)*(1+k-(k*((p2/p1)**(1/n)))))#........#Volumetric efficiency\n",
    "D=sqrt(FAD/((pi/4)*L*N*2*etav))#...........#Compressor bore in m\n",
    "print \"Compressor bore = %0.2f mm\"%(D*1000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.9 PAGE 756"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Volumetric efficiency = 91.10 %\n",
      "Power required to drive the compressor = 2.27 kW\n",
      "Compressor rpm :  486.0\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "m=0.6#..........#Mass of air delivered in kg/min\n",
    "p2=6#.........#Delivery pressure in bar\n",
    "p1=1#..........#Induction pressure in bar\n",
    "t1=303#........#Induction temperature in K\n",
    "D=0.1#.........#Compressor bore in m\n",
    "L=0.15#........#Compressor stroke in m\n",
    "k=0.03#........#Clearance ratio\n",
    "etamech=0.85#....#Mechanical efficiency\n",
    "R=0.287#.......#Gas constant in kJ/kgK\n",
    "n=1.3#........#Compression index\n",
    "#Calculations\n",
    "etav=(1+k)-(k*((p2/p1)**(1/n)))#..........#Volumetric efficiency\n",
    "print \"Volumetric efficiency = %0.2f %%\"%(etav*100)\n",
    "IP=(n/(n-1))*(m/60)*R*t1*(((p2/p1)**((n-1)/n))-1)#.........#Indicated power in kW\n",
    "P=IP/etamech#...........#Power required to drive the compressor in kW\n",
    "print \"Power required to drive the compressor = %0.2f kW\"%P\n",
    "FAD=(m*R*t1*1000)/(p1*10**5)#...........#Free air delivery in m**3/min\n",
    "Vd=FAD/etav#........#Displacement volume in m**3/min\n",
    "N=Vd/((pi/4)*D*D*L)#.........#Compressor rpm\n",
    "print \"Compressor rpm : \",round(N)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.10 PAGE 756"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Percentage change in free air delivery = 2.68 %\n",
      "Percentage change in power delivered = 2.68 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "L=88#...........#Compressor stroke in cm\n",
    "k=0.02#...........#Clearance ratio\n",
    "p3=8.2#...........#Delivery pressure in bar\n",
    "p4=1.025#.......#Suction pressure in bar\n",
    "p1=p4#.......#Suction pressure in bar \n",
    "n=1.3#.........#Compression index\n",
    "lo=0.55#...#Length of distance piece fitted after overhaul in cm\n",
    "#Calculations\n",
    "pcfa=(((L+(L*k))-((L*k)*((p3/p4)**(1/n))))-(((k*L)+lo+L)-(((k*L)+lo)*((p3/p4)**(1/n)))))/((L+L*k)-((L*k)*((p3/p4)**(1/n))))\n",
    "print \"Percentage change in free air delivery = %0.2f %%\"%(pcfa*100)\n",
    "pcpa=pcfa#......#Percentage change in power delivered\n",
    "print \"Percentage change in power delivered = %0.2f %%\"%(pcpa*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.11 PAGE 757"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Motor power = 241.07 kW\n",
      "Compressor bore = 262.71 mm\n",
      "Compressor stroke = 315.25 mm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "v=30#.............#Suction volume in m**3/min\n",
    "p1=1#...........#Suction pressure in bar\n",
    "t1=300#.........#Suction temperature in K\n",
    "p2=16#...........#Delivery pressure in bar\n",
    "N=320#..........#Compressor rpm\n",
    "k=0.04#.........#Clearance ratio\n",
    "rld=1.2#.........#Ratio of stroke to bore\n",
    "etamech=0.82#....#Mechanical efficiency\n",
    "n=1.32#.........#Compression index\n",
    "ti=39+273#......#Temperature inside the suction chamber in K\n",
    "nc=4#.........#No of cylineders\n",
    "#Calculations\n",
    "W=(n/(n-1))*(p1/1000)*10**5*(v/60)*(((p2/p1)**((n-1)/n))-1)#........#Work done in kW\n",
    "mp=W/etamech#..........#Motor power in kW\n",
    "print \"Motor power = %0.2f kW\"%mp\n",
    "etav=((1+k)-(k*((p2/p1)**(1/n))))*(t1/ti)#........#Volumetric efficiency\n",
    "Vs=(v/nc)*(1/(2*N))*(1/etav)#............#Swept volume of cylinder in m**3\n",
    "D=(Vs/((pi/4)*rld))**(1/3)#.............#Compressor bore in m\n",
    "L=D*rld#..............#Compresor stroke in m\n",
    "print \"Compressor bore = %0.2f mm\"%(D*1000)\n",
    "print \"Compressor stroke = %0.2f mm\"%(L*1000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.12 PAGE 758"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Diameter of compressor cylinder = 159.70 mm\n",
      "Stroke of compressor cylinder = 191.64 mm\n",
      "Diameter of engine cylinder = 98.49 mm\n",
      "Stroke of engine cylinder = 118.18 mm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "n=2#........#No of cylinders \n",
    "ma=16#........#Mass of air supplied per min in kg\n",
    "p1=1#........#Suction pressure in bar\n",
    "t1=288#.......#Suction temperature in K\n",
    "k=0.04#.......#Clearance ratio\n",
    "ni=1.3#........#Compression index\n",
    "R=0.287#........#Gas constant in kJ/kgK\n",
    "N=2000#........#Engine rpm\n",
    "p3=7#...........#Delivery pressure in bar\n",
    "rld=1.2#...........#Ratio of stroke to bore for compressor cylinder and engine cylinder\n",
    "etamech=0.82#.........#Mechanical efficiency of engine\n",
    "pmb=5.5#..........#Mean effective pressure in bar in engine\n",
    "ne=4#.............#No of engine cylinders\n",
    "#Calculations\n",
    "Vs=(((ma/n)*R*1000*t1)/(p1*10**5*N))/((1+k)-(k*((p3/p1)**(1/ni))))#\n",
    "Dc=(Vs/((pi/4)*rld))**(1/3)#.........#Diameter of compressor cylinder in m\n",
    "Lc=rld*Dc#.............#Stroke of the compressor cylinder in m\n",
    "print \"Diameter of compressor cylinder = %0.2f mm\"%(Dc*1000)\n",
    "print \"Stroke of compressor cylinder = %0.2f mm\"%(Lc*1000)\n",
    "IP=(ni/(ni-1))*(ma/60)*R*t1*(((p3/p1)**((ni-1)/ni))-1)#......#Indicated power of the compressor in kW\n",
    "BP=IP/etamech#...............#Brake power of the engine in kW\n",
    "De=((BP*60*1000)/(ne*pmb*10**5*rld*(pi/4)*N))**(1/3)#......#Diameter of the engine cylinder in m\n",
    "Le=rld*De#...........#Stroke of the engine cylinder in m\n",
    "print \"Diameter of engine cylinder = %0.2f mm\"%(De*1000)\n",
    "print \"Stroke of engine cylinder = %0.2f mm\"%(Le*1000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.13 PAGE 759"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Volumetric efficiency = 81.44 %\n",
      "Diameter of the cylinder = 17.98 cm\n",
      "Stroke of the cylinder = 17.98 cm\n",
      "Brake power = 11.10 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "nc=1.25#......#Index of compression\n",
    "ne=1.3#......#Index of expansion\n",
    "etamech=0.85#.......#Mechanical efficiency\n",
    "p1=1#.........#Suction pressure in bar\n",
    "p2=7.5#.......#Delivery pressure in bar\n",
    "t1=25+273#....#Suction temperature in bar\n",
    "Vamb=2.2#.....#Volume of free air delivered in m**3\n",
    "N=310#........#Engine rpm\n",
    "k=0.05#.......#Clearance ratio\n",
    "pamb=1.03#.....#Ambient pressure in bar\n",
    "tamb=293#......#Ambient temperature in K\n",
    "#Calculations\n",
    "etav=(1+k-(k*((p2/p1)**(1/ne))))#........#Volumetric efficiency\n",
    "print \"Volumetric efficiency = %0.2f %%\"%(etav*100)\n",
    "v1=(pamb*Vamb*t1)/(p1*tamb)#.......#Volume of air delivered at suction condition in m**3\n",
    "vs=(v1/(etav*N*2))#.........#Swept volume in m**3\n",
    "D=(vs/(pi/4))**(1/3)#........#Diameter of the cylinder in m\n",
    "L=D#\n",
    "print \"Diameter of the cylinder = %0.2f cm\"%(D*100)\n",
    "print \"Stroke of the cylinder = %0.2f cm\"%(L*100)\n",
    "W=2*vs*10**5*(((nc)/(nc-1))*p1*(1+k)*(((p2/p1)**((nc-1)/(nc)))-1)-((ne)/(ne-1))*p1*(k*((p2/p1)**(1/ne)))*(((p2/p1)**((ne-1)/(ne)))-1))#..........#Work done per cycle of operation in Nm/cycle\n",
    "IP=W*N/(60*1000)#...............#Indicated power in kW\n",
    "BP=IP/etamech#.............#Brake power in kW\n",
    "print \"Brake power = %0.2f kW\"%BP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.14 PAGE 760"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Compressor diameter = 35.75 cm\n",
      "Compressor stroke = 53.63 cm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "v=14#..........#Volume of air delivered in m**3\n",
    "p1=1#........#Suction pressure in bar\n",
    "p2=7#........#Delivery pressure in bar\n",
    "N=310#........#Compressor rpm\n",
    "n=1.35#........#Compression index\n",
    "k=0.05#........#Clearance ratio\n",
    "rld=1.5#.........#Ratio of cylinder length and diameter\n",
    "#Calculations\n",
    "etav=(1+k)-(k*((p2/p1)**(1/n)))#..........#Volumetric efficiency\n",
    "Vs=v/(etav*N)#.............#Swept volume in m**3\n",
    "D=((Vs)/((pi/4)*rld))**(1/3)#......#Compressor diameter in m\n",
    "L=rld*D#......................#Compressor stroke in m\n",
    "print \"Compressor diameter = %0.2f cm\"%(D*100)\n",
    "print \"Compressor stroke = %0.2f cm\"%(L*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.15 PAGE 761"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Free air delivered = 13.89 m**3/min\n",
      "Heat rejected during compression = 748.46 kJ/min\n",
      "Power needed to drive the compressor = 52.01 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "D=0.33#.........#Cylinder diameter in m\n",
    "L=0.35#.........#Cylinder stroke in m\n",
    "k=0.05#.........#Clearance ratio \n",
    "N=300#..........#Compressor rpm\n",
    "psuc=0.95#........#Suction pressure in bar\n",
    "tsuc=298#.........#Suction temperature in K\n",
    "pamb=1.013#......#Ambient pressure in bar\n",
    "tamb=293#.........#Ambient temperature in K\n",
    "p2=4.5#...........#Delivery pressure in bar\n",
    "n=1.25#..........#Compression index\n",
    "cv=0.717#...........#Specific heat at constant volume in kJ/kgK\n",
    "ga=1.4#..........#Ratio of specific heats\n",
    "etamech=0.8#......#Mechanical efficiency\n",
    "R=0.287#.........#Gas constant in kJ/kgK\n",
    "#Calculations\n",
    "Vs=(pi/4)*D*D*L*N*2#............#Swept volume in m**3\n",
    "p1=psuc#\n",
    "etav=1-(k*(((p2/p1)**(1/n))-1))#........#Volumetric efficiency\n",
    "Vad=Vs*etav#................#Actual air drawn per min in m**3\n",
    "FAD=(psuc/pamb)*(tamb/tsuc)*Vad#............#Free air delivered in m**3/min\n",
    "print \"Free air delivered = %0.2f m**3/min\"%FAD\n",
    "t1=tsuc#\n",
    "ma=(p1*10**5*Vad)/(R*1000*t1)#.......#Mass of air delivered per min in kg\n",
    "t2=t1*((p2/p1)**((n-1)/n))#..........#Delivery temperature in K\n",
    "Qr=ma*cv*((ga-n)/(n-1))*(t2-t1)#..........#Heat rejected during compression in kJ/min\n",
    "print \"Heat rejected during compression = %0.2f kJ/min\"%Qr\n",
    "P=((n)/(n-1))*R*t1*(ma/60)*(((p2/p1)**((n-1)/(n)))-1)*(1/etamech)#..........#Power needed to drive the compressor in kW\n",
    "print \"Power needed to drive the compressor = %0.2f kW\"%P"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 20.16 PAGE 762"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Power required to run the compressor = 4.19 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "#Initialisation of variables\n",
    "p1=1.03#...........#Intake pressure in bar\n",
    "t1=300#............#Intake temperature in K\n",
    "p2=7#.............#Intake pressure for High pressure cylinder in bar\n",
    "t2=310#..............#Temperature of air entering high pressure cylinder in K\n",
    "p3=40#............#Pressure of air after compression in bar\n",
    "V=30#.........#volume of air delivered in m**3/h\n",
    "R=0.287#............#Gas constant for air in kJ/kgK\n",
    "ga=1.4#...........#Ratio of specific heats\n",
    "#Calculations\n",
    "m=p1*10**5*V/(R*1000*t1)#..........#Mass of air compressed in kg/h\n",
    "t21=t1*((p2/p1)**((ga-1)/ga))#.......#Actual temperature of air entering high pressure cylinder in K\n",
    "t3=t2*((p3/p2)**((ga-1)/ga))#........#Actual temperature of air after compression in K\n",
    "W=((ga)/(ga-1))*m*(R/3600)*(t21-t1+t3-t2)#..........#Power required to run compressor in kW\n",
    "print \"Power required to run the compressor = %0.2f kW\"%W"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.17 PAGE 762"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Diameter of low pressure cylinder = 267.30 mm\n",
      "Diameter of high pressure cylinder = 109.13 mm\n",
      "Power required to run the compressor = 57.49 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "FAD=6#.......#Free air delivered in m**3/min\n",
    "p1=1#........#suction pressure in bar\n",
    "t1=300#......#Suction temperature in K\n",
    "p3=40#.......#Delivery pressure in bar\n",
    "p2=6#........#Intermediate pressure in bar\n",
    "t3=300#........#Temperature at the inlet to 2nd stage in K\n",
    "n=1.3#.........#Compression index\n",
    "etamech=0.8#.....#Mechanical efficiency\n",
    "N=400#............#Compressor rpm\n",
    "R=0.287#.........#Gas constant in kJ/kgK\n",
    "#Calculations  \n",
    "dlp=(FAD/(N*(pi/4)))**(1/3)#...............#Diameter of the low pressure cylinder in m\n",
    "dhp=sqrt(1/(dlp*N*(pi/4)))#............#Diameter of high pressure cylinder in m\n",
    "print \"Diameter of low pressure cylinder = %0.2f mm\"%(dlp*1000)\n",
    "print \"Diameter of high pressure cylinder = %0.2f mm\"%(dhp*1000)\n",
    "m=(p1*FAD*10**5)/(R*t1*1000*60)#........#Mass flow of air in kg/s\n",
    "W=n*(1/(n-1))*m*R*t1*(((p2/p1)**((n-1)/n))+((p3/p2)**((n-1)/n))-2)#........#Indicated work in kJ/s\n",
    "P=W/etamech#...............#Power required in kW\n",
    "print \"Power required to run the compressor = %0.2f kW\"%P"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.18 PAGE 763"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Intermediate pressure = 0.26 Mpa\n",
      "Volume of low pressure cylinder = 0.02 m**3\n",
      "Volume of high pressure cylinder = 0.01 m**3\n",
      "Power required to drive the compressor = 42.96 kW\n",
      "Heat rejected in the intercooler = 15.04 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "ns=2#.............#No of stages\n",
    "v1=0.2#.........#Intake volume in m**3/s\n",
    "p1=1#..........#Intake pressure in bar\n",
    "t1=289#...............#Intake temperature in K\n",
    "p3=7#.........#Final pressure in bar\n",
    "n=1.25#.......#Compression index\n",
    "N=600#........#Compressor rpm\n",
    "cp=1.005#.....#Specific heat at constant pressure in kJ/kgK\n",
    "R=0.287#......#Gas constant in kJ/kgK\n",
    "#Calculations\n",
    "p2=sqrt(p1*p3)#......#Intermediate pressure in bar\n",
    "print \"Intermediate pressure = %0.2f Mpa\"%(p2/10)\n",
    "vslp=60*v1/N#..........#Volume of low pressure cylinder in m**3\n",
    "vshp=p1*vslp/p2#..........#Volume of high pressure cylinder in m**3\n",
    "print \"Volume of low pressure cylinder = %0.2f m**3\"%vslp\n",
    "print \"Volume of high pressure cylinder = %0.2f m**3\"%vshp\n",
    "W=(ns*(n/(n-1)))*p1*10**5*(v1/1000)*(((p3/p1)**((n-1)/(ns*n)))-1)#...........#Power required to drive the compressor in kW\n",
    "print \"Power required to drive the compressor = %0.2f kW\"%W\n",
    "m=p1*10**5*v1/(R*t1*1000)#.........#Mass of air handled in kg/s\n",
    "t2=t1*((p2/p1)**((n-1)/n))#.........#Temperature at the end of first stage compression in K\n",
    "Qr=m*cp*(t2-t1)#.......#Heat rejected in the intercooler in kW\n",
    "print \"Heat rejected in the intercooler = %0.2f kW\"%Qr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 20.19 PAGE 764"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ratio of cylinder diameters : 2.340\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "#initialisation of variables\n",
    "p3=30#..........#delivery pressure in bar\n",
    "p1=1#.........#suction pressure  in bar\n",
    "t1=273+15#.......#suction temperature in K\n",
    "n=1.3#.........#adiabatic index\n",
    "#calculation\n",
    "p2=sqrt(p1*p3)#.....#Pressure before entering High pressure cylinder in bar\n",
    "t21=t1*((p2/p1)**((n-1)/n))#.........#Actual temperature before entering the high pressure turbine in K\n",
    "r=sqrt((p2**(1/n))*(t21/t1))#............#Ratio of cylinder diameters\n",
    "print \"Ratio of cylinder diameters : %0.3f\"%r"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.20 PAGE 765"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Work done in compressing 1 kg of gas = 388.53 kJ\n",
      "Pressure in the intercooler would rise.\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "ns=2#.........#No of stages\n",
    "p1=1#........#Suction pressure in bar\n",
    "p2=7.4#.......#Intercooler pressure in bar\n",
    "p3=42.6#.......#Delivery pressure in bar\n",
    "t1=15+273#......#Suction temperature in K\n",
    "n=1.3#........#Compression index\n",
    "R=0.287#.......#Gas constant in kJ/kgK\n",
    "dlp=0.09#.......#Diameter of low pressure cylinder in m\n",
    "dhp=0.03#.......#Diameter of high pressure cylinder in m\n",
    "etav=0.9#.....#Volumetric efficiency\n",
    "#Calculations\n",
    "W=n*(1/(n-1))*R*t1*(((p2/p1)**((n-1)/n))+((p3/p2)**((n-1)/n))-2)#\n",
    "print \"Work done in compressing 1 kg of gas = %0.2f kJ\"%W\n",
    "#Given that stroke length is same in both cases\n",
    "rV=p2/p1#.........#Ratio of volumes\n",
    "rECV=((dlp/dhp)**2)*etav#.........#Ratio of effective cylinder volumes\n",
    "if (rECV>rV):\n",
    "    print \"Pressure in the intercooler would rise.\"\n",
    "elif (rECV<rV):\n",
    "    print \"Pressure in the intercooler would fall\"\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.21 PAGE 765"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stroke length = 0.36 m\n",
      "Bore = 0.27 m\n",
      "Work required = 49.20 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "V=4#...........#Volume of air handled in m**3/min\n",
    "p1=1.016#.....#Suction pressure in bar\n",
    "t1=288#........#Suction temperature in K\n",
    "N=250#.........#Compressor rpm\n",
    "p3=78.65#.....#Delivery pressure in bar\n",
    "vp=3#........#Piston speed in m/s\n",
    "etamech=0.75#.....#mechanical efficiency\n",
    "etav=0.8#........#Volumetric efficiency\n",
    "n=1.25#..........#Compression index\n",
    "R=287#...........#Gas constant in J/kgK\n",
    "ns=2#............#No of stages\n",
    "#Calculations\n",
    "l=(vp*60)/(2*N)#..........#Stroke length in m\n",
    "d=sqrt(V/((pi/4)*l*N*etav))#.......#Bore in m\n",
    "print \"Stroke length = %0.2f m\"%l\n",
    "print \"Bore = %0.2f m\"%d\n",
    "m=(p1*10**5*V)/(R*t1)#.......#Mass of air handled by the compressor in kg/min\n",
    "p2=sqrt(p1*p3)#.............#Intermediate pressure in bar\n",
    "t2=t1*((p2/p1)**((n-1)/n))#.........#Temperature at the end of first stage compression in K\n",
    "W=ns*(n/(n-1))*(m/60)*(R/1000)*(t2-t1)*(1/etamech)#..........#Work required in kW\n",
    "print \"Work required = %0.2f kW\"%W"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.22 PAGE 766"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated power = 15.48 kW\n",
      "Swept volume for low pressure cylinder = 0.0131 m**3\n",
      "Swept volume of high pressure cylinder = 0.0044 m**3\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "m=4.5#.........#Amount of air compressed in kg/min\n",
    "ps=1.013#.......#Suction pressure in bar\n",
    "ts=288#.........#Suction temperature in K\n",
    "rp=9#...........#Pressure ratio\n",
    "n=1.3#.........#Compression index\n",
    "k=0.05#........#Clearance ratio\n",
    "N=300#.........#Compressor rpm\n",
    "R=287#.........#Gas constant in J/kgK\n",
    "ns=2#............#No of stages\n",
    "#Calculations\n",
    "ti=round(ts*((sqrt(rp))**((n-1)/n)))#......#Intermediate temperature in K\n",
    "W=round(ns*n*(1/(n-1))*m*(R/1000)*(ti-ts))#..........#Work required per min in kJ\n",
    "IP=W/60#.........#Indicated power in kW\n",
    "print \"Indicated power = %0.2f kW\"%IP\n",
    "mc=m/N#...........#Mass induced per cycle in kg\n",
    "etav=(1+k)-(k*(sqrt(rp)**(1/n)))#.......#Volumetric efficiency\n",
    "Vs=(mc*R*ts)/(ps*10**5*etav)#........#Swept volume for low pressure cylinder in m**3\n",
    "print \"Swept volume for low pressure cylinder = %0.4f m**3\"%Vs\n",
    "vdhp=(mc*ts*R)/(sqrt(rp)*ps*10**5)#............#Volume of air drawn in high pressure cylinder per cycle in m**3\n",
    "vshp=vdhp/etav#...............#Swept volume ofhigh pressure cylinder in m**3\n",
    "print \"Swept volume of high pressure cylinder = %0.4f m**3\"%vshp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.23 PAGE 767"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Power required to run the compressor = 18.68 kW\n",
      "Bore of low pressure cylinder = 19.06 cm\n",
      "Stroke of low pressure cylinder = 19.06 cm\n",
      "Bore of high pressure cylinder = 7.00 cm\n",
      "Stroke of high pressure cylinder = 19.06 cm\n",
      "Ratio of cylinder volumes : 7.4162\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "v1=2.2#...........#free air delivered by the compressor in m**3/min\n",
    "p1=1#........#Suction pressure in bar\n",
    "t1=298#.......#Suction temperature in K\n",
    "pd=55#........#Delivery pressure in bar\n",
    "N=210#.......#Compressor rpm\n",
    "n=1.3#........#Compression index\n",
    "k=0.05#.......#Clearance ratio for high pressure and low pressure cylinders\n",
    "R=287#.......#Gas constant in J/kgK\n",
    "ns=2#.......#No of stages\n",
    "#Calculations\n",
    "ps=p1#\n",
    "m =(p1*v1*10**5)/(R*t1)#.........#Mass of air deivered in m**3/min\n",
    "W=(ns*(n/(n-1)))*m*R*t1*(((pd/ps)**((n-1)/(ns*n)))-1)#...........#Work done by compressor in Nm/min\n",
    "P=W/(60*1000)#...........#Power required to run the compressor\n",
    "print \"Power required to run the compressor = %0.2f kW\"%P\n",
    "pi=sqrt(ps*pd)#........#Intermediate pressure in bar\n",
    "etav1=(1+k)-(k*((pi/p1)**(1/n)))#...........#Volumetric efficiency of the low pressure cylinder \n",
    "Vs=(v1*10**6)/(etav1*N)#............#Swept volume in cm**3\n",
    "dlp=(Vs/((pi/4)))**(1/3)#..........#Diameter of low pressure cylinder in cm\n",
    "llp=dlp#.................#Stroke of low pressure cylinder in cm\n",
    "print \"Bore of low pressure cylinder = %0.2f cm\"%dlp\n",
    "print \"Stroke of low pressure cylinder = %0.2f cm\"%llp\n",
    "dhp=sqrt(dlp*dlp/pi)#.........#Diameter of high pressure cylinder in cm\n",
    "lhp=llp#\n",
    "print \"Bore of high pressure cylinder = %0.2f cm\"%dhp\n",
    "print \"Stroke of high pressure cylinder = %0.2f cm\"%lhp\n",
    "rcv=pi/ps#.....#Ratio of cylinder volumes\n",
    "print \"Ratio of cylinder volumes : %0.4f\"%rcv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.24 PAGE 768"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Heat rejected to the intercooler = 2179.62 kJ/min\n",
      "Diameter of high pressure cylinder = 184.68 mm\n",
      "Power required for high pressure cylinder = 45.02 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "p1=1#........#Suction pressure in bar\n",
    "p2=4#.....#Intermediate pressure in bar\n",
    "p5=3.8#.......#Pressure of air leaving the interooler in bar\n",
    "p6=15.2#........#Delivery pressure in bar\n",
    "t1=300#..........#Suction temperature in K\n",
    "dlp=0.36#........#Diameter of low pressure cylinder in m\n",
    "llp=0.4#........#Stroke of low pressure cylinder in m\n",
    "N=220#........#Compressor rpm\n",
    "k=0.04#........#Clearance ratio\n",
    "cp=1.0035#.........#Specific heat at constant pressure in kJ/kgK\n",
    "n=1.3#........#Compression index\n",
    "R=0.287#........#Gas constant in kJ/kgK\n",
    "p8=p5#\n",
    "p3=p2#\n",
    "p7=p6#\n",
    "t5=t1#\n",
    "#Calculations\n",
    "Vslp=(pi/4)*dlp*dlp*llp*N*2#.......#Swept volume in m**3\n",
    "etavlp=(1+k)-(k*((p2/p1)**(1/n)))#.....#Volumetric efficiency\n",
    "valp=Vslp*etavlp#................#Volume of air drawn in low pressure cylinder in m**3\n",
    "m=(p1*10**5*valp)/(R*1000*t1)#........#Mass of air drawin in kg/min\n",
    "t2=round(t1*((p2/p1)**((n-1)/n)))#\n",
    "Qr=m*cp*(t2-t5)#........#Heat rejected to the intercooler in kJ/min\n",
    "print \"Heat rejected to the intercooler = %0.2f kJ/min\"%Qr\n",
    "vahp=(m*R*t5*1000)/(p5*10**5)#...#Volume of air drawn into high pressure cylinder per min in m**3\n",
    "Vshp=vahp/etavlp#.........#Swept volume of high pressure cylinder in m**3/min\n",
    "dhp=sqrt(Vshp/((pi/4)*2*N*llp))#..........#Diameter of high pressure cylinder in m\n",
    "print \"Diameter of high pressure cylinder = %0.2f mm\"%(dhp*1000)\n",
    "P=(n/(n-1))*m*(1/60)*R*(t2-t1)#.......#Power required for high pressure cylinder in kW\n",
    "print \"Power required for high pressure cylinder = %0.2f kW\"%P"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.25 PAGE 769"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Power required to run the compressor = 85.38 kW\n",
      "Heat rejected in intercooler = 1742.36 kJ/min\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "ps=1#........#Suction pressure in bar\n",
    "pi=4.2#.....#Intermediate pressure in bar\n",
    "pi1=4#.......#Pressure of air leaving the interooler in bar\n",
    "pd=18#........#Delivery pressure in bar\n",
    "t1=298#..........#Suction temperature in K\n",
    "t5=t1#\n",
    "dlp=0.4#........#Diameter of low pressure cylinder in m\n",
    "llp=0.5#........#Stroke of low pressure cylinder in m\n",
    "N=200#........#Compressor rpm\n",
    "k=0.05#........#Clearance ratio\n",
    "cp=1.004#.........#Specific heat at constant pressure in kJ/kgK\n",
    "n=1.25#........#Compression index\n",
    "R=0.287#........#Gas constant in kJ/kgK\n",
    "#Calculations\n",
    "Vslp=(pi/4)*dlp*dlp*llp#..........#Swept volume of low pressure cylinder in m**3\n",
    "etavlp=(1+k)-(k*((pi/ps)**(1/n)))#.....#Volumetric efficiency\n",
    "t2=round(t1*((pi/ps)**((n-1)/n)))#\n",
    "m=(ps*10**5*etavlp*Vslp)/(R*1000*t1)#...#Mass of air in kg\n",
    "wlp=((n)/(n-1))*R*1000*t1*m*(((pi/ps)**((n-1)/(n)))-1)#..........#Work done per min in Nm in low pressure cylinder\n",
    "whp=((n)/(n-1))*R*t5*m*1000*(((pd/pi1)**((n-1)/(n)))-1)#..........#Work done per min in Nm in high pressure cylinder\n",
    "W=wlp+whp#.........#Net work done in Nm\n",
    "IP=(W*N)/(60*1000)#............#Power required to run the compressor in kW\n",
    "print \"Power required to run the compressor = %0.2f kW\"%IP\n",
    "Qr=m*N*cp*(t2-t1)#...........#Heat rejected in intercooler in kJ/min\n",
    "print \"Heat rejected in intercooler = %0.2f kJ/min\"%Qr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.26 PAGE 771"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Power required = 49.23 kW\n",
      "Isothermal work done = 41.78 kW\n",
      "Isothermal efficiency = 84.86 %\n",
      "Free air delivered = 9.04 m**3/min\n",
      "Heat transferred in intercooler = 19.89 kW\n",
      "\n",
      "Swept volume for low pressure stage = 0.02 m**3\n",
      "\n",
      "\n",
      "Clearance volume for low pressure stage = 8.90e-04 m**3\n",
      "\n",
      "\n",
      "Swept volume for high pressure stage = 0.01 m**3\n",
      "\n",
      "\n",
      "Clearance volume for high pressure stage = 3.48e-04 m**3\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt,log\n",
    "# Initialisation of Variables\n",
    "p1=1#............#Intake pressure in bar\n",
    "p2=4#..............#Pressure after first stage in bar\n",
    "p3=16#............#Final pressure in bar\n",
    "ns=2#............#No of stages\n",
    "t1=300#............#Intake temperature in K\n",
    "n=1.3#............#Compression index\n",
    "klp=0.04#.........#Clearance ratio for low pressure cylinder\n",
    "khp=0.06#........#Clearance ratio for high pressure cylinder\n",
    "N=440#............#Engine rpm\n",
    "R=0.287#..........#Gas constant in kJ/kgK\n",
    "m=10.5#.............#Mass of air delivered in kg/min\n",
    "cp=1.005#.........#Specific heat at constant pressure in kJ/kgK\n",
    "#Calculations\n",
    "rp=sqrt(p1*p3)#...........#Pressure ratio per stage\n",
    "P=((ns*n)/(n-1))*R*t1*(m/60)*(((p3/p1)**((n-1)/(ns*n)))-1)#..........#Work done per min in Nm\n",
    "print \"Power required = %0.2f kW\"%P\n",
    "isoWd=(m/60)*R*t1*log(p3/p1)#..........#Isothermal work done in Nm\n",
    "print \"Isothermal work done = %0.2f kW\"%isoWd\n",
    "etaiso=isoWd/P#...............#Isothermal efficiency\n",
    "print \"Isothermal efficiency = %0.2f %%\"%(etaiso*100)\n",
    "FAD=(m*R*t1*1000)/(p1*10**5)#.............#Free air delivered in m**3/min\n",
    "print \"Free air delivered = %0.2f m**3/min\"%FAD\n",
    "t2=t1*((p2/p1)**((n-1)/n))#.....#Temperature at the end of compression in K\n",
    "Qt=(m/60)*cp*(t2-t1)#..............#Heat transferred in intercooler in kW\n",
    "print \"Heat transferred in intercooler = %0.2f kW\"%Qt\n",
    "etavlp=(1+klp)-(klp*((p2/p1)**(1/n)))#..........#Volumetric efficiency of low pressure stage\n",
    "etavhp=(1+khp)-(khp*((p2/p1)**(1/n)))#..........#Volumetric efficiency of high pressure stage\n",
    "vslp=FAD/(N*etavlp)#......#Swept volume for low pressure stage in m**3\n",
    "vclp=klp*vslp#..............#Clearance volume for low pressure stage in m**3\n",
    "print \"\\nSwept volume for low pressure stage = %0.2f m**3\\n\"%(vslp)\n",
    "print \"\\nClearance volume for low pressure stage = %0.2e m**3\\n\"%(vclp)\n",
    "vshp=FAD/(N*rp*etavhp)#......#Swept volume for high pressure stage in m**3\n",
    "vchp=khp*vshp#..............#Clearance volume for high pressure stage in m**3\n",
    "print \"\\nSwept volume for high pressure stage = %0.2f m**3\\n\"%(vshp)\n",
    "print \"\\nClearance volume for high pressure stage = %0.2e m**3\\n\"%(vchp)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.27 PAGE 771"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Work done = 1297727.20 Nm\n",
      "Isothermal work done = 1146628.13 Nm\n",
      "Isothermal efficiency = 88.36 %\n",
      "Single stage work done per min = 1686780.23 Nm\n",
      "Percentage of work saved : 23.06 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "ns=3#......#No of stages\n",
    "p1=1.05#......#Intake pressure in bar\n",
    "pd=40#..........#Delivery pressure in bar\n",
    "V=3#..........#Volume of air xupplied per min in m**3\n",
    "n=1.25#........#Compression index\n",
    "#Calculations\n",
    "Wd=((ns*n)/(n-1))*p1*V*10**5*(((pd/p1)**((n-1)/(ns*n)))-1)#..........#Work done per min in Nm\n",
    "print \"Work done = %0.2f Nm\"%Wd\n",
    "isoWd=10**5*p1*V*log(pd/p1)#..........#Isothermal work done in Nm\n",
    "print \"Isothermal work done = %0.2f Nm\"%isoWd\n",
    "etaiso=isoWd/Wd#...............#Isothermal efficiency\n",
    "print \"Isothermal efficiency = %0.2f %%\"%(etaiso*100)\n",
    "wdss=((n)/(n-1))*p1*V*10**5*(((pd/p1)**((n-1)/(n)))-1)#..........#Single stage Work done per min in Nm\n",
    "print \"Single stage work done per min = %0.2f Nm\"%wdss\n",
    "perws=(wdss-Wd)/wdss#.......#Percentage of work saved\n",
    "print \"Percentage of work saved : %0.2f %%\"%(perws*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.28 PAGE 772"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "Intermediate pressures: \n",
      "  p2 = 3.30\n",
      "  p3 = 10.90\n",
      "\n",
      "Indicated power required = 101.19 kW\n"
     ]
    }
   ],
   "source": [
    "# Initialisation of Variables\n",
    "p1=1#.............#Intake pressure in bar\n",
    "p4=36#........#Final pressure in bar\n",
    "n=1.25#.........#Compression index\n",
    "R=0.287#.......#Gas constant in kJ/kgK\n",
    "t1=300#..........#Intake temperature in K\n",
    "ns=3#...........#No of stages\n",
    "v=15#..........#Volume of air delivered in m**3\n",
    "#Calculations\n",
    "p2=p1*((p4/p1)**(1/ns))#\n",
    "p3=p2*((p4/p1)**(1/ns))#\n",
    "print \"\\n\\nIntermediate pressures: \\n  p2 = %0.2f\\n  p3 = %.2f\\n\"%(p2,p3)\n",
    "t2=t1*((p4/p1)**(((n-1)/n)*(1/ns)))#....#Delivery temperature  in K\n",
    "m=p1*10**5*v/(R*1000*t1)#...........#Mass of air handled per min in kg\n",
    "Wt=((n/(n-1))*m*R*(1/60)*(t2-t1)*ns)#........#Total work done in three stages \n",
    "print \"Indicated power required = %0.2f kW\"%Wt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.29 PAGE 772"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Heat rejected in intercooler after first stage = 1276.59 kJ/min\n",
      "Heat rejected in intercooler after second stage = 1639.45 kJ/min\n",
      "Heat rejected in intercooler after third stage = 1875.18 kJ/min\n",
      "Diameter of the intermediate cylinder = 179.48 mm\n",
      "Diameter of the intermediate cylinder = 87.59 mm\n",
      "Shaft power = 142.68 kW\n",
      "\n",
      "Heat transferred during first stage = 455.70 kJ/min\n",
      "\n",
      "Heat transferred during second stage = 438.71 kJ/min\n",
      "\n",
      "Heat transferred during third stage = 334.22 kJ/min\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "ns=3#........#No of stages\n",
    "N=200#.......#Compressor rpm\n",
    "p1=1#.......#Intake pressure in bar\n",
    "t1=20+273#....#Intake temperature in K\n",
    "D=0.35#......#Engine bore in m\n",
    "L=0.4#.......#Engine stroke in m\n",
    "p2=4#........#Discharge pressure from first stage in bar\n",
    "p6=16#........#Discharge pressure from second stage in bar\n",
    "p10=64#........#Discharge pressure from third stage in bar\n",
    "pd=0.2#........#Loss of pressure between intercoolers in bar\n",
    "R=0.287#......#Gas constant in kJ/kgK\n",
    "k=0.04#.......#Clearence volume in 4% of the stroke volume\n",
    "n1=1.2#.....#Compressor index for first stage\n",
    "n2=1.25#.....#Compressor index for second stage\n",
    "n3=1.3#.....#Compressor index for third stage\n",
    "cp=1.005#......#Specific heat at constant pressure in kJ/kgK\n",
    "etamech=0.8#.....#Mechanical efficiency\n",
    "#Calculations\n",
    "p5=p2-pd#\n",
    "p9=p6-pd#\n",
    "t5=t1#\n",
    "t9=t1#\n",
    "Vs=(pi/4)*D*D*L*N*2#............#Swept volume of low pressure cylinder per min in m**3\n",
    "etav1=(1+k)-(k*((p2/p1)**(1/n1)))#.....#Volumetric efficiency in first stage\n",
    "etav2=(1+k)-(k*((p6/p5)**(1/n2)))#.....#Volumetric efficiency in second stage\n",
    "etav3=(1+k)-(k*((p10/p9)**(1/n3)))#.....#Volumetric efficiency in third stage\n",
    "vain1=Vs*etav1#.................#Volume of air taken in first stage in m**3/min\n",
    "m=(p1*10**5)*vain1/(R*t1*1000)#...........#Mass of air intake in kg/min in first stage\n",
    "t2=round(t1*((p2/p1)**((n1-1)/n1)))#\n",
    "t6=t5*((p6/p5)**((n2-1)/n2))#\n",
    "t10=t9*((p10/p9)**((n3-1)/n3))#\n",
    "Qr1=m*cp*(t2-t5)#........#Heat rejected in intercooler after first stage in kJ/min\n",
    "Qr2=m*cp*(t6-t9)#........#Heat rejected in intercooler after second stage in kJ/min\n",
    "Qr3=m*cp*(t10-t1)#........#Heat rejected in intercooler after third stage in kJ/min\n",
    "print \"Heat rejected in intercooler after first stage = %0.2f kJ/min\"%Qr1\n",
    "print \"Heat rejected in intercooler after second stage = %0.2f kJ/min\"%Qr2\n",
    "print \"Heat rejected in intercooler after third stage = %0.2f kJ/min\"%Qr3\n",
    "vainip=m*R*t5*1000/(p5*10**5)#.........#Volume drawn in intermediate pressure cylinder/min\n",
    "Vsip=vainip/etav2#.............#Swept volume of intermediate cylinder in m**3/min\n",
    "Dip=sqrt(Vsip/(2*N*L*(pi/4)))#............#Diameter of the intermediate cylinder in m\n",
    "print \"Diameter of the intermediate cylinder = %0.2f mm\"%(Dip*1000)\n",
    "vainhp=m*R*t9*1000/(p9*10**5)#.........#Volume drawn in high pressure cylinder/min\n",
    "Vshp=vainhp/etav3#.............#Swept volume of high pressure cylinder in m**3/min\n",
    "Dhp=sqrt(Vshp/(2*N*L*(pi/4)))#............#Diameter of the intermediate cylinder in m\n",
    "print \"Diameter of the intermediate cylinder = %0.2f mm\"%(Dhp*1000)\n",
    "Ps=(((n1/(n1-1))*m*R*(t2-t1))+((n2/(n2-1))*m*R*(t6-t5))+((n3/(n3-1))*m*R*(t10-t9)))*(1/(60*etamech))#...#Shaft power in kW\n",
    "print \"Shaft power = %0.2f kW\"%Ps\n",
    "cv=cp-R#..........#Specific heat at constant volume in kJ/kgK\n",
    "ga=cp/cv#...........#Ratio of specific heats\n",
    "Qt1=cv*((ga-n1)/(ga-1))*(t2-t1)*m#............#Heat transfer during first stage in kJ/min\n",
    "Qt2=cv*((ga-n2)/(ga-1))*(t6-t1)*m#............#Heat transfer during second stage in kJ/min\n",
    "Qt3=cv*((ga-n3)/(ga-1))*(t10-t1)*m#............#Heat transfer during third stage in kJ/min\n",
    "print\"\\nHeat transferred during first stage = %0.2f kJ/min\"%(Qt1)\n",
    "print \"\\nHeat transferred during second stage = %0.2f kJ/min\"%(Qt2)\n",
    "print \"\\nHeat transferred during third stage = %0.2f kJ/min\"%(Qt3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.30 PAGE 773"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "No of stages : 4\n",
      "Exact stage pressure ratio : 3.34\n",
      "\n",
      "Intermediate pressures\n",
      "p4=37.38\n",
      "p3=10.90\n",
      "p2=4.00\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "p1=1#.....#Intake pressure in bar\n",
    "p5=125#.....#Pressure of the compressed air in bar\n",
    "rpr=4#.........#Pressure ratio is restricted to 4\n",
    "#Calculations\n",
    "X=(log(p5/p1)/log(rpr))#\n",
    "if(X>round(X)):\n",
    "    x=round(X)+1#\n",
    "else:\n",
    "    x=round(X)#\n",
    "print \"No of stages : %d\"%x\n",
    "esrp=(p5/p1)**(1/x)#\n",
    "print \"Exact stage pressure ratio : %0.2f\"%esrp\n",
    "p4=p5/esrp#p3=p4/esrp#p2=p3/esrp#......#Intermediate pressures in bar\n",
    "print \"\\nIntermediate pressures\\np4=%.2f\\np3=%.2f\\np2=%.2f\"%(p4,p3,p2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.31 PAGE 774"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "No of stages: 4\n",
      "Total work done = 512.24 kJ/kg\n",
      "Heat rejected in intercoolers = 254.23 kJ/kg\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "ps=1#.........#Suction pressure in bar\n",
    "t1=273+125#.......#Delivery temperature in K\n",
    "pd=160#...........#Delivery pressure in bar\n",
    "tm=40+273#........#Min temperature\n",
    "ts=298#........#Suction temperature in K\n",
    "n=1.25#......#Adiabatic index\n",
    "cv=0.71#.......#Specific heat at constant volume in kJ/kgK\n",
    "R=0.287#......#Gas constant in kJ/kgK\n",
    "ns=3#.......#No of stages\n",
    "#Calculations\n",
    "p1=ps*((t1/ts)**(n/(n-1)))#\n",
    "x=(log(pd/p1))/(((n/(n-1))*(log(t1/tm))))#\n",
    "print \"No of stages: %d\"%(round(x)+1)\n",
    "rp1=p1#...........#Pressure ratio in 1st stage\n",
    "rp=(pd/rp1)**(1/ns)#.........#Pressure ratio in the following stage\n",
    "W=(n/(n-1))*R*ts*(((rp1)**((n-1)/n))-1)#.........#Work done in first stage in kJ\n",
    "Wf=ns*(n/(n-1))*R*tm*(((rp)**((n-1)/n))-1)#.........#Work done in next three stages in kJ\n",
    "wt=W+Wf#............#Total work done per kg in kJ\n",
    "print \"Total work done = %0.2f kJ/kg\"%wt\n",
    "cp=cv+R#..............#Specific heat at constant pressure in kJ/kgK\n",
    "Qr=ns*cp*(t1-tm)#.............#Heat rejected in intercoolers in kJ/kg\n",
    "print \"Heat rejected in intercoolers = %0.2f kJ/kg\"%Qr"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.32 PAGE 775"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Swept capacity of low pressure cylinder = 0.12 m**3\n",
      "Swept capacity of intermediate pressure cylinder = 0.03 m**3\n",
      "Swept capacity of intermediate pressure cylinder = 0.01 m**3\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "Vamb=10.5#........#Free air volume in m**3\n",
    "Pamb=1.013#...........#Free air presssure in bar\n",
    "Tamb=273+15#..........#Free air temperature in K\n",
    "T1=(273+25)#...........#Temperature at the end of suction in all cylinders in K\n",
    "P1=1#............#Pressure at the suction in bar\n",
    "pd=95#...........#Delivery presssure in bar\n",
    "N=100#.........#Compressor rpm\n",
    "n=1.25#..........#Adiabatic index\n",
    "k=0.04#.........#Fractional clearances for LP\n",
    "k1=0.07#.........#Fractional clearances for HP\n",
    "#Calculations\n",
    "z=(pd/P1)**(1/3)#.........#Pressure ratio\n",
    "pi1=z*P1#\n",
    "pi2=z*pi1#\n",
    "etavollp=1+k-(k*(z**(1/n)))#\n",
    "etavolhp=1+k1-(k1*(z**(1/n)))#\n",
    "v1=(Pamb*Vamb*T1)/(Tamb*P1)#\n",
    "sclp=(round(v1))/(etavollp*N)#.........#Swept capacity of LP cylinder in m**3\n",
    "print \"Swept capacity of low pressure cylinder = %0.2f m**3\"%sclp\n",
    "vip=(Pamb*Vamb*T1)/(pi1*Tamb)#.........#Volume of free air reduced to suction conditions of IP cylinder\n",
    "scip=vip/(etavolhp*N)#.........#Swept capacity of IP cylinder in m**3\n",
    "print \"Swept capacity of intermediate pressure cylinder = %0.2f m**3\"%scip\n",
    "vhp=(Pamb*Vamb*T1)/(pi2*Tamb)#.........#Volume of free air reduced to suction conditions of HP cylinder\n",
    "schp=vhp/(etavolhp*N)#.........#Swept capacity of HP cylinder in m**3\n",
    "print \"Swept capacity of intermediate pressure cylinder = %0.2f m**3\"%schp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.34 PAGE 776"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Temperature at the end of expansion = 244.63 K\n",
      "Indicated power of the motor = 0.75 kW\n",
      "Mass of air supplied per min = 0.42 kg\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "D=0.0635#.......#Engine bore in m\n",
    "L=0.114#.........#Engine stroke in m\n",
    "p1=6.3#..........#Supply pressure in bar\n",
    "t1=273+24#.........#Supply temperature in K\n",
    "p4=1.013#..........#Exhaust pressure in bar\n",
    "cv=0.05#............#Clearance volume is 5% of the swept volume\n",
    "cr=0.5#..........#Cut off ratio\n",
    "n=1.3#...........#Adiabatic index\n",
    "R=287#...............#gas constant in kJ/kgK\n",
    "N=300#.............#Engine rpm\n",
    "ga=1.4#...........#Ratio of specific heats\n",
    "#Calculations\n",
    "Vs=(pi*D*D*L)/4#........#Swept volume in m**3\n",
    "Vc=cv*Vs#..........#Clearance volume in m**3\n",
    "v6=Vc#\n",
    "v5=v6#\n",
    "v1=(Vs/2)+Vc#\n",
    "v2=Vs+Vc#\n",
    "v3=v2#\n",
    "p3=p4#\n",
    "v4=v5+(cv*Vs)#\n",
    "p2=p1*((v1/v2)**n)#.......#Pressure at the end of expansion\n",
    "t2=t1*((v1/v2)**(n-1))#........#Temperature at the end of expansion in K\n",
    "print \"Temperature at the end of expansion = %0.2f K\"%t2\n",
    "p5=p4*((v4/v5)**n)#\n",
    "w=((p1*(v1-v6))+(((p1*v1)-(p2*v2))/(n-1))-(p3*(v3-v4))-(((p5*v5)-(p4*v4))/(n-1)))*10**5#.......#Workk done per cycle in Nm\n",
    "IP=(w*N)/(60*1000)#..........#Indicated power in kW\n",
    "print \"Indicated power of the motor = %0.2f kW\"%IP\n",
    "t3=t2*((p3/p2)**((ga-1)/ga))#\n",
    "t4=t3#\n",
    "m4=(p4*v4*10**5)/(R*t4)#\n",
    "m1=(p1*v1*10**5)/(R*t1)#\n",
    "ma=(m1-m4)*N#..........#Mass of air supplied per min\n",
    "print \"Mass of air supplied per min = %0.2f kg\"%ma"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.35 PAGE 777"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Work input for roots compressor = 1.52 kJ/rev\n",
      "Work input for vane compressor = 1.35 kJ/rev\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "v=0.03#..............#Induced volume in m**3/rev\n",
    "p1=1.013#...........#Inlet pressure in bar\n",
    "rp=1.5#............#Pressure ratio\n",
    "ga=1.4#...........#Ratio of specific heats\n",
    "#Calculations\n",
    "p2=rp*p1#\n",
    "wr=(p2-p1)*(10**5)*v/1000#.....#Work input for roots compressor in kJ\n",
    "print \"Work input for roots compressor = %0.2f kJ/rev\"%wr\n",
    "pi=(p2+p1)/2#\n",
    "wv=((p2-pi)*(10**5)*v*((p1/pi)**(1/ga))*(1/1000))+((ga/(ga-1))*p1*(10**5)*(v/1000)*(((pi/p1)**((ga-1)/ga))-1))#...#Work input required for vane type in kJ/rev\n",
    "print \"Work input for vane compressor = %0.2f kJ/rev\"%wv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.36 PAGE 778"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Compressor efficiency = 85.98 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "v=0.08#.........#Volume of air compressed in m**3\n",
    "p1=1#..........#Intake pressure in bar\n",
    "p2=1.5#........#Pressure after compression in in bar\n",
    "ga=1.4#.........#Ratio of specific heats\n",
    "#Calculations\n",
    "wac=v*(p2-p1)*10**5#........#Actual work done in Nm\n",
    "wid=(ga/(ga-1))*p1*v*(10**5)*(((p2/p1)**((ga-1)/ga))-1)#...........#Ideal work done per revolution in Nw\n",
    "etac=wid/wac#................#Compressor efficiency\n",
    "print \"Compressor efficiency = %0.2f %%\"%(etac*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.37 PAGE 778"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Isentropic efficiency = 74.46 %\n",
      "Power required to drive the coompressor = 190.69 kW\n",
      "Overall efficiency = 72.92 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "m=2.5#..........#Air flow rate in kg/s\n",
    "p1=1#........#Inlet pressure in bar\n",
    "t1=290#............#Inlet temperature in bar\n",
    "C1=80#..........#Inlet Velocity in m/s\n",
    "p2=1.5#........#pressure after compression in bar\n",
    "t2=345#............#temperature after compression in bar\n",
    "C2=220#..........#Velocity after compression in m/s\n",
    "cp=1.005#...........#Specific heat at constant pressure in kJ/kgK\n",
    "ga=1.4#............#Ratio of specific heats\n",
    "R=287#..............#Gas constant for air in kJ/kgK\n",
    "#Calculations\n",
    "t21=t1*((p2/p1)**((ga-1)/ga))#\n",
    "wisen=cp*(t21-t1)+((C2*C2)-(C1*C1))/(2*1000)#.....#Isentropic work done in kJ/kg\n",
    "w=cp*(t2-t1)+((C2*C2)-(C1*C1))/(2*1000)#.....#Actual work done (in impeller) in kJ/kg\n",
    "etaisen=wisen/w#...............#Isentropic efficiency\n",
    "print \"Isentropic efficiency = %0.2f %%\"%(etaisen*100)\n",
    "P=m*w#..........#Power required to drive the coompressor in kW\n",
    "print \"Power required to drive the coompressor = %0.2f kW\"%P\n",
    "t3=(((C2*C2)-(C1*C1))/(2*1000*cp))+t2#....#Temperature of air after leaving the diffuser in K\n",
    "p3=p2*((t3/t2)**(ga/(ga-1)))#..........#Pressure of air after leaving the diffuser in bar\n",
    "t31=t1*((p3/p1)**((ga-1)/ga))#...........#Delivery temperature from diffuser in K\n",
    "etao=(t31-t1)/(t3-t1)#...............#Overall efficiency \n",
    "print \"Overall efficiency = %0.2f %%\"%(etao*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.38 PAGE 779"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Actual rise in temperature = 165.00\n",
      "Tip diameter of the impeller = 40.99 cm\n",
      "Power required = 1459.26 kW\n",
      "Diameter of the eye = 28.17 cm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "ma=528#.............#Air flow in kg/min\n",
    "m=ma/60#.............#Air flow in kg/s\n",
    "p1=1#........#Inlet pressure in bar\n",
    "t1=293#............#Inlet temperature in bar\n",
    "N=20000#..............#Compressor rpm\n",
    "etaisen=0.8#.........#Isentropic efficiency\n",
    "po1=1#.........#Static pressure in bar\n",
    "p02=4#...........#Final total pressure in bar\n",
    "C1=145#.........#Velocity of air when entering the impeller in m/s\n",
    "rwt=0.9#..........#Ratio of whirl speed to tip speed \n",
    "dh=0.12#........#Hub diameter in m\n",
    "cp=1.005#...........#Specific heat at constant pressure in kJ/kgK\n",
    "ga=1.4#............#Ratio of specific heats\n",
    "R=287#..............#Gas constant for air in kJ/kgK\n",
    "#Calculations\n",
    "t01=t1+((C1*C1)/(2*cp*1000))#..........#Stagnation temperature at the inlet to the machine in K\n",
    "p01=p1*((t01/t1)**(ga/(ga-1)))#.....#Stagnation pressure at the inlet to the machine in bar\n",
    "t021=t01*((p02/p01)**((ga-1)/ga))#\n",
    "deltisen=t021-t01#.........#Isentropic rise in temperature in K\n",
    "delt=round(deltisen/etaisen)#........#Actual rise in temperature \n",
    "print \"Actual rise in temperature = %0.2f\"%delt\n",
    "wc=cp*delt#.........#Work consumed by compressor in kJ/kg\n",
    "Cbl2=sqrt(wc*1000/rwt)#\n",
    "d2=Cbl2*60/(pi*N)#..........#Tip diameter of the impeller in m\n",
    "print \"Tip diameter of the impeller = %0.2f cm\"%(d2*100)\n",
    "P=m*wc#............#Power required in kW\n",
    "print \"Power required = %0.2f kW\"%P\n",
    "rho1=(p1*10**5)/(R*t1)#.......#Density at entry in kg/m**3\n",
    "d1=sqrt(((m*4)/(C1*rho1*pi))+(dh**2))#.......#Eye diameter in m\n",
    "print \"Diameter of the eye = %0.2f cm\"%(d1*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.39 PAGE 780"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Final temperature of air = 466.65 Kevin\n",
      "Theoretical power = 2282.94 kW\n",
      "Impeller diameter at outlet = 84.10 cm\n",
      "Impeller diameter at inlet = 42.05 cm\n",
      "Breadth of impeller at inlet = 14.92 cm\n",
      "Impeller blade angle at inlet = 15.73 degrees\n",
      "Diffuser blade angle at inlet = 8.89 degrees\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt,atan\n",
    "# Initialisation of Variables\n",
    "N=10000#.................#Compressor rpm\n",
    "v=660#............#Volume of air delivered in m**3/min\n",
    "p1=1#.................#Inlet pressure in bar\n",
    "t1=293#.............#Inlet temperature in K\n",
    "rp=4#.............#Pressure ratio\n",
    "etaisen=0.82#........#Isentropic efficiency\n",
    "Cf2=62#...............#Flow velocity in m/s\n",
    "rr=2#.............#Ratio of outer radius of impeller to inner radius of impeller\n",
    "ka=0.9#..............#Blade area co efficient\n",
    "fis=0.9#...........#Slip factor\n",
    "cp=1.005#..............#Specific heat at constant pressure in kJ/kgK\n",
    "ga=1.4#............#Ratio of specific heats\n",
    "R=287#..............#Gas constant for air in kJ/kgK\n",
    "#Calculations\n",
    "t21=t1*(rp**((ga-1)/ga))#\n",
    "Cf1=Cf2#\n",
    "t2=t1+((t21-t1)/etaisen)#..........#Final temperature of air\n",
    "m=(p1*10**5*v/60)/(R*t1)#...............#Mass flow rate in m**3/s\n",
    "P=m*cp*(t2-t1)#.........#Theoretical power in kW\n",
    "print \"Final temperature of air = %0.2f Kevin\"%t2\n",
    "print \"Theoretical power = %0.2f kW\"%P\n",
    "Cbl2=sqrt(1000*cp*(t2-t1)/fis)#\n",
    "d2=60*Cbl2/(pi*N)#..........#Impeller diameter at outlet in m\n",
    "d1=d2/rr#...............#Impeller diameter at inlet in m\n",
    "print \"Impeller diameter at outlet = %0.2f cm\"%(d2*100)\n",
    "print \"Impeller diameter at inlet = %0.2f cm\"%(d1*100)\n",
    "b1=(v/60)/(2*pi*(d1/2)*Cf1*ka)#.........#Breadth of impeller at inlet in m\n",
    "print \"Breadth of impeller at inlet = %0.2f cm\"%(b1*100)\n",
    "Cbl1=Cbl2/rr#\n",
    "beta1=(atan(Cf1/Cbl1))*180/pi#\n",
    "al2=(atan(Cf2/(fis*Cbl2)))*180/pi#\n",
    "print \"Impeller blade angle at inlet = %0.2f degrees\"%(beta1)\n",
    "print \"Diffuser blade angle at inlet = %0.2f degrees\"%(al2,)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.40 PAGE 780"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Blade angles  \n",
      "\n",
      "\t Blade angle at the inlet of the impeller: beta 1=25.869916 \n",
      "\t Blade angle at the outlet of the impeller: beta 2=34.206408 \n",
      "\t Absolute angle at the tip of impeller: alpha 2=21.610499\n",
      "\n",
      "\n",
      "Breadth of the blade at inlet = 7.35 cm\n",
      "Breadth of the blade at outlet = 2.89 cm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt,atan\n",
    "# Initialisation of Variables\n",
    "v1=4.8#......#Volume of air compressed in m**3/s\n",
    "p1=1#....#Inlet pressure in bar\n",
    "t1=293#........#Inlet pressure in K\n",
    "n=1.5#........#Compression index\n",
    "Cf1=65#......#Air flow velocity at inlet in m/s\n",
    "Cf2=Cf1#......#Flow velocity is same at inlet and outlet\n",
    "d1=0.32#..........#Inlet impeller diameter in m\n",
    "d2=0.62#........#Outlet impeller diameter in m\n",
    "N=8000#........#Blower rpm\n",
    "cp=1.005#......#Specific heat at constant pressure in kJ/kgK\n",
    "#Calculations\n",
    "t21=t1*((n/p1)**((n-1)/n))#....#Temperature at the outlet of compressor in K\n",
    "Cbl1=(pi*d1*N)/60#......#Peripheral velocity at inlet in m/s\n",
    "Cbl2=(pi*N*d2)/60#......#Tip peripheral velocity at outlet in m/s\n",
    "Cw2=(cp*(t21-t1)*1000)/Cbl2#\n",
    "be1=(atan(Cf1/Cbl1))*180/pi#\n",
    "be2=(atan(Cf2/(Cbl2-Cw2)))*180/pi#......#Blade angles at the tip of the impeller\n",
    "al2= (atan(Cf2/Cw2))*180/pi# \n",
    "print \"\\nBlade angles  \\n\\n\\t Blade angle at the inlet of the impeller: beta 1=%f \\n\\t Blade angle at the outlet of the impeller: beta 2=%f \\n\\t Absolute angle at the tip of impeller: alpha 2=%f\\n\\n\"%(be1,be2,al2)\n",
    "b1=v1/(2*pi*(d1/2)*Cf1)#........#Breadth of blade at inlet in m\n",
    "print \"Breadth of the blade at inlet = %0.2f cm\"%(b1*100)\n",
    "v2=(v1*t21*p1)/(n*t1)#..............#Discharge at the outlet in m**3/s\n",
    "b2=v2/(2*pi*(d2/2)*Cf2)#........#Breadth of blade at outlet in m\n",
    "print \"Breadth of the blade at outlet = %0.2f cm\"%(b2*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.41 PAGE 781"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Diameter of the impeller = 0.56 m\n",
      "Power input to compressor = 2951.61 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "m=16.5#.......#Air flow in kg/s\n",
    "rp=4#........#Pressure ratio\n",
    "N=15000#.........#Compressor rpm\n",
    "t01=293#.........#Inlet head temperature\n",
    "fis=0.9#...........#Slip factor\n",
    "fiw=1.04#.........#Power input factor\n",
    "etaisen=0.8#.......#Isentropic efficiency\n",
    "cp=1.005#........#Specific heat at constant pressure in kJ/kgK\n",
    "ga=1.4#......#Ratio of specific heats\n",
    "#Calculations\n",
    "t021=t01*(rp**((ga-1)/ga))#\n",
    "delt=(t021-t01)/etaisen#\n",
    "Cbl2=sqrt((1000*cp*delt)/(fiw*fis))#\n",
    "D=(60*Cbl2)/(pi*N)#..............#Diameter of impeller\n",
    "print \"Diameter of the impeller = %0.2f m\"%D\n",
    "P=m*cp*delt#\n",
    "print \"Power input to compressor = %0.2f kW\"%P"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.42 PAGE 781"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Total head temperature = 447.09 K\n",
      "Static temperature at outlet = 439.93 K\n",
      "Static pressure at exit = 3.45 bar\n",
      "Static temperature at inlet = 278.25 K\n",
      "Static pressure at inlet = 0.90 bar\n",
      "Static pressure ratio : 3.8237\n",
      "Work done on air = 159.89 kJ/kg\n",
      "Power required to drive the compressor = 1918.67 kW\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# Initialisation of Variables\n",
    "rp=3.6#..........#Pressure ratio\n",
    "die=0.35#.......#Diameter of inlet eye of compressor in m\n",
    "Cf=140#..........#Axial velocity in m/s\n",
    "m=12#.............#Mass flow in kg/s\n",
    "Cbl2=120#.........#Velocity in the delivery duct in m/s\n",
    "Ci=460#..........#The tip speed of the impeller in m/s\n",
    "N=16000#............#Speed of impeller in rpm\n",
    "etaisen=0.8#.......#Isentropic efficiency\n",
    "pc=0.73#........#Pressure co efficient\n",
    "pa=1.013#..........#Ambient pressure in bar\n",
    "ta=273+15#................#Ambient temperature in K\n",
    "ga=1.4#..........#Ratio of specific heats\n",
    "cp=1.005#.........#Specific heat at constant pressure in kJ/kgK\n",
    "R=0.287#........#Gas constant in kJ/kgK\n",
    "#Calculations\n",
    "delt=((ta*((rp**((ga-1)/ga))-1))/etaisen)#.......#Rise in temperature\n",
    "t02=ta+delt#............#Total head temperature in K\n",
    "print \"Total head temperature = %0.2f K\"%t02\n",
    "t2=t02-((Cbl2*Cbl2)/(2*cp*1000))#..........#Static temperature at outlet in K\n",
    "print \"Static temperature at outlet = %0.2f K\"%t2\n",
    "p02=pa*rp#\n",
    "p2=p02/(1+((Cbl2*Cbl2)/(2*R*t2*1000)))#...........#Static pressure at exit in bar\n",
    "print \"Static pressure at exit = %0.2f bar\"%p2\n",
    "t1=ta-((Cf*Cf)/(2*cp*1000))#.............#Static temperature at inlet in K\n",
    "print \"Static temperature at inlet = %0.2f K\"%t1\n",
    "p1=pa/(1+((Cf*Cf)/(2*R*t1*1000)))#...........#Static pressure at inlet in bar\n",
    "print \"Static pressure at inlet = %0.2f bar\"%p1\n",
    "rp=p2/p1#.....#Static pressure ratio\n",
    "print \"Static pressure ratio : %0.4f\"%rp\n",
    "W=cp*delt#...........#Work done on air in kJ/kg of air\n",
    "print \"Work done on air = %0.2f kJ/kg\"%W\n",
    "P=m*cp*delt#..........#Power required to drive the compressor in kW\n",
    "print \"Power required to drive the compressor = %0.2f kW\"%P"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.43 PAGE 782"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Temperature rise of air while passing through compressor: 159.09 \n",
      "Pressure ratio : 3.8237\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Initialisation of Variables\n",
    "t1=300#.........#Inlet temperature in K\n",
    "N=18000#.............#Compressor rpm\n",
    "etaisen=0.76#.......#Isentropic efficiency\n",
    "od=0.55#......#Outer diameter of blade tip\n",
    "sf=0.82#......#Slip factor\n",
    "cp=1.005#.........#Specific heat capacity at constant pressure in kJ/kgK\n",
    "ga=1.4#.............#Ratio of specific heats\n",
    "#Calculations\n",
    "Cbl2=(pi*od*N)/60#W=Cbl2*Cbl2*sf/1000#...........#Work done per kg of air in kW\n",
    "delt=W/cp#..............#Temperature rise of air while passing through compressor \n",
    "print \"Temperature rise of air while passing through compressor: %0.2f \"%delt\n",
    "t21=(etaisen*delt)+t1#rp=((t21/t1)**(ga/(ga-1)))#.....#Pressure ratio\n",
    "print \"Pressure ratio : %0.4f\"%rp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.44 PAGE 782"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Pressure rise = 0.15 bar\n",
      "Work done per kg of air = 27.54 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt,tan\n",
    "# Initialisation of Variables\n",
    "Cbl=240#........#Mean blade velocity in m/s\n",
    "Cf=190#.........#Air flow velocity in m/s\n",
    "al1=45#\n",
    "al2=14#.........#Blade angels in degrees\n",
    "rho=1#.........#Density of air in kg/m**3\n",
    "#Calculations \n",
    "pr=(1/2)*(rho*Cf*Cf/(10**5))*(((tan(al1*pi/180))**2)-((tan(al2*pi/180))**2))#.......#Pressure rise in bar\n",
    "print \"Pressure rise = %0.2f bar\"%pr\n",
    "W=Cbl*Cf/1000*((tan(al1*pi/180))-(tan(al2*pi/180)))#.............#Work done per kg of air in kW\n",
    "print \"Work done per kg of air = %0.2f kW\"%W"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.45 PAGE 783"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Work done by the machine = 174.52 kJ/kg\n",
      "\n",
      "Blade angels are as follows (In degrees)\n",
      "\n",
      "alpha1=18.091622\tbeta1=59.136727\n",
      "\n",
      "alpha2=59.136727\tbeta2=18.091622\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt,atan\n",
    "# Initialisation of Variables\n",
    "etaisen=0.82#.......#Overall isentropic efficiency \n",
    "N=8#............#No of stages\n",
    "t1=293#...........#Inlet temperature in K\n",
    "ga=1.4#............#Ratio of specific heats\n",
    "rp=4#.............#Pressure ratio\n",
    "Rd=0.5#................#Reaction factor\n",
    "Cbl=180#.................#Mean blade speed in m/s\n",
    "Cf=90#...............#Air flow velocity in m/s\n",
    "cp=1.005#.........#Specific heat at constant pressure in kJ/kgK\n",
    "#Calculations\n",
    "t21=t1*(rp**((ga-1)/ga))#\n",
    "t2=((t21-t1)/etaisen)+t1#\n",
    "wrt=cp*(t2-t1)#.........#Work done by the machine in kJ/kg\n",
    "print \"Work done by the machine = %0.2f kJ/kg\"%wrt\n",
    "be1=atan(((cp*(t2-t1)*1000/(Cf*Cbl*N))+(Cbl/Cf))/2)*180/pi#\n",
    "al1=atan((Cbl/Cf)-tan(be1*pi/180))*180/pi#\n",
    "print \"\\nBlade angels are as follows (In degrees)\\n\\nalpha1=%f\\tbeta1=%f\\n\\nalpha2=%f\\tbeta2=%f\\n\\n\"%(al1,be1,be1,al1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.46 PAGE 784"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Flow velocity = 95.45 m/s\n",
      "No of stages :  8.0\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt,tan\n",
    "# Initialisation of Variables\n",
    "etaisen=0.85#.......#Overall isentropic efficiency\n",
    "t1=293#...........#Inlet temperature in K\n",
    "rp=4#.............#Pressure ratio\n",
    "Rd=0.5#................#Reaction factor\n",
    "Cbl=180#.................#Mean blade speed in m/s\n",
    "wip=0.82#..............#Work input factor\n",
    "al1=12#\n",
    "be1=42#......#Blade angels in degrees\n",
    "ga=1.4#............#Ratio of specific heats  \n",
    "cp=1.005#.........#Specific heat at constant pressure in kJ/kgK\n",
    "#Calculations\n",
    "t21=t1*(rp**((ga-1)/ga))#\n",
    "t2=((t21-t1)/etaisen)+t1#\n",
    "wrt=cp*(t2-t1)#.........#Theoretical work required in kJ/kg\n",
    "Cf=Cbl/(tan(al1*pi/180)+tan(be1*pi/180))#\n",
    "Cw1=Cf*tan(al1*pi/180)#Cw2=Cf*tan(be1*pi/180)#\n",
    "wcps=Cbl*(Cw2-Cw1)*wip/1000#.............#Work consumed per stage in kJ/kg\n",
    "N=round(wrt/wcps)#.......#No of stages\n",
    "print \"Flow velocity = %0.2f m/s\"%Cf\n",
    "print \"No of stages : \",N"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.47 PAGE 784"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Blade angels are as follows (In degrees)\n",
      "\n",
      "alpha1=4.924070\t\tbeta1=59.410637\n",
      "\n",
      "alpha2=59.410637\tbeta2=4.924070\n",
      "\n",
      "\n",
      "Power required by the compressor = 184.95 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt,atan,tan\n",
    "# Initialisation of Variables\n",
    "rp=5#..........#Stagnation pressure ratio ga\n",
    "etaisen=0.92#.......#Overall isentropic efficiency\n",
    "t1=290#.............#Inlet stagnation temperature in K\n",
    "p1=1#...............#Inlet stagnation pressure in bar\n",
    "Cbl=160#...........#Mean blade speed in m/s\n",
    "ga=1.4#...........#Ratio of specific heats\n",
    "Rd=0.5#............#Degree of reaction\n",
    "Cf=90#................#Axial velocity of air through compressor in m/s\n",
    "N=8#.............#No of stages\n",
    "m=1#.........#Mass flow in kg/s\n",
    "cp=1.005#............#Specific heat at constant pressure in kJ/kgK\n",
    "#Calculations\n",
    "tN1=t1*(rp**((ga-1)/ga))#......#Temperature at the end of compression stage due to isentropic expansion in K\n",
    "tN=((tN1-t1)/etaisen)+t1#\n",
    "be1=atan(((cp*(tN-t1)*1000/(Cf*Cbl*N))+(Cbl/Cf))/2)*180/pi#\n",
    "al1=atan((Cbl/Cf)-tan(be1*pi/180))*180/pi#\n",
    "print \"\\nBlade angels are as follows (In degrees)\\n\\nalpha1=%f\\t\\tbeta1=%f\\n\\nalpha2=%f\\tbeta2=%f\\n\\n\"%(al1,be1,be1,al1)\n",
    "P=m*cp*(tN-t1)#..........#Power required by the compressor in kW\n",
    "print \"Power required by the compressor = %0.2f kW\"%P"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.48 PAGE 785"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Stagnation polytropic efficiency = 87.59 %\n",
      "No of stages :  27.0\n",
      "Inlet temperature = 295.35 K\n",
      "Inlet pressure = 0.95 bar\n",
      "Height of the blade in the first stage = 28.23 cm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt,cos,log,tan,atan\n",
    "# Initialisation of Variables\n",
    "rp=4#........#Stagnation pressure ratio\n",
    "etaisen=0.85#.....#Stagnation isentropic efficiency\n",
    "p1=1#.............#Inlet stagnation pressure in bar\n",
    "t1=300#...........#Inlet stagnation temperature in K\n",
    "Rd=0.5#............#Degree of reaction\n",
    "Cu=180#...........#Mean blade speed in m/s\n",
    "Wd=0.9#...........#Work done factor\n",
    "htr=0.42#.......#Hub tip ratio\n",
    "al1=12#\n",
    "be2=al1#.......#Relative air angle at rotor inlet in degrees\n",
    "al2=32#\n",
    "be1=al2#........#Relative air angle at rotor at outlet in degrees\n",
    "ga=1.4#...........#Ratio of specific heats\n",
    "cp=1.005#..........#Specific heat capacity at constant pressure in kJ/kgK\n",
    "R=287#..........#Gas constant in J/kgK\n",
    "m=19.5#..........#Mass flow in kg/s\n",
    "#Calculations\n",
    "tN1=t1*(rp**((ga-1)/ga))#......#Temperature at the end of compression stage due to isentropic expansion in K\n",
    "tN=((tN1-t1)/etaisen)+t1#\n",
    "etap=log(rp**((ga-1)/ga))/log(tN/t1)#...........#Stagnation polytropic efficiency\n",
    "print \"Stagnation polytropic efficiency = %0.2f %%\"%(etap*100)\n",
    "Cf=Cu/(tan(al1*pi/180)+tan(be1*pi/180))#\n",
    "Cw1=Cf*tan(al1*pi/180)\n",
    "Cw2=Cf*tan(al2*pi/180)#\n",
    "wcps=Cu*(Cw2-Cw1)*Wd/1000#.............#Work consumed per stage in kJ/kg\n",
    "wc=cp*(tN-t1)#...............#Work consumed by compressor in kJ/kg\n",
    "N=round(wc/wcps)#.......#No of stages\n",
    "print \"No of stages : \",N\n",
    "C1=Cf/cos(al1*pi/180)#.......#Absolute velocity at exit from guide vanes in m/s\n",
    "ti=t1-((C1*C1)/(2*cp*1000))#..........#Inlet temperature in K\n",
    "print \"Inlet temperature = %0.2f K\"%ti\n",
    "pi=p1*((ti/t1)**(ga/(ga-1)))#......#Inlet pressure in bar\n",
    "print \"Inlet pressure = %0.2f bar\"%pi\n",
    "rho1=(pi*10**5)/(R*ti)#.............#Density of air approaching the first stage\n",
    "r1=sqrt(m/(rho1*pi*Cf*(1-(htr**2))))#\n",
    "rh=r1*htr#\n",
    "l=r1-rh#............#Height of the blade in the first stage in m\n",
    "print \"Height of the blade in the first stage = %0.2f cm\"%(l*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 20.49 PAGE 785"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Delivery pressure = 5.57 bar\n",
      "No of stages :  11.0\n",
      "Overall efficiency = 84.86 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt,cos,log,tan,atan,exp\n",
    "# Initialisation of Variables\n",
    "ma=20#..........#Air flow rate in kg/s\n",
    "p1=1#.........#Inlet stagnation pressure in bar\n",
    "t1=290#.........#Inlet stagnation temperature in Kelvin\n",
    "t2=305#.........#Temperature at the end of first stage in K\n",
    "etapc=0.88#.....#Polytropic efficiency of compression\n",
    "P=4350#......#Power consumed by compressor in kW\n",
    "ga=1.4#.....#Ratio of specific heats\n",
    "cp=1.005#......#Specific heat at constant pressure \n",
    "#Calculations\n",
    "p2byp1=(exp(etapc*log(t2/t1)))**(ga/(ga-1))#\n",
    "tN=(P/(ma*cp))+t1#\n",
    "pN=p1*((tN/t1)**((etapc*ga)/(ga-1)))#......#Delivery pressure in bar\n",
    "print \"Delivery pressure = %0.2f bar\"%pN\n",
    "N=log(pN/p1)/log(p2byp1)#...........#No of stages \n",
    "print \"No of stages : \",round(N)\n",
    "tN1=t1*((pN/p1)**((ga-1)/ga))#\n",
    "etao=(tN1-t1)/(tN-t1)#...............#Overall efficiency\n",
    "print \"Overall efficiency = %0.2f %%\"%(etao*100)"
   ]
  }
 ],
 "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
}
