OMSimulatorPython

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

Examples

from OMSimulator import OMSimulator
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")

Python Scripting Commands

RunFile

Simulates a single FMU or SSP model.

# not available

addBus

Adds a bus to a given component.

status = oms.addBus(cref)

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.

addConnector

Adds a connector to a given component.

status = oms.addConnector(cref, causality, type)

addConnectorToBus

Adds a connector to a bus.

status = oms.addConnectorToBus(busCref, connectorCref)

addConnectorToTLMBus

Adds a connector to a TLM bus.

status = oms.addConnectorToTLMBus(busCref, connectorCref, type)

addExternalModel

Adds an external model to a TLM system.

status = oms.addExternalModel(cref, path, startscript)

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.

addSubModel

Adds a component to a system.

status = oms.addSubModel(cref, fmuPath)

addSystem

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

status = oms.addSystem(cref, type)

addTLMBus

Adds a TLM bus.

status = oms.addTLMBus(cref, domain, dimensions, interpolation)

addTLMConnection

Connects two TLM connectors.

status = oms.addTLMConnection(crefA, crefB, delay, alpha, linearimpedance, angularimpedance)

cancelSimulation_asynchronous

Cancels a running asynchronous simulation.

# 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)

copySystem

Copies a system.

status = oms.copySystem(source, target)

delete

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

status = oms.delete(cref)

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.

deleteConnectorFromBus

Deletes a connector from a given bus.

status = oms.deleteConnectorFromBus(busCref, connectorCref)

deleteConnectorFromTLMBus

Deletes a connector from a given TLM bus.

status = oms.deleteConnectorFromTLMBus(busCref, connectorCref)

export

Exports a composite model to a SPP file.

status = oms.export(cref, filename)

exportDependencyGraphs

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

status = oms.exportDependencyGraphs(cref, initialization, simulation)

extractFMIKind

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

# not available

faultInjection

Defines a new fault injection block.

status = oms.faultInjection(cref, type, value)
type Description”
oms_fault_type_bias y = y.$original + faultValue
oms_fault_type_gain y = y.$original * faultValue
oms_fault_type_const y = faultValue

freeMemory

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

oms.freeMemory(obj)

getBoolean

Get boolean value of given signal.

value, status = oms.getBoolean(cref)

getBus

Gets the bus object.

# not available

getComponentType

Gets the type of the given component.

# not available

getConnections

Get list of all connections from a given component.

# not available

getConnector

Gets the connector object of the given connector cref.

# not available

getElement

Get element information of a given component reference.

# not available

getElements

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

# not available

getFMUInfo

Returns FMU specific information.

# 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.getFixedStepSize(cref)

getInteger

Get integer value of given signal.

value, status = oms.getInteger(cref)

getModelState

Gets the model state of the given model cref.

# not available

getReal

Get real value.

value, status = oms.getReal(cref)

getSolver

Gets the selected solver method of the given system.

solver, status = oms.getSolver(cref)

getStartTime

Get the start time from the model.

startTime, status = oms.getStartTime(cref)

getStopTime

Get the stop time from the model.

stopTime, status = oms.getStopTime(cref)

getSubModelPath

Returns the path of a given component.

path, status = oms.getSubModelPath(cref)

getSystemType

Gets the type of the given system.

# not available

getTLMBus

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

# not available

getTLMVariableTypes

Gets the type of an TLM variable.

# not available

getTolerance

Gets the tolerance of a given system or component.

absoluteTolerance, relativeTolerance, status = oms.getTolerance(cref)

getVariableStepSize

Gets the step size parameters.

initialStepSize, minimumStepSize, maximumStepSize, status = oms.getVariableStepSize(cref)

getVersion

Returns the library’s version string.

oms = OMSimulator()
oms.getVersion()

importFile

Imports a composite model from a SSP file.

cref, status = oms.importFile(filename)

initialize

Initializes a composite model.

status = oms.initialize(cref)

instantiate

Instantiates a given composite model.

status = oms.instantiate(cref)

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)

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)

loadSnapshot

Loads a snapshot to restore a previous model state.

# not available

newModel

Creates a new and yet empty composite model.

status = oms.newModel(cref)

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)

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.

rename

Renames a model, system, or component.

status = oms.rename(cref, newCref)

reset

Reset the composite model after a simulation run.

The FMUs go into the same state as after instantiation.

status = oms.reset(cref)

setActivationRatio

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

# not yet available

setBoolean

Sets the value of a given boolean signal.

status = oms.setBoolean(cref, value)

setBusGeometry

# not available

setCommandLineOption

Sets special flags.

status = oms.setCommandLineOption(cmd)

Available flags:

info:    Usage: OMSimulator [Options] [Lua script] [FMU] [SSP file]
         Options:
           --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)
           --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
           --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'
           --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

setConnectionGeometry

# not available

setConnectorGeometry

Set geometry information to a given connector.

# not available

setElementGeometry

Set geometry information to a given component.

# 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)

setInteger

Sets the value of a given integer signal.

status = oms.setInteger(cref, value)

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)

setLoggingCallback

Sets a callback function for the logging system.

# not available

setLoggingInterval

Set the logging interval of the simulation.

status = oms.setLoggingInterval(cref, loggingInterval)

setLoggingLevel

Enables/Disables debug logging (logDebug and logTrace).

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

oms.setLoggingLevel(logLevel)

setMaxLogFileSize

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

oms.setMaxLogFileSize(size)

setReal

Sets the value of a given real signal.

status = oms.setReal(cref, 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.

setRealInputDerivative

Sets the first order derivative of a real input signal.

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

status = oms.setRealInputDerivative(cref, value)

setResultFile

Set the result file of the simulation.

status = oms.setResultFile(cref, filename)
status = oms.setResultFile(cref, filename, bufferSize)

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

setSignalFilter

status = oms.setSignalFilter(cref, regex)

setSolver

Sets the solver method for the given system.

status = oms.setSolver(cref, solver)

setStartTime

Set the start time of the simulation.

status = oms.setStartTime(cref, startTime)

setStopTime

Set the stop time of the simulation.

status = oms.setStopTime(cref, stopTime)

setTLMBusGeometry

# not available

setTLMConnectionParameters

Simulates a composite model in its own thread.

# not available

setTLMPositionAndOrientation

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

# not yet available

setTLMSocketData

Sets data for TLM socket communication.

# not yet available

setTempDirectory

Set new temp directory.

status = oms.setTempDirectory(newTempDir)

setTolerance

Sets the tolerance for a given model or system.

status = oms.setTolerance(const char* cref, double tolerance)
status = 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.

setVariableStepSize

Sets the step size parameters for methods with stepsize control.

status = oms.getVariableStepSize(cref, initialStepSize, minimumStepSize, maximumStepSize)

setWorkingDirectory

Set a new working directory.

status = oms.setWorkingDirectory(newWorkingDir)

simulate

Simulates a composite model.

status = oms.simulate(cref)

simulate_asynchronous

Simulates a composite model in its own thread.

# not available

simulate_realtime

Experimental feature for (soft) real-time simulation.

# not yet available

stepUntil

Simulates a composite model until a given time value.

status = oms.stepUntil(cref, stopTime)

terminate

Terminates a given composite model.

status = oms.terminate(cref)