diff --git a/CHANGELOG.md b/CHANGELOG.md index 5203229bd3..7764a3b24a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ## Optimizations - Removed the `start_step_offset` setting and disabled minimum `dt` warnings for drive cycles with the (`IDAKLUSolver`). ([#4416](https://github.com/pybamm-team/PyBaMM/pull/4416)) +## Breaking changes +- Renamed `set_events` function to `add_events_from` to better reflect its purpose. ([#4421](https://github.com/pybamm-team/PyBaMM/pull/4421)) + # [v24.9.0](https://github.com/pybamm-team/PyBaMM/tree/v24.9.0) - 2024-09-03 ## Features diff --git a/src/pybamm/models/base_model.py b/src/pybamm/models/base_model.py index 0d4638e178..989465e375 100644 --- a/src/pybamm/models/base_model.py +++ b/src/pybamm/models/base_model.py @@ -757,7 +757,7 @@ def build_model_equations(self): f"Setting initial conditions for {submodel_name} submodel ({self.name})" ) submodel.set_initial_conditions(self.variables) - submodel.set_events(self.variables) + submodel.add_events_from(self.variables) pybamm.logger.verbose(f"Updating {submodel_name} submodel ({self.name})") self.update(submodel) self.check_no_repeated_keys() diff --git a/src/pybamm/models/full_battery_models/base_battery_model.py b/src/pybamm/models/full_battery_models/base_battery_model.py index ccda594b14..e0ade7b429 100644 --- a/src/pybamm/models/full_battery_models/base_battery_model.py +++ b/src/pybamm/models/full_battery_models/base_battery_model.py @@ -1033,7 +1033,7 @@ def build_model_equations(self): f"Setting initial conditions for {submodel_name} submodel ({self.name})" ) submodel.set_initial_conditions(self.variables) - submodel.set_events(self.variables) + submodel.add_events_from(self.variables) pybamm.logger.verbose(f"Updating {submodel_name} submodel ({self.name})") self.update(submodel) self.check_no_repeated_keys() diff --git a/src/pybamm/models/submodels/base_submodel.py b/src/pybamm/models/submodels/base_submodel.py index e120691edd..d5e313e153 100644 --- a/src/pybamm/models/submodels/base_submodel.py +++ b/src/pybamm/models/submodels/base_submodel.py @@ -221,7 +221,7 @@ def set_initial_conditions(self, variables): """ pass - def set_events(self, variables): + def add_events_from(self, variables): """ A method to set events related to the state of submodel variable. Note: this method modifies the state of self.events. Unless overwritten by a submodel, the diff --git a/src/pybamm/models/submodels/electrolyte_diffusion/constant_concentration.py b/src/pybamm/models/submodels/electrolyte_diffusion/constant_concentration.py index eee441446f..006619e8bb 100644 --- a/src/pybamm/models/submodels/electrolyte_diffusion/constant_concentration.py +++ b/src/pybamm/models/submodels/electrolyte_diffusion/constant_concentration.py @@ -76,6 +76,6 @@ def set_boundary_conditions(self, variables): } } - def set_events(self, variables): + def add_events_from(self, variables): # No event since the concentration is constant pass diff --git a/src/pybamm/models/submodels/equivalent_circuit_elements/diffusion_element.py b/src/pybamm/models/submodels/equivalent_circuit_elements/diffusion_element.py index c7f1b4bcd5..bf9a183875 100644 --- a/src/pybamm/models/submodels/equivalent_circuit_elements/diffusion_element.py +++ b/src/pybamm/models/submodels/equivalent_circuit_elements/diffusion_element.py @@ -102,7 +102,7 @@ def set_initial_conditions(self, variables): z = variables["Distributed SoC"] self.initial_conditions = {z: self.param.initial_soc} - def set_events(self, variables): + def add_events_from(self, variables): z_surf = variables["Surface SoC"] self.events += [ pybamm.Event("Minimum surface SoC", z_surf), diff --git a/src/pybamm/models/submodels/equivalent_circuit_elements/ocv_element.py b/src/pybamm/models/submodels/equivalent_circuit_elements/ocv_element.py index 9d1adf3d57..901b63cf74 100644 --- a/src/pybamm/models/submodels/equivalent_circuit_elements/ocv_element.py +++ b/src/pybamm/models/submodels/equivalent_circuit_elements/ocv_element.py @@ -54,7 +54,7 @@ def set_initial_conditions(self, variables): soc = variables["SoC"] self.initial_conditions = {soc: self.param.initial_soc} - def set_events(self, variables): + def add_events_from(self, variables): soc = variables["SoC"] self.events += [ pybamm.Event("Minimum SoC", soc), diff --git a/src/pybamm/models/submodels/equivalent_circuit_elements/voltage_model.py b/src/pybamm/models/submodels/equivalent_circuit_elements/voltage_model.py index 380902fca5..89f8904f32 100644 --- a/src/pybamm/models/submodels/equivalent_circuit_elements/voltage_model.py +++ b/src/pybamm/models/submodels/equivalent_circuit_elements/voltage_model.py @@ -54,7 +54,7 @@ def x_not_zero(x): return variables - def set_events(self, variables): + def add_events_from(self, variables): voltage = variables["Voltage [V]"] # Add voltage events diff --git a/src/pybamm/models/submodels/interface/interface_utilisation/current_driven_utilisation.py b/src/pybamm/models/submodels/interface/interface_utilisation/current_driven_utilisation.py index bbd9af4fb6..e785204882 100644 --- a/src/pybamm/models/submodels/interface/interface_utilisation/current_driven_utilisation.py +++ b/src/pybamm/models/submodels/interface/interface_utilisation/current_driven_utilisation.py @@ -89,7 +89,7 @@ def set_initial_conditions(self, variables): self.initial_conditions = {u: u_init} - def set_events(self, variables): + def add_events_from(self, variables): domain, Domain = self.domain_Domain if self.reaction_loc == "full electrode": diff --git a/src/pybamm/models/submodels/particle_mechanics/crack_propagation.py b/src/pybamm/models/submodels/particle_mechanics/crack_propagation.py index 3bb9ecb7eb..b51f1d1ebd 100644 --- a/src/pybamm/models/submodels/particle_mechanics/crack_propagation.py +++ b/src/pybamm/models/submodels/particle_mechanics/crack_propagation.py @@ -102,7 +102,7 @@ def set_initial_conditions(self, variables): l_cr_0 = pybamm.PrimaryBroadcast(l_cr_0, f"{domain} electrode") self.initial_conditions = {l_cr: l_cr_0} - def set_events(self, variables): + def add_events_from(self, variables): domain, Domain = self.domain_Domain if self.x_average is True: diff --git a/src/pybamm/models/submodels/porosity/constant_porosity.py b/src/pybamm/models/submodels/porosity/constant_porosity.py index 0b9f3c0da4..6d6b93d76f 100644 --- a/src/pybamm/models/submodels/porosity/constant_porosity.py +++ b/src/pybamm/models/submodels/porosity/constant_porosity.py @@ -27,6 +27,6 @@ def get_fundamental_variables(self): return variables - def set_events(self, variables): + def add_events_from(self, variables): # No events since porosity is constant pass diff --git a/src/pybamm/models/submodels/porosity/reaction_driven_porosity.py b/src/pybamm/models/submodels/porosity/reaction_driven_porosity.py index fc69d0f1fd..989c90cd9c 100644 --- a/src/pybamm/models/submodels/porosity/reaction_driven_porosity.py +++ b/src/pybamm/models/submodels/porosity/reaction_driven_porosity.py @@ -64,7 +64,7 @@ def get_coupled_variables(self, variables): return variables - def set_events(self, variables): + def add_events_from(self, variables): eps_p = variables["Positive electrode porosity"] self.events.append( pybamm.Event( diff --git a/src/pybamm/models/submodels/porosity/reaction_driven_porosity_ode.py b/src/pybamm/models/submodels/porosity/reaction_driven_porosity_ode.py index 476845f054..f82a73ae68 100644 --- a/src/pybamm/models/submodels/porosity/reaction_driven_porosity_ode.py +++ b/src/pybamm/models/submodels/porosity/reaction_driven_porosity_ode.py @@ -94,7 +94,7 @@ def set_initial_conditions(self, variables): eps = variables["Porosity"] self.initial_conditions = {eps: self.param.epsilon_init} - def set_events(self, variables): + def add_events_from(self, variables): for domain in self.options.whole_cell_domains: if domain == "separator": continue diff --git a/tests/unit/test_models/test_base_model.py b/tests/unit/test_models/test_base_model.py index 4d5f71201a..d50cd66d2d 100644 --- a/tests/unit/test_models/test_base_model.py +++ b/tests/unit/test_models/test_base_model.py @@ -231,7 +231,7 @@ def set_initial_conditions(self, variables): u = variables["u"] self.initial_conditions = {u: c} - def set_events(self, variables): + def add_events_from(self, variables): e = pybamm.InputParameter("e") u = variables["u"] self.events = [pybamm.Event("u=e", u - e)] @@ -1178,7 +1178,7 @@ def set_initial_conditions(self, variables): v = variables["v"] self.initial_conditions = {u: 0, v: 0} - def set_events(self, variables): + def add_events_from(self, variables): u = variables["u"] self.events.append( pybamm.Event(