Microgrid Harmonic Mitigation Strategy Based on the Optimal Allocation of Active Power and Harmonic Mitigation Capacities of Multi-Functional Grid-Connected Inverters

: Harmonic pollution sources in microgrids have the characteristics of high penetration and decentralization, as well as forming a full network. Local harmonic mitigation is a traditional harmonic mitigation method, which has the disadvantages of complexity and costly operation. Based on the idea of the decentralized autonomy of power quality, this paper establishes a comprehensive optimization model of the active power and harmonic mitigation capacities of grid-connected inverters based on two-layer optimization and realizes harmonic mitigation. Firstly, based on the harmonic sensitivity analysis, the calculation method of harmonic mitigation capacity is given. Secondly, a two-layer model of harmonic mitigation optimization is established. The upper-layer optimization model takes the minimum operation cost of the microgrid as the objective and the active power reduction in the multi-functional grid-connected inverter (MFGCI) as the optimization variable. The lower-layer optimization model offers the best harmonic mitigation effect as the objective and the harmonic current compensation as the optimization variable. According to the relationship between the total remaining capacity of MFGCI and the capacity required for harmonic mitigation, there are three different objective functions in the lower-layer optimization model. Then, the model solving steps are provided. Finally, an example shows that the proposed optimization model can achieve harmonic mitigation at different times. Compared with the case without active power optimization, the operation cost of the whole system can be reduced by up to 14.6%, while ensuring the harmonic mitigation effect. The proposed method has the advantages of a harmonic mitigation effect and economical system operation.


