{
 "metadata": {
  "name": "",
  "signature": "sha256:b2ee1c3d3e88f5241245b2aaba0096c6b15a6abe1de87d5ab25de8744d1af1f8"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 8 : Physical Equilibria Among Phases"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.1 page : 293"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "def  func(C,phi):\n",
      "    return C+2-phi\n",
      "\n",
      "# Calculations and results\n",
      "print (\"part a\")\n",
      "print \"degrees of freedom  =  %d \"%(func(2,2))\n",
      "print (\"part b\")\n",
      "print \"degrees of freedom  =  %d \"%(func(3,2))\n",
      "print (\"part c\")\n",
      "print \"degrees of freedom  =  %d \"%(func(3,3))\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "part a\n",
        "degrees of freedom  =  2 \n",
        "part b\n",
        "degrees of freedom  =  3 \n",
        "part c\n",
        "degrees of freedom  =  2 \n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.2 page : 297"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "T = 95. \t\t\t#C\n",
      "P = 1013. \t\t\t#kPa\n",
      "Tc = 135. \t\t\t#C\n",
      "Pc = 3648. \t\t\t#kPa\n",
      "T0 = 273.1 \t\t\t#C\n",
      "D = 0.3\n",
      "P0 = 1800. \t\t\t#kPa\n",
      "D2 = 0.42\n",
      "\t\t\t\n",
      "# Calculations\n",
      "Zc = 0.283\n",
      "Tr = (T+T0)/(Tc+T0)\n",
      "Pr = P/Pc\n",
      "phic = 0.88\n",
      "phi2 = phic*10**(D*0.013)\n",
      "Prd =  P0/Pc\n",
      "phi3 = 0.78\n",
      "phi4 =  phi3*10**(D2*0.013)\n",
      "gl =  phi2*P/(phi3*P0)\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"equation is gl  =  %.3f *y/x\"%(gl)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "equation is gl  =  0.641 *y/x\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.3 page :300"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\n",
      "# Variables\n",
      "ye = 0.434\n",
      "Pt = 40.25 \t\t\t#kPa\n",
      "xe = 0.616\n",
      "Pe1 = 22.9 \t\t\t#kPa\n",
      "Pe2 = 29.6 \t\t\t#kPa\n",
      "\t\t\t\n",
      "# Calculations\n",
      "ge =  ye*Pt/(xe*Pe1)\n",
      "gb = (1-ye)*Pt/((1-xe)*Pe2)\n",
      "E =  math.log10(ge) *(1+ (1-xe)*math.log(gb) /(xe*math.log(ge)))**2\n",
      "B =  math.log10(gb) *(1+ xe/(1-xe) *math.log(ge) /math.log(gb))**2\n",
      "xe2 = 0.4\n",
      "xb2 = 0.6\n",
      "lnge2 = E/(1+ E*xe2/(B*xb2))**2\n",
      "lngb2 = B/(1+ B*xb2/(E*xe2))**2\n",
      "ge2 = 10**(lnge2)\n",
      "gb2 = 10**(lngb2)\n",
      "Pt1 = ge2*Pe1\n",
      "Pt2 = gb2*Pe2\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"Total pressure in case 1   =  %.2f kPa and in case 2  =  %.2f kPa\"%(Pt1, Pt2 )\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Total pressure in case 1   =  40.78 kPa and in case 2  =  40.93 kPa\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.4 page : 310"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy.linalg import solve\n",
      "\t\t\t\n",
      "# Variables\n",
      "k4 = 1.8\n",
      "k5 = 0.8\n",
      "\t\t\t\n",
      "# Calculations\n",
      "A = [[k4, k5],[1, 1]]\n",
      "b = [[1],[1]]\n",
      "C = solve(A,b)\n",
      "x4 = C[0]\n",
      "x5 = C[1]\n",
      "y4 = k4*x4\n",
      "y5 = k5*x5\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"Vapor and liquid mole fractions of component 1  =  %.2f and %.2f respectively\"%(y4,x4)\n",
      "print \" Vapor and liquid mole fractions of component 2  =  %.2f and %.2f respectively\"%(y5,x5)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Vapor and liquid mole fractions of component 1  =  0.36 and 0.20 respectively\n",
        " Vapor and liquid mole fractions of component 2  =  0.64 and 0.80 respectively\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.5 page : 312"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\n",
      "# Variables\n",
      "v1 = 81. \t\t\t#cm**3/gmol\n",
      "v2 = 97. \t\t\t#cm**3/gmol\n",
      "d1 = 9.2 \t\t\t#(cal/cm**3)**0.5\n",
      "d2 = 8.6 \t\t\t#(cal/cm**3)**0.5\n",
      "R = 1.987\n",
      "T = 373.1 \t\t\t#K\n",
      "\t\t\t\n",
      "# Calculations\n",
      "d = 0.5*(d1+d2)\n",
      "lng1 = v1*(d1-d)**2 /(R*T)\n",
      "lng2 = v2*(d2-d)**2 /(R*T)\n",
      "g1 = math.exp(lng1)\n",
      "g2 = math.exp(lng2)\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"Activity coeffecients of components are %.3f and %.3f respectively\"%(g1,g2)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Activity coeffecients of components are 1.010 and 1.012 respectively\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.6 page : 319"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "xe = 0.3\n",
      "xe2 = 0.9\n",
      "Pe0 = 810.\n",
      "Pa0 = 470.\n",
      "ge = 1.85\n",
      "ge2 = 1.05\n",
      "ga = 1.15\n",
      "ga2 = 3.\n",
      "Pt = 820. \t\t\t#mm\n",
      "Pt2 = 900. \t\t\t#mm\n",
      "\t\t\t\n",
      "# Calculations\n",
      "ye = ge*xe*Pe0/Pt\n",
      "ya = ga*(1-xe)*Pa0/Pt\n",
      "yt = ye+ya\n",
      "ye2 = ye/yt\n",
      "ya2 = ya/yt\n",
      "ye3 = ge2*xe2*Pe0/Pt2\n",
      "ya3 = ga2*(1-xe2)*Pa0/Pt2\n",
      "yt2 = ye+ya\n",
      "ye4 = ye3/yt2\n",
      "ya4 = ya3/yt2\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"In case 1, ye  =  %.3f and ya  =  %.3f\"%(ye2,ya2)\n",
      "print \" In case 1, ye  =  %.3f and ya  =  %.3f\"%(ye4,ya4)\n",
      "print ('The calculations of ya in case 1 in textbook is wrong. please use a calculator')\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "In case 1, ye  =  0.543 and ya  =  0.457\n",
        " In case 1, ye  =  0.842 and ya  =  0.155\n",
        "The calculations of ya in case 1 in textbook is wrong. please use a calculator\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.7 page : 326"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "m1 = 121.\n",
      "m2 = 18.\n",
      "p1 = 0.0042\n",
      "p2 = 0.0858\n",
      "\t\t\t\n",
      "# Calculations\n",
      "massfrac =  (p1*m1)/(p1*m1+p2*m2)\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"mass fractions of DMA and water are %.3f and %.3f respectively\"%(massfrac,1-massfrac)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "mass fractions of DMA and water are 0.248 and 0.752 respectively\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.9 page : 335"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from numpy import array\n",
      "\t\t\t\n",
      "# Variables\n",
      "FR = 25.\n",
      "FE = 19.\n",
      "bf = 130. \t\t\t#kg\n",
      "af = 85. \t\t\t#kg\n",
      "\t\t\t\n",
      "# Calculations\n",
      "law = FR/FE\n",
      "x1 = 45./150\n",
      "x2 = 65./150\n",
      "ER = 18.5/6\n",
      "e = array([0.5, 0.1, 0.9])\n",
      "r = array([0.28, 0.96, 0.04])\n",
      "et = sum(e)\n",
      "rt = sum(r)\n",
      "ett = e/et\n",
      "rtt = r/rt\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"the compositions of raffinate are \",\n",
      "print (rtt)\n",
      "print \"the compositions of extract are\",\n",
      "print (ett)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "the compositions of raffinate are  [ 0.21875  0.75     0.03125]\n",
        "the compositions of extract are [ 0.33333333  0.06666667  0.6       ]\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.10 page : 342"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "v1 = 0.1316\n",
      "v2 = 0.2941\n",
      "x1 = 0.5\n",
      "x2 = 0.2\n",
      "x3 = 0.8  \n",
      "d1 = 14.87\n",
      "d2 = 16.34\n",
      "\t\t\t\n",
      "# Calculations and results\n",
      "vm = x1*(v1+v2)\n",
      "phi1 = x1*v1/vm\n",
      "phi2 = (1-x1)*v2/vm\n",
      "Hl1 = vm*phi1*phi2*(d1-d2)**2 *10**3\n",
      "print (\"case 1\")\n",
      "print \"enthalpy  =  %.1f kJ/mol\"%(Hl1)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "case 1\n",
        "enthalpy  =  98.2 kJ/mol\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.10b page : 343"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\n",
      "# Variables\n",
      "v1 = 0.1316\n",
      "v2 = 0.2941\n",
      "x1 = 0.5\n",
      "x2 = 0.2\n",
      "x3 = 0.8  \n",
      "d1 = 14.87\n",
      "d2 = 16.34\n",
      "\t\t\t\n",
      "# Calculations and results\n",
      "vm = (1-x2)*v1+x2*v2\n",
      "phi1 = (1-x2)*v1/vm\n",
      "phi2 = (x2)*v2/vm\n",
      "Hl2 = vm*phi1*phi2*(d1-d2)**2 *10**3\n",
      "print (\"case 2\")\n",
      "print \"enthalpy  =  %.1f kJ/mol\"%(Hl2)\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "case 2\n",
        "enthalpy  =  81.5 kJ/mol\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 8.10c page : 343"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\n",
      "# Variables\n",
      "v1 = 0.1316\n",
      "v2 = 0.2941\n",
      "x1 = 0.5\n",
      "x2 = 0.2\n",
      "x3 = 0.8  \n",
      "d1 = 14.87\n",
      "d2 = 16.34\n",
      "\t\t\t\n",
      "# Calculations and results\n",
      "vm = (1-x3)*v1+x3*v2\n",
      "phi1 = (1-x3)*v1/vm\n",
      "phi2 = (x3)*v2/vm\n",
      "Hl3 = vm*phi1*phi2*(d1-d2)**2 *10**3\n",
      "print (\"case 3\")\n",
      "print \"enthalpy  =  %.1f kJ/mol\"%(Hl3)\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "case 3\n",
        "enthalpy  =  51.2 kJ/mol\n"
       ]
      }
     ],
     "prompt_number": 11
    }
   ],
   "metadata": {}
  }
 ]
}