A Novel Hybrid-HHOPSO Algorithm Based Optimal Compensators of Four-Layer Cascaded Control for a New Structurally Modified AC Microgrid

This paper proposes a new modified architecture for AC microgrid consisting of multiple grid-supporting master units (MUs) and multiple grid-feeding slave units (SUs). In this study, a coordinated four-layer hierarchal control (HC) approach is applied to the proposed structure for allowing the MUs, SUs and loads to be easily integrated as a microgrid and operated in both grid-integrated and standalone operation mode. The proposed structure of the AC microgrid enhances the system redundancy to prevent the single point of failure of MU and has more stability, efficiency, flexibility and reliability than the conventional structures. Furthermore, optimal design guidelines, based on a new hybrid Harries hawks and particle swarm optimization algorithm (H-HHOPSO) with the cooperation of different types of proposed multi-objective functions, are presented to fulfill the study objectives. The optimization constraints/objectives are employed for optimal parameters selection of HC controllers to improve the power quality, enhance dynamic and steady-state performance and guarantee a seamless transition between operation modes. To accomplish this work, the newly modified structure is modeled, constructed in MATLAB/SIMULINK and tested under the variations of generations and loads. This structure is also examined when the fault occurs at any one of the MUs and during the connecting and disconnecting of utility grid. This testing is to verify its flexibility and reliability, and confirm the effectiveness and robustness of the proposed optimal controllers. Additionally, the experimental work is carried out using the hardware-in-the-loop real-time emulation to prove the optimal controllers’ feasibility. Finally, the experimental and simulation results are compared.


I. INTRODUCTION
Nowadays, the penetration of renewable energy microsources (REMSs) based distributed generation (DG) units in the utility power grid is rapidly growing. Recently, the REMSs DG units, including fuel cells, tidal, hydro and biomass power system, and photovoltaic panels system (PVPS) and wind energy conversion system (WECS), have been integrated into the distributed power systems to The associate editor coordinating the review of this manuscript and approving it for publication was Giambattista Gruosso . provide clean and sustainable energy [1]. DG units use either power electronic converters or synchronous generators to interface micro-sources with loads. These DG units offer several advantages, such as they have high security and reliability against sudden faults. Moreover, they improve the local utilization of REMSs, reduce pollution and greenhouse gas emissions, improve the efficiency of supplied energy, and decrease transmission lines' cost and losses [2]. They are considered as strong support for the main power network. The intelligent control strategies are required for the multiple DG units to be properly integrated as a microgrid into the utility grid to minimize uncertainties and enhance the system performance [3].
Microgrids can work in two modes of operation: (1) grid-tied mode to allow the power to be exchanged with the main power grid [4]; or (2) islanded (autonomous) mode to achieve local power production for local loads when the grid connection failure occurs [5]. The technologies of power electronic converters are rapidly developing and, therefore, the REMSs such as photovoltaic panels and wind turbines can be easily integrated as main DG units to microgrids. The intermittent and volatile nature of REMSs may produce significant fluctuations in generated power across the system, which may lead to harmful impacts on the quality of power [6]. To overcome this challenge, the energy storage systems (ESSs) should be used to improve the controllability and flexibility in microgrids [7]. The proper control methodologies are essential to achieve effective coordination among ESSs, REMSs and loads. One of the main objectives to coordinate control strategies is to compensate for power imbalance between electrical power productions and loads to improve microgrids' reliability and stability [8].
The control strategies for microgrids comprising multiple DG units should have supplementary purposes other than regulation performance, such as power-sharing among different DG units [9]. Many of the control approaches based on communication lines have been proposed in the literature. For example, master-slave control without central controller [10], master-slave control with central controller [11], auto-master-slave control [12], instantaneous average current sharing strategy [13], peak-value based current sharing approach [14], circular chain control [15], angle droop control [16] and distributed control method [17]. Although these previous strategies achieve good stability and accurate current sharing, they have low flexibility, reliability and redundancy. This is because these strategies depend on communication links. Consequently, other control approaches have been addressed by researchers to avoid critical communication lines. These strategies can be classified into three categories: P-F/Q-V droop control [18], P-V/Q-F droop control [19] and frequency-based signal injection method [20]. Recently, many advanced coordinated control strategies including, centralized and decentralized control, have been proposed in [21], [22] to guarantee the power balance among ESSs, REMSs and loads to improve the reliability and stability of the microgrids. In this paper, the coordinated four-layer hierarchal control is applied to the proposed topology of the microgrid.
Several topologies of microgrids based on multiple DG units were discussed in previous works, as in [6], [23], [24]. The microgrid structure suggested in [23] consists of only one energy storage master unit (ESMU), one WECS and one PVPS. The ESMU of this structure, which works as a grid-forming DG unit, has only one control level required to fix the whole microgrid's voltage and frequency by achieving the power balance between generation and loads. The major issue of this structure is when a fault occurs at ESMU; the whole microgrid will shut down, interrupting all amounts of supplied power. Moreover, this structure is capable of operating in islanded mode only. These issues are also found in the microgrid structure proposed by Wu, et al. [24]. To overcome these problems, a newly modified microgrid structure is introduced in this paper, which has more stability, flexibility, and reliability than the structures suggested in the literature. This proposed configuration, shown in Figure 1, has two master units (MUs) empowered by energy storage elements (ESEs) to prevent the single point of failure of the ESMU and enhance the redundancy of the system when operating in islanded mode. During normal operation, the active and reactive powers are shared equally between the two MUs to avoid overstressing for anyone. Furthermore, if the fault occurs at any one of the MUs, the faulty one will be interrupted, whereas the microgrid will continue to operate depending on the other healthy one, which is alone able to regulate the voltage and frequency of the whole microgrid. In this situation, the healthy one will increase its output power to compensate for the faulty one's interrupted power portion. Furthermore, this suggested structure contains multiple slave units (SUs) empowered by REMSs such as WECS and PVPS. The MUs act as grid-supporting DG units. However, the SUs act as grid-feeding units. The types of DG units in AC microgrids are discussed in detail in [25].
Most of microgrids architectures proposed in the literature have only one layer of control. These architectures have several disadvantages such that they unable to integrate into the main utility power grid for importing or exporting the active/reactive powers based on technical and economic considerations, i.e. they can work only in islanded mode, as in [23], [24], [26]- [28]. Moreover, these architectures suffer from deviations in the frequency and voltage due to the using of droop control methodology for realizing accurate active/reactive power-sharing, as in [22], [29], [30]. In contrast to these architectures, the proposed architecture has four layers of coordinated hierarchical control (HC) to be able to operate in both isolated mode and grid-integrated mode, and also to remove the deviations in microgrid's frequency and voltage. The four layers of HC control are primary, secondary, synchronization and tertiary control layer. Recently, many types of research have focused on suggesting the different strategies of HC applied to AC, DC and hybrid microgrids [31]- [33]. In this paper, the four levels of HC are applied to the MUs, whereas the SUs have only the primary control level (PCL). The PCL of the proposed architecture is considered as a decentralized (local) control and employed to achieve accurate power-sharing between the two MUs and to regulate the whole microgrid's voltage and frequency through these MUs, as in [4], [6], [34]. Moreover, new additional objectives are proposed and assigned to this PCL in this study. These objectives include the ability to extract the maximum power from RERs based SUs without using DC-to-DC converters and regulate the reactive power of microgrid via these SUs. The three-phase voltage source inverters (VSIs) are usually used as interfacing modules for MUs and SUs. The PCL of MUs includes the voltage and current inner control loops, the outer droop control loops, and the new added intermediate loops of the virtual inductor in rotating dq-frame and high pass filter (HPF). The droop control loops used in this paper are called P-F/Q-V droops and required to accurately share real and reactive powers among multiple paralleled MUs [34]. These drooping control loops with the virtual inductor and HPF loops are employed to prevent circulating currents among master DG units without needing critical communication lines among these units [4]. The HPF is used with the virtual inductor to avoid the deterioration of transient performance and guarantee the seamless transition between islanding mode and grid-integrated mode. Moreover, the HPF is employed to guarantee accurate active/reactive power-sharing among the MUs. The droop control strategy requires only the local measuring of feedback signals (voltages/currents). On the other hand, the PCL of SUs contains the inner current control loops and the outer active and reactive power control loops. Furthermore, the secondary control level (SCL) is applied only to MUs to remove the deviations in the output voltage amplitude and frequency created by the droop control loops in PCL. Additionally, the third control layer of synchronization is essential to remove the differences in voltage magnitude, phase and frequency between the microgrid and main utility network to prepare the islanded microgrid to be smoothly reconnected back to the main utility network after islanding. After this synchronization process is achieved, the microgrid can be connected to the main power network through the static transfer switch [34]. Previous research works [35], [36] provide different control methodologies and architectures of secondary control. Moreover, the tertiary control level (TCL) is employed to control and manage the power flow between the microgrid and the main power network to obtain the microgrid's most optimal operational cost.
Another vision of this paper is to introduce optimal design procedures for selecting the four-layer HC controllers' parameters to fulfill the study objectives. These objectives aim to damp the oscillations, eliminate the steady-state errors in the microgrid's frequency and voltage, achieve a smooth transition from isolated mode to grid-tied mode, and improve the quality of output powers. The optimization problem of designing the controllers' parameters of microgrid's four-layer HC is tackled throughout four stages to achieve the study objectives. The first stage is to optimize the controllers' parameters of the PCL for master and slave units. Then, the second stage is employed to find the optimal controllers' coefficients of the SCL for MUs. Afterward, the parameters of synchronization controllers for MUs are optimized throughout the third stage. The last stage is used for the optimal parameter-tuning of the TCL compensators for MUs. In this paper, the optimization procedures are applied directly to the nonlinear simulation model, in which the fitness function (FF) is incorporated directly in the results of the simulation. Consequently, the results of optimization procedures in this work are more practical and accurate than those of small signal model simplified and linearized around certain operating conditions. The small-signal analysis based on conventional design procedures were discussed in [37]. In contrast to the trial-error method, the proposed optimal design procedures are more efficient, effective, and save more time. These optimal procedures depend on a new proposed hybrid optimization methodology based on the combination between the Harris hawks optimization (HHO) algorithm [38] and particle swarm optimization (PSO) [39]. This new hybrid algorithm is named as H-HHOPSO. The hybrid algorithms are developed by hybridizing two or more of algorithms. In this paper, the hybridization between HHO and PSO aims to improve the exploration facility in HHO and exploitation in PSO. Several hybrid meta-heuristic algorithms have been proposed to enhance the convergence performance and accuracy of individual algorithms. In [40], a novel hybridization between grey wolf optimizer (GWO) and sine cosine algorithm (SCA) for optimization problems was introduced. A new combination between PSO and salp swarm algorithm for the optimal design of the microgrid droop controller had been suggested in [41]. W. Fu, et al. presented a novel hybrid SCA-HHO approach for fault diagnosis of rolling bearings [42]. A new hybridization between HHO and differential evolution algorithm for color image multi-level threshold segmentation has been developed by Bao et al. [43].
Firstly, in this work, the H-HHOPSO algorithm is coded in MATLAB R2018a and then applied for solving well-known standard twenty-three benchmark functions to confirm its effectiveness. Its performance is investigated and compared with several previously developed algorithms, including PSO, HHO, GWO [44], SCA [45], PSOGWO [46], whale optimization algorithm (WOA) [47], dragonfly algorithm (DA) [48], and ant lion optimizer (ALO) [49]. Secondly, H-HHOPSO, PSO, HHO and GWO algorithms, with the cooperation of the different types of proposed multi-objective functions, are used for tackling the problem of designing the controllers' coefficients of the four-layer HC implemented on the proposed microgrid architecture. The results of the proposed optimal procedures are evaluated and compared with those of a conventional approach. In addition, the experimental testbed is done using the hardware-in-the-loop (HIL) real-time emulation based on C2000 TM microcontroller TMS320F28377S Launchpad development kit, to demonstrate the benefits of the proposed optimal controllers under real-time conditions. HIL emulation is the most promising methodology for faster testing and developing complex control systems in a safe and low-cost environment [50]. Finally, a comparison between the simulation and experimental results is made.
The major contributions of the work presented in this article can be summarized as follows 1. A new hybrid evolutionary algorithm, namely H-HHOPSO, are proposed and developed by synthesizing HHO with PSO to integrate the exploitation ability in HHO with the exploration ability in PSO to combine the strength of both algorithms. 2. A comprehensive comparative study is carried out to examine and confirm the efficacy of the proposed H-HHOPSO algorithm with eight types of the existing optimization algorithms. The obtained results consistently clarify that H-HHOPSO algorithm is extremely competitive and can be employed to tackle various types of engineering problems. 3. A new modified AC microgrid architecture, composed of multiple grid-supporting MUs and multiple grid-feeding SUs, is introduced to easily integrate ESEs, REMSs and loads as a microgrid with guaranteeing more flexibility, reliability and redundancy than architectures in the literature. Four hierarchal control layers were applied to this architecture to able to operate not only in isolated mode, but also in grid-tied mode. 4. The new H-HHOPSO algorithm with the aid of many types of suggested multi-objective functions had been proposed to tackle one of the most complex microgrid technical problems represented in the optimum design of its controllers' coefficients of four control levels to achieve the study objectives. The optimization constraints/objectives were to minimize the tracking errors for microgrid's frequency and voltage, and output active and reactive power, and also to enhance the quality of output powers and guarantee a seamless transition between grid-tied and isolated operation mode. 5. Real-time HIL emulation and MATLAB/SIMULINK simulations were conducted to demonstrate the effectiveness of the proposed architecture and H-HHOPSO algorithm.

