#### Previous topic

Algebraic Solvers

#### Next topic

Post-Process Variables

# Solutions¶

class pybamm.Solution(all_ts, all_ys, all_models, all_inputs, t_event=None, y_event=None, termination='final time', sensitivities=False, check_solution=True)[source]

Class containing the solution of, and various attributes associated with, a PyBaMM model.

Parameters
• all_ts (`numpy.array`, size (n,) (or list of these)) – A one-dimensional array containing the times at which the solution is evaluated. A list of times can be provided instead to initialize a solution with sub-solutions.

• all_ys (`numpy.array`, size (m, n) (or list of these)) – A two-dimensional array containing the values of the solution. y[i, :] is the vector of solutions at time t[i]. A list of ys can be provided instead to initialize a solution with sub-solutions.

• all_models (`pybamm.BaseModel`) – The model that was used to calculate the solution. A list of models can be provided instead to initialize a solution with sub-solutions that have been calculated using those models.

• all_inputs (dict (or list of these)) – The inputs that were used to calculate the solution A list of inputs can be provided instead to initialize a solution with sub-solutions.

• t_event (`numpy.array`, size (1,)) – A zero-dimensional array containing the time at which the event happens.

• y_event (`numpy.array`, size (m,)) – A one-dimensional array containing the value of the solution at the time when the event happens.

• termination (str) – String to indicate why the solution terminated

• sensitivities (bool or dict) – True if sensitivities included as the solution of the explicit forwards equations. False if no sensitivities included/wanted. Dict if sensitivities are provided as a dict of {parameter: sensitivities} pairs.

property all_models

Model(s) used for solution

property first_state

A Solution object that only contains the first state. This is faster to evaluate than the full solution when only the first state is needed (e.g. to initialize a model with the solution)

property last_state

A Solution object that only contains the final state. This is faster to evaluate than the full solution when only the final state is needed (e.g. to initialize a model with the solution)

plot(output_variables=None, **kwargs)[source]

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

Parameters
save(filename)[source]

Save the whole solution using pickle

save_data(filename=None, variables=None, to_format='pickle', short_names=None)[source]

Save solution data only (raw arrays)

Parameters
• filename (str, optional) – The name of the file to save data to. If None, then a str is returned

• variables (list, optional) – List of variables to save. If None, saves all of the variables that have been created so far

• to_format (str, optional) –

The format to save to. Options are:

• ’pickle’ (default): creates a pickle file with the data dictionary

• ’matlab’: creates a .mat file, for loading in matlab

• ’csv’: creates a csv file (0D variables only)

• ’json’: creates a json file

• short_names (dict, optional) – Dictionary of shortened names to use when saving. This may be necessary when saving to MATLAB, since no spaces or special characters are allowed in MATLAB variable names. Note that not all the variables need to be given a short name.

Returns

data – str if ‘csv’ or ‘json’ is chosen and filename is None, otherwise None

Return type

str, optional

property sensitivities

np_array

Type

Values of the sensitivities. Returns a dict of param_name

property sub_solutions

List of sub solutions that have been concatenated to form the full solution

property t

Times at which the solution is evaluated

property t_event

Time at which the event happens

property termination

Reason for termination

update(variables)[source]

Add ProcessedVariables to the dictionary of variables in the solution

property y

Values of the solution

property y_event

Value of the solution at the time of the event