From b404f53893782b305df6870c0672246ce645d919 Mon Sep 17 00:00:00 2001 From: eprade Date: Wed, 15 May 2024 10:56:55 +0200 Subject: [PATCH 01/14] -first changes for circ_pump_pressure --- .../abstract_models/circulation_pump.py | 2 +- .../circulation_pump_pressure_component.py | 22 ++++++++++++++----- src/pandapipes/create.py | 10 ++++----- src/pandapipes/plotting/pipeflow_results.py | 13 ++++++++--- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/pandapipes/component_models/abstract_models/circulation_pump.py b/src/pandapipes/component_models/abstract_models/circulation_pump.py index c678b44a2..bf0aa114a 100644 --- a/src/pandapipes/component_models/abstract_models/circulation_pump.py +++ b/src/pandapipes/component_models/abstract_models/circulation_pump.py @@ -72,7 +72,7 @@ def create_pit_node_entries(cls, net, node_pit): # 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 + press = circ_pump_tbl.p_setpoint_bar.values set_fixed_node_entries(net, node_pit, junction, circ_pump_tbl.type.values, press, circ_pump_tbl.t_flow_k.values, cls.get_connected_node_type()) return circ_pump_tbl, press diff --git a/src/pandapipes/component_models/circulation_pump_pressure_component.py b/src/pandapipes/component_models/circulation_pump_pressure_component.py index fb7ff2af3..6cdd39032 100644 --- a/src/pandapipes/component_models/circulation_pump_pressure_component.py +++ b/src/pandapipes/component_models/circulation_pump_pressure_component.py @@ -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))] @@ -59,7 +60,18 @@ def create_pit_node_entries(cls, net, node_pit): """ circ_pump, press = super().create_pit_node_entries(net, node_pit) - 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") + if circ_pump["setpoint"][0] == "flow": + + junction = circ_pump[cls.from_to_node_cols()[0]].values + p_setpoint = press - circ_pump.plift_bar.values + set_fixed_node_entries(net, node_pit, junction, circ_pump.type.values, p_setpoint, None, + cls.get_connected_node_type(), "p") + elif circ_pump["setpoint"][0] == "return": + junction = circ_pump[cls.from_to_node_cols()[1]].values + p_setpoint = press + circ_pump.plift_bar.values + set_fixed_node_entries(net, node_pit, junction, circ_pump.type.values, p_setpoint, None, + cls.get_connected_node_type(), "p") + else: + raise UserWarning( + "The setpoint can only be set to flow or return. Please enter\ + a valid string") diff --git a/src/pandapipes/create.py b/src/pandapipes/create.py index bf05b253a..e6c5c8653 100644 --- a/src/pandapipes/create.py +++ b/src/pandapipes/create.py @@ -701,9 +701,9 @@ 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 create_circ_pump_const_pressure(net, return_junction, flow_junction, p_setpoint_bar, plift_bar, + setpoint="flow" ,t_flow_k=None, 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 @@ -760,10 +760,10 @@ def create_circ_pump_const_pressure(net, return_junction, flow_junction, p_flow_ _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) diff --git a/src/pandapipes/plotting/pipeflow_results.py b/src/pandapipes/plotting/pipeflow_results.py index c3810043b..9c20aab98 100644 --- a/src/pandapipes/plotting/pipeflow_results.py +++ b/src/pandapipes/plotting/pipeflow_results.py @@ -89,13 +89,20 @@ def plot_pressure_profile(net, ax=None, x0_junctions=None, plot_pressure_control if pipes is None: pipes = net.pipe.index if x0_junctions is None: - x0_junctions = net.ext_grid[net.ext_grid.in_service].junction.values.tolist() - + x0_junctions = list(set(net.ext_grid[net.ext_grid.in_service].junction.values)|\ + set(net.circ_pump_pressure[net.circ_pump_pressure.in_service].junction.values)|\ + set(net.circ_pump_pressure[net.circ_pump_pressure.in_service].junction.values)) + unsupplied_junctions = list(top.unsupplied_junctions(net, slacks=set(x0_junctions))) + net.junction.in_service.loc[unsupplied_junctions] = False d = top.calc_distance_to_junctions(net, x0_junctions) - pipe_table = net.pipe[net.pipe.in_service & net.pipe.index.isin(pipes)] + in_service_junctions = net.junction[net.junction['in_service']==True].index + pipe_table = net.pipe[net.pipe.in_service & net.pipe.index.isin(pipes) & + net.pipe.from_junction.isin(in_service_junctions) & + net.pipe.to_junction.isin(in_service_junctions)] x = np.array([d.loc[pipe_table.from_junction].values, d.loc[pipe_table.to_junction].values]) + x0 y = np.array([net.res_junction.p_bar.loc[pipe_table.from_junction].values, net.res_junction.p_bar.loc[pipe_table.to_junction].values]) + net.junction.in_service.loc[unsupplied_junctions] = True linewidth = kwargs.get("linewidth", 1) ax.plot(x, y, linewidth=linewidth, color=pipe_color, **kwargs) From 111133a4ee1fa81dca1490c29e0d38432c50e6a2 Mon Sep 17 00:00:00 2001 From: eprade Date: Wed, 15 May 2024 13:05:08 +0200 Subject: [PATCH 02/14] -circ_pump_pressure working; added set_fixed_node_entries_circ_pump() so that pressure can be set at return flow junction while temperature is set at flow junction --- .../abstract_models/circulation_pump.py | 15 +++++++--- .../circulation_pump_pressure_component.py | 8 +++--- .../component_models/component_toolbox.py | 28 +++++++++++++++++++ 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/pandapipes/component_models/abstract_models/circulation_pump.py b/src/pandapipes/component_models/abstract_models/circulation_pump.py index bf0aa114a..9359e80d5 100644 --- a/src/pandapipes/component_models/abstract_models/circulation_pump.py +++ b/src/pandapipes/component_models/abstract_models/circulation_pump.py @@ -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 @@ -68,12 +68,19 @@ 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 = junction = circ_pump_tbl[cls.from_to_node_cols()[1]].values + if circ_pump_tbl["setpoint"][0] == "flow": + junction = circ_pump_tbl[cls.from_to_node_cols()[1]].values + elif circ_pump_tbl["setpoint"][0] == "return": + junction = circ_pump_tbl[cls.from_to_node_cols()[0]].values + else: + raise UserWarning( + "The setpoint can only be set to flow or return. Please enter\ + a valid string") # 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_setpoint_bar.values - set_fixed_node_entries(net, node_pit, junction, circ_pump_tbl.type.values, press, + set_fixed_node_entries_circ_pump(net, node_pit, junction, 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 diff --git a/src/pandapipes/component_models/circulation_pump_pressure_component.py b/src/pandapipes/component_models/circulation_pump_pressure_component.py index 6cdd39032..178f245bb 100644 --- a/src/pandapipes/component_models/circulation_pump_pressure_component.py +++ b/src/pandapipes/component_models/circulation_pump_pressure_component.py @@ -5,7 +5,7 @@ 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, set_fixed_node_entries_circ_pump from pandapipes.component_models.junction_component import Junction try: @@ -59,17 +59,17 @@ 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 = junction = circ_pump[cls.from_to_node_cols()[1]].values if circ_pump["setpoint"][0] == "flow": junction = circ_pump[cls.from_to_node_cols()[0]].values p_setpoint = press - circ_pump.plift_bar.values - set_fixed_node_entries(net, node_pit, junction, circ_pump.type.values, p_setpoint, None, + set_fixed_node_entries_circ_pump(net, node_pit, junction, flow_junction, circ_pump.type.values, p_setpoint, None, cls.get_connected_node_type(), "p") elif circ_pump["setpoint"][0] == "return": junction = circ_pump[cls.from_to_node_cols()[1]].values p_setpoint = press + circ_pump.plift_bar.values - set_fixed_node_entries(net, node_pit, junction, circ_pump.type.values, p_setpoint, None, + set_fixed_node_entries_circ_pump(net, node_pit, junction,flow_junction, circ_pump.type.values, p_setpoint, None, cls.get_connected_node_type(), "p") else: raise UserWarning( diff --git a/src/pandapipes/component_models/component_toolbox.py b/src/pandapipes/component_models/component_toolbox.py index 840929bc4..6d5ee5ffd 100644 --- a/src/pandapipes/component_models/component_toolbox.py +++ b/src/pandapipes/component_models/component_toolbox.py @@ -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"): + #adde 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 From 4a41762bd6bbf37364ca6d2a29a2f07d1669a524 Mon Sep 17 00:00:00 2001 From: eprade Date: Wed, 15 May 2024 15:26:16 +0200 Subject: [PATCH 03/14] -circ_pump_pressure tests working; --- src/pandapipes/component_models/component_toolbox.py | 2 +- src/pandapipes/create.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pandapipes/component_models/component_toolbox.py b/src/pandapipes/component_models/component_toolbox.py index 6d5ee5ffd..99171e433 100644 --- a/src/pandapipes/component_models/component_toolbox.py +++ b/src/pandapipes/component_models/component_toolbox.py @@ -164,7 +164,7 @@ def set_fixed_node_entries(net, node_pit, junctions, eg_types, p_values, t_value def set_fixed_node_entries_circ_pump(net, node_pit, junctions, flow_junctions, eg_types, p_values, t_values, node_comp, mode="all"): - #adde so that in case of setpoint for pressure at return junction can be set while setting temperature at flow junction + #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": diff --git a/src/pandapipes/create.py b/src/pandapipes/create.py index e6c5c8653..045f0c6f8 100644 --- a/src/pandapipes/create.py +++ b/src/pandapipes/create.py @@ -702,7 +702,7 @@ def create_pump_from_parameters(net, from_junction, to_junction, new_std_type_na def create_circ_pump_const_pressure(net, return_junction, flow_junction, p_setpoint_bar, plift_bar, - setpoint="flow" ,t_flow_k=None, type="auto", name=None, index=None, + 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 From 01b0836b1b1d05c6bd6445ed643240a7f259164e Mon Sep 17 00:00:00 2001 From: eprade Date: Fri, 17 May 2024 09:04:56 +0200 Subject: [PATCH 04/14] -changed circ_pump_mass; --- .../component_models/circulation_pump_mass_component.py | 3 ++- src/pandapipes/create.py | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/pandapipes/component_models/circulation_pump_mass_component.py b/src/pandapipes/component_models/circulation_pump_mass_component.py index 39cdb217b..d67f20fea 100644 --- a/src/pandapipes/component_models/circulation_pump_mass_component.py +++ b/src/pandapipes/component_models/circulation_pump_mass_component.py @@ -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))] diff --git a/src/pandapipes/create.py b/src/pandapipes/create.py index 045f0c6f8..e1a9600b0 100644 --- a/src/pandapipes/create.py +++ b/src/pandapipes/create.py @@ -770,7 +770,7 @@ def create_circ_pump_const_pressure(net, return_junction, flow_junction, p_setpo return index -def create_circ_pump_const_mass_flow(net, return_junction, flow_junction, p_flow_bar, +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): """ @@ -828,11 +828,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 From 8abf3d96ac9fa46723054b063c6b8ddd49dbb767 Mon Sep 17 00:00:00 2001 From: eprade Date: Tue, 21 May 2024 11:36:13 +0200 Subject: [PATCH 05/14] -changed format version, test and convert_format; --- src/pandapipes/__init__.py | 2 +- src/pandapipes/io/convert_format.py | 11 ++++++++++- .../api/release_cycle/release_control_test_network.py | 8 ++++---- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/pandapipes/__init__.py b/src/pandapipes/__init__.py index f8e6f2dec..e3c4ae048 100644 --- a/src/pandapipes/__init__.py +++ b/src/pandapipes/__init__.py @@ -3,7 +3,7 @@ # 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' +__format_version__ = '0.10.1' import pandas as pd import os diff --git a/src/pandapipes/io/convert_format.py b/src/pandapipes/io/convert_format.py index 07136dc08..f9e7c81ac 100644 --- a/src/pandapipes/io/convert_format.py +++ b/src/pandapipes/io/convert_format.py @@ -54,6 +54,10 @@ def _rename_columns(net): 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) + if "circ_pump_pressure" in net: + net["circ_pump_pressure"].rename(columns={"p_flow_bar": "p_setpoint_bar"}, inplace=True) + if "circ_pump_mass" in net: + net["circ_pump_mass"].rename(columns={"p_flow_bar": "p_setpoint_bar"}, inplace=True) def _add_missing_columns(net): @@ -64,7 +68,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: diff --git a/src/pandapipes/test/api/release_cycle/release_control_test_network.py b/src/pandapipes/test/api/release_cycle/release_control_test_network.py index c1ed060de..c6860f4df 100644 --- a/src/pandapipes/test/api/release_cycle/release_control_test_network.py +++ b/src/pandapipes/test/api/release_cycle/release_control_test_network.py @@ -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 @@ -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 From 8bf32d7bc2bc26aa3b742ab96f3987c886342b56 Mon Sep 17 00:00:00 2001 From: EPrade <90843651+EPrade@users.noreply.github.com> Date: Tue, 21 May 2024 11:38:00 +0200 Subject: [PATCH 06/14] Update CHANGELOG.rst --- CHANGELOG.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3e79f9eb2..fe838e15a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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 ------------------------------- From 8f998fb5302ef5972865be7273e57e21b9a68371 Mon Sep 17 00:00:00 2001 From: EPrade <90843651+EPrade@users.noreply.github.com> Date: Tue, 21 May 2024 11:38:37 +0200 Subject: [PATCH 07/14] Update __init__.py changed version --- src/pandapipes/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pandapipes/__init__.py b/src/pandapipes/__init__.py index e3c4ae048..03b635c7b 100644 --- a/src/pandapipes/__init__.py +++ b/src/pandapipes/__init__.py @@ -2,7 +2,7 @@ # 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' +__version__ = '0.10.1' __format_version__ = '0.10.1' import pandas as pd From b9f66ad34b1f1ce61c265617d12834fe60395c82 Mon Sep 17 00:00:00 2001 From: eprade Date: Tue, 21 May 2024 11:43:22 +0200 Subject: [PATCH 08/14] -adapted docstring; --- src/pandapipes/create.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pandapipes/create.py b/src/pandapipes/create.py index e1a9600b0..f0442fbc5 100644 --- a/src/pandapipes/create.py +++ b/src/pandapipes/create.py @@ -719,12 +719,14 @@ def create_circ_pump_const_pressure(net, return_junction, flow_junction, p_setpo :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 @@ -788,8 +790,8 @@ def create_circ_pump_const_mass_flow(net, return_junction, flow_junction, p_setp :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 From 4b1b90e37a1ea5ea04cbd1ec0ce388b2e8f44bee Mon Sep 17 00:00:00 2001 From: EPrade <90843651+EPrade@users.noreply.github.com> Date: Tue, 21 May 2024 13:02:43 +0200 Subject: [PATCH 09/14] Update circular_flow_in_a_district_heating_grid.ipynb -Updated tutorial --- tutorials/circular_flow_in_a_district_heating_grid.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/circular_flow_in_a_district_heating_grid.ipynb b/tutorials/circular_flow_in_a_district_heating_grid.ipynb index a06e23669..61a7c06ae 100644 --- a/tutorials/circular_flow_in_a_district_heating_grid.ipynb +++ b/tutorials/circular_flow_in_a_district_heating_grid.ipynb @@ -71,7 +71,7 @@ "metadata": {}, "outputs": [], "source": [ - "pp.create_circ_pump_const_mass_flow(net, return_junction=j3, flow_junction=j0, p_flow_bar=5,\n", + "pp.create_circ_pump_const_mass_flow(net, return_junction=j3, flow_junction=j0, p_setpoint_bar=5,\n", " mdot_flow_kg_per_s=20, t_flow_k=273.15+35)" ] }, From d619f86d65c1fb14019bce316b487d1887b4cd60 Mon Sep 17 00:00:00 2001 From: eprade Date: Wed, 22 May 2024 09:56:45 +0200 Subject: [PATCH 10/14] -changed circ_pump to enable multiple circ_pumps calculation and added tests --- .../abstract_models/circulation_pump.py | 23 ++-- .../circulation_pump_pressure_component.py | 47 +++++--- .../test_circ_pump_pressure.py | 109 ++++++++++++++++++ ...pump_pressure_return_and_flow_setpoint.csv | 9 ++ .../test_circ_pump_pressure_return_flow.csv | 6 + 5 files changed, 168 insertions(+), 26 deletions(-) create mode 100644 src/pandapipes/test/data/test_circ_pump_pressure_return_and_flow_setpoint.csv create mode 100644 src/pandapipes/test/data/test_circ_pump_pressure_return_flow.csv diff --git a/src/pandapipes/component_models/abstract_models/circulation_pump.py b/src/pandapipes/component_models/abstract_models/circulation_pump.py index 9359e80d5..a0f42e777 100644 --- a/src/pandapipes/component_models/abstract_models/circulation_pump.py +++ b/src/pandapipes/component_models/abstract_models/circulation_pump.py @@ -68,19 +68,22 @@ def create_pit_node_entries(cls, net, node_pit): """ circ_pump_tbl = net[cls.table_name()][net[cls.table_name()][cls.active_identifier()].values] - flow_junction = junction = circ_pump_tbl[cls.from_to_node_cols()[1]].values - if circ_pump_tbl["setpoint"][0] == "flow": - junction = circ_pump_tbl[cls.from_to_node_cols()[1]].values - elif circ_pump_tbl["setpoint"][0] == "return": - junction = circ_pump_tbl[cls.from_to_node_cols()[0]].values - else: - raise UserWarning( - "The setpoint can only be set to flow or return. Please enter\ - a valid string") + flow_junction = circ_pump_tbl[cls.from_to_node_cols()[1]].values + junctions = np.zeros(len(circ_pump_tbl),dtype=np.int8) + i=0 + for row in circ_pump_tbl["setpoint"]: + + if row == "flow": + junction = circ_pump_tbl[cls.from_to_node_cols()[1]].values + junctions[i] = junction[i] + elif row == "return": + junction = circ_pump_tbl[cls.from_to_node_cols()[0]].values + junctions[i] = junction[i] + i+=1 # 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_setpoint_bar.values - set_fixed_node_entries_circ_pump(net, node_pit, junction, flow_junction, circ_pump_tbl.type.values, press, + 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 diff --git a/src/pandapipes/component_models/circulation_pump_pressure_component.py b/src/pandapipes/component_models/circulation_pump_pressure_component.py index 178f245bb..3fbb0b0cb 100644 --- a/src/pandapipes/component_models/circulation_pump_pressure_component.py +++ b/src/pandapipes/component_models/circulation_pump_pressure_component.py @@ -1,7 +1,7 @@ # 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 @@ -59,19 +59,34 @@ 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 = junction = circ_pump[cls.from_to_node_cols()[1]].values - if circ_pump["setpoint"][0] == "flow": + 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=numpy.int8) + i = 0 + for row in circ_pump["setpoint"]: + + if row == "flow": + junction = circ_pump[cls.from_to_node_cols()[0]].values + junctions[i] = junction[i] + p_setpoint[i] = press[i] - circ_pump.plift_bar.values[i] + + elif row == "return": + junction = circ_pump[cls.from_to_node_cols()[1]].values + junctions[i] = junction[i] + p_setpoint[i] = press[i] + circ_pump.plift_bar.values[i] - junction = circ_pump[cls.from_to_node_cols()[0]].values - p_setpoint = press - circ_pump.plift_bar.values - set_fixed_node_entries_circ_pump(net, node_pit, junction, flow_junction, circ_pump.type.values, p_setpoint, None, - cls.get_connected_node_type(), "p") - elif circ_pump["setpoint"][0] == "return": - junction = circ_pump[cls.from_to_node_cols()[1]].values - p_setpoint = press + circ_pump.plift_bar.values - set_fixed_node_entries_circ_pump(net, node_pit, junction,flow_junction, circ_pump.type.values, p_setpoint, None, - cls.get_connected_node_type(), "p") - else: - raise UserWarning( - "The setpoint can only be set to flow or return. Please enter\ - a valid string") + i += 1 + 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") + # if circ_pump["setpoint"][0] == "flow": + # + # junction = circ_pump[cls.from_to_node_cols()[0]].values + # p_setpoint = press - circ_pump.plift_bar.values + # set_fixed_node_entries_circ_pump(net, node_pit, junction, flow_junction, circ_pump.type.values, p_setpoint, None, + # cls.get_connected_node_type(), "p") + # elif circ_pump["setpoint"][0] == "return": + # junction = circ_pump[cls.from_to_node_cols()[1]].values + # p_setpoint = press + circ_pump.plift_bar.values + # set_fixed_node_entries_circ_pump(net, node_pit, junction,flow_junction, circ_pump.type.values, p_setpoint, None, + # cls.get_connected_node_type(), "p") diff --git a/src/pandapipes/test/api/test_components/test_circ_pump_pressure.py b/src/pandapipes/test/api/test_components/test_circ_pump_pressure.py index bb24286f2..1aa40733e 100644 --- a/src/pandapipes/test/api/test_components/test_circ_pump_pressure.py +++ b/src/pandapipes/test/api/test_components/test_circ_pump_pressure.py @@ -59,3 +59,112 @@ def test_circulation_pump_constant_pressure(use_numba): assert np.all(v_diff < 0.01) assert np.all(mdot_diff < 0.01) assert np.all(deltap_diff < 0.01) + +@pytest.mark.parametrize("use_numba", [True, False]) +def test_circ_pump_pressure_return_flow(use_numba): + net = pandapipes.create_empty_network(fluid="water") + + j0 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=293.15, name="junction 0") + j1 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=293.15, name="junction 1") + j2 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=293.15, name="junction 2") + j3 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=293.15, name="junction 3") + + pandapipes.create_circ_pump_const_pressure(net, return_junction=j3, flow_junction=j0, p_setpoint_bar=7.5, + plift_bar=5, setpoint='flow', t_flow_k=273.15 + 35) + + pandapipes.create_heat_exchanger(net, from_junction=j1, to_junction=j2, diameter_m=200e-3, qext_w=100000) + + pandapipes.create_pipe_from_parameters(net, from_junction=j0, to_junction=j1, length_km=1, + diameter_m=200e-3, k_mm=.1, alpha_w_per_m2k=10, sections=5, text_k=283) + pandapipes.create_pipe_from_parameters(net, from_junction=j2, to_junction=j3, length_km=1, + diameter_m=200e-3, k_mm=.1, alpha_w_per_m2k=10, sections=5, text_k=283) + max_iter_hyd = 10 if use_numba else 10 + max_iter_therm = 4 if use_numba else 4 + pandapipes.pipeflow(net, max_iter_hyd=max_iter_hyd, max_iter_therm=max_iter_therm, + stop_condition="tol", friction_model="nikuradse", + mode="all", transient=False, nonlinear_method="automatic", + tol_p=1e-4, tol_m=1e-4, use_numba=use_numba) + data = pd.read_csv(os.path.join(data_path, "test_circ_pump_pressure_return_flow.csv"), sep=';') + + res_junction = net.res_junction + res_pipe = net.res_pipe.v_mean_m_per_s.values + res_pump = net.res_circ_pump_pressure + + p_diff = np.abs(1 - res_junction.p_bar.values / data['p'].dropna().values) + t_diff = np.abs(1 - res_junction.t_k.values / data['t'].dropna().values) + v_diff = np.abs(1 - res_pipe / data['v'].dropna().values) + mdot_diff = np.abs(1 - res_pump['mdot_flow_kg_per_s'].values / data['mdot'].dropna().values) + deltap_diff = np.abs(1 - res_pump['deltap_bar'].values / data['deltap'].dropna().values) + + assert np.all(p_diff < 0.01) + assert np.all(t_diff < 0.01) + assert np.all(v_diff < 0.01) + assert np.all(mdot_diff < 0.01) + assert np.all(deltap_diff < 0.01) + +@pytest.mark.parametrize("use_numba", [True, False]) +def test_circ_pump_pressure_return_and_flow_setpoint(use_numba): + """ + :param use_numba: + :type use_numba: + :return: + :rtype: + """ + net = pandapipes.create_empty_network(fluid="water") + #first closed loop + j0 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=293.15, name="junction 0") + j1 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=293.15, name="junction 1") + j2 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=293.15, name="junction 2") + j3 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=293.15, name="junction 3") + + pandapipes.create_circ_pump_const_pressure(net, return_junction=j3, flow_junction=j0, p_setpoint_bar=7.5, + plift_bar=5, setpoint='flow', t_flow_k=273.15 + 35) + + + pandapipes.create_heat_exchanger(net, from_junction=j1, to_junction=j2, diameter_m=200e-3, qext_w=100000) + + pandapipes.create_pipe_from_parameters(net, from_junction=j0, to_junction=j1, length_km=1, + diameter_m=200e-3, k_mm=.1, alpha_w_per_m2k=10, sections=5, text_k=283) + pandapipes.create_pipe_from_parameters(net, from_junction=j2, to_junction=j3, length_km=1, + diameter_m=200e-3, k_mm=.1, alpha_w_per_m2k=10, sections=5, text_k=283) + # second closed loop + j4 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=293.15, name="junction 0") + j5 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=293.15, name="junction 1") + j6 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=293.15, name="junction 2") + j7 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=293.15, name="junction 3") + + pandapipes.create_circ_pump_const_pressure(net, return_junction=j7, flow_junction=j4, p_setpoint_bar=5, + plift_bar=5, setpoint='return', t_flow_k=273.15 + 35) + + + pandapipes.create_heat_exchanger(net, from_junction=j5, to_junction=j6, diameter_m=200e-3, qext_w=100000) + + pandapipes.create_pipe_from_parameters(net, from_junction=j4, to_junction=j5, length_km=1, + diameter_m=200e-3, k_mm=.1, alpha_w_per_m2k=10, sections=5, text_k=283) + pandapipes.create_pipe_from_parameters(net, from_junction=j6, to_junction=j7, length_km=1, + diameter_m=200e-3, k_mm=.1, alpha_w_per_m2k=10, sections=5, text_k=283) + + max_iter_hyd = 10 if use_numba else 10 + max_iter_therm = 4 if use_numba else 4 + pandapipes.pipeflow(net, max_iter_hyd=max_iter_hyd, max_iter_therm=max_iter_therm, + stop_condition="tol", friction_model="nikuradse", + mode="all", transient=False, nonlinear_method="automatic", + tol_p=1e-4, tol_m=1e-4, use_numba=use_numba) + + data = pd.read_csv(os.path.join(data_path, "test_circ_pump_pressure_return_and_flow_setpoint.csv"), sep=';') + + res_junction = net.res_junction + res_pipe = net.res_pipe.v_mean_m_per_s.values + res_pump = net.res_circ_pump_pressure + + p_diff = np.abs(1 - res_junction.p_bar.values / data['p'].dropna().values) + t_diff = np.abs(1 - res_junction.t_k.values / data['t'].dropna().values) + v_diff = np.abs(1 - res_pipe / data['v'].dropna().values) + mdot_diff = np.abs(1 - res_pump['mdot_flow_kg_per_s'].values / data['mdot'].dropna().values) + deltap_diff = np.abs(1 - res_pump['deltap_bar'].values / data['deltap'].dropna().values) + + assert np.all(p_diff < 0.01) + assert np.all(t_diff < 0.01) + assert np.all(v_diff < 0.01) + assert np.all(mdot_diff < 0.01) + assert np.all(deltap_diff < 0.01) \ No newline at end of file diff --git a/src/pandapipes/test/data/test_circ_pump_pressure_return_and_flow_setpoint.csv b/src/pandapipes/test/data/test_circ_pump_pressure_return_and_flow_setpoint.csv new file mode 100644 index 000000000..edddd5b4b --- /dev/null +++ b/src/pandapipes/test/data/test_circ_pump_pressure_return_and_flow_setpoint.csv @@ -0,0 +1,9 @@ +p;t;v;mdot;deltap +7.50000;308.15000;2.55808;80.35489;5.50000 +4.75032;307.68389;2.55808;76.60166;5.00000 +4.75032;307.338616;2.43860 +2.00000;306.93421;2.43860 +10.00000;308.15000 +7.50031;307.66127 +7.50031;307.34896 +5.00000;306.87580 diff --git a/src/pandapipes/test/data/test_circ_pump_pressure_return_flow.csv b/src/pandapipes/test/data/test_circ_pump_pressure_return_flow.csv new file mode 100644 index 000000000..ac67d4cac --- /dev/null +++ b/src/pandapipes/test/data/test_circ_pump_pressure_return_flow.csv @@ -0,0 +1,6 @@ +p;t;v;mdot;deltap +7.50000;308.15000;2.55808;80.35489;5.50000 +4.75032;307.68389;2.55808 +4.75032;307.338616 +2.00000;306.93421 + From 92647ea6051db4d3de49e15b608bda8aee7d0ddf Mon Sep 17 00:00:00 2001 From: ocapron Date: Fri, 24 May 2024 15:56:54 +0200 Subject: [PATCH 11/14] 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"] --- src/pandapipes/io/convert_format.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/pandapipes/io/convert_format.py b/src/pandapipes/io/convert_format.py index f9e7c81ac..86cd625ed 100644 --- a/src/pandapipes/io/convert_format.py +++ b/src/pandapipes/io/convert_format.py @@ -48,16 +48,12 @@ 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) - if "circ_pump_pressure" in net: - net["circ_pump_pressure"].rename(columns={"p_flow_bar": "p_setpoint_bar"}, inplace=True) - if "circ_pump_mass" in net: - net["circ_pump_mass"].rename(columns={"p_flow_bar": "p_setpoint_bar"}, inplace=True) def _add_missing_columns(net): From daee1d032527b22cbca974f0d3a80673c7f47585 Mon Sep 17 00:00:00 2001 From: eprade Date: Tue, 28 May 2024 12:10:44 +0200 Subject: [PATCH 12/14] -enabled usage of old implementation and added deprecation warning --- src/pandapipes/create.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/pandapipes/create.py b/src/pandapipes/create.py index 6b96c4b01..8ae686b92 100644 --- a/src/pandapipes/create.py +++ b/src/pandapipes/create.py @@ -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 @@ -702,9 +703,26 @@ def create_pump_from_parameters(net, from_junction, to_junction, new_std_type_na return index +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): + 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 @@ -751,11 +769,10 @@ def create_circ_pump_const_pressure(net, return_junction, flow_junction, p_setpo :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, @@ -772,7 +789,7 @@ def create_circ_pump_const_pressure(net, return_junction, flow_junction, p_setpo return index - +@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): From b837e80c9100c89b81d2076c301ecf89b9f4e6dc Mon Sep 17 00:00:00 2001 From: eprade Date: Tue, 28 May 2024 16:13:15 +0200 Subject: [PATCH 13/14] -removed unused import --- .../component_models/circulation_pump_pressure_component.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pandapipes/component_models/circulation_pump_pressure_component.py b/src/pandapipes/component_models/circulation_pump_pressure_component.py index 3fbb0b0cb..ff0c83795 100644 --- a/src/pandapipes/component_models/circulation_pump_pressure_component.py +++ b/src/pandapipes/component_models/circulation_pump_pressure_component.py @@ -5,7 +5,7 @@ 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, set_fixed_node_entries_circ_pump +from pandapipes.component_models.component_toolbox import set_fixed_node_entries_circ_pump from pandapipes.component_models.junction_component import Junction try: From f65d04255a5430ef258d628a86b3d8716b0c68c0 Mon Sep 17 00:00:00 2001 From: eprade Date: Wed, 5 Jun 2024 10:20:51 +0200 Subject: [PATCH 14/14] -changed circ_pump p_set_point from loop to mask indexing; adapted tests --- .../abstract_models/circulation_pump.py | 19 +++++----- .../circulation_pump_pressure_component.py | 35 +++++++------------ .../component_models/component_toolbox.py | 2 +- .../test_circ_pump_pressure.py | 2 +- ...pump_pressure_return_and_flow_setpoint.csv | 8 ++--- .../test_circ_pump_pressure_return_flow.csv | 8 ++--- 6 files changed, 31 insertions(+), 43 deletions(-) diff --git a/src/pandapipes/component_models/abstract_models/circulation_pump.py b/src/pandapipes/component_models/abstract_models/circulation_pump.py index a0f42e777..118aae173 100644 --- a/src/pandapipes/component_models/abstract_models/circulation_pump.py +++ b/src/pandapipes/component_models/abstract_models/circulation_pump.py @@ -70,16 +70,15 @@ def create_pit_node_entries(cls, net, node_pit): flow_junction = circ_pump_tbl[cls.from_to_node_cols()[1]].values junctions = np.zeros(len(circ_pump_tbl),dtype=np.int8) - i=0 - for row in circ_pump_tbl["setpoint"]: - - if row == "flow": - junction = circ_pump_tbl[cls.from_to_node_cols()[1]].values - junctions[i] = junction[i] - elif row == "return": - junction = circ_pump_tbl[cls.from_to_node_cols()[0]].values - junctions[i] = junction[i] - i+=1 + + 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_setpoint_bar.values diff --git a/src/pandapipes/component_models/circulation_pump_pressure_component.py b/src/pandapipes/component_models/circulation_pump_pressure_component.py index ff0c83795..07054e485 100644 --- a/src/pandapipes/component_models/circulation_pump_pressure_component.py +++ b/src/pandapipes/component_models/circulation_pump_pressure_component.py @@ -61,32 +61,21 @@ def create_pit_node_entries(cls, net, node_pit): 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=numpy.int8) - i = 0 - for row in circ_pump["setpoint"]: + p_setpoint = numpy.zeros(len(circ_pump), dtype=float) - if row == "flow": - junction = circ_pump[cls.from_to_node_cols()[0]].values - junctions[i] = junction[i] - p_setpoint[i] = press[i] - circ_pump.plift_bar.values[i] + flow_col = cls.from_to_node_cols()[0] + return_col = cls.from_to_node_cols()[1] - elif row == "return": - junction = circ_pump[cls.from_to_node_cols()[1]].values - junctions[i] = junction[i] - p_setpoint[i] = press[i] + circ_pump.plift_bar.values[i] + 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] - i += 1 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") - # if circ_pump["setpoint"][0] == "flow": - # - # junction = circ_pump[cls.from_to_node_cols()[0]].values - # p_setpoint = press - circ_pump.plift_bar.values - # set_fixed_node_entries_circ_pump(net, node_pit, junction, flow_junction, circ_pump.type.values, p_setpoint, None, - # cls.get_connected_node_type(), "p") - # elif circ_pump["setpoint"][0] == "return": - # junction = circ_pump[cls.from_to_node_cols()[1]].values - # p_setpoint = press + circ_pump.plift_bar.values - # set_fixed_node_entries_circ_pump(net, node_pit, junction,flow_junction, circ_pump.type.values, p_setpoint, None, - # cls.get_connected_node_type(), "p") + diff --git a/src/pandapipes/component_models/component_toolbox.py b/src/pandapipes/component_models/component_toolbox.py index 99171e433..bb6d1a5b9 100644 --- a/src/pandapipes/component_models/component_toolbox.py +++ b/src/pandapipes/component_models/component_toolbox.py @@ -175,7 +175,7 @@ def set_fixed_node_entries_circ_pump(net, node_pit, junctions, flow_junctions, e 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 + junctions = flow_junctions mask = np.isin(eg_types, valid_types) if not np.any(mask): continue diff --git a/src/pandapipes/test/api/test_components/test_circ_pump_pressure.py b/src/pandapipes/test/api/test_components/test_circ_pump_pressure.py index 1aa40733e..d823476af 100644 --- a/src/pandapipes/test/api/test_components/test_circ_pump_pressure.py +++ b/src/pandapipes/test/api/test_components/test_circ_pump_pressure.py @@ -70,7 +70,7 @@ def test_circ_pump_pressure_return_flow(use_numba): j3 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=293.15, name="junction 3") pandapipes.create_circ_pump_const_pressure(net, return_junction=j3, flow_junction=j0, p_setpoint_bar=7.5, - plift_bar=5, setpoint='flow', t_flow_k=273.15 + 35) + plift_bar=5, setpoint='return', t_flow_k=273.15 + 35) pandapipes.create_heat_exchanger(net, from_junction=j1, to_junction=j2, diameter_m=200e-3, qext_w=100000) diff --git a/src/pandapipes/test/data/test_circ_pump_pressure_return_and_flow_setpoint.csv b/src/pandapipes/test/data/test_circ_pump_pressure_return_and_flow_setpoint.csv index edddd5b4b..50a8b9157 100644 --- a/src/pandapipes/test/data/test_circ_pump_pressure_return_and_flow_setpoint.csv +++ b/src/pandapipes/test/data/test_circ_pump_pressure_return_and_flow_setpoint.csv @@ -1,8 +1,8 @@ p;t;v;mdot;deltap -7.50000;308.15000;2.55808;80.35489;5.50000 -4.75032;307.68389;2.55808;76.60166;5.00000 -4.75032;307.338616;2.43860 -2.00000;306.93421;2.43860 +7.50000;308.15000;2.43860;76.60166;5.00000 +5.00031;307.66127;2.43860;76.60166;5.00000 +5.00031;307.34896;2.43860 +2.50000;306.87580;2.43860 10.00000;308.15000 7.50031;307.66127 7.50031;307.34896 diff --git a/src/pandapipes/test/data/test_circ_pump_pressure_return_flow.csv b/src/pandapipes/test/data/test_circ_pump_pressure_return_flow.csv index ac67d4cac..2ca4e890a 100644 --- a/src/pandapipes/test/data/test_circ_pump_pressure_return_flow.csv +++ b/src/pandapipes/test/data/test_circ_pump_pressure_return_flow.csv @@ -1,6 +1,6 @@ p;t;v;mdot;deltap -7.50000;308.15000;2.55808;80.35489;5.50000 -4.75032;307.68389;2.55808 -4.75032;307.338616 -2.00000;306.93421 +12.50000;308.15000;2.43860;76.60166;5 +10.00031;307.66127;2.43860 +10.00031;307.34896 +7.50000;306.87580