Magic Model Analyst supports Simulink (MATLAB) co-simulation. Simulation executes the entire Simulink model (*.slx) on all steps, if there are any value changes in the input, which is similar to FMI. Simulation works with Simulink models as attached files and Simulink models located in the same directory of the project.

Warning

  • You must successfully integrate MATLAB Version 2016b or later before using Simulink co-simulation. See Integration with MATLAB.
  • Any duplicated Simulink model is not allowed in the project.

Note

  • Simulink models without input/output Ports are not executed because there is no connectivity, and value change is not propagated to the Block.
  • This type of Simulink integration is for atomic calculations. When any input changes, outputs such as the parametric diagram are calculated, e.g. In1 → Gain5 → Out1. It occurs as one step of Simulation time, the same as FMU.
  • If the simulink file (.slx) is updated or modified, Simulation needs to restart the MATLAB session by calling the kill matlab command in the Simulation console.

To use Simulink co-simulation


  1. Drag a Simulink model into the Block Definition diagram or Internal Block diagram of the project. The Simulink Import Options dialog will be shown as in the figure below. All input/output Ports are selected by default.

    The Simulink Import Options dialog is shown after dragging a Simulink model into the Block Definition diagram or Internal Block diagram of the project.

    Note

    • You can select the Attach file to the project option to attach the model to be displayed in the Containment tree.
    • The model will be shown as «SimulinkBlock» «Block».
    • The Block name will be used as the model name.
    • Input and output Ports of the Block will be exposed as Flow Ports with directions.
  2. Connect those Flow ports through binding Connectors  in the Internal Block diagram.
  3. Run the simulation. When inputs are available for initialization (e.g., passed via binding), «SimulinkBlock» will be run at the first time and on every input change. You can also see animation of Flow Ports and set breakpoints for debugging.

From the figure below, a system is with two Simulink models: GainAdd and Gain5. GainAdd will multiply Port In1 by 10, multiply Port In2 by 2, and add the two results to Port Out1. Gain5 will multiply Port m by 5. Therefore, result will be [(2 * 10) + (2 * 2)] * 5 = 120.

The Simulink co-simulation result from the system which has two Simulink models (GainAdd.slx and Gain5.slx) connected via Flow Ports.

A Simulink model can be used in the Activity diagram through drag-and-drop operation. The dropped Simulink file is presented as an Activity in the Containment tree with the same name as the Simulink model name, and «SimulinkBlock» is automatically applied. Parameters and directions are the same as the Simulink In/Out ports and can be used as a CallBehaviorAction on demand as shown in the figure below.

A Simulink model, sumInport1, is presented as an Activity and used as a CallBehaviorAction in the Activity diagram.