**2. System Configuration and Modelling**

The grid connected microgrid structure used in this paper is shown in Figure 2. It consists of the BESS, PV, AC bus, grid and load. It is connected to the grid via the AC bus. The battery and PV are connected to the DC bus via DC/DC converters that charge the battery from the PV throughout the DC bus. The DC bus is connected to the AC bus through the DC/AC inverter. The energy management system tracks load demand, available PV power and battery energy level, and it controls charge/discharge status of the battery and decides whether to demand energy from the grid.

**Figure 2.** The architecture of the microgrid system.

Solar PV module performance is affected by irradiation, pollution, aging, shading and ambient temperature. Since the aim of this study is not maximum power point tracking design, the effects of these parameters will not be examined, and the net output power of the system will be used directly from the previously obtained data. Two different data sets were used to create different scenarios: case 1 and case 2. The data sets used in this study, which show the relationship between the power produced by the PV system and the load demand, are given in Figure 3a,b. The PV data in Figure 3a are obtained by taking the daily average of the annual data of the International Energy Agency (IEA) future prospect. To test the proposed system for another scenario, the PV and load data in Figure 3b are scaled from data published by the Belgian electricity system operator.

**Figure 3.** Average load demand and single PV module output for: (**a**) case 1; (**b**) case 2.

The converter efficiency that affects the amount of energy from the PV to the load is given as 95%. Thus, total PV output to load is:

$$P\_{pv}(t) = P\_{pv} \text{gen}(t) \times \eta\_{conv} \tag{1}$$

where *Ppvgen*(*t*) is generated power from the PV modules during time interval *t*, *ηconv* is the converter efficiency, and *Ppv*(*t*) is transferred power from the PV to load during time interval *t*.

The power generation capabilities of PV modules deteriorate from year to year due to aging. Thus, the economic life of a PV is considered as 25 years in this study, and PV modules are considered, as they will not be replaced during system cost calculation. The cost and other parameters are listed in Table 1.

**Table 1.** PV cost parameters.


As is known, the minimum and maximum of battery state of charge (*Bsoc*) should be defined to prevent shortening the battery life. *Bsoc* can be given as:

$$B\_{\rm soc}(t) = \left[E\_{\rm bat}(t) / E\_{\rm bat,rated}(t)\right] \times 100\% \tag{2}$$

where *Ebat*(*t*) is battery energy level and *Ebat,rated*(*t*) is rated energy capacity [28]. Overcharging and deep discharging of the battery should be prevented, as it will reduce its lifespan and cycle life. Thus, the following limits are defined:

$$E\_{\text{but,min}}(t) \le E\_{\text{but}}(t) \le E\_{\text{but,max}}(t) \tag{3}$$

where *Ebat*,min(*t*) is minimum energy limit, and it is defined as 0.48 kWh. *Ebat*,max(*t*) is a single battery module's maximum energy limit and it is defined as 2.4 kWh.

Battery charging and discharging action defined as below, respectively [28]:

$$E\_{bat}(t)[E\_{PV}(t) - E\_{Load}(t)/\eta\_{inv}] \times \eta\_{Rch} \tag{4}$$

$$E\_{\rm but}(t)[E\_{Load}(t)/\eta\_{\rm inv} - E\_{PV}(t)] \times \eta\_{\rm Bdch} \tag{5}$$

where *EPV*(*t*) is the generated energy, and *ELoad*(*t*) is the load demand during time interval *t*. *ηBch*, *ηBdch* and *ηinv* are battery charging, discharging and inverter efficiencies, respectively, which are defined as 95%.

The capacity of battery modules will also decrease over time. In this work, battery module life is taken as 8 years. Battery modules are replaced three times during system cost calculation. Accordingly, BESS cost and other parameters are given in Table 2.

**Table 2.** BESS cost parameters.


