In this section, the data model (information layer), the control optimization (functional layer) and the economical and ecological balancing (business layer) are presented to optimize the energy flexible operation of the HTS.

### Data model

To enable a flexible operation of the HTS, data need to be gathered, processed and stored. Therefore, a data model as shown in Fig. 3 is set up upon the basis of data interfaces, data analytics as well as a data storage. Data interfaces allow access to data of external systems like energy markets, weather services, the DHS or the EMS of the IESS e. g. via application programming interface (API). Data analytics allow for deeper insights into gathered data e. g. by linking different data to KPI or by applying more complex methods like data mining to detect patterns and trends. With regard to the IESS and HTS, this can be utilized to predict future thermal energy demands as well as identifying dependencies between efficiencies, temperature levels and thermal energy demands e. g. via regression analysis. For that, an efficient and reliable access to runtime and engineering data must be guaranteed by the data storage. Within the data storage, processed and unprocessed data is stored in a defined format to ensure its availability. By that, historical data can be accessed on demand e. g. for data analytics.

Due to the functional segregation of the data interface, analytics and storage the data model allows for an optimal interoperability. Depending on the specific application, the portrayed interfaces can be complemented on demand just as data analytics may show different levels of detail. As the KPI are a central feature of the data model, they exhibit a standardized pattern, e. g. specific prices or costs. Similarly, the KPI can be flexibly adjusted to the requirements of their application. With regard to resilience, missing or erroneous data can be compensated, e. g. via interpolation or boundaries.

The data model must process different kind of data depending on the data source (Fig. 3), e. g. environmental data such as weather conditions or energy prices for electricity or gas. Dependent on the electricity market, the price can be static or varying such as in dynamic pricing models. To operate the connection to the DHS, the data model of the HTS needs to incorporate thermal energy prices and revenues for procured or supplied thermal energy. Prices can be static but also variable, e. g. dependent upon temperature levels. Application specific characteristics must be considered by the data model as well. With regard to electricity, different taxes and remunerations must be taken into account, supporting key functionalities of the business layer. Additionally, data on emissions of the DHS and the maximal procured or supplied thermal energy for each time step must be known. In case of the HTS itself and the IESS these data can be technical runtime data such as network temperatures or thermal and electric power of HEX, energy converters and consumers. Moreover, engineering data can include nominal power or (part load) efficiencies of energy converters. To operate the energy converters, storage and HEX of the HTS the data model must process runtime and engineering data to derive KPI at its technical boundaries which is exemplary shown in Fig. 3. Here, nominal power *P*^{nom} and efficiencies \(\eta = \frac {P^{\text {th}}}{P^{\text {nom}}} \) of energy converters, the thermal power demand *P*^{dem}, the network temperature *T* and final energy cost *c*^{FE} and emissions *e*^{FE} of a thermal network are used to derive the maximum power *P*^{max} as well as specific internal cost and emissions at the system boundary (HEX) of the HTS. The calculation of the latter is based on Eqs. 1 and 2 where all final energy carries must be considered.

$$\begin{array}{*{20}l} \mathrm{c}_{t} &= \frac{\sum_{f\in \mathrm{F}} \mathrm{c}_{f,t}^{\text{FE}} \cdot \mathrm{P}_{f,t}^{\text{FE}}}{\mathrm{P}_{t}^{\text{dem}}} \end{array} $$

(1)

$$\begin{array}{*{20}l} \mathrm{e}_{t} &= \frac{\sum_{f\in \mathrm{F}} \mathrm{e}_{f,t}^{\text{FE}} \cdot \mathrm{P}_{f,t}^{\text{FE}}}{\mathrm{P}_{t}^{\text{dem}}} \end{array} $$

(2)

As portrayed in Eq. 3, the calculation of the specific factors can be rather extensive. Here, the specific internal costs of the HNHT is calculated based on the gas consumption, electricity generation, the associated costs and rewards as well as the proportion of own consumption *α*. If the IESS has an advanced EMS, these derived internal KPI can be delivered by the EMS.

