Skip to content

Commit 91f71dc

Browse files
committed
correct Gibbs free energy for each species based on its 3-parameter polynomial thermo coverage depedent model
1 parent 6566426 commit 91f71dc

File tree

1 file changed

+19
-53
lines changed

1 file changed

+19
-53
lines changed

rmgpy/solver/surface.pyx

Lines changed: 19 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ cdef class SurfaceReactor(ReactionSystem):
174174
)
175175
cdef np.ndarray[np.int_t, ndim=1] species_on_surface, reactions_on_surface
176176
cdef Py_ssize_t index
177-
cdef np.ndarray thermo_coeff_matrix = np.zeros((len(self.species_index)*len(self.species_index), 4), dtype=np.float64)
177+
cdef np.ndarray thermo_coeff_matrix = np.zeros((len(self.species_index), len(self.species_index), 6), dtype=np.float64)
178178
self.thermo_coeff_matrix = thermo_coeff_matrix
179179
#: 1 if it's on a surface, 0 if it's in the gas phase
180180
reactions_on_surface = np.zeros((self.num_core_reactions + self.num_edge_reactions), int)
@@ -211,30 +211,11 @@ cdef class SurfaceReactor(ReactionSystem):
211211
for spec, parameters in sp.thermo.thermo_coverage_dependence.items():
212212
try:
213213
species_index = self.species_index[spec]
214+
thermo_polynomials = parameters['enthalpy-coefficients'] + parameters['entropy-coefficients']
215+
self.thermo_coeff_matrix[sp_index, species_index] = [x.value_si for x in thermo_polynomials]
214216
except KeyError:
215217
logging.warning("Species {} is not in the species list yet, skip the thermodynamic coverage effect estimation!".format(spec))
216-
try:
217-
list_of_thermo_coverage_deps = self.thermo_coverage_dependencies[species_index]
218-
except KeyError: # doesn't exist yet
219-
list_of_thermo_coverage_deps = []
220-
self.thermo_coverage_dependencies[sp_index] = list_of_thermo_coverage_deps
221-
# need to specify the entropy and enthalpy models
222-
# linear, piecewise linear, polynomial, interpolative models
223-
if parameters['model'] == "polynomial":
224-
# for the case of polynomial, we need to insert a 0 for the constant term
225-
parameters['enthalpy-coefficients'] = [0]+[x.value_si for x in parameters['enthalpy-coefficients']]
226-
parameters['entropy-coefficients'] = [0]+[x.value_si for x in parameters['entropy-coefficients']]
227-
list_of_thermo_coverage_deps.append((sp_index, parameters))
228-
229-
"""
230-
self.thermo_coverage_dependencies[2] = [(3, {"model":"linear","enthalpy-coefficients":[], "entropy-coefficients":[]}),]
231-
self.thermo_coverage_dependencies[2] = [(3, {"model":"polynomial","enthalpy-coefficients":[], "entropy-coefficients":[]}),]
232-
self.thermo_coverage_dependencies[2] = [(3, {"model":"piecewise-linear","enthalpy-coefficients":{"enthalpy_high":, "enthalpy_low":, "enthalpy_change":},
233-
"entropy-coefficients":{"entropy_high":, "entropy_low":, "entropy_change"}, "Cp":{"heat-capacity-a":, "heat-capacity-b":}}),]
234-
self.thermo_coverage_dependencies[2] = {(3, {"model":"interpolative","enthalpy-coefficients":{"enthalpy-coverages":, "enthalpies":}, "entropy-coefficients":{"entropy-coverages":, "entropies":}}),}
235-
means that Species with index 2 in the current simulation is used in
236-
Species 3 with parameters for linear, polynomial, piecewise-linear, and interpolative models
237-
"""
218+
238219
self.species_on_surface = species_on_surface
239220
self.reactions_on_surface = reactions_on_surface
240221

