OMSimulatorLua

This is a shared library that provides a Lua interface for the OMSimulatorLib library.

Examples

oms_setTempDirectory("./temp/")
oms_newModel("model")
oms_addSystem("model.root", oms_system_sc)

-- instantiate FMUs
oms_addSubModel("model.root.system1", "FMUs/System1.fmu")
oms_addSubModel("model.root.system2", "FMUs/System2.fmu")

-- add connections
oms_addConnection("model.root.system1.y", "model.root.system2.u")
oms_addConnection("model.root.system2.y", "model.root.system1.u")

-- simulation settings
oms_setResultFile("model", "results.mat")
oms_setStopTime("model", 0.1)
oms_setFixedStepSize("model.root", 1e-4)

oms_instantiate("model")
oms_setReal("model.root.system1.x_start", 2.5)

oms_initialize("model")
oms_simulate("model")
oms_terminate("model")
oms_delete("model")

Lua Scripting Commands

setLoggingInterval

Set the logging interval of the simulation.

status = oms_setLoggingInterval(cref, loggingInterval)

newModel

Creates a new and yet empty composite model.

status = oms_newModel(cref)

setLoggingLevel

Enables/Disables debug logging (logDebug and logTrace).

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

oms_setLoggingLevel(logLevel)

getVersion

Returns the library’s version string.

version = oms_getVersion()

export

Exports a composite model to a SPP file.

status = oms_export(cref, filename)

getBoolean

Get boolean value of given signal.

value, status = oms_getBoolean(cref)

getTLMVariableTypes

Gets the type of an TLM variable.

# not available

addBus

Adds a bus to a given component.

status = oms_addBus(cref)

deleteConnectorFromBus

Deletes a connector from a given bus.

status = oms_deleteConnectorFromBus(busCref, connectorCref)

setConnectorGeometry

Set geometry information to a given connector.

# not available

stepUntil

Simulates a composite model until a given time value.

status = oms_stepUntil(cref, stopTime)

simulate_realtime

Experimental feature for (soft) real-time simulation.

status = experimental_simulate_realtime(ident)

setStartTime

Set the start time of the simulation.

status = oms_setStartTime(cref, startTime)

instantiate

Instantiates a given composite model.

status = oms_instantiate(cref)

getSubModelPath

Returns the path of a given component.

# not available

RunFile

Simulates a single FMU or SSP model.

# not available

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.

status = oms_setFixedStepSize(cref, stepSize)

deleteConnection

Deletes the connection between connectors crefA and crefB.

status = oms_deleteConnection(crefA, crefB)

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

getTLMBus

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

# not available

setResultFile

Set the result file of the simulation.

status = oms_setResultFile(cref, filename)
status = oms_setResultFile(cref, filename, bufferSize)

setSolver

Sets the solver method for the given system.

status = oms_setSolver(cref, solver)
solver Type Description
oms_solver_sc_explicit_euler sc-system Explicit euler with fixed step size
oms_solver_sc_cvode sc-system CVODE with adaptive stepsize
oms_solver_wc_ma wc-system default master algorithm with fixed step size
oms_solver_wc_mav wc-system master algorithm with adaptive stepsize

exportDependencyGraphs

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

status = oms_exportDependencyGraphs(cref, initialization, simulation)

addExternalModel

Adds an external model to a TLM system.

status = oms_addExternalModel(cref, path, startscript)

addTLMConnection

Connects two TLM connectors.

status = oms_addTLMConnection(crefA, crefB, delay, alpha, linearimpedance, angularimpedance)

importFile

Imports a composite model from a SSP file.

cref, status = oms_importFile(filename)

setReal

Set real value of given signal.

status = oms_setReal(cref, value)

deleteConnectorFromTLMBus

Deletes a connector from a given TLM bus.

status = oms_deleteConnectorFromTLMBus(busCref, connectorCref)

setBusGeometry

# not available

setVariableStepSize

Sets the step size parameters for methods with stepsize control.

status = oms_getVariableStepSize(cref, initialStepSize, minimumStepSize, maximumStepSize)

setStopTime

Set the stop time of the simulation.

status = oms_setStopTime(cref, stopTime)

setBoolean

Set boolean value of given signal.

status = oms_setBoolean(cref, value)

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.

contents, status = oms_list(cref)

getInteger

Get integer value of given signal.

value, status = oms_getInteger(cref)

getStopTime

Get the stop time from the model.

stopTime, status = oms_getStopTime(cref)

getReal

Get real value.

value, status = oms_getReal(cref)

addConnectorToTLMBus

Adds a connector to a TLM bus.

status = oms_addConnectorToTLMBus(busCref, connectorCref, type)

copySystem

Copies a system.

status = oms_copySystem(source, target)

addSystem

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

status = oms_addSystem(cref, type)

setMaxLogFileSize

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

oms_setMaxLogFileSize(size)

terminate

Terminates a given composite model.

status = oms_terminate(cref)

setTempDirectory

Set new temp directory.

status = oms_setTempDirectory(newTempDir)

extractFMIKind

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

# not available

setTLMConnectionParameters

Simulates a composite model in its own thread.

# not available

getModelState

Gets the model state of the given model cref.

# not available

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.

stepSize, status = oms_setFixedStepSize(cref)

setCommandLineOption

Sets special flags.

status = oms_setCommandLineOption(cmd)

Available flags:

info:    Usage: OMSimulator [Options|Lua script]
info:    Options:
           <filename>                  FMU or SSP file
           --clearAllOptions           Reset all flags to default values
           --fetchAllVars=<arg>        
           --help [ -h ]               Displays the help text
           --ignoreInitialUnknowns=<arg>  Ignore the initial unknowns from the modelDesction.xml
           --intervals=<arg> [ -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=<arg>            0 default, 1 default+debug, 2 default+debug+trace
           --mode=<arg> [ -m ]         Forces a certain FMI mode iff the FMU provides cs and me [arg: cs (default) or me]
           --progressBar=<arg>         
           --resultFile=<arg> [ -r ]   Specifies the name of the output result file
           --setInputDerivatives=<arg>  
           --solver                    Specifies the integration method (internal, euler, cvode)
           --startTime=<arg> [ -s ]    Specifies the start time
           --stopTime=<arg> [ -t ]     Specifies the stop time
           --suppressPath=<arg>        
           --tempDir=<arg>             Specifies the temp directory
           --timeout=<arg>             Specifies the maximum allowed time in seconds for running a simulation (0 disables)
           --tolerance=<arg>           Specifies the relative tolerance
           --version [ -v ]            Displays version information
           --wallTime=<arg>            Add wall time information for to the result file
           --workingDir=<arg>          Specifies the working directory

reset

Reset the composite model after a simulation run.

The FMUs go into the same state as after instantiation.

status = oms_reset(cref)

delete

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

status = oms_delete(cref)

simulate_asynchronous

Simulates a composite model in its own thread.

# not available

getVariableStepSize

Gets the step size parameters.

initialStepSize, minimumStepSize, maximumStepSize, status = oms_getVariableStepSize(cref)

getBus

Gets the bus object.

# not available

setTLMSocketData

Sets data for TLM socket communication.

status = oms_setTLMSocketData(cref, address, managerPort, monitorPort)

setElementGeometry

Set geometry information to a given component.

# not available

getConnector

Gets the connector object of the given connector cref.

# not available

getElements

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

# not available

addConnectorToBus

Adds a connector to a bus.

status = oms_addConnectorToBus(busCref, connectorCref)

cancelSimulation_asynchronous

Cancels a running asynchronous simulation.

# not available

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”.

status = oms_addConnection(crefA, crefB)

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

setSignalFilter

status = oms_setSignalFilter(cref, regex)

importString

Imports a composite model from a string.

cref, oms_status_enu_t oms_importString(contents)

simulate_asynchronous

Adds a TLM bus.

status = oms_addTLMBus(cref, domain, dimensions, interpolation)

getConnections

Get list of all connections from a given component.

# not available

addSignalsToResults

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

status = oms_addSignalsToResults(cref, regex)

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

rename

Renames a model, system, or component.

status = oms_rename(cref, newCref)

getFMUInfo

Returns FMU specific information.

# not available

setTLMBusGeometry

# not available

getElement

Get element information of a given component reference.

# not available

compareSimulationResults

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

oms_compareSimulationResults(filenameA, filenameB, var, relTol, 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

setInteger

Set integer value of given signal.

status = oms_setInteger(cref, value)

addSubModel

Adds a component to a system.

status = oms_addSubModel(cref, fmuPath)

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.

contents, status = oms_listUnconnectedConnectors(cref)

getComponentType

Gets the type of the given component.

# not available

setConnectionGeometry

# not available

getSystemType

Gets the type of the given system.

# not available

addConnector

Adds a connector to a given component.

status = oms_addConnector(cref, causality, type)

initialize

Initializes a composite model.

status = oms_initialize(cref)

getSolver

Gets the selected solver method of the given system.

solver, status = oms_getSolver(cref)

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.

status = oms_setLogFile(filename)

parseModelName

Parses the model name from a given SSD representation.

Memory is allocated for ident. 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.

ident, status = oms_parseModelName(contents)

setActivationRatio

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

status = experimental_setActivationRatio(cref, k)

removeSignalsFromResults

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

status = oms_removeSignalsFromResults(cref, regex)

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

getStartTime

Get the start time from the model.

startTime, status = oms_getStartTime(cref)

setWorkingDirectory

Set a new working directory.

status = oms_setWorkingDirectory(newWorkingDir)

simulate

Simulates a composite model.

status = oms_simulate(cref)

setTolerance

Sets the tolerance for a given model, system, or component.

status = oms_setTolerance(const char* cref, double tolerance)
status = oms_setTolerance(const char* cref, double absoluteTolerance, double relativeTolerance)

setLoggingCallback

Sets a callback function for the logging system.

# not available

freeMemory

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

oms_freeMemory(obj)

getTolerance

Gets the tolerance of a given system or component.

absoluteTolerance, relativeTolerance, status = oms_getTolerance(cref)

setTLMPositionAndOrientation

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

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