Documentation

Condition Propagation with Variant Subsystem

When you specify variant conditions in models containing Variant Subsystem blocks, Simulink® propagates these conditions to determine which components of the model are active during simulation. A variant condition can be a condition expression or a variant object.

The variant condition annotations help you visualize the propagated conditions. To view the variant condition annotations, click Display > Blocks > Variant Condition Legend.

Note

The Variant Condition Legend option is available only when Display > Blocks > Variant Condition is active.

Consider this model containing a Variant Subsystem block with variant choices. A specific variant condition activates each block.

In the Variant Subsystem (Controller), sensor1 and sensor3 are used both in the Linear Controller and Nonlinear Controllers but sensor2 is used only in the Linear Controller. Hence, the sensor2 block is executed only when the Linear Controller choice is active and is not executed for any other choice. To ensure that the components outside of the Variant Subsystem (Controller) are aware of the active or inactive state of blocks with the Variant Subsystem, the block condition must propagate outside of the Variant Subsystem.

Propagate Conditions Without Generate Preprocessor Conditionals

To propagate conditions outside of Variant Subsystems without generate preprocessor conditionals, select the Propagate conditions outside of variant subsystem check box in the Block Parameter dialog box of the Variant Subsystem block. By default, Propagate conditions outside of variant subsystem is not selected.

When you simulate the model with the active choice as Nonlinear Controller and the Propagate condition outside of variant subsystem selected, only the active choice is analyzed. Notice that the Analyze all choices during update diagram and generate preprocessor conditional check box is not selected.

The Variant Condition Legend displays the inactive conditions as false. Here, sensor2 is inactive with variant choice as Nonlinear Controller and is marked as false. The annotations are displayed on the sensor2 port and the inactive block that is connected to sensor2.

When you generate code for condition propagation without generate preprocessor conditionals, the inactive blocks are ignored. In this example, the input port In2 is not shown in the generated code.

Propagate Conditions with Generate Preprocessor Conditionals

To propagate conditions outside of Variant Subsystem with generate preprocessor conditionals, select the Propagate conditions outside of variant subsystem check box and the Analyze all choices during update diagram and generate preprocessor conditionals check box in the Block Parameter dialog box of the Variant Subsystem.

When you simulate the model with active choice as Nonlinear Controller and Propagate conditions outside of variant subsystem check box and the Analyze all choices during update diagram and generate preprocessor conditionals check box selected, all the variant choices are analyzed. The Variant Condition Legend displays the variant conditions associated with the model.

When you generate code for condition propagation with generate preprocessor conditionals, the model is analyzed for all the choices. In this example, the input port In2 is guarded with necessary conditions.

Adaptive Interface for Variant Subsystems

When you select the Propagate conditions outside of variant subsystem check box in the Block Parameters dialog box, the Variant Subsystem adapts its interface to the connected blocks. Consider this model.

The Controller block is a Variant Subsystem that provides a Linear and a Nonlinear choice. The Linear choice is active when V = 1, and the Nonlinear choice is active when V = 2. Here, V is a variant control variable of the Simulink.Parameter type. Select the Controller block and, in Simulink click Diagram > Block Parameters (Subsystem). Verify that the Propagate condition outside of variant subsystem check box is selected.

To change the value of the variant control variable, in the MATLAB command window, type V.Value = 1 or V.Value = 2.

Double-click the Controller block to view its contents. The Linear choice is using sensor1 and sensor3 inputs of the Controller (Variant Subsystem block). It is not using sensor2 and, therefore, does not produce a saturate output.

When you simulate this model, the Variant Subsystem block adapts its interface such that the condition V = 2 (v:1 V=2) propagates the In2, the filter, and the saturation logger blocks.

Known Limitations

  • Propagated variant conditions from variant subsystems cannot be set on blocks in Simscape™ domain or Stateflow based blocks.

  • C++ code generation is not supported for models that contain propagated conditions outside of a Variant Subsystem.

  • The propagated conditions to a Variant Subsystem choice block must be a subset of the variant condition on the variant subsystem block itself.

Propagate Conditions Programmatically

To propagate conditions outside of Variant Subsystem programmatically, use one of these syntaxes:

  • Propagate conditions without generate preprocessor conditionals:

    set_param(VariantSubsystemName, 'PropagateVariantConditions','on')

    For example,

    set_param('sldemo_variant_subsystems/Controller','PropagateVariantConditions','on')
  • Propagate conditions with generate preprocessor conditionals:

    set_param(VariantSubsystemName,'PropagateVariantConditions',...
    'on','GeneratePreprocessorConditionals','on')

    For example,

    set_param('sldemo_variant_subsystems/Controller','PropagateVariantConditions','on',...
    'GeneratePreprocessorConditionals','on')

Related Topics

Was this topic helpful?