pybop.models.base_model#
Classes#
A base class for constructing and simulating models using PyBaMM. |
|
The current state of a time series model that is a pybamm model. |
Module Contents#
- class pybop.models.base_model.BaseModel(name='Base Model', parameter_set=None)[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 behaviour.
- _check_params(inputs: pybop.parameters.parameter.Inputs = None, allow_infeasible_solutions: bool = True)[source]#
A compatibility check for the model parameters which can be implemented by subclasses if required, otherwise it returns True by default.
- Parameters:
inputs (Inputs) – The input parameters for the simulation.
allow_infeasible_solutions (bool, optional) – If True, infeasible parameter values will be allowed in the optimisation (default: True).
- Returns:
A boolean which signifies whether the parameters are compatible.
- Return type:
bool
- abstract approximate_capacity(inputs: pybop.parameters.parameter.Inputs)[source]#
Calculate a new estimate for the nominal capacity based on the theoretical energy density and an average voltage.
This method must be implemented by subclasses.
- Parameters:
inputs (Inputs) – The parameters that are the inputs of the model.
- Raises:
NotImplementedError – If the method has not been implemented by the subclass.
- build(dataset: pybop.Dataset = None, parameters: pybop.Parameters | Dict = None, check_model: bool = True, init_soc: float = None) 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 discretisation if needed, and prepares the model for simulations.
- Parameters:
dataset (pybamm.Dataset, optional) – The dataset to be used in the model construction.
parameters (pybop.Parameters or Dict, optional) – A pybop Parameters class or 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.
- abstract cell_mass(parameter_set: pybop.ParameterSet = None)[source]#
Calculate the cell mass in kilograms.
This method must be implemented by subclasses.
- Parameters:
parameter_set (dict, optional) – A dictionary containing the parameter values necessary for the mass calculations.
- Raises:
NotImplementedError – If the method has not been implemented by the subclass.
- abstract cell_volume(parameter_set: pybop.ParameterSet = None)[source]#
Calculate the cell volume in m3.
This method must be implemented by subclasses.
- Parameters:
parameter_set (dict, optional) – A dictionary containing the parameter values necessary for the volume calculation.
- Raises:
NotImplementedError – If the method has not been implemented by the subclass.
- check_params(inputs: pybop.parameters.parameter.Inputs = None, parameter_set: pybop.ParameterSet = None, allow_infeasible_solutions: bool = True)[source]#
Check compatibility of the model parameters.
- Parameters:
inputs (Inputs) – The input parameters for the simulation.
allow_infeasible_solutions (bool, optional) – If True, infeasible parameter values will be allowed in the optimisation (default: True).
- Returns:
A boolean which signifies whether the parameters are compatible.
- Return type:
bool
- classify_and_update_parameters(parameters: pybop.Parameters)[source]#
Update the parameter values according to their classification as either ‘rebuild_parameters’ which require a model rebuild and ‘standard_parameters’ which do not.
- Parameters:
parameters (pybop.Parameters)
- get_state(inputs: pybop.parameters.parameter.Inputs, t: float, x: numpy.ndarray) TimeSeriesState[source]#
Returns the given state for the problem (inputs are assumed constant since last reinit)
- predict(inputs: pybop.parameters.parameter.Inputs = None, t_eval: numpy.array = None, parameter_set: pybop.ParameterSet = None, experiment: pybop.Experiment = None, init_soc: float = None) Dict[str, numpy.ndarray[numpy.float64]][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 (Inputs, optional) – Input parameters for the simulation. 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.
- rebuild(dataset: pybop.Dataset = None, parameters: pybop.Parameters | Dict = None, parameter_set: pybop.ParameterSet = None, check_model: bool = True, init_soc: float = None) None[source]#
Rebuild the PyBaMM model for a given parameter set.
This method requires the self.build() method to be called first, and then rebuilds the model for a given parameter set. Specifically, this method applies the given parameters, sets up the mesh and discretisation if needed, and prepares the model for simulations.
- Parameters:
dataset (pybamm.Dataset, optional) – The dataset to be used in the model construction.
parameters (pybop.Parameters or Dict, optional) – A pybop Parameters class or dictionary containing parameter values to apply to the model.
parameter_set (pybop.parameter_set, optional) – A PyBOP parameter set object or a dictionary containing the parameter values
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.
- reinit(inputs: pybop.parameters.parameter.Inputs, t: float = 0.0, x: numpy.ndarray | None = None) TimeSeriesState[source]#
Initialises the solver with the given inputs and returns the initial state of the problem
- set_init_soc(init_soc: float)[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(rebuild=False)[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: pybop.parameters.parameter.Inputs, t_eval: numpy.array) Dict[str, numpy.ndarray[numpy.float64]][source]#
Execute the forward model simulation and return the result.
- Parameters:
inputs (Inputs) – The input parameters for the simulation.
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: pybop.parameters.parameter.Inputs, t_eval: numpy.array)[source]#
Perform the forward model simulation with sensitivities.
- Parameters:
inputs (Inputs) – The input parameters for the simulation.
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.
- step(state: TimeSeriesState, time: numpy.ndarray) TimeSeriesState[source]#
Step forward in time from the given state until the given time.
- Parameters:
state (TimeSeriesState) – The current state of the model
time (np.ndarray) – The time to simulate the system until (in whatever time units the model is in)