Documentation

Get Started with Fast Restart

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. Turn on fast restart using theFast Restartbutton on the Simulink®Toolstrip or from the command line.

  2. Simulate the model. The first simulation requires the model to compile, initialize and save aModelOperatingPointobject. 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.

    • Tune root-level inputs.

    • Modify base workspace, model workspace variables and data dictionary entries that are referenced by tunable parameters.

    • Change inputs toFrom FileandFrom Workspaceblocks.

    • Change theInitial stateparameter for the next simulation.

    • Using theSignal Builderblock, change data, rename signals and signal groups, and add new groups.

    • Change the signal logging override values for the model programmatically by using theset_paramcommand and theDataLoggingOverrideparameter. SeeOverride Signal Logging Settings from MATLAB.

    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 turn off fast restart, Simulink does not store any compile 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:

  • If you have enabled callbacks in the model, make sure they do not attempt to make structural changes when the model is reinitialized. For example, callbacks such as mask initialization commands get called at the beginning of each simulation. Therefore, avoid using mask initialization code that makes structural changes to the model.

  • All blocks in the model must supportModelOperatingPointobject.

  • The simulation mode is Normal or Accelerator mode.

Note

When fast restart is on, you cannot save changes to the model after it compiles. Saving changes requires Simulink to discard information about the compiled state. To save any changes to the model, turn off fast restart first.

Enable Fast Restart

Use one of these methods to enable fast restart:

  • Click theFast restartbuttonon the Simulink Editor toolbar.

  • At the MATLAB®Command prompt, useset_paramto enable fast restart. Type

    set_param(model,'FastRestart','on')

Simulate a Model using Fast Restart

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

  1. Simulate the model by callingsimor clicking theRunbuttonin the Simulink Editor toolstrip. The first simulation in fast restart requires the model to compile and save aModelOperatingPointobject.

    Once the simulation is complete, the status bar shows that the model is initialized in fast restart.

  2. Adjust tunable parameters in the model, such as the gain value of aGainblock, 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 thePlaybutton 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 theFast restartbutton off.

  5. To keep your changes, save the model.

Note

After a model is initialized in fast restart, Simulink displays a warning if you attempt to make a structural change to the model. To make such changes, you must turn off fast restart.

Stop a Simulation

When you clickStopin the middle of a fast restart simulation:

  • Simulation does not terminate.

  • The model is in the initialized state.

  • You can now change tunable parameters in the model

  • You can terminate the simulation and exit fast restart by clicking theFast restartbutton off.

Exit Fast Restart

You can exit fast restart only when the model is in the initialized state. After simulating, click theFast restartbutton off. To do this programmatically, type:

set_param(model,'FastRestart','off')

  • Simulink terminates simulation.

  • Simulink discards any compiled information about the model.

  • The model must compile again the next time you simulate.

Fast Restart Methodology

Tuning Parameters Between Simulations

  • When a model is initialized in fast restart, in addition to block values and base workspace variables, you can tune parameters in theData Import/ExportandSolverpanes in the Configuration Parameters dialog box (on theSimulationtab, underPrepare, clickModel Settings).

  • 模拟之间的某些参数可调only when the model is initialized in fast restart. They include:

    • Initial Valueparameter of theICblock

    • Initial Outputparameter of theMergeblock

    • Dataparameter of theFrom Workspaceblock

    • Signalparameter and signal groups of theSignal Builderblock.

Model Methods and Callbacks in Fast Restart

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

  1. Call modelInitFcncallback.

  2. Call modelSetupRuntimeResourcesmethod.

    1. CallmdlSetupRuntimeResourcesS-function method.

  3. Call modelStartmethod.

    1. CallmdlStartS-function method.

  4. Call modelInitializemethod.

    1. CallmdlInitializeConditionsS-function method.

      Note

      Use thessIsFirstInitCondflag 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 blockStartFcncallbacks.

    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, callModelOperatingPointS-function method.

  7. This is a standard execution phase of any simulation, with or without fast restart.

    • Call modelOutputs.

    • Call modelUpdate.

    • Call modelDerivatives.

    • Repeat these steps in a loop until stop time or a stop is requested.

  8. Call modelTerminatemethod.

    1. CallmdlTerminateS-function method.

  9. After simulation ends, call model and blockStopFcncallbacks. 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, callsetS-function method.

  11. Wait in a reinitialized state until one of these actions:

    • To run another simulation (programmatically or using the Simulink Editor) in fast restart, return to step 3.

    • To end Fast Restart mode and uncompile the model:

      1. Call the model methodCleanupRuntimeResourcesand themdlCleanupRuntimeResourcesS-function method.

      2. Do not callStopFcncallbacks again at this point.

In some cases. theStartandTerminatemethods are only called once and not for each successive Fast Restart simulation. In these cases, these method calls are combined with calls toSetupRuntimeResourcesandCleanupRuntimeResources, respectively. These cases are as follows:

  • When an S-function contains customModelOperatingPoint保存和恢复方法。

  • When an S-function sets the flagSS_OPTION_CALL_TERMINATE_ON_EXIT.

  • When an S-function is placed inside the accelerated mode of a referenced model.

For more information on model callbacks, seeCallbacks for Customized Model Behavior.

Operating Point and Initial State Values

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

When aModelOperatingPoint对象的初始状态是用于快速重启,every new simulation resets to the start time of the model and not the snapshot time of eachModelOperatingPointobject. Thereafter, on the first step forward, Simulink checks to see if aModelOperatingPointhas 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 specifiedModelOperatingPointobject.

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 ofnumberincrements for each simulation.

Custom Code in the Initialize Function

When you place custom code in theConfiguration Parameters>Simulation Target>Custom Code>Initialize functionpane in theModel Configuration Parametersdialog box, this gets called only during the first simulation in fast restart.

Related Topics