A Local Capacity Market Providing Local and System-Wide Flexibility Services

A large amount of renewable energy sources and electric vehicles will be integrated into future electricity distribution and transmission systems. New flexibility services from distribution network are needed to manage the related challenges. This paper proposes a local flexible capacity market (LFCM) in the distribution network providing system-wide and local flexibility services for transmission (TSO) and distribution system operators (DSO). The TSO and the DSO play the role of buyers, whereas prosumers connected to the distribution network are the sellers. The LFCM consists of three stages. At the first stage, the offers of flexibility sellers are matched with the bids of flexibility buyers aiming to maximize the social welfare of all participants. At the second stage, the accepted flexible capacities are checked by the DSO not to violate the constraints of the local network. The third stage accepts the offers of the sellers based on the results of the previous stage. The results related to the chosen case study demonstrate that the local flexible resources can help the DSO control the voltage and manage periods of congestion. Besides, the owners of the resources can obtain revenues by selling flexibility services while improving electricity supply reliability.

Forecasted active/reactive net load of node n at t U rated Nominal voltage The associate editor coordinating the review of this manuscript and approving it for publication was Shiwei Xia .

I max n,n
The maximum current flowing between node n and n S n,n The maximum power in the discretization of quadratic power flow R n,n The resistance of the branch between node n and n Z n,n The impedance of the branch between node n and n X n,n The reactance of the branch between node n and n π offer,up n,i,t The prices of upward flexible capacities offered to the LFCM by prosumer i located at node n at t π offer,dn n,i,t The prices of downward flexible capacities offered to the LFCM by prosumer i located at node n at t Required upward flexible capacities for node n at t FD dn,DSO n,t Required downward flexible capacities for node n at t P + n ,n,t /Q + n,n ,t Active/reactive power flowing in the downstream direction from node n to n at t P − n ,n,t /Q − n,n ,t Active/reactive power flowing in the upstream direction from node n to n at t SI n,n ,t /SU n,t Auxiliary variables representing the squared current flowing between n and n / squared voltage of n at t u DSO t A binary variable that determines the direction of local flexibility need at t P n,n ,r,t Active power flowing between node n and n at t regarding the discretization of the power flow Q n,n ,r,t Reactive power flowing between node n and n at t regarding the discretization of the power flow P G2LN sb,t /Q G2LN sb,t Active/reactive power importing from external grid to the local network through slack bus at t Contemporary power systems need to deal with the increasing penetration of intermittent renewable energy sources (RES) and electric vehicles (EV) in distribution networks. The uncertainties and variabilities related to the RES outputs and EV charging behaviors can cause instability problems for the power system since they can disturb the realtime balance between generation and demand. In addition, the bi-directional flow of power in distribution networks can adversely affect the secure operation of these networks [1]. Thus, the system operators, including both the transmission system operators (TSO) and the distribution system operators (DSO), need to resolve these issues by utilizing more flexibility services in their networks [2].
Flexibility services are typically categorized into systemwide and local services based on the type of system operator (TSO or DSO) utilizing the services [3]. System-wide flexibility services aim to follow load and/or generation variations close to real-time to maintain the system frequency within a permissible level [4]. Hence, system-wide flexibility services are procured by the TSOs. Regarding European terminology for system-wide services, these services mainly consist of different types of reserves such as frequency containment reserves (FCR), fast frequency reserves (FFR), and frequency restoration reserves (FRR) [5].
On the other hand, local flexibility services help DSOs to fulfil their responsibilities. DSOs can purchase flexible VOLUME 9, 2021 energy resources connected to these networks to regulate voltage and manage congestion. Currently, most DSOs still deploy traditional actions to operate their networks. However, because of the increasing amount of intermittent power, these devices may fail to operate the distribution network effectively. As a result, the DSO needs sufficient new active network management schemes to coordinate traditional functionalities, distributed flexible energy resources control settings, and possible new market structures [6]- [9]. Besides, conventional generators are currently the main resources that provide flexibility services for TSOs [9], [11]. In this regard, the flexibility potential of flexible energy resources located at distribution networks and demand-side resources needs to be fully utilized for the provision of the flexibility for the future power systems.

B. LITERATURE REVIEW
In general, some literature offered the utilization of demandside resources to provide system-wide (TSO-level) or local flexibility services. However, a few thorough studies proposed the simultaneous provision of both services by these resources.

