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¶
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)
deleteConnectorFromBus¶
Deletes a connector from a given bus.
status = oms.deleteConnectorFromBus(busCref, connectorCref)
stepUntil¶
Simulates a composite model until a given time value.
status = oms.stepUntil(cref, stopTime)
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.
setResultFile¶
Set the result file of the simulation.
status = oms.setResultFile(cref, filename)
status = oms.setResultFile(cref, filename, bufferSize)
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)
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)
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)
addConnectorToTLMBus¶
Adds a connector to a TLM bus.
status = oms.addConnectorToTLMBus(busCref, connectorCref, type)
setMaxLogFileSize¶
Sets maximum log file size in MB. If the file exceeds this limit, the logging will continue on stdout.
oms.setMaxLogFileSize(size)
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)
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)
getVariableStepSize¶
Gets the step size parameters.
initialStepSize, minimumStepSize, maximumStepSize, status = oms.getVariableStepSize(cref)
addConnectorToBus¶
Adds a connector to a bus.
status = oms.addConnectorToBus(busCref, connectorCref)
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)
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.
setTLMBusGeometry¶
# 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)
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)
setConnectionGeometry¶
# not available
addConnector¶
Adds a connector to a given component.
status = oms.addConnector(cref, causality, type)
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.
# not yet available
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.
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)
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.
# not yet available