**4. Results and Discussion**

In this paper, optimal sizing of the PV and BESS for MG, which can be operated in island mode and grid-tied mode, is carried out with two different data sets. The data are yearly average of a single PV output and the load. Yearly PV generation data have been taken from the IEA database. Then, they are degraded to 24 h by calculating average values for every hour. Yearly load data have also been taken from the IEA database, but some arbitrary changes have been applied on that data to create the desired test system. Then, they have been degraded to 24 h by calculating average values for every hour for case 1. In the second scenario, the data published by the Belgian electricity system operator is used by scaling. For each case, island and grid-connected mode operations are performed at the same time. The optimization algorithm computes the optimum PV and BESS size with regard to optimization parameters and the total cost of the system for case 1 and case 2. The total system cost includes cost of energy, battery and PV module cost, installation cost, battery degradation, and battery and PV lifetime/replacement cost.

First, the PSO algorithm generates a random PV and battery module size between 1 and 50. The first module (or particle) count is equal to *npop*; thus, it is 50. That is, 50 parameters are spread out to different locations randomly at the beginning. Within each iteration, this spreading continues with different velocities depending on *c*1, *c*2, *w*, and *wdamp* (damping ratio) values. These are the values that affect the speed and accuracy of the parameter reaching the optimum point. They can be close to the optimum point at the end, but they may take a long time to reach the optimum point due to their slowness. Contrarily, they can find the optimum point fast, but accuracy may not be guaranteed.

The PSO parameters are chosen to obtain faster and more accurate results. The population size is set to 50, the maximum number of iterations is set to 200, *c*<sup>1</sup> and *c*<sup>2</sup> are set to 2.5, and *wdamp* is set to 0.99. The number of battery and PV modules is limited from 1 to 50. Then, the novel energy management algorithm calculates total PV and BESS power outputs and how much energy is needed from the grid to supply loads. Here, providing uninterrupted power to the loads is the main concern. For this purpose, the energy management algorithm can decide to demand energy from the grid. However, it should be a limited time and level that is defined by the grid total cost parameter at the system design stage. If the MG loads cannot be supplied by any source, there will be a large increase in the total cost. This effect is controlled by another parameter such as the penalty parameter, and thus, the cost increases. The algorithm selects an optimum level of the PV system and BESS capacity to supply the load with the energy required in a day. After the energy management algorithm is calculated for daily total average PV and BESS energy output, total energy cost can be found. The calculated energy cost is compared by the PSO algorithm for every particle, which equals *npop* = 50, along with iterations. The best particle cost over 50 particles (*npop* count) is found, and this is called the "particle best cost". This is saved for the next iterations. The particle best cost can be updated with a new value at the next iteration by a particle that holds lower cost. Thus, after all iterations are completed, the best updated "particle best cost" value will be the "global best". This shows the calculated optimum PV and BESS size with minimum cost with defined constraints. The best particle costs between each of the 50 particles inside an iteration and every best cost throughout the iterations can be seen in Figure 6a,b for case 1 and case 2.

At the first iterations, the PSO algorithm generates lower PV and BESS module counts, which means that the PV and the BESS particles are far from the optimum point. (Cost can be seen on the second y-axis in Figure 6a,b. The y1-axis and y2-axis scales are different). Since loads are supplied mostly from the grid, the cost is increasing. After defined the maximum grid cost is exceeded, the total system cost increases faster due to the penalty factor, and the system can obtain supply mostly from renewable energy resources (because increasing the rate of renewable energy use decreases the system total cost). After 200 iterations, calculations were performed by the energy management algorithm. It was found that the optimum PV and BESS module counts were 47 and 28, respectively, and the total cost was USD 40.972 for case 1. Similarly, it was found that the optimum PV and BESS module counts were 24 and 28, respectively, and the total cost was USD 24.186 for case 2.

To prove the results obtained from the proposed method, the total cost variation of the system according to different PV and battery sizes and penalty factor are given in Figure 7a,b, respectively. At the first point in Figure 7a, there are 45 PV modules and five battery modules. The total system cost at this first point is USD 49.993. In the first area (depicted in Figure 7a), while the number of PV modules is decreasing, the number of battery modules is increasing. It should be considered that the energy cost penalty highly affects the total system cost. The total system cost is increasing slowly until the sixth calculation point. Then, when the number of PV modules is too low, the system cost increases rapidly. At the eighth calculation point, there are five PV modules and 40 battery modules, and this is the highest cost in the figure, which is USD 127.040. At this point, there are not enough PV modules to supply the loads, and there are not enough PV modules to charge this amount of battery modules. Thus, the loads are supplied from the grid for a longer period. At this longer period, as an option, the cost can be increased excessively or the maximum limit can be set in order to prevent taking more energy from the grid. In this study, the maximum level of energy cost that can be taken from the grid has been determined. After reaching the maximum allowable grid supply limit cost, the energy management algorithm cuts off the electricity. Eventually, the total cost will be high in this situation. In the second area, while the number of PV modules has increased, the number of battery modules is low. In this case, the total cost is decreasing because there will be more PV modules to generate energy to supply the loads in the daytime. PV modules can also charge batteries when the number of PV and battery modules are closer to the optimum point. Thus, BESS can supply the loads at night when there is no PV energy. In the third area, both the number of PV and battery modules are increased. The total cost decreases, but at the 18th point, it increases again due to the increased number of battery modules. At the fourth calculation area, both the numbers of PV and battery modules are decreased, and the total cost also starts to decrease. Finally, the number of PV and battery modules reaches the optimum point, such that the total cost is at the lowest value at the 20th point. There are 47 PV modules and 28 battery modules. Total system cost is USD 40.972 at the 20th point. The same study was carried out for case 2. It can be seen from Figure 7b that the cost of the system for 24 PV modules and 28 batteries is USD 24.186. This means that the loads of the MG can be fully supplied by PV and BESS in the daytime, and they can be supplied by BESS most of the night. Therefore, MG can be supplied mostly by its RES, and its dependency to the grid is low. However, the total system cost rises as the number of battery and PV modules continues to decrease because the system needs to import more energy from the grid, which increases the grid supply cost. Another reason is that as the number of both PV and battery modules continues to decrease, the longer the blackout durations occur and thus the penalty cost increases.