1) SYSTEM-WIDE FLEXIBILITY PROVISION
The utilization of demand-side resources for the provision of TSO-level (system-wide) flexibility services has been already analyzed to some extent, in the previous research. For example, the authors of [12] assessed energy storage participation in the provision of system-wide flexibility services, leading to the better management of the fluctuations of demand and generation. Reference [13] offered analysis of the provision of automatic FRR services by storage-based resources at distribution networks. Ref. [14] demonstrated that local energy communities connected to distribution networks could be potential resources for providing manual FRR services for TSOs. The authors of [15] analyzed the deployment of grid-connected PV (Photovoltaic) panels integrated with the battery energy storage system (BESS) to follow the TSO regulation signals. EV charging stations were also proposed in [16] to contribute to the FCR provision. The study estimated the maximum flexibility, which can be procured through the charging cycles of EVs. In another similar study, EVs with vehicle-to-grid capabilities are integrated to provide the TSO with regulation services [17]. Authors of [18] assessed the capability of distributed generations and EV aggregators for the provision of spinning reserves as a system-wide flexibility. Reference [19] suggested the utilization of electric heating appliances to provide TSO-level reserves for the Swedish power system. Similarly, a novel method was also defined in [20] to analyze the flexibility potential of controllable loads contributing to the frequency regulation. Authors of [21] proposed to procure reserves from renewable resources, active demand, and batteries besides conventional generators to maximize the flexibility of power systems. Additionally, [22] analyzed the role of conversion, storage and demandside management in flexibility programs.
It is good if you discuss the strategic behaviours in flexibility and ramp-rate market. These are the papers that you might use:

2) LOCAL FLEXIBILITY PROVISION
In some studies, DSOs were proposed to deploy the flexibility potential of demand-side resources for operating their local distribution networks. For instance, in [23], it was suggested that the DSO assigns its responsibilities to some aggregator. The aggregators utilize EVs, renewable energy resources, and demand response to operate their own local networks. However, the model was not mathematically introduced in this study. Besides, [24] proposed a model that utilizes the flexibility of demand-side resources. In the mentioned study, the operation of household appliances was rescheduled to provide the DSO with the required flexibility. Reference [21] suggested that DSOs use energy hubs in a demand-response format to operate the distribution network effectively. The authors of [25] proposed a hierarchical control model for the distribution network. The model includes flexibility markets at the medium voltage level for assisting the DSO with congestion management tasks. Reference [26] proposed the participation of the distribution network customers in providing voltage control services for the DSO. Finally, the authors of [27] developed a novel scheme utilizing an agent-based coordination mechanism to manage the household appliances to comply with thermal and voltage limits of the distribution grid. In the studies mentioned, however, the owners of flexible resources (e.g., prosumers) could not submit their flexibility offers, and there was no competitive environment for trading local flexibility services. In addition, some references proposed to manage distribution networks and adopt the flexibility of distribution network-located resources implicitly using distribution locational marginal pricing. In this way, the DSO sends economic signals to manage congestion and direct the investments in distributed energy resources [28]. Authors of [29] also suggested the coordination between system operators and the hierarchical economic dispatch to compute the distribution locational marginal pricing. However, the implicit signals such as pricing mechanisms may not always lead to the effective management of distribution networks and they do not provide a competitive environment for flexibility sellers.

3) LOCAL AND SYSTEM-WIDE FLEXIBILITY PROVISION
Flexible energy resources located at distribution networks can also provide flexibility services for both the TSO and DSO, simultaneously. However, in reality, it requires increased collaboration and information sharing between the DSO and the TSO in terms of their control, management systems and platforms. Besides, increasingly holistic approaches are needed to consider flexible resource owners (prosumers) and system operators (TSO and DSO). In terms of the efficient interaction between the DSO and the TSO, [30] proposed a multi-level structure for the TSO-DSO coordination so that it enables distrusted energy resources to participate in wholesale energy markets. In the similar work proposed by [31], the coordination between system operators was modelled using the local energy market concept. In this approach, the local energy market was considered as a strategic player of the wholesale energy market. However, the provision of system-wide flexibility services for the TSO was not considered in these two papers. In other words, distribution network-connected resources were proposed to provide energy (not flexibility services for the TSO) as well as local flexibility services for the DSO.
Comprehensive research is needed to analyze the potential of distribution network-connected resources to provide local and system-wide services simultaneously. In this regard, [32] introduced the participation of DSOs in providing balancing services as well as line congestion and voltage regulation services of the distribution network. However, currently the balancing service is not the responsibility of the DSO. BESS owners were proposed to provide local and system-wide services at the same time, in the work conducted by [33]. The main objective of the paper was totally in favor of the flexibility sellers as it aims to maximize the total revenues of the BESS owners. Reference [34] modelled the coordination of the DSO and the TSO that facilitates the participation of distributed energy resources in providing reactive power ancillary services. The provision of FFR services in addition to the voltage-related services, was proposed in [35]. In this work, different clusters of electric vehicles form a virtual power plant to provide flexibility services. However, there is no market-based approach and competitive environment for the flexibility sellers. the authors of [36] proposed a coordination scheme for the TSO and the DSO to dispatch many distributed energy resources located in the distribution network. Moreover, reference [37] developed a local flexibility market that can simultaneously provide local and systemwide flexibility services. However, these two studies did not specify the type of flexibility services that the local resources can provide. For example, in terms of TSO-level services, there is a wide range of reserve services with different characteristics and technical considerations.
Similar to local energy markets, local flexibility markets can be designed for trading flexibility at local levels. These markets should provide a competitive environment so that it benefits both flexibility sellers and buyers. In this way, buyers and sellers can submit their bids and offers to trade flexibility in a competitive environment. To achieve this environment, the operator who is responsible for clearing the local market needs to be totally impartial and the market-clearing mechanism needs to maximize the social welfare of all the participants. In other words, the clearing mechanism should not be in favor of just one party (either sellers or buyers). However, this type of impartial and competitive environment cannot be completely seen in the previous studies. TABLE 1 compares the existing literature that proposed different coordination schemes between the DSO and the TSO. The first column introduces the paper. The second column assesses whether the paper considers the technical characteristics and specifies the types of flexibility services for the TSO. The third column is presented for those works that consider the provision of congestion management services for the local network. The fourth column analyzes the procurement of voltage control services for distribution network-connected resources. The fifth and sixth columns check whether the reference suggests a local market (LM) as a competitive and impartial environment for flexibility sellers and buyers. The LM needs to have a social-welfaremaximization objective to benefit both flexibility sellers and flexibility buyers. As stated in TABLE 1, this paper aims to consider all the key factors which have not been completely taken into account in the previous literature.

