Fifth ‐ Generation District Heating and Cooling Substations: Demand Response with Artificial Neural Network ‐ Based Model Predictive Control

: District heating and cooling (DHC) is considered one of the most sustainable technologies to meet the heating and cooling demands of buildings in urban areas. The fifth ‐ generation district heating and cooling (5GDHC) concept, often referred to as ambient loops, is a novel solution emerging in Europe and has become a widely discussed topic in current energy system research. 5GDHC systems operate at a temperature close to the ground and include electrically driven heat pumps and associated thermal energy storage in a building ‐ sited energy transfer station (ETS) to satisfy user comfort. This work presents new strategies for improving the operation of these energy transfer stations by means of a model predictive control (MPC) method based on recurrent artificial neural networks. The results show that, under simple time ‐ of ‐ use utility rates, the advanced controller outperforms a rule ‐ based controller for smart charging of the domestic hot water (DHW) thermal energy storage under specific boundary conditions. By exploiting the available thermal energy storage capacity, the MPC controller is capable of shifting up to 14% of the electricity consumption of the ETS from on ‐ peak to off ‐ peak hours. Therefore, the advanced control implemented in 5GDHC networks promotes coupling between the thermal and the electric sector, producing flexibility on the electric grid.


Introduction
Fifth-generation district heating and cooling (5GDHC) is an innovative concept to cover simultaneously both the heating and cooling demands in urban areas. The following two sections introduce the reader to the role of 5GDHC in reducing the carbon footprint of the building sector (Section 1.1) and to a literature review of the latest scientific publications about this topic (Section 1.2).

Decarbonising the Building Sector with 5GDHC Systems
The heating and cooling sector is responsible for about 50% of the total final energy consumption in Europe [1], contributing substantially to poor air quality in urban areas because of fossil fuel combustion; the highest incidence rate of premature deaths due to air pollution occurs in Italy and in Eastern European countries [2]. According to H2020 Hotmaps project assessments on the EU28 building stock [3], and considering the current policy scenario regarding legislation and renovation rates, the 2050 outlook foresees a reduction of the space-heating demand by about 39% and a spacecooling demand three times higher than 2012 values. In Europe, the district heating market share stands at about 12-13% [4,5], whereas, for district cooling, the same value is about 2% [6]. Without any measures being implemented, the current district heating and cooling (DHC) business will be affected by the variation of buildings' thermal energy demands in the coming decades due to various energy efficiency programs [7].
DHC systems are widely considered as a sustainable solution to meet the heating and cooling demands in urban areas; hence, these infrastructures will be supported by means of the new European Green Deal Investment Plan [8]. Traditional district heating systems consist of a distribution network of pre-insulated pipes where thermal energy is supplied at a temperature in the range of 90 ÷ 120 °C and generated normally by centralised combined heat and power (CHP) plants or boilers that burn fossil fuels or biomass. Other applications foresee the recovery of hightemperature excess heat that can be a by-product of industrial processes or solar thermal energy stored in seasonal thermal energy storage systems. The thermal energy is distributed via pumping stations and is supplied to the buildings by means of passive substations that include usually heat exchangers for hydraulic separation and a valve that modulates the flow rate on the primary side to control the supply temperature on the secondary side. In general, this is performed according to a control strategy that enables weather compensation. To reduce the inefficiencies mainly connected to high-distribution heat losses, the district heating technology is evolving according to the so-called fourth-generation district heating (4GDH) towards low-distribution temperatures (in the range of 70 ÷ 30 °C), enhancing the exploitation of large centralised plants powered by renewable and waste heat sources [9]. Fifth-generation district heating and cooling (5GDHC) systems promote these goals, with some marked differences from traditional district heating or district cooling networks, as well from 4GDH. In fact, 5GDHC networks are operated at a temperature close to the ground (0 ÷ 30 °C) and, thus, "neutral" from the perspective of thermal losses. Moreover, 5GDHC allow implementing circular economy principles in the heating sector across the urban environment; because of the low distribution temperature, the ambient heat, as well as all available urban, low-grade excess heat (e.g., from supermarkets refrigeration systems, data centres, electrical transformers, sewage, underground railways, building cooling systems, etc.), can be effectively exploited and reused. 5GDHC systems permit energy balancing and interaction among buildings [10] and productive processes located along the network route, because both heating and cooling demands can be covered simultaneously by means of the two-pipe, or even single-pipe, 5GDHC network.
Potential weaknesses of the 5GDHC concept compared to traditional district heating are due mainly to difficult seasonal load balancing and higher complexity in both the distribution network management and the customer-sited energy transfer stations (ETSs). In fact, as shown in Figure 1, the latter must include a water-source heat pump (WSHP) to boost the temperature of the supplied thermal energy to meet the requirement of the distribution and emission system for space heating/cooling and domestic hot water production. Despite the additional complication introduced, these kinds of networks provide invaluable opportunities to a decentralised coupling of the thermal and power grids. The latter can be achieved through power-to-heat strategies exploiting the capacity of the distributed thermal energy storage (TES), required as a part of the 5GDHC ETS. As it happens in a conventional heat pump system, the thermal storage capacity is needed:  to increase the efficiencies of the WSHP unit with a more stable operation and yield the possibility to operate when the heat demand is below the WSHP minimum capacity, hence limiting the number of on-off switching events that are a cause of stress of both the electrical and mechanical WSHP components, reducing their lifetime,  to meet the user's comfort requirements during thermal peak loads, mainly with respect to domestic hot water (DHW) delivery, and  to increase the self-consumption of electricity from local decentralised non-dispatchable renewable energy sources, like rooftop photovoltaic systems. This is a value both for the user energy bill, as well as for the power distribution grid, benefiting from a form of flexibility that helps reduce the occurrence of power grid faults due to frequency or voltage variations. In fact, an aggregated WSHP pool can increase the electricity consumption when it is needed (negative balancing) and store it in the form of thermal energy or can partially reduce it (positive balancing).
Some relevant aspects of urban excess heat recovery have been reported in a recent position paper from the ReUseHeat project [5]. Here, the authors highlighted that recovering and reusing the low-temperature urban excess heat available in Europe, estimated at 1.2 EJ/year and equivalent to 16% of the heating demand of all buildings in the EU, could be cheaper than using high-temperature heat sources for two reasons: economical heat recovery solutions could be employed, whereas transmission networks are not needed anymore, because low-temperature urban excess heat sources are close to the heat demand. However, to exploit this urban excess heat potential, a tremendous effort is needed to raise the awareness of opportunities for both excess heat producers and users, overcoming legislative obstacles and making such projects "bankable" and, thus, attractive to investors.
In the next section, a short literature review on 5GDHC systems and the motivation of this study is presented.