**Figure 6.** Particle best cost per iteration and best costs through all iterations of the proposed energy management method with PSO: (**a**) case 1; (**b**) case 2.

**Figure 7.** System total cost for various PV and BESS module combinations: (**a**) case 1; (**b**) case 2.

As can be seen, this process is not simple, such as defining the number of PV and battery modules regarding the known changing load demand. PV generation changes according to irradiation and weather conditions. There is an allowed grid supply limit that is defined at the system design stage. Therefore, the energy management algorithm should decide when to charge and discharge the batteries, and when to obtain energy from the grid by considering cost. Eventually, the results show that the proposed optimization algorithm correctly determines the optimum PV and BESS size within the defined constraints. The proposed energy management system with the PSO algorithm has some advantages and superiorities. It also needs only a few initial parameters. In addition, it can be used with different algorithms. Furthermore, the constraints and parameters used in the energy management strategy are also configurable such that they can be easily adapted for different systems. The flexible nature of the proposed approach is its most important strength.

In order to test the performance of the PSO-based method with the energy management algorithm, its performance is compared with GA, which is the one of the well-known optimization algorithms. The obtained results with the GA are shown in Figure 8a,b for case 1 and case 2, respectively. The parameters used in the GA algorithm are as follows: the population size is set to 50, the maximum number of iterations is set to 200, crossover rate = 1, mutation rate = 0.04, and the number of battery and PV module is limited from 1 to 50. As can be seen in Figure 8a,b, the novel energy management method with the PSO algorithm gives better performance than the novel energy management method with the GA algorithm. In addition, the energy management method with GA found that the optimum PV and BESS modules count as 47 and 28, respectively, and the total cost is USD 40.972 at the 192nd iteration for case 1 and the PV and BESS modules count as 24 and 28, respectively, and the total cost is USD 24.186 at the 187th iteration for case 2. It takes more time to find the global point than the proposed algorithm. Furthermore, this comparison is proven that the proposed novel energy management system can also work with other algorithms.

**Figure 8.** Obtained best cost results obtained from the proposed energy management method with GA: (**a**) case1; (**b**) case2.

Comparisons between existing studies and the proposed study are given in Table 3. A close examination of Table 3 provides an idea of the difference between the proposed system and the other algorithms. In past studies, various algorithms have been used for different systems for optimization. This study differs from other studies in the following aspects. As can be seen from the table, some of the studies in the literature do not use the PSO algorithm for both PV and BESS sizing. In most of the studies, one of the PV and BESS parameters was kept constant, and the other parameter was optimized. Although the PSO optimization algorithm has been proposed for both PV and BESS in a limited number of studies, they have only been used for island mode systems. Most of the remaining studies did not use cost minimization as an objective function or energy management system. A limited number of studies have used cost minimization as an objective function or energy management system, but with different optimization algorithms.


**Table 3.**

Comparison

 of existing system and proposed system.


**Table 3.** *Cont.*

#### **5. Conclusions**

This study presents a PSO-based algorithm with a new energy management strategy to find the optimum PV and BESS size for a grid-connected MG. The MG can operate in island mode and, if necessary, in grid-connected mode with some limitations. The MG structure is designed in such a way that it can demand energy from the grid when there is not enough energy in the PV system and BESS. However, the amount of demanded energy is limited by the system authorities. The aim is to find an optimum PV and BESS size by considering the defined energy cost. This allows the microgrid to be supported from the grid in critical situations, although supplying loads from the RES has priority, regardless of whether the system will demand energy from the grid and/or the amount of energy to be demanded from the grid can be configured with the proposed energy management method. Therefore, the energy management algorithm can be reconfigured and used for various systems and different constraints. To validate the proposed approach, various calculations are carried out for different PV and BESS sizes. Furthermore, to prove the effectiveness of the new energy management method with PSO, it has been compared with GA. Results show that the PSO-based algorithm with the energy management strategy can determine the optimum PV and BESS size, with the minimum cost defining the system constraints. Consequently, PV and battery sizes have been optimized together with the proposed PSO algorithm and novel energy management system. The effectiveness of the system is also explained by comparing the results with different algorithms.

**Author Contributions:** Conceptualization, S.G. and S.O.; methodology, S.G. and S.O.; software, S.G. and S.O.; validation, S.G. and S.O.; formal analysis, S.G. and S.O.; investigation, S.G. and S.O.; resources, S.G. and S.O.; data curation, S.G. and S.O.; writing—original draft preparation, S.G. and S.O.; writing—review and editing, S.G. and S.O.; visualization, S.G. and S.O.; supervision, S.O. All authors have read and agreed to the published version of the manuscript.

**Funding:** This research received no external funding.

**Institutional Review Board Statement:** Not applicable.

**Informed Consent Statement:** Not applicable.

**Data Availability Statement:** The dataset associated with this paper can be found in the online version, at https://www.elia.be/en/grid-data?csrt=17010711133344377898 (accessed on 30 July 2022).

**Conflicts of Interest:** The authors declare no conflict of interest.
