{
 "metadata": {
  "name": "",
  "signature": "sha256:6ced269b2d83adfe9e452136249f918e5748b410340744d57a784dbf4aa451de"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 8 : Entropy - Available and Unavailable Energy"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.2 Page No : 211"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "Q = 10. \t\t\t#kJ \t\t\t#heat transfered from reservoir\n",
      "T = 100.+273 \t\t\t#K \t\t\t#isothermal expansion temperature\n",
      "T_res = 300.+273 \t\t\t#K \t\t\t#reservoir temperature\n",
      "\t\t\t\n",
      "# Calculations and Results\n",
      "delta_S_sys = (Q/T) \t\t\t#kJ/K \t\t\t#delta S for the system\n",
      "print \"Change in entropyDelta S) for the system = %.2e kJ/K\"%(delta_S_sys);\n",
      "\n",
      "delta_S_res = -1*(Q/T_res) \t\t\t#kJ/K \t\t\t#delta S for the reservoir\n",
      "print \"Change in entropyDelta S) for the reservoir = %.4e kJ/K\"%(delta_S_res);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in entropyDelta S) for the system = 2.68e-02 kJ/K\n",
        "Change in entropyDelta S) for the reservoir = -1.7452e-02 kJ/K\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.3 Page No : 212"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "Q = 10. \t\t\t#kJ \t\t\t#heat transfered from reservoir\n",
      "T = 100.+273 \t\t\t#K \t\t\t#isothermal expansion temperature\n",
      "T_res = 100.+273 \t\t\t#K \t\t\t#reservoir temperature\n",
      "\t\t\t\n",
      "# Calculations and Results\n",
      "delta_S_sys = (Q/T) \t\t\t#kJ/K \t\t\t#delta S for the system\n",
      "print \"Change in entropyDelta S) for the system = %.2e kJ/K\"%(delta_S_sys)\n",
      "\n",
      "delta_S_res = -1*(Q/T_res) \t\t\t#kJ/K \t\t\t#delta S for the reservoir\n",
      "print \"Change in entropyDelta S) for the reservoir = %.2e kJ/K\"%(delta_S_res);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in entropyDelta S) for the system = 2.68e-02 kJ/K\n",
        "Change in entropyDelta S) for the reservoir = -2.68e-02 kJ/K\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.4 Page No : 212"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "Q = 1.; \t\t\t#kJ \t\t\t#heat transfered from reservoir\n",
      "T = 100.+273; \t\t\t#K \t\t\t#isothermal expansion temperature\n",
      "T_res = 100.+273; \t\t\t#K \t\t\t#reservoir temperature\n",
      "\t\t\t\n",
      "# Calculations and Results\n",
      "delta_S_res = -1*(Q/T_res); \t\t\t#kJ/K \t\t\t#delta S for the reservoir\n",
      "print \"Change in entropyDelta S) for the reservoir = %.2e kJ/K\"%(delta_S_res);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Change in entropyDelta S) for the reservoir = -2.68e-03 kJ/K\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.12 Page No : 225"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Variables\n",
      "pA = 120. \t\t\t#kPa \t\t\t#Pressure at location A\n",
      "TA = 50.+273 \t\t\t#K \t\t\t#Temperature at location A\n",
      "VA = 150. \t\t\t#m/s \t\t\t#Velocity at location A\n",
      "\n",
      "pB = 100. \t\t\t#kPa \t\t\t#Pressure at location B\n",
      "TB = 30.+273 \t\t\t#K \t\t\t#Temperature at location B\n",
      "VB = 250. \t\t\t#m/s \t\t\t#Velocity at location B\n",
      "\n",
      "Cp = 1.005 \t\t\t#kJ/kg\n",
      "R = 0.287 \t\t\t#kJ/kgK\n",
      "\t\t\t\n",
      "# Calculations and Results\n",
      "delta_S_sys = (Cp*math.log(TB/TA))-(R*math.log(pB/pA)) \t\t\t#kJ/kgK \t\t\t#Entropy of system\n",
      "if delta_S_sys < 0 :\n",
      "    print \"Flow is from B to A.\";\n",
      "else:\n",
      "    print \"Flow is from A to B.\"    \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Flow is from B to A.\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.13 Page No : 226"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "# Variables\n",
      "mi = 5. \t\t\t#kg \t\t\t#mass of ice\n",
      "Ti = 273. - 10 \t\t\t#K \t\t\t#Temperature of ice\n",
      "ci = 2.1 \t\t\t#kJ/kgK \t\t\t#specific heat of ice\n",
      "L = 330. \t\t\t#kJ/kg \t\t\t#Latent heat\n",
      "mw = 20. \t\t\t#kg \t\t\t#mass of water\n",
      "Tw = 273.+80 \t\t\t#K \t\t\t#Temperatur of water\n",
      "cw = 4.2 \t\t\t#kJ/kgK \t\t\t#specific heat of water\n",
      "\n",
      "# calculatins and results\n",
      "\n",
      "#Part(a)\n",
      "print \"Part a\";\n",
      "Tmix = ((mi*ci*(Ti-273))-(L*mi)+(mw*cw*Tw)+(mi*cw*273))/(mw*cw+mi*cw)\n",
      "print \"Temperature of the mixture when equilibrium is established between ice and water = %.f K\"%(Tmix)\n",
      "#Part (b)\n",
      "print \"Part b\";\n",
      "delta_S_ice = mi*(ci*math.log(273/Ti)+L/273+cw*math.log(Tmix/273))\t\t\t#kJ/K \t\t\t#Entropy of ice\n",
      "print \"Entropy of ice = %.2f kJ/K\"%(delta_S_ice)\n",
      "#Part (c)\n",
      "print \"Part c\";\n",
      "delta_S_water = mw*(cw*math.log(Tmix/Tw))\t\t\t#kJ/K \t\t\t#Entropy of water\n",
      "print \"Entropy of water = %.2f kJ/K\"%(delta_S_water)\n",
      "#Part (d)\n",
      "print \"Part d\";\n",
      "delta_S_uni = delta_S_water+delta_S_ice\t\t\t#kJ/K \t\t\t#Entropy of universe\n",
      "print \"Entropy of universe = %.2f kJ/K\"%(delta_S_uni)\n",
      "\n",
      "# note : rounding off error"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part a\n",
        "Temperature of the mixture when equilibrium is established between ice and water = 320 K\n",
        "Part b\n",
        "Entropy of ice = 9.79 kJ/K\n",
        "Part c\n",
        "Entropy of water = -8.17 kJ/K\n",
        "Part d\n",
        "Entropy of universe = 1.62 kJ/K\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.14 Page No : 230"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "Q1 = 100. \t\t\t#kJ \t\t\t#Heat input\n",
      "T0 = 300. \t\t\t#K \t\t\t#Surrounding temperature\n",
      "\n",
      "\t\t\t#Part(a)\n",
      "print \"Part a\";\n",
      "T1 = 1000. \t\t\t#K \t\t\t#reservoir temperature\n",
      "print \"Avalable enery of 100 kJ of heat from a reservoir at 1000K = %.f kJ\"%(Q1*1-T0/T1)\n",
      "print \"Unvalable enery of 100 kJ of heat from a reservoir at 1000K = %.1f kJ\"%(Q1*(1-(T0/T1)))\n",
      "\t\t\t#Part(b)\n",
      "print \"Part b\";\n",
      "T1 = 600 \t\t\t#K \t\t\t#reservoir temperature\n",
      "print \"Avalable enery of 100 kJ of heat from a reservoir at 1000K = %.f kJ\"%(Q1*1-T0/T1)\n",
      "print \"Unvalable enery of 100 kJ of heat from a reservoir at 1000K = %.1f kJ\"%(Q1*(1-(T0/T1)))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Part a\n",
        "Avalable enery of 100 kJ of heat from a reservoir at 1000K = 100 kJ\n",
        "Unvalable enery of 100 kJ of heat from a reservoir at 1000K = 70.0 kJ\n",
        "Part b\n",
        "Avalable enery of 100 kJ of heat from a reservoir at 1000K = 100 kJ\n",
        "Unvalable enery of 100 kJ of heat from a reservoir at 1000K = 50.0 kJ\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.15 Page No : 231"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "T0 = 300. \t\t\t#K \t\t\t#Surrounding temperature\n",
      "T1 = 1000. \t\t\t#K \t\t\t#Temperature of final reservoir\n",
      "T2 = 600. \t\t\t#K \t\t\t#Temperature of intermediate reservoir\n",
      "Q1 = 100. \t\t\t#kJ \t\t\t#Heat input\n",
      "\t\t\t\n",
      "# Calculations and Results\n",
      "print \"Increase in unavaliable energy due to irreversible heat transfer = %.1f kJ\"%(Q1*(1-T0/T1)-Q1*(1-T0/T2))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Increase in unavaliable energy due to irreversible heat transfer = 20.0 kJ\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.16 Page No : 234"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "T1 = 500. \t\t\t#K\n",
      "T0 = 300. \t\t\t#K\n",
      "T2 = 350. \t\t\t#K\n",
      "W = 250. \t\t\t#kJ\n",
      "Q1 = 1000. \t\t\t#kJ\n",
      "\n",
      "# Results\n",
      "print \"Available energy = %.1f kJ\"%(((1-T0/T1))*Q1);\n",
      "print \"Unavailable energy = %.1f kJ\"%(Q1 - (((1-T0/T1))*Q1));\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Available energy = 400.0 kJ\n",
        "Unavailable energy = 600.0 kJ\n"
       ]
      }
     ],
     "prompt_number": 20
    }
   ],
   "metadata": {}
  }
 ]
}