Reduce Models Containing Referenced Subsystems
This example shows how to reduce a Simulink® model that contains Subsystem Reference blocks.
Subsystem reference allows you to save the contents of a subsystem in a separate file and reference it using a Subsystem Reference block. You can create multiple instances referencing the same subsystem file. For more information, see Create and Use Referenced Subsystems in Models.
Using Variant Reducer, you can generate a reduced model that retains only the selected variant configurations that you choose from the parent variant model. For more information on Variant Reducer, see Reduce Variant Models Using Variant Reducer.
Explore Example Model
Open the model slexVariantReducerWiper
.
open_system("slexVariantReducerWiper");
This car windshield wiper model uses subsystem reference to implement the front and rear wipers of a car. The Wiper
subsystem contains two Subsystem Reference blocks named Front Wiper
and Rear Wiper
. Both of these blocks refer to the same subsystem block diagram slexVariantWiperSubsysRef.slx
. This block diagram contains the logic to control the speed of the car's windshield wiper by using different rain sensors.
Open the subsystem block diagram slexVariantWiperSubsysRef
.
open_system("slexVariantWiperSubsysRef");
This model switches between a manual wiper speed setting and different variants of automatic rain sensors based on the variant control variable R
. When the value of R
is 1
, the Rain Sensor Variant Source
block selects Rain Sensor Model 1
as the active input. Similarly, when R
is 2
, Rain Sensor Model 2
is the active input.
Open the Controller
block. The Variant Source block, Vendor
, selects one of these inputs:
manual desired speed
when the value ofR
is not equal to1
or2
.
filtered rain sensor
when the value ofR
is equal to1
or2
.
To view the definition of R
, see the PostLoadFcn
callback of the model. For simulation workflows, the default value of R
is set to 0
, which activates the manual wiper setting.
Open Variant Reducer
1. Open Variant Manager. On the Modeling tab, open the Design section and click Variant Manager.
2. To open Variant Reducer, in the Variant Manager toolstrip, in the Apps section, click Variant Reducer.
Reduce the Model
1. You can modify the reduction settings in the Mode and Options section of the Variant Reducer toolstrip as needed. If you do not modify the settings, Variant Reducer uses default values for reduction.
2. Reduction Mode is set to Specify variant control values
because the model does not have any predefined variant configurations. Since the value of R
is set to 0
in the PostLoadFcn
callback function, that value is picked up for reduction. You can change the value of R
to change the configuration that must be retained in the reduced model.
3. Click Reduce Model. Variant Reducer reduces the top-level model and the referenced subsystem for the variant configuration corresponding to R=0
. The manual wiper setting is retained in the reduced models. The reduced models are named slexVariantReducerWiper_r.slx
and slexVariantWiperSubsysRef_r.slx
by default. This image shows the reduced referenced subsystem model.
For more information on Variant Reducer, see Reduce Variant Models Using Variant Reducer.