$$ \mathrm{c}_{t}^{\text{HNHT}}= \frac{\mathrm{c}_{t}^{\text{gas}} \cdot \left(\mathrm{P}_{t}^{\mathrm{gas,CHP}}+\mathrm{P}_{t}^{\mathrm{gas,B}}\right)-\left(\mathrm{\alpha}_{t} \cdot \mathrm{c}_{t}^{\text{el}}+(1-\mathrm{\alpha}_{t}) \cdot \mathrm{r}_{t}^{\text{el}}\right) \cdot \mathrm{P}_{t}^{\mathrm{el,CHP}}}{\mathrm{P}_{t}^{\text{dem}}} \\ $$

(3)

### Control optimization

The data model of the information layer can be used for monitoring and optimized control in the functional layer. To consider market data as well as reliably controlling the technical system, a two stage control approach is proposed (Fig. 4). Based on data from the data model such as day ahead prices, thermal energy cost and emissions, the strategy controller uses mixed integer linear programming (MILP) to calculate a schedule for the HTS, e. g. one day in advance. The task of the technical controller is the fulfilment of the schedule interacting real time with the physical entity or simulation model. The simulation model is integrated as a functional mock-up unit (FMU) and calculates states of the technical system based on the data model.

The MILP model of the strategy controller calculates the thermal power for each time step for the different HEX as well as HP and IH by minimizing its internal cost (min*C*^{HTS}). In the following the main equations (power balances) of the MILP model are outlined. Equation 4 describes the thermal power balance of the HTS for each time step t including every HEX as well as the thermal power of the HP \(P_{t}^{\mathrm {th,HP}}\) and the HS \(P_{t}^{\mathrm {th,HS}}\).

$$ 0 = P_{t}^{\mathrm{th,HP}}+P_{t}^{\mathrm{th,HNHT}}-P_{t}^{\mathrm{th,HNLT}}+P_{t}^{\mathrm{th,in,DHS}}-P_{t}^{\mathrm{th,out,DHS}}+P_{t}^{\mathrm{th,HS}} $$

(4)

The thermal power of the HP is limited by its efficiency (coefficient of performance (COP)) \(\mathrm {\eta }_{t}^{\text {HP}}\), nominal power P^{el,max,HP} and the maximum cooling demand \(\mathrm {P}_{t}^{\mathrm {c,max,HP}}\) (Eqs. 5-8). The efficiency of the HP can be set either time dependent or constant.

$$\begin{array}{*{20}l} &P_{t}^{\mathrm{th,HP}} = P_{t}^{\mathrm{el,HP}} + P_{t}^{\mathrm{th,c,HP}} \end{array} $$

(5)

$$\begin{array}{*{20}l} &P_{t}^{\mathrm{th,HP}} = P_{t}^{\mathrm{el,HP}} \cdot \mathrm{\eta}_{t}^{\text{HP}} \end{array} $$

(6)

$$\begin{array}{*{20}l} &P_{t}^{\mathrm{th,c,HP}} \leq \mathrm{P}_{t}^{\mathrm{c,max,HP}} \end{array} $$

(7)

$$\begin{array}{*{20}l} &P_{t}^{\mathrm{el,HP}} \leq \mathrm{P}^{\mathrm{el,max,HP}} \end{array} $$

(8)

The IH is part of the HS (Eqs. 9-10) and limited by its efficiency \(\mathrm {\eta }_{t}^{\text {IH}}\) and nominal power P^{el,max,IH}.

$$\begin{array}{*{20}l} &P_{t}^{\mathrm{th,IH}} = P_{t}^{\mathrm{el,IH}} \cdot \mathrm{\eta}_{t}^{\text{IH}} \end{array} $$

(9)

$$\begin{array}{*{20}l} &P_{t}^{\mathrm{el,IH}} \leq \mathrm{P}^{\mathrm{el,max,IH}} \end{array} $$

(10)

