Real-Time Control of Power Exchange at Primary Substations: An OPF-Based Solution

Nowadays, integration of more renewable energy resources into distribution systems to inject more clean energy introduces new challenges to power system planning and operation. The intermittent behaviour of variable renewbale resources such as wind and PV generation would make the energy balancing more difficult, as current forecasting tools and existing storage units are insufficient. Transmission system operators may withstand some level of power imbalance, but fluctuations and noise of profiles are undesired. This requires local management performed or encouraged by distribution system operators. They could try to involve aggregators to exploit flexibility of loads through demand response schemes. In this paper, we present an optimal power flow-based algorithm written in Python which reads flexibility of different loads offered by the aggregators from one side, and the power flow deviation with respect to the scheduled profile at transmission-distribution coupling point from the other side, to define where and how much load to adjust. To demonstrate the applicability of this core, we set-up a realtime simulation-based test bed and realised the performance of this approach in a real-like environment using real data of a network.

Abstract-Nowadays, integration of more renewable energy resources into distribution systems to inject more clean energy introduces new challenges to power system planning and operation. The intermittent behaviour of variable renewbale resources such as wind and PV generation would make the energy balancing more difficult, as current forecasting tools and existing storage units are insufficient. Transmission system operators may withstand some level of power imbalance, but fluctuations and noise of profiles are undesired. This requires local management performed or encouraged by distribution system operators. They could try to involve aggregators to exploit flexibility of loads through demand response schemes. In this paper, we present an optimal power flow-based algorithm written in Python which reads flexibility of different loads offered by the aggregators from one side, and the power flow deviation with respect to the scheduled profile at transmission-distribution coupling point from the other side, to define where and how much load to adjust. To demonstrate the applicability of this core, we set-up a realtime simulation-based test bed and realised the performance of this approach in a real-like environment using real data of a network.
Index Terms-Power flow, real-time simulation, aggregator, demand response, Internet of things

