Algebraic Solvers#

class pybamm.AlgebraicSolver(method='lm', tol=1e-06, extra_options=None)[source]#

Solve a discretised model which contains only (time independent) algebraic equations using a root finding algorithm. Uses scipy.optimize.root. Note: this solver could be extended for quasi-static models, or models in which the time derivative is manually discretised and results in a (possibly nonlinear) algebaric system at each time level.

Parameters:
  • method (str, optional) – The method to use to solve the system (default is “lm”). If it starts with “lsq”, least-squares minimization is used. The method for least-squares can be specified in the form “lsq_methodname”

  • tol (float, optional) – The tolerance for the solver (default is 1e-6).

  • extra_options (dict, optional) –

    Any options to pass to the rootfinder. Vary depending on which method is chosen. Please consult SciPy documentation for details. Addititional options to pass to the solver, by default:

    extra_options = {
        # Tolerance for termination by the change of the independent variables.
        "xtol": 1e-12,
        # Tolerance for termination by the norm of the gradient.
        "gtol": 1e-12,
    }
    

Extends: pybamm.solvers.base_solver.BaseSolver

set_up_root_solver(model, inputs_dict, t_eval)[source]#

Create and return a rootfinder object. Not used for pybamm.AlgebraicSolver.

Parameters:
  • model (pybamm.BaseModel) – The model whose solution to calculate.

  • inputs_dict (dict) – Dictionary of inputs.

  • t_eval (numpy.array, size (k,)) – The times at which to compute the solution.

class pybamm.CasadiAlgebraicSolver(tol=1e-06, step_tol=0.0001, extra_options=None)[source]#

Solve a discretised model which contains only (time independent) algebraic equations using CasADi’s root finding algorithm.

Note: this solver could be extended for quasi-static models, or models in which the time derivative is manually discretised and results in a (possibly nonlinear) algebraic system at each time level.

Parameters:
  • tol (float, optional) – The tolerance for the maximum residual error (default is 1e-6).

  • step_tol (float, optional) – The tolerance for the maximum step size (default is 1e-4).

  • extra_options (dict, optional) –

    Any options to pass to the CasADi rootfinder. Please consult CasADi documentation for details. By default:

    extra_options = {
        # Whether to throw an error if the solver fails to converge.
        "error_on_fail": False,
        # Verbosity level
        "verbose": False,
        # Whether to show warnings when evaluating the model
        "show_eval_warnings": False,
    }
    

Extends: pybamm.solvers.base_solver.BaseSolver

set_up_root_solver(model, inputs_dict, t_eval)[source]#

Create and return a CasADi rootfinder object. The parameter argument to the rootfinder is the concatenated time, differential states, and flattened inputs.

Parameters:
  • model (pybamm.BaseModel) – The model whose solution to calculate.

  • inputs_dict (dict) – Dictionary of inputs.

  • t_eval (numpy.array, size (k,)) – The times at which to compute the solution (not used).

Returns:

The rootfinder function is stored in the model as algebraic_root_solver.

Return type:

None