FMIKit-Simulink icon indicating copy to clipboard operation
FMIKit-Simulink copied to clipboard

Reset and Enable Functionality "Slow" with Co-Simulation

Open Marvin-TMG opened this issue 3 years ago • 3 comments

I just tested the new reset and model enable/disable functionality in the latest development branch, with Model Exchange it seems to work really well and the resetting/enabling happens pretty much as quick as you would expect. However, when running in Co-Simulation, the longer the simulation time has progressed, the longer it takes to initialize the model. I think the simulation time of the internal integrator should be offset to compensate for this.

Marvin-TMG avatar Apr 13 '21 15:04 Marvin-TMG

This would allow the FMU time to deviate from the simulation time. How about automatically resetting the Co-Simulation FMU upon re-enabling?

t-sommer avatar Apr 13 '21 19:04 t-sommer

We need to treat the two options independently (reset/re-enable):

  • Reset: FMU should be reset and FMU time should start at zero, so the simulation time passed to the FMU should be t_simulation - t_reset, where t_reset needs to be updated every time the FMU reset is triggered. The current implementation makes it slow, because I think the FMU needs to catch up from zero to the actual current simulation time
  • Re-enable: When re-enabling the model the correct handling is not trivial, the expected behavior would I think be to ‘pause’ the model and essentially freeze time, until the model is re-enabled. This means that we need to keep track of the elapsed time while the model is enabled and not use the absolute simulation time. I believe that in this case you will get the same behavior in co-simulation as in model exchange. I would recommend checking how the native Simulink FMU implementation handles this and follow the same approach.

Marvin-TMG avatar Apr 13 '21 20:04 Marvin-TMG

Just an update on this, the native Simulink implementation does not permit enabling/disabling in Co-Simulation, it allows this only for Model Exchange. None the less, I think it is a nice feature to have for Co-Simulation as well. We can indeed agree to either reset the model when re-enabling, or freeze time.

FYI: I could confirm that when using ME and pulsing the enable port with a 1s period 50% width pulse, both the native Simulink block and FMIKit produce the same result.

Marvin-TMG avatar Apr 14 '21 09:04 Marvin-TMG