Design and verification of an effective state‐of‐charge estimator for thermal energy storage

Thermal energy storage (TES) is widely used in district heating and cooling systems (DHCS) to act as a buffer between the supply and demand schedules. The adequate control of charging and discharging modes of TES may improve the overall performance of a DHCS and, to this end, an effective regulation of its state‐of‐charge (SoC) is required. However, the calculation of SoC depends on the availability and accuracy of temperature measurements. A model‐based observer for the calculation of the SoC of water‐based TES tanks is presented. A dynamic model of a one‐dimensional stratified water tank is adopted to develop the observer. Its effectiveness is assessed through ‘model‐in‐the‐loop’ cosimulations, with the observer and the feedback control system being implemented in MATLAB/Simulink and a high‐fidelity water tank component available in Apros being used as the plant model. Simulation results considering three different system configurations demonstrate that the model‐based observer accurately estimates the temperature distribution within the tank, leading to an effective SoC computation and control—even in the case of sensor failure or upon limited sensor availability.


| INTRODUCTION
The mismatch between the low-cost generation and the peak demand of thermal energy and the large distances between the supply points and the thermal loads are two important challenges faced bydistrict heating and cooling systems (DHCS). To address these issues, thermal energy storage (TES) is used to act as a buffer between supply and demand schedules. TES provides flexibility and improves the performance of a DHCS as it may act as a sink when excessive thermal energy is available during minimum loading, and then operate as a source when additional energy is required during peak loading-whilst meeting the thermal demand of the consumers [1].
Different energy storage media may be adopted for TES systems, but they are mainly classified as latent heat or sensible heat materials. Latent heat-based TES systems consist of a container enclosing a phase change material (PCM) acting as a storage medium and a heat exchanger surface for transferring heat to and from the PCM. A PCM is a substance that releases or absorbs heat, known as latent heat, when phase change occurs. Change in phase takes place at a constant temperature [2] and such a transition can range from solid to liquid, liquid to gas or vice versa. Transition from a solid state to another solid form is also possible-e.g. by the change from a crystalline form into another one [3].
Sensible heat-based TES systems consist of a container inside which the storage medium is placed, but no phase change is present. The amount of thermal energy stored during the system's charging process is dependent on the density, specific heat capacity, volume and the type of the storage material [4]. Water is typically used as the storage medium as it can easily transport thermal energy throughout the DHCS. The use of water/ice as a PCM for latent heat-based TES systems is also common [5].
Three-dimensional (3-D) dynamic models using computational fluid dynamics are used to accurately describe the spatial thermal behaviour within a TES tank [6]. A common modelling approach is thermal stratification, where horizontal layers are defined throughout the height of the tank to represent temperature differences in the storage medium [7][8][9]. Stratified 3-D models are capable of precisely matching results obtained experimentally, at the expense of increased modelling complexity and computational times [10]. However, onedimensional (1-D) models may significantly reduce the computational effort [11,12]. In a 1-D stratified model, a storage tank is also represented by horizontal layers, where the storage medium may exhibit a different density at each layer due to temperature variations. Each layer is modelled by a differential equation based on the law of conservation of energy [13].
Despite their simplicity, stratified 1-D models have the capability to accurately represent the dynamic behaviour of TES. For instance, the charging process of a stratified TES tank, alongside analytical solutions, is presented in [6]. A stratified vertical cylindrical model of a cold store, considering heat conduction, is analysed in [1,14]. In [15], a smooth continuous function is used to dynamically model the buoyancy associated with charging and discharging processes, with real data being employed to validate a tank model. A horizontal cylindrical model is experimentally validated in [16], with thermal conductivity and heat loss being considered. Adaptive grid models are developed and validated experimentally in [17,18], where finely spaced grids are used in the vicinity of the temperature gradient instead of using fixed equally spaced grids. A diffusivity factor to quantify the turbulent mixing of the flow is presented in [19]. With the aid of experimental data, [20] demonstrates that reduced models of water-based TES tanks for heating applications, including 1-D representations, exhibit sufficient accuracy.
Control systems are fundamental to maximise the performance and efficiency of charging and discharging processes of TES, with suitable mathematical models needed for an effective control system design. In a water-based tank, the control system is normally designed to regulate the mass flow rate of the water entering the tank to achieve desired temperature references [13,21]. Accurate temperature measurement is thus essential to guarantee the system's performance. Given that the location of temperature sensors is usually alongside the tank's height, the stratification modelling approach is ideal to understand the data captured by each sensor. However, knowledge of the state-of-charge (SoC), rather than temperature information only is necessary for the effective energy management of TES. Effective SoC monitoring would enable operators to understand the short-term capability of the TES tank and establish how much longer it would be useful before recharging is required.
For SoC estimation in water-based TES tanks, existing references make use of the enthalpy (or specific heat) and the mass of the water in each layer to calculate the total energy in the tank, but this requires temperature information at any moment. Although the SoC computation would be more accurate as the number of layers increases [22], a limited number of temperature sensors is deployed in real systems. In turn, any sensor failure would prevent a useful SoC calculation, leading to inefficient performance.
To bridge the aforementioned gaps, this study presents a model-based observer for the accurate calculation of the SoC of sensible heat-based TES tanks. To this end, a 1-D stratified dynamic model of a water-based TES tank is adopted. The observer is designed to accurately estimate the temperature at different horizontal layers, leading to an effective SoC computation-even in the case of sensor failure or for limited sensor availability. The observer model has been implemented in MATLAB/Simulink and a 'model-in-the-loop' (MiL) simulation method has been adopted to perform cosimulations with Apros-a commercial software where high-fidelity mathematical models of real DHCS's components are available. Simulation results considering different system configurations are shown to demonstrate the effectiveness of SoC calculation.

