Main Content

How Stepping Through Simulations Works

The parameter values you specify in the Simulation Stepping Options dialog box affect how the software:

  • Advances the simulation when you click Step Forward or Step Back

  • Captures snapshots of the model operating point to support stepping back

When you step forward in simulation, the software continues the simulation. However, when you step backward, the software does not simulate the model in reverse. To support stepping backward in a simulation, the software captures snapshots of the model operating point as the simulation runs. When you click Step Back, the software restores the model operating point from one of the snapshots.

Note

The software collects simulation snapshots for stepping back only when stepping back is enabled. When you enable stepping back for a simulation that is in progress, you must step forward before you can step back. You cannot step back to a point in the simulation before you enabled stepping back.

The simulation snapshots contain the same model operating point information that is logged when you select Save final operating point on the Data Import/Export pane of the Configuration Parameters dialog box. The software captures the model operating point information in the simulation snapshots only to support stepping back. The simulation snapshots the software captures for stepping back are not accessible during or after simulation. For more information about saving the model operating point, see Save Block States and Simulation Operating Points.

Stepping Forward

The Move back/forward by parameter specifies the number of time steps to advance the simulation each time you click Step Forward. The image illustrates how the simulation advances based on whether the Move back/forward by option is specified as 1 or 2:

  • At the start of the simulation, State 0, the parameter value is 2. When you click Step Forward, the simulation advances through State 1 and pauses on State 2.

  • While paused after the second time step, suppose you change the parameter value to 1. Now, when you click Step Forward, the simulation advances to State 3, which corresponds to the next time step.

  • Suppose you change the parameter value back to 2 while paused after the fourth major time step. Now, when you click Step Forward, the simulation advances to State 6.

A timeline of the simulation that represents the simulation state for each time step as a green circle. Arced arrows illustrate the simulation progression.

Capturing Simulation Snapshots

The simulation snapshots that the software collects for stepping backward contain all the information required to continue the simulation from the point at which the snapshot was taken. Collecting the snapshots requires memory and can affect simulation performance. When you configure the simulation stepping options, you can specify:

  • Maximum number of saved back steps — Total number of snapshots to save

  • Interval between stored back steps — Number of simulation time steps to skip between saving snapshots

Saving a smaller number of total time steps and skipping steps between snapshots can mitigate the effect that enabling stepping back has on simulation performance.

The simulation stepping options for saving snapshots are independent of the Move back/forward by option, which controls how the simulation advances when you click Step Forward or Step Back.

The image illustrates how snapshots are captured when the Interval between stored back steps parameter value is 3. The software captures a snapshot at the start of the simulation, after the third major time step, and after the sixth major time step.

A timeline of the simulation that represents the simulation state as a green circle. The shade of green is darker for each state that is captured as a snapshot.

You can change the interval between snapshots during simulation when you need to advance the simulation by smaller increments to analyze a point of interest. For example, the image illustrates how the simulation in the previous image would capture snapshots if you changed the interval between snapshots from 3 to 1.

  • The software captures a snapshot of State 0 at the start of the simulation.

  • After three time steps, the software captures a snapshot of State 3.

  • While paused on State 3, you change the value of the Interval between stored back steps parameter from 3 to 1.

  • The software captures a snapshot of the simulation state for each time step through State 6.

A timeline of the simulation that represents the simulation state as a green circle. The shade of green is darker for each state that is captured as a snapshot.

Stepping Back

The way the software steps back in simulation depends on whether a snapshot exists for the time to which you step back.

  • When a snapshot exists for the time step, the software restores the model operating point contained in the snapshot.

  • When a snapshot does not exist for the time step, the software restores the model operating point from the last snapshot before the time step then simulates forward

For example, suppose you are paused after the sixth time step in a simulation that:

  • Captures a snapshot of the model operating point every three time steps

  • Steps backward by one time step each time you click Step Back

When you click Step Back, the software restores the snapshot captured after the third time step and simulates forward two time steps to pause after the fifth time step.

A timeline of the simulation that represents the simulation state as a green circle. The shade of green is darker for each state that is captured as a snapshot. A solid arced arrow represents the progression of the simulation when you click Step Back. Dotted arced arrows illustrate how the software steps back.

You can modify the values of tunable parameters while paused during simulation. The software applies the new parameter value for the next forward step in simulation. Depending on how you configure the simulation stepping options, the next forward step in simulation might happen when you click Step Back.

Pausing on Breakpoints

When your model contains active breakpoints, the simulation pauses on the breakpoint if the condition for the breakpoint is met in the process of stepping forward. The software ignores breakpoints when stepping backward.

By default, the software is configured to pause within a time step as soon as the condition for a breakpoint is met. When you click Step Forward while paused on a breakpoint, the simulation advances through the current time step. When you click Step Back, the software steps back to the start of the current time step. For more information, see Breakpoints List.

Additional Considerations for Stepping Through Simulation

Not all blocks, features, and model configurations support stepping back in simulation. Lack of support for stepping back does not interrupt a simulation. The software issues a warning when a model with stepping back enabled does not support stepping back.

Because stepping back relies on the functionality for saving the model operating point, stepping back is supported only for models that support saving the model operating point. For more information, see Additional Considerations for Saving and Restoring Model Operating Points.

The table summarizes other considerations related to stepping back in simulation for several blocks and modeling constructs.

Feature or Modeling PatternConsiderations for Stepping Back

Model references

If you modify the simulation stepping options for a referenced model during simulation, the same options change in the top model. When the simulation completes, the simulation stepping options for referenced models revert to their values before the simulation. The simulation stepping options for the top model stay the same as they were at the end of the simulation.

Visualization blocks

The visualizations in these blocks do not update to reflect the result of stepping back:

  • Auto Correlator and Cross Correlator

  • Spectrum Analyzer and Averaging Spectrum Analyzer

  • Power Spectral Density and Averaging Power Spectral Density

  • Floating Bar Plot

  • 3DoF Animation

  • MATLAB Animation

  • VR Sink

  • Blocks that implement a custom visualization in their output method

MATLAB Function blocks

The simulation state after stepping back might be incorrect for models that contain MATLAB Function blocks that call C code that contains static variables or has side effects, such as writing to a file.

S-functions

  • S-functions that have Pwork vectors do not support stepping back if the operating point compliance is not specified or is specified as unknown or disallowed. For more information, see ssSetOperatingPointCompliance.

  • Custom visualizations implemented in the output method of an S-function do not update to reflect stepping back.

    Block output methods might not execute when you step backward in simulation. While the block states remain consistent with the simulation time if the S-function complies with model operating point, the visualization does not update until the next forward step in the simulation.

See Also

|

Related Topics