## 3 Outer Layer Modeling and Optimization
### Steady State Operation Modeling of Integrated Energy System
#### 3.1.3. District Heating System  
A district heating system usually consists of supply and return parallel symmetric pipelines that deliver heat energy, from the heat generation point to the end consumers. When a heat distribution system is modeled and simulated, the variables are each node pressure and each pipeline mass flow rates in the hydraulic model, correspondingly, supply and return pipeline temperatures, and transmitted thermal power in the thermal model. Model joint analysis is carried out to determine the mass flow rates within each pipe, the supply and return temperatures, and pressure at each node [8; 16; 25]. The continuity of flow is described as the mass flow that enters into a node such as heat load user is equal to leaving the node plus the flow consumption at the node [25]. To describe the continuity of the flow in a matrix form, the district heating system incidence matrix \(\mathbf{A_{h}^{w}}\) with \(n_{node}\) = \(node\) rows and \(n_{pipe}\) = \(pipe\) columns is defined, where \(n_{node}\) denotes the number of nodes and \(n_{pipe}\) is the number of pipes. For the entire hydraulic network, the continuity of flow is expressed by:  
\[\left\{ \begin{array}{l}0=\mathbf{A_{h}^{w}}\cdot\mathbf{M_{h}}\\ 0=\mathbf{B_{h}^{f}}\cdot(\mathbf{\Delta H_{w}}-\mathbf{H_{pump}})\end{array} \right. \tag{20}\]  
where \(\mathbf{M_{h}}\) is mass flow matrix composed of the mass flow \(\mathbf{m_{h}}\) within each pipe; \(\mathbf{B_{h}^{f}}\) denotes the loop incidence matrix; \(\mathbf{\Delta H_{w}}\) stands for the head losses within a pipe, which is the difference in head pressure \(\mathbf{H_{w}}\) between the start and end nodes within a pipe; \(\mathbf{H_{pump}}\) represents the circulation pump matrix. The pipeline diameter, pipeline length, and hot water fluid density data are assigned to each segment. The sum of all local pressure loss coefficients is assigned to each hot water supply and return pipeline, substation, and heat source plant [23; 25]. The pressure drop due to friction and local losses is calculated by:  
\[\left\{ \begin{array}{l}\Delta H_{w}^{i}=\Delta H_{f}^{i}+\Delta H_{j}^{i}\\ \Delta H_{f}^{i}=\lambda\cdot\frac{L_{h}^{i}}{D_{h}^{i}}\cdot\frac{\rho v^{2}} {2}\\ \Delta H_{j}^{i}=\xi\rho v^{2}/2\end{array} \right. \tag{21}\]  
where the friction coefficient \(\lambda\) is specified with the corresponding hydraulic correlation; the sum of the local loss coefficients is denoted by \(\xi\); the pressure drop in the heat exchange substation at the consumer end or in the heat source is described as \(\Delta H_{w}^{i}\). Figure 3: The electric compressor model of the gas pipe. In general, the thermal model is used to determine the temperatures at start and end of each pipeline. Usually, the supply temperatures at each source and the return temperatures at each heat load user before mixing are identified in the thermal model [25; 29]. The heat load user return temperature depends on the supply temperature from heat source plant, the outdoor temperature, and the heat power consumed by the heat load user. There are four different temperatures associated with each node: the supply temperatures (\(T_{source}^{s}\) and \(T_{load}^{s}\)) and the return temperatures (\(T_{source}^{r}\) and \(T_{load}^{r}\)). The temperature at the start of each pipeline leaving the node is equal to the mixture temperature at the same node, also, the heat power and the temperature at the outlet of a pipe are calculated by:  
\[\left\{ \begin{array}{c}Q_{source}^{heat}=C_{p}m_{h}(T_{source}^{s}-T_{ source}^{r})\\ \mathcal{Q}_{load}^{heat}=C_{p}m_{h}(T_{load}^{s}-T_{load}^{r})\\ T_{end}=(T_{start}-T_{0})\exp(-\frac{\lambda_{pipe}L_{h}^{i}}{C_{p}m_{h}})\\ \sum{(m_{in}T_{in})}=(\sum{m_{out})T_{out}}\end{array} \right.