Skip to content

Commit

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

* pybamm-team#4018 changelog
  • Loading branch information
rtimms authored and js1tr3 committed Aug 12, 2024
1 parent 2515e77 commit 5d5e34a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions pybamm/discretisations/discretisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,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 @@ -1224,6 +1224,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 5d5e34a

Please sign in to comment.