Skip to content

Commit

Permalink
#2304 BaseSolver.models_set_up -> BaseSolver._model_set_up
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed Dec 9, 2022
1 parent 319c186 commit 470e123
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions pybamm/solvers/base_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(
self.root_tol = root_tol
self.root_method = root_method
self.extrap_tol = extrap_tol or -1e-10
self.models_set_up = {}
self._model_set_up = {}

# Defaults, can be overwritten by specific solver
self.name = "Base solver"
Expand Down Expand Up @@ -86,8 +86,8 @@ def root_method(self, method):
def copy(self):
"""Returns a copy of the solver"""
new_solver = copy.copy(self)
# clear models_set_up
new_solver.models_set_up = {}
# clear _model_set_up
new_solver._model_set_up = {}
return new_solver

def set_up(self, model, inputs=None, t_eval=None, ics_only=False):
Expand Down Expand Up @@ -774,7 +774,7 @@ def solve(
model.calculate_sensitivities = []
model.calculate_sensitivities.sort()
if calculate_sensitivities_list != model.calculate_sensitivities:
self.models_set_up.pop(model, None)
self._model_set_up.pop(model, None)
# CasadiSolver caches its integrators using model, so delete this too
if isinstance(self, pybamm.CasadiSolver):
self.integrators.pop(model, None)
Expand All @@ -785,9 +785,9 @@ def solve(

# Set up (if not done already)
timer = pybamm.Timer()
if model not in self.models_set_up:
if len(self.models_set_up) > 0:
existing_model = next(iter(self.models_set_up))
if model not in self._model_set_up:
if len(self._model_set_up) > 0:
existing_model = next(iter(self._model_set_up))
raise RuntimeError(
"This solver has already been initialised for model "
f'"{existing_model.name}". Please create a separate '
Expand All @@ -799,11 +799,11 @@ def solve(
# is passed to `set_up`.
# See https://github.com/pybamm-team/PyBaMM/pull/1261
self.set_up(model, ext_and_inputs_list[0], t_eval)
self.models_set_up.update(
self._model_set_up.update(
{model: {"initial conditions": model.concatenated_initial_conditions}}
)
else:
ics_set_up = self.models_set_up[model]["initial conditions"]
ics_set_up = self._model_set_up[model]["initial conditions"]
# Check that initial conditions have not been updated
if ics_set_up != model.concatenated_initial_conditions:
if self.algebraic_solver is True:
Expand All @@ -815,7 +815,7 @@ def solve(
# If the new initial conditions are different
# and cannot be evaluated directly, set up again
self.set_up(model, ext_and_inputs_list[0], t_eval, ics_only=True)
self.models_set_up[model][
self._model_set_up[model][
"initial conditions"
] = model.concatenated_initial_conditions

Expand Down Expand Up @@ -1148,17 +1148,17 @@ def step(
t = old_solution.t[-1]

first_step_this_model = False
if model not in self.models_set_up:
if model not in self._model_set_up:
first_step_this_model = True
if len(self.models_set_up) > 0:
existing_model = next(iter(self.models_set_up))
if len(self._model_set_up) > 0:
existing_model = next(iter(self._model_set_up))
raise RuntimeError(
"This solver has already been initialised for model "
f'"{existing_model.name}". Please create a separate '
"solver for this model"
)
self.set_up(model, ext_and_inputs)
self.models_set_up.update(
self._model_set_up.update(
{model: {"initial conditions": model.concatenated_initial_conditions}}
)

Expand Down

0 comments on commit 470e123

Please sign in to comment.