About the Expression Editor

The Expression Editor (Figure 57) allows you to control component behaviour via arithmetic expression. In particular, a component’s behaviour can depend on other dynamic values in the model. The Expression Editor is used in places where you might otherwise employ a time series or a piecewise linear relationship.

Expression Editor

Expression calculation

The Expression Editor calculates values according to the expression that you create. Expression Editor does not check units either within an expression or as a returned value. Neither does Expression Editor convert or normalise units. For example, if the result of a calculation is 10 megalitres but the return units are set to kilolitres, the result of the expression is 10 kilolitres. Similarly, if the inputs to an expression are a mixture of units, and you do not allow for this in your expression, the result may not be what you expect.

The Expression Editor always returns a single value at each time step.

Local vs global scope

Expressions are divided into two types according to their scope: local and global. Global expressions are available throughout the scenario whereas local expressions are confined to the feature editor in which they are defined. With respect to the tabs shown in Figure 57, any value defined in the Variables tab is local to the context in which it is defined (eg the particular feature editor). A value defined in any other tab is global to the scenario. To put this another way, a value defined in the Variables tab can only be seen and used in the Expression Editor in which it is defined whereas a value defined in any other tab can be seen and used from any other location within the same scenario in which it is possible to open an Expression Editor.

Played vs non-played variables

Expression Editor distinguishes between two classes of variable:

General rules for expressions

The following rules apply to expressions:

Source warns you if you attempt to delete a node which is referenced in an expression.

If you accidentally use non-unique variable names, Source will warn you when you run your model.

Operator precedence

Unless you use parentheses to modify the order of evaluation, operations are performed according to the precedence rules shown in Table 31. Where two operators have the same level of precedence, the operations are performed left-to-right.

Functions

Functions are predefined formulae that perform calculations which usually depend on the arguments you supply as parameters. Functions can be entered by hand or by using the pull down menu at the top of the Expression Editor (Figure 57). The available functions are summarised in Table 39, Table 40, Table 41 and Table 42. Some examples of function use are shown in Table 32.

Testing expressions

You can test expressions using the Parse button. This opens the Parse Results window (Figure 58) where you can enter values for the various terms in your expression and confirm that the result of evaluating your expression with those values is correct. Your expression is evaluated each time you click the Parse button in the Parse Results window. When you have finished testing, click OK to return to the Expression Editor.

Expression Editor (Parse Results)

Deleting expression components

The various sub-tabs of the Expression Editor allow you to define terms which are then utilised in the construction of expressions. After defining a term you can both rename the term and edit its parameters using the controls in the various columns of the sub-tab.

Deleting a term is a two-step process and involves clicking on the table cell to the left of the name of the term. First, click on that cell. This causes the whole row to become selected. Second, right-click in the same place and choose Delete from the contextual menu. The process is shown in Figure 59.

Expression Editor (delete row)

Variables tab

The Variables tab provides a connection between your expression and model (non-played) variables. You define a name (or meta-name) by which you will refer to a model variable in your expression and configure other parameters governing its use. Once a variable has been defined, it can be used in an expression. To define a new variable:

Table 33 contains some examples of typical variable declarations.

Expression Editor (Variables tab)

Date ranges

During a time-step, the moment at which any given expression is evaluated, and the moment at which each model variable on which the expression depends is updated, are all independent events. Without a detailed understanding of the order of events during a time-step, it may not be possible to be certain about the exact state of any model variable. For this reason, Expression Editor allows to you choose between a number of options according to your need. Table 44 and Table 45 define the options which are available by default.

If none of the default options is appropriate, you can define your own date ranges. To define a custom date range, choose one of the options from the Date range type popup menu (Figure 61).

Custom date ranges fall into three categories:

Expression Editor (Date Range, custom calendar)

For all three custom calendar options:

Note that, while the user interface uses the word set to refer to the concept of returning multiple values, because the values are both ordered and can be repeated, it is probably better to think of these as lists.

Expression Editor (Date Range, period)

Expression Editor (Date Range, time step)

Example

As an example, the Expression Editor can be used in a Maximum Order Constraint node to limit the maximum orders for each time step. Assume that a channel constraint of 80 ML/day is required to prevent flows going overbank, except during floods (defined as more than 2,000 ML/day) when up to 3,000 ML/day is permitted as an environmental flow.

