Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Change Log
=============
[0.10.1] -
-------------------------------
- [CHANGED] circ_pump_pressure to now have the option to chose a "setpoint" (flow or return junction) for the pressure to be set at


[0.10.0] - 2024-04-09
-------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/pandapipes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# and Energy System Technology (IEE), Kassel, and University of Kassel. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

__version__ = '0.10.0'
__format_version__ = '0.10.0'
__version__ = '0.10.1'
__format_version__ = '0.10.1'

import pandas as pd
import os
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pandapipes.component_models.abstract_models.branch_wzerolength_models import \
BranchWZeroLengthComponent
from pandapipes.component_models.component_toolbox import set_fixed_node_entries, \
get_mass_flow_at_nodes
get_mass_flow_at_nodes, set_fixed_node_entries_circ_pump
from pandapipes.idx_branch import D, AREA, ACTIVE
from pandapipes.idx_node import PINIT
from pandapipes.pf.pipeflow_setup import get_lookup
Expand Down Expand Up @@ -68,12 +68,21 @@ def create_pit_node_entries(cls, net, node_pit):
"""
circ_pump_tbl = net[cls.table_name()][net[cls.table_name()][cls.active_identifier()].values]

junction = circ_pump_tbl[cls.from_to_node_cols()[1]].values
flow_junction = circ_pump_tbl[cls.from_to_node_cols()[1]].values
junctions = np.zeros(len(circ_pump_tbl),dtype=np.int8)

flow_col = cls.from_to_node_cols()[1]
return_col = cls.from_to_node_cols()[0]

flow_mask = circ_pump_tbl["setpoint"] == "flow"
return_mask = circ_pump_tbl["setpoint"] == "return"

junctions[flow_mask] = circ_pump_tbl[flow_col][flow_mask]
junctions[return_mask] = circ_pump_tbl[return_col][return_mask]
# TODO: there should be a warning, if any p_bar value is not given or any of the types does
# not contain "p", as this should not be allowed for this component
press = circ_pump_tbl.p_flow_bar.values
set_fixed_node_entries(net, node_pit, junction, circ_pump_tbl.type.values, press,
press = circ_pump_tbl.p_setpoint_bar.values
set_fixed_node_entries_circ_pump(net, node_pit, junctions, flow_junction, circ_pump_tbl.type.values, press,
circ_pump_tbl.t_flow_k.values, cls.get_connected_node_type())
return circ_pump_tbl, press

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ def get_component_input(cls):
return [("name", dtype(object)),
("return_junction", "u4"),
("flow_junction", "u4"),
("p_flow_bar", "f8"),
("p_setpoint_bar", "f8"),
("t_flow_k", "f8"),
("setpoint", "str"),
("mdot_flow_kg_per_s", "f8"),
("in_service", 'bool'),
("type", dtype(object))]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright (c) 2020-2024 by Fraunhofer Institute for Energy Economics
# and Energy System Technology (IEE), Kassel, and University of Kassel. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

import numpy
from numpy import dtype

from pandapipes.component_models.abstract_models.circulation_pump import CirculationPump
from pandapipes.component_models.component_toolbox import set_fixed_node_entries
from pandapipes.component_models.component_toolbox import set_fixed_node_entries_circ_pump
from pandapipes.component_models.junction_component import Junction

try:
Expand All @@ -32,9 +32,10 @@ def get_component_input(cls):
return [("name", dtype(object)),
("return_junction", "u4"),
("flow_junction", "u4"),
("p_flow_bar", "f8"),
("p_setpoint_bar", "f8"),
("t_flow_k", "f8"),
("plift_bar", "f8"),
("setpoint","str"),
("in_service", 'bool'),
("type", dtype(object))]

Expand All @@ -58,8 +59,23 @@ def create_pit_node_entries(cls, net, node_pit):
:return: No Output.
"""
circ_pump, press = super().create_pit_node_entries(net, node_pit)
flow_junction = circ_pump[cls.from_to_node_cols()[1]].values
junctions = numpy.zeros(len(circ_pump), dtype=numpy.int8)
p_setpoint = numpy.zeros(len(circ_pump), dtype=float)

