Previous topic

Utility functions

Next topic

Citations

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, quick_plot_vars=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 (: class: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 (dict (optional)) – A dictionary of 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.
  • quick_plot_vars (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 experiment 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. If you want to rebuild, first use “reset()”. 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(quick_plot_vars=None, testing=False)[source]

A method to quickly plot the outputs of the simulation.

Parameters:
  • quick_plot_vars (list, optional) – A list of the variables to plot.
  • bool, optional (testing,) – If False the plot will not be displayed
reset(update_model=True)[source]

A method to reset a simulation back to its unprocessed state.

save(filename)[source]

Save simulation using pickle

set_defaults()[source]

A method to set all the simulation specs to default values for the supplied model.

set_parameters()[source]

A method to set the parameters in the model and the associated geometry. If the model has already been built or solved then this will first reset to the unprocessed state and then set the parameter values.

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 at which to compute the solution. If None and the parameter “Current function [A]” is not read from data the model will be solved for a full discharge (1 hour / C_rate). If None and the parameter “Current function [A]” is read from data 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(model_options=None, geometry=None, parameter_values=None, submesh_types=None, var_pts=None, spatial_methods=None, solver=None, quick_plot_vars=None, C_rate=None)[source]

A method to set the various specs of the simulation. This method automatically resets the model after the new specs have been set.

Parameters:
  • model_options (dict, optional) – A dictionary of options to tweak the model you are using
  • geometry (pybamm.Geometry, optional) – The geometry upon which to solve the model
  • parameter_values (dict, optional) – A dictionary of 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.
  • quick_plot_vars (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 experiment at.
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