I. INTRODUCTION
The growing penetration of renewable energy sources into distribution systems is creating a lot of new challenges for power system operators. The structure of power system is not anymore following a vertically integrated scheme, in which power is produced in large distant power plants and transmitted to consumption areas through transmission lines. In modern power systems a lot of small scale producers are integrated into distribution systems. In other words the system faces a transition from a centralised to distributed scheme. This transition needs to be planned with the specific tools that are able to estimate production of renewable energy sources in time, exploit flexibility of demand, asses the capabilities and requirements of distribution networks, and estimate the impact on energy markets [1], [2].
Distributed Energy is the utilisation of smaller power generation and storage systems used to power homes, businesses and communities. Most distributed energy generation systems take advantage of renewable energy sources such as solar and wind. In this new scheme, efficiency, flexibility, reliability and cost savings become fundamental keywords and a new architecture that manages this system is necessary. The Smart Grid is a reinvention of how energy is transmitted, distributed, and measured. It is becoming the new standard for utilities and consumers and represents the merging of multiple technologies into a system which provides reliable and cost-effective energy.
In smart grids, there are a lot of new actors like prosumers and aggregators ( Figure 1). Besides economic motivations of introducing these new actors, there are technical demands for involving such players in system control and management. Power balance in smart grids cannot be satisfied without accurate estimation of power production by renewable energy sources (RES) and proper exploitation of demand flexibility [3]. Distribution system management (DSM) constantly monitors the network using SCADA to manage RES and provide ancillary services where needed [4].
A problem with regard to power balancing in modern grids is caused by intermittent behaviour of RES from one side and volatility of power demand from residential loads. Transmission system operator expects to see a power demand from distribution system with minimum deviation from the scheduled profile. It could forecast the net demand power, which is the total power deficit in distribution grid considering local demand and distributed generation. But this forecasting results in an scheduled power profile which may be different in practice from the real-time demand. The real-time demand could be deviated from the scheduled one due to intermittent RES and also new loads like electric vehicles in distribution networks.
Reviewing literature, there are a wide range of solutions to take power balance challenges in distribution systems. In some works, like [5], [6], [7], DSO uses storage units to inject or absorb power in response to variations. However, installation and operation of storage units are quite costly for grid operators. In many cases, accurate load forecasting methods are proposed to capture the dynamic behaviour of demand in realtime and tune the prosumers accordingly [8], [9], [10], [11]. The new challenge in these cases is the controllability of RES. In most cases, no better options than curtailment could be found [12], [13], [14]. In some cases, the load is shifted or the peak is shaved by load shedding [15], [16], [17]. These measures would reduce customer comfort, and result in extra costs due to violation of customer contracts.
As more advanced solutions, demand side management is proposed to support accommodation of more RES in distribution networks [18], [19], [20]. Different Demand Response (DR) methods are in place to provide flexibility. However, before sending demand response signals to individual loads, the amount of change should be defined as well as the location of required adjustments. This is challenging when fluctuations of the demand curve is high due to volatility of loads, specially residential ones, and the unpredictable variation of RES power injection.
A solution to this problem is firstly to encourage loads to be flexible enough for filtering the noises. Aggregators are great sources to control loads and develop demand response schemes. However, aggregators should know where to change the loads, if that is possible. Moreover, aggregators should know how much power is required to be shed or shifted. A tool in DMS should run some algorithms, and outputs such information. This tool should run an optimal power flow to minimise the cost while meeting the grid constraints including the scheduled power introduced earlier in problem description. The focus of the work presented in this paper is on developing such a tool that estimates the deviation of the net power at the point of connection between distribution and transmission systems, and provides signals to aggregators with the information of where and how much power to change in loads. An algorithm is developed which optimally exploits the flexibility offered by the aggregators to ensure the power exchange of the main substation following the schedule trajectory. A realistic energy distribution network is modelled in MATLAB Simulink and run in a digital realtime simulator (RTS), OPAL-RT, to reproduce the behaviour of the real system. A distributed co-simulation framework is also designed to integrate the algorithm, which is supposed to be embedded in DMS, the agent-based aggregator, and the digital real-time simulator, which represents the real grid.
In this paper, we firstly introduce our high-level architecture of energy management system of DSO, including the optimal operation decision (OOD), the grid or representative of the grid which is a real-time simulation platform, forecast tools, and aggregators. This architecture is briefly proposed in Section II. In Section III a laboratory set-up to demonstrate the applicability of our proposed scheme is detailed. Section IV presents some results of the experiment on a realistic network, and Section V concludes this work with some remarks. II. HIGH LEVEL SCHEMA Figure 2 represents the high level architecture of the proposed scheme of ours to efficiently implement demand response algorithms. Most of algorithms are run in aggregators where data of loads including their coordinates, contractual power, details of devices, information of smart meters, etc. may exist. Therefore, flexibility of prosumers can be defined by the aggregators (bottom-left of the scheme). The data includes information about which node of the network has dispatchable loads, and how much demand at that node can be increased or decreased.
On top of "Flexibility of prosumer by aggregator", there are modules providing data of loads and generation. The "load power" data is based on either previously forecast values or real-time measurements from smart meters. The generated power, for instance PV panel production, data can be also estimated by using PV simulators. From these 3 sets of information, the core code needs current operational data, which means the data at the time the imbalance power is calculated. The imbalance power, or power difference, along with those 3 sets of data are fed into an Optimal power flow algorithm (OPF).
The OPF fixes the amount of power exchange at the point of connection (PoC) between distribution and transmission grids. This amount must be set as the scheduled or forecast consumption, unless the difference is bellow a threshold (e.g. 10 percent). The difference is calculated by retrieving power measurement ("real-time active power") at PoC and deducting it from forecast consumption ("forecast active power") which is the scheduled demand at PoC.
In the OPF, parasitic generators are created to represent flexibility of prosumers as dispatch able loads. The "difference" or power imbalance is dispatched among all these parasitic generators by minimising the objective function. If aggregator introduces different costs for the loads at different nodes, OPF would minimise the cost; otherwise, the power loss in the grid will be minimised.
The "New Active Power" defines the adjustment of power at the candidate nodes for demand response. This signal is promptly communicated with the aggregator to change The set points and parameters are periodically configured in the OPF script which is implemented in Python. The Pseudocode of the high level algorithm as well as the modified OPF are shown in Figure 3.

III. EXPERIMENTAL SETUP
To demonstrate the implementation and performance of our schema, a real-time co-simulation platform is configured. We believe this platform is the closest one to the realworld system, and all components of this setup can easily replaced by the real physical systems in plug-and-play fashion. Figure 4 shows the high level infrastructure of our laboratory setup. It contains A) a digital real-time simulator representing the real network, B) the aggregator, C) DMS of DSO, D) real-time data of the load profiles collected either by smart meters or load forecast tools, E) distributed generation realtime estimation, and finally F) communication adapter to glue all aforementioned components. In this section, we briefly introduce these components and the way they are coupling and communicating with each other.

