Main Content

Co-Simulation Signal Compensation

This example shows how to use co-simulation and signal compensation for interfacing signals.

In co-simulation application, components simulate with local solvers. Local solvers maintain separate timelines and integrate from a previous time point to the current time using I/O data exchanged between components and integration model. Co-simulation components do not expose internal states to global solver.

When co-simulation components are integrated in Simulink, you can use periodic discrete rate to exchange I/O data between components. However, communication between co-simulation components may introduce error caused by one-step delay during data exchange. This may cause simulation to be less accurate or unstable.

To mitigate this issue, Simulink automatically identifies interfacing signals between these components that are eligible for numerical compensation. These signals are ideally continuous quantities that have to be discretized due to co-simulation. Simulink automatically compensate for these signals to reduce co-simulation error. A 'gear' icon is displayed on input port if a signal is compensated.

Two co-simulation components with PI Controller

This example model contains two co-simulation components and a discrete PI controller. A monolithic system with two continuous rate systems and same PI controller is used as the baseline for result comparison.

Screenshot 3.png

Plant #1, realized by an S-Function cosim_plant1_sfcn.c, is equivalent to a state-space model cosim_plant1.slx:

Screenshot 4.png

Plant #2, realized by a Co-Simulation FMU v2.0 cosim_plant2_fmu.fmu, is equivalent to a transfer function cosim_plant2.slx:

Screenshot 5.png

Both are causal systems where output signal does not directly depend on inputs. Local solver step size is 0.01. Communication step size is 0.3.

After updating integration model, a gear icon appears at the input ports of the two co-simulation components, indicating Simulink has identified a signal eligible for numerical compensation. Alternatively, you can right click on the icon (or block) and open 'Co-simulation Numerical Compensation' dialog:

Screenshot 2.png

  • Continuous Quantity column shows whether the co-simulation component itself has declared its I/O as continuous quantity. If both source and destination of this signal meet certain requirements, Simulink will mark it for auto-compensation. For example, input port 1 of Plant #1 is declared as continuous quantity, but its source, output port 1 of PI controller is a discrete rate control signal. As a result, input pot1 of Plant #1 will not be auto-compensated.

  • Request Compensation column allows you to override this behavior by always allowing or disallowing numerical compensation. When a signal is marked as 'Always' or is already eligible, you can use Advanced compensation settings... button to configure more numerical compensation settings.

The following plots show the difference between enabling and disabling numerical compensation for this model. With numerical compensation turned on:

Screenshot 6.png

Accumulated error due to co-simulation is 0.4342.

Without numerical compensation:

Screenshot 7.png

Accumulated error due to co-simulation is 6.8520.