The causality attribute

2 posts / 0 new
Last post
michaelb
Offline
Joined: 2017-04-11
The causality attribute

Hi,

We are currently working on using the PyFMI module in order to evaluate these models. I must thank the developpers for providing this tool which simplifies our task greatly.

We are trying to clear up the causality attribute.

In [1], we can read that the four possible values of the causality attribute are : parameter, input, output, local. In the PyFMI module v2.4 however, the available constants are

>>> pyfmi.fmi.FMI2_PARAMETER
0
>>> pyfmi.fmi.FMI2_INPUT
2
>>> pyfmi.fmi.FMI2_OUTPUT
3
>>> pyfmi.fmi.FMI2_LOCAL
4

As you can see, there is a missing value : 1 does not appear. From the following changeset, I can see that there was a fix so that the Python doc prints values consistent with the code. :

https://trac.jmodelica.org/changeset/7983

However, the changeset presents values of the causality attribute which were not specified in [1], i.e. "Calculated Parameter", "Independent" and "Unknown".

In order to make things clear, do we agree that the following code allows to print the causality of all variables in a given FMU ?

allthevariables=mymodele.get_model_variables()
modeleversion = mymodele.get_version()

for name in allthevariables:
myvar = allthevariables[name]
if (modeleversion=="1.0"):
if(myvar.causality==pyfmi.fmi.FMI_OUTPUT):
print "OUTPUT"
elif(myvar.causality==pyfmi.fmi.FMI_INPUT):
print "INPUT"
elif(myvar.causality==pyfmi.fmi.FMI_INTERNAL):
print "INTERNAL"
elif(myvar.causality==pyfmi.fmi.FMI_NONE):
print "NONE"
else:
print "UNKNOWN"
elif (modeleversion=="2.0"):
if(myvar.causality==pyfmi.fmi.FMI2_PARAMETER):
print "PARAMETER"
elif(myvar.causality==pyfmi.fmi.FMI2_INPUT):
print "INPUT"
elif(myvar.causality==pyfmi.fmi.FMI2_OUTPUT):
print "OUTPUT"
elif(myvar.causality==pyfmi.fmi.FMI2_LOCAL):
print "LOCAL"
else:
print "UNKNOWN"

else:
print "The version of the model :",modeleversion," is unknown"

Best regards,

Michaël

[1] Functional Mockup Interface 2.0: The Standard for Tool independent Exchange of Simulation Models,
T. Blochwitz, M. Otter, J. Akesson, M. Arnold, C. Clauß, H. Elmqvist, M. Friedrich, A. Junghanns, J. Mauss, D. Neumerkel, H. Olsson, A. Viel, Functional Mockup Interface 2.0 The Standard for Tool independent Exchange of Simulation Models - Modelica 2012.pdf

michaelb
Offline
Joined: 2017-04-11
A colleague just found the

A colleague just found the file

https://trac.jmodelica.org/browser/PyFMI/trunk/src/pyfmi/fmi.pyx

which makes things much clearer.

As far as I can see, there is a inconsistency between the standard as defined in [1] and the PyFMI module. Indeed, the PyFMI module defines the two causality "CALCULATED_PARAMETER" and "INDEPENDENT", which were not presented in [1] :

 

FMI2_INPUT     = FMIL.fmi2_causality_enu_input
FMI2_OUTPUT    = FMIL.fmi2_causality_enu_output
FMI2_PARAMETER = FMIL.fmi2_causality_enu_parameter
FMI2_CALCULATED_PARAMETER = FMIL.fmi2_causality_enu_calculated_parameter
FMI2_LOCAL       = FMIL.fmi2_causality_enu_local
FMI2_INDEPENDENT = FMIL.fmi2_causality_enu_independent

Am I right ?

If this is correct, this means that the "Unknown==6" value presented in the docstring does not match this list where the "Unknown" causality is not defined.

With respect to the design of the Python module, I'd rather use the variable name FMI2_CAUSALITY_INPUT than the current name FMI2_INPUT, because it makes it clear that this enum is linked to the causality attribute. Don't you think so ?

Best regards,

Michaël

Login or register to post comments