API documentation#

otfmi facilitates the analysis of FMUs over time.

Main API#

The class FMUPointToFieldFunction wraps the FMU evaluation in an openturns.PointToFieldFunction. Its input is a vector (openturns.Point) and its output is a openturns.Field gathering the outputs as function of time.

FMUPointToFieldFunction(path_fmu[, mesh, ...])

Define a PointToFieldFunction from a FMU file.

The FMUFunction allows to perform the FMU evaluation as a openturns.Function. Both its input and output vector are a vector (openturns.Point), the output consisting of the values at the final simulation time.

FMUFunction([path_fmu, inputs_fmu, ...])

Define a Function from a FMU file.

The class FMUFieldFunction wraps the FMU evaluation in an openturns.FieldFunction. Its input is a openturns.Field and its output is a openturns.Field gathering the outputs as function of time.

FMUFieldFunction(path_fmu[, input_mesh, ...])

Define a FieldFunction from a FMU file.

The class FMUFieldToPointFunction wraps the FMU evaluation in an openturns.FieldToPointFunction. Its input is a openturns.Field and its output is a vector (openturns.Point) consisting of the values at the final simulation time.

FMUFieldToPointFunction(path_fmu[, mesh, ...])

Define a FieldToPointFunction from a FMU file.

Here is a summary of the different variants:

Class

Input

Output

FMUPointToFieldFunction

Point

Field

FMUFunction

Point

Point

FMUFieldFunction

Field

Field

FMUFieldToPointFunction

Field

Point

FMI backend#

Driving a FMU requires an FMI backend, that is an implementation of the FMI standard. Two are supported, behind a common interface: PyFMI and FMPy (see Terminology).

PyFMI is used by default whenever it is installed, otherwise otfmi falls back to FMPy. The active backend is reported by otfmi.backend.BACKEND and can be selected at runtime with use_backend, in the spirit of the matplotlib backends:

import otfmi

otfmi.backend.BACKEND  # 'pyfmi' or 'fmpy'
otfmi.use_backend("fmpy")

Backend-specific simulation options are passed with the pyfmi_options and fmpy_options keyword arguments. Only the options matching the active backend are taken into account, so the same call can carry options for both:

model(x, pyfmi_options={"silent_mode": True}, fmpy_options={"solver": "Euler"})

use_backend(name)

Switch the FMI backend.

Common low-level functions#

The submodule otfmi.fmi gathers a set of useful functions, employed by the (higher-level) classes mentioned above.

fmi.load_fmu(path_fmu[, kind])

Load an FMU.

fmi.simulate(model[, initialization_script, ...])

Simulate an FMU.

fmi.parse_kwargs_simulate([value_input, ...])

Parse simulation keyword arguments and feed the simulate method of the backend's object.

fmi.apply_initialization_script(model, ...)

Apply an initialization script to a model.

fmi.get_name_variable(model, **kwargs)

Get the list of variable names.

fmi.get_causality_str(model, name)

Get the causality of a variable (input, output, or other).

fmi.get_variability(model)

Get the variability of the variables (constant, discrete, continuous, or other).

fmi.get_fixed_value(model)

Get the values of the variables with 'fixed' variability, ignoring aliases.

fmi.get_start_value(model)

Get the values of the variables with a start value ignoring aliases.

fmi.set_dict_value(model, dict_value)

Set values from a dictionary with variable names as keys.

From OpenTURNS to FMI#

OTFMI can also export an OpenTURNS function in a Modelica source model (.mo) or Functional Mock-up Unit (.fmu).

FunctionExporter(function[, start])

Function export.