Recent Publications About 5GDHC Systems and Urban Excess Heat Recovery
The literature review revealed that there are several publications on district heating and cooling exploiting decentralised heat pumps; these are hardly retrieved, because the authors identified these systems with different names-in some cases, according to their peculiarities, like (bidirectional) low temperature (DHC) networks ( [25][26][27][28][29][30]), and, in other cases, with country-related names like "Anergienetz" in Switzerland [31,32], "Boucle d'eau tempérée" in France [33], "ambient loops" in English-speaking countries [34,35], and "Kalte Fernwärme" and "Teleriscaldamento Freddo" (translation of "cold district heating" in the national language) in Germany and Italy, respectively. After the first scientific publication, which reviewed 40 existing 5GDHC systems in Europe and explicitly supported the definition of the fifth-generation district heating and cooling [36], several authors recently followed the same direction of using this nomenclature in their works. A short review is provided in the following, showing how this nomenclature harmonisation can help in capacity building for technology transfer. Boesten et al. (2019) [37] outlined the main features of the 5GDHC concept, such as its flexibility and resilience, on the basis of the know-how gained from the development of the urban-scale 5GDHC grid of Mijnwater in Heerlen (The Netherlands). Von Rhein et al. (2019) [38] developed "5GDHCtat": a topology analysis tool for 5GDHC systems. The workflow included the use of URBANopt [39] to identify the district layout and building features that are used by EnergyPlus to obtain hourly building heating and cooling loads. These results have been used to build metamodels of the energy transfer station (ETS) and building loads [35] that have been coupled with a Modelica model of the network to perform yearly simulations. Two 5GDHC network topologies with one-pipe and twopipe configurations, respectively, developed by using models from the open-source Modelica Buildings Library [40], were compared by Sommer et al. (2020) [41] under the same boundary conditions. On the one hand, the results of the yearly numerical simulations revealed very small differences in the electricity consumption of the heating pump pool. On the other hand, the work showed that a one-pipe distribution topology, which is useful to avoid pump-to-pump interactions, had the same operation costs of a two-pipe topology with decentralised hydraulic pumps only if there was variable mass flow control of the main circulation pump that had to maintain the network temperature between the lower and upper bound. However, the authors claimed that if there was the need for a ring-like arrangement of the pipelines, the one-pipe distribution topology had lower installation costs than the two-pipe one. A recent bibliographic analysis concerning the simulation of 5GDHC systems can be found in Abugabbara et al. (2020) [42].
In   [43], the development of a linear programming tool in Python that selects the size of the main 5GDHC components and establishes their optimal operation according to the boundary conditions was presented. The results of its application to a case study that consisted of a German university campus with 17 buildings, most of them with heating and cooling demands, showed that, in comparison with a reference scenario consisting of individual heating, ventilation and air conditioning (HVAC) plants (driven by electric boilers, air-source heat pumps, and chillers), the 5GDHC system designed reduced both the total annualised costs and CO2 emissions by 42% and 56%, respectively. In [44], the same authors introduced and evaluated the demand overlap coefficient (DOC) on the same case study to assess the simultaneity of the heating and cooling demands in different district configurations. With respect to the reference scenario, the results showed that the 5GDHC systems supplying the district with a DOC higher than 0.3 have a higher exergy efficiency, whereas just the ones with a DOC higher than 0.45 imply a lower specific supply cost.
5GDHC systems support the electrification of both the building and transportation sectors towards a broader concept of "fifth-generation smart energy networks", as proposed by Revesz et al. (2020) [34]. The authors compared several scenarios for the integration of a 5GDHC system supplied by low-grade heat with photovoltaic (PV) arrays, batteries, and vehicle-to-grid (V2G) controls in two possible areas of the London Borough of Islington (UK) by using the commercial software energyPRO. Exploiting aquifers, excess heat from data centres, and the underground ventilation shaft, together with electricity from photovoltaics, the economic and environmental advantages of 5G networks with respect to the business-as-usual (BAU) scenario based on gas boilers, electric chillers, and grid electricity, a payback period of about 10 years was assessed.
This study aims at presenting the implementation and assessment of an advanced controller for a 5GDHC energy transfer station (ETS) called also a substation, focusing on the optimisation of domestic hot water (DHW) production by exploiting the thermal capacity of the local thermal energy storage system. Advanced control and load shift potential have been investigated mainly in applications based on air-source heat pump/chiller systems (see [45][46][47][48][49][50]) but not in 5GDHC systems where, conversely, the inlet temperature on the source side of the heat pump can be controlled by the DHC network operator, and the thermal energy extracted from the DHC network is a cost for the user. This paper is organised as follows. Section 2 elaborates on the methodology applied to develop the ETS physical model and the model predictive control (MPC) algorithm divided into six main steps. In Section 3, the results about a parametric analysis and the performance assessment of the MPC under a first test case are discussed.

