CATIA-Systems / FMIKit-Simulink

Import and export Functional Mock-up Units with Simulink
Other
157 stars 51 forks source link

FMU Import has to be repeated for every restart of MATLAB session #280

Closed gowthamsrinivasan closed 2 years ago

gowthamsrinivasan commented 3 years ago

I am able to import the FMU (which was exported using gtrfmi coder target) into FMU Import Block of FMIKit, and I am also able to simulate. After saving this block in a Simulink Library model, when I start a new MATLAB session and simulate the saved model, I expect that the model should work as before. Instead, I get the following error:

image

And the FMU Block looks as if the interfaces cannot be read.

image

It works after I reload the FMU into the block. Is this a known issue? Is there a path problem here?

t-sommer commented 3 years ago

Did you move or delete the folder with the extracted FMU (FMU Dialog > Advanced > Unzip directory)?

gowthamsrinivasan commented 3 years ago

My expectation is that if the extracted folder is not available, the tool shall unzip the .fmu file again as long as it finds the .fmu in the MATLAB path.

Nevertheless, I haven't moved the extracted folder. I just restarted MATLAB and simulated again. The .fmu is also found in MATLAB path, and the extracted folder is also available: image

Still I am facing the issue.

t-sommer commented 3 years ago

Can you provide steps to reproduce the problem with v3.0-alpha.1?

gowthamsrinivasan commented 3 years ago

I installed the new zip to reproduce the problem, and this time I see access violation error.

  1. Open MATLAB (2018b) and set relevant folders to MATLAB path
  2. Initialize FMI Kit
  3. Import the FMU in MATLAB path into the Simulink model
  4. Simulate the model to verify the FMU
  5. Save the model with the imported FMU Block
  6. Close MATLAB
  7. Reopen MATLAB, add (same) folders to MATLAB path and load the Simulink model
  8. Initialize FMU Kit
  9. Simulate the model.

image


Error reported by S-function 'sfun_fmurun' in '<Model>/<Subsystem>/FMU':
The FMU reported an error.
Component:Simulink | Category:Block error
Error reported by S-function 'sfun_fmurun' in '<Model>/<Subsystem>/FMU':
The FMU crashed (exception code 0xc0000005 (ACCESS_VIOLATION)).
fajansen commented 3 years ago

My expectation is that if the extracted folder is not available, the tool shall unzip the .fmu file again as long as it finds the .fmu in the MATLAB path.

That would also be my expectation!

gowthamsrinivasan commented 3 years ago

@t-sommer Do you have any updates?

Marvin-TMG commented 3 years ago

Are you calling FMIKit.initialize first thing before opening the model? We have a similar issue and this was the root cause. To avoid some headaches, we patched FMIKit to automatically initialize. There still seem to be a few cases where we see the same problem with the ports/model disappearing. With regards to automatically unzipping if the path does not exist, that would be a useful feature. But I think the unzipping happens in the GUI / Java code, so you would need to patch that