{
 "metadata": {
  "name": "",
  "signature": "sha256:5402b8a22d5c9c33865300624c06c4e18489eca2e6c2f206a37644a204bd3ed3"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 2 : The First Law and Other Basic Concepts"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.1 page : 26"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "H = 100.;\t\t\t#height = 100m\n",
      "M = 1.; \t\t\t#Mass of water = 1Kg\n",
      "g = 9.8066;\t\t\t#Acceleration due to gravity(m/s**2)\n",
      "\n",
      "\n",
      "# Calculations and Results\n",
      "#(a)\n",
      "PE1 = M*H*g;\t\t\t#[j]\n",
      "print '(a)Potential energy of Water at the Top',PE1,'J'\n",
      "\n",
      "#(b)\n",
      "del_U = 0;\n",
      "KE1 = 0;\n",
      "PE2 = 0;\n",
      "KE2 = PE1;\t\t\t#[j]\n",
      "print '(b)Kinetic energy of Water',KE2,'J'\n",
      "\n",
      "#(c)\n",
      "del_U = KE2;\n",
      "print '(c)Change in Internal energy when 1kg Water added',del_U,'J'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)Potential energy of Water at the Top 980.66 J\n",
        "(b)Kinetic energy of Water 980.66 J\n",
        "(c)Change in Internal energy when 1kg Water added 980.66 J\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.3 page : 27"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "P_atm = 101.3;\t\t\t#Atm Pressure = 101.3KPa\n",
      "V1 = 0.1;\t\t\t#Volume1 = 0.1m**3\n",
      "V2 = 0.2;\t\t\t#Volume2 = 0.2m**3\n",
      "\n",
      "# Calculations\n",
      "del_V = V2-V1;\n",
      "W_by = P_atm*del_V;\n",
      "W_on = -W_by;\n",
      "Q = 0;\n",
      "del_Energy = Q+W_on;\t\t\t#KJ\n",
      "\n",
      "# Results\n",
      "print 'Energy Change',del_Energy,'KJ'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Energy Change -10.13 KJ\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.4 page : 28"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "W_acb = 40;\t\t\t#J\n",
      "Q_acb = 100;\t\t\t#J\n",
      "W_aeb = 20;\t\t\t#J\n",
      "W_bda = 30;\t\t\t#J\n",
      "\n",
      "# Calculations and Results\n",
      "del_U_ab = Q_acb-W_acb;\n",
      "\n",
      "#(a)\n",
      "Q_aeb = del_U_ab-W_aeb;\t\t\t#J\n",
      "print '(a)Heat Flow in acb',Q_aeb,'J'\n",
      "\n",
      "#(b)\n",
      "del_U_ba = -del_U_ab;\t\t\t#J\n",
      "Q_bda = del_U_ba-W_bda;\n",
      "print '(b)Heat Flow in bda',Q_bda,'J'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)Heat Flow in acb 40 J\n",
        "(b)Heat Flow in bda -90 J\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.5 page : 30"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "#(a)-Liquid Water in equllibrium with its vapour.\n",
      "N = 1;\n",
      "pi = 2;\n",
      "\n",
      "# Calculations and Results\n",
      "F = 2-pi+N;\n",
      "print '(a)Degree Of freedom is',F\n",
      "\n",
      "#(b)-Liquid Water in equllibrium with a mixture of vapour and nitrogen.\n",
      "N = 2;\n",
      "pi = 2;\n",
      "F = 2-pi+N;\n",
      "print '(b)Degree Of freedom is',F\n",
      "\n",
      "#(c)-A liquid Soln of alcohol in water in equillibrium with its vapour\n",
      "N = 2;\n",
      "pi = 2;\n",
      "F = 2-pi+N;\n",
      "print '(c)Degree Of freedom is',F\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)Degree Of freedom is 1\n",
        "(b)Degree Of freedom is 2\n",
        "(c)Degree Of freedom is 2\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.6 page no : 31"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from scipy.integrate import quad \n",
      "\n",
      "# Variables\n",
      "P = 14.;\t\t\t#Pressure = 14bar\n",
      "V1 = 0.03;\t\t\t#Initial volume = 0.03m**3\n",
      "V2 = 0.06;\t\t\t#Final Volume\n",
      "\n",
      "#Process is isothermal\n",
      "#(a)-To find the work done by gas in moving the External force\n",
      "#(b)-To find the work done by gas if external force is suddenly reduced to half its initial value\n",
      "\n",
      "# Calculations and Results\n",
      "#(a)\n",
      "K = P*V1*(10**5);\t\t\t#J\n",
      "\n",
      "def f3(V): \n",
      "    return 1./V\n",
      "\n",
      "W1 = round(-K* quad(f3,0.03,0.06)[0],2)\n",
      "\n",
      "P2 = K/V2;\t\t\t#Final Pressure(Pa)\n",
      "P2 = P2/(10**5);\t\t\t#bar\n",
      "print '(a)The work done by gas in moving the External Force is',W1,'J'\n",
      "\n",
      "#(b)\n",
      "def f4(V): \n",
      "    return 1\n",
      "\n",
      "W2 = -P2*(10**5)* quad(f4,0.03,0.06)[0]\n",
      "\n",
      "n = round((W2/W1)*100,1);\t\t\t#Efficiency\n",
      "print '(b)The work done by gas if external force is reduced to half is',W2,'J'\n",
      "print 'Hence the efficiency is',n,'%'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)The work done by gas in moving the External Force is -29112.18 J\n",
        "(b)The work done by gas if external force is reduced to half is -21000.0 J\n",
        "Hence the efficiency is 72.1 %\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.7 page no : 32"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "P = 7;\t\t\t#pressure = 7bar\n",
      "m = 45;\t\t\t#Mass of cube\n",
      "mt = 23;\t\t\t#mass of piston,piston rod,pan\n",
      "x = 0.5;\t\t\t#Dismath.tance moved = 0.5m\n",
      "g = 9.8;\t\t\t#Acceleration Due to gravity(m/s**2)\n",
      "\n",
      "# Calculations\n",
      "#Acc to Eqn del_U_sys+del_U_surr+del_PE_surr = 0\n",
      "del_PE_surr = (m+mt)*g*x;\n",
      "#ans = del_U_sys+del_U_surr\n",
      "\n",
      "# Results\n",
      "print 'Energy Changes in the Process',-del_PE_surr,'J'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Energy Changes in the Process -333.2 J\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.8 pageno : 34"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "m = 1.;     \t\t\t#1kg of water\n",
      "T = 373.15;\t    \t\t#Temp = 373.15K(100`C)\n",
      "P = 101.325;\t\t\t#Pressure = 101.325KPa\n",
      "V2 = 1.673;\t\t    \t#Final Volume[m**3]\n",
      "V1 = 0.00104;\t\t\t#Initial Volume[m**3]\n",
      "Sv_liqiud = 0.00104;\t#Specific Volume of Liqiud\n",
      "Sv_vapour = 1.673;\t\t#Specific Volume of Vapour\n",
      "del_H = 2256.9;\t\t\t#Heat Added(KJ)\n",
      "\n",
      "# Calculations\n",
      "Q = del_H;\n",
      "del_V = V2-V1;\n",
      "W = P*del_V;\t\t\t#KJ\n",
      "del_U = round(del_H-(P*del_V),1);\n",
      "\n",
      "# Results\n",
      "print 'Change in Enthalpy',del_H,'KJ'\n",
      "print 'Change in Internal energy',del_U,'KJ'\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in Enthalpy 2256.9 KJ\n",
        "Change in Internal energy 2087.5 KJ\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.9 page no : 35"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "P1 = 1.;    \t\t\t#Pressure = 1bar\n",
      "T1 = 298.15;\t\t\t#Temp = 298.15K(25`C)\n",
      "V1 = 0.02479;\t\t\t#Molar Volume = 0.02479m**3/mol\n",
      "#Final\n",
      "P2 = 5. \t\t\t#Pressure = 5bar\n",
      "Cv = 20.78;\t\t\t#J/mol/K\n",
      "Cp = 29.10;\t\t\t#J/mol/K\n",
      "\n",
      "# Calculations and Results\n",
      "#to Find del_U,del_H by two processes\n",
      "V2 = V1*(P1/P2);\t\t\t#m**3(1 mol)\n",
      "print 'Final Volume',V2,'m**3'\n",
      "\n",
      "\n",
      "#(a)-Cooling at const pressure followed by heating at const Volume\n",
      "T2 = T1*(V2/V1);\t\t\t#K\n",
      "print 'Final Temperature',T2,'K'\n",
      "\n",
      "del_H = round(Cp*(T2-T1));\t\t\t#J\n",
      "Q1 = del_H;\t\t\t#J\n",
      "del_U1 = round(del_H-(P1*(10**5)*(V2-V1)));\t\t\t#J\n",
      "\n",
      "#Second Step\n",
      "del_U2 = round(Cv*(T1-T2));\t\t\t#J\n",
      "Q2 = del_U2;\n",
      "Q = Q1+Q2;\n",
      "del_U = 0;\n",
      "W = del_U-Q;\t\t\t#J\n",
      "del_H = 0;\t\t\t#const Temperature\n",
      "\n",
      "print ('(a) Cooling at const Pressure Followed by Heating at const Volume')\n",
      "print 'Heat Required',Q,'J'\n",
      "print 'Work Required',W,'J'\n",
      "print 'Change in enthalpy',del_H,'J'\n",
      "print 'Change in Energy',del_U,'J'\n",
      "\n",
      "#(b)-heating at Const Volume Followed by cooling at const Pressure\n",
      "T2 = T1*(P2/P1);\t\t\t#K\n",
      "del_U1 = round(Cv*(T2-T1));\t\t\t#J\n",
      "Q1 = del_U1;\n",
      "del_H = round(Cp*(T1-T2));\t\t\t#J\n",
      "Q2 = del_H;\n",
      "del_U2 = round(del_H-(P2*(10**5)*(V2-V1)));\t\t\t#J\n",
      "Q = Q1+Q2;\n",
      "del_U = 0;\n",
      "W = del_U-Q;\t\t\t#J\n",
      "del_H = 0;\t\t\t#const Temperature\n",
      "print '(b) Heating at const Volume Followed by Cooling at const Pressure'\n",
      "print 'Heat Required',Q,'J'\n",
      "print 'Work Required',W,'J'\n",
      "print 'Change in enthalpy',del_H,'J'\n",
      "print 'Change in Energy',del_U,'J'\n",
      "\n",
      "\n",
      "#Note\n",
      "print ('Note : The Answer varies From That in the book because in Book 4956.44 has been rounded to \\\n",
      " 4958 which is absurd')\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Final Volume 0.004958 m**3\n",
        "Final Temperature 59.63 K\n",
        "(a) Cooling at const Pressure Followed by Heating at const Volume\n",
        "Heat Required -1985.0 J\n",
        "Work Required 1985.0 J\n",
        "Change in enthalpy 0 J\n",
        "Change in Energy 0 J\n",
        "(b) Heating at const Volume Followed by Cooling at const Pressure\n",
        "Heat Required -9923.0 J\n",
        "Work Required 9923.0 J\n",
        "Change in enthalpy 0 J\n",
        "Change in Energy 0 J\n",
        "Note : The Answer varies From That in the book because in Book 4956.44 has been rounded to  4958 which is absurd\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.10 page no : 36"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "T1 = 277.;\t\t\t#Temp = 277K\n",
      "P1 = 10.;\t\t\t#Pressure = 10bar\n",
      "V1 = 2.28;\t\t\t#molar Volume = 2.28m**3/Kmol\n",
      "\n",
      "T2 = 333.;\t\t\t#Temp = 333K\n",
      "P2 = 1. \t\t\t#Pressure = 1atm\n",
      "\n",
      "Cv = 21.;\t\t\t#KJ/Kmol/K\n",
      "Cp = 29.3;\t\t\t#KJ/Kmol/K\n",
      "\n",
      "# Calculations\n",
      "#(a)-Cooled at const Vol to the final pressure\n",
      "#(b)-Heated at const Pressure to final temperature\n",
      "T_ = T1*(1./10);\t\t\t#Intermediate temperature\n",
      "del_Ta = T_-T1;\n",
      "del_Tb = T2-T_;\n",
      "del_Ua = Cv*del_Ta;\t\t\t#KJ/Kmol\n",
      "del_Ha = del_Ua+(V1*(P2-P1)*(10**5)/(10**3));\t\t\t#KJ/Kmol\n",
      "V2 = (V1*P1*T2)/(P2*T1);\t\t\t#m**3/kmol\n",
      "del_Hb = Cp*del_Tb;\n",
      "del_Ub = del_Hb-(P2*(V2-V1)*(10**5)/(10**3));\t\t\t#KJ/Kmol\n",
      "\n",
      "del_U = round(del_Ua+del_Ub,0);\n",
      "del_H = round(del_Ha+del_Hb,0);\n",
      "\n",
      "# Results\n",
      "print 'Change In Internal Energy',del_U,'KJ/Kmol'\n",
      "print 'Change In Enthalpy',del_H,'KJ/Kmol'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change In Internal Energy 1197.0 KJ/Kmol\n",
        "Change In Enthalpy 1658.0 KJ/Kmol\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.13 page no  : 37"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\n",
      "# Variables\n",
      "M = 190.;\t\t\t#Mass = 190Kg\n",
      "T0 = 333.15;\t\t\t#Temperature = 333.15K(60`C)\n",
      "m = 0.2;\t\t\t#Steady rate of mass(Kg/s)\n",
      "T = 308.15;\t\t\t#Temperature = 308.15K(35`C)\n",
      "T1 = 283.15;\t\t\t#Temperature = 283.15K(10`C)\n",
      "\n",
      "# Calculations and Results\n",
      "#Using the Eqn (2.29)\n",
      "t = round(-(M/m)*math.log((T-T1)/(T0-T1)),1);\t\t\t#s\n",
      "print 'Time Taken for temperature of water to drop from 333.15K to 308.15K',t,'s'\n",
      "t = round(t/60);\t\t\t#min\n",
      "print 'Time Taken for temperature of water to drop from 333.15K to 308.15K',t,'min'\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Time Taken for temperature of water to drop from 333.15K to 308.15K 658.5 s\n",
        "Time Taken for temperature of water to drop from 333.15K to 308.15K 11.0 min\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.14 page no : 38"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "rQ = 4.15;\t\t\t#[g/s]  flow rate\n",
      "rQ2 = 12740.;\t\t\t#Rate of Heat addition from resismath.tance heater\n",
      "\n",
      "# Calculations\n",
      "#del_z and del_u*2 are negligible  if Ws and H1 = 0..then H2 = Q\n",
      "H2 = round(rQ2/rQ);\t\t\t#[J/g]\n",
      "\n",
      "# Results\n",
      "print 'Enthalpy of Steam',H2,'J/g'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enthalpy of Steam 3070.0 J/g\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.15 page no : 39"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "V = 600.;           \t\t\t#[m/s]\n",
      "W_compression = 240.;\t\t\t#[KJ/Kg]\n",
      "\n",
      "# Calculations\n",
      "#Umath.sing Eqn(2.32a)\n",
      "Q = (1./2*(V*V)/1000.)-W_compression;\n",
      "\n",
      "# Results\n",
      "print 'Thus Heat Removed from each KG of air compressed is',-Q,'KJ/kg'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Thus Heat Removed from each KG of air compressed is 60.0 KJ/kg\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 2.16 page no : 41"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "R = 3.15*10**-3;\t\t\t#[m**3/s]  Rate of pumping\n",
      "rH = -700.;\t\t\t#[KW]  Rate of Heat lost  \n",
      "h = 15.;\t\t\t#[m]  Height\n",
      "rW = 1.5;\t\t\t#[KW]\n",
      "rho = 958.;\t\t\t#[Kg/m**3]  at 366.65K\n",
      "g = 9.805;\n",
      "gc = 1000.;\n",
      "del_z = h;\n",
      "\n",
      "# Calculations and Results\n",
      "rm = round(R*rho,3);\t\t\t#[Kg/s]  Mass flow rate\n",
      "Q = round(rH/rm,1);\t\t\t#[KJ/Kg]\n",
      "W = round(rW/rm,3);\t\t\t#[KJ/Kg]  Shaft Work\n",
      "K = round(g/gc*del_z,3);\n",
      "\n",
      "#using Eqn(2.32b)\n",
      "del_H = Q+W-K;\n",
      "\n",
      "#From Steam tables for water at 366.65K\n",
      "H1 = 391.6;\t\t\t#[KJ/Kg]\n",
      "H2 = del_H+H1;\n",
      "print 'Enthalpy',H2,'KJ/Kg'\n",
      "\n",
      "#From Steam Tables temp at this enthalpy is\n",
      "T = 311.35;\t\t\t#[K]\n",
      "print 'Temperature in the Second tank',T,'K'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Enthalpy 160.05 KJ/Kg\n",
        "Temperature in the Second tank 311.35 K\n"
       ]
      }
     ],
     "prompt_number": 7
    }
   ],
   "metadata": {}
  }
 ]
}