C. CONTRIBUTION
This paper proposes a three-stage local flexible capacity market (LFCM) capable of providing flexibility services for DSO and TSO needs. The simultaneous fulfilment of flexibility needs for the TSO and the DSO leads to the increased collaboration between these two grid operators. In this regard, the LFCM is developed to provide FCR services for the TSO while offering active power support for local voltage control and congestion management for the DSO. The FCR services include both the FCR for normal operation (FCR-N) and the FCR for disturbances (FCR-D). First, the paper builds the DSO bidding strategy, based on the required flexibility of the local low-voltage (LV) distribution network. Then, the proposed three-stage LFCM is formed. In the LFCM, prosumers trade flexible capacities with the system operators. VOLUME 9, 2021 At the first stage, the flexibility bids of buyers (i.e., the DSO and the TSO) are matched with the sellers' offers (i.e., prosumers), aiming to maximize the social welfare of the participants. At the second stage, the DSO checks whether providing the matched flexibility does not violate the voltage and thermal constraints of the local LV network. At the third stage, the accepted offers of each seller are determined based on the results of the previous stage. The main contributions of this paper are as follows: 1. The paper develops a unique local capacity market for providing both local and system-wide flexibility services.
To the best of the authors' knowledge, there is no research defining local capacity markets in which the flexibility needs of the DSO and the TSO can be satisfied by the flexible capacities of prosumers. The proposed LFCM aims to make a competitive and impartial environment and try to maximize the social welfare of the participants. The prosumers are motivated to participate in the market actively, and the needs of the TSO and DSO can be satisfied through the proposed LFCM. 2. This paper specifies in detail the type of services provided through the LFCM and considers the technical characteristics of these services in the LFCM clearing process. In this way, the LFCM provides the TSO with FCR services for both normal operations (FCR-N) and disturbance situation (FCR-D) and the symmetric characteristic of the FCR-N is fully regarded in the LFCM clearing process. It also fulfils the flexibility needs of the DSO by providing voltage control and congestion management services. 3. This paper analyzes the effect of local distribution network constraints on the provision of system-wide services.
Although the provision of system-wide flexibility service can be beneficial for demand-side resources and the TSO, it should not compromise the security and electricity supply quality of the local distribution network. This issue is considered in the second stage of the proposed model.

D. PAPER ORGANIZATION
The rest of the paper is organized as follows. Section II introduces the flexibility services provided by the proposed LFCM. Section III defines the structure and architecture of the LFCM. The mathematical model of the proposed market is presented in Section IV. Section V demonstrates the simulation results of the proposed LFCM for the chosen case study with weak rural LV network. Finally, section VI concludes the paper.

II. FLEXIBILITY SERVICES FOR TSO AND DSO
The paper first introduces the flexibility services that the LFCM can provide. The DSO and the TSO are the buyers of these services. Our work considers two types of flexibility services. The TSO deploys the first type to satisfy systemwide flexibility needs while the DSO procures local flexibility services to meet the flexibility needs of the local LV network.

A. SYSTEM-WIDE FLEXIBILITY SERVICES FOR TSO
System-wide services mainly require automatically controlled flexible energy resources to avoid the delay of resources' response and enable them to follow the real-time frequency changes. Automatically controlled resources can be controlled automatically based on external signals. In this paper, it is assumed that the proposed LFCM provides FCR services for the TSO. In Nordic markets, FCRs are split into FCR for normal operations (FCR-N) and FCR for disturbances (FCR-D) [5]. The reserve unit providing FCR-N needs to react continually to frequency deviations between 49.9 Hz and 50.1 Hz [38]. The FCR-N is a symmetrical flexibility service. It means that the reserve resource must be capable of activating the reserved power in upward and downward directions. When the reserve resource provides upward flexibility service, it increases its production or decreases its consumption. In downward direction case, the resource should increase its consumption or decrease the production. In addition, the reserved power needs to be activated in a couple of minutes.
In contrast, a reserve resource providing FCR-D, is activated when larger frequency deviations occur in the system. In Finland, FCR-D requires only upward flexibility [16]. In other words, a reserve unit providing FCR-D needs to inject power or decrease its consumption. The flexible resources providing FCR-D, need to activate the reserve power when the frequency is under 49.9 Hz [16]. This power must be able to react to the frequency deviations in less than 5 seconds.

