## 2 Matrix-Based Model Formulation for MES
### District Electricity Network
#### 2.2.2 Thermal Model
For instance, when applied to \(\pm A_{\text{hd}}\), \"\(\cdot\)\" is defined as\(-\)  
\[\left\{ \begin{array}{l}\overline{A_{\text{hd}}}=\frac{|A_{\text{hd}}|+A_{ \text{hd}}}{2}\\ \overline{-A_{\text{hd}}}=\frac{|-A_{\text{hd}}|+(-A_{\text{hd}})}{2}\end{array} \right. \tag{9}\]  
When mass flows with different temperatures mix at node \(i\), the mixture temperature equation is adopted to calculate the nodal outflow temperature:  
\[\left(\sum_{l\in\mathbb{H}^{\text{node}}i}m_{\text{out},i}\right)T_{\text{out },i}^{\text{N}\text{ }\prime}=\sum_{k\in\mathbb{H}^{\text{node}}}\left(m_{\text{in},k}T_{\text{in},i,k}^{\text{N}\text{ }\prime}\right)\hskip 28.452756 pt\forall i\in\mathbb{H}^{\text{node}} \tag{10}\]  
where \(m_{\text{out}}/m_{\text{in}}\) is the mass flow leaving/entering a node; and \(\mathbb{H}^{\text{node}}/\mathbb{H}^{\text{out}}/\mathbb{H}^{\text{in},i}\) is the set of DHN nodes/pipelines with node \(i\) as the inlet/pipeline and node \(i\) as the outlet. By substituting Equation (8) into the matrix form of Equation (10), \(T_{\text{in}}^{\text{N}\prime}\) can be eliminated, thereby expressing the thermal process of the DHN merely through \(T_{\text{out}}^{\text{N}\prime}\). Before rewriting Equation (10), a set of multipliers, \(D_{1}^{\text{S}}\)-\(D_{3}^{\text{S}}\) and \(D_{1}^{\text{R}}\)-\(D_{3}^{\text{R}}\), is first defined for simplicity:  
\[ \begin{cases}D_{1}^{\text{S}}=\text{diag}\big{(}\overline{-A_{\text{hd}}}|m |\big{)}&D_{1}^{\text{R}}=\text{diag}\big{(}\overline{A_{\text{hd}}}|m|\big{)} \\ D_{2}^{\text{S}}=\text{diag}\big{(}m_{\text{q}}\big{)}&D_{2}^{\text{R}}=\text{ diag}\big{(}m_{\text{q}}\big{)}\\ D_{3}^{\text{S}}=\overline{A_{\text{hd}}}\text{diag}(|m|)R_{1}\overline{-A_{ \text{hd}}}^{\text{T}}&D_{3}^{\text{R}}=\overline{-A_{\text{hd}}}\text{diag }(|m|)R_{1}\overline{A_{\text{hd}}}^{\text{T}}\end{cases}  \tag{11}\]  
Considering that the mass flow of non-source nodes may either leave into pipelines or loads and can solely enter from pipelines in the supply network, the nodal temperature equation for supply non-source nodes is derived as Equation (12), where \(D_{1,\text{nn}}^{\text{S}}\), \(D_{2,\text{nn}}^{\text{S}}\), and \(D_{3,\text{n}}^{\text{S}}\) denote the weighted mass flow leaving into pipelines, leaving into loads, and entering from pipelines, respectively:  
\[\Big{(}D_{1,\text{nn}}^{\text{S}}+D_{2,\text{nn}}^{\text{S}}\Big{)}T_{\text{n }}^{\text{S}\prime}=D_{3,\text{n}}^{\text{S}}T^{\text{S}\prime}=\Big{[}D_{3, \text{ns}}^{\text{S}}\quad D_{3,\text{nn}}^{\text{S}}\Big{]}\Big{[}T_{\text{s }}^{\text{S}\prime}\quad T_{\text{n}}^{\text{S}\prime}\Big{]}^{\text{T}} \tag{12}\]  
where \(T^{\text{S}\prime}\) refers to the outflow temperature vector of supply nodes. The single subscript 'n' indicates that the matrix consists of rows corresponding to non-source nodes, while the double subscript 'nn' means the matrix comprises both rows and columns corresponding to non-source nodes. The rest of the subscripts,'s/'/'ss/'/'sn', can be interpreted in the same manner. Likewise, the mass flow of supply source nodes can only leave into pipelines, and may either enter from pipelines or sources. Thereby, Equation (10), for the supply source nodes, is represented as  
\[D_{1,\text{ss}}^{\text{S}}T_{\text{s}}^{\text{S}\prime}=-D_{2,\text{ss}}^{\text{ S}}T_{\text{sp}}^{\text{S}\prime}+D_{3,\text{s}}^{\text{S}}T^{\text{S}\prime}=-D_{2, \text{ss}}^{\text{S}}T_{\text{sp}}^{\text{S}\prime}+\Big{[}D_{3,\text{ss}}^{ \text{S}}\quad D_{3,\text{sn}}^{\text{S}}\Big{]}\Big{[}T_{\text{s}}^{\text{S }\prime}\quad T_{\text{n}}^{\text{S}\prime}\Big{]}^{\text{T}} \tag{13}\]By combining Equations (12) and (13), the matrix-based nodal temperature equation for the entire supply network can be written as  
\[\left\{