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')
.
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
In the Model Properties window, set the value of
A
to1
andB
to2
.Click Run and see the variant conditions propagate from the Variant Connector blocks to the connected components.
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 totrue
. The components inside BoundedRegion_1 become active.B == 1
evaluates tofalse
. The component inside BoundedRegion_2 become inactive.
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
istrue
andB == 1
isfalse
.
Case 2: BoundedRegion_1 Is Inactive and BoundedRegion_2 Is Active
In the Model Properties window, set the value of
A
to2
andB
to1
, and then simulate the model..Analyze the variant conditions and the block activation state.
A == 1
evaluates tofalse
. The components inside BoundedRegion_1 become inactive.B == 1
evaluates totrue
. The component inside BoundedRegion_2 become active.
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
isfalse
andB == 1
istrue
.
Similarly, you can set the value of A
and B
to
0
and analyze how both the regions become inactive during
simulation.