B. DSO LOCAL FLEXIBILITY NEEDS
DSOs control voltages of the network using active power and reactive power support. Hence, the DSO needs to buy flexibility in the form of both active and reactive power to operate the distribution network effectively. Active power plays a more important role than reactive power in controlling the voltage of LV feeders [39]. The reason is that the resistance of low-voltage feeders is higher than their reactance. In this regard, this paper mainly focuses on utilizing the activepower flexibility for the provision of local flexibility needs. In other words, the DSO is proposed to purchase active-power flexibility from the LFCM to fulfil its local flexibility need.
The constraints associated with the voltage and thermal limits of the local distribution network can be fully considered by solving the load flow problem. This paper considers that the DSO deploys a linearized power flow model proposed by [40] to find the optimal local flexibility. The DSO also checks whether providing the system-wide flexibility does not violate the local security constraints. The following objective function is proposed for the DSO to find its required flexibility.
Eq. (1) states that the DSO seeks to find the minimum amount of local flexibility (upward and downward) in the form of active power, through which it operates the local network securely. The introduced objective function is subjected to several constraints. The constraints indicating the active and reactive power balance are denoted by (2) and (3), respectively: According to (2) and (3), the required local flexibility is highly dependent on the forecasted amount of active and reactive power of the net load. The net load is defined as the total load minus the total generation at that node. The local upward flexibility at node n increases the injected power at this node, whereas the local downward flexibility at node n decreases the injected power. The flexibility offered by the LFCM is supposed to be in the form of active power. As a result, no injected reactive-power flexibility exists, as can be seen in (3). Only the reactive power consumed by inductive loads are considered in the formulation.
The linearized equation related to voltages between two nodes is expressed by (4) [40]: where, SU n,t is an auxiliary variable representing the squared voltage of node n during time slot t in (4). Similarly, SI n,n is a variable that refers to the squared current flowing between the nodes n and n during time slot t. Eq. (5) denotes the maximum and minimum limits of the voltage magnitudes (U min = 0.95 and U max = 1.05 p.u were used in the simulations): Equations (6) and (7) are associated with the DSO congestion management, explaining that the power flowing in distribution network lines should not exceed its maximum allowable amount. P + n,n ,t + P − n,n ,t ≤ U rated I max n,n ,t ∀t, ∀n, ∀n Q + n,n ,t + Q − n,n ,t ≤ U rated I max n,n ,t ∀t, ∀n, ∀n Similarly, the current flowing in the feeders should not exceed its maximum rate restricted by its thermal limits.
The following constraints are obtained from the piecewise linearization of the power flow equations [40]. SU rated n SI n,n ,t = r (2r − 1) S n,n P n,n ,r,t + r (2r − 1) S n,n Q n,n ,r,t × ∀t, ∀n, ∀n P + n,n ,t + P − n,n ,t = r P n,n ,r,t ∀t, ∀n, ∀n Q + n,n ,t + Q − n,n ,t = r Q n,n ,r,t ∀t, ∀n, ∀n (11) 0≤ P n,n ,r,t ≤ S n,n ∀t, ∀n, ∀n , ∀r (12) 0≤ Q n,n ,r,t ≤ S n,n ∀t, ∀n, ∀n , ∀r In (14), the value selected for N r should keep the balance between the accuracy and the computational burden of the optimization. Moreover, S n,n is the upper limit for the discretized power flowing through LV feeders.
Finally, at one time slot, a node can provide either upward or downward flexibility. It means that the DSO cannot procure both upward and downward flexibility from one node simultaneously, as denoted by (15) and (16). In addition to this, these equations restrict the maximum values that can be offered for local flexibility demand.
As a result of solving the introduced optimization, the DSO finds the optimal amount of flexibility (FD for each node at time slot t. After that, the DSO submits the required flexibilities for each time slot to the LFCM.

III. LOCAL FLEXIBLE CAPACITY MARKET DESIGN
The proposed LFCM is run on a day-ahead basis. In this way, flexibility transactions are confirmed one day before the actual delivery. The reason is that the LFCM should comply with TSO-level capacity markets mainly formed in the dayahead. Hence, the LFCM can participate in these markets. For example, regarding FCR hourly markets, FCR bids and offers should be submitted one day before the delivery. Thus, each day's LFCM bids and offers need to be determined one day before the delivery. In addition, since the DSO needs to predict each local node's net load, it can estimate more accurately on a day-ahead basis than, for example, a weakahead. It is worth mentioning that each node's net load is defined as the load minus the generation of the node.
In the proposed LFCM, prosumers sell their flexible capacities to the TSO and the DSO. Hence, prosumers within the LFCM are the main sellers, whereas the TSO and the DSO are the main buyers. The buyers are permitted to automatically control the flexible resources of prosumers if their bids are accepted. In other words, the DSO and the TSO can constantly follow their flexibility needs in real-time if they had purchased their required flexible capacities from the LFCM in day-ahead. In real-time, the operators are allowed to activate the purchased capacities fully or partially. The operators may also decide not to activate the purchased flexible capacities if they do not need them in real-time.
The target of the proposed LFCM is to provide flexible capacities for both the TSO and the DSO. Regarding system-wide services for the TSO, these flexible capacities are used to control the frequency of the system in normal operations and disturbances. Hence, these capacities provide flexibility service in the short-term and do not use resources for long-term adequacy. Regarding local services for the DSO, the flexible capacities are utilized to control voltages and manage congestions occurring in distribution networks. In addition, unlike conventional capacity markets which are designed for large-scale generation capacity providers [41], the LFCM is designed for the participation of small-scale flexible resources, such as prosumers.
In addition, the assumptions underlying the proposed LFCM are listed below: 1) The LFCM is designed for trading flexible capacities. It should be noted that the sellers would also receive compensation for the activated reserve energy (based on the prices of the real-time balancing energy markets). However, this paper focuses on the outcomes obtained from flexible capacities traded on a day-ahead basis.
2) The main priority of the proposed LFCM is to satisfy local flexibility needs. It is also assumed that the LFCM has enough flexible capacities to support the local needs. After satisfying the local flexibility requirements, the surplus flexible capacities are sold to the TSO if it does not violate local network constraints.
3) Only automatically controlled flexible resources can participate in the proposed LFCM. It means that the flexible resources should have the capability to be automatically controlled by the TSO or the DSO in real-time. As a result, The LFCM can satisfy the frequency services requiring online and real-time control of resources.
4) The prosumers should consider the operational costs of their resources and their preferences when building their offering strategies. In this way, these constraints are implicitly included in the flexible capacities offers and the LFCM operator does not need to know about the details of the resources. 5) Pay-as-bid pricing mechanism is considered for the LFCM. The accepted sellers and buyers receive/pay based on the prices that they had offered before [30].
In the proposed LFCM, sellers submit their available flexible capacities and the offered prices for each time slot of the next day. Buyers also submit their bids, including the flexible capacities that they decide to procure from the LFCM and the corresponding prices for each time slot of the next day. The LFCM operator, as an independent entity, matches flexible capacities bids and offers. The matching process constitutes the first stage of the proposed LFCM. Hence, the first stage of the LFCM is from the viewpoint of the LFCM operator. At this stage, the LFCM aims to maximize the social welfare of the participants. In other words, the DSO ensures that the provision of flexibility for the TSO from local resources would not violate the local network constraints. The amount of allowable TSOlevel flexibility is then sent to the LFCM operator. Since the DSO is not aware of the offered prices of flexibility sellers, it is not able to allocate these allowable flexible capacities to each seller. This would be the responsibility of the LFCM operator.
At the third stage, the LFCM operator aims to find the amount of flexible power which each seller in the local market should provide. This amount should satisfy the flexibility needs for the local network constraints. Fig. 1 illustrates the architecture of the proposed LFCM. Besides, Fig. 2 reviews the stages of the proposed LFCM. In the next section, the mathematical models for each stage are introduced. The models of the first and third stages are from the LFCM operator's viewpoint whereas that of the second stage is from the DSO's view point.  The main objective of the LFCM operator, as an independent operator, is to maximize the social welfare of the participants. This social welfare is defined as the utility of flexibility demand minus the costs of flexibility production. The bids of flexibility buyers reflect the utility of flexibility demand, while sellers' bids represent their costs. As previously mentioned, we consider a pay-as-bid mechanism for the proposed LFCM. The objective function is defined in (17), and the social welfare of the participants is introduced in (18)

