UPC script language

This topic describes the UPC Script language that can be used to define logical controls of valves and Pump Stations.

The topic is divided into the following subsections:

Simple examples of UPC scripts can be found in the UPC Script Examples topic.

General Notes

This section includes some general notes about the use of UPC Scripts.

Units

Dates

Global and Local Scripts

UPC Scripts may be set up either as Global or Local scripts.

Local Scripts are stored as part of the control for individual network objects. Local Scripts associated with a network objects will override any Global Scripts referring to the object.

In a Local Script, references to the object that the script is associated with can be abbreviated. For example, to define a valve opening in a Global Script, the Valve ID must be specified, followed by the attribute to be controlled:

VALVE K470024.K470023.1 OPENING = 75

In a Local Script stored as part of the control for Valve K470024.K470023.1, this can be abbreviated to just the attribute:

OPENING = 75

Similarly in a Local Script stored as part of the control for a Pump Station, the reference to the Pump Station ID can be omitted.

Gloabl Script:

PST KCH2PMP.KCH20001.1 PUMP 1 = ON AND KCH2PMP.KCH20001.1 PUMP 1 SPEED = 1800

Local Script:

PUMP 1 = ON AND PUMP 1 SPEED = 1800

Evaluation of UPC Script Rules

At the beginning of every time-step all Conditions in all Rules are evaluated to either TRUE or FALSE.

The rules are evaluated in the order they appear in the script to determine which actions should be activated. In general, if activated actions appear to contradict each other or set different values for the same object attribute, the last action in the sequence is used.

The exception to this is when an Action targets a pump station,

e.g.

PST name STATE = state

PST name SPEED = speed

or any indirect action USING a pump station

In this case

For example:

PST name PUMP 1 = ON AND PST name PUMP 2 = OFF

PST name STATE = 010

will result in pumps 1 and 3 being switched off and pump 2 on.

PST name STATE = 010

PST name PUMP 3 = ON

will result in pump 1 off and pumps 2 and 3 ON.

Rules

UPC rules can be written in the general form:

RULE name

IF condition1 THEN

action1

ELSEIF condition2 THEN

action2

ELSE

action3

ENDIF

Where:

Closed

RULE rule1

IF RES CRES2 DEPTH < 3.4 THEN

PST KCH2PMP.KCH20001.1 PUMP 1 = ON AND

PST KCH2PMP.KCH20001.1 PUMP 1 SPEED = 1800

ELSEIF RES CRES2 DEPTH < 3.8 THEN

PST KCH2PMP.KCH20001.1 PUMP 1 = ON AND

PST KCH2PMP.KCH20001.1 PUMP 1 SPEED = 1500

ELSE

PST KCH2PMP.KCH20001.1 PUMP 1 = OFF

ENDIF

If the depth in Reservoir CRES2 is less than 3.4, Pump 1 in Pumping Station KCH2PMP.KCH20001.1 will be turned on and set at 1800 rpm.

If the depth in  Reservoir CRES2 is between 3.4 and 3.8, Pump 1 in Pumping Station KCH2PMP.KCH20001.1 will be turned on and set at 1500 rpm.

If the depth in Reservoir CRES2 is above 3.8, Pump 1 in Pumping Station KCH2PMP.KCH20001.1 will be turned off.

In this example the first action consists of two separate actions joined by the keyword AND. Any number of sub-actions can be joined in this way whenever an action is expected, see Actions below.

Also, object attributes e.g. "PST KCH2PMP.KCH20001.1 PUMP 1 SPEED" have been used a number of times. In order to simplify the rule, an object attribute can be aliased by defining a variable (see Variables below).

Default Rules

To set a default Rule, use _Default_ as the name of the Rule. e.g.

RULE _Default_

    IF TRUE THEN

    PUMP 1 = ON ENDIF

If none of the other rules defined in the UPC Script are satisfied, the default rule will be applied.

Conditions

Conditions are various tests on the state of network objects or a limited set of network wide run properties.

Conditions are defined by using the CONDITION keyword:

CON[DITION] name = arg1 operator1 arg2 operator2 arg3 ...

where:

For example:

Closed

COND condition1 = RES CRES2 PRESSURE >= 4

