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

Added more information to error when drive cycle starts at t>0 #3756

Merged
merged 10 commits into from
Jan 24, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Bug Fixes

- updated `_steps_util.py` to throw a specific exception when drive cycle starts at t>0
kratman marked this conversation as resolved.
Show resolved Hide resolved
- Updated `plot_voltage_components.py` to support both `Simulation` and `Solution` objects. Added new methods in both `Simulation` and `Solution` classes for allow the syntax `simulation.plot_voltage_components` and `solution.plot_voltage_components`. Updated `test_plot_voltage_components.py` to reflect these changes ([#3723](https://github.com/pybamm-team/PyBaMM/pull/3723)).
- The SEI thickness decreased at some intervals when the 'electron-migration limited' model was used. It has been corrected ([#3622](https://github.com/pybamm-team/PyBaMM/pull/3622))

Expand Down
2 changes: 1 addition & 1 deletion docs/source/api/experiment/experiment_steps.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Experiment step functions
=========================

The following functions can be used to define steps in an experiment.
The following functions can be used to define steps in an experiment. Note that the drive cycle must start at t=0

.. autofunction:: pybamm.step.string

Expand Down
9 changes: 8 additions & 1 deletion pybamm/experiment/step/_steps_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,15 @@ def __init__(
t, y = value[:, 0], value[:, 1]
self.duration = t.max()

# Check that drive cycle starts at t=0
if t[0] > 0:
raise ValueError("Drive cycle must start at t=0")

self.value = pybamm.Interpolant(
t, y, pybamm.t - pybamm.InputParameter("start time")
t,
y,
pybamm.t - pybamm.InputParameter("start time"),
name="Drive Cycle",
)
self.period = np.diff(t).min()
else:
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_experiments/test_experiment_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import unittest
import numpy as np
from datetime import datetime
from pybamm.experiment.step import _Step


class TestExperimentSteps(unittest.TestCase):
Expand Down Expand Up @@ -276,6 +277,13 @@ def neg_stoich_cutoff(variables):
self.assertEqual(event.name, "Negative stoichiometry cut-off [experiment]")
self.assertEqual(event.expression, 2)

def test_drive_cycle_start_time(self):
# An example where start_time t>0
t = np.array([[1, 1], [2, 2], [3, 3]])

with self.assertRaisesRegex(ValueError, "Drive cycle must start at t=0"):
_Step("current", t)


if __name__ == "__main__":
print("Add -v for more debug output")
Expand Down
Loading