Main Content

How Stepping Through Simulation Works

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

  • Progresses 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 you simulate the model. 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, and 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 model operating point information is captured by the software to support stepping back and is not available to view 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 major time steps to progress the simulation each time you click Step Forward. The image illustrates how the simulation progresses 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 progresses through State 1 and pauses on State 2.

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

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 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 progress 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 major time steps, the software captures a snapshot of State 3.

  • The Interval between stored back steps parameter value changes from 3 to 1.

  • The software captures a snapshot of the simulation state for each major 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 enabled 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 progresses 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 through a simulation. Lack of support for stepping back does not interrupt a simulation. When the software detects that a simulation with stepping back enabled does not support stepping back, it issues a warning in the Command Window.

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 Limitations of Saving and Restoring Operating Point.

These blocks do not support stepping back for reasons other than model operating point support:

  • S-functions that have Pwork vectors but do not declare their model operating point compliance level or declare it to be unknown or disallowed. For more information, see S-Function Compliance with the ModelOperatingPoint.

  • SimEvents® blocks from a release before R2016a

MATLAB Function blocks generally support stepping back. However, the use of certain constructs in the MATLAB® can prevent the block from supporting stepping back. These scenarios prevent the MATLAB Function blocks from stepping back:

  • When the code contains persistent variables with an opaque data type, stepping back is not supported.

  • When the code calls extrinsic functions that can contain state (such as properties of objects or persistent data of functions), the result of stepping back might be incorrect.

  • When the code calls custom C code that does not contain static variables, the result of stepping back might be incorrect.

These visualization blocks do not update to reflect the result of stepping back:

  • Auto Correlator

  • Cross Correlator

  • Spectrum Analyzer

  • Averaging Spectrum Analyzer

  • Power Spectral Density

  • Averaging Power Spectral Density

  • Floating Bar Plot

  • 3DoF Animation

  • MATLAB Animation

  • VR Sink

  • Blocks that implement a custom visualization in their output method, such as an S-function that sends output to a MATLAB figure

    The block output does not execute when you step backward in simulation. While the state of the block remains consistent with the simulation time if the block complies with model operating point, the visualization component does not update until the next forward step in the simulation.

During simulations, the simulation stepping options remain in sync throughout a model hierarchy, no matter where you modify the options. For example, 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.

See Also

|

Related Topics