- Geometry — defines the physical extent of each domain
- Mesh — divides domains into nodes using a chosen submesh type
- 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:
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
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:
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:
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 aDiscretisation manually:
manual_discretisation.py
Discretisation constructor parameters: