Introduction

There is a global interest to reduce the production of greenhouse gases. A major part of greenhouse gas productions is due to energy generation from fossil fuels. Renewable energy resources are seen to be an alternative to fossil fuels. The solar energy is one of the dominant renewable energy resources. The photovoltaic cells are used for generating electrical energy from solar light. These photovoltaic cells are installed by consumers at their home. The installation of the photovoltaic cells at the home makes that home a energy producer. So, with the energy production capability a consumer household becomes a prosumer (i.e., consumer as well as producer). Information and Communication Technology (ICT) and advanced power electronics have led the realization of smart grid. A microgrid (a small sized smart grid that can work in isolation or as a subpart of a large grid) consists of distributed energy resources (like solar photovoltaic cell, small wind turbine, batteries), advanced power electronics devices (like DC/DC converter, DC/AC converter, AC/DC converter), smart meters, microcontrollers, smart electrical appliances, and communication technology enablers (protocols, devices). All these constituent members of microgrid play important role in energy sharing. This article addresses the energy sharing issues among the users of a microgrid.

The electrical grid works on the principle of the balance of supply and demand of the electrical energy. When the supply and demand are not equal, it affects the voltage and frequency, which can cause the power outage, malfunction, and damage of the electrical equipment.

The variability of the renewable energy resources into the grid may cause a sharp increase or drop in the power supply. The storage is required to handle the said gap, instantaneously. The major portion of stored energy (approximately 95%) [1] is in the form of pumped hydro storage. This kind of storage is good to inject a surge of power into the grid to balance the peak electricity demand. But, for the momentary fluctuations, the smart grid requires energy storage having a fast response time. The battery energy storage system for the smart grid is more suited. Battery energy storage can store the surge of energy from the renewable energy resources. It also can inject energy into the grid in the case of a spike in demand. The battery storage system is suitable for the instant smoothing of the fluctuations [1]. The utility of the battery energy storage system has been studied [2, 3] in terms of the saving of energy from distributed energy generation. The study [2] listed out the benefits of the battery storage system, such as the decoupling of the time of generation and consumption of the electric energy (e.g., time-shifting and peak shaving), integration of renewable energy generation, telecommunications back-up power, voltage control, grid fluctuation suppression, and distribution stabilization.

As it has been discussed that the battery storage system plays several roles in the smart grid. This work focuses on the battery storage system management for the end-users using the concept of virtual energy storage. The concept of virtual energy storage [4, 5], analogous to the sharing computing resources in a virtualized fashion, is the virtualization of the central physical battery storage. The meaning of the virtualization of the central physical battery storage is the logical separation of the storage capacity into many virtual storage capacities. These virtual storage capacities are allocated to end-users. Each end-user feels that he/she has his/her own battery. The research work in this article proposes a new idea, which virtualizes the physically distant (distributed battery energy storage) rather than central physical battery storage. The proposed idea is analogous to distributed shared memory in the distributed computing system, which provides virtual address space for all the shared nodes [6]. The contributions of this research work are as follows:

(i) The novel idea of the virtual shared distributed energy storage for cyber-physical energy sharing. To the best of our knowledge, this research work is the first of its kind, which virtualizes the physically distant battery energy storage. We have named this concept as ‘Softmicrogrid’.

(ii) An algorithm is proposed to store energy from the electrical grid based on the day-ahead real-time pricing. This energy is stored on the basis of the predicted energy generation, energy consumption, and time.

Related Work

This work is pertaining to the microgrid. Energy trading among prosumers is a hot topic. Energy sharing at the prosumers levels (where the number of prosumers is large and the amount of energy exchange is very small) is discussed in this research. Energy sharing among multiple prosumers in a microgrid is studied in [8, 9] using auction bidding among the sellers; and is studied in [10,11,12] using auction bidding among the sellers and buyers. The auction bidding method is not good for the domestic prosumers because it is a very cumbersome process. Prosumers are not going to bid, decide the prices, and change their energy usage pattern every hour. For the small quantity of energy sharing among the prosumers, the strategies are studied in [13,14,15,16,17,18,19]. The approaches for the sharing of energy are compared in Table 1. The “ ” indicates that the corresponding attribute is present. The “ ” indicates that corresponding attribute is not present. The “ ” indicate the solution strategy can work with/without the corresponding attribute. The schemes in the first three rows have the issues of frequent energy injection to the grid and economical inefficiency. These two problems are addressed in the scheme provided in the fourth row using physical central storage and internal pricing mechanism using Stackelberg game. The scheme given in fifth and sixth rows also proposed solution based on penalty mechanism and internal price co-decided by the prosumers. Seventh row proposed a scheme based on energy generation and consumption information of prosumers. But the concept of physical central battery storage has another problem of efficiency and thereby energy loss when it is charging and discharging to store surplus energy and fulfill excess demand of the prosumers. This research proposes a novel approach of sharing energy among the prosumers based on software program to solve the above issues. This research article removes physical central storage and use the concept of virtual shared distributed energy storage which gives the impression of a central storage but in reality the storages are physically distributed.

Table 1 Comparison of solution strategies for small scale energy sharing among prosumers

The work in [5] and [7] deserve a detailed explanation and comparison of the concepts because the proposed idea is closely related. We have considered four bases, namely, (i) concept, (ii) computation requirement, (iii) cost of investment for the battery energy storage, and (iv) benefit, on which the work is compared.

On the Basis of Concept