Materials and Methods
To investigate a smart power-to-heat operation considering the implementation of a demand response (DR) strategy and exploiting the local heat pump and thermal energy storage system at the ETS level, a simulation tool for the application of model predictive control (MPC) has been developed. It is based on algorithms that belong to the field of artificial intelligence (AI) and uses a reduced order model (ROM) to make predictions of the substation performance. The following six sections offer a description of the methodology applied to develop and test the MPC according to the six steps of the flowchart in Figure 2.

Physical Modelling and Laboratory Test of the 5GDHC Energy Transfer Station (ETS)
The 5GDHC ETS physical model developed has the equivalent capacity of one of the two singlecompressor speed WSHPs available at the Energy Exchange Laboratory of EURAC Research [51] that has been used for model calibration and validation. The ETS, modelled in TRNSYS, consists of a number of components that are connected according to the layout reported in Figure 3 with some improvements with respect to the standard installation of heat pump systems. In fact, the mixing valves at the DHW recirculation circuit (MV3) has been added to limit the maximum supply temperature of the DHW recirculation circuit of 50 °C, so that the thermal losses could be minimised if the ETS is operated for excess-charging the DHW. Moreover, the mixing valves MV4 at the WSHP condenser has been considered to control the inlet temperature at 45 °C during the DHW mode (30 °C during SH mode), limiting the destratification process that occurs at each turn-on of the WSHP. The latter is a single-stage unit with a capacity of 23 kWh connected to an insulated buffer for space heating (SH) or space cooling (SC), with a capacity of 0.375 m 3 that satisfies the common requirement of heat pump manufacturers to have a buffer capacity of about 15 ÷ 20 L/kWh of the heat pump. Moreover, a DHW TES system is needed to cover the peaks in the DHW demand, and its size has been determined following the parametric analysis presented in the next section. The ETS satisfies the energy demands of a small multi-family house with five floors and two apartments per floor located in Rome. The specific DHW demand has been estimated at 24 kWh/m 2 per year, and it has been created by generating the draw-off profile with the software DHWcalc V.2.02b [27] with a time step of one minute, considering an occupancy level of 2 people/apartment and the specific hot water demand of 40/l (person/day). The time step used in the simulation is one minute to achieve a high resolution and a realistic temperature profile inside the thermal energy storage tanks by satisfying the maximum volume change ratio in one time step for each node of the modelled tank. The TRNSYS types used are type 927 of the TESS library to model the WSHP using a performance map validated with laboratory tests, as described in the next section; type 110 to model the variable speed hydraulic pumps and type 534 of the TESS library to model the DHW TES and the space heating/cooling buffer; and type 11f, type 11h, and custom type 843 to model both diversion valves and mixing points. The 5GDHC network itself has not been modelled, and it has been considered as an ideal heat source that always supplies the ETS at a constant temperature of 15 °C. The investigation of the 5GDHC network, as well as the optimal sizing of the 5GDHC ETS, is out of the scope of this work.
The other activity carried out in parallel with modelling consists of laboratory tests under steady-state and stress conditions at the Energy Exchange Lab. The steady-state tests were performed with nominal constant flow rates, operating the WSHP both at a constant inlet temperature at the evaporator and varying the inlet temperature at the condenser and vice versa. In particular, the inlet temperature at the condenser was varied with steps of 5 °C between 30 °C and 55 °C, whereas the inlet temperature at the evaporator was varied with steps of 2.5 °C between 10 °C and 20 °C. Stress tests were carried out to identify the real operation limits of the WSHP to avoid that the compressor stops its operation due to some alarms that would require a manual reset. In fact, some of these could arise if the advanced controller operates the WSHP in a different way compared to the standard operation by excess charging the thermal energy storage at a very high temperature. In the next section, it will be presented how the laboratory test results were used in this study to validate the ETS model.

Physical Model Calibration, WSHP Limits, and Parametric Simulations on the Thermal Energy Storage System
The key performance indicators (KPIs) used for model calibration and validation have been suggested by ASHRAE Guideline 14 [52] and adopted in general for building energy simulations, like in Harmer and Henze (2015) [53] and in Ruiz et al. (2017) [54]. Considering , the jth output variable of the system under study, a weight associated with the jth output variable, samples of a generic output variable and the measured values of the variable , and the simulated values of the variable (obtained from a system model providing the same measured inputs), the KPIs considered are the normalised mean bias error for the variable ( ), the coefficient of variation of the root mean square error for the variable ( ), the goodness of fit of the NMBE for different variables ( ), and the goodness of fit of the CVRMSE for different variables ( ), according to the Equations (1)-(4). The total goodness of fit ( ) in Equation (5) was obtained considering the weights 1.