flow_col = cls.from_to_node_cols()[0]
return_col = cls.from_to_node_cols()[1]

flow_mask = circ_pump["setpoint"] == "flow"
return_mask = circ_pump["setpoint"] == "return"

junctions[flow_mask] = circ_pump[flow_col][flow_mask]
junctions[return_mask] = circ_pump[return_col][return_mask]

p_setpoint[flow_mask] = press[flow_mask] - circ_pump.plift_bar.values[flow_mask]
p_setpoint[return_mask] = press[return_mask] + circ_pump.plift_bar.values[return_mask]

set_fixed_node_entries_circ_pump(net, node_pit, junctions, flow_junction, circ_pump.type.values,
p_setpoint, None,
cls.get_connected_node_type(), "p")

junction = circ_pump[cls.from_to_node_cols()[0]].values
p_in = press - circ_pump.plift_bar.values
set_fixed_node_entries(net, node_pit, junction, circ_pump.type.values, p_in, None,
cls.get_connected_node_type(), "p")
28 changes: 28 additions & 0 deletions src/pandapipes/component_models/component_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,34 @@ def set_fixed_node_entries(net, node_pit, junctions, eg_types, p_values, t_value
else:
val_col, type_col, eg_count_col, typ, valid_types, values = \
TINIT, NODE_TYPE_T, EXT_GRID_OCCURENCE_T, T, ["t", "pt"], t_values

mask = np.isin(eg_types, valid_types)
if not np.any(mask):
continue
use_numba = get_net_option(net, "use_numba")
juncts, press_sum, number = _sum_by_group(use_numba, junctions[mask], values[mask],
np.ones_like(values[mask], dtype=np.int32))
index = junction_idx_lookups[juncts]
node_pit[index, val_col] = (node_pit[index, val_col] * node_pit[index, eg_count_col]
+ press_sum) / (number + node_pit[index, eg_count_col])
node_pit[index, type_col] = typ
node_pit[index, eg_count_col] += number


def set_fixed_node_entries_circ_pump(net, node_pit, junctions, flow_junctions, eg_types, p_values, t_values, node_comp,
mode="all"):
#added so that in case of setpoint for pressure at return junction can be set while setting temperature at flow junction
junction_idx_lookups = get_lookup(net, "node", "index")[node_comp.table_name()]
for eg_type in ("p", "t"):
if eg_type not in mode and mode != "all":
continue
if eg_type == "p":
val_col, type_col, eg_count_col, typ, valid_types, values = \
PINIT, NODE_TYPE, EXT_GRID_OCCURENCE, P, ["p", "pt"], p_values
else:
val_col, type_col, eg_count_col, typ, valid_types, values = \
TINIT, NODE_TYPE_T, EXT_GRID_OCCURENCE_T, T, ["t", "pt"], t_values
junctions = flow_junctions
mask = np.isin(eg_types, valid_types)
if not np.any(mask):
continue
Expand Down
51 changes: 35 additions & 16 deletions src/pandapipes/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from pandapipes.std_types.std_type_class import regression_function, PumpStdType
from pandapipes.std_types.std_types import add_basic_std_types, create_pump_std_type, \
load_std_type
import warnings

try:
import pandaplan.core.pplog as logging
Expand Down Expand Up @@ -702,9 +703,26 @@ def create_pump_from_parameters(net, from_junction, to_junction, new_std_type_na
return index


def create_circ_pump_const_pressure(net, return_junction, flow_junction, p_flow_bar, plift_bar,
t_flow_k=None, type="auto", name=None, index=None,
in_service=True, **kwargs):
def handle_deprecated_args_circ_pump(func):
def wrapper(*args, **kwargs):

if 'p_setpoint_bar' not in kwargs and 'p_flow_bar' in kwargs:

kwargs['p_setpoint_bar'] = kwargs.pop('p_flow_bar')
warnings.warn(
"The 'p_flow_bar' argument is deprecated and will be removed in a future version. "
"Please use 'p_setpoint_bar' instead.",
DeprecationWarning
)

return func(*args, **kwargs)

return wrapper

@handle_deprecated_args_circ_pump
def create_circ_pump_const_pressure(net, return_junction, flow_junction, p_setpoint_bar, plift_bar,
t_flow_k=None, setpoint="flow", type="auto",
name=None, index=None, in_service=True,**kwargs):
"""
Adds one circulation pump with a constant pressure lift in table net["circ_pump_pressure"]. \n
A circulation pump is a component that sets the pressure at its outlet (flow junction) and
Expand All @@ -720,12 +738,14 @@ def create_circ_pump_const_pressure(net, return_junction, flow_junction, p_flow_
:type return_junction: int
:param flow_junction: ID of the junction on the other side which the pump will be connected with
:type flow_junction: int
:param p_flow_bar: Pressure set point at the flow junction
:type p_flow_bar: float
:param p_setpoint_bar: Pressure set point at the set junction
:type p_setpoint_bar: float
:param plift_bar: Pressure lift induced by the pump
:type plift_bar: float
:param t_flow_k: Temperature set point at the flow junction
:type t_flow_k: float, default None
:param setpoint: set point for the pressure; either "flow" or "return" junction
:type setpoint: string, default "flow"
:param type: The pump type denotes the values that are fixed:\n
- "auto": Will automatically assign one of the following types based on the input for \
p_bar and t_k \n
Expand All @@ -749,29 +769,28 @@ def create_circ_pump_const_pressure(net, return_junction, flow_junction, p_flow_
:rtype: int

:Example:
>>> create_circ_pump_const_pressure(net, 0, 1, p_flow_bar=5, plift_bar=2,
>>> create_circ_pump_const_pressure(net, 0, 1, p_setpoint_bar=5, plift_bar=2,
>>> t_flow_k=350, type="p")

"""

add_new_component(net, CirculationPumpPressure)

index = _get_index_with_check(net, "circ_pump_pressure", index,
name="circulation pump with constant pressure")
_check_branch(net, "circulation pump with constant pressure", index, return_junction,
flow_junction)

type = _auto_ext_grid_type(p_flow_bar, t_flow_k, type, CirculationPumpPressure)
type = _auto_ext_grid_type(p_setpoint_bar, t_flow_k, type, CirculationPumpPressure)

v = {"name": name, "return_junction": return_junction, "flow_junction": flow_junction,
"p_flow_bar": p_flow_bar, "t_flow_k": t_flow_k, "plift_bar": plift_bar, "type": type,
"p_setpoint_bar": p_setpoint_bar, "t_flow_k": t_flow_k, "plift_bar": plift_bar , "setpoint":setpoint,"type": type,
"in_service": bool(in_service)}
_set_entries(net, "circ_pump_pressure", index, **v, **kwargs)

return index


def create_circ_pump_const_mass_flow(net, return_junction, flow_junction, p_flow_bar,
@handle_deprecated_args_circ_pump
def create_circ_pump_const_mass_flow(net, return_junction, flow_junction, p_setpoint_bar,
mdot_flow_kg_per_s, t_flow_k=None, type="auto", name=None,
index=None, in_service=True, **kwargs):
"""
Expand All @@ -789,8 +808,8 @@ def create_circ_pump_const_mass_flow(net, return_junction, flow_junction, p_flow
:type return_junction: int
:param flow_junction: ID of the junction on the other side which the pump will be connected with
:type flow_junction: int
:param p_flow_bar: Pressure set point at the flow junction
:type p_flow_bar: float
:param p_setpoint_bar: Pressure set point at the set junction
:type p_setpoint_bar: float
:param mdot_flow_kg_per_s: Constant mass flow, which is transported through the pump
:type mdot_flow_kg_per_s: float
:param t_flow_k: Temperature set point at the flow junction
Expand Down Expand Up @@ -829,11 +848,11 @@ def create_circ_pump_const_mass_flow(net, return_junction, flow_junction, p_flow
_check_branch(net, "circulation pump with constant mass flow", index, return_junction,
flow_junction)

type = _auto_ext_grid_type(p_flow_bar, t_flow_k, type, CirculationPumpMass)
type = _auto_ext_grid_type(p_setpoint_bar, t_flow_k, type, CirculationPumpMass)

v = {"name": name, "return_junction": return_junction, "flow_junction": flow_junction,
"p_flow_bar": p_flow_bar, "t_flow_k": t_flow_k, "mdot_flow_kg_per_s": mdot_flow_kg_per_s,
"type": type, "in_service": bool(in_service)}
"p_setpoint_bar": p_setpoint_bar, "t_flow_k": t_flow_k, "mdot_flow_kg_per_s": mdot_flow_kg_per_s,
"setpoint":"flow", "type": type, "in_service": bool(in_service)}
_set_entries(net, "circ_pump_mass", index, **v, **kwargs)

return index
Expand Down
13 changes: 9 additions & 4 deletions src/pandapipes/io/convert_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def _rename_columns(net):
for comp in [CirculationPumpMass, CirculationPumpPressure]:
cp_tbl = comp.table_name()
if cp_tbl in net:
old_cols = ["from_junction", "to_junction", "mdot_kg_per_s", "p_bar", "t_k"]
new_cols = list(comp.from_to_node_cols()) + ["mdot_flow_kg_per_s", "p_flow_bar",
"t_flow_k"]
old_cols = ["from_junction", "to_junction", "mdot_kg_per_s", "p_bar","p_flow_bar", "t_k"]
new_cols = list(comp.from_to_node_cols()) + ["mdot_flow_kg_per_s",
"p_setpoint_bar","p_setpoint_bar","t_flow_k"]
for old_col, new_col in list(zip(old_cols, new_cols)):
if old_col in net[cp_tbl].columns and new_col not in net[cp_tbl].columns:
net[cp_tbl].rename(columns={old_col: new_col}, inplace=True)
Expand All @@ -64,7 +64,12 @@ def _add_missing_columns(net):
net.controller.at[ctrl.name, 'initial_run'] = ctrl['object'].initial_run
else:
net.controller.at[ctrl.name, 'initial_run'] = ctrl['object'].initial_pipeflow

if "circ_pump_pressure" in net:
if "setpoint" not in net.circ_pump_pressure:
net.circ_pump_pressure.insert(6, 'setpoint', "flow")
if "circ_pump_mass" in net: #Why are circ pumps in some versions existing and in some not?
if "setpoint" not in net.circ_pump_mass:
net.circ_pump_mass.insert(6, 'setpoint', "flow")

def _rename_attributes(net):
if "std_type" in net and "std_types" not in net:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ def release_control_test_network(max_iter_hyd, save=False):

# circulation pump mass
pp.create_circ_pump_const_mass_flow(
net, return_junction=3, flow_junction=4, p_flow_bar=6, mdot_flow_kg_per_s=1, t_flow_k=290,
net, return_junction=3, flow_junction=4, p_setpoint_bar=6, mdot_flow_kg_per_s=1, t_flow_k=290,
name="Circ. Pump Mass", index=None, in_service=True, type="pt")

# circulation pump pressure
pp.create_circ_pump_const_pressure(
net, return_junction=11, flow_junction=5, p_flow_bar=5, plift_bar=2, t_flow_k=290,
net, return_junction=11, flow_junction=5, p_setpoint_bar=5, plift_bar=2, t_flow_k=290,
name="Circ. Pump Pressure", index=None, in_service=True, type="pt")

# heat exchanger
Expand Down Expand Up @@ -222,12 +222,12 @@ def release_control_test_network_water(max_iter_hyd, save=False):

# circulation pump mass
pp.create_circ_pump_const_mass_flow(
net, return_junction=3, flow_junction=4, p_flow_bar=6, mdot_flow_kg_per_s=0.2, t_flow_k=290,
net, return_junction=3, flow_junction=4, p_setpoint_bar=6, mdot_flow_kg_per_s=0.2, t_flow_k=290,
name="Circ. Pump Mass", index=None, in_service=True, type="pt")

# circulation pump pressure
pp.create_circ_pump_const_pressure(
net, return_junction=11, flow_junction=5, p_flow_bar=5, plift_bar=2, t_flow_k=290,
net, return_junction=11, flow_junction=5, p_setpoint_bar=5, plift_bar=2, t_flow_k=290,
name="Circ. Pump Pressure", index=None, in_service=True, type="pt")

# heat exchanger
Expand Down
Loading