Real-Time Control of Urban Water Cycle under Cyber-Physical Systems Framework

: The urban water cycle (UWC), which is composed of the water supply system (WSS) and urban drainage system (UDS), is a critical infrastructure required for the functioning of urban society. Considering the growing pollution and subsequent water scarcity caused by increasing urbanization and climate change, e ﬃ cient UWC management is required to maintain resource sustainability and environmental protection. Cyber-physical systems (CPSs) provide a technological suite for the e ﬃ cient management of critical systems. To exploit advantages of CPS for UWC, this paper proposes a CPS-based management framework enabling supervision, subsystem interoperability, and integrated optimization of UWC: (1) Firstly, clear deﬁnitions are provided to demonstrate that UWC systems can be considered as CPSs. (2) A multi-layer CPS-based supervision framework is presented afterwards, conceptually dividing the physical UWC and its digital counterpart into Supervision&Control, Scheduling, Digital Twin, and Water Users and Environment four layers. (3) The information ﬂows that interact with each layer, as well as a key aspect of CSP operation, namely the interoperability among subsystems in the context of UWC, are also addressed. (4) To demonstrate advantages of supervision and interoperability of subsystems under the CPS framework, an integrated optimizer based on model predictive control (MPC) is applied and compared against the individual control of each system. A real case study of the WSS and UDS in Barcelona UWC is applied in order to validate the proposed approaches through virtual reality simulations based on MATLAB / SIMULIN and EPA-SWMM.


Introduction
Water is a vital resource. The regular and reliable supply of water and treatment services in a city are critical for many urban activities [1]. The urban water cycle (UWC) infrastructure, including the water supply system (WSS) and the urban drainage system (UDS), maintain proper water services in a city. However, with increasing urbanization and climate change, water resources and the associated environment are increasingly threatened by water scarcity and pollution problems. To confront this challenge, efficient and reliable management of systems in the UWC is required.
The WSS and UDS are usually operated separately by different water authorities under their respective control objectives [2][3][4][5][6][7]. Furthermore, these systems are composed of numerous functional subsystems. As presented in Figure 1, in WSS, the Drinking Water Treatment Plant (DWTP) extracts water from the Natural Water Bodies. After that, the drinkable water is delivered to the Water Users through the Drinking Water Delivery and Distribution system (DWDDS). In UDS, especially in the combined UDS (which is the main UDS infrastructure generates pollutions through combined sewer overflows in storm weather), wastewater and storm water are collected through the Wastewater and The release of CSO may cause significant pollutions and effects for the aquatic ecosystems and human health because of the mix of untreated domestic, commercial, industrial wastewater with storm water runoff [11]. Minimize the pollutions of CSO is the goal for storm water management in many cities with combined sewers. Traditionally, passive approaches were used such as constructing separated sewers, building storage retention tanks with problems in high cost and land availability [12]. Besides, green infrastructure and low impact development (LID) are other options which work well for some case studies [13] but with difficulties for designing standards applicable worldwide.
Cyber-physical systems (CPSs) is an emerging framework with the ability to control the physical system using digital representations due to the development of information and communication technologies (ICT) and digital methodologies. Up to now, there are plenty of research contributions about CPS, e.g., enable smart manufacturing or industrial application by CPS through integrating the virtual computation with physical processes [14][15][16][17]. However, there is still lack of a comprehensive contribution with clear explanation and system-wide application details of applying CPS in the water field, which can exploit potential to generate revolutionary change to the UWC. Moreover, there is another concept, the Internet of Things (IoT) which also refers to trends in integrating digital capabilities with physical devices and systems. However, IoT focuses more on simple trackable and/or data objects with limited consideration of system-level control [18]. Under this context, this paper is motivated to propose a CPS-based framework in order to explore innovated technologies to the management of UWC [15].
The WSS and UDS can be considered as CPSs because they contain different components which can be described by a digital representation and interact with the physical world using the embedded sensors, automatic meter reading (AMR) and supervisory control and data acquisition (SCADA) systems. Furthermore, the digital representations can be used to monitor networks and optimize control strategies from a control room, allowing the physical infrastructures to be monitored and controlled through processors and actuators to achieve the desired performance [10,19]. The digital representation, also named digital twin [20], of UWC can be developed through high-fidelity simulation platforms, such as SIMULINK/MATLAB, storm water management model (SWMM) [21], MIKE Urban [22], and EPANET [23] etc.
As in all CPS management, the monitoring and control processes for these digital representations are meant to work in real time, with regular interactions between the virtual and physical spaces of the Water 2020, 12,406 3 of 17 systems [10]. Real-time control (RTC) allows the operation of a system to be optimized, including the monitoring of the current system state and the determination of control actions, which are then sent to actuators [24]. RTC is also an efficient approach for storm water control devices [25]. The important nature of RTC means that the management structure of CPS should be able to account for the regular interactions among subsystems and their operational limits in an efficient computation time. This is one of the challenges of implementing CPS for UWC.
Moreover, CPS for UWC is typically designed as a complex network of interacting elements (subsystems). As mentioned above, the subsystems of the UWC are usually managed and operated by different utilities. Additionally, subsystems of CPS may have different individual objectives, which may influence the global performance. The interoperability among different subsystems and the integrated optimization for the supervision of the whole CPS is another challenge [17].
To address these challenges of operating UWC under the CPS context, the main contributions of this work are: • Definitions illustrating UWC systems as a CPS; • Development of a multilayer CPS-based supervision framework that conceptually divides the physical UWC and its digital counterpart into four layers (Supervision&Control Layer, Scheduling Layer, Digital Twin Layer, Water User, and Environment Layer) and definition of the information flows between layers; • Examination of a key aspect of CPS operation, namely the interoperability among subsystems, in the context of systems in the UWC; • Demonstration of the advantages of supervision control and interoperability among subsystems of the water cycle with case studies using an integrated optimization approach based on model predictive control (MPC), which improves the reliability and sustainability of the overall control compared with the individual control of both systems.
The remainder of this paper is organized as follows. Section 2 explains the proposed methodologies, which include a multilayer CPS-based supervision management framework, subsystems interoperability and integrated MPC-based optimization algorithm. Section 3 presents the results from case study of the Barcelona UWC to validate the proposed approaches. Finally, Section 4 summarizes the conclusions and presents future research paths.

