Main Content

Model Variants in an Electrical Circuit Using Variant Connector Blocks

This example shows how to simulate the flow of a current in an electrical circuit for different variant configurations using primary and nonprimary type Variant Connector blocks. Variant Connector blocks allow you to activate or deactivate a set of components in the network during simulation without having to physically remove the components or exclude them from simulation.

Explore the Model

To open the Variant Bounded Region in Electrical Circuit example model, at the MATLAB® command prompt, enter : openExample('simscape/VariantBoundedRegionElectricalCircuitExample').

The variant bounded region in electrical circuit example model that represents an electrical circuit

This model has two bounded regions, BoundedRegion_1 and BoundedRegion_2. In BoundedRegion_1, the Connector tag parameters of the Variant Connector blocks are set to Reg1, and in BoundedRegion_2, the Connector tag parameters are set to Reg2. BoundedRegion_1 has one primary Variant Connector block, VC_1, and an associated nonprimary Variant Connector block, VC_2. The variant condition of BoundedRegion_1 is A == 1. BoundedRegion_2 has one primary Variant Connector block, VC_3, and two associated nonprimary Variant Connector blocks, VC_4 and VC_5. The variant condition of BoundedRegion_2 is B == 1.

During simulation, Simulink® computes the variant conditions associated with each bounded region. If the variant condition of a region evaluates to true, all the physical components located inside the region become active. For example, if A == 1 evaluates to true during simulation, the components of BoundedRegion_1, Resistor3 and Resistor4, become active. If A == 1 evaluates to false, the components of BoundedRegion_1 are inactive.

Simulate the Flow of a Current for Different Variant Configurations

The variant condition variables, A and B, are defined in the PostLoadFcn callback. To view or modify the value of these variables, on the Modeling tab, select Model Settings > Model Properties. On the Callbacks tab, in the Model callbacks pane, click PostLoadFcn. In this example, A = 1 and B = 2. The associated bounded region activates based on these variables..

Case 1: BoundedRegion_1 Is Active and BoundedRegion_2 Is Inactive

  1. In the Model Properties window, set the value of A to 1 and B to 2.

  2. Click Run and see the variant conditions propagate from the Variant Connector blocks to the connected components.

  3. To analyze the propagated variant conditions and the block activation state, on the Debug tab, select Information Overlays > Variant Legend. For more information on Variant Condition Legend, see Visualize Propagated Variant Conditions in Variant Conditions Legend.

    • A == 1 evaluates to true. The components inside BoundedRegion_1 become active.

    • B == 1 evaluates to false. The component inside BoundedRegion_2 become inactive.

    The simulation result of the variant bounded region in electrical circuit example model when BoundedRegion1 is active and BoundedRegion2 is inactive

  4. To view the flow of the current in this scenario, double-click the Scope block named Current. Alternatively, on the model, click the Plot link in the Variant Bounded Region in Electrical Circuit table that corresponds to the condition, A == 1 is true and B == 1 is false.

Flow of current in the electrical circuit plotted against time when BoundedRegion1 is active and BoundedRegion2 is inactive

Case 2: BoundedRegion_1 Is Inactive and BoundedRegion_2 Is Active

  1. In the Model Properties window, set the value of A to 2 and B to 1, and then simulate the model..

  2. Analyze the variant conditions and the block activation state.

    • A == 1 evaluates to false. The components inside BoundedRegion_1 become inactive.

    • B == 1 evaluates to true. The component inside BoundedRegion_2 become active.

  3. View the flow of the current in Current, or click the Plot link in the Variant Bounded Region in Electrical Circuit table that corresponds to the condition, A == 1 is false and B == 1 is true.

    Flow of current in the electrical circuit plotted against time when BoundedRegion1 is inactive and BoundedRegion2 is active

Similarly, you can set the value of A and B to 0 and analyze how both the regions become inactive during simulation.

Related Topics