Previous topic

Algebraic Solvers

Next topic

Post-Process Variables

This Page

Solutions

class pybamm._BaseSolution(t, y, t_event=None, y_event=None, termination='final time', copy_this=None)[source]

(Semi-private) class containing the solution of, and various attributes associated with, a PyBaMM model. This class is automatically created by the Solution class, and should never be called from outside the Solution class.

Parameters:
  • t (numpy.array, size (n,)) – A one-dimensional array containing the times at which the solution is evaluated
  • y (numpy.array, size (m, n)) – A two-dimensional array containing the values of the solution. y[i, :] is the vector of solutions at time t[i].
  • 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
  • copy_this (pybamm.Solution, optional) – A solution to copy, if provided. Default is None.
inputs

Values of the inputs

model

Model used for 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, variables=None, to_format='pickle', short_names=None)[source]

Save solution data only (raw arrays)

Parameters:
  • filename (str) – The name of the file to save data to
  • 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)
  • 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.
t

Times at which the solution is evaluated

t_event

Time at which the event happens

termination

Reason for termination

update(variables)[source]

Add ProcessedVariables to the dictionary of variables in the solution

y

Values of the solution

y_event

Value of the solution at the time of the event

class pybamm.Solution(t, y, t_event=None, y_event=None, termination='final time')[source]

Class extending the base solution, with additional functionality for concatenating different solutions together

Extends: _BaseSolution

append(solution, start_index=1, create_sub_solutions=False)[source]

Appends solution.t and solution.y onto self.t and self.y.

Note: by default this process removes the initial time and state of solution to avoid duplicate times and states being stored (self.t[-1] is equal to solution.t[0], and self.y[:, -1] is equal to solution.y[:, 0]). Set the optional argument start_index to override this behavior

sub_solutions

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