Averaging Level Control for Urban Drainage System

In the work, averaging level control using model-based control and estimation algorithm on a buffer tank system is studied. Implementation of Model Predictive Control (MPC) and Proportional-Integral (PI) control together with Kalman filter for state and disturbance estimation show decent benefits and potentials. Results show that acceptable setpoint tracking of water level in the basin under varying inflow can be achieved. MPC precedes PI for smoother pump actions. Python as a popular programming language is adopted and showed potential for real-time control (RTC).


Introduction
Real-time control (RTC) of Urban Drainage System (UDS) is an important part for different goals in the drainage network.
Literature review (Lund et al., 2018) shows that MPC is an efficient tool for UDS control, and there have been a few projects provided promising results, even though the total number of operational implementations is limited. MPC has been used for controlling different components in UDS, including basin, pipe, junction, reservoir, etc. with linear and/or nonlinear models available internally or externally. More than 60 percent of 113 references addressed using MPC for UDS control from 1983 to 2018 in a few cities globally. Reported applications are mostly found in North America and central European countries. In particular, more active research projects can be found in Span, Canada and Denmark.
Kalman filter is an important data assimilation algorithm in weather forecast to combine numerical methods and observations (Sun et al., 2016).
We present results from a research project, which is about potential use of automatic control on an existing UDS in Norway. Figure 1 illustrates a 42 km long tunnel, which is a main component of the drainage system, transports total volume up to 110 million m 3 /year combined sewage overflow (CSO) to one of the largest Water Resource Recovery Facility (WRRF) in Norway named VEAS. An equalization magazine downstream the tunnel works as a buffer tank of the wastewater before it enters the VEAS plant, being processed and discharged into the Oslo Fjord.
Due to the process requirement at VEAS and flow control along the tunnel, the combined drainage must be controlled for different purposes:  Smoothed inflow to the plant.  Relatively short retaining time of water inside the tunnel.  The water flow has certain constraints/ limits, i.e., the tunnel should not be total empty, meanwhile, as less overflows into the Oslo Fjord as possible.  Dealing with precipitation according to weather data/ forecast. A laboratory buffer tank in Figure 2 is to be used to emulate the actual basin part in the end of the tunnel. Details of the system is to be presented in Section 2.1.
This work aims at: 1. Mathematical modelling of the buffer tank. 2. Averaging level control using model-based control. 3. Inflow estimation using Extended Kalman filter (EKF).

Materials and methods
The simulated buffer tank as the testing bench and algorithms for control and estimation are introduced.

Buffer tank system
Main components of the laboratory buffer tank in Figure  2 consist of:  Left-hand side: A buffer tank equipped with an ultrasonic level transmitter (Level sensor); a pump (Pump 1) followed by a flowmeter measuring the flowrate of outflow from the buffer tank;  Right-hand side: A tank as a reservoir of outflow; a pump (Pump 2) to transport simulated varying "precipitation and wastewater" into the buffer tank.  Bottom center: I/O devices for communication between computer and the buffer tank system. Power supply unit for powering the electronic devices and electrical components. Table 1 lists the main components used in the system.  Local PI controllers: The flow from each pump is controlled based on readings of inline flow meters.

Mathematical modelling
The mathematical model of the system can be derived from mass balance of the water tank, given in continuous state-space form by (1): where,  ℎ [cm], the process state variable, the water level inside the tank.  [cm], the process output, the water level measurement.  [cm 3 /s], the control variable of the pump to manipulate the outflow from the buffer tank.  [cm 2 ], the tank cross-sectional area. In this system, a cylindrical tank is installed vertically so = 2 /4 is a constant, with tank inner diameter = 8.5 cm. In reality, the basin cross-sectional area varies with the water level, i.e., = (ℎ), where is a nonlinear function.  [cm 3 /s], inflow into the tank, which in the real VEAS case is unknown.  and are process noise and measurement noise with covariances = [ 2 ] and = [ 2 ] , respectively.

