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.

Attention

You are viewing this notebook on the latest version of the documentation, where these notebooks may not be compatible with the stable release of PyBaMM since they can contain features that are not yet released. We recommend viewing these notebooks from the stable version of the documentation. To install the latest version of PyBaMM that is compatible with the latest notebooks, build PyBaMM from source.

# Using model options in PyBaMM#

In this notebook we show how to pass options to models. This allows users to do things such as include extra physics (e.g. thermal effects) or change the macroscopic dimension of the problem (e.g. change from a 1D model to a 2+1D pouch cell model). To see all of the options currently available in PyBaMM, please take a look at the documentation here. For more information on combining submodels explicitly to create your own custom model, please see the Using Submodels notebook.

## Example: Solving the SPMe with a lumped thermal model#

PyBaMM is designed to be a flexible modelling package that allows users to easily include different physics within a model without having to start from scratch. In this example, we show how to pass model options to include thermal effects in the SPMe (for more information on the SPMe see here). First we import PyBaMM and any other packages we need

```
[ ]:
```

```
%pip install "pybamm[plot,cite]" -q # install PyBaMM if it is not installed
import pybamm
import os
os.chdir(pybamm.__path__[0] + "/..")
```

```
Note: you may need to restart the kernel to use updated packages.
```

We then choose out model options, which a set as a dictionary. We choose to model the behaviour in the particle by assuming the concentration profile is quadratic within the particle. We also choose a lumped thermal model (note that this is fully-coupled, i.e. parameters can depend on temperature). For an in-depth look at the thermal models see the thermal models notebook

```
[ ]:
```

```
options = {"particle": "quadratic profile", "thermal": "lumped"}
```

We then pass our options to the model

```
[3]:
```

```
model = pybamm.lithium_ion.SPMe(options)
```

We choose to use the parameters from Chen2020.

```
[4]:
```

```
param = pybamm.ParameterValues("Chen2020")
```

We then create and solve a simulation, making sure we pass in our updated parameter values

```
[5]:
```

```
simulation = pybamm.Simulation(model, parameter_values=param)
simulation.solve([0, 3600])
```

```
[5]:
```

```
<pybamm.solvers.solution.Solution at 0x7f6169de4690>
```

Finally we plot the voltage and the cell temperature

```
[6]:
```

```
simulation.plot(
[
"Voltage [V]",
"X-averaged cell temperature [K]",
]
)
```

Note that the variable “X-averaged cell temperature [K]” is the scalar-valued lumped temperature, whereas the variable “Cell temperature [K]” is the value of the lumped temperature broadcasted across the whole cell domain. This type of behaviour is purposefully designed to allow easy comparison of different models and settings. For instance we may wish to compare a simulation that uses a lumped thermal model with a simulation that uses a full thermal model (i.e. one that solves the heat equation in the x-direction). When comparing these two model we could then plot the same variable “Cell temperature [K]” to compare the temperature throughout the cell.

## References#

The relevant papers for this notebook are:

```
[7]:
```

```
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] Venkat R. Subramanian, Vinten D. Diwakar, and Deepak Tapriyal. Efficient macro-micro scale coupled modeling of batteries. Journal of The Electrochemical Society, 152(10):A2002, 2005. doi:10.1149/1.2032427.
[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.
```