II. NEW PROPOSED H-HHOPSO OPTIMIZATION ALGORITHM
In this section, a new hybrid optimization algorithm named H-HHOPSO is presented to be used afterward to tune the controllers' parameters of four-layer HC for the new microgrid architecture. The H-HHOPSO is developed by hybridizing between HHO and PSO optimization algorithms. The aim of H-HHOPSO algorithm is to enhance the ability of exploitation in PSO and improve the ability of exploration in HHO. PSO is selected to be synthesized with the HHO algorithm due to its convergence speed, simplicity, few parameters, robustness, and exploration ability. PSO was introduced in 1995 by Eberhart and Kennedy as an evolutionary computation algorithm. This algorithm is one of the most wellknown meta-heuristics inspired by the social behavior of swarms such as fishes schooling and birds flocking. PSO algorithm mimics the food searching mechanism of these swarms in nature. The mathematical model of PSO algorithm can be found in [39]. Recently, HHO has been proposed in 2019 as a novel meta-heuristic inspired by Harris' hawks in nature. HHO mimics the cooperative strategy and chasing mechanism of Harris' hawks for catching the prey, which is usually a rabbit. HHO was mathematically modeled and discussed in [38]. The updated positions of Harris' hawks are improved by involving PSO with HHO. The inertia weight α (k) of PSO, mentioned in (6), is employed to improve and modify the positions of Harris' hawks in HHO. The velocity and position equations in the PSO algorithm are used to update Harris' hawks' positions according to (3) and (4). The movements and updated positions of Harris' hawks are based on the escaping energy of the prey E prey illustrated in (5). If E prey ≥ 1, then the Harris' hawks are in the exploration phase and randomly perch in different locations and wait for the detection of prey based on two modified mechanisms represented by the following set of equations where Here, X (k + 1) are the updated positions of hawks in the next iteration k; X (k) are the current positions of hawks, X prey (k) is the position of prey; α (k) is the PSO time-varying inertia weight, which is calculated based on the iteration number; LB and UB are the lower and upper bounds of optimization problem variables; d 1 , d 2 , d 3 , d 4 , d 5 , and q are random coefficients which are often in the range [0-1] and updated in each iteration; max_iter is the maximum number of iterations; α max and α min are the maximum and minimum inertia weights of PSO algorithm, which equal 0.9 and 0.2, respectively; X mean (k) is the mean current position of the VOLUME 9, 2021 hawks population; X rand (k) is the hawk position which is selected randomly from the current population, N is the total number of search agents (hawks); X i (k) is the position of hawk i at iteration k. v (k + 1) is the updated velocity of particle in PSO; E prey is the escaping energy of the rabbit (prey); E 0 is the initial value of escaping energy of the rabbit. If E prey < 1, then the Harris' hawks transition from the exploration phase to the exploitation phase. In this situation, the Harris' hawks attack the prey using four strategies concerning the prey's behavior. The hawks update their positions according to the modified set of equations described in (8), (9) and (10). If r < 0.5, then the prey escapes successfully from the hawks; otherwise, the prey fails to escape. The first strategy is called hard besiege, applied when E prey < 0.5 and r ≥ 0.5. In this strategy, the positions of hawks are updated according to the modified set of equations shown in (11), (9) and (10). The second strategy is called soft besiege, applied when E prey ≥ 0.5 and r ≥ 0.5. In this situation, the behavior of hawks can be modeled by the modified equations illustrated in (12), (9) and (10). In the third and fourth strategy, the prey tries to escape by several zigzag misleading motions. The third strategy is called soft besiege with progressive rapid dives applied when E prey ≥ 0.5 and r < 0.5. If F(C) < F (X (k)), then the locations of hawks are updated by modified equations clarified in (13), (9) and (10). If F(D) < F (X (k)), then the hawks update their positions by (14), (9) and (10). The fourth strategy is called soft besiege with progressive rapid dives applied when E prey < 0.5 and r < 0.5. If F(Y) < F (X (k)), then the hawks update their positions by (15), (9) and (10). If F(Z) < F (X (k)), the positions of hawks are updated by (16), (9) and (10). where Here, J is the random jump strength of the prey during the escaping behavior, which randomly changes in each iteration to mimic the nature of prey movements; d 6 , d 8 , r, and d 9 are random numbers which are usually between [0-1]; LF (x) is the levy flight function; d is the dimension of variables; d 7 is a random vector with dimension 1 × d; and γ is constant adjust to 1.5. Figure 2 depicts a flowchart of the new proposed H-HHOPSO optimization algorithm. Different types of benchmark functions with different properties must be used and employed to appropriately investigate both exploration and exploitation performance of any algorithm. In this paper, the benchmark functions are twenty-three well-known test problems which are considered as minimization functions and classified into three categories: multimodal, unimodal and fixed-dimension multimodal functions. The unimodal functions are from F1 to F7, multimodal functions are from F8 to F16, and fixed-dimension multimodal functions are from F17 to F23. For any algorithm, the multimodal functions are used to test its exploration ability, while its exploitation ability is tested using unimodal functions [44]. The new proposed H-HHOPSO algorithm is applied to tackle these benchmark problems to test and evaluate its performance. Moreover, to confirm its effectiveness, the attained findings are compared with those of eight previously published algorithms, including PSO, HHO, DA, WOA, ALO, SCA, GWO, and PSOGWO. The twenty-three well-known benchmark functions can be found in [44]. The proposed H-HHOPSO algorithm and the other eight algorithms were run 30 times on each test function. The statistical results, including average (ave) and standard deviation (std), are given in Table 1. The number of search agents is set to 30 and the maximum number of iterations is 500. Figure 3 illustrates a comparison of convergence performance between the proposed H-HHOPSO algorithm and the other eight algorithms for functions F1, F2, F3, F4, F5, F6, F7, and F8. It can be observed from Table 1 and Figure 3 that the new proposed H-HHOPSO algorithm is more effective and efficient than the other existing algorithms. The results in Table 1 show that the H-HHOPSO algorithm provides very competitive results and has a superior performance.
The H-HHOPSO technique outperforms all others in functions F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, and F19. The high performance of H-HHOPSO is due to the integration of the abilities of HHO in exploitation and PSO in exploration. Finally, it can be concluded from the simulation analysis and statistical results that the proposed H-HHOPSO algorithm is the most promising among the existing optimization algorithms in solving the twenty-three benchmark functions.

III. THE PCL AND OPTIMIZATION FOR ITS CONTROLLERS
The PCL is the first control layer of HC required for satisfying the following objectives: (1) regulation and stabilization of the microgrid's frequency and voltage via grid-supporting MUs empowered by ESEs, (2) responsibility of plug and play capability of DG units and realizing accurate power-sharing among MUs via droop control method without using any communications (3) mitigation of the circulating currents among DG units (4) obtaining the maximum power from REMSs based grid-feeding SUs and regulating the microgrid reactive power via these SUs. In this section, two control strategies are discussed. The first strategy deals with grid-supporting MUs, whereas the second deals with gridfeeding SUs. The grid-supporting MU is controlled as a voltage source with series output impedance, whereas the grid-feeding SU is controlled as a current source with paralleled high output impedance.

