## 2 Materials and Methods
### Methods
#### 2.1.2 Calculation of Energy Performance Indicators  
The results from dynamic simulations were used to calculate the system's energy performance indicators. The scheme of the energy supply concept in the DH system is presented in Figure 3.  
Energy flows are evaluated at each time step of the simulation. Energy consumption for the system operation is denoted as \(E_{\text{cons},\text{g,pH}}\) represents natural gas consumption in the boiler, \(E_{\text{cons},\text{g,CHP}}\) represents natural gas consumption in the CHP unit, while the electricity consumption from the HP unit is presented as \(E_{\text{cons,ee,HP}}\). The total produced  
Figure 3: Scheme of the energy flows in DH system.  
Figure 2: Control logic diagram for prioritised operation of HP, CHP, and boiler (highest to lowest priority).  
thermal energy \(E_{\rm prod,t}\), which is distributed across the DH network, is calculated as the sum of thermal energy produced by each thermal energy generator in the system:  
\[E_{\rm prod,t}=\rm{SUM}(E_{\rm prod,t,B}+E_{\rm prod,t,CHP}+E_{\rm prod,t,HP}) \tag{1}\]  
Natural gas is imported from the gas network; therefore, the imported energy to the system is calculated as follows:  
\[E_{\rm imp,g}=\rm{SUM}(E_{\rm cons,g,B}+E_{\rm cons,g,CHP}) \tag{2}\]  
The electricity produced by the CHP unit is denoted as \(E_{\rm prod,ee,CHP}\), the electricity which is consumed by HP is denoted as \(E_{\rm cons,ee,HP}\), the electricity which is imported from the grid is expressed as \(E_{\rm imp,ee}\), while the electricity exported to the grid is \(E_{\rm exp,ee}\).  
Concerning strategies for management of produced electricity, for the case when the electricity produced by CHP is used for HP operation, the calculation is as follows:  
\[\begin{split}&\text{for }E_{\rm cons,ee,HP}>E_{\rm prod,ee,CHP}\\ & E_{\rm imp,ee}=\rm{SUM}(E_{\rm cons,ee,HP}-E_{\rm prod,ee,CHP}) \end{split} \tag{3}\]  
while the electricity which is exported to the grid is as follows:  
\[\begin{split}&\text{for }E_{\rm cons,ee,HP}<E_{\rm prod,ee,CHP}\\ & E_{\rm exp,ee}=\rm{SUM}(E_{\rm prod,ee,CHP}-E_{\rm cons,ee,HP}) \end{split} \tag{4}\]  
The exported and imported electricity for the case when the HP is operated by using electricity from the grid and the electricity produced by CHP unit is sold to the grid is calculated as follows:  
\[E_{\rm imp,ee}=\rm{SUM}(E_{\rm cons,ee,HP}) \tag{5}\]  
\[E_{\rm exp,ee}=\rm{SUM}(E_{\rm prod,ee,CHP}) \tag{6}\]  
The primary energy consumption \(EP\) is calculated as the product imported and the primary energy factor \(f_{\rm imp,nren}\) for each energy carrier. The calculation for electricity is performed in a way that imported energy is deducted by exported energy. Primary energy factors (\(f_{\rm ee,nren,i}\)) depend on the share of renewable, non-renewable, and imported energy components. The primary energy consumption for electricity is calculated with a factor of 1.614, while the primary energy for natural gas is calculated with a factor of 1.095. These values are determined at the national level [19].  
\[EP=\rm{SUM}(E_{\rm imp,ee}-E_{\rm exp,ee})\cdot f_{\rm imp,nren,ee}+\rm{SUM}( E_{\rm imp,g}\cdot f_{\rm imp,nren,g}) \tag{7}\]  
The primary energy indicator \(EPI\) is defined as the ratio of total primary energy consumption to the total useful area of the buildings connected to DH system:  
\[EPI=EP/A \tag{8}\]  
The share of renewable energy \(RES\) is calculated using the following equation:  
\[RES=\rm{SUM}\;E_{\rm cons,res}/E_{\rm prod,t} \tag{9}\]  
In the Expression (9), \(E_{\rm cons,res}\) represents the renewable energy produced in the system. For heat generators powered entirely by natural gas, such as boilers and CHP units,\(E_{\text{s,cons,res}}\) equals zero, and for systems using HP, it corresponds to the thermal energy derived from the source:  
\[E_{\text{cons,res}}=E_{\text{prod,t,HP}}-E_{\text{cons,ee,HP}} \tag{10}\]