src.friction_calibration module

class src.friction_calibration.FrictionCalibration(calibration_data: dict, simulation_folder: str, user_options: dict, logger: Logger | None = None)[source]

Bases: object

Class to handle the calibration process.

_optimization_var_args(main_args: dict) dict[source]

Extracts and processes the optimization variable user options

Parameters:

main_args (dict) – Dictionary containing the main arguments.

Returns:

Dictionary containing the optimization arguments.

Return type:

dict

_quantize_vector(vector: ndarray) ndarray[source]

Snap a vector to the exact Decimal grid defined by bounds and precision.

initialize_process(sampler)[source]

Initializes the optimization process.

objective_function(vector: ndarray, verbose: bool = True) float[source]

Optimization function to minimize the calibration error.

Parameters:
  • vector (np.ndarray) – Array containing the friction values.

  • verbose (bool) – If True, the function will print the current friction vector and the corresponding calibration error.

Returns:

The calibration error.

Return type:

float

opt_memory(vector: ndarray | None, error: float = 0.0, search: bool = False, initial: bool = False) tuple | int | None[source]

Saves the optimization memory to a file. This includes the friction vector and the corresponding calibration error.

This function will either create or append the memory file.

The function is called before the optimization process starts and loads the results from the memory file if it exists. Additionally, the memory file is updated after each optimization iteration.

Parameters:
  • vector (np.array) – Array containing the friction values.

  • error (float) – The calibration error.

  • search (bool) – If True, the function will search for the memory file.

  • initial (bool) – If True, the function will search the memory file and return as a solution if the file is longer than the number of samples.

  • override (bool) – Override the first memory check. This allows the creation of new LHS samples.

Returns:

If initial is True and the memory file exists, returns a tuple containing the friction vectors and their corresponding calibration errors. int: If search is True and the memory file does not exist, returns 0. None: If search is False and the memory file does not exist, returns None.

Return type:

tuple

src.friction_calibration.main(data: dict, paths: dict, user_opts: dict) None[source]

This function orchestrates the calibration process. It initializes the calibrator class, sets up the sampler and the Bayesian optimizer, and runs the calibration.

Parameters:
  • data (dict) – Dictionary containing the simulation data.

  • paths (dict) – dictionary containing all relevant paths

  • main_args (dict) – Additional arguments for file saving.