Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add split_pipe function #521

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/toolbox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ Topology Modification

.. autofunction:: pandapipes.drop_pipes

.. autofunction:: pandapipes.split_pipe

====================================
pandapower toolbox functions
====================================
Expand Down
10 changes: 10 additions & 0 deletions pandapipes/test/test_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,16 @@ def test_pit_extraction():
))


def test_split_pipe():
net = nw.simple_gas_networks.gas_tcross1()
net_org = net.deepcopy()
split_id = 0
p = 0.3
new_pipe, new_junc = pandapipes.split_pipe(net, split_id, p)
assert net.pipe.at[new_pipe, "length_km"] == net_org.pipe.at[split_id, "length_km"] * (1 - p)
assert net.pipe.at[split_id, "length_km"] == net_org.pipe.at[split_id, "length_km"] * p


def runpp_with_mark(net, **kwargs):
pandapower.runpp(net, **kwargs)
net['mark'] = "runpp"
Expand Down
64 changes: 64 additions & 0 deletions pandapipes/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,70 @@ def check_pressure_controllability(net, to_junction, controlled_junction):
# logger.info("dropped %d %s elements with %d switches" % (len(trafos), table, num_switches))


def split_pipe(net, pipe_idx, position_along_pipe=0.5, new_pipe_prefix="split"):
"""Splits a pipe into two pipes by inserting a new junction.

The new junction is located in a relative distance of `position_along_pipe` to the
from_junction. The length of the old (long) pipe is modified accordingly.
The new pipe segment is inserted between the newly created junction and the
to_junction. The initial pressure, height and coordinates of the new junction are interpolated.

:param net: pandapipes net that contains the pipe that will be split
:type net: pandapipesNet
:param pipe_idx: index of the pipe that will be split
:type pipe_idx: int
:param position_along_pipe: (>=0, <= 1), position where the pipe will be split, seen from
the from_junction (0 = at the from_junction, 1 = at the to_junction)
:type position_along_pipe: float
:param new_pipe_prefix: prefix for the new junction and new pipe names
:type new_pipe_prefix: str, default "split"
:return: id of newly created pipe and id of new junction
:rtype: int, int
"""
if new_pipe_prefix is not None and len(new_pipe_prefix):
new_pipe_prefix = new_pipe_prefix + "_"

# 1. insert new junction and interpolate values
old_fj = int(net.pipe.loc[pipe_idx, "from_junction"])
old_tj = int(net.pipe.loc[pipe_idx, "to_junction"])
p = position_along_pipe
assert (position_along_pipe >= 0) & (position_along_pipe <= 1), \
"Position along pipe is relative. It has to be >= 0 and <= 1."

param = ["pn_bar", "tfluid_k", "height_m"]
new_junction_parameters = (net.junction.loc[old_fj, param] * (1 - p)
+ net.junction.loc[old_tj, param] * p).to_dict()
new_junction_parameters["name"] = new_pipe_prefix + str(pipe_idx)

if not any(net.junction_geodata.loc[[old_fj, old_tj]].isna()): # if all coordinates exist
# interpolate coordinates
new_junction_parameters["geodata"] = ((net.junction_geodata.loc[old_fj, "x"] * (1-p) +
net.junction_geodata.loc[old_tj, "x"] * p),
(net.junction_geodata.loc[old_fj, "y"] * (1 - p) +
net.junction_geodata.loc[old_tj, "y"] * p))

nj = pandapipes.create_junction(net, **new_junction_parameters)

# 2. add new pipe between old junction and new junction
pipe_parameters = net.pipe.loc[pipe_idx].to_dict()
for rmv in ["name", "from_junction", "to_junction", "std_type"]:
pipe_parameters.pop(rmv)
pipe_parameters["length_km"] *= (1 - p)

new_pipe_idx = pandapipes.create_pipe_from_parameters(net,
from_junction=nj,
to_junction=old_tj,
name=new_pipe_prefix + str(pipe_idx),
**pipe_parameters)
net.pipe.loc[new_pipe_idx, "std_type"] = net.pipe.loc[pipe_idx, "std_type"]

# 3. reroute old pipe to new junction and adjust parameters
net.pipe.loc[pipe_idx, "to_junction"] = nj
net.pipe.loc[pipe_idx, "length_km"] *= p

return new_pipe_idx, nj


node_pit_indices = {
TABLE_IDX_NODE: "TABLE_IDX",
ELEMENT_IDX_NODE: "ELEMENT_IDX",
Expand Down