Modeling and Energy Management of a Microgrid Based on Predictive Control Strategies

: This work presents the modeling and energy management of a microgrid through models developed based on physical equations for its optimal control. The microgrid’s energy management system was built with one of the most popular control algorithms in microgrid energy management systems: model predictive control. This control strategy aims to satisfy the load demand of an ofﬁce located in the CIESOL bioclimatic building, which was placed in the University of Almería, using a quadratic cost function. The simulation scenarios took into account real simulation parameters provided by the microgrid of the building. For case studies of one and ﬁve days, the optimization was aimed at minimizing the input energy ﬂows of the microgrid and the difference between the energy generated and demanded by the load, subject to a series of physical constraints for both outputs and inputs. The results of this work show how, with the correct tuning of the control strategy, the energy demand of the building is covered through the optimal management of the available energy sources, reducing the energy consumption of the public grid, regarding a wrong tuning of the controller, by 1 kWh per day for the ﬁrst scenario and 7 kWh for the last.


Introduction
The continuous increase in electrical energy demand, which has risen by more than 3% annually since 1980, together with an increment in the use of electric vehicles worldwide, will cause exponential growth in the emission of polluting and greenhouse gases [1]. This increase in emissions will deteriorate the environment. For this reason, in 2018, the European Union (EU) discussed and approved a series of environmental policies intending to decarbonize the EU by 2030 [2]. Within this package of policies, there are two fundamental objectives: (i) to increase energy efficiency by 32.5% compared to 2005, and (ii) to minimize greenhouse gases by 40% compared to 1990 [3,4].
One of the solutions to counteract climate change is to reduce the use of fossil energy sources (FES) while increasing the use of renewable energy sources (RES) (photovoltaic (PV), wind, solar thermal, biomass, etc.). In this context, a microgrid (MG) may be defined as an electrical energy grid that can be self-sufficient or part of a global electricity generation system. In a MG, RES, energy storage systems (ESS), and controllable and non-controllable loads are interconnected [5]. Generally, a MG is connected to the public grid, but when there are failures in said grid, or the energy demand is very low, the MG works in off-grid mode, also called island mode [5,6]. Smart grids are made up of an energy management system (EMS), which allows for a more efficient use of available RES, thereby increasing the reliability of renewable plants and ESS [7,8]. Nowadays, smart buildings have MGs to cover part of their energy demand, through RES integration. Yan et al. [9] described that 30% of CO 2 emissions are related to energy consumption from commercial and residential buildings. These buildings' consumption currently represents 32% of global energy. For this reason, MGs are very beneficial, since they solve various types of problems, such as: (i) forecast of the energy demand, (ii) response to demand, (iii) cost of energy optimization, (iv) reduction of the carbon footprint, and (v) energy management [10,11]. The EMS manages the energy of the RES and the ESS, which have been used in recent years in energy distribution systems with the aims of reducing emissions of CO 2 , controlling the increasing demand for energy, and obtaining socio-economic benefits for sustainable growth.
The EMS aims to optimize the available energy resources to satisfy energy demand. Thus, an EMS requires a control algorithm to manage the MG's available energy resources. The authors of [12][13][14] presented strategies based on frequency control to manage the energy resources of an MG. On the other hand, Topa et al. [5] reviewed the most used optimization techniques in the EMS of MGs: metaheuristic methods, linear and nonlinear programming, dynamic programming, stochastic and robust programming, artificial intelligence, and model predictive control (MPC). This last technique, the MPC, is one of the most widelyused strategies today [15,16]. MPC is a control strategy used in multiple applications, which requires a system model to perform actions in the current time based on the future predictions of the system [17,18]. This optimal control strategy is based on an objective function that includes a series of restrictions present in the process. Through this, it is intended to meet a series of objectives, such as minimizing the energy bill, satisfying demand, minimizing CO 2 emissions, or any other aim that the user wishes to achieve [16,19]. Recent studies have developed several MPC formulations, which use various types of strategies. These EMS based on MPC aimed to minimize reliance on FES, minimize polluting emissions, and maximize RES production [20,21]. For example, references [22][23][24][25][26][27][28] used a strategy based on a linear MPC to manage the energy resources of a residential MG. This control strategy aimed to maximize the economic benefit of the MG, minimize ESS degradation, and respect the different operational constraints. On the other hand, the authors of [26,[29][30][31][32][33], proposed EMSs of microgrids based on nonlinear predictive control strategies. The main objective was to respond to demand by getting a balance between energy production and demand while at the same time minimizing the electricity bill, polluting emissions, and degradation of the MG instrumentation.
This work deals with the development of an MPC to efficiently manage the available energy resources of an MG. This is located at the CIESOL research center located at the University of Almería; a more detailed description of the MG can be found in [34]. The case study used as a reference in this work involved an MG composed of: a PV system, a battery storage system, controllable/non-controllable loads, and power electronic devices for energy regulation and transformation; and it is connected to the public grid. The energy resources of the MG will be managed by an EMS based on an MPC algorithm, which aims to satisfy the energy demand of an office in the CIESOL building, through the optimal control of the energy flows present in the MG. The commercial prices of electricity in Spain were taken into account for a determined time [35][36][37]. Optimum energy management in this paper allows for reducing costs related to the energy bill and CO 2 emissions. Additionally, the EMS must guarantee the energy supply of the building. To achieve these objectives, two simulation scenarios have been used, which included real generation and demand data for one and five days. These simulations evidenced how, with the correct tuning of the control strategy, the energy consumption of the public grid can considerably be reduced, regarding a wrong tuning of the controller, by 1 kWh per day for the first scenario and 7 kWh for the last.
The rest of this document is organized as follows: The system modeling is found in Section 2, and the controller design can be seen in Section 3. In addition, Section 4 shows the analysis of the results, and finally, the conclusions are detailed in Section 5.