| STRATIFIED 1-D MODEL OF A WATER -BASED TES TANK
The operating temperatures in a heating network fluctuate between 55°C and 95°C [23]. This implies that if water is selected as the storage medium, its phase does not change and a sensible heat-based TES tank can be adopted. A stratified 1-D model of the water tank is used, with Figure 1 showing an example for a tank stratification into five layers and its operation within a DHCS [13,21]. The heat produced by the combined heat and power (CHP) unit is managed by a pump system to coordinate the filling of the tank and the amount of heat supplied to a thermal load. For a charging process, the system collects hot water through the top of the tank and, for discharging, cold water through the bottom. It is assumed that the tank is fully charged when the temperature in all layers is 90°C and, conversely, fully discharged when the temperature in all layers is 60°C.
The modelling approach used is based on the law of conservation of energy and has been borrowed from [18]. The mathematical representation of the tank is constituted by nonlinear dynamic equations, where the thermal conductivity of water is neglected as its effect on the general system performance is insignificant [13] Schematic of a five-layer water-based TES tank for operation in a DHCS [13] MORALES SANDOVAL ET AL.
Simulations are conducted to provide confidence in the TES tank model described by Equations (6)- (8). The model is implemented in MATLAB/Simulink, with simulation results compared with those obtained using an existing water tank component available in Apros. For a simple yet representative comparison between the two software engines, the MATLAB model has been stratified into five layers (n = 5) and, for consistency, the number of calculation nodes selected in the Apros tank element has been set as 5 as well. This way, a calculation node in the Apros tank represents a stratified layer in the model. For simplicity, the tank's performance is assessed under a step variation of mass flow rate input without any controllers being implemented. Figure 2 shows a screenshot of the water tank simulated in Apros. As it can be seen, a temperature sensor for each calculation node is available (see the temperature measurements at the left-hand side of Figure 2). Table 1 shows the dimensions of the tank and the initial conditions.
Simulation results are shown in Figure 3. As it can be observed, there is a good agreement between the results obtained in MATLAB and Apros.
Note: It should be highlighted that the comparison presented in this section has been included to provide confidence in the effectiveness of the modelling approach. This has been achieved by demonstrating that the mathematical model described by Equations (6)-(8) offers similar results as those from a commercial software package. Although a large number of stratified layers as in [17,18] would describe more faithfully the internal thermal behaviour of the tank, such as an increased accuracy in the temperature variations along the tank's height would imply increasing the number of equations describing the models and, in turn, increasing the computation time (for both Apros and MATLAB). In addition, the design of the modelbased observer later presented in Section 3 for temperature estimation and, subsequently, SoC calculation, would significantly increase in complexity as the number of layers, and thus system states, increase. A five-layer water tank representation as shown in Figure 1 is sufficient to capture the required temperature information to estimate the amount of energy stored in the tank, with this number being consistent with the discrete number of temperature sensors deployed in practical TES systems [24,25].

