{
 "metadata": {
  "name": "",
  "signature": "sha256:753b89f4a49b587e649e81b025cbd0732ffa221e89b7d46871678d863ea83955"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 3 : First Law of Thermodynamics"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.1  Page No : 50"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Given\n",
      "W = -((2*745.6*(10**-3)/4.18)*3600) #work added to the system in Kcal/hr\n",
      "m = 10.0 #Amount of fluid in math.tank in Kg\n",
      "Q = -378.0 #Heat losses from the system in Kcal/hr\n",
      "\n",
      "#To calculate the change in internal energy\n",
      "delE=(Q-W)/m # Change in internal energy in Kcal/hr kg\n",
      "print \"Change in Internal energy is \",\n",
      "print \"%.6f\"%delE,\n",
      "print \"Kcal/hr Kg\"\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in Internal energy is  90.628708 Kcal/hr Kg\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.2  Page No : 53"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "n = 1.0 #kg moles of a gas\n",
      "Cv = 5.0 #specific heat in Kcal/Kgmole\n",
      "delT = 15.0 #increase in temperature in deg celsius\n",
      "\n",
      "#To calculate the change in internal energy\n",
      "Q = n*Cv*delT #heat given to the system in Kcal\n",
      "W = 0 #work done\n",
      "delE = Q-W #Change in internal energy\n",
      "print \"Change in internal energy is \",\n",
      "print \"%.6f\"%delE,\n",
      "print \"Kcal\"\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in internal energy is  75.000000 Kcal\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.3  Page No : 55"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "P = 1.0 #consmath.tant pressure throughout the process in atm\n",
      "T1 = 273.0 #Initial temperature in K\n",
      "T2 = 373.0 #Final temperature in K\n",
      "V1 = 0.0#Volume of liquid water or initial volume\n",
      "V0 = 22.4 #volume of vapour at smath.radians(numpy.arcmath.tan(ard condition in cubic meter\n",
      "Q = 9.7 #Heat of vapourisation in Kcal\n",
      "\n",
      "#To calculate the work done by the expanding gas and increase in internal energy\n",
      "#(i)Calculation of work done\n",
      "V2 = 22.4*(T2/T1)*(P)*(10**-3) #Volume of final vapour in cubic meter\n",
      "w = P*(V2-V1) #Work done in atm cubic meter\n",
      "W = w*(1.03*10**4)/427 #Work done in Kcal\n",
      "print \"i)Work done by the expanding gas is \",\n",
      "print \"%.6f\"%W,\n",
      "print \"Kcal\"\n",
      "\n",
      "#(ii)Calculation of change in internal energy\n",
      "delE = Q-W\n",
      "print \" ii)Increase in internal energy is \",\n",
      "print \"%.6f\"%delE,\n",
      "print \"Kcal\"\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i)Work done by the expanding gas is  0.738250 Kcal\n",
        " ii)Increase in internal energy is  8.961750 Kcal\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.4  Page No : 58"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "W = 0.0 #work done during the process\n",
      "P1 = 1.0 #Initial pressure in atm\n",
      "P2 = 10.0 #Final pressure in atm\n",
      "#V2 = V1;#Initial & final volume are equal\n",
      "Cv = 0.23#specific heat at consmath.tant volume in Kcal/Kg deg K\n",
      "#(delQ/delT)=Q\n",
      "Q = 1.3 #Rate of heat addition in Kcal/min\n",
      "m = 2.5 #Weight of an ideal gas in Kg\n",
      "T1 = 298.0 #Initial temperature in Kelvin\n",
      "\n",
      "#To calculate the time taken for the gas to attain 10 atm\n",
      "#Q = m*Cv*(delT/delt)=1.3\n",
      "T2 = (P2*T1)/(P1) #Final temperature in Kelvin\n",
      "t = ((m*Cv)/1.3)*(T2-T1) #time taken in minutes\n",
      "print \"The time taken to attain a pressure of 10 atm is \",\n",
      "print \"%.6f\"%(t/60),\n",
      "print \"hours\"\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The time taken to attain a pressure of 10 atm is  19.771154 hours\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.6  Page No : 61"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "#Given\n",
      "R = 1.98 #gas consmath.tant in kcal/Kgmole deg K\n",
      "T = 293.0 #Temperature in K\n",
      "M = 29.0 #Molecular weight of air\n",
      "\n",
      "#To calculate the flow work per kg of air\n",
      "#W=(P*V)=(R*T)\n",
      "W = R*T #Flow work in Kcal/Kg mole\n",
      "W1 = W/M \n",
      "print \"Flow work is %f Kcal/Kg\"%W1\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Flow work is 20.004828 Kcal/Kg\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.7  Page No : 62"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "m = 5000.0 #Amount of steam recived per hour in Kg\n",
      "H1 = 666.0 #Specific enthalpy when steam entered in the turbine in Kcal/Kg\n",
      "H2 = 540.0 #Specific enthalpy when steam left the turbine in Kcal/Kg\n",
      "u1 = 3000/60.0 #velocity at which steam entered in m/sec\n",
      "u2 = 600/60.0 #velocity at which steam left in m/sec\n",
      "Z1 = 5.0 #height at which steam entered in m\n",
      "Z2 = 1.0#height at which steam left in m\n",
      "Q = -4000.0 #heat lost in Kcal\n",
      "g = 9.81\n",
      "\n",
      "#To calculate the horsepuwer output of the turbine\n",
      "delH = H2-H1#change in enthalpy in Kcal\n",
      "delKE = ((u2**2)-(u1**2)/(2*g))/(9.8065*427) #change in kinetic energy in Kcal; 1kgf = 9.8065 N\n",
      "delPE = ((Z2-Z1)*g)/(9.8065*427) #change in potential energy in Kcal\n",
      "W = -(m*(delH+delKE+delPE))+Q #work delivered in Kcal/hr\n",
      "W1 = W*(427/(3600*75.0))#work delivered by turbine in hp\n",
      "print \"Work delivered by turbine is %f hp\"%W1\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Work delivered by turbine is 990.133290 hp\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.8  Page No : 63"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "m = 183.0 #rate of water flow in Kg/min\n",
      "H1 = 95.0 #enthalpy of storage math.tank 1 in Kcal/Kg\n",
      "h = 15.0#height difference between two storage math.tanks in m\n",
      "Q = -10100.0 #extraced heat from storage math.tank 1 in a heat exchanger in Kcal/min\n",
      "W = -2.0 #work delivered by motor in hp\n",
      "\n",
      "# To find out the  enthalpy of water math.tank2 and the temperature of water in the second math.tank\n",
      "delPE = h/427.0 #change in potential energy in Kcal/Kg\n",
      "delKE = 0.0 #change in kinetic energy\n",
      "W1 = W*(75/427.0) #work delivered by motor in Kcal/sec\n",
      "W2 = W1*60.0#work delivered by motor in Kcal/min\n",
      "H2 = ((Q+W2)/m)-delKE-delPE+H1#enthalpy of storage math.tank 2 in Kcal/Kg\n",
      "print \"The enthalpy of storage tank 2 is %f Kcal/Kg\"%(H2)\n",
      "\n",
      "#The enthalpy H2=39.66 corresponds to the temperature T according to steam table\n",
      "T=40 #Temperature is in deg celsius\n",
      "print \" The temperature of water in the second tank is %d deg celsius\"%(T)\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The enthalpy of storage tank 2 is 39.658438 Kcal/Kg\n",
        " The temperature of water in the second tank is 40 deg celsius\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.9  Page No : 68"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#To calculate the mass of steam required\n",
      "#Given\n",
      "m2 = 100.0 #mass of water to be heated\n",
      "#From diagram, \n",
      "#m3 = m1+m2;..(a)\n",
      "#Hs = H1;..(b) math.since throttling is a consmath.tant enthalpy process\n",
      "#m3*H3-(m1*H1+m2*H2)=0;..(c) math.since delH=0\n",
      "\n",
      "#From steam tables, \n",
      "Hs = 681.7 #enthalpy of steam at 200 deg cel bleeded at the rate of 5Kgf/(cm**2) in Kcal/Kg\n",
      "H2 = 5.03 #enthalpy of liquid water at 5 deg cel\n",
      "H3 = 64.98 #enthalpy of liquid water at 65 deg cel\n",
      "#from equn (a),(b)&(c);(page no 80)\n",
      "m1 = ((H3-H2)/(Hs-H3))*m2 #mass of steam required in Kg  (page no 80)\n",
      "print \"The mass of steam required to heat 100 Kg of water is %f Kg\"%(m1)\n",
      "#end \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The mass of steam required to heat 100 Kg of water is 9.720781 Kg\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.10  Page No : 69"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "V = 0.3 #Volume of the math.tank in m**3\n",
      "P1 = 1.0 #Initial pressure of the math.tank in atm\n",
      "P2 = 0.0 #Final pressure of the math.tank in atm\n",
      "T = 298.0 #Temperature of the math.tank in K\n",
      "t = 10.0 #evacuation time in min\n",
      "\n",
      "#delN=(V/(R*T)*delP)..(a) change in moles as V and T are consmath.tant\n",
      "#delW=delN*R*T*lnP..(b)pump work required\n",
      "#From (a)&(b),delW=V*delP*lnP\n",
      "\n",
      "#To calculate the pump work required\n",
      "#On doing integration of dW we will get\n",
      "\n",
      "W = V*(P1-P2);#pump work done in J/sec\n",
      "W1=(W*(1.033*10**4))/(75*600.0);\n",
      "print \"The pump work required is %f hp\"%(W1);\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The pump work required is 0.068867 hp\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.11  Page No : 71"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "H1 = 680.6;#Enthalpy of entering steam at 6Kgf/cm**2 &200 deg cel in Kcal/Kg\n",
      "u1 = 60.0;#velocity at which steam entered the nozzle in m/sec\n",
      "u2 = 600.0;#velocity at which steam left the nozzle in m/sec\n",
      "g = 9.8;\n",
      "Hg = 642.8; Hlq = 110.2;#Enthalpy of saturated vapour & saturated liquid at 1.46 Kgf/cm**2 respectively\n",
      "\n",
      "#To calculate the quality of exit steam\n",
      "H2 = H1+((u1**2)-(u2**2))/(2*g*427);#enthalpy of leaving steam in Kcal/Kg\n",
      "x = (H2-Hlq)/(Hg-Hlq);\n",
      "print \"The quality of exit steam is %f percent\"%(x*100);\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The quality of exit steam is 99.101631 percent\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.12  Page No : 73"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "W = 0.0;#pump work\n",
      "Mi = 0.0;#chamber is initially evacuated\n",
      "M2 = 0.0;#no exist stream\n",
      "H1 = 684.2;#enthalpy of steam at 200 deg cel & 3 Kgf/cm**2\n",
      "\n",
      "#To calculate the internal energy of the steam in the chamber\n",
      "#Q=150*m1;.. (a) heat lost from the chamber in Kcal/Kg\n",
      "#m1=mf;..(b) mass of steam added from large pipe is equal to steam in chamber\n",
      " #H1*M1-Q=Mf*Ef; umath.sing (a)&(b)\n",
      "Ef = H1-150;\n",
      "print \"The internal energy of steam in chamber is %f Kcal\"%(Ef);\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The internal energy of steam in chamber is 534.200000 Kcal\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.13  Page No : 76"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "import numpy\n",
      "\n",
      "#Given\n",
      "#Q=W=delPE=delKE=0;\n",
      "#M2=0; no exit stream\n",
      "Ti = 288.0;#initial temperature in K\n",
      "H = 7*Ti;#enthalpy of air in Kcal/Kgmole\n",
      "Ei = 5*Ti;# initial internal energy of air in Kcal/Kgmole\n",
      "#Ef=5*Tf;Final internal energy of air in Kcal/Kgmole\n",
      "Pi = 0.3;#initial pressure in atm\n",
      "V = 0.57;#volume of the math.tank in m**3\n",
      "R = 848.0;#gas consmath.tant in mKgf/Kg mole K\n",
      "Pf = 1.0;#final prssure in atm\n",
      "\n",
      "#To calculate the final weight and the final temperature of the air in the math.tank\n",
      "Mi = (Pi*V*1.03*10**4)/(R*Ti);#initial quantity of air in math.tank in Kg mole\n",
      "#Tf=(Pf*V*1.033*10**4)/(Mf*R)..(a) final temperature,Mf=final quantity of air in math.tank in Kg mole\n",
      "#M1=Mf-Mi..(b) M1 is mass of steam added in Kg mole\n",
      "#H*M1=(Ef*Mf)-(Ei*Mi)\n",
      "#H*M1=((5*Pf*V*1.033*10**4)/(Tf*R))*Tf-(Ei*Mi)...(c)\n",
      "A = [[1,-1],[0,-H]];\n",
      "B = [Mi,((Ei*Mi)-((5*Pf*V*1.03*10**4)/R))];\n",
      "x = numpy.divide(A,B)\n",
      "\n",
      "Mf = x[0][0];\n",
      "print  \"The final weight of air in the tank is %f Kg\"%Mf;\n",
      "\n",
      "Tf = (Pf*V*1.03*10**4)/(Mf*R);\n",
      "print \" The final temperature of air in the tank is %f K\"%(Tf);\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The final weight of air in the tank is 138.661216 Kg\n",
        " The final temperature of air in the tank is 0.049930 K\n"
       ]
      }
     ],
     "prompt_number": 17
    }
   ],
   "metadata": {}
  }
 ]
}