The thermal energy which can be stored in the HS \(Q_{t}^{\text {HS}}\) has a maximum capacity Q^{max,HS} (Eqs. 11-12)

$$\begin{array}{*{20}l} &Q_{t}^{\text{HS}} = Q_{t-1}^{\text{HS}} + \left(P_{t}^{\mathrm{th,HS}}+P_{t}^{\mathrm{th,IH}}\right) \cdot \mathrm{\Delta t} \end{array} $$

(11)

$$\begin{array}{*{20}l} &0 \leq Q_{t}^{\text{HS}} \leq \mathrm{Q}^{\mathrm{max,HS}} \end{array} $$

(12)

The thermal power of each HEX is limited by the KPI of the surrounding systems especially the maximum power P^{th,max,HEX} (Eq. 13). To decide whether thermal power is supplied by the DHS \(P_{t}^{\mathrm {th,in,DHS}}\) or fed into the DHS \(P_{t}^{\mathrm {th,out,DHS}}\) a distinction has to be integrated with the binary variable \(\delta _{t}^{\mathrm {in,DHS}}\) (Eqs. 14-15).

$$\begin{array}{*{20}l} &0 \leq P_{t}^{\mathrm{th,HEX}} \leq \mathrm{P}^{\mathrm{th,max,HEX}} \end{array} $$

(13)

$$\begin{array}{*{20}l} &0 \leq P_{t}^{\mathrm{th,in,DHS}} \leq \mathrm{P}^{\mathrm{th,max,in,DHS}} \cdot \delta_{t}^{\mathrm{in,DHS}} \end{array} $$

(14)

$$\begin{array}{*{20}l} &0 \leq P_{t}^{\mathrm{th,out,DHS}} \leq \mathrm{P}^{\mathrm{th,max,out,DHS}} \cdot \left(1-\delta_{t}^{\mathrm{in,DHS}}\right) \end{array} $$

(15)

Besides the thermal balance, the electric power demand of the HTS \(P_{t}^{\mathrm {el,HTS}}\) is calculated in the electric power balance (Eq. 16). To consider peak loads, the electric power of the HTS is added up with the electric power demand of the industrial site \(P_{t}^{\mathrm {el,Factory}}\) and the change of the peak load *P*^{el,deltaPeak} is calculated compared to the former peak *P*^{el,currentPeak}.

$$\begin{array}{*{20}l} &P_{t}^{\mathrm{el,HTS}} = P_{t}^{\mathrm{el,IH}}+P_{t}^{\mathrm{el,HP}} \end{array} $$

(16)

$$\begin{array}{*{20}l} &P_{t}^{\mathrm{el,HTS}} + P_{t}^{\mathrm{el,Factory}} - P^{\mathrm{el,currentPeak}} \leq P^{\mathrm{el,deltaPeak}} \end{array} $$

(17)

$$\begin{array}{*{20}l} &0 \leq P^{\mathrm{el,deltaPeak}} \end{array} $$

(18)

Equation 19 calculates the total scope 1+2 emissions of the HTS *E*^{HTS} as internal values depending on the thermal power shifted between the different thermal networks through the HEX or the HP as well as the emissions from the electric power procurement \(E_{t}^{\text {el}}\). The emissions of each time step are dependent on the thermal power *P*_{t} and the specific emissions of each thermal energy source e_{t} (Eq. 20).

$$\begin{array}{*{20}l} &E^{\text{HTS}} = \sum_{t\in \mathrm{T}}\left(E_{t}^{\text{HNHT}}-E_{t}^{\text{HNLT}}+E_{t}^{\mathrm{in,DHS}}-E_{t}^{\mathrm{out,DHS}}+E_{t}^{\text{el}}\right) \end{array} $$

(19)

$$\begin{array}{*{20}l} &E_{t} = \mathrm{e}_{t} \cdot P_{t} \cdot \mathrm{\Delta t} \end{array} $$

(20)

