Skip to content

[Bug]: #5018

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

Open
None2None opened this issue May 16, 2025 · 0 comments
Open

[Bug]: #5018

None2None opened this issue May 16, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@None2None
Copy link

PyBaMM Version

25.4.2

Python Version

Python3.12.7

Describe the bug

Code that works in my pybamm 25.1 version does not work in pybamm 25.4.2, for example:
Image

Image

If pybamm 25.4.2 makes changes to termination, please make the changes in Examples:Custom experiments as well:
Image

Steps to Reproduce

import pybamm
import numpy as np
from scipy.signal import butter, lfilter, savgol_filter
import pandas as pd
import matplotlib.pyplot as plt

定义P2D模型

pybamm.set_logging_level("INFO")
model = pybamm.lithium_ion.DFN(
{
"SEI": "solvent-diffusion limited",
"SEI porosity change": "true",
"lithium plating": "partially reversible",
"lithium plating porosity change": "true",
}
)

定义参数与变量

parameter_values = pybamm.ParameterValues("OKane2022")
parameter_values.update({"Ambient temperature [K]": 298.15}) #定义温度298.15K 283.15 273.15 268.15

#在常规充电电流上叠加一正弦电流作为激励信号对电池进行充电
#值得注意的是,正弦电流被控制在充电电流的10%以内,以确保响应电压保持在10mV附近
#1.定义直流充电电流
C_rate = 0.25
I_dc = parameter_values["Nominal cell capacity [A.h]"] * C_rate
#2.定义扰动电流
AC_amp = 0.1 * I_dc
AC_fre = 1
Sample_rate = 20
Sample_period = 1 / Sample_rate
#3.定义总电流
def current_function(t):
I_total = I_dc + AC_amp * np.sin(2 * np.pi * AC_fre * t)
return -I_total

######划分网格######
var_pts = {
"x_n": 5,
"x_s": 5,
"x_p": 5,
"r_n": 15,
"r_p": 15,
}

######定义终止条件######
def soc_cutoff(variables):
return variables["Discharge capacity [A.h]"] + 4.5

soc_termination = pybamm.step.CustomTermination(name="SOC 90%", event_function=soc_cutoff)
terminations = [soc_termination, "4.3 V"]

######定义实验######
experiment = pybamm.Experiment(
[
pybamm.step.current(
current_function,
period=f"{Sample_period} seconds",
termination=terminations
),
]
)

######求解######
solver = pybamm.CasadiSolver(mode="safe")
sim = pybamm.Simulation(model, parameter_values=parameter_values, experiment=experiment, var_pts=var_pts, solver=solver)
sol = sim.solve(initial_soc=0)

Relevant log output

2025-05-16 20:45:02.214 - [INFO] base_model._build_model(890): Start building Doyle-Fuller-Newman model
2025-05-16 20:45:02.298 - [INFO] base_battery_model.build_model(1083): Finish building Doyle-Fuller-Newman model
Traceback (most recent call last):
  File "D:\post_graduate\Third_article\ThirdArticleModels\DEIS_CMWT.py", line 56, in <module>
    pybamm.step.current(
  File "D:\Anaconda\envs\py312\Lib\site-packages\pybamm\experiment\step\steps.py", line 143, in current
    return Current(value, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Anaconda\envs\py312\Lib\site-packages\pybamm\experiment\step\steps.py", line 133, in __init__
    super().__init__(value, **kwargs)
  File "D:\Anaconda\envs\py312\Lib\site-packages\pybamm\experiment\step\base_step.py", line 449, in __init__
    super().__init__(*args, **kwargs)
  File "D:\Anaconda\envs\py312\Lib\site-packages\pybamm\experiment\step\base_step.py", line 177, in __init__
    operator, typ, val = _parse_termination(term, self.value)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Anaconda\envs\py312\Lib\site-packages\pybamm\experiment\step\base_step.py", line 606, in _parse_termination
    raise ValueError(
ValueError: Termination must include an operator when using InputParameter.
@None2None None2None added the bug Something isn't working label May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant