1. Overview of JModelica.org FMI Python package

The JModelica.org interface to FMI is written in Python and is intended to be a close copy of the defined C-interface for an FMU and provides classes and functions for interacting with FMUs.

The JModelica.org platform offers a Pythonic and convenient interface for FMUs which can be used to connect other simulation software. JModelica.org also offers a connection to Assimulo, the default simulation package included in JModelica.org so that FMUs can easily be simulated.

The interface is located in pyfmi.fmi and consist of the class FMUModel together with methods for unzipping the FMU and for writing the simulation results. Connected to this interface is a wrapper for JModelica.org's simulation package to enable an easy simulation of the FMUs. The simulation wrapper is located in pyfmi.simulation.assimulo, FMIODE.

In the table below is a list of the FMI C-interface and its counterpart in the JModelica.org Python package. We have adapted the name convention of lowercase letters and underscores separating words. For methods with no calculations, as for example fmi(Get/Set)ContinuousStates they are instead of different methods, connected with a property. In the table, a lack of parenthesis indicates that the method is instead a property.

Table 5.1. Conversion table.

FMI C-Interface JModelica.org FMI Python Interface
const char* fmiGetModelTypesPlatform() string FMUModel.model_types_platform
const char* fmiGetVersion() string FMUModel.version
fmiComponent fmiInstantiateModel(...) FMUModel.__init__()
void fmiFreeModelInstance(fmiComponent c) FMUModel.__del__()
fmiStatus fmiSetDebugLogging(...) none FMUModel.set_debug_logging(flag)
fmiStatus fmiSetTime(...) FMUModel.time
fmiStatus fmi(Get/Set)ContinuousStates(...) FMUModel.continuous_states
fmiStatus fmiCompletedIntegratorStep(...) boolean FMUModel.completed_integrator_step()
fmiStatus fmiSetReal/Integer/Boolean/String(...) none FMUModel.set_real/integer/boolean/string(valueref,values)
fmiStatus fmiInitialize(...) none FMUModel.initialize() (also sets the start attributes)
struct fmiEventInfo FMUModel.get_event_info()
fmiStatus fmiGetDerivatives(...) numpy.array FMUModel.get_derivatives()
fmiStatus fmiGetEventIndicators(...) numpy.array FMUModel.get_event_indicators()
fmiStatus fmiGetReal/Integer/Boolean/String(...) numpy.array FMUModel.get_real/integer/boolean/string(valueref)
fmiStatus fmiEventUpdate(...) none FMUModel.event_update()
fmiStatus fmiGetNominalContinuousStates(...) FMUModel.nominal_continuous_states
fmiStatus fmiGetStateValueReferences(...) numpy.array FMUModel.get_state_value_references()
fmiStatus fmiTerminate(...) FMUModel.__del__()

If logging is set to True the log can be retrieved with the method,

FMUModel.get_log()

Documentation of the functions can also be accessed interactively from IPython by using for instance,

FMUModel.get_real?

There is also a one-to-one map to the C-functions, meaning that there is an option to use the low-level C-functions as they are specified in the standard instead of using our wrapping of the functions. These functions are also located in FMUModel and is named with a leading underscore together with the same name as specified in the standard.