forked from kiranyalamanchi/CLC_script
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViolation_check.py
More file actions
358 lines (316 loc) · 11.9 KB
/
Violation_check.py
File metadata and controls
358 lines (316 loc) · 11.9 KB
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
##Mechanism check for violation of collision limit##
###Combust. Flame. 186 (2017) 208-210###
import cantera as ct
import numpy as np
import math
import sys
f = open("Output.out", 'w')
sys.stdout = f
#Mechanism input
ct.add_directory('#####input directory of mechanism########')
gas = ct.Solution('#######Mech_file.cti####################')
#define variables
r = gas.n_reactions
s = gas.n_species
######Change following temperatre Accordingly#########
gas.TP = 500, 1.013e+8
T = gas.T
#v is no. of reactions violating limit and b is no. of bimolecular reactions in mechanism#
v = 0
b = 0
#constants
pi = math.pi
Na = 6.02214129*(10**26)
kb = 1.3806488*(10**(-23))
##########################################
##Vioaltion check for forward reactions##
print ('elementary and forward')
print('rxn no.,','rxn,', 'k_f,', 'k_coll')
k_forward = gas.forward_rate_constants
k_eq = gas.equilibrium_constants
stoic_coeff = gas.reactant_stoich_coeff
ratiolow=np.zeros(gas.n_reactions)
for i in range(0,r):
red_mass_num = 1
red_mass_den = 0
coll_dia = 0
well_dep = 1
tot_coeff = 0
for l in range (0,s): tot_coeff = tot_coeff + stoic_coeff(l,i)
if gas.reaction_type(i)==1 and tot_coeff == 2:
for j in range(0,s):
if stoic_coeff(j,i) == 1:
S = gas.species(j)
diameter = S.transport.diameter
well_depth = S.transport.well_depth
red_mass_num = red_mass_num * gas.molecular_weights[j]
red_mass_den = red_mass_den + gas.molecular_weights[j]
coll_dia = coll_dia + diameter
well_dep = well_dep * well_depth
elif stoic_coeff(j,i) == 2:
S = gas.species(j)
diameter = S.transport.diameter
well_depth = S.transport.well_depth
red_mass_num = gas.molecular_weights[j] * gas.molecular_weights[j]
red_mass_den = 2 * gas.molecular_weights[j]
coll_dia = 2 * diameter
well_dep = well_depth * well_depth
Ts = kb * T / (math.sqrt(well_dep))
Om = (1.16145 * (Ts**(-0.14874))) + (0.52487 * (math.exp(-0.7732 * Ts))) + (2.16178 * (math.exp(-2.437887*Ts)))
k_limit = (math.sqrt((8 * pi * kb * T * red_mass_den * Na) / red_mass_num)) * ((coll_dia/2)**2) * Na * Om
if k_forward[i] > k_limit:
v = v + 1
ratiolow[i] = k_forward[i]/k_limit
print(i, gas.reaction_equations([i]), "{:.2e}".format(k_forward[i]), "{:.2e}".format(k_limit))
b = b + 1
print('# of rxns,', '# of violations')
print (b , v )
print (' ')
##########################################
##Vioaltion check for reverse reactions##
print ('elementary and reverse')
print('rxn no.,','rxn,', 'k_r,', 'k_coll,', 'k_f,', 'k_eq')
k_reverse = gas.reverse_rate_constants
stoic_coeff = gas.product_stoich_coeff
v = 0
b = 0
ratiolow=np.zeros(gas.n_reactions)
for i in range(0,r):
red_mass_num = 1
red_mass_den = 0
coll_dia = 0
well_dep = 1
tot_coeff = 0
for l in range (0,s): tot_coeff = tot_coeff + stoic_coeff(l,i)
if gas.reaction_type(i)==1 and tot_coeff == 2 and gas.is_reversible(i)==True:
for j in range(0,s):
if stoic_coeff(j,i) == 1:
S = gas.species(j)
diameter = S.transport.diameter
well_depth = S.transport.well_depth
red_mass_num = red_mass_num * gas.molecular_weights[j]
red_mass_den = red_mass_den + gas.molecular_weights[j]
coll_dia = coll_dia + diameter
well_dep = well_dep * well_depth
elif stoic_coeff(j,i) == 2:
S = gas.species(j)
diameter = S.transport.diameter
well_depth = S.transport.well_depth
red_mass_num = gas.molecular_weights[j] * gas.molecular_weights[j]
red_mass_den = 2 * gas.molecular_weights[j]
coll_dia = 2 * diameter
well_dep = well_depth * well_depth
Ts = kb * T / (math.sqrt(well_dep))
Om = (1.16145 * (Ts**(-0.14874))) + (0.52487 * (math.exp(-0.7732 * Ts))) + (2.16178 * (math.exp(-2.437887*Ts)))
k_limit = (math.sqrt((8 * pi * kb * T * red_mass_den * Na) / red_mass_num)) * ((coll_dia/2)**2) * Na * Om
if k_reverse[i] > k_limit:
v = v + 1
ratiolow[i] = k_reverse[i]/k_limit
print(i, gas.reaction_equations([i]), "{:.2e}".format(k_reverse[i]), "{:.2e}".format(k_limit), "{:.2e}".format(k_forward[i]), "{:.2e}".format(k_eq[i]))
b = b + 1
print('# of rxns,', '# of violations')
print (b , v )
print (' ')
#################################################
#falloff rxns#
##########################################
##Vioaltion check for forward reactions##
print ('falloff and forward')
print('rxn no.,','rxn,', 'k_f,', 'k_coll')
stoic_coeff = gas.reactant_stoich_coeff
v = 0
b = 0
ratiolow=np.zeros(gas.n_reactions)
for i in range(0,r):
red_mass_num = 1
red_mass_den = 0
coll_dia = 0
well_dep = 1
tot_coeff = 0
for l in range (0,s): tot_coeff = tot_coeff + stoic_coeff(l,i)
if gas.reaction_type(i)==4 and tot_coeff == 2:
for j in range(0,s):
if stoic_coeff(j,i) == 1:
S = gas.species(j)
diameter = S.transport.diameter
well_depth = S.transport.well_depth
red_mass_num = red_mass_num * gas.molecular_weights[j]
red_mass_den = red_mass_den + gas.molecular_weights[j]
coll_dia = coll_dia + diameter
well_dep = well_dep * well_depth
elif stoic_coeff(j,i) == 2:
S = gas.species(j)
diameter = S.transport.diameter
well_depth = S.transport.well_depth
red_mass_num = gas.molecular_weights[j] * gas.molecular_weights[j]
red_mass_den = 2 * gas.molecular_weights[j]
coll_dia = 2 * diameter
well_dep = well_depth * well_depth
Ts = kb * T / (math.sqrt(well_dep))
Om = (1.16145 * (Ts**(-0.14874))) + (0.52487 * (math.exp(-0.7732 * Ts))) + (2.16178 * (math.exp(-2.437887*Ts)))
k_limit = (math.sqrt((8 * pi * kb * T * red_mass_den * Na) / red_mass_num)) * ((coll_dia/2)**2) * Na * Om
ArrA = gas.reaction(i).high_rate.pre_exponential_factor
EA = gas.reaction(i).high_rate.activation_energy
Arrb = gas.reaction(i).high_rate.temperature_exponent
k_forward[i] = ArrA*np.power(T,Arrb)*np.exp(-EA/(T*ct.gas_constant))
if k_forward[i] > k_limit:
v = v + 1
ratiolow[i] = k_forward[i]/k_limit
print(i, gas.reaction_equations([i]), "{:.2e}".format(k_forward[i]), "{:.2e}".format(k_limit))
b = b + 1
print('# of rxns,', '# of violations')
print (b , v )
print (' ')
##########################################
##Vioaltion check for reverse reactions##
print ('falloff and reverse')
print('rxn no.,','rxn,', 'k_r,', 'k_coll,', 'k_f,', 'k_eq')
stoic_coeff = gas.product_stoich_coeff
v = 0
b = 0
ratiolow=np.zeros(gas.n_reactions)
for i in range(0,r):
red_mass_num = 1
red_mass_den = 0
coll_dia = 0
well_dep = 1
tot_coeff = 0
for l in range (0,s): tot_coeff = tot_coeff + stoic_coeff(l,i)
if gas.reaction_type(i)==4 and tot_coeff == 2 and gas.is_reversible(i)==True:
for j in range(0,s):
if stoic_coeff(j,i) == 1:
S = gas.species(j)
diameter = S.transport.diameter
well_depth = S.transport.well_depth
red_mass_num = red_mass_num * gas.molecular_weights[j]
red_mass_den = red_mass_den + gas.molecular_weights[j]
coll_dia = coll_dia + diameter
well_dep = well_dep * well_depth
elif stoic_coeff(j,i) == 2:
S = gas.species(j)
diameter = S.transport.diameter
well_depth = S.transport.well_depth
red_mass_num = gas.molecular_weights[j] * gas.molecular_weights[j]
red_mass_den = 2 * gas.molecular_weights[j]
coll_dia = 2 * diameter
well_dep = well_depth * well_depth
Ts = kb * T / (math.sqrt(well_dep))
Om = (1.16145 * (Ts**(-0.14874))) + (0.52487 * (math.exp(-0.7732 * Ts))) + (2.16178 * (math.exp(-2.437887*Ts)))
k_limit = (math.sqrt((8 * pi * kb * T * red_mass_den * Na) / red_mass_num)) * ((coll_dia/2)**2) * Na * Om
ArrA = gas.reaction(i).high_rate.pre_exponential_factor
EA = gas.reaction(i).high_rate.activation_energy
Arrb = gas.reaction(i).high_rate.temperature_exponent
k_forward[i] = ArrA*np.power(T,Arrb)*np.exp(-EA/(T*ct.gas_constant))
k_reverse[i] = (ArrA*np.power(T,Arrb)*np.exp(-EA/(T*ct.gas_constant)))/k_eq[i]
if k_reverse[i] > k_limit:
v = v + 1
ratiolow[i] = k_reverse[i]/k_limit
print(i, gas.reaction_equations([i]), "{:.2e}".format(k_reverse[i]), "{:.2e}".format(k_limit), "{:.2e}".format(k_forward[i]), "{:.2e}".format(k_eq[i]))
b = b + 1
print('# of rxns,', '# of violations')
print (b , v )
print (' ')
#################################################
#plog#
##########################################
##Vioaltion check for forward reactions##
print ('plog and forward')
print('rxn no.,','rxn,', 'LP,', 'HP,', 'k_f@LP,', 'k_f@HP,', 'k_coll')
stoic_coeff = gas.reactant_stoich_coeff
v = 0
b = 0
ratiolow=np.zeros(gas.n_reactions)
for i in range(0,r):
red_mass_num = 1
red_mass_den = 0
coll_dia = 0
well_dep = 1
tot_coeff = 0
for l in range (0,s): tot_coeff = tot_coeff + stoic_coeff(l,i)
if gas.reaction_type(i)==5 and tot_coeff == 2:
for j in range(0,s):
if stoic_coeff(j,i) == 1:
S = gas.species(j)
diameter = S.transport.diameter
well_depth = S.transport.well_depth
red_mass_num = red_mass_num * gas.molecular_weights[j]
red_mass_den = red_mass_den + gas.molecular_weights[j]
coll_dia = coll_dia + diameter
well_dep = well_dep * well_depth
elif stoic_coeff(j,i) == 2:
S = gas.species(j)
diameter = S.transport.diameter
well_depth = S.transport.well_depth
red_mass_num = gas.molecular_weights[j] * gas.molecular_weights[j]
red_mass_den = 2 * gas.molecular_weights[j]
coll_dia = 2 * diameter
well_dep = well_depth * well_depth
Ts = kb * T / (math.sqrt(well_dep))
Om = (1.16145 * (Ts**(-0.14874))) + (0.52487 * (math.exp(-0.7732 * Ts))) + (2.16178 * (math.exp(-2.437887*Ts)))
k_limit = (math.sqrt((8 * pi * kb * T * red_mass_den * Na) / red_mass_num)) * ((coll_dia/2)**2) * Na * Om
myarray = np.asarray(gas.reaction(i).rates)
for n in range(0,len(myarray)):
P = myarray[n,0]
gas.TP = T, P
k_forward[i] = gas.forward_rate_constants[i]
if k_forward[i] > k_limit:
v = v + 1
# ratiolow[i] = k_forward[i]/k_limit
print(i, gas.reaction_equations([i]), P, "{:.2e}".format(k_forward[i]), "{:.2e}".format(k_limit))
b = b + 1
print('# of rxns,', '# of violations(counting violation at each pressure)')
print (b , v )
print (' ')
##########################################
##Vioaltion check for reverse reactions##
print ('plog and reverse')
print('rxn no.,','rxn,','LP,', 'HP,', 'k_r@LP,', 'k_r@HP,', 'k_coll,', 'k_f,', 'k_eq')
stoic_coeff = gas.product_stoich_coeff
v = 0
b = 0
ratiolow=np.zeros(gas.n_reactions)
for i in range(0,r):
red_mass_num = 1
red_mass_den = 0
coll_dia = 0
well_dep = 1
tot_coeff = 0
for l in range (0,s): tot_coeff = tot_coeff + stoic_coeff(l,i)
if gas.reaction_type(i)==5 and tot_coeff == 2 and gas.is_reversible(i)==True:
for j in range(0,s):
if stoic_coeff(j,i) == 1:
S = gas.species(j)
diameter = S.transport.diameter
well_depth = S.transport.well_depth
red_mass_num = red_mass_num * gas.molecular_weights[j]
red_mass_den = red_mass_den + gas.molecular_weights[j]
coll_dia = coll_dia + diameter
well_dep = well_dep * well_depth
elif stoic_coeff(j,i) == 2:
S = gas.species(j)
diameter = S.transport.diameter
well_depth = S.transport.well_depth
red_mass_num = gas.molecular_weights[j] * gas.molecular_weights[j]
red_mass_den = 2 * gas.molecular_weights[j]
coll_dia = 2 * diameter
well_dep = well_depth * well_depth
Ts = kb * T / (math.sqrt(well_dep))
Om = (1.16145 * (Ts**(-0.14874))) + (0.52487 * (math.exp(-0.7732 * Ts))) + (2.16178 * (math.exp(-2.437887*Ts)))
k_limit = (math.sqrt((8 * pi * kb * T * red_mass_den * Na) / red_mass_num)) * ((coll_dia/2)**2) * Na * Om
myarray = np.asarray(gas.reaction(i).rates)
for n in range(0,len(myarray)):
P = myarray[n,0]
gas.TP = T, P
k_reverse[i] = gas.reverse_rate_constants[i]
k_forward[i] = gas.forward_rate_constants[i]
k_eq[i] = gas.equilibrium_constants[i]
if k_reverse[i] > k_limit:
v = v + 1
# ratiolow[i] = k_forward[i]/k_limit
print(i, gas.reaction_equations([i]), P, "{:.2e}".format(k_reverse[i]), "{:.2e}".format(k_limit), "{:.2e}".format(k_forward[i]), "{:.2e}".format(k_eq[i]))
b = b + 1
print('# of rxns,', '# of violations(counting violation at each pressure)')
print (b , v )
print (' ')
#################################################
f.close()