cideMOD.helpers.miscellaneous

miscellaneous.py involves all the auxiliary functions which dosen’t belong to any class.

Functions

get_spline(data, spline_type = “not-a-knot”)

Functions

add_to_results_folder(save_path, files[, ...])

Add the given files to the results folder.

analyze_jacobian(J, fields)

constant_expression(expression[, return_fenics])

Evaluates expression with given arguments

format_time(timespan[, small])

generate_CV_txt(fname[, v_max, v_min, ...])

generate_class_name(name[, prefix, suffix])

This method returns a valid class name from the given one.

get_spline(data[, spline_type, return_fenics])

This function adapts the CubicSpline of scipy package to the UFL classes type.

hysteresis_property(property)

init_results_folder(case_name[, overwrite, ...])

Function to initialize the results folder.

plot_jacobian(problem, x, J[, filename, ...])

plot_list_variable(x, y[, name, save_path, ...])

This function plots y values in x axis.

plot_ocps(problem[, dpi])

Plots the OCVs comparing the splines used with the interpolated data

plot_ocvs(problem[, dpi])

read_input_data(filename[, init_line])

refine_ocp(data[, tol])

Refine the OCP dataset to shorten the number of data points

save_plot([filename, suffix, isuffix, ...])

Classes

ParsedList([iterable])

Container abstracting a list of elements of some specific types.

class cideMOD.helpers.miscellaneous.ParsedList(iterable=None)[source]

Bases: list, ABC

Container abstracting a list of elements of some specific types.

append(value)[source]

Append object to the end of the list.

copy()[source]

Return a shallow copy of the list.

extend(value)[source]

Extend list by appending elements from the iterable.

insert(index, value)[source]

Insert object before index.

cideMOD.helpers.miscellaneous.add_to_results_folder(save_path, files, filenames=None, comm=None, overwrite=False)[source]

Add the given files to the results folder.

Parameters:
  • save_path (str) – Path to the results folder.

  • files (List[Union[str, dict]]) – Files to be saved. Could be the path to an existing file that will be copied or a dictionary that will be saved as a json file.

  • filenames (Optional[List[str]]) – List containing the name of the files.

  • comm (Optional[MPI.Intracomm]) – MPI intracommunicator for parallel computing. Default to None.

  • overwrite (bool, optional) – Switch for overwriting an existing file. Default to False.

cideMOD.helpers.miscellaneous.analyze_jacobian(J, fields)[source]
cideMOD.helpers.miscellaneous.constant_expression(expression, return_fenics=True, **kwargs)[source]

Evaluates expression with given arguments

Parameters:
  • expression (str) – String form of the expression in python syntax.

  • return_fenics (bool, optional) – Whether or not to return a spline which result is a dolfinx object.

  • **kwargs (dict) – variables to replace inside the expression.

Returns:

value – Evaluation of the expression or constant given.

Return type:

Float, Constant

cideMOD.helpers.miscellaneous.format_time(timespan, small=True)[source]
cideMOD.helpers.miscellaneous.generate_CV_txt(fname: str, v_max=4.2, v_min=2.8, v_rate=0.001, v_init=None, dT=1)[source]
cideMOD.helpers.miscellaneous.generate_class_name(name: str, prefix: str = '', suffix: str = '')[source]

This method returns a valid class name from the given one.

Parameters:
  • name (str) – Initial name from which the class name will be generated. It must be a valid identifier.

  • prefix (str) – Prefix of the class name.

  • suffix (str) – Suffix of the class name.

Examples

>>> generate_class_name('electrode', suffix='Parameters')
'ElectrodeParameters'
>>> generate_class_name('active_material', suffix='Parser')
'ActiveMaterialParser'
>>> generate_class_name('SEI', prefix= 'ModelOptions')
'ModelOptionsSEI'
cideMOD.helpers.miscellaneous.get_spline(data, spline_type='Akima1D', return_fenics=True)[source]

