InfoWorks WS – User Programmable Control Scripts
USER PROGRAMMABLE CONTROL SCRIPTS
PRACTICAL EXAMPLES OF UPC’S IN INFOWORKS WS
JUNE 2013
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd ii June 2013
CONTENTS
USER PROGRAMMABLE CONTROL SCRIPTS ................................ 1
PRACTICAL EXAMPLES OF UPC’S IN INFOWORKS WS ............................... 1
JUNE 2013 ............................................................................................... 1
1. INTRODUCTION ............................................................... 1
2. BASIC PRINCIPLES OF UPC SCRIPTS .................................... 1
2.1 General Notes ................................................................................. 1
2.2 UPC Script Language ....................................................................... 2
3. EXAMPLES ....................................................................... 6
3.1 Level Controlled Pump .................................................................... 6
3.2 Variable Speed Pump Used to Maintain Reservior Level...................... 7
3.3 30 Minute Pump Delay .................................................................... 8
3.4 Time Dealy on 2nd Pump Starting and Reservoir Level Still Falling ....... 9
3.5 Set Valve Opening Based on Time of Day......................................... 11
3.6 Variable on and Off Levels for a Pump............................................. 13
3.7 Calculate Volume Through Pipe and Close if Limit Breached ............ 15
3.8 Slowly Open/Close a Valve Based on Reservoir Level over a Time
Period .................................................................................................. 16
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 1 June 2013
1. INTRODUCTION
User programmable control scripts are a flexible way of controlling assets in an InfoWorks WS
model. This document aims to show some examples of some UPC’s so that users can use
these to build their own UPC’s within their models.
2. BASIC PRINCIPLES OF UPC SCRIPTS
2.1 GENERAL NOTES
2.1.1 UNITS AND DATES
User units are always assumed in UPC Scripts. Dates are in the ISO Standard 8601 format of
YYYY-MM-DD
2.1.2 GLOBAL OR LOCAL UPC SCRIPTS
Within InfoWorks it is possible to have Global UPC Scripts or Local UPC Scripts. Global UPC
Scripts are accessible from the Network Menu. Local UPC Scripts are accessible from the
Properties Sheet of and object.
Global Scripts Local Scripts
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 2 June 2013
Global UPC Scripts are useful if you have rules that apply to a number of assets but they are
related to each other or if you have common conditions and variable that you want to use for
multiple objects. Local UPC Scripts only apply to the object that they are attached to. The
language for a Local UPC Script can be simpler as you do not have to define the asset that is
being controlled.
Global Script: VALVE K470024.K470023.1 OPENING = 75
Local Script: OPENING = 75
2.1.3 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
• any activated actions targeting individual pumps which appear earlier in the script are
overridden
• any actions targeting individual pumps which follow are performed independently
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.
2.2 UPC SCRIPT LANGUAGE
2.2.1 RULES
UPC Rules have a general form of;
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 3 June 2013
RULE name
IF condition1 THEN
action1
ELSEIF condition2 THEN
action2
ELSE
action3
ENDIF
Default Rules can be used and if no other rules in the script apply then the default rule will be
used.
RULE _Default_
IF TRUE THEN
PUMP 1 = ON ENDIF
2.2.2 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:
• arg1 is, or represents, some object attribute, run property or any predefined script
object which provides an appropriate numerical or time value;
• operator can be any of the relational operators <, <=, =, >=, >, !=, and
• arg2 is either a number, time value, an expression, another object attribute or any
other predefined script object returning a numerical or time value.
The result is either TRUE or FALSE
For example:
COND condition1 = RES CRES2 PRESSURE >= 4
2.2.3 ACTIONS
Actions specify the changes to be made to object attributes. Actions can be:
• Direct, e.g. turn a pump on:
PST pstup.pstdn.1 PUMP1 = ON
• Indirect, e.g. using a pump to maintain the level in a reservoir
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:
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 4 June 2013
arg1 = arg2 [USING stream arg3]
Where:
• arg1 is, or represents, some allowed object attribute
• arg2 is either a number, some script object returning a value or a numerical
expression containing numbers and/or any script objects returning values
• the optional keyword USING signifies an indirect control
• stream is either UP[STREAM] or DOWN[STREAM] to indicate that the regulator is
either up or downstream from the control point
• arg1 and arg3 can only specify object attributes and cannot contain arithmetic
expressions
For example:
RES CRES2 DEPTH = 3 USING UPSTREAM PST KCH2PMP.KCH20001.1
2.2.4 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
For example:
VAR var_2 = PST pstup.pstdn.1 PUMP 1 SPEED
2.2.5 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:
• the timer is started if not running when cond1 is TRUE
• the timer is stopped and reset to zero if cond2 is TRUE
• the timer is paused if cond3 is TRUE
Conditions can either be explicit or predefined condition names. The output from a timer is the
elapsed time in seconds.
2.2.6 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
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 5 June 2013
data1 data2
…
ENDTABLE
where:
• arg1 can be: an object attribute, another table name, variable name or timer name
• arg2 is the output quantity, e.g. HEAD, FLOW, etc.
• type is either LIN[EAR] or [STEP]
• data1 data2 are data pairs
For example:
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
2.2.7 INITIAL CONDITIONS
Initial conditions are defined by using the INITIALISE keyword:
INIT[IALISE] object id attribute = attribute_value
where:
• object is the regulator type: PST or VALVE
• id is the object id
• attribute is the object attribute: SPEED or STATE for Pump Stations, or OPENING for
Valves
• attribute_value is the numeric value to which the SPEED, STATE or OPENING of the
regulator is to be set
For example:
INITIALISE VALVE K470024.K470023.1 OPENING = 75
2.2.8 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.
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 6 June 2013
3. EXAMPLES
3.1 LEVEL CONTROLLED PUMP
A pump is used to control the level in a reservoir. It is programmed to turn on when the level
in the reservoir falls below 3.92m and the pump will turn off if the level goes above 4.08m
As you are probably aware this situation can be modelled using the standard controls in
InfoWorks using the AUTO. Sometimes it is useful to be able to replicate the standard
controls in UPC in case you need to add any additional parameters to them (e.g. abstraction
limits).
3.1.1 UPC SCRIPTS
Local UPC Script Global UPC Script
RULE autocontrol
IF RES CRES2 DEPTH < 3.92 THEN
PUMP = ON
ELSEIF RES CRES2 DEPTH > 4.08 THEN
PUMP = OFF
ENDIF
RULE autocontrol
IF RES CRES2 DEPTH < 3.92 THEN
PST KCH2PMP.KCH20001.1 PUMP 1 = ON
ELSEIF RES CRES2 DEPTH > 4.08 THEN
PST KCH2PMP.KCH20001.1 PUMP 1 = OFF
ENDIF
Reservoir
CRES2
Off level = 4.08m
On level = 3.92m
Pump KCH2PMP.KCH20001.1
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 7 June 2013
3.2 VARIABLE SPEED PUMP USED TO MAINTAIN RESERVIOR LEVEL
A pump is used to maintain a set level in a reservoir. The pump is on continuously and it
varies its speed to maintain a set level of 4m.
This is another situation that can be modelled using the standard controls in InfoWorks. This
is a PROF control.
3.2.1 UPC SCRIPTS
Local UPC Script Global UPC Script
INIT PUMP = ON
RULE profcontrol
IF PUMP = ON THEN
RES KRES32 DEPTH = 4 USING
UPSTREAM PST KKR1PMP.KKR10001.1
ENDIF
INIT PST KKR1PMP.KKR10001.1 PUMP 1 =
ON
RULE profcontrol
IF PST KKR1PMP.KKR10001.1 PUMP 1 =
ON THEN
RES KRES32 DEPTH = 4 USING
UPSTREAM PST KKR1PMP.KKR10001.1
ENDIF
Reservoir
KRES32
Target level = 4.0m
Pump KKR1PMP.KKR10001.1
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 8 June 2013
3.3 30 MINUTE PUMP DELAY
A pump is used to control the level in a reservoir. It is programmed to turn on when the level
in the reservoir falls below 3.79m and the pump will turn off if the level goes above 3.81m.
This control has an added parameter that the pump is not allowed to turn on again until 30
minutes has passed since it turned on.
3.3.1 UPC SCRIPTS
Local UPC Script Global UPC Script
COND PumpOn = NODE KRES32
PRESSURE < 3.79
COND PumpOff = NODE KRES32
PRESSURE >= 3.81
COND POn = PUMP STATE >= 1
COND POff = PUMP STATE < 1
TIMER Timer START POff RESET POn
COND Delay = Timer >= 1800
COND On = Delay AND PumpOn
RULE On
IF On THEN
PUMP 1 = ON
ENDIF
RULE PumpOff
IF PumpOff THEN
PUMP 1 = OFF
ENDIF
COND PumpOn = NODE KRES32
PRESSURE < 3.79
COND PumpOff = NODE KRES32
PRESSURE >= 3.81
COND POn = PST KKR1PMP.KKR10001.1
PUMP STATE >= 1
COND POff = PST KKR1PMP.KKR10001.1
PUMP STATE < 1
TIMER Timer START POff RESET POn
COND Delay = Timer >= 1800
COND On = Delay AND PumpOn
RULE On
IF On THEN
PST KKR1PMP.KKR10001.1 PUMP 1 = ON
ENDIF
RULE PumpOff
IF PumpOff THEN
PST KKR1PMP.KKR10001.1 PUMP 1 = OFF
ENDIF
Reservoir
KRES32
Off level = 3.81m
On level = 3.79m
Pump KKR1PMP.KKR10001.1
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 9 June 2013
3.4 TIME DEALY ON 2ND PUMP STARTING AND RESERVOIR LEVEL
STILL FALLING
Two pumps are used to control the level in a reservoir. Pump 1 is programmed to start when
the reservoir level falls below 3.5m and it will turn off if the reservoir level goes above 4.5m.
The second pump is programmed to start if pump 1 has been on for 10mins and the reservoir
depth is still falling.
3.4.1 UPC SCRIPTS
Local UPC Script Global UPC Script
Global Script
COND PumpOn = NODE KRES32
PRESSURE < 3.5
COND PumpOff = NODE KRES32
PRESSURE >= 4.5
COND Pump1On = PST
KKR2PMP.KKR20001.1 PUMP STATE >= 1
COND Pump1Off = PST
KKR2PMP.KKR20001.1 PUMP STATE < 1
TIMER Time1On START Pump1On RESET
Pump1Off
COND 10Mins = Time1On >= 600
COND PresDec = NODE KRES32 DHDT < 0
COND Pump2On = PumpOn AND 10Mins
AND PresDec
KKR2PMP.KKR20001.1 Local Script
RULE PumpOn
IF PumpOn THEN
PUMP 1 = ON ENDIF
COND PumpOn = NODE KRES32
PRESSURE < 3.5
COND PumpOff = NODE KRES32
PRESSURE >= 4.5
COND Pump1On = PST
KKR2PMP.KKR20001.1 PUMP STATE >= 1
COND Pump1Off = PST
KKR2PMP.KKR20001.1 PUMP STATE < 1
TIMER Time1On START Pump1On RESET
Pump1Off
COND 10Mins = Time1On >= 600
COND PresDec = NODE KRES32 DHDT < 0
COND Pump2On = PumpOn AND 10Mins
AND PresDec
RULE PumpOn
IF PumpOn THEN
PST KKR2PMP.KKR20001.1 PUMP 1 =
ON ENDIF
Reservoir
KRES32
Off level = 4.5m
On level = 3.5m
Pump 2 KKR1PMP.KKR10001.1
Pump 1 KKR2PMP.KKR20001.1
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 10 June 2013
RULE PumpOff
IF PumpOff THEN
PUMP 1 = OFF ENDIF
KKR1PMP.KKR10001.1 Local Script
RULE Pump2On
IF Pump2On THEN
PUMP 1 = ON ENDIF
RULE PumpOff
IF PumpOff THEN
PUMP 1 = OFF ENDIF
RULE PumpOff
IF PumpOff THEN
PST KKR2PMP.KKR20001.1 PUMP 1 =
OFF ENDIF
RULE Pump2On
IF Pump2On THEN
PST KKR1PMP.KKR10001.1 PUMP 1 =
ON ENDIF
RULE PumpOff
IF PumpOff THEN
PST KKR1PMP.KKR10001.1 PUMP 1 =
OFF ENDIF
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 11 June 2013
3.5 SET VALVE OPENING BASED ON TIME OF DAY
A valve (K200239.K2000240.1) has a set opening for given times of the day, as shown in the
diagram below.
3.5.1 UPC SCRIPTS
Local UPC Script Global UPC Script
Standalone Control Profile
20%
75%
35%
05:00
22:00
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 12 June 2013
VAR setting = RUN PROF ValveOpening
RULE ValOpen
IF TRUE THEN
OPENING = setting ENDIF
VAR setting = RUN PROF ValveOpening
RULE ValOpen
IF TRUE THEN
VALVE K200239.K2000240.1 OPENING =
setting ENDIF
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 13 June 2013
3.6 VARIABLE ON AND OFF LEVELS FOR A PUMP
A pump is used to control the level in a reservoir. The on and off levels are calculated from
the reservoir set point that varies over the day. The on level is 0.3m below the set point and
the off level is 0.5m above the set point.
Time Set Point Level
00:00:00 3.8m
08:00:00 3.5m
22:00:00 3.8m
3.6.1 UPC SCRIPTS
Local UPC Script Global UPC Script
Standalone Control Profile
Reservoir
KCT1
Off level = Variable
On level = Variable
Pump KPB2HOL.KPB20001.1
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 14 June 2013
VAR setpoint = RUN PROF SetPoint
VAR onlevel = setpoint - 0.3
VAR offlevel = setpoint + 0.5
RULE varautocontrol
IF RES KCT1 DEPTH < onlevel THEN
PUMP = ON
ELSEIF RES KCT1 DEPTH > offlevel THEN
PUMP = OFF
ENDIF
VAR setpoint = RUN PROF SetPoint
VAR onlevel = setpoint - 0.3
VAR offlevel = setpoint + 0.5
RULE varautocontrol
IF RES KCT1 DEPTH < onlevel THEN
PST KPB2HOL.KPB20001.1 PUMP 1 = ON
ELSEIF RES KCT1 DEPTH > offlevel THEN
PST KPB2HOL.KPB20001.1 PUMP 1 = OFF
ENDIF
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 15 June 2013
3.7 CALCULATE VOLUME THROUGH PIPE AND CLOSE IF LIMIT
BREACHED
A particular pipepline has a volume limit on it. Once the volume for the day has reached 1Ml
then the valve should shut to prevent any further flow through that pipe.
3.7.1 UPC SCRIPTS
Local UPC Script Global UPC Script
INITIALISE OPENING = 100
VAR Flow = LINK K200076.K200077.1
FLOW
TABLE Volume IN LINK K200076.K200077.1
FLOW OUT VOLUME TYPE LINEAR
20.000 6
25.000 7.5
30.000 9
ENDTABLE
VAR Var VOLUME = Volume + Var
COND Limit = Var >= 1000
RULE Limit
IF Limit THEN
OPENING = 0 ENDIF
INITIALISE VALVE K200015.K200074.1
OPENING = 100
VAR Flow = LINK K200076.K200077.1
FLOW
TABLE Volume IN LINK K200076.K200077.1
FLOW OUT VOLUME TYPE LINEAR
20.000 6
25.000 7.5
30.000 9
ENDTABLE
VAR Var VOLUME = Volume + Var
COND Limit = Var >= 1000
RULE Limit
IF Limit THEN
VALVE K200015.K200074.1 OPENING = 0
ENDIF
Note: In the table flow is measured in l/s and the volume is measured in m3. So the values in
the table are to convert l/s to l in a 5 min period. If the timestep of the simulation is not 5 min
then a different table will need to be calculated.
Valve K200015.K200074.1
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 16 June 2013
3.8 SLOWLY OPEN/CLOSE A VALVE BASED ON RESERVOIR LEVEL
OVER A TIME PERIOD
An inlet valve to a reservoir is programmed to slowly open and slowly close based on
reservoir level. The valve should take 30mins to open or close.
3.8.1 UPC SCRIPTS
Local UPC Script Global UPC Script
INITIALISE OPENING = 0
COND Closed = NODE KRES32 HEAD >=
146.25
COND Open = NODE KRES32 HEAD <
146.15
TIMER TimerOpen START Open RESET
Closed
TIMER TimerClose START Closed RESET
Open
TABLE %Close IN TimerClose OUT
OPENING TYPE LINEAR
0.000 100
900.000 50
1800.000 0
86400.000 0
ENDTABLE
TABLE %Open IN TimerOpen OUT
OPENING TYPE LINEAR
0.000 0
900.000 50
1800.000 100
86400.000 100
ENDTABLE
INITIALISE VALVE KRES0033.KRES32.1
OPENING = 0
COND Closed = NODE KRES32 HEAD >=
146.25
COND Open = NODE KRES32 HEAD <
146.15
TIMER TimerOpen START Open RESET
Closed
TIMER TimerClose START Closed RESET
Open
TABLE %Close IN TimerClose OUT
OPENING TYPE LINEAR
0.000 100
900.000 50
1800.000 0
86400.000 0
ENDTABLE
TABLE %Open IN TimerOpen OUT
OPENING TYPE LINEAR
0.000 0
900.000 50
1800.000 100
86400.000 100
ENDTABLE
Reservoir
KRES32
Off level = 146.25
On level = 146.15
Valve KRES0033.KRES32.1
Bottom level = 142.3
InfoWorks WS – User Programmable Control Scripts
© Innovyze Ltd 17 June 2013
RULE Open
IF Open THEN
OPENING = %Open ENDIF
RULE Closed
IF Closed THEN
OPENING = %Close ENDIF
RULE Open
IF Open THEN
VALVE KRES0033.KRES32.1 OPENING =
%Open ENDIF
RULE Closed
IF Closed THEN
VALVE KRES0033.KRES32.1 OPENING =
%Close ENDIF