RULE rule1

    IF condition1 THEN

             PST KCH2PMP.KCH20001.1 PUMP 1 = OFF

    ELSE

             PST KCH2PMP.KCH20001.1 PUMP 1 = ON

   ENDIF

If the pressure in Reservoir, CRES2 is more than or equal to 4, Pump 1 in Pumping Station KCH2PMP.KCH20001.1 will be turned off. Otherwise, Pump 1 will be turned on.

When using a Local UPC Script the definition of the Pump Station can be omitted. (See the General Notes section above.)

If the number of the pump is not defined, Pump 1 will be assumed.

Allowable object attributes for use in conditions take the form

object id attribute

Where:

Notes

Object Types

Allowable object types for use in UPC Script Conditions are detailed below:

RUN is also an allowable object type and can be used to define times and dates and refer to Control Profiles.

Object Object Type

Nodes

NODE

RES[ERVOIR]

FIX[EDHEAD]

TRANS[FER]

WELL

HYD[RANT]

Links

LINK

PIPE

VAL[VE]

PST

Object Groups

GROUP LINK

GROUP RES[ERVOIR]

GROUP PST

Object Attributes

Allowable object attributes for use in UPC Script Conditions are detailed below:

Object Description
Nodes

All Nodes:

UPC Attribute Description
HEAD Head
PRESS[URE] Pressure

DHDT

Rate of change in head with time

DPDT

Rate of change in pressure with time

DEM[AND]

Demand at node

LEAK[AGE]

Leakage at node

CONC[ENTRATION]

Concentration at node (will be tested in Water Quality Runs only)

AGE

Water Age in hours (will be tested in Water Quality Runs only)

 

RES[ERVOIR]

UPC Attribute Description

DEP[TH]

Reservoir Depth

VOL[UME]

Reservoir Volume

PCVOL[UME]

Reservoir volume as a percentage of the full volume

 

HYD[RANT]

UPC Attribute Description

FLOW

Hydrant Flow

OPEN[ING]

Hydrant Opening

Links

All Links:

UPC Attribute Description

FLOW

Flow

STATUS

Status

DQDT

Rate of change in flow with time

 

VAL[VE]

UPC Attribute Description

OPEN[ING]

Valve Opening

PROF[ILE]

Control Profile defined on Valve Control Page of Valve Property Sheet.

 

PST

UPC Attribute Description

SPEED

SPEED will test the speed of the first running variable speed pump in PST name against the value speed.

Use PUMP followed by the pump number to define speed of a particular pump in the PST.

STATE

STATE will test the pump state of all pumps in the PST, where ON = 1 and OFF = 0.

e.g. STATE = 010 tests for pumps 1 and 3 off and pump 2 on

PUMP

PUMP implies pump 1 unless followed by the pump number and has the sub attribute SPEED.

e.g. PUMP 1 SPEED = 2500

PROF[ILE]

Control Profile defined on the Pump Control Data Page of the Pump Station Property Sheet.

POW[ER]

Electric Power

TAR[IFF]

Electricity Tariff

COST

Cost

ONPU[MPS]

The number of pumps switched on in the PST

OFFPU[MPS]

The  number of available pumps switched off in the PST.

This number excludes pumps defined as 'Not Available' in an AUTO or PROF PST.

Object Groups

GROUP LINK

UPC Attribute Description

FLOW

Link Group Flow

DQDT

Rate of change in Link Group flow with time

 

GROUP RES[ERVOIR]

UPC Attribute Description

DEM[AND]

Demand at Reservoirs in Reservoir Group

LEAK[AGE]

Leakage at Reservoirs in Reservoir Group

VOL[UME]

Reservoir Group Volume

PCVOL[UME]

Reservoir Group Percentage Volume

 

GROUP PST

UPC Attribute Description

FLOW

Pump Station Group Flow

DQDT

Rate of change in Pump Station Group flow with time

ONPU[MPS]

The number of pumps switched on in the Pump Station Group

OFFPU[MPS]

The number of available pumps switched off in the Pump Station Group.

This number excludes pumps defined as 'Not Available' in AUTO and PROF Pumping Stations.

POW[ER]

Pump Station Group Electric Power

COST

Pump Station Group Cost

RUN
UPC Attribute Description

DATET[IME]

Date and Time in ISO Standard Format:

YYYY-MM-DD HH:MM

DATE

