{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 8 - Combustion"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1: pg 198"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.1\n",
      " The stoichiometric mass of air required to burn 1 kg the fuel should be (kg/kg fuel) =  14.8\n"
     ]
    }
   ],
   "source": [
    "#pg 198\n",
    "print('Example 8.1');\n",
    "\n",
    "#  aim : To determine\n",
    "#   the stoichiometric mass of air required to burn 1 kg the fuel \n",
    "\n",
    "#  Given values\n",
    "C = .72;#  mass fraction of C; [kg/kg]\n",
    "H2 = .20;#  mass fraction of H2;, [kg/kg]\n",
    "O2 = .08;#  mass fraction of O2, [kg/kg]\n",
    "aO2=.232;#  composition of oxygen in air\n",
    "\n",
    "#  solution\n",
    "#  for 1kg of fuel\n",
    "mO2  = 8./3*C+8*H2-O2;#  mass of O2, [kg]\n",
    "\n",
    "#  hence stoichiometric mass of O2 required is\n",
    "msO2  = mO2/aO2;# [kg]\n",
    "\n",
    "#results\n",
    "print ' The stoichiometric mass of air required to burn 1 kg the fuel should be (kg/kg fuel) = ',round(msO2,1)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2: pg 198"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.2\n",
      " The stoichiometric mass of air required to burn 1 kg the fuel should be (kg/kg fuel) =  15.18\n"
     ]
    }
   ],
   "source": [
    "#pg 198\n",
    "print('Example 8.2');\n",
    "\n",
    "#  aim : To determine\n",
    "#   the stoichiometric mass of air required to burn 1 kg of heptane\n",
    "\n",
    "#  Given values\n",
    "C = .84;#  mass fraction of C; [kg/kg]\n",
    "H2 = .16;#  mass fraction of H2;, [kg/kg]\n",
    "x1 = 11.5;#  mass fraction of O2, [kg/kg]\n",
    "x2 = 34.5;#  composition of oxygen in air\n",
    "\n",
    "#  solution\n",
    "#  for 1kg of fuel\n",
    "mO2  = x1*C + x2*H2 ;#  mass of O2, [kg]\n",
    "\n",
    "mO22 = ((11*32)+100)/100\n",
    "mO2x = (mO22-1)/.232\n",
    "#results\n",
    "print ' The stoichiometric mass of air required to burn 1 kg the fuel should be (kg/kg fuel) = ',round(mO2,2)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3: pg 199"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.3\n",
      " The stoichiometric mass of air is (kg/kg fuel) =  13.52\n",
      " CO2 produced  =  3.01  kg/kg fuel,  percentage composition  =  20.7 ,\n",
      " H2O produced  =  1.08  kg/kg fuel,  percentage composition  =  7.43 ,\n",
      " SO2 produced  =  0.02  kg/kg fuel,  percentage composition  =  0.14 ,\n",
      " N2 produced  =  10.43  kg/kg fuel,  percentage composition  =  71.74\n"
     ]
    }
   ],
   "source": [
    "#pg 199\n",
    "print('Example 8.3');\n",
    "\n",
    "#  aim : To determine \n",
    "#  the stoichiometric mass of air\n",
    "#  the products of combustion both by mass and as percentage \n",
    "\n",
    "#  Given values\n",
    "C = .82;# mass composition C\n",
    "H2 = .12;# mass composition of H2\n",
    "O2 = .02;# mass composition of O2\n",
    "S = .01;# mass composition of S\n",
    "N2 = .03;# mass composition of N2\n",
    "\n",
    "#  solution\n",
    "#  for 1kg fuel\n",
    "mo2 = 8./3*C+8*H2-O2+S*1;# total mass of  O2 required, [kg]\n",
    "sa = mo2/.232;# stoichimetric  air, [kg]\n",
    "print ' The stoichiometric mass of air is (kg/kg fuel) = ',round(sa,2)\n",
    "\n",
    "# for one kg fuel\n",
    "mCO2 = C*11/3;# mass of CO2 produced, [kg]\n",
    "mH2O = H2*9;# mass of H2O produced, [kg]\n",
    "mSO2 = S*2;# mass of SO2 produce, [kg]\n",
    "mN2 = C*8.84+H2*26.5-O2*.768/.232+S*3.3+N2;# mass of N2 produced, [kg]\n",
    "\n",
    "mt = mCO2+mH2O+mSO2+mN2;# total mass of product, [kg]\n",
    "\n",
    "x1 = mCO2/mt*100;# %age mass composition of CO2 produced\n",
    "x2 = mH2O/mt*100;# %age mass composition of H2O produced\n",
    "x3 = mSO2/mt*100;# %age mass composition of SO2 produced\n",
    "x4 = mN2/mt*100;# %age mass composition of N2 produced\n",
    "\n",
    "print ' CO2 produced  = ',round(mCO2,2),' kg/kg fuel,  percentage composition  = ',round(x1,1),',\\n H2O produced  = ',mH2O,' kg/kg fuel,  percentage composition  = ',round(x2,2),',\\n SO2 produced  = ',mSO2,' kg/kg fuel,  percentage composition  = ',round(x3,2),',\\n N2 produced  = ',round(mN2,2),' kg/kg fuel,  percentage composition  = ',round(x4,2)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4: pg 202"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.4\n",
      " The  stoichiometric volume of air required for complete combustion is  (m^3/m^3  fuel) =  0.952\n"
     ]
    }
   ],
   "source": [
    "#pg 202\n",
    "print('Example 8.4');\n",
    "\n",
    "#  aim : To determine \n",
    "#  the stoichiometric volume of air required for complete combution of 1 m^3 of the gas\n",
    "\n",
    "#  Given values\n",
    "H2 = .14;# volume fraction of H2\n",
    "CH4 = .02;# volume fraction of CH4\n",
    "CO = .22;# volume fraction of CO\n",
    "CO2 = .05;# volume fraction of CO2\n",
    "O2 = .02;# volume fraction of O2\n",
    "N2 = .55;# volume fraction of N2\n",
    "\n",
    "# solution\n",
    "#  for 1 m^3 of fuel\n",
    "Va = .5*H2+2*CH4+.5*CO-O2;# [m^3]\n",
    "\n",
    "#  stoichiometric air required is\n",
    "Vsa = Va/.21;#  [m^3]\n",
    "#results\n",
    "print ' The  stoichiometric volume of air required for complete combustion is  (m^3/m^3  fuel) = ',round(Vsa,3)\n",
    "\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5: pg 203"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.5\n",
      " The volume of air required is(m^3/m^3 fuel) =  3.451\n",
      "Result in the book is misprinted\n"
     ]
    }
   ],
   "source": [
    "#pg 203\n",
    "print('Example 8.5');\n",
    "\n",
    "#  aim : To determine\n",
    "#   the volume of the air required \n",
    "\n",
    "#  Given values\n",
    "H2 = .45;# volume fraction of H2\n",
    "CO = .40;# volume fraction of CO\n",
    "CH4 = .15;# volume fraction of CH4\n",
    "\n",
    "#  solution\n",
    "V = 2.38*(H2+CO)+9.52*CH4;# stoichimetric volume of air, [m^3]\n",
    "#results\n",
    "print ' The volume of air required is(m^3/m^3 fuel) = ',V\n",
    "\n",
    "print 'Result in the book is misprinted'\n",
    "\n",
    "# End\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6: pg 203"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.6\n",
      " Stoichiometric volume of air required is (m^3/m^3 fuel) =  3.15\n",
      " N2 in products  =  2.516  m^3/m^3  fuel,  percentage composition  =  66.8 ,\n",
      " CO2 in products =  0.561  m^3/m^3 fuel,  percentage composition  = 14.9 ,\n",
      " H2O in products  =  0.689 m^3/m^3  fuel,  percentage composition  = 18.3\n"
     ]
    }
   ],
   "source": [
    "#pg 203\n",
    "print('Example 8.6');\n",
    "\n",
    "# aim : To determine\n",
    "# the stoichiometric volume of air for the complete combustion\n",
    "# the products of combustion\n",
    "\n",
    "# given values\n",
    "CH4 = .142;# volumetric composition of CH4\n",
    "CO2 = .059;# volumetric composition of CO2\n",
    "CO = .360;# volumetric composition of CO\n",
    "H2 = .405;# volumetric composition of H2\n",
    "O2 = .005;# volumetric composition of O2\n",
    "N2 = .029;# volumetric composition of N2\n",
    "\n",
    "aO2 = .21;# O2 composition into air by volume\n",
    "\n",
    "#  solution\n",
    "svO2 = CH4*2+CO*.5+H2*.5-O2;# stroichiometric volume of O2 required, [m^3/m^3 fuel]\n",
    "svair = svO2/aO2;# stroichiometric volume of air required, [m^3/m^3 fuel]\n",
    "print ' Stoichiometric volume of air required is (m^3/m^3 fuel) = ',svair\n",
    "\n",
    "# for one m^3 fuel\n",
    "vN2 = CH4*7.52+CO*1.88+H2*1.88-O2*.79/.21+N2;# volume of N2 produced, [m^3]\n",
    "vCO2 = CH4*1+CO2+CO*1;# volume of CO2 produced, [m^3]\n",
    "vH2O = CH4*2+H2*1;# volume of H2O produced, [m^3]\n",
    "\n",
    "vt = vN2+vCO2+vH2O;# total volume of product, [m^3]\n",
    "\n",
    "x1 = vN2/vt*100;# %age composition of N2 in product,\n",
    "x2 = vCO2/vt*100;# %age composition of CO2 in product\n",
    "x3 = vH2O/vt*100;# %age composition of H2O in product\n",
    "\n",
    "print ' N2 in products  = ',round(vN2,3),' m^3/m^3  fuel,  percentage composition  = ',round(x1,1),',\\n CO2 in products = ',vCO2,' m^3/m^3 fuel,  percentage composition  =',round(x2,1),',\\n H2O in products  = ',vH2O,'m^3/m^3  fuel,  percentage composition  =',round(x3,1)\n",
    "\n",
    "# End \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7: pg 206"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.7\n",
      " Mass percentage of CO2 is  =  27.8  \n",
      "\n",
      " Mass percentage of N2 is  =  62.0  \n",
      "\n",
      " Mass percentage of O2 is  =   10.1\n"
     ]
    }
   ],
   "source": [
    "#pg 206\n",
    "print('Example 8.7');\n",
    "\n",
    "#  aim : To determine\n",
    "#  the percentage analysis of the gas by mass\n",
    "\n",
    "#  Given values\n",
    "CO2 = 20.;# percentage volumetric composition  of CO2\n",
    "N2 = 70.;# percentage volumetric composition of N2\n",
    "O2 = 10.;# percentage volumetric composition  of O2\n",
    "\n",
    "mCO2 = 44.;#  moleculer mas of CO2\n",
    "mN2 = 28.;#  moleculer mass of N2\n",
    "mO2 = 32.;#  moleculer mass of O2\n",
    "\n",
    "#  solution\n",
    "mgas = CO2*mCO2+N2*mN2+O2*mO2;#  moleculer mass of gas \n",
    "m1 = CO2*mCO2/mgas*100;# percentage composition of CO2 by mass \n",
    "m2 = N2*mN2/mgas*100;# percentage composition of N2 by mass \n",
    "m3 = O2*mO2/mgas*100;# percentage composition of O2 by mass \n",
    "#results\n",
    "print ' Mass percentage of CO2 is  = ',round(m1,1),' \\n\\n Mass percentage of N2 is  = ',round(m2,1),' \\n\\n Mass percentage of O2 is  =  ',round(m3,1)\n",
    "\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 8: pg 206"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.8\n",
      " The percentage composition of CO by volume is  =  6.9  \n",
      ",\n",
      "The percentage composition of N2 by volume is  = 4.6 \n",
      "\n",
      "The percentage composition of CH4 by volume is  =  6.0 \n",
      "\n",
      "The percentage composition of H2 by volume is  =  80.5  \n",
      "\n",
      "The percentage composition of O2by volume is=  2.0\n"
     ]
    }
   ],
   "source": [
    "#pg 206\n",
    "print('Example 8.8');\n",
    "\n",
    "#  aim : To determine\n",
    "#  the percentage composition of the gas by volume\n",
    "\n",
    "#  given values\n",
    "CO = 30.;# %age mass composition of CO\n",
    "N2 = 20.;# %age mass composition of N2\n",
    "CH4 = 15.;# %age mass composition of CH4\n",
    "H2 = 25.;# %age mass composition of H2\n",
    "O2 = 10.;# %age mass composition of O2\n",
    "\n",
    "mCO = 28.;# molculer mass of CO\n",
    "mN2 = 28.;# molculer mass of N2\n",
    "mCH4 = 16.;# molculer mass of CH4\n",
    "mH2 = 2.;# molculer mass of H2\n",
    "mO2 = 32.;# molculer mass of O2\n",
    "\n",
    "# solution\n",
    "vg = CO/mCO+N2/mN2+CH4/mCH4+H2/mH2+O2/mO2;\n",
    "v1 = CO/mCO/vg*100;# %age volume composition of CO\n",
    "v2 = N2/mN2/vg*100;# %age volume composition of N2\n",
    "v3 = CH4/mCH4/vg*100;# %age volume composition of CH4\n",
    "v4 = H2/mH2/vg*100;# %age volume composition of H2\n",
    "v5 = O2/mO2/vg*100;# %age volume composition of O2\n",
    "#results\n",
    "print ' The percentage composition of CO by volume is  = ',round(v1,1),' \\n,\\nThe percentage composition of N2 by volume is  =',round(v2,1), '\\n\\nThe percentage composition of CH4 by volume is  = ',round(v3,1),'\\n\\nThe percentage composition of H2 by volume is  = ',round(v4,1),' \\n\\nThe percentage composition of O2by volume is= ',round(v5,1)\n",
    "\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 9: pg 209"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.9\n",
      " The mass of air supplied per/kg of fuel burnt is (kg) =  21.1\n"
     ]
    }
   ],
   "source": [
    "#pg 209\n",
    "print('Example 8.9');\n",
    "\n",
    "# aim : To determine\n",
    "# the mass of air supplied per kilogram of fuel burnt\n",
    "\n",
    "# given values\n",
    "CO2 = 8.85;# volume composition of CO2\n",
    "CO = 1.2;#  volume composition of CO\n",
    "O2 = 6.8;#  volume composition of O2\n",
    "N2 = 83.15;#  volume composition of N2 \n",
    "\n",
    "# composition of gases in the fuel oil\n",
    "C = .84;# mass composition of carbon \n",
    "H = .14;# mass composition of hydrogen\n",
    "o2 = .02;# mass composition of oxygen\n",
    "\n",
    "mC = 12.;# moleculer mass of Carbon\n",
    "mCO2 = 44.;# molculer mass of CO2\n",
    "mCO = 28.;# molculer mass of CO\n",
    "mN2 = 28.;# molculer mass of N2\n",
    "mO2 = 32.;# molculer mass of O2\n",
    "aO2 = .23;# mass composition of O2 in air\n",
    "\n",
    "# solution\n",
    "ma = (8./3*C+8*H-o2)/aO2;# theoretical mass of air/kg fuel, [kg]\n",
    "\n",
    "mgas = CO2*mCO2+CO*mCO+N2*mN2+O2*mO2;#  total mass of gas/kg fuel, [kg]\n",
    "x1 = CO2*mCO2/mgas;#  composition of CO2 by mass \n",
    "x2 = CO*mCO/mgas;# composition of CO by mass\n",
    "x3 = O2*mO2/mgas;#  composition of O2 by mass \n",
    "x4 = N2*mN2/mgas;#  composition of N2 by mass \n",
    "\n",
    "m1 = x1*mC/mCO2+x2*mC/mCO;# mass of C/kg of dry flue gas, [kg]\n",
    "m2 = C;# mass of C/kg fuel, [kg]\n",
    "mf = m2/m1;# mass of dry flue gas/kg fuel, [kg]\n",
    "mo2 = mf*x3;# mass of excess O2/kg fuel, [kg]\n",
    "mair = mo2/aO2;# mass of excess air/kg fuel, [kg]\n",
    "m = ma+mair;# mass of excess air supplied/kg fuel, [kg]\n",
    "#results\n",
    "print ' The mass of air supplied per/kg of fuel burnt is (kg) = ',round(m,1)\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 10: pg 210"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.10\n",
      "The percentage composition of CO2 by volume is  = 10.98 \n",
      ",\n",
      "The percentage composition of H2O by volume is  =  10.72   \n",
      ",\n",
      "The percentage composition of O2 by volume is  =  3.27 \n",
      ",\n",
      "The percentage composition of N2 by volume is  =  75.03\n"
     ]
    }
   ],
   "source": [
    "#pg 210\n",
    "print('Example 8.10');\n",
    "\n",
    "# aim : To determine\n",
    "# volumetric composition of the products of combustion\n",
    "\n",
    "# given values\n",
    "C = .86;#  mass composition of carbon\n",
    "H = .14;# mass composition of hydrogen\n",
    "Ea = .20;#  excess air for combustion\n",
    "O2 = .23;# mass composition of O2 in air \n",
    "\n",
    "MCO2 = 44.;# moleculer mass of CO2\n",
    "MH2O = 18.;# moleculer mass of H2O\n",
    "MO2 = 32.;# moleculer mass of O2\n",
    "MN2 = 28.;# moleculer mass of N2,\n",
    "\n",
    "\n",
    "# solution\n",
    "sO2 = (8./3*C+8*H);# stoichiometric O2 required, [kg/kg petrol]\n",
    "sair = sO2/O2;# stoichiometric air required, [kg/kg petrol]\n",
    "# for one kg petrol\n",
    "mCO2 = 11./3*C;# mass of CO2,[kg]\n",
    "mH2O = 9*H;# mass of H2O, [kg]\n",
    "mO2 = Ea*sO2;# mass of O2, [kg]\n",
    "mN2 = 14.84*(1+Ea)*(1-O2);# mass of N2, [kg]\n",
    "\n",
    "mt = mCO2+mH2O+mO2+mN2;# total mass, [kg]\n",
    "# percentage mass composition\n",
    "x1 = mCO2/mt*100;# mass composition of CO2\n",
    "x2 = mH2O/mt*100;# mass composition of H2O\n",
    "x3 = mO2/mt*100;# mass composition of O2\n",
    "x4 = mN2/mt*100;# mass composition of N2\n",
    "\n",
    "vt = x1/MCO2+x2/MH2O+x3/MO2+x4/MN2;# total volume of petrol\n",
    "v1 = x1/MCO2/vt*100;# %age composition of CO2 by volume\n",
    "v2 = x2/MH2O/vt*100;# %age composition  of H2O by volume\n",
    "v3 = x3/MO2/vt*100;# %age composition of O2 by volume\n",
    "v4 = x4/MN2/vt*100;# %age composition of N2 by volume\n",
    " #results\n",
    "print 'The percentage composition of CO2 by volume is  =',round(v1,2),'\\n,\\nThe percentage composition of H2O by volume is  = ',round(v2,2),'  \\n,\\nThe percentage composition of O2 by volume is  = ',round(v3,2),'\\n,\\nThe percentage composition of N2 by volume is  = ',round(v4,2)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11: pg 211"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.11\n",
      " The energy carried away by the dry flue gas/kg is (kg) =  5000.0\n"
     ]
    }
   ],
   "source": [
    "#pg 211\n",
    "print('Example 8.11');\n",
    "\n",
    "# aim : To determine\n",
    "#  the energy carried away by the dry flue gas/kg of fuel burned\n",
    "\n",
    "# given values\n",
    "C = .78;#  mass composition of carbon\n",
    "H2 = .06;# mass composition of hydrogen\n",
    "O2 = .09;# mass composition of oxygen\n",
    "Ash = .07;# mass composition of ash\n",
    "Ea = .50;#  excess air for combustion\n",
    "aO2 = .23;# mass composition of O2 in air \n",
    "Tb = 273.+20;# boiler house temperature, [K]\n",
    "Tf = 273.+320;# flue gas temperature, [K]\n",
    "c = 1.006;# specific heat capacity of dry flue gas, [kJ/kg K]\n",
    "\n",
    "# solution\n",
    "# for one kg of fuel\n",
    "sO2 = (8./3*C+8*H2);# stoichiometric O2 required, [kg/kg fuel]\n",
    "sO2a = sO2-O2;# stoichiometric O2 required from air, [kg/kg fuel]\n",
    "sair = sO2a/aO2;# stoichiometric air required, [kg/kg fuel]\n",
    "ma = sair*(1+Ea);# actual air supplied/kg of fuel, [kg]\n",
    "# total mass of flue gas/kg fuel is\n",
    "mf = ma+1;# [kg]\n",
    "mH2 = 9*H2;#H2 produced, [kg] \n",
    "# hence, mass of dry flue gas/kg coall is\n",
    "m = mf-mH2;# [kg]\n",
    "Q = m*c*(Tf-Tb);# energy carried away by flue gas, [kJ]\n",
    "#results\n",
    "print ' The energy carried away by the dry flue gas/kg is (kg) = ',round(Q)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 12: pg 212"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.12\n",
      " (a) The stoichiometric volume of air for the complete combustion (m^3/m^3 gas) =  9.702\n",
      " (b) The percentage volumetric composition of CO2 in produced is  =   9.6  \n",
      ",\n",
      "     The percentage volumetric composition of H2O in produced is  =  18.8   \n",
      ",\n",
      "     The percentage volumetric composition of N2 in produced is  =  71.6\n"
     ]
    }
   ],
   "source": [
    "#pg 212\n",
    "print('Example 8.12');\n",
    "\n",
    "# aim : To determine\n",
    "# (a) the stoichiometric volume of air for the complete combustion of 1 m^3\n",
    "# (b) the percentage volumetric analysis of the products of combustion\n",
    "\n",
    "# given values\n",
    "N2 = .018;# volumetric composition of N2\n",
    "CH4 = .94;# volumetric composition of CH4\n",
    "C2H6 = .035;# volumetric composition of C2H6\n",
    "C3H8 = .007;# volumetric composition of C3H8\n",
    "aO2 = .21;# O2 composition in air\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "# for CH4\n",
    "# CH4 +2 O2= CO2 + 2 H2O\n",
    "sva1 = 2./aO2;# stoichiometric volume of air, [m^3/m^3 CH4]\n",
    "svn1 = sva1*(1-aO2);# stoichiometric volume of nitrogen in the air, [m^3/m^3 CH4]\n",
    "\n",
    "# for C2H6\n",
    "# 2 C2H6 +7 O2= 4 CO2 + 6 H2O\n",
    "sva2 = 7./2/aO2;# stoichiometric volume of air, [m^3/m^3 C2H6]\n",
    "svn2 = sva2*(1-aO2);# stoichiometric volume of nitrogen in the air, [m^3/m^3 C2H6]\n",
    "\n",
    "# for C3H8\n",
    "# C3H8 +5 O2=3 CO2 + 4 H2O\n",
    "sva3 = 5/aO2;# stoichiometric volume of air, [m^3/m^3 C3H8]\n",
    "svn3 = sva3*(1-aO2);# stoichiometric volume of nitrogen in the air, [m^3/m^3 C3H8]\n",
    "\n",
    "Sva = CH4*sva1+C2H6*sva2+C3H8*sva3;# stoichiometric volume of air required, [m^3/m^3 gas]\n",
    "print ' (a) The stoichiometric volume of air for the complete combustion (m^3/m^3 gas) = ',round(Sva,3)\n",
    "\n",
    "# (b)\n",
    "# for one m^3 of natural gas\n",
    "vCO2 = CH4*1+C2H6*2+C3H8*3;# volume of CO2 produced, [m^3]\n",
    "vH2O = CH4*2+C2H6*3+C3H8*4;# volume of H2O produced, [m^3]\n",
    "vN2 = CH4*svn1+C2H6*svn2+C3H8*svn3+N2;# volume of N2 produced, [m^3]\n",
    "\n",
    "vg = vCO2+vH2O+vN2;# total volume of gas, [m^3]\n",
    "x1 = vCO2/vg*100;# volume percentage of CO2 produced\n",
    "x2 = vH2O/vg*100;# volume percentage of H2O produced\n",
    "x3 = vN2/vg*100;# volume percentage of N2 produced\n",
    "\n",
    "print ' (b) The percentage volumetric composition of CO2 in produced is  =  ',round(x1,1),' \\n,\\n     The percentage volumetric composition of H2O in produced is  = ',round(x2,1),'  \\n,\\n     The percentage volumetric composition of N2 in produced is  = ',round(x3,1)\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 13: pg 214"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.13\n",
      " (a) Volume of air taken by fan is (m^3/s) =  2.51\n",
      " (b) Percentage mass composition of CO2 is (percent) =  18.77\n",
      "     Percentage mass composition of O2 is (percent) =  5.24\n",
      "     Percentage mass composition of N2 is (percent) =  75.99\n"
     ]
    }
   ],
   "source": [
    "#pg 214\n",
    "print('Example 8.13');\n",
    "\n",
    "# aim : To determine\n",
    "# (a) the volume of air taken by the fan\n",
    "# (b) the percentage composition of dry flue gas\n",
    "\n",
    "# gien values\n",
    "C = .82;# mass composition of carbon\n",
    "H = .08;# mass composition of hydrogen\n",
    "O = .03;# mass composition of oxygen\n",
    "A = .07;# mass composition of ash\n",
    "mc = .19;# coal uses, [kg/s] \n",
    "ea = .3;# percentage excess air of oxygen in the air required for combustion\n",
    "Oa = .23;# percentage of oxygen by mass in the air\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "P = 100.;# air pressure, [kN/m^2]\n",
    "T = 18.+273;# air temperature, [K]\n",
    "R = .287;# [kJ/kg K]\n",
    "# basis one kg coal\n",
    "sO2 = 8./3*C+8*H;# stoichiometric O2 required, [kg]\n",
    "aO2 = sO2-.03;# actual O2 required, [kg]\n",
    "tO2 = aO2/Oa;# theoretical O2 required, [kg]\n",
    "Aa = tO2*(1+ea);# actual air supplied, [kg]\n",
    "m = Aa*mc;# Air supplied, [kg/s]\n",
    "\n",
    "# now using P*V=m*R*T\n",
    "V = m*R*T/P;# volume of air taken ,[m^3/s]\n",
    "print ' (a) Volume of air taken by fan is (m^3/s) = ',round(V,2)\n",
    "\n",
    "# (b)\n",
    "mCO2 = 11./3*C;# mass of CO2 produced, [kg]\n",
    "mO2 = aO2*.3;# mass of O2 produces, [kg]\n",
    "mN2 = Aa*.77;# mass of N2 produced, [[kg]\n",
    "mt = mCO2+mO2+mN2;# total mass, [kg]\n",
    "\n",
    "print ' (b) Percentage mass composition of CO2 is (percent) = ',round(mCO2/mt*100,2)\n",
    "print '     Percentage mass composition of O2 is (percent) = ',round(mO2/mt*100,2)\n",
    "print '     Percentage mass composition of N2 is (percent) = ',round(mN2/mt*100,2)\n",
    "\n",
    "\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 14: pg 215"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.14\n",
      " (a) Mass of fuel used per cycle is (g) =  0.444\n",
      " (b) The mass of air supplied per cycle is (kg) =  0.0136\n",
      " (c) The volume of air taken in per cycle is (m^3) =  0.0114\n"
     ]
    }
   ],
   "source": [
    "#pg 215\n",
    "print('Example 8.14');\n",
    "\n",
    "# aim : To determine \n",
    "# (a) the mass of fuel used per cycle\n",
    "# (b) the actual mass of air taken in per cycle\n",
    "# (c) the volume of air taken in per cycle\n",
    "\n",
    "# given values\n",
    "W = 15.;# work done, [kJ/s]\n",
    "N = 5.;# speed, [rev/s]\n",
    "C = .84;# mass composition of carbon\n",
    "H = .16;# mass composition of hydrogen\n",
    "ea = 1.;# percentage excess air supplied \n",
    "CV = 45000.;# calorificvalue of fuel, [kJ/kg]\n",
    "n_the = .3;# thermal efficiency\n",
    "P = 100.;# pressuer, [kN/m^2]\n",
    "T = 273.+15;# temperature, [K]\n",
    "R = .29;# gas constant, [kJ/kg K]\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "E = W*2/N/n_the;# energy supplied, [kJ/cycle]\n",
    "mf = E/CV;# mass of fuell used, [kg]\n",
    "print ' (a) Mass of fuel used per cycle is (g) = ',round(mf*10**3,3)\n",
    "\n",
    "# (b)\n",
    "# basis 1 kg fuel\n",
    "mO2 = C*8./3+8*H;# mass of O2 requirea, [kg]\n",
    "smO2 = mO2/.23;# stoichiometric mass of air, [kg]\n",
    "ma = smO2*(1+ea);# actual mass of air supplied, [kg]\n",
    "m = ma*mf;# mass of air supplied, [kg/cycle]\n",
    "print ' (b) The mass of air supplied per cycle is (kg) = ',round(m,4)\n",
    "\n",
    "# (c)\n",
    "V = m*R*T/P;# volume of air, [m^3]\n",
    "print ' (c) The volume of air taken in per cycle is (m^3) = ',round(V,4)\n",
    "\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 15: pg 216"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.15\n",
      " (a) The mass of coal used per hour is (kg) =  95.7\n",
      " (b) The mass of air supplied per hour is (kg) =  1590.0\n",
      " (c) The mass percentage composition of CO2  =   20.83  ,\n",
      "      The mass percentage composition of H2O  =  3.08  ,\n",
      "      The mass percentage composition of O2  =  3.89  ,\n",
      "      The mass percentage composition of N2  = 72.2\n"
     ]
    }
   ],
   "source": [
    "#pg 216\n",
    "print('Example 8.15');\n",
    "\n",
    "#  aim : To determine\n",
    "#  (a) the mass of coal used per hour\n",
    "#  (b) the mass of air used per hour\n",
    "#  (c) the percentage analysis of the flue gases by mass\n",
    "\n",
    "#  given values\n",
    "m = 900.;# mass of steam boiler generate/h, [kg]\n",
    "x = .96;# steam dryness fraction\n",
    "P = 1400.;# steam pressure, [kN/m^2]\n",
    "Tf = 52.;# feed water temperature, [C]\n",
    "BE = .71;# boiler efficiency\n",
    "CV = 33000.;# calorific value  of coal, [kJkg[\n",
    "ea = .22;# excess air supply\n",
    "aO2 = .23;# oxygen composition in air\n",
    "c = 4.187;# specific heat capacity of water, [kJ/kg K]\n",
    "\n",
    "#  coal composition\n",
    "C = .83;# mass composition of carbon\n",
    "H2 = .05;# mass composition of hydrogen\n",
    "O2 = .03;# mass composition of oxygen\n",
    "ash = .09;# mass composition of ash\n",
    "\n",
    "# solution\n",
    "# from steam table at pressure P\n",
    "hf = 830.1;# specific enthalpy, [kJ/kg]\n",
    "hfg = 1957.1;# specific enthalpy, [kJ/kg]\n",
    "hg = 2728.8;# specific enthalpy, [kJ/kg]\n",
    "\n",
    "# (a)\n",
    "h = hf+x*hfg;# specific enthalpy of steam generated by boiler, [kJ/kg]\n",
    "hfw = c*Tf;# specific enthalpy of feed water, [kJ/kg]\n",
    "Q = m*(h-hfw);# energy to steam/h, [kJ]\n",
    "Qf = Q/BE;# energy required from fuel/h, [kJ]\n",
    "mc = Qf/CV;# mass of coal/h,[kg]\n",
    "print ' (a) The mass of coal used per hour is (kg) = ',round(mc,1)\n",
    "\n",
    "# (b)\n",
    "# for one kg coal\n",
    "mO2 = 8./3*C+8*H2-O2;# actual mass of O2 required, [kg]\n",
    "mta = mO2/aO2;# theoretical mass of air, [kg]\n",
    "ma = mta*(1+ea);# mass of air supplied, [kg]\n",
    "mas = ma*116;# mass of air supplied/h, [kg]\n",
    "print ' (b) The mass of air supplied per hour is (kg) = ',round(mas)\n",
    "\n",
    " \n",
    "# (c)\n",
    "# for one kg coal\n",
    "mCO2 = 11./3*C;# mass of CO2 produced, [kg]\n",
    "mH2O = 9*H2;# mass of H2O produced, [kg]\n",
    "mO2 = mO2*ea;# mass of excess O2 in flue gas, [kg]\n",
    "mN2 = ma*(1-aO2);# mass of N2 in flue gas, [kg]\n",
    "\n",
    "mt = mCO2+mH2O+mO2+mN2;# total mass of gas\n",
    "x1 = mCO2/mt*100;# mass percentage composition of CO2\n",
    "x2 = mH2O/mt*100;# mass percentage composition of H2O\n",
    "x3 = mO2/mt*100;# mass percentage composition of O2\n",
    "x4 = mN2/mt*100;# mass percentage composition of N2\n",
    "\n",
    "print ' (c) The mass percentage composition of CO2  =  ',round(x1,2),' ,\\n      The mass percentage composition of H2O  = ',round(x2,2),' ,\\n      The mass percentage composition of O2  = ',round(x3,2),' ,\\n      The mass percentage composition of N2  =',round(x4,2)\n",
    "#  mass of coal taken in part (b) is wrong so answer is not matching\n",
    "\n",
    "#  End\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 16: pg 223"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.16\n",
      " (a) The volume of the gas is (m^3) =  22.4\n",
      " (b)(1) The average moleculer mass of air is (g/mol) =  28.84\n",
      "    (2) The value of R is (kJ/kg K) =  0.288\n",
      "    (3) The mass of one cubic metre of air at STP is (kg/m^3) =  1.287\n"
     ]
    }
   ],
   "source": [
    "#pg 223\n",
    "print('Example 8.16');\n",
    "\n",
    "# aim : To determine\n",
    "# (a) volume of gas\n",
    "# (b) (1) the average molecular mass of air\n",
    "#       (2) the value of R\n",
    "#       (3) the mass of 1 m^3 of air at STP\n",
    "\n",
    "# given values\n",
    "n = 1.;# moles of gas, [kmol]\n",
    "P = 101.32;# standard pressure, [kN/m^2]\n",
    "T = 273.;# gas tempearture, [K]\n",
    "\n",
    "O2 = 21.;# percentage volume composition of oxygen in air\n",
    "N2 = 79.;# percentage volume composition of nitrogen in air\n",
    "R = 8.3143;# molar gas constant, [kJ/kg K]\n",
    "mO2 = 32.;# moleculer mass of O2\n",
    "mN2 = 28.;# moleculer mass of N2\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "V = n*R*T/P;# volume of gas, [m^3]\n",
    "print ' (a) The volume of the gas is (m^3) = ',round(V,1)\n",
    "\n",
    "# (b)\n",
    "#(1)\n",
    "Mav = (O2*mO2+N2*mN2)/(O2+N2);# average moleculer mass of air\n",
    "print ' (b)(1) The average moleculer mass of air is (g/mol) = ',Mav\n",
    "\n",
    "# (2)\n",
    "Rav = R/Mav;# characteristic gas constant, [kJ/kg k]\n",
    "print '    (2) The value of R is (kJ/kg K) = ',round(Rav,3)\n",
    "\n",
    "# (3)\n",
    "rho = Mav/V;# density of air, [kg/m^3]\n",
    "print '    (3) The mass of one cubic metre of air at STP is (kg/m^3) = ',round(rho,3)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 17: pg 223"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.17\n",
      " (a)The partial pressure of O2 is (kN/m^2) =  104.0 ,\n",
      "   The partial pressure of N2 is (kN/m^2) =  104.0 \n",
      "    The partial pressure of CO2 is (kN/m^2) =  208.0\n",
      " (b) The volume of the container is (m^3) =  6.655\n",
      " (c) The new total pressure in the vessel is (kN/m^2) =  626.0\n"
     ]
    }
   ],
   "source": [
    "#pg 223\n",
    "print('Example 8.17');\n",
    "\n",
    "# aim : To determine\n",
    "# (a) the partial pressure of each gas in the vessel\n",
    "# (b) the volume of the vessel\n",
    "# (c)  the total pressure in the gas when temperature is raised to228 C\n",
    "\n",
    "# given values\n",
    "MO2 = 8.;#  mass of O2, [kg]\n",
    "MN2 = 7.;#  mass of N2, [kg]\n",
    "MCO2 = 22.;#  mass of CO2, [kg]\n",
    "\n",
    "P = 416.;# total pressure in the vessel, [kN/m^2]\n",
    "T = 273.+60;# vessel temperature, [K]\n",
    "R = 8.3143;# gas constant, [kJ/kmol K]\n",
    "\n",
    "mO2 = 32.;# molculer mass of O2 \n",
    "mN2 = 28.;# molculer mass of N2\n",
    "mCO2 = 44.;# molculer mass of CO2\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "n1 = MO2/mO2;# moles of O2, [kmol]\n",
    "n2 = MN2/mN2;# moles of N2, [kmol]\n",
    "n3 = MCO2/mCO2;# moles of CO2, [kmol]\n",
    "\n",
    "n = n1+n2+n3;# total moles in the vessel, [kmol]\n",
    "# since,Partial pressure is proportinal, so\n",
    "P1 = n1*P/n;# partial pressure of O2, [kN/m^2]\n",
    "P2 = n2*P/n;# partial pressure of N2, [kN/m^2]\n",
    "P3 = n3*P/n;# partial pressure of CO2, [kN/m^2]\n",
    "\n",
    "print ' (a)The partial pressure of O2 is (kN/m^2) = ',P1,',\\n   The partial pressure of N2 is (kN/m^2) = ',P2,'\\n    The partial pressure of CO2 is (kN/m^2) = ',P3\n",
    "\n",
    "# (b)\n",
    "# assuming ideal gas \n",
    "V = n*R*T/P;# volume of the container, [m^3]\n",
    "print ' (b) The volume of the container is (m^3) = ',round(V,3)\n",
    "\n",
    "# (c)\n",
    "T2 = 273.+228;# raised vessel temperature, [K]\n",
    "# so volume of vessel  will constant , P/T=constant\n",
    "P2 = P*T2/T;# new pressure in the vessel , [kn/m62]\n",
    "print ' (c) The new total pressure in the vessel is (kN/m^2) = ',round(P2)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 18: pg 225"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.18\n",
      " The actual mass of air supplied is (kg/kg coal) =  13.64\n",
      " The velocity of flue gas is (m/s) =  3.99\n"
     ]
    }
   ],
   "source": [
    "#pg 225\n",
    "print('Example 8.18');\n",
    "\n",
    "# aim : To determine\n",
    "# the actual mass of air supplied/kg coal\n",
    "# the velocity of flue gas\n",
    "\n",
    "# given values\n",
    "mc = 635;# mass of coal burn/h, [kg]\n",
    "ea = .25;# excess air required\n",
    "C = .84;# mass composition of carbon\n",
    "H2 = .04;# mass composition of hydrogen\n",
    "O2 = .05;# mass composition of oxygen\n",
    "ash = 1-(C+H2+O2);# mass composition of ash\n",
    "\n",
    "P1 = 101.3;# pressure, [kJn/m^2]\n",
    "T1 = 273;# temperature, [K]\n",
    "V1 = 22.4;# volume, [m^3]\n",
    "\n",
    "T2 = 273.+344;# gas temperature, [K]\n",
    "P2 = 100.;# gas pressure, [kN/m^2]\n",
    "A = 1.1;# cross section area, [m^2]\n",
    "aO2 = .23;# composition of O2 in air\n",
    "\n",
    "mCO2 = 44.;# moleculer mass of carbon\n",
    "mH2O = 18.;# molecular mass of hydrogen\n",
    "mO2 = 32.;# moleculer mas of oxygen\n",
    "mN2 = 28.;# moleculer mass of nitrogen\n",
    "\n",
    "# solution\n",
    "mtO2 = 8./3*C+8*H2-O2;# theoretical O2 required/kg coal, [kg]\n",
    "msa= mtO2/aO2;# stoichiometric mass of  air supplied/kg coal, [kg]\n",
    "mas = msa*(1+ea);# actual mass of air supplied/kg coal, [kg]\n",
    "\n",
    "m1 = 11./3*C;# mass of CO2/kg coal produced, [kg]\n",
    "m2 = 9*H2;# mass of H2/kg coal produced, [kg]\n",
    "m3 = mtO2*ea;# mass of O2/kg coal produced, [kg]\n",
    "m4 = mas*(1-aO2);# mass of N2/kg coal produced, [kg]\n",
    "\n",
    "mt = m1+m2+m3+m4;# total mass, [kg]\n",
    "x1 = m1/mt*100;# %age mass composition of CO2 produced\n",
    "x2 = m2/mt*100;# %age mass composition of H2O produced\n",
    "x3 = m3/mt*100;# %age mass composition of O2 produced\n",
    "x4 = m4/mt*100;# %age mass composition of N2 produced\n",
    "\n",
    "vt = x1/mCO2+x2/mH2O+x3/mO2+x4/mN2;# total volume\n",
    "v1 = x1/mCO2/vt*100;# %age volume composition of CO2\n",
    "v2 = x2/mH2O/vt*100;# %age volume composition of H2O\n",
    "v3 = x3/mO2/vt*100;# %age volume composition of O2\n",
    "v4 = x4/mN2/vt*100;# %age volume composition of N2\n",
    "\n",
    "Mav = (v1*mCO2+v2*mH2O+v3*mO2+v4*mN2)/(v1+v2+v3+v4);# average moleculer mass, [kg/kmol]\n",
    "# since no of moles is constant so PV/T=constant\n",
    "V2 = P1*V1*T2/(P2*T1);#volume, [m^3]\n",
    "\n",
    "mp = mt*mc/3600.;# mass of product of combustion/s, [kg]\n",
    "\n",
    "V = V2*mp/Mav;# volume of flowing gas /s,[m^3]\n",
    "\n",
    "v = V/A;# velocity of flue gas, [m/s]\n",
    "print ' The actual mass of air supplied is (kg/kg coal) = ',round(mas,2)\n",
    "print ' The velocity of flue gas is (m/s) = ',round(v,2)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 19: pg 227"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.19\n",
      " (a) The temperature of the gas after compression is (C) =  354.1\n",
      " (b) The density of air-gas mixture is (kg/m^3) =  1.133\n"
     ]
    }
   ],
   "source": [
    "#pg 227\n",
    "print('Example 8.19');\n",
    "\n",
    "# aim : To determine\n",
    "# (a) the temperature of the gas after compression\n",
    "# (b) the density of the air-gas mixture\n",
    "\n",
    "# given values\n",
    "CO = 26.;# %age volume composition of CO \n",
    "H2 = 16.;# %age volume composition of H2\n",
    "CH4 = 7.;# %age volume composition of CH4 \n",
    "N2 = 51.;# %age volume composition of N2\n",
    "\n",
    "P1 = 103.;# gas pressure, [kN/m^2]\n",
    "T1 = 273.+21;# gas temperature, [K]\n",
    "rv = 7.;# volume ratio\n",
    "\n",
    "aO2 = 21.;# %age volume composition of O2 in the air\n",
    "c = 21.;# specific heat capacity of diatomic gas, [kJ/kg K]\n",
    "cCH4 = 36.;# specific heat capacity of CH4, [kJ/kg K]\n",
    "R = 8.3143;# gas constant, [kJ/kg K]\n",
    "\n",
    "mCO = 28.;# moleculer mass of carbon\n",
    "mH2 = 2.;# molecular mass of hydrogen\n",
    "mCH4 = 16.;# moleculer mas of methane\n",
    "mN2 = 28.;# moleculer mass of nitrogen\n",
    "mO2 = 32.;# moleculer mass of oxygen\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "Cav = (CO*c+H2*c+CH4*cCH4+N2*c+100*2*c)/(100.+200);# heat capacity, [kJ/kg K]\n",
    "\n",
    "Gama = (Cav+R)/Cav;# heat capacity ratio\n",
    "# rv = V1/V2\n",
    "# process is polytropic, so\n",
    "T2 = T1*(rv)**(Gama-1);# final tempearture, [K]\n",
    "print ' (a) The temperature of the gas after compression is (C) = ',round(T2-273.15,1)\n",
    "\n",
    "# (b)\n",
    "\n",
    "Mav = (CO*mCO+H2*mH2+CH4*mCH4+N2*mN2+42*mO2+158*mN2)/(100.+200)\n",
    "\n",
    "# for 1 kmol of gas\n",
    "V = R*T1/P1;# volume of one kmol of gas, [m^3]\n",
    "# hence\n",
    "rho = Mav/V;# density of gas, [kg/m^3]\n",
    "\n",
    "print ' (b) The density of air-gas mixture is (kg/m^3) = ',round(rho,3)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 20: pg 228"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.20\n",
      "The required stoichiometric equation is  =  \n",
      "2 H2+ O2+3.76 N2 = 2 H2O+3.76 N2\n"
     ]
    }
   ],
   "source": [
    "#pg 228\n",
    "print('Example 8.20');\n",
    "\n",
    "# aim : to determine \n",
    "# stoichiometric equation for combustion of hydrogen\n",
    "\n",
    "# solution\n",
    "# equation with algebric coefficient is\n",
    "# H2+aO2+79/21*aN2=bH2O+79/21*aN2\n",
    "# by equating coefficients\n",
    "b = 1;\n",
    "a = b/2.;\n",
    "# so equation becomes\n",
    "# 2 H2+ O2+3.76 N2=2 H2O+3.76 N2\n",
    "#results\n",
    "print('The required stoichiometric equation is  =  ');\n",
    "print('2 H2+ O2+3.76 N2 = 2 H2O+3.76 N2');\n",
    "\n",
    "# End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 22: pg 229"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.22\n",
      " Percentage gravimetric composition of CO2  =  12.65   \n",
      " ,\n",
      " Percentage gravimetric composition of H2O  =  11.7   \n",
      "\n",
      " Percentage gravimetric composition of O2  =  2.77   \n",
      "\n",
      " Percentage gravimetric composition of N2  =  72.89\n"
     ]
    }
   ],
   "source": [
    "#pg 229\n",
    "print('Example 8.22');\n",
    "\n",
    "# aim : To determine\n",
    "# the percentage gravimetric analysis of the total products of combustion\n",
    "\n",
    "# given values\n",
    "CO = 12.;#  %age volume composition of CO\n",
    "H2 = 41.;#  %age volume composition of H2\n",
    "CH4 = 27.;#  %age volume composition of CH4\n",
    "O2 = 2.;#  %age volume composition of O2\n",
    "CO2 = 3.;#  %age volume composition of CO2\n",
    "N2 = 15.;#  %age volume composition of N2\n",
    "\n",
    "mCO2 = 44.;# moleculer mass of CO2,[kg/kmol]\n",
    "mH2O = 18.;# moleculer mass of H2O, [kg/kmol]\n",
    "mO2 = 32.;# moleculer mass of O2, [kg/kmol]\n",
    "mN2 = 28.;# moleculer mass of N2, [kg/kmol]\n",
    " \n",
    "ea = 15.;# %age excess air required\n",
    "aO2 = 21.;# %age air composition in the air\n",
    "\n",
    "# solution\n",
    "# combustion equation by no. of moles\n",
    "# 12CO + 41H2 + 27CH4 + 2O2 + 3CO2 + 15N2 + aO2+79/21*aN2 = bCO2 + dH2O + eO2 + 15N2 +79/21*aN2\n",
    "# equating C coefficient\n",
    "b = 12.+27+3;# [mol]\n",
    "# equatimg H2 coefficient\n",
    "d = 41.+2*27;# [mol]\n",
    "# O2 required is 15 % extra,so\n",
    "# e/(e-a)=.15 so e=.13a\n",
    "# equating O2 coefficient\n",
    "# 2+3+a=b+d/2 +e\n",
    "\n",
    "a = (b+d/2.-5)/(1-.13);\n",
    "e = .13*a;# [mol]\n",
    "\n",
    "# gravimetric analysis of product\n",
    "v1 =  b*mCO2;# gravimetric volume of CO2 \n",
    "v2 =  d*mH2O ;# gravimetric volume of H2O \n",
    "v3 = e*mO2;# gravimetric volume of O2\n",
    "v4 = 15*mN2 +79./21*a*mN2;# gravimetric volume of N2 \n",
    "\n",
    "vt = v1+v2+v3+v4;# total\n",
    "x1 = v1/vt*100;# percentage gravimetric of CO2\n",
    "x2 = v2/vt*100;# percentage gravimetric of H2O\n",
    "x3 = v3/vt*100;# percentage gravimetric of O2\n",
    "x4 = v4/vt*100;# percentage gravimetric of N2\n",
    "#results\n",
    "print ' Percentage gravimetric composition of CO2  = ',round(x1,2),'  \\n ,\\n Percentage gravimetric composition of H2O  = ',round(x2,2),'  \\n\\n Percentage gravimetric composition of O2  = ',round(x3,2),'  \\n\\n Percentage gravimetric composition of N2  = ',round(x4,2)\n",
    "\n",
    "#  End \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 23: pg 231"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.23\n",
      " (a) The mass of actual air supplied per kg of fuel is (kg) =  31.2\n",
      " (b) The volumetric efficiency of the engine is (percent) =  89.9\n"
     ]
    }
   ],
   "source": [
    "#pg 231\n",
    "print('Example 8.23');\n",
    "import math\n",
    "#  aim : To determine\n",
    "# (a) the actual quantity of air supplied/kg of fuel\n",
    "# (b) the volumetric efficiency of the engine\n",
    "\n",
    "# given values\n",
    "d = 300.*10**-3;# bore,[m]\n",
    "L = 460.*10**-3;# stroke,[m]\n",
    "N = 200.;# engine speed, [rev/min]\n",
    "\n",
    "C = 87.;#  %age mass composition of Carbon in the fuel\n",
    "H2 = 13.;#  %age mass composition of H2 in the fuel\n",
    "\n",
    "mc = 6.75;# fuel consumption, [kg/h]\n",
    "\n",
    "CO2 = 7.;# %age composition of CO2 by volume\n",
    "O2 = 10.5;# %age composition of O2 by volume\n",
    "N2 = 7.;# %age composition of N2 by volume\n",
    "\n",
    "mC = 12.;# moleculer mass of CO2,[kg/kmol]\n",
    "mH2 = 2.;# moleculer mass of H2, [kg/kmol]\n",
    "mO2 = 32.;# moleculer mass of O2, [kg/kmol]\n",
    "mN2 = 28.;# moleculer mass of N2, [kg/kmol]\n",
    "\n",
    "T = 273.+17;# atmospheric temperature, [K]\n",
    "P = 100;# atmospheric pressure, [kn/m**2]\n",
    "R =.287;# gas constant, [kJ/kg k]\n",
    "\n",
    "# solution\n",
    "# (a)\n",
    "# combustion equation by no. of moles\n",
    "# 87/12 C + 13/2 H2 + a O2+79/21*a N2 = b CO2 + d H2O + eO2 + f N2\n",
    "# equating  coefficient\n",
    "b = 87./12;# [mol]\n",
    "a = 22.7;# [mol]\n",
    "e = 10.875;# [mol]\n",
    "f = 11.8*b;# [mol]\n",
    "# so fuel side combustion equation is\n",
    "# 87/12 C + 13/2 H2 +22.7 O2 +85.5 N2\n",
    "mair = ( 22.7*mO2 +85.5*mN2)/100;# mass of air/kg fuel, [kg]\n",
    "print ' (a) The mass of actual air supplied per kg of fuel is (kg) = ',round(mair,2)\n",
    "\n",
    "# (b)\n",
    "m = mair*mc/60;# mass of air/min, [kg]\n",
    "V = m*R*T/P;# volumetric flow of air/min, [m**3]\n",
    "SV = math.pi/4*d**2*L*N/2;# swept volume/min, [m**3]\n",
    "\n",
    "VE = V/SV;# volumetric efficiency\n",
    "print ' (b) The volumetric efficiency of the engine is (percent) = ',round(VE*100,1)\n",
    "\n",
    "#  End\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 24: pg 232"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Example 8.24\n",
      " The mass of air supplied per kg of fuel is (kg) =  21.07\n"
     ]
    }
   ],
   "source": [
    "#pg 232\n",
    "print('Example 8.24');\n",
    "\n",
    "# aim : To determine\n",
    "#  the mass of air supplied/kg of fuel burnt\n",
    "\n",
    "# given values\n",
    "# gas composition in the fuel\n",
    "C = 84.;#  %age mass composition of Carbon in the fuel\n",
    "H2 = 14.;#  %age mass composition of H2 in the fuel\n",
    "O2f = 2.;# %age mass composition of O2 in the fuel\n",
    "\n",
    "# exhaust gas composition\n",
    "CO2 = 8.85;# %age composition of CO2 by volume\n",
    "CO = 1.2# %age composition of CO by volume\n",
    "O2 = 6.8;# %age composition of O2 by volume\n",
    "N2 = 83.15;# %age composition of N2 by volume\n",
    "\n",
    "mC = 12.;# moleculer mass of CO2,[kg/kmol]\n",
    "mH2 = 2.;# moleculer mass of H2, [kg/kmol]\n",
    "mO2 = 32.;# moleculer mass of O2, [kg/kmol]\n",
    "mN2 = 28.;# moleculer mass of N2, [kg/kmol]\n",
    "\n",
    "# solution\n",
    "# combustion equation by no. of moles\n",
    "# 84/12 C + 14/2 H2 +2/32 O2 + a O2+79.3/20.7*a N2 = b CO2 + d CO2+  eO2 + f N2 +g H2\n",
    "# equating  coefficient and given condition\n",
    "b = 6.16;# [mol]\n",
    "a = 15.14;# [mol]\n",
    "d = .836;# [mol]\n",
    "f = 69.3*d;# [mol]\n",
    "# so fuel side combustion equation is\n",
    "# 84/12 C + 14/2 H2 +2/32 O2 +  15.14 O2 +85.5 N2\n",
    "mair = ( a*mO2 +f*mN2)/100;# mass of air/kg fuel, [kg]\n",
    "#results\n",
    "print ' The mass of air supplied per kg of fuel is (kg) = ',round(mair,2)\n",
    "\n",
    "#  End\n"
   ]
  }
 ],
 "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.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}