Skip to content

Commit

Permalink
#835 move 'save' functionality to the solver
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Feb 19, 2020
1 parent 099915a commit f5b0ae7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
28 changes: 9 additions & 19 deletions pybamm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,25 +471,15 @@ def step(
if solver is None:
solver = self.solver

if save is False:
# Don't pass previous solution
self._solution = solver.step(
None,
self.built_model,
dt,
npts=npts,
external_variables=external_variables,
inputs=inputs,
)
else:
self._solution = solver.step(
self._solution,
self.built_model,
dt,
npts=npts,
external_variables=external_variables,
inputs=inputs,
)
self._solution = solver.step(
self._solution,
self.built_model,
dt,
npts=npts,
external_variables=external_variables,
inputs=inputs,
save=save,
)

def get_variable_array(self, *variables):
"""
Expand Down
14 changes: 11 additions & 3 deletions pybamm/solvers/base_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,14 @@ def solve(self, model, t_eval, external_variables=None, inputs=None):
return solution

def step(
self, old_solution, model, dt, npts=2, external_variables=None, inputs=None
self,
old_solution,
model,
dt,
npts=2,
external_variables=None,
inputs=None,
save=True,
):
"""
Step the solution of the model forward by a given time increment. The
Expand All @@ -599,7 +606,8 @@ def step(
values at the current time
inputs : dict, optional
Any input parameters to pass to the model when solving
save : bool
Turn on to store the solution of all previous timesteps
Raises
------
Expand Down Expand Up @@ -677,7 +685,7 @@ def step(
pybamm.logger.debug(
"Step time: {}".format(timer.format(solution.solve_time))
)
if old_solution is None:
if save is False or old_solution is None:
return solution
else:
return old_solution + solution
Expand Down

0 comments on commit f5b0ae7

Please sign in to comment.