From 001e46c237775262e1eb315a45d6a669c9d0b84e Mon Sep 17 00:00:00 2001 From: medha-14 Date: Fri, 6 Sep 2024 21:06:19 +0530 Subject: [PATCH 1/5] changed set_events to add_events_from --- src/pybamm/models/base_model.py | 2 +- src/pybamm/models/full_battery_models/base_battery_model.py | 2 +- src/pybamm/models/submodels/base_submodel.py | 2 +- .../submodels/electrolyte_diffusion/constant_concentration.py | 2 +- .../equivalent_circuit_elements/diffusion_element.py | 2 +- .../submodels/equivalent_circuit_elements/ocv_element.py | 2 +- .../submodels/equivalent_circuit_elements/voltage_model.py | 2 +- .../interface_utilisation/current_driven_utilisation.py | 2 +- .../models/submodels/particle_mechanics/crack_propagation.py | 2 +- src/pybamm/models/submodels/porosity/constant_porosity.py | 2 +- .../models/submodels/porosity/reaction_driven_porosity_ode.py | 2 +- tests/unit/test_models/test_base_model.py | 4 ++-- 12 files changed, 13 insertions(+), 13 deletions(-) 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_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( From 9687f8cec8b749a016effde4965239c0b0a6d462 Mon Sep 17 00:00:00 2001 From: medha-14 Date: Fri, 6 Sep 2024 23:04:53 +0530 Subject: [PATCH 2/5] all changes made --- .../models/submodels/porosity/reaction_driven_porosity.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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( From 76893666ab4d6d23e890b17fc3eec6ab14e90b3c Mon Sep 17 00:00:00 2001 From: medha-14 Date: Fri, 6 Sep 2024 23:20:57 +0530 Subject: [PATCH 3/5] changelog added --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5203229bd3..d7cbbc0c01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ `have_iree` with `has_iree` ([#4398](https://github.com/pybamm-team/PyBaMM/pull/4398)) - Remove deprecated function `pybamm_install_jax` ([#4362](https://github.com/pybamm-team/PyBaMM/pull/4362)) - Removed legacy python-IDAKLU solver. ([#4326](https://github.com/pybamm-team/PyBaMM/pull/4326)) +- Renamed `set_events` function to `add_events_from` to better reflect its purpose. This may require updating calls to set_events in your codebase. ([#4421](https://github.com/pybamm-team/PyBaMM/pull/4421)) # [v24.5](https://github.com/pybamm-team/PyBaMM/tree/v24.5) - 2024-07-26 From b9d9d7a29a01077bdecde3ed35ed143790d890c0 Mon Sep 17 00:00:00 2001 From: medha-14 Date: Fri, 6 Sep 2024 23:33:22 +0530 Subject: [PATCH 4/5] changelog updated --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7cbbc0c01..4ea2615382 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ `have_iree` with `has_iree` ([#4398](https://github.com/pybamm-team/PyBaMM/pull/4398)) - Remove deprecated function `pybamm_install_jax` ([#4362](https://github.com/pybamm-team/PyBaMM/pull/4362)) - Removed legacy python-IDAKLU solver. ([#4326](https://github.com/pybamm-team/PyBaMM/pull/4326)) -- Renamed `set_events` function to `add_events_from` to better reflect its purpose. This may require updating calls to set_events in your codebase. ([#4421](https://github.com/pybamm-team/PyBaMM/pull/4421)) +- Renamed `set_events` function to `add_events_from` to better reflect its purpose. ([#4421](https://github.com/pybamm-team/PyBaMM/pull/4421)) # [v24.5](https://github.com/pybamm-team/PyBaMM/tree/v24.5) - 2024-07-26 From 4f72bcd9ab8bbf93d9fb679dc5c3e84a9d0ca831 Mon Sep 17 00:00:00 2001 From: medha-14 Date: Fri, 6 Sep 2024 23:42:54 +0530 Subject: [PATCH 5/5] corrected changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4ea2615382..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 @@ -29,7 +32,6 @@ `have_iree` with `has_iree` ([#4398](https://github.com/pybamm-team/PyBaMM/pull/4398)) - Remove deprecated function `pybamm_install_jax` ([#4362](https://github.com/pybamm-team/PyBaMM/pull/4362)) - Removed legacy python-IDAKLU solver. ([#4326](https://github.com/pybamm-team/PyBaMM/pull/4326)) -- Renamed `set_events` function to `add_events_from` to better reflect its purpose. ([#4421](https://github.com/pybamm-team/PyBaMM/pull/4421)) # [v24.5](https://github.com/pybamm-team/PyBaMM/tree/v24.5) - 2024-07-26