Skip to content

Commit

Permalink
Merge pull request #2986 from julian-evers/develop
Browse files Browse the repository at this point in the history
Realign 'count' increment
  • Loading branch information
rtimms authored May 30, 2023
2 parents 57d06db + 4645b66 commit 56b63e9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# [Unreleased](https://github.com/pybamm-team/PyBaMM/)

## Bug fixes

- Realign 'count' increment in CasadiSolver._integrate() ([#2986](https://github.com/pybamm-team/PyBaMM/pull/2986))

## Features

- Enable multithreading in IDAKLU solver ([#2947](https://github.com/pybamm-team/PyBaMM/pull/2947))
Expand Down
3 changes: 2 additions & 1 deletion examples/notebooks/parameterization/parameter-values.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand All @@ -270,7 +271,7 @@
"The toy model used is:\n",
"$$\\frac{\\mathrm{d} u}{\\mathrm{d} t} = -a u$$\n",
"\n",
"with initial conditions $u(0) = b$. The model is first solved with $a = 3, b = 2$, then with $a = 4, b = -1$"
"with initial conditions $u(0) = b$. The model is first solved with $a = 3, b = 2$, then with $a = -1, b = 2$"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions pybamm/solvers/casadi_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,15 @@ def _integrate(self, model, t_eval, inputs_dict=None):
except pybamm.SolverError as error:
pybamm.logger.debug("Failed, halving step size")
dt /= 2
count += 1
# also reduce maximum step size for future global steps,
# but skip them in the beginning
# sometimes, for the first integrator smaller timesteps are
# needed, but this won't affect the global timesteps. The
# global timestep will only be reduced after the first timestep.
if first_ts_solved:
dt_max = dt
if count >= self.max_step_decrease_count:
if count > self.max_step_decrease_count:
message = (
"Maximum number of decreased steps occurred at "
f"t={t} (final SolverError: '{error}'). "
Expand All @@ -287,7 +288,6 @@ def _integrate(self, model, t_eval, inputs_dict=None):
"return the solution object up to the point where "
"failure occured."
)
count += 1
if termination_due_to_small_dt:
break
# Check if the sign of an event changes, if so find an accurate
Expand Down

0 comments on commit 56b63e9

Please sign in to comment.