A Model Predictive Control for Heat Supply at Building Thermal Inlet Based on Data-Driven Model

: At present, the traditional control strategy of heating systems is still unable to achieve building heating on demand, which enhances the energy consumption of heating and affects the thermal comfort of buildings. Therefore, this study puts forward a novel data-driven MPC for building thermal inlet, which allows the optimal operation of the district heating system and has been veriﬁed by simulation with three public buildings. In this method, the indoor temperature at the next moment reaches the temperature set value by changing the current ﬂow rate. First, based on the energy consumption monitoring platform and the measured data of the buildings, the building indoor temperature prediction model at the next moment is established by using long short-term memory (LSTM). Compared with subspace model identiﬁcation (SMI), LSTM has higher prediction accuracy, and the R 2 was about 0.9 in three buildings. Second, the particle generated by particle swarm optimization, which represents the ﬂow variation, is input to the trained LSTM to predict the indoor temperature. By minimizing the objective function, the optimal ﬂow change at the current time can be calculated. The results showed that the MPC based on a data-driven model can adjust the ﬂow rate in time to maintain a stable indoor temperature with ± 0.5 ◦ C error. In addition, when the temperature setting needs to be changed, the indoor temperature can reach the new set value in 3 h, which outperforms the PID control. The method proposed in this paper can greatly reduce the inﬂuence of regulation lag by adjusting the ﬂow in advance.


Introduction
With the development of urban construction, building energy consumption is increasing year by year.Research shows that the heating energy consumption of cities and towns in north China accounts for about 40% of the total energy consumption of urban buildings in China, which is the largest part of the total energy consumption of urban buildings [1,2].The energy savings in district heating are mainly divided into two parts, improving the insulation of a building envelope to reduce the building's heat load and improving the energy efficiency of a heating system to reduce the energy consumption of system operation.In recent years, with the continuous improvement of building energy saving standards, the insulation performance of the envelope has been significantly improved.For example, China's residential and public buildings generally implement the standard of 65% energy savings [3].Therefore, improving the energy efficiency of heating systems is becoming more and more important in building energy conservation.Because the building heating load is affected by the outdoor temperature, solar radiation, and so on, the district heating system (DHS) is a dynamic process in actual operation.In order to reduce the heating energy consumption and improve thermal comfort, it is very crucial to control the heating system to realize building heating on demand.
In the DHS, the main control strategy includes temperature control and flow rate control.For the temperature control strategy, though the regulation of the supply water temperature can save thermal energy, the pump consumes more electricity [4].As for flow In the DHS, the main control strategy includes temperature control and flow rate control.For the temperature control strategy, though the regulation of the supply water temperature can save thermal energy, the pump consumes more electricity [4].As for flow rate control, the regulation of the pump frequency can realize the reasonable distribution of heat [5].Meanwhile, there are many typical control algorithms (TCA) applied to the DHS, including on-off control, weather-compensated control, and PID control [6,7].However, due to the hysteresis and attenuation of the heating pipe network and the envelope, the regulation based on hysteresis feedback cannot respond well to the coupling effect of the heating pipe network and the envelope on the building's indoor temperature.Therefore, the TCA has limited energy-saving capacity, which thus restricts its development [8].
On the contrary, model predictive control (MPC) has been widely researched and applied in recent years because of its efficient control, higher energy savings, and better indoor environment [9][10][11].MPC strategies predict the future internal and external environmental data (ambient temperature, occupancy, building load, etc.) of the building, in combination with the information of the controlled object, in order to obtain the optimal values of the control variables through optimization methods.
Yao, et al. [12] divided the MPC scheme into two parts: (a) a prediction model and (b) an objective function for establishing the optimization problem.The prediction model is the cornerstone of the MPC system, which is used to predict the future process dynamics of the controlled object [12,13].The accuracy of the prediction model is highly important for the application of an MPC [14,15].ASHRAE [16] categorized modeling techniques based on the estimation of energy usage as first-principle modeling and datadriven modeling.A first-principle model is created primarily through resistance-capacitance networks (R-C networks) to capture the dynamics and interactions of elements in buildings, which are based on heat balance to simulate the heat transfer process in buildings [17][18][19], such as thermal conduction through the building envelope, convection between internal surfaces and the air, radiative heat transfer (see Figure 1), etc.However, this approach requires considerable detailed information about the building, which may be difficult to obtain.Unlike first-principle modeling, data-driven modeling does not require complex physical models and is better at predicting future uncertainties.It is unique that this method needs simulation data or experimental data.In recent years, subspace model identification (SMI) has developed rapidly and has been widely used in the field of MPC [20,21].It can result in a linear time-invariant model and has been adapted to handle data from several runs.SMI relies on the kind of the training data that can be noisy and can be led astray when finding the best model [22].Pippia et al. [23] used simulation data Unlike first-principle modeling, data-driven modeling does not require complex physical models and is better at predicting future uncertainties.It is unique that this method needs simulation data or experimental data.In recent years, subspace model identification (SMI) has developed rapidly and has been widely used in the field of MPC [20,21].It can result in a linear time-invariant model and has been adapted to handle data from several runs.SMI relies on the kind of the training data that can be noisy and can be led astray when finding the best model [22].Pippia et al. [23] used simulation data generated by Modelica software to solve the least-square problem and identify parameters.Drgo ňa et al. [24] used simulation data generated by Modelica software for the parameter identification of the state space model (SSM).Killian et al. [25] applied proper orthogonal decomposition (POD) and a k-means algorithm to predict occupancy for an MPC in a smart building.
Garnier et al. [26] developed an artificial neural network (ANN) model to predict air and radiant temperatures for MPC controllers whose training data were generated by the building's EnergyPlus model.The results showed that the correlation coefficient was higher than 0.8, whereas the mean relative error was lower than 6%.Indeed, ANNs have been extensively used to model indoor environments [27][28][29][30], which proves the effectiveness of the deep learning approach in MPC.However, an ANN considers each input as an independent parameter and ignores the time dependency between sequential values.As we all know, indoor environmental variables are time-series data, and there is a certain correlation between them.Obviously, time series cannot be accurately fitted with an ANN.
A recurrent neural network (RNN) is an effective solution to establish time series dependence.Long short-term memory (LSTM) is a kind of RNN that uses a learnable gate structure to overcome the gradient extinction and explosion in RNN.LSTM has been found to be suitable for energy consumption, price forecasting, and emission factor forecasting.A building thermal system is time-dependent.Due to its nonlinear and large lag, indoor temperature will be affected by external parameters in a period prior to the current time.The long short-term memory (LSTM) compatibly solves this problem by taking the output of the previous LSTM cell as the input of the next LSTM cell [31].The researchers verified that an LSTM model performed better an ANN in focusing on indoor air temperature (IAT) for MPC [32][33][34].Although LSTM has been applied in the MPC of air conditioning, there is no research on the district heating system, and the input features of the model have not been considered comprehensively.
In MPC for the DHS, the main purpose of the optimization problem is to minimize energy consumption while satisfying the thermal comfort constraints.For this purpose, researchers have to determine the suitable control object and optimal objective function definition.Aoun et al. [35] provided indoor thermal comfort by controlling the supply water temperature at the DHS substation.Hering et al. [36] presented an MPC for the return water temperature control of a low-temperature district heating (LTDH) system.The results showed savings in electrical energy consumption of 1.55-5.49%.However, this control strategy operated in the mode of large flow and small temperature difference, resulting in high energy consumption.Moreover, temperature regulation can only be regarded as a coarse adjustment measure, so it cannot accurately be called heating on demand [37].In recent years, the flow rate regulation has been paid more and more attention by researchers [5,38,39].For example, the thermal inlet was equipped with a regulating valve or a frequency conversion water pump to achieve flow regulation.On one hand, the energy consumption of the system was greatly reduced.On the other hand, the heat was truly distributed according to the needs of the building.Therefore, how to quickly obtain the optimal flow from the thermal inlet of a building is a pivotal problem.
In past studies, many optimization algorithms have been applied in MPC, such as linear programming (LP) [40], the interior-point algorithm (IPA) [41], the genetic algorithm (GA) [42], particle swarm optimization (PSO) [43], etc. Coelho [44] et al. confirmed that the PSO algorithm was able to reduce the set-point tracking error compared with GA and sequential quadratic programming (SQP) and could decrease the variations in the heating and ventilation control signals, reducing the effort over the actuators.PSO has been widely used in MPC and was proven to be efficient [45][46][47].Therefore, this paper presents an MPC based on a data-driven method for a variable flow DHS.The IAT prediction model was formulated, and illustrative MPC tests based on the PSO optimization are presented and analyzed.
Based on the above analysis, this paper presents an MPC based on a data-driven method for a variable flow DHS.The LSTM model uses reasonable disturbance factors (collected by sensors and a database) as inputs to predict future IATs in identifying the indoor dynamic environment for the heating season.The PSO leads to finding the optimal flow rate of the building thermal inlet, which minimizes the cost function.In order to demonstrate the accuracy and robustness of the proposed method, real data from three public buildings were used for the simulation analysis.This paper is structured as follows: Section 2 describes the indoor temperature prediction model, including the theoretical background of LSTM, the case used in this study, data acquisition and processing, and results analysis.Section 3 illustrates the framework of the MPC and optimization.Section 4 presents the control performance of the proposed method and provides a discussion.Finally, in Section 5 the conclusions are drawn.

