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 ):
@@ -683,6 +686,8 @@ def execute(self, initialize=True, **kwargs):
683686 try :
684687 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 ])
685688 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 ])
689+ 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 ])
690+ 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 ])
686691 except AttributeError :
687692 pass
688693
@@ -696,6 +701,16 @@ def execute(self, initialize=True, **kwargs):
696701 self .rmg_memories .append (RMG_Memory (reaction_system , self .balance_species ))
697702 self .rmg_memories [index ].generate_cond ()
698703 log_conditions (self .rmg_memories , index )
704+ conditions = self .rmg_memories [index ].get_cond ()
705+ temperature = potential = None
706+ if isinstance (reaction_system , ElectrodeReactor ):
707+ if conditions :
708+ potential = conditions .get ('potential' )
709+ temperature = conditions .get ('T' )
710+ if not potential :
711+ potential = reaction_system .potential .value_si
712+ if not temperature :
713+ temperature = reaction_system .T .value_si
699714
700715 # Update react flags
701716 if self .filter_reactions :
@@ -709,7 +724,7 @@ def execute(self, initialize=True, **kwargs):
709724 atol = self .simulator_settings_list [0 ].atol ,
710725 rtol = self .simulator_settings_list [0 ].rtol ,
711726 filter_reactions = True ,
712- conditions = self . rmg_memories [ index ]. get_cond () ,
727+ conditions = conditions ,
713728 )
714729
715730 self .update_reaction_threshold_and_react_flags (
@@ -730,7 +745,9 @@ def execute(self, initialize=True, **kwargs):
730745 self .reaction_model .enlarge (react_edge = True ,
731746 unimolecular_react = self .unimolecular_react ,
732747 bimolecular_react = self .bimolecular_react ,
733- trimolecular_react = self .trimolecular_react )
748+ trimolecular_react = self .trimolecular_react ,
749+ temperature = temperature ,
750+ potential = potential )
734751
735752 if not np .isinf (self .model_settings_list [0 ].thermo_tol_keep_spc_in_edge ):
736753 self .reaction_model .set_thermodynamic_filtering_parameters (
@@ -791,6 +808,15 @@ def execute(self, initialize=True, **kwargs):
791808 objects_to_enlarge = []
792809
793810 conditions = self .rmg_memories [index ].get_cond ()
811+ if isinstance (reaction_system , ElectrodeReactor ):
812+ if conditions :
813+ potential = conditions .get ('potential' )
814+ temperature = conditions .get ('T' )
815+ if not potential :
816+ potential = reaction_system .potential .value_si
817+ if not temperature :
818+ temperature = reaction_system .T .value_si
819+
794820 if conditions and self .solvent :
795821 T = conditions ['T' ]
796822 # Set solvent viscosity
@@ -820,7 +846,7 @@ def execute(self, initialize=True, **kwargs):
820846 prune = prune ,
821847 model_settings = model_settings ,
822848 simulator_settings = simulator_settings ,
823- conditions = self . rmg_memories [ index ]. get_cond ()
849+ conditions = conditions
824850 )
825851 except :
826852 logging .error ("Model core reactions:" )
@@ -833,9 +859,9 @@ def execute(self, initialize=True, **kwargs):
833859 self .make_seed_mech () # Just in case the user wants to restart from this
834860 raise
835861
862+ log_conditions (self .rmg_memories , index )
836863 self .rmg_memories [index ].add_t_conv_N (t , x , len (obj ))
837864 self .rmg_memories [index ].generate_cond ()
838- log_conditions (self .rmg_memories , index )
839865
840866 reactor_done = self .reaction_model .add_new_surface_objects (obj , new_surface_species ,
841867 new_surface_reactions , reaction_system )
@@ -920,7 +946,9 @@ def execute(self, initialize=True, **kwargs):
920946 self .reaction_model .enlarge (react_edge = True ,
921947 unimolecular_react = self .unimolecular_react ,
922948 bimolecular_react = self .bimolecular_react ,
923- trimolecular_react = self .trimolecular_react )
949+ trimolecular_react = self .trimolecular_react ,
950+ potential = potential ,
951+ temperature = temperature )
924952
925953 if old_edge_size != len (self .reaction_model .edge .reactions ) or old_core_size != len (
926954 self .reaction_model .core .reactions ):
@@ -2210,6 +2238,9 @@ def __init__(self, reaction_system, bspc):
22102238 if hasattr (reaction_system , 'Prange' ) and isinstance (reaction_system .Prange , list ):
22112239 Prange = reaction_system .Prange
22122240 self .Ranges ['P' ] = [np .log (P .value_si ) for P in Prange ]
2241+ if hasattr (reaction_system , 'potential_range' ) and isinstance (reaction_system .potential_range , list ):
2242+ potential_range = reaction_system .potential_range
2243+ self .Ranges ['potential' ] = [V .value_si for V in potential_range ]
22132244 if hasattr (reaction_system , 'initial_mole_fractions' ):
22142245 if bspc :
22152246 self .initial_mole_fractions = deepcopy (reaction_system .initial_mole_fractions )
@@ -2324,6 +2355,8 @@ def obj(y):
23242355 enumerate (ykey )}
23252356 if 'P' in list (new_cond .keys ()):
23262357 new_cond ['P' ] = np .exp (new_cond ['P' ])
2358+ if 'potential' in list (new_cond .keys ()):
2359+ new_cond ['potential' ] = new_cond ['potential' ]
23272360
23282361 if hasattr (self , 'initial_mole_fractions' ):
23292362 for key in self .initial_mole_fractions .keys ():
@@ -2353,6 +2386,8 @@ def log_conditions(rmg_memories, index):
23532386 s += 'T = {0} K, ' .format (item )
23542387 elif key == 'P' :
23552388 s += 'P = {0} bar, ' .format (item / 1.0e5 )
2389+ elif key == 'potential' :
2390+ s += 'potential = {0} V, ' .format (item )
23562391 else :
23572392 s += key .label + ' = {0}, ' .format (item )
23582393
0 commit comments