This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Co-Simulation Numerical Compensation

Simulink® supports co-simulation between components. Co-simulation signals typically represent continuous physical quantities that are discretized due to co-simulation. In Simulink, co-simulation occurs between components with local solvers or involves simulation tools. For example, co-simulation can be an S-function implemented as a co-simulation gateway between Simulink and third-party tools or custom code. It can also be a Functional Mockup Unit (FMU) in co-simulation mode imported to Simulink.

Data exchanges between co-simulation components such as C MEX S-functions and Co-Simulation FMU blocks can introduce numerical inaccuracies from signal delays. Use numerical compensation to improve numerical behavior for simulation involving components that use their own solver.

Simulink automatically performs numerical compensation for co-simulation signals, which are between co-simulation components. Simulink performs numerical compensation at the input of the receiving block. A signal is automatically qualified if its source port and destination port satisfy these conditions:

  • The source port for the signal must satisfy these requirements:

    • S-Function

      • Output port data type is double

      • Output port sample time is periodic and discrete

      • Output port complexity is real

      • ssSetOutputPortIsContinuousQuantity() is set to true for the port

    • FMU

      • Output port datatype is double

      • FMU is in co-simulation mode

      • Block sample time is periodic and discrete

      • Output port maps to a variable with variability='continuous' in modelDescription.xml

  • The destination port for the signal must satisfy these requirements:

    • S-Function

      • Input port data type is double

      • Input port sample time is periodic and discrete

      • Input port complexity is real

      • ssSetInputPortIsContinuousQuantity() is set to true for this port

      • ssSetInputPortDirectFeedThrough() is set to false for this port

    • FMU

      • Input port data type is double

      • FMU is in co-simulation mode

      • Block sample time is periodic and discrete

      • Input port maps to a variable with variability='continuous' in modelDescription.xml

When Simulink detects the signals that can have numerical compensation, it marks the corresponding input ports with the icon.

The following model includes co-simulation signals that can have numerical compensation:

  1. Open the model.

    slexCoSimTripleMassSpringExample

  2. Update the diagram. Simulink detects the signals that can have numerical compensation, and marks the corresponding ports with the icon.

  3. Adjust the parameters for compensation accuracy: Right-click the icon and select Configure Cosimulation Signal Compensation and adjust the calculation parameters:

    • Extrapolation Method — From the list, select Linear, Quadratic, or Cubic. Linear is default.

    • Signal correction coefficient — Specify a coefficient between 0 and 1, where 0 means no correction based on previous steps, 1 is default. Signal coefficient is based on previous steps.

  4. To disable numerical compensation, left-click the icon. When disabled, the icon appears with a red slash.

If automatic compensation is not possible, you can manually enable numerical compensation using the CoSimSignalCompensationMode property.

The CoSimSignalCompensationMode property has these values:

BehaviorSetting

Enable automatic numerical compensation, allowing Simulink to detect if the port has a signal eligible for numerical compensation. Simulink shows the badge if all of these conditions hold:

  • The signal line connects two ports that are both double, real, and continuous.

  • The signal has discrete sample time

  • The destination of the signal is nondirect feedthrough.

'Auto'

Disable automatic numerical compensation. Icon appears with a red slash.

'Auto_Off'

Force the port to be considered numerical compensation compliant, even if the signal is not eligible for numerical compensation. Icon appears with a green rectangle. This setting lets you add compensation without declaring it to be continuous.

'Always'

Disable forcing the port to be considered numerical compensation compliant. Icon appears with a red slash.

'Always_Off'

For example, to disable numerical compensation for the first input port from the previous model:

  1. Select the block for which you want to select the port for numerical compensation. For example, get all the port handles for the currently selected block, gcb.

    p = get_param(gcb, 'PortHandles')

    This function returns all the ports for the currently selected block. For example,

    p = 
    
      struct with fields:
    
          Inport: [22.0001 20.0001]
         Outport: [23.0001 25.0001]
          Enable: []
         Trigger: []
           State: []
           LConn: []
           RConn: []
        Ifaction: []
           Reset: []
  2. To disable numerical compensation for the first port:

    set_param(p.Inport(1), 'CoSimSignalCompensationMode', 'Auto_Off')
    

    The associated port appears with a red slash.

For an example of identifying co-simulation signals for numerical compensation, see the slexCoSimTripleMassSpringExample model.

See Also

| | | | |

Related Topics