IV. PROBLEM FORMULATION
where Utility I indicates the TSO's utility for meeting its flexibility demand associated with FCR-N and FCR-D services. Utility II denotes the DSO's utility for fulfilling the local-network flexibility demand. On the other hand, Cost I states the cost of providing flexible capacities by sellers. The flexibility production of each node at each time slot should meet the same node's flexibility demand for the same time slot. These constraints are the balancing constraints of the LFCM and are defined separately for downward and upward flexibility services. The constraints are expressed by (19) and (20). Eq. (19) states that the accepted upward flexible capacities of sellers at each node should meet the accepted upward flexibility need of the TSO for both FCR-N and FCR-D services and the accepted upward flexibility need of the DSO. Eq. (20) explains the same constraint for the accepted downward flexibility need and capacities. It is noticeable that the FCR-D services require upward flexibility, whereas we consider both directions for FCR-N services. In (19) and (20), the values of FD DSO,up n,t and FD DSO,dn n,t were determined by the DSOs using (1)- (16). Thus, these are considered as parameters of the LFCM optimization problem.
As previously mentioned, FCR-N services are symmetrical. It means that the resources at each node should be capable of activating their maximum flexible capacity in both directions [16]. Players located at one node are considered as one reserve unit. Hence, the related constraint can be seen in (21).
Finally, the matched offers and bids should not violate the amount that their owners had submitted. These constraints are explained by (22) Inequality constraints (23) and (24) state that the TSO does not care about the nodes that are going to provide systemwide flexibility services. It means that system-wide flexibility services need to control the frequency of the system regarding the location of the flexible resources. However, providing these services must not cause any danger to the local network. The LFCM operator solves optimization problem (17)- (26) to maximize the social welfare of the participants. However, the capacities obtained from satisfying system-wide flexibility need may violate local network operational limits. In this regard, the DSO must ensure that trading flexibility with the TSO will not endanger the security of the distribution network. This security check process is performed in the second stage.

