3. OMSimulatorLib

This library is the core of OMSimulator and provides a C interface that can easily be utilized to handle co-simulation scenarios.

3.1. C-API

3.1.1. RunFile

Simulates a single FMU or SSP model.

oms_status_enu_t oms_RunFile(const char* filename);

3.1.2. addBus

Adds a bus to a given component.

oms_status_enu_t oms_addBus(const char* cref);

3.1.3. addConnection

Adds a new connection between connectors A and B. The connectors need to be specified as fully qualified component references, e.g., “model.system.component.signal”.

oms_status_enu_t oms_addConnection(const char* crefA, const char* crefB);

The two arguments crefA and crefB get swapped automatically if necessary.

3.1.4. addConnector

Adds a connector to a given component.

oms_status_enu_t oms_addConnector(const char* cref, oms_causality_enu_t causality, oms_signal_type_enu_t type);

3.1.5. addConnectorToBus

Adds a connector to a bus.

oms_status_enu_t oms_addConnectorToBus(const char* busCref, const char* connectorCref);

3.1.6. addConnectorToTLMBus

Adds a connector to a TLM bus.

oms_status_enu_t oms_addConnectorToTLMBus(const char* busCref, const char* connectorCref, const char *type);

3.1.7. addExternalModel

Adds an external model to a TLM system.

oms_status_enu_t oms_addExternalModel(const char* cref, const char* path, const char* startscript);

3.1.8. addSignalsToResults

Add all variables that match the given regex to the result file.

oms_status_enu_t oms_addSignalsToResults(const char* cref, const char* regex);

The second argument, i.e. regex, is considered as a regular expression (C++11). “.*” and “(.)*” can be used to hit all variables.

3.1.9. addSubModel

Adds a component to a system.

oms_status_enu_t oms_addSubModel(const char* cref, const char* fmuPath);

3.1.10. addSystem

Adds a (sub-)system to a model or system.

oms_status_enu_t oms_addSystem(const char* cref, oms_system_enu_t type);

3.1.11. addTLMBus

Adds a TLM bus.

oms_status_enu_t oms_addTLMBus(const char* cref, oms_tlm_domain_t domain, const int dimensions, const oms_tlm_interpolation_t interpolation);

3.1.12. addTLMConnection

Connects two TLM connectors.

oms_status_enu_t oms_addTLMConnection(const char* crefA, const char* crefB, double delay, double alpha, double linearimpedance, double angularimpedance);

3.1.13. compareSimulationResults

This function compares a given signal of two result files within absolute and relative tolerances.

int oms_compareSimulationResults(const char* filenameA, const char* filenameB, const char* var, double relTol, double absTol);

The following table describes the input values:

Input Type Description
filenameA String Name of first result file to compare.
filenameB String Name of second result file to compare.
var String Name of signal to compare.
relTol Number Relative tolerance.
absTol Number Absolute tolerance.

The following table describes the return values:

Type Description
Integer 1 if the signal is considered as equal, 0 otherwise

3.1.14. copySystem

Copies a system.

oms_status_enu_t oms_copySystem(const char* source, const char* target);

3.1.15. delete

Deletes a connector, component, system, or model object.

oms_status_enu_t oms_delete(const char* cref);

3.1.16. deleteConnection

Deletes the connection between connectors crefA and crefB.

oms_status_enu_t oms_deleteConnection(const char* crefA, const char* crefB);

The two arguments crefA and crefB get swapped automatically if necessary.

3.1.17. deleteConnectorFromBus

Deletes a connector from a given bus.

oms_status_enu_t oms_deleteConnectorFromBus(const char* busCref, const char* connectorCref);

3.1.18. deleteConnectorFromTLMBus

Deletes a connector from a given TLM bus.

oms_status_enu_t oms_deleteConnectorFromTLMBus(const char* busCref, const char* connectorCref);

3.1.19. doStep

Simulates a macro step of the given composite model. The step size will be determined by the master algorithm and is limited by the definied minimal and maximal step sizes.

oms_status_enu_t oms_doStep(const char* cref);

3.1.20. export

Exports a composite model to a SPP file.

oms_status_enu_t oms_export(const char* cref, const char* filename);

3.1.21. exportDependencyGraphs

Export the dependency graphs of a given model to dot files.

oms_status_enu_t oms_exportDependencyGraphs(const char* cref, const char* initialization, const char* event, const char* simulation);

3.1.22. exportSSMTemplate