In the work of [5], it is virtualizing the central physical energy storage into multiple small virtual storages. In the work of [7], it is also virtualizing the central physical energy storage into multiple small virtual storages. It virtualizes the storage services into fine-grained resources, namely, (i) charging power (kW), (ii) discharging power (kW), (iii) capacity (kWh), and (iv) energy (kWh). In the proposed work, we are virtualizing the physical battery energy storages which are physically distant i.e., distributed or located at different locations, into one large virtual storage which is managed centrally. The basic difference from the work in [5] and [7] is that the one central physical storage is divided into multiple small virtual storages while, in the proposed work, the multiple physically distributed storages are virtualized into one large virtual storage.

On the Basis of Computation Requirements

The work, in [5], is formulated as a two-stage problem. In stage 1, it determines the price of the virtual storage. In stage 2, for the given unit price of the virtual storage, each end-user decides the optimal capacity to purchase. This problem is solved through backward induction. Firstly, stage 2 is solved to get the end-users optimal solution under a fixed price. Secondly, stage 1 is solved by incorporating the end-users decision into stage 1. The stage 1 problem is formulated as a linear programming problem. The stage 2 problem is formulated as a quadratic programming problem.

The work, in [7], is formulated as the NP-hard problem using auction strategy. A fully polynomial-time approximation scheme is developed to decide the pricing of the auction. This formulation is also similar to work in [5] in terms of computation. The energy storage operator acts as auctioneer. The end-users bids for the storage resource. The end-users bid the price, keeping in mind that they have to optimize their utility. So, end-users do computation like the work in [5], and after that, send the bid to the energy storage operator, i.e., auctioneer. The auctioneer does computation and decides the price. The work in [7] also proposes a distributed algorithm to solve the price. It offloads the computation to the end-users through the communication network. Offloading the computations to the end-users requires advanced software functionality. Therefore, by distributing the computation, it reduces the centralized computation requirement, but on the other hand, it increases the overhead on the end-users. So, the overall computation requirement is similar to the work in [5].

In the proposed work, the Stackelberg game is used for pricing, and it is similar to the two-stage problem. The end-users first decide their requirement on the basis of their utility maximization under the given price. After this, energy sharing computer program computes the price using the data provided by the end-users. So, the proposed strategy also requires similar computation as the work in [5].

On the Basis of the Cost of Investment for Battery Energy Storage

The cost for battery storage in the work [5] and [7] would be the same because both are the centralized management. In the proposed work, it seems there would be more costly, but it would be similar to the centralized management because all the physically distributed batteries are managed centrally. The cost would be more only, as given in the [5], if the batteries are installed in a distributed manner and are managed by the end-user itself.

On the Basis of Benefit

The work in [5] gets the benefit of the central management, e.g., the complementarity of the different end-users charge and discharge requirement. The work in [7] also gets the same benefit as in the work [5]. The proposed work gets the benefits of both, first, the central management, e.g., the complementarity of different end-users’ charge and discharge, and second, distributed energy storages, e.g., reduces distribution energy loss.

Softmicrogrid: Cyber-Physical Energy Sharing Program

A prosumer has an energy generation unit (e.g., photovoltaic cells), an energy storage, and a smart meter. It is assumed that the energy infrastructure has the capability of communication (advanced metering infrastructure). The idea is to construct a Virtual Shared Distributed Energy Storage (VSDES) which is constituted from the energy storage of the spread out prosumers across the microgrid. VSDES acts as a public central energy storage. There is not any physical central energy storage in the cyber-physical energy sharing structure. Figure 1a illustrates a scenario of cyber-physical energy sharing structure. Energy Sharing Program (ESP) constructs the VSDES and takes care of the internal pricing and the charging/discharging activity of the VSDES. ESP broadcasts the internal prices to the prosumers and sends control signal for charging and discharging to the prosumers. It is assumed that every prosumer is the member of VSDES. The partial capacity of the battery is taken from the prosumers to constitute the VSDES. The battery of a home is logically divided in two parts (i) prosumer’s portion (named private portion), and (ii) VSDES’s portion (named public portion). As shown in the Fig. 1a, the VSDES is constituted by the public portion of storage of prosumers p1, p2, p3, and p4. What are the benefits of VSDES compared to a central physical energy storage? To understand the benefits, let us take a scenario as in the Fig. 1b.

Fig. 1
figure 1

Cyber-physical energy sharing structure. a Energy sharing structure. b An example to show the benefit of VSDES

Suppose homes p2, p4, and p7 require i2, i4, and i7 current for time t. These electric current are fulfilled by the physical central battery as shown in Fig. 1b. The resistance of the wire segments are shown in Fig. 1b. The segment AB has R1 resistance, segment BC has R2 resistance, segment BD has R3 resistance, etc. Here, the segment AB and BC are equal; R1 and R2 are also equal. According to Joule’s equation, electrical heating energy loss would be

$$ \begin{array}{@{}rcl@{}} H_{1} &=& (i_{2}+i_{4})^{2}R_{2}t + (i_{2}+i_{4})^{2}R_{3}t + (i_{2}+i_{4})^{2}R_{4}t \\ &&+ (i_{4})^{2}R_{5}t + (i_{7})^{2}(R_{6}+R_{7}+R_{8})t \end{array} $$
(1)

Suppose, instead of the physical central energy storage, a virtual central energy storage which is constituted by the concept of the virtual shared distributed energy storage is used. For example, public portion of battery of prosumer p1, public portion of battery of prosumer p3, and public portion of battery of prosumer p5 constitute a VSDES. Electric current requirements of the homes p2, p4, and p7 are fulfilled by the VSDES (i.e., p1 provides i2, p3 provides i4, and p5 provides i7). Then the electrical heating energy loss would be