The overall cost *C*^{HTS} of the HTS for the calculated time horizon include cost for thermal and electric energy, electric peak power as well as cost for CO_{2} emissions (Eq. 21). The cost for CO_{2} emissions can be either set to scope 1 (direct) or scope 1+2 (direct+indirect) emissions dependent on the specific optimization goal. The specific cost c_{t} for each term are either external cost such as day ahead prices of the electricity market or thermal energy cost of the DHS as well as internal prices such as cost for thermal energy supply in the HNHT (Eq. 22). Moreover, revenues *R* of the HTS are included such as the supply of thermal energy for the DHS or CN calculated by specific revenues r_{t} (Eq. 23).

$$\begin{array}{*{20}l} C^{\text{HTS}} &= \sum_{t\in \mathrm{T}} \left(C_{t}^{\text{HNHT}}+C_{t}^{\text{DHS}}+C_{t}^{\text{el}}+C_{t}^{\mathrm{CO2}}\right) +C^{\text{Peak}} \\ & - \sum_{t\in \mathrm{T}} \left(R_{t}^{\text{HNLT}}-R_{t}^{\text{DHS}}-R_{t}^{\text{CN}}\right) \end{array} $$

(21)

$$\begin{array}{*{20}l} C_{t} &= \mathrm{c}_{t} \cdot P_{t}\cdot \mathrm{\Delta t} \end{array} $$

(22)

$$\begin{array}{*{20}l} R_{t} &= \mathrm{r}_{t} \cdot P_{t}\cdot \mathrm{\Delta t} \end{array} $$

(23)

All of the equations with index *t* are calculated for the time horizon *T* of the MILP model which can be set individually. In the use case, the MILP based on the described power balances is used which are parameterized from the data model. To improve the overall MILP model also temperature dependencies as described in Kohne et al. (2019) can be integrated.

The technical controller receives the schedule generated by the strategy controller as an input. Besides fulfilling the schedule, the technical controller must also ensure that temperature requirements are met to operate the technical system sufficiently. Therefore, the technical controller interacts constantly with the simulation model or physical entity and uses PID control elements to adjust and calculate control signals for the subsystems of the HTS such as energy converters and pumps. Here, runtime data from the HTS and the surrounding systems are necessary. The control signals of the energy converters can be calculated by Eq. 24 where *e* typically represents the difference between target and actual temperature.

$$ u = K_{p}*e+K_{i}\int_{0}^{t}edt+K_{d}\frac{d}{dt}e $$

(24)

The simulation model must contain physical equations of the HTS and may contain ones of the surrounding systems evaluate control signals and the economic and ecological balancing. Those physical equations of the HTS as well as the engineering data of the data model can be utilized to generate estimates for the PID parameters, e. g. by applying the method presented in Chien (1972). By that, the users effort for PID parametrization is minimized.

### Economic and ecological balancing

The DT of the HTS must be connected to the business logic of the IESS and its EMS to determine and evaluate its operating behaviour. The overall balancing can be divided into economic and ecological quantities. Within the IESS, the ecological balancing can be achieved by assigning specific emission factors to energy flows. Depending on necessary level of detail, scope 1 and scope 2 emissions as well as primary energy demand for DHS are common assessment criteria (DIN Deutsches Institut für Normung e.V. 2018). As demonstrated in Kohne et al. (2021) the aforementioned criteria are strongly influenced by the operating conditions within the thermal networks. Therefore, the business layer must be provided with information about the current utilisation level and efficiencies of the energy converters of the the HTS. Moreover, purchased as well as supplied thermal and electric energy is of key interest. Especially with regard to electric energy, the distinction between purchase and supply is of key interest as applied. Therefore, the balancing requires detailed information about the IESS via the EMS. Similar to the ecological balancing, the economic balancing can be achieved by assigning specific prices/cost to energy flows. Depending on the energy procurement of the IESS, those prices can be static or dynamic. Additionally to the energy procurement, the business layer may support regulatory requirements of the IESS with regard to the accounting of energy taxes and fees.