pythonfmi

FMI - Amesim, Can be modified Local variables under ModelExchange?


Main Goal

Modify the Local variables exposed in the FMU under ModelExchange with FMPy.

Approach

  1. Take the FMU already created from the FMI standard web.
  2. Launch it with FMPY.
  3. Change value every step with step_finished parameter from simulate_fmu with my_callback function.

First step

FMU is loaded perfectly, can modify all the values declared as casuality= "input" or "output" also some with variability = "tunable".

The problem

Variables declares as casuality= "Local" cant be modified, and I would like to be able to interact with some of these variables to be able to access the internal states of the model, these states are all declared as local, according to the documentation they are internal variables used by the FMU.

This is how looks the variable in the XML

enter image description here

I have tried to modified it via fmi2setReal:

enter image description here

but then i get the next error:

enter image description here

My question

could be that variable modified in any way?


Solution

  • In event mode, this is definitely not possible. According to the FMI 2.0.1 specification, page 127-128, only variables with "input" causality or "parameter" causality and "tunable" variability can be changed using fmi2SetReal.

    In continuous-time mode, it could be possible to set indirectly the value of a local continuous variable, if it is also a continuous-time state variable, refereed to by another scalar variable listed under the ModelStructure Derivatives tag. This can be done by calling the fmi2SetContinuousStates function.

    Regarding the case you showed, this local variable seems to be an (internal) input variable of a Simcenter Amesim DYNMUX submodel, and as such it it a purely internal variable that cannot be modified. However, if this input variable is connected to another submodel which has a state variable as output, it could be possible to change its value.