System Modeling
The physical modeling of the system consists of obtaining a function or grouping of mathematical functions that define the behavior of the system, which for the case study of this work is the MG to be controlled. To have a general concept of an MG and its available energy resources, Figure 1 shows a simplified diagram of the elements that the MG is composed of.
The PV system is connected through a DC/DC converter, direct current (DC), which has a maximum power point tracking (MPPT) algorithm, guaranteed to work in its proper operation point. The MPPT output is connected to the input of a DC/AC converter, which will convert the DC energy to AC required by the loads. Furthermore, the battery bank is connected to a charge regulator, which is in charge of supplying or consuming energy of the MG. Its output is connected to the DC/AC converter. These converted energy parameters are sent to the control system, which is in charge of efficiently managing the available energy resources, to decide between switching to the consumption or sale of energy from the public grid.

PV Panel Modeling
The PV system model is obtained through physical equations based on an equivalent electrical circuit [38]. Figure 2 shows the electrical circuit used in the modeling of the PV system. In order to simplify the model, the parameters known as standard test conditions (STC) are used (G STC = 1000 W/m 2 , T STC = 25 • C). Equation (2) was obtained through the development of Equation (1)-expressing it as a function of both the current I and the output voltage V of the photovoltaic panel, where I D is equivalent to the current in a diode. This model based on an electrical circuit requires the following parameters to be known: the diode reverse saturation current I o , the light current I L , the shunt resistance R sh , the series resistance R s , and the parameter a, which is called the modified ideality factor. All these parameters in standard conditions are available in [40].
Since the MG has maximum power point tracking (MPPT) equipment, the operating point of the maximum power current I mp and maximum power voltage V mp are assumed. Equation (3) is obtained by replacing the parameters I mp and V mp in Equation (2). On the other hand, to obtain Equation (6), it is important to obtain the maximum power point in operating conditions. This is obtained through the partial derivative of electrical power P mp (see Equation (4)) with respect to V mp equal to zero; see Equation (5). This operation has been described in detail in [38]. The solution of the equations must be reached through a solver of complex equations. In this study case, the Newton-Raphson method was used [41].
Vmp +Imp Rs a

Battery Modeling
The percentage of energy stored by the battery is given by the battery's state of charge (SOC), as shown in Equation (7).
In order to manage the different behaviors in charging and discharging, the performance of the battery n bat was considered the same for both processes. In this simulation, it is useful to simplify the optimization problem, despite the fact that the performance of the battery for charging and discharging may be different.
The SOC(t) is defined as the ratio between the current capacity P bat (t) and the maximum capacity of the battery, C max expressed in (kWh), for each sampling time T s .

Controller Design
To solve the EMS, it is recommended to express the MG model in a state-space model [16]. Hence, the general representation of this model is shown by Equation (8).
where the states of the system are represented by the vector x(t), whose elements are: the SOC of the battery SOC(t), the renewable power P rnv (t), and P gen (t), which is the total generated power available to cover the energy demand. The input vector of the system is u(t) and is composed of: The power of the battery P bat (t). P grid (t), which represents the power supplied by the public grid. The renewable power destined to cover the demand, P rnv,dem (t), and the renewable power injected into the batteries, P rnv,iny (t). Finally, the output vector of the system is y(t) = [SOC(t)P rnv (t)P gen (t)] T . The strategy based on the MPC algorithm has the objective of covering the energy demand of an office located in the CIESOL building. The expressions, defined by Equations (9)- (11), describe the MG model. Additionally, we consider the expression, K bat = n bat /C max , as a constant.
u(t) = P bat (t) P grid (t) P rnv,dem (t) P rnv,iny (t) T Matrices A, B, and C calculated from Equations (9)-(11) are those of the MG model represented in state space. These matrices make up the general form of the model in state space.
Through this, the augmented model as a function of increments is obtained. Said model is described in detail in [18]. The matrixes of both forced response G and free F are represented by Equations (17) and (18), respectively. These expressions have been built through the prediction equations, which have been developed along the prediction horizon N p with a control horizon N c . These equations are composed by the states and control increments of the MG, where F is related with MG states and G is related to control increments; see [17,18].
The output equation of the system in its compact form is expressed through Equation (19), where Y is the output vector of the system; the states of the system are represented by x(t); and ∆U contains the increments of the MG input signal.
Thus, the optimization problem can be posed as reflected in Equation (20): SOC min ≤ SOC(t) ≤ SOC max P bat,min ≤ P bat (t) ≤ P bat,max P grid,min ≤ P grid (t) ≤ P grid,max P gen,min ≤ P gen (t) ≤ P gen,max P rnv,min ≤ P rnv (t) ≤ P rnv,max P rnv,dem,min ≤ P rnv,dem (t) ≤ P rnv,dem,max P rnv,iny,min ≤ P rnv,iny (t) ≤ P rnv,iny,max where Q δ is the cost of covering the demand in e/kWh; Q λ contains the costs of energy production from RES, ESS, and FES in e/kWh; and R is the reference which is equivalent to the electrical energy demand of the office. As pointed out in Section 2.2, a simplified model for the battery is used in this work. Thus, the model lacks non-linearities in its formulation, and a linear optimizer can be used to solve the optimization problem. This is expressed through Equation (20), where the optimal vector ∆U contains ∆u(k), ∆u(k + 1), ∆u(k + 2), · · · , ∆u(k + N c − 1). One of the MPC features is the sliding horizon control principle: only the first sample of control sequence, ∆U, is used-i.e., ∆u(k), rejecting the rest of the solutions. In the next sample time, the optimization problem is solved again with new information. This feature is repeated for every single sample time, T s .

