Skip to content

Commit af53b93

Browse files
committed
use stoichiometric matrix to calculate the correct value for Keq
1 parent 91f71dc commit af53b93

File tree

1 file changed

+36
-21
lines changed

1 file changed

+36
-21
lines changed

rmgpy/solver/surface.pyx

Lines changed: 36 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ cdef class SurfaceReactor(ReactionSystem):
6868
cdef public np.ndarray reactions_on_surface # (catalyst surface, not core/edge surface)
6969
cdef public np.ndarray species_on_surface # (catalyst surface, not core/edge surface)
7070
cdef public np.ndarray thermo_coeff_matrix
71+
cdef public np.ndarray stoi_matrix
7172

7273
cdef public bint coverage_dependence
7374
cdef public dict coverage_dependencies
@@ -175,7 +176,9 @@ cdef class SurfaceReactor(ReactionSystem):
175176
cdef np.ndarray[np.int_t, ndim=1] species_on_surface, reactions_on_surface
176177
cdef Py_ssize_t index
177178
cdef np.ndarray thermo_coeff_matrix = np.zeros((len(self.species_index), len(self.species_index), 6), dtype=np.float64)
179+
cdef np.ndarray stoi_matrix = np.zeros((self.reactant_indices.shape[0], len(self.species_index)), dtype=np.float64)
178180
self.thermo_coeff_matrix = thermo_coeff_matrix
181+
self.stoi_matrix = stoi_matrix
179182
#: 1 if it's on a surface, 0 if it's in the gas phase
180183
reactions_on_surface = np.zeros((self.num_core_reactions + self.num_edge_reactions), int)
181184
species_on_surface = np.zeros((self.num_core_species), int)
@@ -215,7 +218,36 @@ cdef class SurfaceReactor(ReactionSystem):
215218
self.thermo_coeff_matrix[sp_index, species_index] = [x.value_si for x in thermo_polynomials]
216219
except KeyError:
217220
logging.warning("Species {} is not in the species list yet, skip the thermodynamic coverage effect estimation!".format(spec))
218-
221+
222+
if self.thermo_coverage_dependence:
223+
ir = self.reactant_indices
224+
ip = self.product_indices
225+
for rxn_id, rxn_stoi_num in enumerate(stoi_matrix):
226+
if ir[rxn_id, 0] >= self.num_core_species or ir[rxn_id, 1] >= self.num_core_species or ir[rxn_id, 2] >= self.num_core_species:
227+
continue
228+
elif ip[rxn_id, 0] >= self.num_core_species or ip[rxn_id, 1] >= self.num_core_species or ip[rxn_id, 2] >= self.num_core_species:
229+
continue
230+
else:
231+
if ir[rxn_id, 1] == -1: # only one reactant
232+
rxn_stoi_num[ir[rxn_id, 0]] += -1
233+
elif ir[rxn_id, 2] == -1: # only two reactants
234+
rxn_stoi_num[ir[rxn_id, 0]] += -1
235+
rxn_stoi_num[ir[rxn_id, 1]] += -1
236+
else: # three reactants
237+
rxn_stoi_num[ir[rxn_id, 0]] += -1
238+
rxn_stoi_num[ir[rxn_id, 1]] += -1
239+
rxn_stoi_num[ir[rxn_id, 2]] += -1
240+
if ip[rxn_id, 1] == -1: # only one product
241+
rxn_stoi_num[ip[rxn_id, 0]] += 1
242+
elif ip[rxn_id, 2] == -1: # only two products
243+
rxn_stoi_num[ip[rxn_id, 0]] += 1
244+
rxn_stoi_num[ip[rxn_id, 1]] += 1
245+
else: # three products
246+
rxn_stoi_num[ip[rxn_id, 0]] += 1
247+
rxn_stoi_num[ip[rxn_id, 1]] += 1
248+
rxn_stoi_num[ip[rxn_id, 2]] += 1
249+
self.stoi_matrix = stoi_matrix
250+
219251
self.species_on_surface = species_on_surface
220252
self.reactions_on_surface = reactions_on_surface
221253

@@ -455,28 +487,11 @@ cdef class SurfaceReactor(ReactionSystem):
455487
for matrix in self.thermo_coeff_matrix:
456488
sp_free_energy_correction = np.diag(np.dot(matrix, thermo_dep_coverage)).sum()
457489
free_energy_coverage_corrections.append(sp_free_energy_correction)
458-
free_energy_coverage_corrections = np.array(free_energy_coverage_corrections)
459-
490+
rxns_free_energy_change = np.diag(np.dot(self.stoi_matrix, np.transpose(np.array([free_energy_coverage_corrections]))))
460491
corrected_K_eq = copy.deepcopy(self.Keq)
461-
# correct the K_eq
462-
for j in range(ir.shape[0]):
463-
if ir[j, 0] >= num_core_species or ir[j, 1] >= num_core_species or ir[j, 2] >= num_core_species:
464-
pass
465-
elif ir[j, 1] == -1: # only one reactant
466-
corrected_K_eq[j] *= np.exp(free_energy_coverage_corrections[ir[j, 0]] / (constants.R * self.T.value_si))
467-
elif ir[j, 2] == -1: # only two reactants
468-
corrected_K_eq[j] *= np.exp((free_energy_coverage_corrections[ir[j, 0]] + free_energy_coverage_corrections[ir[j, 1]]) / (constants.R * self.T.value_si))
469-
else: # three reactants!! (really?)
470-
corrected_K_eq[j] *= np.exp((free_energy_coverage_corrections[ir[j, 0]] + free_energy_coverage_corrections[ir[j, 1]] + free_energy_coverage_corrections[ir[j, 2]]) / (constants.R * self.T.value_si))
471-
if ip[j, 0] >= num_core_species or ip[j, 1] >= num_core_species or ip[j, 2] >= num_core_species:
472-
pass
473-
elif ip[j, 1] == -1: # only one product
474-
corrected_K_eq[j] /= np.exp(free_energy_coverage_corrections[ip[j, 0]] / (constants.R * self.T.value_si))
475-
elif ip[j, 2] == -1: # only two products
476-
corrected_K_eq[j] /= np.exp((free_energy_coverage_corrections[ip[j, 0]] + free_energy_coverage_corrections[ip[j, 1]]) / (constants.R * self.T.value_si))
477-
else: # three products!! (really?)
478-
corrected_K_eq[j] /= np.exp((free_energy_coverage_corrections[ip[j, 0]] + free_energy_coverage_corrections[ip[j, 1]] + free_energy_coverage_corrections[ip[j, 2]]) / (constants.R * self.T.value_si))
492+
corrected_K_eq *= np.exp(-1 * rxns_free_energy_change / (constants.R * self.T.value_si))
479493
kr = kf / corrected_K_eq
494+
480495
# Coverage dependence
481496
coverage_corrections = np.ones_like(kf, float)
482497
if self.coverage_dependence:

0 commit comments

Comments
 (0)