Previous topic

Post-Process Variables

Next topic

Simulation

This Page

Utility functions

pybamm.get_infinite_nested_dict()[source]

Return a dictionary that allows infinite nesting without having to define level by level.

See: https://stackoverflow.com/questions/651794/whats-the-best-way-to-initialize-a-dict-of-dicts-in-python/652226#652226

Example

>>> import pybamm
>>> d = pybamm.get_infinite_nested_dict()
>>> d["a"] = 1
>>> d["a"]
1
>>> d["b"]["c"]["d"] = 2
>>> d["b"]["c"] == {"d": 2}
True
pybamm.load_function(filename)[source]

Load a python function from a file “function_name.py” called “function_name”. The filename might either be an absolute path, in which case that specific file will be used, or the file will be searched for relative to PyBaMM root.

Parameters:filename (str) – The name of the file containing the function of the same name.
Returns:The python function loaded from the file.
Return type:function
pybamm.rmse(x, y)[source]

Calculate the root-mean-square-error between two vectors x and y, ignoring NaNs

pybamm.root_dir()[source]

return the root directory of the PyBaMM install directory

class pybamm.Timer[source]

Provides accurate timing.

Example

timer = pybamm.Timer() print(timer.format(timer.time()))

format(time=None)[source]

Formats a (non-integer) number of seconds, returns a string like “5 weeks, 3 days, 1 hour, 4 minutes, 9 seconds”, or “0.0019 seconds”.

Parameters:time (float, optional) – The time to be formatted.
Returns:The string representation of time in human-readable form.
Return type:string
reset()[source]

Resets this timer’s start time.

time()[source]

Returns the time (float, in seconds) since this timer was created, or since meth:reset() was last called.