∑
, , • 100 % (1) In this study, the WSHP has been modelled by means of a performance map in the form of a look-up table using type 927 of the TRNSYS TESS library. This model, after reading the inlet temperatures and flow rates as inputs, provides as outputs the outlet temperatures and electrical and thermal energy flows at the evaporator and condenser side of the WSHP, which are the results of linear interpolation in a specified range. The performance map adopted was derived from previous laboratory tests on a similar WSHP with the same refrigerant R410A [55], and the linear interpolation coefficients were reassessed. Moreover, the performance map was normalised with respect to the WSHP capacity so that it can be used for machines with different sizes. These normalisation parameters are the rated heating capacity ( , * ) and the rated electricity capacity in the heating mode ( , , * ), which the calibrated values were found with an exhaustive parametric search using half of the lab dataset.
The results of the calibration are reported in Figure 1; on the left, with the NMBE vs. CVRMSE plot for the different outputs of the WSHP model and, on the right, with the vs.
plot, calculated according to the equations presented above. The circled point in Figure 4b is the one with the lowest values of the equal to 2.6%, which corresponds to , *

and
, , * 4.08 . The rest of the dataset was used for validation purposes, whose results are shown in Figure 5, where the outputs of the calibrated WSHP model are plotted and compared with the measured quantities. In Figure 5a, the agreement of the outlet temperatures at the evaporator ( , ) and at the condenser ( , ) during the two tests in the heating mode is shown, assuming a constant inlet temperature at the evaporator ( , ) and constant inlet temperature at the condenser ( , ), respectively. In Figure 5b, the corresponding thermal power at the evaporator ( ) and condenser ( ), as well as the electricity consumption ( ), are shown. It can be noticed that the simulated profiles fall within the measurement uncertainty band (in grey) in almost all operating conditions. The fluctuations of the measured thermal power quantities are because of the effects of the control system during the laboratory tests.  Beyond the steady-state tests, additional stress tests were performed to identify the real operation limits of the WSHP in the heating mode using water in all the circuits. For this reason, starting from four extreme operating points (A, B, C, and D) of the standard operation map in the heating mode (referred to as ΔT = 5 °C on both the evaporator and condenser side, as reported by the manufacturer) shown in Figure 6a, these tests were performed to achieve different temperature differences on both the evaporator and the condenser side. This was possible by varying the volumetric flowrates within the ranges achievable at the lab: a minimum of 1.8 m 3 /h and a maximum of 3.5 m 3 /h at the evaporator and a minimum of 2.2 m 3 /h and a maximum of 4 m 3 /h at the condenser. In particular, the operating condition of points A and B could represent the ones of a WSHP supplied by a low-temperature source, like groundwater, respectively, in SH and DHW modes. Similarly, points D and C represent the operation of a WSHP supplied by a high-temperature source. The main results of the stress tests can be summarised as follows:


The outlet temperature at the evaporator ( , ) must be higher than 4.9 °C to avoid a freezing alarm. This critical condition can be reached during the WSHP operation around points A and B of Figure 6a.  The outlet temperature at the condenser ( , ) must be lower than 57.3 °C to avoid an alarms for refrigerant high temperature (max 118 °C) and high pressure (max 40 bar at the compressor outlet). This critical condition can be reached during the WSHP operation around points B and C of Figure 6a.
The coefficient of performance (COP) variation, together with the average temperature values for the different operating steady-state conditions, are shown in Figure 6b. Four operating conditions were explored around each extreme operation point (A, B, C, and D). As expected, the smaller the difference between the average temperatures at the evaporator and at the condenser (ΔTlift), the higher is the COP. Nevertheless, it is important to highlight that, at some operating points (D2, D3, and D4), the WSHP can operate with an inlet temperature at the evaporator that is higher than the inlet temperature at the condenser. Among the tests at each single extreme operation point (e.g., A1, A2, A3, and A4), a slight increase in the COP can be observed for tests in which the difference between the inlet and outlet temperature at the condenser is maximised. Finally, a parametric analysis has been performed on the 5GDHC ETS model to define the optimal size of the thermal energy storage system to meet the DHW load satisfying the user´s comfort and to assess the optimal height of the temperature sensor used to control the DHW TES. This was done to verify the impact of thermal energy storage capacity exploitation by the MPC controller, together with the operational limitations of the WSHP, such as the maximum outlet temperature at the condenser, as mentioned above. The analysis was performed considering a control based on a hysteresis rule that has a fixed lower bound of 45 °C and a variable dead-band that has been varied.
The overall values of the parameters that have been varied one at a time are:  four values for the relative height of the sensor used to control the thermal energy storage temperature, as shown in Figure 7, and identified with a letter (A = 20%, B = 40%, C = 60%, and D = 80%);  two values for the DHW TES volume identified by a number that follows the letter, equal to 0.5 m 3 (1) and 1 m 3 (2), respectively; and  three values for the dead-band of the hysteresis implemented in the rule-based control that was fixed equal to 5 °C (1), 10 °C (2), and 15 °C (3).
For instance, case C2.2 represents the case where the sensor position has been fixed at the 60% (C) of the thermal energy storage total height, the thermal energy storage has a volume of 1 m 3 (2), and the hysteresis band is equal to 10 °C (2), so that, during a charging process, the temperature of the sensor is increased from 45 °C to 55 °C. This is the final solution adopted for the development of the reduced order model (ROM) of the substation as a conclusion of the results presented in Section 3.1 obtained by assessing the following KPIs:


% that aims at evaluating the fraction of time when the DHW tap water has a temperature below 44 °C with respect to the total draw-off period, according to Equation (6). It allows verifying whether the boundary conditions concerning the thermal energy storage capacity and control settings satisfy the user's comfort.  , and , , which are the average thermal energy supplied by the WSHP to the DHW TES and average electricity consumption per single charge, calculated as the yearly energy quantity divided by the yearly number of on-off cycles, according to Equations (7) and (8) , , ,

