Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.ionworks.com/llms.txt

Use this file to discover all available pages before exploring further.

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 uu 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 viv_i is centered at position xix_i, with interfaces at xi12x_{i-\frac{1}{2}} and xi+12x_{i+\frac{1}{2}}. The state variable uiu_i represents the average of uu over that volume: ui=1viΩuu_i = \frac{1}{v_i} \int_\Omega u

Flux Calculation

Fluxes at each interface are calculated via the central difference method. For the interface at xi12x_{i-\frac{1}{2}}, the flux Ji12J_{i-\frac{1}{2}} is given by: Ji12=Di12uiui1xixi1J_{i-\frac{1}{2}} = D_{i-\frac{1}{2}} \frac{u_i - u_{i-1}}{x_i - x_{i-1}} where Di12D_{i-\frac{1}{2}} is the harmonic mean of DiD_i and Di1D_{i-1}.
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 uiu_i is calculated by taking the boundary integral of the fluxes in and out of each volume: duidt=1viN(u)ndS\frac{du_i}{dt} = \frac{1}{v_i} \oint N(u) \cdot \mathbf{n} \, dS For the 1D case, this simplifies to: duidt=Ji12Ji+12Δxi\frac{du_i}{dt} = \frac{J_{i-\frac{1}{2}} - J_{i+\frac{1}{2}}}{\Delta x_i}

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

Constant

Uses the value from the nearest volume directly

Linear

Linearly extrapolates from the two volumes nearest the boundary (default in PyBaMM)

Quadratic

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.