A. THE PCL OF MASTER UNITS AND OPTIMIZATION FOR ITS CONTROLLERS
The proposed PCL of grid-supporting MUs is illustrated in Figure 4. It includes the outer droop control loops, the new added intermediate loops of virtual inductor and high pass filter, the inner voltage control loops, and the inner current control loops. The ESEs are interfaced with the microgrid through the VSIs, which operate as grid-supporting MUs. The following set of equations can represent the voltage and current dynamics of these VSIs in synchronous dq-frame d dt where, i fd , i fq , V id and V iq are the inverter side currents and voltages in dq-axis; V cd , V cq , V od and V oq are the filter capacitor and point of common coupling (PCC) voltages in dq-axis; ω is the grid angular frequency; i od and i oq are the output currents in dq-axis; L c and R c are the inductance and resistance of coupling output inductor, respectively; and C f , L f and R f are the capacitance, inductance and resistance of the LC-filter, respectively. The components of instantaneous real and reactive powers can be calculated as a function of d-and q-axis voltages and currents as follows The instantaneous powers can be processed through the LPF to improve the quality of injected power as follows where, ω cL is the cutoff frequency of the LPF. The droop control strategy is used to mimic synchronous generators' behavior to increase the virtual inertias of the grid-supporting inverters-based MUs. This behavior reduces the frequency when the output active power increases. Similarly, the voltage amplitude is decreased when the output reactive power is increased. The droop characteristics are artificially created for the grid-supporting MUs to behave the same as the synchronous generators in a traditional power network. This principle allows the powers to be equally shared among the MUs without any communication links. The dynamics of P-F/Q-V droop control loops are given by [4] where, ω * and V * are the reference (nominal) values of angular frequency and voltage magnitude at no load; and D Pi and D Qi are the droop coefficients of angular frequency and voltage amplitude for ith unit, respectively. These coefficients can be determined as follows where, ω max , ω min , V cdmax and V cdmin are the permissible maximum and minimum boundaries of angular frequency and voltage magnitude, respectively; P max and Q max are the maximum output real and reactive power. The following constraints should be fulfilled to realize a power-sharing among MUs The inner voltage control loops are employed to regulate the VSI output voltage closely. The reference currents in the dq-axis can be generated by PI voltage controllers, feed-forward parts and decoupling terms. The dynamics of the inner voltage control loops are as follows where, Here, µ is the feed-forward gain; and K ppv and K ipv are the parameters of primary voltage PI controllers.
The inner current control loops are required for shaping the voltage across the filter inductance to minimize the error in the current. The currents in the dq-axis can be regulated using PI current controllers, feed-forward parts and decoupling terms. The dynamics of the inner current control loops can VOLUME 9, 2021 be expressed as where, Here, K ppi and K ipi are the parameters of primary current PI controllers.
The new virtual inductor and HPF control loops in synchronous dq-frame are implemented and added to the PCL of grid-supporting to improve the droop control strategy's performance and reliability. These new loops achieve accurate power-sharing among the MUs and guarantee a smooth transfer between the isolated and grid-tied modes. The output series impedance of VSI, used in MU, is predominantly inductive because of using LCL-filter. This output impedance should be made more inductive using the virtual inductor to avoid the coupling between the real and reactive power. Consequently, the droop control loops can adjust independently both the active power according to the phase (power) angle and the reactive power according to the voltage amplitude. An additional physical inductor can be carried out instead of the virtual inductor, but this causes power losses and increases the size and cost. In this work, the virtual inductor is carried out in rotating arbitrary dq-axis to avoid the differential calculation, resulting in the noises being amplified and causing instability issues. The virtual inductor increases the inertias of the MUs, which lead to mitigate the over-shoot of the dynamic response, but the system regulation becomes slow. Therefore, the HPF is used to enhance both the swiftness and the closeness of the system. The direct current components in the dq-frame, equivalent to the fundamental currents in fixed αβ-frame, can be eliminated and filtered using the HPF. Therefore, the fundamental frequency response does not affected by the virtual inductor. At the same time, good damping of transient response and harmonics currents is still achieved.
The dynamics of virtual inductor and HPF loops can be given by where, V dref and V qref are the references of voltages in dq-axis after adding the virtual inductor and HPF loops; and ω cH is the cutoff frequency of the HPF. Figure 5 shows the effect of adding or removing the HPF on active and reactive power-sharing between two MUs. The HPF is inserted into the control system at the microgrid initiation, then removed at time 1 s, and lastly returned back at time 1.3 s. It can be observed that when the HPF is added, the active and reactive powers are equally shared between two MUs. However, when the HPF is removed, the sharing of active and reactive power between two MUs is deteriorated and the microgrid may be exposed to instability issues. The proposed H-HHOPSO algorithm is used for optimal parameter-tuning of the controllers of PCL for MUs. Several multi-objective functions were applied and compared at the same constraints and variables range to fulfill the control requirements, including the improvement of power quality and enhancing the dynamic and steady-state performance under the different operating conditions. The best results were obtained by the multi-objective function mentioned in (33). This multi-objective function minimizes the arithmetic sum of the following: the total harmonic distortion (THD) in voltage, the THD in current, ITAE in d-axis voltage, ITAE in q-axis voltage, ITAE in d-axis current, ITAE in q-axis current, ITAE in angular frequency, and ITAE in voltage amplitude.
The optimization problem of designing the controllers' coefficients of PCL for MUs can be formulated as where, β 1 , β 2 and β 3 are weighting coefficients determine the priority of terms in above multi-objective error function; THD v is the THD in voltage; THD i is the THD in the current; e d_ω and e d_V are the droop control errors in angular frequency and voltage magnitude; e p_Vd and e p_Vq are the errors in d-and q-axis primary voltages; and e p_id and e p_iq are the errors in d-and q-axis primary currents.
In this optimization problem, the Harris hawks represent the search agents used to search in the solution space for the best variables, which are the optimal controllers' parameters of the PCL of MUs. There are many parameters that are fed to any intelligent optimization algorithm and are required to be appropriately adjusted to obtain the optimal results. These parameters include the number of iterations, the dimension of variables, the FF value, the number of search agents, and the upper and lower boundaries of variables. In this paper, the numbers of search agents and iterations are 20 and 30, respectively. Moreover, all optimization problems in this work were run ten times to get the best statistical results.

B. THE PCL OF SLAVE UNITS AND OPTIMIZATION ITS CONTROLLERS
The PCL of grid-feeding SUs is shown in Figure 6. It includes the outer active and reactive control loops, and the inner current control loops. The REMSs are interfaced to the microgrid through the VSIs which work as grid-feeding SUs. The phase locked loop is used for the SUs to be synchronized with the MUs. The active power reference of SU is generated by the maximum power point tracking unit, whereas the set-point of the reactive power is adjusted by the microgrid system VOLUME 9, 2021 FIGURE 6. Primary control methodology for grid-feeding SUs [25].
operator. The dynamics of outer power control loops can be given by where, K pP and K iP are the parameters of PI power controller;i SU dref and i SU qref are the current references in dq-axis; and P SU meas , Q SU meas , P SU ref and Q SU ref are the measured values of active and reactive power and their references, respectively.
The output currents in dq-axis can be regulated using PI current controller, decoupling terms and feed-forward parts. The dynamics of inner current control loops can be expressed as where, K pi and K ii are the parameters of PI current controller; i SU od and i SU oq are the measured currents in dq-axis; L fSU is the SU filter inductance; and V SU od and V SU oq are the output feedforward voltages in dq-axis.
The new proposed H-HHOPSO optimization algorithm is employed and cooperated with the multi-objective function illustrated in (36) to find the optimal parameters of SU controllers. The optimization problem for selecting the optimal coefficients of these controllers can be formulated as where, e P and e Q are the errors in active and reactive power; and e id and e iq are the errors in d-and q-axis currents.

IV. SCL AND OPTIMIZATION OF ITS CONTROLLERS
Due to using the droop control strategy in PCL, the voltage and frequency of microgrid are deviated from their reference values according to the droop coefficients and load power. Consequently, the second layer of control called SCL is required. The secondary control layer's functionality is to remove all deviations in frequency and voltage amplitude resulted from droop loops to restore their reference values. When the microgrid is worked in standalone mode, all distributed generators are controlled for supplying the power to loads by taking into account the permissible limits in frequency and voltage magnitude deviations recommended by IEEE and IEC Standards. The allowable deviations limit of voltage amplitude is lesser than ±5% of its nominal value, whereas the limit of frequency deviations is smaller than ±1.5% of its nominal value [51]. Considering utility network requirements [52], the deviations in frequency should be corrected to become within the acceptable limit, which is ±0.2Hz in UCTE (Continental-Europe) or ±0.1Hz in Nordel (North-of-Europe). In order to produce the secondary compensation signals required for eliminating the voltage and frequency deviations produced by PCL, the angular frequency and voltage magnitude of the microgrid ω meas MG and V meas MG are measured and compared with their reference values ω ref MG and V ref MG . The obtained differences are then processed through PI controllers to generate the secondary compensation signals to be sent and fed the droop control loops for each MU. The secondary control correction signals δω res sec and δV res sec can be expressed as [4] δω res where K psω , K isω , K psV and K isV are the control coefficients of the PI SCL compensators, and ω syn and V syn are the synchronization compensation signals which remain have zero value when the utility power network is absent. In this situation, δω res sec and δV res sec should be restricted to avoid exceeding the maximum allowable voltage magnitude and frequency deviations.
After the controllers' parameters of the first control layer were optimized in the previous section, an optimal design procedure is proposed in this section to appropriately select compensators coefficients of the second control layer. These coefficients are K psω , K isω , K psV and K isV . The optimization objectives are to minimize the steady-state error, rise time, settling time, and maximum overshoot for microgrid frequency and voltage after applying the second layer of control. In this case, PSO, GWO, HHO and H-HHOPSO algorithms are adopted, applied and collaborated with several types of multi-objective error functions, including integral square error (ISE), integral absolute error (IAE), integral time square error (ITSE) and integral time absolute error (ITAE). This optimization problem requires the multi-objective error functions to be minimized. Figure 7 explains the block diagram of SCL based on the proposed optimal controllers for grid-supporting MUs. The SCL errors in voltage amplitude and frequency, e sec V and e sec ω , are measured to be used for calculating four proposed types of multi-objective error functions as follows where ζ 1 and ζ 2 are weighting coefficients determine the priority of terms in above multi-objective error functions. Many parameters such as the maximum number of iteration, number of search agents, and maximum and minimum limits of variables should be carefully selected. They are then fed alongside the above calculated multi-objective functions into the parameters tuning optimizers to obtain the optimal coefficients of SCL controllers. In this optimization problem, the maximum and minimum limits of the SCL controllers' parameters required to be optimized are  Each of the algorithms is applied individually with each one of four multi-objective functions, and then the obtained results are evaluated and compared to get the optimal solution that represents the best controllers' parameters of SCL.
In order to evaluate the performance of proposed secondary controllers, an autonomous microgrid consisting of only one master DG unit, based on primary and secondary control levels, is modeled and simulated using MATLAB/ Simulink. Figure 8 shows the responses of microgrid frequency and voltage in cases of H-HHOPSO, PSO, GWO and HHO algorithms based optimal secondary controllers. The objective functions and optimized parameters of SCL controllers obtained by the proposed optimal design guidelines are illustrated in Table 2. A comparison of settling time and percentage overshoot for H-HHOPSO, PSO, GWO and HHO algorithms based optimal secondary controllers and conventional secondary controller are given in Table 3. Figure 9 depicts a comparison of frequency, voltage magnitude, and active and reactive powers of microgrid under load variations in cases of the optimal secondary controller, conventional secondary controller and without SCL. It can be observed from Figure 9 that without using SCL, both voltage amplitude and frequency are deviated from their reference values according to the droop coefficients and the load  connected. These deviations are eliminated by using SCL. Furthermore, it is evident from Table 3 and Figure 9 that the conventional secondary controller suffers from undesirable oscillations and high overshoot and settling time in responses of voltage, frequency, and active and reactive powers. Moreover, it can be noticed from Figure 8 and Table 3 that the H-HHOPSO algorithm based secondary controller introduces better dynamic response and reaches the nominal frequency (50Hz) and voltage amplitude (311.13Volt) in the minimum  Table 4 clarifies the comparison between conventional, PSO, GWO, HHO and H-HHOPSO based controllers on the basis of THD levels for output voltage and current waveforms for five-cycles with a fundamental frequency of 50 Hz. Figures 10 and 11 display the output voltage and current waveforms with their harmonics spectrum in cases of conventional controllers and H-HHOPSO based controllers, respectively. Finally, the results obtained by the proposed optimal guidelines are better than those of previously published research works in this scope. Reference [53], at microgrid initiation, the maximum overshoot and settling time are 0.53% and 0.111 s for voltage, and 0.52% and 0.339 s for frequency. However, in this research work, the maximum overshoot and settling time were 0.0367% and 0.0669 s for voltage, and 0.036647% and 0.30748536 s for frequency. The voltage controller addressed in [54] produces an overvoltage of 20% during the steady-state condition (from 0.5 s to 0.7 s of the simulation). In [55], the frequency is settled at 59.8Hz after microgrid insertion and at 59.7Hz after load change achieving a declination of 0.5% from its nominal value of 60Hz. Unlike the previously published works, the proposed optimal controllers in this paper can reach and maintain the nominal values of frequency and voltage with achieving minimum values of settling time and overshoot and without any deviations or oscillations around the desired values.

