Load an FMU

First, retrieve the path to the example FMU deviation.fmu.

import pyfmi
import otfmi.example.utility

path_fmu = otfmi.example.utility.get_path_fmu("deviation")

Loading an FMU only requires the FMU name or path.

model = otfmi.fmi.load_fmu(path_fmu)

If the FMU is both ModelExchange and CoSimulation, the CoSimulation type is favoured. This choice, opposite to PyFMI’s default, enables the CoSimulation to impose a solver not available in PyFMI.

All options of pyfmi.load_fmu can be passed on to Otfmi:

print(help(pyfmi.load_fmu))
Help on built-in function load_fmu in module pyfmi.fmi:

load_fmu(...)
    Helper method for creating a model instance.

    Parameters::

        fmu --
            Name of the fmu as a string.

        log_file_name --
            Filename for file used to save logmessages.
            This argument can also be a stream if it supports 'write', for full functionality
            it must also support 'seek' and 'readlines'. If the stream requires use of other methods, such as 'drain'
            for asyncio-streams, then this needs to be implemented on the user-side, there is no additional methods invoked
            on the stream instance after 'write' has been invoked on the PyFMI side.
            The stream must also be open and writable during the entire time.
            Default: "" (Generates automatically)

        kind --
            String indicating the kind of model to create. This is only
            needed if a FMU contains both a ME and CS model.
            Available options:
                - 'ME'
                - 'CS'
                - 'auto'
            Default: 'auto' (Chooses ME before CS if both available)

        log_level --
            Determines the logging output. Can be set between 0
            (no logging) and 7 (everything).
            Default: 2 (log error messages)
        allow_unzipped_fmu --
            If set to True, the argument 'fmu' can be a path specifying a directory
            to an unzipped FMU. The structure of the unzipped FMU must conform
            to the FMI specification.
            Default: False

    Returns::

        A model instance corresponding to the loaded FMU.

None

For instance, enforce CoSimulation kind and specify the filename for the logs writing:

model = otfmi.fmi.load_fmu(path_fmu, kind="CS", log_file_name="deviation.log")

Note

Otfmi load_fmu is an overlay of PyFMI load_fmu function. Hence the FMU loaded here upper benefits of all PyFMI’s methods.

For example, get_description is a PyFMI method (not re-implemented in Otfmi):

model.get_description()
'Model from here: http://openturns.github.io/openturns/master/usecases/use_case_cantilever_beam.html'

Total running time of the script: (0 minutes 0.068 seconds)