ANN Model and Training Algorithm
In this work, the advanced controller were implemented in LabVIEW in the form of artificial neural network-based model predictive control (ANN-MPC). A literature review of this application for HVAC systems can be found in Afram et al. (2017) [56]. Here, ANNs were used for a prediction problem by creating a reduced order model (ROM) of the 5GDHC ETS for smart charging of the DHW TES system. The benefits of such kinds of ROMs include the fact that the data-driven approach allows for building simplified models, even with the same architecture, that can be connected in a bottom-up approach neglecting some less-important variables. Moreover, using real-time data of the system, the ANN can be retrained periodically, unlocking the "adaptative" potential of such kinds of control solutions and reducing the deviations between the boundary and operation conditions and the one considered in the design phase. This reduces the effects of the mismatch between the design model and the current operation of the system on the controller performance.
However, such models need a large amount of training data and a tool for raw data collection and preprocessing together with a training algorithm to periodically update the model. Compared to white-box physical models, ANNs are a form of black-box models that exhibit the advantage of low computational effort when running simulations. This can be very useful for running MPC algorithms in embedded systems; however, the results must be interpreted carefully, because they cannot be explained easily.
The ROM of the 5GDHC ETS was built in a modular fashion using the same ANN architecture to model each component: one for the WSHP and one for the DHW TES. This ANN architecture is based on a nonlinear autoregressive network with exogenous inputs (NARX), also called "dynamic" or "recurrent" ANNs, because they have a feedback loop that provide "memory" capabilities typical of dynamic systems; here, a tapped delay line (TDL) of one time step is used so that the model outputs at time t depend not only on the inputs at time t but, also, on the model inputs and outputs at the previous time step t−1. The network structure includes one hidden layer with 15 neurons, as well as the tangent-sigmoid and the linear activation functions in the hidden and output layers, respectively. Due to the good performance observed, reported in the next section, an optimisation of the ANN features has not been performed in this work. The variables considered as inputs and outputs of the ANN models are: is the thermal energy delivered by the on-off WSHP to the DHW TES in one control time step (4 kWhth) and represents the control input * provided according to the results of the MPC algorithms during the on-line simulation (see Section 2.5). are the outputs. The ambient temperature of the room was not used as the input, since it is not commonly monitored in the mechanical room where the ETS are installed; here, it has been assumed constant and equal to 15 °C. The recurrent ANN models were implemented in LabVIEW, creating a dedicated objectoriented class for regression or prediction problems. The training algorithm adopted is a heuristic modification of the traditional backpropagation algorithm that includes a variable learning rate α that is adjusted during the course of the training. Network training is performed in an open-loop mode; i.e., since during the training, the target values are available, there is no need to feed back to the ANN input the estimation of the output, instead providing accurate inputs to the model directly from the training dataset.

ANN Model Training and Validation Results
The two ANN models of the WSHP and DHW TES system were trained by using the results of 20 days of numerical simulations from the TRNSYS calibrated model. The dataset time resolution is 10 min, which is the same as the control time step at which the MPC solves the optimisation problem and provides the on-off signal. This choice has been adopted according to the information reported in Curtis and Pine (2012) [57], who claim that it is important to avoid short cycling conditions for heat pumps by setting a minimum off-time between 6 and 10 min and a minimum runtime of 10 min. The first is useful so that, after a prior run, the refrigerant pressures in the heat pump are re-equalised, avoiding a restart of the compressor under high-pressure and high-temperature conditions. The second allows maintaining an adequate level of lubrication of the compressor that is compromised if there are short runtime periods, because the oil is transported out of the compressor by the refrigerant and could be trapped in the refrigerant circuit, leading to potential damage at the following starts.
The training dataset from the numerical simulations was created using a rule-based controller (RBC) for the DHW operation, trying to allow the ANN models to explore a wide range of operation conditions. Both the implementations of the RBC and MPC controller are explained in the next section. Creating such a large training dataset was not done with laboratory tests, because it would be very expensive. The performance of the ANNs models was assessed by evaluating the KPIs listed in Equations (1)-(5) for the ANN outputs vs. the target values by using a validation dataset of 24 h (144 time steps of 10 min) that has not been used for training purposes and are shown in Figure 9. Different from the training phase, the model validation is performed in a closed loop fashion of the NARX process feeding back to the ANN inputs errors in the estimated outputs at the previous time step t-1. The KPI results listed in Table 1 show that a high accuracy is obtained in the prediction of the WSHP electricity consumption ( , , ) and thermal energy extracted from the DHC network at the evaporator ( , , ). The ANN model for the DHW TES results in a somewhat lower accuracy with respect to the WSHP model; nevertheless, the NRMSE for both of the two outputs, the temperature at the top ( ) and at the bottom ( ), are below 5% over a simulation time of 24 h.