| Limitations of the linear TES model for linear observer design
Linear time-invariant plant models are normally necessary to design effective linear control structures. However, the highly nonlinear dynamics of the TES system restricts the adoption of linear models for accurate temperature estimation. To examine this, let: be the state-space representation of the five-layer stratified TES tank shown in Figure 1. Both the system state variables and system outputs are the temperatures at each layer i (y i = T i = x i , i = 1, 2, …, 5) and mass flow rate _ m is the input of the system.
Thus, the state vector is defined as x ¼ ½x 1 ; x 2 ; …; x 5 � T , the output vector as y ¼ ½y 1 ; y 2 ; …; y 5 � T , the scalar input as u ¼ _ m and the control matrix as The output matrix C = I 5�5 is a 5 � 5 identity matrix and system matrix A is given as: Elements a mi , b mi , c mi and ΔT li of A and B depend on the operating mode of the tank. This is summarised as follows, where subindex '0' stands for initial conditions: Initial conditions should be obtained from specific equilibrium points, but the solution of Equations (6)-(8) is non-trivial. For instance, given that _ m ¼ 0 for equilibrium (i.e. for _ x ¼ 0), T i,0 may be arbitrarily chosen from an infinite number of solutions. System linearisation at such an equilibrium point yields: where 0 5�5 is 5 � 5 matrix with zero entries. The output equation of the state-space representation remains as in Equation (10). From Equations (10) and (12), it can be observed that the linearised model is valid only for a very small range of operation as the initial temperature differences ΔT li inside the tank may vary significantly. Furthermore, for fully charged or fully discharged conditions (i.e. all initial layer temperatures are either 90°C or 60°C, respectively), null dynamics for four of the five layers would arise.
It can be emphasised that even when linear controllers designed using linearised models may offer a good performance [13,21], the high non-linearity of the TES system makes the design of a linear observer for adequate temperature estimation (and ultimately SoC calculation) unfeasible.

| Limitations of the non-linear TES model for the observer design
The non-linear state-space representation of the TES system has the form [26]. Initial temperatures (T 1 , T 2 , T 3 , T 4 , T 5 ) 60°C

F I G U R E 3 Comparison of results obtained with MATLAB and Apros
MORALES SANDOVAL ET AL.
where A and C are the linear system and output matrices obtained from system linearisation at _ m ¼ 0 (as discussed in Section 3.1) and B(x, u) is a matrix whose entries depend on the temperature of the layers and on the operating mode of the system (defined by x and u, respectively). For the five-layer stratified TES tank, The pair (A, C) defines the observability of the system [27]. Given that A in Equation (12) is a null matrix and C in Equation (14) is an identity matrix, the system is fully observable only when all output variables are measuredotherwise the observability matrix would not be full rank and, thus, it would not be possible to estimate all the states. Additionally, any given state variable x i can be observed only through its respective output y i ; that is, the observer would offer redundant information as it would estimate variables being directly measured (since y i = T i = x i ).
The aspects above pose important design limitations. As there may be a limited number of sensors within a TES tank, this may lead to not having access to the necessary outputs of the system to adequately estimate state vector x (i.e. layer temperatures) for an effective SoC calculation.

| Non-linear model-based observer design
Consider the discrete Luenberger observer structure [26] shown in Figure 4. Mathematically, this is described by: where k stands for the discrete instants of time for which the system is solved, b x½k� and b y½k� are the estimated state and output vectors at k, respectively, and L is a matrix of appropriate dimensions with scalar gains as entries.
The estimation error e e½k� and the error dynamics e e½k þ 1� are given by, respectively, From Equation (19), the observer dynamics are asymptotically stable if A − LC ð Þ is asymptotically stable [26] as the non-linear matrix B e x ½k�; u½k� ð Þ in Equation (16) is bounded from T c to T h (notice in Equation (15) that as the states tend to these temperatures, matrix B x; u ð Þ becomes null). Equations (16) and (17) can be rewritten as: where and vector U[k] contains the inputs of the observer: For the five-layer water-based TES tank, assuming it is equipped with sensors for each layer, the input vector of the observer becomes, Matrix L in Equation (22) is a 5 � 5 matrix determining the poles of the observer. Thus, if the eigenvalues of L are on the left-hand side of the s-plane, then the observer is stable. From the observability analysis of the system presented in Section 3.2, since each state variable x i can be observed only through its respective output y i , L has the form: F I G U R E 4 Nonlinear Luenberger observer for the TES system

