Skip to content

Commit bc32883

Browse files
committed
#858 improve coverage
1 parent d8808a6 commit bc32883

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

pybamm/models/base_model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,11 @@ def check_well_posedness(self, post_discretisation=False):
381381
post_discretisation : boolean
382382
A flag indicating tests to be skipped after discretisation
383383
"""
384+
self.check_for_time_derivatives()
384385
self.check_well_determined(post_discretisation)
385386
self.check_algebraic_equations(post_discretisation)
386387
self.check_ics_bcs()
387388
self.check_default_variables_dictionaries()
388-
self.check_for_time_derivatives()
389389
# Can't check variables after discretising, since Variable objects get replaced
390390
# by StateVector objects
391391
# Checking variables is slow, so only do it in debug mode

tests/unit/test_models/test_base_model.py

+55
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,61 @@ def test_check_well_posedness_variables(self):
248248
):
249249
model.check_well_posedness(post_discretisation=True)
250250

251+
# model must be in semi-explicit form
252+
model = pybamm.BaseModel()
253+
model.rhs = {c: d.diff(pybamm.t), d: -1}
254+
model.initial_conditions = {c: 1, d: 1}
255+
with self.assertRaisesRegex(
256+
pybamm.ModelError,
257+
"time derivative of variable found",
258+
):
259+
model.check_well_posedness()
260+
261+
# model must be in semi-explicit form
262+
model = pybamm.BaseModel()
263+
model.algebraic = {
264+
c: 2 * d - c,
265+
d: c * d.diff(pybamm.t) - d,
266+
}
267+
model.initial_conditions = {c: 1, d: 1}
268+
with self.assertRaisesRegex(
269+
pybamm.ModelError,
270+
"time derivative of variable found",
271+
):
272+
model.check_well_posedness()
273+
274+
# model must be in semi-explicit form
275+
model = pybamm.BaseModel()
276+
model.rhs = {c: d.diff(pybamm.t), d: -1}
277+
model.initial_conditions = {c: 1, d: 1}
278+
with self.assertRaisesRegex(
279+
pybamm.ModelError,
280+
"time derivative of variable found",
281+
):
282+
model.check_well_posedness()
283+
284+
# model must be in semi-explicit form
285+
model = pybamm.BaseModel()
286+
model.algebraic = {
287+
d: 5 * pybamm.StateVector(slice(0, 15)) - 1,
288+
c: 5 * pybamm.StateVectorDot(slice(0, 15)) - 1
289+
}
290+
with self.assertRaisesRegex(
291+
pybamm.ModelError,
292+
"time derivative of state vector found",
293+
):
294+
model.check_well_posedness(post_discretisation=True)
295+
296+
# model must be in semi-explicit form
297+
model = pybamm.BaseModel()
298+
model.rhs = {c: 5 * pybamm.StateVectorDot(slice(0, 15)) - 1}
299+
model.initial_conditions = {c: 1}
300+
with self.assertRaisesRegex(
301+
pybamm.ModelError,
302+
"time derivative of state vector found",
303+
):
304+
model.check_well_posedness(post_discretisation=True)
305+
251306
def test_check_well_posedness_initial_boundary_conditions(self):
252307
# Well-posed model - Dirichlet
253308
whole_cell = ["negative electrode", "separator", "positive electrode"]

0 commit comments

Comments
 (0)