summaryrefslogtreecommitdiff
path: root/Physical_And_Chemical_Equilibrium_For_Chemical_Engineers/ch10.ipynb
blob: c6aa5bdff94c096211af294bff46462d7acf21bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
{
 "metadata": {
  "name": "",
  "signature": "sha256:45cc28c15d520b01f5e80bb34453647affc5cb5c7ebd0520e71c71e74dcb84cd"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 10 : Vapor Liquid Equilibrium VLE at High Pressures"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 10.1  Page: 260"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "\n",
      "import math \n",
      "\n",
      "# Variables\n",
      "P = 100.                #[psia] Bubble point pressure\n",
      "x_ethane = 0.10         # Mole fraction of ethane in liquid phase\n",
      "x_hepmath_tane = (1-x_ethane)\n",
      "\n",
      "# a) From figure 10.7( page 260 ) given in the book\n",
      "# We read the chart to get the bubble-point temperature\n",
      "# The dew point curve for 100 psia crosses the 10 mol% ethane line at about temperature \n",
      "T1 = 165.               #[C]\n",
      "# Now, we horizontally from that intersection point to the dew-point curve, finding the vapor phase composition of ethane \n",
      "y1_e = 0.92\n",
      "y1_h = (1- y1_e)\n",
      "\n",
      "# b) By Raoult's law, we use a trial and error procedureon the temperature\n",
      "# Antoine equation consmath.tants for ethanol are given \n",
      "A_e = 6.80267\n",
      "B_e = 656.4028\n",
      "C_e = 255.99\n",
      "\n",
      "# and that for n-hepmath_tane are\n",
      "A_h = 6.9024\n",
      "B_h = 1268.115\n",
      "C_h = 216.9\n",
      "\n",
      "# Antoine equation is given by\n",
      "# (math.log10p) = (A - B/(T+C))\n",
      "T = 50.                     #[C]\n",
      "err = 1.\n",
      " \n",
      "# Calculations\n",
      "while err > 10**(-4):\n",
      "    p1_e = (10**(A_e - B_e/(C_e + T)))*(14.7/760)\n",
      "    p1_h = (10**(A_h - B_h/(C_h + T)))*(14.7/760)\n",
      "    y2_e = p1_e*x_ethane/P\n",
      "    y2_h = p1_h*x_hepmath_tane/P\n",
      "    err = abs((y2_e + y2_h) - 1)\n",
      "    T = T + 0.0001\n",
      "\n",
      "# Changing the temperature in deg F \n",
      "T2 = T*9./5 + 32            #[F] Bubble-point temperature\n",
      "\n",
      "# c) In this method, we use L-R rule, instead of simple Raoult's law\n",
      "# So,\n",
      "# y_i = (x_i*p_i)/(v_i*P)\n",
      "# Where calculated values of v_i from EOS are given in the table 10.A and are \n",
      "v_e = 0.950                     # For ethane\n",
      "v_h = 0.459                     # For n-hepmath_tane\n",
      "\n",
      "# We again use trial and error on the temperature\n",
      "# Let us assume the initial temperature \n",
      "Ti = 50.                       #[C]\n",
      "err = 1\n",
      " \n",
      "while err > 10**(-4):\n",
      "    p2_e = (10**(A_e - B_e/(C_e + Ti)))*(14.7/760)\n",
      "    p2_h = (10**(A_h - B_h/(C_h + Ti)))*(14.7/760)\n",
      "    y3_e = p2_e*x_ethane/(P*v_e)\n",
      "    y3_h = p2_h*x_hepmath_tane/(P*v_h)\n",
      "    err = abs((y3_e + y3_h) - 1)\n",
      "    Ti = Ti + 0.0001\n",
      "\n",
      "# Changing the temperature in deg F \n",
      "T3 = Ti*9./5 + 32               #[F] Bubble-point temperature\n",
      "\n",
      "# Results\n",
      "print \" The results are summarized in the following table:\"\n",
      "print \" Variable \\t Values calculated from\\t Values calculated from \\t Values calculated  \"\n",
      "print \"               \\t from figure 10.7  \\t Raoult''s law \\t\\t\\t from L-R rule\"\n",
      "print \" Tdeg F) \\t %f \\t\\t %f \\t\\t\\t    %f\"%(T1,T2,T3)\n",
      "print \" y_ethane \\t %f \\t\\t %f \\t\\t\\t    %f\"%(y1_e,y2_e,y3_e)\n",
      "print \" y_heptane \\t %f \\t\\t %f \\t\\t\\t    %f\"%(y1_h,y2_h,y3_h)\n",
      "print \"\\nWhere T is boiling point temperature\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The results are summarized in the following table:\n",
        " Variable \t Values calculated from\t Values calculated from \t Values calculated  \n",
        "               \t from figure 10.7  \t Raoult''s law \t\t\t from L-R rule\n",
        " Tdeg F) \t 165.000000 \t\t 133.014380 \t\t\t    124.179620\n",
        " y_ethane \t 0.920000 \t\t 0.968397 \t\t\t    0.943469\n",
        " y_heptane \t 0.080000 \t\t 0.031504 \t\t\t    0.056431\n",
        "\n",
        "Where T is boiling point temperature\n"
       ]
      }
     ],
     "prompt_number": 33
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 10.2  Page: 262\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "import math \n",
      "\n",
      "# Variables\n",
      "P = 800.            #[psia] Bubble point pressure\n",
      "x_ethane = 0.60     # Mole fraction of ethane in liquid phase\n",
      "x_hepmath_tane = (1-x_ethane)\n",
      "\n",
      "# a) From figure 10.7( page 260 ) given in the book\n",
      "# We read the chart to get the bubble-point temperature\n",
      "# The dew point curve for 800 psia crosses the 60 mol% ethane line at about temperature \n",
      "# T1 = 165\n",
      "# Now, we horizontally from that intersection point to the dew-point curve, finding the vapor phase composition of ethane \n",
      "# y1_e = 0.95\n",
      "# But, by linear interpolation in the experimental data on which Figure 10.7 is based we make a slightly more reliable estimate and get \n",
      "T1 = 209.           #[F]\n",
      "y1_e = 0.945\n",
      "y1_h = (1- y1_e)\n",
      "\n",
      "# b) By Raoult's law, we use a trial and error procedureon the temperature\n",
      "# Antoine equation consmath.tants for ethanol are given \n",
      "A_e = 6.80267\n",
      "B_e = 656.4028\n",
      "C_e = 255.99\n",
      "\n",
      "# and that for n-hepmath_tane are\n",
      "A_h = 6.9024\n",
      "B_h = 1268.115\n",
      "C_h = 216.9\n",
      "\n",
      "# Antoine equation is given by\n",
      "# (math.log10p) = (A - B/(T+C))\n",
      "T = 50.             #[C]\n",
      "err = 1.\n",
      " \n",
      "# Calculations\n",
      "while err > 10**(-4):\n",
      "    p1_e = (10**(A_e - B_e/(C_e + T)))*(14.7/760)\n",
      "    p1_h = (10**(A_h - B_h/(C_h + T)))*(14.7/760)\n",
      "    y2_e = p1_e*x_ethane/P\n",
      "    y2_h = p1_h*x_hepmath_tane/P\n",
      "    err = abs((y2_e + y2_h) - 1)\n",
      "    T = T + 0.0001\n",
      "\n",
      "# Changing the temperature in deg F \n",
      "T2 = T*9./5 + 32            #[F] Bubble-point temperature\n",
      "\n",
      "# c) In this method, we use L-R rule, instead of simple Raoult's law\n",
      "# So,\n",
      "# y_i = (x_i*p_i)/(v_i*P)\n",
      "# Where calculated values of v_i from EOS are given  \n",
      "v_e = 0.6290642             # For ethane\n",
      "v_h = 0.0010113             # For n-hepmath_tane\n",
      "\n",
      "# We again use trial and error on the temperature\n",
      "# Let us assume the initial temperature \n",
      "Ti = 10.                    #[C]\n",
      "err = 1.\n",
      " \n",
      "while err > 10**(-4):\n",
      "    p2_e = (10**(A_e - B_e/(C_e + Ti)))*(14.7/760)\n",
      "    p2_h = (10**(A_h - B_h/(C_h + Ti)))*(14.7/760)\n",
      "    y3_e = p2_e*x_ethane/(P*v_e)\n",
      "    y3_h = p2_h*x_hepmath_tane/(P*v_h)\n",
      "    err = abs((y3_e + y3_h) - 1)\n",
      "    Ti = Ti + 0.0001\n",
      "\n",
      "# Changing the temperature in deg F \n",
      "T3 = Ti*9./5 + 32           #[F] Bubble-point temperature\n",
      "\n",
      "# Results\n",
      "print \" The results are summarized in the following table:\"\n",
      "print \" \\t   Variable \\t\\t Values calculated from\\t Values calculated from Values calculated\"\n",
      "print \" \\t\\t\\t\\t from figure 10.7 \\t Raoult''s law \\t\\t from L-R rule\"\n",
      "print \" \\n\\t  Tdeg F \\t\\t %f \\t\\t %f \\t\\t    %f\"%(T1,T2,T3)\n",
      "print \" \\t  y_ethane \\t\\t %f \\t\\t %f \\t\\t    %f\"%(y1_e,y2_e,y3_e)\n",
      "print \" \\t  y_heptane \\t\\t %f \\t\\t %f \\t\\t    %f\"%(y1_h,y2_h,y3_h)\n",
      "print \"\\nWhere T is boiling point temperature\"\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The results are summarized in the following table:\n",
        " \t   Variable \t\t Values calculated from\t Values calculated from Values calculated\n",
        " \t\t\t\t from figure 10.7 \t Raoult''s law \t\t from L-R rule\n",
        " \n",
        "\t  Tdeg F \t\t 209.000000 \t\t 172.210640 \t\t    70.854980\n",
        " \t  y_ethane \t\t 0.945000 \t\t 0.996044 \t\t    0.632080\n",
        " \t  y_heptane \t\t 0.055000 \t\t 0.003856 \t\t    0.367822\n",
        "\n",
        "Where T is boiling point temperature\n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      " Example 10.3  Page: 262\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "\n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\n",
      "# Variables\n",
      "# The initial data for this example is same as that of example 10.2, i.e.\n",
      "P = 800.             #[psia] Bubble point pressure\n",
      "x_e = 0.60           # Mole fraction of ethane in liquid phase\n",
      "x_h = (1-x_e)        # Mole fraction of n-hepmath.tane in the liquid phase\n",
      "R = 0.08314         #( L*bar/(mol*K)) Universal gas consmath.tant \n",
      "\n",
      "# Changing the pressure in bar\n",
      "Pb = (800/14.7)*(1.01325)           #[bar]\n",
      "\n",
      "# In this problem we will denote ethane by 'e' and that to n-hepmath.tane by 'h'\n",
      "# From table A.1 ( page 417 ) given in the book, critical temperatures of ethane and hepmath.tane are \n",
      "T_c_e = 305.3           #[K]\n",
      "T_c_h = 540.2           #[K]\n",
      "\n",
      "# and critical pressures are\n",
      "P_c_e = 48.72           #[bar]\n",
      "P_c_h = 27.40           #[bar]\n",
      "\n",
      "# also the accentric facors are \n",
      "w_e = 0.1\n",
      "w_h = 0.35\n",
      "\n",
      "# Thus we have\n",
      "P_r_e = Pb/P_c_e\n",
      "P_r_h = Pb/P_c_h\n",
      "\n",
      "# Now from equations (F.13) and (F.14) ( page 459 ) given in the book we have\n",
      "# A_e = 0.42747 + ( 1 + (0.480 + 1.574*w_e - 0.17*w_e**(2))*( 1 - T_r_e**(0.5)))**(2)*(P_r_e/T_r_e**(2))\n",
      "# A_h = 0.42747 + ( 1 + (0.480 + 1.574*w_h - 0.17*w_h**(2))*( 1 - T_r_h**(0.5)))**(2)*(P_r_h/T_r_h**(2))\n",
      "# and\n",
      "# B_e = 0.08664*(P_r_e/T_r_e)\n",
      "# B_h = 0.08664*(P_r_h/T_r_h)\n",
      "\n",
      "# We will take the help trial and error method both on Temperature and the vapor phase composition of ethane\n",
      "# Let us assume the starting temperature 200 deg F. Changing this temperature in K\n",
      "T = (200-32)*5./9 + 273.15           #[K]\n",
      "err = 1\n",
      "\n",
      "# Calculations\n",
      "while err > 10**(-4):\n",
      "    T_r_e = T/T_c_e\n",
      "    T_r_h = T/T_c_h\n",
      "    A_e = 0.42747*( 1 + (0.480 + 1.574*w_e - 0.17*w_e**(2))*( 1 - T_r_e**(0.5)))**(2)*(P_r_e/T_r_e**(2))\n",
      "    A_h = 0.42747*( 1 + (0.480 + 1.574*w_h - 0.17*w_h**(2))*( 1 - T_r_h**(0.5)))**(2)*(P_r_h/T_r_h**(2))\n",
      "    \n",
      "    B_e = 0.08664*(P_r_e/T_r_e)\n",
      "    B_h = 0.08664*(P_r_h/T_r_h)\n",
      "    \n",
      "    # Now we will take the starting value of vapor phase composition of ethane as \n",
      "    y_e = 0.9\n",
      "    err1 = 1\n",
      "    \n",
      "    while err1 > 10**(-6):\n",
      "        # Now value of A_mix and B_mix for both liquid and vapor phase are calculated as\n",
      "        \n",
      "        A_mix_l = (x_e*math.sqrt(A_e) + x_h*math.sqrt(A_h))**(2)        # For liquid phase\n",
      "        A_mix_v = (y_e*math.sqrt(A_e) + (1 - y_e)*math.sqrt(A_h))**(2)  # For vapor phase\n",
      "        B_mix_l = (x_e*B_e + x_h*B_h)                                   # For liquid \n",
      "        B_mix_v = (y_e*B_e + (1 - y_e)*B_h)                             # For liquid \n",
      "\n",
      "        def f(z1): \n",
      "            return  z1**(3) - z1**(2) + z1*(A_mix_l - B_mix_l - B_mix_l**(2)) - A_mix_l*B_mix_l\n",
      "        z_l = fsolve(f,0.2)\n",
      "        # and\n",
      "        def g(z2): \n",
      "            return  z2**(3) - z2**(2) + z2*(A_mix_v - B_mix_v - B_mix_v**(2)) - A_mix_v*B_mix_v\n",
      "        z_v = fsolve(g,0.3)\n",
      "        # Now\n",
      "        phi_el = B_e/B_mix_l*( z_l - 1) - math.log(z_l - B_mix_l) - (A_mix_l/B_mix_l)*(2*math.sqrt(A_e/A_mix_l)-B_e/B_mix_l)*math.log(1-B_mix_l/z_l)\n",
      "        phi_hl = B_h/B_mix_l*( z_l - 1) - math.log(z_l - B_mix_l) - (A_mix_l/B_mix_l)*(2*math.sqrt(A_h/A_mix_l)-B_h/B_mix_l)*math.log(1-B_mix_l/z_l)\n",
      "        phi_ev = B_e/B_mix_v*( z_v - 1) - math.log(z_v - B_mix_v) - (A_mix_v/B_mix_v)*(2*math.sqrt(A_e/A_mix_v)-B_e/B_mix_v)*math.log(1-B_mix_v/z_v)\n",
      "        phi_hv = B_h/B_mix_v*( z_v - 1) - math.log(z_v - B_mix_v) - (A_mix_v/B_mix_v)*(2*math.sqrt(A_h/A_mix_v)-B_h/B_mix_v)*math.log(1-B_mix_v/z_v)\n",
      "        K_e = phi_el/phi_ev\n",
      "        K_h = phi_hl/phi_hv\n",
      "        y_e1 = K_e*x_e\n",
      "        y_h1 = K_h*x_h\n",
      "        err1 =abs((y_e1 - y_e))\n",
      "        y_e = y_e1\n",
      "\n",
      "    err = abs((y_e1 + y_h1) -1)\n",
      "    T = T + 0.1\n",
      "\n",
      "\n",
      "# Changing the temperature in deg F, we have \n",
      "Tf = ( T - 273.15)*9./5 + 32         #[F]\n",
      "\n",
      "# Results\n",
      "print \" Bubble point of the given ethanol and n-hepmath.tane mixture at 800 psia is %f deg F\"%(Tf)\n",
      "print \" Amount of ethanol in the vapour phase of the mixture at the given condition is %f \"%(y_e1)\n",
      "print \" Amount of n-heptane in the vapour phase of the mixture at the given condition is %f \"%(y_h1)\n",
      "\n",
      "# Answers may vary because of rounding error."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " Bubble point of the given ethanol and n-hepmath.tane mixture at 800 psia is 200.180000 deg F\n",
        " Amount of ethanol in the vapour phase of the mixture at the given condition is 0.599997 \n",
        " Amount of n-heptane in the vapour phase of the mixture at the given condition is 0.399997 \n"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stderr",
       "text": [
        "/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py:227: RuntimeWarning: The iteration is not making good progress, as measured by the \n",
        "  improvement from the last five Jacobian evaluations.\n",
        "  warnings.warn(msg, RuntimeWarning)\n",
        "/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py:227: RuntimeWarning: The iteration is not making good progress, as measured by the \n",
        "  improvement from the last ten iterations.\n",
        "  warnings.warn(msg, RuntimeWarning)\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}