B. STAGE II: CHECKING FEASIBILITY OF PROVIDING SYSTEM-WIDE FLEXIBILITY
At the second stage of the LFCM, the DSO assesses the potential effects of the system-wide flexibility provision. In other words, the DSO checks whether the provision of system-wide flexibility from local resources does not violate the security constraints of the local network. However, FCR-N services can be activated in two different directions, and the DSO does not know about the real-time activation. To solve this issue, the DSO considers two different scenarios for each time slot to create the worst case for the network. In the first scenario, w1, FCR-N is fully activated in the upward direction while in the second scenario, w2, FCR-N is fully activated in the downward direction. The DSO then runs the following optimization to check the feasibility of the provision of TSOlevel flexibility:  29) and (30) explain that the first scenario considers the upward direction for FCR-N, whereas the second scenario regards the downward direction. With the help of (31) and (32), the accepted FCR-N should be selected from the minimum of the optimum value of the upward flexibility in scenario w1 and the downward flexibility in scenario w2. Constraint (33) also states that the selected amount of FCR-D should be the minimum value of FCR-D considering two scenarios. Finally, (34) and (35) indicate that the accepted flexibilities should be less than the amount accepted in the first stage of the LFCM. Finally, (36) denotes other constraints related to the power flow equations.
As a result of solving (27)- (36), the feasibility of systemwide flexibility is checked, and the possible amount of TSO-level flexibility demand which the LFCM can meet is obtained. The feasible amount of system-wide flexibility for each node at each time slot is then sent to the LCFM operator.  Eq. (37) and (38) specify that the main objective of stage III is to maximize the social welfare of the participants. Again, social welfare is thought to be equal to the utility of flexibility demand minus the cost of flexible capacities. The objective function is subjected to the following constraints.
Eq. (39) and (40) are balance-related constraints for upward and downward flexibility power, respectively. In addition, (41) and (42) express that the amounts of upward It should be noted that the proposed three-stage LFCM clearing model consists of linear programming (LP) problems with linear and convex functions. We use GAMS software and CPLEX solver to solve the LP problems. The CPLEX solver uses dual simplex algorithm to solve the LP problems [42]. Since the optimization problems are convex, the feasible answers obtained from solving these problems are optimal.

V. CASE STUDY
The studied LV network illustrated in Fig. 3 is a typical weak Finnish rural overhead network adopted from [39] and modified based on our proposed model. The case study consists of one 50-kVA MV/LV-transformer feeding two LV feeders. There are seven loading points regarding the first feeder, and each load point consists of some households. In the second feeder, there are three loading points, each with some households. The information on resistance and reactance of the studied LV network can be found in [39].
For simplicity, it is assumed that the neighboring households at each loading point form a micro-energy community, and therefore they are considered one flexibility seller in the LFCM. The daily amounts of forecasted load and generation for the studied system are depicted in Fig. 4 and Fig. 5, respectively.
The households are equipped with PV panels, and thus their produced power is illustrated in Fig. 5. It is supposed that households have three different types of flexible resources, including 5 kW/13.5 kWh lithium-ion batteries, 1 kW heater, and EVs which can be charged with a rate of 3 kW. These resources are considered providers of upward and downward flexible capacities (Fig. 6 and Fig. 7). To develop the mathematical models of EVs and batteries, we utilize the model introduced in [14] while for the electric heaters, the model is extracted from [43].   The EVs provide only downward flexibility since they are assumed to have chargers capable of charging with constant power and the vehicle-to-grid option was not taken into account. However, heaters and batteries are able to offer both upward and downward flexibility at different time slots. This means that, for example, the charging power of EV is only regarded as downward flexibility offer (Fig. 7). It should be noted that the amount consumed by flexible appliances is considered as flexibility and not demand. It means that VOLUME 9, 2021  only the amounts consumed by uncontrollable appliances considered as loads. Therefore, the charging pattern of EVs can be seen in Fig. 7. It is assumed that the EVs can be charged from 17.00 to 7.00 where during this time frame the EV owners do not use them much. Hence, the flexibility offers of sellers were built based on the mentioned flexible energy resources. Note that the issue related to the flexibility seller's offering strategy is not within the scope of the paper. However, the daily flexibility offers of the sellers can be found in Fig. 6 and Fig. 7.
Moreover, local sellers are assumed to behave competitively. In this regard, the offered prices of selling flexible capacities are assumed to be constant for the whole day, and they are dependent on the type of flexible energy resources they are using. These prices are denoted in TABLE 2. In addition, the prices of buying FCR-N and FCR-D capacities are also illustrated in Fig. 8. The prices of these services are extracted from Fingrid's (Finnish TSO) open dataset on 18.3.2020 [44]. This paper considers that the TSO seeks to exploit all of the flexible capacities of the local market. Thus, it requests a high value (even more than the LFCM's available capacities) for its required flexibility.

