component_model.utils.fmu

Miscelaneous functions, not generally needed to make a FMU model, but which can be useful to work with fmu files (e.g. retrieving and working with a modelDefinition.xml file), to make an OSP system structure file, or to reverse-engineer the interface of a model (e.g. when making a surrogate model).

Functions

model_from_fmu(fmu[, provideMsg, sep])

Generate a Model from an FMU (excluding the inner working functions like do_step()), i.e. partially reverse-engineering a FMU.

variables_from_fmu(el[, sep])

From the supplied <ModelVariables> el subtree identify and define all variables.

component_model.utils.fmu.model_from_fmu(fmu: str | Path, provideMsg: bool = False, sep='.') dict

Generate a Model from an FMU (excluding the inner working functions like do_step()), i.e. partially reverse-engineering a FMU. This can be useful for convenient access to model information like variables or as starting point for surrogate models (e.g. speeding up models for optimisation studies or when using continuous time models in discrete event simulations) Note: structured variables with name: <name>[i], with otherwise equal causality, variability, initial and consecutive index and valueReference are stored as one Variable. .. todo:: <UnitDefinitions>, <LogCategories>.

Parameters:
  • fmu (str, Path) – the FMU file which is to be read. can be the full FMU zipfile, the modelDescription.xml or a equivalent string

  • provideMsg (bool) – Optional possibility to provide messages during the process (for debugging purposes)

  • sep (str) – separation used for structured variables (both for sub-systems and variable names)

Return type:

Arguments of Model.__init__ as dict (not the model object itself)

component_model.utils.fmu.variables_from_fmu(el: Element | None, sep: str = '[')

From the supplied <ModelVariables> el subtree identify and define all variables. Return an iterator through variable arguments as dict, so that variables can be added to model through .add_variable(**kwargs). .. toDo:: implement unit and displayUnit handling + <UnitDefinitions>.

Return type:

List of argument dicts, which then can be used to instantiate Variable objects Variable(**kwargs)