Date in ISO Standard Format:

YYYY-MM-DD

DAY

Day of the week, values 1 to 7 representing Monday to Sunday

TIME

Time of day HH:MM

DAY[TIME] Day of the week with time of day. This combines DAY and TIME in the format dd HH:MM where dd is 1 through 7, representing the day of the week, Monday to Sunday.

SIMT[IME]

Time elapsed from the beginning of the run.

For simulations of less than one day this can be tested against time values HH:MM.

For multi-day runs, to test against times after the first day values take the form DD HH:MM with the number of days varying between 00 and 99.

DEM[AND]

Total demand across the network

LEAK[AGE]

Total leakage across the network

PROF[ILE] id

Refers to Control Profile named id

The use of a PROFILE is similar to that of a TABLE.

Actions

Actions specify the changes to be made to object attributes. Actions can be:

PST pstup.pstdn.1 PUMP1 = ON

RES res_name DEPTH = 3.0 USING UPSTREAM VALVE valve_name

where valve valve_name is used to maintain a level of 3 at reservoir res_name and the valve is upstream from the reservoir, that is, it acts as a pressure reducing valve.

In general, an action can be written as:

arg1 = arg2 [USING stream arg3]

where:

Closed

COND condition1 = RUN TIME >= 07:00 AND RUN TIME < 10:00

RULE rule1

IF condition1

THEN RES CRES2 DEPTH = 3 USING UPSTREAM PST KCH2PMP.KCH20001.1

ELSE

RES CRES2 DEPTH = 2.5 USING UPSTREAM PST KCH2PMP.KCH20001.1

ENDIF

If the time is between 07:00 and 10:00 the depth in Reservoir CRES2 will be maintained at 3 using PST KCH2PMP.KCH20001.1, else a depth of 2.5 will be maintained.

When using a Local UPC Script the definition of the Pump Station can be replaced with REGULATOR:

RES CRES2 DEPTH = 2.5 USING UPSTREAM REGULATOR

Actions can be explicit in a rule or can be given an alias by using the ACTION keyword:

Closed

COND condition1 = RUN TIME >= 07:00 AND RUN TIME < 10:00

ACTION action1 RES CRES2 DEPTH = 3 USING UPSTREAM PST KCH2PMP.KCH20001.1

ACTION action2 RES CRES2 DEPTH = 2.5 USING UPSTREAM PST KCH2PMP.KCH20001.1

RULE rule1

IF condition1

THEN action1

ELSE

action2

ENDIF

If the time is between 07:00 and 10:00 the depth in Reservoir CRES2 will be maintained at 3 using PST KCH2PMP.KCH20001.1, else a depth of 2.5 will be maintained.

When using a Local UPC Script the definition of the Pump Station can be replaced with REGULATOR:

RES CRES2 DEPTH = 2.5 USING UPSTREAM REGULATOR

ACT[ION] name action

where:

ACT[ION] name = action1 AND action2 AND action3 ...

For example:

Closed

COND condition1 = RUN TIME >= 07:00 AND RUN TIME < 10:00

ACTION action1 PUMP 1 = ON AND PUMP 1 SPEED = 1500

ACTION action2 PUMP 1 = ON AND PUMP 1 SPEED = 1800

RULE rule1

IF condition1

THEN action1

ELSE

action2

ENDIF

Object Attributes

Allowable object attributes for use in UPC Script Actions, depend on whether the Action is Direct or Indirect:

Direct Actions

Object UPC Attribute Description

VAL[VE]

OPEN[ING]

Valve Opening

PST

SPEED

SPEED will set the speed of the first running variable speed pump in PST name against the value speed.

Use PUMP followed by the pump number to define speed of a particular pump in the PST.

STATE

STATE will set the pump state of all pumps in the PST to the value specified, where ON = 1 and OFF = 0.

e.g. STATE = 010 tests for pumps 1 and 3 off and pump 2 on

PUMP

PST name PUMP number = setting will switch pump number to setting where setting is either ON or OFF.

(PUMP implies pump 1 unless followed by the pump number.)

Indirect Actions

For indirect actions, regulators can only control:

Variables

Variables can be used as an alias for object attributes, or numerical expressions involving object attributes.

An alias for an object attribute is defined:

VAR[IABLE] name = object_attribute

Closed

