Power Quality Improvement of a Microgrid with a Demand-Side-Based Energy Management System

This chapter addresses the power quality of grid-connected microgrids in steady state. Three different power quality issues are evaluated: the voltage drop, the harmonic distortion, and the phase unbalance. A formulation for an energy management algorithm for microgrids is proposed under the form of a mixed-integer linear optimization including harmonic load flows. It handles both the optimization of the scheduling of all the generation, storage, and load assets, and the resolution of power quality issues at the tertiary level of control by adjusting the levels of certain types of loads within the system. This algorithm is simulated for different scenarios on a conceptual test-case microgrid with residential, industrial, and commercial loads. The results show that the demand-side management mechanism inside the algorithm can adapt efficiently the consumption behavior of certain loads, so that the voltage drop, the voltage total harmonic distortion, and the voltage unbalance factor meet the required standards at every node of the microgrid during the day. It is also highlighted that the microgrid can gradually reduce the purchase of power from the utility grid to which it is connected if the electricity price on the spot market increases.


Introduction
The sectors of electricity generation, transmission, and distribution are currently facing a change of paradigm. The introduction of decentralized renewable energy sources and storage systems, the rise of electric vehicles, the multiplication of international high-voltage lines, and the development of smart grids are many reasons to believe that the way our societies produce, transmit, and consume electricity will progressively change in the coming decades [1].
A reliable and economically feasible supply of electricity remains, however, primordial for industrial and residential consumers. In the near future, several countries plan to introduce real-time pricing (RTP) at distribution levels, in order to reflect directly the variability of the electricity price on the consumers [2]. But since the costs of distributed renewable sources and storage systems have been decreasing, many important consumers see an opportunity to build their own microgrid. Their goal is to reduce their electricity bills by covering partially or totally their electrical loads [3]. Buildings, factories, or even residential neighborhoods are often referred to as the types of consumers that could foresee the creation of a microgrid if it appears to be economically viable [4]. In areas where blackouts and grid outages are frequent, certain microgrids have the interesting capability to isolate themselves from the rest of the grid, and thus act as an uninterrupted power supply (UPS) for the sensitive loads. This islanding mode is also called stand-alone mode of a microgrid, in opposition to the grid-connected mode.
The presence of nonlinear, single-phase, or highly inductive loads in the system can impair the usual three-phase direct symmetric voltage and current waveforms. In general, the parameters concerning reliability and waveform quality of the voltage and current are part of the so-called power quality (PQ), a set of characteristics which define an adequate supply of electricity [5]. According to the performance required and the operative standards, specific bounds should be defined for each PQ index. It is moreover essential for microgrids, as several scientific articles have pointed out that PQ-related issues are more frequent in this type of architecture, especially when they are disconnected from the main grid [6].
For larger networks, PQ issues are normally handled with different techniques at the primary level of control, such as droop control of synchronous machines, active filtering, static VAR compensators (SVC), or other kinds of equipment [7]. But the cost of most of these installations is high for small-scale microgrids. Hence, another less effective but more economical method to tackle long-lasting PQ issues consists in regulating the demand levels of flexible loads to stabilize the microgrid [6]. This modification of the energy used by the consumers is called demand-side management (DSM) and requires an adapted communication system between the consumers and the central controller of the microgrid.
This DSM feature is included inside the energy management system (EMS) algorithm, situated at the tertiary level of control of the microgrid [8]. The EMS is normally only focused on dispatching the active and reactive power fluxes between the distributed energy resources (DERs), the utility grid, and the loads to satisfy the active and reactive power balances while reaching an economic optimum on a daily basis [5]. However, including an appropriate DSM mechanism inside the EMS makes it also a potential solution for the assessment of the PQ in steady state. To our knowledge, very few authors have proposed such an approach based on PQ-related scheduling decisions taken over the multihour horizon. In [6], an energy scheduling algorithm is presented, aiming at mitigating PQ issues through coordinating the operating schedules of sensitive devices in a commercial building microgrid. Yet, most works in literature are based on intelligent control strategies of the DERs interfacing inverters or utilization of dedicated power electronic devices for compensation, all acting on a faster time scale (see, e.g., [9] for a thorough survey of PQ improvement techniques in microgrids).
The main objective of the present chapter is to design and simulate an EMS algorithm for microgrids with specific PQ-related constraints while analyzing its behavior on realistic situations. The resulting algorithm proposed in this work investigates three different PQ issues, namely voltage drop, phase unbalance, and harmonic distortion. It also introduces new considerations regarding the operation of diesel generators during the transitions between grid-connected and stand-alone modes. The main advantage of the proposed algorithm is that it can effectively manage the abovementioned issues, whether the primary control means for PQ enhancements are available or not in the microgrid. The chapter starts with a description of the PQ indices and the common recommendations for their evaluation. Then, the model chosen for the DSM of the loads is presented in the following section. The third section enlightens the equations governing the EMS algorithm and outlines their role in the whole control mechanism of the microgrid. The fourth section presents and analyzes the results of the simulations for different scenarios on a test-case microgrid. A conclusion ends this chapter with the reminders on the conceptual approach, the procedure, and the major findings, while pointing the way toward further research.