MPC Implementation with an RBC Back-Up Controller and TRNSYS-LabVIEW Dynamic Link Library (DLL)
Model predictive control (MPC) is an emerging control technology that has been used since the 1980s in the chemical process industry. Nowadays, its implementation with HVAC systems is mainly devoted to large commercial and institutional buildings that employ building energy management (BEM) systems, as shown in the literature review of Afram and Janabi-Sharifi (2014) [58]. Other MPC implementations of heat pumps and chiller-based systems coupled with thermal energy storage are presented in Kajgaard et al. (2013) [59], Henze et al. (2004) [46], and Yudong Ma et al. (2009) [60]. Moreover, MPC has been studied in the context of a low-temperature district heating network in Vivian et al. (2017) [61] and in Knudsen and Petersen (2017) [62]. MPC employs a model of the process whose identification is usually demanding in terms of effort depending on the complexity of the process or the model fidelity to achieve. By performing real-time simulations, this model is employed to make a prediction of the future outputs of the process according to a sequence of future inputs that one would like to apply. In this study, MPC is implemented according to the block diagram of Figure 10 to solve a constrained optimisation problem in real-time at each control time step (10 min)-hence, to find the best sequence of control actions ̅ * that minimises (or maximises) a given performance index over a time window. Only the first element * is applied to the plant at the current time step , discarding the rest of the control action sequence. In this study, the so-called receding horizon control approach is applied, consisting of a shift of the time window forward at each control time step where, once the new measurements have been acquired and the state of the model is updated, the optimisation problem is solved again. Moreover, a blocking technique is applied in a way that the control horizon (M) is shorter than the prediction horizon (N) to reduce the effort in solving the optimisation problem. For this work, the prediction horizon is equal to 180 min (N = 18 time steps), and the control horizon is equal to 60 min (M = 6 time steps); since the length of the control action sequence vector ̅ * is less than the number of time steps in the prediction horizon (M < N), the last value of ̅ * is maintained constant for the rest of the simulation.
MPC can be employed both as a low-level (slave) or high-level (master/supervisory) controller. When MPC is operated in a supervisory fashion, it is a common practice to implement it with the objective being to minimise the operating costs of the system. For this reason, this kind of solution as adopted here is usually referred to as economic model predictive control (EMPC). Due to the nonlinearities of the ANNs, a different solution from traditional hard-computing MPC implementation was applied to solve the optimisation problem. In fact, in this study, the binary form of the particle swarm optimisation (PSO) algorithm proposed by Kennedy and Eberhart (1997) [63] is used, as it is suitable for this kind of application of solving multi-objective optimisation problems with low computational times [56]. Moreover, a similar use was performed in Amarasinghe et al. (2015) [64] and in other HVAC applications, as reviewed in   [65]. PSO is a metaheuristic algorithm that belongs to the field of swarm intelligence, biologically inspired by the collective behaviour of species like birds (flocking) and fishes (shoaling and schooling). The algorithm, derived from the "perturbed PSO" [66] available in the Advanced Metaheuristics Algorithms library implemented by Derouiche M. L. (2015) and available at [67], is implemented in such a way that a population of interacting agents directly search for the minimum of the cost function in a multidimensional domain with no information about its gradient (unknown environment).
As mentioned above, the MPC application presented in the following covers a power-to-heat operating strategy controlling the WSHP of the 5GDHC ETS. The constrained optimisation problem aims at minimising the operating costs of the ETS over the prediction horizon with N time steps ( , … , , … , ). For this reason, the terms reported in the cost function in Equation (9) considers the electricity consumption of the substation , , , the specific cost of electricity , the thermal energy supplied by the 5GDHC network to the substation , , , and its specific cost , . The last term of the objective function considers a "state change cost" to minimise the on-off switching events of the heat pump that are a cause of inefficiencies, as well as electrical and mechanical stresses, of its components. The problem constraints consider having the minimum temperature at the top of the DHW TES higher than 45 °C to satisfy the user´s comfort (Equation (10)) and the maximum temperature at the top of the DHW TES lower than 55 °C to satisfy the operating limits of the WSHP, as shown from the stress tests results above (Equation (11)). , , , ,,

°
, 55 ° Referring to the block diagram in Figure 10 (bottom), the MPC implementation consists of a matrix of variables that are computed externally, like the DHW load perfect prediction, prediction of the DHC network supply temperature, and profiles of the electricity and thermal energy prices over the prediction horizon. The output of the optimisation algorithm is a binary vector that considers the different trajectories of the WSHP on-off state and allows directly evaluating the "state-change cost". Nevertheless, to be compatible with the input required in the ANN model implementation, the on signal is expressed as the average thermal energy that the WSHP is able to provide to DHW TES in one control time step of 10 min, equal to 4 kWhth. Finally, since the bound constraints of Equations (10) and (11) have been implemented by applying the external static penalty technique, as in [68], and adding this to the rest of the cost function , the top temperature of the DHW TES system, together with the electricity and thermal energy consumption, are all forecasted by the ANN model and are considered in the cost function evaluation section.
As shown in the block diagram of Figure 10 (top), a back-up controller is used to filter the MPC signal * . It consists of an RBC that includes two levels of hysteresis: one operating in parallel to the MPC, such that, if the top temperature of the DHW TES drops below 45 °C, it is charged up to 50 °C, and another hysteresis operating in series with the MPC so that, if the top temperature of the DHW TES exceeds 55 °C, the WSHP is disabled (bypassing the MPC on signal) and can be turned on only if it is below 53 °C. This has been adopted to make the overall controller more robust with respect to the soft-constrains implementation. Finally, there was the need to create a bidirectional communication between the MPC controller implemented in LabVIEW and the physical model in TRNSYS that has been used as the plant to test the controller. For this reason, a dedicated TRNSYS type has been programmed in C++ that gets inputs and provides outputs at each simulation time step to the MPC algorithm by means of a dynamic link library (DLL) programmed in LabVIEW.

