CATIA-Systems / FMIKit-Simulink

Import and export Functional Mock-up Units with Simulink
Other
155 stars 50 forks source link

How to use FMI.set/getStartValue for hierarchical values ? #391

Closed JBRDLR closed 1 year ago

JBRDLR commented 1 year ago

Functions work fine if values are top level values. When it comes to values in Submodels e.g. Infinity_C (Infinity's capacity) i do get the following error: FMIKit.getStartValue(gcb, 'infinty_C') Error using FMIKit.getStartValue (line 19) Java exception occurred: java.lang.RuntimeException: Variable 'infinty_C' does not exist at fmikit.ui.FMUBlockDialog.getStartValue(FMUBlockDialog.java:1611)

How does this need to be formatted to work?

Many thanks,

JBR

t-sommer commented 1 year ago

Can you share an FMU and some code to reproduce the problem?

JBRDLR commented 1 year ago

We develop IEEE MVC 2023 control competition - It will be announced via different channels the next week. Simply follow the installation instructions (about 1min). Afterwards open the testEnergyManagementAlgorithm.slx and select the FMU block. Afterwards, when you run in the MATLAB comandline: _FMIKit.getStartValue(gcb, 'SOCinit') --> Works fine, because it is atop level variable But this will fail: _FMIKit.getStartValue(gcb, 'powerSource_rex_REXparameters_H2_tank_level') Error using FMIKit.getStartValue (line 19) Java exception occurred: java.lang.RuntimeException: Variable 'powerSource_rex_REXparameters_H2_tanklevel' does not exist at fmikit.ui.FMUBlockDialog.getStartValue(FMUBlockDialog.java:1611) The Name of the variable seems to be correct when - i extracted it from the userData _userData = getparam(gcb, 'UserData') userData.parameters

Many thanks in advance,

Best JBR

t-sommer commented 1 year ago

You have to use the name as defined in the modelDescription.xml:

...
    <!-- Index for next variable = 4923 -->
    <ScalarVariable
      name="powerSource.rex.REXparameters.H2_tank_level"
      valueReference="16777500"
      description="10-3[kg] H2 tank initial level value"
      causality="parameter"
      variability="tunable">
      <Real start="4000.0"/>
    </ScalarVariable>
...
JBRDLR commented 1 year ago

Many thanks!