A. Digital real-time simulator
In order to reproduce the behaviour of the grid, digital real-time simulators are integrated to the platform. They are capable of capturing the fast dynamic behaviour of system in electromagnetic analysis (EMT) as well as slow transients of the system in phasor domain. They are also capable of being used in co-simulation setups so-called software in-the-loop or hardware in-the-loop very efficiently. The communication Fig. 4. Experimental setup in the laboratory capability of these simulators is very wide and different realworld configurations could be made using them. For our specific platform, which is based on Internet-of-Things (IoT) paradigms, real-time simulators can bidirectionally communicate with clouds or brokers through TCP/IP or UDP/IP.
In our laboratory setup, we used an OPAL-RT real-time simulator to run the model of grid which is implemented in MATLAB Simulink. The generation and load trajectories are based on some scenarios which are unknown to the DMS OPF algorithm. They are fed into the grid model running on real-time hardware. The minimum data retrieved from the grid is the power exchange measurement at the point of connection between transmission and distribution networks. This is the active power measured at the medium side of HV/MV transformers in primary substation.

B. Aggregator
To represent the aggregator, a separate PC with a Python script running is set up, which is in charge of controlling the end-users including prosumers and storage units from one side, and communicating with market entities as well as distribution system operators from the other side. For our particular practice, the aggregator is communicating data and signals related to demand response. This means the aggregator periodically (i.e. in real-time), intra-day, or day-ahead sends information about prosumers' flexibility to the DMS. The data includes 3 vectors: bus ID (i.e. location) of the flexible loads, amount of flexibility in power unit of measurement, and the price or cost of the reserves. DMS, instead, returns the exact amount of load adjustment along with the corresponding bus IDs to the aggregator. It is out of scope of this paper to discuss how the aggregator, then, control the loads and appliances to perform demand response. The aggregators seek to achieve this demand set-point defined by DMS by providing monetary incentives to household users to modify their demand pattern, or through direct load control. The objective of each aggregator is to maximise its own net profit, namely the income received from the operator minus the compensation it provides to the end-users.

C. Distribution Management System
The DMS in our configuration is actually a part of DMS which is in charge of controlling power exchange at primary substations. It ensures the scheduled demand profile of the distribution network is not violated. The violation may happen if loads or generation change beyond what was predicted. Not all DMS features are modelled, but a PC as a gateway or the SCADA system is set up to represent the DMS. It runs Python script of the modified Optimal power Flow developed as the core algorithm.
DMS, for this demand response support application, retrieves flexibility data from the aggregators, the measurement of active power flow at primary substations, and the forecast values of loads and generation in the network. It runs the OPF to minimise overall cost of load dispatching and network losses subject to assuring the power exchange set-point from the scheduled profile. It should be noted that not any deviation from the scheduled trajectory will trigger DMS to take actions; there is a sort of thresholds considered. The upper and lower thresholds define an acceptable zone where deviation is tolerated.

D. Load Profile
Not necessarily in real-time, but in advance, DMS should have load profile data. This could come either from widely distributed smart meters in the network which periodically report consumption data, or from load forecasting tools. In both cases, historic data of the loads is used. In our platform, we provided all load profiles at different buses to DMS, but the values are corrected once the load profile module is requested. The algorithm is always running based on the data at time t 1 to achieve the set-point at time t 1 + dt, where dt is the timestep. In our DR practice, 15-minute intervals are considered as time-step.

E. Distributed Power Generator
Similar to load data, power flow calculation requires the generation data. This is a separate PC which estimates the generation values and responds to any requests from DMS to provide the power values. In our demonstration test case, we used our "PV Simulator" which was developed to estimate the power output of roof-top PV panels in urban areas [21].

F. Communication Adapter
The communication adapter is in charge of enabling data exchange among the RTS and other infrastructure modules. It implements two communication paradigms: i) publish/subscribe which is based on message queuing telemetry transport (MQTT) protocol; and ii) request/response which is based on representational state transfer (REST).
In particular, the publish/subscribe communication model allows the development of loosely coupled event-based systems. Each module can publish data and this data can be independently received by a number of subscribers. On the other hand, the request/response approach enables the RTS in retrieving information from REST web services.
In its core, the communication adapter exploits the TCP/UDP module to allow a bidirectional communication with the digital real-time simulator. It is worth noting that the communication adapter also allows the integration of the RTS with other smart metering infrastructure, where each smart meter is an IoT device. Hence, data coming from such devices can be used to simulate and test innovative control strategies with (near) real-time data from the grid. Conversely, each simulated grid component is also seen by other modules as an IoT device able to send information and to receive commands. Our simulated devices could be also replaced by real smart meters integrated in the infrastructure.