MPC vs. RBC Scenario Boundary Conditions
To assess the MPC performance, a simulation test was performed for a period of 31 days (January 2017) coupling TRNSYS and LabVIEW by means of the DLL presented above. The study aimed at comparing a standard rule-based control (RBC) strategy applied to the ETS with the model predictive control (MPC) one presented above for the DHW TES management when a price variation of the electricity tariff was introduced. This was done according to a time-of-use demand response strategy based on the Italian tariff D1. Accordingly, the on-peak hours were defined as the period between 8:00 and 19:00 on workdays, while the rest were considered off-peak hours. The RBC operated by means of a hysteresis that was active when the DHW TES top temperature dropped below 45 °C and stopped the charging process when it reached 50 °C. Conversely, the MPC controller was capable of exploiting its prediction capabilities to optimise the ETS operation.
The guiding principle of the analysis is based on the following considerations introduced also in a previous publication [69]. Charging the thermal energy storage beyond the currently needed value introduces a drawback: the higher the temperature, the larger are both the drop of the WSHP coefficient of performance and additional thermal losses ( , . . For the sake of simplicity, by accounting only for the electricity cost as an optimisation parameter ( is in EUR/kWh), the thermal energy needed would cost , /COP during the peak hour when it is produced at the minimum storage temperature, while it would cost , , .
/COP when produced in advance at a higher temperature. To achieve savings in the electricity bill, the inequality of Equation (12) must hold. Rearranging it to Equation (13), it can be observed that there is a lower limit of the COP for the thermal energy storage excess charge process that depends on the electricity price ratio between off-peak hours and on-peak hours and the ratio between the additional thermal losses introduced with respect to the thermal energy produced ( ). Charging the DHW TES at higher temperatures is worthwhile only if the electricity costs ratio compensates at least the additional thermal losses introduced. Moreover, for 5GDHC ETS, the variation of the COP affects the weight of the electricity bill with respect to the bill for the thermal energy drawn off from the DHC grid, because the higher the COP, the higher the amount of thermal energy extracted by the WSHP at the evaporator.
The time-of-use demand response scenario analysis performed in this study is simplified to verify the effects reported above during the MPC (scenarios 1 and 2) with respect to a standard RBC (baseline) operation for charging the DHW TES. The conditions set have in common the same ETS plant and DHW load, while the economic boundary conditions are the following:


The price of the thermal energy extracted from the 5GDHC grid is considered constant and equal to 0.05 (EUR/kWh) for the different scenarios.  The electricity tariff during off-peak hours is considered constant and equal to 0.15 (EUR/kWh) for the different scenarios.  The electricity tariff during on-peak hours varies, and it is equal to 0.30 (EUR/kWh) for MPC scenario 1 and 0.60 (EUR/kWh) for MPC scenario 2.

Results and Discussion
The results of this study have been divided into two parts: in Section 3.1, the parametric analysis on the DHW TES system introduced in Section 2.2 is discussed, whereas, in Section 3.2, the performance of the system operated with an advanced control strategy is compared with respect to a rule-based one under different boundary conditions, as presented in Section 2.6.

Parametric Analysis on the DHW TES System
The cases analysed reported on the x-axis of Figure 11 and Figure  ) for the different cases. It can be observed that, for a given thermal energy storage volume, a higher height of the temperature sensor and a larger hysteresis band have the same effects in terms of a lower , , as well as , , , achieving a higher for the DHW operation. The variation of the thermal energy storage volume has almost no effect on these variables. In Figure 11b, the sensor height is compared with the discomfort percentage for the different cases. The results show that, for given values of the hysteresis band and thermal energy storage volume, the higher the position of the sensor, the larger is the % , because it results in a smaller hot volume of the thermal energy storage to absorb a peak in the DHW demand. For instance, in case D1.1, where a thermal energy storage of 0.5 m 3 is controlled with a hysteresis of 5 °C using the sensor at the top ( of 80%), for 37.3% of the draw off time, the tap water temperature is lower than 44 °C. This issue can be resolved in two ways: either by increasing the thermal energy storage volume or by increasing the hysteresis band, where the latter appears to have a larger positive effect on % reduction with respect to the increase of the thermal energy storage volume. The results shown in Figure 12a are referring to the average thermal energy supplied by the WSHP to the DHW TES ( , ) and average electricity consumption per single charge ( , ). Both increase by varying the hysteresis band or the thermal energy storage volume. Assessing the , is useful to understand the amount of electricity that can be consumed during a DHW charging process if the WSHP is operated as an equivalent electrical battery to provide load flexibility and resilience to the electricity grid.
Finally, the maximum hourly number of on-off switching events, reported in Figure 12b, is calculated in order to verify when it exceeds values suggested by the literature, identified as between 3 and 4 [57], to limit the low efficiency and component failure. In this context, case A1.1 is the worst, with a maximum number of hourly switching cycles equal to 14 due to both SH and DHW operation starts and the highest number of yearly switching events in the DHW mode. This is a consequence of the fact that the sensor used to control the DHW TES is located at the bottom ( of 20%) close to the pipe connection of the return pipeline of the DHW recirculation system. When a large DHW draw-off occurs in the apartments, the temperature in the return pipe of the DHW can be very low (~20 °C), causing an instantaneous turn-on of the WSHP in the DHW mode, even if the thermal energy storage is fully charged. For this reason, the installation of the temperature sensor at the bottom of the DHW TES must be avoided.
The best compromise to satisfy the different constraints described above is obtained for case C2.2, which assumes a DHW TES capacity of 1 m 3 , a temperature sensor position at a height of 60%, and a maximum range in controlling the thermal energy storage temperature between 45 °C and 55 °C. Under these conditions, alarms for the high temperature/pressure of the refrigerant are avoided, the % assessed is 2.2%, and a decent amount of energy can be stored in the DHW TES during a full charge

