Skip to main content
PyBaMM solves PDEs by discretising them spatially before handing the resulting ODE/DAE system to a time-integrator. The spatial pipeline has three layers:
  1. Geometry — defines the physical extent of each domain
  2. Mesh — divides domains into nodes using a chosen submesh type
  3. Spatial method — turns symbolic differential operators (pybamm.grad, pybamm.div) into matrices acting on the mesh

Battery geometry

For standard battery models, use the convenience function:
battery_geometry() returns a pybamm.Geometry dict whose structure is:
You can also build a pybamm.Geometry by hand:

Submesh types

A submesh divides a single domain into nodes. PyBaMM provides four 1-D submesh classes:

Uniform1DSubMesh

Uniform node spacing. The default for all battery domains.

Exponential1DSubMesh

Nodes clustered toward one or both boundaries — useful for thin SEI layers.

Chebyshev1DSubMesh

Chebyshev-cosine node distribution — tighter at boundaries.

UserSupplied1DSubMesh

Arbitrary node positions you supply as an array.

Exponential submesh parameters

Pass extra parameters by wrapping with pybamm.MeshGenerator:

User-supplied submesh

UserSupplied1DSubMesh validates that len(edges) == npts + 1 and that the endpoints match the geometry limits.

Available spatial methods

FiniteVolume

pybamm.FiniteVolume is the default for all 1-D domains. It implements cell-centred finite volumes and supports an optional extrapolation option:

SpectralVolume

pybamm.SpectralVolume is a higher-order method that subdivides each finite volume into Chebyshev control volumes. It must be paired with pybamm.SpectralVolume1DSubMesh:
The order argument controls the number of sub-cells per spectral volume (default is 2).

ScikitFiniteElement

pybamm.ScikitFiniteElement is used for 2-D current collector problems (dimensionality=2):
ScikitFiniteElement requires the optional pybamm[scikit-fem] extra to be installed.

Building a mesh

pybamm.Mesh takes the geometry, a submesh_types dict, and a var_pts dict:
build_mesh.py

Controlling resolution with var_pts

var_pts maps spatial variable names (strings or pybamm.SpatialVariable objects) to the number of nodes:
Default values for battery models (BaseBatteryModel.default_var_pts):

Passing custom spatial methods to Simulation

pybamm.Simulation accepts submesh_types, var_pts, and spatial_methods directly:
custom_spatial.py

Discretisation object

For lower-level control, build a Discretisation manually:
manual_discretisation.py
Discretisation constructor parameters:
The "macroscale" key in spatial_methods is a shortcut that simultaneously sets "negative electrode", "separator", and "positive electrode" to the same method.