1 Introduction

Renewable energy is volatile and intermittent, therefore to stabilize its energy consumption through the energy storage technology is necessary. The battery energy storage technology is becoming one of the promising development direction with those advantages such as high energy density, flexible installation and high charging and discharging speed [1,2,3]. The Microgrid technology is an important form of efficient use of distributed renewable energy, and the optimal allocation of energy storage capacity is an important problem in the design of grid-connected microgrid.

There are many related research results about the allocation strategy for storage capacity in micro-grids. In the literature [4,5,6], the distribution of the fluctuation of the microgrid is summarized by analyzing the historical operational data, and then the capacity of the energy storage system is obtained based on the stabilization effect and cost. In [7, 8], the time constant of the best first-order low-pass filter is determined by the stabilizing effect of the grid-connected output power, and the power and capacity of energy storage system are configured by the time constant. Literature [9, 10] uses the spectrum analysis method to optimize the output power storage, but this method is only a single-objective optimization to stabilize photovoltaic fluctuations without considering the cost factor. In [11, 12], the operation characteristics of important load in industry, and the optimization method of energy storage capacity of industrial photovoltaic microgrid is constructed with the aim of maximizing the utilization ratio of PV and the maximum annual net profit, but the impact of new energy volatility to grid is not involved. In [13, 14], a method of rationally configuring the composite storage capacity is proposed for the microgrid including photovoltaic power generation, wind power generation and typical load. A multi-objective optimization model with the lowest equipment cost, the best power matching and the most smooth renewable energy output power is established and the solution method is an adaptive inertia weight particle swarm optimization algorithm. In view of the randomness of new energy output, literature [15,16,17] puts forward a hybrid energy storage capacity allocation method based on opportunistic constraint planning, and the genetic algorithm is used to solve the problem with the lowest cost, but the optimization for energy storage to stabilize power fluctuations is not taken into account.

In this paper, the optimal allocation strategy of energy storage capacity in the grid-connected microgrid is studied, and the two-layer decision model is established. The decision variables of the outer programming model are the power and capacity of the energy storage. The objective is the least investment of the energy storage and the fluctuation. The decision variable of the inner-layer programming model is the charging and discharging power of the energy storage at the operation stage, the objective is the lowest power fluctuation of the system connection line. Then a case study of a grid-connected microgrid with wind power, photovoltaic, battery energy storage and load is given. Through the case study, the multi-scenario probability method is used to make the decision of the energy storage configuration.

2 The two-layer decision problem

The two-layer decision problem is an optimization problem with two-level hierarchical structure, and the outer the inner layer optimization problems have their own objective function and constraints. The objective function and constraints of the outer optimization problem are not only related to the decision variables of the outer optimization problem, but also on the optimal solution of the inner optimization problem. The optimal solution of the inner optimization problem is also affected by the decision variables of the outer optimization problem. The general mathematical model of the two-layer decision problem is as follows:

