MG systems have spurred increasing interest in the electric power industry   . MG is a smart small-scale electric power system that consists of a mix of generating units, controllable loads, storage units, low-voltage transmission lines, transformers and a point of common coupling (PCC) to the main grid. PCC represents the main circuit breaker that is used to switch between two operation modes: islanded and grid connected. The successful implementation of these modes in MG has contributed to its widespread deployment, worldwide .
References   have presented a number of challenges in MG implementation. These include demand-side management, control of energy resources, and frequency restoration in momentary generation failures or abrupt load change. In a grid-connected mode, the MG system is generally stable since frequency and voltage variations can be tuned by the grid. In an islanded mode, a robust control system has to be implemented to maintain consistent power flow within voltage and frequency limits . The intermittent nature of renewable resources and the unpredictable weather conditions driving solar power can easily make MG systems unreliable and unstable. Different types of control systems have been introduced to address the unreliable and unstable behavior of MG . Generally, these behaviors are simulated using OPAL-RT and MATLAB .
An important real-time energy management system was presented to reduce cost of operation  for different stability scenarios. Reference  presented an implementation of intelligent controls to ensure stability of MG in real-time. Further investigations have been made to provide insights on inverter-based PV and controllable load mechanisms to control voltage variations in an islanded mode . These variations are probabilistic in nature and so a stochastic modeling approach for reactive power control was used for an industrial 47-bus MG system  . The results have shown that stochastic modeling can accurately capture voltage variations and can produce consistent reliable MG operation. Software and hardware implementation of voltage and load controls have been presented using FPGA . Real-time simulation of MG is still an open research.
In this paper, OPAL-RT real-time analysis of MG is presented. The objective is to optimally allocate solar power to meet power demand in realtime. In an islanded mode, momentary failures in power generation are introduced and recovery of critical loads is simulated in real-time based on a priority scheme. The impact of power balance while varying the amounts of power generation and demand is examined. In the simulation of MG mode transition, reactive power coordination control is used in order to minimize power loss while load shedding is used in order to maintain generation-load balance. GJU microgrid system is used for illustration. The results show that reactive power coordination control not only stabilizes the MG operation in real-time but also reduces power losses.
The remaining sections of the paper are organized as follow: Section 2 gives details of MG system. Section 3 presents GJU MG for real-time simulation. Reactive power control and load shedding mechanisms are presented in Section 4. Section 5 presents simulation results of GJU case study. Finally, the paper is concluded in Section 6.
2. MG System
As shown in Figure 1, MG generally consists of controllable loads and renewable generation resources (e.g. wind and solar) that are complemented by on-site diesel generators and/or storage batteries. MG is managed and operated in real-time either in a grid-connected mode or an islanded mode mainly controlled
Figure 1. Microgrid system.
through PCC. In the following subsections, formal models of MG components are introduced as a basis of formulation.
2.1. Controllable Loads
Controllable loads consist of load profiles that are generally time varying and are mainly driven by the type of customer behavior. Methods such as linear regression, time series, autoregressive, exponential smoothing, curve fitting, permutation and machine learning, are used for load forecasting . Using curve fitting and given the dominant load profile at MG site under study, a piecewise function in three-time intervals is developed and gives the forecasted total power demand at time t as follows:
where A and B represent constant values that can be calculated using curve fitting of historical data and ω and ϕ denote angular frequency and phase shift of a sinusoidal function that best fits the load profile during 24 hours of a given day, respectively.
2.2. Generation Resources
Renewable generation consists of solar and wind. Since the output power of solar and wind is intermittent and non-controllable, it is necessary to have storage and/or controllable generation that can replace power shortage and maintain constant local power.
Solar Power: Solar power is produced by large array of photovoltaic cells, formally defined as, :
where G, T, A, η, and α denote solar radiation, ambient temperature, area of panels, system efficiency, and power degradation, respectively.
Wind Power: Wind power is produced by converting the kinetic energy of wind turbines, formally defined as, :
where σ, , and ν denote air density, swept area of rotor blade, and wind speed, respectively.
Diesel Generating Power: The output power of N diesel generators is formally defined as:
where denotes the output power of the ith diesel generator, cost of which at time t is defined as:
and , A, F, and ∆t denote the cost ($), price of diesel ($/Liter), variable cost, and time interval, respectively.
Utility power: In a grid-connected mode, the operational cost also includes the cost of power absorbed from utility grid, defined as,
where K is the price of utility grid energy ($/kWh). A negative value represents that energy is being sold from MG to the utility grid.
2.3. Storage Batteries
Storage batteries are considered the fastest element to provide power when it is needed. Charging and discharging of storage batteries depends on the utility grid price of energy when the microgrid is working with grid-connected mode, . At high load peaks, discharge of batteries provides more economic benefits. It avoids the MG from paying high energy prices to the utility grid and in some cases selling can take place When the MG is turning into islanded mode, storage batteries can contribute in stabilizing the system and mentaing generation-load balance.
3. GJU Microgrid
The single line diagram of the GJU campus microgrid is shown in Figure 2. The main components represented as controllable loads; generating units; and PCC to the main grid. Loads are categorized in buildings A, B, C, D, E and F as essential, nonessential, and air conditioning that are connected through remotely controllable circuit breakers. Details of demonstration have been throughly investegated in the 3DMicrogrid project, . Figure 3 shows a typical load profile for a Winter and a Summer day, where peak loads occur during working hours
Figure 2. GJU Campus single-line diagram.
Figure 3. Load profile for summer and winter day.
8:00-17:00. PV power generation exists at Buildings B, D, E, and F with a total capacity of 1.5 MW. The PV power generation for a Winter and a Summer day is shown in Figure 4. The patterns indicate the intermittent nature of PV and therefore, the six diesel generators that are installed in buildings A to F are used to accommodate the intermittence of PV resources. There is also a PCC substation with 33/11KV transformer which interconnects to the main grid for a two-way power flow.
The transmissions lines interconnect generation resources and building substations with 11/.4KV bus transformers. The PV generation is dependent mainly on weather conditions which vary over the year. Figure 5 shows the energy patterns of PV generation and Load for 12 months. In January, for instance, PV produces 40% less power than load. In May and June, PV produces 32% and 24% more power than load, respectively.
Power losses and power balance factors are important keys in power system analysis. They have direct impact on performance and economic operation. Power balance is impacted by the amounts of power generation and demand. Maintaining generation-load balance of the islanded MG while keeping a stable real-time operation is a challenging task. Furthermore, in electrical power systems, reactive power plays a vital role in power stability. This leads to the necessity of addressing reactive power losses as a critical term. Two scenarios are analyzed for real-time generation-load balance in a stabilized MG. One is the reactive power coordination control that aims to minimize power losses and the second is the load shedding that aims to meet accurate generation-load balance, especially during transition between MG operation modes.
Figure 4. PV generation for summer and winter day.
Figure 5. PV Generation and consumption.
4. Control Algorithm
4.1. Reactive Power Control
Inverter-based systems have a critical role in controlling the injection and absorption of reactive power in order to perform several functionalities such as voltage variation control, power losses control, and power curtailment. This is mainly achieved through reactive power control which largely reduces power loss in transmission lines. The power loss on a given transmission line is formally defined as, :
where V, R, P and Q represent the voltage, line resistance, active power and reactive power, respectively.
The reactive power control is known as Q-coordination control and generally contributes to a loss reduction of few percentages. The process begins with adjusting reactive power set points based on the local variation of feeder power losses. The value of the set point is essential in performing the inverter operation in terms of reactive power compensation. Accordingly, the power transfer through system buses will be limited and hence the power losses will be decreased. The PV block has two predefined set points for both active and reactive power parameters. Inside the PV subsystem, a large group of blocks has been built to perform a robust control system for the PV operation in MG. Reactive power directly affects the inverter functions in terms of the reactive power compensation based on acceptable voltage limits.
The determination of the new setpoint in the PV block is based on reactive power of load, leading to a minimum reactive power flow via the network feeder. Figure 6 presents an illustration diagram of the proposed coordination control, starting with sensing the reactive power output from the load (Qload). The value of Qload will be fed to Zero Order Hold block. This value will be transformed to a per-unit (pu) value in order to be utilized as a set point of the PV block that is connected with the specified load. PV systems are installed and connected with substations 2, 4, 5 and 6. Q-coordination control has been implemented in substations 2 and 4 for testing. Figure 7 represents the output reactive power real-time readings of substation 2.
Figure 6. Block B with the reactive power coordination control.
Figure 7. Reactive power readings of substation 2.
The blue line shows the original case without implementing the Q-coordination control. The orange line indicates the impact of implementing the control on reactive power reduction. The disturbance in the signals at t = 5 seconds is due to the transition between islanded and connected modes. In the Simulink model, the conversion between the restoration operation of the system occurs during this interval, resulting in signal disturbance. This allows testing and analyzing the proposed scheme in both operational modes. The results show that power losses at substation 2 were decreased by 9.8%. The losses at substation 4 were decreased by about 6%.
4.2. Load Shedding
The load shedding algorithm is shown in Figure 8. In case there is a difference between power generated and power consumed, load shedding is a mechanism to guarantee generation-load balance in real-time. Let ΔP represents the power difference, then its value can be zero (perfect balance between generation and demand), positive or negative. The positive value indicates a surplus of power generation that can be stored in batteries, charging electric vehicles or injected to the utility grid. The negative value indicates shortage of power which can be compensated by the utility grid, power storage, turning on diesel generators, or load shedding. In a grid-connected mode, the main grid becomes the master controller of MG and the PCC acts as a two-way power flow. In case ΔP is negative, the grid compensates shortage of power in real-time and stabilizes MG voltage and frequency. In an islanded mode, a load shedding algorithm can be a viable
Figure 8. Load shedding algorithm.
solution in the absence of enough storage and insufficient DG capacity. When ΔP is negative, load is curtailed by a percentage defined by the load at a given substation over the total load and the priority of the load connected to the substations. The load with a small load percentage and a lower load priority is considered as the first choice to be disconnected in order to decrease the overall required demand. After load shedding, ΔP is computed again and curtailment is made on the basis of load priority as described. Based on GJU load profile, load curtailment is made at substations 6, 5, 2, 3 and 4 with percentages 6%, 10%, 25%, 45% and 19% respectively. For load shedding in real-time, a robust sensor system is built. This system has the responsibility of sensing the power flow from MG. In an islanded mode, the power flow from the main grid becomes zero. During transition to an islanded mode, a triggering pulse will be set to measure the power difference that triggers load shedding algorithm providing on/off signals to load points at substations.
5. Simulation Results
We use RT-LAB, the OPAL-RT’s real-time simulation platform for GJU MG, with Edit, Compile, Execute, and Interact in three subsystems: Master, Slave, and Console as summarized in Table 1. The generic voltage and frequency variables
Table 1. Subsystems in RT-LAB platform.
are represented in discrete time with a step size T. Two factors impact the simulation of RTS, namely: the model complexity and the computational speed of the installed hardware, .
Figure 9 shows GJU MG in Matlab/simulink and RT-Lab with the main grid interconnecting six PV areas, load substations and the diesel generator units via the PCC breaker. The two main stations are connected with six substations. The parameters of transformers, cables, load, PV, DGs and other components have been identified for simulation, . The RT-LAB software is used in the second stage of the simulation. It is composed of two subsystems; Master and Console as shown in Figure 10. The computational components are located in the Master subsystem, while the scopes blocks are located in the console subsystem. The “powergui” block performs simulation solver type, obtains steady-state values, adjusts initial state, and runs FFT (Fast Fourier Transform) analysis. The ARTEMIS is a Simulink block in OPAL-RT. The Solver of RTS is used and compatible with MATLAB and “SimPowerSystems”. The “OpComm” block is a key component in the model during the RTS that is installed from the RT-LAB library. It has the responsibilities of providing the communication infrastructure between the MG subsystems.
The historical data of GJU power profile during years 2015-2018 have been used, . Figure 11 shows the power difference of GJU model in a real-time mode. As the MG transmits to the islanded mode, the Power difference (ΔP) parameter becomes negative. This is due to the absence of power from the main grid. Accordingly, substation 6 is disconnected as the first choice in the proposed load shedding.
Figure 12 shows the voltage and current signals of the load attached with the substation 6 where the disconnection has occurred at t = 5.5 sec. After the disconnection of load 6 and since the value of the ΔP is still a negative value, the second choice of load shedding is then made for substation 5. Figure 13 shows the voltage and current signals. When ΔP goes to an acceptable positive value at t = 6.3, MG system is then said to have reached to the desired power balance level.
Figure 9. GJU model in MATLAB/Simulink.
Figure 10. Master and console subsystems in RT-LAB.
Figure 11. Power difference in a real-time mode.
Figure 12. Voltage and current signals of load 6.
Reactive power coordination control process was used in  to stabilize a 50 MWp PV power planet connected directly to the utility grid. Simulations show that in case of small disturbances, PV panels can recover the system while during large disturbances it depends on the power planet capability. The process
Figure 13. Voltage and current signals of load 5.
was also used to reduce the power loss caused by the transmission lines. We have investigated the process on a MG that contains 2.1 MWp PV system, six low-medium voltage and two medium-medium voltage substations. The process showed high potential of achieving stability of the system supported with the load-shedding strategy. Authors of  have investigated the concept development and cost-benefit analysis of the reactive power management used at the distribution level.
This study has investigated the capability of MG to maintain a safe and stable operation in critical conditions through real-time simulation. Two scenarios have been studied to address the power losses and power balance factors. The first one is the reactive power coordination control which mainly aims to minimize power losses. The second scenario is load shedding which mainly aims to balance generation power and load in the absence of connection to the utility grid. Fault Ride Through technique has been used to examine the ability of generating units to stay connected and available in case of voltage sag occurrences. A real-time simulator using OPAL-RT platform with Matlab has been used for GJU MG model construction and analysis. The results have shown that reactive power coordination control not only stabilizes the MG operation in real-time but also reduces power losses by 6% - 9.8%. Load shedding has also been implemented for generation-load balance of MG in the islanded mode. Further development of the study may include optimal resource allocation, load management, and storage implementation to support self-healing in critical and abrupt failures.
This work has been partially supported by the EC FP7 ERANETMED project named “3DMicroGrid” with project number: ERANETMED_ENERG-11-286.
 Che, L., Zhang, X., Shahidehpour, M., Alabdulwahab, A. and Al-Turki, Y. (2016) Optimal Planning of Loop-Based Microgrid Topology. IEEE Transactions on Smart Grid, 8, 1771-1781.
 Prete, C. and Hobbs, B. (2016) A Cooperative Game Theoretic Analysis of Incentives for Microgrids in Regulated Electricity Markets. Applied Energy, 169, 524-541.
 Gregoratti, D. and Matamoros, J. (2015) Distributed Energy Trading: The Multiple-Microgrid Case. IEEE Transactions on Industrial Electronics, 62, 2551–2559.
 Yoldaş, Y., Önen, A., Muyeen, S., Vasilakos, A. and Alan, Ì. (2017) Enhancing Smart Grid with Microgrids: Challenges and Opportunities. Renewable and Sustainable Energy Reviews, 72, 205-214.
 Almutairy, I. (2016) A Review of Coordination Strategies and Techniques for Overcoming Challenges to Microgrid Protection. Proceedings of Smart Grid (SASG), Jeddah, 6-8 December 2016, 1-4.
 Guo, F., Wen, C., Mao, J. and Song, Y. (2015) Distributed Secondary Voltage and Frequency Restoration Control of Droop-Controlled Inverter-Based Microgrids. IEEE Transactions on industrial Electronics, 62, 4355-4364.
 Guerrero, J., Chandorkar, M., Lee, T. and Loh, P. (2013) Advanced Control Architectures for Intelligent Microgrids Part I: Decentralized and Hierarchical Control. IEEE Transactions on Industrial Electronics, 60, 1254-1262.
 Bouzid, A., Sicard, P., Paquin, J. and Yamane, A. (2016) A Robust Control Strategy for Parallel-Connected Distributed Generation Using Real-Time Simulation. Proceedings of 2016 IEEE 7th International Symposium on Power Electronics for Distributed Generation Systems (PEDG), Vancouver, 27-30 June 2016, 1-8.
 Elsied, M., Oukaour, A., Youssef, T., Gualous, H. and Mohammed, O. (2016) An Advanced Real Time Energy Management System for Microgrids. Energy, 114, 742-752.
 Farzinfar, M., Jazaeri, M., Nair, N. and Razavi, F. (2014) Stability Evaluation of MicroGrid Using Real-Time Simulation. Proceeedings of 2014 Australasian Universities Power Engineering Conference, Perth, 28 September-1 October 2014, 1-6.
 Acharya, S., El Moursi, M., Al-Hinai, A., Al-Sumaiti, A. and Zeineldin, H. (2018) A Control Strategy for Voltage Unbalance Mitigation in an Islanded Microgrid Considering Demand Side Management Capability. IEEE Transactions on Smart Grid, 10, 2558-2568.
 Kekatos, V., Wang, G., Conejo, A. and Giannakis, G. (2014) Stochastic Reactive Power Management in Microgrids with Renewables. IEEE Transactions on Power Systems, 30, 3386-3395.
 Sheikh, S., Iqbal, S., Kazim, M. and Ulasyar, A. (2019) Real-Time Simulation of Microgrid and Load Behavior Analysis Using FPGA. Proceedings of 2019 International Conference on Computing, Mathematics and Engineering Technologies, 30-31 January 2019, 1-5.
 Jacob, M., Neves, C. and Vukadinović, D. (2020) Short Term Load Forecasting. In: Forecasting and Assessing Risk of Individual Electricity Peaks, Springer, Berlin, 15-37.
 Aryuanto, S., Lomi, A. and Mulayanto, W. (2011) Modeling of Wind Energy System with MPPT Control. Proceedings of the 2011 International Conference on Electrical Engineering and Informatics, Bandung, 17-19 July 2011.
 Ni, K.X., Wei, Z.B., Yan, H., Xu, K.Y., He, L.J. and Cheng, S. (2019) Bi-Level Optimal Scheduling of Microgrid with Integrated Power Station Based on Stackelberg Game. Proceeding of 2019 International Conference on Intelligent Green Building and Smart Grid, Yichang, 6-9 September 2019.
 Do, D., Kothari, D. and Kalam, A. (1995) Simple and Efficient Method for Load Flow Solution of Radial Distribution Networks. International Journal of Electrical Power and Energy Systems, 17, 335-346.
 Qian, M., Liu, Y., Chen, N., Zhu, L., Zhao, D. and Jiang, D. (2015) A Static Reactive Power Coordination Control Strategy of Solar PV Plant Considering Voltage and Power Factor. Proceedings of International Conference on Renewable Power Generation, Beijing, 17-18 October 2015, 1-6.
 Wang, H., Kraiczy, M., Wende-von, B., Kämpf, E., Ernst, B., Schmidt, S. and Braun, M. (2017) Reactive Power Coordination Strategies with Distributed Generators in Distribution Networks. Proceedings of the 1st International Conference on Large-Scale Grid Integrated Renewable Energy India, New Delhi, 6-8 September 2017.