PyBaMM
PyBaMM copied to clipboard
[Bug]: IDA_CONV_FAIL
PyBaMM Version
23.9
Python Version
3.9
Describe the bug
2023-12-19 17:07:05.545 - [INFO] base_model._build_model(550): Start building Doyle-Fuller-Newman model
2023-12-19 17:07:05.739 - [INFO] base_battery_model.build_model(1047): Finish building Doyle-Fuller-Newman model
2023-12-19 17:07:05.770 - [INFO] base_model._build_model(550): Start building Single Particle Model with electrolyte
2023-12-19 17:07:05.889 - [INFO] base_battery_model.build_model(1047): Finish building Single Particle Model with electrolyte
2023-12-19 17:07:05.904 - [INFO] parameter_values.process_model(398): Start setting parameters for Doyle-Fuller-Newman model
2023-12-19 17:07:06.085 - [INFO] parameter_values.process_model(479): Finish setting parameters for Doyle-Fuller-Newman model
2023-12-19 17:07:06.085 - [INFO] parameter_values.process_model(398): Start setting parameters for Single Particle Model with electrolyte
2023-12-19 17:07:06.304 - [INFO] parameter_values.process_model(479): Finish setting parameters for Single Particle Model with electrolyte
2023-12-19 17:07:06.304 - [INFO] discretisation.process_model(147): Start discretising Doyle-Fuller-Newman model
2023-12-19 17:07:06.320 - [INFO] discretisation.remove_independent_variables_from_rhs(1134): removing variable Discharge capacity [A.h] from rhs
2023-12-19 17:07:06.320 - [INFO] discretisation.remove_independent_variables_from_rhs(1134): removing variable Throughput capacity [A.h] from rhs
2023-12-19 17:07:07.040 - [INFO] discretisation.process_model(253): Finish discretising Doyle-Fuller-Newman model
2023-12-19 17:07:07.040 - [INFO] discretisation.process_model(147): Start discretising Single Particle Model with electrolyte
2023-12-19 17:07:07.055 - [INFO] discretisation.remove_independent_variables_from_rhs(1134): removing variable Discharge capacity [A.h] from rhs
2023-12-19 17:07:07.055 - [INFO] discretisation.remove_independent_variables_from_rhs(1134): removing variable Throughput capacity [A.h] from rhs
2023-12-19 17:07:07.586 - [INFO] discretisation.process_model(253): Finish discretising Single Particle Model with electrolyte
2023-12-19 17:07:07.586 - [INFO] base_solver.solve(751): Start solving Doyle-Fuller-Newman model with CasADi solver with 'fast' mode
2023-12-19 17:07:07.586 - [INFO] base_solver.set_up(117): Start solver set-up
2023-12-19 17:07:07.931 - [INFO] base_solver.set_up(286): Finish solver set-up
At t = 3133.8 and h = 1.15464e-15, the corrector convergence failed repeatedly or with |h| = hmin.
Traceback (most recent call last):
File "E:\Anaconda3\envs\DDPG-EMS\lib\site-packages\pybamm\solvers\casadi_solver.py", line 681, in _run_integrator
casadi_sol = integrator(
File "E:\Anaconda3\envs\DDPG-EMS\lib\site-packages\casadi\casadi.py", line 23390, in __call__
return self.call(kwargs)
File "E:\Anaconda3\envs\DDPG-EMS\lib\site-packages\casadi\casadi.py", line 20039, in call
return _casadi.Function_call(self, *args)
RuntimeError: Error in Function::call for 'F' [IdasInterface] at .../casadi/core/function.cpp:1401:
Error in Function::call for 'F' [IdasInterface] at .../casadi/core/function.cpp:330:
.../casadi/interfaces/sundials/idas_interface.cpp:596: IDASolve returned "IDA_CONV_FAIL". Consult IDAS documentation.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:\Anaconda3\envs\DDPG-EMS\lib\site-packages\pybamm\solvers\casadi_solver.py", line 687, in _run_integrator
raise pybamm.SolverError(error.args[0])
pybamm.expression_tree.exceptions.SolverError: Error in Function::call for 'F' [IdasInterface] at .../casadi/core/function.cpp:1401:
Error in Function::call for 'F' [IdasInterface] at .../casadi/core/function.cpp:330:
.../casadi/interfaces/sundials/idas_interface.cpp:596: IDASolve returned "IDA_CONV_FAIL". Consult IDAS documentation.
Process finished with exit code 1
Steps to Reproduce
import numpy as np
import pybamm
# C_rate
C_rates = {"01": 0.1, "05": 0.5, "1": 1, "2": 2, "3": 3}
C_rate = "1" # choose the key from the above dictionary of available results
# load model and geometry
pybamm.set_logging_level("INFO")
pybamm_DFN = pybamm.lithium_ion.DFN()
pybamm_SPMe = pybamm.lithium_ion.SPMe()
param_DFN = pybamm.ParameterValues('Prada2013')
param_SPMe = pybamm.ParameterValues('Prada2013')
geometry_DFN = pybamm_DFN.default_geometry
geometry_SPMe = pybamm_SPMe.default_geometry
param_DFN.process_model(pybamm_DFN)
param_DFN.process_geometry(geometry_DFN)
param_SPMe.process_model(pybamm_SPMe)
param_SPMe.process_geometry(geometry_SPMe)
# create mesh
var_pts = {"x_n": 31, "x_s": 11, "x_p": 31, "r_n": 11, "r_p": 11}
mesh_DFN = pybamm.Mesh(geometry_DFN, pybamm_DFN.default_submesh_types, var_pts)
mesh_SPMe = pybamm.Mesh(geometry_SPMe, pybamm_SPMe.default_submesh_types, var_pts)
# discretise model
disc_DFN = pybamm.Discretisation(mesh_DFN, pybamm_DFN.default_spatial_methods)
disc_DFN.process_model(pybamm_DFN)
disc_SPMe = pybamm.Discretisation(mesh_SPMe, pybamm_SPMe.default_spatial_methods)
disc_SPMe.process_model(pybamm_SPMe)
# solve model
time = np.arange(0,3600,100)
pybamm_solution_DFN = pybamm.CasadiSolver(mode="fast").solve(pybamm_DFN, time)
pybamm_solution_SPMe = pybamm.CasadiSolver(mode="fast").solve(pybamm_SPMe, time)
# plot
output_variables = [
"Negative particle surface concentration [mol.m-3]",
"Electrolyte concentration [mol.m-3]",
"Positive particle surface concentration [mol.m-3]",
"Current [A]",
"Negative electrode potential [V]",
"Electrolyte potential [V]",
"Positive electrode potential [V]",
"Voltage [V]",
]
plot = pybamm.QuickPlot(
[pybamm_solution_DFN, pybamm_solution_SPMe],
output_variables=output_variables,
labels=["PyBaMM_DFN","Pybamm_SPMe"],
)
plot.dynamic_plot()
Hi @Mrzhang-hub, switching the solver mode from "fast" to "safe" works for me and gives me the desired plot – does that resolve your issue?
@agriyakhetarpal Yes, changing the mode works. But when I use my own parameter set. It still give this error(But SPMe works). I wanna know why this error happens and how to fix it from the root.
@Mrzhang-hub It is not always easy to dig into why the solver failed especially when you are using your own parameter set.
Things you could also try for the solver:
- Changing the number grid points
- Changing the size of the time step
If multiple existing pybamm parameter sets are working then it can also be good to check your custom parameters.
Things for your parameter set:
- Checking the functions in your parameter set to make sure they are well behaved
- Check for any scale/unit issues in your parameter set
Is there anything else for this ticket?