7373from rmgpy .rmg .settings import ModelSettings
7474from rmgpy .solver .base import TerminationTime , TerminationConversion
7575from rmgpy .solver .simple import SimpleReactor
76+ from rmgpy .solver .electrode import ElectrodeReactor
7677from rmgpy .stats import ExecutionStatsWriter
7778from rmgpy .thermo .thermoengine import submit
7879from rmgpy .tools .plot import plot_sensitivity
@@ -166,6 +167,8 @@ def __init__(self, input_file=None, output_directory=None, profiler=None, stats_
166167 self .Tmax = 0.0
167168 self .Pmin = 0.0
168169 self .Pmax = 0.0
170+ self .potential_min = 0.0
171+ self .potential_max = 0.0
169172 self .database = None
170173
171174 def clear (self ):
@@ -685,6 +688,8 @@ def execute(self, initialize=True, **kwargs):
685688 try :
686689 self .Pmin = min ([x .Prange [0 ].value_si if hasattr (x , 'Prange' ) and x .Prange else x .P .value_si for x in self .reaction_systems ])
687690 self .Pmax = max ([x .Prange [1 ].value_si if hasattr (x , 'Prange' ) and x .Prange else x .P .value_si for x in self .reaction_systems ])
691+ self .potential_min = min ([x .potential_range [0 ].value_si if x .potential_range else x .potential .value_si for x in self .reaction_systems ])
692+ self .potential_max = max ([x .potential_range [1 ].value_si if x .potential_range else x .potential .value_si for x in self .reaction_systems ])
688693 except AttributeError :
689694 pass
690695
@@ -698,6 +703,16 @@ def execute(self, initialize=True, **kwargs):
698703 self .rmg_memories .append (RMG_Memory (reaction_system , self .balance_species ))
699704 self .rmg_memories [index ].generate_cond ()
700705 log_conditions (self .rmg_memories , index )
706+ conditions = self .rmg_memories [index ].get_cond ()
707+ temperature = potential = None
708+ if isinstance (reaction_system , ElectrodeReactor ):
709+ if conditions :
710+ potential = conditions .get ('potential' )
711+ temperature = conditions .get ('T' )
712+ if not potential :
713+ potential = reaction_system .potential .value_si
714+ if not temperature :
715+ temperature = reaction_system .T .value_si
701716
702717 # Update react flags
703718 if self .filter_reactions :
@@ -711,7 +726,7 @@ def execute(self, initialize=True, **kwargs):
711726 atol = self .simulator_settings_list [0 ].atol ,
712727 rtol = self .simulator_settings_list [0 ].rtol ,
713728 filter_reactions = True ,
714- conditions = self . rmg_memories [ index ]. get_cond () ,
729+ conditions = conditions ,
715730 )
716731
717732 self .update_reaction_threshold_and_react_flags (
@@ -732,7 +747,9 @@ def execute(self, initialize=True, **kwargs):
732747 self .reaction_model .enlarge (react_edge = True ,
733748 unimolecular_react = self .unimolecular_react ,
734749 bimolecular_react = self .bimolecular_react ,
735- trimolecular_react = self .trimolecular_react )
750+ trimolecular_react = self .trimolecular_react ,
751+ temperature = temperature ,
752+ potential = potential )
736753
737754 if not np .isinf (self .model_settings_list [0 ].thermo_tol_keep_spc_in_edge ):
738755 self .reaction_model .set_thermodynamic_filtering_parameters (
@@ -793,6 +810,15 @@ def execute(self, initialize=True, **kwargs):
793810 objects_to_enlarge = []
794811
795812 conditions = self .rmg_memories [index ].get_cond ()
813+ if isinstance (reaction_system , ElectrodeReactor ):
814+ if conditions :
815+ potential = conditions .get ('potential' )
816+ temperature = conditions .get ('T' )
817+ if not potential :
818+ potential = reaction_system .potential .value_si
819+ if not temperature :
820+ temperature = reaction_system .T .value_si
821+
796822 if conditions and self .solvent :
797823 T = conditions ['T' ]
798824 # Set solvent viscosity
@@ -822,7 +848,7 @@ def execute(self, initialize=True, **kwargs):
822848 prune = prune ,
823849 model_settings = model_settings ,
824850 simulator_settings = simulator_settings ,
825- conditions = self . rmg_memories [ index ]. get_cond ()
851+ conditions = conditions
826852 )
827853 except :
828854 logging .error ("Model core reactions:" )
@@ -835,9 +861,9 @@ def execute(self, initialize=True, **kwargs):
835861 self .make_seed_mech () # Just in case the user wants to restart from this
836862 raise
837863
864+ log_conditions (self .rmg_memories , index )
838865 self .rmg_memories [index ].add_t_conv_N (t , x , len (obj ))
839866 self .rmg_memories [index ].generate_cond ()
840- log_conditions (self .rmg_memories , index )
841867
842868 reactor_done = self .reaction_model .add_new_surface_objects (obj , new_surface_species ,
843869 new_surface_reactions , reaction_system )
@@ -922,7 +948,9 @@ def execute(self, initialize=True, **kwargs):
922948 self .reaction_model .enlarge (react_edge = True ,
923949 unimolecular_react = self .unimolecular_react ,
924950 bimolecular_react = self .bimolecular_react ,
925- trimolecular_react = self .trimolecular_react )
951+ trimolecular_react = self .trimolecular_react ,
952+ potential = potential ,
953+ temperature = temperature )
926954
927955 if old_edge_size != len (self .reaction_model .edge .reactions ) or old_core_size != len (
928956 self .reaction_model .core .reactions ):
@@ -2212,6 +2240,9 @@ def __init__(self, reaction_system, bspc):
22122240 if hasattr (reaction_system , 'Prange' ) and isinstance (reaction_system .Prange , list ):
22132241 Prange = reaction_system .Prange
22142242 self .Ranges ['P' ] = [np .log (P .value_si ) for P in Prange ]
2243+ if hasattr (reaction_system , 'potential_range' ) and isinstance (reaction_system .potential_range , list ):
2244+ potential_range = reaction_system .potential_range
2245+ self .Ranges ['potential' ] = [V .value_si for V in potential_range ]
22152246 if hasattr (reaction_system , 'initial_mole_fractions' ):
22162247 if bspc :
22172248 self .initial_mole_fractions = deepcopy (reaction_system .initial_mole_fractions )
@@ -2326,6 +2357,8 @@ def obj(y):
23262357 enumerate (ykey )}
23272358 if 'P' in list (new_cond .keys ()):
23282359 new_cond ['P' ] = np .exp (new_cond ['P' ])
2360+ if 'potential' in list (new_cond .keys ()):
2361+ new_cond ['potential' ] = new_cond ['potential' ]
23292362
23302363 if hasattr (self , 'initial_mole_fractions' ):
23312364 for key in self .initial_mole_fractions .keys ():
@@ -2355,6 +2388,8 @@ def log_conditions(rmg_memories, index):
23552388 s += 'T = {0} K, ' .format (item )
23562389 elif key == 'P' :
23572390 s += 'P = {0} bar, ' .format (item / 1.0e5 )
2391+ elif key == 'potential' :
2392+ s += 'potential = {0} V, ' .format (item )
23582393 else :
23592394 s += key .label + ' = {0}, ' .format (item )
23602395
0 commit comments