Class fmipp.FMUCoSimulationV2

class FMUCoSimulationV2([fmuDirUri, ]modelIdentifier[, loggingOn=False, timeDiffResolution=1e-9])

This class provides a basic Python wrapper that offers a set of convenient methods for accessing and manipulating FMUs for Co-Simulation according to the FMI CS V2.0 standard. Instances of class FMUCoSimulationV2 own the actual FMU instance.

When creating the first instance of this class, the FMU has to be loaded. For this, the URI to the unzipped FMU has to be provided:

fmu = fmipp.FMUCoSimulationV2(fmuDirUri, modelIdentifier, False, 1e-9)

An FMU can be instantiated many times (provided capability flag canBeInstantiatedOnlyOncePerProcess is False). In case you want to have more than one instance of the same FMU, just create another instance of this class without providing the URI to the unzipped FMU (the FMU will have already been loaded in the background the first time):

fmu = fmipp.FMUCoSimulationV2(modelIdentifier, False, 1e-9)
Parameters
  • fmuDirUri (str) – URI to the unzipped FMU

  • modelIdentifier (str) – model identifier of the FMU

  • loggingOn (bool) – enable logger for debugging

  • timeDiffResolution (float) – internal resolution for comparing time differences

Methods for interacting with the FMU

instantiate(instanceName, timeout, visible, interactive)

This functions creates a new internal FMU instance. This function must be called successfully, before any of the following functions can be called.

Parameters
  • instanceName (str) – a unique identifier for a given FMI component instance, used to identify a component within a co-simulation graph model and for logging messages

  • timeout (float) – a communication timeout value in milli-seconds to allow interprocess communication to take place (a value of 0 indicates an infinite wait period)

  • visible (bool) – indicates whether or not the simulator application window needed to execute a model should be visible (False indicates that the simulator is executed in batch mode, True indicates that the simulator is executed in interactive mode)

  • interactive (bool) – indicates whether the simulator application must be manually started by the user (False indicates that the co-simulation tool automatically starts the simulator application and executes the model referenced in the model description, True indicates that the simulator application must be manually started by the user)

Return type

int (statusOK, statusWarning, statusDiscard, statusError or statusFatal)

initialize(startTime, stopTimeDefined, stopTime)

Informs the FMU instance that the simulation run starts now.

Parameters
  • startTime (float) – can be used together with stopTime to check whether the model is valid within the given boundaries or to allocate memory which is necessary for storing results

  • stopTimeDefined (bool) – if True, the FMU returns statusError if the environment tries to compute past stopTime.

  • stopTime (float) – can be used together with startTime to check whether the model is valid within the given boundaries or to allocate memory which is necessary for storing results

Return type

int (statusOK, statusWarning, statusDiscard, statusError or statusFatal)

doStep(currentCommunicationPoint, communicationStepSize, newStep)

The computation of a time step is started.

Parameters
  • currentCommunicationPoint (float) – current communication point of the cco-simulation algorithm

  • communicationStepSize (float) – communication step size (if the co-simulation algorithm carries out an event iteration the parameter is 0)

  • newStep (bool) – parameter not used (only for consistency with methods doStep from class FMUCoSimulationV1)

Return type

int (statusOK, statusWarning, statusDiscard, statusError or statusFatal)

terminate()

Is called by the co-simulation algorithm to signal the end of the co-simulation run.

Methods for getting/setting values

getBooleanValue(name)
Parameters

name (str) – variable name

Return type

bool

getIntegerValue(name)
Parameters

name (str) – variable name

Return type

int

getRealValue(name)
Parameters

name (str) – variable name

Return type

float

getStringValue(name)
Parameters

name (str) – variable name

Return type

str

getLastStatus()
Return type

int (statusOK, statusWarning, statusDiscard, statusError or statusFatal)

getTime()
Return type

float

getType(name)

Get information about the type of a variable.

Parameters

name (str) – variable name

Return type

int (typeReal, typeInteger, typeBoolean, typeString or typeUnknown)

getValueRef(name)

Get the value reference of a variable.

Parameters

name (str) – variable name

Return type

int

setBooleanValue(name, val)
Parameters
  • name (str) – variable name

  • val (bool) – vew value for the variable

Return type

int (statusOK, statusWarning, statusDiscard, statusError or statusFatal)

setIntegerValue(name, val)
Parameters
  • name (str) – variable name

  • val (int) – vew value for the variable

Return type

int (statusOK, statusWarning, statusDiscard, statusError or statusFatal)

setRealValue(name, val)
Parameters
  • name (str) – variable name

  • val (float) – vew value for the variable

Return type

int (statusOK, statusWarning, statusDiscard, statusError or statusFatal)

setStringValue(name, val)
Parameters
  • name (str) – variable name

  • val (str) – vew value for the variable

Return type

int (statusOK, statusWarning, statusDiscard, statusError or statusFatal)

Methods for retrieving model description flags

canBeInstantiatedOnlyOncePerProcess()
Return type

bool

canHandleEvents()
Return type

bool

canHandleVariableCommunicationStepSize()
Return type

bool

canInterpolateInputs()
Return type

bool

canNotUseMemoryManagementFunctions()
Return type

bool

canRejectSteps()
Return type

bool

canRunAsynchronuously()
Return type

bool

canSignalEvents()
Return type

bool

maxOutputDerivativeOrder()
Return type

int

nEventInds()
Return type

int

nStates()
Return type

int

nValueRefs()
Return type

int

Miscellaneous methods

setCallbacks(logger, allocateMemory, freeMemory, stepFinished)

Set FMU callback functions.

Return type

int (statusOK, statusWarning, statusDiscard, statusError or statusFatal)

setComponentEnvironment(env)

Set a pointer to a data structure in the simulation environment that calls the FMU. Via this pointer, data from the model description file can be transferred between the simulation environment and the logger function.

logger(status, category, msg)

Call the FMU’s logger.

Parameters
  • status (int) – logger status

  • category (str) – logger category

  • msg (str) – logger message

sendDebugMessage(msg)

Send a debug message.

Parameters

msg (str) – debug message