Skip to content

Commit

Permalink
Merge pull request #1850 from pybamm-team/issue-1842-esoh-fails-drive…
Browse files Browse the repository at this point in the history
…-cycle

Fix bug simulations with drive cycle and initial_soc
  • Loading branch information
brosaplanella committed Dec 9, 2021
2 parents 5a03208 + 0e054a4 commit e23cd18
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

## Features

- Experiments can be set to terminate when a voltage is reached (across all steps) ([#1832](https://github.com/pybamm-team/PyBaMM/pull/1832))
- Added cylindrical geometry and finite volume method ([#1824](https://github.com/pybamm-team/PyBaMM/pull/1824))

## Bug fixes

- Experiments can be set to terminate when a voltage is reached (across all steps) ([#1832](https://github.com/pybamm-team/PyBaMM/pull/1832))
- Simulations with drive cycles now support `initial_soc` ([#1842](https://github.com/pybamm-team/PyBaMM/pull/1842))
- Fixed bug in expression tree simplification ([#1831](https://github.com/pybamm-team/PyBaMM/pull/1831))
- Solid tortuosity is now correctly calculated with Bruggeman coefficient of the respective electrode ([#1773](https://github.com/pybamm-team/PyBaMM/pull/1773))

Expand Down
4 changes: 3 additions & 1 deletion pybamm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,9 @@ def solve(
raise ValueError(
"starting_solution can only be provided if simulating an Experiment"
)
if self.operating_mode == "without experiment":
if self.operating_mode == "without experiment" or isinstance(
self.model, pybamm.lithium_ion.ElectrodeSOH
):
if t_eval is None:
raise pybamm.SolverError(
"'t_eval' must be provided if not using an experiment or "
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,21 @@ def test_solve_with_initial_soc(self):
sim.solve(initial_soc=0.8)
self.assertEqual(sim._built_initial_soc, 0.8)

# test with drive cycle
drive_cycle = pd.read_csv(
os.path.join("pybamm", "input", "drive_cycles", "US06.csv"),
comment="#",
header=None
).to_numpy()
timescale = param.evaluate(model.timescale)
current_interpolant = pybamm.Interpolant(
drive_cycle[:, 0], drive_cycle[:, 1], timescale * pybamm.t
)
param["Current function [A]"] = current_interpolant
sim = pybamm.Simulation(model, parameter_values=param)
sim.solve(initial_soc=0.8)
self.assertEqual(sim._built_initial_soc, 0.8)

def test_solve_with_inputs(self):
model = pybamm.lithium_ion.SPM()
param = model.default_parameter_values
Expand Down

0 comments on commit e23cd18

Please sign in to comment.