# Single Particle Model (SPM) 

## Model Equations

The SPM consists of two spherically symmetric diffusion equations: one within a representative negative particle ($\text{k}=\text{n}$) and one within a representative positive particle ($\text{k}=\text{p}$). In the centre of the particle the standard no-flux condition is imposed. Since the SPM assumes that all particles in an electrode behave in exactly the same way, the flux on the surface of a particle is simply the current $I$ divided by the thickness of the electrode $L_{\text{k}}$. The concentration of lithium in electrode $\text{k}$ is denoted $c_{\text{k}}$ and the current is denoted by $I$. All parameters in the model stated here are dimensionless and are given in terms of dimensional parameters at the end of this notebook. The model equations for the SPM are then: 
\begin{align}
\mathcal{C}_{\text{k}} \frac{\partial c_{\text{s,k}}}{\partial t} &= -\frac{1}{r_{\text{k}}^2} \frac{\partial}{\partial r_{\text{k}}} \left(r_{\text{k}}^2 N_{\text{s,k}}\right), \\
N_{\text{s,k}} &= -D_{\text{s,k}}(c_{\text{s,k}}) \frac{\partial c_{\text{s,k}}}{\partial r_{\text{k}}}, \quad \text{k} \in \text{n, p}, \end{align}
$$
N_{\text{s,k}}\big|_{r_{\text{k}}=0} = 0, \quad \text{k} \in \text{n, p}, \quad \ \ - \frac{a_{R, \text{k}}\gamma_{\text{k}}}{\mathcal{C}_{\text{k}}} N_{\text{s,k}}\big|_{r_{\text{k}}=1} = 
\begin{cases}
		  \frac{I}{L_{\text{n}}}, \quad &\text{k}=\text{n}, \\ 
		  -\frac{I}{L_{\text{p}}}, \quad &\text{k}=\text{p}, 
\end{cases} \\
c_{\text{s,k}}(r_{\text{k}},0) = c_{\text{s,k,0}}, \quad \text{k} \in \text{n, p},$$
where $D_{\text{s,k}}$ is the diffusion coefficient in the solid, $N_{\text{s,k}}$ denotes the flux of lithium ions in the solid particle within the region $\text{k}$, and $r_{\text{k}} \in[0,1]$ is the radial coordinate of the particle in electrode $\text{k}$. 

### Voltage Expression
The terminal voltage is obtained from the expression: 
$$
V = U_{\text{p}}(c_{\text{p}})\big|_{r_{\text{p}}=1} - U_{\text{n}}(c_{\text{n}})\big|_{r_{\text{n}}=1} -2\sinh^{-1}\left(\frac{I}{j_{\text{0,p}} L_{\text{p}}}\right) - 2\sinh^{-1}\left(\frac{I}{j_{\text{0,n}} L_{\text{n}}}\right)
$$
with the exchange current densities given by
$$j_{\text{0,k}} =  \frac{\gamma_{\text{k}}}{\mathcal{C}_{\text{r,k}}}(c_{\text{k}})^{1/2}(1-c_{\text{k}})^{1/2}  $$

