{
 "metadata": {
  "name": "",
  "signature": "sha256:503de9d648d2755ec204b8822b124187c44f6b43ec4e442774530019aef1c520"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 3 : The Simplest Phase Equilibrium Examples and Some Simple Estimating Rules"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.1  Page: 52\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "T = 20.         #[C]\n",
      "P = 1.          #[atm]\n",
      "\n",
      "x_N2 = 0\n",
      "x_O2 = 0\n",
      "x_water = 1-x_N2-x_O2\n",
      "p_water = 0.023     #[atm]\n",
      "y_water = x_water*p_water/P\n",
      "\n",
      "print \"The mole fraction of water vapour in air in equilibrium with water is %f\"%(y_water)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The mole fraction of water vapour in air in equilibrium with water is 0.023000\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.2   Page: 53\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "T = 20.         #[C]\n",
      "P = 1.          #[atm]\n",
      "y_water = 0.023\n",
      "y = 1-y_water\n",
      "y_O2 = y*0.21\n",
      "H_O2 = 40100        #[atm]\n",
      "x_O2 = y_O2*P/H_O2\n",
      "y_N2 = y*0.79\n",
      "H_N2 = 80400.       #[atm]\n",
      "\n",
      "x_N2 = y_N2*P/H_N2\n",
      "c = x_O2*998.2/18   #[(mole O2)/(L solution)]\n",
      "V = c*24.06         #[(L O2, STP)/(L solution)]\n",
      "V = V*1000          #[(ml O2, STP)/(L solution)]\n",
      "\n",
      "print \"Concentration of oxygen dissolved in water at equilibrium is %f mL O2, STP)/L solution)\"%(V)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Concentration of oxygen dissolved in water at equilibrium is 6.826690 mL O2, STP)/L solution)\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.3  Page: 52\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "from numpy import *\n",
      "\n",
      "P = 1.0             #[atm]\n",
      "p_w = 0.023         #[atm] Vapor pressure of pure water\n",
      "H_o = 40100         #[atm] Vapor pressure of pure oxygen\n",
      "H_n = 80400.        #[atm] Vapor pressure of pure nitrogen\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "A = matrix([[0.023, 0, 0, -1, 0, 0],[0, 40100, 0, 0, -1, 0],[0, 0 ,80400, 0, 0, -1],[0, 0, 0, 1, 1 ,1],[1 ,1, 1, 0, 0 ,0],[0, 0, 0, 0, 0.79, -0.21]]);\n",
      "B = matrix([[0],[0],[0],[1],[1],[0]])\n",
      "X = linalg.inv(A)\n",
      "X = X * B\n",
      "\n",
      "print \" The composition in liquid and vapor phase are summarized in the following table:\"\n",
      "print \"    y_water       \\t %f\"%(X[3])\n",
      "print \"    y_oxygen      \\t %f\"%(X[4])\n",
      "print \"    y_nitrogen    \\t %f\"%(X[5])\n",
      "print \"    x_water       \\t %f\"%(X[0])\n",
      "print \"    x_oxygen      \\t %e\"%(X[1])\n",
      "print \"    x_nitrogen    \\t %e\"%(X[2])\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The composition in liquid and vapor phase are summarized in the following table:\n",
        "    y_water       \t 0.023000\n",
        "    y_oxygen      \t 0.205170\n",
        "    y_nitrogen    \t 0.771830\n",
        "    x_water       \t 0.999985\n",
        "    x_oxygen      \t 5.116461e-06\n",
        "    x_nitrogen    \t 9.599879e-06\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.4   Page: 57\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "\n",
      "T = 20.         #[C]\n",
      "x_b = 0.80\n",
      "x_t = 0.20\n",
      "A_b = 6.90565\n",
      "B_b = 1211.033\n",
      "C_b = 220.79\n",
      "\n",
      "p_b = 10**(A_b-B_b/(T+C_b))\n",
      "A_t = 6.95334\n",
      "B_t = 1343.943\n",
      "C_t = 219.337\n",
      "p_t = 10**(A_t-B_t/(T+C_t))\n",
      "p_1 = x_b*p_b\n",
      "p_2 = x_t*p_t\n",
      "y = 1.00        # y =(y_b+y_t) sum of the mole fractions of the benzene and toluene in the gaseous phase\n",
      "P = (p_1+p_2)/y\n",
      "y_b = x_b*p_b/P\n",
      "y_t = x_t*p_t/P\n",
      "\n",
      "print \" Vapour pressure of the mixture in the gaseous phase is %f torr\"%(P)\n",
      "print \" Mole fraction of the benzene in the vapour phase is    %f\"%(y_b)\n",
      "print \" Mole fraction of the toluene in the vapour phase is    %f\"%(y_t)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Vapour pressure of the mixture in the gaseous phase is 64.518358 torr\n",
        " Mole fraction of the benzene in the vapour phase is    0.932483\n",
        " Mole fraction of the toluene in the vapour phase is    0.067517\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 3.5  Page: 57"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "\n",
      "T = 20.             #[C]\n",
      "x_benzene = 1.00\n",
      "p_i = 75.2          #[torr] vapour pressure of the benzene\n",
      "P = 760.            #[torr] Pressure of the atmosphere\n",
      "\n",
      "y_benzene = (x_benzene*p_i)/P\n",
      "\n",
      "print \" Mole fraction of the benzene in air that is saturated with benzene is %0.1f\"%(y_benzene)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Mole fraction of the benzene in air that is saturated with benzene is 0.1\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 3.6  Page: 58\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "P = 760.            #[mm Hg]\n",
      "x_b = 0.8           # Mole fraction of benzene in liquid phase\n",
      "x_t = 0.2           # Mole fraction of toluene in liquid phase\n",
      "\n",
      "A_b = 6.90565\n",
      "B_b = 1211.003\n",
      "C_b = 220.79\n",
      "\n",
      "A_t = 6.95334\n",
      "B_t = 1343.943\n",
      "C_t = 219.337\n",
      "T = 82.              #[C]\n",
      "err = 1.\n",
      "\n",
      "while err > 10**(-3):\n",
      "    p_b = 10**(6.90565 - 1211.003/(T + 220.79))\n",
      "    p_t = 10**(6.95334 - 1343.943/(T + 219.337))\n",
      "    y_b = x_b*p_b/P\n",
      "    y_t = x_t*p_t/P\n",
      "    err = abs((y_b + y_t) - 1)\n",
      "    T = T + 0.01\n",
      "\n",
      "print \" The temperature at which the given benzene-toluene mixture will have vapor pressure of 1 atm is %0.3f deg C\"%(T)\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The temperature at which the given benzene-toluene mixture will have vapor pressure of 1 atm is 84.360 deg C\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "\n",
      "Example 3.7  Page: 60\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "from numpy import *\n",
      "import math \n",
      "\n",
      "\n",
      "V = 0.25            #[L] Volume of water \n",
      "T_1 = 0.            #[C] Initial temperature of water\n",
      "T_2 = 20.           #[C] Final temperature of water\n",
      "\n",
      "x_o = 5.12*10**(-6)         # mole fraction of oxygen\n",
      "x_n = 9.598*10**(-6)        # mole fraction of nitrogen\n",
      "\n",
      "\n",
      "H_o = 2.55*10**(4)      #[atm]\n",
      "H_n = 5.29*10**(4)      #[atm]\n",
      "\n",
      "p_w = 0.006             #[atm]\n",
      "\n",
      "\n",
      "A = matrix([[0.006, 0, 0, -1, 0, 0],[0, 25500, 0, 0, -1, 0],[0, 0 ,52900, 0, 0, -1],[0, 0, 0, 1, 1, 1],[1, 1, 1, 0, 0, 0],[0, 0, 0, 0, 0.79, -0.21]])\n",
      "B = matrix([[0],[0],[0],[1],[1],[0]])\n",
      "X = linalg.inv(A)\n",
      "X = X*B\n",
      "\n",
      "M_o_rej = V*( X[1] - x_o )/0.018        #[mole] oxygen\n",
      "V_o = M_o_rej*24200                     #[ml] oxygen\n",
      "\n",
      "M_n_rej = V*( X[2] - x_n )/0.018        #[mole] nitrogen\n",
      "V_n = M_n_rej*24200                     #[ml]\n",
      "\n",
      "print \" At equilibrium at 20 deg C the rejected amount of oxygen will be   %0.2f ml\"%(V_o)\n",
      "print \" At equilibrium at 20 deg C the rejected amount of nitrogen will be %0.2f ml\"%(V_n)\n",
      "print \" And total amount of the air rejected from the water will be        %0.2f ml\"%(V_o + V_n)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " At equilibrium at 20 deg C the rejected amount of oxygen will be   1.03 ml\n",
        " At equilibrium at 20 deg C the rejected amount of nitrogen will be 1.76 ml\n",
        " And total amount of the air rejected from the water will be        2.79 ml\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 3.8  Page: 61"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import math \n",
      "\n",
      "\n",
      "P_1 = 5.                #[atm]\n",
      "y_n = 0.79              # Mole fraction of nitrogen in atmosphere\n",
      "P_2 = 1.0               #[atm]\n",
      "M = 55.                 #[kg] Mass of the diver\n",
      "x_w = 0.75              # Fraction of water in human body\n",
      "T = 37                  #[C] Body temperature of the diver\n",
      "\n",
      "H_n = 10.05*10**(4)     # [atm]\n",
      "\n",
      "M_rej = (M*1000*x_w/18)*( P_1*y_n/H_n - P_2*y_n/H_n)        #[mol]\n",
      "\n",
      "V_n = M_rej*24.2            #[L]\n",
      "\n",
      "print \" Amount of rejected nitrogen will be %0.2f Litre\"%(V_n)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Amount of rejected nitrogen will be 1.74 Litre\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}