Methodology
This section introduces the methodology and provides a detailed research flow on the data-driven MPC strategy.Figure 2 shows the principal structure of the control and adjustment method of the thermal inlet proposed in this paper.The method realizes intelligent regulation by controlling the pump frequency of the thermal inlet so that the heat supply can meet the demand of the building load.First, the LSTM model predicts the indoor temperature at the next moment based on the feature dataset, including the outdoor meteorological parameters, heating system operating parameters, and historical indoor temperature.The dataset is divided into training data and test data.The training data are used to train the model, and the test data are used to test the performance of the prediction model (LSTM).Next, based on the deviation between the predicted indoor temperature and the set value of the indoor temperature, the PSO is used to optimize the flow of the thermal inlet.
(collected by sensors and a database) as inputs to predict future IATs in identifying the indoor dynamic environment for the heating season.The PSO leads to finding the optimal flow rate of the building thermal inlet, which minimizes the cost function.In order to demonstrate the accuracy and robustness of the proposed method, real data from three public buildings were used for the simulation analysis.
This paper is structured as follows: Section 2 describes the indoor temperature prediction model, including the theoretical background of LSTM, the case used in this study, data acquisition and processing, and results analysis.Section 3 illustrates the framework of the MPC and optimization.Section 4 presents the control performance of the proposed method and provides a discussion.Finally, in Section 5 the conclusions are drawn.

Methodology
This section introduces the methodology and provides a detailed research flow on the data-driven MPC strategy.Figure 2 shows the principal structure of the control and adjustment method of the thermal inlet proposed in this paper.The method realizes intelligent regulation by controlling the pump frequency of the thermal inlet so that the heat supply can meet the demand of the building load.First, the LSTM model predicts the indoor temperature at the next moment based on the feature dataset, including the outdoor meteorological parameters, heating system operating parameters, and historical indoor temperature.The dataset is divided into training data and test data.The training data are used to train the model, and the test data are used to test the performance of the prediction model (LSTM).Next, based on the deviation between the predicted indoor temperature and the set value of the indoor temperature, the PSO is used to optimize the flow of the thermal inlet.