Introduction
With the development and use of a large number of new energy devices, the random and massive access of non-linear loads, and the normalization of network power electronics, the harmonic pollution of microgrids is becoming a pressing issue [1,2].On the one hand, with continuous expansion in the size of the microgrid, the distribution range of and level of pollution from harmonic sources are gradually increasing.The ability of microgrids to absorb power quality pollution is weak, and the powerful electronic equipment in the network is susceptible to power quality and has high requirements for waveforms, amplitude and frequency.This makes the power quality problem of microgrids even more pressing [3,4].In [5], a medium-sized industrial microgrid is calculated shows that the levels of total harmonic distortion have exceeded the limit value imposed in the standard.On the other hand, due to the decentralized and wide-area characteristics of microgrid harmonic sources [6], the traditional method of centralized mitigation has the problems of a high installation cost of equipment, single function, and low utilization of equipment capacity, making it more difficult to meet the increasingly complex mitigation needs of network Energies 2022, 15, 6109 2 of 20 distribution and unsuitable for new energy microgrids with a decentralized distribution of multiple harmonic sources.Therefore, there is an urgent need to seek a power-quality mitigation method for local mitigation of harmonic pollution sources.
It is demonstrated that a multi-functional grid-connected inverter (MFGCI) can mitigate power-quality pollution on a local scale.The MFGCI has the same topology as the active power filter (APF) and only requires appropriate software upgrades to enable the integration of renewable energy, while considering the improvement of microgrid power quality [7].With its multitasking function, MFGCI not only improves the cost performance of grid-connected inverters, but also reduces investment costs by avoiding the installation of additional power-quality improvement devices in the microgrid.
In previous research on MFGCI structures, a sliding mode controller and a positive fundamental component estimator were used to calculate current and voltage to realize the simultaneous outputs of the active power and reactive power of MFGCI [8].In [9], the design, development and implementation process of the MFGCI laboratory prototype with APF function is described.In [10], a new type of MFGCI was studied.The MFGCI is composed of a three-phase DC/AC converter with three ports and a DC/DC converter at the front stage, and a 5kVA laboratory prototype was designed, which cannot only output active power but also compensate for harmonic current and reactive power.In [11], MFGCI is proposed with the function of compensating harmonic current, reactive power and the three-phase imbalance on the basis of considering the power quality of microgrids and the effectiveness of grid-connected inverters.
To more effectively control reactive power and voltage, a type of shutdown seriesswitched MFGCI (SSS-MFGCI) was proposed in [12], which achieved the four-quadrant operation of SSS-MFGCI through a bidirectional switch commutation method.In [13], a MFGCI control scheme was designed that can suppress both steady and dynamic disturbances; the control scheme includes an inner-loop controller and an improved reference for the current generation algorithm.From the references [8][9][10][11][12][13], we can draw a clear conclusion that MFGCI achieves harmonic compensation or harmonic mitigation.
In research on operation control strategy, the authors of [14] used SSS-MFGCI, which was first proposed in [12], and set different operation modes according to various grid disturbances to realize the control of voltage swell, voltage sag and voltage imbalance.In [15], SSS-MFGCI was applied to V2G based on [14].In [16], an improved MFGCI power governance compensation algorithm based on the conservative power theory was proposed, and the small signal stability of MFGCI was analyzed using the impedance modeling method.In [17], MFGCI is modelled based on impedance reconstruction model, realizes the purpose of MFGCI providing virtual inertia and eliminating harmonic resonance.In [18], a multi-objective control strategy was designed, which enables the MFGCI to simultaneously output harmonic compensation current and reactive power through closedloop active power control technology, compensating the harmonic and reactive power of the system.In [19], a virtual impedance droop control and secondary power balance control were combined, and a comprehensive control strategy for MFGCIs was proposed, which can achieve harmonic mitigation and a three-phase unbalance suppression of the grid.In [20], MFGCI can operate in shunt-connected and cascade-connected modes; therefore, the required compensation can be provided for current-or voltage-related power-quality issues with the assistance of bidirectional switches.In [21], a power management algorithm was developed to determine the optimal operating mode of the MFGCI and realize selective power injection and power regulation.From the references [14][15][16][17][18][19][20][21], it is observed that active output, reactive output and harmonic compensation can be simultaneously realized through the control algorithm of MFGCI.
However, power quality management is only an auxiliary function of MFGCI.The compensation capacity that can be used in a single MFGCI is always limited.Microgrids often contain multiple grid-connected inverters, which can play a greater role if the compensation capacity of these grid-connected inverters is aggregated.In [22], the study proposed a control method to coordinate multiple MFGCIs to participate in microgrid power quality management based on the Fryze-Buchholz-Dpenbrock (FBD) power theory.In [23], a comprehensive power-quality evaluation (CPQE) index was proposed based on the mutation theory, and a multi-objective optimal compensation model with multiple MFGCIs was established with the objectives of optimizing the CPQE index and minimizing the occupied capacity of MFGCIs used for power-quality compensation.
Similar to [23], a new comprehensive power-quality evaluation method was proposed in [24], which used the G1 method and hybrid variable weight principle to establish a multiobjective optimal compensation model containing multiple MFGCIs with the objectives of optimizing the CPQE index and minimizing the occupied capacity of MFGCIs for powerquality compensation.In addition to local management, MFGCI can also be used for targeted power-quality management of specific nodes at remote ends.In [25], a distribution control strategy of the MFGCI output current was proposed based on the remaining capacity of MFGCIs, the harmonic currents of the shunt nodes, and reactive currents of the shunt nodes.In [26], an optimization model to realize the best operation state of the MFGCI and OLTC was proposed, which offers the best results in terms of voltage quality, minimum power losses and the longest OLTC life as the optimization objectives.In [27], a new strategy for the cooperative and optimal allocation of VDAPF and SVG considering the contribution of MFGCI is proposed, focusing mainly on the capacity allocation of VDAPF and SVG.References [22][23][24][25][26][27] introduce corresponding control strategies for different application requirements, which can realize local and decentralized harmonics mitigation in microgrids.However, it cannot be ignored that the part of capacity of MFGCI needs to be occupied when compensating harmonics.Therefore, the relationship between the remaining capacity of MFGCI and the capacity required for harmonic compensation needs to be considered, and when the remaining capacity is small, some of the active power capacity can be appropriately reduced to improve the harmonic compensation capacity.A photovoltaic (PV) is connected to the grid through MFGCI.
In research on PV active power control, a new type of photovoltaic power generation module and its control strategy are proposed in [28], which can ensure the continuous output of active power when the solar radiation intensity changes unexpectedly.In [29], according to the solar irradiance and cloud cover at different stages of the day, the reference value of power per hour is optimized based on random dynamic programming to realize the PV active power control.However, the reduction in active power grid-connected capacity affects the economy of microgrid operation.The allocation of the MFGCI harmonic compensation capacity and active power grid-connected capacity to ensure the economy of microgrid operations with optimal power-quality improvement has not been thoroughly studied in the references [18][19][20][21][22][23][24][25][26][27][28][29].
In order to integrate the active power grid-connected and harmonic mitigation functions of MFGCI and achieve the integrated optimization of system operation and harmonic mitigation, this paper solves the problem of allocating the active power grid-connected capacity and harmonic mitigation capacity of MFGCI through the use of microgrid active optimization and nodal harmonic mitigation.A two-layer optimization model was established for the integrated active power-harmonic mitigation capacity allocation of MFGCI, with the upper layer of active power optimization used to determine the optimal amount of MFGCIs to be connected to the grid.The lower layer for harmonic mitigation optimization determines the corresponding objective function according to the relationship between the total remaining capacity of the system and the size of the capacity required for harmonic mitigation, optimizing the harmonic mitigation scheme and the harmonic mitigation capacity of each MFGCI.A discrete binary-coded two-layer simulated annealing particle swarm algorithm (SAPSO) with a nested harmonic power flow calculation is used to solve the problem.The validation results show that the two-layer optimization model established in this paper not only ensures the optimal PV active grid-connected inverters, but also enables the harmonic mitigation of the system to achieve the best results.

Relationship between Active Power and Remaining Capacity of MFGCI
Due to the uncertainty of renewable energy power generation, the rated capacity of grid-connected inverters is often larger than the actual power generated by wind turbines or PV panels.Moreover, due to natural factors, PV does not always operate at full power; there is always a certain remaining capacity of MFGCI.This remaining capacity can be used to realize the harmonic mitigation function.The utilization rate of the equipment can be improved by formulating a reasonable allocation strategy of MFGCI active grid-connected capacity and remaining capacity.
DG can generate active power and reactive power, assuming that the total capacity of the inverter is available.Since its rated capacity is a certain value, according to the active power output value and reactive power output value of DG at a certain time, the remaining capacity of each inverter available for harmonic mitigation at the corresponding time can be obtained, and the formula for calculating the remaining capacity S m_remain is shown in the following equation: where S m_MFGCI is the rated capacity of the m-th inverter; P m_MFGCI and Q m_MFGCI are the active power and reactive power output of the m-th inverter, respectively.

