Previous topic

Algebraic Solvers

Next topic

Experiments

This Page

Solution

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

save(filename)[source]

Save the whole solution using pickle

save_data(filename, variables=None, to_format='pickle')[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 (1D variables only)
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