# Optimization of PV and Battery Energy Storage Size in Grid-Connected Microgrid
## 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  
Figure 5: Proposed PSO algorithm flowchart. 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 \(n_{pop}\); 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 \(w_{damp}\) (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_{1}\) and \(c_{2}\) are set to 2.5, and \(w_{damp}\) 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 \(n_{pop}=50\), along with iterations. The best particle cost over 50 particles (\(n_{pop}\) 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.