Relationship between Compensation Current and Harmonic Compensation Capacity
The remaining capacity of MFGCI after active power connection is used to compensate for the harmonics, and the relationship between the compensation capacity required for harmonic mitigation and each emitted harmonic compensation current is: where S recoupi is the required capacity of MFGCI at node i to compensate for harmonics; U i1 is the fundamental voltage at node i; U ih is the h-th harmonic voltage at node i; I ih is the h-th harmonic current compensated at node i; and H is the maximum order of harmonics.
Considering that the amplitude of each harmonic voltage is smaller than the fundamental voltage, in the actual calculation, the value of each harmonic voltage can be ignored, and only the fundamental voltage is retained.

Harmonic Mitigation Sensitivity Analysis
The harmonic mitigation sensitivity W ij of MFGCI of node j to node i is: where α ih is the weight accounted for by the h-th harmonic voltage at node I; I jh is the h-th harmonic current compensated at node j.
In this paper, the harmonic power flow calculation of the simulation example adopts the approximate harmonic power flow calculation method.∂U ih /∂I jh is equal to the h-th harmonic mutual impedance Z ijh between node i and node j, so that the above equation can be written as: Depending on the magnitude of W ij , the MFGCIs with the best and worst harmonic mitigation sensitivity at node i can be determined, respectively.
If the total harmonic distortion (THD) at node i in the system is the maximum, i.e., THD = M i % (M i > 4), then the magnitude of each harmonic voltage is U h , respectively.If the W ij between node j connected with MFGCI and node i is the minimum, then the MFGCI at node j has the worst harmonic mitigation sensitivity to node i, and the capacity required for the harmonic mitigation of node i using the MFGCI at node j is maximum.The maximum mitigation capacity S demand_max required to mitigate the THD of node i to 4% is shown below: where λ i is the difference coefficient, and its value is less than 1, depending on the difference between M i and 4; U j1 is the fundamental voltage at node j.
Similarly, if the W ik between node k connected with MFGCI and node i is maximum, then the MFGCI at node k has the best harmonic mitigation sensitivity with node i.The minimum capacity required for the harmonic mitigation of node i using the MFGCI at node k is minimum.The minimum mitigation capacity S demand_min required to mitigate the THD of node i to 4% is shown below.
where U k1 is the fundamental voltage at node k; Z ikh is the h-th harmonic mutual impedance between node i and node k.

Modeling Ideas
When the generation power of DG is large, the remaining capacity available for harmonic mitigation has a relatively similar value.Using only the existing MFGCI remaining capacity, the system may have nodes with excessive harmonic content under the same harmonic pollution injection; and the extreme effort to achieve the power-quality index of harmonic voltage requires more MFGCI capacity for harmonic mitigation, which affects the maximum grid-connected power of DG and is not conducive to the maximum utilization of new energy, despite the improvement in power-quality.Considering the mutual constraint relationship between the active grid-connected capacity of MFGCI and the capacity of harmonic mitigation, this paper establishes a two-layer optimization model for the integrated active grid-connected and harmonic mitigation capacity allocation of MFGCI, starting from the allocation of the active grid-connected capacity and the remaining capacity of MFGCI.This optimization strategy is shown in Figure 1.
Energies 2022, 15, x FOR PEER REVIEW MFGCI, starting from the allocation of the active grid-connected capacity and the r ing capacity of MFGCI.This optimization strategy is shown in Figure 1.

Upper Layer-Active Power Optimization
The upper layer takes the minimum system operation cost as the optimization tive, and the objective function includes the cost of purchasing and selling electric

Upper Layer-Active Power Optimization
The upper layer takes the minimum system operation cost as the optimization objective, and the objective function includes the cost of purchasing and selling electricity, the cost of network power loss, the cost of inverter operation and maintenance, and the benefit of power-quality improvement.The benefits of power-quality improvement include the equivalent APF installation cost and equivalent APF operation and maintenance cost.

Objective Function
The total objective function of the upper layer is: where C en is the cost of purchasing and selling electricity; C loss is the cost of network power loss; C om is the cost of MFGCI operation and maintenance; E dev is the cost of equivalent APF installation; E om is the cost of equivalent APF operation and maintenance.The calculation equation of each component is shown below.

•
Cost of Purchasing and Selling Electricity: where P t is the total power required by the microgrid load at time t; P tm is the active grid-connected of the m-th MFGCI at time t; ∆t is the length of each optimization period; M is the total number of MFGCIs; c bt is the real-time purchasing and selling electricity of the microgrid unit price, the expression of c bt at time t is as follows: where c ut is the price of purchasing electricity by microgrid from the grid at time t; c st is the price of selling electricity by microgrid to the grid at time t.

• Cost of Network Power Loss
Network power loss mainly considers line active power loss, and its calculation is expressed as follows: where j ∈ i indicates that node j is directly connected to node i; U tih and U tjh are the h-th harmonic voltage values of node i and node j at time t, respectively; R ij is the branch resistance value between node i and node j; N is the number of nodes; and c pu is the factor of network power loss cost.

•
Cost of MFGCI Operation and Maintenance: where C op is the cost of operation of MFGCI; C ma is the cost of maintenance of MFGCI; c 1 is the cost factor of MFGCI active power grid-connected inverter; c 2 is the cost factor of MFGCI harmonic mitigation; S tm_recoup is the capacity of the m-th MFGCI involved in harmonic mitigation at time t; and c MFGCI is the maintenance cost per unit capacity of MFGCI.

