PyBaMM
PyBaMM copied to clipboard
[Bug]: Interpolator seems to get stuck on small time steps
PyBaMM Version
Latest
Python Version
3.10 +
Describe the bug
The car_current time series has gaps of 0.001 s between some steps. This seems to trip up the solver. Making these steps bigger fixes the issue as a work around but maybe some checks should be put in place on steps from time-series
Steps to Reproduce
import pybamm
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.close("all")
car_current = pd.read_csv("C:\\Code\\PyBaMM\\pybamm\\input\\drive_cycles\\car_current.csv", header=[0, 1], on_bad_lines='skip', delimiter=",").to_numpy()
drive = np.array([
[ 0.00000e+00, 1.00000e+00],
[ 5.00000e+01, 1.00000e+00],
[ 5.10000e+01, -5.00000e-01],
[ 6.00000e+01, -5.00000e-01],
[ 6.10000e+01, 5.00000e-01],
[ 2.10000e+02, 5.00000e-01],
[ 2.11000e+02, 1.00000e+00],
[ 4.10000e+02, 1.00000e+00],
[ 4.11000e+02, 2.00000e+00],
[ 4.15000e+02, 2.00000e+00],
[ 4.16000e+02, 1.25000e+00],
[ 6.15000e+02, 1.25000e+00],
[ 6.16000e+02, -5.00000e-01],
[ 3.60000e+03, -5.00000e-01]]
)
plt.figure()
plt.plot(car_current[:, 0], car_current[:, 1])
plt.plot(drive[:, 0], drive[:, 1])
step = pybamm.step.current(value=drive, termination="3 V", period="1s", duration="5 minutes")
experiment = pybamm.Experiment([step])
model = pybamm.lithium_ion.SPM()
param_vals = pybamm.ParameterValues("Chen2020")
sim = pybamm.Simulation(model=model, experiment=experiment, parameter_values=param_vals)
sim.solve(initial_soc=0.5)
sim.plot()
Relevant log output
No response
Is this just with the CasadiSolver? And does it help to set the max step size? solver = pybamm.CasadiSolver(extra_options_setup={"max_step_size": dt}) (will slow it down).