V. SYNCHRONIZATION CONTROL APPROACH AND OPTIMIZATION OF ITS CONTROLLERS
The synchronization process is a critical procedure required for preparing the standalone microgrid to be inserted into the main utility grid. To guarantee a seamless transition from standalone mode to grid-tied mode, the PCC of the microgrid VOLUME 9, 2021  must be synchronized with the main power network in voltage amplitude, frequency and phase. Active synchronization control methodology is used to prepare the islanded microgrid to be smoothly reconnected back to the main utility network after islanding. This control strategy is responsible for allowing a droop-controlled based microgrid to adjust the voltage magnitude, phase and frequency before connecting to the utility power grid. The synchronization process is necessary to remove the difference of instantaneous voltages between the microgrid PCC and the main utility grid. The difference in the voltage phase angle for three-phase microgrid can be determined as where V Gαβ and V MGαβ are the voltages of the main utility grid and PCC of the microgrid in stationary αβ-axis. The difference of the voltage magnitude is calculated as follows The goal of the synchronization control method is to make the values of e synθ and e synV equal to zero for eliminating the differences in phase angle, frequency and voltage magnitude between the microgrid and main utility network. This can be achieved using PI controllers to obtain the synchronization correction signals to be sent and added to droop control loops of each MU. These compensation signals ω syn and V syn can be expressed as [56] where K syn pω , K syn iω , K syn pV and K syn iV are the control parameters of the PI synchronization controllers. Figure 12 shows the block diagram for generating the synchronization correction signals of a droop-controlled microgrid.
The aiding of optimization algorithms can appropriately achieve the objectives of the grid synchronization process. The H-HHOPSO algorithm is used to obtain the optimal parameters of PI synchronization controllers. Several objective functions were applied and compared at the same constraints and variables range to meet the requirements of distributed generators synchronization recommended by IEEE Standard 1547-2003 [57] and listed in Table 5. The best results obtained by the FF in (45) which minimizes the arithmetic sum of both ITAE of voltage amplitude and ITAE of the voltage phase angle. To prevent significant inrush current and guarantee a seamless and successful transfer to grid connected mode, synchronization recommendations in the table must be replaced by more stiff exigencies [56]. Consequently, the optimization problem is subject to three rigid constraints. These constraints and optimization problem of the synchronization process for selecting the    A Flow chart of the proposed optimization procedure for the synchronization process is depicted in Figure 13. Firstly, the simulation model is run to calculate the FF. Then, the FF value is stored in the workspace to be fed to H-HHOPSO algorithm. The algorithm's inputs are FF value, the number of search agents, each search agent's dimension, maximum number of iteration, and upper and lower limits of variables. In this optimization problem, the Harris hawks represent the search agents employed to find the optimal variables in the solution space, which are the best PI synchronization controllers' parameters. Initially, each search agent generates a randomly possible parameter vector solution, which will be updated according to algorithm strategy. The possible parameter vector of PI synchronization controllers is sent to MAT-LAB/Simulink model for investigation. For each possible parameter vector, the simulation model runs and calculates some variables, which are V, θ and f . Each search agent's variables are compared and evaluated according to the constraints to obtain the best result. When the constraints are violated, the strict penalty factor is applied to FF. This process is repeated until the maximum number of iteration is reached or the optimal solution is obtained. Figure 14 illustrates the instantaneous voltage difference between the utility power network and microgrid during the synchronization process. It can be observed that the instantaneous voltage difference is decreased from 186.6 volt (peak) before synchronization to roughly 2 volt (peak) after the end of the synchronization process. However, the synchronization controller proposed in [52] gives a voltage difference of 3 Volt (peak) after the synchronization process is finished. The voltage waveforms of the utility power grid and microgrid during the synchronization process are clarified in Figure 15. Figure 16 displays the phase angle difference  between the utility power grid and microgrid during the synchronization process. It can be noticed that the phase angle difference is minimized from 35.78 • before synchronization to 0.76 • after synchronization. Finally, it can be concluded that the obtained differences in voltage, frequency and phase angle satisfy the more rigid exigencies needed for achieving a smooth and successful connection to the utility power network.

VI. TERTIARY CONTROL LEVEL AND OPTIMIZATION OF ITS CONTROLLERS
The upper layer of hierarchal control is known as TCL. The TCL is responsible for managing power flow by controlling and adjusting the voltage amplitude and frequency when the microgrid is connected to the utility main grid. The structure of TCL is shown in Figure 17. Firstly, the active/reactive powers of the microgrid, P meas G and Q meas G , are measured at the PCC and compared with their reference values, P ref G and Q ref G . Secondly, the obtained differences, e tP and e tQ , are processed FIGURE 17. Four-layer coordinated HC based the new modified microgrid architecture. VOLUME 9, 2021 through PI controllers to give the tertiary control signals as follows [4]: where K ptP , K itP , K ptQ and K itQ are the control parameters of PI TCL controllers. The tertiary control signals, ω ref MG and V ref MG , are the references of frequency and voltage amplitude, which are internally generated inside SCL when the microgrid is working in islanded mode. However, when the utility main network is present, the synchronization procedure starts and TCL signals are calculated by (46) and (47) to be further used after synchronization as desired references to SCL, as in (37) and (38). TCL can manage the importing or exporting of active and reactive powers between the main grid and microgrid for achieving an economically optimal operation of the microgrid. The references of active and reactive powers, exchanged between the microgrid and the utility power grid, are determined by artificial intelligence algorithms based on the energy management system (EMS). The electricity market, load demand, technical considerations, and predicted generation from renewables are the input variables to the EMS for making optimal decisions. The direction of power flow can be determined as follows: if microgrid frequency ω ref MG is greater than the main grid frequency ω G then the active power P G is injected from the microgrid to the main grid (i.e., P G > 0). However, if ω ref MG < ω G then P G is absorbed from the main grid to the microgrid (i.e., P G < 0). The same analysis can be performed for the reactive power Q G .
The hybrid H-HHOPSO algorithm is employed for tackling the problem of designing the controller coefficients of TCL to improve its dynamic and steady-state performance. The FF is selected to minimize the arithmetic sum of both ITAE of active power and ITAE of reactive power. Here, the optimization problem of TCL for searching and obtaining its optimal controllers' parameters can be formulated as

VII. SIMULATION RESULTS AND DISCUSSIONS
The four-layer coordinated HC based the new modified microgrid architecture, shown in Figure 17, is modeled and simulated in MATLAB/SIMULINK, and examined under the variations of generations and consumptions. Moreover, this structure is tested when the fault occurs at any one of MUs, and during the transitions between isolated mode and grid-tied mode. The new microgrid configuration under study consists of two grid-supporting VSIs emulate two energy storage MUs, and two grid-feeding VSIs emulate WECS and PVPS, as illustrated in Figure 17. The proposed microgrid parameters and optimal coefficients of HC controllers are listed in Table 7. In this study, the battery state of charge will not be taken into consideration for simplification. The plug and play capability of WECS and PVPS to the proposed microgrid is verified and validated. Furthermore, the proposed optimal controllers of four-layer coordinated HC are applied and examined to prove their effectiveness and robustness. Three scenarios are proposed, simulated and discussed in the following subsections to investigate the feasibility of the new microgrid architecture.