Exports all signals that have start values of one or multiple FMUs to a SSM file that are read from modelDescription.xml with a mapping entry. The mapping entry specifies a single mapping between a parameter in the source and a parameter of the system or component being parameterized. The mapping entry contains two attributes namely source and target. The source attribute will be empty and needs to be manually mapped by the users associated with the parameter name defined in the SSV file, the target contains the name of parameter in the system or component to be parameterized. The function can be called for a top level model or a certain FMU component. If called for a top level model, start values of all FMUs are exported to the SSM file. If called for a component, start values of just this FMU are exported to the SSM file.

oms_status_enu_t oms_exportSSMTemplate(const char* cref, const char* filename)

3.1.23. exportSSVTemplate

Exports all signals that have start values of one or multiple FMUs to a SSV file that are read from modelDescription.xml. The function can be called for a top level model or a certain FMU component. If called for a top level model, start values of all FMUs are exported to the SSV file. If called for a component, start values of just this FMU are exported to the SSV file.

oms_status_enu_t oms_exportSSVTemplate(const char* cref, const char* filename)

3.1.24. exportSnapshot

Lists the SSD representation of a given model, system, or component.

Memory is allocated for contents. The caller is responsible to free it using the C-API. The Lua and Python bindings take care of the memory and the caller doesn’t need to call free.

oms_status_enu_t oms_exportSnapshot(const char* cref, char** contents);

3.1.25. extractFMIKind

Extracts the FMI kind of a given FMU from the file system.

oms_status_enu_t oms_extractFMIKind(const char* filename, oms_fmi_kind_enu_t* kind);

3.1.26. faultInjection

Defines a new fault injection block.

oms_status_enu_t oms_faultInjection(const char* signal, oms_fault_type_enu_t faultType, double faultValue);
type Description”
oms_fault_type_bias y = y.$original + faultValue
oms_fault_type_gain y = y.$original * faultValue
oms_fault_type_const y = faultValue

3.1.27. freeMemory

Free the memory allocated by some other API. Pass the object for which memory is allocated.

void oms_freeMemory(void* obj);

3.1.28. getBoolean

Get boolean value of given signal.

oms_status_enu_t oms_getBoolean(const char* cref, bool* value);

3.1.29. getBus

Gets the bus object.

oms_status_enu_t oms_getBus(const char* cref, oms_busconnector_t** busConnector);

3.1.30. getComponentType

Gets the type of the given component.

oms_status_enu_t oms_getComponentType(const char* cref, oms_component_enu_t* type);

3.1.31. getConnections

Get list of all connections from a given component.

oms_status_enu_t oms_getConnections(const char* cref, oms_connection_t*** connections);

3.1.32. getConnector

Gets the connector object of the given connector cref.

oms_status_enu_t oms_getConnector(const char* cref, oms_connector_t** connector);

3.1.33. getElement

Get element information of a given component reference.

oms_status_enu_t oms_getElement(const char* cref, oms_element_t** element);

3.1.34. getElements

Get list of all sub-components of a given component reference.

oms_status_enu_t oms_getElements(const char* cref, oms_element_t*** elements);

3.1.35. getFMUInfo

Returns FMU specific information.

oms_status_enu_t oms_getFMUInfo(const char* cref, const oms_fmu_info_t** fmuInfo);

3.1.36. getFixedStepSize

Gets the fixed step size. Can be used for the communication step size of co-simulation systems and also for the integrator step size in model exchange systems.

oms_status_enu_t oms_getFixedStepSize(const char* cref, double* stepSize);

3.1.37. getInteger

Get integer value of given signal.

oms_status_enu_t oms_getInteger(const char* cref, int* value);

3.1.38. getModelState

Gets the model state of the given model cref.

oms_status_enu_t oms_getModelState(const char* cref, oms_modelState_enu_t* modelState);

3.1.39. getReal

Get real value.

oms_status_enu_t oms_getReal(const char* cref, double* value);

3.1.40. getResultFile

Gets the result filename and buffer size of the given model cref.

oms_status_enu_t oms_getResultFile(const char* cref, char** filename, int* bufferSize);

3.1.41. getSolver

Gets the selected solver method of the given system.

oms_status_enu_t oms_getSolver(const char* cref, oms_solver_enu_t* solver);

3.1.42. getStartTime

Get the start time from the model.

oms_status_enu_t oms_getStartTime(const char* cref, double* startTime);

3.1.43. getStopTime

Get the stop time from the model.