Control and estimation algorithms
MPC and PI as the control algorithms and EKF as the estimation method are introduced in this section.

Averaging level control
The overall purpose of averaging level control is to smooth the inflow in real-time through the buffer tank so that the variation of outflow from the buffer tank is smoothed (Haugen, 2010). Block diagram of such principle is presented in Figure 3.
The level of water inside the buffer tank is to be maintained close to a user-specified value by manipulating Pump 1 based on the level measurement from Level sensor. Situations like full tank and empty tank are restricted.
The pump control signals are limited to be: (2) where, and are the allowed minimum and maximum flow, respectively. In addition, to have smooth pump actions as the process required, constraint for Δ is introduced as: where, =10 cm 3 /s 2 is the user-specified limit, =0.2 s is the time step, the pump action is limited to be: ∈ [ −1 − 2 cm 3 /s , −1 + 2 cm 3 /s]

State and inflow estimation
The water level measurement is the only measurement for feedback control in the buffer tank. As mentioned, the inflow in (1) is a random variable representing the unknown precipitation and wastewater flowing into the buffer tank/ basin. Extended Kalman filter (EKF) is used for the inflow estimation in this work (Simon, 2006). To estimate the inflow, the state vector is augmented with inflow disturbance as is given by (4): where, ̇ [cm 3 /(s 2 )] is the first order derivative of the inflow, ̇= . The only measurement = ℎ is used to update the EKF in this work. Tuning of the EKF with covariance matrices is done by using: = , = 10 ×

Discretized state-space model
Based on the model (1), discretization of (4) gives the process model in discretized state-space form as in (5): Checking the rank of these matrices, giving: ( ) = 1, ℎ is controllable. ( ) = 2, the system is observable.

Output feedback MPC
The main idea of implementing MPC is to solve an open-loop optimal control problem over a moving horizon with finite length at each sampling time, starting at the current state. At the next time step, the computation is repeated starting from the new state and over a shifted horizon.
In an output feedback MPC, feedback of states is obtained through an estimator, i.e., EKF, to recursively estimate the states based on the measurement at every time step. The estimated states ̂= [ ĥ , ] is sent to MPC, instead of the states measured directly from the process . Figure 4 shows the block diagram of the principle of output feedback MPC.
For a Single-Input-Single-Output (SISO) MPC, the cost function in this case is defined by (6): where,  is the control signal to be optimized. Control error Δ = − −1 .  Constraints on and Δ are as in (2) where,  , controller output at time step with constraints introduced as in (2) and (3).  0 , manual control input.


= − , where and are the measurement and the reference at , respectively.  , , proportional gain and integral time of the PI controller. Skogestad's method as a model-based tuning method (Haugen, 2010) is used for tuning of these parameters.

Results and discussion
In this section, results of averaging level control are presented and discussed.

Averaging level control using PI
Experiment results are shown in Figure 5 with controller settings: ℎ = -5.67 (direct actions), ℎ =20 s. In general, the water level ℎ showed smooth changes in the meantime of tracking the setpoint ℎ , as can be seen from the top plot. The real-time measurement ℎ and the estimated signal ĥ match each other well, except for slight deviation in the beginning phase (< 10 s) due to a guessed initial value used for the EKF estimator.
PI controller calcucates , based on the estimated inflow ̂, for updating the pump actions at each time step. The estimated inflow ̂, started to reflect the real data after about 10 s as the middle plot shows. The large deviation of the estimated inflow from the real value in the beginning phase caused delayed controller actions, in addition to the / constraint for smooth pump actions shown in the bottom plot. Even though the estimation of inflow is noisy, the Pump 1 control actions = slowly resembled the varying inflow, including conditions of two stepwise changes at =0 s and =50 s. The Pump 1 control actions fluctuated at low flow rate, i.e., from =50 s to =100 s when the inflow is ~20 cm 3 /s shown in the middle plot, caused by the nonlinear pump characteristics.

