Experiment step functions#

The following functions can be used to define steps in an experiment.

pybamm.step.string(string, **kwargs)#

Create a step from a string.

Parameters:
  • string (str) – The string to parse. Each operating condition should be of the form “Do this for this long” or “Do this until this happens”. For example, “Charge at 1 C for 1 hour”, or “Charge at 1 C until 4.2 V”, or “Charge at 1 C for 1 hour or until 4.2 V”. The instructions can be of the form “(Dis)charge at x A/C/W”, “Rest”, or “Hold at x V until y A”. The running time should be a time in seconds, minutes or hours, e.g. “10 seconds”, “3 minutes” or “1 hour”. The stopping conditions should be a circuit state, e.g. “1 A”, “C/50” or “3 V”.

  • **kwargs – Any other keyword arguments are passed to the pybamm.step._Step class.

Returns:

A step parsed from the string.

Return type:

pybamm.step._Step

pybamm.step.current(value, **kwargs)#

Create a current-controlled step. Current is positive for discharge and negative for charge.

Parameters:
  • value (float) – The current value in A. It can be a number or a 2-column array (for drive cycles).

  • **kwargs – Any other keyword arguments are passed to the pybamm.step._Step class.

Returns:

A current-controlled step.

Return type:

pybamm.step._Step

pybamm.step.voltage(value, **kwargs)#

Create a voltage-controlled step. Voltage should always be positive.

Parameters:
  • value (float) – The voltage value in V. It can be a number or a 2-column array (for drive cycles).

  • **kwargs – Any other keyword arguments are passed to the pybamm.step._Step class.

Returns:

A voltage-controlled step.

Return type:

pybamm.step._Step

pybamm.step.power(value, **kwargs)#

Create a power-controlled step. Power is positive for discharge and negative for charge.

Parameters:
  • value (float) – The power value in W. It can be a number or a 2-column array (for drive cycles).

  • **kwargs – Any other keyword arguments are passed to the pybamm.step._Step class.

Returns:

A power-controlled step.

Return type:

pybamm.step._Step

pybamm.step.resistance(value, **kwargs)#

Create a resistance-controlled step. Resistance is positive for discharge and negative for charge.

Parameters:
  • value (float) – The resistance value in Ohm. It can be a number or a 2-column array (for drive cycles).

  • **kwargs – Any other keyword arguments are passed to the pybamm.step._Step class.

Returns:

A resistance-controlled step.

Return type:

pybamm.step._Step

These functions return the following step class, which is not intended to be used directly:

class pybamm.step._Step(typ, value, duration=None, termination=None, period=None, temperature=None, tags=None, start_time=None, description=None)#

Class representing one step in an experiment. All experiment steps are functions that return an instance of this class. This class is not intended to be used directly.

Parameters:
  • typ (str) – The type of step, can be “current”, “voltage”, “c_rate”, “power”, or “resistance”.

  • value (float) – The value of the step, corresponding to the type of step. Can be a number, a 2-tuple (for cccv_ode), or a 2-column array (for drive cycles)

  • duration (float, optional) – The duration of the step in seconds.

  • termination (str or list, optional) – A string or list of strings indicating the condition(s) that will terminate the step. If a list, the step will terminate when any of the conditions are met.

  • period (float or string, optional) – The period of the step. If a float, the value is in seconds. If a string, the value should be a valid time string, e.g. “1 hour”.

  • temperature (float or string, optional) – The temperature of the step. If a float, the value is in Kelvin. If a string, the value should be a valid temperature string, e.g. “25 oC”.

  • tags (str or list, optional) – A string or list of strings indicating the tags associated with the step.

  • datetime (str or datetime, optional) – A string or list of strings indicating the tags associated with the step.

  • description (str, optional) – A description of the step.

basic_repr()#

Return a basic representation of the step, only with type, value, termination and temperature, which are the variables involved in processing the model. Also used for hashing.

to_dict()#

Convert the step to a dictionary.

Returns:

A dictionary containing the step information.

Return type:

dict

Step terminations#

Standard step termination events are implemented by the following classes, which are called when the termination is specified by a specific string. These classes can be either be called directly or via the string format specified in the class docstring

class pybamm.step.CrateTermination(value)#

Termination based on C-rate, created when a string termination of the C-rate type (e.g. “C/10”) is provided

Extends: pybamm.experiment.step.step_termination.BaseTermination

get_event(variables, step_value)#

See BaseTermination.get_event()

class pybamm.step.CurrentTermination(value)#

Termination based on current, created when a string termination of the current type (e.g. “1A”) is provided

Extends: pybamm.experiment.step.step_termination.BaseTermination

get_event(variables, step_value)#

See BaseTermination.get_event()

class pybamm.step.VoltageTermination(value)#

Termination based on voltage, created when a string termination of the voltage type (e.g. “4.2V”) is provided

Extends: pybamm.experiment.step.step_termination.BaseTermination

get_event(variables, step_value)#

See BaseTermination.get_event()

The following classes can be used to define custom terminations for an experiment step:

class pybamm.step.BaseTermination(value)#

Base class for a termination event for an experiment step. To create a custom termination, a class must implement get_event to return a pybamm.Event corresponding to the desired termination. In most cases the class pybamm.step.CustomTermination can be used to assist with this.

Parameters:

value (float) – The value at which the event is triggered

get_event(variables, step_value)#

Return a pybamm.Event object corresponding to the termination event

Parameters:
  • variables (dict) – Dictionary of model variables, to be used for selecting the variable(s) that determine the event

  • step_value (float or pybamm.Symbol) – Value of the step for which this is a termination event, to be used in some cases to determine the sign of the event.

class pybamm.step.CustomTermination(name, event_function)#

Define a custom termination event using a function. This can be used to create an event based on any variable in the model.

Parameters:
  • name (str) – Name of the event

  • event_function (callable) – A function that takes in a dictionary of variables and evaluates the event value. Must be positive before the event is triggered and zero when the event is triggered.

Example

Add a cut-off based on negative electrode stoichiometry. The event will trigger when the negative electrode stoichiometry reaches 10%.

>>> def neg_stoich_cutoff(variables):
...    return variables["Negative electrode stoichiometry"] - 0.1
>>> neg_stoich_termination = pybamm.step.CustomTermination(
...    name="Negative stoichiometry cut-off", event_function=neg_stoich_cutoff
... )

Extends: pybamm.experiment.step.step_termination.BaseTermination

get_event(variables, step_value)#

See BaseTermination.get_event()