Simulation#

class pybamm.Simulation(model, experiment=None, geometry=None, parameter_values=None, submesh_types=None, var_pts=None, spatial_methods=None, solver=None, output_variables=None, C_rate=None, discretisation_kwargs=None, cache_esoh=True, experiment_model_mode='legacy')[source]#

Extends BaseSimulation with experiment support.

Accepts all parameters from BaseSimulation, plus:

Parameters:
  • experiment (pybamm.Experiment or string or list (optional)) – The experimental conditions under which to solve the model. If a string is passed, the experiment is constructed as pybamm.Experiment([experiment]). If a list is passed, the experiment is constructed as pybamm.Experiment(experiment).

  • experiment_model_mode (str, optional) – How to construct experiment models. Options are: "legacy" (default), which always uses one model per step; and "unified", which requires the shared experiment model path.

Extends: pybamm.simulation.base_simulation.BaseSimulation

build_for_experiment(initial_soc=None, direction=None, inputs=None, solve_kwargs=None)[source]#

Similar to Simulation.build(), but for the case of simulating an experiment, where there may be several models and solvers to build.

save(filename)[source]#

Save simulation using pickle module.

Parameters:

filename (str) – The file extension can be arbitrary, but it is common to use “.pkl” or “.pickle”

save_model(filename: str | None = None, mesh: bool = False, variables: bool = False)[source]#

Write out a discretised model to a JSON file

Parameters:
  • mesh (bool) – The mesh used to discretise the model. If false, plotting tools will not be available when the model is read back in and solved.

  • variables (bool) – The discretised variables. Not required to solve a model, but if false tools will not be available. Will automatically save meshes as well, required for plotting tools.

  • filename (str, optional) – The desired name of the JSON file. If no name is provided, one will be created based on the model name, and the current datetime.

solve(t_eval=None, solver=None, save_at_cycles=None, calc_esoh=None, starting_solution=None, initial_soc=None, direction=None, callbacks=None, showprogress=False, inputs=None, t_interp=None, **kwargs)[source]#

Solve the model, with experiment support.

Accepts all parameters from BaseSimulation.solve(), plus:

Parameters:
  • save_at_cycles (int or list of ints, optional) – Which cycles to save the full sub-solutions for. If None, all cycles are saved. If int, every multiple of save_at_cycles is saved. If list, every cycle in the list is saved. The first cycle (cycle 1) is always saved.

  • starting_solution (pybamm.Solution) – The solution to start stepping from. If None (default), then self._solution is used. Must be None if not using an experiment.

  • showprogress (bool, optional) – Whether to show a progress bar for cycling. If true, shows a progress bar for cycles. Has no effect when not used with an experiment. Default is False.