A. LOCAL FLEXIBILITY NEED
The optimization problem (1)- (16) has been solved for the rural LV network introduced in section 6 in order to find the  minimum amount of upward and downward local flexibility and assist with the secure operation of the local network. The required local flexibility is depicted in Fig. 9. According to the result, the local network needed only upward flexibility and did not require any downward flexible capacities. These amounts of flexibility will be offered to the LFCM by the DSO. Comparing Fig. 4 with Fig. 9 shows that the local network requires only upward flexibility at time slots with the high demand. Fig. 9 also states that the nodes which are located at the end of feeders and those which have longer physical distance from the LV main transformer require more upward flexibility. Nodes b8, b10, b11 and b12 are examples of these nodes requiring upward flexibility during time slots at which the local consumption is high. Then, the DSO bids for its required upward flexibility to the LFCM operator, having solved the optimization problem (1)- (16). This paper assumes that the DSO prices are equal to the prices submitted by the TSO for providing FCR-N services which is the most expensive service. This assumption is because the priority of the LFCM is to provide local flexibility. Thus, this priority should not make the local sellers achieve less revenue than the cases in which the priority is to provide system-wide flexibility. Hence, the DSO is better not to offer lower prices to the LFCM.

B. ACCEPTED FLEXIBILITY BIDS AND OFFERS 1) ACCEPTED BIDS OF BUYERS
In this section, the first and second stages of the LFCM are run, considering the data introduced in section 5 and those obtained by the previous stage. In fact, this section analyzes the system-wide flexibility need, which will be satisfied through the LFCM with and without considering network constraints. In this regard, in the first step, (17)- (26) is solved for the case study aiming to obtain the amount of TSO-level bids accepted in the LFCM. In the next step, the feasibility  of providing system-wide (TSO-level) flexibility is checked through solving (27)- (37). The results of accepted bids of the TSO for each node are illustrated in Fig. 10 and Fig. 11.
As shown in Fig. 10, in general, nodes b8, b10, b11, and b12 have a minor contribution to providing FCR-N services. Besides, during 18:00-0:00, they cannot provide FCR-N anymore because most of the flexible capacities of these nodes at the mentioned time slots utilized for meeting local flexibility need (according to Fig. 9). During 18:00-23:00, the local network needs upward flexibilities from b8, b10, b11, and b12. It means that the network requires these nodes to decrease their injection. As a result, they cannot inject more power and provide downward flexibility for FCR-N services. In contrast, the flexible capacities of b3, b5, b7, b14, b16, and b17 were mostly devoted to providing FCR-N. Regarding FCR-D services illustrated in Fig. 11, b8 (P4) and b12 (P7), b3, and b16 have the highest contribution to the provision of FCR-D services.
The total hourly amounts of the accepted TSO-level flexibility bids for FCR-N and FCR-D services are illustrated in Fig. 12.  The following results can be obtained from this figure: 1) FCR-N services receive a bigger share of the local flexible capacities than FCR-D as long as this kind of service is more expensive and profitable for the sellers. 2) FCR-D services are highly provided during 13:00-16:00. Fig. 12 states that the LFCM provides more FCR-D during hours when the local market has a positive surplus (see Fig. 4 and Fig. 5).
3) The provision of FCR-N services decreases during 18:00-23:00 as well as 8:00. According to Fig. 4, during these time slots, the local demand increases considerably. Thus, generally, the amount of accepted FCR-N decreases during peak hours. As previously mentioned, the accepted system-wide flexibility bids may differ in the first and second stages of the LFCM. In fact, flexibility bids and offers are matched at the first stage regardless of the local network constraints. However, network physical limits, including voltage and congestion-related constraints, are considered at the second stage. Accordingly, the effect of network constraints can be observed by calculating the difference of TSO-level accepted flexibility bids between first and second stage LFCM. In this regard, the ratio of difference (RoD) indexes regarding These indexes are calculated for the case study and depicted in Fig. 13. According to Fig. 13, during 13:00-16:00 and at 23:00, considerable amounts of accepted bids (more than 60%) of FCR-D violate the local network constraints. Thus, the DSO does not accept these bids. It is worth mentioning that we select the weights of the second-stage objective function based on the prices of FCR-N and FCR-D services. As a result, during 13:00-16:00 and 23:00, it was more profitable for the local market sellers to reduce the provision of its FCR-D services rather than FCR-N ones. However, during other time slots, the local network constraints restrict the amount of accepted bids for the FCR-N provision. Fig. 13 also states that the network constraints are more binding during peak hours.