oms_status_enu_t oms_getStopTime(const char* cref, double* stopTime);

3.1.44. getSubModelPath

Returns the path of a given component.

oms_status_enu_t oms_getSubModelPath(const char* cref, char** path);

3.1.45. getSystemType

Gets the type of the given system.

oms_status_enu_t oms_getSystemType(const char* cref, oms_system_enu_t* type);

3.1.46. getTLMBus

Gets the TLM bus objects of the given TLM bus cref.

oms_status_enu_t oms_getTLMBus(const char* cref, oms_tlmbusconnector_t** tlmBusConnector);

3.1.47. getTLMVariableTypes

Gets the type of an TLM variable.

oms_status_enu_t oms_getTLMVariableTypes(oms_tlm_domain_t domain, const int dimensions, const oms_tlm_interpolation_t interpolation, char ***types, char ***descriptions);

3.1.48. getTime

Get the current simulation time from the model.

oms_status_enu_t oms_getTime(const char* cref, double* time);

3.1.49. getTolerance

Gets the tolerance of a given system or component.

oms_status_enu_t oms_getTolerance(const char* cref, double* absoluteTolerance, double* relativeTolerance);

3.1.50. getVariableStepSize

Gets the step size parameters.

oms_status_enu_t oms_getVariableStepSize(const char* cref, double* initialStepSize, double* minimumStepSize, double* maximumStepSize);

3.1.51. getVersion

Returns the library’s version string.

const char* oms_getVersion();

3.1.52. importFile

Imports a composite model from a SSP file.

oms_status_enu_t oms_importFile(const char* filename, char** cref);

3.1.53. importSnapshot

Loads a snapshot to restore a previous model state. The model must be in virgin model state, which means it must not be instantiated.

oms_status_enu_t oms_importSnapshot(const char* cref, const char* snapshot, char** newCref);

3.1.54. initialize

Initializes a composite model.

oms_status_enu_t oms_initialize(const char* cref);

3.1.55. instantiate

Instantiates a given composite model.

oms_status_enu_t oms_instantiate(const char* cref);

3.1.56. list

Lists the SSD representation of a given model, system, or component.

Memory is allocated for contents. The caller is responsible to free it using the C-API. The Lua and Python bindings take care of the memory and the caller doesn’t need to call free.

oms_status_enu_t oms_list(const char* cref, char** contents);

3.1.57. listUnconnectedConnectors

Lists all unconnected connectors of a given system.

Memory is allocated for contents. The caller is responsible to free it using the C-API. The Lua and Python bindings take care of the memory and the caller doesn’t need to call free.

oms_status_enu_t oms_listUnconnectedConnectors(const char* cref, char** contents);

3.1.58. loadSnapshot

Loads a snapshot to restore a previous model state. The model must be in virgin model state, which means it must not be instantiated.

oms_status_enu_t oms_loadSnapshot(const char* cref, const char* snapshot, char** newCref);

3.1.59. newModel

Creates a new and yet empty composite model.

oms_status_enu_t oms_newModel(const char* cref);

3.1.60. removeSignalsFromResults

Removes all variables that match the given regex to the result file.

oms_status_enu_t oms_removeSignalsFromResults(const char* cref, const char* regex);

The second argument, i.e. regex, is considered as a regular expression (C++11). “.*” and “(.)*” can be used to hit all variables.

3.1.61. rename

Renames a model, system, or component.

oms_status_enu_t oms_rename(const char* cref, const char* newCref);

3.1.62. reset

Reset the composite model after a simulation run.

The FMUs go into the same state as after instantiation.

oms_status_enu_t oms_reset(const char* cref);

3.1.63. setActivationRatio

Experimental feature for setting the activation ratio of FMUs for experimenting with multi-rate master algorithms.

oms_status_enu_t experimental_setActivationRatio(const char* cref, int k);

3.1.64. setBoolean

Sets the value of a given boolean signal.

oms_status_enu_t oms_setBoolean(const char* cref, bool value);

3.1.65. setBusGeometry

oms_status_enu_t oms_setBusGeometry(const char* bus, const ssd_connector_geometry_t* geometry);

3.1.66. setCommandLineOption

Sets special flags.

oms_status_enu_t oms_setCommandLineOption(const char* cmd);

Available flags:

