Simulation class is the primary entry point for running PyBaMM simulations. It wraps a model together with parameter values, a solver, and optional experimental conditions, and exposes a simple .solve() → .plot() workflow.
Class signature
Constructor parameters
The model to be simulated. For example
pybamm.lithium_ion.DFN() or pybamm.lithium_ion.SPM().Experimental conditions under which to solve the model. Accepts a
pybamm.Experiment instance, a single step string, or a list of step strings. If omitted, the simulation runs a simple constant-current (dis)charge controlled by parameter_values.The geometry on which to solve the model. Defaults to
model.default_geometry.Parameter set to use. Defaults to
model.default_parameter_values.Mapping of subdomain names to submesh classes. Defaults to
model.default_submesh_types.Number of mesh points for each spatial variable. Defaults to
model.default_var_pts.Mapping of domain names to spatial method instances (e.g.
pybamm.FiniteVolume). Defaults to model.default_spatial_methods.The solver to use. Defaults to
model.default_solver.Variable names to plot automatically when
plot() is called without arguments.C-rate for a constant-current (dis)charge. Only used when
experiment is None. Sets Current function [A] in parameter_values to C_rate * Nominal cell capacity [A.h].Extra keyword arguments forwarded to
pybamm.Discretisation. See pybamm.Discretisation for details.Whether to cache the electrode state-of-health (eSOH) solver between calls to
solve(). Disabling this forces eSOH to be recomputed on every call, which is useful when parameters are modified in-place between solves.Methods
solve()
Build the model (if not already built) and run the solver. Returns a pybamm.Solution object.
Times at which to return the solution. Required when not using an experiment or drive cycle. Can be
[t0, tf] (returns 100 points) or a full array. Ignored when using an experiment.Override the solver for this call only.
Which experiment cycles to store full sub-solutions for. Only valid when using an experiment.
None saves all cycles.Whether to compute eSOH (electrode state-of-health) summary variables. Overrides the model default.
Resume stepping from a previous solution. Only valid when using an experiment.
Initial State of Charge between 0 and 1. Overwrites initial concentrations from the parameter set.
Callback objects called at each time step. Each must implement all methods from
pybamm.callbacks.BaseCallback.Show a progress bar over cycles. Has no effect without an experiment.
Times (in seconds) at which to interpolate the solution. Only valid for solvers that support intra-solve interpolation (
IDAKLUSolver).build()
Discretise the model into matrices and vectors. Called automatically by solve(). Use this to pre-build the model and inspect the discretised form.
Initial SOC between 0 and 1. Sets electrode stoichiometries via the eSOH solver.
plot()
Create an interactive pybamm.QuickPlot and call dynamic_plot().
Variable names to include. Defaults to
sim.output_variables if set.save() and pybamm.load_sim()
Persist and reload a simulation using Python’s pickle module.
File path. Common extensions are
.pkl or .pickle. Models using convert_to_format = 'python' cannot be saved.save_model()
Write the built, discretised model to a JSON file for later use without rebuilding.
Output JSON file path. Auto-generated from the model name and current datetime if not provided.
Include the mesh in the saved file (required for plotting after reloading).
Include discretised variables in the saved file. Also saves the mesh.
save_model() requires the model to be built first. Call sim.build() before saving. Experiments are not yet supported.set_initial_state()
Set the initial state of charge or lithiation direction before building.
Target SOC between 0 and 1.
"discharge" or "charge" — the lithiation direction used by the eSOH solver.Properties
The most recent solution returned by
solve(). None before the first solve.The model (with parameters set if
build() has been called).The parameter values currently in use.
The solver instance.
The fully discretised model.
None until build() or solve() is called.The mesh used for discretisation.