-
where 'diag' implies that L is a square matrix with entries l i in the main diagonal and, since A = 0 5�5 and C = I 5�5 , From Equation (28), if the coefficients of L are all positive, the observer will be stable. Given that the dynamics of a thermal system such as a TES tank are sufficiently slow (as shown by the simulation results in Figure 3), all the observer eigenvalues can be set at −0.1 rad/s for a convergence time of around 20 s.
For a five-layer TES tank considering only two sensors at the top and at the bottom layers, the input vector of the observer is: For such a configuration, it would only be possible to directly observe the temperatures at the top and at the bottom of the tank, that is x 1 [k] and x 5 [k]. However, the remaining states can be estimated using the nonlinear model of the system and by setting l 2 , l 3 and l 4 of L in Equation (27)

| Observer reconfiguration upon sensor failure
Reliability due to sensor failure is a possible scenario in any practical system. For the presented observer, sensor failure would imply the possibility of sudden changes in its input vector U[k]. Under a failure condition, leading to unavailability of temperature measurements, the elements of matrix L would need to be expressed as a function of the nonzero elements of y[k]. In other words, where

| Control of the TES tank based on its SoC
As mentioned in Section 1, the total energy available in a water-based TES tank is typically calculated using the mean value of temperature alongside the tank's height and the mass of water [23]. The temperature in each layer i is used to compute the energy available in the layer using U i = m i h i (T i ), where m i is the mass of water in the layer and h i is the specific enthalpy of water at temperature T i . The total energy U st [ J] in the tank would be obtained by adding the energy of all layers. U st would be available at any moment if the temperature of the layers is monitored continuously. The SoC calculation adopted makes use of the available temperature measurements. The SoC operation range is defined using the minimum to maximum possible temperatures of the stored water. For instance, if the minimum temperature is 60°C, this corresponds to a specific enthalpy value of 251.18 kJ/kg and the TES tank is fully discharged (i.e. SoC = 0%). Conversely, the TES tank is fully charged (SoC = 100%) at a maximum temperature of 90°C and a specific enthalpy of 377.4 kJ/kg.
A feedback control scheme based on the SoC, as shown in Figure 5, is implemented. This makes use of the nonlinear observer presented in Section 3.3. The reference signal r % is a value between 0% and 100% corresponding to the SoC previously defined. Look-up tables are used to convert the reference SoC (r % ) to a given specific enthalpy reference r h and subsequently to a given temperature reference r T suitable for the TES model. The mean value of the temperatures estimated by the observer is used as the feedback signal of the control system.
From the state-space representation of the TES system in Equations (10) and (12), a transfer function between the average temperature of the tank layers T ave ¼ T 1 þ T 2 þ ⋯ þ T 5 ð Þ=5 and the mass flow rate _ m is given as: where operator 'avg' implies that G(s) is the average of the transfer functions obtained from C sI − A ð Þ −1 B and, more explicitly, In Equation (33), the value of K ave depends on the mean value of the observer output (i.e. temperatures of the layers); that is, F I G U R E 5 SoC feedback control scheme of a TES tank using a nonlinear model-based observer MORALES SANDOVAL ET AL. -207 A proportional controller k p = 3.5 is chosen. Due to the system's high nonlinearity, the value of the proportional gain was determined empirically.

| MiL CONFIGURATION FOR MATLAB AND APROS COSIMULATION
Different software packages have been developed to simulate complex dynamics of real systems. These use powerful solver engines and may include libraries with high-fidelity mathematical models for a variety of components. Availability of specialised software tools and the adoption of a model-based design (MBD) approach have enabled the development of control, signal processing and communications systems without the need for expensive laboratory facilities including practical system components.
Following an MBD approach, the effectiveness of the model-based observer presented in Section 3 is demonstrated through the MiL configuration shown in Figure 6. The MiL simulation is carried out as a cosimulation using two software platforms, with the control scheme and the nonlinear observer being implemented in MATLAB/Simulink and a high-fidelity water tank representation available in Apros being used as the plant model. The link between the two software platforms is achieved via an open platform communication (OPC) protocol-widely adopted in automation and process control [28] and available in both MATLAB and Apros.
The OPC protocol is used to define the interface between clients and servers, allowing to access data in real-time [28]. Data exchange between MATLAB and Apros is shown in Figure 7. When Apros is launched, the OPC server is created and the protocol is made available. The variables generated in processes running in Apros can be then read and written by MATLAB using the OPC toolbox. For the model-based observer implemented in MATLAB, temperature values of the TES tank in Apros are read and mass flow rate is modified according to the output of the controller-also implemented in MATLAB.

