# Fault-Tolerant Model Predictive Control Applied to a Sewer Network
## 4 Case Study: Benchmark Simulation Model for Sewer Networks
### Model Predictive Control Algorithm  
The control objective is to ensure a flow rate in the treatment plant that maximizes its capacity without exceeding a maximum value, avoiding overflows in the tanks and in the station itself as much as possible, and minimizing operating costs. The algorithm used for predictive control uses a linear model of the process in the state space for prediction that includes disturbances and a cost function that calculates the outlet flow rates of the tanks for optimal operation. These flow rates calculated by the MPC are the setpoints for local output flow regulation loops for each tank, type P-I. The cost function or objective function of the MPC is a quadratic form that considers both the tracking errors in the states, as well as the increases in the control sequence with respect to the flow reference (penalizing the control efforts), if the prediction and control horizons coincide, and their value is \(N\)[5]:\[J(k,\mathbf{U})=\sum_{i=1}^{N-1}\left[\|\hat{\mathbf{x}}(k+i)-\mathbf{x}_{ref}(k) \|_{\mathbf{Q}(k)}^{2}+\|\mathbf{u}(k+i)-\mathbf{u}_{ref}(k)\|_{\mathbf{R}}^{2} \right]+\mathbf{x}^{T}(k+N)\mathbf{P}\mathbf{x}(k+N), \tag{13}\]  
where:  
\[\mathbf{x}_{ref}(k)=(x_{1 ref},x_{2 ref},\ldots,x_{1 ref}),\ \mathbf{u}_{ref}(k)=(u_{1 ref},u_{2 ref},\ldots,u_{5 ref}), \tag{14}\]  
The optimization problem that MPC solves is:  
\[\mathbf{U}^{*}(k)=\underset{\mathbf{U}(k)}{\operatorname{argmin}}J(k,\mathbf{ U}),\mathbf{U}^{*}(k)=\left[\mathbf{u}^{*}(k)\quad\mathbf{u}^{*}(k+1)\quad\ldots \quad\mathbf{u}^{*}(k+N-1)\right]^{T} \tag{15}\]  
subject to:  
\[\hat{\mathbf{x}}(k+i+1)=\mathbf{A}(k)\hat{\mathbf{x}}(k+i)+ \mathbf{B}_{p}(k)\mathbf{u}(k+i)+\mathbf{B}_{d}(k)\mathbf{d}(k+i),\ \mathbf{d}(k+i)=\mathbf{d}(k)\] \[\hat{\mathbf{x}}(k)=\mathbf{x}(k)\] \[0\leq\hat{x}_{j}(k+i),\ i=0,\ldots,N-1,\ j=1,\ldots,5 \tag{16}\] \[0\leq\hat{x}_{j}(k+i)\leq q_{\max j},\ i=0,\ldots,N-1,\ j=6, \ldots,9\] \[0\leq u_{j}(k+i)\leq u_{\max j},\ i=0,\ldots,N-1,\ j=1,\ldots,5,\]  
where \(q_{\max j}\) and \(u_{\max j}\) are the upper bounds for flow rate in the link elements and the tank outputs, respectively. The matrices \(\mathbf{Q}(k)\), \(\mathbf{P}\) and \(\mathbf{R}\) serve to penalize the tracking errors and the control efforts (inputs) and will be used as controller tuning parameters, as will the control horizon \(N\) (\(\mathbf{P}\) is a terminal penalty for MPC stability obtained by means of the Riccati equation [5]). A variable \(\mathbf{Q}(k)\) matrix has been considered so that if an overflow occurs in a tank, the corresponding weight is modified to avoid it as much as possible. The non-zero elements of \(\mathbf{Q}(k)\) that constitute MPC tuning parameters are \(q_{9}\) and:  
\[q_{i}= \begin{cases}f_{i}&x_{i}\leq h_{\max i}\\ f_{i}\Big{(}1+\alpha_{i}(x_{i}-h_{\max i})^{2}\Big{)}&x_{i}>h_{\max i}\end{cases} ,\ j=1,2,\ldots,5, \tag{17}\]  
Parameters \(f_{i}\) y \(\alpha_{i}\) are used to tune the MPC algorithm. To achieve optimal system operation, the level setpoints are calculated following the strategy of distributing the current volume of water among all tanks as evenly as possible considering their capacity. This is achieved by calculating for each one its reference level as a function of the total capacity of the network and the capacity of that tank [40]:  
\[x_{\mathit{iref}}(k)=\bigg{(}\frac{V_{G}(k)}{A_{i}}\bigg{)}v_{i},\ j=1,2, \ldots,5, \tag{18}\]  
where \(x_{\mathit{iref}}(k)\) is the reference level for deposit \(i\) at time \(k\), \(V_{G}(k)\) is the total volume occupied at the moment \(k\); \(v_{i}\) is a factor that represents the weight of the tank capacity \(i\) in the total available volume (sum of all tank volumes); \(V_{i}\) and \(A_{i}\) are the maximum capacity and the surface area of tank \(i\), respectively. The reference values for the flow rates would be zero because they are not considered except \(x_{ref9}=60.000\) m\({}^{3}/\)d, which is the desired inlet flow for the WWTP.