Results of the Rule-Based Control (RBC) vs. Model Predictive Control (MPC) Scenario Analysis
The second part of the results section aims at comparing the MPC to RBC performance under the boundary conditions of the time-of-use demand response scenario presented in Section 2.6, where the electricity tariff variation occurs twice per day and only during weekdays, whereas the price of the thermal energy extracted from the DHC network is constant. The selected ETS configuration is the one of C2.2 (see Section 3.1), and the MPC operates to minimise the energy bill and "state change" of the WSHP according to the cost function of Equation (9). The prediction horizon has been set equal to 180 min (N = 18 time steps) and the control horizon equal to 60 min (M = 6 time steps). The results of this analysis are reported in Table 2 and Table 3, whereas the relative differences between MPC scenarios 1 and 2 with respect to the baseline (RBC operation) are shown in Figure 13. It can be observed that, for MPC scenarios 1 and 2, the advanced controller operates by charging the DHW TES more frequently with respect to the baseline scenario. In fact, the number of start-up signals ( ) of the heat pump in the DHW mode increases by about 57.4%, and 67.3%, respectively. Thus, it results, on average, in less thermal energy being provided by the heat pump to the DHW TES during a single charge with respect to the standard charging process of the baseline scenario. From the energy assessment reported in Table 2, on the one hand, it emerges that extending the ΔT range operation between 45 and 55 °C for extra charging of the DHW TES with the MPC controller results in a higher maximum temperature at the top ( , ) and average temperature ( ) of the DHW TES. This, in turn, affects the performance of the WSHP, with a drop in the coefficient of performance ( ) by about 3-4% for both MPC scenarios. As a consequence, both the electricity and thermal energy consumptions of the ETS coming from the electrical and thermal grids ( , , and , , ) increase. On the other hand, focusing on the electricity uses of the substation, it emerges that the larger the electricity tariff variation between off-peak and peak hours, the larger is the electricity load shifted from peak to off-peak hours. The reduction in the electricity consumption during peak hours ( , , , ) is about 10% for MPC scenario 1 and about 14% for MPC scenario 2, where a larger electricity tariff variation occurs. Nonetheless, the reduction of electricity consumption during peak hours is at the expense of an increase in consumption during off-peak hours ( , , , ) that is larger, because, during the MPC scenarios, the ETS operates at a lower . From the economic assessment reported in Table 3, one infers that there are no savings on the total utility energy bill ( ) in MPC scenario 1, while small savings are achieved in MPC scenario 2, since the savings obtained by the limited time-of-use price variation in MPC scenario 1 do not compensate for the additional energy consumptions due to the drop in the and additional thermal losses of the TES. In MPC scenario 2, it can be noticed that the situation is different. The onpeak electricity tariff is four times that of the off-peak hours. The has a reduction of 3.5% with respect to the baseline, which makes the MPC control slightly attractive with respect to a standard RBC control operation in terms of electricity costs, in addition to the load shift effect.

Conclusions
This work presents a detailed assessment on 5GDHC energy transfer station (ETS) operations, offering solutions for improving the management of the local domestic hot water (DHW) thermal energy storage (TES) system. The first implementation and test of an ANN-based model predictive controller (MPC) are discussed. This tool aims at unlocking the smart control of the 5GDHC ETS to cover the DHW load by exploiting the thermal capacity of the DHW TES. In this context, one of the main outcomes of the work is that a modular ANN approach can be a valuable solution for implementing an adaptive reduced order model of the ETS that could be periodically retrained with monitoring data, reducing the mismatch between the design and real control conditions. Furthermore, a test presented in this study deals with the energetic and economic performance assessments of the 5GDHC ETS, comparing its operation under a model predictive control (MPC) strategy with respect to a standard rule-based control (RBC). Different scenarios were analysed considering different electricity prices, and the results show that excess charging of the thermal energy storage leads to a drop in system performance due to a lower COP and higher thermal energy losses that are not always compensated economically by the savings achieved due to smart-charging the thermal energy storage during off-peak hours. In fact, the MPC is able to offer economic savings of about 3.5% (over a period of one month) on the total utility energy bill only when the electricity price during on-peak hours is four times the value at off-peak hours. However, it is important to point out that these results were obtained under specific boundary conditions where the electricity tariff variation occurs twice per day and only during weekdays and under the assumption of a perfect prediction of the DHW load.
Further research is needed to evaluate the performance under real-time pricing (RTP) and other demand response programs, larger prediction horizons, the extension of the smart control to a pool of substations, and assess the optimal architecture of the ANN models. It is important to highlight that, in this study, the MPC operation contributes to shaving the electricity peak-load up to 14% by shifting demand to off-peak hours with a constant supply temperature of the 5GDHC network. However, conversely from air-source heat pump system applications, the supply temperature of a 5GDHC system can be considered an additional variable that can be manipulated by the DHC operator to further gain elasticity in pooling 5GDHC substations to participate in demand response programs. This kind of energy flexibility and resilience provided by advanced control are additional benefits that will become increasingly important under high-penetration scenarios of distributed renewable energy resources where 5GDHC systems could cooperate with power grids in decentralised smart energy systems.
Author Contributions: S.B.: conceptualisation, data curation, formal analysis, investigation, methodology, software, validation, visualisation, and writing-original draft. A.S.: conceptualisation, software, and resources. M.P.: data curation, investigation, software, validation, and resources. G.H.: conceptualisation, supervision, and writing-review and editing. R.F.: conceptualisation, supervision, writing-review and editing, and funding acquisition. All authors have read and agreed to the published version of the manuscript.

Funding:
The research leading to these results has received funding from the European Union's Horizon 2020 research and innovation programme, under Grant Agreement 857811, Renewable and Waste Heat Recovery for Competitive District Heating and Cooling Networks-REWARDHeat.

Conflicts of Interest:
The authors declare no conflicts of interest.