Skip to content

Commit 5d62c23

Browse files
committed
#738 check model option
1 parent 68539d3 commit 5d62c23

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

pybamm/discretisations/discretisation.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def bcs(self, value):
8282
# reset discretised_symbols
8383
self._discretised_symbols = {}
8484

85-
def process_model(self, model, inplace=True):
85+
def process_model(self, model, inplace=True, check_model=True):
8686
"""Discretise a model.
8787
Currently inplace, could be changed to return a new model.
8888
@@ -91,9 +91,15 @@ def process_model(self, model, inplace=True):
9191
model : :class:`pybamm.BaseModel`
9292
Model to dicretise. Must have attributes rhs, initial_conditions and
9393
boundary_conditions (all dicts of {variable: equation})
94-
inplace: bool, optional
94+
inplace : bool, optional
9595
If True, discretise the model in place. Otherwise, return a new
9696
discretised model. Default is True.
97+
check_model : bool, optional
98+
If True, model checks are performed after discretisation. For large
99+
systems these checks can be slow, so can be skipped by setting this
100+
option to False. When developing, testing or debugging it is recommened
101+
to leave this option as True as it may help to identify any errors.
102+
Default is True.
97103
98104
Returns
99105
-------
@@ -173,7 +179,9 @@ def process_model(self, model, inplace=True):
173179
model_disc.mass_matrix = self.create_mass_matrix(model_disc)
174180

175181
# Check that resulting model makes sense
176-
self.check_model(model_disc)
182+
if check_model:
183+
pybamm.logger.info("Performing model checks for {}".format(model.name))
184+
self.check_model(model_disc)
177185

178186
pybamm.logger.info("Finish discretising {}".format(model.name))
179187

tests/unit/test_discretisations/test_discretisation.py

+17
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,23 @@ def test_check_tab_bcs_error(self):
852852
with self.assertRaisesRegex(pybamm.ModelError, "Boundary conditions"):
853853
disc.check_tab_conditions(b, bcs)
854854

855+
def test_process_with_no_check(self):
856+
# create model
857+
whole_cell = ["negative electrode", "separator", "positive electrode"]
858+
c = pybamm.Variable("c", domain=whole_cell)
859+
N = pybamm.grad(c)
860+
model = pybamm.BaseModel()
861+
model.rhs = {c: pybamm.div(N)}
862+
model.initial_conditions = {c: pybamm.Scalar(3)}
863+
model.boundary_conditions = {
864+
c: {"left": (0, "Neumann"), "right": (0, "Neumann")}
865+
}
866+
model.variables = {"c": c, "N": N}
867+
868+
# create discretisation
869+
disc = get_discretisation_for_testing()
870+
disc.process_model(model, check_model=False)
871+
855872

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

0 commit comments

Comments
 (0)