info:    Usage: OMSimulator [Options] [Lua script] [FMU] [SSP file]
         Options:
           --addParametersToCSV=<arg>      Export parameters to .csv file (true, [false])
           --algLoopSolver=<arg>           Specifies the alg. loop solver method ([fixedpoint], kinsol) used for algebraic loops spanning over multiple components.
           --clearAllOptions               Reset all flags to default values
           --deleteTempFiles=<bool>        Deletes temp files as soon as they are no longer needed ([true], false)
           --emitEvents=<bool>             Specifies whether events should be emitted or not ([true], false)
           --exportParametersInline=<arg>  Export ParameterBindings inline with .ssd file, 
           --fetchAllVars=<arg>            Workaround for certain FMUs that do not update all internal dependencies automatically
           --help [-h]                     Displays the help text
           --ignoreInitialUnknowns=<bool>  Ignore the initial unknowns from the modelDescription.xml (true, [false])
           --inputExtrapolation=<bool>     Enables input extrapolation using derivative information (true, [false])
           --intervals=<int> [-i]          Specifies the number of communication points (arg > 1)
           --logFile=<arg> [-l]            Specifies the logfile (stdout is used if no log file is specified)
           --logLevel=<int>                0 default, 1 debug, 2 debug+trace
           --maxEventIteration=<int>       Specifies the max. number of iterations for handling a single event
           --maxLoopIteration=<int>        Specifies the max. number of iterations for solving algebraic loops between system-level components. Internal algebraic loops of components are not affected.
           --mode=<arg> [-m]               Forces a certain FMI mode iff the FMU provides cs and me (cs, [me])
           --numProcs=<int> [-n]           Specifies the max. number of processors to use (0=auto, 1=default)
           --progressBar=<bool>            Shows a progress bar for the simulation progress in the terminal (true, [false])
           --realTime=<bool>               Experimental feature for (soft) real-time co-simulation (true, [false])
           --resultFile=<arg> [-r]         Specifies the name of the output result file
           --setInputDerivatives=<bool>    Deprecated; see '--inputExtrapolation'
           --skipCSVHeader=<arg>           Skip exporting the scv delimiter in the header (true, [false]), 
           --solver=<arg>                  Specifies the integration method (euler, [cvode])
           --solverStats=<bool>            Adds solver stats to the result file, e.g. step size; not supported for all solvers (true, [false])
           --startTime=<double> [-s]       Specifies the start time
           --stopTime=<double> [-t]        Specifies the stop time
           --stripRoot=<bool>              Removes the root system prefix from all exported signals (true, [false])
           --suppressPath=<bool>           Supresses path information in info messages; especially useful for testing ([true], false)
           --tempDir=<arg>                 Specifies the temp directory
           --timeout=<int>                 Specifies the maximum allowed time in seconds for running a simulation (0 disables)
           --tolerance=<double>            Specifies the relative tolerance
           --version [-v]                  Displays version information
           --wallTime=<bool>               Add wall time information for to the result file (true, [false])
           --workingDir=<arg>              Specifies the working directory

3.1.67. setConnectionGeometry

oms_status_enu_t oms_setConnectionGeometry(const char* crefA, const char* crefB, const ssd_connection_geometry_t* geometry);

3.1.68. setConnectorGeometry

Set geometry information to a given connector.

oms_status_enu_t oms_setConnectorGeometry(const char* cref, const ssd_connector_geometry_t* geometry);

3.1.69. setElementGeometry

Set geometry information to a given component.

oms_status_enu_t oms_setElementGeometry(const char* cref, const ssd_element_geometry_t* geometry);

3.1.70. setFixedStepSize

Sets the fixed step size. Can be used for the communication step size of co-simulation systems and also for the integrator step size in model exchange systems.

oms_status_enu_t oms_setFixedStepSize(const char* cref, double stepSize);

3.1.71. setInteger

Sets the value of a given integer signal.

oms_status_enu_t oms_setInteger(const char* cref, int value);

3.1.72. setLogFile

Redirects logging output to file or std streams. The warning/error counters are reset.

filename=”” to redirect to std streams and proper filename to redirect to file.

oms_status_enu_t oms_setLogFile(const char* filename);

3.1.73. setLoggingCallback

Sets a callback function for the logging system.

void oms_setLoggingCallback(void (*cb)(oms_message_type_enu_t type, const char* message));

3.1.74. setLoggingInterval

Set the logging interval of the simulation.

oms_status_enu_t oms_setLoggingInterval(const char* cref, double loggingInterval);

3.1.75. setLoggingLevel

Enables/Disables debug logging (logDebug and logTrace).