Multilayer CPS-Based Supervision Management Framework
This section describes a multilayer CPS-based supervision management framework for the digital counterparts (the cyber world) of the physical world. Each layer in the cyber world is corresponding to specific systems in the physical world (as shown in Figure 2).
(1) Supervision&Control Layer corresponds to the computing and control system in the physical world as presented in Figure 1. In this layer, conceptual models of UWC are used by the advanced control algorithms that provide global strategy by solving an optimal control problem in a timely manner. The control goals are provided by the water users and natural environment (defined in the 4th layer). (2) Scheduling Layer is in charge of converting the strategies computed by the supervisory control into set-points for specific actuators, through the PLC's (Programable Logic Controller-PLC). Similarly, sensor data are sent to the Supervision&Control Layer through this layer. Practically, PLCs are flexible and sophisticated enough to run their own control logic, without constantly receiving an input from SCADA. However, this paper discusses advanced global control used in the Supervision&Control Layer, which generates optimal control actions considering all the subsystems in the CPS.
(3) The Digital Twin Layer is a digital representation of the physical plant, which uses high fidelity models such as SIMULINK, SWMM, EPANET, and MIKE Urban evaluating the control performance with the desired accuracy. The digital twin may be used to obtain hydraulic or quality variable estimations at locations where no sensors are available. In this sense, they provide extra soft-sensor data, as additional measurements for the upper layers. (4) Water Users, and Environment Layer. Water users and the environments receive the impact of the control actions in the cyber physical system. Similarly, they define boundary constraints for developing the digital twin and the control goals for the upper control layer. Besides, the impact indicator is generated by the Digital Twin Layer in the format of reliable water service for the water users and environmental influence. (4) Water Users, and Environment Layer. Water users and the environments receive the impact of the control actions in the cyber physical system. Similarly, they define boundary constraints for developing the digital twin and the control goals for the upper control layer. Besides, the impact indicator is generated by the Digital Twin Layer in the format of reliable water service for the water users and environmental influence.

Interoperability
Interoperability is a key aspect under CSP operation framework. In the context of UWC, several subsystems are working independently, usually with adequate results for each specific exploitation [8,26]. However, addressing the interoperability among subsystems is vital for improving the efficiency of the supervision global management performance.
Interoperability refers to the use of data from one subsystem in processing the supervision control actions of another subsystem. The exchanged information may usually consider outputs of one system as boundary conditions for the next system. CPS should guarantee that the information sets are communicated fluently and the corresponding boundary constraints are updated in a real time manner during the management process for all the subsystems.
Consider the interoperability between WSCS and WWTP as an example (Figure 3). At each time step (e.g., 5 min), the WWTP provides the available treatment capacity (information set) to WSCS. This information allows establishing the boundary constraints for the corresponding RTC optimization problem. Then, the WSCS computes the optimal pump flow (information set) and sends this to the WWTP for the next control interval.