Power quality issues in steady state
The term power quality has often been the subject of different interpretations. In [10], e.g., the definition encompasses several aspects without giving defined bounds: "Electric power quality is a term that refers to maintaining the near sinusoidal waveform of power distribution bus voltages and currents at rated magnitude and frequency. Thus, PQ is often used to express voltage quality, current quality, reliability of service, quality of power supply, etc." In this chapter, the attention will be focusing on issues with a large time scale (at every hour), such as undervoltage, voltage phase unbalance, and voltage harmonic distortion.

Voltage deviation
The voltage magnitude at a bus can deviate from its rated value. These deviations are often tolerated for small percentages, but if they cross certain limits, they are considered as disturbances. Considering a short line model between nodes 1 and 2, the real part of the voltage difference between the two nodes ΔV d is given by the well-known expression [11]: where P 1 and Q 1 are the active and reactive power flowing from node 1 to node 2.
Eq. (1) represents the voltage drop across the line. It clearly shows that it is highly dependent on the reactive power flow for inductive lines. However, in distribution lines with lower reactance on resistance ratio (X=R) such as in microgrids, both the active and reactive powers have an impact on the voltage deviation. The IEEE 1547-2003 standard recommends that a microgrid should not make voltage variations greater than AE5% around the nominal value [12]. The new norm IEEE 1547.4 also recommends that at least one DER should be responsible for regulating the voltage and the frequency in islanded mode, while staying in coordination with the other loads and DERs. In this chapter, the attention is focused on voltage drop.

Harmonic distortion
In recent years, the rising use of nonlinear power electronic devices along with an increase of the sensitive loads has resulted in various concerns [13]. The continued presence of harmonics can damage or degrade components in the networks such as transformers, electric motors, or electronic appliances. Harmonics also increase the total amount of power losses in the system [13]. High harmonics can normally be easily filtered by passive or active filters or, at least, reduced using appropriate modulation schemes in the control of the power electronic switches. However, low harmonics (3rd, 5th, 7th, 11th, etc.) are difficult to filter without reducing in the same way the signal at the base frequency. Harmonic cancellation techniques exist to tackle this problem, but they are usually expensive and technically difficult to implement [14].
The most used index to evaluate the distortion of a signal is called the total harmonic distortion (THD). The correct definition according to the IEC 61000-2-2 standard states that it is the ratio, in percentage, of the root-sum-square of all the harmonic magnitudes (without including the fundamental) on the magnitude of the fundamental [15]. THDs for voltage and current can thus be written as: At low voltages, the limit of 5% voltage THD is commonly used [16]. In this work, the current THD will be considered as a known factor for each load. But the voltage THD, which results from those current harmonics, will be the PQ index measured in each node and the one that will be effectively constrained with the bound of 5%.