This function adapts the CubicSpline of scipy package to the UFL classes type.

It gets the spline coefficients and uses them for computing the spline in a given point, y.

Parameters:
  • data (array [x_vector, y_vector]) – Data in array form, the first column is the x values, and the second column is the function value for x.

  • spline_type (str, optional) – If ‘Akima1D’ use scipy.interpolate.Akima1DInterpolator Else spline type for the scipy.interpolate.CubicSpline. See scipy documentation for more types, by default “not-a-knot”.

  • return_fenics (bool, optional) – Whether or not to return a spline which result is a dolfinx object.

Returns:

Spline expression.

Return type:

UFL Expression

Raises:

ValueError – ‘Unknown type of spline’

cideMOD.helpers.miscellaneous.hysteresis_property(property: dict)[source]
cideMOD.helpers.miscellaneous.init_results_folder(case_name, overwrite=False, copy_files: list = [], filenames: list = [], prefix='results_', comm: mpi4py.MPI.Intracomm | None = None, verbose=True)[source]

Function to initialize the results folder.

Parameters:
  • case_name (str) – String containing the case name.

  • overwrite (bool, optional) – Switch for overwriting an existing case_name, by default False.

  • copy_files (List[Union[str, dict]]) – Files to be saved. Could be the path to an existing file that will be copied or a dictionary that will be saved as a json file.

  • filenames (Optional[List[str]]) – List containing the name of the files.

  • comm (Optional[MPI.Intracomm]) – MPI intracommunicator for parallel computing. Default to None.

  • verbose (bool) – Whether or not to print the save path.

Returns:

Complete saving path.

Return type:

str

cideMOD.helpers.miscellaneous.plot_jacobian(problem, x, J, filename='J', save_path='', extension='.png', overwrite=False, save_fig=True)[source]
cideMOD.helpers.miscellaneous.plot_list_variable(x, y, name='plot', save_path='.', show=False, hide_ax_tick_labels=False, label_axes=True, title='', hide_axis=False, xlabel='x', ylabel='y', ymin=None, ymax=None, xmin=None, xmax=None, i_app=None, data_path=None, save=True, ref='', close=True, fig_kwargs={})[source]

This function plots y values in x axis.

Parameters:
  • x (list) – List values for x axis.

  • y (list) – List values for y axis.

  • name (str) – Saving image file name.

  • save_path (str) – Saving path.

  • show (bool, optional) – Switch for showing the figure, by default True

  • hide_ax_tick_labels (bool, optional) – Switch for hiding the axis tick labels, by default False

  • label_axes (bool, optional) – Switch for writing the axis labels, by default True

  • title (str, optional) – Plot title, by default ‘’

  • hide_axis (bool, optional) – Switch for hiding the axis, by default False

  • xlabel (str, optional) – X label name, by default ‘x’

  • ylabel (str, optional) – Y label name, by default ‘y’

cideMOD.helpers.miscellaneous.plot_ocps(problem, dpi=150)[source]

Plots the OCVs comparing the splines used with the interpolated data

Parameters:
  • problem – Problem class

  • dpi (float, optional) – resolution of the plot

Returns:

N/A

cideMOD.helpers.miscellaneous.plot_ocvs(problem, dpi=150)[source]
cideMOD.helpers.miscellaneous.read_input_data(filename, init_line=0)[source]
cideMOD.helpers.miscellaneous.refine_ocp(data, tol=0.005)[source]

Refine the OCP dataset to shorten the number of data points

Parameters:
  • data (numpy.dnarray) – the ocp data of shape (n,2)

  • tol (float, optional) – the maximum error allowed in V. Defaults to 5e-3.

Returns:

the refined data if was possible to refine the OCP otherwise,

returns the original data

Return type:

numpy.ndarray

cideMOD.helpers.miscellaneous.save_plot(filename='plot', suffix='', isuffix='_v{i}', extension='.png', foldername='', overwrite=False)[source]