Previous topic

Scikits.odes Solvers

Next topic

Algebraic Solvers

This Page

Casadi Solver

class pybamm.CasadiSolver(mode='safe', rtol=1e-06, atol=1e-06, root_method='casadi', root_tol=1e-06, max_step_decrease_count=5, dt_max=None, extra_options_setup=None, extra_options_call=None)[source]

Solve a discretised model, using CasADi.

Extends: pybamm.BaseSolver

Parameters:
  • mode (str) –

    How to solve the model (default is “safe”):

    • ”fast”: perform direct integration, without accounting for events. Recommended when simulating a drive cycle or other simulation where no events should be triggered.
    • ”safe”: perform step-and-check integration in global steps of size dt_max, checking whether events have been triggered. Recommended for simulations of a full charge or discharge.
    • ”old safe”: perform step-and-check integration in steps of size dt for each dt in t_eval, checking whether events have been triggered.
  • rtol (float, optional) – The relative tolerance for the solver (default is 1e-6).
  • atol (float, optional) – The absolute tolerance for the solver (default is 1e-6).
  • root_method (str or pybamm algebraic solver class, optional) – The method to use to find initial conditions (for DAE solvers). If a solver class, must be an algebraic solver class. If “casadi”, the solver uses casadi’s Newton rootfinding algorithm to find initial conditions. Otherwise, the solver uses ‘scipy.optimize.root’ with method specified by ‘root_method’ (e.g. “lm”, “hybr”, …)
  • root_tol (float, optional) – The tolerance for root-finding. Default is 1e-6.
  • max_step_decrease_counts (float, optional) – The maximum number of times step size can be decreased before an error is raised. Default is 5.
  • dt_max (float, optional) – The maximum global step size (in seconds) used in “safe” mode. If None the default value corresponds to a non-dimensional time of 0.01 (i.e. 0.01 * model.timescale_eval).
  • extra_options_setup (dict, optional) –

    Any options to pass to the CasADi integrator when creating the integrator. Please consult CasADi documentation for details. Some typical options:

    • ”max_num_steps”: Maximum number of integrator steps
  • extra_options_call (dict, optional) –

    Any options to pass to the CasADi integrator when calling the integrator. Please consult CasADi documentation for details.