Figure 64 shows a fragment of the river network. Downstream demands are represented by a Supply Point and Water User node. In the Expression Editor for the Maximum Order Constraint node, you specify the internal (orders and unregulated river gain) of the model in the Variables tab of the Expression Editor and determine the maximum orders using an expression. Table 33 shows the relevant variables and Table 35 an expression which returns a value of 3,000 ML/day if flows are above 2,000 ML/day but 80 ML/day otherwise.

Maximum Order Constraint node (example)

Piecewise Linear tab

You use the Piecewise Linear tab to create piecewise linear relations for use in expressions. You can find more information about such relations at About piecewise linear editors.

Expression Editor (Piecewise Linear tab)

To define a new piecewise linear relation:

Expression Editor (Piecewise Linear, Interpolated Function)

Example

As an example, xxxxxx.

Patterns tab

You use patterns (Figure 67) to create a named dataset of repeating time-dependent values (eg daily or monthly pattern).

Input is:

Name

All expression names must start with a $.

Units

The default units for pattern values are the units defined for the simulation. You can enter data values in different units by right-clicking the column header in the pattern data entry window. To convert the entered data to different units for use in the expressions, choose the new units from the drop-down menu adjacent to the user-defined pattern name.

Type

Select time period for the pattern from the drop-down menu (eg monthly, weekly, daily, 6-hourly, hourly).

Edit

To load pattern data, click on the edit link. Either manually or via a text file, enter the amount per time period specified, eg monthly accepts 12 values; weekly accepts 53 values; daily accepts 366 values; 6-hourly (over 1 year) accepts 1464 values; hourly accepts 24 values.

EXAMPLE - Application of the Patterns tab of Expression Editor using an inflow node as an example

As an example, the Expression Editor is used in the Inflow node to specify the values of monthly inflows using the Patterns tab.

Example You want to use mean monthly inflows for every time step in a monthly time step model simulation.

Use Case The inflow node is connected to the river network. In the inflow node Feature Editor, you select the Expression Editor to access the Time Series tab into which data can be entered. You enter the twelve (12) monthly values through the Patterns tab of the Expression Editor and then specify this data set in the expression box of the Expression Editor.

From the Patterns tab of the Inflow node’s Expression Editor, assign a name to the variable (Table 46 & Figure 67). In this example, $MonthlyInflows is given the name of the monthly time-series pattern for the inflow node.

Expression Editor (Patterns tab)

After entering the variable name of $MonthlyInflows, select "Megalitres per Day (ML/day)" from the Units drop-down menu. Next, select "Monthly" from the Type drop-down menu. Then click "Edit". This will open the $MonthlyInflows window (Figure 68). Enter the monthly stream flows and click OK.

Expression Editor (Monthly stream flow patterns)

Next, specify the equation (or function) type of relationship and enter this in the expression box of the Expression Editor as shown in Table 47 and Figure 69. After entering the expressions, configure and run the scenario. Source then evaluates the expression (or function) equation for each time step and returns a value for each time step.

Expression Editor ($MonthlyInflows expression)

Time Series tab

Create a named time series (FIGURE).

Expression Editor (Time Series tab)

Input is:

Name

All expression names must start with a $.

Edit

To load a time series, click on the edit link. Then upload the file and select the units. Start and end dates are extracted from the file and listed with the name of the time series.

Start

Loading a time-series automatically provides the start date, which cannot be edited.

End

Loading a time-series automatically provides the end date, which cannot be edited.

Units

The units for time series are selected from a drop-down menu within the "edit" window. To convert the time series to different units for use in the expression, choose the new units from the drop-down menu adjacent to the data series end date.

EXAMPLE - Application of the Time Series tab of Expression Editor using a Water User node

As an example, the Expression Editor is used in a Water User node to specify the summation of two sets of water demands along a particular river segment.

Example A Water User node is situated below two stream flow points along a stretch of river in which the water demands for two water users are known. You can incorporate the two water demands into a single Water User node by adding the respective values for each corresponding time steps.

Use Case A Water User node is drawn schematically to represent the combined water demands of two water users along a particular river network. In the Water User node Expression Editor, specify the water demands of the two water users using the Time Series tab of the Expression Editor and determine the combined flow using an equation (or function) type of relationship in the expression box.

