modelReal_Real

Block that exchanges a vector of real values with a Python function

Extends from Modelica.Blocks.Interfaces.DiscreteBlock (Base class of discrete control blocks).

Information

Block that exchanges data with a Python function that does not need to pass an object from one call to the next.

For each element in the input vector uR[nDblWri], the value of the flag flaDblWri[nDblWri] determines whether the current value, the average over the sampling interval or the integral over the sampling interval is sent to Python. The following three options are allowed:


flaDblWri[i] Value sent to Python
0 Current value of uR[i]
1 Average value of uR[i] over the sampling interval
2 Integral of uR[i] over the sampling interval

If the function needs to pass an object from one invocation to the next, set passPythonObject = true. Otherwise, leave it at its default value passPythonObject = false.

Parameters

TypeNameDefaultDescription
SI.TimesamplePeriod (from DiscreteBlock)Sample period of component
SI.TimestartTime (from DiscreteBlock)0First sample time instant
StringmoduleNameName of the python module that contains the function
StringfunctionNamemoduleNameName of the python function
IntegernDblWriNumber of double values to write to Python
IntegernDblReaNumber of double values to be read from the Python
Integerflag0Flag for double values (0: use current value, 1: use average over interval, 2: use integral over interval)
Integer[nDblWri]flaDblWrifill(flag, nDblWri)Flag for double values (0: use current value, 1: use average over interval, 2: use integral over interval)
BooleanpassPythonObjectfalseSet to true if the Python function returns and receives an object, see User's Guide

Connectors

TypeNameDefaultDescription
Modelica.Blocks.Interfaces.RealInput[nDblWri]uRReal inputs to be sent to Python
Modelica.Blocks.Interfaces.RealOutput[nDblRea]yRReal outputs received from Python

Components

TypeNameDefaultDescription
Real[nDblWri]uRIntValue of integral
Real[nDblWri]uRIntPreValue of integral at previous sampling instance
Real[nDblWri]uRWriValue to be sent to Python
Real[nDblWri]uRWri_tempInternal value

Revisions

  • September 19, 2025, by Michael Wetter:
    Updated to Python 3.12.
  • August 27, 2021, by Michael Wetter:
    Updated to Python 3.8.
  • April 10, 2020, by Jianjun Hu and Michael Wetter:
    Updated to Python 3.6.
  • March 06, 2020, by Jianjun Hu:
    Corrected implementation so it allows different flag for double values.
    This is for issue #1716.
  • June 9, 2015 by Michael Wetter:
    Set firstTrigger(fixed=true, start=false) to avoid a warning about unspecified initial conditions if Buildings.Obsolete.Utilities.IO.Python27.Examples.KalmanFilter is translated using pedantic mode in Dymola 2016. This is for #426.
  • September 29, 2014, by Michael Wetter:
    Changed algorithm to equation section and assigned start values to avoid a translation warning in Dymola.
  • February 5, 2013, by Michael Wetter:
    First implementation, based on Buildings.Utilities.IO.BCVTB.BCVTB.