summaryrefslogtreecommitdiff
path: root/Chemical_Engineering_Thermodynamics_by_Y_V_C_Rao/ch10.ipynb
blob: 5d1a66e8c71058b637db85c09057c45944a2aa98 (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
{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 10 : Stability and phase transition in thermodynamic systems"
     ]
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 10.2  Page No : 369"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "# Variables\n",
      "P = 2;\t\t\t #number of phases (no unit)\n",
      "C = 2;\t\t\t #number of components (no unit)\n",
      "\n",
      "# Calculations\n",
      "F = C+2-P\n",
      "\n",
      "# Results\n",
      "print \" The number of degrees of freedom  =  %d \"%(F);\n",
      "print \"Two intensive properties are required to be specified to\\\n",
      " describe the thermodynamic state of the system,and the fundamental relation in\\\n",
      "  the Gibbs free energy representation for this system is of the type, G = GT,P,N1,N2\"\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The number of degrees of freedom  =  2 \n",
        "Two intensive properties are required to be specified to describe the thermodynamic state of the system,and the fundamental relation in  the Gibbs free energy representation for this system is of the type, G = GT,P,N1,N2\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 3,
     "metadata": {},
     "source": [
      "Example 10.3  Page No : 370"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import cmath\n",
      "import math\n",
      "\n",
      "# Variables\n",
      "T = 427.85;\t\t\t #temperature of n-octane vapour in K\n",
      "R = 8.314;\t\t\t #universal gas constant in J/molK\n",
      "Tc = 569.4;\t\t\t #critical temperature of n-octane in K\n",
      "Pc = 24.97;\t\t\t #critical pressure of n-octane in bar\n",
      "w = 0.398;\t\t\t #acentric factor (no unit) \n",
      "\n",
      "# Calculations\n",
      "Pguess = 0.215\n",
      "\n",
      "\n",
      "Tr = T/Tc\n",
      "Pr = (Pguess*10**6)/(Pc*10**5)\n",
      "S = 0.37464+(1.54226*w)-(0.26992*w**2)\n",
      "alpha1 = (1+(S*(1-math.sqrt(Tr))))**2;\n",
      "a = (0.45724*R**2*Tc**2*alpha1)/(Pc*10**5)\n",
      "b = (0.07780*R*Tc)/(Pc*10**5);\t\t\t \n",
      "A = (a*Pguess*10**6)/(R*T)**2;\t\t\t \n",
      "B = (b*Pguess*10**6)/(R*T);\t\t\t \n",
      "alpha = -1+B\n",
      "beeta = A-(2*B)-(3*B**2)\n",
      "gaamma = -(A*B)+(B**2)+(B**3)\n",
      "p = beeta-(alpha**2)/3;\t\t\n",
      "q = ((2*alpha**3)/27)-((alpha*beeta)/3)+gaamma\n",
      "D = (((q)**2)/4)+(((p)**3)/27);\t\t\t \n",
      "\n",
      "\n",
      "if D>0:\n",
      "    Z = ((-q/2)+(math.sqrt(D)))**(1./3)+((-q/2)-(math.sqrt(D)))**(1./3)-(alpha/3);\n",
      "    Z_l = Z;\n",
      "    Z_v = Z;\n",
      "elif D == 0:\n",
      "    Z1 = ((-2*(q/2))**(1./3))-(alpha/3);\t\t\t \n",
      "    Z2 = ((q/2)**(1./3))-(alpha/3);\n",
      "    Z3 = ((q/2)**(1./3))-(alpha/3);\n",
      "    Z = [Z1 ,Z2, Z3];\n",
      "    Z_l = min(Z);\n",
      "    Z_v = max(Z);\n",
      "else:\n",
      "    r = math.sqrt((-(p**3)/27));\t\t\t \n",
      "    theta = math.acos((-(q)/2)*(1./r));\t\t\n",
      "    Z1 = (2*(r**(1./3))*math.cos(theta/3))-(alpha/3);\n",
      "    Z2 = (2*(r**(1./3))*math.cos(((2*math.pi)+theta)/3))-(alpha/3)\n",
      "    Z3 = (2*(r**(1./3))*math.cos(((4*math.pi)+theta)/3))-(alpha/3)\n",
      "    Z = [Z1, Z2, Z3];\n",
      "    Z_l = min(Z)\n",
      "    Z_v = max(Z)\n",
      "\n",
      "\n",
      "phi_l = math.exp(Z_l-1-math.log(Z_l-B)-((a/(2*math.sqrt(2)*b*R*T))*math.log((Z_l+(B*(1+math.sqrt(2))))/(Z_l+(B*(1-math.sqrt(2)))))));\n",
      "phi_v = math.exp(Z_v-1-math.log(Z_v-B)-((a/(2*math.sqrt(2)*b*R*T))*math.log((Z_v+(B*(1+math.sqrt(2))))/(Z_v+(B*(1-math.sqrt(2)))))));\n",
      "fl = Pguess*phi_l;\t\t\t # Calculations of the fugacity of the liquid in MPa\n",
      "fv = Pguess*phi_v;\t\t\t # Calculations of the fugacity of the vapour in MPa\n",
      "tolerance = 1e-3;\t\t\t #defining the tolerance to compare fl and fv\n",
      "\n",
      "if abs(fl-fv)<tolerance:\n",
      "    P = Pguess;\t\t\t\n",
      "else:\n",
      "    Prevised = Pguess*(fl/fv)\n",
      "\n",
      "while abs(fl-fv)>tolerance:\n",
      "    Tr = T/Tc\n",
      "    Pr = (Prevised*10**6)/(Pc*10**5);\n",
      "    S = 0.37464+(1.54226*w)-(0.26992*w**2)\n",
      "    alpha1 = (1+(S*(1-math.sqrt(Tr))))**2;\n",
      "    a = (0.45724*R**2*Tc**2*alpha1)/(Pc*10**5)\n",
      "    b = (0.07780*R*Tc)/(Pc*10**5);\t\t\t \n",
      "    A = (a*Prevised*10**6)/(R*T)**2;\t\t\n",
      "    B = (b*Prevised*10**6)/(R*T);\t\t\t\n",
      "    alpha = -1+B;\t\t\t \n",
      "    beeta = A-(2*B)-(3*B**2);\n",
      "    gaamma = -(A*B)+(B**2)+(B**3)\n",
      "    p = beeta-(alpha**2)/3;\t\t\n",
      "    q = ((2*alpha**3)/27)-((alpha*beeta)/3)+gaamma\n",
      "    D = (((q)**2)/4)+(((p)**3)/27);\t\n",
      "        \n",
      "    if D > 0:\n",
      "        Z=((-q/2)+(math.sqrt(D)))**(1./3)+((-q/2)-(math.sqrt(D)))**(1./3)-(alpha/3);     #One real root given by  Eq.(3.32)\n",
      "        Z_l=Z;\n",
      "        Z_v=Z;\n",
      "    elif D==0:\n",
      "        Z1=((-2*(q/2))**(1./3))-(alpha/3);             #Three real roots and two equal given by Eq.(3.33)\n",
      "        Z2=((q/2)**(1./3))-(alpha/3);\n",
      "        Z3=((q/2)**(1./3))-(alpha/3);\n",
      "        Z=[Z1, Z2, Z3];\n",
      "        Z_l=min(Z);\n",
      "        Z_v=max(Z);\n",
      "    else:\n",
      "        r = math.sqrt((-(p**3)/27));\t\t\t \n",
      "        theta = math.acos((-(q)/2)*(1./r));\t\t\n",
      "        Z1 = (2*(r**(1./3))*math.cos(theta/3))-(alpha/3);\n",
      "        Z2 = (2*(r**(1./3))*math.cos(((2*math.pi)+theta)/3))-(alpha/3)\n",
      "        Z3 = (2*(r**(1./3))*math.cos(((4*math.pi)+theta)/3))-(alpha/3);\n",
      "        Z = [Z1, Z2, Z3];\n",
      "        Z_l = Z[0];\n",
      "        Z_v = Z[1];\n",
      "\n",
      "    phi_l = math.exp(Z_l-1-math.log(Z_l-B)-((a/(2*math.sqrt(2)*b*R*T))*math.log((Z_l+(B*(1+math.sqrt(2))))/(Z_l+(B*(1-math.sqrt(2)))))));\n",
      "    phi_v = math.exp(Z_v-1-math.log(Z_v-B)-((a/(2*math.sqrt(2)*b*R*T))*math.log((Z_v+(B*(1+math.sqrt(2))))/(Z_v+(B*(1-math.sqrt(2)))))));\n",
      "    fl = Prevised*phi_l;\t\n",
      "    fv = Prevised*phi_v;\t\n",
      "    Prevised = Prevised*fl/fv\n",
      "\n",
      "P = Prevised;\t\t\t\n",
      "\n",
      "# Results\n",
      "print \" The vapour pressure of n-octane at 427.85K  =  %.5f\"%P,\" MPa\"\n",
      "\n",
      "# Note: answer is slightly differnt because of rounding off error."
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        " The vapour pressure of n-octane at 427.85K  =  0.21196  MPa\n"
       ]
      }
     ],
     "prompt_number": 34
    }
   ],
   "metadata": {}
  }
 ]
}