Integrated MPC-Based Optimization Algorithm
To demonstrate the advantages of supervision control and interoperability of subsystems, an integrated optimization algorithm is required to compute the optimal operation strategies for the CPS

Interoperability
Interoperability is a key aspect under CSP operation framework. In the context of UWC, several subsystems are working independently, usually with adequate results for each specific exploitation [8,26]. However, addressing the interoperability among subsystems is vital for improving the efficiency of the supervision global management performance.
Interoperability refers to the use of data from one subsystem in processing the supervision control actions of another subsystem. The exchanged information may usually consider outputs of one system as boundary conditions for the next system. CPS should guarantee that the information sets are communicated fluently and the corresponding boundary constraints are updated in a real time manner during the management process for all the subsystems.
Consider the interoperability between WSCS and WWTP as an example (Figure 3). At each time step (e.g., 5 min), the WWTP provides the available treatment capacity (information set) to WSCS. This information allows establishing the boundary constraints for the corresponding RTC optimization problem. Then, the WSCS computes the optimal pump flow (information set) and sends this to the WWTP for the next control interval. (4) Water Users, and Environment Layer. Water users and the environments receive the impact of the control actions in the cyber physical system. Similarly, they define boundary constraints for developing the digital twin and the control goals for the upper control layer. Besides, the impact indicator is generated by the Digital Twin Layer in the format of reliable water service for the water users and environmental influence.

Interoperability
Interoperability is a key aspect under CSP operation framework. In the context of UWC, several subsystems are working independently, usually with adequate results for each specific exploitation [8,26]. However, addressing the interoperability among subsystems is vital for improving the efficiency of the supervision global management performance.
Interoperability refers to the use of data from one subsystem in processing the supervision control actions of another subsystem. The exchanged information may usually consider outputs of one system as boundary conditions for the next system. CPS should guarantee that the information sets are communicated fluently and the corresponding boundary constraints are updated in a real time manner during the management process for all the subsystems.
Consider the interoperability between WSCS and WWTP as an example (Figure 3). At each time step (e.g., 5 min), the WWTP provides the available treatment capacity (information set) to WSCS. This information allows establishing the boundary constraints for the corresponding RTC optimization problem. Then, the WSCS computes the optimal pump flow (information set) and sends this to the WWTP for the next control interval.

Integrated MPC-Based Optimization Algorithm
To demonstrate the advantages of supervision control and interoperability of subsystems, an integrated optimization algorithm is required to compute the optimal operation strategies for the CPS that maximizes the reliability and sustainability of the overall UWC.

