Class fmipp.VariableStepSizeFMU¶
-
class
VariableStepSizeFMU
(fmuDirUri, modelIdentifier[, loggingOn=False, timeDiffResolution=1e-4])¶ This class eases the use of FMUs for Co-Simulation in case variable communication step sizes are supported by the FMU. Its handling is very similar to class IncrementalFMU, i.e., it defines the methods
defineRealInputs(...)
,defineRealOutputs(...)
,getRealOutputs(...)
, etc. in an analogous way.Note
This class uses objects of type
SwigPyObject
as inputs and outputs, which are wrappers around C/C++ arrays. Instantiation of and data access to these objects should be done via the corresponding helper functions.- 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
-
init
(instanceName, realVariableNames, realValues, nRealVars, [integerVariableNames, integerValues, nIntegerVars, booleanVariableNames, booleanValues, nBooleanVars, stringVariableNames, stringValues, nStringVars, ]startTime, defaultCommunicationStepSize[, stopTimeDefined=False, stopTime=float('inf'), timeout=0, visible=False, interactive=False])¶ Initialize the internal FMU model.
- 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
realVariableNames (SwigPyObject) – names of real variables
realValues (SwigPyObject) – initial values of real variables
nRealVars (int) – number of real variables to be initialized
integerVariableNames (SwigPyObject) – names of integer variables
integerValues (SwigPyObject) – initial values of integer variables
nIntegerVars (int) – number of integer variables to be initialized
booleanVariableNames (SwigPyObject) – names of boolean variables
booleanValues (SwigPyObject) – initial values of boolean variables
nBooleanVars (int) – number of boolean variables to be initialized
stringVariableNames (SwigPyObject) – names of string variables
stringValues (SwigPyObject) – initial values of string variables
nStringVars (int) – number of string variables to be initialized
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 resultsdefaultCommunicationStepSize (float) – default communication step size
stopTimeDefined (bool) – if
True
, the FMU returnsstatusError
if the environment tries to compute paststopTime
.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 resultstimeout (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
- Returns
1 on success, 0 on failure
-
sync
(t0, t1[, realInputs, integerInputs, booleanInputs, stringInputs, iterateOnce=False])¶ Simulate FMU from time
t0
untilt1
. If provided, the inputs are set at the end of the interval [t0
,t1
]. Methodsync(...)
always returns the time of the next FMU communication point. Whenever an FMU communication point is reached, the latest inputs are handed to the FMU. This means, that multiple calls tosync(...)
between two FMU communication points with different inputs will only cause the latest input to be handed to the FMU (no queueing).- Parameters
t0 (float) – simulation interval start time
t1 (float) – simulation interval end time
realInputs (SwigPyObject) – real inputs, previously defined via
defineRealInputs(...)
integerInputs (SwigPyObject) – integer inputs, previously defined via
defineIntegerInputs(...)
booleanInputs (SwigPyObject) – boolean inputs, previously defined via
defineBooleanInputs(...)
stringInputs (SwigPyObject) – string inputs, previously defined via
defineStringInputs(...)
iterateOnce (bool) – if
True
, iterate the FMU (simulation step with length 0) at timet1
- Return type
float
- Returns
time of the next FMU communication point
-
iterateOnce
()¶ Iterate the FMU (simulation step with length 0).
Methods for defining inputs/outputs
-
defineBooleanInputs
(inputs, nInputs)¶ Define boolean inputs to be applied to the FMU via the
sync(...)
method.- Parameters
inputs (SwigPyObject) – initial values of the input variables
nInputs (int) – number of boolean inputs
-
defineBooleanOutputs
(outputs, nOutputs)¶ Define boolean outputs to be retrieved from the FMU via the
getBooleanOutputs(...)
method.- Parameters
outputs (SwigPyObject) – initial values of the output variables
nOutputs (int) – number of boolean outputs
-
defineIntegerInputs
(inputs, nInputs)¶ Define integer inputs to be applied to the FMU via the
sync(...)
method.- Parameters
inputs (SwigPyObject) – initial values of the input variables
nInputs (int) – number of integer inputs
-
defineIntegerOutputs
(outputs, nOutputs)¶ Define integer outputs to be retrieved from the FMU via the
getIntegerOutputs(...)
method.- Parameters
outputs (SwigPyObject) – initial values of the output variables
nOutputs (int) – number of integer outputs
-
defineRealInputs
(inputs, nInputs)¶ Define real inputs to be applied to the FMU via the
sync(...)
method.- Parameters
inputs (SwigPyObject) – initial values of the input variables
nInputs (int) – number of real inputs
-
defineRealOutputs
(outputs, nOutputs)¶ Define real outputs to be retrieved from the FMU via the
getRealOutputs(...)
method.- Parameters
outputs (SwigPyObject) – initial values of the output variables
nOutputs (int) – number of real outputs
-
defineStringInputs
(inputs, nInputs)¶ Define string inputs to be applied to the FMU via the
sync(...)
method.- Parameters
inputs (SwigPyObject) – initial values of the input variables
nInputs (int) – number of string inputs
-
defineStringOutputs
(outputs, nOutputs)¶ Define string outputs to be retrieved from the FMU via the
getStringOutputs(...)
method.- Parameters
outputs (SwigPyObject) – initial values of the output variables
nOutputs (int) – number of string outputs
Methods for getting variable values
-
getBooleanOutputs
()¶ - Return type
SwigPyObject
- Returns
value of boolean outputs
-
getIntegerOutputs
()¶ - Return type
SwigPyObject
- Returns
value of integer outputs
-
getRealOutputs
()¶ - Return type
SwigPyObject
- Returns
value of real outputs
-
getStringOutputs
()¶ - Return type
SwigPyObject
- Returns
value of string outputs
Miscellaneous methods
-
getLastStatus
()¶ - Returns
status returned by latest internal FMU function call
- Return type
int (
statusOK
,statusWarning
,statusDiscard
,statusError
orstatusFatal
)