| Simulation conditions
The effectiveness and performance of the model-based observer presented in Section 3 were assessed through MiL cosimulations (as described in Section 4) for charging and discharging cycles of the TES system. To this end, the tank's SoC is varied by introducing ramp changes in the reference signal r % [k]. The slope of the ramp is set to 1% (i.e. 1% of the total charging capacity every 100 s) to prevent sudden changes in mass flow rate.
The number of sensors for the five-layer stratified tank in Figure 1 is six (a temperature sensor per layer and one sensor for mass flow rate) assuming that the system is fully equipped. Resistance temperature detector (RTD) sensors are typically used in heat accumulators, with several types of sensors being available for flow metering. Although practical temperature and flow sensors provide accurate measurements with very low levels of noise (of up to 30 μ°C and around 0.01 kg/s, respectively) [29,30], a random signal error is introduced to test the system's tolerance to large measurement errors. The induced noise into temperature and mass flow rate signals generates metering errors of ±0.5°C and ±0.5 kg/s, respectively.
Three simulation scenarios have been considered. The initial layer temperatures of the TES tank in Apros and the initial operating point for the observer in MATLAB are assumed different. This is shown in Table 2. Additionally, while the observer considers initial hot and cold stream temperatures of T h = 90°C and T c = 60°C, for the tank component these temperatures are selected as T h = 88°C and T c = 60°C. This has been done to assess the effect of uncertainty in the charging and discharging of temperatures on the estimation of the temperature distribution alongside the water tank.

| Fully equipped TES tank
In this scenario, the TES tank features temperature sensors at each layer. For such a case, the observer input vector U[k] is described by Equation (26), where the input signal is u½k� ¼ _ m and the i-th output signal is y i [k] = T i [k]. A single charging and discharging cycle of the tank is simulated. Simulation results are provided in Figures 8-11. Figure 8 shows the performance of the SoC control scheme, where a comparison between the actual SoC calculated from the Apros data (SoC A , green trace), the estimated SoC from the observer data ( d SoC , blue trace) and the SoC reference signal r % (black trace) are presented. For completeness, the specific enthalpy (h A , b h, r h ) and average temperature of the layers (T ave,A , b T ave , r T ) are also shown. The system has an initial SoC of 55%. At the beginning of the simulation, the system is requested to reach 70% of SoC, charging the TES tank. After 3.3 h of simulation time, the system is requested to decrease its SoC to 45%, discharging the tank instead. As it can be seen, the accurate temperature estimation from the observer, together with the control configuration shown in Figure 5, enables an effective manipulation of the system's SoC during the charging and discharging cycles. It should be emphasised that the ripple exhibited in the plots produced from observer data (blue traces) arises from the measurement error considered in the temperature sensors (as mentioned in Section 5.1 and shown more clearly in Figure 9). Figure 9 shows the measured temperatures T 1 [k] to T 5 [k] inside the tank (top plots) and the sensed mass flow rate (bottom plot). Notice that all signals exhibit measurement error-as discussed in Section 5.1. As it can be seen, an increment in the value of the measured temperatures for all layers occurs from 0 h to 2 h into the simulation when the mass flow rate is positive (i.e. charging stage). Conversely, a decrement is presented from 3.3 h to 5 h into the simulation when the mass flow rate is negative (i.e. discharging stage). This is consistent with the SoC behaviour shown in Figure 8. It can also be noticed that all layers exhibit a different temperature given that the TES tank has not been either fully charged or fully discharged. Figure 10 shows a comparison between the estimated temperatures b T i ½k� obtained from the model-based observer and the actual temperatures T i,A [k] obtained directly from the TES tank in Apros. It can be noticed that there is a good agreement between these signals, with the slight differences arising due to sensor measurement error being considered (see the traces for T i [k] in Figure 9). For completeness, the estimation error e e i ½k� ¼ T i;A ½k� − b T i ½k� is shown in Figure 11. As it can be seen, all the estimated temperatures b T i ½k� quickly converge to the actual values T i,A [k].