•
Cost of Equivalent APF Installation: where c 3 is the installed cost per unit capacity of APF.
• Cost of Equivalent APF Operation and Maintenance: where c 4 is the cost factor of operation of the APF, and c 5 is the cost factor of maintenance of the APF.

Constraint Condition
The constraints for the upper-layer optimization are the power balance constraint, node voltage constraint, branch power constraint and control variable constraint.The specific expressions of each part are shown below.

•
Power Balance Constraint: where P i , Q i are the injected active power and reactive power of node i, respectively; U i , U j are the voltage amplitudes of nodes i and j, respectively; G ij , B ij are the real and imaginary parts of the node derivative matrix, respectively; and θ ij is the phase angle difference between the voltages of nodes i and j.
• Node Voltage Constraint: where U i_max and U i_min are the upper and lower limits of the voltage amplitude at node i, respectively.
• Branch Power Constraint: where P l is the active power transmitted by branch l; P l_max is the maximum allowable value of active power transmitted by branch l; and Ω is the set of branches.
where S m_cut is the active power reduction in the m-th MFGCI.

Lower-Layer-Harmonic Mitigation Optimization
The lower layer is a microgrid harmonic mitigation optimization model.The maximum and minimum capacities required for harmonic mitigation can be calculated by harmonic mitigation sensitivity analysis.According to the size relationship between the total remaining capacity of MFGCI and the maximum and minimum capacity required for harmonic mitigation, the lower-layer optimization can be subdivided into three sub-objectives.

Objective Function I
When the sum of the total remaining capacity of the MFGCI and the installed capacity of the APF is greater than the maximum capacity required for harmonic mitigation, the remaining capacity of the MFGCI is sufficient to mitigate harmonics without reducing the active grid-connected capacity: where β i is the importance coefficient of node i, which is related to the power of the load connected to node i and the requirements of the load on power-quality; S APF is the installed capacity of the APF; THD i is the THD of node i after harmonic mitigation; THD i is the THD of node i before harmonic mitigation.The constraints include THD constraints [30] at each node and MFGCI harmonic mitigation capacity constraints: S m_recoup ≤ S m_remain (23) where S m_remain is the remaining capacity of the m-th MFGCI.

Objective Function II
When the sum of the total remaining capacity of MFGCI and the installed capacity of APF is less than the minimum capacity required for harmonic mitigation, the remaining capacity of the MFGCI is not enough to mitigate harmonics, and it is necessary to reduce the active grid-connected capacity: The constraints include THD constraints and active power reduction constraints for each node: S m_cut ≤ P m_MFGCI (26) where P m_MFGCI is the grid-connected capacity of the active power of the m-th MFGCI:

Objective Function III
When the sum of the total remaining capacity of MFGCI and the installed capacity of APF is between the minimum and maximum capacity required for harmonic mitigation, it is impossible to judge whether the remaining capacity of the MFGCI is sufficient to mitigate harmonics or whether it is necessary to reduce the grid-connected capacity of the active power of the MFGCI.In order to ensure that the remaining capacity of the MFGCI is preferentially used to mitigate harmonics, and to avoid the remaining capacity and partial reduction in the useful grid-connected capacity caused by some MFGCIs, the sign function sgn is added to the objective function.When the harmonic mitigation capacity of the MFGCI is greater than its remaining capacity, sgn = 1, which increases the value of the objective function.When the harmonic mitigation capacity of the MFGCI is less than its remaining capacity, sgn = −1, which makes the value of the objective function smaller.When the harmonic mitigation capacity of the MFGCI is equal to its remaining capacity, Energies 2022, 15, 6109 9 of 20 sgn = 0, meaning that the objective function value remains unchanged.The objective function is as follows.
The constraints include the THD constraint of each node and the harmonic mitigation capacity constraint of each MFGCI.
According to different operating conditions of the system, the selection of three objective functions for lower-layer optimization is shown in Figure 2.

Model Solving
The upper and lower models are interrelated; therefore, a fast optimization algorithm is needed.The discrete binary coded two-layer simulated annealing particle swarm optimization (SAPSO) with nested harmonic power flow calculation has the advantages of a simple and easy implementation, fast search speed and few parameter settings.It can find the global optimum in a short time.Therefore, the upper and lower objective functions are solved by SAPSO algorithm.
The upper-layer optimization solution parameters are set as follows: the particle population size is 200, the learning factor is 1.5, the inertia weight linearly decreases with a maximum value of 0.95 and minimum value of 0.7, and the maximum number of iterations is 300.The lower-layer optimization solution parameters are set as follows: the particle population size is 300, the learning factor is 1.5, the inertia weight linearly decreases with a maximum value of 0.95 and minimum value of 0.7, and the maximum number of iterations is 300.

Upper-Layer Particle Coding
In the upper-layer optimization, the optimization variable is the active power reduction; therefore, the upper-layer particle is the MFGCI active power reduction.It should be noted that a single particle can be a value or a group of values.If a microgrid contains Mth MFGCIs, each particle is composed of M-th MFGCI active power reductions.The upper-layer optimized particle structure is shown in Figure 3

