# Optimal Sizing of Battery Energy Storage System for Implicit Flexibility in Multi-Energy Microgrids
## 2 Methodology
### Bess
\[soc_{t}^{BESS}=\sum_{k=1}^{K_{\text{shuLUT}}}\left(SOC_{k}^{disLUT}\times y_{ k,t}^{disLUT}\right)+\sum_{k=1}^{K_{\text{shuLUT}}}\left(SOC_{k}^{chuLUT}\times y_{ k,t}^{chuLUT}\right)+soc_{t}^{BESS_{\text{shoE}}}, \tag{21}\]  
\[soc_{t}^{BESS}=soc_{t-1}^{BESS}+\frac{\left((p_{t}^{BESS_{\text{sho}DC}}-p_{ t}^{BESS_{\text{shoE}}})\times P^{BESS_{\text{shom}}}\times\Delta t\right)}{E^{BESS_{ \text{shom}}}}. \tag{22}\]  
The constraints reported in Equations (23)-(30) are used to model the BESS capability curves shown in Figure 2. In this case, the maximum charge and discharge powers are not fixed values but depend on the SOC range and are expressed as functions of the support points defined in the corresponding capability LUT, as shown in Equations (23) and (24). Unlike the previous LUT formulation, the variables \(y_{k,t}^{chuC_{\text{LUT}}}\) and \(y_{k,t}^{disC_{\text{LUT}}}\) are binary, reflecting the fact that the BESS operating point must lie within one and only one of the SOC intervals into which the capability curve has been discretized. This is enforced by Equations (25) and (26), which require that the sum of the binary variables over the LUT support points equals one. Equations (27) and (28) ensure that the selected segment of the capability curve is consistent with the current SOC value. Finally, Equations (29) and (30) impose upper bounds on the BESS charge and discharge AC power flows, according to the selected segment of the capability curve. \[p_{t}^{BESS_{\text{sho}AC}}=\sum_{k=1}^{K_{\text{shuLUT}}}\left(p_{k}^{\text{ chuAC}_{\text{LUT}}}\times y_{k,t}^{\text{chuLUT}}\right), \tag{15}\]0  
\[p_{t}^{BESS_{\text{sho}AC}}=\sum_{k=1}^{K_{\text{shuLUT}}}\left(p_{k}^{\text{ chuAC}_{\text{LUT}}}\times y_{k,t}^{\text{chuLUT}}\right), \tag{15}\]1  
\[p_{t}^{BESS_{\text{sho}AC}}=\sum_{k=1}^{K_{\text{shuLUT}}}\left(p_{k}^{\text{ chuAC}_{\text{LUT}}}\times y_{k,t}^{\text{chuLUT}}\right), \tag{15}\]2  
The first part of the modeling involves formulating constraints that for each time step \(t\), identify the portion of power withdrawn from the grid that can be classified as _negative injected electricity_ (NIE). The principle adopted in this study is based on comparing the battery's power flows with the internal energy balance of the system. Specifically, during each time step \(t\) in which the BESS is charging, the model compares the battery's charging power with the internally generated electricity \(p_{t}^{\text{POD}_{\textit{fund}}}\), which may originate from sources such as CHP units and/or PV systems. If the internal generation at time \(t\) is greater than or equal to the charging power, it is assumed that charging is entirely supplied by self-generation. Only when the charging power exceeds internal generation, the surplus is considered as withdrawn from the grid. Similarly, during each time step in which the BESS is discharging, the model compares the power discharged with the internal electrical load \(P_{t}^{\text{POD}_{\textit{fund}}}\). If the internal load is greater than or equal to the BESS discharging power, it is assumed that the discharged energy is entirely used to serve internal demand. Only when the discharging power exceeds the internal load, the surplus is considered as injected into the grid. Formally, the portions of BESS power flows that may be classified as NIE are defined as follows:  
* If the battery is charging at time \(t\), the portion of charging power intended as withdrawn from the grid is given by the following: \[ \begin{array}{c}p_{t}^{\text{POD}_{\textit{chain}_{\textit{inj}}}}=0,\text{ if }p_{t}^{\text{BESS}_{\textit{data}}C}\times p^{\text{BESS}_{\textit{num}}}\leq p _{t}^{\text{POD}_{\textit{fund}}}\\ p_{t}^{\text{POD}_{\textit{chain}_{\textit{inj}}}}=p_{t}^{\text{BESS}_{ \textit{data}}C}\times p^{\text{BESS}_{\textit{num}}}-p_{t}^{\text{POD}_{ \textit{fund}}},\text{ otherwise.}\end{array} \]
* If the battery is discharging at time t, the portion of discharging power associated with grid injection is defined as follows: \[