LSTM Model
The detailed structure of LSTM is described in Figure 3.The previous output, ℎ −1 ; previous memory unit,  −1 ; and current input,   , are concentrated as the input of LSTM; ℎ  denotes the current output.The input and output of the LSTM cell are  The detailed structure of LSTM is described in Figure 3.The previous output, h t−1 ; previous memory unit, C t−1 ; and current input, X t , are concentrated as the input of LSTM; h t denotes the current output.The input and output of the LSTM cell are controlled by the forget gate ( f t ), the input gate (i t ), and the output gate (O t ) [31].The control operation at any time of T is as follows: (1) Forget gate: this gate will acquire X t and h t−1 , and output a value between 0 and 1 through the sigmoid layer to choose to forget or remember part of the C t−1 information: Buildings 2022, 12, 1879 5 of 20 (2) Input gate: This gate is responsible for determining the information stored in the memory unit and consists of two main parts.The first part is called the tanh layer.X t and h t−1 are collected to create c t , which is stored in the memory unit.The second part is the sigmoid layer, which obtains X t and h t−1 to determine the information in the memory cells: (3) Memory unit: X t and h t−1 update the memory information under this LSTM cell after passing through the forget gate and the input gate: (4) Output gate: this gate combines X t , h t−1 , and the C t output prediction result h t : controlled by the forget gate (  ), the input gate (  ), and the output gate (  ) [31].The control operation at any time of T is as follows: (1) Forget gate: this gate will acquire   and ℎ −1 , and output a value between 0 and 1 through the sigmoid layer to choose to forget or remember part of the  −1 information: (2) Input gate: This gate is responsible for determining the information stored in the memory unit and consists of two main parts.The first part is called the tanh layer.  and ℎ −1 are collected to create ̃, which is stored in the memory unit.The second part is the sigmoid layer, which obtains   and ℎ −1 to determine the information in the memory cells: (3) Memory unit:   and ℎ −1 update the memory information under this LSTM cell after passing through the forget gate and the input gate:  In order to highlight the accuracy of the LSTM model, the subspace model identification method was analyzed and compared.The biggest difference between subspace model identification (SMI) and the LSTM model is that the core of subspace model is the state space model.It uses training data to construct matrices and perform matrix operations to estimate state space models.

Model of Input and Output
Referring to the building thermal model, the building obtains heat from the heating pipe network and releases heat to the outdoor air.When the obtained heat is equal to the released heat, the building reaches thermal balance, and the indoor temperature reaches a stable state.We can use the indoor temperature to intuitively evaluate the operation of In order to highlight the accuracy of the LSTM model, the subspace model identification method was analyzed and compared.The biggest difference between subspace model identification (SMI) and the LSTM model is that the core of subspace model is the state space model.It uses training data to construct matrices and perform matrix operations to estimate state space models.

Model of Input and Output
Referring to the building thermal model, the building obtains heat from the heating pipe network and releases heat to the outdoor air.When the obtained heat is equal to the released heat, the building reaches thermal balance, and the indoor temperature reaches a stable state.We can use the indoor temperature to intuitively evaluate the operation of a building heating system, so this paper uses the building indoor temperature as the output parameter of the LSTM model.
In order to ensure the accuracy of the model identification results and reduce the impact of noise, the input parameters should, as much as possible, include the factors affecting the room temperature, mainly including weather parameters and thermal parameters.The thermal parameters mainly include the hot water flow rate and the water supply temperature, which mainly affect the building heat.The meteorological factors affecting the building thermal load mainly include the indoor and outdoor temperatures, envelope, wind speed, solar radiation, etc.The building envelope is determined in the design stage and can be regarded as a fixed parameter.Therefore, the outdoor temperature, solar radiation, and wind speed are used as inputs to the model.The building's indoor temperature is influenced by historical information.Even with the same weather conditions, if the historical weather conditions are different, the actual results will be different.The weather parameters and heating parameters mainly affect the variation in indoor temperature.In order to establish an accurate prediction model of indoor temperature, the time series of the model input should be considered.The time series selected in this paper is the indoor temperature at the previous moment.

Calculation of Flow Rate 2.2.1. Particle Swarm Optimization
Particle swarm optimization (PSO) was proposed in 1995 [48] and is an intelligent optimization algorithm designed based on the simulation of birds' predation behavior.PSO assumes that there are different food sources in a certain area, and the task of the birds is to find the largest food source (the global optimal solution).Therefore, the birds spread out and search together.Throughout the search, the partners are able to tell each other where the largest food source is in their field of view by communicating their location information to each other.Eventually, the whole flock gathers around the largest food source, and the optimal solution is found.
The calculation steps of the PSO algorithm are as follows: First, the particle swarm optimization algorithm needs to initialize all particles in the space.Then, the initial position and initial velocity are assigned to the particle, and the initial fitness is calculated to find the initial optimal solution of the particle.Finally, the velocity and position of the particle are updated, which are shown in Equations ( 6) and ( 7): where x i denotes the position of the i-th particle; v i denotes the velocity of the i-th particle; ω denotes the inertial factor; C 1 and C 2 are constants that affect the particle learning speed; p is the local optimal solution; and g is the global optimal solution.The update of particle velocity is related to the local and global optimal solutions.As the calculation progresses, the particles cluster around one or more optimal points.The advantage of this algorithm is that it preserves both the local optimal solutions and the global optimal solution known to the particles.Subsequent experiments show that the retention of these two pieces of information has a good effect on a faster convergence speed and avoiding premature entrapment into a local optimal solution.This also laid the foundation for the improvement direction of subsequent particle swarm optimization algorithms.

Objective Function and Constraint
In this paper, PSO is used to obtain the optimal flow at the current time.Therefore, the particle position is expressed as the variation in flow, and the particle velocity is the variation in the variation in flow.The purpose of implementing the intelligent control of a thermal inlet is to make the building indoor temperature stay at the set value for a long time and ensure the thermal comfort of the building.In order to protect the building heating pipe network, sudden increases and sudden drops in flow should be avoided as much as possible in the control process.Therefore, the objective function in the PSO algorithm was set as: and the constraint is as follows: where q and r represent the system response weighing and system stability weighing matrices; T set and T i represent the set point and i-th hour indoor temperature; and dG min and dG max represent the minimum and maximum variations in the flow rate.

Calculation Process
According to the mathematical model for each part of the MPC mentioned above, the simulation model was established in MATLAB using Equations ( 1)- (8).First, the hybrid optimization algorithm of particle swarm optimization (PSO) and the Levenberg-Marquardt (LM) algorithm was used to calculate the parameters of the prediction model (LSTM).The algorithm operation step can be found in Ref. [49].Next, the calculation process of the variation in flow rate was divided into the following four steps (see Figure 4):

