Skip to content

Commit

Permalink
add function for reverse links direction
Browse files Browse the repository at this point in the history
  • Loading branch information
GalPerelman committed Aug 13, 2023
1 parent 94b0e87 commit 6a47c81
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions wntr/morph/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"""
import logging
import copy

import wntr.network
from wntr.network.elements import Reservoir, Pipe

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -209,8 +211,7 @@ def _split_or_break_pipe(wn, pipe_name_to_split, new_pipe_name,
# Identify the segment that cross the split point and compute the new
# junction coordinates
for segment in segments:
if (segment['subtotal'] + segment['length'] >= split_length
and segment['subtotal'] < split_length):
if segment['subtotal'] + segment['length'] >= split_length > segment['subtotal']:
split_at = ((split_length - segment['subtotal'])
/ segment['length'])
x0 = segment['start_pos'][0]
Expand Down Expand Up @@ -268,4 +269,17 @@ def _split_or_break_pipe(wn, pipe_name_to_split, new_pipe_name,
logger.warn('You are splitting a pipe with a check valve. The new \
pipe will not have a check valve.')

return wn2
return wn2


def reverse_link(wn: wntr.network.WaterNetworkModel, link_name: str) -> wntr.network.WaterNetworkModel:
link = wn.get_link(link_name)
start_node = link.start_node
end_node = link.end_node
vertices = link.vertices

link.start_node = end_node
link.end_node = start_node
link.vertices = vertices[::-1]

return wn

0 comments on commit 6a47c81

Please sign in to comment.