Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug simulations with drive cycle and initial_soc #1850

Merged
merged 3 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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