Skip to content

Commit

Permalink
first working version of circuit breaker relocation added
Browse files Browse the repository at this point in the history
in tools.set_circuit_breakers()
  • Loading branch information
nesnoj committed Dec 19, 2016
1 parent f8d7110 commit f5745a6
Showing 1 changed file with 59 additions and 28 deletions.
87 changes: 59 additions & 28 deletions dingo/grid/mv_grid/tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from dingo.core.network.stations import LVStationDingo
from dingo.core.network import CableDistributorDingo
from dingo.tools.geo import calc_geo_centre_point


def set_circuit_breakers(mv_grid, debug=False):
Expand All @@ -14,7 +17,7 @@ def set_circuit_breakers(mv_grid, debug=False):
circuit breaker which is open at normal operation.
Assuming a ring (route which is connected to the root node at either sides), the optimal position of a circuit
breaker is defined as the position (virtual cable) between two nodes where the conveyed current is minimal on
the route.
the route. Instead of the peak current, the peak load is used here (assuming a constant voltage).
The core of this function (calculation of the optimal circuit breaker position) is the same as in
dingo.grid.mv_grid.models.Route.calc_circuit_breaker_position but here it is
Expand All @@ -33,35 +36,63 @@ def set_circuit_breakers(mv_grid, debug=False):
# set init value
demand_diff_min = 10e6

# # remove old circuit breakers if existent
# if mv_grid.circuit_breakers_count > 0:
# for circ_breaker in mv_grid.circuit_breakers():
# # add new branch (bypass circuit breaker)
# nodes = mv_grid.graph_nodes_from_branch(circ_breaker.branch)
# # remove circuit breaker
# mv_grid._graph.remove_node(circ_breaker)
# iterate over all rings and circuit breakers
for ring, circ_breaker in zip(mv_grid.rings(include_root_node=False), mv_grid.circuit_breakers()):

for ring, circ_breaker in zip(mv_grid.rings(), mv_grid.circuit_breakers()):
print(ring, circ_breaker)
nodes_peak_load = []
# iterate over all nodes of ring
for node in ring:

# node is LV station -> get peak load
if isinstance(node, LVStationDingo):
nodes_peak_load.append(node.peak_load)

# node is cable distributor -> get all connected nodes of subtree using graph_nodes_from_subtree()
elif isinstance(node, CableDistributorDingo):
nodes_subtree = mv_grid.graph_nodes_from_subtree(node)
nodes_subtree_peak_load = 0
for node_subtree in nodes_subtree:

# node is LV station -> get peak load
if isinstance(node_subtree, LVStationDingo):
nodes_subtree_peak_load += node_subtree.peak_load

nodes_peak_load.append(nodes_subtree_peak_load)

else:
raise ValueError('Ring node has got invalid type.')

# calc optimal circuit breaker position

# set init value
demand_diff_min = 10e6

# check possible positions in route
for ctr in range(len(nodes_peak_load)):
# split route and calc demand difference
route_demand_part1 = sum(nodes_peak_load[0:ctr])
route_demand_part2 = sum(nodes_peak_load[ctr:len(nodes_peak_load)])
demand_diff = abs(route_demand_part1 - route_demand_part2)

if demand_diff <= demand_diff_min: # equality has to be respected, otherwise comparison stops when demand=0
demand_diff_min = demand_diff
position = ctr
else:
break

# relocate circuit breaker
node1 = ring[position-1]
node2 = ring[position]
circ_breaker.branch = mv_grid._graph.edge[node1][node2]['branch']
circ_breaker.branch_nodes = (node1, node2)
circ_breaker.branch.circuit_breaker = circ_breaker
circ_breaker.geo_data = calc_geo_centre_point(node1, node2)

if debug:
print('Ring:', ring)
print('Circuit breaker', circ_breaker, 'was relocated to edge', node1, '-', node2,
'(position on route=', position, ')')
print('Peak load sum:', sum(nodes_peak_load))
print('Peak loads:', nodes_peak_load)

# # check possible positions in route
# for ctr in range(len(self._nodes)):
# # split route and calc demand difference
# route_demand_part1 = sum([node.demand() for node in self._nodes[0:ctr]])
# route_demand_part2 = sum([node.demand() for node in self._nodes[ctr:len(self._nodes)]])
# demand_diff = abs(route_demand_part1 - route_demand_part2)
#
# if demand_diff < demand_diff_min:
# demand_diff_min = demand_diff
# position = ctr
#
# if debug:
# print('sum 1=', sum([node.demand() for node in self._nodes[0:position]]))
# print('sum 2=', sum([node.demand() for node in self._nodes[position:len(self._nodes)]]))
# print('Position of circuit breaker: ', self._nodes[position-1], '-', self._nodes[position],
# '(sumdiff=', demand_diff_min, ')')
#
# return position
print('=====> MV Circuit Breakers relocated')

0 comments on commit f5745a6

Please sign in to comment.