## 2 Modeling of Distribution System Components
### PV Generation System and ESS System Modeling
#### 2.2.4 ESS Model  
Several equivalent circuit designs of batteries have been documented in the literature. These models can be used to examine battery behavior over short or extended periods of time throughout the charge/discharge process [32]. A lithium-ion (Li-ion) battery was modeled in this study. The model applies the following equations to various types of Li-ion batteries [33]:  
* Model of discharging stage \((i*>0)\) \[f_{1}(it,\;i*,i)=E_{0}-K\cdot\frac{Q}{Q-it}\cdot i*-K\cdot\frac{Q}{Q-it}\cdot it +A\cdot\exp(-B\cdot it)\] (19)
* Model of charging stage \((i*<0)\) \[f_{2}(it,\;i*,i)=E_{0}-K\cdot\frac{Q}{it+0.1\cdot Q}\cdot i*-K\cdot\frac{Q}{Q- it}\cdot it+A\cdot\exp(-B\cdot it)\] (20)  
where \(E_{0}\) denotes the nonlinear voltage (V), \(K\) represents the polarization constant (V/Ah), \(i*\) represents the low-frequency current dynamics (A), \(i\) represents the battery current (A), \(it\) gives the extracted capacity in Ah, \(Q\) is the maximum battery capacity (Ah), \(A\) represents the exponential voltage (V), and \(B\) denotes the exponential capacity (Ah\({}^{-1}\)).  
The following equation describes how temperature affects the model's parameters:  
* Model of discharging stage \((i*>0)\)  
Figure 7: Flowchart of the P&O algorithm.  
\[f_{1}(it,\,i*,i,T,T_{a})=E_{0}(T)-K(T)\cdot\frac{Q(T_{a})}{Q(T_{a})-it}\cdot(i*+it)+ A\cdot\exp(-B\cdot it)-C\cdot it \tag{21}\]  
\[V_{batt}(t)=f_{1}(it,\,i*,i,T,T_{a})-R(T)\cdot i \tag{22}\]  
* Model of charging stage (\(i*<0\))  
\[f_{1}(it,\,i*,i,T,T_{a})=E_{0}(T)-K(T)\cdot\frac{Q(T_{a})}{it+0.1\cdot Q(T_{a} )}\cdot i*-K(T)\cdot\frac{Q(T_{a})}{Q(T_{a})-it}\cdot it+A\cdot\exp(-B\cdot it )-C\cdot it \tag{23}\]  
\[V_{batt}(t)=f_{1}(it,\,i*,i,T,T_{a})-R(T)\cdot i \tag{24}\]  
Here,  
\[\left\{\begin{aligned} E_{0}(t)=\left.E_{0}\right|_{T_{ref}}+\frac{ \partial E}{\partial T}\Big{(}T-T_{ref}\Big{)}\\ K(T)=\left.K\right|_{T_{ref}}\cdot exp\Big{(}\alpha\Big{(}\frac{1}{T}- \frac{1}{T_{ref}}\Big{)}\Big{)}\\ Q(T_{a})=\left.Q\right|_{T_{a}}+\frac{\Delta Q}{\Delta T}\cdot(T_{a}-T_ {ref})\\ R(T)=\left.R\right|_{T_{ref}}\cdot exp\Big{(}\beta\Big{(}\frac{1}{T}- \frac{1}{T_{ref}}\Big{)}\Big{)}\end{aligned}\right. \tag{25}\]  
where \(E/T\) is the coefficient for reversible voltage and temperature (V/K); \(\alpha\) and \(\beta\) are the polarization and internal resistance Arrhenius rate constants, respectively; \(\Delta Q/\Delta T\) denotes the temperature coefficient of maximum capacity (Ah/K); \(C\) is the slope of the nominal discharge curve (V/Ah); \(T_{ref}\) denotes the nominal ambient temperature (K); \(T_{a}\) represents the ambient temperature (K); and \(T\) denotes the cell temperature (K), which is given by:  
\[T(t)=L^{-1}\bigg{(}\frac{P_{loss}R_{th}+T_{a}}{1+s\cdot t_{c}}\bigg{)} \tag{26}\]  
where \(R_{th}\) is the thermal resistance, \(t_{c}\) represents the thermal time constant, and \(P_{loss}\) denotes the total heat produced (W) throughout the charging or discharging process, which is calculated as follows:  
\[P_{loss}=\left(E_{0}(t)-V_{batt}(t)\right)\cdot i+\frac{\partial E}{\partial T }\cdot i\cdot T \tag{27}\]  
Regarding the lithium-ion battery control, two limits on the state of charge (\(SOCmin=15\%\) and \(SOCmax=90\%\)) were established to prevent the overcharging and discharging of the battery. The PV/battery power flow is managed by a discrete PID controller connected to a bidirectional converter (buck-boost converter) [34]. The Simulink model of the PID controller is depicted in Figure 8. This diagram shows that the battery is charged using the upper switch K1 and discharged using the lower switch K2.  
Figure 8: PID battery controller.