{
 "metadata": {
  "name": "",
  "signature": "sha256:cba11d6ad27a555b5f3aecc639d6f99831950fba74d42eb631521eded4620d06"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 4 : Second Law of Thermodynamics"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.1  Page No : 84"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "Q1 = 250.0;#Heat absorbed in Kcal\n",
      "T1 = (260+273.0);#Temperature at which engine absorbs heat\n",
      "T0 = (40+273.0);#Temperature at which engine discards heat\n",
      "#To Calculate work output, heat rejected, entropy change of system,surronding & total change in entropy and the efficiency of the heat engine\n",
      "\n",
      "#(i)Calculation of work output\n",
      "W = (Q1*((T1-T0)/T1));#Work done umath.sing equations 4.7 & 4.9 given on page no 98\n",
      "print \"i)The work output of the heat engine is %f Kcal\"%(W);\n",
      "\n",
      "#(ii)Calculation of heat rejected\n",
      "Q2 = (Q1*T0)/T1;\n",
      "print \" ii)The heat rejected is %f Kcal\"%(Q2);\n",
      "\n",
      "#(iii)Calculation of entropy\n",
      "del_S1 = -(Q1/T1);#Change in the entropy of source in Kcal/Kg K\n",
      "del_S2 = Q2/T0;#Change in the entropy of math.sink in Kcal/Kg K\n",
      "del_St = del_S1+del_S2;#Total change in entropy in Kcal/Kg K\n",
      "print \" iii)Total change in entropy is %d confirming that the process is reversible\"%(del_St);\n",
      "\n",
      "#(iv)Calculation of efficiency\n",
      "n = (W/Q1)*100;\n",
      "print \" iv)The efficiency of the heat engine is %f percent\"%(n);\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i)The work output of the heat engine is 103.189493 Kcal\n",
        " ii)The heat rejected is 146.810507 Kcal\n",
        " iii)Total change in entropy is 0 confirming that the process is reversible\n",
        " iv)The efficiency of the heat engine is 41.275797 percent\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.2  Page No : 89"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "T1 = 373.0;#Temperature of the saturated steam in K\n",
      "T2 = 298.0;#Temperature of the saturated water in K\n",
      "#To calculate the total change in entropy and hence determine the reversibility of the process\n",
      "\n",
      "#del_H = del_Q+(V*del_P)\n",
      "#del_H =del_Q; math.since it is a consmath.tant pressure process\n",
      "\n",
      "#From steam table,\n",
      "#enthalpy of saturated steam at 373K is\n",
      "H1 = 6348.5;# in Kcal/Kg\n",
      "#enthalpy of saturated liquid water at 373K is\n",
      "H2 = 99.15;#in Kcal/Kg\n",
      "Q = H2-H1;#heat rejected in Kcal/Kg\n",
      "del_S1 = Q/T1;#change in entropy of the system in Kcal/Kg K\n",
      "del_S2 = Q/T2;#change in entropy of the surronding in Kcal/Kg K\n",
      "del_St = del_S1+del_S2;#total change in the entropy in Kcal/Kg K\n",
      "if(del_St == 0):\n",
      "    print \"Process is reversible\";\n",
      "else:\n",
      "    print \"Process is irreversible\";\n",
      "#end\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Process is irreversible\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.3  Page No : 91"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "Cp = 0.09;#specific heat of metal block in Kcal/Kg K\n",
      "m = 10.0;#mass of metal block in Kg\n",
      "T1 = 323.0;#initial temperature of the block in K\n",
      "T2 = 298.0;#final temperature of the block in K\n",
      "#consmath.tant pressure process\n",
      "#To find out entropy change of block,air and total entropy change\n",
      "\n",
      "#(i)To calculate the entropy change of block\n",
      "del_S1 = m*Cp*math.log(T2/T1);\n",
      "print \"i)Entropy change of block is %f Kcal/Kg K\"%(del_S1);\n",
      "\n",
      "#(ii)To calculate the entropy change of air\n",
      "Q = m*Cp*(T1-T2);#heat absorbed by air = heat rejected by block in Kcal\n",
      "del_S2 = (Q/T2);\n",
      "print \" ii)Entropy change of air is %f Kcal/Kg K\"%(del_S2);\n",
      "\n",
      "#(iii)To calculate the total entropy change\n",
      "del_St = del_S1+del_S2;\n",
      "print \" iii)Total entropy change is %f Kcal/Kg K\"%(del_St);\n",
      "if(del_St == 0):\n",
      "    print \" Process is reversible\";\n",
      "else:\n",
      "    print \" Process is irreversible\";\n",
      "#end\n",
      "#end \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i)Entropy change of block is -0.072503 Kcal/Kg K\n",
        " ii)Entropy change of air is 0.075503 Kcal/Kg K\n",
        " iii)Total entropy change is 0.003000 Kcal/Kg K\n",
        " Process is irreversible\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.4  Page No : 94"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "m1 = 10 #mass of metal block in Kg\n",
      "m2 = 50 #mass of water in Kg\n",
      "Cp1 = 0.09 #Specific heat of metal block in Kcal/Kg K\n",
      "Cp2 = 1 #Specific heat of water in Kcal/Kg K\n",
      "T1 = 50 #Initial temperature of block in deg celsius\n",
      "T2 = 25 #Final temperature of block in deg celsius\n",
      "\n",
      "#To calculate the total change in entropy\n",
      "#Heat lost by block = Heat gained by water\n",
      "Tf = ((m1*Cp1*T1)+(m2*Cp2*T2))/((m1*Cp1)+(m2*Cp2)) #final temperature of water in deg celsius\n",
      "Tf1 = Tf+273.16 #final temperature in K\n",
      "del_S1 = m1*Cp1*math.log(Tf1/(T1+273)) #change in entropy of the block in Kcal/K\n",
      "del_S2 = m2*Cp2*math.log(Tf1/(T2+273)) #change in entropy of the block in Kcal/K\n",
      "del_St = del_S1+del_S2\n",
      "print \"The total change entropy is \",\n",
      "print \"%.6f\" %del_St,\n",
      "print \"Kcal/K\"\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The total change entropy is  0.030226 Kcal/K\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.5  Page No : 96"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "#Air at 20 deg celsius\n",
      "#P1 = 250;initial pressure in atm\n",
      "#P2 = 10;final pressure after throttling in atm\n",
      "\n",
      "#To calculate the entropy change\n",
      "#According to the given conditions from figure4.5(page no 103)\n",
      "S1 = -0.38;#initial entropy in Kcal/Kg K\n",
      "S2 = -0.15;#final entroy in Kcal/Kg K\n",
      "del_S = S2-S1;\n",
      "print \"Change in entropy for the throttling process is %f Kcal/Kg K\"%(del_S);\n",
      "#From figure 4.6(page no 104), the final temperature is -10 deg celsius\n",
      "#end \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in entropy for the throttling process is 0.230000 Kcal/Kg K\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.7  Page No : 101"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "#Basis: 1 hour\n",
      "m = 10.0;#mass of air in Kg\n",
      "T = 293.0;#Consmath.tant temperature throughout the process in K\n",
      "#P1 = 1;#Initial pressure in atm\n",
      "#P2 = 30;#Final pressure in atm\n",
      "#According to the given data and umath.sing the graph  or figure A.2.7 given in page no 105\n",
      "S1 = 0.02;#Initial entropy in Kcal/Kg\n",
      "S2 = -0.23;#Final entropy in Kcal/Kg\n",
      "H1 = 5.0;#Initial enthalpy in Kcal/Kg\n",
      "H2 = 3.0;#Final enthalpy in Kcal/Kg\n",
      "\n",
      "W = -((H2-H1)+T*(S2-S1))*m*(427/(3600*75.0));\n",
      "print \"The horse power of the compressor is %f hp\"%(W);\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The horse power of the compressor is 1.190065 hp\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.8  Page No : 104"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "#Basis: 1 Kg of steam\n",
      "#P1 = 30;Intial pressure in Kgf/cm**2\n",
      "#P2 = 3;Final pressure in Kgf/cm**2\n",
      "#T = 300;#Operating temperature\n",
      "#From figure A.2.8, \n",
      "H1 = 715.0;#Initial enthalpy of steam in Kcal/Kg\n",
      "H2 = 625.0;#Final enthalpy of steam in Kcal/Kg\n",
      "S1 = 1.56;#Initial entropy of steam in Kcal/Kg K\n",
      "S2 = 1.61;#Final entropy of steam in Kcal/Kg K\n",
      "Q = -1.0;#heat loss in Kcal/Kg\n",
      "To = 298;#The lowest surronding temperature in K\n",
      "\n",
      "#To calculate the effectiveness of the process\n",
      "W = (-(H2-H1)+Q);#Actual work output by the turbine in Kcal\n",
      "#The maximum or available work can be calculated from equation 4.14\n",
      "del_B = -((H2-H1)-(To*(S2-S1)));# Maximum work that can be obtained in Kcal\n",
      "E = (W/del_B)*100.0;\n",
      "print \"The effectiveness of the process is %f percent\"%(E);\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The effectiveness of the process is 84.842707 percent\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 4.9  Page No : 108"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "#Given\n",
      "m = 1.0;#mass of liquid water in Kg\n",
      "T1 = 1350.0;#initial temperature in deg celsius\n",
      "T2 = 400.0;#final temperature in deg celsius\n",
      "Cp = 1.0;#Specific heat of water in Kcal/Kg K\n",
      "Cpg = 0.2;#Specific heat of combustion gases in Kcal/Kg K\n",
      "Hv = 468.35;#Heat of vapourisation at 14 Kgf/cm**2 and 194.16 deg celsius in Kcak/Kg\n",
      "To = 298.0;#Surronding temperature\n",
      "Tb = 194.16+273;#Boiling point of liquid water\n",
      "\n",
      "#To Calculate the maximum work obtained and the entropy change\n",
      "#(i)Calculation of maximum work\n",
      "#Q = del_H = m*Cp*(T2-T1); gas can be assumed to cool at consmath.tant pressure\n",
      "#From equation 4.14 (page no 110)\n",
      "del_B = -((m*Cpg*(T2-T1))-(To*m*Cp*math.log((T2+273)/(T1+273))));\n",
      "print \"i)The maximum work that can be obtained is %f Kcal/Kg of gas\"%(del_B);\n",
      "\n",
      "#(ii)To Calculate the change in entropy\n",
      "del_S =(m*Cp*math.log(Tb/To))+((m*Hv)/Tb);\n",
      "print \"ii)The entropy change per Kg of water is %f\"%(del_S);\n",
      "#end\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "i)The maximum work that can be obtained is -72.325299 Kcal/Kg of gas\n",
        "ii)The entropy change per Kg of water is 1.452126\n"
       ]
      }
     ],
     "prompt_number": 7
    }
   ],
   "metadata": {}
  }
 ]
}