| TES tank with reduced number of sensors
In this scenario, a limited number of sensors installed alongside the water tank's height are assumed. Compared to the previous scenario, temperature measurements at layers 2 to 4 are not available and, thus, U[k] is described by Equation (29); that is only the sensors for the top and bottom layers are considered. Several charging and discharging cycles of the TES tank are simulated, with simulation results provided in Figures 12-15. The performance of the SoC control scheme is shown in Figure 12. Changes in SoC are required in a range between 35% and 75%. As it can be seen, the actual and estimated SoC do not converge initially, restricting the tracking performance of the control system. However, the control performance improves after 7 h into the simulation, allowing to properly control the system's SoC. Figure 13 shows the measured temperatures at the top and bottom layers of the tank (top plots) and the measured mass flow rate (bottom plot). Although there are restricted temperature measurements due to the limited availability of sensors, the model-based observer is capable of estimating an accurate temperature distribution along the tank's height (see Figure 14) for the calculation of the system's SoC-as shown in Figure 12. Figure 14 shows a comparison of the estimated layer temperatures obtained from the model-based observer (red traces) with respect to the actual temperatures from the TES tank in Apros (black traces), while Figure 15 shows the estimation error. As it can be seen, the estimated temperatures b T 1 ½k� and b T 5 ½k� quickly converge to their actual value as there is a sensor present for these layers. However, estimation of temperatures for the intermediate layers without sensors, namely b T 2 ½k�, b T 3 ½k� and b T 4 ½k�, is slower. The initial estimation error at the middle layers restricts the tracking performance at the beginning of the simulation, which is consistent with the results shown in Figure 12. However, convergence is achieved for all estimated temperatures after 7 h into the simulation, with the estimation error becoming negligible.

| Sensor failure
In the third simulation scenario, a fully equipped tank with a temperature sensor per layer is considered, but the sensor failure is assessed. During the simulation, the availability of sensed signals T 2 [k], T 3 [k] and T 4 [k] is interrupted at different moments into the simulation. As a result, the configuration of U[k] progressively changes from Equations (26) to (29). Simulation results are provided in Figures 16-19. Figure 16 shows the control of the system's SoC as a percentage of total charging capacity, specific enthalpy and the average temperature. As in Section 5.3, several charging and discharging cycles of the TES tank are simulated, with SoC being modified in a range between 35% and 75%. As in the simulation with a fully equipped TES tank (Section 5.2), an adequate control of the system's SoC is achieved as a result of the accurate estimation from the observer-despite multiple sensor failure. Figure 17 shows the temperature measurements from the five sensors inside the tank (top plots) and the measured mass flow rate (bottom plot). As it can be seen, a disruption in the sensor signals for T 2 Figure 18 shows a comparison between the estimated temperatures obtained from the model-based observer in MATLAB and the actual temperatures from the TES tank in Apros. The estimation error is provided in Figure 19. As it can be seen, despite the disruption in three temperature sensors, the difference in initial temperature conditions, and the difference in the charging temperature between the observer representation and the TES tank, the temperature estimation quickly converges to the actual values. A good accuracy is maintained throughout the whole simulation.

| Brief discussion on the observer performance and limitations
The simulation results in this section demonstrate that the presented model-based observer accurately estimates the temperature distribution within a TES tank regardless of the availability of temperature sensors for the internal layers alongside the tank's height. As a result, this enables a good estimation of the system's SoC. This, in turn, allows an accurate control of the charging and discharging processes of the tank. The observer is capable of supporting the operation of the control system to achieve a good performance in case of sensor failure. However, it should be emphasised that sensor accuracy and the initialisation conditions represent critical factors for a reliable estimation.
A limitation of the observer structure presented is that temperature sensors located at the top and bottom layers of the tank are required for a good SoC calculation. These two temperature measurements are needed to guarantee the convergence of the intermediate states (estimated by the nonlinear model) to the actual values. Absence of such sensors would not be ideal, as in such conditions the temperature estimation for the top and bottom layers would directly depend on the temperatures of the hot and cold streams. Any uncertainty with respect to the stream temperatures may lead to a wrong estimation of the temperatures of the top and bottom layers and, in turn, may lead to a wrong estimation of the intermediate states-resulting in an inaccurate SoC calculation.

