Skip to content

Commit

Permalink
#858 improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Mar 18, 2020
1 parent d8808a6 commit bc32883
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pybamm/models/base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,11 @@ def check_well_posedness(self, post_discretisation=False):
post_discretisation : boolean
A flag indicating tests to be skipped after discretisation
"""
self.check_for_time_derivatives()
self.check_well_determined(post_discretisation)
self.check_algebraic_equations(post_discretisation)
self.check_ics_bcs()
self.check_default_variables_dictionaries()
self.check_for_time_derivatives()
# Can't check variables after discretising, since Variable objects get replaced
# by StateVector objects
# Checking variables is slow, so only do it in debug mode
Expand Down
55 changes: 55 additions & 0 deletions tests/unit/test_models/test_base_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,61 @@ def test_check_well_posedness_variables(self):
):
model.check_well_posedness(post_discretisation=True)

# model must be in semi-explicit form
model = pybamm.BaseModel()
model.rhs = {c: d.diff(pybamm.t), d: -1}
model.initial_conditions = {c: 1, d: 1}
with self.assertRaisesRegex(
pybamm.ModelError,
"time derivative of variable found",
):
model.check_well_posedness()

# model must be in semi-explicit form
model = pybamm.BaseModel()
model.algebraic = {
c: 2 * d - c,
d: c * d.diff(pybamm.t) - d,
}
model.initial_conditions = {c: 1, d: 1}
with self.assertRaisesRegex(
pybamm.ModelError,
"time derivative of variable found",
):
model.check_well_posedness()

# model must be in semi-explicit form
model = pybamm.BaseModel()
model.rhs = {c: d.diff(pybamm.t), d: -1}
model.initial_conditions = {c: 1, d: 1}
with self.assertRaisesRegex(
pybamm.ModelError,
"time derivative of variable found",
):
model.check_well_posedness()

# model must be in semi-explicit form
model = pybamm.BaseModel()
model.algebraic = {
d: 5 * pybamm.StateVector(slice(0, 15)) - 1,
c: 5 * pybamm.StateVectorDot(slice(0, 15)) - 1
}
with self.assertRaisesRegex(
pybamm.ModelError,
"time derivative of state vector found",
):
model.check_well_posedness(post_discretisation=True)

# model must be in semi-explicit form
model = pybamm.BaseModel()
model.rhs = {c: 5 * pybamm.StateVectorDot(slice(0, 15)) - 1}
model.initial_conditions = {c: 1}
with self.assertRaisesRegex(
pybamm.ModelError,
"time derivative of state vector found",
):
model.check_well_posedness(post_discretisation=True)

def test_check_well_posedness_initial_boundary_conditions(self):
# Well-posed model - Dirichlet
whole_cell = ["negative electrode", "separator", "positive electrode"]
Expand Down

0 comments on commit bc32883

Please sign in to comment.