%% Simulate Variant Blocks in Accelerator and Rapid Accelerator Modes with Startup Activation Time
% This example shows how to simulate Variant Source and Variant Sink blocks
% in accelerator and rapid accelerator mode with |startup| variant 
% activation time.
%
% Both modes enable faster simulation without changing the 
% model itself. The accelerator and rapid accelerator modes replace the 
% normal interpreted code with compiled target code. Using compiled code 
% speeds up simulation of many models, especially those where runtime is 
% long compared to the time associated with compilation and checking to see 
% if the target is up to date. For more information on accelerator modes,
% see <docid:simulink_ug#brc69gc How Acceleration Modes Work>.
%
% Combined with the |startup| variant activation time, simulating in 
% accelerator or rapid accelerator mode retains all variant choices. Thus  
% incremental simulation does not regenerate code when there are no 
% structural changes in the model and you only change the variant control 
% value.

% Copyright 2021 The MathWorks, Inc.

%% Model 
% Open the model |slexVariantSourceAndSinkWithStartup.slx|. The 
% |Variant Source1| has conditions |X==1| and |X==2| for its input ports. 
% The block named |Variant Source1| has an |update diagram| activation time. 
% |X| is a variant control variable and is defined in the |PostLoadFcn| of 
% *File -> Model Properties -> Callbacks*. The |Sine3| block is active when 
% |X==1| is true, and the |Sine4| block is active when |X==2| is true. 
%
% In the block named |Variant Source2| block, the first input port is active 
% when |V==1| is true.The second input port is active when |V==2| is true. 
% The |Variant Source2| has a |startup| activation time. 
% 
% The block named |Variant Sink| has the conditions |W==1| and |W==2| on 
% its output ports. These conditions are propagated to the connected blocks. 
% The |Gain5| block is assigned the condition |W==1|.The second output port 
% of the |Variant Sink| block has the condition |W==2|. This condition is 
% propagated to the |Out4| block.
% 
% Since the |Variant Source2| and |Variant Sink| blocks have a |startup| 
% activation time, all the choices are available. You can toggle the active 
% or inactive branch just before simulation. 
%
%%
open_system('slexVariantSourceAndSinkWithStartup.slx');
%% Simulate the Model
% Before you run the simulation, set the mode to be either *Accelerator* or
% *Rapid Accelerator*. 
%% 
%    sim(slexVariantSourceAndSinkWithStartup);
% 
% You can generate code by clicking on *Build ERT* or *Build GRT*. The 
% generated code from Embedded Coder (ERT) or Simulink Coder (GRT) will 
% have regular |if| conditions. For more information on generating code 
% with |startup| activation time, see
% <docid:simulink_ug#mw_1455889c-c8b9-4fc0-89cf-459c46d5c852 Generate Code from Variant Blocks with Startup Activation Time>.

