pybamm.BaseModel defines the structure that every PyBaMM model must follow. It stores the equation system (RHS, algebraic equations, initial and boundary conditions), the output variables, and events. Battery-specific models (lithium-ion, lead-acid, ECM) extend pybamm.BaseBatteryModel, which itself extends BaseModel.
You do not normally instantiate
BaseModel directly. Use one of the ready-made model classes such as pybamm.lithium_ion.DFN() or pybamm.lead_acid.Full().Key attributes
Equations
Right-hand side of the system of ODEs. Maps state variable expressions to their time derivatives.
Algebraic equations for DAE systems. Maps variable expressions to residuals that must equal zero.
Initial values for each state variable. Keys match those in
rhs and algebraic.Boundary conditions for PDEs. Nested dict mapping variable → boundary →
(value, type) pairs where type is "Dirichlet" or "Neumann".Named output expressions. Anything you want to access in the
Solution (e.g. sol["Terminal voltage [V]"]) must be registered here. Supports fuzzy-string lookup.A list of events (zero-crossings) that can terminate a step or the simulation. For example, a minimum voltage event.
Named sub-model components that together make up the full model. Sub-models are assembled during
build_model().Flags
Whether to provide an analytic Jacobian to the solver. Default
True. Setting to False can be useful for debugging or for very simple models.Format to which expression trees are converted before solving. Options:
None (retain PyBaMM trees), "python" (Python-evaluated), "casadi" (default, required for most solvers), "jax".True after pybamm.Discretisation has processed the model.True after pybamm.ParameterValues has processed the model.build_model()
Assemble all sub-models into the final equation system. Called automatically by pybamm.Simulation.build() and pybamm.Simulation.solve().
Serialisation
save_model() (via pybamm.Simulation)
Write a discretised model to JSON. This avoids the cost of re-building and re-discretising on subsequent runs:
BaseModel.deserialise()
Class method to restore a model from a serialised property dictionary (used internally by pybamm.load_model).
to_json()
Serialise the model (after discretisation) to a JSON-compatible dictionary. Used by the Serialise class:
Geometry and domains
PyBaMM models are defined over named domains — e.g."negative electrode", "separator", "positive electrode". Spatial variables live in these domains, and boundary conditions are applied at domain interfaces.
The geometry is described by a pybamm.Geometry dict mapping domain names to spatial extents:
model.default_geometry, model.default_submesh_types, model.default_var_pts, and model.default_spatial_methods so that pybamm.Simulation can set up the mesh automatically.