Phase unbalance
According to the theory of the Fortescue decomposition, any three-phase system can be decoupled into direct, inverse, and zero-sequence components. The voltage unbalance is generally evaluated with an index called voltage unbalance factor (VUF), which corresponds to the ratio between the inverse V i ð Þ (or zero V h ð Þ) and direct-sequence V d ð Þ components of the Fortescue decomposition of the voltage: The IEEE 1547.4-2011 standard warns the owner of the microgrid that large voltage unbalances can cause problems to the three-phase inverter-based DERs, by placing high ripple currents on the DC bus. These ripple currents may also have an adverse effect on the synchronous generators and energy sources (like batteries and fuel cells). The norm recommends the objective of keeping a VUF lower than 3% at every node [12].
3. Building the energy management system 3.1 Control structure of an AC microgrid One can easily understand that communication between all the actors of the microgrid is essential, in order to maintain satisfying performance and to minimize the operating costs in both grid-connected and stand-alone modes. The control of AC microgrids is generally divided into a hierarchical three-level structure. In a similar way to traditional networks, the levels are differentiated by their usual time response. As shown in Figure 1, the entity that will supervise the communication between the different layers is called microgrid central controller (MGCC) [17].
The EMS algorithm supporting PQ that this work aims to develop is part of the tertiary control scheme. The algorithm will essentially compute cost minimizing optimization for 24 h, with specific decisions at each hour, thanks to a mixedinteger linear programming (MILP) algorithm. The algorithm will set the operating point of the production, storage systems, and load levels at every hour and assumes inherently that the frequency remains constant at 60 Hz. Steady-state PQ issues are addressed as well under the form of constraints, namely voltage drop, phase unbalance, and harmonic distortion. As already mentioned, it is interesting to notice that in traditional distribution grids, those PQ issues would normally be treated at the primary or secondary level of control, often with static compensator or dynamic power-electronics-based devices. But those installations are often too expensive for small-scale microgrids.
The constraints of the EMS algorithm can be divided into different sections, depending on the asset they concern: loads, grid connection, DGs, ESSs, etc. They are presented below using the following indices notations: • The time index in hours is called t (1, …, 24).
• The phase index is called ph (a, b, c).
• The load type index is called ty (HVAC, appliances, motors, etc.).
• The iteration index of the PQ regulation loop is denoted it (0, 1, 2, etc.). It should be noted that the r genset index gathers the different diesel generators that will have the task to maintain the frequency during stand-alone mode. Practically, only one diesel generator is enough if its capacity is sufficient.

Load-related parameters and variables
To represent the diversity of loads present in the system, each aggregated load l at a node of a microgrid is disaggregated into several subloads depending on the end use, called types of load and denoted ty. These types of loads gather common devices that have similar power factor, harmonic content, and flexibility, namely HVAC, domestic hot water (DHW), lights, appliances, and motor drives. The purpose of this distinction is to get a better knowledge of the types of equipment that are causing PQ issues within the aggregated loads. It could be, for example, foreseeable that the MGCC asks a consumer at a certain point of the network to reduce slightly the temperature of its building to avoid the purchase of power on the utility grid when this one is expensive.
The parameter type ratio l; ty ð Þ tells us the usual proportion of a load type ty in the consumption of an aggregated load l. For example, the type ratio l; ty ð Þof motors inside an industrial load is usually higher than 0.5. Each type of load also has the following parameters: fundamental-frequency power factor (pf ty ð Þ), harmonic content (harm ty; h ð Þ), current THD (THD I ty ð Þ), and flexibility (flex ty ð Þ), i.e., the percentage of the power consumption that a device can reduce without overly affecting its users. Those parameters are considered to be constant for every load type, whatever the active power they consume.
At an aggregate level, the total demand curve of a load at a specific node of the microgrid is supposed to be known and is referenced as P load, curve l; t ð Þ. Note that it is evaluated at the normal consumption usage, without the possible reduction linked with DSM. The aggregated loads could also be unbalanced between their phases. The phase distribution index phase distrib l; ph ð Þrepresents the ratio between the power that is actually required by a phase (a, b, or c) of an aggregated load and the power that would normally be consumed by this phase if the load was balanced. Thus, if these indices are unitary for all the phases of a load, this load is perfectly balanced. Finally, another parameter that will be useful for PQ matters is x=r l ð Þ, the ratio between reactance and resistance of the line to which the load is connected.
At each hour, each load type can be either active or not, this binary variable is called On load l; ty; t ð Þand is equal to 1 if the load is active. If it is the case, the active and reactive powers that the type of load effectively consumes are called P load l; ty; t ð Þand Q load l; ty; t ð Þ. The total active and reactive powers for the aggregated loads at each node of the microgrid are called P load, tot l; t ð Þ and Q load, tot l; t ð Þ.

