Manage Model Fidelity Using Variants
This example shows how to compare and contrast modeling different fidelity levels by using variants. The controller model uses a Variant Source block configured in Expression mode. The plant model uses a Variant Subsystem.
To permit easy interaction, this example demonstrates the commands you must type to configure the model from the command line.
Create variant controls for the converter controller. The controller has three different levels of fidelity: Averaged, AveragedPulse, and Pulse.
Averaged = Simulink.Variant; Averaged.Condition = 'fidelity==FidelityVariantsEnum.Low';
AveragedPulse = Simulink.Variant; AveragedPulse.Condition = 'fidelity==FidelityVariantsEnum.Medium';
Pulse = Simulink.Variant; Pulse.Condition = 'fidelity==FidelityVariantsEnum.High';
Create variant controls for the converter plant. The plant has two different levels of fidelity.
AveragedSwitch = Simulink.Variant; AveragedSwitch.Condition = 'fidelity==FidelityVariantsEnum.Low || fidelity==FidelityVariantsEnum.Medium';
IdealSwitch = Simulink.Variant; IdealSwitch.Condition = 'fidelity==FidelityVariantsEnum.High';
Averaged Control Output, Averaged Switch Converter
Configure the model to run in low fidelity with a timestep of 100us.
fidelity = FidelityVariantsEnum.Low; Ts = 1e-4;
Averaged Pulse Control Output, Averaged Switch Converter
Configure the model to run in medium fidelity with a timestep of 50us.
fidelity = FidelityVariantsEnum.Medium; Ts = 5e-5;
Pulse Control Output, Ideal Switch Converter
Configure the model to run in high fidelity with a timestep of 10us.
fidelity = FidelityVariantsEnum.High; Ts = 1e-5;
Results from Real-Time Simulation
This example, with level of fidelity set to Low and Medium, has been tested on a Speedgoat Performance real-time target machine with an Intel® 3.5 GHz i7 multi-core CPU. This model can run in real time with a step size of 50 microseconds.