COND condition_1 RES res1 DEPTH < 2

VAR var_1 = PST pstup.pstdn.1 PUMP 1

VAR var_2 = PST pstup.pstdn.1 PUMP 1 SPEED

COND condition_2 var_2 >= 1450

ACTION action_1 var_name = ON AND var_2 = 1450

RULE rule_name

IF condition_1 THEN

action_1

ELSEIF RES res1 DEPTH >= 5 THEN

IF condition_2 THEN

var_2 = 1150

ELSE

var_1 = OFF

ENDIF

ENDIF

var_1 and var_2 are aliases for the state of pump 1 (ON or OFF) and the speed of pump 1.

An alias for a numerical expression is defined:

VAR[IABLE] name [attribute] = arg1 operator1 arg2 operator2 arg3 ...

where:

IF and ELSE can also be used as operator1 and operator2 respectively:

VAR[IABLE] name [attribute] = arg1 IF arg2 ELSE arg3

where:

Using Time Variables

All Time object attributes (DATETIME, DATE, DAY, TIME, DAYTIME, SIMTIME) can be used as Variables. The rules when adding or subtracting these variables are listed below.

When adding Time Variables:

When subtracting Time Variables:

Using Variables as Accumulators

Variables can be used as accumulators. The accumulator function is achieved by redefining a variable as itself, plus or minus the attribute to be accumulated.

A variable can be re-zeroed using the IF...ELSE form (see above).

Closed

RULE _Default_

    IF TRUE THEN

    PUMP 1 = ON ENDIF

VAR Outflow = LINK K200032.K200236.1 FLOW

VAR CumulativeFlow = Outflow * 300.00000

VAR Total = Total + CumulativeFlow

COND Reset = RUN TIME < 00:01

COND Off = Total  >= 100000

RULE Off

    IF Off THEN

    PUMP 1 = OFF ENDIF

VAR Total = 0.00000 IF Reset ELSE Total

The cumulative flow in a link is calculated by using variable Total as an accumulator. When the cumulative flow reaches 100000, Pump1 is switched off.

Timers

A Timer provides a means for measuring time elapsed between specified trigger conditions.

Timers are defined by:

TIMER name START condition1 [RESET condition2] [PAUSE condition3]

where:

Conditions can either be explicit or predefined condition names. The output from a timer is the elapsed time in seconds.

Tables

Tables allow the translation from an input value to a new output value where values are given in tabular form. The output value is found either from linear interpolation or from a step function interpretation.

Tables are defined by:

Tab[LE] name IN arg1 OUT arg2 TYPE type

data1 data2

data1 data2

data1 data2

...

ENDTABLE

where:

For example:

Closed

COND Time = RUN DATETIME >= 1998-10-01 02:00 AND RUN DATETIME < 1998-10-02 00:00

TABLE NewTable IN RUN DATETIME OUT OPENING TYPE LINEAR

    1998-10-01 00:00 100

    1998-10-01 12:00 90

    1998-10-01 14:00 100

ENDTABLE

RULE Time

    IF Time THEN

   VALVE K200229.K200230.1 OPENING = NewTable ENDIF

If the time is between 1 Oct 1998 02:00 and 2 Oct 1998 00:00, the opening of Valve K200229.K200230.1 will follow the profile described in Table NewTable.

When using a Local UPC Script the definition of the Valve can be omitted.

Initial Conditions

Initial conditions are defined by using the INITIALISE keyword:

INIT[IALISE] object id attribute = attribute_value

where:

For example:

Closed

INITIALISE VALVE K470024.K470023.1 OPENING = 75

Initialise the opening of Valve K470024.K470023.1 at 75%.

INITIALISE PST KCH2PMP.KCH20001.1 PUMP 1 SPEED = 1500

Initialise the speed of Pump 1 at Pump Station KCH2PMP.KCH20001.1 at 1500 rpm

When using a Local UPC Script the definition of the PST / Valve can be omitted.

Comments

Comments can be added to a script by using the COMMENT keyword:

COM[MENT] Logical Rule for controlling Pump Station KCH2PMP

Any text on a line following the keyword COM[MENT] is ignored and treated as a comment.


UPC Scripts

UPC Script Page

Global UPC Script View

Updating Control Data from a UPC Scenario

UPC Script Examples