@@ -418,7 +399,6 @@ cdef class SurfaceReactor(ReactionSystem):
418399
cdef np.ndarray[np.float64_t, ndim=2] jacobian, dgdk
419400
cdef list list_of_coverage_deps
420401
cdef double surface_site_fraction, total_sites, a, m, E
421-
422402
ir = self.reactant_indices
423403
ip = self.product_indices
424404
equilibrium_constants = self.Keq
@@ -452,7 +432,6 @@ cdef class SurfaceReactor(ReactionSystem):
452432
V = self.V # constant volume reactor
453433
A = self.V * surface_volume_ratio_si # area
454434
total_sites = self.surface_site_density.value_si * A # todo: double check units
455-
456435
for j in range(num_core_species):
457436
if species_on_surface[j]:
458437
C[j] = (N[j] / V) / surface_volume_ratio_si
@@ -462,35 +441,22 @@ cdef class SurfaceReactor(ReactionSystem):
462441
core_species_concentrations[j] = C[j]
463442

464443
# Thermodynamic coverage dependence
465-
free_energy_coverage_corrections = np.zeros(len(self.species_index), float) # length of core + edge species
466444
if self.thermo_coverage_dependence:
467-
"""
468-
self.thermo_coverage_dependencies[2] = [(3, {"model":"linear","enthalpy-coefficients":[], "entropy-coefficients":[]}),]
469-
self.thermo_coverage_dependencies[2] = [(3, {"model":"polynomial","enthalpy-coefficients":[], "entropy-coefficients":[]}),]
470-
self.thermo_coverage_dependencies[2] = [(3, {"model":"piecewise-linear","enthalpy-coefficients":{"enthalpy_high":, "enthalpy_low":, "enthalpy_change":},
471-
"entropy-coefficients":{"entropy_high":, "entropy_low":, "entropy_change"}, "Cp":{"heat-capacity-a":, "heat-capacity-b":}}),]
472-
self.thermo_coverage_dependencies[2] = {(3, {"model":"interpolative","enthalpy-coefficients":{"enthalpy-coverages":, "enthalpies":}, "entropy-coefficients":{"entropy-coverages":, "entropies":}}),}
473-
means that Species with index 2 in the current simulation is used in
474-
Species 3 with parameters for linear, polynomial, piecewise-linear, and interpolative models
475-
"""
476-
for i, list_of_thermo_coverage_deps in self.thermo_coverage_dependencies.items():
477-
surface_site_fraction = N[i] / total_sites
478-
if surface_site_fraction < 1e-15:
479-
continue
480-
for j, parameters in list_of_thermo_coverage_deps:
481-
# Species i, Species j
482-
# need to specify the entropy and enthalpy models
483-
# linear, piecewise linear, polynomial, interpolative models
484-
if parameters['model'] == "linear":
485-
pass
486-
elif parameters['model'] == "polynomial":
487-
enthalpy_cov_correction = np.polynomial.polynomial.polyval(surface_site_fraction, parameters['enthalpy-coefficients']) # insert 0 for the constant term
488-
entropy_cov_correction = np.polynomial.polynomial.polyval(surface_site_fraction, parameters['entropy-coefficients'])
489-
free_energy_coverage_corrections[j] += enthalpy_cov_correction - self.T.value_si * entropy_cov_correction
490-
elif parameters['model'] == "piecewise-linear":
491-
pass
492-
elif parameters['model'] == "interpolative":
493-
pass
445+
coverages = []
446+
for i in range(len(N)):
447+
if species_on_surface[i]:
448+
surface_site_fraction = N[i] / total_sites
449+
else:
450+
surface_site_fraction = 0
451+
coverages.append(surface_site_fraction)
452+
coverages = np.array(coverages)
453+
thermo_dep_coverage = np.stack([coverages, coverages**2, coverages**3, -self.T.value_si*coverages, -self.T.value_si*coverages**2, -self.T.value_si*coverages**3])
454+
free_energy_coverage_corrections = []
455+
for matrix in self.thermo_coeff_matrix:
456+
sp_free_energy_correction = np.diag(np.dot(matrix, thermo_dep_coverage)).sum()
457+
free_energy_coverage_corrections.append(sp_free_energy_correction)
458+
free_energy_coverage_corrections = np.array(free_energy_coverage_corrections)
459+
494460
corrected_K_eq = copy.deepcopy(self.Keq)
495461
# correct the K_eq
496462
for j in range(ir.shape[0]):

0 commit comments

Comments
 (0)