Distributed generators
The DGs are generally interfaced with the grid by a fully controllable converter. These converters have the ability to absorb or generate reactive power in addition to the active power generation. Since the converter is independent from the DG, it can absorb or generate reactive power, even if the DG is turned off. The left-hand graph in Figure 2 shows the capability curve of the DG converter with active and reactive power axes. Normally, the rating of power electronic converters is expressed in VA, which means that the feasible zone should be a circle on an active and reactive power axis diagram. However, linear programming does not allow quadratic equations and the capability zone of the converter is then approximated by a rectangle. The absolute reactive power remains anyway small in general and this simplification would normally not affect significantly the results.

DG-related parameters and variables
If the DG is on, it will be able to regulate its output useful power between a maximum and a minimum. Of course, renewable and intermittent sources are less flexible concerning this last feature because they often depend on meteorological conditions. The minimal and maximal active power outputs if the DG is running are denoted P DG, min r; t ð Þ and P DG, max r; t ð Þ. The absolute reactive power generated or absorbed by the converter must also be enclosed by a maximum Q DG, max r; t ð Þ, depending on its rating. Capability zone of a DG and an ESS converter, with active and reactive power feasible ranges (in blue for discharging and green for charging). The real power rating (in VA) of the power electronic converter is represented with a dashed green line.
As for the loads, the DGs in the system can either be activated or not, depending on if they produce effectively active power or not. This binary variable is called On DG r; t ð Þ. The output active and reactive powers are denoted P DG r; t ð Þ, Q DG, gen r; t ð Þ, and Q DG, abs r; t ð Þ. The start-up and shutdown of a DG at a specific hour are also binary variables and are denoted ST DG r; t ð Þ and SD DG r; t ð Þ. Finally, the offgrid t ð Þ binary variable is equal to 1 if the microgrid operates in stand-alone mode at the hour t.

DG-related constraints
If the DG is activated (the variable On DG r; t ð Þ is equal to 1), the active power must be between the allowable minimum and maximum: On the opposite, a DG can produce or absorb reactive power even if the DG itself does not produce active power, it then behaves like a dynamic VAR compensator: ∀r, ∀t Q DG, gen r; t ð Þ≤ Q DG, max r; t ð Þ (10) In stand-alone mode, the role of certain diesel generators (gensets) is to regulate the frequency. For this reason, they should not directly contribute to the reactive power balance, but the converters of other DERs can take this task.
The start-up and shutdown of a DG at the hour t are defined as follows: Another novel constraint added to this algorithm is the use of diesel generator engines (genset) to smooth the transition between grid-connected and stand-alone modes. Indeed, in grid-connected mode, the stabilization of the frequency is achieved by the main utility grid. But in stand-alone mode, the diesel generators included in r genset (at least one) will have to take over the task. If the binary variable offgrid t ð Þ is equal to 1 at the hour t, the constraint then forces at least one genset to produce active power during each hour of stand-alone operation, and 1 h before and 1 h after as well.

Energy storage systems
As it is shown on the right-hand graph in Figure 2, the power converters interfacing the energy storage systems with the microgrid are usually able to work in the four quadrants of the active and reactive power plane. This is explained by the fact that they can manage a bidirectional flow of active and reactive powers.
Note that the generator convention is adopted, so, e.g., the active power is positive when discharging. As it was already explained in the previous section, the capability zone of these converters is approximated by a rectangle instead of a circle, due to the limitations of linear programming.

ESS-related parameters and variables
Every storage system in the microgrid possesses the following parameters: round-trip efficiency eff es ð Þ, maximal useful energy E ESS es ð Þ, maximal reactive power Q ESS, max , and maximal power for charging P ESS, char, max es ð Þ and discharging P ESS, dis, max es ð Þ. Another information needed is the initial state of charge (SoC) of the storage system at the hour preceding the beginning of the simulation, denoted SOC init es ð Þ [18]. The different variables for each ESS are the amount of active power it delivers or it absorbs, P ESS, dis es; t ð Þ and P ESS, char es; t ð Þ, the amount of reactive power it generates or absorbs, Q ESS, gen es; t ð Þ and Q ESS, abs es; t ð Þ, and the remaining SoC at every hour SOC es; t ð Þ. The binary variables ESS char es; t ð Þ and ESS dis es; t ð Þ are equal to 1 if the ESS charges or discharges active power, respectively.