| On the uses and benefits of temperature and SoC estimators for TES in DHCS
Temperature sensing in DHCS has two main purposes: metering for customer billing and the control of different components (e.g. valves, heat accumulators, chillers, boilers, CHP units). Following a fault in a temperature sensor, the customer may be wrongly billed or may experience discomfort-for instance, due to a wrong supply temperature for space heating or cooling.
It has been estimated that the potential annual savings afforded by TES in district heating systems (DHS) can reach 5% of the total cost depending on the system configuration [31], with energy savings up to 1400 TWh in all Europe [32]. Additionally, annual heat losses due to a wrong supply temperature have been estimated at ∼10% [33]. From this perspective, improvements in the reliability of sensors and control systems may help reducing losses in DHS while increasing energy savings-thus decreasing costs. These beneficial characteristics may be likely exhibited by district cooling systems (DCS) and combined DHCS supported by TES as well, although to the knowledge of the authors, references in the open literature are yet to be made available.
RTD sensors, typically used in TES systems, have a failure rate of 110 failures per million hours. According to [34], a 3sensor system has a reliability of ∼38% in a year. This means that from every 100 components using a 3-temperature sensor system, 62 will present a failure once a year, and 31 failures may be related directly to the sensor or to analogue-to-digital converters. As the number of sensors increases, the probability of failure does as well. Relevant fault detection methods have been developed to reduce DHS downtime following failure of system components, thus minimising losses [33,35,36]. However, even when the system may still run with faulty sensors, problems remain.
The implementation of an observer for temperature estimation enables the control of a TES system with a reduced number of sensors, thus increasing its reliability. It also allows that in the case of sensor failure, the control system keeps working effectively while the failure is addressed. This may prevent comfort issues in end-users.
The control approach presented may also provide additional benefits to a practical system. The control system is based on the F I G U R E 1 8 Comparison of the estimated layer temperatures (in MATLAB, red traces) against actual temperatures (in Apros, black traces) for a fully equipped TES tank during sensor failure F I G U R E 1 9 Temperature estimation error in each layer for a fully equipped TES tank during sensor failure SoC, which provides a quantitative description of the total energy available in a TES tank within minimum and maximum temperature constraints. These constraints are defined at a DHCS level as the minimum and maximum operating temperatures. Even when SoC is not an essential requirement for conventional control strategies of TES systems [37], the control management of a DHCS is typically performed manually [38]. Therefore, the SoC provides the operator with a clearer view of the TES operating conditions at any time. This is particularly beneficial for short-term TES units, which are subjected to daily charging and discharging cycles, and whose control management considers changes in weather conditions [39]. In addition, the approach here followed may enable to optimise the operation of the TES system [40,41] and the automated control management of a DHCS by implementing model predictive control [42]however, this falls out of the scope of this study.

| CONCLUSIONS
Effective control systems are required to maximise the performance of charging and discharging processes of TES in DHCS. To achieve this, SoC monitoring is essential to understand the short-term capability of a TES tank and to establish how much longer it would be useful before recharging is required. Following this line, a method to calculate the SoC of sensible heat-based TES tanks has been presented. SoC computation is based on an observer that estimates the internal temperature of the storage medium (in this case, water) alongside the tank's height by making use of measurements from temperature sensors-which are usually provided by manufacturers.
A model-based observer structure making use of a 1-D stratified dynamic model of a water-based TES tank has been used. It has been shown that the adopted tank representation is sufficient to ensure a good observer performancecorroborated through comparisons with a water tank component available in the commercial software (Apros). The model-based observer configuration guarantees a good temperature estimation alongside the height of the water tank, resulting both in a simple temperature control scheme based on a proportional controller and in a reliable SoC calculation even for a limited availability of sensors or in the event of multiple sensor failure. Simulation results show a good performance of the control scheme, leading to an efficient TES charging and discharging processes-which could, in turn, result in an improved overall energy consumption of the system. An MiL configuration supported by the OPC communication protocol has been used. This has enabled real-time cosimulations between MATLAB/Simulink and Apros. Such a configuration has been instrumental to assess the performance of the model-based observer acting on a detailed and highfidelity representation of a water-based TES tank available in commercial software. The MiL configuration presented is useful for other applications where verified models of practical components are available but the possibility to conduct the experimental work is not an option.