Skip to content

Commit

Permalink
#4018 check indepedent vars in events (#4019)
Browse files Browse the repository at this point in the history
* #4018 check indepedent vars in events

* #4018 changelog
  • Loading branch information
rtimms committed Apr 17, 2024
1 parent b0bc5cf commit 51c4120
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

## Bug Fixes

- Fixed a bug where independent variables were removed from models even if they appeared in events ([#4019](https://github.com/pybamm-team/PyBaMM/pull/4019))
- Fix bug with upwind and downwind schemes producing the wrong discretised system ([#3979](https://github.com/pybamm-team/PyBaMM/pull/3979))
- Allow evaluation of an `Interpolant` object with a number ([#3932](https://github.com/pybamm-team/PyBaMM/pull/3932))
- `plot_voltage_components` now works even if the time does not start at 0 ([#3915](https://github.com/pybamm-team/PyBaMM/pull/3915))
Expand Down
1 change: 1 addition & 0 deletions pybamm/discretisations/discretisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,7 @@ def remove_independent_variables_from_rhs(self, model):
# only check children of variables, this will skip the variable itself
# and catch any other cases
+ [child for var in model.variables.values() for child in var.children]
+ [event.expression for event in model.events]
)
all_vars_in_eqns = unpacker.unpack_list_of_symbols(eqns_to_check)
all_vars_in_eqns = [var.name for var in all_vars_in_eqns]
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/test_discretisations/test_discretisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,22 @@ def test_independent_rhs(self):
disc.process_model(model)
self.assertEqual(len(model.rhs), 2)

def test_independent_rhs_with_event(self):
a = pybamm.Variable("a")
b = pybamm.Variable("b")
c = pybamm.Variable("c")
model = pybamm.BaseModel()
model.rhs = {a: b, b: c, c: -c}
model.initial_conditions = {
a: pybamm.Scalar(0),
b: pybamm.Scalar(1),
c: pybamm.Scalar(1),
}
model.events = [pybamm.Event("a=1", a - 1)]
disc = pybamm.Discretisation()
disc.process_model(model)
self.assertEqual(len(model.rhs), 3)


if __name__ == "__main__":
print("Add -v for more debug output")
Expand Down

0 comments on commit 51c4120

Please sign in to comment.