Building Description
Due to the limitations of practical conditions, it was impossible to collect data large quantities of buildings.This paper measured three buildings at a university in lian, China, namely building A, building B, and building C, as shown in Figure 5. Am them, building A and building B are teaching buildings, and building C is an office bu ing.They are supplied heat from the same DHS substation.The specific informatio shown in Table 1.Step 1: Initializing the parameters of PSO.The number of particles, i; the maximum number of iterations, k; and the upper and lower bounds of the search space and velocity were set in advance.In addition, the position, X i , and velocity, v i , of the particles were randomly initialized.The positions of the particle could be expressed as follows: Step 2: Updating the speeds and positions of the particles.The velocities and positions of each particle were updated with Equations ( 6) and (7), respectively, then evaluated as to whether the updated velocities and positions exceeded the particle velocity range from Equation (9).
Step 3: Calculating particle fitness.The positions of the particles, x i , was input to a feature dataset to change the flow rate from G t to G t + x i .Then, the prediction model (LSTM) was used to predict the indoor temperature at the next moment (T t+1 i ).Equation ( 8) was employed to calculate the particle fitness value, J i .
Step 4: Evaluating the quality of particles.When the number of iterations reached k or the global optimum reached the minimum value, the computation program was terminated.Otherwise, the program returned to Step 2.
Finally, the x i calculated by PSO was the value of the variation in the flow of the heating pipeline at the current time.By changing the flow rate at the current time, the indoor temperature at the next time was close to the temperature set point.Meanwhile, the indoor temperature at the next time was calculated by the prediction model (LSTM).

Building Description
Due to the limitations of practical conditions, it was impossible to collect data for large quantities of buildings.This paper measured three buildings at a university in Dalian, China, namely building A, building B, and building C, as shown in Figure 5.Among them, building A and building B are teaching buildings, and building C is an office building.They are supplied heat from the same DHS substation.The specific information is shown in Table 1.

Building Description
Due to the limitations of practical conditions, it was impossible to collect data for large quantities of buildings.This paper measured three buildings at a university in Dalian, China, namely building A, building B, and building C, as shown in Figure 5.Among them, building A and building B are teaching buildings, and building C is an office building.They are supplied heat from the same DHS substation.The specific information is shown in Table 1.

Data Acquisition
According to Section 2.1.2,LSTM model input parameters included outdoor meteorological parameters, system operation parameters, and building indoor temperature.

Data Acquisition
According to Section 2.1.2,LSTM model input parameters included outdoor meteorological parameters, system operation parameters, and building indoor temperature.
Outdoor meteorological parameters were collected by the local weather station (see Figure 6) installed on the roof of the school building, including outdoor temperature, wind speed, and irradiation.The measurement range and accuracy of the corresponding sensors are shown in Table 2. Outdoor meteorological parameters were collecte Figure 6) installed on the roof of the school building, in speed, and irradiation.The measurement range and a sors are shown in Table 2.This study used the heat meter data in the energy The three modeling objects selected in this paper wer the buildings, and the data collected by the gateway data platform.The data acquisition instrument was a the thermal inlet of the building, which communicated bus-RTU communication protocol.The flow rate wa with an accuracy of 1%, while the heat meter had a t real-time temperature of the water supply and return The indoor temperature was obtained by installin sensors in the rooms.In a building, the indoor temp where.This is not only due to the structure of the build also due to the form of the heating system inside th system easily produces vertical imbalances, and a hori izontal imbalances.In order to use a temperature valu This study used the heat meter data in the energy consumption monitoring platform.The three modeling objects selected in this paper were installed with a data gateway in the buildings, and the data collected by the gateway were uploaded to the building big data platform.The data acquisition instrument was an ultrasonic heat meter installed at the thermal inlet of the building, which communicated with the gateway through a Modbus-RTU communication protocol.The flow rate was measured by an ultrasonic wave with an accuracy of 1%, while the heat meter had a temperature sensor to measure the real-time temperature of the water supply and return pipes.
The indoor temperature was obtained by installing a certain number of temperature sensors in the rooms.In a building, the indoor temperature cannot be the same everywhere.This is not only due to the structure of the building itself and human activities but also due to the form of the heating system inside the building.For example, a vertical system easily produces vertical imbalances, and a horizontal system easily produces horizontal imbalances.In order to use a temperature value to reflect the overall indoor temperature of a building, a certain number of temperature sensors are necessary, and it is also very important to flexibly arrange the sensors according to the form of the building heating system.The three buildings all use vertical single-pipe systems with a high temperature at the top and a low temperature at the bottom, so most of the sensors should be placed on the middle floors.In addition, the external weather also affects the measurement accuracy of the sensor, so the measurement points should be placed in the middle of different classrooms on different floors to avoid direct sunlight and to avoid being directly blown by the wind due to window opening.Figure 7 shows the arrangement of the measuring points of the indoor temperature sensors in the three buildings.The box represents the temperature sensor, and the first number represents the floor where it is located.Therefore, T2-3 represents the third sensor placed on the second floor.The use of a statistical modeling method requires a large amount of data, and some buildings were in use during the measurement, so the temperature sensors needed to have the characteristics of long measurement times, accurate measurement values, and small volumes.For this paper, the Apresys U-disk temperature and humidity recorder 179-DTH (Figure 8) was selected.The temperature range was −40 • C to 80 • C, and the accuracy was ±0.4 • C. It had the functions of temperature selfrecording, timed start, setting the measurement interval, etc.After the measurement was completed, the data could be exported by connecting to a computer.interval, etc.After the measurement was completed, the data could be exported by connecting to a computer.The building has certain thermal storage.If the sampling time is too short or too long, it may fail to reflect the dynamic response of the indoor temperature.In order to ensure the validity of the collected data and improve the accuracy of the data, the temperature sensor collection interval was set to 15 min, and the system sampling interval was set to 1 h.The collected data needed to be reprocessed.First, the sum of the data at adjacent moments was averaged to fill the lost data.Then, the calculated mean value of the 15 min data was converted into hourly data, and the equation can be represented as follows: where T i denotes the i-th hour calculated temperature and T 0 , T 15 , T 30 , and T 45 denote the 0-th, 15-th, 30-th, and 45-th minute measured temperature in the i-th hour.
After data collection and processing, Table 3 presents the descriptive statistics of the system operation parameters and indoor temperature data in these three buildings, including the maximum, minimum, and mean values.Moreover, the dataset was divided into training data and test data, and the three datasets were used by LSTM to establish the prediction models for the three buildings.For building A, the data were from 16 January to 1 March 2021.For building B, the data were from 29 November 2020 to 16 February 2021.For building C, the data were from 16 November to 20 December 2020.In this study, the evaluation indices of the accuracy of the prediction model included the coefficient of determination (R 2 ), mean absolute percentage error (MAPE), root-meansquare error (RMSE), and mean absolute error (MAE).R 2 was used to evaluate the degree of linear correlation between the prediction values and the real values.The closer R 2 was to 1, the better the fitting result was.MAPE measured the error of the prediction values in percentage terms.The RMSE is a performance metric that paid more attention to the large distance between the predictions and real values.The MAE measured the average distance between the predictions and real values.The performance criteria are defined as follows: where y i denotes measured data; ŷi denotes prediction results; cov denotes covariance; and var denotes variance.