IV. EXPERIMENTAL RESULTS
The case study made based on an urban district area located in Northern Italy with about 2200 residential buildings. The MV grid in the district ( Figure 5) consists of a primary substation with three 22-kV bus-bars, each of which is fed by a transformer characterised by voltage ratio of 220 kV/22 kV. Forty-three substations are supplying loads (mainly residential buildings). These substations are equipped with MV/LV transformers characterised by voltage ratio of 22 kV/400 V, and a nominal power of 400 kVA or 250 kVA. The total length of MV lines, mostly constituted by underground cables, is around 39 km.
In this study, we demonstrate the advantage of using our IoT-based real-time control of power exchange at primary substation in presence of high penetration of PV generation. A cloudy day scenario is considered when PV production is less predictable and also lower than a clear sky day. The net demand of the distribution network from upstream transmission system at primary substation is plotted in Figure 6 for two cases as with and without PV integration. The net demand is the power exchange at the primary substation, which is sum of total load and total loss of the network minus total generation. As it is shown in the figure, during the day when PV production rises, a portion of the demand is supplied locally so that less power is absorbed from the primary substation. The amount of power which could be locally generated would not be purchased from the main upstream network. This amount could be estimated by running some PV production forecast tools or simulators. Nevertheless, there is always some error in predictions especially on cloudy days, which may result in fluctuations beyond estimated curve. Figure 6 shows the behaviour of end-user consumption during a cloudy day. Even if we are considering a cloudy day scenario, in which PV panel production is quite low, the introduction of the distributed generator (DG) reduce the total demand of the distribution grid. Obviously the improvement is visible only during daytime hours during which, despite the cloudiness, the sun allows the production of a certain amount of energy that can be spent by the prosumer. The cloudy-day scenario is chosen to stress the impact of low predictability of PV production on total net demand deviation.
In our implementation, the load profile is retrieved from a MATLAB matrix that contains consumer behaviour forecast   The scheduled power profile at the point of connection (i.e. primary substation) is based on the day-ahead or intra-day forecast of prosumer behaviour anticipated by distribution system operator. In practice, the operator is committed to respect the scheduled profile. This means any violations beyond some sort of thresholds must be resolved locally in the distribution grid, otherwise there may be more expensive reserve power from HV system to buy or even some penalties for local grid operator. In practice, specially in a cloudy day, at some points, there is deviation of total demand with respect to the scheduled or forecast profile. Figure 7 depicts the forecast profile and the real measurement of power exchange at primary substation. The real measurements come from the grid simulator. An OPAL-RT 5600 machine runs the model of network in realtime. The real cloudy-day scenario is injected as generation data to the network model, while the system operator is blind to this data. System operator would run PV simulators to forecast the generation. Figure 7 represents the overall behaviour of the system without real-time control of power exchange using our developed schema. During the central hours of the day the active power required by the substations far exceeds that expected on the basis of the data available a day ahead, violating the two thresholds set by the DSO.
Assuming this scenario, the modified OPF algorithm, scripted in Python, is called by DMS to calculate the total power adjustment needed, and associate it to all network nodes which are candidates to provide flexibility. New trend of the curve obtained after the application of the algorithm is shown in Figure 8. Differently from Figure 7, this time the active power is always kept within the threshold. Subsequently, the high volatility of the residential prosumers due to the presence of rooftop PV panels is controlled in real-time, and the peak demand is reduced about 30% in this scenario. Integration of widely distributed small-scale RES like rooftop PV panels and emerging loads like plug-in EVs would cause more volatility in total net demand of distribution networks. The trajectory of the power exchange at primary substation needs to be controlled in real-time, since forecast error may deviate the real power flow with respect to the agreed or scheduled one. In this paper, we presented our solution to solve this problem by running a modified OPF to adjust dispatchable loads which are nominated by their aggregators. A laboratory test bed is also developed based on IoT paradigms in which the grid simulator can be replaced by the real grid with minimum effort. The test platform demonstrated the performance of the algorithm in filtering the noise or deviation of power flow at primary substations. The outcome of the algorithm is a set of load adjustments sent to the aggregators. As a future work, the way this outcome is used by the aggregator to perform demand response can be investigated.