Model Solving
The upper and lower models are interrelated; therefore, a fast optimization algorithm is needed.The discrete binary coded two-layer simulated annealing particle swarm optimization (SAPSO) with nested harmonic power flow calculation has the advantages of a simple and easy implementation, fast search speed and few parameter settings.It can find the global optimum in a short time.Therefore, the upper and lower objective functions are solved by SAPSO algorithm.
The upper-layer optimization solution parameters are set as follows: the particle population size is 200, the learning factor is 1.5, the inertia weight linearly decreases with a maximum value of 0.95 and minimum value of 0.7, and the maximum number of iterations is 300.The lower-layer optimization solution parameters are set as follows: the particle population size is 300, the learning factor is 1.5, the inertia weight linearly decreases with a maximum value of 0.95 and minimum value of 0.7, and the maximum number of iterations is 300.

Upper-Layer Particle Coding
In the upper-layer optimization, the optimization variable is the active power reduction; therefore, the upper-layer particle is the MFGCI active power reduction.It should be noted that a single particle can be a value or a group of values.If a microgrid contains M-th MFGCIs, each particle is composed of M-th MFGCI active power reductions.The upper-layer optimized particle structure is shown in Figure 3.In the figure, S m_cut is the active power reduction in the m-th MFGCI.

Upper-Layer Particle Coding
In the upper-layer optimization, the optimization variable is the active power reduction; therefore, the upper-layer particle is the MFGCI active power reduction.It should be noted that a single particle can be a value or a group of values.If a microgrid contains Mth MFGCIs, each particle is composed of M-th MFGCI active power reductions.The upper-layer optimized particle structure is shown in Figure 3

Lower-Layer Particle Coding
In the lower-layer optimization, the optimization variable is the harmonic compensation current; therefore, the lower-layer particle is the harmonic compensation current of MFGCI.In the lower-layer harmonic mitigation optimization, each particle contains an M-th harmonic compensation current of MFGCIs, and each harmonic compensation current of MFGCI is divided into 5th, 7th, 11th and 13th harmonic compensation currents.The initial state of each particle in the lower-layer optimization is randomly generated

Lower-Layer Particle Coding
In the lower-layer optimization, the optimization variable is the harmonic compensation current; therefore, the lower-layer particle is the harmonic compensation current of MFGCI.In the lower-layer harmonic mitigation optimization, each particle contains an M-th harmonic compensation current of MFGCIs, and each harmonic compensation current of MFGCI is divided into 5th, 7th, 11th and 13th harmonic compensation currents.The initial state of each particle in the lower-layer optimization is randomly generated within the range determined by the upper-layer optimization results and the constraint conditions.The lower-layer particle structure is shown in

Model Solving Steps
Step 1: Collect real-time power information of photovoltaics and loads, and set the initial value of active power reduction to 0; Step 2: Calculate the remaining capacity of the inverter that can be used for harmonic mitigation; Step 3: Carry out harmonic power flow calculation to obtain the voltage harmonic distortion rate of each node; Step 4: Determine whether there is a node with THD exceeding the standard in the system.If it does not exist, the optimization is over.If it exists, go to step 5; Step 5: Perform harmonic mitigation sensitivity analysis on nodes whose THD exceeds the standard, and calculate the maximum and minimum capacity required for harmonic mitigation; Step 6: The lower-layer optimizes particle coding and selects the corresponding objective function for harmonic mitigation optimization according to the relationship between the remaining capacity and the capacity required for harmonic mitigation; Step 7: Determine whether the active work needs to be reduced.If not, output the optimization result, the optimization is over; if necessary, go to step 8; Step 8: The upper layer optimizes the particle coding, performs the upper-layer active power optimization, and obtains the active power reduction in each MFGCI; Step 9: Go to step 2 and continue to optimize until the optimal solution is obtained.
The flow chart of the model solution is shown in Figure 5.

Model Solving Steps
Step 1: Collect real-time power information of photovoltaics and loads, and set the initial value of active power reduction to 0; Step 2: Calculate the remaining capacity of the inverter that can be used for harmonic mitigation; Step 3: Carry out harmonic power flow calculation to obtain the voltage harmonic distortion rate of each node; Step 4: Determine whether there is a node with THD exceeding the standard in the system.If it does not exist, the optimization is over.If it exists, go to step 5; Step 5: Perform harmonic mitigation sensitivity analysis on nodes whose THD exceeds the standard, and calculate the maximum and minimum capacity required for harmonic mitigation; Step 6: The lower-layer optimizes particle coding and selects the corresponding objective function for harmonic mitigation optimization according to the relationship between the remaining capacity and the capacity required for harmonic mitigation; Step 7: Determine whether the active work needs to be reduced.If not, output the optimization result, the optimization is over; if necessary, go to step 8; Step 8: The upper layer optimizes the particle coding, performs the upper-layer active power optimization, and obtains the active power reduction in each MFGCI; Step 9: Go to step 2 and continue to optimize until the optimal solution is obtained.
The flow chart of the model solution is shown in Figure 5.