ESS-related constraints
The first constraint forces the SoC of the storage system to be between 0 and 100%: At hour 1, the ESS needs a special equation because it uses the initial SoC parameter: The following inequalities restrict the active power of the charge and discharge by their maximal bounds: The same constraints as for the DGs apply concerning the generation and absorption of reactive power: ∀es, ∀t Q ESS, gen es; t ð Þ≤ Q ESS, max es ð Þ Q ESS, abs es; t ð Þ≤ Q ESS, max es ð Þ Finally, it seems natural that a storage system cannot charge and discharge its active power at the same time: ∀es, ∀t ESS char es; t ð ÞþESS dis es; t ð Þ≤ 1 (24)

Power exchange with the utility grid
As long as it is not in stand-alone mode, the microgrid is physically connected to a larger traditional utility grid at the point of common coupling (PCC).

Grid-related parameters and variables
The maximal power that can be drawn from the grid is denoted P grid, in, max . If the microgrid produces a surplus of energy, it can inject it into the grid. The maximum power that can be injected is called P grid, out, max . In grid-connected mode, the microgrid can also help the utility grid to achieve its own voltage stability by providing the reactive power it needs, which is denoted Q grid, req t ð Þ. The variables concerning the connection with the utility grid are the active power drawn from it, P grid, in t ð Þ, and rejected to it, P grid, out t ð Þ, and the reactive power absorbed from it, Q grid, in t ð Þ, or supplied to it, Q grid, out t ð Þ.

Grid-related constraints
The active and reactive power can, of course, only be exchanged if the switch at the PCC is closed, and so if the binary variable offgrid t ð Þ is equal to zero: ∀t P grid, in t ð Þ ≤ P grid, in, max Á 1 À offgrid t ð Þ ð Þ

Power balance
Some of the most essential equations in the algorithm are the balance equations that will equilibrate load and generation. Here are the equations for the active and reactive power balances: In this work, predetermined hourly values are used for loss P and loss Q that represent the upper bounds of losses in the system, as a ratio to the total active or reactive power demand. These values are calculated by the load flow studies and represent a very small percentage of the total hourly loads.

Power quality issue avoidance
The PQ constraints are not directly active at the first dispatch optimization of the MILP algorithm. The results will be first analyzed with a load flow and only then, if some standards are violated, new constraints will be added to address these issues. One difficulty is that the MILP optimization of the EMS only gives active and reactive power results and not voltages. It is therefore not possible to compute the voltage drop, the voltage THD, and the VUF directly. Three new constraints are thus defined to reflect the PQ issues, but with the leverage of active and reactive powers. The aim of this approach is to act on the demand level of problematic types of loads at the different nodes of the microgrid. For instance, if the voltage THD is above the limits at a node with residential loads, then the algorithm will ask the customers to reduce the consumption of their nonlinear loads, within a feasible range, to support the microgrid PQ and help to secure the safety of their own electrical equipment.

Power-quality-related parameters and variables
As mentioned previously, multiple iterations are launched between the MILP optimization and harmonic load flows if at least one PQ disturbance exceeds the standards. The goal is to find at the end of the iteration process the right constraints to add in the optimization that will prevent any PQ issue. In this work, sensitivity parameters λ ΔV , λ dist , and λ unb are used to strengthen these constraints at every iteration loop. The tuning of these sensitivity parameters essentially results in a trade-off between the accuracy of the final results and the speed of convergence. In practice, the voltage indices (ΔV, THD V , VUF) should be just below the standard in the best case, to limit the impacts on the levels of the loads.
The variables for the voltage drop, the harmonic distortion, and the phase unbalance in the MILP optimization are denoted α ΔV , α dist , α unb, ab , α unb, bc , and α unb, ca . They will be defined in the equality constraints presented below.

