The Finite Volume Method
How PyBaMM uses the finite volume method to discretize battery PDEs into ODEs and DAEs for numerical solution.
PyBaMM uses the Finite Volume Method (FVM) to convert systems of partial differential equations (PDEs) into systems of ordinary differential equations (ODEs) and differential algebraic equations (DAEs).
Overview
The FVM discretizes the domain into a series of "volumes" and tracks the average value of each state variable across each volume.
+------------+------------+------------+
| | | |
| u(i-1) | u(i) | u(i+1) |
| | | |
+------------+------------+------------+
^ ^ ^
x(i-1) x(i) x(i+1)
^ ^
x(i-1/2) x(i+1/2)
| |
J(i-1/2) J(i+1/2)Each volume is centered at position , with interfaces at and . The state variable represents the average of over that volume:
Flux Calculation
Fluxes at each interface are calculated via the central difference method. For the interface at , the flux is given by:
where is the harmonic mean of and .
We use the harmonic mean to find the values of transport properties at interfaces, and the arithmetic mean for other properties.
Rate of Change
The rate of change of is calculated by taking the boundary integral of the fluxes in and out of each volume:
For the 1D case, this simplifies to:
Extrapolation and Boundary Values
One important consequence of using the finite volume method is that we do not directly calculate the value of state variables at the boundaries of the domain. For example, when simulating a battery, we do not directly calculate the potential of the positive electrode at the current collector (i.e., the terminal voltage of the cell). Instead, we must extrapolate from the nearest volume.
Extrapolation Methods
Uses the value from the nearest volume directly
Linearly extrapolates from the two volumes nearest the boundary (default in PyBaMM)
Fits a quadratic polynomial to the three volumes nearest the boundary
All of these extrapolations incur some error, which depends on:
- The steepness of the state variable near the boundary
- The size of the mesh
For maximum accuracy, we recommend using the quadratic extrapolation. Linear extrapolation is the default in PyBaMM for legacy reasons.