@@ -20,7 +20,7 @@ def __init__(self,reaction_model=None):
20
20
"stagnated or diverging (residual = ${resid})." + \
21
21
" Assuming Jacobian is 0." ,
22
22
}
23
- # Create a log file of the solver
23
+ # Create a log file of the solver
24
24
self .outer_solver_log = 'outer_solver.log'
25
25
26
26
def get_rxn_rates (self ,coverages ,rate_constants ):
@@ -110,7 +110,7 @@ def get_selectivity(self,rxn_parameters,weights=None):
110
110
tofs = self .get_turnover_frequency (rxn_parameters )
111
111
if weights is None :
112
112
weights = [1 ]* len (tofs ) #use for weighted selectivity (e.g. % carbon)
113
-
113
+
114
114
if self .products is None :
115
115
self .products = [g for g ,r in zip (self .gas_names ,tofs ) if r > 0 ]
116
116
if self .reactants is None :
@@ -241,7 +241,7 @@ def get_rxn_order(self,rxn_parameters,epsilon=1e-10):
241
241
dP = (new_p [i ] - current_Ps [i ])/ current_Ps [i ]
242
242
DRC_i .append (float (dTOF / dP ))
243
243
DRC .append (DRC_i )
244
- self .gas_pressures = current_Ps
244
+ self .gas_pressures = current_Ps
245
245
self ._rxn_order = DRC
246
246
return DRC
247
247
@@ -299,12 +299,12 @@ def rate_equation_term(self,species_list,rate_string,d_wrt=None,specific_ads_nam
299
299
adsorbate_names = specific_ads_names
300
300
else :
301
301
adsorbate_names = self .adsorbate_names
302
-
302
+
303
303
# Separate the species_list into gas and sites
304
304
gas_idxs = [self .gas_names .index (gas )
305
305
for gas in species_list if gas in self .gas_names ]
306
306
#allows for multiple site types
307
- sites = [s for s in species_list if s in self .site_names ]
307
+ sites = [s for s in species_list if s in self .site_names ]
308
308
309
309
# Create an adsorbate list by making sure that the adsorbates do not
310
310
# include elements already present in the sites list.
@@ -314,9 +314,9 @@ def rate_equation_term(self,species_list,rate_string,d_wrt=None,specific_ads_nam
314
314
ads_idxs .append (adsorbate_names .index (ads ))
315
315
if len (gas_idxs + ads_idxs + sites ) != len (species_list ):
316
316
raise ValueError ('Undefined species in ' + ',' .join (species_list ))
317
-
317
+
318
318
if not d_wrt :
319
- # If the derivative is not required, simply
319
+ # If the derivative is not required, simply
320
320
# return the rate string based on the pressures and coverages
321
321
# of the relevant species
322
322
for iden in gas_idxs :
@@ -346,17 +346,17 @@ def rate_equation_term(self,species_list,rate_string,d_wrt=None,specific_ads_nam
346
346
# Also get the site in which the adsorbate is present
347
347
d_site = self .species_definitions [d_wrt ]['site' ]
348
348
349
- if (d_wrt not in sites # Not differentiating with respect to a site
350
- and d_idx in ads_idxs # Differentiating with respect to an adsorbate
351
- and d_site not in sites # Site not present in the rate expression
352
- and self .fix_x_star == True ): # Fixing x_star
349
+ if (d_wrt not in sites # Not differentiating with respect to a site
350
+ and d_idx in ads_idxs # Differentiating with respect to an adsorbate
351
+ and d_site not in sites # Site not present in the rate expression
352
+ and ( self .use_numbers_solver == False or self . fix_x_star == True ) ): # Fixing x_star
353
353
# Scenario 1: Differentiating with respect to an adsorbate
354
- # but there is no site term in the rate equation.
354
+ # but there is no site term in the rate equation.
355
355
multiplier = ads_idxs .count (d_idx ) #get order
356
356
ads_idxs .remove (d_idx ) #reduce order by 1
357
357
if multiplier != 1 :
358
358
rate_string = str (multiplier )+ '*' + rate_string
359
-
359
+
360
360
elif (len (ads_idxs )> 0 # Adsorbate is present in the rate expression
361
361
and d_site not in sites # Site not present in the rate expression
362
362
and d_wrt in self .site_names # Differentiating with respect to a site
@@ -367,7 +367,7 @@ def rate_equation_term(self,species_list,rate_string,d_wrt=None,specific_ads_nam
367
367
# of each adsorbate with respect to the site.
368
368
temp_rate_string = ''
369
369
for ie , ads_idx in enumerate (ads_idxs ):
370
- # get the other adsorbates by getting
370
+ # get the other adsorbates by getting
371
371
# all other index of ads_idxs expect ie
372
372
other_ads_idxs = []
373
373
for je in range (len (ads_idxs )):
@@ -376,7 +376,7 @@ def rate_equation_term(self,species_list,rate_string,d_wrt=None,specific_ads_nam
376
376
# the rate string will just be the coverage of
377
377
# the other adsorbates multiplied to each other
378
378
# multiplied by a -1 because the derivative with
379
- # respect to the site is negative of that of the
379
+ # respect to the site is negative of that of the
380
380
# adsorbate.
381
381
if other_ads_idxs :
382
382
temp_rate_string += '*' .join (['theta[' + str (i )+ ']' for i in other_ads_idxs ])
@@ -387,26 +387,26 @@ def rate_equation_term(self,species_list,rate_string,d_wrt=None,specific_ads_nam
387
387
rate_string += '*-1*(' + temp_rate_string + ')'
388
388
ads_idxs = [] #no more adsorbates
389
389
390
- elif ( d_site in sites # Site present in the rate expression
391
- and d_idx not in ads_idxs # Adsorbates not present in the rate expression
392
- and self .fix_x_star == True ): # Fixing x_star
393
- # Scenario 3: There is an empty site in
390
+ elif ( d_site in sites # Site present in the rate expression
391
+ and d_idx not in ads_idxs # Adsorbates not present in the rate expression
392
+ and ( self .use_numbers_solver == False or self . fix_x_star == True ) ): # Fixing x_star
393
+ # Scenario 3: There is an empty site in
394
394
# the rate equation but there is no adsorbate term
395
395
multiplier = sites .count (d_site )
396
- # Account for the fact that d/dsite does not have
396
+ # Account for the fact that d/dsite does not have
397
397
# a -1 pre-multiplier while d/dads does
398
398
if d_wrt not in self .site_names :
399
- multiplier = - 1 * multiplier # dsite/dtheta_* is negative
399
+ multiplier = - 1 * multiplier # dsite/dtheta_* is negative
400
400
sites .remove (d_site ) # reduce the order of site by 1
401
401
rate_string = str (multiplier )+ '*' + rate_string
402
402
403
- elif ( d_site in sites # Site present in the rate expression
403
+ elif ( d_site in sites # Site present in the rate expression
404
404
and d_idx in ads_idxs # Adsorbates present in the rate expression
405
405
and self .fix_x_star == True ): # Fixing x_star
406
406
# Scenario 4: Both an empty site and adsorbate in the rate equation
407
407
# need to use chain rule.
408
408
ads_mult = ads_idxs .count (d_idx )
409
- # Account for the fact that d/dsite doesnt have
409
+ # Account for the fact that d/dsite doesnt have
410
410
# a -1 pre-multiplier while d/dads does
411
411
if d_wrt not in self .site_names :
412
412
site_mult = - 1 * sites .count (d_site ) #negative 1 to account for d_site/d_ads
@@ -438,18 +438,18 @@ def rate_equation_term(self,species_list,rate_string,d_wrt=None,specific_ads_nam
438
438
[ads_str ]* (ads_mult - 1 ))+ ')'
439
439
rate_string += '*' + mult_rule
440
440
441
- elif self .fix_x_star == False :
442
- # Scenario 5: If x_star is not fixed, then
443
- # the partial derivatives are to be taken
444
- # independently for each site and adsorbate
441
+ elif ( self .use_numbers_solver == True and self . fix_x_star == False ) :
442
+ # Scenario 5: If x_star is not fixed, then
443
+ # the partial derivatives are to be taken
444
+ # independently for each site and adsorbate
445
445
if d_idx in ads_idxs and d_wrt not in self .site_names :
446
- # Taking a derivative with respect to an
446
+ # Taking a derivative with respect to an
447
447
# adsorbate coverage
448
448
multiplier = ads_idxs .count (d_idx ) #get order
449
449
ads_idxs .remove (d_idx ) #reduce order by 1
450
450
if multiplier != 1 :
451
451
rate_string = str (multiplier )+ '*' + rate_string
452
- elif d_wrt in sites :
452
+ elif d_wrt in sites :
453
453
# Taking the derivative with respect to a site
454
454
multiplier = sites .count (d_site )
455
455
sites .remove (d_site ) #reduce order by 1
@@ -463,9 +463,9 @@ def rate_equation_term(self,species_list,rate_string,d_wrt=None,specific_ads_nam
463
463
else :
464
464
# No dependence on either the adsorbate or the site
465
465
return '0'
466
-
467
- # Create the rate string for the derivative by taking into
468
- # account the derivative done by string manipulation in the
466
+
467
+ # Create the rate string for the derivative by taking into
468
+ # account the derivative done by string manipulation in the
469
469
# previous step
470
470
for iden in gas_idxs :
471
471
rate_string += '*p[' + str (iden )+ ']'
@@ -577,7 +577,7 @@ def rate_equations(self):
577
577
578
578
if self .use_numbers_solver :
579
579
# In case we use the numbers solver, the steady state
580
- # equations needs to be n+1 dimensional
580
+ # equations needs to be n+1 dimensional
581
581
adsorbate_names = self .adsorbate_names + self .site_names
582
582
# Remove 'g' if adsorbate_names if present
583
583
if 'g' in adsorbate_names :
@@ -609,7 +609,7 @@ def rate_equations(self):
609
609
surface_names = list (surface_names )
610
610
surface_names .remove ('g' )
611
611
surface_names = tuple (surface_names )
612
- species_iterate = self .adsorbate_names + surface_names
612
+ species_iterate = self .adsorbate_names + surface_names
613
613
else :
614
614
species_iterate = self .adsorbate_names
615
615
@@ -630,7 +630,7 @@ def rate_equations(self):
630
630
dcdt_strings .append (dcdt_str )
631
631
632
632
all_strings = rate_strings + dcdt_strings
633
-
633
+
634
634
return all_strings
635
635
636
636
def jacobian_equations (self ,adsorbate_interactions = True ):
@@ -683,7 +683,7 @@ def jacobian_equations(self,adsorbate_interactions=True):
683
683
# Standard CatMAP solver needs only an nxn Jacobian matrix
684
684
adsorbate_names = self .adsorbate_names
685
685
686
- if self .DEBUG :
686
+ if self .DEBUG :
687
687
with open ('adsorbate_names.log' ,'w' ) as f :
688
688
f .write (str (adsorbate_names ))
689
689
@@ -693,10 +693,10 @@ def jacobian_equations(self,adsorbate_interactions=True):
693
693
for i , ads_i in enumerate (adsorbate_names ):
694
694
# The second index is for the column
695
695
for j , ads_j in enumerate (adsorbate_names ):
696
- # Populate the Jacobian matrix based on the
696
+ # Populate the Jacobian matrix based on the
697
697
# required dimensions
698
698
J_str = 'J[' + str (i )+ '][' + str (j )+ '] = 0'
699
- # Iterate over the elementary reactions such that
699
+ # Iterate over the elementary reactions such that
700
700
# we get how much of the species are present
701
701
for k , rxn in enumerate (self .elementary_rxns ):
702
702
# Get the number of ads_i in the forward and reverse
@@ -705,7 +705,7 @@ def jacobian_equations(self,adsorbate_interactions=True):
705
705
rxnCounts = [- 1.0 * rxn [0 ].count (ads_i ),
706
706
1.0 * rxn [- 1 ].count (ads_i )]
707
707
rxnOrder = [o for o in rxnCounts if o ]
708
- # In the following, the drdx term is constructed
708
+ # In the following, the drdx term is constructed
709
709
# and then multiplied by the reaction order to get
710
710
# the df/dx term.
711
711
if rxnOrder :
@@ -714,7 +714,7 @@ def jacobian_equations(self,adsorbate_interactions=True):
714
714
rRate_string = self .rate_equation_term (rxn [- 1 ], 'kr[' + str (k )+ ']' , ads_j , adsorbate_names )
715
715
if adsorbate_interactions == True :
716
716
if ads_j not in self .site_names :
717
- # If one of the "adsorbates" is an empty site then
717
+ # If one of the "adsorbates" is an empty site then
718
718
# there should be no inclusion of adsorbate-adsorbate interaction
719
719
dfRate_string = self .rate_equation_term (rxn [0 ],'(kfkBT[' + str (k )+ '])*dEf[' + str (k )+ '][' + str (j )+ ']' )
720
720
drRate_string = self .rate_equation_term (rxn [- 1 ],'(krkBT[' + str (k )+ '])*dEr[' + str (k )+ '][' + str (j )+ ']' )
0 commit comments