Analysis of Results
The simulation scenarios addressed in this work aimed to analyze how the tuning parameters of the MPC-based EMS affect the efficiency of the MG in terms of FES consumption. Specifically, in these scenarios, two energy demands of normal consumption in the office were used for one and five days (see Figures 3 and 4), i.e., two periods that the EMS intends to cover.
In order to evaluate the MPC algorithm performance, several simulations were developed for each scenario with different N p and N c parameters; see Table 1. Based on these simulations, the MPC can be fine-tuned while trying to find a compromise between execution time T exe and demand response. In this case, the control parameters chosen were: N p = 24, N c = 6, and T s = 10 min for one and five days, respectively. On the other hand, both the maximum execution time T exe,max and the mean execution time T exe,mean for one day were T exe,max = 3.9997 seconds and T exe,mean = 0.3658 seconds, and for five days were T exe,max = 1.4956 seconds and T exe,mean = 0.1089 seconds. This configuration has a significantly lower execution time than the sampling time of the MPC algorithm and provides the best use of available renewable energy.   Figure 5 shows the results obtained with the proposed control strategy and the selected configuration of the tuning parameters for the first scenario. In his figure, it can be seen how the MPC controller reaches the objective of covering the energy demand of the building throughout the day. Additionally, it shows the SOC of the battery, where it can be seen how the battery remains within the limits allowed to preserve its useful life. These limits were established as a restriction within the solution of the optimization problem. The battery is always in the range of 20-80%.
The second scenario was conducted for five days in a row, with different generations of PV energy and different energy demand profiles for each day, as can be seen in Figure 6. The main objective of the EMS is accomplished even with different generation profiles for the PV system. On the other hand, the SOC trend of the battery remains within the limits allowed by the restriction, which is 20-80%.   The results obtained through the EMS confirm that the available energy resources are optimally managed with N p = 24, N c = 6, and T s = 10 min, compared to the other cases. Hence, the energy balance between generation and demand remain stable while saving the useful life of the battery storage system. On the other hand, the initial state of the SOC can be different to SOC max without affecting the tuning parameters of the MPC. However, the SOC is directly proportional to the energy generation time of the ESS. In other words, less energy production will be obtained from the ESS; therefore, a greater energy supply from the public grid will be required. Lastly, with this configuration, the EMS showed a reduction in the consumption of FES of up to 1 kWh per day and up to 7 kWh over five days, both with respect to shorter N p and N c . These indicators represent a reduction in: energy consumption from the public grid, the electricity bill, and CO 2 emissions.

Conclusions
This work addressed the modeling and control of a microgrid located in the CIESOL building (University of Almería, Spain) through an MPC strategy. In particular, the work evaluated the efficiency of the microgrid by fine-tuning the MPC control strategy. To do that, two simulation scenarios were used as references, which worked with real demand profiles of one and five days. In these scenarios, the MPC controller took into account the cost of electric energy from the public grid, the costs resulting from equipment degradation, and the energy consumption of the building.
The results show how the correct tuning of the setting parameters of the MPC controller (i.e., correct choice of N p , N c , and T s ) results in an efficient management of energy resources from the MG, such as: PV system, public grid, and battery storage, allowing us to reduce the consumption of FES by up to 1 kWh per day and by up to 7 kWh over five days, both with respect to the lowest values N p and N c . This reduction is notable for daily operation, as it is directly reflected in a reduction in the electric bill, a reduction in the consumption of FES, and, indirectly, in a minimization of the CO 2 emissions sent into the environment.
Future works are aimed to include both electric vehicles and non-linear states that were not taken into account in this methodology. Therefore, this new EMS will have non-linear states expressed as binary variables, which will define the real behavior of the battery and the electric vehicle. The results obtained from this new methodology will be an approach to reality.

Conflicts of Interest:
The authors declare no conflict of interest.

Abbreviations
The following abbreviations are used in this manuscript: EMS