Skip to content

Commit

Permalink
#963 add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Apr 17, 2020
1 parent 3834a3e commit 18895f1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pybamm/discretisations/discretisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ def process_model(self, model, inplace=True, check_model=True):
`model.variables = {}`)
"""
if model.is_discretised is True:
raise pybamm.ModelError(
"Cannot re-discretise a model. "
"Set 'inplace=False' when first discretising a model to then be able "
"to discretise it more times (e.g. for convergence studies)."
)

pybamm.logger.info("Start discretising {}".format(model.name))

Expand Down
10 changes: 6 additions & 4 deletions tests/unit/test_discretisations/test_discretisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,9 +601,10 @@ def test_process_model_ode(self):

combined_submesh = mesh.combine_submeshes(*whole_cell)
disc.process_model(model)
# Processing twice should work
disc = get_discretisation_for_testing()
disc.process_model(model)

# We cannot re-discretise after discretising a first time
with self.assertRaisesRegex(pybamm.ModelError, "Cannot re-discretise a model"):
disc.process_model(model)

y0 = model.concatenated_initial_conditions.evaluate()
np.testing.assert_array_equal(
Expand Down Expand Up @@ -765,6 +766,7 @@ def test_process_model_dae(self):
mesh = disc.mesh

disc.process_model(model)

combined_submesh = mesh.combine_submeshes(*whole_cell)

y0 = model.concatenated_initial_conditions.evaluate()
Expand Down Expand Up @@ -1119,7 +1121,7 @@ def test_exceptions(self):

# check doesn't raise if concatenation
model.variables = {c_n.name: pybamm.Concatenation(c_n, c_s)}
disc.process_model(model)
disc.process_model(model, inplace=False)

# check doesn't raise if broadcast
model.variables = {
Expand Down

0 comments on commit 18895f1

Please sign in to comment.