Analysis of Prediction Results
In order to highlight the accuracy of LSTM, the subspace system identification (SMI) method was used to compare with the LSTM model.The biggest difference between the SMI and LSTM was that the core of the subspace model was the state space model.It used the training data to construct the matrix and directly performed matrix operations to estimate the state space model, which had a better identification effect for the multi-input multi-output (MIMO) system.A detailed building process of the model can be found in the Ref. [50]. Figure 9a shows a comparison of the LSTM and SMI prediction results and the actual results for building A. It can be seen that LSTM had a considerable ability to forecast the indoor temperature compared to the SMI method.Specifically, the prediction results of SMI showed peaks at the 10-th, 45-th, and 73-th hours.According to the weather conditions and flow rates during this period (see Figure 9b), there was a peak outdoor temperature at the 10th hour, and the irradiance fluctuated most strongly at the 45th and 70th hours.It can be concluded that the SMI method was too sensitive to the outdoor temperature and solar radiation intensity, leading to large errors in the identification results.However, LSTM can remember valid historical information, which significantly improved the accuracy of the LSTM model.follows: where   denotes measured data;   ̂ denotes prediction results;  denotes covariance; and  denotes variance.

Analysis of Prediction Results
In order to highlight the accuracy of LSTM, the subspace system identification (SMI) method was used to compare with the LSTM model.The biggest difference between the SMI and LSTM was that the core of the subspace model was the state space model.It used the training data to construct the matrix and directly performed matrix operations to estimate the state space model, which had a better identification effect for the multi-input multi-output (MIMO) system.A detailed building process of the model can be found in the Ref. [50]. Figure 9a shows a comparison of the LSTM and SMI prediction results and the actual results for building A. It can be seen that LSTM had a considerable ability to forecast the indoor temperature compared to the SMI method.Specifically, the prediction results of SMI showed peaks at the 10-th, 45-th, and 73-th hours.According to the weather conditions and flow rates during this period (see Figure 9b), there was a peak outdoor temperature at the 10th hour, and the irradiance fluctuated most strongly at the 45th and 70th hours.It can be concluded that the SMI method was too sensitive to the outdoor temperature and solar radiation intensity, leading to large errors in the identification results.However, LSTM can remember valid historical information, which significantly improved the accuracy of the LSTM model.Due to the limitation of the experimental conditions, data were not collected in the three buildings at the same time.In order to ensure the training data amount and model accuracy, different buildings had different amounts of valid data.Figure 10 shows the prediction results of LSTM in building B and building C. As a result, the SMI model performance was poorer, so there is no display in Figure 10.It is intuitive to see that the proposed method can fit the temperature trend accurately.The prediction accuracy was lower in a few moments that were affected by extreme weather.Meanwhile, the evaluation indices of LSTM were calculated, as shown in Table 4.The prediction error of the Due to the limitation of the experimental conditions, data were not collected in the three buildings at the same time.In order to ensure the training data amount and model accuracy, different buildings had different amounts of valid data.Figure 10 shows the prediction results of LSTM in building B and building C. As a result, the SMI model performance was poorer, so there is no display in Figure 10.It is intuitive to see that the proposed method can fit the temperature trend accurately.The prediction accuracy was lower in a few moments that were affected by extreme weather.Meanwhile, the evaluation indices of LSTM were calculated, as shown in Table 4.The prediction error of the three buildings was reasonable, and R 2 was about 0.9.Obviously, the evaluation indices of building C were larger than for the other buildings, mainly because of the small amount of valid data.Under the normal operation of the amount of valid data, the MAPE, RMSE, and MAE of building A and B implied very good predictive ability during the prediction phases.To sum up, the LSTM model had good performance in indoor temperature prediction and wide applicability.Due to the limitation of the experimental conditions, data were not collected in the three buildings at the same time.In order to ensure the training data amount and model accuracy, different buildings had different amounts of valid data.Figure 10 shows the prediction results of LSTM in building B and building C. As a result, the SMI model performance was poorer, so there is no display in Figure 10.It is intuitive to see that the proposed method can fit the temperature trend accurately.The prediction accuracy was lower in a few moments that were affected by extreme weather.Meanwhile, the evaluation indices of LSTM were calculated, as shown in Table 4.The prediction error of the three buildings was reasonable, and R 2 was about 0.9.Obviously, the evaluation indices of building C were larger than for the other buildings, mainly because of the small amount of valid data.Under the normal operation of the amount of valid data, the MAPE, RMSE, and MAE of building A and B implied very good predictive ability during the prediction phases.To sum up, the LSTM model had good performance in indoor temperature prediction and wide applicability.MPC can adapt well to a multiple-parameter control system.The input of the building thermal system in this paper included the outdoor temperature, wind speed, irradiance, and water supply temperature.Before exploring its overall control effect, the influences of different disturbances on heating flow were studied for a building based on control variables.When the model predicted that the indoor temperature would decrease in the future, the flow rate would increase.Otherwise, when the indoor temperature increased, the flow rate would decrease.Therefore, the change in flow rate can reflect the change in indoor temperature, which can be used to analyze the sensitivity of the model predictive controller to different disturbances.
For the disturbances of outdoor temperature, wind speed, irradiance, and water supply temperature, the influences of the indoor temperature and flow rate in building B are shown in Figure 11. Figure 11a shows the variations in indoor temperature and flow rate under the disturbance of outdoor temperature.As for the other disturbances, irradiance and wind speed were set to 0, the water supply temperature was set to 40 • C, and the indoor temperature was set to 19 • C. It can be seen that the flow rate was negatively correlated with the outdoor temperature.According to the heat transfer theory, the greater the temperature difference between the interior and exterior, the faster the heat loss.Therefore, when the outdoor temperature dropped, the controller adjusted and increased the flow rate.Although the outdoor temperature varied dramatically during this period (the highest temperature was 1 • C, and the lowest temperature was −10 • C), the indoor temperature of the building was maintained at the set temperature of 19 • C. In Figure 11b-d, we can see that the flow rate was negatively correlated with the irradiance and the water supply temperature and positively correlated with the wind speed.
shown in Figure 11. Figure 11a shows the variations in indoor temperature and flow rate under the disturbance of outdoor temperature.As for the other disturbances, irradiance and wind speed were set to 0, the water supply temperature was set to 40 °C, and the indoor temperature was set to 19 °C.It can be seen that the flow rate was negatively correlated with the outdoor temperature.According to the heat transfer theory, the greater the temperature difference between the interior and exterior, the faster the heat loss.Therefore, when the outdoor temperature dropped, the controller adjusted and increased the flow rate.Although the outdoor temperature varied dramatically during this period (the highest temperature was 1 °C, and the lowest temperature was −10 °C), the indoor temperature of the building was maintained at the set temperature of 19 °C.In Figure 11bd, we can see that the flow rate was negatively correlated with the irradiance and the water supply temperature and positively correlated with the wind speed.