$$ H_{2} = (i_{2})^{2}(R_{1}+R_{3})t + (i_{2}+i_{4})^{2}R_{4}t + (i_{4})^{2}R_{5}t + (i_{7})^{2}R_{8}t $$
(2)

Subtract (2) from Eq. 1

$$ \begin{array}{@{}rcl@{}} H_{1} - H_{2} &=& (i_{4})^{2}R_{2}t + 2i_{2}i_{4}R_{2}t + (i_{4})^{2}R_{3}t \\ &&+ 2i_{2}i{4}R_{3}t + (i_{7})^{2}(R_{6}+R_{7})t \end{array} $$
(3)

If we compare H1 and H2, H1 is greater than H2. It shows that reduction in loss of energy by VSDES. This illustration uses simple distribution topology to show the advantage of reduction in loss of energy by VSDES. In reality, the energy distribution topology can be very complex but VSDES will provide its benefit of reduction of loss of energy. Assume that i2 = 5 amp, i4 = 10 amp, i7 = 12 amp, R1 = 10 ohm, R2 = 10 ohm, R3 = 6 ohm, R4 = 8 ohm, R5 = 7 ohm, R6 = 12 ohm, R7 = 5 ohm, R8 = 9 ohm, R9 = 11 ohm, and t = 1 hour (i.e., 3600 seconds). Value of H1 and H2 would be 35438400 Joule and 15105600 Joule.

$$ \begin{array}{@{}rcl@{}} H_{1} &=& (5+ 10)^{2}\times10\times3600 + (5+ 10)^{2}\times6\times3600 \\ &&+ (5+ 10)^{2}\times8\times3600 + (10)^{2}\times7\times3600 \\ &&+ (12)^{2}\times(12+5+9)\times3600 \end{array} $$
(4)
$$ \begin{array}{@{}rcl@{}} H_{2} &=& (5)^{2}\times(10+6)\times3600 + (5+ 10)^{2}\times8\times3600 \\ &&+ (10)^{2}\times7\times3600 + (12)^{2}\times9\times3600 \end{array} $$
(5)

We can observe that the difference between H1 and H2 is 20332800 Joule. ((H1H2) × 100)/H1 = 57.375 i.e., H1 is 57.375% more than H2. It shows that VSDES has a huge impact on reduction in loss of energy. The technical loss of the energy is due to the resistance in the wire, the magnetization of energy, iron and copper loss in equipments. There is also energy loss in charging and discharging of the battery, i.e., electrical to chemical energy conversion loss and chemical to electrical energy conversion loss. Here, in the example, we are not considering all other losses except only the resistive loss is considered to understand the concept. Along with this, other benefits of VSDES are as follows: (i) suppose a prosumer wants to sell energy which is stored in his/her private battery portion (prosumer’s battery is logically divided into two parts one for prosumer (i.e., private) and another for VSDES (i.e., public)) and public battery portion of VSDES is empty or have space to store energy then prosumer sells energy without any loss (i.e., zero loss), here only the logical transfer of energy rather than physical transfer, (ii) the maximum charging/discharging rate bottleneck of a central physical storage is also addressed. We illustrate it with an example. Suppose there is a central physical storage which has 3kW charging and discharging rate. VSDES is made of six prosumer’s storage which has 2kW charging and discharging rate. So, VSDES maximum charging and discharging rate would be 12kW. In this way, VSDES helps to reduce the charging/discharging rate bottleneck of the central physical storage.

