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, extrap_tol=0, 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.
    • ”fast with events”: perform direct integration of the whole timespan, then go back and check where events were crossed. Experimental only.
    • ”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.
    • ”safe without grid”: perform step-and-check integration step-by-step. Takes more steps than “safe” mode, but doesn’t require creating the grid each time, so may be faster. Experimental only.
  • 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).
  • extrap_tol (float, optional) – The tolerance to assert whether extrapolation occurs or not. Default is 0.
  • extra_options_setup (dict, optional) –

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

    • ”max_num_steps”: Maximum number of integrator steps
    • ”print_stats”: Print out statistics after integration
  • extra_options_call (dict, optional) –

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

create_integrator(model, inputs, t_eval=None, use_event_switch=False)[source]

Method to create a casadi integrator object. If t_eval is provided, the integrator uses t_eval to make the grid. Otherwise, the integrator has grid [0,1].