Model Predictive Control of Thermo-Hydraulic Systems Using Primal Decomposition footnoteinfo preprint This research is supported by the German federal ministry of economic affairs and climate action (BMWK) under the agreement no. 03EWR007O2. This work has been submitted to IFAC for possible publication. Jonathan Vieth, Annika Eichler, Arne Speerforck Abstract Decarbonizing the global energy supply requires more efficient heating and cooling systems. Model predictive control enhances the operation of cooling and heating systems but depends on accurate system models, often based on control volumes. We present an automated framework including time discretization to generate model predictive controllers for such models. To ensure scalability, a primal decomposition exploiting the model structure is applied. The approach is validated on an underground heating system with varying numbers of states, demonstrating the primal decomposition’s advantage regarding scalability. keywords Model predictive control, Thermal systems modeling, Large-scale and networked optimization problems, Primal decomposition, Control and optimization for sustainability and energy systems, Energy management systems, Urban energy distribution systems 1 INTRODUCTION The 9 specified that the heat supply of buildings in the European Union must be decarbonized by 2050. A recent study by 11 showed that the share of buildings supplied with heat by district heating networks (DHNs) needs to increase in Germany, in order to meet the targets. This finding is consistent with the results of 20 . To meet the climate targets, DHNs must be decarbonized. According to 21 , an important aspect of decarbonizing DHNs is increasing efficiency, for example through intelligent operation strategies, or decreasing the overall system temperature. In addition, cooling is the fastest-growing energy use in buildings globally. According to the 16 , efficiency measures can reduce the global electricity costs related to cooling demand by approximately 38\text{\,}\mathrm{\%} compared to a baseline scenario. In summary, the need for efficiency measures for heating and cooling systems will increase in the future. Efficiency can be increased through optimized planning and more efficient operating procedures. The optimal operation of DHNs using model predictive control (MPC) is studied in 23 and 29 , while 13 , 31 , and 19 focus on the optimal planning of DHNs. 7 apply optimization approaches to district heating and cooling networks (DHCNs). These systems allow for the combined supply of heat and cooling to buildings while using the soil as natural storage. In 27 , a literature review on MPC for heating, ventilation, and air conditioning (HVAC) systems is conducted, concluding that MPC for HVAC systems has gained attention in recent years. All of these systems have two things in common: they can be modeled using control volumes (CVs), and a fluid (e. g., water) often circulates in pipes to transport energy. For instance, 32 present a library for simulating DHNs that can also be used for cooling systems with minor modifications. This library is used in 30 for optimal DHN planning. In 22 , several pipe models are compared to find the best model for MPC of DHNs. The authors conclude that models based on CVs are a reasonable choice because they are simple to implement and have a constant number of variables, unlike the Node Method first presented by 2 . However, models based on CVs lead to systems governed by time-continuous differential-algebraic equations (DAEs). Automated approaches for MPC generation for time-continuous DAEs are presented in 10 , 15 , and 6 . In 10 , the optimal control problem is solved using a direct method. According to 24 , in direct methods first the time-continuous DAEs are time-discretized, and then an optimization problem is solved based on the discretized system model. In contrast, the approaches presented by 15 and 6 employ multiple shooting techniques to solve the optimal control problem based on the continuous system model. This work presents a direct method for thermo-hydraulic systems modeled by CVs. One drawback of a direct approach is that the time discretization of nonlinear systems is not trivial. However, since the discretization occurs beforehand, this method may be more computationally efficient. Additionally, focusing on thermo-hydraulic systems allows us to exploit the specific structure of the models using primal decomposition. 1.0.1 Contribution In this work, we present an automated workflow for MPC generation consisting of • a general dynamic system model for thermo-hydraulic systems (Section 2 ) • a procedure for time discretization of nonlinear dynamic systems based on Backward-Differentiation (Section 3 ) • a fast and scalable MPC approach for thermo-hydraulic systems using primal decomposition (Section 4 ) 1.0.2 Notation The identity matrix with n rows and columns is represented by \bm{I}_{n} and \bm{1}_{n\times m} is a matrix with n rows and m columns where all elements are equal to one. Vectors are denoted by lowercase bold letters, and matrices by uppercase bold letters. 2 DYNAMICS OF SYSTEMS MODELED BY CONTROL VOLUMES \theta_{1} , \dot{m}_{1} \theta_{2} , \dot{m}_{2} \theta_{3} \theta_{4} \theta_{\mathrm{in}} , \dot{m}_{\mathrm{in}} \theta_{\mathrm{a}} \theta_{\mathrm{s}} \theta_{\mathrm{s}} \theta_{2} , \dot{m}_{\mathrm{out}} \frac{1}{2}\sigma_{\mathrm{y}} \frac{1}{2}\sigma_{\mathrm{y}} \sigma_{\mathrm{x}} \sigma_{\mathrm{pi}} \frac{1}{2}\sigma_{\mathrm{x}} \frac{1}{2}\sigma_{\mathrm{x}} \sigma_{\mathrm{pi}} pipe CV soil CV conductive heat convective heat x y Figure 1 : Simple setup of CVs Consider the system shown in Figure 1 , which could represent any type of heating or cooling system. The differential equations (DEs) \displaystyle\frac{\mathrm{d}\bm{\theta}}{\mathrm{d}t}=\bm{A}\bm{\theta}+\bm{D}\bm{d}+\bm{X}_{\mathrm{\theta}}\left[\dot{\bm{m}}\circ\left(\bm{Z}_{\mathrm{\theta}}\bm{\theta}\right)\right]+\bm{X}_{\mathrm{z}}\left[\bm{Y}_{\mathrm{z}}\dot{\bm{m}}\theta_{\mathrm{in}}\right] (1a) describe the temperatures \bm{\theta}^{\top}=\begin{bmatrix}\theta_{1}&\theta_{2}&\theta_{3}&\theta_{4}\end{bmatrix} and the mass flows \dot{\bm{m}}^{\top}=\begin{bmatrix}\dot{m}_{1}&\dot{m}_{2}\end{bmatrix} in the CVs. The vector \bm{d}^{\top}=\begin{bmatrix}\theta_{\mathrm{s}}&\theta_{\mathrm{a}}\end{bmatrix} comprises the non-controllable inputs: the soil temperature \theta_{\mathrm{s}} and the air temperature \theta_{\mathrm{a}} . Here, the input temperature \theta_{\mathrm{in}} is assumed to be an algebraic state (later denoted by z ), as in many heating or cooling systems it would be linked with \theta_{2} and an input variable via an algebraic equation. The constant matrices in ( 1a ) are \displaystyle\bm{A}=\begin{bmatrix}-\frac{\sigma_{\mathrm{pi}}}{c_{\mathrm{w}}\rho_{\mathrm{w}}V}&0&\frac{\sigma_{\mathrm{pi}}}{c_{\mathrm{w}}\rho_{\mathrm{w}}V}&0\\ 0&-\frac{\sigma_{\mathrm{pi}}}{c_{\mathrm{w}}\rho_{\mathrm{w}}V}&0&\frac{\sigma_{\mathrm{pi}}}{c_{\mathrm{w}}\rho_{\mathrm{w}}V}\\ \frac{\sigma_{\mathrm{pi}}}{c_{\mathrm{s}}\rho_{\mathrm{s}}V}&0&-\frac{\sigma_{\mathrm{pi}}+\frac{3}{2}\sigma_{\mathrm{x}}+\frac{1}{2}\sigma_{\mathrm{y}}}{c_{\mathrm{s}}\rho_{\mathrm{s}}V}&\frac{\sigma_{\mathrm{x}}}{c_{\mathrm{s}}\rho_{\mathrm{s}}V}\\ 0&\frac{\sigma_{\mathrm{pi}}}{c_{\mathrm{s}}\rho_{\mathrm{s}}V}&\frac{\sigma_{\mathrm{x}}}{c_{\mathrm{s}}\rho_{\mathrm{s}}V}&-\frac{\sigma_{\mathrm{pi}}+\frac{3}{2}\sigma_{\mathrm{x}}+\frac{1}{2}\sigma_{\mathrm{y}}}{c_{\mathrm{s}}\rho_{\mathrm{s}}V}\\ \end{bmatrix}, \displaystyle\bm{D}=\frac{1}{2}\begin{bmatrix}0&0\\ 0&0\\ \frac{\sigma_{\mathrm{x}}}{c_{\mathrm{s}}\rho_{\mathrm{s}}V}&\frac{\sigma_{\mathrm{y}}}{c_{\mathrm{s}}\rho_{\mathrm{s}}V}\\ \frac{\sigma_{\mathrm{x}}}{c_{\mathrm{s}}\rho_{\mathrm{s}}V}&\frac{\sigma_{\mathrm{y}}}{c_{\mathrm{s}}\rho_{\mathrm{s}}V}\\ \end{bmatrix},\bm{X}_{\mathrm{\theta}}=\begin{bmatrix}\frac{1}{\rho_{\mathrm{w}}V}&0\\ 0&\frac{1}{\rho_{\mathrm{w}}V}\\ 0&0\\ 0&0\\ \end{bmatrix},\bm{X}_{\mathrm{z}}=\begin{bmatrix}\frac{1}{\rho_{\mathrm{w}}V}\\ 0\\ 0\\ 0\\ \end{bmatrix}, \displaystyle\bm{Z}_{\mathrm{\theta}}=\begin{bmatrix}-1&0&0&0\\ 1&-1&0&0\\ \end{bmatrix},\bm{Y}_{\mathrm{z}}=\begin{bmatrix}1&0\\ \end{bmatrix}. Here, V is the volume of each CV, \sigma_{\mathrm{x}} , \sigma_{\mathrm{y}} , and \sigma_{\mathrm{pi}} are thermal conductivities, and c_{i} and \rho_{i} are the heat capacity and density of the soil ( \mathrm{s} ) and the water ( \mathrm{w} ) inside the pipe, respectively, all considered as constant. In ( 1a ), we assume that changes in enthalpy due to changes in pressure are negligible, a condition that is generally met for the systems under consideration. Additionally, algebraic equations (AEs) \displaystyle\dot{m}_{\mathrm{in}}=\dot{m}_{1}=\dot{m}_{2}=\dot{m}_{\mathrm{out}} (1b) connect the mass flow variables. Note that inserting ( 1b ) into ( 1a ) would simplify ( 1a ). However, the structure of ( 1a ) leads us to the DAE system \displaystyle\frac{\mathrm{d}\bm{\theta}}{\mathrm{d}t} \displaystyle=\bm{A}\bm{\theta}+\bm{B}\bm{u}+\bm{C}\bm{z}+\bm{D}\bm{d}+\sum_{\bm{v}\in\mathcal{V}}\bm{X}_{v}\left[\left(\bm{Y}_{v}\dot{\bm{m}}\right)\circ\left(\bm{Z}_{v}\bm{v}\right)\right], (2a) \displaystyle\bm{0} \displaystyle=\bm{f}_{\mathrm{h}}(\dot{\bm{m}},\bm{z}_{\mathrm{h}},\bm{u}_{\mathrm{h}},\bm{d}), (2b) \displaystyle\bm{0} \displaystyle=\bm{f}_{\mathrm{t}}(\bm{\theta},\dot{\bm{m}},\bm{z},\bm{u},\bm{d}), (2c) \displaystyle\bm{0} \displaystyle\geq\bm{g}_{\mathrm{h}}(\dot{\bm{m}},\bm{z}_{\mathrm{h}},\bm{u}_{\mathrm{h}},\bm{d}), (2d) \displaystyle\bm{0} \displaystyle\geq\bm{g}_{\mathrm{t}}(\bm{\theta},\dot{\bm{m}},\bm{z},\bm{u},\bm{d}), (2e) which represents an arbitrary system of interconnected CVs with the controllable inputs \bm{u}^{\top}=\begin{bmatrix}\bm{u}^{\top}_{\mathrm{h}}&\bm{u}^{\top}_{\mathrm{t}}\end{bmatrix} and the algebraic variables \bm{z}^{\top}=\begin{bmatrix}\bm{z}^{\top}_{\mathrm{h}}&\bm{z}^{\top}_{\mathrm{t}}\end{bmatrix} . The subscript h denotes variables related to the hydraulics (e. g. pressure differences in pipes) and t to the thermal-model (e. g. power input at heat exchangers). All matrices are constant, \bm{f}_{\mathrm{h}} is a function representing the hydraulic AEs, \bm{f}_{\mathrm{t}} all other AEs, \bm{g}_{\mathrm{h}} the hydraulic inequality constraints, \bm{g}_{\mathrm{t}} all other inequality constraints, and \mathcal{V}=\{\bm{\theta},\bm{z},\bm{u},\bm{d}\} . The reason for extracting the hydraulic constraints from the other constraints is solely for notational purposes and does not lead to any modeling restrictions, since all variables can occur in \bm{f}_{\mathrm{t}} and \bm{g}_{\mathrm{t}} . This approach is motivated by the primal decomposition scheme, as discussed in Section 4.2 . 3 TIME DISCRETIZATION OF SYSTEMS MODELED BY CONTROL VOLUMES The goal of this section is to find a time-discrete representation of ( 2a ). Common techniques for the time discretization of nonlinear control systems include the Taylor approximation, as presented in 17 and 26 , Runge-Kutta integration, see 14 and 12 , and backward differentiation, as performed in 28 . As shown in 28 , Taylor approximation and Runge-Kutta integration can result in time-discrete system dynamics with additional complicating nonlinear terms. Furthermore, as the discretization order increases, the general structure of ( 2a ) may change due to the discretization. This has the disadvantage of making the time-discrete form of ( 2a ) non-bilinear. Thus, the complexity of optimization within MPC is probably increased. Additionally, the ability to obtain linear optimization problems using primal decomposition disappears if nonlinear equations that are not bilinear result from the time-discretization approach. For this reason, second-order backward differentiation is used. According to 1 , the time-discrete system dynamics are given by \displaystyle\begin{split}\bm{0}=&\bm{f}_{\mathrm{de},k}\left(\bm{\theta}_{k},\dot{\bm{m}}_{k},\bm{z}_{k},\bm{u}_{k},\bm{d}_{k}\right)\\ =&\left[\bm{I}_{|\bm{\theta}_{k}|}-\frac{2}{3}\Delta t\bm{A}\right]\bm{\theta}_{k}-\frac{4}{3}\bm{\theta}_{k-1}+\frac{1}{3}\bm{\theta}_{k-2}\\ -&\frac{2}{3}\Delta t\bigg[\bm{B}\bm{u}_{k}+\bm{C}\bm{z}_{k}+\bm{D}\bm{d}_{k}\\ +&\sum_{\bm{v}\in\mathcal{V}}\bm{X}_{\bm{v}}\left[\left(\bm{Y}_{\bm{v}}\dot{\bm{m}}_{k}\right)\circ\left(\bm{Z}_{\bm{v}}\bm{v}_{k}\right)\right]\bigg]\end{split} (3) with the constant timestep \Delta t . Note that the implementation of higher-order backward differentiation is similar. 4 PRIMAL-DECOMPOSITION OF SYSTEMs MODELED BY CONTROL VOLUMES 4.1 General MPC optimization problem The goal of the MPC is to minimize an objective function \displaystyle\begin{split}J_{k}\left(\hat{\bm{\theta}}_{k},\hat{\dot{\bm{m}}}_{k},\hat{\bm{z}}_{k},\hat{\bm{u}}_{k}\right)=&J_{\mathrm{h},k}\left(\hat{\dot{\bm{m}}}_{k},\hat{\bm{z}}_{\mathrm{h},k},\hat{\bm{u}}_{\mathrm{h},k}\right)\\ +&J_{\mathrm{t},k}\left(\hat{\bm{\theta}}_{k},\hat{\dot{\bm{m}}}_{k},\hat{\bm{z}}_{k},\hat{\bm{u}}_{k}\right),\end{split} (4a) with the notation convention \displaystyle\hat{\bm{a}}_{k}=\begin{bmatrix}\bm{a}^{\top}_{k}&\bm{a}^{\top}_{k+1}&\dots&\bm{a}^{\top}_{k+n_{\mathrm{c}}-1}\end{bmatrix}^{\top}, and with \displaystyle J_{\mathrm{h},k}\left(\hat{\dot{\bm{m}}}_{k},\hat{\bm{z}}_{\mathrm{h},k},\hat{\bm{u}}_{\mathrm{h},k}\right) \displaystyle=\sum_{\kappa\in\mathcal{K}}j_{\mathrm{h},\kappa}\left(\dot{\bm{m}}_{\kappa},\bm{z}_{\mathrm{h},\kappa},\bm{u}_{\mathrm{h},\kappa}\right), (4b) \displaystyle J_{\mathrm{t},k}\left(\hat{\bm{\theta}}_{k},\hat{\dot{\bm{m}}}_{k},\hat{\bm{z}}_{k},\hat{\bm{u}}_{k}\right) \displaystyle=\sum_{\kappa\in\mathcal{K}}j_{\mathrm{t},\kappa}\left(\bm{\theta}_{\kappa},\dot{\bm{m}}_{\kappa},\bm{z}_{\kappa},\bm{u}_{\kappa}\right) (4c) over all time-steps \mathcal{K}=\{k,k+n_{\mathrm{c}}-1\} within the control-horizon n_{\mathrm{c}} with respect to the hydraulic constraints \displaystyle\bm{f}_{\mathrm{h},\kappa}(\dot{\bm{m}}_{\kappa},\bm{z}_{\mathrm{h},\kappa},\bm{u}_{\mathrm{h},\kappa},\bm{d}_{\kappa}) \displaystyle=0,\quad\forall\kappa\in\mathcal{K}, (5a) \displaystyle\bm{g}_{\mathrm{h},\kappa}(\dot{\bm{m}}_{\kappa},\bm{z}_{\mathrm{h},\kappa},\bm{u}_{\mathrm{h},\kappa},\bm{d}_{\kappa}) \displaystyle\leq 0,\quad\forall\kappa\in\mathcal{K}, (5b) and the non-hydraulic constraints \displaystyle\bm{f}_{\mathrm{de},\kappa}\left(\bm{\theta}_{\kappa},\dot{\bm{m}}_{\kappa},\bm{z}_{\kappa},\bm{u}_{\kappa},\bm{d}_{\kappa}\right) \displaystyle=0,\quad\forall\kappa\in\mathcal{K}, (6a) \displaystyle\bm{f}_{\mathrm{t},\kappa}\left(\bm{\theta}_{\kappa},\dot{\bm{m}}_{\kappa},\bm{z}_{\kappa},\bm{u}_{\kappa},\bm{d}_{\kappa}\right) \displaystyle=0,\quad\forall\kappa\in\mathcal{K}, (6b) \displaystyle\bm{g}_{\mathrm{t},\kappa}\left(\bm{\theta}_{\kappa},\dot{\bm{m}}_{\kappa},\bm{z}_{\kappa},\bm{u}_{\kappa},\bm{d}_{\kappa}\right) \displaystyle\leq 0,\quad\forall\kappa\in\mathcal{K}. (6c) Note that splitting the objective into a hydraulic objective j_{\mathrm{h}} and a temperature objective j_{\mathrm{t}} does not impose any restrictions, since all optimization variables can still be part of j_{\mathrm{t}} . Therefore, the optimization problem that must be solved at each time-step k is given by \displaystyle\begin{split}J^{\star}_{k}=\min_{\hat{\bm{\theta}}_{k},\hat{\dot{\bm{m}}}_{k},\hat{\bm{z}}_{k},\hat{\bm{u}}_{k}}J_{k}\left(\hat{\bm{\theta}}_{k},\hat{\dot{\bm{m}}}_{k},\hat{\bm{z}}_{k},\hat{\bm{u}}_{k}\right)\\ \text{subject to}\ \eqref{eq:mpc:constraintsHydraulic}\text{ and }\eqref{eq:mpc:constraintsTemp},\end{split} (7) where J^{\star}_{k} is the optimal function value of ( 4a ). 4.2 Primal decomposition As can be seen in ( 3 ), assuming \dot{\bm{m}}_{k} is constant makes ( 3 ) a linear system of equations. If the same holds true for ( 2b )–( 2e ), then primal decomposition can be used to efficiently solve the optimization problem ( 7 ). Figure 2 displays a procedure of the primal decomposition scheme. solve hydraulic optimization problem ( 8 ) converged? update \dot{\bm{m}} by ( 16 ) solve temperature optimization problem ( 9 ) converged? calculate subgradients ( 12 ) calculate feasible starting point by solving ( 5 ), ( 6 ) Start calculate objective value ( 10 ) update \dot{\bm{m}} by ( 11 ) update \alpha by ( 15 ), i\leftarrow i+1 converged? Stop yes no yes no yes no Figure 2 : Procedure of the primal decomposition scheme First, a feasible starting point is calculated by solving the system of nonlinear equations ( 5 ) and ( 6 ), where the control variables are taken from the MPC results of the previous time-step. The algorithm works by iteratively altering \hat{\dot{\bm{m}}}_{k} . The first step in each iteration is to solve the hydraulic optimization problem \displaystyle\begin{split}J^{i}_{\mathrm{h},k}=\min_{\hat{\bm{z}}_{\mathrm{h},k},\hat{\bm{u}}_{\mathrm{h},k}}&J_{\mathrm{h},k}\left(\hat{\dot{\bm{m}}}_{k}^{i},\hat{\bm{z}}_{\mathrm{h},k}^{i},\hat{\bm{u}}_{\mathrm{h},k}^{i}\right)\\ &\text{subject to}\ \eqref{eq:mpc:constraintsHydraulic}\end{split} (8) with i being the primal decomposition iteration index. Solving ( 8 ) yields the optimal values for \hat{\bm{z}}_{\mathrm{h},k}^{i} and \hat{\bm{u}}_{\mathrm{h},k}^{i} . Next, the thermal optimization problem \displaystyle\begin{split}J^{i}_{\mathrm{t},k}=\min_{\bm{\theta}_{k},\hat{\bm{z}}_{\mathrm{t},k},\hat{\bm{u}}_{\mathrm{t},k}}&J_{\mathrm{t},k}\left(\hat{\bm{\theta}}_{k}^{i},\hat{\dot{\bm{m}}}_{k}^{i},\hat{\bm{z}}_{\mathrm{h},k}^{i},\hat{\bm{z}}_{\mathrm{t},k}^{i},\hat{\bm{u}}_{\mathrm{h},k}^{i},\hat{\bm{u}}_{\mathrm{t},k}^{i}\right)\\ &\text{subject to}\ \eqref{eq:mpc:constraintsTemp}\end{split} (9) is solved, resulting in \bm{\theta}_{k}^{i} , \bm{z}_{\mathrm{t},k}^{i} , and \bm{u}_{\mathrm{t},k}^{i} . The objective value after iteration i is given by \displaystyle J^{i}_{k}=J^{i}_{\mathrm{h},k}+J^{i}_{\mathrm{t},k}. (10) A convergence criterion, e. g. based on \Delta J=J^{i}_{k}-J^{i-1}_{k} , can then be used. If the convergence criterion is not met, the primal variable is updated by 4 \displaystyle\hat{\dot{\bm{m}}}_{k}^{i+1}=\hat{\dot{\bm{m}}}_{k}^{i}-\alpha^{i}\bm{s}_{k}^{i} (11) with the subgradient \displaystyle\bm{s}_{k}=\frac{\partial L_{k}\left(\hat{\bm{\theta}}_{k},\hat{\dot{\bm{m}}}_{k},\hat{\bm{z}}_{k},\hat{\bm{u}}_{k},\hat{\bm{\lambda}}_{k}\right)}{\partial\hat{\dot{\bm{m}}}_{k}}, (12) the Lagrangian as in 25 \displaystyle L_{k}=J_{k}-\sum_{\kappa\in\mathcal{K}}\sum_{\bm{h}\in\mathcal{H}}\bm{\lambda}^{\top}_{h,\kappa}\bm{h}_{\kappa}, (13) the set of constraint functions \mathcal{H}=\{\bm{f}_{\mathrm{h}},\bm{g}_{\mathrm{h}},\bm{f}_{\mathrm{de}},\bm{f}_{\mathrm{t}},\bm{g}_{\mathrm{t}}\} , and the optimal Lagrange multipliers \displaystyle\hat{\bm{\lambda}}^{\top}_{k}=\begin{bmatrix}\hat{\bm{\lambda}}_{f_{\mathrm{h}},k}^{\top}&\hat{\bm{\lambda}}_{g_{\mathrm{h}},k}^{\top}&\hat{\bm{\lambda}}_{f_{\mathrm{de}},k}^{\top}&\hat{\bm{\lambda}}_{f_{\mathrm{t}},k}^{\top}&\hat{\bm{\lambda}}_{g_{\mathrm{t}},k}^{\top}\end{bmatrix}. (14) Once again the notation convention from ( 4 ) is used, e. g. \hat{\bm{\lambda}}_{f_{\mathrm{h}},k}^{\top}=\begin{bmatrix}\bm{\lambda}_{f_{\mathrm{h}},k}^{\top}&\dots&\bm{\lambda}_{f_{\mathrm{h}},k+n_{\mathrm{c}}-1}^{\top}\end{bmatrix} . At the end of each iteration, \alpha^{i} is updated using the nonsummable, diminishing step-size rule 5 \displaystyle\alpha^{i}=\frac{\alpha}{\sqrt{i}} (15) which is in accordance with the conditions specified in 3 . If ( 5 ) or ( 6 ) become infeasible due to the primal variables update by ( 11 ), then the primal variables are re-updated by \displaystyle\hat{\dot{\bm{m}}}_{k}^{i}=\hat{\dot{\bm{m}}}_{k}^{i-1}-b\alpha^{i-1}\bm{s}^{i-1}, (16) and procedure ( 16 ) is repeated with a decreasing b<1 until ( 5 ) and ( 6 ) are fulfilled. This is similar to the backtracking approach presented by 18 . 8 present a different approach, using relaxation techniques and auxiliary variables to find a feasible \alpha^{i} . 5 UNDERGROUND HEATING SYSTEM 1 4 7 10 13 16 19 22 25 28 4 pipe CV 4 1 soil CV 1 undisturbed soil undisturbed air y z 4 5 6 19 20 21 \theta_{\mathrm{in}} \dot{m}_{\mathrm{in},1} \theta_{6} \dot{m}_{\mathrm{in},1} x z Figure 3 : underground heating system with two parallel pipes and 30 CVs 5.1 System model To validate the MPC approach and the scalability of the primal decomposition, we use three different versions of a simple underground heating system. Such system setups are frequently used in geothermal or underfloor heating systems. Furthermore, such systems are used at airports and sports fields to maintain a snow-free surface. The three versions vary in system size regarding number of pipes n_{\mathrm{pi}} , number of CVs n_{\mathrm{cv}} and number of CVs in x -direction n_{\mathrm{x}} which is equal to the number of CVs per pipe. Figure 3 shows two perspectives of the system with n_{\mathrm{pi}}=2 , n_{\mathrm{cv}}=30 , and n_{\mathrm{x}}=3 . For all three cases with different n_{\mathrm{pi}} values, two layers of CVs are assumed in the z -direction, and soil CVs are assumed at both ends of the bottom layers in the y -direction. The objective is to minimize energy costs while keeping soil CV temperatures between 278.15\text{\,}\mathrm{K} and 313.15\text{\,}\mathrm{K} . 5.1.1 System variables The states of the system are the CV temperatures \bm{\theta}^{\top}=\begin{bmatrix}\theta_{1}&\dots&\theta_{n_{\mathrm{cv}}}\end{bmatrix} . The algebraic states are the CV mass flows \dot{\bm{m}}^{\top}=\begin{bmatrix}\dot{m}_{1}&\dots&\dot{m}_{n_{\mathrm{x}}}\end{bmatrix} , the pipe pressure losses \bm{\Delta p}^{\top}=\begin{bmatrix}\Delta p_{1}&\dots&\Delta p_{n_{\mathrm{pi}}}\end{bmatrix} , the input temperature of the pipes \theta_{\mathrm{in}} and the temperature \theta_{\mathrm{out}} of the mass flow after mixing all pipe exit temperatures (see ( 20 )). The controllable inputs of the system consist of the mass flows in the pipes \dot{\bm{m}}_{\mathrm{in}}^{\top}=\begin{bmatrix}\dot{m}_{\mathrm{in},1}&\dots&\dot{m}_{\mathrm{in},n_{\mathrm{cv}}}\end{bmatrix} and the temperature increase \Delta\theta in between pipe out- and input. The uncontrollable inputs are soil temperature \theta_{\mathrm{s}} and air temperature \theta_{\mathrm{a}} . Table 1 depicts all variables together with their assignment to the vectors contained in \mathcal{V} . 5.1.2 Objective The goal of the controller is to minimize the cost of the required electrical energy for the pumps and the heating system given the electricity price c_{\mathrm{el},k} . The cost of electricity for the pumps per time step is given by \displaystyle j_{\mathrm{h},k}=\frac{c_{\mathrm{el},k}}{\rho_{\mathrm{w}}\eta_{\mathrm{pu}}}\bm{z}^{\top}_{\mathrm{h},k}\bm{u}_{\mathrm{h},k} (17a) with the pump efficiency \eta_{\mathrm{pu}}=$0.8$ . Assuming an electric boiler is used, the cost of the electricity required to heat the water between the pipe inputs and outputs is given by \displaystyle j_{\mathrm{t},k} \displaystyle=c_{\mathrm{el},k}c_{\mathrm{w}}u_{\mathrm{t},k}\bm{1}_{1\times n_{\mathrm{pi}}}\bm{u}_{\mathrm{h},k}. (17b) 5.1.3 System dynamics The system dynamics are based on ( 1 ) and are not repeated here due to space limitations. The parameters are set to V=$3.75\text{\,}{\mathrm{m}}^{3}$ , \sigma_{\mathrm{x}}=$0.025\text{\,}\mathrm{W}\text{\,}{\mathrm{K}}^{-1}$ , \sigma_{\mathrm{y}}=\sigma_{\mathrm{z}}=$22.5\text{\,}\mathrm{W}\text{\,}{\mathrm{K}}^{-1}$ , \sigma_{\mathrm{pi}}=$44.86\text{\,}\mathrm{W}\text{\,}{\mathrm{K}}^{-1}$ , c_{\mathrm{w}}=$4200\text{\,}\mathrm{J}\text{\,}{\mathrm{kg}}^{-1}\text{\,}{\mathrm{K}}^{-1}$ , \rho_{\mathrm{w}}=$1000\text{\,}\mathrm{kg}\text{\,}{\mathrm{m}}^{-3}$ , and c_{\mathrm{s}}\rho_{\mathrm{s}}=$1.5\text{\times}{10}^{6}\text{\,}\mathrm{J}\text{\,}{\mathrm{m}}^{-3}\text{\,}\mathrm{K}$ . Table 1 : System variables states controllable inputs uncontrollable inputs \bm{\theta} \bm{z}_{\mathrm{h}} \bm{z}_{\mathrm{t}} \dot{\bm{m}} \bm{u}_{\mathrm{h}} \bm{u}_{\mathrm{t}} \bm{d} \theta_{1} \Delta p_{1} \theta_{\mathrm{in}} \dot{m}_{1} \dot{m}_{\mathrm{in},1} \theta_{\mathrm{s}} \vdots \vdots \vdots \vdots \Delta\theta \theta_{n_{\mathrm{cv}}} \Delta p_{n_{\mathrm{pi}}} \theta_{\mathrm{out}} \dot{m}_{n_{\mathrm{x}}} \dot{m}_{\mathrm{in},n_{\mathrm{pi}}} \theta_{\mathrm{a}} 5.1.4 Algebraic equations In series with each pipe p , there is a pump that controls the mass flow rate \dot{m}_{\mathrm{in},p} . The first set of algebraic equations are the pressure loss relations \displaystyle\Delta p_{p}\left(\dot{m}_{\mathrm{in},p}\right)=\frac{\Delta p_{\mathrm{nom}}}{\dot{m}_{\mathrm{nom}}^{2}}\dot{m}_{\mathrm{in},p}^{2}, (18a) where \Delta p_{\mathrm{nom}}=$8\text{\times}{10}^{5}\text{\,}\mathrm{Pa}$ and \dot{m}_{\mathrm{nom}}=$30\text{\,}\mathrm{kg}\text{\,}{\mathrm{s}}^{-1}$ are nominal values. The input temperature is given by \displaystyle\theta_{\mathrm{in}}=\theta_{\mathrm{out}}+\Delta\theta (19) and \theta_{\mathrm{out}} is governed by \displaystyle\left(\sum_{p=1}^{n_{\mathrm{pi}}}\dot{m}_{\mathrm{in},p}\right)\theta_{\mathrm{out}}=\left(\sum_{p=1}^{n_{\mathrm{pi}}}\dot{m}_{\mathrm{in},p}\theta_{\mathrm{out},p}\right), (20) where \theta_{\mathrm{out},p} is the temperature of the last CV of pipe p , for example \theta_{6} for p=1 and \theta_{12} for p=2 in Figure 3 . 5.2 Time discretization One version of the underground heating system was implemented in Matlab . It was time-discretized using ( 3 ) with a time step of \Delta t=$2\text{\,}\mathrm{h}$ and simulated by solving the resulting system of equations. A second version was created using the library from 32 in Dymola . Dymola also uses backward differentiation. In Dymola , however, the solver selects \Delta t and the order of the backward differentiation depending on the state of the system. Due to the validated models from 32 , as well as the highly sophisticated time discretization in Dymola , the Dymola model is used as a benchmark. Figure 4 shows a comparison of the two simulations. As can be seen, the Matlab model is more accurate for soil CVs, with a maximum error of 0.473\text{\,}\mathrm{K} , than for pipe CVs, with a maximum error of 0.936\text{\,}\mathrm{K} , due to the slower dynamics. The highest deviations in the pipes occur after increasing \dot{m}_{\mathrm{in},2} from 2\text{\,}\mathrm{kg}\text{\,}{\mathrm{s}}^{-1} to 5\text{\,}\mathrm{kg}\text{\,}{\mathrm{s}}^{-1} after 10\text{\,}\mathrm{h} and after decreasing \Delta\theta from 1\text{\,}\mathrm{K} to 0.5\text{\,}\mathrm{K} . Figure 3 shows ambient temperature data, and \dot{m}_{\mathrm{in},1} is kept constant at 2\text{\,}\mathrm{kg}\text{\,}{\mathrm{s}}^{-1} . If higher model accuracy is required, \Delta t must be decreased. For \Delta t=$15\text{\,}\mathrm{min}$ , the maximum pipe temperature error is 0.23\text{\,}\mathrm{K} . 0 5 10 15 20 25 30 35 40 45 260 265 270 275 time ( \mathrm{h} ) Temperature ( \mathrm{K} ) air soil (a) Ambient temperatures 0 5 10 15 20 25 30 35 40 45 320 322 324 326 328 time ( \mathrm{h} ) Temperature ( \mathrm{K} ) Matlab CV 5 Dymola CV 5 Matlab CV 10 Dymola CV 10 Matlab CV 12 Dymola CV 12 (b) Pipe temperatures 0 5 10 15 20 25 30 35 40 45 290 300 time ( \mathrm{h} ) Temperature ( \mathrm{K} ) Matlab CV 1 Dymola CV 1 Matlab CV 23 Dymola CV 23 Matlab CV 27 Dymola CV 27 (c) Soil temperatures Figure 4 : Comparison of the Dymola (dashed lines) and the Matlab (dots) simulations for the system depicted in Figure 3 Table 2 : Numerical results of the two MPCs number of pipes number of variables average j_{\mathrm{h}} + j_{\mathrm{t}} per time step in \mathrm{\mbox{€}} average calc. time per time step in \mathrm{s} IPM MPC PD MPC IPM MPC PD MPC 1 19 116.01 117.91 1.18 6.03 2 43 271.53 274.4 12.51 7.81 7 202 1074.7 1298.5 3706 124.29 5.3 Model predictive controllers Two MPCs were used to control each system. Both controllers were implemented in Matlab . One MPC solved optimization problem ( 7 ) using the standard interior-point method (IPM) of Matlab . The second MPC solved ( 7 ) using the primal decomposition (PD) scheme presented in this work with the vector of primal variables \bm{u}_{\mathrm{h}} . The control-horizon was set to n_{\mathrm{c}}=12 , spanning 24\text{\,}\mathrm{h} , since \Delta t=$2\text{\,}\mathrm{h}$ . Hence, the total number of optimization variables of each MPC is given by n_{\mathrm{c}}\left(n_{\mathrm{cv}}+n_{\mathrm{x}}+2n_{\mathrm{pi}}+3\right) (see Table 1 ). 5.4 Results of the model predictive controller As shown in Table 2 , the IPM outperformed the PD in all three system setups in terms of objective value. However, the PD outperformed the IPM in terms of calculation time for all but the smallest system setup. For n_{\mathrm{pi}}=2 , the PD MPC calculation time is 62.4\text{\,}\mathrm{\%} of the IPM MPC calculation time; for n_{\mathrm{pi}}=7 , it is 3.35\text{\,}\mathrm{\%} . In conclusion, the PD MPC is more scalable than the IPM MPC. For the two smallest system setups, the average cost per time step is nearly equal for both MPCs, and for the system with seven pipes, the IPM MPC outperforms the PD MPC by 17.2\text{\,}\mathrm{\%} . 320 325 330 Temperature ( \mathrm{K} ) CV 5 CV 10 CV 12 280 290 300 310 Temperature ( \mathrm{K} ) CV 1 CV 23 CV 30 min. temp. 0 2 4 6 8 mass flow ( \frac{\mathrm{kg}}{\mathrm{s}} ) pipe 1 pipe 2 0 2 4 \Delta\theta ( \mathrm{K} ) 0 5 10 15 20 25 30 35 40 45 0 10 20 30 time ( \mathrm{h} ) elec. price ( \frac{\mathrm{\mbox{€}}}{\mathrm{kW}\text{\,}\mathrm{h}} ) Figure 5 : Results for the primal MPC for the system displayed in Figure 3 Figure 5 shows the simulation results for the system controlled by the PD MPC. When electricity prices are low, the MPC increases \Delta\theta , resulting in higher pipe temperatures. Otherwise, using only the mass flow rate is sufficient for distributing the stored heat at the beginning of the simulation without raising the temperature. As the soil temperature decreases, the mass flow increases. Note that the same mass flow is used for both pipes due to the symmetry of the system. The simulation results clearly demonstrate that the PD MPC can control the system according to changing electricity prices and leverage the system’s flexibility to minimize operating costs. 6 CONCLUSION This work presents a direct method for model predictive controller design for thermo-hydraulic systems modeled by control volumes. Using primal-decomposition increases the approach’s scalability massively compared to a standard MPC approach. Future work should include a more extensive analysis of more sophisticated system setups to provide a more robust evaluation of the presented approach. Additionally, comparisons with other automated MPC frameworks, as presented in 15 and 6 , are necessary. DECLARATION OF GENERATIVE AI AND AI-ASSISTED TECHNOLOGIES IN THE WRITING PROCESS During the preparation of this work the authors used DeepL Write and GPT4.1-Mini in order to improve readability. After using these tools, the authors reviewed and edited the content as needed and take full responsibility for the content of the publication.