pybop.pybamm.eis_simulator#

Classes#

EISSimulator

A class to extend a PyBaMM model for EIS, automatically build/rebuild a pybamm.Simulation to obtain

Module Contents#

class pybop.pybamm.eis_simulator.EISSimulator(model: pybamm.BaseModel, f_eval: numpy.ndarray | list[float], parameter_values: pybamm.ParameterValues | None = None, initial_state: float | str | None = None, solver: pybamm.BaseSolver | None = None, geometry: pybamm.Geometry | None = None, submesh_types: dict | None = None, var_pts: dict | None = None, spatial_methods: dict | None = None, discretisation_kwargs: dict | None = None, build_every_time: bool = False)[source]#

Bases: pybop.simulators.base_simulator.BaseSimulator

A class to extend a PyBaMM model for EIS, automatically build/rebuild a pybamm.Simulation to obtain a built model which can be solved to compute the complex impedance for a given set of frequencies.

There are two contexts in which this class can be used: 1. A pybamm model can be built once and then run multiple times with different inputs. 2. A pybamm model needs to be built and then run for each set of inputs, for example in the case

where one of the inputs is a geometric parameter which requires a new mesh.

The logic for (1) and (2) occurs within the composed Simulator and happens automatically. To override this logic, the argument build_every_time can be set to True which will force (2) to occur.

Parameters:
  • model (pybamm.BaseModel) – The PyBaMM model to be used.

  • f_eval (list) – The frequencies at which to evaluate the impedance.

  • parameter_values (pybamm.ParameterValues, optional) – The parameter values to be used in the model.

  • initial_state (dict, optional) – A valid initial state, e.g. “Initial open-circuit voltage [V]” or ``”Initial SoC”`. Defaults to None, indicating that the existing initial state of charge (for an ECM) or initial concentrations (for an EChem model) will be used.

  • solver (pybamm.BaseSolver, optional) – The solver to simulate the composed Simulator. If None, uses pybop.pybamm.RecommendedSolver.

  • geometry (pybamm.Geometry, optional) – The geometry upon which to solve the model.

  • submesh_types (dict, optional) – A dictionary of the types of submesh to use on each subdomain.

  • var_pts (dict, optional) – A dictionary of the number of points used by each spatial variable.

  • spatial_methods (dict, optional) – A dictionary of the types of spatial method to use on each domain (e.g. pybamm.FiniteVolume).

  • discretisation_kwargs (dict, optional) – Any keyword arguments to pass to the Discretisation class. See pybamm.Discretisation for details.

  • build_every_time (bool, optional) – If True, the model will be rebuilt every evaluation. Otherwise, the need to rebuild will be determined automatically.

_catch_errors(inputs: list[Inputs]) list[pybop.simulators.base_simulator.Solution | pybop.simulators.failed_solution.FailedSolution][source]#
_initialise_eis_matrices(inputs: pybop.parameters.parameter.Inputs) None[source]#

Initialise the electrochemical impedance spectroscopy (EIS) simulation. This method sets up the mass matrix and solver, converts inputs to the appropriate format, extracts the necessary attributes from the model, and prepares matrices for the simulation.

Raises:

RuntimeError – If the model hasn’t been built yet.

_model_rebuild(inputs: pybop.parameters.parameter.Inputs) None[source]#

Update the parameter values and rebuild the EIS model.

_solve(inputs: pybop.parameters.parameter.Inputs) pybop.simulators.base_simulator.Solution[source]#

Run the EIS simulation to calculate impedance at all specified frequencies.

Parameters:
  • inputs (Inputs) – Input parameters.

  • calculate_sensitivities (bool) – Whether to calculate sensitivities (default: False). Currently not implemented for EIS.

Returns:

Complex impedance results.

Return type:

Solution

calculate_impedance(frequency)[source]#

Calculate the impedance for a given frequency.

This method computes the system matrix, solves the linear system, and calculates the impedance based on the solution.

Parameters:

frequency (float) – The frequency at which to calculate the impedance in Hz.

Returns:

The calculated impedance.

Return type:

complex

copy()[source]#

Return a copy of the simulation.

set_up_for_eis(model: pybamm.BaseModel) pybamm.BaseModel[source]#

Set up the model for electrochemical impedance spectroscopy (EIS) simulations. This method adds the necessary algebraic equations and variables to the model. Originally developed by pybamm-eis: pybamm-team/pybamm-eis

Parameters:

model (pybamm.BaseModel) – The PyBaMM model to be used for EIS simulations.

Returns:

The modified model ready for EIS simulations.

Return type:

pybamm.BaseModel

Raises:

ValueError – If the model is missing required variables.

solve(inputs: Inputs | list[Inputs] | None = None, calculate_sensitivities: bool = False) pybop.simulators.base_simulator.Solution | list[pybop.simulators.base_simulator.Solution][source]#

Run the EIS simulation for one or more sets of inputs and return the result(s).

Parameters:
  • inputs (Inputs | list[Inputs], optional) – Input parameters (default: None).

  • calculate_sensitivities (bool) – Whether to also return the sensitivities (default: False). Currently not implemented for EIS.

Returns:

Complex impedance results.

Return type:

Solution | list[Solution]

solve_batch(inputs: list[Inputs] = None, calculate_sensitivities: bool = False) list[pybop.simulators.base_simulator.Solution | pybop.simulators.failed_solution.FailedSolution][source]#

Run the EIS simulation for each set of inputs and return dict-like results.

Parameters:
  • inputs (list[Inputs]) – A list of input parameters.

  • calculate_sensitivities (bool) – Whether to calculate sensitivities (default: False). Currently not implemented for EIS.

Returns:

A list of len(inputs) containing the complex impedance results.

Return type:

list[Solution]

M = None#
_f_eval#
_jac = None#
_simulator#
b = None#
property debug_mode#
property has_sensitivities#
property input_parameter_names#
property parameter_values#
property simulation#
z_scale#