-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_reaction_info.py
198 lines (166 loc) · 5.76 KB
/
get_reaction_info.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
# Author: Yang Gao
# Email: [email protected]
#################################################
# Extract reaction information from Cantera functions
# including: reaction rate parameters, third-body species and efficiencies, fall-off parameters
# reac.RA, reac.RB, reac.RE : forward temperature ABE factors
# reac.ITHB: number of enhanced third-body species, type: int
# reac.NKTB: indices of enhanced third-body species, type: list
# reac.AIK: efficiencies of enhanced third-body species, type: list
# reac.Fall: first 3-> low pressure limit ABE, 4th-7th: alpha, T3, T1, T2 (T2 is only for 7 parameters Troe)
# reaction type flag:
# reac.isReversible = False
# reac.isThirdbody = False
# reac.isFalloff = False
# reac.isChemical = False
# reac.isPLOG = False
# reac.isSimple = False
# reac.isLindemann = False
# reac.isTroe = False
# reac.isTroe6 = False
# reac.isTroe7 = False
#################################################
import numpy as np
# class of reaction information
class ReactionInfo:
def __init__(self):
self.isReversible = False
self.isThirdbody = False
self.isFalloff = False
self.isChemical = False
self.isPLOG = False
self.isSimple = False
self.isLindemann = False
self.isTroe = False
self.isTroe6 = False
self.isTroe7 = False
# Forward reaction ABE factors
self.RA = 0.0
self.RB = 0.0
self.RE = 0.0
# Number of third body species
self.ITHB = -1
# Third body coefficients
self.AIK = []
# Third body species indices
self.NKTB = []
# Fall off reaction parameters
# 1st:3rd : RKLOW ABE
# 4th:7th : alpha, T3, T1, T2
# Note that index starts from 0
self.Fall = []
# PLOG
self.NPLG = -1
self.P_plog = []
self.A_plog = []
self.B_plog = []
self.E_plog = []
# function to get reaction information
def get_reaction_info(g, i):
# g is the initialized chemistry
# e.g.
# g = ct.Solution('h2.cti')
# i the reaction index - 1 (Python is 0 based)
# E is converted and divided by ruc in this function
# i.e.
# k = A*T**B*exp(-E/T)
# Note that A is kmol based!!!
ruc = 8314.4621
r1 = g.reaction(i)
R_type = r1.reaction_type
reac = ReactionInfo()
if r1.reversible:
reac.isReversible = True
if R_type == 1:
reac.isSimple = True
rfhigh = r1.rate
a_high = rfhigh.pre_exponential_factor
b_high = rfhigh.temperature_exponent
e_high = rfhigh.activation_energy / ruc
reac.RA = a_high
reac.RB = b_high
reac.RE = e_high
# simple third-body, not fall-off
elif R_type == 2:
reac.isThirdbody = True
rfhigh = r1.rate
a_high = rfhigh.pre_exponential_factor
b_high = rfhigh.temperature_exponent
e_high = rfhigh.activation_energy / ruc
reac.RA = a_high
reac.RB = b_high
reac.RE = e_high
efficiencies = r1.efficiencies
third_body_species_keys = efficiencies.keys()
third_body_efficiencies_values = efficiencies.values()
third_body_species = list(third_body_species_keys)
third_body_efficients = list(third_body_efficiencies_values)
n_third = len(third_body_species)
reac.ITHB = n_third
for n in range(n_third):
# index
reac.NKTB.append( g.species_index(third_body_species[n]) )
# coefficients
reac.AIK.append ( third_body_efficients[n] )
# fall-off
elif R_type == 4:
reac.isFalloff = True
rfhigh = r1.high_rate
a_high = rfhigh.pre_exponential_factor
b_high = rfhigh.temperature_exponent
e_high = rfhigh.activation_energy / ruc
rflow = r1.low_rate
a_low = rflow.pre_exponential_factor
b_low = rflow.temperature_exponent
e_low = rflow.activation_energy / ruc
reac.RA = a_high
reac.RB = b_high
reac.RE = e_high
reac.Fall.append(a_low)
reac.Fall.append(b_low)
reac.Fall.append(e_low)
efficiencies = r1.efficiencies
third_body_species_keys = efficiencies.keys()
third_body_efficiencies_values = efficiencies.values()
third_body_species = list(third_body_species_keys)
third_body_efficients = list(third_body_efficiencies_values)
n_third = len(third_body_species)
reac.ITHB = n_third
for n in range(n_third):
# index
reac.NKTB.append(g.species_index(third_body_species[n]))
# coefficients
reac.AIK.append(third_body_efficients[n])
# Lindemann
if r1.falloff.falloff_type == 100:
reac.isLindemann = True
# no further fall off parameters
# Troe
if r1.falloff.falloff_type == 110:
reac.isTroe = True
troe_parameters = r1.falloff.parameters
alpha = troe_parameters[0]
t3 = troe_parameters[1]
t1 = troe_parameters[2]
t2 = troe_parameters[3]
if t2==0:
reac.isTroe6 = True
else:
reac.isTroe7 = True
reac.Fall.append(alpha)
reac.Fall.append(t3)
reac.Fall.append(t1)
reac.Fall.append(t2)
elif R_type == 5:
reac.isPLOG = True
reac.NPLG = len(r1.rates)
for n in range(0, reac.NPLG):
rate_plog = r1.rates[n]
reac.P_plog.append(rate_plog[0])
reac.A_plog.append(rate_plog[1].pre_exponential_factor)
reac.B_plog.append(rate_plog[1].temperature_exponent)
reac.E_plog.append(rate_plog[1].activation_energy / ruc)
else:
print ('Unknown reaction type, not supported!')
return 0
return reac