As shown in Fig. 1a, energy sharing program (i.e., a computer program) which manages the energy sharing, has three components, as depicted in Fig. 2. The prosumers’ location and identity component contains the information about the physical location and identity of the prosumer. The day-ahead VSDES charging and discharging component implements the VSDES concept and implements the charging and discharging mechanism. The internal day-ahead real-time pricing component implements the mechanism for calculating the internal day-ahead real-time price using grid day-ahead real-time price. The concepts to implement energy sharing program is discussed in detail throughout in this article. The implementation of these concepts is hosted at github.com. One can access the implementation at GitHub Repository (https://github.com/BrijendraMNNIT/EnhancedFNCSApplicationPatch).

Fig. 2
figure 2

Energy Sharing Program (Softmicrogrid)

Cyber-Physical Energy Sharing System Model

To implement VSDES, ESP has arrays to contain the information of public portion of battery storage of each prosumer, available amount of energy of public portion of battery storage of each prosumer, and physical location of each prosumer. ESP sends control signals to the VSDES batteries for charging and discharging. ESP updates the the available amount of energy of public portion of each battery by their usage time and charging and discharging rate. Another way is also to update this information if the battery sends its charging and discharging energy amount to the ESP. A day is divided into 24 slots of one hour each. \({\lambda _{s}^{h}}\) is the price in time slot h at which a prosumer can sell energy to the ESP (i.e., ESP buys energy from the prosumer at \({\lambda _{s}^{h}}\) price in time slot h), \({\lambda _{b}^{h}}\) is the price in time slot h at which prosumer can buy energy from the ESP (i.e., ESP sells energy to the prosumers at \({\lambda _{b}^{h}}\) price in time slot h), \(\lambda _{gs}^{h}\) is the price in time slot h at which ESP sells energy to the electrical grid (i.e., electrical grid buys energy at the price \(\lambda _{gs}^{h}\) in time slot h), and \(\lambda _{gb}^{h}\) is the price in time slot h at which ESP buys energy from the electrical grid (i.e., electrical grid sells energy to ESP at the price \(\lambda _{gb}^{h}\) in time slot h). λmin is the minimum price at which ESP can sell energy to the grid or prosumer in a day. λmax is maximum price at which ESP bought energy to save in the VSDES. λmin is the minimum of \(\lambda _{gs}^{h}\) in a day (i.e., minimum of \(\{\lambda _{gs}^{1}, ..., \lambda _{gs}^{h}, ..., \lambda _{gs}^{24}\}\)). λmax is the maximum of \(\lambda _{gb}^{h}\) in a day. One important constraint which should be satisfied in every time slot is given in Eq. 6. This equation says that internal prices should be within the electrical grid prices.

$$ \lambda_{gs}^{h} \leq {\lambda_{s}^{h}} < {\lambda_{b}^{h}} \leq \lambda_{gb}^{h} $$
(6)

Utility Model of a Prosumer

Let P be a set of N prosumers i.e., P = {p1,...,pi,...,pN}. pi denotes a unique identity of the ith prosumer. Every prosumer pi has its physical location (lxi,lyi). Each prosumer pi generates energy \(E_{p_{i}}^{h}\) and consumes \(x_{p_{i}}^{h}\) in time slot h. Private portion of the battery of a prosumer is assumed a variable load/energy source of the prosumer and its load/supply is included in \(x_{p_{i}}^{h}\) and \(E_{p_{i}}^{h}\). The utility model of a prosumer is given as

$$ U_{p_{i}}^{h} = \begin{cases} k_{p_{i}}^{h}ln(1+x_{p_{i}}^{h}) + {\lambda_{s}^{h}}(E_{p_{i}}^{h} - x_{p_{i}}^{h}) - b|c_{p_{i}}^{h}|, & \text{if} E_{p_{i}}^{h} > x_{p_{i}}^{h}\\ k_{p_{i}}^{h}ln(1+x_{p_{i}}^{h}) + {\lambda_{b}^{h}}(E_{p_{i}}^{h} - x_{p_{i}}^{h}) - b|c_{p_{i}}^{h}|, & \text{if} E_{p_{i}}^{h} \leq x_{p_{i}}^{h} \end{cases} $$
(7)

where b is battery life loss cost, \(c_{p_{i}}^{h}\) is the amount of energy exchange in time slot h from the private portion of the battery. \(k_{p_{i}}^{h}ln(1+x_{p_{i}}^{h})\) is the utility achieved by consuming \(x_{p_{i}}^{h}\) amount of energy and \(k_{p_{i}}^{h}\) is a preference parameter [16, 17, 19]. The natural logarithm function has been used for modeling utility of a power consumer [20]. For given internal prices \({\lambda _{s}^{h}}\) and \({\lambda _{b}^{h}}\), the Eq. 7 is a concave function with some constraints, explained in Appendix.

Utility Model of ESP

All the prosumers are divided in two groups, (i) buyer and (ii) seller. Assume that PB be the set of buyer prosumers and PS be the set of seller prosumers. Therefore, P = PBPS. Let \({E_{b}^{h}}= {\sum }_{p_{i} \in PS} (E_{p_{i}}^{h} - x_{p_{i}}^{h})\) if \(E_{p_{i}}^{h} - x_{p_{i}}^{h} > 0\) and \({E_{s}^{h}}= {\sum }_{p_{i} \in PB} (x_{p_{i}}^{h} - E_{p_{i}}^{h})\) if \(E_{p_{i}}^{h} - x_{p_{i}}^{h} \leq 0\)

$$ \begin{aligned} U_{ESP}^{h} = \begin{cases} {\lambda_{b}^{h}}{E_{s}^{h}} - {\lambda_{s}^{h}}{E_{b}^{h}} + \\ \lambda_{gs}^{h}({E_{b}^{h}} - {E_{s}^{h}} - d_{pp}^{h} - d_{pl}^{h}) \\ - b|d_{pp}^{h}| + \lambda_{min}|d_{pp}^{h} + d_{pl}^{h}|, & \text{if}~ E_{b}^{h} - {E_{s}^{h}} > 0 \\ {\lambda_{b}^{h}}{E_{s}^{h}} - {\lambda_{s}^{h}}{E_{b}^{h}} + \\ \lambda_{gb}^{h}({E_{b}^{h}} - {E_{s}^{h}} + d^{h}) \\ - b|d^{h}| - \lambda_{max}|d^{h}|, & \text{if} E_{b}^{h} + d^{h} - {E_{s}^{h}} \leq 0 \end{cases} \end{aligned} $$
(8)

where \(d_{pp}^{h}\) is physical movement of energy in the VSDES from prosumers, \(d_{pl}^{h}\) is logical movement of energy from prosumers to VSDES, (\(d_{pp}^{h} + d_{pl}^{h} \)) is the amount of energy which is stored in the VSDES by the ESP, and dh is energy supplied by the VSDES to the prosumers in the hth time slot. Suppose a prosumer is selling its energy to the ESP, which is stored in the private portion of his/her battery. If the ESP stores that energy into the public portion of the same physical battery of the prosumer, this means that there is not any physical movement of the energy from one place to another place; we have named it as the logical movement of energy. If the ESP stores that energy into some other prosumers’ battery public portion, it means the energy has to flow from one place to another place; we named it as the physical movement of energy. ESP is a non-physical entity. That means, there is no third identity between electrical grid and prosumers who makes profit. So, the profit by sharing energy is distributed among the prosumers.

Charging/Discharging of Virtual Shared Distributed Energy Storage and Internal Pricing

This section explains charging and discharging policy for VSDES and mechanism to decide internal pricing (i.e., \({\lambda _{s}^{h}}\), \({\lambda _{b}^{h}}\)).

Day-ahead Charging Schedule of VSDES to Store Energy from the Electrical Grid

In the day-ahead charging schedule algorithm, we are only finding out the time slots and amount of energy which is going to be stored in the VSDES. Here, we assume that there is enough storage capacity is available, and there is not any bottleneck of the charging and discharging rate.

figure e

If the energy produced by all the prosumers is not sufficient, then the VSDES stores energy from electrical grid when the price is low based on the expected generation and consumption information of the prosumers. An assumption is that the electricity grid announces day-ahead real-time pricing for buying and selling energy by ESP from the electrical grid (i.e., \(\lambda _{gb}^{h}\) and \(\lambda _{gs}^{h}\)). Every prosumer sends day-ahead expected energy generation and consumption to the ESP. Therefore, ESP has information about approximate power generation and consumption of each time slot. Let energy production in each time slot is < ee1,...,eeh,...,ee24 > by all the prosumers and required energy is < er1,...,erh,...,er24 > by all the prosumers. eeh is the energy generation by all the prosumers in hth time slot. erh is the energy consumption by all the prosumers in hth time slot. It is the day-ahead predicted values by all the prosumers. The prediction will have some error (i.e., either some more energy or less energy). If the error has the mean μ and variance σ2 then the total error by prosumers is normally distributed (Gaussian distribution) with mean Nμ and variance Nσ2 (by Central Limit Theorem). So, the energy production would be < ee1 + X1,...,eeh + Xh,...,ee24 + X24 >, where Xh is a random variable which is normally distributed with mean Nμ1 and variance \(N{\sigma _{1}^{2}}\). Similarly, energy consumption would be < er1 + Y1,...,erh + Yh,...,er24 + Y24 >, where Yh is a random variable which is normally distributed with mean Nμ2 and variance \(N{\sigma _{2}^{2}}\). Cumulative energy production and cumulative energy requirement are < ee1 + X1,ee1 + ee2 + X1 + X2,...,ee1 + ... + ee24 + X1 + ... + X24 > and < er1 + Y1,er1 + er2 + Y1 + Y2,...,er1 + ... + er24 + Y1 + ... + Y24 >. Let the cumulative energy production and requirement are denoted as < EE1,EE2,...,EE24 > and < ER1,ER2,...,ER24 >, respectively. Algorithm 1 gives the day-ahead charging schedule for the VSDES. The ESP stores energy in the VSDES using this schedule from the electrical grid. Algorithm 1 gives the tuple < (bc0,cs0),(bc1,cs1),...,(bc23,cs23) >. bci contains the amount of energy which would be purchased from grid and csi is the corresponding time slot in which energy is purchased. Sort this tuple according to charging slot (cs). So, this tuple will give the charging slot (which has the lowest price) and amount of energy which needs to be stored in the VSDES. The idea of day-ahead charging schedule of VSDES is based on the known information of generation and consumption in each time slot. If we know how much energy is going to be a shortage in which slot, we can charge the VSDES with that amount of energy with the lowest price available before that slot. While in [16], the charging schedule is based on two threshold values regardless of the generation or consumption information.

VSDES Charging and Discharging Mechanism for Surplus Energy Generated/Demanded by Prosumers

If the total produced energy by all the prosumers is greater than the total consumption by all the prosumers at any instant of time then that surplus energy will be stored in the VSDES or to be sold to the electrical grid directly. Here, ESP sells energy to the grid only when VSDES is full (to reduce the penetration to the electrical grid). Every prosumer pi has a coordinate (lxi,lyi). By this coordinate, ESP knows the location of every prosumer. Suppose, if prosumer pi has surplus energy (i.e., \(E_{p_{i}}^{h} > x_{p_{i}}^{h}\)) then it will sell energy to the ESP. ESP will store this energy in the VSDES if \({E_{b}^{h}} > {E_{s}^{h}}\). The question is that which public storage in VSDES would be chosen to store energy. To select the public storage, the idea is based on the distance between the energy supplier prosumer and the public storage prosumer. To find out the distances, ESP has an N × N distance matrix.

$$ \begin{bmatrix} d_{11}&d_{12}&{\cdots} &d_{1N} \\ d_{21}&d_{22}&{\cdots} &d_{2N} \\ {\vdots} & {\vdots} & {\ddots} & \vdots\\ d_{N1}&a_{N2}&{\cdots} &d_{NN} \end{bmatrix} $$

where dij is the distance between the prosumer pi and pj. The value dij = 0, if i = j. Distance between the prosumer pi and pj is calculated by \(d_{ij} = \sqrt {(ly_{j} - ly_{i})^{2} + (lx_{j} - lx_{i})^{2}}\). If prosumer pi wants to sell energy to the ESP, then ESP stores this energy in the public storage at the prosumer pj which is nearest to the prosumer pi. If the battery (i.e., the public storage) at the nearest prosumer is full, then ESP assigns next nearest prosumer. Similarly, if prosumer pi needs some energy and if it is fulfilled by VSDES then the ESP chooses the nearest pj to supply energy.

One can think that charging VSDES from electrical grid causes more energy loss than central physical storage due to more travel distance of the electric current. In the case of the VSDES, energy loss is high during charging than the central physical storage but discharging loss is low due to consumption units are nearby to the VSDES. In the case of central physical storage, charging loss is less but discharging loss is high. Here, we consider that in both cases (central physical storage and VSDES), loss of the energy is the same in respect of energy from the electrical grid. VSDES provides benefits of energy loss reduction for the case of charging/discharging from/to the prosumer’s local energy supply and consumption.

Internal Pricing Based on Stackelberg Game

ESP decides the prices \({\lambda _{b}^{h}}\) and \({\lambda _{s}^{h}}\). The prosumers decide their consumption based on the \({\lambda _{b}^{h}}\) and \({\lambda _{s}^{h}}\). The ESP and prosumers rationally maximize their utility profit. ESP works as a leader while prosumers work as followers. So deciding the internal price is a single leader and multiple followers game. ESP gets the advantage of being a leader. ESP knows the utility function of the prosumers; therefore, ESP can find out what would be the energy consumption by prosumers on a particular price. Using this information, ESP decides internal prices such that ESP maximizes its utility profit. For a given price \({\lambda _{b}^{h}}\) and \({\lambda _{s}^{h}}\), it is a simple game among N prosumers in which each prosumer will maximize his/her utility profit. Formally, this game can be written in the strategic form as follows

$$ G= \{(P \cup {ESP}), \{\mathbf{X_{p_{i}}^{h}}\}_{p_{i}\in P}, \{\mathbf{U_{p_{i}}^{h}}\}_{p_{i}\in P}, \{U_{ESP}^{h}\}, \{\mathbf{{{\Lambda}_{b}^{h}}}\}, \{\mathbf{{{\Lambda}_{s}^{h}}}\} \} $$
(9)

where

  1. 1.

    P is the set of prosumers who act as the follower and ESP acts as the leader

  2. 2.

    \(\mathbf {X_{p_{i}}^{h}}\) is the set of strategies for prosumer pi, i.e., the energy consumption in time slot h by prosumer pi (i.e., \( x_{p_{i}}^{h} \in \mathbf {X_{p_{i}}^{h}}\))

  3. 3.

    \(\mathbf {U_{p_{i}}^{h}}\) is utility function of prosumer pi (given in Eq. 7) by which prosumer calculates its utility profit on the consumption of energy \( x_{p_{i}}^{h}\)

  4. 4.

    \(U_{ESP}^{h}\) is the utility function (given in Eq. 8) of the ESP by which ESP calculates its profit

  5. 5.

    \(\boldsymbol {{{\Lambda }_{b}^{h}}}\) and \(\boldsymbol {{{\Lambda }_{s}^{h}}}\) are strategies set of the ESP which always hold (6).

Solution for game G is the Stackelberg equilibrium. A set of strategies \((\mathbf {X^{h*}},\lambda _{b}^{h*}, \lambda _{s}^{h*})\) constitutes an Stackelberg equilibrium if and only if

$$ \begin{array}{ll} U_{p_{i}}^{h}(x_{p_{i}}^{h*},\lambda_{b}^{h*}, \lambda_{s}^{h*}) \geq U_{p_{i}}^{h}(x_{p_{i}}^{h},\mathbf{X_{-p_{i}}^{h*}} ,\lambda_{b}^{h*}, \lambda_{s}^{h*}), \\ \qquad\qquad\qquad\qquad\quad\forall p_{i} \in P, \forall x_{p_{i}}^{h} \in \mathbf{X_{p_{i}}^{h}} \end{array} $$
(10)
$$ \begin{array}{ll} U_{ESP}^{h}(\mathbf{X^{h*}},\lambda_{b}^{h*}, \lambda_{s}^{h*}) \geq U_{ESP}^{h}(\mathbf{X^{h*}},{\lambda_{b}^{h}}, {\lambda_{s}^{h}}), \\ \qquad\qquad\qquad\qquad\qquad\forall {\lambda_{b}^{h}} \in \mathbf{{{\Lambda}_{b}^{h}}}, \forall {\lambda_{s}^{h}} \in \mathbf{{{\Lambda}_{s}^{h}}} \end{array} $$
(11)

where \( \mathbf {X^{h*}} = [x_{p_{1}}^{h*}, x_{p_{2}}^{h*}, ..., x_{p_{N}}^{h*}]\) and \( \mathbf {X_{-p_{i}}^{h*}} = [x_{p_{1}}^{h*}, ...,\\ x_{p_{i-1}}^{h*},x_{p_{i+1}}^{h*}, ... ,x_{p_{N}}^{h*}] \). At the Stackelberg Equilibrium (SE), prosumer or ESP can not make higher benefits by choosing other strategies. The existence of a unique Stackelberg equilibrium for the proposed model is discussed in Appendix.

How to find the Stackelberg equilibrium for the proposed utility model of prosumers and the ESP. The internal price \({\lambda _{b}^{h}}\) and \({\lambda _{s}^{h}}\) can be solved in centralized manner having objective to maximize the benefit of ESP. To find the SE, the following steps are performed [17] as follows.

  1. 1.

    Each prosumer sends its energy generation information \(E_{p_{i}}^{h}\) and \(k_{p_{i}}^{h}\). \(k_{p_{i}}^{h}\) is calculated by using the electrical grid prices \(\lambda _{gs}^{h}\) and \(\lambda _{gb}^{h}\) as reference price.

  2. 2.

    ESP calculates \({\lambda _{b}^{h}}\) and \({\lambda _{s}^{h}}\) using Eqs. 8 and 6.

  3. 3.

    ESP broadcasts the \({\lambda _{b}^{h}}\) and \({\lambda _{s}^{h}}\) to all the prosumers.

  4. 4.

    Above three steps are repeated for each time slot.

Case Study

For the simulation, we used the GridLAB-D (power distribution system simulator), ns-3 (network simulator), and FNCS (Framework for Network Co-Simulation). We have taken six houses. Photovoltaic cells are used at every house as an energy generator. The VSDES is constituted using battery public portion of the houses. The solar panel size, VSDES size, and schedule skew of each house are given in Table 2.

Table 2 Simulation parameters

Schedule skew is the variation of time when each house uses their appliances. Maximum discharging rate and maximum charging rate are 3kW. Charge lockout time and discharge lockout time are one second. Inverter efficiency is 0.95. Each house consists of HVAC (Heating, Ventilation, and Air Conditioning) system, water heater, light, cloth washer, refrigerator, dryer, freezer, range, and microwave. Each house also has 10kWh battery storage. HVAC system and water heater are controlled by the passive controller which work on the basis of internal real-time price. The data for the devices are taken from [21]. Water heater tank volume size is 50 gallons. We have also taken a three phase load 10 kVA, 50 kVA, and 49 kVA in phase A, B, and C, respectively. The different types of loads, are water heater, HVAC (Heating, Ventilation, and Air Conditioning), lights, clothes washer, refrigerator, dryer, freezer, cooking range, and microwave. Figure 3 shows the topology of the simulation setup. The load profile and PV generation profile is as given in the Figs. 4 and 5. In the simulator to implement VSDES, we use two separate batteries at each house (for example, at the house 4, there is a battery of capacity 20 kWh which is part of the VSDES and there is another battery of capacity 10 kWh which is the part of the prosumer portion). A software-defined battery [22] is implemented in which the charging and discharging operations are controlled by software. In ns-3, all the houses are connected through the Ethernet network. The data rate of the channel is 100Mbps and delay is 6560 nanoseconds. There are two nodes n0 and n1 which are connected through the point to point network. Node n0 is corresponding to the subauction object in the GridLAB-D simulator. The node n1 implements the proposed software-assisted mechanism as an application program which determines the day-ahead charging schedule for the VSDES and determines internal real-time price. This application program sends control signals to the VSDES batteries for charging and discharging. It sends internal real-time price to the subauction object (which acts as a market for the prosumers) of GridLAB-D. VSDES charging and discharging for the surplus generation and excess demand by prosumers are implemented in the application program at the node n1 with some assumptions for the simulation purpose. These assumptions are (i) for the surplus energy generated by a prosumer, the nearest public storage is sufficient to accommodate all those energies (i.e., there is no need of next nearest VSDES battery), (ii) for the excess demand of energy by a prosumer, only the nearest VSDES public storage is considered to provide those energies, if the VSDES public storage is not sufficient, then the energy is taken from the grid rather than the next nearest VSDES public storage. For this case study, each \(k_{p_{i}}^{h}\) [16] is generated as a uniform random variable between range [90,150]. The day-ahead grid real-time price (\(\lambda _{gb}^{h}\)) is taken from New York Independent System Operator (NYISO) for Central New York for date 21 February 2019 to 28 February 2019. And the \(\lambda _{gs}^{h}\) is 50 percent less than the \(\lambda _{gb}^{h}\) [18]. For the case study, six solar panels of size (i) 567.04, (ii) 850.56, (iii) 708.80, (iv) 1134.08, (v) 283.52, and (iv) 425.28 square feet have been considered. The inverter efficiency 0.95 is considered. The inverter is of type four-quadrant and the maximum charging and discharging rate is 3 kW. The charge lockout and discharge lockout time of the battery storage is taken 1 second. The battery efficiency 0.81 is taken. The battery is the Lithium-ion battery. The home floor area is 2100 square feet, the cooling system type is electric, the number of doors is 2, indoor air temperature is 71.9 Fahrenheit, HVAC power factor is 0.97, water heater tank volume is 50 gallons, and lights, clothes washer, refrigerator, dryer, freezer, range, and microwave are ZIP (Impedance (Z), Current (I), and Power (P)) load. The load profiles and PV power generation of each prosumer is shown in Figs. 4 and 5. The adjacent prosumers storage capacity are as follows (i) prosumer 1, 2, 3, 4, 5 and 6 the adjacent storage capacity are (10, 10, 20, 15, 5), (10, 20, 15, 5, 10), (20, 15, 5, 10, 10), (15, 5, 10, 10, 10), (5, 10, 10, 10, 20), and (10, 10, 10, 20, 15) in kWh, respectively [21].

Fig. 3
figure 3

Topology for experiment

Fig. 4
figure 4

Load profile of the prosumers

Fig. 5
figure 5

PV profile of the prosumers. a Home 1 b Home 2 c Home 3 d Home 4 e Home 6 e Home 6

Fig. 6
figure 6

Comparison of central and distributed battery scheme

The system losses are energy loss due to resistance in the wire, the magnetization of energy, iron loss, copper loss, loss in power electronic device (inverter), electrical to chemical energy conversion loss, and chemical to electrical energy conversion loss in the battery. In the simulation study, inverter efficiency has been taken 0.95, and round trip efficiency of the battery has been taken 0.81. From the Fig. 6, we can see that the distributed mechanism is better than the central storage mechanism; it is compared for the total energy of each day for seven days in the simulation study. A comparison has been done to observe the effects of the distributed batteries management and the central battery management. The total energy consumption of each day is compared for seven days in the simulation study. The Fig. 6 shows that the distributed batteries management system can perform better. The grid trading power and load profile of all the prosumer are depicted in the Fig. 7.

Fig. 7
figure 7

Grid trading power and load profile

The ns-3 implements the application programs corresponding to each house. The GridLAB-D implements the electrical grid topology. FNCS cooperates for co-simulation of ns-3 and GridLAB-D. The internal price of day 4 is depicted in Fig. 8a. It shows that the price for hours 7 to 8, 8 to 9, 16 to 17, and 17 to 18 are less than the grid selling price which benefit the prosumers in terms of the electricity bill. The day-ahead charging schedule of VSDES of the day 4 is depicted in Fig. 8b. It shows that the 1st time slot, 4th time slot, and the 7th time slot for charging VSDES with the respective amount of energy. The other simulation days results are depicted in Figs. 9 and 10 and summarized in Table 3.

Fig. 8
figure 8

Internal pricing and charging schedule of 4th day. a Internal pricing day 4 b Charging Schedule day 4

Fig. 9
figure 9

Internal pricing. a Day 1 b Day 2 c Day 3 d Day 5 e Day 6 f Day 7

Fig. 10
figure 10

VSDES charging schedule. a Day 1 b Day 2 c Day 3 d Day 5 d Day 6 e Day 7

Table 3 Simulation results

Analysis of Results

In [16], two thresholds based charging and discharging of central physical battery storage is discussed. In the two thresholds based scheme, two price levels (such as, \(p_{gb}^{min}\) and \(p_{gb}^{max}\)) are decided by the controller. The controller charges the central battery storage if the grid real-time price is less than \(p_{gb}^{min}\) and discharging central battery storage if the grid real-time price is greater than \(p_{gb}^{max}\). In the proposed approach, the charging of VSDES is based on the hourly information of energy generation and the energy consumption of the prosumers. The benefit of the proposed scheme is that it only purchases the required amount of energy from the grid while the two thresholds based scheme does not care about the energy requirement but only care about the price. In [19], the charging schedule scheme utilizes the information of prosumers’ energy generation, consumption, and real-time price of the grid. They discussed the scheme based on the minimization of an objective function which is based on two price weight coefficients (i) ratio of current real-time price of that slot and maximum selling price of the day and (ii) ratio of minimum buying price of the day and current real-time price of that slot for each time slot. In the proposed approach, we consider the current time slot energy difference and all the preceding time slots to find the lowest price. The basis is to calculate how much energy is going to be a shortage in which time slot as explained in the Algorithm 1. So, before that time slot, we charge VSDES with that amount of energy with the lowest price available till that slot. Figure 11a depicts the comparison of the cost between the proposed day-ahead charging schedule, threshold based day-ahead charging schedule, and price-based coefficient scheme. We can clearly observe that there is a huge difference in cost. In Figs. 9e and 10e, we can see that in the 1st time slot the price is very low that is intentionally modified from the NYISO price to test the effectiveness of the proposed charging algorithm. In Fig. 11a, we can observe that at the 6th day cost is very low that means the proposed algorithm is highly sensitive to the price (while the scheme proposed in [19] is not) and provides economic benefits to the prosumers. The charging threshold is taken as (maximum grid selling price of the day - minimum grid selling price of the day)×0.25 + minimum grid selling price of the day [16] i.e., one fourth of the range of minimum to maximum price. Figure 11b shows that threshold based scheme stores huge unnecessary energy from the grid which is not required.

Fig. 11
figure 11

Comparison of charging cost and amount of energy. a VSDES Charging Cost Comparison for Seven Days b VSDES Charging Energy Comparison for Seven Days

The virtual shared distributed energy storage depends on the photovoltaic (PV) power generation. In the day-ahead charging scheme of the VSDES, we have used the predicted power generation of the PV cells of the prosumers. If the PV power generation varies from the predicted value, then the day-ahead charging schedule will not get the benefit of low pricing electricity slots from the real-time pricing scheme. In the situation when the power is not enough collectively by both the PV power and stored power in the VSDES, the power is directly taken from the grid on a real-time price basis, and it would be costly for the prosumers.

The cost-benefit analysis of the central battery storage system and the distributed batteries storage system answers the following three cases: (i) central battery storage management, (ii) distributed battery storage, installed at each prosumer’s site and managed by the individual prosumer itself, and (iii) distributed battery storage, installed at the prosumer site but managed centrally.

The investment cost for the case (ii) would be greater [5] than the investment cost for the case (i). The central battery storage investment cost is lesser than when each prosumer invests individually because, if each prosumer manages its battery resource, he/she does not know the information of generation and demand for all the prosumer collectively, and battery resources are underutilized. So, it is better to own central storage by a third party than the owning battery storage by each prosumer. In the case (iii), we are utilizing the benefit of central battery management that is knowing information about the storage requirement of each prosumer and takes the benefits of complementarity of the different prosumers’ charge and discharge requirements through the software. In the case (iii), the cost would be similar to the central battery management even though the batteries are physically distributed because these are managed centrally using the ICT.

Conclusion

This research work discussed energy management using battery storage. The battery energy storage is suitable for balancing the variability of the renewable energy resources. The battery energy storage has a fast response time to handle the momentary fluctuations. This fast response time makes it suitable for the smart grid. The key contributions of this research work are (i) a cyber-physical energy sharing structure introducing a novel idea of the virtual shared distributed energy storage; this idea utilizes the well-known fact that energy resources nearby the consumption unit reduces the energy loss; in the VSDES, the storages are physically distant and placed at the prosumers’ house and managed centrally through software, (ii) a day-ahead charging scheduling algorithm; this proposed algorithm utilizes the predicted generation, consumption, and the consumption time of the energy to take advantage of the real-time pricing information of the grid. This work showed that the proposed strategy performs better than the threshold-based strategy and the price weight coefficient based strategy.