Integrated MPC-Based Optimization Algorithm
To demonstrate the advantages of supervision control and interoperability of subsystems, an integrated optimization algorithm is required to compute the optimal operation strategies for the CPS that maximizes the reliability and sustainability of the overall UWC.
MPC is selected as the optimization approach. Already used by many industry sectors, including the water industry [9,[26][27][28][29][30][31][32][33][34][35][36][37][38], MPC is an efficient control technique for achieving global operational goals in dynamic systems by computing control actions predictively based on a model of the system dynamics, taking into account physical and operational constraints, disturbance predictions, and real-time observations of the system state [26,28,39]. Generally, the MPC method includes prediction optimization based on an internal model and a control formulation of the systems to be controlled. The internal model is usually a simplified discrete model to describe the internal dynamics of the controlled system. The control formulation defines the desired behavior of the controlled system, the optimal behavior, and the length of each prediction.
There have been applications of MPC to UDS, and significant reductions in CSO have been obtained [26,[33][34][35]38,39]. Additionally, MPC-based optimization algorithms have been successfully implemented in WSS subsystems [31,32,36,37] to optimize the water usage or cost produced by electricity consumption. While most MPC applications in UWC management refer to a specific system and its individual operational goals, here we demonstrate the use of MPC in the coordinated (or integrated) management of two (or more) subsystems of the larger UWC system. This integration is related with the concept of supervision control and interoperability in CPS.
The designing of internal models and control formulations of the MPC method are presented in detail in the Sections 2.3.1 and 2.3.2 for the WSS and UDS, respectively.

Internal Models
In the WSS, a complete system is generally composed of water tanks to store drinking water from natural sources; a pressurized pipe network to transfer water using valves and/or pumps; and a number of consumer demands d ∈ R n d . Assuming the stored volumes (m 3 ) in water tanks Vol ∈ R n v are provided by the difference of water inflows Flow in ∈ R n f i (m 3 /s), outflows Flow out ∈ R n f o (m 3 /s) and consumer demands d (m 3 /s), the conceptual discrete-time model for the water volumes stored in the tanks is presented as: where ∆t ∈ N + is the sampling time and t ∈ N + is the discrete-time instant. Besides, n d , n v , n f i , n f o are the numbers of consumer demands, tanks, water inflows and outflows, respectively. Constraints are required for the valve/pump actuators so as to fulfill the lower and upper physical limits: Mass-balance conservation applies to the system nodes where water flows are split and merged: In UDS, the detention tank has a similar hydraulic model as Equation (1). In addition, sewers in a catchment of the UDS have been simplified as virtual tanks that have a storage capacity and a similar hydraulic model as (1). When considering the quality model, detention tanks are important elements for the integrated CPS control, as they store polluted water before it is released into the WWTP with the aim of reducing the pollutant loads when CSO cannot be avoided. To build a quality model for UDS, Total Suspended Solid (TSS) index can be selected as a representative variable because of its correlation with water turbidity, which can be measured online. Simplified TSS models for the sewers Water 2020, 12, 406 6 of 17 and junction nodes are created following the procedure presented in [9,40], and the conceptual model for the total mass in the detention tank can be written as: where Mass ∈ R n m (mg) represents the total mass in the detention tank; Tss in ∈ R n ti and Tss out ∈ R n to are the TSS inputs and outputs (mg/L) for the detention tank; e ∈ R is the coefficient parameter which needs to be calibrated in the range of [-1, 1] (represents sedimentation when e is positive and represents erosion effects when e is a negative number). Besides, n m , n ti , n to are the numbers of detention tanks, TSS inflows and outflows, respectively. Calibration of the parameter e is executed using measurements generated through virtual reality simulation in SWMM. Details about the calibration processes can be referred from [9].

Control Formulation
There are two MPC controllers being developed in this paper, one for WSS and another for UDS. The two MPC controllers are computed and optimized independently. Considering the MPC design, the development of MPC controller for the WSS is based on solving the following optimization problem [9,27,28,39]: where the state variable x ∈ R n v represents tank volumes; the control variable u ∈ R n uw manipulates flows through the available actuators (n uw equals with 0.5 * n f i + 0.5 * n f o ); and the disturbance variable w ∈ R n w related to consumer demand for water in the WSS (n w equals with n d ), J WSS represents the objective function for the MPC method of WSS.
In the WSS, the integrated control performances normally involve: (i) Minimizing energy consumption; (ii) maintain ecological requirement for the supply rivers; (iii) balancing water usage to sustain water resources; (iv) emergency handling to maintain a certain amount of water in the tank; and (v) smoothness management for water gates to protect assets [27,41]: J WSS (x, u, w) = a energy J energy + a ecol J ecol + a balance J balance + a sa f ety J sa f ety + a smooth J smooth (6) The development of MPC controller for the UDS is based on solving the following optimization problem [9,27,28,39]: where the state variable x ∈ R n x represents both tank volumes and TSS mass in UDS (n x equals with 2 * n m ); u ∈ R n u is the control variable manipulated flow through the available actuators for UDS (n u equals with 0.5 * n ti + 0.5 * n to ); the disturbance variable w is not considered for the UDS, J UDS represents the objective function for the MPC method of UDS.
Furthermore, in the UDS, five performance indexes are normally considered for the integrated MPC approach, which are: (i) CSO minimization; (ii) suspended solids discharges minimization; (iii) WWTP usage maximization; (iv) safety level maintenance for the detention tank; and (v) control variables smoothness: J UDS (x, u, w) = a cso J cso + a mass J mass + a wwtp J wwtp + a sa f e J sa f e + a smoot J smoot (8)  In Equations (6) and (8), a ∈ R + are the control weights that can be tuned by the system manager according to operational priorities; J WSS and J UDS are considered independently by different MPC controllers. It should be noted that a energy , a ecol , a balance , a sa f ety , a smooth , a cso , a mass , a wwtp , a sa f e , and a smoot are weights which decide priorities of the items appearing in the objective functions. In reality, the weights are established by the water authorities. In this paper, the following weights in Table 1 are used, which show higher importance for energy and water usage balance in WSS and CSO minimization in the UDS: For the MPC applications in UWC, different sampling times ∆t are defined depending on the system dynamics. Within this interval, the MPC receives required state estimation from the measurements obtained by the sensors, generating the optimal control actions, and afterwards sending them as set-points to the controlled actuators. In the WSS, the ∆t is normally set to 1 h with a predict/control horizon of 24-48 h; while the UDS is usually operated with a 30-60 min horizon, and control intervals of 5-10 min.
Based on the internal model and control formulation, the MPC approach is defined. In the case of MPC with linear prediction models, constraints, and quadratic performance indexes, the MPC approach can be translated into a quadratic programming (QP) problem, which can be solved using MATLAB and the QP solver of TOMLAB [42], a free toolbox for academic usage. In term of MPC with nonlinearity at the prediction model, constraints or control formulations, GAMS optimization environment [43] with CPLEX solver [44] appears as a good option due to the combination benefits in term of modelling difficulty, economic cost, and computational efficiency.

Barcelona Pilot WSS
The Barcelona WSS is located within the Catalonia internal basins, which supplies drinking water to approximately 5.5 million people. The main water resources are extracted from two rivers, Llobregat and Ter, which are limited by the reduced amount of rain in the Mediterranean area. Since 1980, there have been increasing water scarcity problems in this area. Figure 4 shows one part of the aggregated Barcelona WSS network, where the Llobregat and Ter are the main water sources and the drinking water is transported through the pumping network. Water tanks are shown in light blue (T1, T2, . . . T7), pumps are in yellow, and the aggregated demands, inside which are also district metered areas (DMAs), are shown in dark blue (D0, D1, . . . D7).
According to the definitions of CPS for UWC, the Barcelona WSS can be considered as two subsystems. The two rivers (simplified as two water sources in Figure 4) represent the DWTP subsystem, whose objectives are to maintain ecological requirements for the rivers and the sustainability of water resources (J balance ) through balancing water extraction from the two rivers. The transportation network inside the city (Figure 4) can be considered as the DWDDS subsystem, whose management objectives are to satisfy the water consumers using minimal energy cost (J energy ) and safe storage inside the tank (J sa f ety ).
Several water production plants located upstream along the Ter river make the treatment process more complex and economically demanding. Thus, water from the Llobregat river can be obtained by the water distribution managers at a lower cost than that from the Ter. Considering the control of the DWDDS subsystem, most of the required water should come from the cheaper source to satisfy the minimal cost objective. However, taking into account the river ecological levels required by the DWTP subsystem, different management strategies are required. According to the CPS-based management approach, the DWDDS and the DWTP subsystems should interoperate by means of supervision control through integrated MPC approach, which can achieve optimal performance considering objectives for all of the subsystems. To validate the proposed strategy, the following two scenarios are considered: Scenario 1: Manage the Barcelona WSS using separate control algorithms; Scenario 2: Manage the Barcelona WSS under CPS-based structure, considering supervision control and interoperability of subsystems by integrated MPC optimization algorithm.  The integrated MPC optimization was implemented using MATLAB and the QP solver of TOMLAB. A digital representation of the Barcelona WSS has been developed using MATLAB/SIMULINK ( Figure 5) in order to simulate the physical network and evaluate the MPC controller in virtual reality. The optimization and simulation are working interactively by communicating mutual information automatically, which is achieved by the two S-functions in SIMULINK S-controller and S-simulator, where they produce, transfer and receive useful information in a closed loop [31]. The sampling time ∆ for this MPC is 1 h with a prediction/control horizon of 24 h and simulation period of 6 days. The integrated MPC optimization was implemented using MATLAB and the QP solver of TOMLAB. A digital representation of the Barcelona WSS has been developed using MATLAB/SIMULINK ( Figure 5) in order to simulate the physical network and evaluate the MPC controller in virtual reality. The optimization and simulation are working interactively by communicating mutual information automatically, which is achieved by the two S-functions in SIMULINK S-controller and S-simulator, where they produce, transfer and receive useful information in a closed loop [31]. The sampling time ∆t for this MPC is 1 h with a prediction/control horizon of 24 h and simulation period of 6 days.  Figure 6 illustrates the water resources required by the DWDDS subsystem from both the Ter and Llobregat rivers in Scenario 1. Considering the cheaper price, more than 80% of the water comes from the Llobregat, which results in ecological problems for the DWTP subsystem, as illustrated in Figure 7. The red line in Figure 7 represents the minimal river flow (0.95 m 3 /s) should be maintained due to ecological requirement, the blue line is the real river flow at Llobregat. Obviously, ecological problem happens frequently at this scenario.   Figure 6 illustrates the water resources required by the DWDDS subsystem from both the Ter and Llobregat rivers in Scenario 1. Considering the cheaper price, more than 80% of the water comes from the Llobregat, which results in ecological problems for the DWTP subsystem, as illustrated in Figure 7. The red line in Figure 7 represents the minimal river flow (0.95 m 3 /s) should be maintained due to ecological requirement, the blue line is the real river flow at Llobregat. Obviously, ecological problem happens frequently at this scenario.  Figure 6 illustrates the water resources required by the DWDDS subsystem from both the Ter and Llobregat rivers in Scenario 1. Considering the cheaper price, more than 80% of the water comes from the Llobregat, which results in ecological problems for the DWTP subsystem, as illustrated in Figure 7. The red line in Figure 7 represents the minimal river flow (0.95 m 3 /s) should be maintained due to ecological requirement, the blue line is the real river flow at Llobregat. Obviously, ecological problem happens frequently at this scenario.                More detailed results for Scenario 2 are presented in Table 2, where the Source, Demand, Balance, and Ecological represent water supply capacities of the two rivers, water consumption associated to each river, available water sources in the rivers after meeting water demand, and the ecological requirement from the two rivers, respectively. Besides, the Supplying means the water supply abilities in days of the Barcelona WSS before meeting deficit problem at the hypothesis with no rain and no water flow in from outside. From Table 2, a conclusion can be obtained, which is the supervision control and interoperability of subsystems in the CPS-based management structure can prevent the water scarcity problem and ensures that the rivers can supply water for more than 107 days before meeting any ecological problems. This improves the reliability of the ecological management of the rivers and the sustainable usage of the water resources.  Figure 10 compares the flow of one pump (Bom_Masquefa, connected with tank T1, as marked by a rectangular frame in Figure 4) and its electricity cost. The blue line at this figure represents water flow pumped by Bom_Masquefa. The red line is the electricity price at different hours. The efficiency cost is for the qualitative comparison only due to the requirement from the electricity company. Considering the confidential requirement form the water companies, the numbers of the price are modified without unit. From this plot, we can see that MPC forces the pump to work more when the electricity is cheaper and less when the electricity is more expensive. Using this optimal strategy, the objectives in the DWDDS subsystem have also been satisfied, with energy savings of up to 5% (4.1 GWh/year) and energy cost savings of up to 20% (0.4 M€/year).

Ecological Objective
More detailed results for Scenario 2 are presented in Table 2, where the Source, Demand, Balance, and Ecological represent water supply capacities of the two rivers, water consumption associated to each river, available water sources in the rivers after meeting water demand, and the ecological requirement from the two rivers, respectively. Besides, the Supplying means the water supply abilities in days of the Barcelona WSS before meeting deficit problem at the hypothesis with no rain and no water flow in from outside. From Table 2, a conclusion can be obtained, which is the supervision control and interoperability of subsystems in the CPS-based management structure can prevent the water scarcity problem and ensures that the rivers can supply water for more than 107 days before meeting any ecological problems. This improves the reliability of the ecological management of the rivers and the sustainable usage of the water resources.  Figure 10 compares the flow of one pump (Bom_Masquefa, connected with tank T1, as marked by a rectangular frame in Figure 4) and its electricity cost. The blue line at this figure represents water flow pumped by Bom_Masquefa. The red line is the electricity price at different hours. The efficiency cost is for the qualitative comparison only due to the requirement from the electricity company. Considering the confidential requirement form the water companies, the numbers of the price are modified without unit. From this plot, we can see that MPC forces the pump to work more when the electricity is cheaper and less when the electricity is more expensive. Using this optimal strategy, the objectives in the DWDDS subsystem have also been satisfied, with energy savings of up to 5% (4.1 GWh/year) and energy cost savings of up to 20% (0.4 M€/year).

Badalona Pilot UDS
Badalona is located in Eastern Catalonia (Spain) and is part of the Barcelona metropolitan area. A population of around 215,000 inhabitants lives within an area of 21.2 km². Figure 11 presents a

Badalona Pilot UDS
Badalona is located in Eastern Catalonia (Spain) and is part of the Barcelona metropolitan area. A population of around 215,000 inhabitants lives within an area of 21.2 km 2 . Figure 11 presents a simplified model of the Badalona UDS, including one detention tank T1 served by two upstream catchments VT1 and VT3, which send water to T1 through gates G1 and G2. Wastewater in T1 is extracted by pump P and sent to the WWTP for treatment. However, CSO can occur when the WWTP capacity is exceeded.  According to the definitions of CPS for UWC, in the Badalona UDS, the WSCS and WWTP are considered as two subsystems. Generally, the treatment capacity of a WWTP varies with time, depending on several factors related to the operational status of the physical and biological processes in the plant. However, when the systems are operated separately, the WSCS subsystem usually considers the WWTP capacity to be constant, equal to the nominal plant capacity. The timely notification of the real plant capacity and its predicted values for a control horizon, as constraints for the WSCS water detention and diversion optimization, can significantly improve the ability of UDS to prevent CSO. In order to validate the CSP-based framework, two different scenarios are defined: Scenario 1: Optimization of the WSCS subsystem separately with a nominal WWTP capacity. Scenario 2: Supervision control and Interoperability of the WSCS and WWTP subsystems through integrated MPC optimization considering real-time capacity of WWTP and global optimization objectives.
The Equation (4) in the MPC internal model for the UDS includes coefficient which needs to be calibrated in order to obtain the best performance of this model. The calibration processes can be referred from [9,33]. The being used in this case study is 0.25.
Considering nonlinearity of the MPC problem of UDS, the MPC optimization has been applied through MATLAB and the GAMS optimization environment [43] using internal models. A digital representation of the Badalona UDS has been developed through SWMM in order to simulate the physical network and evaluate the MPC controller. The communication between optimization and simulation is based on MATLAB script environment in text-editing routines to manipulate the simulator files automatically at each iteration [45,46]. The sampling time ∆ for this MPC is 5 min with a prediction/control horizon of 30 min and simulation period of 6 days. Figure 12 compares the mixed sewage water sent from the WSCS to the WWTP for treatment in the form of water flow. The yellow dashed line is the nominal constant WWTP capacity used for Scenario 1, which is 1.6 l/s; the green dash-dot line represents the real-time WWTP capacity for According to the definitions of CPS for UWC, in the Badalona UDS, the WSCS and WWTP are considered as two subsystems. Generally, the treatment capacity of a WWTP varies with time, depending on several factors related to the operational status of the physical and biological processes in the plant. However, when the systems are operated separately, the WSCS subsystem usually considers the WWTP capacity to be constant, equal to the nominal plant capacity. The timely notification of the real plant capacity and its predicted values for a control horizon, as constraints for the WSCS water detention and diversion optimization, can significantly improve the ability of UDS to prevent CSO. In order to validate the CSP-based framework, two different scenarios are defined: Scenario 1: Optimization of the WSCS subsystem separately with a nominal WWTP capacity. Scenario 2: Supervision control and Interoperability of the WSCS and WWTP subsystems through integrated MPC optimization considering real-time capacity of WWTP and global optimization objectives.
The Equation (4) in the MPC internal model for the UDS includes coefficient e which needs to be calibrated in order to obtain the best performance of this model. The calibration processes can be referred from [9,33]. The e being used in this case study is 0.25.
Considering nonlinearity of the MPC problem of UDS, the MPC optimization has been applied through MATLAB and the GAMS optimization environment [43] using internal models. A digital representation of the Badalona UDS has been developed through SWMM in order to simulate the physical network and evaluate the MPC controller. The communication between optimization and simulation is based on MATLAB script environment in text-editing routines to manipulate the simulator files automatically at each iteration [45,46]. The sampling time ∆t for this MPC is 5 min with a prediction/control horizon of 30 min and simulation period of 6 days. Figure 12 compares the mixed sewage water sent from the WSCS to the WWTP for treatment in the form of water flow. The yellow dashed line is the nominal constant WWTP capacity used for Scenario 1, which is 1.6 l/s; the green dash-dot line represents the real-time WWTP capacity for Scenario 2. The blue line is the flow being sent to the WWTP when separate control is applied, and the red crosses denote the flow sent from the WSCS to the WWTP by the CPS control approach.  In the integrated MPC optimization approach, the WWTP capacity prediction has been integrated and considered as a real-time parameter during the optimization process. The real treatment capacity of the WWTP is sent to the MPC-based controller, allowing the working schedule of the detention tank and other elements of the UDS to be adjusted to minimize CSO.
In the separate management algorithm, the WSCS continues to send the same amount of wastewater to the WWTP, regardless of whether the capacity has been enlarged or reduced. This does not allow the UDS to take full advantage of the WWTP capacity.
This comparison confirms that, after applying CPS-based management framework, the water flow being sent to the WWTP always considers the real treatment capacity, whereas the water flow produced by separate control may exceed the treatment capacity of the WWTP, resulting in CSO being released directly to the environment without treatment. Figure 13 compares the CSO produced by the two different control algorithms. The CSO produced by the CPS-based supervision paradigm has been reduced by more than 32% compared with the CSO produced by the separate control approach.

Discussion
This paper has analyzed the operation of UWC under the CPS framework and demonstrated some of the key technical features of CPS applied to UWC systems. Clear definitions of how UWC can be considered as a CPS have been provided. A multilayer CPS-based supervision management structure was proposed in which the physical UWC and its digital counterpart were conceptually divided into four layers (Supervision&Control Layer, Scheduling Layer, Digital Twin Layer, Water Users, and Environment Layer). The information flows have also been defined to interact with each In the integrated MPC optimization approach, the WWTP capacity prediction has been integrated and considered as a real-time parameter during the optimization process. The real treatment capacity of the WWTP is sent to the MPC-based controller, allowing the working schedule of the detention tank and other elements of the UDS to be adjusted to minimize CSO.
In the separate management algorithm, the WSCS continues to send the same amount of wastewater to the WWTP, regardless of whether the capacity has been enlarged or reduced. This does not allow the UDS to take full advantage of the WWTP capacity.
This comparison confirms that, after applying CPS-based management framework, the water flow being sent to the WWTP always considers the real treatment capacity, whereas the water flow produced by separate control may exceed the treatment capacity of the WWTP, resulting in CSO being released directly to the environment without treatment. Figure 13 compares the CSO produced by the two different control algorithms. The CSO produced by the CPS-based supervision paradigm has been reduced by more than 32% compared with the CSO produced by the separate control approach. Scenario 2. The blue line is the flow being sent to the WWTP when separate control is applied, and the red crosses denote the flow sent from the WSCS to the WWTP by the CPS control approach. In the integrated MPC optimization approach, the WWTP capacity prediction has been integrated and considered as a real-time parameter during the optimization process. The real treatment capacity of the WWTP is sent to the MPC-based controller, allowing the working schedule of the detention tank and other elements of the UDS to be adjusted to minimize CSO.
In the separate management algorithm, the WSCS continues to send the same amount of wastewater to the WWTP, regardless of whether the capacity has been enlarged or reduced. This does not allow the UDS to take full advantage of the WWTP capacity.
This comparison confirms that, after applying CPS-based management framework, the water flow being sent to the WWTP always considers the real treatment capacity, whereas the water flow produced by separate control may exceed the treatment capacity of the WWTP, resulting in CSO being released directly to the environment without treatment. Figure 13 compares the CSO produced by the two different control algorithms. The CSO produced by the CPS-based supervision paradigm has been reduced by more than 32% compared with the CSO produced by the separate control approach.

Discussion
This paper has analyzed the operation of UWC under the CPS framework and demonstrated some of the key technical features of CPS applied to UWC systems. Clear definitions of how UWC can be considered as a CPS have been provided. A multilayer CPS-based supervision management structure was proposed in which the physical UWC and its digital counterpart were conceptually divided into four layers (Supervision&Control Layer, Scheduling Layer, Digital Twin Layer, Water Users, and Environment Layer). The information flows have also been defined to interact with each

Discussion
This paper has analyzed the operation of UWC under the CPS framework and demonstrated some of the key technical features of CPS applied to UWC systems. Clear definitions of how UWC can be considered as a CPS have been provided. A multilayer CPS-based supervision management structure was proposed in which the physical UWC and its digital counterpart were conceptually divided into four layers (Supervision&Control Layer, Scheduling Layer, Digital Twin Layer, Water Users, and Environment Layer). The information flows have also been defined to interact with each layer of the supervision structure. Moreover, the supervision control and the interoperability of subsystems in the context of UWC systems has been addressed. An integrated MPC-based optimization algorithm was implemented to demonstrate the advantages of supervision control and interoperability of two (or more than two) subsystems in the water cycle. The application results confirm that, after operating the UWC using the CPS conception, globally optimal strategies were obtained, offering significant improvements in resource sustainability and environmental protection in the overall UWC.
In order to continue exploring the management improvements generated by digitalization and modelling frameworks based on the CPS concept to the UWC sector, more deep research in about detailed interconnected digital twins, interfacing with real systems to provide RTC features will be presented in future. Moreover, theoretical innovations about the MPC approach considering the stochastic characteristics of UWC will also be considered.