Virtual Expo 2026

Li-ion Diffusion Modelling using FiPy

Envision Piston

Meet link P03: Li-ion Diffusion Modelling Envision Expo
Video call link: https://meet.google.com/cfs-pnga-ehi

Introduction

Lithium-ion batteries power everything from electric vehicles to consumer electronics, yet their internal behaviour during charge and discharge cannot be directly observed.

The concentration of lithium inside electrode particles, the rate at which it diffuses, and how the surface chemistry evolves over time are all quantities that must be inferred through mathematical modelling.

At the heart of every Li-ion battery model is the process of intercalation lithium ions (Li⁺) shuttle back and forth through the electrolyte, inserting into and extracting from electrode particles without permanently altering the host crystal lattice. During discharge, lithium de-intercalates from the graphite anode and intercalates into the metal-oxide cathode. During charging, the reverse occurs. The electrolyte provides an ionic conduction path, while the separator prevents short-circuiting.

Mathematical modelling provides a window into this interior that experiments alone cannot. Models can guide electrode design, reduce the number of physical prototypes required, and inform battery management systems operating in real time. This project focuses on the Single Particle Model (SPM) regime one spherical representative particle per electrode and extends it by coupling solid-phase diffusion with realistic Butler-Volmer interfacial kinetics.


Objective

  • Solve the spherical solid-phase diffusion equation numerically using FiPy and validate it against the Crank analytical solution.
  • Develop a custom finite difference PDE solver that couples solid-phase diffusion with Butler-Volmer electrode kinetics.
  • Integrate real-time interactive widgets for live parameter exploration.

 


Background: How a Li-ion Battery Works

A lithium-ion battery consists of four key components:

  • Anode:The negative electrode, typically graphite (a layered carbon material modelled as spherical particles), which absorbs and releases lithium.
  • Cathode: The positive electrode, typically a lithium metal oxide, which holds lithium ions when the battery is discharged.
  • Separator: A porous membrane between the electrodes that prevents short-circuiting while allowing ionic exchange.
  • Electrolyte: Lithium ions dissolved in an organic solvent; both electrodes are submerged in it.

The driving force for lithium movement is the chemical potential gradient lithium has a much higher electrochemical potential at the graphite anode than at the metal-oxide cathode, creating a thermodynamic driving force for it to migrate.


Governing Equations

1. Solid-Phase Diffusion: Fick's Second Law (Spherical)

Lithium ions diffuse radially inside each spherical electrode particle. 

 

2. Butler-Volmer Kinetics

The Butler-Volmer equation governs the rate of the electrochemical reaction at the electrode-electrolyte interface determining how much lithium inserts or extracts per unit time:

 

where:

  • η = φₛ − φₑ − U(θ) is the overpotential
  • i₀ = m_ref · √( cₛ(cₛ,ₘₐₓ − cₛ) · cₑ ) is the exchange current density
  • αₐ = αc = 0.5 (symmetric transfer coefficients)

The exchange current density i₀ depends on the surface concentration when the surface depletes, i₀ drops and the reaction slows, even under large applied overpotentials. This is the key coupling between solid diffusion and kinetics.

Temperature dependence of i₀ is captured via an Arrhenius correction:

 


Numerical Methods

Finite Volume Method (FVM) FiPy Solver

The FVM integrates the PDE over discrete control volumes, enforcing conservation exactly at every cell. This is critical for battery modelling where total lithium must be conserved globally.

To handle the spherical geometry, a variable substitution u = C·r is applied, transforming the spherical diffusion equation into a 1D Cartesian-like form:

∂u/∂t = D · ∂²u/∂r²

Validation: The relative L2 error against the Crank analytical solution remained below 6×10⁻³ across all six snapshot times (t = 0.1 s to t = 10 s), confirming excellent agreement.

 

 

Why FiPy Falls Short for Butler-Volmer

While FiPy performed well for the constant-flux diffusion problem, extending it to Butler-Volmer kinetics revealed three fundamental limitations that made it impractical for this next stage:

Issue Explanation
Per-step overhead FiPy's abstraction adds large Python overhead a 50×50 tridiagonal solve should take microseconds, not seconds
No native Robin BC No direct way to specify the nonlinear ∂u/∂r = u/a  (a/D)j boundary condition
Constant matrix wasted The diffusion matrix is time-independent, but FiPy rebuilds it every step; cannot pre-factorise

