Previous topic

Base Experiment Class

Next topic

Plotting

This Page

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)[source]

A Simulation class for easy building and running of PyBaMM simulations.

Parameters:
  • model (pybamm.BaseModel) – The model to be simulated
  • experiment (pybamm.Experiment (optional)) – The experimental conditions under which to solve the model
  • geometry (pybamm.Geometry (optional)) – The geometry upon which to solve the model
  • parameter_values (pybamm.ParameterValues (optional)) – Parameters and their corresponding numerical values.
  • submesh_types (dict (optional)) – A dictionary of the types of submesh to use on each subdomain
  • var_pts (dict (optional)) – A dictionary of the number of points used by each spatial variable
  • spatial_methods (dict (optional)) – A dictionary of the types of spatial method to use on each domain (e.g. pybamm.FiniteVolume)
  • solver (pybamm.BaseSolver (optional)) – The solver to use to solve the model.
  • output_variables (list (optional)) – A list of variables to plot automatically
  • C_rate (float (optional)) – The C_rate at which you would like to run a constant current (dis)charge at.
build(check_model=True)[source]

A method to build the model into a system of matrices and vectors suitable for performing numerical computations. If the model has already been built or solved then this function will have no effect. This method will automatically set the parameters if they have not already been set.

Parameters:check_model (bool, optional) – If True, model checks are performed after discretisation (see pybamm.Discretisation.process_model()). Default is True.
get_variable_array(*variables)[source]

A helper function to easily obtain a dictionary of arrays of values for a list of variables at the latest timestep.

Parameters:variable (str) – The name of the variable/variables you wish to obtain the arrays for.
Returns:variable_arrays – A dictionary of the variable names and their corresponding arrays.
Return type:dict
plot(output_variables=None, quick_plot_vars=None, **kwargs)[source]

A method to quickly plot the outputs of the simulation. Creates a pybamm.QuickPlot object (with keyword arguments ‘kwargs’) and then calls pybamm.QuickPlot.dynamic_plot().

Parameters:
  • output_variables (list, optional) – A list of the variables to plot.
  • quick_plot_vars (list, optional) – A list of the variables to plot. Deprecated, use output_variables instead.
  • **kwargs – Additional keyword arguments passed to pybamm.QuickPlot.dynamic_plot(). For a list of all possible keyword arguments see pybamm.QuickPlot.
save(filename)[source]

Save simulation using pickle

set_parameters()[source]

A method to set the parameters in the model and the associated geometry.

set_up_experiment(model, experiment)[source]

Set up a simulation to run with an experiment. This creates a dictionary of inputs (current/voltage/power, running time, stopping condition) for each operating condition in the experiment. The model will then be solved by integrating the model successively with each group of inputs, one group at a time.

solve(t_eval=None, solver=None, external_variables=None, inputs=None, check_model=True)[source]

A method to solve the model. This method will automatically build and set the model parameters if not already done so.

Parameters:
  • t_eval (numeric type, optional) –

    The times (in seconds) at which to compute the solution. Can be provided as an array of times at which to return the solution, or as a list [t0, tf] where t0 is the initial time and tf is the final time. If provided as a list the solution is returned at 100 points within the interval [t0, tf].

    If not using an experiment or running a drive cycle simulation (current provided as data) t_eval must be provided.

    If running an experiment the values in t_eval are ignored, and the solution times are specified by the experiment.

    If None and the parameter “Current function [A]” is read from data (i.e. drive cycle simulation) the model will be solved at the times provided in the data.

  • solver (pybamm.BaseSolver) – The solver to use to solve the model.
  • external_variables (dict) – A dictionary of external variables and their corresponding values at the current time. The variables must correspond to the variables that would normally be found by solving the submodels that have been made external.
  • inputs (dict, optional) – Any input parameters to pass to the model when solving
  • check_model (bool, optional) – If True, model checks are performed after discretisation (see pybamm.Discretisation.process_model()). Default is True.
specs(geometry=None, parameter_values=None, submesh_types=None, var_pts=None, spatial_methods=None, solver=None, output_variables=None, C_rate=None)[source]

Deprecated method for setting specs

step(dt, solver=None, npts=2, external_variables=None, inputs=None, save=True)[source]

A method to step the model forward one timestep. This method will automatically build and set the model parameters if not already done so.

Parameters:
  • dt (numeric type) – The timestep over which to step the solution
  • solver (pybamm.BaseSolver) – The solver to use to solve the model.
  • npts (int, optional) – The number of points at which the solution will be returned during the step dt. Default is 2 (returns the solution at t0 and t0 + dt).
  • external_variables (dict) – A dictionary of external variables and their corresponding values at the current time. The variables must correspond to the variables that would normally be found by solving the submodels that have been made external.
  • inputs (dict, optional) – Any input parameters to pass to the model when solving
  • save (bool) – Turn on to store the solution of all previous timesteps