$$ {\displaystyle \begin{array}{l}\left\{\begin{array}{l}\underset{x}{\min \limits }F\left(x,y\right)\\ {}s.t.g\left(x,y\right)\le 0\kern0.5em \end{array}\right.\\ {}\left\{\begin{array}{l}\underset{y}{\min \limits }f\left(x,y\right)\\ {}s.t.h\left(x,y\right)\le 0\kern0.5em \end{array}\right.\end{array}} $$
(1)

In the above formulas:\( x\in {R}^{n_x} \), \( y\in {R}^{n_y} \)are the decision variables of the outer optimization problem and the inner layer optimization problem, respectively.\( F,f:{R}^{n_x+{n}_y}\to R \)are the objective functions of the outer optimization problem and the inner layer optimization problem. \( g:{R}^{n_x+{n}_y}\to {R}^{n_l} \)are rrespectively the Restrictions of the outer optimization problem and the inner layer optimization problem.

It is usually difficult to obtain the global optimal solution of the two-layer optimization problem, and it is considered that the optimal solution is obtained by the iterative approximation of the numerical solution and satisfying certain convergence conditions.

3 Energy storage configuration model

In the two-layer programming model proposed in this paper, the decision variables of the upper-level model are the capacity and power of the storage system and the objective is the lowest cost of the battery energy storage system. The decision variables in the lower-level model is the charging and discharging power of battery. With the increasing number of grid-connected microgrids, the power fluctuations on connection line will adversely affect the stability of the grid. So in the lower-level model, the objective is the lowest power fluctuation of the system connection line.

3.1 The upper-level model

The objective function is:

$$ {\displaystyle \begin{array}{l}\min {C}_A={c}_1{P}_{ES}+{c}_2{E}_{ES}+\\ {}\kern0.1em \lambda \sqrt{\frac{1}{N-1}\sum \limits_{i=1}^N\left({P}_{ES}(i)+{P}_L(i)-{P}_G(i)-{P}_{base}\right)}\end{array}} $$
(2)

In the above formula, c 1is the unit power cost, for lithium batteries, lead acid and other battery energy storage, it is mainly the cost of power converter system (PCS); c 2 is the unit capacity costs, it is mainly the cost of the battery; λ is the penalty factor for the power fluctuation of the connection line; P ES is the power of energy storage in microgrid; P L is the power of load in microgrid; P G is the power of generation in microgrid; P base is the demand capacity reported to the grid by the microgrid corporation.

The constraints are shown as follows:

$$ {\displaystyle \begin{array}{l}{P}_{ES}\le {P}_M\kern3em {E}_{ES}\ge \frac{1}{SOC_M-{SOC}_0}\sum \limits_{k=1}^i{P}_{ES}(i)\varDelta t\\ {}{E}_{ES}\le {E}_M\kern2.5em {P}_{ES}\ge {P}_{ES}(i)\\ {}i=1,2,\dots N\end{array}} $$
(3)

Where N is the calculated number of time period, P M and E M are respectively the power and energy capacity of the storage system due to the installation site, grid power, etc., SOC M is the highest state of charge that allowed by the battery energy storage system, SOC 0 is the initial state of charge of the battery energy storage system.

3.2 The lower-level model

Two–part electricity price is implemented for the grid-connected microgrid. The first part is the fixed demand capacity cost which is calculated according to the demand power. And the second part is the electricity cost bought from the connection line. For the microgrid operator, the fluctuation variance of the connection line means extral tarrif. As a result, the inner objective function is given as below:

$$ {\displaystyle \begin{array}{l}\min f=\sum \limits_{i=1}^N\Big\{{P}_{ES}(i)+{P}_L(i)-{P}_G(i)-\\ {}\kern0em \frac{\sum \limits_{i=1}^N\left[{P}_L(i)-{P}_G(i)\right]}{N}\Big\}{}^2\end{array}} $$
(4)

The above equation shows the fluctuation variance of the power of the connection line within one day. p ES (i), p L (i), andp G (i)are respectively the energy storage power, load power and generation power in the microgrid system in the i time period.

The constraints are:

$$ \left\{\begin{array}{l}-{P}_{ES}\le {p}_{ES}(i)\le {P}_{ES}\\ {}{SOC}_m\le SOC(i)\le {SOC}_M\\ {}-{P}_{G0}\le {p}_{ES}(i)+{p}_L(i)-{p}_G(i)\le {P}_{L0}\end{array}\right. $$
(5)

Where P L0, P G0 are respectively the maximum allowable consumption power and reverse power on the connect line. The first constrain is.

Here, p ES is maximum the charging and discharging power of the energy storage. Assuming that the energy storage system charging efficiency η c and discharge efficiency η d remains constant, set α as follows:

$$ \alpha =\left\{\begin{array}{l}{\eta}_c\kern0.5em {p}_{ES}>0\\ {}1/{\eta}_d\begin{array}{c}\end{array}{p}_{ES}\le 0\end{array}\right. $$
(6)

So we can get the equation:

$$ SOC(i)= SOC\left(i-1\right)+\frac{\alpha (i){P}_{ES}(i)\varDelta t}{E_{ES}} $$
(7)

where Δt is the calculating length of the time period.

3.3 Solving algorithm

It can be seen that the outer programming model is a quadratic problem and easy to solve. The inner programming mode is a mixed integer nonlinear programming (MINLP) problem, its objective function can be expressed as a form of univariate function and the dynamic programming method can be used to solve the problem. The dynamic programming method decomposes a multi-stage optimization problem into single-stage optimization problem by stage division, which is an effective algorithm to solve the problem. The dynamic programming model needs to determine the calculated decision quantity and state quantity. For each controllable resource, the power of each calculation period is the decision quantity in the dynamic programming model; for the energy storage, the SOC at the end of each calculation period is its state quantity, the initial state quantity and the end state quantity are known quantities.

The optimal strategy of the dynamic programming decision-making process has the property as follows: the rest of the decisions must be an optimal strategy when any of the state is taken as the initial level and initial state, regardless of the initial state and the initial decision. That is, if there is a N-level decision process with initial state of x(0), its optimal strategy is{u(0), u(1), …u(N − 1)}. Then, for a N-1-level decision process with initial state of x(1), the decision set {u(1), u(2), …u(N − 1)} must be the optimal strategy.

Figure 1 shows the state transfer diagram of the N-level decision process. An N-level decision process can be expressed as follows:

$$ {\displaystyle \begin{array}{l}x\left(k+1\right)=f\left[x(k),u(k),k\right]\\ {}x(0)={x}_0\end{array}} $$
(8)
Fig. 1
figure 1

Transition diagram of stage state

The constraints in the above formula are:x(k) ∈ X ∈ R n, u(k) ∈ Ω ⊂ R m. At this point, the programming problem can be described as solving an optimal control (decision) seriesu (k) , k = 0 , 1 ,  … N − 1, which can make the performance indicator minimum.

The solving method of dynamic programming problem can be divided into two directions: forward and backward. The forward direction means starting from the initial layer and calculating gradually to the end; the backward direction means starting from the end layer and reversing the solution. In practical problems, the backward direction is more commonly used. The paper adopt the backward direction method.

At each stage, SOC at the end is considered as the state quantity, the power of the energy storage p ES (i) is the decision quantity, the variance of the power becomes the corresponding cost function, and eq. (7) is the dynamic equation.

The power decision set of energy storage can be established through the charging and discharging power limit and the line power limit. The state set of energy storage can be established through the SOC range of operation. Enumeration method is adopted to solve the single stage MINLP problem. According to the second constrain in eq. (5), the state set is composed of discrete value from SOC m to SOC M by a step of ΔSOC. The decision set can be calculated accordingly. The lessΔSOC value, the larger the decision set. As a result, it takes more time to calculate the optimal decision.

According to the steps above, the optimal charging and discharging process of energy storage system can be solved. Figure 2 shows the transition diagram of SOC’s stage state.

Fig. 2
figure 2

Transition diagram of SOC’s stage state

From the inner problem we can get the optimal charging and discharging process of the energy storage system. The solve of inner problem is transferred to the upper-level model to get the optimal configuration of energy storage system. And the configuration is transferred to the lower-lever model as constrains. The iteration process is illustrated in Fig. 3.

Fig. 3
figure 3

The variable quantity transfer of the two-level model

4 Case study

In this case, a grid-connected microgrid with wind power, photovoltaic, battery energy storage and load is studied. The system structure of the microgrid is shown in Fig. 4.

Fig. 4
figure 4

System structure diagram of grid-connected microgrid

In this system, the installed capacity of photovoltaic is 300 kW, the installed capacity of wind power is 500 kW, the maximum load is 1200 kW, the maximum power limit of the connection line is 1000 kW, and the reverse transmission power is limited to 500 kW.

For the uncertainties of wind power, photovoltaic power and load, the multi-scene probability method is used to make the decision of the energy storage configuration. That is to say, the energy storage configuration is calculated in several scenes, and decisions are made according to the probability level of each scene. Scene analysis is an effective method to solve stochastic problems. By modeling the possible scenes, the uncertainties in the model are transformed into multiple deterministic scene problems, where the difficulty of modeling and solving is reduced. The time series of a possible operating state in the period being studied is called a scene s, and the set of all possible scenes of the system is called the scene set S. The uncertainty of the system can be simulated by generating a scene set.

Here, the historical data of wind power, photovoltaic power and load in this microgrid during one year is used for analysis, that is, the number of scenes is 365. In order to trade-off between the computational burden and maintain a certain degree of credibility, an approximate subset of the original scene is selected using the probability distance to reduce the number of scenarios. The original scene set can be reduced to four scenes which are shown in Table 1 and Figs. 5, 6, 7 and 8. Table 2 shows the optimal configuration of energy storage in each scene. Figure 9 shows the energy storage configuration of grid-connected microgrid system based on scene decision.

Table 1 Energy storage configuration scenes
Fig. 5
figure 5

Daily power generation and load curve of microgrid in scene S1

Table 2 Optimize configuration results for energy storage in each SCENE
Fig. 6
figure 6

Daily power generation and load curve of microgrid in scene S2

Fig. 7
figure 7

Daily power generation and load curve of microgrid in scene S3

Fig. 8
figure 8

Daily power generation and load curve of microgrid in scene S4

Fig. 9
figure 9

Energy storage configuration process based on scene decision

Fig. 10
figure 10

Energy storage and contact line power curve in scene S1

Fig. 11
figure 11

Energy storage and contact line power curve in scene S2

Fig. 12
figure 12

Energy storage and contact line power curve in scene S3

Fig. 13
figure 13

Energy storage and contact line power curve in scene S4

The power curves of energy storage system and connection line in each scene are shown in Figs. 10, 11, 12 and 13. According to the configuration results of energy storage in each scene, the power and capacity of energy storage can be calculated as follows:

$$ {P}_{ES}=\frac{\sum \limits_{s=1}^n{P}_{ES}^s{p}_s}{\sum \limits_{s=1}^n{p}_s},{P}_{ES}=\frac{\sum \limits_{s=1}^n{E}_{ES}^s{p}_s}{\sum \limits_{s=1}^n{p}_s} $$
(13)

The energy storage configuration result is 227. 4 kW / 240. 7kWh after calculation. The values of the parameters are shown in Table 3. The value of c 1 and c 2 is given as an example for Lithium energy storage system cost nowadays. λ is given considering the total cost of construction of distribution network and the reserve capacity of system.

Table 3 Optimal configuration of energy storage in each scenario

After calculation, the standard deviation of the power fluctuation of connection line in the grid-connected microgrid can be suppressed within 50 kW (expected value) under this energy storage configuration.

5 Summary

This paper studies an optimal configuration strategy of energy storage in grid-connected microgrid and detail work is as follows:

(1) The two-layer decision model of energy storage capacity configuration is given. The decision variables of the upper-level model are the power and capacity of the energy storage and the objective is to minimize the initial investment and the fluctuation on the connection line. The decision variable of the lower-level programming model is the charging and discharging power of the energy storage, and the objective is the lowest power fluctuation of the connection line. The upper-level model is a quadratic programming problem, which is easy to solve. For the lower-level model which is not easy to be solved, the dynamic programming method can be used.

(2) A case study of a grid-connected microgrid containing wind power, photovoltaic, battery energy storage and load is given. The multi-scene probability method is used to make the decision on the configuration of energy storage according to the probability level of each scene. Finally, the result of the energy storage configuration is 227.4 kW / 240.7kWh under which the power fluctuation of connection line in the grid-connected microgrid can be suppressed within 50 kW.