{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# CHAPTER 17 - Testing and performance of I.C. engines"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.1 PAGE 570"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated power developed = 13.30 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "Pmi=6#.....................#Mean effective pressure in bar\n",
    "N=1000#....................#Engine rpm\n",
    "d=0.11#.....................#Diameter of piston in m\n",
    "l=0.14#.....................#Stroke length in m\n",
    "n=1#........................#No of cylinders\n",
    "k=1#........................#k=1 for two stroke engine\n",
    "#Calculations\n",
    "V=l*(pi/4)*d*d#.............#Volume of the cylinder in m**3\n",
    "IP=(n*Pmi*V*k*10*N)/6#.........#Indicated Power developed in kW\n",
    "print \"Indicated power developed = %0.2f kW\"%IP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.2 PAGE 571"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The bore of the engine = 87.96 mm\n",
      "The stroke of the engine = 131.94 mm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=4#........................#No of cylinders\n",
    "P=14.7#....................#Power developed in kW\n",
    "N=1000#....................#Engine speed in rpm\n",
    "Pmi=5.5#....................#Mean effective pressure in bar\n",
    "lbyd=1.5#...................#Ratio of stroke to bore\n",
    "k=0.5#.......................#For four stroke engine\n",
    "#Calculations\n",
    "d=((P*6)/(n*Pmi*N*k*10*(pi/4)*lbyd))**(1/3)#......................#Calculation of bore in m\n",
    "l=lbyd*d#................................#Calculation of stroke in m\n",
    "print \"The bore of the engine = %0.2f mm\"%(d*1000)\n",
    "print \"The stroke of the engine = %0.2f mm\"%(l*1000)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.3 PAGE 572"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Brake Power = 2.51 KW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "Db=0.6#.....................#Diameter of the brake wheel in m\n",
    "d=0.026#......................#Diameter of the rope in m\n",
    "W=200#.......................#Dead load on the brake in N\n",
    "S=30#......................#Spring balance reading in N\n",
    "N=450#......................#Engine speed in rpm\n",
    "#Calculations\n",
    "BP=((W-S)*pi*(Db+d)*N)/(60*1000)#...............#Brake Power in KW\n",
    "print \"Brake Power = %0.2f KW\"%(BP)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.4 PAGE 572"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Since it is given that the stroke is equal to bore, their value is = 138.67 mm\n",
      "The engine displacement = 0.00 m**3\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=4#........................#No of cylinders\n",
    "k=0.5#......................#For four stroke engine\n",
    "Tb=160#.....................#Max brake torque in Nm\n",
    "N=3000#......................#Engine rpm\n",
    "Pm=9.6#....................#Brake mean effective pressure in bar\n",
    "#Calculations\n",
    "D=((2*pi*N*Tb*6)/(60*1000*Pm*(pi/4)*N*k*10))**(1/3)#.....................#Bore of engine in m\n",
    "L=D#...................#Given that the stroke is equal to bore\n",
    "Disp=(pi/4)*D*D*L#....................................#Displacement in m**3\n",
    "print \"Since it is given that the stroke is equal to bore, their value is = %0.2f mm\"%(D*1000)\n",
    "print \"The engine displacement = %0.2f m**3\"%(Disp)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.5 PAGE 572"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Since the stroke and bore are equal, their value is = 290.90 mm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=6#.....................#No of cylinders\n",
    "Pmb=6#....................#Brake mean effective pressure in bar\n",
    "N=1000#..................#Engine rpm\n",
    "k=0.5#.......................#For four stroke engine\n",
    "Wce=820#.................#Work during compression and expansion in kW\n",
    "Wie=50#...................#Work during intake and exhaust in kW\n",
    "f=150#......................#Rubbing friction in engiine in kW\n",
    "WnetT=40#...................#Net work done by turbine in kW\n",
    "#Calculations\n",
    "BP=Wce-(Wie+f+WnetT)#.....................#Net work available or brake power in kW\n",
    "D=((BP*6)/(n*Pmb*(pi/4)*N*k*10))**(1/3)#......................#Bore of engine in m\n",
    "L=D#.........................................#Given that bore is equal to stroke\n",
    "print \"Since the stroke and bore are equal, their value is = %0.2f mm\"%(D*1000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.6 PAGE 573"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ratio of the power input of the engine with methane fuel to that with octane : 1.12\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "Cm=50150#............................#Heating value of methane in kJ/kg\n",
    "Co=44880#............................#Heating value of octane in kJ/kg\n",
    "#Calculations\n",
    "#Since Energy supplied is proportional to mass of fuel supplied time calorific value of the fuel supplied\n",
    "ratioP=Cm/Co#.........................#Ratio of the power input of the engine with methane fuel to that with octane\n",
    "print \"Ratio of the power input of the engine with methane fuel to that with octane : %0.2f\"%ratioP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.7 PAGE 573"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Brake power = 250.00 kW\n",
      "Brake thermal efficiency = 33.07 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "N=2000#...........................#Engine rpm\n",
    "k=0.5#..............................#Four stroke engine\n",
    "Disp=0.025#........................#Engine displacement in m**3\n",
    "Pmb=6#..............................#Brake mean effective pressure in bar\n",
    "mf=0.018#............................#Fuel consumption in kg/s\n",
    "Cf=42000#............................#Calorific value of fuel in kJ/kg\n",
    "#Calcuations \n",
    "BP=(Pmb*Disp*N*k*10)/(6)#................#Brake power in kW\n",
    "etaBT=BP/(mf*Cf)#.................#Brake thermal efficiency\n",
    "print \"The Brake power = %0.2f kW\"%(BP)\n",
    "print \"Brake thermal efficiency = %0.2f %%\"%(etaBT*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.8 PAGE 574"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Brake power developed by engine = 9.16 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "T=175#.......................#Torque due to brake load in Nm\n",
    "N=500#.........................#Engine speed in rpm\n",
    "#calcuations\n",
    "BP=(2*pi*N*T)/(60*1000)#.......................#Brake power developed by engine in kW\n",
    "print \"Brake power developed by engine = %0.2f kW\"%(BP)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.9 PAGE 575"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated power = 47.71 kW\n",
      "Brake power = 42.88 kW\n",
      "Mechanical efficiency = 89.88 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "D=0.3#.............................#Bore of engine cylinder in m\n",
    "L=0.45#............................#Stroke of engine cylinder in m\n",
    "N=300#.............................#Engine rpm\n",
    "Pmi=6#.............................#Indicated mean effective pressure in bar\n",
    "Nbl=1.5#...........................#Net brake load in kN\n",
    "Db=1.8#............................#Diameter of brake drum in m\n",
    "d=0.02#............................#Brake rope diameter\n",
    "k=0.5#.............................#Four stroke engine\n",
    "n=1#...............................#No of cylinders\n",
    "#Calculations\n",
    "IP=(n*Pmi*L*(pi/4)*D*D*N*k*10)/6#......................#Indicated power in kW\n",
    "BP=(Nbl*pi*(Db+d)*N)/60#...............................#Brake power in kW\n",
    "etam=BP/IP#.............................................#Mechanical efficiency\n",
    "print \"Indicated power = %0.2f kW\"%(IP)\n",
    "print \"Brake power = %0.2f kW\"%(BP)\n",
    "print \"Mechanical efficiency = %0.2f %%\"%(etam*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.10 PAGE 576"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Brake specific fuel consumption = 0.27 kJ/hW-h\n",
      "Brake thermal efficiency : 30.78 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "Db=0.7#.............................#Diameter of brake pulley in m\n",
    "d=0.025#............................#Diameter of the rope in m\n",
    "W=50#...............................#Load on the tight side of the rope in kg\n",
    "S=50#...............................#Spring balance reading in N\n",
    "N=900#..............................#Engine rpm\n",
    "mf=4#...............................#Rate of fuel consumption in kg/h\n",
    "C=44000#............................#Calorific value of fuel in kJ/kg\n",
    "g=9.81#.............................#Acceleration due to gravity in m/s**2\n",
    "#Calculations\n",
    "BP=(((W*g)-S)*pi*(Db+d)*N)/(60*1000)#........................#Brake power in kW\n",
    "bsfc=mf/BP#...................................................#Brake specific fuel consumption in kJ/hW-h\n",
    "print \"Brake specific fuel consumption = %0.2f kJ/hW-h\"%bsfc\n",
    "etathB=(BP*3600)/(mf*C)#.............................................#Brake thermal efficiency\n",
    "print \"Brake thermal efficiency : %0.2f %%\"%(etathB*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.11 PAGE 576"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated thermal efficiency = 42.52 %\n",
      "Brake power = 100.53 kW\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=4#.......................#No of cylinders\n",
    "k=0.5#.....................#Four stroke engine\n",
    "r=8#.......................#Compression ratio\n",
    "d=0.1#.....................#Engine bore in m\n",
    "l=0.1#.....................#Engine stroke in m\n",
    "etaV=0.75#.................#Volumetric efficiency\n",
    "N=4800#....................#Engine rpm\n",
    "afr=15#....................#Air fuel ratio\n",
    "C=42000000#................#Calorific value of fuel\n",
    "rhoa=1.12#.................#Atmospheric density in kg/m**3\n",
    "Pmi=10#....................#Mean effective pressure in bar\n",
    "etamech=0.8#...............#Mechanical efficiency\n",
    "#Calculations \n",
    "IP=(n*Pmi*l*(pi/4)*d*d*N*k*10)/6#.................#Indicated power in kW\n",
    "Ac=n*(pi/4)*d*d*l*(N/2)*(etaV/60)#.....................#Air consumption in m**3/s\n",
    "ma=Ac*rhoa#........................................#Mass flow of air in kg/s\n",
    "mf=ma/afr#.........................................#Mass flow of fuel in kg/s\n",
    "etath=(IP*1000)/(mf*C)#...................................#Indicated thermal efficiency\n",
    "print \"Indicated thermal efficiency = %0.2f %%\"%(etath*100)\n",
    "BP=IP*etamech#.....................................#Brake Power in kW\n",
    "print \"Brake power = %0.2f kW\"%BP"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 7.12 PAGE 577"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The volumetric efficiency = 84.48 %\n",
      "Brake specific fuel consumption = 0.28 kg/kWh\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "N=1800#...................#Engine rpm\n",
    "l=0.11#...................#Engine stroke in m\n",
    "d=0.085#..................#Engine bore in m\n",
    "ma=0.56#..................#Air flow rate in kg/min\n",
    "BP=6#.....................#Brake power developed in kW\n",
    "afr=20#...................#Air fuel ratio\n",
    "C=42550#..................#Calorific value of fuel in kJ/kg\n",
    "rhof=1.18#................#Density of fuel in kg/m**3\n",
    "#calculations\n",
    "V=(pi/4)*d*d*l*(N/2)#.....................#Volume displacemt in m**3/min\n",
    "Ma=V*rhof#.................................#Mass of air in kg/min\n",
    "etaV=ma/Ma#................................#Volumetric efficiency\n",
    "fc=ma/afr#.................................#Fuel concumption\n",
    "bsfc=(fc*60)/BP#...........................#Brake specific fuel consumption in kg/kWh\n",
    "print \"The volumetric efficiency = %0.2f %%\"%(etaV*100)\n",
    "print \"Brake specific fuel consumption = %0.2f kg/kWh\"%(bsfc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.13 PAGE 578"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The mechanical efficiency = 63.59 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "pmicover=6.5#....................#Mean effective pressure on cover side in bar\n",
    "pmicrank=7#......................#Mean effective pressure on crank side in bar\n",
    "D=0.2#...........................#Engine bore in m\n",
    "l=0.35#..........................#Engine stroke in m\n",
    "drod=0.02#.........................#Diameter of piston rod in m\n",
    "W=1370#............................#Dead load on the brake in N\n",
    "S=145#.............................#Spring balance reading in N\n",
    "Db=1.2#............................#Brake wheel diameter in m\n",
    "d=0.02#............................#Brake rope diameter in m\n",
    "k=0.5#.............................#Four stroke engine\n",
    "N=420#.......................#Engine rpm\n",
    "#calculations\n",
    "Acover=(pi/4)*D*D#.......................#Area of cylinder on the cover side in m**2\n",
    "Acrank=(pi/4)*((D**2)-(drod**2))#..........#Effective area of cylinder on the crank end side in m**2\n",
    "IPcover=(pmicover*l*Acover*N*k*10)/6#................#Indicated power on the cover end side in kW\n",
    "IPcrank=(pmicrank*l*Acrank*N*k*10)/6#................#Indicated power on the crank end side in kW\n",
    "IPtotal=IPcover+IPcrank#....................#TOtal\n",
    "BP=((W-S)*pi*(Db+d)*N)/(60*1000)#...................#Brake power in kW\n",
    "etamech=BP/IPtotal#..................................#Mechanical efficiency\n",
    "print \"The mechanical efficiency = %0.2f %%\"%(etamech*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.14 PAGE 579"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Engine bore = 152.98 mm\n",
      "Engine stroke = 229.47 mm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "BP=14.7#........................#Brake power in kW\n",
    "p1=0.9#.........................#Suction pressure in bar\n",
    "etamech=0.8#....................#Mechanical efficiency\n",
    "r=5#............................#Compression ratio\n",
    "p3=24#..........................#maximum explosion pressure in bar\n",
    "N=1000#.........................#Engine rpm\n",
    "rld=1.5#........................#Ratio of length and stroke\n",
    "ic=1.35#........................#Index of compression curve\n",
    "ie=1.3#.........................#Index of expansion curve\n",
    "k=0.5#..........................#Four stroke engine\n",
    "#calculations\n",
    "p2=(r**ic)*p1#......................#intermediate pressure = %0.2f bar) during compression\n",
    "p4=p3/(r**ie)#......................#Intermediate pressure = %0.2f bar) during expansion\n",
    "pm=((((p3-r*p4)/(ie-1))-((p2-p1*r)/(ic-1)))*(10**5))/(r-1)#...........#Mean effective pressure in N/m**2\n",
    "pmb=pm/100000#........................................#Mean effective pressure in bar\n",
    "IP=BP/etamech#........................................#Indicated power in kW\n",
    "D=((IP*6*4)/(pmb*rld*(pi)*N*k*10))**(1/3)#............#Engine bore in m\n",
    "L=rld*D#..............................................#Engine stroke in m\n",
    "print \"Engine bore = %0.2f mm\"%(D*1000)\n",
    "print \"Engine stroke = %0.2f mm\"%(L*1000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.15 PAGE 580"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated thermal efficiency = 27.03 %\n",
      "Indicated brake efficiency = 23.43 %\n",
      "Mechanical efficiency = 86.67 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "#Initialisation of Variables\n",
    "IP=30#........................#Indicated power in kW\n",
    "BP=26#........................#Brake power in kW\n",
    "N=1000#.......................#Engine rpm\n",
    "fpbph=0.35#...................#Fuel per brake power hour in kg/B.P.h\n",
    "C=43900#......................#Calorific value of fuel used in kJ/kg\n",
    "#Calculations\n",
    "mf=BP*fpbph#.............#Fuel consumption per hour in kg/h\n",
    "etaIth=IP/((mf/3600)*C)#.................#Indicated thermal efficiency\n",
    "etaBth=BP/((mf/3600)*C)#.................#Indicated brake efficiency\n",
    "etamech=BP/IP#...........................#Mechanical efficiency\n",
    "print \"Indicated thermal efficiency = %0.2f %%\"%(etaIth*100)\n",
    "print \"Indicated brake efficiency = %0.2f %%\"%(etaBth*100)\n",
    "print \"Mechanical efficiency = %0.2f %%\"%(etamech*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.16 PAGE 581"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Brake specific fuel consumption  = 0.29 kg/kWh\n",
      "Brake thermal efficiency = 28.62 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "#Initialisation of Variables\n",
    "Db=0.75#.....................#Diameter of brake pulley in m\n",
    "d=0.05#......................#Rope diameter in m\n",
    "W=400#.......................#Dead load in N\n",
    "S=50#........................#Spring balance reading in N\n",
    "cf=4.2#......................#Consumption of fuel in kg/h\n",
    "N=1000#......................#Engine rpm\n",
    "C=43900#.....................#Calorific value of fuel in kJ/kg\n",
    "#Calculations\n",
    "BP=((W-S)*pi*(Db+d)*N)/(60*1000)#...............#Brake power in kW\n",
    "bsfc=cf/BP#......................................#Brake specific fuel consumption  in kg/kWh\n",
    "etabth=BP/((cf/3600)*C)#.........................#Brake thermal efficiency\n",
    "print \"Brake specific fuel consumption  = %0.2f kg/kWh\"%(bsfc)\n",
    "print \"Brake thermal efficiency = %0.2f %%\"%(etabth*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.17 PAGE 581"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The calorific value of the fuel used = 40341.03 kJ/kg\n",
      "Fuel consumption = 20.52 (kg/h\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "#Initialisation of Variables\n",
    "n=6#.............................#No of cylinders\n",
    "D=0.09#..........................#Bore of cylinder in m\n",
    "L=0.1#...........................#Stroke length in m\n",
    "r=7#.............................#Compression ratio\n",
    "etarel=0.55#.....................#Relative efficiency\n",
    "isfc=0.3#........................#Indicated specific fuel consumption in kg/kWh\n",
    "imep=8.6#........................#Indicated mean effective pressure in bar\n",
    "N=2500#..........................#Engine speed\n",
    "ga=1.4#..........................#Degree of freedom for air\n",
    "k=0.5#...........................#Four stroke engine\n",
    "#calculations\n",
    "etastan=1-1/(r**(ga-1))#...................#Air standard efficiency\n",
    "etath=etarel*etastan#.....................#Indicated thermal efficiency \n",
    "C=3600/(etath*isfc)#.......................#Calorific value of fuel in kJ/kg\n",
    "IP=(n*imep*L*D*D*(pi/4)*N*k*10)/6#................#Indicated power in kW\n",
    "fc=IP*isfc#.............................#Fuel consumption in kg/h\n",
    "print \"The calorific value of the fuel used = %0.2f kJ/kg\"%(C)\n",
    "print \"Fuel consumption = %0.2f (kg/h\"%(fc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.18 PAGE 582"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Engine bore = 62.04 mm\n",
      "Engine stroke = 93.05 mm\n",
      "Fuel consumption = 8.79 kg/h\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "BP=30#........................#Brake power in kW\n",
    "pmi=8#.........................#Mean effective pressure in bar\n",
    "etamech=0.8#....................#Mechanical efficiency\n",
    "n=4#............................#No of cylinders\n",
    "N=2500#.........................#Engine rpm\n",
    "rld=1.5#........................#Ratio of length and stroke\n",
    "etabth=0.28#......................#Brake thermal efficiency\n",
    "k=1#..........................#Two stroke engine\n",
    "C=43900#.........................#Calorific value of fuel in kJ/kg\n",
    "#calculations\n",
    "IP=BP/etamech#........................................#Indicated power in kW\n",
    "D=((IP*6*4)/(pmi*n*rld*(pi)*N*k*10))**(1/3)#............#Engine bore in m\n",
    "L=rld*D#..............................................#Engine stroke in m\n",
    "print \"Engine bore = %0.2f mm\"%(D*1000)\n",
    "print \"Engine stroke = %0.2f mm\"%(L*1000)\n",
    "mf=BP/(etabth*C)#..............................#Fuel consumption in kg/s\n",
    "print \"Fuel consumption = %0.2f kg/h\"%(mf*3600)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.19 PAGE 583"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The volumetric efficiency of the engine = 78.16 %\n",
      "The brake thermal efficiency of the engine = 23.64 %\n",
      "Brake torque = 0.23 kNm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=6#......................#No of cylinders\n",
    "pdpc=700*10**(-6)#.................#Piston displacement per cylinder in m**3\n",
    "P=78#............................#Power developed in kW\n",
    "N=3200#.............................#Engine rpm\n",
    "mf=27#.............................#Fuel consumption in kg/h\n",
    "C=44000#...........................#Calorific value of fuel in kJ/kg\n",
    "afr=12#..............................#Air fuel ratio\n",
    "p1=0.9#..........................#Intake air pressure\n",
    "pa=p1#\n",
    "t1=305#...............................#Intake air temperature\n",
    "ta=t1#\n",
    "R=0.287#.....................#Gas constant in kJ/kgK\n",
    "#Calculations\n",
    "ma=afr*mf#............................#maaa of air in kg/h\n",
    "Va=(ma*R*t1)/(p1*100)#.............#Volume of air intake in m**3/h\n",
    "Vs=pdpc*n*(N/2)*60#.....................#Swept volume in m**3/h\n",
    "etaV=Va/Vs#.............................#Volumetric efficiency\n",
    "print \"The volumetric efficiency of the engine = %0.2f %%\"%(etaV*100)\n",
    "etabt=P/(mf*(C/3600))#...................#Brake thermal efficiency\n",
    "print \"The brake thermal efficiency of the engine = %0.2f %%\"%(etabt*100)\n",
    "Tb=(P*60)/(2*pi*N)#..........................#Brake torque in kNm\n",
    "print \"Brake torque = %0.2f kNm\"%(Tb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.20 PAGE 583"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average no of times each cylinder misfires in one min : 2.00\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi,floor\n",
    "# Initialisation of Variables\n",
    "n=6#.......................#No of cylinders\n",
    "Vs=1.75*10**(-3)#..............#Stroke volume in m**3\n",
    "IP=26.3#.....................#Indicated power in kW\n",
    "Ne=504#.......................#Expected Engine rpm\n",
    "Pmi=6#........................#Mean effective pressure in bar\n",
    "k=0.5#.........................#Four stroke engine\n",
    "#Calculations\n",
    "Na=floor((IP*6)/(n*Pmi*Vs*k*10))#.......................#Actual Engine rpm\n",
    "af=(Na*n)/2#.......................#Actual no of fires in min\n",
    "ef=(Ne*n)/2#.......................#Expected no of fires in min\n",
    "Nm=ef-af#........................#No of misfires/min\n",
    "nm=Nm/n#....................#Average no of times each cylinder misfires in one min\n",
    "print \"Average no of times each cylinder misfires in one min : %0.2f\"%nm"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.21 PAGE 584"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated power = 14.24 kW\n",
      "Indicated thermal efficiency = 34.63 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=4#.......................#No of cylinders\n",
    "D=0.075#.......................#Engine bore in m\n",
    "L=0.09#........................#Engine length in m\n",
    "err=39/8#.......................#Engine to rear axle ratio\n",
    "Dw=0.65#.........................#Wheel diameter in m\n",
    "pc=0.227#.......................#Petrol consumption in kg\n",
    "pmi=5.625#.........................#Mean effective pressure in bar\n",
    "C=43470#..............................#Calorific value of petrol in kJ/kg\n",
    "k=0.5#.............................#Four stroke engine\n",
    "sc=48#............................#Speed of the car in km/h\n",
    "d=3.2#.............................#Distance covered by car in km\n",
    "#Calculations\n",
    "sc1=sc*(1000/60)#...................#Speed of the car in m/min\n",
    "Nt=sc1/(pi*Dw)#......................#Revolutions made by tire per min\n",
    "Ne=Nt*err#............................#Speed of engine shaft\n",
    "IP=(n*pmi*L*(pi/4)*D*D*Ne*k*10)/6#........#Indicated power in kW\n",
    "print \"Indicated power = %0.2f kW\"%(IP)\n",
    "sc2=sc/60#.......................#Speed of the car in km/min\n",
    "t=d/sc2#..........................#Time for covering 3.2 km in min\n",
    "fc=pc/(t*60)#.....................#Fuel consumed per second in kg\n",
    "etait=IP/(fc*C)#...............#Indicated thermal efficiency\n",
    "print \"Indicated thermal efficiency = %0.2f %%\"%(etait*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.22 PAGE 584"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated power = 26.59 kW\n",
      "Brake power = 21.21 kW\n",
      "Mechanical efficiency = 79.75 %\n",
      "Indicated thermal efficiency = 21.61 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=1#.................#No of cylinders\n",
    "D=0.25#................#Engine bore in m\n",
    "L=0.4#.................#Engine stroke in m\n",
    "pmg=7#.................#Gross mean effective pressure in bar\n",
    "pmp=0.5#...............#Pumping mean effective pressure in bar\n",
    "N=250#..................#Engine rpm\n",
    "Db=1.5#................#Effective diameter of the brake in m\n",
    "Nl=1080#..............#Net load on the brake in N\n",
    "fh=10#.................#Fuel used per hour in kg\n",
    "C=44300#...............#Calorific value of fuel in kJ/kg\n",
    "k=0.5#.................#Four stroke engine\n",
    "#Calculations\n",
    "mf=fh/3600#.........................#Fuel used per second in kg\n",
    "pm=pmg-pmp#.......................#Net pressure\n",
    "IP=(n*pm*L*(pi/4)*D*D*N*k*10)/6#..........#/Indicated power in kW\n",
    "print \"Indicated power = %0.2f kW\"%(IP)\n",
    "BP=((Nl)*pi*Db*N)/(60*1000)#...............#Brake power in kW\n",
    "print \"Brake power = %0.2f kW\"%(BP)\n",
    "etamech=BP/IP#...........................#Mechanical efficiency\n",
    "print \"Mechanical efficiency = %0.2f %%\"%(etamech*100)\n",
    "etath=IP/(mf*C)#.........................#Indicated thermal efficiency\n",
    "print \"Indicated thermal efficiency = %0.2f %%\"%(etath*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.23 PAGE 585"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Brake mean effective pressure = 553.38 bar\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "etabth=0.3#....................#Brake thermal efficiency\n",
    "afrw=20#........................#Air fuel ratio by weight\n",
    "C=41800#.........................#Calorific value of fuel used in kJ/kg\n",
    "R=287#........................#Gas constant in J/kg\n",
    "#Calculations\n",
    "Wp=etabth*C#...................#Work produced per kg of fuel in kJ\n",
    "p1=1.0132#\n",
    "t=273+15#............#STP conditions in bar and Kelvin\n",
    "V=(afrw*t*R)/(p1*10**5)#.......#Volume of air used in m**3\n",
    "pmb=(Wp*1000)/(V*10**5)#........#Brake mean effective pressure in bar\n",
    "print \"Brake mean effective pressure = %0.2f bar\"%(pmb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.24 PAGE 585"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Volumetric efficiency = 85.67 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "v1=0.216#.....................#Gas consumption in m**3/min\n",
    "pw=75#........................#Pressure of gas in mm of water\n",
    "t1=290#......................#Temperature of gas in K\n",
    "ac=2.84#....................#Air consumption in kg/min\n",
    "br=745#......................#Barometer reading in m of Hg\n",
    "D=0.25#.....................#Engine bore in m\n",
    "L=0.475#......................#Engine stroke in m\n",
    "N=240#........................#Engine rpm\n",
    "R=287#......................#Gas constant for air in J/kgK\n",
    "#Calculations\n",
    "p1=br+(pw/13.6)#...................#Pressure of gas in mm of mercury\n",
    "p2=760\n",
    "t2=273#.....................#NTP conditions in mm of Hg and Kelvin\n",
    "v2=(p1*v1*t2)/(t1*p2)#...............#Volume of gas used at NTP in m**3\n",
    "gs=v2/(N/2)#.........................#Gas used per stroke in m**3\n",
    "v=(ac*R*t2)/(1.0132*10**5)#...........#Volume occupied by air at NTP in m**3/min\n",
    "aps=v/(N/2)#...........................#Air used per stroke\n",
    "Va=gs+aps#.....................#Actual volume of mixture in m**3 drawn per stroke at NTP\n",
    "Vs=(pi/4)*D*D*L#...............#Swept volume in mm**3\n",
    "etaV=(Va/Vs)#...................#Volumetric efficiency\n",
    "print \"Volumetric efficiency = %0.2f %%\"%(etaV*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.25 PAGE 586"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated power = 26.59 kW\n",
      "Brake power = 22.87 kW\n",
      "Mechanical efficiency = 86.00 %\n",
      "Indicated thermal efficiency = 22.79 %\n",
      "Relative efficiency = 43.24 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "t=1#...................#Duration of trial in hrs\n",
    "Rev=14000#.............#Revolutions\n",
    "nmc=500#...............#Number of missed cycles\n",
    "bl=1470#................#Net Brake load in N\n",
    "mep=7.5#................#Mean effective pressure in bar\n",
    "gc=20000#...............#Gas consumption in litres\n",
    "lcv=21#.................#LCV of gas at supply condition in kJ/litre\n",
    "D=0.25#.................#Engine bore in m\n",
    "L=0.4#.................#Engine stroke in m\n",
    "r=6.5#..................#Compression ratio\n",
    "n=1#......................#No of cylinders\n",
    "Cb=4#......................#Effective brake Circumference \n",
    "k=0.5#....................#Four stroke engine\n",
    "ga=1.4#......................#Degree of freedom\n",
    "#Calculations\n",
    "N=Rev/60#..............#Engine rpm\n",
    "Vg=gc/3600#.............#Fuel consumption in litres/s\n",
    "Na=((Rev/2)-nmc)/60#................#Working cycles per min\n",
    "IP=(n*mep*L*(pi/4)*D*D*Na*10)/6#............#indicated power in kW\n",
    "print \"Indicated power = %0.2f kW\"%(IP)\n",
    "BP=((bl)*Cb*N)/(60*1000)#...............#Brake power in kW\n",
    "print \"Brake power = %0.2f kW\"%(BP)\n",
    "etamech=BP/IP#...........................#Mechanical efficiency\n",
    "print \"Mechanical efficiency = %0.2f %%\"%(etamech*100)\n",
    "etath=IP/(Vg*lcv)#.........................#Indicated thermal efficiency\n",
    "print \"Indicated thermal efficiency = %0.2f %%\"%(etath*100)\n",
    "etast=1-(1/r**(ga-1))#............#Air standard efficiency \n",
    "etarel=etath/etast#............#Relative efficiency\n",
    "print \"Relative efficiency = %0.2f %%\"%(etarel*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.26 PAGE 587"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The compression ratio : 5.58\n",
      "Thermal efficiency = 19.89 %\n",
      "Gas consumption = 0.96 m**3/IP hour\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=1.3#...................#Index of compression\n",
    "pa=1.4#\n",
    "pb=3.6#\n",
    "posa=(1/4)#..........#Point a - the position 1/4 of the stroke\n",
    "posb=(3/4)#..........#Point b - the position 3/4 of the stroke\n",
    "ga=1.4#...............#Degree of freedom for gas\n",
    "etarel=0.4#...................#Relative efficiency\n",
    "C=18800#....................#Calorific value of fuel in kJ/m**3\n",
    "#Calculations\n",
    "r=1+((((pb/pa)**(1/n))-1)/(posb-(((pb/pa)**(1/n))*(posa))))#.........#Compression ratio\n",
    "print \"The compression ratio : %0.2f\"%r\n",
    "etast=1-(1/r**(ga-1))#............#Air standard efficiency \n",
    "etath=etarel*etast#............#Thermal efficiency\n",
    "print \"Thermal efficiency = %0.2f %%\"%(etath*100)\n",
    "v=1/(etath*C)#...............#Gas consumption per IP sec\n",
    "print \"Gas consumption = %0.2f m**3/IP hour\"%(v*3600)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.27 PAGE 587"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mean effective pressure developed = 6.54 bar\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=6#.....................#No of cylinders\n",
    "r=5#..................#Compression ratio\n",
    "Vc=0.000115#................#Clearance volume of each cylinder in m**3\n",
    "fc=10.5#.....................#Fuel consumed in kg/h\n",
    "C=41800#......................#Calorific value of fuel in  kJ/kg\n",
    "N=2500#.......................#Engine speed in rpm\n",
    "er=0.65#.......................#Efficiency ratio\n",
    "ga=1.4#........................#Degree of freedom\n",
    "#calculations\n",
    "etast=1-(1/r**(ga-1))#...............................#Air standard efficiency\n",
    "etath=etast*er#.................................#Thermal efficiency\n",
    "IP=etath*(fc/3600)*C#..........................#Indicated power in kW\n",
    "Wnet=(IP*(10**3)*60)/(n*(N/2))#..............#Net work froom one cycle per cylinder in N-m\n",
    "Vs=(r-1)*Vc#......................#Swept volume in m**3\n",
    "pm=Wnet/(Vs*10**5)#...................#Mean effective pressure developed\n",
    "print \"Mean effective pressure developed = %0.2f bar\"%(pm)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.28 PAGE 588"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mean effective pressure = 8.11 bar\n",
      "Brake mean effective pressure = 6.16 bar\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "D=0.2#.................#Engine bore in m\n",
    "L=0.25#...............#Engine stroke in m\n",
    "n=2#......................#No of cylinders\n",
    "r=13#......................#Compression ratio\n",
    "fc=14#..................#Fuel consumption in kg/h\n",
    "N=300#....................#Engine rpm\n",
    "etarel=0.65#..............#Relative efficiency\n",
    "etamech=0.76#.............#Mechanical efficiency\n",
    "co=0.05#.....................#Cut off of the stroke\n",
    "C=41800#.....................#Calorific value of fuel in kJ/kg\n",
    "k=1#........................#Two stroke engine\n",
    "ga=1.4#.......................#Degree of freedom\n",
    "#calculations\n",
    "rho=1+(co*(r-1))#\n",
    "etast=1-((1/(r**(ga-1)))*(1/ga)*((rho**ga)-1)*(1/(rho-1)))#............#Air standard efficiency\n",
    "etath=etarel*etast#........................#Thermal efficiency\n",
    "IP=etath*(fc/3600)*C#........................#Indicated power in kW\n",
    "BP=etamech*IP#................................#Brake power in kW\n",
    "pmi=(6*IP)/(n*N*L*(pi/4)*D*D*k*10)#............#mean effective pressure in bar\n",
    "print \"Mean effective pressure = %0.2f bar\"%(pmi)\n",
    "pmb=pmi*etamech#...........................#Brake mean effective pressure in bar\n",
    "print \"Brake mean effective pressure = %0.2f bar\"%(pmb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.29 PAGE 589"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The compression ratio : 6.26\n",
      "Indicated thermal efficiency : 36.40 %\n",
      "Brake specific fuel consumption = 0.27 kg/kWs\n",
      "Engine bore = 108.20 mm\n",
      "Engine stroke = 135.25 mm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=4#.................#No of cylinders\n",
    "C=45200#..................#calorific value of fuel in kJ/kg\n",
    "etamech=0.82#...............#Mechanical efficiency\n",
    "etarel=0.7#.................#Relative efficiency\n",
    "etast=0.52#...............#Air standard efficiency\n",
    "etav=0.78#...............#Volumetric efficiency\n",
    "sbr=1.25#...................#Stroke bore ratio\n",
    "N=2400#...................#Engine rpm\n",
    "p=1#.......................#Suction pressure in bar\n",
    "t=298#....................#Suction temperature in bar\n",
    "BP=72#...................#Brake power in kW\n",
    "ga=1.4#......................#Degree of freedom\n",
    "afr=16#.................#Air fuel ratio\n",
    "R=287#.......................#Gas constant in J/kg\n",
    "#calculations\n",
    "r=(1/(1-etast))**(1/(ga-1))#............#Compression ratio\n",
    "print \"The compression ratio : %0.2f\"%r\n",
    "etath=etast*etarel#......................#Indicated thermal efficiency\n",
    "print \"Indicated thermal efficiency : %0.2f %%\"%(etath*100)\n",
    "IP=BP/etamech#....................#Indicated power in kW\n",
    "mf=IP/(etath*C)#......................#Fuel consumption in kg/s\n",
    "bsfc=mf/BP#......................#Brake specific fuel consumption in kg/kWs\n",
    "print \"Brake specific fuel consumption = %0.2f kg/kWs\"%(bsfc*3600)\n",
    "mafm=afr+1#......................#Mass of air fuel mixture in kg/kg of fuel\n",
    "mafm1=mafm*mf#....................#Mass of air fuel mixture when mf amount of fuel is supplied to engine per second\n",
    "v=(mafm1*R*t)/(p*10**5)#.......................#/Volume of air fuel mixture supplied to the engine in m**3\n",
    "Vs=v/etav#..............................#Swept volume in m**3\n",
    "D=((Vs)/((pi/4)*sbr*n*(N/(2*60))))**(1/3)#............#Engine bore in m\n",
    "print \"Engine bore = %0.2f mm\"%(D*1000)\n",
    "print \"Engine stroke = %0.2f mm\"%(D*1000*sbr)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.30 PAGE 589"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Brake power = 14.81 kW\n",
      "Mechanical efficiency = 85.00 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=1#.......................#No of cylinders\n",
    "D=0.18#...................#Engine bore in m\n",
    "L=0.34#....................#Engine stroke in m\n",
    "N=400#......................#Engine rpm\n",
    "mepw=6.4#.................#Mean effective pressure of working loop in bar\n",
    "mepp=0.36#..................#Mean effective pressure of pumping loop in bar\n",
    "mepd=0.64#.................#Mean effective pressure (dead cycle) iin bar\n",
    "fs=46#................#Firing strokes per min\n",
    "#calculations\n",
    "pminet=mepw-mepp#..........#Net indicated mean effective pressure in bar\n",
    "dc=(N/2)-fs#...............#Dead cycles per min\n",
    "IPnet=(n*pminet*(pi/4)*L*D*D*fs*4*10)/6#.............#Net indicated power output in kW\n",
    "ppdc=(n*pminet*L*(pi/4)*D*D*10*dc)/6#.............#Pumping power of dead cycles in kW\n",
    "FP=IPnet-ppdc#...........................#Frictional power in kW\n",
    "IP=(n*pminet*L*(pi/4)*D*D*(N/2)*10)/6#...............#Indicated power in kW\n",
    "BP=IP-FP#..................#Brake power in kW\n",
    "print \"Brake power = %0.2f kW\"%(BP)\n",
    "etamech=BP/IP#.................#Mechanical efficiency\n",
    "print \"Mechanical efficiency = %0.2f %%\"%(etamech*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.31 PAGE 590"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mechanical efficiency = 81.61 %\n",
      "Brake thermal efficiency = 39.54 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=1#..............#No of cylinders\n",
    "B=0.32#...............#Engine bore in m\n",
    "L=0.42#..............#Engine stroke in m\n",
    "N=200#................#Engine rpm\n",
    "Nk=90#..................#No of explosions per min\n",
    "v1=11.68#............#Gas used in m**3/h\n",
    "pg=170#................#Pressure of gas in mm of water \n",
    "br=755#................#Barometer reading in mm of Hg\n",
    "pmi=6.2#.................#Mean effective pressure in bar\n",
    "C=21600#.......................#Calorific value of gas in kJ/kg\n",
    "bl=2040#......................#Net load on brake in N\n",
    "Db=1.2#......................#Brake drum diameter in m\n",
    "t1=298#.....................#Ambient temperature in Kelvin\n",
    "#Calculations\n",
    "IP=(n*pmi*L*(pi/4)*B*B*Nk*10)/6#..........................#Indicated power in kW\n",
    "BP=(bl*pi*Db*N)/(60*1000)#.........................#Brake power in kW\n",
    "etamech=(BP/IP)#...................#Mechanical efficiency\n",
    "print \"Mechanical efficiency = %0.2f %%\"%(etamech*100)\n",
    "p1=br+(pg/13.6)#.................#In mm of Hg\n",
    "p2=760#\n",
    "t2=273#...................#NTP conditions in mm of Hg and Kelvin\n",
    "v2=(p1*v1*t2)/(p2*t1)#\n",
    "etabth=BP/((v2/3600)*C)#..............#Brake thermal efficiency\n",
    "print \"Brake thermal efficiency = %0.2f %%\"%(etabth*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.32 PAGE 591"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Volumetric efficiency = 66.45 %\n",
      "Air fuel ratio : 13.20\n",
      "Mean effective pressure = 7.55 bar\n",
      "Relative efficiency = 53.79 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi,sqrt\n",
    "# Initialisation of Variables\n",
    "n=1#...................#No of cylinders\n",
    "d=0.032#................#Diameter of circular orifice in m\n",
    "Cd=0.62#.............#Co efficient of discharge\n",
    "hw=150#.................#Pressure across orfice in mm of water\n",
    "t=20+273#..............#Temperature of air in the room in Kelvin\n",
    "p=1.0132#.................#Ambient pressure in bar\n",
    "pd=0.00178#............#Piston displacement in m**3\n",
    "R=287#....................#Gas constant in J/kg\n",
    "r=6.5#..................#Compression ratio\n",
    "fc=0.135#................#Fuel consumption in kg/min\n",
    "C=43900#.................#Calorific value of fuel in kJ/kg\n",
    "BP=28#................#Brake power in kW\n",
    "N=2500#...................#Engine rpm\n",
    "k=0.5#....................#Four stroke engine\n",
    "g=9.81#.......................#Acceleration due to gravity in m/s**2\n",
    "rhow=1000#....................#Density of water in kg/m**3\n",
    "ga=1.4#........................#Degree of freedom\n",
    "#calculations\n",
    "mbyv=(p*10**5)/(R*t)#\n",
    "pw=(hw/rhow)*rhow#....................#Pressure across orifice in kg/m**2\n",
    "H=pw/mbyv#........................#Head of air column causing the flow in m\n",
    "ma=Cd*(pi/4)*d*d*sqrt(2*g*H)#................#Air flow through orifice in m**3/s\n",
    "maps=(ma*60)/(N/2)#........................#Air consumption per stroke\n",
    "etav=maps/pd#.................#Volumetric efficiency\n",
    "print \"Volumetric efficiency = %0.2f %%\"%(etav*100)\n",
    "ac=ma*60*mbyv#...............#Mass of air drawn into cylinder per min in kg\n",
    "afr=ac/fc#...................#Air fuel ratio\n",
    "print \"Air fuel ratio : %0.2f\"%afr\n",
    "pmb=(6*BP)/(n*pd*N*k*10)#...................#Mean effective pressure in bar\n",
    "print \"Mean effective pressure = %0.2f bar\"%(pmb)\n",
    "etast=1-(1/(r**(ga-1)))#...............#Air standard efficiency\n",
    "etabth=BP/((fc/60)*C)#...............#Brake thermal efficiency\n",
    "etarel=etabth/etast#.................#Relative efficiency\n",
    "print \"Relative efficiency = %0.2f %%\"%(etarel*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.33 PAGE 591"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated power = 7.50 kW\n",
      "Brake power = 8.04 kW\n",
      "Brake mean effective pressure = 6.00 bar\n",
      "Brake specific fuel consumption = 0.35 kg/BP h\n",
      "Brake thermal efficiency = 24.74 %\n",
      "Indicated thermal efficiency = 30.92 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "N=400#.................#Engine rpm\n",
    "n=1#....................#no of cylinders\n",
    "W=370#.................#Load on the brake in N\n",
    "S=50#..................#Spring balance readin in N\n",
    "Db=1.2#.................#Diameter of the brake drum\n",
    "mf=2.8#.................#Fuel consumption in kg/h\n",
    "C=41800#..................#Calorific value of fuel in kJ/kg\n",
    "D=0.16#...................#Engine bore in m\n",
    "L=0.2#....................#Engine stroke in m\n",
    "k=0.5#.....................#Four stroke engine\n",
    "Sc=1#....................#Spring constant in bar/mm\n",
    "l=40#....................#Length of diagram in mm\n",
    "aic=300#.................#Area of indicator card in mm**2\n",
    "#Calculations\n",
    "pmi=aic*(Sc/l)#..................#Mean effective pressure in bar\n",
    "IP=(n*pmi*L*(pi/4)*D*D*k*N*10)/6#..............#Indicated power in kW\n",
    "print \"Indicated power = %0.2f kW\"%(pmi)\n",
    "BP=((W-S)*pi*Db*N)/(60*1000)#............#Brake power in kW\n",
    "print \"Brake power = %0.2f kW\"%(BP)\n",
    "pmb=(BP*6)/(n*L*D*D*(pi/4)*k*N*10)#...........#Brake mean effective pressure in bar\n",
    "print \"Brake mean effective pressure = %0.2f bar\"%(pmb)\n",
    "bsfc=mf/BP#.................#Brake specific fuel consumption in kg/BP h\n",
    "print \"Brake specific fuel consumption = %0.2f kg/BP h\"%bsfc\n",
    "etabth=BP/((mf/3600)*C)#..................#Brake thermal efficiency\n",
    "print \"Brake thermal efficiency = %0.2f %%\"%(etabth*100)\n",
    "etaith=IP/((mf/3600)*C)#....................#Indicated thermal efficiency\n",
    "print \"Indicated thermal efficiency = %0.2f %%\"%(etaith*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.34 PAGE 592"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated thermal efficiency = 27.96 %\n",
      "Mean effective pressure = 8.06 bar\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "R=287#................#Gas constant in J/kg K\n",
    "n=4#...................#No of cylinders\n",
    "D=0.0825#..............#Engine bore in m\n",
    "L=0.13#................#Engine stroke in m\n",
    "BP=28#..................#Brake power in kW\n",
    "N=1500#.................#Engine rpm\n",
    "afrth=14.8#...............#theoretical air fuel ratio \n",
    "C=45980#..................#Calorific value of fuel in kJ/kg\n",
    "etamech=0.9#.............#Mechanical efficiency\n",
    "ap=70#..................#Percentage of Volume of air in he cylinder\n",
    "fr=20#..................#Percentage richness of the fuel\n",
    "p1=1.0132#.................#Ambient pressure in bar\n",
    "pc=762#...................#Pressure in the cylinder in mm of Hg \n",
    "tc=273+15.5#...............#Temperature in the cylinder in Kelvin\n",
    "k=0.5#..................#Four stroke engine\n",
    "#Calculations\n",
    "Vs=(pi/4)*D*D*L#.......................#Swept volume in m**3\n",
    "va=(ap/100)*Vs#.....................#Volume of air drawn in m**3\n",
    "p=(pc/760)*p1#\n",
    "m=(p*(10**5)*va)/(R*tc)#...................#Mass of air per stroke per cylinder\n",
    "tmau=m*(N/2)*n#...................#Theoretical mass of air used per minute in kg\n",
    "tmfu=tmau/afrth#..................#Theoretical mass of fyel used per min in kg\n",
    "mf=(tmfu/60)*((100+fr)/100)#...............#Mass of fuel burnt per second in kg\n",
    "IP=BP/etamech#.........................#Indicated power in kW\n",
    "etaith=IP/(mf*C)#.....................#Indicated thermal efficiency \n",
    "print \"Indicated thermal efficiency = %0.2f %%\"%(etaith*100)\n",
    "pmb=(BP*6)/(n*L*D*D*(pi/4)*N*10*k)#...............#Mean effective pressure in bar\n",
    "print \"Mean effective pressure = %0.2f bar\"%(pmb)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.35 PAGE 593"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated power = 13.44 kW\n",
      "Brake power = 10.76 kW\n",
      "Indicated thermal efficiency = 23.87 %\n",
      "Brake thermal efficiency = 19.11 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=1#..................#No of cylinders\n",
    "D=0.2#............#Engine bore in m\n",
    "L=0.4#..............#Engine stroke in m\n",
    "Nt=9400#...............#Total no of revolutions \n",
    "Ne=4200#...............#Total no of explosions\n",
    "t=40#...................#Duration of testing in min\n",
    "Nk=Ne/t#...............#No of explosions\n",
    "bl=540#...............#Brake load in N\n",
    "Db=1.6#.................#Diameter of brake wheel in m\n",
    "d=0.02#................#Diameter of rope in m\n",
    "gu=8.5#..................#Gas used in m**3/sec\n",
    "C=15900#...............#Calorific value of fuel in kJ/kg\n",
    "Vg=(gu/(t*60))#.................#Volume of gas used in m**3/sec\n",
    "aic=550#.....................#Area of indicator diagram mm**2\n",
    "l=72#.......................#Length of indicator diagram in mm\n",
    "s=0.8#.....................#Spring number in bar/mm\n",
    "#calculations\n",
    "pmi=(aic*s)/l#................#Mean effective pressure in bar\n",
    "IP=(n*pmi*L*D*D*(pi/4)*Nk*10)/6#............#Indicated power in kW\n",
    "print \"Indicated power = %0.2f kW\"%(IP)\n",
    "BP=(bl*pi*(Db+d)*(Nt/t))/(60*1000)#...............#Brake power in kW\n",
    "print \"Brake power = %0.2f kW\"%(BP)\n",
    "etaith=IP/(Vg*C)#...............#Indicated thermal efficiency\n",
    "print \"Indicated thermal efficiency = %0.2f %%\"%(etaith*100)\n",
    "etabth=BP/(Vg*C)#...............#Brake thermal efficiency\n",
    "print \"Brake thermal efficiency = %0.2f %%\"%(etabth*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.36 PAGE 594"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Brake mean effective pressure = 3.97 bar\n",
      "Brake specific fuel consumption = 0.30 kg/kWh\n",
      "Brake thermal efficiency = 26.38 %\n",
      "Volumetric efficiency = 61.01 %\n",
      "Percentage of excess air supplied : 43.76\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi,sqrt\n",
    "# Initialisation of Variables\n",
    "n=6#....................#No of cylinders\n",
    "D=0.125#................#Engine bore in m\n",
    "L=0.125#...............#Engine stroke in m\n",
    "N=2400#.................#Engine rpm\n",
    "W=490#...............#Load on the dynamometer in N\n",
    "CD=16100#...............#Dynamometer constant\n",
    "d0=0.055#...................#Air orifice diameter in m\n",
    "Cd=0.66#...................#Co efficient of discharge\n",
    "hw=310#.................#Head causing flow through prifice in mm of water\n",
    "br=760#................#Barometer reading in mm of Hg\n",
    "t=298#..................#Ambient temperature in Kelvin\n",
    "fc=22.1#..................#Fuel consumption per hour in kg\n",
    "C=45100#..................#Calorific value of fuel used in kJ/kg\n",
    "perc=85#...................#Percentage of carbon in the fuel\n",
    "perh=15#...................#Percentage of hydrogen in the fuel\n",
    "p1=1.013#....................#Pressure of air at the end of suction stroke in bar\n",
    "t1=298#......................#Temperature of air the the end of suction stroke in Kelvin\n",
    "k=0.5#.......................#Four stroke engine\n",
    "R=287#.......................#Gas constant in J/kgK\n",
    "#calculations\n",
    "BP=W*(N/CD)#................#Brake power in kW\n",
    "pmb=(BP*6)/(L*D*D*k*10*N*n*(pi/4))#................#Brake mean effective pressure in bar\n",
    "print \"Brake mean effective pressure = %0.2f bar\"%(pmb)\n",
    "bsfc=fc/BP#.......................#Brake specific fuel consumption in kg/kWh\n",
    "print \"Brake specific fuel consumption = %0.2f kg/kWh\"%(bsfc)\n",
    "etathb=BP/((fc/3600)*C)#......................#Brake thermal efficiency\n",
    "print \"Brake thermal efficiency = %0.2f %%\"%(etathb*100)\n",
    "Vst=(pi/4)*D*D*L#..............#Stroke volume in m**3\n",
    "Val=840*(pi/4)*d0*d0*Cd*sqrt((hw/10)/((p1*10**5)/(R*t1)))#............#Volume of air passing through orifice of air box per min\n",
    "Vac=Val/n#.........................#Actual volume of air per cylinder in m**3/min\n",
    "asps=Vac/(N/2)#.......................#Air supplied per stroke per cylinder in m**3\n",
    "etav=asps/Vst#....................#Volumetric efficiency\n",
    "print \"Volumetric efficiency = %0.2f %%\"%(etav*100)\n",
    "Qa=(100/23)*(((perc/100)*(8/3))+((perh/100)*(8/1)))#.....................#Quantity of air required per kg of fuel combustion\n",
    "aqas=(Val*((p1*10**5)/(R*t1))*60)/fc#....................#Actual quantity of air supplied per kg of fuel\n",
    "pe=(aqas-Qa)/Qa#....................#Fraction of excess air supplied to engine\n",
    "print \"Percentage of excess air supplied : %0.2f\"%(pe*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.37 PAGE 595"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mechanical efficiency = 77.28 %\n",
      "Brake thermal efficiency = 23.26 %\n",
      "HEAT BALANCE TABLE : \n",
      "_______________________________________________________________________\n",
      "Item                                      kJ                  Percent\n",
      "_______________________________________________________________________\n",
      "Heat supplied by fuel                     367840             100.00\n",
      "Heat absorbed in IP                       110694             30.09\n",
      "Heat taken away by cooling water          59774             16.25\n",
      "Heat carried away by exhaust gases        197371             53.66\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=1#......................#No of cylinders\n",
    "D=0.3#....................#Engine bore in m\n",
    "L=0.45#....................#Engine stroke in m\n",
    "mf=8.8#...................#Fuel consumption in kg/h\n",
    "C=41800#...................#Calorific value of fuel in kJ/kg\n",
    "N=200#....................#Engine rpm\n",
    "pmi=5.8#....................#Mean effective pressure in bar\n",
    "bl=1860#....................#Brake load in N\n",
    "Db=1.22#...................#Diameter of brake drum in m\n",
    "k=0.5#........................#four stroke engine\n",
    "mw=650#......................#Mass of cooling water in kg\n",
    "cpw=4.18#....................#Specific heat capacity of water\n",
    "delt=22#......................#Temperature rise\n",
    "#Calculations\n",
    "IP=(n*L*D*D*k*10*pmi*N*(pi/4))/6#...............#Indicated power in kW\n",
    "BP=(bl*pi*Db*N)/(60*1000)#..................#Brake power in kW\n",
    "etamech=BP/IP#............#Mechanical efficiency\n",
    "print \"Mechanical efficiency = %0.2f %%\"%(etamech*100)\n",
    "etathb=BP/((mf/3600)*C)#...................#Brake thermal efficiency\n",
    "print \"Brake thermal efficiency = %0.2f %%\"%(etathb*100)\n",
    "#Heat supplied\n",
    "hip=IP*3600#...........#Heat equivalent of IP in kJ/h\n",
    "hcw=mw*cpw*delt#..........#Heat carried away by cooling water\n",
    "hf=mf*C#................#heat supplied by fuel\n",
    "hex=hf-hip-hcw#..........#Heat carried by exhaust gasses\n",
    "pf=100#\n",
    "pip=(hip/hf)*100#\n",
    "pcw=(hcw/hf)*100#\n",
    "pex=(hex/hf)*100\n",
    "print \"HEAT BALANCE TABLE : \"\n",
    "print \"_______________________________________________________________________\"\n",
    "print \"Item                                      kJ                  Percent\"\n",
    "print \"_______________________________________________________________________\"\n",
    "print \"Heat supplied by fuel                     %d             %0.2f\"%(hf,pf)\n",
    "print \"Heat absorbed in IP                       %d             %0.2f\"%(hip,pip)\n",
    "print \"Heat taken away by cooling water          %d             %0.2f\"%(hcw,pcw)\n",
    "print \"Heat carried away by exhaust gases        %d             %0.2f\"%(hex,pex)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.38 PAGE 596"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Brake power = 37.01 kW\n",
      "Brake specific fuel consumption = 0.28 kg/kWh:\n",
      "Brake thermal efficiency = 29.76 %\n",
      "HEAT BALANCE TABLE:\n",
      "_______________________________________________________________________\n",
      "Item                                      kJ                  Percent\n",
      "_______________________________________________________________________\n",
      "Heat supplied by fuel                     7461             100.00\n",
      "Heat absorbed in BP                       2220             29.76\n",
      "Heat taken away by cooling water          2332             31.26\n",
      "Heat carried away by exhaust gases        1811             24.28\n",
      "Unaccounted heat                          1097             14.70\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "r=15#................#Compression ratio\n",
    "n=1#...................#No of cylinders\n",
    "mf=10.2#..................#Fuel consumption in kg/h\n",
    "C=43890#.................#Calorific value of fuel in kJ/kg\n",
    "ma=3.8#.................#Consumption of air in kg/min\n",
    "N=1900#...................#Engine rpm\n",
    "T=186#....................#Torque on brake drum in Nm\n",
    "mw=15.5#.................#Mass of cooling water used in kg/min\n",
    "delt=36#..................#temperature rise\n",
    "tg=410#..................#Exhaust gas temperature in Celsius\n",
    "tr=20#...................#Room temperature in Celsius\n",
    "cp=1.17#.................#Specific heat capacity for exhaust gases kJ/kgK\n",
    "cpw=4.18#..................#Specific heat capacity for water in kJ/kgK\n",
    "#calculations\n",
    "BP=(2*pi*N*T)/(60*1000)#................#Brake power in kW\n",
    "print \"Brake power = %0.2f kW\"%BP\n",
    "bsfc=mf/BP#.............................#Brake specific fuel consumption in kg/kWh\n",
    "print \"Brake specific fuel consumption = %0.2f kg/kWh:\"%bsfc\n",
    "etabth=BP/((mf/3600)*C)#....................#Brake thermal efficiency\n",
    "print \"Brake thermal efficiency = %0.2f %%\"%(etabth*100)\n",
    "#Heat supplied\n",
    "mg=(mf/60)+ma#....................#Mass of exhaust gases in kg/min\n",
    "hbp=BP*60#...........#Heat equivalent of BP in kJ/min\n",
    "hcw=mw*cpw*delt#..........#Heat carried away by cooling water\n",
    "hf=(mf/60)*C#................#heat supplied by fuel\n",
    "hex=mg*cp*(tg-tr)#..........#Heat carried by exhaust gasses\n",
    "ha=round(hf)-round(hbp+hex+hcw)#............#Unaccounted heat\n",
    "pf=100#\n",
    "pbp=(hbp/hf)*100#\n",
    "pcw=(hcw/hf)*100#\n",
    "pex=(hex/hf)*100#\n",
    "pa=(ha/hf)*100#\n",
    "print \"HEAT BALANCE TABLE:\"\n",
    "print \"_______________________________________________________________________\"\n",
    "print \"Item                                      kJ                  Percent\"\n",
    "print \"_______________________________________________________________________\"\n",
    "print \"Heat supplied by fuel                     %d             %0.2f\"%(hf,pf)\n",
    "print \"Heat absorbed in BP                       %d             %0.2f\"%(hbp,pbp)\n",
    "print \"Heat taken away by cooling water          %d             %0.2f\"%(hcw,pcw)\n",
    "print \"Heat carried away by exhaust gases        %d             %0.2f\"%(hex,pex)\n",
    "print \"Unaccounted heat                          %d             %0.2f\"%(ha,pa)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.39 PAGE 597"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated power = 15.91 kW\n",
      "Brake power = 11.73 kW\n",
      "HEAT BALANCE TABLE\n",
      "_______________________________________________________________________\n",
      "Item                                          kJ               Percent\n",
      "_______________________________________________________________________\n",
      "Heat supplied by fuel                       66728             100.000000\n",
      "Heat absorbed in IP                         19088             28.606158\n",
      "Heat taken away by cooling water            16929             25.370159\n",
      "Heat carried away by dry exhaust gases      13448             20.154897\n",
      "Heat carried away by steam in exhaust gases 6606             9.901049\n",
      "Unaccounted heat                            10655             15.967810\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "Cpw=4.18#..............#Specific heat of water in kJ/kgK\n",
    "n=1#................#No of cylinders\n",
    "N=350#.......#Engine rpm\n",
    "pmi=3.1#..........#Mean effective pressure in bar\n",
    "bl=640#..........#Brake load in N\n",
    "mf=1.52#............#Fuel consumption in kg\n",
    "mw=162#..............#Mass of cooling water\n",
    "tw1=30#...............#Water inlet temperature in C\n",
    "tw2=55#................#Water outlet temperature in C\n",
    "ma=32#..................#Mass of air used per kg of fuel in kg\n",
    "tr=25#.................#Room temperature in C\n",
    "tg=305#.................#Exhaust temperature in C\n",
    "D=0.2#.................#Engine bore in m\n",
    "L=0.28#.................#Engine stroke in m\n",
    "Db=1#......................#Brake drum diameter in m\n",
    "ms=1.4#......................#Mass of steam formed per kg of fuel exhaust in kg\n",
    "C=43900#...................#Calorirfic value of fuel in kJ/kg\n",
    "Cps=2.09#..................#Specific heat of steamm in exhaust in kJ/kgK\n",
    "Cpg=1.0#...................#Specific heat of dry exhaust gases in kJ/kgK\n",
    "k=1#....................#Two stroke engiine\n",
    "t=20#.....................#Duration of testing in min\n",
    "#Calculations\n",
    "IP=(n*pmi*N*D*D*L*k*10*(pi/4))/6#...................#Indicated power in kW\n",
    "print \"Indicated power = %0.2f kW\"%IP\n",
    "BP=(bl*pi*Db*N)/(60*1000)#......................#Brake power in kW\n",
    "print \"Brake power = %0.2f kW\"%BP\n",
    "#Heat supplied\n",
    "hf=mf*C#................#heat supplied by fuel\n",
    "hip=IP*60*t#...........#Heat equivalent of BP in kJ/min\n",
    "hcw=mw*Cpw*(tw2-tw1)#..........#Heat carried away by cooling water\n",
    "mg=mf+(ma*mf)#....................#Mass of exhaust gases in kg/min\n",
    "mst=mf*ms#..................#Mass of steam formed\n",
    "hg=(mg-mst)*Cpg*(tg-tr)#..........#Heat carried by exhaust gasses\n",
    "hst=mst*(417.5+2257.9+(Cps*(305-99.6)))#....................#Heat carried by exhaust steam, the obtained values are from steam table and hence are constants at NTP\n",
    "ha=round(hf)-round(hip+hg+hst+hcw)#............#Unaccounted heat\n",
    "pf=100#\n",
    "pip=(hip/hf)*100#\n",
    "pcw=(hcw/hf)*100#\n",
    "pg=(hg/hf)*100#\n",
    "pa=(ha/hf)*100#\n",
    "pst=(hst/hf)*100#\n",
    "print \"HEAT BALANCE TABLE\"\n",
    "print \"_______________________________________________________________________\"\n",
    "print \"Item                                          kJ               Percent\"\n",
    "print \"_______________________________________________________________________\"\n",
    "print \"Heat supplied by fuel                       %d             %f\"%(hf,pf)\n",
    "print \"Heat absorbed in IP                         %d             %f\"%(hip,pip)\n",
    "print \"Heat taken away by cooling water            %d             %f\"%(hcw,pcw)\n",
    "print \"Heat carried away by dry exhaust gases      %d             %f\"%(hg,pg)\n",
    "print \"Heat carried away by steam in exhaust gases %d             %f\"%(hst,pst)\n",
    "print \"Unaccounted heat                            %d             %f\"%(ha,pa)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.40 PAGE 598"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Volumetric efficiency = 68.49 %\n",
      "Brake mean effective pressure = 5.14 bar\n",
      "Engine torque = 269.63 N-m\n",
      "Brake specific fuel consumption = 0.27 kg/kWh\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi,sqrt\n",
    "# Initialisation of Variables\n",
    "n=6#................#No of cylinders\n",
    "D=0.1#...............#Engine bore in m\n",
    "L=0.14#...............#Engine stroke in m\n",
    "N=2500#...............#Engine rpm\n",
    "k=0.5#..................#Four stroke\n",
    "bl=480#.................#Brake load in N\n",
    "br=76#..................#Barometer reading in cm of Hg\n",
    "d0=3.3/100#..............#Orifice diameter in m\n",
    "Cd=0.62#.................#Co efficient of discharge of orifice\n",
    "pd=14#...................#Pressure drop across orifice in cm of Hg\n",
    "tr=25#...............#Room temperature in C\n",
    "mf=0.32#................#Fuel consumption in kg/min\n",
    "rhohg=13600#.................#Density of Hg in kg/m**3\n",
    "R=0.287#...................#gas constant in kJ/kgK\n",
    "g=9.81#.................#Acceleration due to gravity in m/s**2\n",
    "CD=17000#....................#dynamometer constant\n",
    "#Calculations\n",
    "Vs=(pi/4)*D*D*L*(N/2)*(n/60)#..............#Swept volume in m**3\n",
    "br1=(br/100)*rhohg*g*(10**-3)#.............#Barometer reading into kN/m**2\n",
    "rhoa=br1/(R*(tr+273))#...............#Density of air\n",
    "pd1=(pd/100)*rhohg*g#......................#Conversion of pd into N/m**2\n",
    "ha=pd1/(rhoa*g)#.......................#Head of air causing flow in m\n",
    "Va=Cd*(pi/4)*d0*d0*sqrt(2*g*ha)#............#Volume of air passing through orifice of air box per min\n",
    "etav=Va/Vs#....................#Volumetric efficiency\n",
    "print \"Volumetric efficiency = %0.2f %%\"%(etav*100)\n",
    "BP=bl*(N/CD)#................#Brake power in kW\n",
    "pmb=(BP*6)/(L*D*D*k*10*N*n*(pi/4))#................#Brake mean effective pressure in bar\n",
    "print \"Brake mean effective pressure = %0.2f bar\"%(pmb)\n",
    "T=(BP*60*1000)/(2*pi*N)#....................#Engine torque in N-m\n",
    "print \"Engine torque = %0.2f N-m\"%T\n",
    "bsfc=(mf*60)/BP#.......................#Brake specific fuel consumption in kg/kWh\n",
    "print \"Brake specific fuel consumption = %0.2f kg/kWh\"%bsfc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.41 PAGE 598"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated power = 14.06 kW\n",
      "Indicated thermal efficiency = 26.85 %\n",
      "HEAT BALANCE TABLE\n",
      "_______________________________________________________________________\n",
      "Item                                          kJ               Percent\n",
      "_______________________________________________________________________\n",
      "Heat supplied by fuel                       3141.79             100.00\n",
      "Heat equivalent of BP                       659.73             21.00\n",
      "Heat taken away by cooling water            862.12             27.44\n",
      "Heat carried away by dry exhaust gases      782.78             24.92\n",
      "Heat carried away by steam in exhaust gases 294.85             9.38\n",
      "Unaccounted heat                            543.00             17.28\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "Cpw=4.18#..............#Specific heat of water in kJ/kgK\n",
    "n=1#................#No of cylinders\n",
    "N=350#.......#Engine rpm\n",
    "pmi=2.74#..........#Mean effective pressure in bar\n",
    "bl=600#..........#Brake load in N\n",
    "mf=4.22#............#Fuel consumption in kg\n",
    "mw=495#..............#Mass of cooling water\n",
    "tw1=13#...............#Water inlet temperature in C\n",
    "tw2=38#................#Water outlet temperature in C\n",
    "ma=135#..................#Mass of air used in kg/h\n",
    "tr=20#.................#Room temperature in C\n",
    "tg=370#.................#Exhaust temperature in C\n",
    "D=0.2#.................#Engine bore in m\n",
    "L=0.28#.................#Engine stroke in m\n",
    "Db=1#......................#Brake drum diameter in m\n",
    "C=44670#...................#Calorirfic value of fuel in kJ/kg\n",
    "Cps=2.093#..................#Specific heat of steamm in exhaust in kJ/kgK\n",
    "Cpg=1.005#...................#Specific heat of dry exhaust gases in kJ/kgK\n",
    "k=1#....................#Two stroke engiine\n",
    "t=60#.....................#Duration of testing in min\n",
    "perh=15#.................#Percentage of H2 in the fuel\n",
    "#Calculations\n",
    "IP=(n*pmi*N*D*D*L*k*10*(pi/4))/6#...................#Indicated power in kW\n",
    "print \"Indicated power = %0.2f kW\"%IP\n",
    "BP=(bl*pi*Db*N)/(60*1000)#......................#Brake power in kW\n",
    "etaith=(IP)/((mf/3600)*C)#.................#Indicated thermal efficiency\n",
    "print \"Indicated thermal efficiency = %0.2f %%\"%(etaith*100)\n",
    "#Heat supplied\n",
    "hf=(mf/t)*C#................#heat supplied by fuel\n",
    "hbp=BP*t#...........#Heat equivalent of BP in kJ/min\n",
    "hcw=(mw/60)*Cpw*(tw2-tw1)#..........#Heat carried away by cooling water\n",
    "mg=(mf+ma)/t#....................#Mass of exhaust gases in kg/min\n",
    "mst=9*(perh/100)*(mf/60)#..................#Mass of steam formed\n",
    "mdg=mg-mst#..............................#Mass of dry exhaust gases per min\n",
    "hg=(mdg)*Cpg*(tg-tr)#..........#Heat carried by exhaust gasses\n",
    "hst=mst*(417.5+2257.9+(Cps*(305-99.6)))#....................#Heat carried by exhaust steam, the obtained values are from steam table and hence are constants at NTP\n",
    "ha=round(hf)-round(hbp+hg+hst+hcw)#............#Unaccounted heat\n",
    "pf=100#\n",
    "pbp=(hbp/hf)*100#\n",
    "pcw=(hcw/hf)*100#\n",
    "pg=(hg/hf)*100#\n",
    "pa=(ha/hf)*100#\n",
    "pst=(hst/hf)*100#\n",
    "print \"HEAT BALANCE TABLE\"\n",
    "print \"_______________________________________________________________________\"\n",
    "print \"Item                                          kJ               Percent\"\n",
    "print \"_______________________________________________________________________\"\n",
    "print \"Heat supplied by fuel                       %0.2f             %0.2f\"%(hf,pf)\n",
    "print \"Heat equivalent of BP                       %0.2f             %0.2f\"%(hbp,pbp)\n",
    "print \"Heat taken away by cooling water            %0.2f             %0.2f\"%(hcw,pcw)\n",
    "print \"Heat carried away by dry exhaust gases      %0.2f             %0.2f\"%(hg,pg)\n",
    "print \"Heat carried away by steam in exhaust gases %0.2f             %0.2f\"%(hst,pst)\n",
    "print \"Unaccounted heat                            %0.2f             %0.2f\"%(ha,pa)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.42 PAGE 599"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Indicated power = 17.38 kW\n",
      "Brake power = 10.81 kW\n",
      "HEAT BALANCE TABLE : \n",
      "_______________________________________________________________________\n",
      "Item                                          kJ               Percent\n",
      "_______________________________________________________________________\n",
      "Heat supplied by fuel                       3146             100.00\n",
      "Heat absorbed in IP                         1043             33.15\n",
      "Heat taken away by cooling water            870             27.68\n",
      "Heat carried away by dry exhaust gases      877             27.89\n",
      "Heat carried away by steam in exhaust gases 319             10.16\n",
      "Unaccounted heat                            35             1.11\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "Cpw=4.18#..............#Specific heat of water in kJ/kgK\n",
    "n=1#................#No of cylinders\n",
    "N=350#.......#Engine rpm\n",
    "pmi=2.8#..........#Mean effective pressure in bar\n",
    "bl=590#..........#Brake load in N\n",
    "mf=4.3#............#Fuel consumption in kg\n",
    "mw=500#..............#Mass of cooling water\n",
    "tw1=25#...............#Water inlet temperature in C\n",
    "tw2=50#................#Water outlet temperature in C\n",
    "ma=33#..................#Mass of air used per kg of fuel in kg\n",
    "tr=25#.................#Room temperature in C\n",
    "tg=400#.................#Exhaust temperature in C\n",
    "D=0.22#.................#Engine bore in m\n",
    "L=0.28#.................#Engine stroke in m\n",
    "Db=1#......................#Brake drum diameter in m\n",
    "C=43900#...................#Calorirfic value of fuel in kJ/kg\n",
    "Cps=2.09#..................#Specific heat of steamm in exhaust in kJ/kgK\n",
    "Cpg=1.0#...................#Specific heat of dry exhaust gases in kJ/kgK\n",
    "k=1#....................#Two stroke engiine\n",
    "perh=15#...................#Percentage of hydrogen\n",
    "#Calculations\n",
    "IP=(n*pmi*N*D*D*L*k*10*(pi/4))/6#...................#Indicated power in kW\n",
    "print \"Indicated power = %0.2f kW\"%IP\n",
    "BP=(bl*pi*Db*N)/(60*1000)#......................#Brake power in kW\n",
    "print \"Brake power = %0.2f kW\"%BP\n",
    "#Heat supplied\n",
    "hf=(mf/60)*C#................#heat supplied by fuel\n",
    "hip=IP*60#...........#Heat equivalent of BP in kJ/min\n",
    "hcw=(mw/60)*Cpw*(tw2-tw1)#..........#Heat carried away by cooling water\n",
    "mg=(mf+(mf*ma))/60#....................#Mass of exhaust gases in kg/min\n",
    "mst=9*(perh/100)*(mf/60)#..................#Mass of steam formed\n",
    "mdg=mg-mst#..............................#Mass of dry exhaust gases per min\n",
    "hg=(mdg)*Cpg*(tg-tr)#..........#Heat carried by exhaust gasses\n",
    "hst=mst*(417.5+2257.9+(Cps*(400-99.6)))#....................#Heat carried by exhaust steam, the obtained values are from steam tables at NTP\n",
    "mg=mf+(ma*mf)#....................#Mass of exhaust gases in kg/min\n",
    "ha=round(hf)-round(hip+hg+hst+hcw)#............#Unaccounted heat\n",
    "pf=100#\n",
    "pip=(hip/hf)*100#\n",
    "pcw=(hcw/hf)*100#\n",
    "pg=(hg/hf)*100#\n",
    "pa=(ha/hf)*100#\n",
    "pst=(hst/hf)*100#\n",
    "print \"HEAT BALANCE TABLE : \"\n",
    "print \"_______________________________________________________________________\"\n",
    "print \"Item                                          kJ               Percent\"\n",
    "print \"_______________________________________________________________________\"\n",
    "print \"Heat supplied by fuel                       %d             %0.2f\"%(hf,pf)\n",
    "print \"Heat absorbed in IP                         %d             %0.2f\"%(hip,pip)\n",
    "print \"Heat taken away by cooling water            %d             %0.2f\"%(hcw,pcw)\n",
    "print \"Heat carried away by dry exhaust gases      %d             %0.2f\"%(hg,pg)\n",
    "print \"Heat carried away by steam in exhaust gases %d             %0.2f\"%(hst,pst)\n",
    "print \"Unaccounted heat                            %d             %0.2f\"%(ha,pa)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.43 PAGE 600"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "HEAT BALANCE TABLE: \n",
      "_______________________________________________________________________\n",
      "Item                                      kJ                  Percent\n",
      "_______________________________________________________________________\n",
      "Heat supplied by fuel                     7951             100.00\n",
      "Heat absorbed in BP                       3073             21.00\n",
      "Heat taken away by cooling water          2544             27.68\n",
      "Heat carried away by exhaust gases        1745             27.89\n",
      "Unaccounted heat                          589             1.11\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "I=210#.....................#Output of generator in A\n",
    "V=200#.....................#Generator voltage in V\n",
    "etag=0.82#.................#Generator efficiency \n",
    "mf=11.2#....................#Fuel used in kg/h\n",
    "C=42600#.......................#Calorific value of fuel in kJ/kg\n",
    "afr=18#....................#Air fuel ratio\n",
    "mc=580#.....................#Mass of water through calorimeter in kg/h\n",
    "delt=36#....................#Temperature raise in C\n",
    "tg=98#........................#Temperature of exhaust in C\n",
    "ta=20#.......................#Ambient temperature in C\n",
    "phcw=0.32#.....................#Heat lost to cooling jacket is 32% of heat supplied\n",
    "cpe=1.05#...................#Specific heat of exhause gases in kJ/kgK\n",
    "cpw=4.18#...................#Specific heat of water in kJ/kgK\n",
    "#Calculations\n",
    "pow=V*I#......................#Total power generated in W\n",
    "BP=(pow/1000)/etag#..................#Brake power in kW\n",
    "hf=(mf/60)*C#...................#Heat supplied to the engine\n",
    "hbp=BP*60#.........................#Heat equivalent of BP\n",
    "mg=(mf/60)*(afr+1)#...............#Mass of exhaust gases formed per min in kg\n",
    "hg=((mc/60)*cpw*(delt))+(mg*cpe*(tg-ta))#..........#Heat carried by exhaust gases per min\n",
    "hcw=phcw*hf#...................#Heat lost to cooling jacket\n",
    "ha=hf-(hcw+hg+hbp)#...................#Unaccounted heat\n",
    "pf=100#pbp=(hbp/hf)*100#pcw=(hcw/hf)*100#pg=(hg/hf)*100#pa=(ha/hf)*100\n",
    "print \"HEAT BALANCE TABLE: \"\n",
    "print \"_______________________________________________________________________\"\n",
    "print \"Item                                      kJ                  Percent\"\n",
    "print \"_______________________________________________________________________\"\n",
    "print \"Heat supplied by fuel                     %d             %0.2f\"%(hf,pf)\n",
    "print \"Heat absorbed in BP                       %d             %0.2f\"%(hbp,pbp)\n",
    "print \"Heat taken away by cooling water          %d             %0.2f\"%(hcw,pcw)\n",
    "print \"Heat carried away by exhaust gases        %d             %0.2f\"%(hg,pg)\n",
    "print \"Unaccounted heat                          %d             %0.2f\"%(ha,pa)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.44 PAGE 601"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "HEAT BALANCE TABLE : \n",
      "_______________________________________________________________________\n",
      "Item                                          kJ               Percent\n",
      "_______________________________________________________________________\n",
      "Heat supplied by fuel                       8745             100.00\n",
      "Heat absorbed in BP                         3056             34.95\n",
      "Heat lost by FP                             658              7.53\n",
      "Heat taken away by cooling water            2612             29.87\n",
      "Heat carried away by dry exhaust gases      1569             17.94\n",
      "Heat carried away by steam in exhaust gases 795              9.10\n",
      "Unaccounted heat                            52               0.60\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "D=0.34#..............#Engine bore in m\n",
    "k=0.5#...............#Four stroke engine\n",
    "n=1#..................#No of cylinders\n",
    "L=0.44#................#Engine stroke in m\n",
    "Ne=400#................#Engine rpm\n",
    "aic=465#..............#Area of indicator diagram in mm**2\n",
    "l=60#..................#Length of diagram in mm\n",
    "s=0.6#...............#Spring constant in bar/mm\n",
    "W=950#.................#Load of dynamometer in N\n",
    "CD=7460#................#Dynamometer constant\n",
    "mf=10.6#................#Fuel used in kg/h\n",
    "Ca=49500#.................#Calorific value of fuel in kJ/kg\n",
    "mw=25#...................#Cooling water circulated in kg/min\n",
    "cpw=4.18#..................#Specific heat capacity of water in kJ/kgC\n",
    "delt=25#..................#Rise in temperature of water\n",
    "#Mass analysis of fuel\n",
    "C=84#..................#Percentage of carbon\n",
    "H=15#..................#Percentage of hydrogen\n",
    "In=1#..................#Percentage of incombustible\n",
    "#Volume analysis of exhaust gases\n",
    "CO2=9#..................#Percentage of caron dioxide\n",
    "O=10#..................#Percentage of oxygen\n",
    "N=81#..................#Percentage of nitrogen\n",
    "tg=400#................#Temperature of exhaust gases in C\n",
    "cpg=1.05#..............#Specific heat of exhaust gases in kJ/kgC\n",
    "tr=25#.................#Temperature of room in C\n",
    "ppst=0.03#..............#Partial pressure of steam in exhaust gases in bar\n",
    "cpst=2.1#.................#Specific heat of superheated steam in kJ/kgC\n",
    "#Calculations\n",
    "pmi=(aic*s)/l#................#Mean effective pressure in bar\n",
    "IP=(n*pmi*L*D*D*k*10*Ne*(pi/4))/6#...............#Indicated power in kW\n",
    "BP=(W*Ne)/CD#.......................#Brake power in kW\n",
    "FP=IP-BP#...........................#Frictional power in kW\n",
    "hf=(mf/60)*Ca#...................#Heat supplied in kJ per min\n",
    "hbp=BP*60#.....................#Heat equivalent of Brake power in kW\n",
    "hfp=FP*60#......................#heat equivalent of frictional power in kW\n",
    "hcw=mw*cpw*delt#..................#Heat carried away by cooling water\n",
    "ma1=(N*C)/(33*(CO2))#...........#Mass of air supplied per kg of fuel\n",
    "mg1=ma1+1#.......................#Mass of exhaust gases per kg of fuel\n",
    "mg=mg1*(mf/60)#.................#Mass of exhaust gas formed per min\n",
    "mst1=9*(H/100)#.................#Mass of steam formed per kg of fuel\n",
    "mst=mst1*(mf/60)#..................#Mass of steam formed per min\n",
    "mdg=mg-mst#.......................#Mass of dry exhaust gas \n",
    "Hex=mdg*cpg*(tg-tr)#...............#Heat carried by exhaust gases\n",
    "hst=(2545.5+(cpst*(tg-24.1)))*mst#................#Heat carried by steam in exhaust gases in kJ/kg.....The values are from steam tables corresponding to the partial pressure 0.03 and temperature 400 Celsius\n",
    "ha=hf-(hbp+hfp+hcw+Hex+hst)#.....................#Unaccounted heat\n",
    "pf=100#\n",
    "pbp=(hbp/hf)*100#\n",
    "pfp=(hfp/hf)*100#\n",
    "pcw=(hcw/hf)*100#\n",
    "pex=(Hex/hf)*100#\n",
    "pa=(ha/hf)*100#\n",
    "pst=(hst/hf)*100#\n",
    "print \"HEAT BALANCE TABLE : \"\n",
    "print \"_______________________________________________________________________\"\n",
    "print \"Item                                          kJ               Percent\"\n",
    "print \"_______________________________________________________________________\"\n",
    "print \"Heat supplied by fuel                       %d             %0.2f\"%(hf,pf)\n",
    "print \"Heat absorbed in BP                         %d             %0.2f\"%(hbp,pbp)\n",
    "print \"Heat lost by FP                             %d              %0.2f\"%(hfp,pfp)\n",
    "print \"Heat taken away by cooling water            %d             %0.2f\"%(hcw,pcw)\n",
    "print \"Heat carried away by dry exhaust gases      %d             %0.2f\"%(Hex,pex)\n",
    "print \"Heat carried away by steam in exhaust gases %d              %0.2f\"%(hst,pst)\n",
    "print \"Unaccounted heat                            %d               %0.2f\"%(ha,pa)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.45 PAGE 602"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mechanical efficiency = 83.29 %\n",
      "Indicated thermal efficiency = 13.44 %\n",
      "Air standard efficiency = 49.13 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=4#........................#No of cylinders\n",
    "ga=1.4#...................#Degree of freedom\n",
    "D=0.075#..................#Engine bore in m\n",
    "L=0.1#...................#Engine stroke in m\n",
    "mf=6#.......................#Fuel consumption in kg/h\n",
    "C=83600#..................#Calorific value of fuel used\n",
    "Vc=0.0001#.................#Clearence volume in m**3\n",
    "BP=15.6#.................#Brake power wilh all cylinder working in kW\n",
    "BP1=11.1#...................#Brake power wilh cylinder no 1 cutout in kW\n",
    "BP2=11.03#...................#Brake power wilh cylinder no 2 cutout in kW\n",
    "BP3=10.88#...................#Brake power wilh cylinder no 3 cutout in kW\n",
    "BP4=10.66#...................#Brake power wilh cylinder no 4 cutout in kW\n",
    "#Calculations\n",
    "IP1=BP-BP1#...........................#Indicated power produced in cylinder 1 in kW\n",
    "IP2=BP-BP2#...........................#Indicated power produced in cylinder 2 in kW\n",
    "IP3=BP-BP3#...........................#Indicated power produced in cylinder 3 in kW\n",
    "IP4=BP-BP4#...........................#Indicated power produced in cylinder 4 in kW\n",
    "IP=IP1+IP2+IP3+IP4#.............................#Total Indicated power produced in kW\n",
    "etamech=BP/IP#..............................#Mechanical efficiency\n",
    "print \"Mechanical efficiency = %0.2f %%\"%(etamech*100)\n",
    "etaith=IP/((mf/3600)*C)#.....................#Indicated thermal efficiency\n",
    "print \"Indicated thermal efficiency = %0.2f %%\"%(etaith*100)\n",
    "Vs=(pi/4)*D*D*L#..........................#Stroke volume in m**3\n",
    "r=(Vs+Vc)/Vc#................................#Compression ratio\n",
    "etast=1-(1/(r**(ga-1)))#...........................#Air standard efficiency\n",
    "print \"Air standard efficiency = %0.2f %%\"%(etast*100)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## EXAMPLE 17.46 PAGE 603"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Engine torque = 59.20 Nm:\n",
      "Brake mean effective pressure = 7.31 bar\n",
      "Brake thermal efficiency = 21.31 %\n",
      "Specific fuel consumption = 0.38 kg/kWh\n",
      "Mechanical efficiency = 76.56 %\n",
      "Indicated mean effective pressure = 9.55 bar \n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "# Initialisation of Variables\n",
    "n=4#..........................#No of cylinders\n",
    "D=0.06#......................#Engine bore in m\n",
    "L=0.09#.......................#Engine stroke in m\n",
    "N=2800#.......................#Engine rpm\n",
    "Ta=0.37#.......................#Length of torque arm in m\n",
    "spgr=0.74#.....................#Specific graviy of fuel \n",
    "fc=8.986#......................#Fuel consumption in ltrs/h\n",
    "mf=fc*spgr#.....................#Fuel consumed in kg/h\n",
    "C=44100#......................#Calorific value of fuel in kJ/kg\n",
    "BPnl=160#.................#Net brake load in N\n",
    "BP1=110#...................#Brake load with cylinder no 1 cutout in N\n",
    "BP2=107#...................#Brake load with cylinder no 2 cutout in N\n",
    "BP3=104#...................#Brake load with cylinder no 3 cutout in N\n",
    "BP4=110#...................#Brake load with cylinder no 4 cutout in N\n",
    "k=0.5#.....................#Four stroke engine\n",
    "#Calculations\n",
    "T=BPnl*Ta#.......................#Engine torque in N-m\n",
    "print \"Engine torque = %0.2f Nm:\"%T\n",
    "BP=(2*pi*N*T)/(60*1000)#..........................#Brake power in kW\n",
    "pmb=(BP*6)/(n*D*D*L*N*10*(pi/4)*k)#...................#Brake mean effective pressure in bar\n",
    "print \"Brake mean effective pressure = %0.2f bar\"% pmb\n",
    "etabth=BP/((mf/3600)*C)#...........................#Brake thermal efficiency\n",
    "print \"Brake thermal efficiency = %0.2f %%\"%(etabth*100)\n",
    "sfc=mf/BP#.......................#Specific fuel consumption in kg/kWh\n",
    "print \"Specific fuel consumption = %0.2f kg/kWh\"%sfc\n",
    "IP1=BPnl-BP1#...........................#Indicated power produced in cylinder 1 in kW\n",
    "IP2=BPnl-BP2#...........................#Indicated power produced in cylinder 2 in kW\n",
    "IP3=BPnl-BP3#...........................#Indicated power produced in cylinder 3 in kW\n",
    "IP4=BPnl-BP4#...........................#Indicated power produced in cylinder 4 in kW\n",
    "IP=IP1+IP2+IP3+IP4#.............................#Total Indicated power produced in kW\n",
    "etamech=BPnl/IP#..............................#Mechanical efficiency\n",
    "print \"Mechanical efficiency = %0.2f %%\"%(etamech*100)\n",
    "pmi=pmb/etamech#............................#Indicated mean effective pressure in bar\n",
    "print \"Indicated mean effective pressure = %0.2f bar \"%pmi"
   ]
  }
 ],
 "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
}
