pybamm.IDAKLUSolver is generally the fastest solver for lithium-ion battery models. It wraps the SUNDIALS IDA DAE integrator with the KLU sparse-direct linear solver, provided by the pybammsolvers package.
Constructor
Relative tolerance for the IDA integrator.
Absolute tolerance for the IDA integrator.
Method for consistent initial conditions.
"casadi" uses CasADi’s Newton solver; any scipy.optimize.root method string is also accepted.Tolerance for the root-finding step.
Tolerance for detecting extrapolation beyond the solved interval.
Behaviour on extrapolation:
"warn", "error", or "ignore".Behaviour when the solver returns an error flag:
"error", "warn", or "ignore".If provided, only these variables are computed during the solve. This can significantly reduce memory usage and solve time for large models.
Advanced solver options. See the Options reference below.
Options Reference
Theoptions dict exposes the full SUNDIALS IDA configuration. All keys and their defaults:
| Key | Default | Description |
|---|---|---|
print_stats | False | Print solver statistics after each solve |
num_threads | 1 | Number of OpenMP threads |
num_solvers | num_threads | Number of parallel solvers (for input-parameter sweeps) |
linear_solver | "SUNLinSol_KLU" | SUNDIALS linear solver. Options: "SUNLinSol_KLU", "SUNLinSol_Dense", "SUNLinSol_Band", "SUNLinSol_SPBCGS", "SUNLinSol_SPGMR", etc. |
jacobian | "sparse" | Jacobian form: "none", "dense", "banded", "sparse", "matrix-free" |
preconditioner | "BBDP" | Preconditioner for iterative solvers: "none" or "BBDP" |
max_order_bdf | 5 | Maximum order of the BDF linear multistep method |
max_num_steps | 100000 | Maximum steps to reach the next output time |
dt_init | 0.0 | Initial step size (0 = solver chooses) |
dt_min | 0.0 | Minimum absolute step size (0 = solver chooses) |
dt_max | 0.0 | Maximum absolute step size (0 = solver chooses) |
max_error_test_failures | 10 | Maximum error-test failures per step |
max_nonlinear_iterations | 40 | Maximum nonlinear iterations per step |
max_convergence_failures | 100 | Maximum nonlinear convergence failures per step |
hermite_interpolation | True | Store Hermite interpolation data. Disabled when output_variables are given. |
hermite_reduction_factor | 1.0 | Compression factor for Hermite spline (values > 1 reduce storage with a small accuracy cost) |
suppress_algebraic_error | False | Exclude algebraic variables from the error test |
silence_sundials_errors | False | Suppress SUNDIALS error messages during solve |
calc_ic | True | Calculate consistent initial conditions |
init_all_y_ic | False | If True, compute all y₀ given ẏ₀; if False, compute algebraic y₀ and differential ẏ₀ given differential y₀ |