Changes in the efficiency of system elements can cause errors. In addition, since the battery capacity and PV must be a certain level as an integer (selected unit has a certain value), it will cause some errors. They can be minimized by reducing the PV unit power and battery unit capacity values. However, using a small PV module and batteries with small capacities may not be both practical and economical. More precisely, this is another optimization problem.

#### **3. Proposed Algorithm**

The proposed algorithm will be given in sequence as the objective function, energy management strategy for grid-connected and island modes and the proposed PSO algorithm. First, the PSO algorithm generates random PV and BESS sizes. The proposed energy management algorithm, which also will be explained later, uses these sizing values and generates PV and BESS power output according to the inputs and constraints.

#### *3.1. Objective Function*

In this study, the energy cost is chosen as an objective function. The goal is to obtain minimum total energy cost for the MG without compromising defined constraints; thus, the optimum PV and BESS size can be found.

The energy cost (*EC*) is calculated as:

$$EC = \left(PV\_{Total,energy} \times PV\_{\text{cost}}\right) + \left(BESS\_{Total,energy} \times BESS\_{\text{cost}}\right) \tag{6}$$

Here, *PVTotal,energy* and *BESSTotal,energy* are total output energy of PV and BESS, respectively. They are generated from the energy management algorithm in a defined time span. *PV*cos *<sup>t</sup>* and *BESS*cos *<sup>t</sup>* are the cost of PV and BESS, which include the capital, replacement, operation and maintenance costs.

#### *3.2. Energy Management Strategy*

The management of the power flow is an important process for optimizing the system components and the efficient operation of the system. The proposed energy management strategy can be divided into two parts as island mode and grid-connected mode operation. Figure 4 shows the flowchart of the proposed energy management strategy.

**Figure 4.** Proposed energy management flowchart.

In the island mode, the MG operates without grid support. The load demand can be satisfied by PV generation and/or BESS available capacity. There is always a balance between the available PV power, BESS capacity and load. Net energy (*Enet*(*t*) *= EPV*(*t*) − *ELoad*(*t*)) is followed, and it is decided that the battery is charged if *Enet*(*t*) *>* 0 and *BSOC*(*t*) < *Ebat,max*(*t*). Batteries are charged with *EBch*(*t*) until their *Ebat,max*(*t*) level. If BESS reaches its charge limit and there is still available power in the PV system, this remaining power cannot be used or sold to the grid due to the island mode operation. If *Enet*(*t*) *=* 0, then there is no excess energy, and thus, load demand is equal to PV generation. If there is not enough PV generation to satisfy load demand (*Enet*(*t*) < 0), EMS controls *Bsoc*(*t*) level at that time. If BESS has available energy, batteries can be discharged until their *Ebat,min*(*t*) level. Finally, if both *Enet*(*t*) < 0 and *BSOC*(*t*) < *ELoad*(*t*), but there is still some available PV power generation (that is, 0 < *EPV*(*t*) < *ELoad*(*t*)), then batteries are charged by PV power.

For the grid-connected mode operation, the MG operates with grid support. In this study, the aim is to find optimum PV and BESS size for mostly self-sufficient MG in a yearly period. The grid energy is only used for supplying load demand if there is not enough energy in the PV and batteries. In this study, the grid is not used for charging batteries. It is assumed that it is costly to obtain energy from the grid. Thus, there is a grid cost limitation. The MG can be partially or fully supplied from the grid only for a limited time when there is either no or not enough energy in the BESS and PV. The EMS tracks the current energy level of the system components, the status of the PV system and BESS, and if there is not enough energy to be able to supply the load demand (*EPV*(*t*) + *BSOC*(*t*) < *ELoad*(*t*)), then the MG can obtain energy from the grid with penalty. There is a flag that holds the record of obtained energy from the grid. If energy from the grid exceeds a previously defined limit value, the flag increases. Hence, the PSO algorithm, which is explained below, decides to increase the PV or BESS module capacity to minimize the dependency of grid connectivity by considering the total installation cost.