Simulation Results for One Week
In this section, all disturbance factors were integrated to simulate the operation of the intelligent control of the thermal inlet in a more realistic environment for one week.Figure 12 shows the information of the disturbance factors for one week.In this period, the characteristics of the outdoor temperature were the large temperature difference between day and night and that the average temperature of the 6th and 7th days was lower.In addition, the variation in irradiance was relatively regular and fluctuated greatly at noon.

Simulation Results for One Week
In this section, all disturbance factors were integrated to simulate the operation of the intelligent control of the thermal inlet in a more realistic environment for one week.Figure 12 shows the information of the disturbance factors for one week.In this period, the characteristics of the outdoor temperature were the large temperature difference between day and night and that the average temperature of the 6th and 7th days was lower.In addition, the variation in irradiance was relatively regular and fluctuated greatly at noon. Figure 13 shows the results of a one-week simulation of three buildings under the simultaneous action of all disturbance factors.Despite the interference of multiple factors, the indoor temperature of the buildings remained at the set value of 19 °C .The indoor temperature of building A rose slightly on the third day because the irradiance, outdoor temperature, and water supply temperature were all at peak values at this time, which jointly led to the increase in the indoor temperature of the building.In addition, the controller reached the lower limit of flow regulation at this time, so the room temperature fluctuated.The flow variation in the three buildings was at a low value at noon every day, which was mainly due to irradiance.The variation in flow on the 5th and 7th days was smaller than that on the other days, mainly due to the low irradiance on these two days.The control logic of the system was that when a deviation between the indoor temperature Figure 13 shows the results of a one-week simulation of three buildings under the simultaneous action of all disturbance factors.Despite the interference of multiple factors, the indoor temperature of the buildings remained at the set value of 19 • C. The indoor temperature of building A rose slightly on the third day because the irradiance, outdoor temperature, and water supply temperature were all at peak values at this time, which jointly led to the increase in the indoor temperature of the building.In addition, the controller reached the lower limit of flow regulation at this time, so the room temperature fluctuated.The flow variation in the three buildings was at a low value at noon every day, which was mainly due to irradiance.The variation in flow on the 5th and 7th days was smaller than that on the other days, mainly due to the low irradiance on these two days.The control logic of the system was that when a deviation between the indoor temperature and the set value was predicted, the optimal control was carried out.If the current flow could meet the indoor temperature setting value or the error was within a certain range, the control program was not started, which is also the reason why the flow rate of building C was a straight line for part of the time.Moreover, building C had a large variation in the flow generated by irradiance, indicating that irradiance had a great influence on the indoor temperature of this building.In addition, SPO may be trapped at a local optimum, leading to indoor temperature fluctuations at individual moments.

Simulation Result of Changing Set Temperature
From Figure 13, we can see that the indoor temperature of the three buildings could be kept stable at the set value, and the error was within ±0.5 • C, which reflects the good adaptability of MPC to different disturbances.However, the set temperature of the controller was constant in the above case.In practical application, keeping the building temperature constant for 24 h does not meet the requirements of green buildings and intelligent control, which means that the specific control strategy needs to be determined according to the building's function.For example, office buildings do not need heating at night because no one works at this time.The occupancy of residential buildings is low during the day, so the set temperature during the day can be appropriately lowered.When the set temperature changes, the controller needs to be able to respond quickly to reach the target value.
Figure 14 shows the simulation results of indoor temperature and flow in building B when the set temperature changed.In the simulation conditions, the disturbance factors on the 3rd to 5th days in Figure 12 were selected, and the set temperature was changed from 19 • C to 20 • C at the 36th hour.It can be seen that when the set temperature changed the controller could reach and maintain the new set temperature in 3 h.There are two main reasons for why such a long time was needed.First, the adjustment interval of the controller was 1 h, and the adjustment periods in a short time were limited.Second, there was a delay in room temperature adjustment due to the thermal inertia of the building itself.

Simulation Result of Changing Set Temperature
From Figure 13, we can see that the indoor temperature of the three buildings could be kept stable at the set value, and the error was within ±0.5 °C , which reflects the good adaptability of MPC to different disturbances.However, the set temperature of the controller was constant in the above case.In practical application, keeping the building temperature constant for 24 h does not meet the requirements of green buildings and intelligent control, which means that the specific control strategy needs to be determined according to the building's function.For example, office buildings do not need heating at night because no one works at this time.The occupancy of residential buildings is low during the day, so the set temperature during the day can be appropriately lowered.When the set temperature changes, the controller needs to be able to respond quickly to reach the target value.
Figure 14 shows the simulation results of indoor temperature and flow in building B when the set temperature changed.In the simulation conditions, the disturbance factors on the 3rd to 5th days in Figure 12 were selected, and the set temperature was changed from 19 °C to 20 °C at the 36th hour.It can be seen that when the set temperature changed the controller could reach and maintain the new set temperature in 3 h.There are two main reasons for why such a long time was needed.First, the adjustment interval of the controller was 1 h, and the adjustment periods in a short time were limited.Second, there was a delay in room temperature adjustment due to the thermal inertia of the building itself.

