pybop.models.base_model#

Module Contents#

Classes#

BaseModel

A base class for constructing and simulating models using PyBaMM.

class pybop.models.base_model.BaseModel(name='Base Model')[source]#

A base class for constructing and simulating models using PyBaMM.

This class serves as a foundation for building specific models in PyBaMM. It provides methods to set up the model, define parameters, and perform simulations. The class is designed to be subclassed for creating models with custom behavior.

property built_model[source]#
property geometry[source]#
property mesh[source]#
property model_with_set_params[source]#
property parameter_set[source]#
property solver[source]#
property spatial_methods[source]#
property submesh_types[source]#
property var_pts[source]#
build(dataset=None, parameters=None, check_model=True, init_soc=None)[source]#

Construct the PyBaMM model if not already built, and set parameters.

This method initializes the model components, applies the given parameters, sets up the mesh and discretization if needed, and prepares the model for simulations.

Parameters:
  • dataset (pybamm.Dataset, optional) – The dataset to be used in the model construction.

  • parameters (dict, optional) – A dictionary containing parameter values to apply to the model.

  • check_model (bool, optional) – If True, the model will be checked for correctness after construction.

  • init_soc (float, optional) – The initial state of charge to be used in simulations.

predict(inputs=None, t_eval=None, parameter_set=None, experiment=None, init_soc=None)[source]#

Solve the model using PyBaMM’s simulation framework and return the solution.

This method sets up a PyBaMM simulation by configuring the model, parameters, experiment (if any), and initial state of charge (if provided). It then solves the simulation and returns the resulting solution object.

Parameters:
  • inputs (dict or array-like, optional) – Input parameters for the simulation. If the input is array-like, it is converted to a dictionary using the model’s fitting keys. Defaults to None, indicating that the default parameters should be used.

  • t_eval (array-like, optional) – An array of time points at which to evaluate the solution. Defaults to None, which means the time points need to be specified within experiment or elsewhere.

  • parameter_set (pybamm.ParameterValues, optional) – A PyBaMM ParameterValues object or a dictionary containing the parameter values to use for the simulation. Defaults to the model’s current ParameterValues if None.

  • experiment (pybamm.Experiment, optional) – A PyBaMM Experiment object specifying the experimental conditions under which the simulation should be run. Defaults to None, indicating no experiment.

  • init_soc (float, optional) – The initial state of charge for the simulation, as a fraction (between 0 and 1). Defaults to None.

Returns:

The solution object returned after solving the simulation.

Return type:

pybamm.Solution

Raises:

ValueError – If the model has not been configured properly before calling this method or if PyBaMM models are not supported by the current simulation method.

set_init_soc(init_soc)[source]#

Set the initial state of charge for the battery model.

Parameters:

init_soc (float) – The initial state of charge to be used in the model.

set_params()[source]#

Assign the parameters to the model.

This method processes the model with the given parameters, sets up the geometry, and updates the model instance.

simulate(inputs, t_eval)[source]#

Execute the forward model simulation and return the result.

Parameters:
  • inputs (dict or array-like) – The input parameters for the simulation. If array-like, it will be converted to a dictionary using the model’s fit keys.

  • t_eval (array-like) – An array of time points at which to evaluate the solution.

Returns:

The simulation result corresponding to the specified signal.

Return type:

array-like

Raises:

ValueError – If the model has not been built before simulation.

simulateS1(inputs, t_eval)[source]#

Perform the forward model simulation with sensitivities.

Parameters:
  • inputs (dict or array-like) – The input parameters for the simulation. If array-like, it will be converted to a dictionary using the model’s fit keys.

  • t_eval (array-like) – An array of time points at which to evaluate the solution and its sensitivities.

Returns:

A tuple containing the simulation result and the sensitivities.

Return type:

tuple

Raises:

ValueError – If the model has not been built before simulation.