Get Started with Fast Restart - MATLAB & Simulink (original) (raw)

When you need to simulate a model iteratively to tune parameters, achieve a desired response, or automate testing, use fast restart to avoid compiling again. Fast restart allows you to perform iterative simulations without compiling a model or terminating the simulation each time. A generic workflow using fast restart involves the following steps.

  1. Enable fast restart using the Fast Restart button on the Simulink® Toolstrip.
  2. Simulate the model.
    The first simulation requires the model to compile, initialize and capture a snapshot of the model operating point. Once the simulation is complete, it does not terminate. Instead, the model is initialized again in fast restart.
  3. Perform any of these actions:
    • Change tunable parameters.
    • Switch between variable-step solvers.
    • Tune root-level inputs.
    • Modify variables in the base workspace or model workspace and data dictionary entries that are referenced by tunable parameters.
    • Change inputs to From File and From Workspace blocks.
    • Change the Initial state parameter for the next simulation.
    • Using the Signal Editor block, change data, rename signals and scenarios, and add new scenarios.
    • Change the signal logging override values for the model programmatically by using the set_param function and the DataLoggingOverride parameter. See Override Signal Logging Settings Programmatically.
      Once you have initialized a model in fast restart, you cannot
    • Change the dimension, type, or complexity of a signal or variable.
    • Make changes to a nontunable parameter such as sample time.
    • Make structural changes such as adding or deleting blocks or connections.
      These changes require you to compile the model again. To make changes like these, turn off fast restart, make your changes, and repeat this procedure.
  4. Simulate the model. The model uses the new values of parameters and inputs that you provided but does not compile again.
  5. Once you have achieved the desired response, turn off fast restart.
    Note
    When you disable fast restart, the software does not retain any compilation information for the model. The model compiles when you next simulate the model.

Prepare a Model to Use Fast Restart

Before you simulate a model in fast restart, ensure that the model meets these requirements:

Note

When fast restart is on, you cannot save changes to the model after it compiles. To save changes, the software must discard information about the compiled state. To save changes to the model, disable fast restart.

Enable Fast Restart

Use one of these methods to enable fast restart:

Simulate a Model using Fast Restart

After you load your model and turn on fast restart, simulate the model.

  1. Simulate the model by calling sim or clicking theRun button in the Simulink Toolstrip. The first simulation in fast restart requires the model to compile and capture a snapshot of the model operating point.
    Once the simulation is complete, the status bar shows that the model is compiled in fast restart.
    While fast restart is in progress, the simulation status becomesRestarting, and the Simulink Editor becomes frozen like it is during model compilation and initialization.
    The status bar shows the Restarting status message
  2. Adjust tunable parameters in the model, such as the gain value of aGain block, or tune root-level input values. You can also make changes to base workspace variables. You cannot adjust nontunable parameters such as sample time, because doing so requires the model to compile once more.
  3. Simulate the model again. This time, the model does not compile. When you click the Play button or step forward, Simulink updates blocks that have new values as well as blocks that reference workspace variables.
  4. When you are satisfied with your results, turn off fast restart by clicking the Fast restart button off.
  5. To keep your changes, save the model.

Note

After a model is initialized in fast restart, the software issues a warning if you attempt to make a structural change to the model. To make such changes, disable fast restart.

Stop a Simulation

When you click Stop in the middle of a fast restart simulation:

Exit Fast Restart

You can exit fast restart only when the model is in the initialized state. After simulating, click the Fast restart button. To do this programmatically, use the set_param function.

set_param(model,"FastRestart","off")

Fast Restart Methodology

Tuning Parameters Between Simulations

Switching Solvers Between Simulations

When fast restart is on, you can switch solvers between simulations. Only valid solvers that can be switched to are listed in theSolver list in the Configuration Parameters dialog box. If you switch solvers using set_param command between simulations and set to an invalid solver, you will see a warning and the invalid solver will be ignored.

Model Methods and Callbacks in Fast Restart

When fast restart is on, Simulink calls model and block methods and callbacks as follows:

  1. Call model InitFcn callback.
  2. Call model SetupRuntimeResources method.
    1. Call mdlSetupRuntimeResources S-function method.
  3. Call model Start method.
    1. Call mdlStart S-function method.
  4. Call model Initialize method.
    1. Call mdlInitializeConditions S-function method.
      Note
      Use the ssIsFirstInitCond flag to guard code that should run only during the initialization phase of any simulation, including the first and subsequent initializations in fast restart.
  5. Call model and block StartFcn callbacks.
    Note
    Steps 1–5 apply to all simulations in Simulink (with or without fast restart).
  6. For the first simulation in fast restart, capture a simulation snapshot. A simulation snapshot contains simulation state (ModelOperatingPoint) and information related to logged data and visualization blocks. As part of the snapshot capture, call ModelOperatingPoint S-function method.
  7. This is a standard execution phase of any simulation, with or without fast restart.
    • Call model Outputs.
    • Call model Update.
    • Call model Derivatives.
    • Repeat these steps in a loop until stop time or a stop is requested.
  8. Call model Terminate method.
    1. Call mdlTerminate S-function method.
  9. After simulation ends, call model and block StopFcn callbacks. This is a standard phase of any simulation, with or without fast restart.
  10. Restore the simulation snapshot taken for fast restart. As part of the restore, call set S-function method.
  11. Wait in a reinitialized state until one of these actions:

In some cases. the Start and Terminate methods are only called once and not for each successive Fast Restart simulation. In these cases, these method calls are combined with calls toSetupRuntimeResources andCleanupRuntimeResources, respectively. These cases are as follows:

For more information on model callbacks, see Customize Model Behavior with Callbacks.

Operating Point and Initial State Values

You can change initial state values, includingModelOperatingPoint, in between fast restart simulations.

When a ModelOperatingPoint object for initial state is used in fast restart, every new simulation resets to the start time of the model and not the snapshot time of each ModelOperatingPoint object. Thereafter, on the first step forward, Simulink checks to see if a ModelOperatingPoint has been specified. If yes, Simulink restores it before computing the next step. Thus, the first simulation step effectively fast forwards to the snapshot time of the specifiedModelOperatingPoint object.

Analyze Data Using the Simulation Data Inspector

Fast restart supports data logging using the Simulation Data Inspector. Every simulation in fast restart creates an SDI object with the name** fast restart run **. The value of number increments for each simulation.

Custom Code in the Initialize Function

When you place custom code in the > > > pane in the Model Configuration Parameters dialog box, this gets called only during the first simulation in fast restart.

See Also

Topics