summaryrefslogtreecommitdiff
path: root/Chemical_Engineering_Thermodynamics_by_P_Ahuja/ch13_1.ipynb
blob: d2334255181d3ca447c1099d6c8862d4a416931f (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
{
 "metadata": {
  "name": "ch13_1",
  "signature": "sha256:894f18dec91baf4a10867e0d301a68220274d02a1e24c4e2bef1038061daa009"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "\n",
      "Chapter 13 : Fugacity of a Component in a Mixture by Equations of State"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 13.2  Page Number : 433"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "import math \n",
      "\n",
      "\n",
      "# Variables\n",
      "T = 310.93;\t\t\t#[K] - Temperature\n",
      "P = 2.76*10**(6);\t\t\t#[Pa] - Pressure\n",
      "y1 = 0.8942;\t\t\t#[mol] - mole fraction of component 1\n",
      "y2 = 1 - y1;\t\t\t#[mol] - mole fraction of component 2\n",
      "R=8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
      "\n",
      "#For component 1 (methane)\n",
      "Tc_1 = 190.6;\t\t\t#[K] - Critical temperature\n",
      "Pc_1 = 45.99*10**(5);\t\t\t#[N/m**(2)] - Critical pressure\n",
      "Vc_1 = 98.6;\t\t\t#[cm**(3)/mol] - Critical molar volume\n",
      "Zc_1 = 0.286;\t\t\t# - Critical compressibility factor\n",
      "w_1 = 0.012;\t\t\t# - Critical acentric factor\n",
      "#Similarly for component 2 (n-Butane)\n",
      "Tc_2 = 425.1;\t\t\t#[K]\n",
      "Pc_2 = 37.96*10**(5);\t\t\t#[N/m**(2)]\n",
      "Vc_2 = 255;\t\t\t#[cm**(3)/mol]\n",
      "Zc_2=0.274;\n",
      "w_2=0.2;\n",
      "\n",
      "# Calculations\n",
      "#For component 1\n",
      "Tr_1 = T/Tc_1;\t\t\t#Reduced temperature\n",
      "#At reduced temperature\n",
      "B1_0 = 0.083-(0.422/(Tr_1)**(1.6));\n",
      "B1_1 = 0.139-(0.172/(Tr_1)**(4.2));\n",
      "#We know,(B*Pc)/(R*Tc) = B_0+(w*B_1)\n",
      "B_11 = ((B1_0+(w_1*B1_1))*(R*Tc_1))/Pc_1;\t\t\t#[m**(3)/mol]\n",
      "\n",
      "#Similarly for component 2\n",
      "Tr_2 = T/Tc_2;\t\t\t#Reduced temperature\n",
      "#At reduced temperature Tr_2,\n",
      "B2_0 = 0.083-(0.422/(Tr_2)**(1.6));\n",
      "B2_1 = 0.139-(0.172/(Tr_2)**(4.2));\n",
      "B_22 = ((B2_0+(w_2*B2_1))*(R*Tc_2))/Pc_2;\t\t\t#[m**(3)/mol]\n",
      "\n",
      "#For cross coeffcient\n",
      "Tc_12 = (Tc_1*Tc_2)**(1./2);\t\t\t#[K]\n",
      "w_12 = (w_1+w_2)/2;\n",
      "Zc_12 = (Zc_1+Zc_2)/2;\n",
      "Vc_12 = (((Vc_1)**(1./3)+(Vc_2)**(1./3))/2)**(3);\t\t\t#[cm**(3)/mol]\n",
      "Vc_12 = Vc_12*10**(-6);\t\t\t#[m**(3)/mol]\n",
      "Pc_12 = (Zc_12*R*Tc_12)/Vc_12;\t\t\t#[N/m**(2)]\n",
      "\n",
      "# Variables, Z = 1 + (B*P)/(R*T)\n",
      "#Now we have,(B_12*Pc_12)/(R*Tc_12) = B_0 + (w_12*B_1)\n",
      "#where B_0 and B_1 are to be evaluated at Tr_12\n",
      "Tr_12 = T/Tc_12;\n",
      "#At reduced temperature Tr_12\n",
      "B_0 = 0.083-(0.422/(Tr_12)**(1.6));\n",
      "B_1 = 0.139-(0.172/(Tr_12)**(4.2));\n",
      "B_12 = ((B_0+(w_12*B_1))*R*Tc_12)/Pc_12;\t\t\t#[m**(3)/mol]\n",
      "#For the mixture\n",
      "B = y1**(2)*B_11+2*y1*y2*B_12+y2**(2)*B_22;\t\t\t#[m**(3)/mol]\n",
      "\n",
      "#Now del_12 can be calculated as,\n",
      "del_12 = 2*B_12 - B_11 - B_22;\t\t\t#[m**(3)/mol]\n",
      "\n",
      "#We have the relation, math.log(phi_1) = (P/(R*T))*(B_11 + y2**(2)*del_12), therefore\n",
      "phi_1 = math.exp((P/(R*T))*(B_11 + y2**(2)*del_12));\n",
      "#Similarly for component 2\n",
      "phi_2 = math.exp((P/(R*T))*(B_22 + y1**(2)*del_12));\n",
      "\n",
      "# Results\n",
      "print \" The value of fugacity coefficient of component 1 phi_1) is %f\"%(phi_1);\n",
      "print \" The value of fugacity coefficient of component 2 phi_2) is %f\"%(phi_2);\n",
      "\n",
      "#Finally fugacity coefficient of the mixture is given by\n",
      "#math.log(phi) = y1*math.log(phi_1) + y2*math.log(phi_2);\n",
      "phi = math.exp(y1*math.log(phi_1) + y2*math.log(phi_2));\n",
      "\n",
      "print \" The value of fugacity coefficient of the mixture phi) is %f \"%(phi);\n",
      "#The fugacity coefficient of the mixture can also be obtained using\n",
      "#math.log(phi) = (B*P)/(R*T)\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The value of fugacity coefficient of component 1 phi_1) is 0.965152\n",
        " The value of fugacity coefficient of component 2 phi_2) is 0.675374\n",
        " The value of fugacity coefficient of the mixture phi) is 0.929376 \n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 13.7  Page Number : 447"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "from scipy.optimize import fsolve \n",
      "import math \n",
      "\n",
      "# Variables\n",
      "T = 460.;\t\t\t#[K] - Temperature\n",
      "P = 40.*10**(5);\t\t\t#[Pa] - Pressure\n",
      "R=8.314;\t\t\t#[J/mol*K] - Universal gas constant\n",
      "# component 1 = nitrogen\n",
      "# component 2 = n-Butane\n",
      "y1 = 0.4974;\t\t\t# Mole percent of nitrogen\n",
      "y2 = 0.5026;\t\t\t# Mole percent of n-Butane\n",
      "Tc_nit = 126.2;\t\t\t#[K]\n",
      "Pc_nit = 34.00*10**(5);\t\t\t#[Pa]\n",
      "Tc_but = 425.1;\t\t\t#[K]\n",
      "Pc_but = 37.96*10**(5);\t\t\t#[Pa]\n",
      "\n",
      "# (1). van der Walls equation of state\n",
      "\n",
      "# The fugacity coefficient of component 1 in a binary mixture following van der Walls equation of state is given by,\n",
      "# math.log(phi_1) = b_1/(V-b) - math.log(Z-B) -2*(y1*a_11 + y2*a_12)/(R*T*V)\n",
      "# and for component 2 is given by,\n",
      "# math.log(phi_2) = b_2/(V-b) - math.log(Z-B) -2*(y1*a_12 + y2*a_22)/(R*T*V)\n",
      "# Where B = (P*b)/(R*T)\n",
      "\n",
      "# Calculations\n",
      "# For componenet 1 (nitrogen)\n",
      "a_1 = (27*R**(2)*Tc_nit**(2))/(64*Pc_nit);\t\t\t#[Pa-m**(6)/mol**(2)]\n",
      "b_1 = (R*Tc_nit)/(8*Pc_nit);\t\t\t#[m**(3)/mol]\n",
      "\n",
      "# Similarly for componenet 2 (n-Butane)\n",
      "a_2 = (27*R**(2)*Tc_but**(2))/(64*Pc_but);\t\t\t#[Pa-m**(6)/mol**(2)]\n",
      "b_2 = (R*Tc_but)/(8*Pc_but);\t\t\t#[m**(3)/mol]\n",
      "\n",
      "# Here\n",
      "a_11 = a_1;\n",
      "a_22 = a_2;\n",
      "# For cross coefficient\n",
      "a_12 = (a_1*a_2)**(1./2);\t\t\t#[Pa-m**(6)/mol**(2)]\n",
      "\n",
      "# For the mixture \n",
      "a = y1**(2)*a_11 + y2**(2)*a_22 + 2*y1*y2*a_12;\t\t\t#[Pa-m**(6)/mol**(2)]\n",
      "b = y1*b_1 + y2*b_2;\t\t\t#[m**(3)/mol]\n",
      "\n",
      "# The cubic form of the van der Walls equation of state is given by,\n",
      "# V**(3) - (b+(R*T)/P)*V**(2) + (a/P)*V - (a*b)/P = 0\n",
      "# Substituting the value and solving for V, we get\n",
      "# Solving the cubic equation\n",
      "def f(V): \n",
      "    return V**(3)-(b+(R*T)/P)*V**(2)+(a/P)*V-(a*b)/P\n",
      "V_1=fsolve(f,-1)\n",
      "V_2=fsolve(f,0)\n",
      "V_3=fsolve(f,1)\n",
      "# The molar volume V = V_3, the other two roots are imaginary\n",
      "V = V_3;\t\t\t#[m**(3)/mol]\n",
      "\n",
      "# The comprssibility factor of the mixture is \n",
      "Z = (P*V)/(R*T);\n",
      "# And B can also be calculated as\n",
      "B = (P*b)/(R*T);\n",
      "\n",
      "# The fugacity coefficient of component 1 in the mixture is\n",
      "phi_1 = math.exp(b_1/(V-b) - math.log(Z-B) -2*(y1*a_11 + y2*a_12)/(R*T*V));\n",
      "# Similarly fugacity coefficient of component 2 in the mixture is \n",
      "phi_2 = math.exp(b_2/(V-b) - math.log(Z-B) -2*(y1*a_12 + y2*a_22)/(R*T*V));\n",
      "\n",
      "# The fugacity coefficient of the mixture is given by,\n",
      "# math.log(phi) = y1*math.log(phi_1) + y2*math.log(phi_2)\n",
      "phi = math.exp(y1*math.log(phi_1) + y2*math.log(phi_2));\n",
      "\n",
      "# Also the fugacity coefficient of the mixture following van der Walls equation of state is given by,\n",
      "# math.log(phi) = b/(V-b) - math.log(Z-B) -2*a/(R*T*V)\n",
      "phi_dash = math.exp(b/(V-b) - math.log(Z-B) -2*a/(R*T*V));\n",
      "# The result is same as obtained above\n",
      "\n",
      "# Results\n",
      "print \" 1van der Walls equation of state\";\n",
      "print \"  The value of fugacity coefficient of component 1 nitrogen) is %f\"%(phi_1);\n",
      "print \"  The value of fugacity coefficient of component 2 n-butane) is %f\"%(phi_2);\n",
      "print \"  The value of fugacity coefficient of the mixture is %f\"%(phi);\n",
      "print \"  Also the fugacity coefficient of the mixture from van der Walls equation of state is %f which is same as above)\"%(phi_dash);\n",
      "\n",
      "# (2). Redlich-Kwong equation of state\n",
      "\n",
      "# For component 1,\n",
      "a_1_prime = (0.42748*R**(2)*Tc_nit**(2.5))/Pc_nit;\t\t\t#[Pa-m**(6)/mol**(2)]\n",
      "b_1_prime = (0.08664*R*Tc_nit)/Pc_nit;\t\t\t#[m**(3)/mol]\n",
      "\n",
      "#similarly for component 2,\n",
      "a_2_prime = (0.42748*R**(2)*Tc_but**(2.5))/Pc_but;\t\t\t#[Pa-m**(6)/mol**(2)]\n",
      "b_2_prime = (0.08664*R*Tc_but)/Pc_but;\t\t\t#[m**(3)/mol]\n",
      "\n",
      "# For cross coefficient\n",
      "a_12_prime = (a_1_prime*a_2_prime)**(1./2);\t\t\t#[Pa-m**(6)/mol**(2)]\n",
      "# For the mixture\n",
      "a_prime = y1**(2)*a_1_prime + y2**(2)*a_2_prime +2*y1*y2*a_12_prime;\t\t\t#[Pa-m**(6)/mol**(2)]\n",
      "b_prime = y1*b_1_prime +y2*b_2_prime;\t\t\t#[m**(3)/mol]\n",
      "\n",
      "\n",
      "#The cubic form of Redlich Kwong equation of state is given by,\n",
      "#  V**(3)-((R*T)/P)*V**(2)-((b**(2))+((b*R*T)/P)-(a/(T**(1/2)*P))*V-(a*b)/(T**(1/2)*P)=0\n",
      "# Solving the cubic equation\n",
      "def f1(V): \n",
      "    return V**(3)-((R*T)/P)*V**(2)-((b_prime**(2))+((b_prime*R*T)/P)-(a_prime/(T**(1./2)*P)))*V-(a_prime*b_prime)/(T**(1./2)*P)\n",
      "V_4=fsolve(f1,1)\n",
      "V_5=fsolve(f1,0)\n",
      "V_6=fsolve(f1,-1)\n",
      "# The molar volume V = V_4, the other two roots are imaginary\n",
      "V_prime = V_4;\t\t\t#[m**(3)/mol]\n",
      "\n",
      "# The compressibility factor of the mixture is\n",
      "Z_prime = (P*V_prime)/(R*T);\n",
      "# And B can also be calculated as\n",
      "B_prime = (P*b_prime)/(R*T);\n",
      "\n",
      "# The fugacity coefficient of component 1 in the binary mixture is given by\n",
      "# math.log(phi_1) = b_1/(V-b) - math.log(Z-B) + ((a*b_1)/((b**(2)*R*T**(3/2))))*(math.log((V+b)/V)-(b/(V+b)))-(2*(y1*a_1+y2*a_12)/(R*T**(3/2)b))*(math.log(V+b)/b)\n",
      "\n",
      "phi_1_prime = math.exp((b_1_prime/(V_prime-b_prime))-math.log(Z_prime-B_prime)+((a_prime*b_1_prime)/((b_prime**(2))*R*(T**(3./2))))*(math.log((V_prime+b_prime)/V_prime)-(b_prime/(V_prime+b_prime)))-(2*(y1*a_1_prime+y2*a_12_prime)/(R*(T**(3./2))*b_prime))*(math.log((V_prime+b_prime)/V_prime)));\n",
      "\n",
      "\n",
      "# Similarly fugacity coefficient of component 2 in the mixture is \n",
      "phi_2_prime = math.exp((b_2_prime/(V_prime-b_prime))-math.log(Z_prime-B_prime)+((a_prime*b_2_prime)/((b_prime**(2))*R*(T**(3./2))))*(math.log((V_prime+b_prime)/V_prime)-(b_prime/(V_prime+b_prime)))-(2*(y1*a_12_prime+y2*a_2_prime)/(R*(T**(3./2))*b_prime))*(math.log((V_prime+b_prime)/V_prime)));\n",
      "\n",
      "# The fugacity coefficient of the mixture is given by,\n",
      "# math.log(phi) = y1*math.log(phi_1) + y2*math.log(phi_2)\n",
      "phi_prime = math.exp(y1*math.log(phi_1_prime) + y2*math.log(phi_2_prime));\n",
      "\n",
      "# Also the fugacity coefficient for the mixture following Redlich-kwong equation of state is also given by\n",
      "# math.log(phi) = b/(V-b) - math.log(Z-B) - (a/(R*T**(3/2)))*(1/(V+b)+(1/b)*math.log((V+b)/V))\n",
      "phi_prime_dash = math.exp(b_prime/(V_prime-b_prime) - math.log(Z_prime-B_prime) - (a_prime/(R*T**(3./2)))*(1/(V_prime+b_prime)+(1./b_prime)*math.log((V_prime+b_prime)/                   V_prime)));\n",
      "\n",
      "print \"  \\nRedlich-Kwong equation of state\";\n",
      "print \"  The value of fugacity coefficient of component 1 nitrogen) is %f\"%(phi_1_prime);\n",
      "print \"  The value of fugacity coefficient of component 2 n-butane) is %f\"%(phi_2_prime);\n",
      "print \"  The value of fugacity coefficient of the mixture is %f\"%(phi_prime);\n",
      "print \"  Also the fugacity coefficient for the mixture from Redlich-kwong equation of state is %f which is same as above)\"%(phi_prime_dash);\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " 1van der Walls equation of state\n",
        "  The value of fugacity coefficient of component 1 nitrogen) is 1.057500\n",
        "  The value of fugacity coefficient of component 2 n-butane) is 0.801865\n",
        "  The value of fugacity coefficient of the mixture is 0.920192\n",
        "  Also the fugacity coefficient of the mixture from van der Walls equation of state is 0.920192 which is same as above)\n",
        "  \n",
        "Redlich-Kwong equation of state\n",
        "  The value of fugacity coefficient of component 1 nitrogen) is 1.071129\n",
        "  The value of fugacity coefficient of component 2 n-butane) is 0.793063\n",
        "  The value of fugacity coefficient of the mixture is 0.920948\n",
        "  Also the fugacity coefficient for the mixture from Redlich-kwong equation of state is 0.920948 which is same as above)\n"
       ]
      }
     ],
     "prompt_number": 2
    }
   ],
   "metadata": {}
  }
 ]
}