Search code examples
pythonsimulinkopenmodelicafmi

fmi2GetFMUState/fmi2SetFMUState supported for Matlab/OpenModelica generated FMUs?


I am trying to test a simple fmu to save and restore the states.

For example openmodelica:

model modelicatest
input Real In1;
output Real Out1(start=0, fixed=true);
equation
der(Out1) = In1;
end modelicatest;

Also for simulink:

enter image description here

I am using FMPy to simulate the generated FMUs.

But for OpenModelica v1.14.1 generated FMU, I get the following error when I call getFMUState from FMPy:

Exception: fmi2GetFMUstate failed with status 3

For Simulink (2019b) generated FMU using the built-in exporter, FMU state does not reset (i.e. the output value) when I run setFMUState.

Just wondering these functions are supported for OpenModelica and Simulink generated FMUs? or is it FMPy issue?


Solution

  • With respect to fmi2GetFMUstate/fmi2SetFMUstate, the FMI Specification, section 2.1.8. states:

    These functions are only supported by the FMU, if the optional capability flag <fmiModelDescription> <ModelExchange / CoSimulation canGetAndSetFMUstate in = "true"> in the XML file is explicitly set to true (see sections 3.3.1 and 4.3.1).

    You can unzip the fmu file and take a look at the modelDescription.xml file to find out if the flag is set: If it is false or not set all, the get and set functions are not supported.