{
 "metadata": {
  "name": "",
  "signature": "sha256:2c9e6fedd22fa6b2ae65a19697803d5aa951ae2982e5a733c3ba66fccdc2f728"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 5: Enthalpy and the Second and Third Laws of Thermodynamics"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example Problem 5.1, Page Number 84"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable Declaration\n",
      "Th, Tc = 500.,200.     #Temeperatures IN Which reversible heat engine works, K\n",
      "q = 1000.              #Heat absorbed by heat engine, J\n",
      "\n",
      "#Calcualtions\n",
      "eps = 1.-Tc/Th\n",
      "w = eps*q\n",
      "\n",
      "#Results\n",
      "print 'Efficiency of heat engine is %4.3f'%eps\n",
      "print 'Work done by heat engine is %4.1f J'%w"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Efficiency of heat engine is 0.600\n",
        "Work done by heat engine is 600.0 J\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example Problem 5.4, Page Number 87"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from sympy import integrate, symbols\n",
      "from math import log\n",
      "#Variable Declaration\n",
      "n = 1.0                #Number of moles of CO2\n",
      "Ti, Tf = 320.,650.     #Initial and final state Temeperatures of CO2, K\n",
      "vi, vf = 80.,120.      #Initial and final state volume of CO2, K\n",
      "A, B, C, D = 31.08,-0.01452,3.1415e-5,-1.4973e-8\n",
      "                       #Constants in constant volume Heat capacity equation in J, mol, K units\n",
      "R = 8.314              #Ideal Gas Constant, J/(mol.K) \n",
      "#Calcualtions\n",
      "T = symbols('T')\n",
      "dS1 = n*integrate( (A + B*T + C*T**2 + D*T**3)/T, (T,Ti,Tf)) \n",
      "dS2 = n*R*log(vf/vi)\n",
      "dS = dS1 + dS2\n",
      "#Results\n",
      "print 'Entropy change of process is %4.2f J/(mol.K)'%dS"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Entropy change of process is 24.43 J/(mol.K)\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example Problem 5.5, Page Number 88"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from sympy import integrate, symbols\n",
      "from math import log\n",
      "\n",
      "#Variable Declaration\n",
      "n = 2.5                #Number of moles of CO2\n",
      "Ti, Tf = 450.,800.     #Initial and final state Temeperatures of CO2, K\n",
      "pi, pf = 1.35,3.45     #Initial and final state pressure of CO2, K\n",
      "A, B, C, D = 18.86,7.937e-2,-6.7834e-5,2.4426e-8\n",
      "                       #Constants in constant pressure Heat capacity equation in J, mol, K units\n",
      "R = 8.314              #Ideal Gas Constant, J/(mol.K) \n",
      "#Calcualtions\n",
      "T = symbols('T')\n",
      "dS1 = n*integrate( (A + B*T + C*T**2 + D*T**3)/T, (T,Ti,Tf)) \n",
      "dS2 = n*R*log(pf/pi)\n",
      "dS = dS1 - dS2\n",
      "#Results\n",
      "print 'Entropy change of process is %4.2f J/(mol.K)'%dS"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Entropy change of process is 48.55 J/(mol.K)\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example Problem 5.6, Page Number 89"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log\n",
      "\n",
      "#Variable Declaration\n",
      "n = 3.0                #Number of moles of CO2\n",
      "Ti, Tf = 300.,600.     #Initial and final state Temeperatures of CO2, K\n",
      "pi, pf = 1.00,3.00     #Initial and final state pressure of CO2, K\n",
      "cpm = 27.98            #Specific heat of mercury, J/(mol.K)\n",
      "M = 200.59             #Molecualr wt of mercury, g/(mol)\n",
      "beta = 1.81e-4         #per K\n",
      "rho = 13.54            #Density of mercury, g/cm3\n",
      "R = 8.314              #Ideal Gas Constant, J/(mol.K) \n",
      "\n",
      "#Calcualtions\n",
      "dS1 = n*cpm*log(Tf/Ti)\n",
      "dS2 = n*(M/(rho*1e6))*beta*(pf-pi)*1e5\n",
      "dS = dS1 - dS2\n",
      "\n",
      "#Results\n",
      "print 'Entropy change of process is %4.1f J/(mol.K)'%dS\n",
      "print 'Ratio of pressure to temperature dependent term %3.1e\\nhence effect of pressure dependent term isvery less'%(dS2/dS1)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Entropy change of process is 58.2 J/(mol.K)\n",
        "Ratio of pressure to temperature dependent term 2.8e-05\n",
        "hence effect of pressure dependent term isvery less\n"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example Problem 5.7, Page Number 93"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log\n",
      "\n",
      "#Variable Declaration\n",
      "n = 1.0                #Number of moles of CO2\n",
      "T = 300.0              #Temeperatures of Water bath, K\n",
      "vi, vf = 25.0,10.0     #Initial and final state Volume of Ideal Gas, L\n",
      "R = 8.314              #Ideal Gas Constant, J/(mol.K) \n",
      "\n",
      "#Calcualtions\n",
      "qrev = n*R*T*log(vf/vi)\n",
      "w = -qrev\n",
      "dSsys = qrev/T\n",
      "dSsur = -dSsys\n",
      "dS = dSsys + dSsur\n",
      "\n",
      "#Results\n",
      "print 'Entropy change of surrounding is %4.1f J/(mol.K)'%dSsur\n",
      "print 'Entropy change of system is %4.1f J/(mol.K)'%dSsys\n",
      "print 'Total Entropy changeis %4.1f J/(mol.K)'%dS"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Entropy change of surrounding is  7.6 J/(mol.K)\n",
        "Entropy change of system is -7.6 J/(mol.K)\n",
        "Total Entropy changeis  0.0 J/(mol.K)\n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example Problem 5.8, Page Number 93"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from math import log\n",
      "\n",
      "#Variable Declaration\n",
      "n = 1.0                #Number of moles of CO2\n",
      "T = 300.0              #Temeperatures of Water bath, K\n",
      "vi, vf = 25.0,10.0     #Initial and final state Volume of Ideal Gas, L\n",
      "R = 8.314              #Ideal Gas Constant, J/(mol.K) \n",
      "\n",
      "#Calcualtions\n",
      "pext = n*R*T/(vf/1e3)\n",
      "pi = n*R*T/(vi/1e3)\n",
      "q = pext*(vf-vi)/1e3\n",
      "qrev = n*R*T*log(vf/vi)\n",
      "w = -q\n",
      "dSsur = -q/T\n",
      "dSsys = qrev/T\n",
      "dS = dSsys + dSsur\n",
      "\n",
      "#Results\n",
      "print 'Constant external pressure and initial pressure are %4.3e J,and %4.3e J respectively'%(pext,pi)\n",
      "print 'Heat in reverssible and irreversible processes are %4.1f J,and %4.1f J respectively'%(qrev,q)\n",
      "print 'Entropy change of system is %4.1f J/(mol.K)'%dSsys\n",
      "print 'Entropy change of surrounding is %4.2f J/(mol.K)'%dSsur\n",
      "print 'Total Entropy changeis %4.2f J/(mol.K)'%dS"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Constant external pressure and initial pressure are 2.494e+05 J,and 9.977e+04 J respectively\n",
        "Heat in reverssible and irreversible processes are -2285.4 J,and -3741.3 J respectively\n",
        "Entropy change of system is -7.6 J/(mol.K)\n",
        "Entropy change of surrounding is 12.47 J/(mol.K)\n",
        "Total Entropy changeis 4.85 J/(mol.K)\n"
       ]
      }
     ],
     "prompt_number": 28
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example Problem 5.9, Page Number 96"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from sympy import integrate, symbols\n",
      "from math import log\n",
      "\n",
      "#Variable Declaration\n",
      "n = 1.0                #Number of moles of CO2\n",
      "pi, pf = 1.35,3.45     #Initial and final state pressure of CO2, K\n",
      "D1 = 2.11e-3           #Constants in constant pressure Heat capacity equation for K<T<12.97K, in J, mol, K units\n",
      "A2, B2, C2, D2 = -5.666,0.6927,-5.191e-3,9.943e-4\n",
      "        #Constants in constant pressure Heat capacity equation for 12.97<T<23.66, J, mol, K units\n",
      "A3, B3, C3, D3 = 31.70,-2.038,0.08384,-6.685e-4\n",
      "        #Constants in constant pressure Heat capacity equation for 23.66<T<43.76, J, mol, K units\n",
      "A4 = 46.094 #Constants in constant pressure Heat capacity equation for 43.76<T<54.39, J/(mol.K)\n",
      "A5, B5, C5, D5 = 81.268,-1.1467,0.01516,-6.407e-5\n",
      "        #Constants in constant pressure Heat capacity equation for 54.39<T<90.20K, J, mol, K units\n",
      "A6, B6, C6, D6 = 32.71,-0.04093,1.545e-4,-1.819e-7\n",
      "        #Constants in constant pressure Heat capacity equation for 90.20<T<298.15 KJ, mol, K units\n",
      "R = 8.314         #Ideal Gas Constant, J/(mol.K) \n",
      "Ltrans1 = 93.80   #Entalpy of transition at 23.66K, J/mol\n",
      "Ltrans2 = 743.0   #Entalpy of transition at 43.76K, J/mol\n",
      "Ltrans3 = 445.0   #Entalpy of transition at 54.39K, J/mol\n",
      "Ltrans4 = 6815.   #Entalpy of transition at 90.20K, J/mol\n",
      "T1 = 12.97        #Maximum applicabliltiy temeprature for first heat capacity equation, K\n",
      "T12 = 23.66       #Phase Change temperature from Solid III--II, K\n",
      "T23 = 43.76       #Phase Change temperature from Solid II--I, K\n",
      "T34 = 54.39       #Phase Change temperature from Solid I--liquid, K\n",
      "T45 = 90.20       #Phase Change temperature from liquid--gas, K\n",
      "Ts = 298.15       #Std. Temeprature, K\n",
      "#Calcualtions\n",
      "T = symbols('T')\n",
      "dS1 = n*integrate( (D1*T**3)/T, (T,0,T1)) \n",
      "dS2 = n*integrate( (A2 + B2*T + C2*T**2 + D2*T**3)/T, (T,T1,T12)) \n",
      "dS21 = Ltrans1/T12\n",
      "dS3 = n*integrate( (A3 + B3*T + C3*T**2 + D3*T**3)/T, (T,T12,T23)) \n",
      "dS31 = Ltrans2/T23\n",
      "dS4 = n*integrate( (A4)/T, (T,T23,T34)) \n",
      "dS41 = Ltrans3/T34\n",
      "dS5 = n*integrate( (A5 + B5*T + C5*T**2 + D5*T**3)/T, (T,T34,T45)) \n",
      "dS51 = Ltrans4/T45\n",
      "dS6 = n*integrate( (A6 + B6*T + C6*T**2 + D6*T**3)/T, (T,T45,Ts))\n",
      "#print dS1+dS2,dS21\n",
      "#print dS3, dS31\n",
      "#print dS4, dS41\n",
      "#print dS5, dS51\n",
      "#print dS6\n",
      "dS = dS1+dS2+dS21+dS3+dS31+dS4+dS41+dS5+dS51+dS6\n",
      "\n",
      "#Results\n",
      "print 'Entropy change Sm0 for O2 is %4.1f J/(mol.K)'%dS"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Entropy change Sm0 for O2 is 204.8 J/(mol.K)\n"
       ]
      }
     ],
     "prompt_number": 26
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example Problem 5.10, Page Number 99"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from sympy import integrate, symbols\n",
      "from math import log\n",
      "\n",
      "#Variable Declaration\n",
      "n = 1.0                #Number of moles of CO2 formed, mol\n",
      "p = 1.                 #Pressure of CO2, K\n",
      "\n",
      "A1, B1, C1, D1 = 18.86,7.937e-2,-6.7834e-5,2.4426e-8\n",
      "        #Constants in constant pressure Heat capacity equation for CO2, J/(mol.K)\n",
      "A2, B2, C2, D2 = 30.81,-1.187e-2,2.3968e-5, 0.0\n",
      "        #Constants in constant pressure Heat capacity equation for O2, J/(mol.K)\n",
      "A3, B3, C3, D3 =  31.08,-1.452e-2,3.1415e-5 ,-1.4793e-8          \n",
      "        #Constants in constant pressure Heat capacity equation for CO, J/(mol.K)\n",
      "DSr298CO = 197.67   #Std. Entropy change for CO, J/(mol.K)\n",
      "DSr298CO2 = 213.74  #Std. Entropy change for CO, J/(mol.K)\n",
      "DSr298O2 = 205.138  #Std. Entropy change for CO, J/(mol.K)\n",
      "Tr = 475.           #Reaction temperature, K\n",
      "Ts = 298.15         #Std. temperature, K\n",
      "#Calcualtions\n",
      "T = symbols('T')\n",
      "v1,v2,v3 = 1.,1./2,1.\n",
      "DSr = DSr298CO2*v1 - DSr298CO*v1 - DSr298O2*v2\n",
      "DA = v1*A1-v2*A2-v3*A3\n",
      "DB = v1*B1-v2*B2-v3*B3\n",
      "DC = v1*C1-v2*C2-v3*C3\n",
      "DD = v1*D1-v2*D2-v3*D3\n",
      "dS = DSr + n*integrate( (DA + DB*T + DC*T**2 + DD*T**3)/T, (T,Ts,Tr)) \n",
      "\n",
      "#Results\n",
      "print 'Entropy change for reaction at %4d K is %4.2f J/(mol.K)'%(Tr,dS)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Entropy change Sm0 for O2 is 204.83 J/(mol.K)\n"
       ]
      }
     ],
     "prompt_number": 24
    }
   ],
   "metadata": {}
  }
 ]
}