A. SCENARIO I
In this scenario, the plug and play capability of WECS and PVPS to the proposed microgrid is examined and evaluated. Moreover, the reactive power's injection and absorption capabilities for the master and slave units are investigated. Furthermore, the proposed microgrid's performance is verified during the three steps of load change and during the interruption of any one of MUs. Moreover, the power-sharing between the two MUs is confirmed throughout this scenario. The WECS and PVPS inject their maximum power points to the microgrid, while the energy storage MUs support and regulate the frequency and voltage for the microgrid, as clarified in Figure 17. In this scenario, the microgrid is operated in an islanded mode. Figure 18 describes the active and reactive powers' tracking behaviors when the WECS, PVPS and loads 1&2&3 are plugged and played to the microgrid.
Initially, the load 1(36 kW and 27 KVAR) is connected to the microgrid, and the two MUs, ESS1 and ESS2, generate and maintain the frequency and voltage of the microgrid. At this instant, the two MUs inject the active and reactive powers to the microgrid for power balancing between generations and consumption.The active and reactive powers are shared equally between the two MUs, which have the same power rating. Suddenly, the WECS is connected at 1 s to the microgrid and injects 40 kW and 0 kVAR. The WECS delivers all the active power demanded by load 1 and the extra active power (4 kW) is charged in the two MUs equally. The two MUs support equally all the reactive power consumed by the load 1.
At time 2 s, the PVPS is suddenly plugged and played to the microgrid and inject 30 kW and 0 kVAR. The surplus active power (34 kW) is absorbed equally by the two MUs to keep the microgrid's frequency and voltage. The two MUs are still supplying equally all the reactive power demanded by the load 1. Another load of 34 kW and 6 kVAR is connected at time 3 s to the microgrid. Simultaneously, the PVPS is adjusted to absorb 10 kVAR from the microgrid, therefore the two MUs increase their output reactive power to 21.5 kVAR each to compensate for those required by loads (33 kVAR) and PVPS (10 kVAR). Moreover, the active power of two MUs becomes zero, and the WECS and PVPS generate all active power consumed by the load 1&2.
After 4 s, the active power generated by the WECS is reduced from 40 kW to 30 kW. Thus, the two MUs increase their output active power from 0 kW/unit to 5 kW/unit to compensate for the active power imbalance between the generations and consumptions. At the same time of 4 s, the absorbed reactive power by PVPS is adjusted to return back to zero, while the WECS is adjusted to absorb 10 kVAR from the microgrid. The MUs are maintained to supply the same amount of reactive power (21.5 kVAR each).
After 5 s, the third load of 20 kW and 4 kVAR is connected to the microgrid. Consequently, the discharged active power of the two MUs is increased from 5 kW/unit to 15 kW/unit to compensate for the active power consumed by the third load. At the same time of 5 s, the absorbed reactive power by WECS is adjusted to return back to zero, while the PVPS is adjusted to inject 10 kVAR to the microgrid. Hence, the two MUs decrease their output reactive power from 21.5 kVAR/unit to 13.5 kVAR/unit. It can be observed that there is a power balance between generations and consumptions. After 6 s, the ESS1 is disconnected from the microgrid due to the fault. Therefore, the other energy storage master unit, ESS2, increases and doubles its output active and reactive power to compensate for the interrupted power portion of ESS1. The active power of ESS1 becomes zero, while the active power of ESS2 increases from 15 kW to 30 kW. In this situation, the ESS1 is alone able to regulate and maintain the frequency and voltage of the microgrid. Consequently, the microgrid is still operating and delivering the powers to the local loads. At the same time of 6 s, the delivered reactive power of PVPS is adjusted to return back to zero, while the WECS is adjusted to inject 10 kVAR to the microgrid. The output reactive power of ESS1 doubles and rises from 13.5 kVAR to 27 kVAR to compensate for the interrupted reactive power portion of ESS2. Figure 19 depicts the microgrid frequency and voltage during connecting WECS, PVPS and loads, and during the disconnecting of ESS1. It is clear that, at any change, the frequency and voltage of the microgrid are recovered to their nominal values by the MUs.

B. SCENARIO II
In this scenario, the proposed microgrid architecture's behavior is examined during the preplanned transfer from grid-tied mode to isolated mode. The active and reactive powers of renewables and loads during the transition from grid-tied mode to islanded mode are illustrated in Figure 20. Figure 21 shows the performance of the utility grid's active and reactive powers and storage systems for the proposed microgrid architecture during the transition from grid-tied mode to islanded mode. During this scenario, the PVPS is adjusted to inject 20 kW and 0 kVAR, while the WECS is adjusted to deliver 30 kW and 0 kVAR to the microgrid. Before 2 s, the microgrid is tied to the main utility grid. The microgrid's tertiary control layer is adjusted by the EMS to import 20 kW and 5 kVAR from the main utility grid to the microgrid. The local load of 90 kW and 20 kVAR is connected to the PCC of the microgrid. The total active power of renewables and the grid is 70 kW. The Active power difference between production and consumption (20 kW) is supplied by the two MUs equally. Also, these two MUs provide 15 kVAR to compensate for the reactive power imbalance. At 2 s, the microgrid is disconnected from the main utility grid due to preplanned islanding occurrence and then worked in islanded operation. In this instant, the tertiary control layer is deactivated. Therefore, the microgrid is controlled throughout two-layer cascaded control. The first primary layer generates deviations in frequency and voltage, which can be canceled by the secondary control layer. At the same time of 2 s, the active and reactive powers imported from the main utility grid are interrupted and became zero. Consequently, the two MUs increase their output powers equally to compensate for the utility grid's interrupted power portion. The output active power of each MU increases from 10 kW to 20 kW, while the reactive power increases from 7.5 kVAR to 10 kVAR. Afterward, at time 3 s, the load demand is increased from 90 kW and 20 kVAR to 110 kW and 25 kVAR. Hence, the two MUs raise their injected active and reactive power to 30 kW/unit and 12.5 kVAR/unit to compensate for the increasing load demand to maintain the frequency and voltage in the microgrid. Figure 22 describes the grid's currents and load during the transition from grid-tied mode to islanded mode. The microgrid frequency and voltage amplitude during the transition from grid-tied mode to islanded mode are represented in Figure 23. As can be seen from Figure 23, after the transition from grid-tied mode to islanded mode and after the load increasing, the proposed microgrid can recover and settle the frequency and voltage to their nominal values. It can be concluded that the proposed microgrid achieves a successful smooth transfer from grid-connected mode to islanded mode.

