{
 "metadata": {
  "name": "",
  "signature": "sha256:a96d6bb31c1b3d7ae1ce5516661e1ba259f94d24cfffad925aea849eb83692cf"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 4:WORK AND HEAT"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.1, Page No:114"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "p1=5; # Pressure of Helium gas at initial state in bar\n",
      "T1=222; # Temperature of Helium gas at initial state in K\n",
      "V1=0.055; # Volume of Helium gas at initial state in m^3\n",
      "n=1.5; # Index of expansion process\n",
      "R=2.078;# Characteristic gas constant of Helium gas in kJ/kg K\n",
      "p2=2; # Pressure of Helium gas at final state (after expansion) in bar\n",
      "\n",
      "#Calculation for Method I\n",
      "V2=V1*(p1/p2)**(1/n);# From Polytropic process relation for final volume\n",
      "W=((p2*10**2*V2)-(p1*10**2*V1))/(n-1); # Work done from Polytropic process relation\n",
      "\n",
      "#Result for Method I\n",
      "print \"Method I\"\n",
      "print \"\\nWork done =\",round(W,2),\"kJ\"\n",
      "\n",
      "#Calculation for Method II\n",
      "m=(p1*10**2*V1)/(R*T1); # ideal gas equation\n",
      "T2=T1*(p2/p1)**((n-1)/n); # From Polytropic process relation of final temperature\n",
      "W=(m*R*(T1-T2))/(1-n); # Work done from Polytropic process relation\n",
      "\n",
      "#Result for Method II\n",
      "print \"\\n\\nMethod II\"\n",
      "print \"\\nWork done =\",round(W,2),\"kJ\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Method I\n",
        "\n",
        "Work done = -14.48 kJ\n",
        "\n",
        "\n",
        "Method II\n",
        "\n",
        "Work done = -14.48 kJ\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.3, Page No:115"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "p1=1.3; # Initial pressure of gas in bar\n",
      "V1=0.03; # Initial volume of gas in m^3\n",
      "V2=0.1; # Final volume of gas in m^3\n",
      "\n",
      "#Calculation for (a)\n",
      "W=p1*10**2*(V2-V1); # work done by gas\n",
      "\n",
      "#Result for (a)\n",
      "print \"(a).Constant pressure process\"\n",
      "print \"\\nwork done by gas =\",W,\"kJ\"\n",
      "\n",
      "#Calculation for (b)\n",
      "W=p1*10**2*V1*math.log(V2/V1);# Work done by gas\n",
      "\n",
      "#Result for (b)\n",
      "print \"\\n\\n(b).Constant Temperature process\"\n",
      "print \"\\nwork done by gas =\",W,\"kJ\"\n",
      "\n",
      "#Calculation for (c)\n",
      "n=1.3; #index of polytropic process \n",
      "p2=p1*(V1/V2)**n; # From Polytropic process relation for final pressure\n",
      "W=((p2*10**2*V2)-(p1*10**2*V1))/(1-n); # Work done by gas\n",
      "\n",
      "#Result for (c)\n",
      "print \"\\n\\n(c).polytropic process of index 1.3\"\n",
      "print \"\\nwork done by gas =\",round(W,3),\"kJ\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a).Constant pressure process\n",
        "\n",
        "work done by gas = 9.1 kJ\n",
        "\n",
        "\n",
        "(b).Constant Temperature process\n",
        "\n",
        "work done by gas = 4.69549393687 kJ\n",
        "\n",
        "\n",
        "(c).polytropic process of index 1.3\n",
        "\n",
        "work done by gas = 3.941 kJ\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.4, Page No:120"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "patm=1; # Atmospheric pressure in bar\n",
      "V1=0.0135; # Volume of Freon 12 at initial state in m^3\n",
      "D=9; # Diameter of the cylinder in cm\n",
      "m=90; # Mass of the piston in kg\n",
      "g=9.80665; # acceleration due to gravity in m/s^2\n",
      "\n",
      "#Calculation for (a)\n",
      "# (a). Determination of the final pressure and volume of the system\n",
      "A=3.14/4 * (D*10**-2)**2; # Area of the cylinder\n",
      "p1=0.7449; # Initial pressure of saturated vapour at 30 degree celcius in MPa\n",
      "v1=0.023508; # Initial specific volume of saturated vapour at 30 degree celcius in m^3/kg\n",
      "p2=(patm*10**5)+(m*g)/A; # Final pressure of Freon 12\n",
      "v2=0.084022; # Final specific volume from superheated table at p2 and 30 degree celcius in m^3/kg\n",
      "mf=V1/v1; # Mass of Freon 12\n",
      "V2=mf*v2; # Final volume of Freon 12\n",
      "\n",
      "#Result for (a)\n",
      "print \"(a)\",\"\\nFinal pressure = \",p2,\"Pa\",\"\\nFinal volume = \",round(V2,5),\"m^3   (round off error)\"\n",
      "\n",
      "#Calculation for (b)\n",
      "# (b). Calculation of workdone by Freon 12 during this process\n",
      "Wirrev=p2*(V2-V1);  # P dv Work done \n",
      "\n",
      "#Result for (b)\n",
      "print \"\\n\\n(b)\",\"\\nWork done = \",round(Wirrev/1000,3),\"kJ   (round off error)\"\n",
      "\n",
      "#Calculation for (c)\n",
      "# (c). Calculation of workdone by Freon 12 during reversible process\n",
      "Wrev=p1*10**6*V1*math.log (V2/V1);#From reversible process relation for work done\n",
      "\n",
      "#Result for (c)\n",
      "print \"\\n\\n(c)\",\"\\nWork done in reveersible process = \",round(Wrev/1000,2),\"kJ   (round off error)\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a) \n",
        "Final pressure =  238806.086341 Pa \n",
        "Final volume =  0.04825 m^3   (round off error)\n",
        "\n",
        "\n",
        "(b) \n",
        "Work done =  8.299 kJ   (round off error)\n",
        "\n",
        "\n",
        "(c) \n",
        "Work done in reveersible process =  12.81 kJ   (round off error)\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.5, Page No:129"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "p1=0.1; # Initial pressure (before compression) of air in MPa\n",
      "T1=30; # Initial temperature (before compression) of air in degree celcius\n",
      "p2=0.9; # Final pressure (after compression) of air in MPa\n",
      "R=0.287; # Characteristic constant of air in kJ/kg k\n",
      "\n",
      "# (i) Actual work in the flow process\n",
      "\n",
      "#Calculation for (a)\n",
      "# (a).Isothermal Process\n",
      "w=-R*(T1+273)*math.log (p2/p1); # work done for isothermal process\n",
      "\n",
      "#Result for (a)\n",
      "print \"(i) Actual work in the flow process\",\"\\n(a).Isothermal Process\",\"\\nwork done = \",round(w,1),\"kJ/kg\"\n",
      "\n",
      "#Calculation for (b)\n",
      "# (b).Polytropic process\n",
      "n=1.4; # Index of polytropic process\n",
      "T2=(T1+273)*(p2/p1)**((n-1)/n); # From Polytropic process relation for final temperature\n",
      "w=(n/(1-n))*R*(T2-(T1+273)); # work done for polytropic process\n",
      "\n",
      "#Result for (b)\n",
      "print \"\\n\\n(b).Polytropic process\",\"\\ncompression work = \",round(w,1),\"kJ/kg\"\n",
      "\n",
      "# (ii).Nonflow work\n",
      "\n",
      "#Calculation for (a)\n",
      "# (a).Isothermal Process\n",
      "w=-R*(T1+273)*math.log (p2/p1); # work done for isothermal process\n",
      "\n",
      "#Result for (a)\n",
      "print \"\\n\\n\\n(ii).Nonflow work\",\"\\n(a).Isothermal Process\",\"\\nwork done = \",round(w,1),\"kJ/kg\"\n",
      "\n",
      "#Calculation for (b)\n",
      "# (b).Polytropic process\n",
      "w=(1/(1-n))*R*(T2-(T1+273));# work done for polytropic process\n",
      "\n",
      "#Result for (b)\n",
      "print \"\\n\\n(b).Polytropic process\",\"\\ncompression work = \",round(w,1),\"kJ/kg\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(i) Actual work in the flow process \n",
        "(a).Isothermal Process \n",
        "work done =  -191.1 kJ/kg\n",
        "\n",
        "\n",
        "(b).Polytropic process \n",
        "compression work =  -265.8 kJ/kg\n",
        "\n",
        "\n",
        "\n",
        "(ii).Nonflow work \n",
        "(a).Isothermal Process \n",
        "work done =  -191.1 kJ/kg\n",
        "\n",
        "\n",
        "(b).Polytropic process \n",
        "compression work =  -189.9 kJ/kg\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.6, Page No:135"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "p1=1; # Initial pressure (before compression) of air in bar\n",
      "p2=8; # Final pressure (after compression) of air in bar\n",
      "Vp=15; # Displacement volume of reciprocating air compressor in litres\n",
      "Vc=0.05*Vp; # Clearance volume of reciprocating air compressor in litres\n",
      "N=600; # Speed of compressor in rpm\n",
      "V1=Vc+Vp; # Total volume of reciprocating air compressor in litres\n",
      "p3=p2; # constant pressure process\n",
      "p4=p1; # constant pressure process\n",
      "V3=Vc;# Clearance volume of reciprocating air compressor in litres\n",
      "n=1.3; # Index of reversible adiabatic compression process\n",
      "m=1.4; # Index of reversible adiabatic expansion process\n",
      "V4=V3*(p3/p4)**(1/m);\n",
      "\n",
      "#Calculation for (a)\n",
      "# (a).Work per machine cycle\n",
      "Wcycle = ((n/(n-1))*p1*10**2*V1*10**-3*(1-(p2/p1)**((n-1)/n)))-((m/(m-1))*p4*10**2*V4*10**-3*(1-(p3/p4)**((m-1)/m)));\n",
      "# Work per machine cycle\n",
      "Wpower=abs (Wcycle)*(N/60); # Power consumption of the compressor\n",
      "\n",
      "#Result for (a)\n",
      "print \"(a)\",\"\\nWork per machine cycle = \",round(Wcycle,3),\"kJ   (Error in textbook)\"\n",
      "print \"\\nPower consumption of the compressor\",round(Wpower,2),\"kW\"\n",
      "\n",
      "#Calculation for (b)\n",
      "# (b).Work of the cycle if m=n\n",
      "m=n;\n",
      "W_cycle=(n/(n-1))*p1*10**2*(V1-V4)*10**-3*(1-(p2/p1)**((n-1)/n)); # Work per machine cycle\n",
      "er=((W_cycle-Wcycle)/Wcycle) * 100 # Error involved in calculating work if m=n\n",
      "\n",
      "#Result for (b)\n",
      "print \"\\n\\n(b)\",\"\\nWork per machine cycle\",round(W_cycle,3),\"kJ  (round off error)\"\n",
      "print \"\\nError = \",round(er,3),\"%   (Error in textbook)\"\n",
      "\n",
      "#Calculation for (c)\n",
      "# (c).Clearance volumetric efficiency\n",
      "C=Vc/Vp;\n",
      "eff = 1+C+-C*(p2/p1)**(1/n); # Clearance volumetric efficiency\n",
      "\n",
      "#Result for (c)\n",
      "print \"\\n\\n(c).\",\"\\nClearance volumetric efficiency = \",round(eff*100,0),\"%\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a) \n",
        "Work per machine cycle =  -3.263 kJ   (Error in textbook)\n",
        "\n",
        "Power consumption of the compressor 32.63 kW\n",
        "\n",
        "\n",
        "(b) \n",
        "Work per machine cycle -3.319 kJ  (round off error)\n",
        "\n",
        "Error =  1.739 %   (Error in textbook)\n",
        "\n",
        "\n",
        "(c). \n",
        "Clearance volumetric efficiency =  80.0 %\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.7, Page No:137"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "D=150; # Cylinder Diameter in mm\n",
      "L=200; # Piston stroke in mm\n",
      "C=0.05; # Clearance factor\n",
      "p1=15; # Steam inlet conditions (saturated) in bar\n",
      "p4=1; # Exhaust or back pressure in bar\n",
      "p2=p1; # Constant pressure process\n",
      "p5=p4; # Constant pressure process\n",
      "\n",
      "#Calculation\n",
      "Vp=(3.14*(D*10**-3)**2*L*10**-3)/4; # Swept volme of cylinder\n",
      "Vc=C*Vp; # Clearance volume of cylinder\n",
      "V3=Vc+Vp; # Total volume of cylinder\n",
      "V1=Vc; # Clearance volume\n",
      "V6=V1; # constant volume process\n",
      "V4=V3; # constant volume process\n",
      "V5=Vc+0.3*Vp; # Compression begins at 30% of stroke\n",
      "V2=Vc+0.4*Vp; # Cut-off occurs at 40% of stroke\n",
      "p6=p5*(V5/V6); # Pressure after compression\n",
      "Wcycle=(p1*10**2*(V2-V1))+(p2*10**2*V2*math.log (V3/V2))-(p4*10**2*(V4-V5))-(p5*10**2*V5* math.log(V5/V6)); # Work per Cycle\n",
      "\n",
      "#Result\n",
      "print \"Work per cycle =\",round(Wcycle,3),\"kJ\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work per cycle = 3.652 kJ\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.8, Page No:142"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "D=10; #Bore in cm\n",
      "L=12.5; #Stroke length in cm\n",
      "a=9.68; # Area of indicator card in cm^2\n",
      "l=5.33; # Card length in cm\n",
      "Ks=21.7; # Indicator spring constant per meter of card length\n",
      "\n",
      "#Calculation\n",
      "A=(3.14*(D*10**-2)**2)/4; # Area of pisaton\n",
      "Pm=(a/l)*10**-2*Ks*10**6; # Mean effective pressure\n",
      "W=Pm*A*L*10**-2; # Work done by cycle\n",
      "\n",
      "#Result\n",
      "print \"Work done by cycle = \",round(W,0),\"kJ\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work done by cycle =  387.0 kJ\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.9, Page No:142"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "D=152; # Bore of steam engine in mm\n",
      "l=89; # Stroke length of steam engine in mm\n",
      "a1=8;a2=10; # area of indicatior diagram on two sides\n",
      "Ks=50; # Indicator spring constant in lbf/in^2/in\n",
      "N=310; # Engine speed in rpm\n",
      "d=0.664; # Diameter of flywheel in m\n",
      "\n",
      "#Calculation for (a)\n",
      "# (a)\n",
      "a=(a1+a2)/2; # Average area of indicator diagram\n",
      "Ks=50*4.44822/(0.0254)**3; # Unit conversion from lbf/in^2/in to N/m^2\n",
      "pm=(a/(l/10))*10**-2*Ks; # Mean effective pressure \n",
      "A=(3.14*(D*10**-3)**2)/4; # Area of the piston\n",
      "IP=2*pm*l*10**-3*A*N/60; # Indicated power\n",
      "\n",
      "#Result for (a)\n",
      "print \"(a)\",\"\\nIndicated power of Engine =\",round(IP/1000,2),\"kW\"\n",
      "\n",
      "#Calculation for (b)\n",
      "# (b)\n",
      "F=12-1.5; # Tangential force on the brake drum in kgf\n",
      "BP=F*9.81*d/2*2*3.14*N/60; # Brake power of Engine\n",
      "eff=BP/IP *100 ; # Mechanical efficiency \n",
      "\n",
      "#Result for (b)\n",
      "print \"\\n\\n(b)\",\"\\nBrake power of Engine = \",round(BP/1000,2),\"kW\",\"\\nMechanical efficiency of Engine =\",round(eff,2),\"%\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a) \n",
        "Indicated power of Engine = 2.29 kW\n",
        "\n",
        "\n",
        "(b) \n",
        "Brake power of Engine =  1.11 kW \n",
        "Mechanical efficiency of Engine = 48.47 %\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.10, Page No:156"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "Tc1=10; # Feed water inlet temperature in degree celcius\n",
      "Tc2=77; # Feed water outlet temperature in degree celcius\n",
      "th1=166; # Initial temperature of flue gas in degree celcius\n",
      "r=4; # Ratio of mass flow rates of flue gases and water\n",
      "Ch=1.05; # The specific heat of flue gas in kJ/kg K\n",
      "Cc=4.187; # The specific heat of feed water in kJ/kg K\n",
      "U=114; # Overall heat transfer coefficient in W/m^2\n",
      "mc=1; # massflowrate of feed water in kg/s\n",
      "\n",
      "#Calculation for Parallel flow\n",
      "th2=th1-((Cc*(Tc2-Tc1))/(r*Ch)); # Outlet temperature of flue gas in degree celcius\n",
      "Q=mc/3600*Cc*(Tc2-Tc1); # Heat transfer rate per kg/h of water flow\n",
      "# Parallel flow    \n",
      "del_Tm=((th1-Tc1)-(th2-Tc2))/math.log ((th1-Tc1)/(th2-Tc2)); # Logarthamic Mean Temperature Difference in degree celcius\n",
      "A=Q*10**3/(U*del_Tm); # Economiser surface area\n",
      "\n",
      "#Result for Parallel flow\n",
      "print \" (a)Parallel flow\",\"\\nLogarthamic Mean Temperature Difference=\",round(del_Tm,1),\"degree celcius\",\n",
      "print \"\\nEconomiser surface area =\",round(A,2),\"m^2\"\n",
      "\n",
      "#Calculation for Counter flow\n",
      "# Counter flow\n",
      "del_Tm=((th1-Tc2)-(th2-Tc1))/math.log ((th1-Tc2)/(th2-Tc1)); # Logarthamic Mean Temperature Difference in degree celcius\n",
      "A=Q*10**3/(U*del_Tm); # Economiser surface area\n",
      "\n",
      "#Result for Counter flow\n",
      "print\" \\n\\n(b) Counter flow\",\"\\nLogarthamic Mean Temperature Difference=\",round(del_Tm,1),\"degree celcius\",\n",
      "print \"\\nEconomiser surface area =\",round(A,5),\"m^2\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " (a)Parallel flow \n",
        "Logarthamic Mean Temperature Difference= 68.6 degree celcius \n",
        "Economiser surface area = 0.01 m^2\n",
        " \n",
        "\n",
        "(b) Counter flow \n",
        "Logarthamic Mean Temperature Difference= 89.1 degree celcius \n",
        "Economiser surface area = 0.00767 m^2\n"
       ]
      }
     ],
     "prompt_number": 9
    }
   ],
   "metadata": {}
  }
 ]
}