System Parameters
To verify the effectiveness of the model established in this paper for microgrid power-quality improvement, the IEEE 33-bus system connected to the distributed photovoltaic grid was selected as the simulation object, as shown in Figure 6.The system voltage level is 10 kV, nodes 4, 7, 22, 25 and 27 are DG grid-connected nodes, and the rated capacity of MFGCI connected to each node is shown in Table 1.Nodes 4, 9, 13, 17, 21, 24, 27 and 31 are harmonic source access nodes, and the 5th, 7th, 11th and 13th harmonics were considered.The magnitudes of the load power and harmonic sources for each harmonic current at each node at different moments are shown in the Appendix A [31].The weight values of different harmonic voltages are shown in Table 2. Nodes 8, 20, 23 and 32 are APF access nodes, and the total installed capacity of APFs is 100 kW.Considering the low voltage level of microgrids and scattered distribution of harmonic sources, γ is 0.95.The re- active power output of MFGCI is ignored.Solar intensity data are derived from a region in the southern Hebei Province, China.

System Parameters
To verify the effectiveness of the model established in this paper for microgrid powerquality improvement, the IEEE 33-bus system connected to the distributed photovoltaic grid was selected as the simulation object, as shown in Figure 6.The system voltage level is 10 kV, nodes 4, 7, 22, 25 and 27 are DG grid-connected nodes, and the rated capacity of MFGCI connected to each node is shown in Table 1.Nodes 4, 9, 13, 17, 21, 24, 27 and 31 are harmonic source access nodes, and the 5th, 7th, 11th and 13th harmonics were considered.The magnitudes of the load power and harmonic sources for each harmonic current at each node at different moments are shown in the Appendix A [31].The weight values of different harmonic voltages are shown in Table 2. Nodes 8, 20, 23 and 32 are APF access nodes, and the total installed capacity of APFs is 100 kW.Considering the low voltage level of microgrids and scattered distribution of harmonic sources, γ is 0.95.The reactive power output of MFGCI is ignored.Solar intensity data are derived from a region in the southern Hebei Province, China.

System Parameters
To verify the effectiveness of the model established in this paper for microgrid power-quality improvement, the IEEE 33-bus system connected to the distributed photo voltaic grid was selected as the simulation object, as shown in Figure 6.The system voltage level is 10 kV, nodes 4, 7, 22, 25 and 27 are DG grid-connected nodes, and the rated capac ity of MFGCI connected to each node is shown in Table 1.Nodes 4, 9, 13, 17, 21, 24, 27 and 31 are harmonic source access nodes, and the 5th, 7th, 11th and 13th harmonics were con sidered.The magnitudes of the load power and harmonic sources for each harmonic cur rent at each node at different moments are shown in the Appendix A [31].The weigh values of different harmonic voltages are shown in Table 2. Nodes 8, 20, 23 and 32 are APF access nodes, and the total installed capacity of APFs is 100 kW.Considering the low volt age level of microgrids and scattered distribution of harmonic sources, γ is 0.95.The re active power output of MFGCI is ignored.Solar intensity data are derived from a region in the southern Hebei Province, China.To verify the adaptability of the proposed model to different situations, the system operation was optimized with the model at three typical times: 7:00, 13:00 and 16:00, respectively.

System Optimization Results at 7:00
According to the basic parameters of the system at 7:00, the remaining capacity of MFGCI and the maximum and minimum capacity required for harmonic mitigation can be obtained from Equations ( 1), ( 6) and ( 7), as shown in Tables 3 and 4. As observed from Tables 3 and 4, the active power of the PV at 7:00 is small, and the remaining capacity of the MFGCI is large.The total remaining capacity is larger than the maximum capacity required for harmonic mitigation, which is sufficient to compensate for the harmonics and does not need to cut active power.Thus, objective function I is selected for the lower optimization in the process of solving the two-layer optimization model.According to the optimization results, the capacity of each MFGCI involved in harmonic mitigation can be obtained from Equation (3), and the results are shown in Table 5. Figure 7 shows the THD of each node before and after harmonic mitigation.The capacity of each MFGCI involved in harmonic mitigation at 7:00 is less than the remaining capacity, and the total capacity used for harmonic is 319.26 kW, which is between the maximum and minimum capacity required for harmonic mitigation.The THD of each node is less than 4% after optimization, and the capacity used for harmonic mitigation and the level of harmonic mitigation meet the requirements.The capacity of each MFGCI involved in harmonic mitigation at 7:00 is less than the remaining capacity, and the total capacity used for harmonic mitigation is 319.26 kW, which is between the maximum and minimum capacity required for harmonic mitigation.The THD of each node is less than 4% after optimization, and the capacity used for harmonic mitigation and the level of harmonic mitigation meet the requirements.

System Optimization Results at 13:00
According to the basic parameters of the system at 13:00, the remaining capacity of MFGCI and the maximum and minimum capacity required for harmonic mitigation can be obtained from Equations (1), ( 6) and ( 7), as shown in Tables 6 and 7.At 13:00, the PV active power reaches the maximum, the active power grid-connected capacity of each MFGCI also reaches the maximum, and the total remaining capacity is the minimum at this time.The sum of the total remaining capacity and the APF installed capacity is less than the minimum capacity required for harmonic mitigation, which is not enough to mitigate harmonics, so objective function II is selected for the lower-layer optimization in the process of solving the two-layer optimization model.To achieve our optimization results, the capacity of each MFGCI involved in harmonic mitigation was obtained from Equation (3), and the results are shown in Table 8.The THD of each node before and after harmonic mitigation is shown in Figure 8.

