Add and Evaluate a Condition for an Event

Conditions are powerful tools allowing the implementation of feedback and what-if logic in a simulation. This guide demonstrates the basics of how to add a condition to an event and how to change the way a condition is evaluated.

For more details on conditions see section Conditions of the Reference guide.

1. Add a condition

Conditions are an extra layer of logic you can build on top of events in a dynamic simulation scenario. Start by selecting an event in the event table of the active scenario. You can either type directly your new condition in the Condition column, after clicking one time on the cell (Figure 1 top), or in the Condition row of the section Condition of the Property Editor (Figure 1 bottom).

add evaluate conditions 00
Figure 1. The user can enter an expression either in the Events Table (top) using the column Condition or in the dedicated section of the Property Editor after selecting the event.

In both cases, you need to be sure of the correct syntax of the condition. SAInt performs a syntax check, and the expression will be in red if it fails to pass. Alternatively, in the Property Editor click in the cell where you write the expression and open the Script Editor by clicking the three dots on the right of the cell. The Script Editor allows writing an expression and checking if it is correctly interpreted and evaluated (Figure 2). Just use the button Evaluate.

add evaluate conditions 01
Figure 2. How to use the Script Editor to write and check the syntax of an expression.

This section shows some simple examples using the scenario DYN_6 of the gas network GNET29_18 available in the user’s Projects folder (C:\...\Documents\encoord\SAInt-v3\Projects).

The same steps are valid for any type of event and network given a dynamic simulation scenario.

2. Add the evaluation rule

After defining the content of your expression, it is necessary to specify how SAInt will use the expression. Each expression needs an "evaluation rule", and the user can choose among NONE (the default), DoIFTRUE, DoIFFALSE, DoUntilTRUE, and DoUntilFALSE.

You can select the rule by using the drop-down list from the cell of the column Evaluation of the table of events or the Evaluation row of the section Condition of the Property Editor (Figure 1 bottom).

add evaluate conditions 02
Figure 3. How to specify the evaluation rule for the condition of a certain event from the drop-down list of the Evaluation column in the events table.

3. Expressions and simulation time

The built-in function gtime explicitly incorporates the active simulation time step in the statement and evaluates any condition.

Figure 4 (top) shows an example of a set of events for the gas demand object CGS_02. All events start at the same time. Their expressions are composed of two parts. One side checks the status of the control valve CV_1. The other side checks if the time step is before or after the time 04.02 06:00 (i.e., 72 hours is equivalent to 06:00 a.m. of February 4).

All expressions use the evaluation rule DoIFTRUE. The resulting demand dynamic is described in the chart at the bottom of Figure 4.

add evaluate conditions 03
Figure 4. Example of how to consider the simulation time in an expression.

The example in Figure 4 is to showcase the use of gtime. A better approach is to set different starting times for each event.