-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBS-MS Solutions Kinetics Project.py
220 lines (153 loc) · 4.04 KB
/
BS-MS Solutions Kinetics Project.py
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
# coding: utf-8
# In[1]:
import numpy as np
get_ipython().magic('matplotlib inline')
from matplotlib import pyplot as plt
import scipy
import scipy.integrate
import scipy.optimize
# In[2]:
T = 473. # K. remember decimal points on non-integers!
R = 8.314 # J/mol/K
Ca0 = 100. # mole/m3
v0 = 120. # m3/hr
Fa0 = Ca0 * v0
Price_a = 200. # $/kmol
Price_b = 300. # $/kmol
Price_r = 1000. # $/kmol
Cost_SQ = 5. # $/mol
def k1(T):
A = 0.05 # m3/mol/s
Ea = 6000. # J
return A*np.exp(-1*Ea / R / T)
def k2(T):
A = 1.0 # m3/mol/s
Ea = 12500. # J
return A*np.exp(-1*Ea / R / T)
def k3(T):
A = 0.08 # m3/mol/s
Ea = 7000. # J
return A*np.exp(-1*Ea / R / T)
def k4(T):
A = 0.06 # m3/mol/s
Ea = 9000. # J
return A*np.exp(-1*Ea / R / T)
# In[3]:
print(k1(473))
print(k2(473))
print(k3(473))
print(k4(473))
# In[4]:
def dFsoldV(Fsol,V):
Fa, Fb, Fr, Fs, Fq = Fsol # unpack values from Fsol vector into
# five variables
# Total molar flowrate:
Ft = Fa + Fb + Fr + Fs + Fq
# Total concentration, from ideal gas law:
Ct = 100. #mol/m3
# Concentrations:
Ca = Ct * (Fa / Ft)
Cb = Ct * (Fb / Ft)
Cr = Ct * (Fr / Ft)
Cs = Ct * (Fs / Ft)
Cq = Ct * (Fq / Ft)
# rates of progress of reactions
r1 = k1(T) * Ca
r2 = k2(T) * Cb**2
r3 = k3(T) * Cb
r4 = k4(T) * Cb
# rates of generation of species
ra = -r1
rb = r1 - (r2 + r3 + r4)
rr = r2
rs = r3
rq = r4
# Differential equations
dFadV = ra
dFbdV = rb
dFrdV = rr
dFsdV = rs
dFqdV = rq
return[dFadV,dFbdV,dFrdV,dFsdV,dFqdV]
# In[5]:
V_output = np.linspace(0,100000.,num=10000)
# In[6]:
Fsol0 = [Fa0,0,0,0,0]
# In[7]:
Y_result = scipy.integrate.odeint(dFsoldV, Fsol0, V_output)
Fa, Fb, Fr, Fs, Fq = Y_result.T
# In[8]:
plt.plot(V_output, Fa, label='Fa')
plt.plot(V_output, Fb, label='Fb')
plt.plot(V_output, Fr, label='Fr')
plt.plot(V_output, Fs, label='Fs')
plt.plot(V_output, Fq, label='Fq')
plt.legend(loc="best")
plt.xlabel('PFR Volume (m$^3$)')
plt.ylabel('Molar flow rate (mol/hr)')
plt.show()
# In[9]:
final_r=[]
Trange = np.linspace(323,473,150)
for i in Trange:
T = i
solution=scipy.integrate.odeint(dFsoldV,Fsol0,V_output)
Fa, Fb, Fr, Fs, Fq = solution.T
final_r.append(Fr[-1])
plt.plot(Trange-273,final_r)
plt.xlabel('Reactor Temperature(degC)')
plt.ylabel('Molar flow rate of R(mol/hr)')
plt.show()
# In[10]:
P_a = Price_a * Fa0/1000.
Prec_a = Price_a * Fa/1000.
P_b = Price_b * Fb/1000.
P_r = Price_r * Fr/1000.
P_s = Cost_SQ * Fs
P_q = Cost_SQ * Fq
P_tot = P_r + Prec_a + P_b - P_a - P_s - P_q
# In[11]:
plt.plot(V_output, P_tot)
plt.xlabel('PFR Volume (m$^3$)')
plt.ylabel('Profit ($/hr)')
plt.show()
# In[12]:
max_y = np.max(P_tot)
max_x = V_output[np.argmax(P_tot)]
print("The max profit is ${:5.2f}/hour.".format(max_y))
print("This occurs at reactor volume %.2f m3." %max_x)
# In[13]:
Cb = Fb/v0 #Ft
plt.plot(V_output, Cb)
plt.xlabel('PFR Volume (m$^3$)')
plt.ylabel('Concentration (mol/m$^3$)')
plt.show()
# In[14]:
max_Cb = np.max(Cb)
max_Vselect = V_output[np.argmax(Cb)]
#print(max_Vselect, max_Cb)
print("The maximum concentration of B under these conditions is %.2f mol/m3." %max_Cb)
# In[15]:
selectivity = k2(473.)/(k3(473.) + k4(473.))*max_Cb
print("The maximum selectivity of the desired to the undesired is %.2f." %selectivity)
print("This occurs at a reactor volume of %.2f m3." %max_Vselect)
# In[16]:
Ca = Fa/v0
Cb = Fb/v0 #Ft
plt.plot(V_output, Ca, label='Ca')
plt.plot(V_output, Cb, label='Cb')
plt.legend(loc="best")
plt.xlabel('PFR Volume (m$^3$)')
plt.ylabel('Concentration (mol/m$^3$)')
plt.show()
# In[17]:
yield_tot = k2(473.)/k1(473.) * (Cb**2/Ca)
plt.plot(V_output, yield_tot)
plt.xlabel('PFR Volume (m$^3$)')
plt.ylabel('Yield (R/A), unitless')
plt.show()
# In[18]:
max_yield = np.max(yield_tot)
max_Vyield = V_output[np.argmax(yield_tot)]
print("The maximum yield is {:05.3f}, which occurs at a reactor volume of {:07.2f} m3.".format(max_yield,max_Vyield))
# In[ ]: