Open-Access Model of a PV–BESS System: Quantifying Power and Energy Exchange for Peak-Shaving and Self Consumption Applications

: Energy storage is vital for a future where energy generation transitions from a fossil fuels-based one to an energy system that relies heavily on clean energy sources such as photovoltaic (PV) solar energy. To foster this transition, engineers and practitioners must have open-access models of PV systems coupled with battery storage systems (BESS). These models are fundamental to quantifying their economic and technical merits during the design phase. This paper contributes in this direction by carefully describing a model that accurately represents the power directions and energy dealings between the PV modules, the battery pack, and the loads. Moreover, the general model can be implemented using two different PV generation methods, the Gaussian model and the meteorological data-based model (MDB). We found that the MDB model is more appropriate for short-term analysis compared to the Gaussian model, while for long-term studies, the Gaussian model is closer to measured data. Moreover, the proposed model can reproduce two different energy management strategies: peak-shaving and maximizing self-consumption, allowing them to be used during PV–BESS sizing stages. Furthermore, the results obtained by the simulation are closed when compared to a real grid-tied PV–BESS, demonstrating the model’s validity.


Introduction
As the adverse effects that climate change pose to humanity become more evident due to extreme weather events, mitigation actions are fundamental and must occur promptly.Definitely, the way and pace at which developed countries have consumed energy is not sustainable.Therefore, the actions to mitigate climate change must be directly related to a drop in the world energy demand and an increase in clean energy generation in the near future [1].Among those actions are the electrification of transport and heating.However, such components of the energy transition urge a dramatic, but planned, expansion of the installed power capacity from renewable energy sources and energy storage systems.As detailed in [2], renewable energy sources (RES) spread in low-voltage distribution networks can cause overvoltages, and the increasing power demand created by the electrification of heat and transportation can cause congestion.This way, energy storage systems can contribute to avoiding such issues on the distribution network.Thus, combining renewable energy sources with energy storage technologies is expected to grow exponentially in the coming years [3].Particularly, photovoltaic (PV) energy has been identified as one of the most prominent RES technology, as it is accessible to everyone and has low maintenance costs.The PV system's upfront costs have been decreasing [4] continuously.Likewise, battery energy storage systems (BESS) are becoming more reliable and profitable and, therefore, more attractive to investors [5].
Given the massive rise expected in the amount of PV systems worldwide, it is crucial to develop models that help engineers and practitioners during the design process of the PV system.Among the processes needed for a correct design, energy yield simulations and profitability studies must be performed [6].For doing so, the power flow between a PV system's components-PV modules, grid, and battery pack-and the criteria defined by the Energy Management Systems must be simulated to calculate the energy exchange.
There are several commercial PV-related software available.For instance, PVSYST © was one of the first programs developed to evaluate PV potential, considering the location and meteorological data while also including a database of products-e.g., PV modules, inverters, battery packs, optimizers, and charge controllers-that better suit the PV system to be installed [7].Additionally, PV*SOL © is a simulation program that allows designing PV systems with energy storage with the possibility of 3D visualization and shading analysis [8].In the case of PVSYST © , the professional license costs around 675 USD per year, while the license for PV*SOL © is 1295 USD with an updating scheme.Thus, to facilitate the adoption of PV systems in place where buying this proprietary software is too high, it is fundamental to have open-access models and libraries that provide free tools, which are essential in enabling the adoption of PV systems in places where the cost of purchasing proprietary software is prohibitive for many people.

Relevant Literature
During the last few years, multiple papers have described methods to model the output power of PV systems.Authors have proposed several mathematical tools for forecasting short, medium, and long periods of PV generation.For instance, in [9], a 15 min ahead method based on a higher Markov chain is proposed to obtain the PV generation's probability distribution function, considering temperature and irradiance to determine the PV system operation points.Similarly, in [10], a PV power forecasting method was implemented for ranges between 5 min to 36 h, including in situ measurements and satellite images as inputs.These approaches are beneficial for PV power predictions, especially in the context of smart grids, as reported in [11], where having a reliable estimation of PV power for the electricity grid's stability is fundamental.Convolutional neural networks are also proposed by [12] to forecast PV output based on historical operation and meteorological data from power plants in the region.
Despite the increasing research in modeling renewable energy sources, they alone cannot create strong grids due to their dependency on weather conditions.Therefore, energy storage systems should be coupled to ensure stability [13].While historical data is essential to validate such tools for designing a well-sized PV system (viz., adequate installed PV peak power and battery storage capacity, quantification of economic benefits), recent works have proposed different approaches for modeling the interaction between RES and battery energy storage systems, as shown in Table 1.For instance, ref. [14] proposed a multifunctional control strategy for a battery energy storage system, in which minimizing the PV power ramp rate was proposed.An improved electric system cascade analysis to optimize a PV system with a BESS for a residential load based on historical data, with results comparable with HOMER, was presented in [15].In contrast, proprietary software such as Matlab-Simulink © , DIgSILENT © , and HOMER © have been used in different case studies involving the power flow within a PV system and other distributed energy sources.One can notice the importance of accurate data for PV-BESS models from Table 1.As can be seen, most of the models require measurements of temperature and irradiance for an appropriate output.These data can be obtained from multiple sources of software such as Meteonorm © or SolarGIS © , local meteorological institutes and international projects, as well as the ERA-Interim [20].Nevertheless, forecasts are required to accurately predict the behavior of the system.
Although previous research has been published under the open access scheme, the complete details of how to implement the model presented have not been made available in its entirety [21][22][23][24].Moreover, most of the literature uses proprietary software requiring a license purchase, as shown in Table 1.Therefore, this paper introduces an open-access platform (the repository can be found in [25]) for modeling and simulating a PV-battery system that can be included in the publicly available options for designing and understanding the dynamics of a PV-battery system for solar engineers and practitioners.Additionally, this article provides the possibility of choosing among two PV generation models based on the data available and the objective of the analysis.

Contributions
This paper contributes by Demonstrating the dynamics of a PV-BESS system using both integrated models for peak-shaving and self-consumption applications, validating them with measurements of a PV system in Costa Rica.

PV-BESS Model
The open-access model consists of several parts, as shown in Figure 1.The PV modeling part is carried out to obtain the PV power.The energy management system (EMS) manages the energy flow between all the system components according to the mode of operation defined.The battery modeling keeps track, among other things, of the battery state-of-charge (SoC) to determine whether it can deliver, receive, or stay idle according to the energy management system.The PV model is considered an optimal orientation method, which provides the optimum tilt and azimuth of the PV array to obtain the maximum energy yield annually.

PV Modeling
In this section, we explain two approaches to calculating the power generated by a PV system: the meteorological data-based model and the Gaussian model.Both methods need a different set of inputs and have different advantages and limitations.This way, one can use the model that fits better according to the information available and project requirements.

Meteorological Data-Based Model
This model consists of three main parts: the solar calculator, PV system optimum orientation block for a specific objective (e.g., maximizing annual yield, yield during winter, or production during peak demand hours), and the thermal model.The inputs for the solar calculator are the location (latitude and longitude) of the PV system and the time frame where the analysis will be performed (date), as shown in Figure 2. Based on that, and following the procedure reported in [26], it is possible to express the position of the sun in terms of altitude (a s ) and azimuth (A s ).These two coordinates are calculated every time step k and are the PV system optimum orientation block inputs.This block also takes annual irradiance information to estimate the total irradiance over a PV module (G m ) for a specific orientation, i.e., azimuth (A m ) and inclination of the module (a m ).Note that the values of A m and a m are changed to find the combination that yields the maximum energy (in kWh/m 2 ) over a year.This way, it is possible to study modules not optimally oriented due to installation constraints such as roof orientation.
Several equations are used as intermediate steps to arrive at the annual energy yield E m .First, the cosine of the angle of incidence (θ m ) is calculated as Once angle of incidence is obtained based on the position of the sun using the solar calculator, one can calculate the direct irradiance (G direct ) as a function of the direct normal irradiance (DNI) as Then, the diffuse irradiance (G diffused ) is calculated as where DHI is the global horizontal irradiance and V sky,factor is the sky view factor (fraction of the PV module facing the sky), calculated as Moreover, the reflected irradiance results from the albedo (α), considered constant at a value of 0.2 in this article, and the global horizontal irradiance (GHI) can be calculated as All the contributions of the irradiance over the plane of an array (G m ) can be computed as This gives the value of the irradiance falling into the PV modules for every timestep.By integrating it, the total energy that can be potentially converted into electricity over a period of time is determined as Once G m is known, the power of the PV module can be calculated using where the efficiency of the module is represented by η PV , and A PV is the area of the PV module.However, η PV is heavily influenced by the temperature of the PV module.Therefore, the thermal model introduced by Duffie and Beckman in [27] considers it by including ambient temperature and wind speed.This model consists of an iterative process that assumes an initial temperature, and it is run through a loop until T m converges to a particular value.With a known (T m ), the final efficiency of the PV module to be later used by Equation ( 8) is given by where η STC is the efficiency at STC (standard test conditions), T STC is the module temperature at standard test conditions (25 • C), and β is a temperature coefficient.For monocrystalline PV modules, β is normally taken as −0.0035/ • C. As mentioned by [16], few studies estimated the effect of tilted PV arrays.The proposed meteorological data-based model considers it in two approaches: it can either estimate the optimal tilt angle for the modules or the output for any given tilt angle.This is especially useful for designers, as using the optimal tilt angle is not always possible.Moreover, the inputs required for this model are similar to other methods in the state-of-theart (see Table 1), requiring temperature, irradiance, longitude and latitude, and the ratings of the PV and the BESS; and as it is a non-iterative process, the computational cost is very low.On the other hand, the outputs for real-time applications will not be precise if historical data is used.However, the output is expected to be accurate if measurements are used as input instead of historical data.Likewise, if the intention is to use the model to forecast, its accuracy will highly depend on the quality of the predicted values for temperature and irradiance.

Gaussian Model
The stochastic behavior of the weather variables, such as temperature, wind speed, and irradiance, make it difficult to forecast the output of a PV system accurately.As indicated in Section 1.1, and demonstrated with the meteorological data-based model, a representative behavior is an alternative for precise calculations.On the other hand, ref. [28] proposed a simplified approximation for the ideal clear-sky solar curve, called envelope curve.The model is based on the Gaussian bell equation, associating the probability density with the daily specific energy production and using the error function, er f (x), to adjust the output near sunrise and sunset.Using this approach, the maximum theoretical power during sun hours can be estimated as where t sr is the sunrise time, t ss is the sunset time, and µ is the mean power time.E PV is the output energy from the system given by where P p PV is the peak power of the system and E sd is the daily specific energy production per unit of power.
The Equation (10) also considers two fitting factors that can be adjusted based on previous meteorological measurements: α, related to the slope of the bell near the sunrise (α 1 ) and sunset time (α 2 ), and σ, related with the width of the bell.To avoid residual power values outside the sun hours, Equation (10) can be rewritten as Figure 3 shows the algorithm to implement the Gaussian model.First, one needs a dataset with measurements of the power output of a reference PV system, P for that location.Then, the fitting factors σ, α 1 , and α 2 have to be adjusted so the resulting envelope curve correlates with the envelope curve of the reference dataset.Once tuned, the model can be extrapolated for systems close to the reference system since the radiation conditions and the sunrise and sunset times would be similar.Unlike the meteorological-based (MDB) model, this model's results are helpful for preliminary energy-based approximations thanks to its low computational requirements and because it assumes evenly distributed meteorological data during specific timeframes.Note that the model's accuracy depends directly on the accuracy of the measurements, both the meteorological and the reference PV system datasets.Nevertheless, this model is not recommended for real-time control, as it does not consider the effect of cloudiness and temperature on instant power.This is a major drawback compared with the MDB model or the models reported in the literature (for example, the cases presented in Table 1).Still, this model was proposed for initial estimations instead of precise instant power calculations, so designers have a fast tool to estimate the yearly energy output of a PV system.

Battery Modeling
Among the main challenges of the massive deployment of PV systems in distribution networks is their non-controllable behavior.Such behavior causes sudden changes in the energy flow, leading to overvoltages or congestion issues [29].Battery energy storage systems provide a solution, as they act as filters for those sudden changes, absorbing the surplus of energy and compensating deficits [30], providing flexibility to the electrical network.Furthermore, the advantages of BESS installed with PV systems go beyond the distribution system owner (DSO), as they can also benefit their owner economically.If the energy price varies in time, the storage system can purchase energy from the grid when the prices are lower, avoiding or reducing the purchase when the price is higher.
Consistently with most of the literature, we used an energy-balance approach to model the BESS.The energy stored in a BESS at a particular moment depends on its previous state and the amount of power extracted or provided between sampling times.This way, the state equation of the energy stored in the BESS can be written as where E BESS is the future amount of energy stored in the battery, C BESS is the capacity of the battery, SoC is the state-of-charge of the battery, η c,d is the charge or discharge efficiency as it corresponds, P BESS is the charge or discharge power as it corresponds, ∆t is the sampling time, and E SD BESS is the self-discharge of the battery between time samples.Note that most of the variables from Equation (13) depend on external conditions.The capacity and charge and discharge efficiencies depend on the temperature and the depth of charge or discharge.Moreover, they decrease as the battery ages [31].On the other hand, the state-of-charge cannot be calculated but has to be estimated.This estimation will depend on the BESS technology, but in most cases, it can be estimated based on the battery's voltage [31].
For this work, we evaluated the models for two applications: maximize self-consumption and peak-shaving.For the first application, the EMS will meet the demand first by the PV and then by the BESS.If the combined power of the PV and BESS inverters is insufficient to supply the demand, the remaining power will be purchased to the grid.For the second application, the batteries will only cover the power demand above a certain threshold when the PV is insufficient and will charge only with the surplus of energy from the PV.Similar to the first application, the power from the BESS will be restrained by its inverter capacity, both for charging and discharging the batteries.
The flowchart in Figure 4 depicts the general control scheme.Note that both applications will follow the same logic, governed by two constraints: the state-of-charge of the battery and the permitted power from the grid, P perm Grid .The main difference is that the self-consumption will have a permitted power from the grid of 0 kW, whereas the peak-shaving will have a permitted power above 0 kW.

Inputs to the Models
Figures 2 and 3 depict the algorithms behind the meteorological data-based and Gaussian models.The source code for both codes can be found in [25].
The meteorological-based model takes inputs such as ambient temperature, all the components of the solar irradiance (DNI, DHI, and GHI), and wind speed, as seen in Equations ( 2), ( 3), ( 5), ( 6) and (8).For this work, we used the software Meteonorm© as the source for a yearly (1 h timestep) dataset.It is essential to point out that the output datasets from Meteonorm© are constructed taking meteorological stations as a reference; thus, the data are adjusted based on location.Therefore, although the datasets correctly reflect the meteorological conditions of a particular place, they only partially fit datasets measured at the site of interest, as the data from meteorological software give information on a typical year while measuring data changes from year to year.
The Gaussian model only uses the daily average irradiance and requires a dataset of power output to tune the Gaussian bell equation.However, we used the same parameters used in [28] for two reasons: first, both systems are close enough, and second, because the purpose of this work is to provide models that can be used with available information before installing the system.

PV System Installed
We used measurements from a PV system installed at the University of Costa Rica to validate the results obtained with the models.This system comprises 17 modules of 265 W p Canadian Solar, each connected to a P400 SolarEdge power optimizer and arranged in a single string to a 7.6 kW SolarEdge SE7600A-US inverter.

Load
The electrical load used was based on [32], where the average weekdays' electrical consumption for Costa Rica was reported.Two peaks characterize the load profile.One occurs at noon, while the other is at 6:00 pm, close to sunset (see Figure 5).This load can be easily replaced or used as a reference to be scaled up or down to study different cases.To quantify the cost savings projected with the two models and compare them with the actual cost savings, we used a timeframe tariff shown in Table 2.

PV Generation
Figure 6 shows a representative week from the simulated year, considering simulation parameters indicated in Table 3.As can be seen, the Gaussian model considers a uniform curve throughout the month.As it does not consider cloudiness, its accuracy for real-time predictions is very low, as on June 26.Still, it can perform relatively well on sunny days, as on July 1.On the other hand, the meteorological data-based model depends on weather conditions.This way, it can recreate sudden changes in power due to meteorological conditions, as on July 2. We must highlight that the results of the meteorological databased model do not coincide with the real-time variations because we used historical data.However, the MDB includes the seasonal effects on PV generation from an energy and power perspective.As tools for preliminary assessment of monthly PV generation, the models showed an acceptable accuracy, as detailed in Figure 7.For this purpose, the Gaussian model performed better, with a monthly error ranging from −20.7% and 25.3%, with an average of 1.456%.The MDB model, on the other hand, had a monthly error ranging from −15.8% and 37.18%, with an average of 17.74% (the error was considered as the difference between the total accumulated energy resulting from the measurements and each model, divided by the total accumulated energy from the measurements).The reason behind this behavior is similar to the analysis of the real-time comparison presented above.Since the Gaussian model is based on monthly values gathered from PV power measurements from previous years, the representative behavior of more extended periods (such as months) performs better than short periods (such as specific days).Similarly, it is less sensitive than the MDB model, which depends on meteorological data that vary yearly.
In the case of having actual measured meteorological data as inputs to the MDB model, it will undoubtedly perform better than using historical data as provided by the software Meteonorm© or the Gaussian Model.Similarly, the PV generation curves from the MDB model represent more realistically the behavior of partially cloudy days than the Gaussian Model.The Gaussian model and the MDB adequately represent the behavior expected during sunny days regarding the PV generation profile.

PV-BESS
We also modeled a BESS to evaluate its combined behavior with the PV system with two objectives: maximize self-consumption and perform peak-shaving.The inverter of the PV system and the inverter of the BESS are connected with an AC coupling.The proposed models allow the designer to adjust the different parameters for the PV and BESS systems.
Table 3 shows the parameters used to simulate the BESS.With this information, the power flow balance is implemented to make decisions regarding the operation of the battery pack, i.e., charging (positive power), discharging (negative power), or idle (zero output power).It is important to note that the battery capacity can be easily changed.Thus, an iterative process can be performed to progressively increase the battery capacity to quantify energy exchange and electricity costs.This way, the optimal PV-battery system sizing can be determined.

Self-Consumption
As mentioned before, the EMS can influence the power magnitude and direction, ensuring a specific mode of operation to fulfill a predefined objective.In this case, the main objective is to supply the electrical load only via the PV system and the BESS.Therefore, the energy purchased from the grid can be minimized.
To validate the performance of the models under self-consumption schemes, we defined a permitted purchase power of 0 W (P perm = 0).This way, the algorithm will always prioritize supplying the demand from the BESS. Figure 8 shows a representative section of the simulated year.As expected, the BESS cannot supply the load entirely in the absence of PV availability, as the power demand is higher than the capacity of the BESS inverter.Thus, power is purchased from the grid.Similarly, when the available PV power surpasses the load, the BESS is charged, constrained by the inverter's nominal capacity, returning the excess to the grid.
Complementary to the power exchange shown in Figure 8, the behavior of the SoC of the BESS is shown in Figure 9 for the measured PV power and the two models.One can notice that the SoC curves overlap at the beginning until the PV power becomes available.Given the uniformity of the Gaussian model, the charge and discharge behavior is consistent between days.For the MDB model, the effects of the meteorological conditions are present when the PV power drops below the load near sunset.The power used to charge the BESS drops for short periods, usually during the evening.The costs associated with coupling the PV and BESS systems for each PV curve (measurements, Gaussian model, and MDB model) are presented in Table 4.As can be seen, both models propose lower costs than the reference scenario.The reference scenario considers the measured PV instant power.The Gaussian model predicts costs 2.89% less than the reference scenario, while the MDB model predicts 17.49% lower costs than the reference scenario.This difference can be explained because of the input variables for each model.As demonstrated in Section 4.1, the Gaussian model uses representative available irradiance per month.Thus, the overall results are expected to be closer to the reference scenario.The MDB model, on the other hand, depends on more variables, making it less preferable to predict long periods.

Peak-Shaving
To perform peak-shaving, we attempted to keep the load under a specific value by reducing the power supplied from the grid.In this case, we considered a maximum permitted load of 1.5 kW.To do so, the PV power is directly fed to the load, and if the PV power is not enough to satisfy the load, the battery pack delivers the remaining power to the load if the SoC is above 20%.
The results are presented in Figure 10.As can be seen, the BESS provides power to supply part of the load only when it surpasses the threshold of 1.5 kW.Nevertheless, if the load is above 2 kW, the difference should be provided from the grid, as the BESS inverter is at its maximum capacity of 500 W. As a result, the power from the grid is drastically reduced during the day, and once the PV generation reduces, the BESS delivers power to fulfill the 2 kW goal.
Increasing or decreasing the maximum peak power from the grid affects the SoC behavior of the BESS and the battery inverter.Figure 10b shows that the BESS never reaches the minimum SoC allowed.Likewise, near noon, the BESS charges completely.This way, the BESS distributes its energy more effectively throughout the day.In this case, the battery is fully cycled for the nominal PV capacity defined during the day.Therefore, parameters such as the maximum load peak or battery inverter power rating can be changed to optimize the system sizing.

Conclusions
It is fundamental to have open-access to simulation tools able to reproduce the dynamic behavior of PV-BESS, especially for practitioners.Accordingly, this paper gives a detailed description of all the stages needed to adequately express the nature of the PV-BESS system in terms of power and energy.Two models to estimate PV generation were documented and compared to an experimental dataset.Such models use similar data inputs to the models reported in the literature and are not computationally expensive, thanks to their non-iterative nature.Choosing one model over another is related to the data availability of the particular site of interest and the user's purpose.Based on our results, the Gaussian model is beneficial for yearly energy-based estimations.In contrast, the meteorological data-based model is better for understanding the variable behavior of PV systems and can be used for real-time control if measurements are available as inputs instead of historical data.Moreover, the MDB model considers the PV modules' tilt to determine the optimal angle or evaluate the modules on any given angle, a condition omitted in many models in the literature.Since we used historical data, the results of the MDB model do not coincide with the real-time variations.Still, for more prolonged analysis, it can resemble the seasonality effect regarding cloudiness and temperature.Nevertheless, it would be suitable for short-term predictions if predicted values for the meteorological variables are provided.
Then, we evaluated EMS operation modes for the PV-BESS system: maximize self-consumption and peak-shaving.In both cases, the model allocates the power without violating the maximum BESS power.In our case scenario, the Gaussian model performed better on energy estimation, with an average error of 1.456% vs. the 17.74% of the MDB model, both compared to monthly energy measurements.When coupling the BESS model, the predicted energy costs with the Gaussian model were 2.89 and less than the actual costs, while the MDB model predicted costs of 17.49% more than the actual costs.Both behaviors are explained by the input data and how the model performs in the longer term.As the Gaussian model considers an evenly distributed energy production per month, it is expected to represent better periods as months or years.On the other hand, in the short term, it becomes less accurate, as it does not consider weather conditions.In those cases, the MDB model outperforms the Gaussian model.
Further research includes the development of accurate short-term weather predictions so that the EMS can use the MDB model for predictive control.Additionally, implementing other ancillary services than peak-shaving can be useful to evaluate the flexibility PV-BESS systems can provide to the grid.

Figure 1 .
Figure 1.Block diagram of the PV-BESS model, considering the parameters for each instant k.

Figure 2 .
Figure 2. Block diagram of the meteorological data-based model to determine the optimal orientation for a given objective.
re f PV , as well as the specific energy production, E month, ref s,D , sunrise time, t month, ref sr , and sunset time, t month, ref ss

Figure 3 .
Figure 3. Block diagram of the Gaussian model.

Figure 5 .
Figure 5. Representative section of the electrical load considered for the test (graph created from the data provided in [32]).

Figure 6 .
Figure 6.Comparison of the instant power measured and the results obtained with the Gaussian model and the meteorological data-based model during a representative week.

Figure 7 .
Figure 7.Comparison of the measured monthly accumulated energy and forecasted by the Gaussian model and the MDB meteorological data-based model.

Figure 8 .
Figure 8.Comparison of (a) the instant power measured and the results obtained with (b) the Gaussian model and (c) the meteorological data-based model during a representative week, considering a self-consumption scenario.

Figure 9 .
Figure 9. SoC of battery during the self-consumption operation.

Figure 10 .
Power exchange using as a reference measured instant power measured (a), and (b) SoC of the battery during the peak-shaving operation, considering a maximum allowed power purchased from the grid of 1.5 kW.

Table 3 .
Parameters for the simulations.

Table 4 .
Comparison of the monthly energy costs considering an average daily consumption of 40 kWh under a self-consumption operation.