Share
 
 

UPC script examples

User programmable control (UPC) scripts are a flexible way of controlling assets in an InfoWorks WS Pro model. This topic aims to show some examples of UPC scripts so that they can be used to build your own UPC scripts.

Please refer to UPC scripts and UPC script language for more information on UPC scripts.

This sections below contain a few simple examples as well as a more complex one to demonstrate the use of UPC scripts in InfoWorks WS Pro.

Simple examples

Level controlled pump

Let us imagine a pump used to control the level in a reservoir. This pump is programmed to turn on when the level in the reservoir falls below 3.92m and to turn off if the level goes above 4.08m.

Level Controlled Pump

This situation can be modelled using the standard controls in InfoWorks WS Pro using the AUTO mode of control. However it is sometimes useful to be able to replicate the standard controls in UPC in case you need to set any additional parameters (e.g. abstraction limits).

The local and global UPC scripts for this example are presented in the table below:

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

Variable speed pump used to maintain reservoir level

Now let us take the example of a similar pump used to maintain a set level in a reservoir, except that it is on continuously and varies its speed to maintain a set level of 4m.

This is another situation that can be modelled using standard controls in InfoWorks WS Pro (using the PROF standard control)

Variable Speed Pump

UPC scripts for this are as follows:

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

30-minute pump delay

If we now consider a pump used to control the level in a reservoir which is programmed to turn on when the level in the reservoir falls below 3.79m and to 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.

30 minute Pump Delay

UPC scripts for this example are detailed below:

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

Time delay on second pump starting and reservoir level still falling

We now have 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 10 mins and the reservoir depth is still falling.

Two Pumps

Corresponding UPC scripts can be found in the table below:

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

KKR1PMP.KKR10001.1 Local Script

RULE Pump2On

IF Pump2On THEN

PUMP 1 = ON ENDIF

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

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

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

Set valve opening based on time of day

Let us look at a valve (K200239.K2000240.1) that has a set opening for given times of the day, as shown in the diagram below:

Set Valve Opening

Control profiles and UPC scripts for this are detailed below:

Local UPC Script Global UPC Script

Standalone Control Profile

Control Profile

Control Profile tab

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

Variable on and off levels for a pump

We now have a pump used to control the level in a reservoir for which 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.

Variable On and Off Levels for a Pump

Control profiles and UPC scripts illustrating this example are shown in the table below:

Local UPC Script Global UPC Script

Standalone Control Profile

Control Profile

Control Profile tab

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

Calculate volume through pipe and close if limit breached

Let us consider a particular pipepline that 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.

Volume Through Pipe

Related 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

Tip:

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.

Slowly open / close a valve based on reservoir level over a time period

This section show the example of an inlet valve to a reservoir which is programmed to slowly open and slowly close based on reservoir level. The valve should take 30 mins to open or close.

Slowly Open / Close Valve

UPC scripts for this are as follows:

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

RULE Open

IF Open THEN

OPENING = %Open ENDIF

RULE Closed

IF Closed THEN

OPENING = %Close ENDIF

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

RULE Open

IF Open THEN

VALVE KRES0033.KRES32.1 OPENING = %Open ENDIF

RULE Closed

IF Closed THEN

VALVE KRES0033.KRES32.1 OPENING = %Close ENDIF

More complex example

Let us now consider the example of two pumps (Pump 1 and Pump 2) and two reservoirs (RESA and RESB). Both pumps pump from RESA to RESB under certain conditions.

Worked Example 1

Pump conditions are detailed in the sections below.

Pump 1 On Conditions

If the level in RESB is below the time varying level below and there is sufficient depth in RESA then Pump 1 can be switched on.

Time RESB Depth
00:00

3.2m

16:00

3.0m

19:00

3.2m

Sufficient Depth is classed as the following:

Time RESA Depth
00:00

2.3m

07:00

2.6m

19:00

2.3m

Pump 1 On Conditions

Pump 2 On Conditions

If the level in RESB is below the time varying level below and there is sufficient depth in RESA then Pump 2 can be switched on.

Time RESB Depth
00:00

3.1m

16:00

2.8m

19:00

3.1m

Sufficient Depth is classed as the following:

Time RESA Depth
00:00

2.4m

07:00

2.6m

19:00

2.4m

Pump 2 On Conditions

Pump 1 Off Conditions

If the level in RESB is above the time varying level below then Pump 1 can be switched off.

Time RESB Depth
00:00

3.5m

16:00

3.4m

19:00

3.5m

Pump 1 Off Conditions

Pump 2 Off Conditions

If the level in RESB is above the time varying level below then Pump 2 can be switched off.

Time RESB Depth
00:00

3.4m

16:00

3.1m

19:00

3.4m

Pump 2 Off Conditions

Pump 1 and 2 Override Off Control

If the level in RESA is below the time varying level below then Pump 1 will be switched off regardless of the level in RESB.

Time RESA Depth
00:00

1.9m

07:00

2.1m

19:00

1.9m

If the level in RESA is below the time varying level below then Pump 2 will be switched off regardless of the level in RESB.

Time RESA Depth
00:00

2.2m

07:00

2.4m

19:00

2.2m

Pump 1 On Conditions

Pump 1 On Conditions

Reservoir Control Levels

There are four control levels for reservoir RESA:

RESA Control Levels

There are four control levels for reservoir RESB:

RESB Control Levels

InfoWorks WS Pro Control Profiles

All eight control profiles need to be added as standalone control profiles in InfoWorks WS Pro:

Control Profile

UPC Scripts

Rules must be worked out for each pump:

  • If the level in RESB is below x and the level in RESA is above y then PUMPz can be turned on
  • If the level in RESB is above a then PUMPz will turn off
  • If the level in RESA is below b then PUMPz will turn off

Define the action definitions and rules for each pump in the Pump Station property sheet (UPC Script page) for the desired pumps:

Script example

Was this information helpful?