Comparison between MPC and PID
PID control is currently the most widely used control method.It carries out macrocontrol through three parameters without considering the characteristics of the system itself, while MPC is controlled by finding the optimal solution through the system prediction model.In this section, MPC and PID control were simultaneously applied to building B, and the control effects of the two methods were compared and analyzed.
There are many forms of PID control, and incremental PID control was selected for this paper, as the building thermal inlet control object was a variable-frequency water pump whose regulating range was limited.Meanwhile, in order to protect the internal pipeline of the building, rapid and large-scale adjustments should be avoided as much as possible in the adjustment process.The output value of incremental PID control is an increment rather than a direct flow, which can reduce the disorder caused by the control system.On the premise that the change in disturbance was the same as that in Section 4.2, we discuss the control effect for building B using the PID control method under a constant

Comparison between MPC and PID
PID control is currently the most widely used control method.It carries out macrocontrol through three parameters without considering the characteristics of the system itself, while MPC is controlled by finding the optimal solution through the system prediction model.In this section, MPC and PID control were simultaneously applied to building B, and the control effects of the two methods were compared and analyzed.
There are many forms of PID control, and incremental PID control was selected for this paper, as the building thermal inlet control object was a variable-frequency water pump whose regulating range was limited.Meanwhile, in order to protect the internal pipeline of the building, rapid and large-scale adjustments should be avoided as much as possible in the adjustment process.The output value of incremental PID control is an increment rather than a direct flow, which can reduce the disorder caused by the control system.On the premise that the change in disturbance was the same as that in Section 4.2, we discuss the control effect for building B using the PID control method under a constant set temperature and the result is shown in the Figure 15.It can be seen that the indoor temperature was stable at 19 • C, and the flow trend of this method was not significantly different from that of MPC.In order to discuss the performance of PID control under the condition of a variable set temperature, the disturbance in the first three days in Figure 12 and the change in set temperature from 19 °C to 18 °C were selected for simulation.The results are shown in Figure 16. Figure 16a shows the indoor temperature under the PID and MPC methods, and it can be seen that both PID and MPC could achieve the automatic adjustment of indoor temperature, but the time for PID to reach the new room temperature was longer than for MPC.Combined with the flow rate (Figure 16b) and meteorological parameters (Figure 12), it was found that when the outdoor temperature was in the rising stage, MPC responded to the disturbance factors to lower the flow rate and reach the new operating condition faster, while PID only adjusted according to the indoor temperature deviation, so the response time was slow.Figure 17 shows the results of PID and MPC during the intermittent operation of a building heating system.The temperature was set to 19 °C during the day and 18 °C at night.The indoor temperature curve of MPC needed some time to adjust when the temperature rose, and its change trend closely followed the set temperature curve, while the PID control had a wide range of maladjustment phenomena, and the time to In order to discuss the performance of PID control under the condition of a variable set temperature, the disturbance in the first three days in Figure 12 and the change in set temperature from 19 • C to 18 • C were selected for simulation.The results are shown in Figure 16. Figure 16a shows the indoor temperature under the PID and MPC methods, and it can be seen that both PID and MPC could achieve the automatic adjustment of indoor temperature, but the time for PID to reach the new room temperature was longer than for MPC.Combined with the flow rate (Figure 16b) and meteorological parameters (Figure 12), it was found that when the outdoor temperature was in the rising stage, MPC responded to the disturbance factors to lower the flow rate and reach the new operating condition faster, while PID only adjusted according to the indoor temperature deviation, so the response time was slow.In order to discuss the performance of PID control under the condition of a variable set temperature, the disturbance in the first three days in Figure 12 and the change in set temperature from 19 °C to 18 °C were selected for simulation.The results are shown in Figure 16. Figure 16a shows the indoor temperature under the PID and MPC methods, and it can be seen that both PID and MPC could achieve the automatic adjustment of indoor temperature, but the time for PID to reach the new room temperature was longer than for MPC.Combined with the flow rate (Figure 16b) and meteorological parameters (Figure 12), it was found that when the outdoor temperature was in the rising stage, MPC responded to the disturbance factors to lower the flow rate and reach the new operating condition faster, while PID only adjusted according to the indoor temperature deviation, so the response time was slow.Figure 17 shows the simulation results of PID and MPC during the intermittent operation of a building heating system.The temperature was set to 19 °C during the day and 18 °C at night.The indoor temperature curve of MPC needed some time to adjust when the temperature rose, and its change trend closely followed the set temperature curve, while the PID control had a wide range of maladjustment phenomena, and the time to Figure 17 shows the simulation results of PID and MPC during the intermittent operation of a building heating system.The temperature was set to 19 • C during the day and 18 • C at night.The indoor temperature curve of MPC needed some time to adjust when the temperature rose, and its change trend closely followed the set temperature curve, while the PID control had a wide range of maladjustment phenomena, and the time to reach the set temperature in the daytime was far more than that of MPC.The conclusion is that MPC can better track the set temperature when the heating system is operating intermittently.
reach the set temperature in the daytime was far more than that of MPC.The conclusion is that MPC can better track the set temperature when the heating system is operating intermittently.On the whole, PID and MPC can achieve the stable control of indoor temperatures.However, in the face of extreme weather and set temperature changes, PID control cannot effectively integrate a variety of disturbance factors to control.When the system operates intermittently, there are a lot of overshoots in PID control, so MPC is a better choice for the intelligent control of a building's thermal inlet.