Power-quality-related constraints
The index it represents the iteration number. It is initialized at zero and then incremented each time it goes through a harmonic load flow (the variable i is in this case a positive integer).
As reminded within the Section 2.1, the voltage drop between two nodes is linked with the active and reactive power flows (see (1)). If the X/R ratio of the line that connects each aggregated load is known, then the variable α ΔV is defined as: The following equation is applied at every iteration if the voltage is below 95% of its rated value (i.e., ΔV >0.05 pu), at every load bus l and every hour t: with: If ΔV l ð Þ j j. 0:05 pu and it . 0: α ΔV, lim l; t For the harmonic distortion, Eq. (2) shows that nonlinear loads with a rich harmonic content will have a higher current THD and should therefore be limited when the distortion is too high with respect to the norms. One should notice that in this work, the current THD is a parameter fixed for every type of load ty, while the voltage THD is a PQ index computed with harmonic load flows. The variable α dist represents the total amount of distortion in the network and is defined as: The following equation is applied at every iteration, if the voltage THD is over 5% at least at one load bus l, and at every hour t: with: If several buses have an irregular voltage THD at a certain hour, the load bus that has the highest distortion is selected to create α dist, lim t ð Þ in (36). The constraints on the voltage distortion are global, for the whole microgrid, and only depend on the hour of the day t.
Regarding the phase unbalance, the following set of variables is adopted between each phase: α unb, ca t ð Þ it¼i ¼ ∑ l P load, tot l; t ð Þ Á phase distrib l; c ð Þ À phase distrib l; a ð Þ ð Þ (39) The following equation is applied at every iteration if the VUF is over 3% at least at one load bus, and at every hour t. The index ph 0 represents here the different phase to phase combinations. ∀t, ph 0 ∈ ab; bc; ca with: If VUF . 3% and it . 0: In these constraints, α unb, lim t ð Þ is also a global limitation for the whole microgrid that only depends on the time t. Hence, Eq. (41) selects at each hour the largest previous phase-to-phase α unb, ph 0 and the load bus with the largest VUF.

Objective function
The cost curve C grid, buy t ð Þ tells how much it costs to buy 1 kWh from the utility grid at each hour. If the microgrid has enough resources to produce more power than its own loads require, it can either store energy in the storage system or sell it back to the utility grid. The gain from selling energy at an hour t is called C grid, sell t ð Þ. For each type of load, a parameter called value of lost load (VoLL) and denoted C load ty ð Þ represents the lost gain from diminishing the use of this kind of load by 1 kW for 1 h. This parameter really depicts how valuable is each type of load. The type of load with the lowest VoLL will be the first one that the microgrid will reduce, drop out, or shift by some hours in case of emergency or high cost of electricity. On the other hand, critical loads which are important for the consumer should never be disconnected and a very high VoLL is attributed to them (e.g., important motor drives in a factory).
For the DGs, a fixed cost C DG, on r ð Þ represents the cost of maintaining and operating a DG when this one is running. An additional variable cost C DG, var r ð Þ represents the marginal cost of producing an additional kilowatt. This last parameter is often correlated with the price of the fuel for fossil-fueled engines. The cost related to the start-up of a synchronous fossil-fueled generator is denoted C DG, ST r ð Þ. For the storage systems, a small cost C ESS, dis is also attributed for discharging electricity from the storage equipment. This is done to prioritize the power production from renewable sources directly, rather than discharging the energy stored in the ESSs.
Since the reactive power is usually free of charges, any power electronic converter can produce or consume it. A side effect can happen in which a converter from a DER supplies reactive power to the converter of another DER. Yet, reactive power flows must be minimized to prevent voltage drops. The exchange of reactive power should indeed only be done to compensate the low power factor of certain loads or to participate actively in voltage support of the utility grid. So, to restrict the reactive power flows, a small fictive cost C DER, react is assigned to any kVAR exchanged. Furthermore, the microgrid should also prioritize its own reactive power at low voltages rather than requesting it to the utility grid at a higher voltage. The reactive power exchanged with the utility grid has been assigned with a cost C grid, react , which should be higher than C DER, react . Now, the MILP objective function can be stated gathering linear and binary decision variables with their respective cost coefficients. The total cost of operation for 24 h, C tot , should be minimized by tuning the various decision variables correctly and satisfying the constraints:

