{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 2 Test"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.1 Page No: 44"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Input data\n",
      "d=20.0            #Cylinder bore diameter in cm\n",
      "L=25.0            #Stroke length in cm\n",
      "Vc=1570.0         #The clearance volume in cm**3\n",
      "P1=1.0            #Pressure at the beginning of the compression in bar\n",
      "T1=300.0          #Temperature at the beginning of the compression in K\n",
      "T3=1673           #The maximum temperature of the cycle in K\n",
      "Cv=0.718          #specific heat at constant volume for air in kJ/kgK\n",
      "R=0.287           #Real gas constant in kJ/kgK\n",
      "g=1.4             #Isentropic index\n",
      "c=500.0           #Number of cycles per minute\n",
      "\n",
      "#Calculations\n",
      "import math\n",
      "Vs=(math.pi/4.0)*d**2*L\n",
      "V1=Vs+Vc\n",
      "V2=Vc                                     #cm**3\n",
      "r=V1/V2                                   #Compression ratio\n",
      "T2=T1*r**(g-1)\n",
      "P2=P1*r**g\n",
      "P3=P2*(T3/T2)                             #In constant volume, process Pressure at point 3 in bar\n",
      "T4=T3*(1/r)**(g-1)                        #In isentropic process, Temperature at point 4 in degree centigrade\n",
      "P4=P3*(1/r)**(g)                          #In isentropic process, Pressure at point 4 in bar\n",
      "no=(1-(1/r)**(g-1))*100                   #Air standard efficiency of otto cycle\n",
      "Q1=Cv*(T3-T2)                                    #Heat supplied in kJ/kg\n",
      "Q2=Cv*(T4-T1)                                    #Heat rejected in kJ/kg\n",
      "W=Q1-Q2                                          #Work done per unit mass in kJ/kg\n",
      "m=((P1*10**5*V1*10**-6)/(R*T1))/1000.0           #The amount of mass in kg\n",
      "W1=W*m                                           #Work done in kJ\n",
      "pm=((W1*10**3)/(Vs*10.0**-6))/10.0**5            #Mean effective pressure in N/m**2\n",
      "P=W1*(c/60.0)                                    #Power developed in kW\n",
      "\n",
      "#Output\n",
      "print\"Temperature at point 2 = \",round(T2-273.15,1),\"C\"\n",
      "print\"Pressure at point 2 =\" ,round(P2,2),\" bar\"\n",
      "print\"Pressure at point 3 = \",round(P3,2),\"bar\" \n",
      "print\"Temperature at point 4 = \",round(T4-273.15),\" C \\nPressure at point 4 = \",round(P4,3),\"bar\"\n",
      "print\"Air standard efficiency of otto cycle = \",round(no,2),\" percent \"\n",
      "print\"Work done = \",round(W1,2),\" kJ\"\n",
      "print\"Mean effective pressure = \",round(pm,2),\"bar \"\n",
      "print\"Power developed = \",round(P,1),\"kW \"\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Temperature at point 2 =  341.3 C\n",
        "Pressure at point 2 = 12.29  bar\n",
        "Pressure at point 3 =  33.47 bar\n",
        "Temperature at point 4 =  544.0  C \n",
        "Pressure at point 4 =  2.723 bar\n",
        "Air standard efficiency of otto cycle =  51.17  percent \n",
        "Work done =  4.26  kJ\n",
        "Mean effective pressure =  5.42 bar \n",
        "Power developed =  35.5 kW \n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.2 Page No: 46"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Input data\n",
      "CV=42000.0          #The calorific value of the fuel in kJ/kg\n",
      "pa=5.0            #Percentage of compression\n",
      "Pa=1.2            #Pressure in the cylinder at 5% compression stroke\n",
      "pb=75             #Percentage of compression\n",
      "Pb=4.8            #Pressure in the cylinder at 75% compression stroke\n",
      "g=1.3             #polytropic index\n",
      "g1=1.4            #Isentropic index\n",
      "n=0.6             #Air standard efficiency\n",
      "\n",
      "#Calculations\n",
      "V=(Pb/Pa)**(1/1.3)#Ratio of volumes\n",
      "r=(V*(pb/100.0)-(pa/100.0))/((1-(pa/100.0))-(V*(1-(pb/100.0))))               #Compression ratio\n",
      "n1=((1-(1/r)**(g1-1)))*100                                                    #Relative efficiency\n",
      "nthj=n*(n1/100.0)                                                             #Indicated thermal efficiency\n",
      "x=(1/(CV*nthj))*3600                                                          #Specific fuel consumption in kg/kW.h\n",
      "\n",
      "#Output\n",
      "print\"The compression ratio of the engine is \",round(r,1)\n",
      "print\"The specific fuel consumption is \",round(x,3),\"kg/kwh\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The compression ratio of the engine is  9.5\n",
        "The specific fuel consumption is  0.241 kg/kwh\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.4 Page No: 48"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Input data\n",
      "d=0.2           #The diameter of the cylinder bore in m\n",
      "L=0.3           #The length of the stroke in m\n",
      "P1=1            #The pressure at the beginning of the compression in bar\n",
      "T1=300.0        #The temperature at the beginning of the compression in K\n",
      "r=16.0          #Compression ratio\n",
      "V=0.08          #Cutt off takes place at 8& of the stroke\n",
      "R=0.287         #Real gas constant in kJ/kgK\n",
      "g=1.4           #Isentropic index\n",
      "Cp=1.005        #Specific heat at constant prassure in kJ/kgK\n",
      "Cv=0.718        #specific heat at constant volume for air in kJ/kgK\n",
      "\n",
      "#Calculations\n",
      "import math\n",
      "Vs=(math.pi/4.0)*d**2*L  #Swept volume in m**3\n",
      "Vc=Vs/(r-1)              #Clearance volume in m**3\n",
      "V2=Vc                    #Volume at point 2 in m**3\n",
      "V1=Vs+Vc                 #Volume at point 1 in m**3\n",
      "m=(P1*10**5*V1)/(R*T1)   #The amount of mass in kg\n",
      "P2=P1*(r**g)             #Pressure at point 2 in bar\n",
      "P3=P2                    #Pressure at point 3 in bar\n",
      "T2=T1*r**(g-1)           #Temperature at point 2 in K\n",
      "V3=(V*Vs)+V2             #Volume at point 3 in m**3\n",
      "C=V3/V2                  #Cut off ratio\n",
      "T3=C*T2                  #Temperature at point 3 in K\n",
      "P4=P3*(C/r)**g           #Pressure at the point 4 in bar\n",
      "T4=T3*(C/r)**(g-1)       #Temperature at point 4 in K\n",
      "V4=V1                    #Volume at point 4 in m**3\n",
      "Q1=(m*Cp*(T3-T2))/1000.0 #Heat supplied in kJ\n",
      "Q2=(m*Cv*(T4-T1))/1000.0 #Heat rejected in kJ\n",
      "W=(Q1-Q2)                #Work done per cycle in kJ\n",
      "na=(W/Q1)*100            #Air standard efficiency\n",
      "Pm=(W*1000/Vs)/10.0**5   #Mean effective pressure in bar\n",
      "\n",
      "#Output\n",
      "print\"(a) Volume at point 2 = \",round(V2,5),\" m**3 \\nVolume at point 1 = \",round(V1,5),\"m**3 \"\n",
      "print\"Pressure at point 2 = \",round(P2,1),\" bar\" \n",
      "print\"Temperature at point 2 = \",round(T2,1),\"K\"\n",
      "print\"beeta is\",C,\"\\nTemperature at point 3 = \",round(T3,0),\" K \\nPressure at point 4 =\",round(P4,3),\" bar\"\n",
      "print\"Temperature at point 4 = \",round(T4,1),\" K \\nVolume at point 4 = \",round(V4,5),\"m**3\" \n",
      "print\"(b) cut off ratio = \",round(c,1)\n",
      "print\"(c) Work done per cycle = \",round(W,3),\"kJ\" \n",
      "print\"(d) air smath.tandard efficiency = \",round(na,1),\" percent\" \n",
      "print\"(e)Mean effective pressure = \",round(Pm,2),\" bar \"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a) Volume at point 2 =  0.00063  m**3 \n",
        "Volume at point 1 =  0.01005 m**3 \n",
        "Pressure at point 2 =  48.5  bar\n",
        "Temperature at point 2 =  909.4 K\n",
        "beeta is 2.2 \n",
        "Temperature at point 3 =  2001.0  K \n",
        "Pressure at point 4 = 3.016  bar\n",
        "Temperature at point 4 =  904.7  K \n",
        "Volume at point 4 =  0.01005 m**3\n",
        "(b) cut off ratio =  500.0\n",
        "(c) Work done per cycle =  7.736 kJ\n",
        "(d) air smath.tandard efficiency =  60.4  percent\n",
        "(e)Mean effective pressure =  8.21  bar \n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.5 Page No:50"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#given\n",
      "P1=7\n",
      "g=1.4\n",
      "r=12\n",
      "import numpy as np\n",
      "from scipy.optimize import fsolve\n",
      "\n",
      "def f(b):\n",
      "    return P1-1/((g-1)*(r-1))*(g*r**g*(b-1)-r*(b**1.4-1))\n",
      "b = fsolve(f, 1)\n",
      "f(b)\n",
      "na=(1-(1/(r**(g-1)))*(((b**g)-1)/(g*(b-1))))*100  #Air standard efficiency\n",
      "\n",
      "#Output \n",
      "print\"The cut off ratio = \",round(b,1),\" \\n The air standard efficiency =\",na,\"percent\"\n",
      "#NOTE:In the book Answer is wrong for Air standard efficiency .\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The cut off ratio =  2.2  \n",
        " The air standard efficiency = [ 55.47110058] percent\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.6 Page no 51"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#given\n",
      "m=30.0                                  #The air fuel ratio by mass\n",
      "T1=300                                  #The temperature of air at the beginning of the compression in K\n",
      "r=16                                    #The compression ratio\n",
      "CV=42000                                #The calorific value of the fuel in kJ/kg\n",
      "g=1.4                                   #Isentropic index\n",
      "Cp=1.005                                #Specific heat at constant prassure in kJ/kgK\n",
      "\n",
      "#Calculations\n",
      "T2=T1*(r**(g-1))                        #Temperature at point 2 in K\n",
      "T3=((1/m)*(CV/Cp))+T2                   #Temperature at point 3 in K\n",
      "C=T3/T2                                 #The cut off ratio\n",
      "n=(1-((1/r**(g-1))*(((C**g)-1)/(g*(C-1)))))*100#The ideal efficiency of the engine based on the air standard cycle\n",
      "\n",
      "#Output\n",
      "print\" The ideal efficiency of the engine based on the air standard cycle = \",round(n,1)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The ideal efficiency of the engine based on the air standard cycle =  58.9\n"
       ]
      }
     ],
     "prompt_number": 30
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.7 Page No: 52"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#given\n",
      "p1=1.0      #Inlet pressure in bar\n",
      "p2=32.425   #Pressure at the end of isentropic compression in bar\n",
      "r=6.0       #Ratio of expansion\n",
      "r1=1.4      #Isentropic index\n",
      "\n",
      "#Calculations\n",
      "rc=(p2/p1)**(1/r1)     #Compression ratio\n",
      "b=(rc/r)               #cut-off ratio\n",
      "n=(1-((b**r1-1)/(rc**(r1-1)*r1*(b-1))))*100          \n",
      "pm=((p1*rc**r1*n/100.0*r1*(b-1))/((r1-1)*(rc-1))) \n",
      "\n",
      "#Output\n",
      "print\"Air-smath efficiency is \",round(n,3),\"percent\"\n",
      "print\"Mean effective pressure is \",round(pm,3),\"bar\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Air-smath efficiency is  56.671 percent\n",
        "Mean effective pressure is  5.847 bar\n"
       ]
      }
     ],
     "prompt_number": 31
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.8 Page No: 52"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Input data\n",
      "rc=15.0         #Compression ratio\n",
      "p1=1            #Pressure at which compression begins in bar\n",
      "T1=27.0+273.0   #Temperature in K\n",
      "pm=60           #Maximum pressure in bar\n",
      "h=2             #Heat transfered to air at constant volume is twice that at consmath.tant pressure\n",
      "g=1.4           #Isentropic index\n",
      "Cv=0.718        #specific heat at constant volume for air in kJ/kgK\n",
      "Cp=1.005        #specific heat at constant pressure for air in kJ/kgK\n",
      "R=0.287         #Real gas constant in kJ/kgK\n",
      "\n",
      "#Calculations\n",
      "T2=(T1*rc**(g-1))     #Temperature in K\n",
      "p2=(p1*rc**g)         #Pressure in bar\n",
      "T3=(T2*(pm/p2))       #Temperature in K\n",
      "T4=(Cv*(T3-T2))/(2*Cp)+T3   #Temperature in K\n",
      "b=(T4/T3)                   #Cut-off ratio\n",
      "T5=(T4*(b/rc)**(g-1))       #Temperature in K\n",
      "p5=(p1*(T5/T1))             #Pressure in bar\n",
      "Q1=(Cv*(T3-T2))+(Cp*(T4-T3))#Heat supplied per unit mass in kJ/kg\n",
      "Q2=Cv*(T5-T1)               #Heat rejected per unit mass in kJ/kg\n",
      "W=(Q1-Q2)                   #Workdone in kJ/kg\n",
      "n=(W/Q1)*100                #Air standard efficiency\n",
      "Vs=((1*R*1000*T1)/(p1*10**5))*(1-1/rc)   #Swept volume in m**3/kg\n",
      "pmean=((W*1000)/Vs)/10.0**5                #Mean-effective pressure in bar\n",
      "\n",
      "#Output\n",
      "print\"(a) The pressures and temperatures at the cardinal points of the cycle are \"\n",
      "print\"T2 =\",round(T2,1),\" K \\np2 =\", round(p2,1),\" bar \\nT3 = \",round(T3,1), \"K  \\np3 =\",round(p3,1),\"bar\"\n",
      "print\"T4 =\",round(T4,1),\"K  \\nT5 = \",round(T5,1), \"K  \\np5 = \",round(p5,1),\"bar\"\n",
      "print\"(b) The cycle efficiency is\",round(n,0),\"percent\" \n",
      "print\"(c) The mean effective pressure of the cycle is \",round(pmean,1),\"bar\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a) The pressures and temperatures at the cardinal points of the cycle are \n",
        "T2 = 886.3  K \n",
        "p2 = 44.3  bar \n",
        "T3 =  1200.0 K  \n",
        "p3 = 52.2 bar\n",
        "T4 = 1312.1 K  \n",
        "T5 =  460.3 K  \n",
        "p5 =  1.5 bar\n",
        "(b) The cycle efficiency is 66.0 percent\n",
        "(c) The mean effective pressure of the cycle is  2.8 bar\n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.9 Page No: 55"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Input data\n",
      "r=12.0     #Compression ratio\n",
      "B=1.615    #Cut off ratio\n",
      "p3=52.17   #Maximum pressure in bar\n",
      "p4=p3      #Maximum pressure in bar\n",
      "p1=1       #Initial pressure in bar\n",
      "T1=(62+273)    #Initial temperature in K\n",
      "n=1.35         #Indices of compression and expansion\n",
      "g=1.4          #Adiabatic exponent\n",
      "mR=0.287       #Real gas constant in kJ/kgK\n",
      "Cv=0.718       #specific heat at constant volume for air in kJ/kgK\n",
      "Cp=1.005       #specific heat at constant pressure for air in kJ/kgK\n",
      "\n",
      "#Calculations\n",
      "T2=T1*r**(n-1)     #The temperature at point 2 in K\n",
      "p2=p1*(r)**n       #The pressure at point 2 in bar\n",
      "T3=T2*(p3/p2)      #The temperature at point 3 in K\n",
      "T4=T3*B            #The temperature at point 4 in K\n",
      "T5=T4*(B/r)**(n-1) #The temperature at point 5 in K\n",
      "Q12=((g-n)/(g-1))*mR*((T1-T2)/(n-1))     # kJ/kg\n",
      "Q23=Cv*(T3-T2)                          \n",
      "Q34=Cp*(T4-T3)                            \n",
      "Q45=((g-n)/(g-1))*mR*((T4-T5)/(n-1))      \n",
      "Q51=Cv*(T1-T5)                            \n",
      "Q1=Q23+Q34+Q45                            \n",
      "Q2=-Q12+(-Q51)                           \n",
      "W=Q1-Q2                                   \n",
      "E=(W/Q1)*100                            \n",
      "Vs=((mR*T1)/p1)*(r-1)/r                   # m**3/kg\n",
      "pm=(W*1000/Vs)/10.0**3                      #Mean effective pressure in bar\n",
      "\n",
      "#Output\n",
      "print\"(a)The temperature at cardinal points \\nT2 =\",round(T2,0),\" K\\nT3 = \",round(T3,0),\"K \\nT4 = \",round(T4,0),\"K \\nT5 = \",round(T5,0),\"K \" \n",
      "print\"(b) The cycle efficiency = \",round(E,1),\" percent\"\n",
      "print\"(c) The mean effective pressure of the cycle = \",round(pm,3),\"bar\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)The temperature at cardinal points \n",
        "T2 = 799.0  K\n",
        "T3 =  1456.0 K \n",
        "T4 =  2352.0 K \n",
        "T5 =  1166.0 K \n",
        "(b) The cycle efficiency =  56.9  percent\n",
        "(c) The mean effective pressure of the cycle =  9.638 bar\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.10 Page No: 57"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Input data\n",
      "p1=1.0         #Inlet pressure in bar\n",
      "T1=27.0+273.0    #Temperature in K\n",
      "p2=4.0         #pressure at point 2 in bar\n",
      "p3=16.0        #Maximum pressure in bar\n",
      "Cv=0.573     #specific heat at constant volume for gas in kJ/kgK\n",
      "Cp=0.761     #specific heat at constant pressure for gas in kJ/kgK\n",
      "\n",
      "#Calculations\n",
      "g=(Cp/Cv)      \n",
      "T2=(T1*(p2/p1)**((g-1)/g))    # K\n",
      "T3=(p3/p2)*T2               \n",
      "T4=T3*(p1/p3)**((g-1)/g)    \n",
      "Q1=Cv*(T3-T2)                 #kJ/kg\n",
      "Q2=Cp*(T4-T1)                 \n",
      "W=Q1-Q2                       \n",
      "n=(W/Q1)*100    \n",
      "r=(p2/p1)**(1/g)\n",
      "R=(Cp-Cv)                     #kJ/kg.K\n",
      "Vs=(R*1000*T1*(r-1))/(p1*10.0**5*r)       #m**3/kg\n",
      "pm=(W/(Vs*100.0))                         \n",
      "\n",
      "#Output\n",
      "print\"(a) The work done per kg of gas is \",round(W,1),\"kJ/kg\"\n",
      "print\"(b) The efficiency of the cycle is \",round(n,1),\"percent \"\n",
      "print\"(c) Mean effective pressure is \",round(pm,1),\"bar\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a) The work done per kg of gas is  306.2 kJ/kg\n",
        "(b) The efficiency of the cycle is  42.2 percent \n",
        "(c) Mean effective pressure is  8.4 bar\n"
       ]
      }
     ],
     "prompt_number": 5
    }
   ],
   "metadata": {}
  }
 ]
}