Tip

An interactive online version of this notebook is available, which can be accessed via Open this notebook in Google Colab


Alternatively, you may download this notebook and run it offline.

Tutorial 2 - Compare models#

In Tutorial 1, we saw how to run a PyBaMM simulation of the DFN model. However, PyBaMM includes other standard electrochemical models such as the Single Particle Model (SPM) and the Single Particle Model with electrolyte (SPMe). In this tutorial, we will see how to simulate and compare these three models.

Again, the first step is to import the pybamm library into the notebook:

[1]:
%pip install "pybamm[plot,cite]" -q    # install PyBaMM if it is not installed
import pybamm
Note: you may need to restart the kernel to use updated packages.

We start creating a list of all the models we wish to solve

[2]:
models = [
    pybamm.lithium_ion.SPM(),
    pybamm.lithium_ion.SPMe(),
    pybamm.lithium_ion.DFN(),
]

and now we can loop over the list, creating and solving simulations as we go. The solved simulations are stored in the list sims

[3]:
sims = []
for model in models:
    sim = pybamm.Simulation(model)
    sim.solve([0, 3600])
    sims.append(sim)

We can now pass our list of simulations to the dynamic plot method, which will plot the different outputs in the same figure

[4]:
pybamm.dynamic_plot(sims, time_unit="seconds")
[4]:
<pybamm.plotting.quick_plot.QuickPlot at 0x7fab1bee6490>

In this tutorial we have seen how easy it is to run and compare different electrochemical models. In Tutorial 3 we show how to create different plots using PyBaMM’s built-in plotting capability.

References#

The relevant papers for this notebook are:

[5]:
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] Marc Doyle, Thomas F. Fuller, and John Newman. Modeling of galvanostatic charge and discharge of the lithium/polymer/insertion cell. Journal of the Electrochemical society, 140(6):1526–1533, 1993. doi:10.1149/1.2221597.
[3] 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.
[4] 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.
[5] 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.