Skip to main content
The pybamm.Simulation class is the primary entry point for running PyBaMM simulations. It wraps a model together with parameter values, geometry, mesh, discretisation, and solver into a single object, and provides a simple solve() method.

Creating a simulation

At minimum, a Simulation requires a model:
When no arguments are provided, Simulation uses the model’s defaults for geometry, mesh types, spatial methods, parameter values, and solver.

Full constructor signature

Passing parameters

Pass a ParameterValues object to override the model defaults:
See Using Parameter Sets for more on working with ParameterValues.

Passing a solver

See Choosing Solvers for a comparison of available solvers.

Solving

1

Without an experiment

When not using a pybamm.Experiment, you must provide a time span as [t0, tf] in seconds. PyBaMM returns the solution at 100 evenly-spaced points within this interval (or the adaptive solver’s natural steps).
For a 1C discharge, a safe upper bound is 3700 seconds:
You can also pass an array to request the solution at specific times:
2

With an experiment

When passing a pybamm.Experiment, the solution times are determined by the experiment. Do not pass t_eval:
3

Setting initial SOC

Pass initial_soc to start at a specific state of charge (0 to 1):

Convenience: C-rate

Use C_rate on the Simulation to set the discharge current automatically:

Additional solve options

Accessing the solution

After calling solve(), the solution is available as sim.solution or as the return value:

Common variables

Cycle and step data (experiments)

For experiment simulations, the solution is organised into cycles and steps:

Saving and loading

Simulations can be saved to disk using Python’s pickle module:
Saving is not supported when model.convert_to_format == "python". Use model.convert_to_format = "casadi" (the default) instead.

Saving only the model

You can export a discretised model to JSON for later use without re-building:

Building manually

You can separate the build and solve steps:
This is useful when you want to inspect or modify the discretised model before solving, or when solving multiple times with different inputs.