Conclusions
This paper provides a data-driven MPC for a building's thermal inlet in a DHS, which was simulated and evaluated in three public buildings.In the MPC framework, LSTM was used for model identification, which was to predict the indoor temperature at the next moment based on the energy consumption monitoring platform and the measured data of the buildings, and PSO was developed to minimize the energy consumption of the pump in the building thermal inlet as well as discomfort.The results showed that the proposed method can be quickly and effectively deployed and applied on a large scale.The main conclusions are as follows: (a) Different sensors were used to monitor the indoor temperature, water supply temperature, flow rate, and corresponding weather parameters of three public buildings, and the indoor temperature prediction models (LSTM and SMI) of these buildings were built.The R 2 of the LSTM prediction results was about 0.9 for the three buildings.The accuracy of LSTM was better than that of the SMI, mainly because SMI was too sensitive to input parameters, but LSTM had strong robustness.(b) Model predictive control based on a particle swarm optimization algorithm was used to regulate the flow at the thermal entrance of the buildings.The influences of different disturbance factors on indoor temperature were simulated by model predictive control.It was found that the outdoor temperature, irradiation, and water supply temperature were positively correlated with the indoor temperature.Wind speed was negatively correlated with the indoor temperature.The actual weekly weather parameters were selected for simulation, and the results showed that the three buildings could effectively control the indoor temperature at the set value.In addition, when the setting temperature needed to be changed, the indoor temperature could reach the new set value in 3 h.(c) MPC was compared with the traditional PID control.Incremental PID control was adopted to ensure the steady flow rate of the system.The results showed that PID could control the flow rate well and stabilize the indoor temperature when the set On the whole, PID and MPC can achieve the stable control of indoor temperatures.However, in the face of extreme weather and set temperature changes, PID control cannot effectively integrate a variety of disturbance factors to control.When the system operates intermittently, there are a lot of overshoots in PID control, so MPC is a better choice for the intelligent control of a building's thermal inlet.

Conclusions
This paper provides a data-driven MPC for a building's thermal inlet in a DHS, which was simulated and evaluated in three public buildings.In the MPC framework, LSTM was used for model identification, which was to predict the indoor temperature at the next moment based on the energy consumption monitoring platform and the measured data of the buildings, and PSO was developed to minimize the energy consumption of the pump in the building thermal inlet as well as discomfort.The results showed that the proposed method can be quickly and effectively deployed and applied on a large scale.The main conclusions are as follows: (a) Different sensors were used to monitor the indoor temperature, water supply temperature, flow rate, and corresponding weather parameters of three public buildings, and the indoor temperature prediction models (LSTM and SMI) of these buildings were built.The R 2 of the LSTM prediction results was about 0.9 for the three buildings.The accuracy of LSTM was better than that of the SMI, mainly because SMI was too sensitive to input parameters, but LSTM had strong robustness.(b) Model predictive control based on a particle swarm optimization algorithm was used to regulate the flow at the thermal entrance of the buildings.The influences of different disturbance factors on indoor temperature were simulated by model predictive control.It was found that the outdoor temperature, irradiation, and water supply temperature were positively correlated with the indoor temperature.Wind speed was negatively correlated with the indoor temperature.The actual weekly weather parameters were selected for simulation, and the results showed that the three buildings could effectively control the indoor temperature at the set value.In addition, when the setting temperature needed to be changed, the indoor temperature could reach the new set value in 3 h.(c) MPC was compared with the traditional PID control.Incremental PID control was adopted to ensure the steady flow rate of the system.The results showed that PID could control the flow rate well and stabilize the indoor temperature when the set temperature was unchanged.However, when the set temperature value changed, PID control responded slowly to weather parameters, leading to maladjustment.

Figure 2 .
Figure 2. Principal structure of the control and adjustment method.

Figure 2 .
Figure 2. Principal structure of the control and adjustment method.

2. 1 .
Prediction Model of IAT 2.1.1.LSTM Model ) where w f , w i , w C , and w o denote the weight matrix and b f , b i , b C , and b o denote bias.

Figure 3 .
Figure 3.The structure of the LSTM cell.

Figure 3 .
Figure 3.The structure of the LSTM cell.

Figure 7 .
Figure 7.The layout of the indoor temperature measuring points.Figure 7. The layout of the indoor temperature measuring points.

Figure 7 .Figure 7 .
Figure 7.The layout of the indoor temperature measuring points.Figure 7. The layout of the indoor temperature measuring points.
(a) The prediction results of LSTM and SMI Buildings 2022, 12, x FOR PEER REVIEW 13 of 22 (b) The disturbance of model input parameters

Figure 9 .
Figure 9.Comparison between LSTM and SMI in building A.

Figure 9 .
Figure 9.Comparison between LSTM and SMI in building A.
(b) The disturbance of model input parameters

Figure 9 .
Figure 9.Comparison between LSTM and SMI in building A.

Figure 10 .
Figure 10.The prediction results of LSTM in building B and building C.

Figure 10 .
Figure 10.The prediction results of LSTM in building B and building C.

Figure 11 .
Figure 11.Variation in parameters under different disturbances in building B.

Figure 11 .
Figure 11.Variation in parameters under different disturbances in building B.

Figure 12 .
Figure 12.Disturbance factors for one week.

Figure 12 .
Figure 12.Disturbance factors for one week.

Figure 13 .
Figure 13.The simulated flow rate and indoor temperature changes of three buildings for one week.

Figure 13 .
Figure 13.The simulated flow rate and indoor temperature changes of three buildings for one week.

Figure 14 .
Figure 14.Simulation results in building B when the set temperature changed.

Figure 14 .
Figure 14.Simulation results in building B when the set temperature changed.

Buildings 2022 ,
12,  x FOR PEER REVIEW 18 of 22 set temperature and the result is shown in the Figure15.It can be seen that the indoor temperature was stable at 19 °C , and the flow trend of this method was not significantly different from that of MPC.

Figure 15 .
Figure 15.PID control effect in building B.
(a) Changes in indoor temperature (b) Changes in flow rate

Figure 16 .
Figure 16.Comparison between PID and MPC under variable temperature settings.

Figure 15 .
Figure 15.PID control effect in building B.

Buildings 2022 ,
12,  x FOR PEER REVIEW 18 of 22 set temperature and the result is shown in the Figure15.It can be seen that the indoor temperature was stable at 19 °C , and the flow trend of this method was not significantly different from that of MPC.

Figure 15 .
Figure 15.PID control effect in building B.
(a) Changes in indoor temperature (b) Changes in flow rate

Figure 16 .
Figure 16.Comparison between PID and MPC under variable temperature settings.

Figure 16 .
Figure 16.Comparison between PID and MPC under variable temperature settings.

Figure 17 .
Figure 17.Comparison of the intermittent operation of PID and MPC.

Figure 17 .
Figure 17.Comparison of the intermittent operation of PID and MPC.
5North and south Vertical single-pipe system for upper supply and lower return

Table 2 .
The sensor information of the weather station.

Table 3 .
The statistics of the three buildings.

Table 4 .
Evaluation metric results of LSTM in three buildings.

Table 4 .
Evaluation metric results of LSTM in three buildings.