These limitations were only apparent once the Butler-Volmer coupling was attempted making it clear that continuing to work around FiPy's abstractions was not viable, and that a purpose-built solver was necessary.


Custom PDE Solver for Butler-Volmer Kinetics

A custom finite difference PDE solver was therefore built from scratch using NumPy and SciPy, specifically designed to handle the nonlinear Butler-Volmer boundary condition efficiently.

Discretisation

Surface Boundary Condition (Robin BC)

 

 

Algorithm (Per Timestep)

  1. Get surface concentration: csurfn = ulastn / a
  2. Compute jⁿ from Butler-Volmer equation (using csurfn, T, η from voltage inversion)
  3. Assemble the right-hand side bn (only the last entry changes each step)
  4. Solve Aun+1= bn via pre-factorised LU decomposition
  5. Update concentration: Cn+1 = un+1/r (extrapolate at centre)
  6. Log SoC, η, OCP, and surface occupancy

The key efficiency gain is that the diffusion matrix A is assembled once and LU-factorised before the time loop.

Since the matrix is time-independent, every subsequent timestep only requires a fast back-substitution, cutting per-step cost from seconds (FiPy) to microseconds.

 


Simulation Parameters


Interactive Widgets

An interactive simulation interface was built using ipywidgets, allowing real-time exploration of how physical parameters affect Li-ion insertion dynamics:

 


Key Results & Observations

  1. FiPy Validation The numerical solution matched the Crank analytical solution to within 0.06% at early times, confirming the correctness of the spherical diffusion solver and the u = C·r coordinate transformation.
  2. Concentration increases with time At any fixed radial position, concentration increases as charging progresses, consistent with a constant inward flux continuously adding mass to the particle.
  3. Radial gradient is parabolic Concentration is highest at the surface (r = a) and decreases toward the centre, a profile characteristic of diffusion driven by a constant surface flux.
  4. Butler-Volmer coupling The exchange current density i₀ is nonlinear in surface concentration, causing the reaction rate to self-limit as the surface saturates this is captured correctly in the custom solver.
  5. Computational efficiency Pre-factorising the LU matrix before the time loop reduced per-step overhead from seconds (FiPy) to microseconds, making real-time interactive simulations feasible.

Conclusions

This project successfully implemented a two-stage numerical model for Li-ion diffusion in spherical electrode particles:

  • Stage 1 (FiPy): The spherical diffusion equation was solved using FVM on a 50-cell grid and validated against the Crank analytical solution, confirming numerical accuracy and the validity of the u = C·r coordinate transformation.
  • Stage 2 (Custom Solver): A custom finite difference PDE solver was built from scratch to couple solid-phase diffusion with Butler-Volmer kinetics.
  • By using a pre-factorised LU tridiagonal method, the solver achieves microsecond-per-step performance orders of magnitude faster than FiPy for this class of nonlinear boundary condition problem.

FiPy, while excellent for general PDE problems, is unsuitable for Butler-Volmer kinetics due to excessive per-step overhead, lack of native Robin/nonlinear BC support, and inability to pre-factorise the constant matrix.

References

  1. Botte, Gerardine G., Venkat R. Subramanian, and Ralph E. White. "Mathematical modeling of secondary lithium batteries." Electrochimica Acta 45, no. 15 (2000): 2595-2609
  2. Chen, C.-H., Brosa Planella, F., O’Regan, K., Gastol, D., Widanage, W. D., & Kendrick, E. (2020). Development of Experimental Techniques for Parameterization of Multi-scale Lithium-ion Battery Models. Journal of the Electrochemical Society, *167*(8), 080534
  3. Garapati, Vamsi Krishna, Frederik Huld, Hanho Lee, Jacob Joseph Lamb. "Perspective and comparative analysis of physics-based models for sodium-ion batteries." Electrochimica Acta 514 (2025): 145573
  4. Shewmon, P. (2016). Diffusion in Solids (2nd ed.). Springer International Publishing.
  5. Battery Electrochemistry Modeling with PDEs: From Single-Particle to Full Models. MATFORGE. , https://matforge.org/battery-electrochemistry-modeling-pdes/
  6. https://www.youtube.com/playlist?list=PLAkf2LZiuWhmnZfOrLRBhe8kdVyp83Uzv Playlist by Billy wu, Dyson School of Design Engineering, Imperial College London
  7. Crank, J. (1975). The Mathematics of Diffusion (2nd ed.). Clarendon Press.

 

Report Information

Explore More Projects

View All 2026 Projects