Select Time Series Demand from the list of available models and select Expression Editor as the source of data to be loaded (FIGURE) Then click on the ellipse button to open the Expression Editor interface.

Expression Editor (Water User node)

From the Time Series tab of the Inflow node’s Expression Editor, specify the Variable Name of the time series (remember that variable names are preceded by a $ sign) and then clicks "Edit" to import the time series from the file location.

Table 48 and FIGURE display the variable names for two different daily water demands. The start and end periods will automatically fill in when the files are imported and correspond to the start and end period of the time series. The units will correspond to the units of the time series and no units are specified prior to importing the files.

Expression Editor (Time Series, example)

To check the equation (or function), click Parse. The Parse Results window opens (FIGURE). Manually enter test values and click Parse. For example, use a value of 2 for both $DailyDemand1 and $DailyDemand2. The correct result is 4, which will appear in the Result field.

Global Expressions tab

The Global Expressions tab is a special case. When editing a global expression, a second copy of Expression Editor is opened. The second Expression Editor window is usually placed directly on top of the first window and this behaviour can sometimes be confusing (eg clicking OK closes the second window but the first window is still present and is usually not greatly different in appearance). For this reason, we recommend moving the second window slightly whenever you edit a global expression.

Create named expressions that are visible from all instances of the Expression Editor (Figure 73).

Input is:

Name

All expression names must start with a $.

Expression

Enter the global expression using the Expression Editor.

EXAMPLE - Application of the Global tab of the Expression Editor using a Minimum Flow Constraint node

As an example, the Expression Editor is used with a Minimum Flow constraint node to determine the value of the minimum flow for each time step based on a given set of flow requirements.

Example: There are two storages in series on a river segment. A Minimum Flow Requirement node is used to generate orders from the upstream storage so that the downstream storage can meet the orders from further down the valley. It is assumed that the average order from the previous week (last 7 days set) is a good approximation of the water that will be ordered from the lower dam when the water from the upstream storage arrives. In addition there is a flow constraint between the two storages that limits the flow in the channel to a maximum of 4000 ML/day.

Use Case: The Minimum Flow Requirement node sits on the river channel between two storages (Figure 72). The upstream dam is selected as the storage that orders generated by the minimum flow node will be sent to. In the minimum flow requirement Expression Editor, specify an internal model data set (orders) in the Variables tab of the Expression Editor and then calculate the preliminary minimum flow requirements using the Global tab of the Expression Editor. Finally enter an equation (or function) type of relationship into the expression box of the Expression Editor. When the model is configured and run, the model calculates the equation (or function) in the expression box of the Expression Editor.

Minimum Flow Constraint node (example)

From the Variables tab of the Minimum Flow Requirement node’s Expression Editor, specify the Variable Name (preceded by a $ sign) for developing an expression equation (or function) similar to Microsoft Excel syntax to determine the time periods in which flows meet the criteria of the example. Next, select the Global tab of the Expression Editor to calculate the preliminary minimum flow requirement by entering a Variable name preceded by the $ sign (for example, $MinimumFlow) and then the expression (or function) type relationship (for example, average($OrderWeek) ) (Table 51 and Figure 73).

Next, specify the final expression (or function) to set the minimum flow requirement after consideration of the flow constraint of 4000 ML per day and enter this in the expression box of the Expression Editor (Figure 73).

Expression Editor (Global Expressions tab)

Expression Editor (Custom Functions tab)

Expression Editor (Time of Evaluation tab)

Next, define the expression average($OrderWeek). Click on the ellipse button to the right of the expression average($OrderWeek) (Figure 73). Notice the words "Expression Editor ($MinimumFlow)" at the top of the schematic in Figure 76. This denotes the expression associated with the variable $MinimumFlow that had been previously defined in the Global tab of the Expression Editor. It is important to remember the difference between this and the Expression Editor shown in Figure 73.

Enter the arithmetic expression in the Expression Editor box as shown in Figure 76. After entering the expressions, the configure and run the model scenario. The model then evaluates the expression equation for each time step and returns a value for each time step.

Expression Editor (Variables, $OrderWeek)

Custom Functions tab

This functionality is yet to be documented. If you would like assistance, please call 1300-5-WATER (1300-592-837).

Time of Evaluation tab

Expressions are evaluated at the start of each time step. Providing a choice of:

