PyBaMM icon indicating copy to clipboard operation
PyBaMM copied to clipboard

Clarify definition of PyBaMM's SPMe

Open brosaplanella opened this issue 1 year ago • 6 comments

The definition of the SPMe remains a sticking point in PyBaMM. Even though the cited article for its definition is the Marquis et al (2019) paper, the actual implementation is a bit different (more accurate) as some terms have been "unlinearised"*. As part of improving the Creating Models notebooks (#3844) I wanted to write a BasicSPMe file and document the SPMe definition better. However, I have also noticed that the current approach falls somewhat in the middle: some terms are unlinearised and some are not. The marginal cost of doing the SPMe fully "unlinearised". All this discussion pertains to composite_conductivity.py

*by "unlinearised" I mean that some terms in the asymptotic expansion get later grouped again in their nonlinear form.

Current implementation

\phi_\mathrm{e,const} = - \overline{\Delta \phi}_\mathrm{n} + \overline{\phi}_\mathrm{n}  - \left[ \chi(\overline{c}_\mathrm{e}) \frac{R T}{F} \frac{1}{L_\mathrm{n}} \int_0^{L_\mathrm{n}} \log \left(\frac{c_\mathrm{e,n}}{\overline c_\mathrm{e}} \right) \mathrm{d} x - i_\mathrm{app} L_\mathrm{n} \left(\frac{1}{3 \kappa_\mathrm{e,eff} (\overline{c}_\mathrm{e,n})} - \frac{1}{\kappa_\mathrm{e,eff} (\overline{c}_\mathrm{e,s})} \right)\right]
\phi_\mathrm{e,n} = \phi_\mathrm{e,const}  + \chi(\overline{c}_\mathrm{e,n}) \frac{R T}{F} \log \left( \frac{c_\mathrm{e,n}}{\overline{c}_\mathrm{e}} \right) - \frac{i_\mathrm{app}}{\kappa_\mathrm{e,eff} (\overline{c}_\mathrm{e,n})} \frac{x_\mathrm{n}^2 - L_\mathrm{n}^2}{2 L_\mathrm{n}} - \frac{i_\mathrm{app} L_\mathrm{n}}{\kappa_\mathrm{e,eff} (\overline{c}_\mathrm{e,s})}
\phi_\mathrm{e,s} = \phi_\mathrm{e,const}  + \chi(\overline{c}_\mathrm{e,s}) \frac{R T}{F} \log \left( \frac{c_\mathrm{e,s}}{\overline{c}_\mathrm{e}} \right) - \frac{i_\mathrm{app} x_\mathrm{s}}{\kappa_\mathrm{e,eff} (\overline{c}_\mathrm{e,s})}
\phi_\mathrm{e,p} = \phi_\mathrm{e,const}  + \chi(\overline{c}_\mathrm{e,p}) \frac{R T}{F} \log \left( \frac{c_\mathrm{e,p}}{\overline{c}_\mathrm{e}} \right) - \frac{i_\mathrm{app} }{\kappa_\mathrm{e,eff} (\overline{c}_\mathrm{e,p})} \frac{x_\mathrm{p} (2 L_x - x_\mathrm{p}) + L_\mathrm{p}^2 - L_x^2}{2 L_\mathrm{p}}

Proposed implementation

\phi_\mathrm{e,const} = - \overline{\Delta \phi}_\mathrm{n} + \overline{\phi}_\mathrm{n}  - \frac{R T}{F} \frac{1}{L_\mathrm{n}}  \int_0^{L_\mathrm{n}} \int_0^x \chi(c_\mathrm{e,n}) \frac{\partial \log c_\mathrm{e,n}}{\partial s} \mathrm{d} s \mathrm{d} x + \frac{1}{L_\mathrm{n}} \int_0^{L_\mathrm{n}} \int_0^x \frac{i_\mathrm{e,n}}{\kappa_\mathrm{e,eff}(c_\mathrm{e,n})} \mathrm{d} s \mathrm{d} x
\phi_\mathrm{e,n} = \phi_\mathrm{e,const}  + \frac{R T}{F} \int_0^x \chi(c_\mathrm{e,n}) \frac{\partial \log c_\mathrm{e,n}}{\partial s} \mathrm{d} s - \int_0^x \frac{i_\mathrm{e,n}}{\kappa_\mathrm{e,eff}(c_\mathrm{e,n})} \mathrm{d} s
\phi_\mathrm{e,s} = \phi_\mathrm{e,n} ( x = L_\mathrm{n}) + \frac{R T}{F} \int_{L_\mathrm{n}}^x \chi(c_\mathrm{e,s}) \frac{\partial \log c_\mathrm{e,s}}{\partial s} \mathrm{d} s - \int_{L_\mathrm{n}}^x \frac{i_\mathrm{e,s}}{\kappa_\mathrm{e,eff}(c_\mathrm{e,s})} \mathrm{d} s
\phi_\mathrm{e,p} =  \phi_\mathrm{e,s} ( x = L_x - L_\mathrm{p}) + \frac{R T}{F} \int_{L_x - L_\mathrm{p}}^x \chi(c_\mathrm{e,p}) \frac{\partial \log c_\mathrm{e,p}}{\partial s} \mathrm{d} s - \int_{L_x - L_\mathrm{p}}^x \frac{i_\mathrm{e,p}}{\kappa_\mathrm{e,eff}(c_\mathrm{e,p})} \mathrm{d} s

I suggest moving to this version, which I believe is the most general one (I have dropped T dependence from parameters for simplicity, but will be accounted for). The version is taken from Brosa Planella & Widanage (2022), but the derivation is not explained with a lot of detail as the focus was the side reaction. My older paper Brosa Planella et al (2021) has a lot more detail but still assumes $\chi$ to be constant. This would make the integrated conductivity model redundant so we can get rid of it.

brosaplanella avatar Jul 17 '24 19:07 brosaplanella

Sounds good to me

valentinsulzer avatar Jul 18 '24 16:07 valentinsulzer

Me too, thanks!

rtimms avatar Jul 26 '24 13:07 rtimms

@rtimms @brosaplanella Is there now a quick win here by documenting that PyBaMM implements SPMe according to BPX v1.0? Are there any features that we wrote in for BPX where PyBaMM might deviate?

ejfdickinson avatar Jul 16 '25 14:07 ejfdickinson

@brosaplanella Could I ask if there is any intention to progress this issue or its associated PR? The ambiguous alignment between the PyBaMM implementation and any specific published set of equations (including BPX v1.0) remains a bit of a hassle for us when we are benchmarking between different open- and closed-source solvers.

ejfdickinson avatar Aug 20 '25 10:08 ejfdickinson

Hi! Sorry for the late response. The implementation in the branch I was working on works for the standard SPMe but there were some issues with the model with capacitances. Unfortunately quite some stuff came up, so it fell down my priority list. Happy to take another look in the next few weeks.

Are the definitions in the first post of the thread in line with what you have in BPX?

brosaplanella avatar Aug 28 '25 09:08 brosaplanella

@brosaplanella The BPX v1.0 definitions are now public, so I suggest you check directly with the latest document (n.b. bugs as noted above), @rtimms has a foot in both camps and has drafted this, so I think he'll be able to give a better/faster answer than I can, but I think the presumption is that PyBaMM compliance with the standard should require minimal effort at the PyBaMM side!

ejfdickinson avatar Aug 28 '25 11:08 ejfdickinson