2) ACCEPTED OFFERS OF SELLERS AND THEIR REVENUES
The sellers' offers were submitted to the proposed LFCM, leading to the provision of local and system-wide services. The accepted capacity offers of sellers devoted to each flexibility service are reported in TABLE 3. In addition, by calculating each stage's accepted offers separately, the effects of local network constraints on the sellers' accepted offers can be analyzed using reported results in TABLE 3. TABLE  3 explains that, in general, P8, P9 and P10 have the greatest acceptance percentage for their flexibility offers. The network constraints did not considerably affect these players' flexibility provision compared to the other players located at weak nodes. Players P4-P7 are examples of those located at weak nodes b8, b10, b11, and b12. As a result, less than 31% of their flexibility offers were accepted in the LFCM. Weak nodes can also be identified by their local flexibility needs, as TABLE 3 explains. For instance, b8, b10, b11, and b12 are the only nodes which require flexible capacities for their secure operation. Consequently, less system-wide flexibility can be procured from these nodes since localnetwork constraints are mostly binding for these nodes. Regarding local flexibility services, the sellers cannot make income during most of the time slots. The local sellers can just make revenues during time slots that the local network needs flexibility. These time slots are 18:00-22:00 for this case study. However, by providing system-wide services, the prosumers can increase their revenues up to 25 times more than when the local market cannot provide these services. It should be highlighted that the revenues of prosumers from selling energy and flexibility in real-time are not considered in this work. Nevertheless, extra profits will be also added based on the prices of balancing markets.

3) DISTRIBUTION NETWORK VOLTAGE CONTROL USING THE PROPOSED LFCM
As mentioned before, the voltage of nodes at distribution networks can be controlled using flexible energy resources' active power. In this regard, this paper considers four different cases to show the effect of the proposed local market on the voltage magnitude of the nodes in the studied network. The cases are as follows: Case 1: This case considers the voltage magnitude of nodes without any regulation. It should be noted that the preferred voltage magnitude is 1 p.u. and this value can vary within the range 0.95-1.05 p.u. The above-mentioned cases are calculated for time slot18:00 at which the demand reaches its peak value. Fig. 15 illustrates the results for these cases.
Regarding the unregulated case (Case 1), the figure shows that the local network can be insecure since the voltage magnitudes of b8, b9, b10, b11, and b12 are not in their pre-determined range. It is noticeable that the mentioned nodes belong to the longer feeder and considered weak nodes. However, the voltage magnitudes of b8-b12 and those of other nodes, totally maintain within their acceptable range with the help of the proposed LFCM (Case 2, Case 3, and Case 4). In Case 2, the local market solely provides local services. Accordingly, the DSO buys the amount of flexibility so that the voltage magnitudes reach their permissible values. In Case 3, the upward FCR-N and FCR-D are activated as well.
However, the voltage magnitudes still maintain within the acceptable range. However, it also improves the voltage of nodes because the DSO has checked the feasibility of providing the system-wide flexibility at the second stage. The amount accepted in the local market will not jeopardize the security of the network. In Case 4, the upward FCR-N is assumed to be activated and FCR-D and local flexibility services. Again, the voltage magnitudes maintain within limits. It should be emphasized that the local network is considered a weak LV network which needs to be supported by the active power flexibility of prosumers.

VII. CONCLUSION
This paper deals with designing a local capacity market for providing system-wide and local flexibility. In this regard, the proposed local flexible capacity market (LFCM) consists of three stages. The first stage is related to pre-matching the bids of the DSOs and the TSO with the offers of flexible capacity sellers. At this stage, the LFCM operator accepts the offers and bids aiming to maximize the social welfare of the participants. At the second stage, the DSO checks as if the accepted offers and bids do not violate the security constraints of the network, and the results are sent to the third stage. Consequently, the third stage determines the accepted offers of each seller based on the results of the previous stage. As a result, providing system-wide flexibility would not jeopardize the security of the local network.
The proposed LFCM was implemented for a case study which is a typical weak Finnish rural overhead network. The results show that the local network needs significant upward flexibility, especially during peak-load hours. It is shown that the voltage magnitudes of local nodes can be regulated through the flexibility services purchased from the LFCM. The simulation results also demonstrate that the local flexibility sellers can sell considerable amounts of flexible capacities to the TSO, which increases their revenues significantly (up to 25 times more than the case in which the local market cannot contribute to the system-wide flexibility provision). Moreover, it was found that the provision of TSO-level flexibility does not result in voltage magnitudes violating their limits if these capacities are traded through the proposed LFCM. Finally, this research can be expanded in the future in the following directions: a) The future works can analyze how the system operators will perform the real-time control for the flexible resources of prosumers whose offers are accepted in the LFCM. b) The possibility of the provision of other system-wide flexibility services for frequency control, such as FFR and FRR, can be analyzed in the future. c) The offering strategies of prosumers who are participating in the proposed LFCM can also be a part of future research work. d) In the future, the possibilities of EVs to provide FCR services through both vehicle-to-grid and grid-to-vehicle modes and the related cost-effectiveness can be also studied further.