Methodology
As it can be seen in Figure 3, the user of the algorithm can first insert the values of different parameters in an Excel spreadsheet to create a specific scenario. Then, the algorithm first runs an initial optimization, under the form of an MILP that minimizes the daily costs, while respecting a set of constraints. The main linear variables for this optimization are either active or reactive powers. In order to quantify the impact of the PQ issues in terms of active and reactive powers, new PQ indices have been created for the purpose of this work (α ΔV , α dist , α unb, ab , α unb, bc , and α unb, ca ). These new indices have the advantage to be directly computed in the MILP and do not require any load flow (see Section 3.7.2). The MILP optimizations are solved with the software GAMS. The solver typically converges in around 90 iterations within a relative error of 2 Â 10 À6 .
Using the results of the MILP, the program OpenDSS [19] will launch a set of harmonic load flows. These load-flows will give all the information about the voltage on the different nodes of the microgrid that is needed to compute the PQ indices, i.e., the voltage deviation in per unit, the voltage THD, and the VUF. If any of these indices does not respect the standards that have been presented in the Section 2, a noninfinite value will be attributed to the corresponding α lim , so that at

Simulation for different case studies
The conceptual microgrid that has been used in this chapter is shown in Figure 4. It is an alteration of the one presented in [6]. While the properties of the lines, the American voltage levels, and the characteristics of the transformers and the DERs have been kept identical, this microgrid has different kinds of loads and a smaller number of branches. In order to show the diversity of power consumers in a microgrid, three main different loads have been introduced: a residential load, an industrial load, and a commercial load.
The test microgrid has three different levels of voltage, at 11.2 kV, 408, and 207 V. They are interfaced by transformers but do not include any DC bus. The architecture is radial, as usual in distribution systems, and divided into four different branches. The first branch contains two diesel generators genset 1 and genset 2 . These diesel generators are essentially a backup power supply in stand-alone operations. The second branch has a first bus at 408 V (node 3), which is connected to a small 60 kWp wind turbine and a battery storage system of 80 kWh useful energy. This branch continues to the 207 V voltage to feed a residential load of 48 dwellings, called Load 1 . The third branch supplies an important industrial load named Load 2 . Finally, the fourth branch is a bidirectional line that reaches a small office building load, Load 3 , with a 40 kWp PV installation. The power demands of the different aggregated loads are represented in Figure 5.
The utility grid seen from the PCC at node 4 has been replaced by its Thevenin equivalent. It has a short-circuit power of 1000 MVA and a X/R ratio of 22. All the technical and economical parameters concerning the properties of the lines, the transformers, and the DERs are listed in Appendix. The loss parameters loss P and loss Q are tuned to the upper bound of the ratio between the total active (or reactive) loss with respect to the active (or reactive) total load. After several trials, it has been found that loss P is worth 1.5% and loss Q is worth 13.0%.
The VoLL and the flexibility of each type of load for this test-case microgrid are reported in Table 1, alongside other characteristics from [20][21][22][23][24].

Normal operation
The first investigated scenario aims to represent the operation of the microgrid under standard technical and economic conditions. In order to establish a realistic price curve for the utility grid electricity throughout the day, the data are directly taken from the hourly values of the day-ahead prices from the Belgian power exchange (BELPEX) on March 2, 2018 [25]. The tariffs for the system operators and regulators and the other public obligations reproduce the one imposed by the Brussels DSO Sibelga on middle-voltage clients [26]. Figure 6 shows the composition of the cost of electricity from the utility grid, translated into dollars with a fixed exchange rate of 1.1942$/€. The reactive power flow required by the grid at each hour for the voltage support has been fixed arbitrarily, but it remains small with respect to the reactive power from the load and does not impact substantially the results.  The Normal operation scenario depicts how the microgrid operates without PQ issues, when the utility grid is reliable and its cost profile is based on real historical data. Figure 7 shows the results of the simulation concerning the active power operation points of all the DERs and the electricity drawn from the utility grid to cover the total load. The active power losses are not represented in this graph because they are relatively small, usually below 3 kW, and can be neglected. It can be seen that the diesel generators never appear in the electricity mix in this scenario. This is due to the fact that the different costs associated with their operation are quite high compared to the cost of electricity bought on the spot market. The renewable sources are obviously always running because their variable cost is extremely low. Concerning the ESS, it is charged when the grid is the lowest, at 3, 4, 5, and 13 h and discharged three times, at 1, 10, and 20 h, when the price of electricity peaks ( Figure 6). Figure 8 shows the voltages in per unit at the important nodes of the network. The 5% deviation from 1 pu is never exceeded during 24 h. Figure 9 represents the voltage THD evolution at each load node throughout the day. As one can observe, the Load 1 and Load 3 have a low-voltage THD, below 1.5%. For the industrial Load 2 , it is practically negligible because of the scarcity of nonlinear devices. Since all the  Active power dispatch during the day for the "normal operation" scenario. aggregated loads are assumed perfectly balanced in this scenario, the VUF is equal to 0 at every node.
Since none of the PQ norms are violated in this scenario, the constraints in (32), (35), and (40) are not activated and there is no need for iterations between the MILP and the harmonic load flows.

