Skip to content

Commit

Permalink
Merge pull request #3756 from R-Yash/fix-3612
Browse files Browse the repository at this point in the history
Added more information to error when drive cycle starts at t>0
  • Loading branch information
arjxn-py authored Jan 24, 2024
2 parents 0ac01eb + c13f153 commit c93570f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
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 ([#3756](https://github.com/pybamm-team/PyBaMM/pull/3756))
- 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

0 comments on commit c93570f

Please sign in to comment.