Tip
An interactive online version of this notebook is available, which can be accessed via
Alternatively, you may download this notebook and run it offline.
A look at solution data and processed variables#
Once you have run a simulation the first thing you want to do is have a look at the data. Most of the examples so far have made use of PyBaMM’s handy QuickPlot function but there are other ways to access the data and this notebook will explore them. First off we will generate a standard SPMe model and use QuickPlot to view the default variables.
[1]:
%pip install "pybamm[plot,cite]" -q # install PyBaMM if it is not installed
import pybamm
import numpy as np
import os
import matplotlib.pyplot as plt
os.chdir(pybamm.__path__[0] + "/..")
# load model
model = pybamm.lithium_ion.SPMe()
# set up and solve simulation
simulation = pybamm.Simulation(model)
dt = 90
t_eval = np.arange(0, 3600, dt) # time in seconds
solution = simulation.solve(t_eval)
quick_plot = pybamm.QuickPlot(solution)
quick_plot.dynamic_plot();
Note: you may need to restart the kernel to use updated packages.
Behind the scenes the QuickPlot classed has created some processed variables which can interpolate the model variables for our solution and has also stored the results for the solution steps
[2]:
solution.data.keys()
[2]:
dict_keys(['Negative particle surface concentration [mol.m-3]', 'Electrolyte concentration [mol.m-3]', 'Positive particle surface concentration [mol.m-3]', 'Current [A]', 'Negative electrode potential [V]', 'Electrolyte potential [V]', 'Positive electrode potential [V]', 'Voltage [V]'])
[3]:
solution.data["Negative particle surface concentration [mol.m-3]"].shape
[3]:
(20, 40)
[4]:
solution.t.shape
[4]:
(40,)
Notice that the dictionary keys are in the same order as the subplots in the QuickPlot figure. We can add new processed variables to the solution by simply using it like a dictionary. First let’s find a few more variables to look at. As you will see there are quite a few:
[5]:
keys = list(model.variables.keys())
keys.sort()
print(keys)
['Ambient temperature', 'Ambient temperature [K]', 'Average negative particle concentration', 'Average negative particle concentration [mol.m-3]', 'Average positive particle concentration', 'Average positive particle concentration [mol.m-3]', 'Battery voltage [V]', 'C-rate', 'Cell temperature', 'Cell temperature [K]', 'Change in measured open-circuit voltage', 'Change in measured open-circuit voltage [V]', 'Current [A]', 'Current collector current density', 'Current collector current density [A.m-2]', 'Discharge capacity [A.h]', 'Electrode current density', 'Electrode tortuosity', 'Electrolyte concentration', 'Electrolyte concentration [Molar]', 'Electrolyte concentration [mol.m-3]', 'Electrolyte current density', 'Electrolyte current density [A.m-2]', 'Electrolyte flux', 'Electrolyte flux [mol.m-2.s-1]', 'Electrolyte potential', 'Electrolyte potential [V]', 'Electrolyte tortuosity', 'Exchange current density', 'Exchange current density [A.m-2]', 'Exchange current density per volume [A.m-3]', 'Gradient of electrolyte potential', 'Gradient of negative electrode potential', 'Gradient of negative electrolyte potential', 'Gradient of positive electrode potential', 'Gradient of positive electrolyte potential', 'Gradient of separator electrolyte potential', 'Inner SEI concentration [mol.m-3]', 'Inner SEI interfacial current density', 'Inner SEI interfacial current density [A.m-2]', 'Inner SEI thickness', 'Inner SEI thickness [m]', 'Inner positive electrode SEI concentration [mol.m-3]', 'Inner positive electrode SEI interfacial current density', 'Inner positive electrode SEI interfacial current density [A.m-2]', 'Inner positive electrode SEI thickness', 'Inner positive electrode SEI thickness [m]', 'Interfacial current density', 'Interfacial current density [A.m-2]', 'Interfacial current density per volume [A.m-3]', 'Irreversible electrochemical heating', 'Irreversible electrochemical heating [W.m-3]', 'Leading-order current collector current density', 'Leading-order electrode tortuosity', 'Leading-order electrolyte tortuosity', 'Leading-order negative electrode porosity', 'Leading-order negative electrode tortuosity', 'Leading-order negative electrolyte tortuosity', 'Leading-order porosity', 'Leading-order positive electrode porosity', 'Leading-order positive electrode tortuosity', 'Leading-order positive electrolyte tortuosity', 'Leading-order separator porosity', 'Leading-order separator tortuosity', 'Leading-order x-averaged negative electrode porosity', 'Leading-order x-averaged negative electrode porosity change', 'Leading-order x-averaged negative electrode tortuosity', 'Leading-order x-averaged negative electrolyte tortuosity', 'Leading-order x-averaged positive electrode porosity', 'Leading-order x-averaged positive electrode porosity change', 'Leading-order x-averaged positive electrode tortuosity', 'Leading-order x-averaged positive electrolyte tortuosity', 'Leading-order x-averaged separator porosity', 'Leading-order x-averaged separator porosity change', 'Leading-order x-averaged separator tortuosity', 'Local ECM resistance', 'Local ECM resistance [Ohm]', 'Local voltage', 'Local voltage [V]', 'Loss of lithium to SEI [mol]', 'Loss of lithium to positive electrode SEI [mol]', 'Maximum negative particle concentration', 'Maximum negative particle concentration [mol.m-3]', 'Maximum negative particle surface concentration', 'Maximum negative particle surface concentration [mol.m-3]', 'Maximum positive particle concentration', 'Maximum positive particle concentration [mol.m-3]', 'Maximum positive particle surface concentration', 'Maximum positive particle surface concentration [mol.m-3]', 'Measured battery open-circuit voltage [V]', 'Measured open-circuit voltage', 'Measured open-circuit voltage [V]', 'Minimum negative particle concentration', 'Minimum negative particle concentration [mol.m-3]', 'Minimum negative particle surface concentration', 'Minimum negative particle surface concentration [mol.m-3]', 'Minimum positive particle concentration', 'Minimum positive particle concentration [mol.m-3]', 'Minimum positive particle surface concentration', 'Minimum positive particle surface concentration [mol.m-3]', 'Negative current collector potential', 'Negative current collector potential [V]', 'Negative current collector temperature', 'Negative current collector temperature [K]', 'Negative electrode active material volume fraction', 'Negative electrode active material volume fraction change', 'Negative electrode current density', 'Negative electrode current density [A.m-2]', 'Negative electrode entropic change', 'Negative electrode exchange current density', 'Negative electrode exchange current density [A.m-2]', 'Negative electrode exchange current density per volume [A.m-3]', 'Negative electrode extent of lithiation', 'Negative electrode interfacial current density', 'Negative electrode interfacial current density [A.m-2]', 'Negative electrode interfacial current density per volume [A.m-3]', 'Negative electrode ohmic losses', 'Negative electrode ohmic losses [V]', 'Negative electrode open-circuit potential', 'Negative electrode open-circuit potential [V]', 'Negative electrode oxygen exchange current density', 'Negative electrode oxygen exchange current density [A.m-2]', 'Negative electrode oxygen exchange current density per volume [A.m-3]', 'Negative electrode oxygen interfacial current density', 'Negative electrode oxygen interfacial current density [A.m-2]', 'Negative electrode oxygen interfacial current density per volume [A.m-3]', 'Negative electrode oxygen open-circuit potential', 'Negative electrode oxygen open-circuit potential [V]', 'Negative electrode oxygen reaction overpotential', 'Negative electrode oxygen reaction overpotential [V]', 'Negative electrode porosity', 'Negative electrode porosity change', 'Negative electrode potential', 'Negative electrode potential [V]', 'Negative electrode pressure', 'Negative electrode reaction overpotential', 'Negative electrode reaction overpotential [V]', 'SEI film overpotential', 'SEI film overpotential [V]', 'SEI interfacial current density', 'SEI interfacial current density [A.m-2]', 'Negative electrode surface area to volume ratio', 'Negative electrode surface area to volume ratio [m-1]', 'Negative electrode surface potential difference', 'Negative electrode surface potential difference [V]', 'Negative electrode temperature', 'Negative electrode temperature [K]', 'Negative electrode tortuosity', 'Negative electrode transverse volume-averaged acceleration', 'Negative electrode transverse volume-averaged acceleration [m.s-2]', 'Negative electrode transverse volume-averaged velocity', 'Negative electrode transverse volume-averaged velocity [m.s-2]', 'Negative electrode volume-averaged acceleration', 'Negative electrode volume-averaged acceleration [m.s-1]', 'Negative electrode volume-averaged concentration', 'Negative electrode volume-averaged concentration [mol.m-3]', 'Negative electrode volume-averaged velocity', 'Negative electrode volume-averaged velocity [m.s-1]', 'Negative electrolyte concentration', 'Negative electrolyte concentration [Molar]', 'Negative electrolyte concentration [mol.m-3]', 'Negative electrolyte current density', 'Negative electrolyte current density [A.m-2]', 'Negative electrolyte potential', 'Negative electrolyte potential [V]', 'Negative electrolyte tortuosity', 'Negative particle concentration', 'Negative particle concentration [mol.m-3]', 'Negative particle flux', 'Negative particle radius', 'Negative particle radius [m]', 'Negative particle surface concentration', 'Negative particle surface concentration [mol.m-3]', 'Negative SEI concentration [mol.m-3]', 'Ohmic heating', 'Ohmic heating [W.m-3]', 'Outer SEI concentration [mol.m-3]', 'Outer SEI interfacial current density', 'Outer SEI interfacial current density [A.m-2]', 'Outer SEI thickness', 'Outer SEI thickness [m]', 'Outer positive electrode SEI concentration [mol.m-3]', 'Outer positive electrode SEI interfacial current density', 'Outer positive electrode SEI interfacial current density [A.m-2]', 'Outer positive electrode SEI thickness', 'Outer positive electrode SEI thickness [m]', 'Oxygen exchange current density', 'Oxygen exchange current density [A.m-2]', 'Oxygen exchange current density per volume [A.m-3]', 'Oxygen interfacial current density', 'Oxygen interfacial current density [A.m-2]', 'Oxygen interfacial current density per volume [A.m-3]', 'Porosity', 'Porosity change', 'Positive current collector potential', 'Positive current collector potential [V]', 'Positive current collector temperature', 'Positive current collector temperature [K]', 'Positive electrode active material volume fraction', 'Positive electrode active material volume fraction change', 'Positive electrode current density', 'Positive electrode current density [A.m-2]', 'Positive electrode entropic change', 'Positive electrode exchange current density', 'Positive electrode exchange current density [A.m-2]', 'Positive electrode exchange current density per volume [A.m-3]', 'Positive electrode extent of lithiation', 'Positive electrode interfacial current density', 'Positive electrode interfacial current density [A.m-2]', 'Positive electrode interfacial current density per volume [A.m-3]', 'Positive electrode ohmic losses', 'Positive electrode ohmic losses [V]', 'Positive electrode open-circuit potential', 'Positive electrode open-circuit potential [V]', 'Positive electrode oxygen exchange current density', 'Positive electrode oxygen exchange current density [A.m-2]', 'Positive electrode oxygen exchange current density per volume [A.m-3]', 'Positive electrode oxygen interfacial current density', 'Positive electrode oxygen interfacial current density [A.m-2]', 'Positive electrode oxygen interfacial current density per volume [A.m-3]', 'Positive electrode oxygen open-circuit potential', 'Positive electrode oxygen open-circuit potential [V]', 'Positive electrode oxygen reaction overpotential', 'Positive electrode oxygen reaction overpotential [V]', 'Positive electrode porosity', 'Positive electrode porosity change', 'Positive electrode potential', 'Positive electrode potential [V]', 'Positive electrode pressure', 'Positive electrode reaction overpotential', 'Positive electrode reaction overpotential [V]', 'Positive electrode SEI film overpotential', 'Positive electrode SEI film overpotential [V]', 'Positive electrode SEI interfacial current density', 'Positive electrode SEI interfacial current density [A.m-2]', 'Positive electrode surface area to volume ratio', 'Positive electrode surface area to volume ratio [m-1]', 'Positive electrode surface potential difference', 'Positive electrode surface potential difference [V]', 'Positive electrode temperature', 'Positive electrode temperature [K]', 'Positive electrode tortuosity', 'Positive electrode transverse volume-averaged acceleration', 'Positive electrode transverse volume-averaged acceleration [m.s-2]', 'Positive electrode transverse volume-averaged velocity', 'Positive electrode transverse volume-averaged velocity [m.s-2]', 'Positive electrode volume-averaged acceleration', 'Positive electrode volume-averaged acceleration [m.s-1]', 'Positive electrode volume-averaged concentration', 'Positive electrode volume-averaged concentration [mol.m-3]', 'Positive electrode volume-averaged velocity', 'Positive electrode volume-averaged velocity [m.s-1]', 'Positive electrolyte concentration', 'Positive electrolyte concentration [Molar]', 'Positive electrolyte concentration [mol.m-3]', 'Positive electrolyte current density', 'Positive electrolyte current density [A.m-2]', 'Positive electrolyte potential', 'Positive electrolyte potential [V]', 'Positive electrolyte tortuosity', 'Positive particle concentration', 'Positive particle concentration [mol.m-3]', 'Positive particle flux', 'Positive particle radius', 'Positive particle radius [m]', 'Positive particle surface concentration', 'Positive particle surface concentration [mol.m-3]', 'Positive SEI concentration [mol.m-3]', 'Pressure', 'R-averaged negative particle concentration', 'R-averaged negative particle concentration [mol.m-3]', 'R-averaged positive particle concentration', 'R-averaged positive particle concentration [mol.m-3]', 'Reversible heating', 'Reversible heating [W.m-3]', 'Sei interfacial current density', 'Sei interfacial current density [A.m-2]', 'Sei interfacial current density per volume [A.m-3]', 'Separator electrolyte concentration', 'Separator electrolyte concentration [Molar]', 'Separator electrolyte concentration [mol.m-3]', 'Separator electrolyte potential', 'Separator electrolyte potential [V]', 'Separator porosity', 'Separator porosity change', 'Separator pressure', 'Separator temperature', 'Separator temperature [K]', 'Separator tortuosity', 'Separator transverse volume-averaged acceleration', 'Separator transverse volume-averaged acceleration [m.s-2]', 'Separator transverse volume-averaged velocity', 'Separator transverse volume-averaged velocity [m.s-2]', 'Separator volume-averaged acceleration', 'Separator volume-averaged acceleration [m.s-1]', 'Separator volume-averaged velocity', 'Separator volume-averaged velocity [m.s-1]', 'Sum of electrolyte reaction source terms', 'Sum of interfacial current densities', 'Sum of negative electrode electrolyte reaction source terms', 'Sum of negative electrode interfacial current densities', 'Sum of positive electrode electrolyte reaction source terms', 'Sum of positive electrode interfacial current densities', 'Sum of x-averaged negative electrode electrolyte reaction source terms', 'Sum of x-averaged negative electrode interfacial current densities', 'Sum of x-averaged positive electrode electrolyte reaction source terms', 'Sum of x-averaged positive electrode interfacial current densities', 'Terminal power [W]', 'Voltage', 'Voltage [V]', 'Time', 'Time [h]', 'Time [min]', 'Time [s]', 'Total concentration in electrolyte [mol]', 'Total current density', 'Total current density [A.m-2]', 'Total heating', 'Total heating [W.m-3]', 'Total lithium in negative electrode [mol]', 'Total lithium in positive electrode [mol]', 'Total SEI thickness', 'Total SEI thickness [m]', 'Total positive electrode SEI thickness', 'Total positive electrode SEI thickness [m]', 'Transverse volume-averaged acceleration', 'Transverse volume-averaged acceleration [m.s-2]', 'Transverse volume-averaged velocity', 'Transverse volume-averaged velocity [m.s-2]', 'Volume-averaged Ohmic heating', 'Volume-averaged Ohmic heating [W.m-3]', 'Volume-averaged acceleration', 'Volume-averaged acceleration [m.s-1]', 'Volume-averaged cell temperature', 'Volume-averaged cell temperature [K]', 'Volume-averaged irreversible electrochemical heating', 'Volume-averaged irreversible electrochemical heating[W.m-3]', 'Volume-averaged reversible heating', 'Volume-averaged reversible heating [W.m-3]', 'Volume-averaged total heating', 'Volume-averaged total heating [W.m-3]', 'Volume-averaged velocity', 'Volume-averaged velocity [m.s-1]', 'X-averaged Ohmic heating', 'X-averaged Ohmic heating [W.m-3]', 'X-averaged battery concentration overpotential [V]', 'X-averaged battery electrolyte ohmic losses [V]', 'X-averaged battery open-circuit voltage [V]', 'X-averaged battery reaction overpotential [V]', 'X-averaged battery solid phase ohmic losses [V]', 'X-averaged cell temperature', 'X-averaged cell temperature [K]', 'X-averaged concentration overpotential', 'X-averaged concentration overpotential [V]', 'X-averaged electrolyte concentration', 'X-averaged electrolyte concentration [Molar]', 'X-averaged electrolyte concentration [mol.m-3]', 'X-averaged electrolyte ohmic losses', 'X-averaged electrolyte ohmic losses [V]', 'X-averaged electrolyte overpotential', 'X-averaged electrolyte overpotential [V]', 'X-averaged electrolyte potential', 'X-averaged electrolyte potential [V]', 'X-averaged inner SEI concentration [mol.m-3]', 'X-averaged inner SEI interfacial current density', 'X-averaged inner SEI interfacial current density [A.m-2]', 'X-averaged inner SEI thickness', 'X-averaged inner SEI thickness [m]', 'X-averaged inner positive electrode SEI concentration [mol.m-3]', 'X-averaged inner positive electrode SEI interfacial current density', 'X-averaged inner positive electrode SEI interfacial current density [A.m-2]', 'X-averaged inner positive electrode SEI thickness', 'X-averaged inner positive electrode SEI thickness [m]', 'X-averaged irreversible electrochemical heating', 'X-averaged irreversible electrochemical heating [W.m-3]', 'X-averaged negative electrode active material volume fraction', 'X-averaged negative electrode active material volume fraction change', 'X-averaged negative electrode entropic change', 'X-averaged negative electrode exchange current density', 'X-averaged negative electrode exchange current density [A.m-2]', 'X-averaged negative electrode exchange current density per volume [A.m-3]', 'X-averaged negative electrode extent of lithiation', 'X-averaged negative electrode interfacial current density', 'X-averaged negative electrode interfacial current density [A.m-2]', 'X-averaged negative electrode interfacial current density per volume [A.m-3]', 'X-averaged negative electrode ohmic losses', 'X-averaged negative electrode ohmic losses [V]', 'X-averaged negative electrode open-circuit potential', 'X-averaged negative electrode open-circuit potential [V]', 'X-averaged negative electrode oxygen exchange current density', 'X-averaged negative electrode oxygen exchange current density [A.m-2]', 'X-averaged negative electrode oxygen exchange current density per volume [A.m-3]', 'X-averaged negative electrode oxygen interfacial current density', 'X-averaged negative electrode oxygen interfacial current density [A.m-2]', 'X-averaged negative electrode oxygen interfacial current density per volume [A.m-3]', 'X-averaged negative electrode oxygen open-circuit potential', 'X-averaged negative electrode oxygen open-circuit potential [V]', 'X-averaged negative electrode oxygen reaction overpotential', 'X-averaged negative electrode oxygen reaction overpotential [V]', 'X-averaged negative electrode porosity', 'X-averaged negative electrode porosity change', 'X-averaged negative electrode potential', 'X-averaged negative electrode potential [V]', 'X-averaged negative electrode pressure', 'X-averaged negative electrode reaction overpotential', 'X-averaged negative electrode reaction overpotential [V]', 'X-averaged negative electrode resistance [Ohm.m2]', 'X-averaged SEI concentration [mol.m-3]', 'X-averaged SEI film overpotential', 'X-averaged SEI film overpotential [V]', 'X-averaged SEI interfacial current density', 'X-averaged SEI interfacial current density [A.m-2]', 'X-averaged negative electrode surface area to volume ratio', 'X-averaged negative electrode surface area to volume ratio [m-1]', 'X-averaged negative electrode surface potential difference', 'X-averaged negative electrode surface potential difference [V]', 'X-averaged negative electrode temperature', 'X-averaged negative electrode temperature [K]', 'X-averaged negative electrode tortuosity', 'X-averaged negative electrode total interfacial current density', 'X-averaged negative electrode total interfacial current density [A.m-2]', 'X-averaged negative electrode total interfacial current density per volume [A.m-3]', 'X-averaged negative electrode transverse volume-averaged acceleration', 'X-averaged negative electrode transverse volume-averaged acceleration [m.s-2]', 'X-averaged negative electrode transverse volume-averaged velocity', 'X-averaged negative electrode transverse volume-averaged velocity [m.s-2]', 'X-averaged negative electrode volume-averaged acceleration', 'X-averaged negative electrode volume-averaged acceleration [m.s-1]', 'X-averaged negative electrolyte concentration', 'X-averaged negative electrolyte concentration [mol.m-3]', 'X-averaged negative electrolyte potential', 'X-averaged negative electrolyte potential [V]', 'X-averaged negative electrolyte tortuosity', 'X-averaged negative particle concentration', 'X-averaged negative particle concentration [mol.m-3]', 'X-averaged negative particle flux', 'X-averaged negative particle surface concentration', 'X-averaged negative particle surface concentration [mol.m-3]', 'X-averaged open-circuit voltage', 'X-averaged open-circuit voltage [V]', 'X-averaged outer SEI concentration [mol.m-3]', 'X-averaged outer SEI interfacial current density', 'X-averaged outer SEI interfacial current density [A.m-2]', 'X-averaged outer SEI thickness', 'X-averaged outer SEI thickness [m]', 'X-averaged outer positive electrode SEI concentration [mol.m-3]', 'X-averaged outer positive electrode SEI interfacial current density', 'X-averaged outer positive electrode SEI interfacial current density [A.m-2]', 'X-averaged outer positive electrode SEI thickness', 'X-averaged outer positive electrode SEI thickness [m]', 'X-averaged positive electrode active material volume fraction', 'X-averaged positive electrode active material volume fraction change', 'X-averaged positive electrode entropic change', 'X-averaged positive electrode exchange current density', 'X-averaged positive electrode exchange current density [A.m-2]', 'X-averaged positive electrode exchange current density per volume [A.m-3]', 'X-averaged positive electrode extent of lithiation', 'X-averaged positive electrode interfacial current density', 'X-averaged positive electrode interfacial current density [A.m-2]', 'X-averaged positive electrode interfacial current density per volume [A.m-3]', 'X-averaged positive electrode ohmic losses', 'X-averaged positive electrode ohmic losses [V]', 'X-averaged positive electrode open-circuit potential', 'X-averaged positive electrode open-circuit potential [V]', 'X-averaged positive electrode oxygen exchange current density', 'X-averaged positive electrode oxygen exchange current density [A.m-2]', 'X-averaged positive electrode oxygen exchange current density per volume [A.m-3]', 'X-averaged positive electrode oxygen interfacial current density', 'X-averaged positive electrode oxygen interfacial current density [A.m-2]', 'X-averaged positive electrode oxygen interfacial current density per volume [A.m-3]', 'X-averaged positive electrode oxygen open-circuit potential', 'X-averaged positive electrode oxygen open-circuit potential [V]', 'X-averaged positive electrode oxygen reaction overpotential', 'X-averaged positive electrode oxygen reaction overpotential [V]', 'X-averaged positive electrode porosity', 'X-averaged positive electrode porosity change', 'X-averaged positive electrode potential', 'X-averaged positive electrode potential [V]', 'X-averaged positive electrode pressure', 'X-averaged positive electrode reaction overpotential', 'X-averaged positive electrode reaction overpotential [V]', 'X-averaged positive electrode resistance [Ohm.m2]', 'X-averaged positive electrode SEI concentration [mol.m-3]', 'X-averaged positive electrode SEI film overpotential', 'X-averaged positive electrode SEI film overpotential [V]', 'X-averaged positive electrode SEI interfacial current density', 'X-averaged positive electrode SEI interfacial current density [A.m-2]', 'X-averaged positive electrode surface area to volume ratio', 'X-averaged positive electrode surface area to volume ratio [m-1]', 'X-averaged positive electrode surface potential difference', 'X-averaged positive electrode surface potential difference [V]', 'X-averaged positive electrode temperature', 'X-averaged positive electrode temperature [K]', 'X-averaged positive electrode tortuosity', 'X-averaged positive electrode total interfacial current density', 'X-averaged positive electrode total interfacial current density [A.m-2]', 'X-averaged positive electrode total interfacial current density per volume [A.m-3]', 'X-averaged positive electrode transverse volume-averaged acceleration', 'X-averaged positive electrode transverse volume-averaged acceleration [m.s-2]', 'X-averaged positive electrode transverse volume-averaged velocity', 'X-averaged positive electrode transverse volume-averaged velocity [m.s-2]', 'X-averaged positive electrode volume-averaged acceleration', 'X-averaged positive electrode volume-averaged acceleration [m.s-1]', 'X-averaged positive electrolyte concentration', 'X-averaged positive electrolyte concentration [mol.m-3]', 'X-averaged positive electrolyte potential', 'X-averaged positive electrolyte potential [V]', 'X-averaged positive electrolyte tortuosity', 'X-averaged positive particle concentration', 'X-averaged positive particle concentration [mol.m-3]', 'X-averaged positive particle flux', 'X-averaged positive particle surface concentration', 'X-averaged positive particle surface concentration [mol.m-3]', 'X-averaged reaction overpotential', 'X-averaged reaction overpotential [V]', 'X-averaged reversible heating', 'X-averaged reversible heating [W.m-3]', 'X-averaged SEI film overpotential', 'X-averaged SEI film overpotential [V]', 'X-averaged separator electrolyte concentration', 'X-averaged separator electrolyte concentration [mol.m-3]', 'X-averaged separator electrolyte potential', 'X-averaged separator electrolyte potential [V]', 'X-averaged separator porosity', 'X-averaged separator porosity change', 'X-averaged separator pressure', 'X-averaged separator temperature', 'X-averaged separator temperature [K]', 'X-averaged separator tortuosity', 'X-averaged separator transverse volume-averaged acceleration', 'X-averaged separator transverse volume-averaged acceleration [m.s-2]', 'X-averaged separator transverse volume-averaged velocity', 'X-averaged separator transverse volume-averaged velocity [m.s-2]', 'X-averaged separator volume-averaged acceleration', 'X-averaged separator volume-averaged acceleration [m.s-1]', 'X-averaged solid phase ohmic losses', 'X-averaged solid phase ohmic losses [V]', 'X-averaged total heating', 'X-averaged total heating [W.m-3]', 'X-averaged total SEI thickness', 'X-averaged total SEI thickness [m]', 'X-averaged total positive electrode SEI thickness', 'X-averaged total positive electrode SEI thickness [m]', 'X-averaged volume-averaged acceleration', 'X-averaged volume-averaged acceleration [m.s-1]', 'r_n', 'r_n [m]', 'r_p', 'r_p [m]', 'x', 'x [m]', 'x_n', 'x_n [m]', 'x_p', 'x_p [m]', 'x_s', 'x_s [m]']
If you want to find a particular variable you can search the variables dictionary
[6]:
model.variables.search("time")
Time
Time [h]
Time [min]
Time [s]
We’ll use the time in hours
[7]:
solution["Time [h]"]
[7]:
<pybamm.solvers.processed_variable.ProcessedVariable at 0x7f69966b6210>
This created a new processed variable and stored it on the solution object
[8]:
solution.data.keys()
[8]:
dict_keys(['Negative particle surface concentration [mol.m-3]', 'Electrolyte concentration [mol.m-3]', 'Positive particle surface concentration [mol.m-3]', 'Current [A]', 'Negative electrode potential [V]', 'Electrolyte potential [V]', 'Positive electrode potential [V]', 'Voltage [V]', 'Time [h]'])
We can see the data by simply accessing the entries attribute of the processed variable
[9]:
solution["Time [h]"].entries
[9]:
array([0. , 0.025, 0.05 , 0.075, 0.1 , 0.125, 0.15 , 0.175, 0.2 ,
0.225, 0.25 , 0.275, 0.3 , 0.325, 0.35 , 0.375, 0.4 , 0.425,
0.45 , 0.475, 0.5 , 0.525, 0.55 , 0.575, 0.6 , 0.625, 0.65 ,
0.675, 0.7 , 0.725, 0.75 , 0.775, 0.8 , 0.825, 0.85 , 0.875,
0.9 , 0.925, 0.95 , 0.975])
We can also call the method with specified time(s) in SI units of seconds
[10]:
time_in_seconds = np.array([0, 600, 900, 1700, 3000])
[11]:
solution["Time [h]"](time_in_seconds)
[11]:
array([0. , 0.16666667, 0.25 , 0.47222222, 0.83333333])
If the variable has not already been processed it will be created behind the scenes
[12]:
var = "X-averaged negative electrode temperature [K]"
solution[var](time_in_seconds)
[12]:
array([298.15, 298.15, 298.15, 298.15, 298.15])
In this example the simulation was isothermal, so the temperature remains unchanged.
Saving the solution#
The solution can be saved in a number of ways:
[13]:
# to a pickle file (default)
solution.save_data(
"outputs.pickle",
["Time [h]", "Current [A]", "Voltage [V]", "Electrolyte concentration [mol.m-3]"],
)
# to a matlab file
# need to give variable names without space
solution.save_data(
"outputs.mat",
["Time [h]", "Current [A]", "Voltage [V]", "Electrolyte concentration [mol.m-3]"],
to_format="matlab",
short_names={
"Time [h]": "t",
"Current [A]": "I",
"Voltage [V]": "V",
"Electrolyte concentration [mol.m-3]": "c_e",
},
)
# to a csv file (time-dependent outputs only, no spatial dependence allowed)
solution.save_data(
"outputs.csv", ["Time [h]", "Current [A]", "Voltage [V]"], to_format="csv"
)
Stepping the solver#
The previous solution was created in one go with the solve method, but it is also possible to step the solution and look at the results as we go. In doing so, the results are automatically updated at each step.
[14]:
dt = 360
time = 0
end_time = solution["Time [s]"].entries[-1]
step_simulation = pybamm.Simulation(model)
while time < end_time:
step_solution = step_simulation.step(dt)
print("Time", time)
print(step_solution["Voltage [V]"].entries)
time += dt
Time 0
[3.77047806 3.71250693]
Time 360
[3.77047806 3.71250693 3.68215218]
Time 720
[3.77047806 3.71250693 3.68215218 3.66125574]
Time 1080
[3.77047806 3.71250693 3.68215218 3.66125574 3.64330942]
Time 1440
[3.77047806 3.71250693 3.68215218 3.66125574 3.64330942 3.61166857]
Time 1800
[3.77047806 3.71250693 3.68215218 3.66125574 3.64330942 3.61166857
3.59709451]
Time 2160
[3.77047806 3.71250693 3.68215218 3.66125574 3.64330942 3.61166857
3.59709451 3.58821334]
Time 2520
[3.77047806 3.71250693 3.68215218 3.66125574 3.64330942 3.61166857
3.59709451 3.58821334 3.58056055]
Time 2880
[3.77047806 3.71250693 3.68215218 3.66125574 3.64330942 3.61166857
3.59709451 3.58821334 3.58056055 3.55158694]
Time 3240
[3.77047806 3.71250693 3.68215218 3.66125574 3.64330942 3.61166857
3.59709451 3.58821334 3.58056055 3.55158694 3.16842636]
We can plot the voltages and see that the solutions are the same
[15]:
voltage = solution["Voltage [V]"].entries
step_voltage = step_solution["Voltage [V]"].entries
plt.figure()
plt.plot(solution["Time [h]"].entries, voltage, "b-", label="SPMe (continuous solve)")
plt.plot(
step_solution["Time [h]"].entries, step_voltage, "ro", label="SPMe (stepped solve)"
)
plt.legend()
[15]:
<matplotlib.legend.Legend at 0x7f69964178d0>
As a final step, we will clean up the output files created by this notebook:
[ ]:
os.remove("outputs.csv")
os.remove("outputs.mat")
os.remove("outputs.pickle")
References#
The relevant papers for this notebook are:
[16]:
pybamm.print_citations()
[1] Joel A. E. Andersson, Joris Gillis, Greg Horn, James B. Rawlings, and Moritz Diehl. CasADi – A software framework for nonlinear optimization and optimal control. Mathematical Programming Computation, 11(1):1–36, 2019. doi:10.1007/s12532-018-0139-4.
[2] Charles R. Harris, K. Jarrod Millman, Stéfan J. van der Walt, Ralf Gommers, Pauli Virtanen, David Cournapeau, Eric Wieser, Julian Taylor, Sebastian Berg, Nathaniel J. Smith, and others. Array programming with NumPy. Nature, 585(7825):357–362, 2020. doi:10.1038/s41586-020-2649-2.
[3] Scott G. Marquis, Valentin Sulzer, Robert Timms, Colin P. Please, and S. Jon Chapman. An asymptotic derivation of a single particle model with electrolyte. Journal of The Electrochemical Society, 166(15):A3693–A3706, 2019. doi:10.1149/2.0341915jes.
[4] Valentin Sulzer, Scott G. Marquis, Robert Timms, Martin Robinson, and S. Jon Chapman. Python Battery Mathematical Modelling (PyBaMM). ECSarXiv. February, 2020. doi:10.1149/osf.io/67ckj.