C. SCENARIO III
The capability to import and export active and reactive powers between the main utility grid and the proposed microgrid is examined and evaluated throughout this scenario. Moreover, the proposed microgrid architecture's performance is tested and investigated during the transition from islanded mode to grid-connected mode. Active and reactive powers of renewables and loads during the transition from islanded mode to grid-connected mode are shown in Figure 24. Figure 25 illustrates the performance of the utility grid's active and reactive powers and storage systems for the proposed microgrid architecture during the transition from islanded mode to grid-connected mode. During this scenario, the PVPS and WECS are adjusted to inject 20 kW and 0 kVAR each. At the beginning, the synchronization control level is activated to synchronize the proposed microgrid with the main utility network. From the initiation to 1 s, the microgrid is operated in an islanded mode. The local load of 60 kW and 15 kVAR is plugged and played to the microgrid.
The total active power of renewables is 40 kW. Therefore, the two MUs share equally the rest of the demanded active power of load, in which each MU gives 10 kW. Also, each MU supplies 7.5 kVAR to the load. The frequency and voltage in the microgrids are maintained due to the power balance between generations and consumptions. Afterward, at 1 s, the synchronization process was accomplished. Therefore, the static transition switch is closed to connect the proposed microgrid to the power utility grid. Simultaneously, the TCL is activated to exchange the active and reactive power between the proposed microgrid and the main utility network.
The references of active and reactive powers for the TCL are determined by the EMS. From 1 s to 2 s, the TCL adjusts the microgrid to absorb and import 20 kW and 5 kVAR from the utility main grid. Hence, the active power of the two MUs decreases from 10 kW/unit to zero, while the reactive power decreases from 7.5 kVAR/unit to 5 kVAR/unit. From 2 s to 3 s, the active and reactive powers, exchanged between the proposed microgrid and the main power network, are adjusted by the TCL to become zero. Consequently, the active power of the two MUs increases from zero to return back to 10 kW/unit, while the reactive power rises from 5 KVAR/unit to return back to 7.5 kVA/unit. From 3 s to 4 s, the TCL adjusts the proposed microgrid to inject and export 20 kW and 5 kVAR to the main utility grid. Therefore, the active power of the two MUs increases from 10 kW/unit to 20 kW/unit, while the reactive power increases from 7.5 kVAR/unit to 10 kVAR/unit. It can be concluded that the proposed microgrid can import/absorb the power from the grid, and also can export/inject the power to the grid.
Moreover, the proposed microgrid acts like a capacitor when it injects the reactive power to the main utility grid. Additionally, the proposed microgrid acts like an inductor when it absorbs the main power grid's reactive power. Furthermore, the proposed microgrid achieves the unity power factor when the reactive power exchanged between the microgrid and the main power network is zero. The proposed microgrid can improve the low voltage ride-through capability by injecting the reactive power to the main utility grid to maintain the voltage stability and enhance the PCC's power quality. Figure 26 describes renewables and storage systems' currents for the proposed microgrid architecture during the transition from islanded mode to grid-tied mode. Figure 27 clarifies the currents of grid and load during the transition from islanded mode to grid-connected mode.
The microgrid frequency and voltage amplitude during the transition from islanded mode to grid-tied mode are displayed in Figure 28. It can be observed from Figure 28 that after the  transition from islanded mode to grid-connected mode and also after any change in the exchanged power, the proposed microgrid is capable of recovering and settling the frequency and voltage to their nominal values. Finally, it can be concluded that the proposed microgrid guarantees a successful, seamless transfer from islanded mode to grid-integrated mode. This is due to the additional inertia provided by HPF's new added control loops and virtual inductor.

VIII. HIL REAL-TIME EMULATION EXPERIMENTAL RESULTS
The high complexity of control systems motivates researchers to develop more efficient, inexpensive and appropriate real-time testbeds taking into account the following challenges: cost of testing and failure cost, developing time, safety, repeatability, availability, and system variation [50]. The HIL based testing methodologies are kind of real-time simulators used for facilitating the development of complex control systems in a safe, non-destructive and low-cost environment. HIL emulation testbed is implemented by hosting  HIL emulation is more credible and reliable than numerical simulation that operates in ideal environments without considering disturbances, noise and some practical issues leading to fatal failures. HIL emulation aims to individually VOLUME 9, 2021 test the different parts of the control system in real-time simulation to ensure that they are working as planned before applying them to the physical plant (real process). In order to avoid catastrophic failure of the whole system and prevent the endangerment of equipment. In this work, the HIL testbed is carried out to experimentally validate and verify the proposed current and voltage controllers of PCL, as well as frequency and voltage controllers of SCL. The same procedures can test the synchronization and tertiary controllers. In this paper, the host-PC utilized in HIL emulation has a processor of Intel (R) Core (TM) i7 / 4510U CPU@2.00GHz with 8.00GB installed memory (RAM). The external hardware of the Launchpad-TMS320F28377S kit has a 200MHz CPU+200MHz CLA processor with 164KB RAM (parity) and 1MB flash (ECC). The host-PC and TMS320F28377S kit cab be serially communicated with each other through XDS100v2/JTAG onboard emulator using the mini USB cable and the virtual COM port. Figure 29 shows the main parts and communicated real-time HIL emulation testbed signals for testing the proposed controllers. The three-phase VSI with LCL filter and output coupling inductor, loads, abc-to-dq axis transformations, and droop control and virtual inductor loops are modeled and hosted by the PC. However, the current and voltage loops of PCL, and frequency and voltage loops of SCL are implemented on the target C2000 TM microcontroller TMS320F28377S Launchpad development kit. Subsequently, the host-PC transmits many signals to the target TMS320 F28377S microcontroller, including errors in d-axis and q-axis voltages of PCL e p_Vdq , dq-axis currents through filter inductance i fdq , microgrid measured voltage V meas MG , microgrid measured angular frequency ω meas MG , DC voltage bus V dc and voltage phase angle θ. The microcontroller kit receives these signals and, therefore, the microgrid voltage and frequency can be controlled through the loops of controllers implemented on the target kit. Finally, the target kit sends many signals to be received and fed to the model hosted by PC. The signals, received to host-PC, include six switching pulses to be applied to IGBTs of VSI and control actions of SCL δω res sec and δV res sec to be fed to droop control loops. Every sampling time T s of 5e-6 sec, this process will be repeated. Figure 30 and Table 6 depict a comparison between experimental and simulation results for optimal and conventional controllers. It can be observed that there are only insignificant discrepancies between the simulation and experimental results. This is because of the authors' many tries for the optimal selection of sample time, baud rate, and data rate transfer.

IX. CONCLUSION
New modified microgrid architecture, composed of multiple grid-supporting MUs and multiple grid-feeding slave DG units, has been introduced in this paper. Four HC layers, including primary, secondary, synchronization, and tertiary control layer, were carried out and applied to the new configuration to be able to work in both grid-tied mode and islanded mode. A new optimization algorithm called H-HHOPSO was proposed and employed with different types of suggested multi-objective functions to tune PI controllers' parameters of PI controllers for all levels of microgrid control. The proposed algorithm was examined using well-known twentythree benchmark functions to prove its effectiveness. Its performance was evaluated and compared with eight types of the existing optimization algorithms, including HHO, PSO, GWO, SCA, ALO, PSOGWO, WOA and DA. The obtained results reflect a superior performance for the proposed optimization algorithm. The objectives and constraints for the optimization problem of four-layer microgrid HC were to minimize the tracking errors for microgrid's frequency and voltage, and output active and reactive power, and also to enhance the quality of output powers and guarantee a seamless transition between grid-tied and isolated operation mode. The newly modified structure was modeled, simulated in MATLAB/SIMULINK and examined under the variations of generations and consumptions. Furthermore, this configuration was tested when the fault occurs at any one of MUs, and also during the transitions between the grid-connected mode and autonomous mode. These tests confirmed that the proposed architecture has more efficiency, redundancy, flexibility, reliability and stability than the conventional structures. Additionally, the effectiveness and robustness of the proposed optimal controllers of four-layer HC were verified and validated. The optimal and conventional controllers were compared. Moreover, the experimental work was implemented using the hardware-in-the-loop real-time emulation based on the C2000 TM microcontroller TMS320F28377S Launchpad development kit, to demonstrate the feasibility and superior performance of the suggested optimal controllers under realistic conditions. Finally, the experimental and simulation results were compared. Only insignificant discrepancies can be observed between the experimental and simulation results.