System Optimization Results at 13:00
According to the basic parameters of the system at 13:00, the remaining capacity of MFGCI and the maximum and minimum capacity required for harmonic mitigation can be obtained from Equations ( 1), ( 6) and ( 7), as shown in Tables 6 and 7.At 13:00, the PV active power reaches the maximum, the active power grid-connected capacity of each MFGCI also reaches the maximum, and the total remaining capacity is the minimum at this time.The sum of the total remaining capacity and the APF installed capacity is less than the minimum capacity required for harmonic mitigation, which is not enough to mitigate harmonics, so objective function II is selected for the lower-layer optimization in the process of solving the two-layer optimization model.To achieve our optimization results, the capacity of each MFGCI involved in harmonic mitigation was obtained from Equation (3), and the results are shown in Table 8.The THD of each node before and after harmonic mitigation is shown in Figure 8.
As can be seen from Figure 8, each MFGCI at 13:00 requires active power reduction for harmonic mitigation.The total capacity required for harmonic mitigation is 375.59 kW, which lies between the maximum and minimum capacity required for harmonic mitigation.After optimization, the THD of each node is less than 4%, and the capacity used for harmonic mitigation and the level of harmonic mitigation meet the requirements.As can be seen from Figure 8, each MFGCI at 13:00 requires active power reduction for harmonic mitigation.The total capacity required for harmonic mitigation is 375.59 kW, which lies between the maximum and minimum capacity required for harmonic mitigation.After optimization, the THD of each node is less than 4%, and the capacity used for harmonic mitigation and the level of harmonic mitigation meet the requirements.

System Optimization Results at 16:00
Similarly, based on the basic parameters of the system at 16:00, the remaining capacity of the MFGCI and the maximum and minimum capacities required for harmonic mitigation can be obtained, and the results are shown in Tables 9 and 10.At 16:00, PV is not in a full-generation state, MFGCI has some remaining capacity, the total remaining capacity is between the maximum and minimum capacity needed for harmonic mitigation.Therefore, MFGCI may or may not need to cut active power; thus, in the process of solving the two-layer optimization model, the objective function III is selected for the lower-layer optimization.According to the optimization results, the capacity of each MFGCI involved in harmonic mitigation is obtained from Equation (3), and the results are shown in Table 11.The THD of each node before and after harmonic mitigation is shown in Figure 9. Similarly, based on the basic parameters of the system at 16:00, the remaining capacity of the MFGCI and the maximum and minimum capacities required for harmonic mitigation can be obtained, and the results are shown in Tables 9 and 10.At 16:00, PV is not in a full-generation state, MFGCI has some remaining capacity, the total remaining capacity is between the maximum and minimum capacity needed for harmonic mitigation.Therefore, MFGCI may or may not need to cut active power; thus, in the process of solving the two-layer optimization model, the objective function III is selected for the lower-layer optimization.According to the optimization results, the capacity of each MFGCI involved in harmonic mitigation is obtained from Equation (3), and the results are shown in Table 11.The THD of each node before and after harmonic mitigation is shown in Figure 9.
From the above results, at 16:00, it can be observed that the MFGCIs connected at nodes 4, 25 and 27 require active power reduction, while the MFGCIs connected at nodes 7 and 22 do not, and their remaining capacities are all used for harmonic mitigation.The total capacity used for harmonic mitigation is 421.64 kW, which is between the maximum and minimum capacity required for harmonic mitigation.After optimization, the THD of each node is less than 4%, and the capacity used for harmonic mitigation and its corresponding level meet the requirements.From the above results, at 16:00, it can be observed that the MFGCIs connected at nodes 4, 25 and 27 require active power reduction, while the MFGCIs connected at nodes 7 and 22 do not, and their remaining capacities are all used for harmonic mitigation.The total capacity used for harmonic mitigation is 421.64 kW, which is between the maximum and minimum capacity required for harmonic mitigation.After optimization, the THD of each node is less than 4%, and the capacity used for harmonic mitigation and its corresponding level meet the requirements.

Contrast Analysis
In order to verify the economy and superiority of the mitigation effect of the strategy proposed in this paper, two cases are set for comparative analysis.
Case 1: Only the lower-layer model established in this paper is used for harmonic mitigation optimization.If the harmonic mitigation capacity of the MFGCI needs to be increased, the reduction in its active power is not limited, and the capacity of each MFGCI to participate in harmonic mitigation is determined.
Case 2: Based on Case 1, this case considers active power optimization, which is the strategy proposed in this paper.
Similarly, the optimization results of the two strategies are compared and analyzed at three typical times: 7:00, 13:00 and 16:00.

Comparison of Mitigation Effects
System harmonics are mitigated by Case 1 and Case 2, respectively, and the THD of each node after harmonic mitigation is shown in Figure 10.
As can be seen from Figure 10, both cases can mitigate the system harmonics to the expected level.At 7:00, the harmonic mitigation effects of the two cases are exactly the same because the total remaining capacity of the system is large at 7:00, which is sufficient to mitigate harmonics and does not require active power to be reduced.At 13:00 and 16:00, the harmonic mitigation effects of the two cases were roughly the same.Therefore, the difference between the two cases is not obvious in terms of the harmonic mitigation effect alone.

