Pause Conditions
The Twin Activate debugger interface lets you define conditions under which the debugger pauses so you can inspect and modify blocks.
Introduction
In a typical Twin Activate model, the number of calls to block functions can be very large during a simulation, especially when the model contains blocks with continuous-time states, due to solver calls made by numerical solver. Debugging often consists of identifying and inspecting a limited number of blocks during simulation under special circumstances. The ability to filter the calls so that the inspections can be confined to the desired blocks and circumstances is important.
The circumstances might include conditions depending on the reason for which the block is called (task to perform, such as Initialization, Output update, State update), the time, the values of inputs, or internal states. The debugger lets you define filters using predefined conditions through menus and OML expressions to express conditions to pause. Different filters can be implemented, and a call is paused only if it is not filtered out by any of the filters. The only exception to this rule is when an error is generated by a block. In that case, the pause is systematic.
Blocks to pause
One pause condition is to make a list of blocks to pause. The List of blocks to pause is located under the action buttons in the Twin Activate debugger dialog box. To the right of the list are options to add and remove blocks. To add a specific block, select it from the Add a block to the list drop-down list.
By default, the list of blocks to pause in is empty. If the simulation is started or continued using the START or CONTINUE buttons, it either runs to the end or pauses due to an error. The behavior in this case is like that of the FINISH button. If one or more blocks are selected, then a pause cannot occur in any other block other than the selected blocks, unless an error occurs in that other block. Regardless of the chosen filters, if an error occurs during simulation in debug mode inside a block, the simulation is paused in that block.
The correspondence between basic blocks in the list and blocks visible in the diagram is one-to-one for most blocks. When paused, the full name of the block is shown at the top of the dialog box. To open the diagram containing the block, click Show in the upper right. The block is marked with a specific icon in the diagram indicating whether the pause is a pre-call, a post-call, or post-call subsequent to an error. These icons are shown in the image below.
Action flags
You can define pause conditions based on the block action requested by the simulator. By default, the All actions option is selected. The Simulation error or end option means that the simulation never stops unless an error occurs in a block. The other options are described in the table below.
Flag | Action |
---|---|
1 | Output update: Can be used in both try mode and non-try mode. |
2 | State updated: Updates block internal states, both continuous and discrete. |
0 | Derivative update |
4 | Initial call: Initialization actions such as opening a file. Each block is called once at the start. |
6 | Reinitialization call of continuous time states in try mode. |
5 | Final actions such as closing a file. Each block is called once at the end. |
3 | Event generation: Scheduling event on output activation ports. |
9 | Zero-crossing call: Computes the zero-crossing surfaces. |
Try mode calls
You can define pause conditions based on whether to include try mode calls. By default, try mode calls are included in pause conditions. To exclude try mode calls, deselect the Include try mode calls check box in the upper right of the Twin Activate debugger dialog box.
Phases
You can define pause conditions based on the phase of the simulation function. The pre-call phase occurs before the action of the simulation function, and the post-call phase occurs after. Including or excluding these phases lets you decide whether to pause and examine blocks before or after their actions, or both.
In the upper right of the Twin Activate debugger dialog box, select an option from the Included phases drop-down menu. You can choose both pre- and post-calls, only pre-calls, or only post-calls.
OML stopping condition
You can define pause conditions based on an OML expression. Write the OML expression in the Stopping condition field in the Twin Activate debugger dialog box. A pause occurs if the OML expression evaluates to true or 1.
The stopping condition is tested if the other conditions (block name, flag, phase, and try mode) do not filter out the call.
The stopping condition can contain any of the variables in the table below. The variables that can be used are shown at the bottom of the dialog box.
Variable | Description |
---|---|
block_name | Block name (string) |
t | Current simulation time (double) |
inputs | Input values (cell | mat) |
outputs | Output values (cell | mat) |
nevprt | Block activation code (double) |
x | Continuous-time state (vector) |
xd | Derivative of the continuous-time state (vector) |
mode | Block modes (vector) |
zcross | Zero-crossing surfaces (vector) |
z | Discrete-time block state (vector) |
oz | Discrete-time object states (cell | mat) |
rpar | Block parameter (vector) |
opar | Object parameters (cell | mat | scalar | string) |
trymode | True if call is made in try mode, otherwise false |
block | OML object corresponding to the block structure |
flag | Indicates the action associated with the call |
prepost | 0 or 1 depending whether in pre- or post-call phase |
t > 0.05
inputs{1} < 0
t > 1 && inputs{1} < 0