Time of Evaluation

Expression Editor (evaluation order)

Order of precedence

Operator symbol

Meaning

1 (highest)

(   )

explicit ordering

2

-

negation

3

** and ^

exponentiation

4

* and /

multiplication and division

5

+ and -

addition and subtraction

Sample expressions using functions

Expression

Result

Expression

Result

Expression

Result

Average($var1)

3

Median($var1)

3

Lookup($var1,13.5)

2.5

Lookup($var1,14)

3

Count($var1)

5

Max($var1)

5

Where: $var1 is the piecewise linear relationship {(12, 1), (13, 2), (14, 3), (15, 4), (16, 5)}

Expression Editor (variables, expression inputs)

Variable Name

Source

Part

Units

Data Range

$Orders

Storage 2

Requested Flow Rate

ML/day

Last time step

$predictedinflow

Inflow 3

Inflow (played input value)

ML/day

Last time step

Expression Editor (custom calendars, value sets)

Option

Summary

Result

Simple Set

Returns the set of observations without modification

[1,2,3,4,5]

Set of Averages

Returns a set of the same size where each member is the average of all of the members of the set

[3,3,3,3,3]

Set of Progressive Averages

Returns a set of the same size where each member is the original value of that member averaged with the value of the first member.

[1,1.5,2,2.5,3]

Where: input is the series [1,2,3,4,5]

Example expression

Expression

Result Units