Voltage drop issue
To illustrate the action of the EMS algorithm when a power quality issue is detected, a scenario is created concerning a potential voltage drop. Other scenarios on harmonic distortion and phase unbalance have been conducted in a longer version of this study and essentially show similar results in terms of accuracy and speed of convergence.
In this scenario, the load curves of Load 1 and Load 3 are increased by 10% in comparison with the Table 1. This scenario was created to test the resilience of the microgrid toward voltage deviations. After the initial optimization, the EMS detects with the load flows that the increase of the total power requested by the first load causes several voltage drops under the 0.95 bound, at 10 h, from 12 till 16 h, and at  18 h. This first observation can be seen in Figure 10. The voltage at the node 8, where the Load 3 is connected, is only worth 0.9307 in per units at 12 h. To address this problem, an iteration process is started and activates the constraint (31), with a parameter λ ΔV equal to 0.9. The value of this sensitivity parameter has been found by a trial-and-error process. It comes from a trade-off between the speed and the accuracy of the convergence. The next graph on Figure 11 shows the reduction of the voltage drop after the third iteration. It can be concluded that the EMS manages to keep the voltage above 0.95 pu after only two iterations. The voltage obtained at 12 h after the first iteration is 0.9350 and then 0.9551 after the second iteration. Still for this particular hour, the DSM scheme has reduced the HVAC consumption in Load 3 by 20% and the appliance share by 11.41%. The appliances have indeed a low fundamental-frequency power factor, which leads to a higher reactive power demand and a worse effect on the voltage drop.

Conclusion and perspectives
Security of electricity supply, flexibility, cost-effectiveness, and renewable sources integration are some of the motivations that lead private or public entities to consider the implementation of grid-connected microgrid. The local production and storage systems allow some microgrids to ensure the supply of electricity for their loads in case of a frequency or voltage outage on the traditional grid. However, studies have shown that PQ disturbances can be difficult to tackle in small-scale microgrids, due to the lower stiffness of the distributed power generation.
The purpose of this chapter is to tackle several of these PQ issues that occur in steady state, namely voltage drop, harmonic distortion, and phase unbalance, by acting on the demand level of certain types of electrical devices in the microgrid. First, it has been considered that any load at a node of the network can be represented as the aggregation of several smaller loads that account for a particular type of end use. Consequently, every type of load has its own physical and economical properties. A demand-side management framework has been implemented, so the demand level can be regulated within a certain flexibility range. The DSM mechanism can be launched whenever the cost of electricity peaks, in offgrid situations, or to mitigate a PQ issue that violates the standards. This process is integrated under the form of constraints inside an optimization-based EMS algorithm that minimizes the overall daily costs. The algorithmic structure of this tool consists in a regulation loop between an MILP optimization and harmonic load flows. In order to reflect the magnitude of the PQ issues in the MILP optimization, new power quality indices that rely on active and reactive powers have been introduced. The designed algorithm has been simulated according to different scenarios on a test-case microgrid. The results show that the production, the storage, and the consumption in the microgrid can adapt efficiently to the price of electricity from the traditional grid and that the different power quality standards can be met after few iterations. This algorithm can be used for grid-connected microgrids at low or medium voltage that possess an efficient communication framework between the different consumers and producers of electricity.
Further research on the topic of power-quality-supporting EMS algorithms could include the possibility to add electric vehicles (EV) management, combined heat and power (CHP) generation units, or other kinds of electrical equipment inside the microgrid.

A. Appendix
Tables 2-7 gather the data used to run the simulations on the test-case microgrid presented in the fifth section.   Table 6. Technical properties of the ESS.  Table 7. Current harmonic spectrum of the types of load.