Averaging level control using MPC
Results of MPC control algorithm are presented in Figure 6, with the following controller settings:  Optimization method: SLSQP (SciPy.org, 2021a), tolerance = 0.001.  Constraint/ boundaries: as in (2)   Weighting matrices: = 5, = 1.  : Estimated inflow at each time step , is used for prediction and cost function calculation, meaning that the inflow is a "fixed" value for the entire prediction horizon . Comparing the results from MPC to from PI control, one can firstly notice that the MPC outperforms PI with "smoother" (middle plot) and much less varied outflow Δ /Δ (bottom plot). This is because of the moving horizon and optimization algorithm used for optimal control in the prediction horizon, given the same constraints of on and / as for PI controller. It is worth noting that, with smoother outflow, more overall setpoint deviation of the water level should have been observed since the volume would have varied more to buffer against inflow. However, from the results, the differences are noticeable but not obvious, comparing the two "level" plots in Figure 5 and Figure 6. Estimation of both water level ĥ and the inflow ̂ are about the same overall performance as in PI controlled case. However, the less noisy control actions led to less noisy ̂.
Both PI controller and MPC can be tuned for less tracking error suffering more abrupt control action changes or more varied water level with less fluctuated pump actions.

"Time" issue in real-time control
One problem of using Python for real-time control (RTC) is how to ensure the time step during the computation, since Python is not designed for real-time purpose and the computation speed is dependent on many factors. Figure 7 presents the differences between computational load for the averaging level control using MPC and PI, given computer configurations in Table 3

Hardware
Processor: Intel(R) Core(TM) i7-8750H @ 2.20GHz Installed RAM: 32.0 GB Operating system Windows 10 Enterprise 64-bit Version 20H2 OS build 19042.985 The computational load is relatively less heavy using PI control than using MPC. In the experiments based on PI control, more than 70% cycles have about 9~10 ms computation time (not the "average" computation time) and maximum cycle time is ~31 ms. For MPC case, more than 50% cycles have 29~31 ms running time and maximum is ~70 ms, both are much higher than using PI control. As can be seen from the histogram, the cycle time distribution for MPC is much "wider", meaning the cycle time varies a lot from loop to loop. This is because MPC is an optimization-based algorithm. The computation depends highly on the problem construction, optimization method, and solver setup, etc. A few other factors can also influence the cycle time including file I/O, hardware communication and setup, computer configurations, etc.
In this work, Python built-in "time" module is used with the following method to handle the issue:

Conclusions and future development
The work presents a demonstration of using modelbased control algorithms for averaging level control of urban drainage system, to be specific, a wastewater equalization magazine using a small-scale buffer tank. The conclusions are:  Averaging level control using model-based control algorithms is successful, with unknown inflow.  MPC is based on the system model and optimization solver. PI controller does not require the system model to compute the control action. With proper settings, MPC can achieve smoother control actions than PI control.  The process can benefit from both PI and MPC algorithms for averaging level control, given constrained control signal with upper/ lower limits  , ] ) and allowed maximum change of flow rate (|Δ Δ ⁄ |).
 For the buffer tank system, the inflow is observable so that it can be estimated as an augmented state with water level as the only measurement. EKF is easy to implement for the estimation but some effort is required for tuning.  Python is a promising option for programming for real-time control. As one can see, a number of open libraries are available for the purpose.
To improve the MPC performance in the future, instead of using a "fixed" for the entire prediction horizon, a "forecast horizon" can be used to obtain a sequence of "future inflow" for the MPC optimization, i.e., [ , , , +1 , … , , + ] . Choosing of is based on the information available and computation resource. ≥ is suggested so that the inflow information is available throughout the prediction horizon for the optimizer. Different algorithms for estimating/ forecasting inflow can be tested, i.e., Particle Filter (PF), Ensemble Kalman filter (EnKF), Moving Horizon Estimation (MHE), neural network, etc. Tradeoff between extra computational load and performance should be taken into consideration.