If(($predictedinflow+$orders)>2000,3000,80

ML/day

Expression Editor (arithmetic operators)

Operator

Meaning

Example

Result

+

addition

10 + 5

15

-

subtraction; negation

10 - 5 = 5 or 10 + (-5)

5

*

multiplication

10 * 5

50

/

division

10 / 5

2

** or ^

power/exponentiation

10**5 or 10^5

100000

Expression Editor (comparison operators)

Operator

Meaning

Example

Result

>

greater than

10 > 5

true

<

less than

10 < 5

false

>=

greater than or equal

10 >= 5

true

<=

less than or equal

10 <= 5

false

=

equal

10 = 5

false

Expression Editor (logical operators)

Operator

Meaning

Example

Result

OR

or

false OR true

true

AND

and

false AND true

false

Expression Editor (general mathematical functions)

Function

Meaning

Example use

EXP

Returns e raised to the power of a given number

EXP(number)

LOG10

Returns the base-10 logarithm of a number

LOG10(number)

LN

Returns the natural logarithm of a number

LN(number)

ABS

Returns the absolute value of a number

ABS(number)

SQRT

Returns a positive square root

SQRT(number)

MOD

Returns the remainder from division

MOD(number,divisor)

ROUND

Rounds a number to the nearest integer

ROUND(number)

Expression Editor (statistical functions)

Function

Meaning

Example use

AVERAGE

Returns the average of its arguments

AVERAGE(variable_name)

COUNT

Counts how many numbers are in the list of arguments

COUNT(variable_name)

COUNTIF

Counts how many numbers in the list of arguments satisfy the expression

COUNTIF(variable_name,expression)

MAX

Returns the maximum value in a list of arguments

MAX(variable_name) or MAX(number,number)

MEDIAN

Returns the median of its arguments

MEDIAN(variable_name)

MIN

Returns the minimum value in a list of arguments

MIN(variable_name) or MIN(number,number)

STDEV

Estimates standard deviation based on a sample

STDEV(variable_name)

Expression Editor (trigonometric functions)

Function

Meaning

Example use

ARCCOS

Returns the inverse cosine of a number

ARCCOS(number)

ARCSIN

Returns the inverse sine of a number

ARCSIN(number)

ARCTAN

Returns the inverse tangent of a number

ARCTAN(number)

COS

Returns the cosine of a number

COS(number)

SIN

Returns the sine of a number

SIN(number)

Expression Editor (miscellaneous functions)

Function

Meaning

Example use

IF

Specifies a logical test to perform

IF(logical_test,value_if_true,value_if_false)

N1

Returns 1 if the number is less than zero, 0 otherwise

N1(number)

P1

Returns 1 if the number is greater than zero, 0 otherwise

P1(number)

Expression Editor (predefined variables)

Function

Meaning

$now.year

Returns the 4-digit year of the current time-step

$now.day

Returns the day of the current time-step (range: 1...31)

Expression Editor (date range instances)

Date Range

Meaning

Current Time Step

The most-recently-updated value.

Current Iteration

Only applicable to NetLP. The value updated during the last iteration of the solver.

Current Day

For a daily model, this is a synonym for Current Time Step. For a sub-daily model, it is the sum of the values for the current day.

This Month

For a monthly model, this is a synonym for Current Time Step. For a sub-monthly model, it is the sum of the values for the current month.

This Calendar Year

For a yearly model, this is a synonym for Current Time Step. For a sub-yearly model, it is the sum of the values for the current calendar year.

Last Time Step

The value of the variable at the completion of the previous iteration of the model.

Previous Day

For a daily model, this is a synonym for Last Time Step. For a sub-daily model, it is the sum of the values for the previous day.

Last Month

For a monthly model, this is a synonym for Last Time Step. For a sub-monthly model, it is the sum of the values for the previous month.

Last Calendar Year

For a yearly model, this is a synonym for Last Time Step. For a sub-yearly model, it is the sum of the values for the previous calendar year.

Expression Editor (date range sets)

Date Range

Meaning

Example of use

Last Hundred Time Steps

The set of values from the model for the previous 100 iterations.

Lookup($var,35)
(finds 35th value)

Last Seven Days

For a daily or monthly model, this is the set of the values from the last seven time steps. For a sub-daily model, it is the set of the average daily values for each of the previous seven days.

Average($var)

Previous 30 Days

For a daily or monthly model, this is the set of the values from the last 30 time steps. For a sub-daily model, it is the set of the average daily values for each of the previous 30 days.

Average($var)

Patterns tab (expression inputs)

Name

Units

Type

Edit

$MonthlyInflows

ML/day

Monthly

Edit

Patterns tab (result units)

Expression Editor Equation

Result Units

$MonthlyInflows

ML/day

Time Series tab (expression inputs)

Variable Name

Edit

Start

End

Units

$DailyDemands1

Edit

Model will auto fill

Model will auto fill

No units selected

$DailyDemands2

Edit

Model will auto fill

Model will auto fill

No units selected

Time Series tab (result units)

Expression Editor Equation

Result Units

$DailyDemands1 + $DailyDemands2

ML/day

Variable Name

Source

Part

Units

Data Range

$OrderWeek

Storage 2

Requested Flow Rate

ML/day

Last 7 days (set)

Global expressions (expression inputs)

Name

Expression

$Minimum Flow

average($OrderWeek)

Global expressions (example expression)

Expression Box Equation using the Expression Editor

Result Units

If(($MinimumFlow>4000,4000,if($MinimumFlow<0,0,$MinimumFlow))

ML/day

Expression Editor file format (monthly pattern, .CSV)

Row

Column (comma-separated)

1

2

1

Monthly

Monthly Amount (units)

Where: units are the units specified in Expression Editor (eg "ML/day")
month is the full name of the month in order from "January" to "December"
value is the observation to apply for the corresponding month

Expression Editor file format (weekly pattern, .CSV)

Row

Column (comma-separated)

1

2

1

Weekly

Weekly Amount (units)

Where: units are the units specified in Expression Editor (eg "ML/day")
week is the week ordinal from 1 through 53
value is the observation to apply for the corresponding week

Expression Editor file format (daily pattern, .CSV)

Row

Column (comma-separated)

1

2

1

Daily

Daily Amount (units)

Where: units are the units specified in Expression Editor (eg "ML/day")
dd is the day of the month (1...the number of days in the month, assuming 29 for February)
mm is the 3-character abbreviated month name (eg "Jan")
value is the observation to apply for the corresponding day

Expression Editor file format (6-hourly pattern, .CSV)

Row

Column (comma-separated)

1

2

1

Six hourly

Six hourly Amount (units)

Where: units are the units specified in Expression Editor (eg "ML/day")
ddd is the Julian day of the year (1...366)
hh is a two digit hour, either "00", "06", "12" or "18"
value is the observation to apply for the corresponding six-hour period

Expression Editor file format (hourly pattern, .CSV)

Row

Column (comma-separated)

1

2

1

Hourly

Hourly Amount (units)

Where: units are the units specified in Expression Editor (eg "ML/day")
hh is a one- or two-digit hour from "0" ... "23"
value is the observation to apply for the corresponding hour