More details can be found in [[1]](#ref).

## Example solving SPM using PyBaMM

Below we show how to solve the Single Particle Model, using the default geometry, mesh, parameters, discretisation and solver provided with PyBaMM. In this notebook we explicitly handle all the stages of setting up, processing and solving the model in order to explain them in detail. However, it is often simpler in practice to use the `Simulation` class, which handles many of the stages automatically, as shown [here](../simulation-class.ipynb).

First we need to import `pybamm`, and then change our working directory to the root of the pybamm folder. 


```python
%pip install pybamm -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]+'/..')
```

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


We then create an instance of the SPM:


```python
model = pybamm.lithium_ion.SPM()
```

The model object is a subtype of [`pybamm.BaseModel`](https://pybamm.readthedocs.io/en/latest/source/models/base_model.html), and contains all the equations that define this particular model. For example, the `rhs` dict contained in `model` has a dictionary mapping variables such as $c_n$ to the equation representing its rate of change with time (i.e. $\partial{c_n}/\partial{t}$). We can see this explicitly by visualising this entry in the `rhs` dict:


```python
variable = next(iter(model.rhs.keys()))
equation = next(iter(model.rhs.values()))
print('rhs equation for variable \'',variable,'\' is:')
path = 'examples/notebooks/models/'
equation.visualise(path+'spm1.png')
```

    rhs equation for variable ' Discharge capacity [A.h] ' is:




We need a geometry in which to define our model equations. In pybamm this is represented by the [`pybamm.Geometry`](https://pybamm.readthedocs.io/en/latest/source/geometry/geometry.html) class. In this case we use the default geometry object defined by the model


```python
geometry = model.default_geometry
```

This geometry object defines a number of domains, each with its own name, spatial variables and min/max limits (the latter are represented as equations similar to the rhs equation shown above). For instance, the SPM has the following domains:


```python
print('SPM domains:')
for i, (k, v) in enumerate(geometry.items()):
    print(str(i+1)+'.',k,'with variables:')
    for var, rng in v.items():
        if 'min' in rng:
            print('  -(',rng['min'],') <=',var,'<= (',rng['max'],')')
        else:
            print(var, '=', rng['position'])
```

    SPM domains:
    1. negative electrode with variables:
      -( 0 ) <= x_n <= ( Negative electrode thickness [m] / (Negative electrode thickness [m] + Separator thickness [m] + Positive electrode thickness [m]) )
    2. separator with variables:
      -( Negative electrode thickness [m] / (Negative electrode thickness [m] + Separator thickness [m] + Positive electrode thickness [m]) ) <= x_s <= ( Negative electrode thickness [m] / (Negative electrode thickness [m] + Separator thickness [m] + Positive electrode thickness [m]) + Separator thickness [m] / (Negative electrode thickness [m] + Separator thickness [m] + Positive electrode thickness [m]) )
    3. positive electrode with variables:
      -( Negative electrode thickness [m] / (Negative electrode thickness [m] + Separator thickness [m] + Positive electrode thickness [m]) + Separator thickness [m] / (Negative electrode thickness [m] + Separator thickness [m] + Positive electrode thickness [m]) ) <= x_p <= ( 1 )
    4. negative particle with variables:
      -( 0 ) <= r_n <= ( 1 )
    5. positive particle with variables:
      -( 0 ) <= r_p <= ( 1 )
    6. current collector with variables:
    z = 1


Both the model equations and the geometry include parameters, such as $\gamma_p$ or $L_p$. We can substitute these symbolic parameters in the model with values by using the [`pybamm.ParameterValues`](https://pybamm.readthedocs.io/en/latest/source/parameters/parameter_values.html) class, which takes either a python dictionary or CSV file with the mapping between parameter names and values. Rather than create our own instance of `pybamm.ParameterValues`, we will use the default parameter set included in the model


```python
param = model.default_parameter_values
```

We can then apply this parameter set to the model and geometry


```python
param.process_model(model)
param.process_geometry(geometry)
```

The next step is to mesh the input geometry. We can do this using the [`pybamm.Mesh`](https://pybamm.readthedocs.io/en/latest/source/meshes/meshes.html) class. This class takes in the geometry of the problem, and also two dictionaries containing the type of mesh to use within each domain of the geometry (i.e. within the positive or negative electrode domains), and the number of mesh points. 

The default mesh types and the default number of points to use in each variable for the SPM are:


```python
for k, t in model.default_submesh_types.items():
    print(k,'is of type',t.__repr__())
for var, npts in model.default_var_pts.items():
    print(var,'has',npts,'mesh points')
```

    negative electrode is of type Generator for Uniform1DSubMesh
    separator is of type Generator for Uniform1DSubMesh
    positive electrode is of type Generator for Uniform1DSubMesh
    negative particle is of type Generator for Uniform1DSubMesh
    positive particle is of type Generator for Uniform1DSubMesh
    current collector is of type Generator for SubMesh0D
    x_n has 20 mesh points
    x_s has 20 mesh points
    x_p has 20 mesh points
    r_n has 30 mesh points
    r_p has 30 mesh points
    y has 10 mesh points
    z has 10 mesh points


With these defaults, we can then create our mesh of the given geometry:


```python
mesh = pybamm.Mesh(geometry, model.default_submesh_types, model.default_var_pts)
```

The next step is to discretise the model equations using this mesh. We do this using the [`pybamm.Discretisation`](https://pybamm.readthedocs.io/en/latest/source/discretisations/discretisation.html) class, which takes both the mesh we have already created, and a dictionary of spatial methods to use for each geometry domain. For the case of the SPM, we use the following defaults for the spatial discretisation methods:


```python
for k, method in model.default_spatial_methods.items():
    print(k,'is discretised using',method.__class__.__name__,'method')
```

    macroscale is discretised using FiniteVolume method
    negative particle is discretised using FiniteVolume method
    positive particle is discretised using FiniteVolume method
    current collector is discretised using ZeroDimensionalSpatialMethod method


We then create the `pybamm.Discretisation` object, and use this to discretise the model equations


```python
disc = pybamm.Discretisation(mesh, model.default_spatial_methods)
disc.process_model(model);
```

After this stage, all of the variables in `model` have been discretised into `pybamm.StateVector` objects, and spatial operators have been replaced by matrix-vector multiplications, ready to be evaluated within a time-stepping algorithm of a given solver. For example, the rhs expression for $\partial{c_n}/\partial{t}$ that we visualised above is now represented by:


```python
model.concatenated_rhs.children[0].visualise(path+'spm2.png')
```



Now we are ready to run the time-stepping routine to solve the model. Once again we use the default ODE solver.


```python
# Solve the model at the given time points (in seconds)
solver = model.default_solver
n = 250
t_eval = np.linspace(0, 3600, n)
print('Solving using',type(solver).__name__,'solver...')
solution = solver.solve(model, t_eval)
print('Finished.')
```

    Solving using ScipySolver solver...
    Finished.


Each model in pybamm has a list of relevant variables defined in the model, for use in visualising the model solution or for comparison with other models. The SPM defines the following variables:


```python
print('SPM model variables:')
for v in model.variables.keys():
    print('\t-',v)
```

    SPM model variables:
    	- Time
    	- Time [s]
    	- Time [min]
    	- Time [h]
    	- x
    	- x [m]
    	- x_n
    	- x_n [m]
    	- x_s
    	- x_s [m]
    	- x_p
    	- x_p [m]
    	- Sum of electrolyte reaction source terms
    	- Sum of negative electrode electrolyte reaction source terms
    	- Sum of positive electrode electrolyte reaction source terms
    	- Sum of x-averaged negative electrode electrolyte reaction source terms
    	- Sum of x-averaged positive electrode electrolyte reaction source terms
    	- Sum of interfacial current densities
    	- Sum of negative electrode interfacial current densities
    	- Sum of positive electrode interfacial current densities
    	- Sum of x-averaged negative electrode interfacial current densities
    	- Sum of x-averaged positive electrode interfacial current densities
    	- r_n
    	- r_n [m]
    	- r_p
    	- r_p [m]
    	- Total current density
    	- Total current density [A.m-2]
    	- Current [A]
    	- C-rate
    	- Discharge capacity [A.h]
    	- Porosity
    	- Negative electrode porosity
    	- Separator porosity
    	- Positive electrode porosity
    	- X-averaged negative electrode porosity
    	- X-averaged separator porosity
    	- X-averaged positive electrode porosity
    	- Active material volume fraction
    	- Negative electrode active material volume fraction
    	- Separator active material volume fraction
    	- Positive electrode active material volume fraction
    	- X-averaged negative electrode active material volume fraction
    	- X-averaged separator active material volume fraction
    	- X-averaged positive electrode active material volume fraction
    	- Leading-order porosity
    	- Leading-order negative electrode porosity
    	- Leading-order separator porosity
    	- Leading-order positive electrode porosity
    	- Leading-order x-averaged negative electrode porosity
    	- Leading-order x-averaged separator porosity
    	- Leading-order x-averaged positive electrode porosity
    	- Leading-order active material volume fraction
    	- Leading-order negative electrode active material volume fraction
    	- Leading-order separator active material volume fraction
    	- Leading-order positive electrode active material volume fraction
    	- Leading-order x-averaged negative electrode active material volume fraction
    	- Leading-order x-averaged separator active material volume fraction
    	- Leading-order x-averaged positive electrode active material volume fraction
    	- Porosity change
    	- Negative electrode porosity change
    	- Separator porosity change
    	- Positive electrode porosity change
    	- X-averaged negative electrode porosity change
    	- X-averaged separator porosity change
    	- X-averaged positive electrode porosity change
    	- Leading-order x-averaged negative electrode porosity change
    	- Leading-order x-averaged separator porosity change
    	- Leading-order x-averaged positive electrode porosity change
    	- Negative electrode volume-averaged velocity
    	- Positive electrode volume-averaged velocity
    	- Negative electrode volume-averaged velocity [m.s-1]
    	- Positive electrode volume-averaged velocity [m.s-1]
    	- Negative electrode volume-averaged acceleration
    	- Positive electrode volume-averaged acceleration
    	- Negative electrode volume-averaged acceleration [m.s-1]
    	- Positive electrode volume-averaged acceleration [m.s-1]
    	- X-averaged negative electrode volume-averaged acceleration
    	- X-averaged positive electrode volume-averaged acceleration
    	- X-averaged negative electrode volume-averaged acceleration [m.s-1]
    	- X-averaged positive electrode volume-averaged acceleration [m.s-1]
    	- Negative electrode pressure
    	- Positive electrode pressure
    	- X-averaged negative electrode pressure
    	- X-averaged positive electrode pressure
    	- Separator pressure
    	- X-averaged separator pressure
    	- Negative electrode transverse volume-averaged velocity
    	- Separator transverse volume-averaged velocity
    	- Positive electrode transverse volume-averaged velocity
    	- Negative electrode transverse volume-averaged velocity [m.s-2]
    	- Separator transverse volume-averaged velocity [m.s-2]
    	- Positive electrode transverse volume-averaged velocity [m.s-2]
    	- X-averaged negative electrode transverse volume-averaged velocity
    	- X-averaged separator transverse volume-averaged velocity
    	- X-averaged positive electrode transverse volume-averaged velocity
    	- X-averaged negative electrode transverse volume-averaged velocity [m.s-2]
    	- X-averaged separator transverse volume-averaged velocity [m.s-2]
    	- X-averaged positive electrode transverse volume-averaged velocity [m.s-2]
    	- Transverse volume-averaged velocity
    	- Transverse volume-averaged velocity [m.s-2]
    	- Negative electrode transverse volume-averaged acceleration
    	- Separator transverse volume-averaged acceleration
    	- Positive electrode transverse volume-averaged acceleration
    	- Negative electrode transverse volume-averaged acceleration [m.s-2]
    	- Separator transverse volume-averaged acceleration [m.s-2]
    	- Positive electrode transverse volume-averaged acceleration [m.s-2]
    	- X-averaged negative electrode transverse volume-averaged acceleration
    	- X-averaged separator transverse volume-averaged acceleration
    	- X-averaged positive electrode transverse volume-averaged acceleration
    	- X-averaged negative electrode transverse volume-averaged acceleration [m.s-2]
    	- X-averaged separator transverse volume-averaged acceleration [m.s-2]
    	- X-averaged positive electrode transverse volume-averaged acceleration [m.s-2]
    	- Transverse volume-averaged acceleration
    	- Transverse volume-averaged acceleration [m.s-2]
    	- Negative particle concentration
    	- Negative particle concentration [mol.m-3]
    	- X-averaged negative particle concentration
    	- X-averaged negative particle concentration [mol.m-3]
    	- R-averaged negative particle concentration
    	- R-averaged negative particle concentration [mol.m-3]
    	- Average negative particle concentration
    	- Average negative particle concentration [mol.m-3]
    	- Negative particle surface concentration
    	- Negative particle surface concentration [mol.m-3]
    	- X-averaged negative particle surface concentration
    	- X-averaged negative particle surface concentration [mol.m-3]
    	- Negative electrode active volume fraction
    	- Negative electrode volume-averaged concentration
    	- Negative electrode volume-averaged concentration [mol.m-3]
    	- Negative electrode extent of lithiation
    	- X-averaged negative electrode extent of lithiation
    	- Total lithium in negative electrode [mol]
    	- Minimum negative particle concentration
    	- Maximum negative particle concentration
    	- Minimum negative particle concentration [mol.m-3]
    	- Maximum negative particle concentration [mol.m-3]
    	- Minimum negative particle surface concentration
    	- Maximum negative particle surface concentration
    	- Minimum negative particle surface concentration [mol.m-3]
    	- Maximum negative particle surface concentration [mol.m-3]
    	- Negative particle radius
    	- Negative particle radius [m]
    	- Negative surface area to volume ratio
    	- Negative surface area to volume ratio [m-1]
    	- Positive particle concentration
    	- Positive particle concentration [mol.m-3]
    	- X-averaged positive particle concentration
    	- X-averaged positive particle concentration [mol.m-3]
    	- R-averaged positive particle concentration
    	- R-averaged positive particle concentration [mol.m-3]
    	- Average positive particle concentration
    	- Average positive particle concentration [mol.m-3]
    	- Positive particle surface concentration
    	- Positive particle surface concentration [mol.m-3]
    	- X-averaged positive particle surface concentration
    	- X-averaged positive particle surface concentration [mol.m-3]
    	- Positive electrode active volume fraction
    	- Positive electrode volume-averaged concentration
    	- Positive electrode volume-averaged concentration [mol.m-3]
    	- Positive electrode extent of lithiation
    	- X-averaged positive electrode extent of lithiation
    	- Total lithium in positive electrode [mol]
    	- Minimum positive particle concentration
    	- Maximum positive particle concentration
    	- Minimum positive particle concentration [mol.m-3]
    	- Maximum positive particle concentration [mol.m-3]
    	- Minimum positive particle surface concentration
    	- Maximum positive particle surface concentration
    	- Minimum positive particle surface concentration [mol.m-3]
    	- Maximum positive particle surface concentration [mol.m-3]
    	- Positive particle radius
    	- Positive particle radius [m]
    	- Positive surface area to volume ratio
    	- Positive surface area to volume ratio [m-1]
    	- Electrolyte concentration
    	- Electrolyte concentration [mol.m-3]
    	- Electrolyte concentration [Molar]
    	- X-averaged electrolyte concentration
    	- X-averaged electrolyte concentration [mol.m-3]
    	- X-averaged electrolyte concentration [Molar]
    	- Negative electrolyte concentration
    	- Negative electrolyte concentration [mol.m-3]
    	- Negative electrolyte concentration [Molar]
    	- Separator electrolyte concentration
    	- Separator electrolyte concentration [mol.m-3]
    	- Separator electrolyte concentration [Molar]
    	- Positive electrolyte concentration
    	- Positive electrolyte concentration [mol.m-3]
    	- Positive electrolyte concentration [Molar]
    	- X-averaged negative electrolyte concentration
    	- X-averaged negative electrolyte concentration [mol.m-3]
    	- X-averaged separator electrolyte concentration
    	- X-averaged separator electrolyte concentration [mol.m-3]
    	- X-averaged positive electrolyte concentration
    	- X-averaged positive electrolyte concentration [mol.m-3]
    	- Electrolyte flux
    	- Electrolyte flux [mol.m-2.s-1]
    	- Negative current collector temperature
    	- Negative current collector temperature [K]
    	- X-averaged negative electrode temperature
    	- X-averaged negative electrode temperature [K]
    	- Negative electrode temperature
    	- Negative electrode temperature [K]
    	- X-averaged separator temperature
    	- X-averaged separator temperature [K]
    	- Separator temperature
    	- Separator temperature [K]
    	- X-averaged positive electrode temperature
    	- X-averaged positive electrode temperature [K]
    	- Positive electrode temperature
    	- Positive electrode temperature [K]
    	- Positive current collector temperature
    	- Positive current collector temperature [K]
    	- Cell temperature
    	- Cell temperature [K]
    	- X-averaged cell temperature
    	- X-averaged cell temperature [K]
    	- Volume-averaged cell temperature
    	- Volume-averaged cell temperature [K]
    	- Ambient temperature [K]
    	- Ambient temperature
    	- Inner negative electrode sei thickness
    	- Inner negative electrode sei thickness [m]
    	- X-averaged inner negative electrode sei thickness
    	- X-averaged inner negative electrode sei thickness [m]
    	- Outer negative electrode sei thickness
    	- Outer negative electrode sei thickness [m]
    	- X-averaged outer negative electrode sei thickness
    	- X-averaged outer negative electrode sei thickness [m]
    	- Total negative electrode sei thickness
    	- Total negative electrode sei thickness [m]
    	- X-averaged total negative electrode sei thickness
    	- X-averaged total negative electrode sei thickness [m]
    	- X-averaged negative electrode resistance [Ohm.m2]
    	- Inner negative electrode sei concentration [mol.m-3]
    	- X-averaged inner negative electrode sei concentration [mol.m-3]
    	- Outer negative electrode sei concentration [mol.m-3]
    	- X-averaged outer negative electrode sei concentration [mol.m-3]
    	- Negative sei concentration [mol.m-3]
    	- X-averaged negative electrode sei concentration [mol.m-3]
    	- Loss of lithium to negative electrode sei [mol]
    	- Total negative electrode sei thickness
    	- Total negative electrode sei thickness [m]
    	- X-averaged total negative electrode sei thickness
    	- X-averaged total negative electrode sei thickness [m]
    	- X-averaged negative electrode resistance [Ohm.m2]
    	- Inner negative electrode sei interfacial current density
    	- Inner negative electrode sei interfacial current density [A.m-2]
    	- X-averaged inner negative electrode sei interfacial current density
    	- X-averaged inner negative electrode sei interfacial current density [A.m-2]
    	- Outer negative electrode sei interfacial current density
    	- Outer negative electrode sei interfacial current density [A.m-2]
    	- X-averaged outer negative electrode sei interfacial current density
    	- X-averaged outer negative electrode sei interfacial current density [A.m-2]
    	- Negative electrode sei interfacial current density
    	- Negative electrode sei interfacial current density [A.m-2]
    	- X-averaged negative electrode sei interfacial current density
    	- X-averaged negative electrode sei interfacial current density [A.m-2]
    	- Inner positive electrode sei thickness
    	- Inner positive electrode sei thickness [m]
    	- X-averaged inner positive electrode sei thickness
    	- X-averaged inner positive electrode sei thickness [m]
    	- Outer positive electrode sei thickness
    	- Outer positive electrode sei thickness [m]
    	- X-averaged outer positive electrode sei thickness
    	- X-averaged outer positive electrode sei thickness [m]
    	- Total positive electrode sei thickness
    	- Total positive electrode sei thickness [m]
    	- X-averaged total positive electrode sei thickness
    	- X-averaged total positive electrode sei thickness [m]
    	- X-averaged positive electrode resistance [Ohm.m2]
    	- Inner positive electrode sei concentration [mol.m-3]
    	- X-averaged inner positive electrode sei concentration [mol.m-3]
    	- Outer positive electrode sei concentration [mol.m-3]
    	- X-averaged outer positive electrode sei concentration [mol.m-3]
    	- Positive sei concentration [mol.m-3]
    	- X-averaged positive electrode sei concentration [mol.m-3]
    	- Loss of lithium to positive electrode sei [mol]
    	- Total positive electrode sei thickness
    	- Total positive electrode sei thickness [m]
    	- X-averaged total positive electrode sei thickness
    	- X-averaged total positive electrode sei thickness [m]
    	- X-averaged positive electrode resistance [Ohm.m2]
    	- Inner positive electrode sei interfacial current density
    	- Inner positive electrode sei interfacial current density [A.m-2]
    	- X-averaged inner positive electrode sei interfacial current density
    	- X-averaged inner positive electrode sei interfacial current density [A.m-2]
    	- Outer positive electrode sei interfacial current density
    	- Outer positive electrode sei interfacial current density [A.m-2]
    	- X-averaged outer positive electrode sei interfacial current density
    	- X-averaged outer positive electrode sei interfacial current density [A.m-2]
    	- Positive electrode sei interfacial current density
    	- Positive electrode sei interfacial current density [A.m-2]
    	- X-averaged positive electrode sei interfacial current density
    	- X-averaged positive electrode sei interfacial current density [A.m-2]
    	- Electrolyte tortuosity
    	- Negative electrolyte tortuosity
    	- Positive electrolyte tortuosity
    	- X-averaged negative electrolyte tortuosity
    	- X-averaged positive electrolyte tortuosity
    	- Separator tortuosity
    	- X-averaged separator tortuosity
    	- Electrode tortuosity
    	- Negative electrode tortuosity
    	- Positive electrode tortuosity
    	- X-averaged negative electrode tortuosity
    	- X-averaged positive electrode tortuosity
    	- Separator volume-averaged velocity
    	- Separator volume-averaged velocity [m.s-1]
    	- Separator volume-averaged acceleration
    	- Separator volume-averaged acceleration [m.s-1]
    	- X-averaged separator volume-averaged acceleration
    	- X-averaged separator volume-averaged acceleration [m.s-1]
    	- Volume-averaged velocity
    	- Volume-averaged velocity [m.s-1]
    	- Volume-averaged acceleration
    	- X-averaged volume-averaged acceleration
    	- Volume-averaged acceleration [m.s-1]
    	- X-averaged volume-averaged acceleration [m.s-1]
    	- Pressure
    	- Negative particle flux
    	- X-averaged negative particle flux
    	- Positive particle flux
    	- X-averaged positive particle flux
    	- Total concentration in electrolyte [mol]
    	- Ohmic heating
    	- Ohmic heating [W.m-3]
    	- X-averaged Ohmic heating
    	- X-averaged Ohmic heating [W.m-3]
    	- Volume-averaged Ohmic heating
    	- Volume-averaged Ohmic heating [W.m-3]
    	- Irreversible electrochemical heating
    	- Irreversible electrochemical heating [W.m-3]
    	- X-averaged irreversible electrochemical heating
    	- X-averaged irreversible electrochemical heating [W.m-3]
    	- Volume-averaged irreversible electrochemical heating
    	- Volume-averaged irreversible electrochemical heating[W.m-3]
    	- Reversible heating
    	- Reversible heating [W.m-3]
    	- X-averaged reversible heating
    	- X-averaged reversible heating [W.m-3]
    	- Volume-averaged reversible heating
    	- Volume-averaged reversible heating [W.m-3]
    	- Total heating
    	- Total heating [W.m-3]
    	- X-averaged total heating
    	- X-averaged total heating [W.m-3]
    	- Volume-averaged total heating
    	- Volume-averaged total heating [W.m-3]
    	- Negative current collector potential
    	- Negative current collector potential [V]
    	- Current collector current density
    	- Current collector current density [A.m-2]
    	- Leading-order current collector current density
    	- Sei interfacial current density
    	- Sei interfacial current density [A.m-2]
    	- Sei interfacial current density per volume [A.m-3]
    	- 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]
    	- Negative electrode exchange current density
    	- X-averaged negative electrode exchange current density
    	- Negative electrode exchange current density [A.m-2]
    	- X-averaged negative electrode exchange current density [A.m-2]
    	- Negative electrode exchange current density per volume [A.m-3]
    	- X-averaged negative electrode exchange current density per volume [A.m-3]
    	- Negative electrode reaction overpotential
    	- X-averaged negative electrode reaction overpotential
    	- Negative electrode reaction overpotential [V]
    	- X-averaged negative electrode reaction overpotential [V]
    	- Negative electrode surface potential difference
    	- X-averaged negative electrode surface potential difference
    	- Negative electrode surface potential difference [V]
    	- X-averaged negative electrode surface potential difference [V]
    	- Negative electrode sei film overpotential
    	- X-averaged negative electrode sei film overpotential
    	- Negative electrode sei film overpotential [V]
    	- X-averaged negative electrode sei film overpotential [V]
    	- Negative electrode open circuit potential
    	- Negative electrode open circuit potential [V]
    	- X-averaged negative electrode open circuit potential
    	- X-averaged negative electrode open circuit potential [V]
    	- Negative electrode entropic change
    	- X-averaged negative electrode entropic change
    	- 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]
    	- Positive electrode exchange current density
    	- X-averaged positive electrode exchange current density
    	- Positive electrode exchange current density [A.m-2]
    	- X-averaged positive electrode exchange current density [A.m-2]
    	- Positive electrode exchange current density per volume [A.m-3]
    	- X-averaged positive electrode exchange current density per volume [A.m-3]
    	- Positive electrode reaction overpotential
    	- X-averaged positive electrode reaction overpotential
    	- Positive electrode reaction overpotential [V]
    	- X-averaged positive electrode reaction overpotential [V]
    	- Positive electrode surface potential difference
    	- X-averaged positive electrode surface potential difference
    	- Positive electrode surface potential difference [V]
    	- X-averaged positive electrode surface potential difference [V]
    	- Positive electrode sei film overpotential
    	- X-averaged positive electrode sei film overpotential
    	- Positive electrode sei film overpotential [V]
    	- X-averaged positive electrode sei film overpotential [V]
    	- Positive electrode open circuit potential
    	- Positive electrode open circuit potential [V]
    	- X-averaged positive electrode open circuit potential
    	- X-averaged positive electrode open circuit potential [V]
    	- Positive electrode entropic change
    	- X-averaged positive electrode entropic change
    	- Negative electrode interfacial current density
    	- X-averaged negative electrode interfacial current density
    	- Negative electrode interfacial current density [A.m-2]
    	- X-averaged negative electrode interfacial current density [A.m-2]
    	- Negative electrode interfacial current density per volume [A.m-3]
    	- X-averaged negative electrode interfacial current density per volume [A.m-3]
    	- Positive electrode interfacial current density
    	- X-averaged positive electrode interfacial current density
    	- Positive electrode interfacial current density [A.m-2]
    	- X-averaged positive electrode interfacial current density [A.m-2]
    	- Positive electrode interfacial current density per volume [A.m-3]
    	- X-averaged positive electrode interfacial current density per volume [A.m-3]
    	- Interfacial current density
    	- Interfacial current density [A.m-2]
    	- Interfacial current density per volume [A.m-3]
    	- Exchange current density
    	- Exchange current density [A.m-2]
    	- Exchange current density per volume [A.m-3]
    	- Negative electrode oxygen interfacial current density
    	- X-averaged negative electrode oxygen interfacial current density
    	- Negative electrode oxygen interfacial current density [A.m-2]
    	- X-averaged negative electrode oxygen interfacial current density [A.m-2]
    	- Negative electrode oxygen interfacial current density per volume [A.m-3]
    	- X-averaged negative electrode oxygen interfacial current density per volume [A.m-3]
    	- Negative electrode oxygen exchange current density
    	- X-averaged negative electrode oxygen exchange current density
    	- Negative electrode oxygen exchange current density [A.m-2]
    	- X-averaged negative electrode oxygen exchange current density [A.m-2]
    	- Negative electrode oxygen exchange current density per volume [A.m-3]
    	- X-averaged negative electrode oxygen exchange current density per volume [A.m-3]
    	- Negative electrode oxygen reaction overpotential
    	- X-averaged negative electrode oxygen reaction overpotential
    	- Negative electrode oxygen reaction overpotential [V]
    	- X-averaged negative electrode oxygen reaction overpotential [V]
    	- Negative electrode oxygen open circuit potential
    	- Negative electrode oxygen open circuit potential [V]
    	- X-averaged negative electrode oxygen open circuit potential
    	- X-averaged negative electrode oxygen open circuit potential [V]
    	- Positive electrode oxygen interfacial current density
    	- X-averaged positive electrode oxygen interfacial current density
    	- Positive electrode oxygen interfacial current density [A.m-2]
    	- X-averaged positive electrode oxygen interfacial current density [A.m-2]
    	- Positive electrode oxygen interfacial current density per volume [A.m-3]
    	- X-averaged positive electrode oxygen interfacial current density per volume [A.m-3]
    	- Positive electrode oxygen exchange current density
    	- X-averaged positive electrode oxygen exchange current density
    	- Positive electrode oxygen exchange current density [A.m-2]
    	- X-averaged positive electrode oxygen exchange current density [A.m-2]
    	- Positive electrode oxygen exchange current density per volume [A.m-3]
    	- X-averaged positive electrode oxygen exchange current density per volume [A.m-3]
    	- Positive electrode oxygen reaction overpotential
    	- X-averaged positive electrode oxygen reaction overpotential
    	- Positive electrode oxygen reaction overpotential [V]
    	- X-averaged positive electrode oxygen reaction overpotential [V]
    	- Positive electrode oxygen open circuit potential
    	- Positive electrode oxygen open circuit potential [V]
    	- X-averaged positive electrode oxygen open circuit potential
    	- X-averaged positive electrode oxygen open circuit potential [V]
    	- Oxygen interfacial current density
    	- Oxygen interfacial current density [A.m-2]
    	- Oxygen interfacial current density per volume [A.m-3]
    	- Oxygen exchange current density
    	- Oxygen exchange current density [A.m-2]
    	- Oxygen exchange current density per volume [A.m-3]
    	- Negative electrode potential
    	- Negative electrode potential [V]
    	- X-averaged negative electrode potential
    	- X-averaged negative electrode potential [V]
    	- Negative electrode ohmic losses
    	- Negative electrode ohmic losses [V]
    	- X-averaged negative electrode ohmic losses
    	- X-averaged negative electrode ohmic losses [V]
    	- Gradient of negative electrode potential
    	- Negative electrode current density
    	- Negative electrode current density [A.m-2]
    	- Negative electrolyte potential
    	- Negative electrolyte potential [V]
    	- Separator electrolyte potential
    	- Separator electrolyte potential [V]
    	- Positive electrolyte potential
    	- Positive electrolyte potential [V]
    	- Electrolyte potential
    	- Electrolyte potential [V]
    	- X-averaged electrolyte potential
    	- X-averaged electrolyte potential [V]
    	- X-averaged negative electrolyte potential
    	- X-averaged negative electrolyte potential [V]
    	- X-averaged separator electrolyte potential
    	- X-averaged separator electrolyte potential [V]
    	- X-averaged positive electrolyte potential
    	- X-averaged positive electrolyte potential [V]
    	- X-averaged electrolyte overpotential
    	- X-averaged electrolyte overpotential [V]
    	- Gradient of negative electrolyte potential
    	- Gradient of separator electrolyte potential
    	- Gradient of positive electrolyte potential
    	- Gradient of electrolyte potential
    	- Electrolyte current density
    	- Electrolyte current density [A.m-2]
    	- Negative electrolyte current density
    	- Negative electrolyte current density [A.m-2]
    	- Positive electrolyte current density
    	- Positive electrolyte current density [A.m-2]
    	- X-averaged concentration overpotential
    	- X-averaged electrolyte ohmic losses
    	- X-averaged concentration overpotential [V]
    	- X-averaged electrolyte ohmic losses [V]
    	- Positive electrode potential
    	- Positive electrode potential [V]
    	- X-averaged positive electrode potential
    	- X-averaged positive electrode potential [V]
    	- Positive electrode ohmic losses
    	- Positive electrode ohmic losses [V]
    	- X-averaged positive electrode ohmic losses
    	- X-averaged positive electrode ohmic losses [V]
    	- Gradient of positive electrode potential
    	- Positive electrode current density
    	- Positive electrode current density [A.m-2]
    	- Electrode current density
    	- Positive current collector potential
    	- Positive current collector potential [V]
    	- Local voltage
    	- Local voltage [V]
    	- Terminal voltage
    	- Terminal voltage [V]
    	- X-averaged open circuit voltage
    	- Measured open circuit voltage
    	- X-averaged open circuit voltage [V]
    	- Measured open circuit voltage [V]
    	- X-averaged reaction overpotential
    	- X-averaged reaction overpotential [V]
    	- X-averaged sei film overpotential
    	- X-averaged sei film overpotential [V]
    	- X-averaged solid phase ohmic losses
    	- X-averaged solid phase ohmic losses [V]
    	- X-averaged battery open circuit voltage [V]
    	- Measured battery open circuit voltage [V]
    	- X-averaged battery reaction overpotential [V]
    	- X-averaged battery solid phase ohmic losses [V]
    	- X-averaged battery electrolyte ohmic losses [V]
    	- X-averaged battery concentration overpotential [V]
    	- Battery voltage [V]
    	- Change in measured open circuit voltage
    	- Change in measured open circuit voltage [V]
    	- Local ECM resistance
    	- Local ECM resistance [Ohm]
    	- Terminal power [W]


To help visualise the results, pybamm provides the `pybamm.ProcessedVariable` class, which takes the output of a solver and a variable, and allows the user to evaluate the value of that variable at any given time or $x$ value. These processed variables are automatically created by the solution dictionary.


```python
voltage = solution['Terminal voltage [V]']
c_s_n_surf = solution['Negative particle surface concentration']
c_s_p_surf = solution['Positive particle surface concentration']
```

One we have these variables in hand, we can begin generating plots using a library such as Matplotlib. Below we plot the terminal voltage and surface particle concentrations versus time


```python
t = solution["Time [s]"].entries
x = solution["x [m]"].entries[:, 0]
f, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(13,4))

ax1.plot(t, voltage(t))
ax1.set_xlabel(r'$Time [s]$')
ax1.set_ylabel('Terminal voltage [V]')

ax2.plot(t, c_s_n_surf(t=t, x=x[0]))  # can evaluate at arbitrary x (single representative particle)
ax2.set_xlabel(r'$Time [s]$')
ax2.set_ylabel('Negative particle surface concentration')

ax3.plot(t, c_s_p_surf(t=t, x=x[-1]))  # can evaluate at arbitrary x (single representative particle)
ax3.set_xlabel(r'$Time [s]$')
ax3.set_ylabel('Positive particle surface concentration')

plt.tight_layout()
plt.show()
```

Some of the output variables are defined over space as well as time. Once option to visualise these variables is to use the `interact` slider widget. Below we plot the negative/positive particle concentration over $r$, using a slider to change the current time point


```python
c_s_n = solution['Negative particle concentration']
c_s_p = solution['Positive particle concentration']
r_n = solution["r_n [m]"].entries[:, 0]
r_p = solution["r_p [m]"].entries[:, 0]
```


```python
c_s_n = solution['Negative particle concentration']
c_s_p = solution['Positive particle concentration']
r_n = solution["r_n [m]"].entries[:, 0, 0]
r_p = solution["r_p [m]"].entries[:, 0, 0]

def plot_concentrations(t):
    f, (ax1, ax2) = plt.subplots(1, 2 ,figsize=(10,5))
    plot_c_n, = ax1.plot(r_n, c_s_n(r=r_n,t=t,x=x[0]))  # can evaluate at arbitrary x (single representative particle)
    plot_c_p, = ax2.plot(r_p, c_s_p(r=r_p,t=t,x=x[-1]))  # can evaluate at arbitrary x (single representative particle)
    ax1.set_ylabel('Negative particle concentration')
    ax2.set_ylabel('Positive particle concentration')
    ax1.set_xlabel(r'$r_n$ [m]')
    ax2.set_xlabel(r'$r_p$ [m]')
    ax1.set_ylim(0, 1)
    ax2.set_ylim(0, 1)
    plt.show()
    
import ipywidgets as widgets
widgets.interact(plot_concentrations, t=widgets.FloatSlider(min=0,max=3600,step=10,value=0));

```


    interactive(children=(FloatSlider(value=0.0, description='t', max=3600.0, step=10.0), Output()), _dom_classes=…


The QuickPlot class can be used to plot the common set of useful outputs which should give you a good initial overview of the model. The method `Quickplot.dynamic_plot` employs the slider widget.  


```python
quick_plot = pybamm.QuickPlot(solution)
quick_plot.dynamic_plot();
```


    interactive(children=(FloatSlider(value=0.0, description='t', max=1.0, step=0.01), Output()), _dom_classes=('w…


## Dimensionless Parameters

In the table below, we provide the dimensionless parameters in the SPM in terms of the dimensional parameters in LCO.csv. We use a superscript * to indicate dimensional quantities. 

| Parameter                 | Expression                              |Interpretation                             |
|:--------------------------|:----------------------------------------|:------------------------------------------|
| $L_{\text{k}}$            | $L_{\text{k}}^*/L^*$                    | Ratio of region thickness to cell thickness|
|$\mathcal{C}_{\text{k}}$   | $\tau_{\text{k}}^*/\tau_{\text{d}}^*$   | Ratio of solid diffusion and discharge timescales |
|$\mathcal{C}_{\text{r,k}}$ |$\tau_{\text{r,k}}^*/\tau_{\text{d}}^*$  |Ratio of reaction and discharge timescales|
|$a_{R, \text{k}}$             |$a_{\text{k}}^* R_{\text{k}}^*$          | Product of particle radius and surface area to volume ratio|
|$\gamma_{\text{k}}$        |$c_{\text{k,max}}^*/c_{\text{n,max}}^*$  |Ratio of maximum lithium concentrations in solid|

<a name="ref">[1]</a> 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


```python

```

5db6220b9947efa151c069b8165c0b46eaf002c6
ipynb
Jupyter Notebook
examples/notebooks/models/SPM.ipynb
kinnala/PyBaMM
3c4ef83d1ea06287a55ceac5f25e139e54599ea9
BSD-3-Clause
examples/notebooks/models/SPM.ipynb
kinnala/PyBaMM
3c4ef83d1ea06287a55ceac5f25e139e54599ea9
BSD-3-Clause
examples/notebooks/models/SPM.ipynb
kinnala/PyBaMM
3c4ef83d1ea06287a55ceac5f25e139e54599ea9
BSD-3-Clause
Qwen/Qwen-72B
1. YES
2. YES