Contrast Analysis
In order to verify the economy and superiority of the mitigation effect of the strategy proposed in this paper, two cases are set for comparative analysis.
Case 1: Only the lower-layer model established in this paper is used for harmonic mitigation optimization.If the harmonic mitigation capacity of the MFGCI needs to be increased, the reduction in its active power is not limited, and the capacity of each MFGCI to participate in harmonic mitigation is determined.
Case 2: Based on Case 1, this case considers active power optimization, which is the strategy proposed in this paper.
Similarly, the optimization results of the two strategies are compared and analyzed at three typical times: 7:00, 13:00 and 16:00.

Comparison of Mitigation Effects
System harmonics are mitigated by Case 1 and Case 2, respectively, and the THD of each node after harmonic mitigation is shown in Figure 10.
As can be seen from Figure 10, both cases can mitigate the system harmonics to the expected level.At 7:00, the harmonic mitigation effects of the two cases are exactly the same because the total remaining capacity of the system is large at 7:00, which is sufficient to mitigate harmonics and does not require active power to be reduced.At 13:00 and 16:00, the harmonic mitigation effects of the two cases were roughly the same.Therefore, the difference between the two cases is not obvious in terms of the harmonic mitigation effect alone.

Comparison of Economy
Case 1 and Case 2 are used for harmonic mitigation.The capacity and active power reduction in each MFGCI participating in harmonic mitigation are shown in Tables 12 and 13.
It can be seen from Tables 12 and 13 that the capacity of each MFGCI to participate in harmonic mitigation is the same under the two cases at 7:00.At 13:00 and 16:00, the capacity and active power reduction in each MFGCI in Case 1 involved in harmonic mitigation are greater than those in Case 2. The operating costs of the system under different cases are shown in Table 14.

Comparison of Economy
Case 1 and Case 2 are used for harmonic mitigation.The capacity and active power reduction in each MFGCI participating in harmonic mitigation are shown in Tables 12 and  13.It can be observed from Table 14 that the operating costs of the systems under the two cases are the same at 7:00.At 13:00 and 16:00, the system operating cost of Case 1 is more than that of Case 2; therefore, Case 2 is more economical than Case 1.
It is worth noting that harmonic mitigation is only an auxiliary function of MFGCI, and the importance of an active power grid-connected function is greater than that of harmonic mitigation function.Therefore, the level of active power grid-connected function cannot be reduced indefinitely because of the harmonic mitigation effect.Both cases can mitigate the system harmonics to just meet the expected level.However, because Case 1 does not carry out active power optimization, the active power reduction in MFGCI is not limited.Therefore, the inverter capacity occupied by harmonic mitigation is large, which makes the active output power of MFGCI smaller, the system needs to absorb more active power from the power grid.The purchasing electricity cost and network loss cost of the system increase, and the operation economy becomes worse.However, when using Case 2 for optimization, the harmonic mitigation of the system just meets the requirements, and at the same time, the active power reduction in MFGCI is limited, which is more in line with the auxiliary function of the harmonic mitigation of MFGCI.Since harmonic mitigation does not occupy too much of the MFGCI capacity, the active power grid-connected function of the MFGCI is large, which reduces the purchasing electricity cost and network loss cost of the system, and improves the system operation economy.When comprehensively comparing the harmonic mitigation effect and economy of the two cases, it was found that Case 2 is better than Case 1.

Energies 2022 ,Figure 2 .
Figure 2. The choice of three objective functions for lower-layer optimization.
. In the figure, in the m-th MFGCI.

Figure 2 .
Figure 2. The choice of three objective functions for lower-layer optimization.

Figure 5 .
Figure 5.The flow chart of solving the two-layer optimization model.

Figure 5 .
Figure 5.The flow chart of solving the two-layer optimization model.

Figure 5 .
Figure 5.The flow chart of solving the two-layer optimization model.

Table 2 .
Weight of each harmonic voltage.

Table 4 .
Total remaining capacity and maximum and minimum capacity required for harmonic mitigation (kW).

Table 5 .
Capacity of each MFGCI involved in harmonic mitigation (kW).

Table 7 .
Total remaining capacity and maximum and minimum capacity required for harmonic mitigation (kW).

Table 8 .
Capacity of each MFGCI involved in harmonic mitigation (kW).

Table 7 .
Total remaining capacity and maximum and minimum capacity required for harmonic mitigation (kW).

Table 8 .
Capacity of each MFGCI involved in harmonic mitigation (kW).

Table 10 .
Total remaining capacity and maximum and minimum capacity required for harmonic mitigation (kW).

Table 11 .
Capacity of each MFGCI involved in harmonic mitigation (kW).

Table 10 .
Total remaining capacity and maximum and minimum capacity required for harmonic mitigation (kW).

Table 11 .
Capacity of each MFGCI involved in harmonic mitigation (kW).

Table 12 .
Capacity comparison of each MFGCI participating in harmonic mitigation (kW).

Table 13 .
Comparison of active power reduction by MFGCI (kW).

Table 12 .
Capacity comparison of each MFGCI participating in harmonic mitigation (kW).

Table 13 .
Comparison of active power reduction by MFGCI (kW).

Table 14 .
System operating costs under different cases (thousand CNY).

Table A1 .
Load power of each node at different times (kW).

Table A2 .
The magnitude of the 5th harmonic current of each harmonic source at different times (A).

Table A3 .
The magnitude of the 7th harmonic current of each harmonic source at different times (A).

Table A4 .
The magnitude of the 11th harmonic current of each harmonic source at different times (A).

Table A5 .
The magnitude of the 13th harmonic current of each harmonic source at different times (A).