0 default, 1 default+debug, 2 default+debug+trace

void oms_setLoggingLevel(int logLevel);

3.1.76. setMaxLogFileSize

Sets maximum log file size in MB. If the file exceeds this limit, the logging will continue on stdout.

void oms_setMaxLogFileSize(const unsigned long size);

3.1.77. setReal

Sets the value of a given real signal.

oms_status_enu_t oms_setReal(const char* cref, double value);

This function can be called in different model states:

  • Before instantiation: setReal can be used to set start values or to define initial unknowns (e.g. parameters, states). The values are not immediately applied to the simulation unit, since it isn’t actually instantiated.
  • After instantiation and before initialization: Same as before instantiation, but the values are applied immediately to the simulation unit.
  • After initialization: Can be used to force external inputs, which might cause discrete changes of continuous signals.

3.1.78. setRealInputDerivative

Sets the first order derivative of a real input signal.

This can only be used for CS-FMU real input signals.

oms_status_enu_t oms_setRealInputDerivative(const char* cref, double value);

3.1.79. setResultFile

Set the result file of the simulation.

oms_status_enu_t oms_setResultFile(const char* cref, const char* filename, int bufferSize);

The creation of a result file is omitted if the filename is an empty string.

3.1.80. setSolver

Sets the solver method for the given system.

oms_status_enu_t oms_setSolver(const char* cref, oms_solver_enu_t solver);

3.1.81. setStartTime

Set the start time of the simulation.

oms_status_enu_t oms_setStartTime(const char* cref, double startTime);

3.1.82. setStopTime

Set the stop time of the simulation.

oms_status_enu_t oms_setStopTime(const char* cref, double stopTime);

3.1.83. setTLMBusGeometry

oms_status_enu_t oms_setTLMBusGeometry(const char* bus, const ssd_connector_geometry_t* geometry);

3.1.84. setTLMConnectionParameters

Simulates a composite model in its own thread.

oms_status_enu_t oms_setTLMConnectionParameters(const char* crefA, const char* crefB, const oms_tlm_connection_parameters_t* parameters);

3.1.85. setTLMPositionAndOrientation

Sets initial position and orientation for a TLM 3D interface.

oms_status_enu_t oms_setTLMPositionAndOrientation(cref, x1, x2, x3, A11, A12, A13, A21, A22, A23, A31, A32, A33);

3.1.86. setTLMSocketData

Sets data for TLM socket communication.

oms_status_enu_t oms_setTLMSocketData(const char* cref, const char* address, int managerPort, int monitorPort);

3.1.87. setTempDirectory

Set new temp directory.

oms_status_enu_t oms_setTempDirectory(const char* newTempDir);

3.1.88. setTolerance

Sets the tolerance for a given model or system.

oms_status_enu_t oms_setTolerance(const char* cref, double absoluteTolerance, double relativeTolerance);

Default values are 1e-4 for both relative and absolute tolerances.

A tolerance specified for a model is automatically applied to its root system, i.e. both calls do exactly the same:

oms_setTolerance("model", absoluteTolerance, relativeTolerance);
oms_setTolerance("model.root", absoluteTolerance, relativeTolerance);

Component, e.g. FMUs, pick up the tolerances from there system. That means it is not possible to define different tolerances for FMUs in the same system right now.

In a strongly coupled system (oms_system_sc), the relative tolerance is used for CVODE and the absolute tolerance is used to solve algebraic loops.

In a weakly coupled system (oms_system_wc), both the relative and absolute tolerances are used for the adaptive step master algorithms and the absolute tolerance is used to solve algebraic loops.

3.1.89. setVariableStepSize

Sets the step size parameters for methods with stepsize control.

oms_status_enu_t oms_getVariableStepSize(const char* cref, double* initialStepSize, double* minimumStepSize, double* maximumStepSize);

3.1.90. setWorkingDirectory

Set a new working directory.

oms_status_enu_t oms_setWorkingDirectory(const char* newWorkingDir);

3.1.91. simulate

Simulates a composite model.

oms_status_enu_t oms_simulate(const char* cref);

3.1.92. simulate_realtime

Experimental feature for (soft) real-time simulation.

oms_status_enu_t experimental_simulate_realtime(const char* ident);

3.1.93. stepUntil

Simulates a composite model until a given time value.

oms_status_enu_t oms_stepUntil(const char* cref, double stopTime);

3.1.94. terminate

Terminates a given composite model.

oms_status_enu_t oms_terminate(const char* cref);