MATLAB: There is a time delay of one time step while co-simulating a FMU in Simulink

delaydifferentfmifmuresultssimulinksteptime

I exported an FMU from a Simulink model with Simulink Compiler and imported it into Simulink with FMU Import block.
In the results, when comparing the Simulink output and the FMU output, I see that they do not match with a one-time step difference/one-time step delay.

What is causing this behavior?

Best Answer

The delay you see in co-simulation is a documented behavior for co-simulation of FMUs and standardized in the FMI standard.
Here is a reference in our documentation:
"You might experience an expected time delay in the exported FMU for Co-Simulation mode."
 
Due to co-simulation, there must be a time delay for communication between the local solver of the FMU and the Simulink solver. This is analogously the case in other simulation software when the FMU is co-simulated.
Here you can find more information about this and also ways how this can be intercepted under certain circumstances with special FMUs (which have certain properties) by so-called Numerical Compensation:
By the way, you define the step size of this delay via the Communication Step Size: