{
 "metadata": {
  "name": "",
  "signature": "sha256:20736bf3d0b99872401315f1d4792e0a0a693067ab204fabe4415026bbd6d5a0"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 7 : Solution Properties and Physical Equilibria"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.2 page : 268"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\n",
      "# Variables\n",
      "T = 154.5 \t\t\t#C\n",
      "P = 8620.*10**3 \t\t\t#Pa\n",
      "Tc = 135. \t\t\t#C\n",
      "T0 = 273.1 \t\t\t#C\n",
      "Pc = 3648.*10**3 \t\t\t#Pa\n",
      "w = 0.1756\n",
      "V = 0.154 \n",
      "R = 8.3143*10**3\n",
      "\t\t\t\n",
      "# Calculations\n",
      "Tr = (T+T0)/(T0+Tc)\n",
      "Pr =  P/Pc\n",
      "Z = P*V/(R*(T+T0))\n",
      "a =  0.42747*R**2 *(Tc+T0)**2 /Pc *(1+ (0.48508 + 1.55171*w - 0.15613*w**2)*(1-math.sqrt(Tr)))**2\n",
      "b = 0.08664*R*(Tc+T0)/Pc\n",
      "A =  a*P/(R**2 *(T+T0)**2)\n",
      "B = b*P/(R*(T+T0))\n",
      "lnphi =  (Z-1) - math.log(Z-B) - A/B *math.log((Z+B)/Z) \n",
      "phi = math.exp(lnphi)\n",
      "f = phi*P\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"fugacity  =  %d kPa\"%(f/10**3)\n",
      "\t\t\t#The answer is a bit different due to rounding off error in textbook\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "fugacity  =  3824 kPa\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.3 page : 273"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "T = 154.5 \t\t\t#C\n",
      "P = 8620.*10**3 \t\t\t#Pa\n",
      "Tc = 135. \t\t\t#C\n",
      "T0 = 273.1 \t\t\t#C\n",
      "Pc = 3648.*10**3 \t\t\t#Pa\n",
      "w = 0.1756\n",
      "V = 0.154 \n",
      "R = 8.3143*10**3\n",
      "D = 0.35\n",
      "Vc = 0.263 \t\t\t#m**3/kmol\n",
      "\t\t\t\n",
      "# Calculations\n",
      "Tr = (T+T0)/(T0+Tc)\n",
      "Pr =  P/Pc\n",
      "Zc = Pc*Vc/(R*(Tc+T0))\n",
      "phi1 = 0.44\n",
      "phi2 = phi1*10**(D*(Zc-0.27))\n",
      "f = phi2*P\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"fugacity  =  %d kPa\"%(f/10**3)\n",
      "\n",
      "# rounding off error."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "fugacity  =  3832 kPa\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.4 page : 277"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\n",
      "# Variables\n",
      "f0 = 0.7\n",
      "V = 5.1e-2\n",
      "P1 = 0.77 \t\t\t#Mpa\n",
      "P2 = 10. \t\t\t#Mpa\n",
      "R = 8.3143*10**3\n",
      "T = 298. \t\t\t#K\n",
      "\t\t\t\n",
      "# Calculations\n",
      "lnr =  V/(R*T) *(P2-P1)*10**6\n",
      "f = math.exp(lnr) *f0\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"Fugacity  =  %.3f Mpa\"%(f)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Fugacity  =  0.846 Mpa\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.5 page : 280"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math \n",
      "\t\t\t\n",
      "# Variables\n",
      "Pt = 0.1013\n",
      "ya = 0.605\n",
      "P1 = 0.1373\n",
      "P2 = 0.06\n",
      "xa = 0.4\n",
      "\t\t\t\n",
      "# Calculations\n",
      "if ya*Pt == xa*Pt and (1-ya)*Pt == (1-xa)*Pt:\n",
      "    print \"The system is ideal\"\n",
      "else:\n",
      "    print \"The system is not ideal\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The system is not ideal\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.6 page : 282"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "Y = 0.06\n",
      "X = 0.0012\n",
      "P = 2.53 \t\t\t#Mpa\n",
      "\t\t\t\n",
      "# Calculations\n",
      "y = Y/(1+Y)\n",
      "x = X/(1+X)\n",
      "H = y*P/x\n",
      "\t\t\t\n",
      "# Results\n",
      "print \"Henrys law constant  =  %.2f Mpa\"%(H)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Henrys law constant  =  119.48 Mpa\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 7.7 page : 285"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\t\t\t\n",
      "# Variables\n",
      "Hi = 55.\n",
      "Pi = 11.8\n",
      "xi = 0.514\n",
      "H2 = 18.1\n",
      "H3 = 26.9\n",
      "Pi2 = 17.4\n",
      "\t\t\t\n",
      "# Calculations\n",
      "ai = Pi/Hi\n",
      "gam = ai/xi\n",
      "a2 = Pi/H2\n",
      "gam2 = a2/xi\n",
      "a3 = Pi2/H3\n",
      "gam3 = a3/(1-xi)\n",
      "\t\t\t\n",
      "# Results\n",
      "print (\"part a\")\n",
      "print \"Activity of acetic acid  =  %.4f \"%(ai)\n",
      "print \" Activity coefficient   =  %.4f \"%(gam)\n",
      "\n",
      "print (\"part b\")\n",
      "print \"Activity of acetic acid  =  %.4f \"%(a2)\n",
      "print \" Activity coefficient   =  %.4f \"%(gam2)\n",
      "\n",
      "print (\"part c\")\n",
      "print \"Activity of toluene  =  %.4f \"%(a3)\n",
      "print \" Activity coefficient   =  %.4f \"%(gam3)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "part a\n",
        "Activity of acetic acid  =  0.2145 \n",
        " Activity coefficient   =  0.4174 \n",
        "part b\n",
        "Activity of acetic acid  =  0.6519 \n",
        " Activity coefficient   =  1.2684 \n",
        "part c\n",
        "Activity of toluene  =  0.6468 \n",
        " Activity coefficient   =  1.3309 \n"
       ]
      }
     ],
     "prompt_number": 7
    }
   ],
   "metadata": {}
  }
 ]
}