Skip to content

Commit

Permalink
Merge branch 'e2nIEE:develop' into release_0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
EPrade authored Nov 7, 2024
2 parents 123ccc8 + 941ee4d commit 712f1d0
Show file tree
Hide file tree
Showing 45 changed files with 604 additions and 482 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/run_tests_develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ jobs:
- name: Check docs for Python ${{ matrix.python-version }}
uses: e2nIEE/sphinx-action@master
with:
pre-build-command: "apt-get update -y && apt-get install -y git;
git --version;
python -m pip install --upgrade pip;
python -m pip install .[docs];"
pre-build-command: "python -m pip install --upgrade pip;
python -m pip install .[docs]"
build-command: "sphinx-build -b html source _build -W"
docs-folder: "doc/"
4 changes: 1 addition & 3 deletions .github/workflows/run_tests_master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ jobs:
- name: Check docs for Python ${{ matrix.python-version }}
uses: e2nIEE/sphinx-action@master
with:
pre-build-command: "apt-get update -y && apt-get install -y git;
git --version;
python -m pip install --upgrade pip;
pre-build-command: "python -m pip install --upgrade pip;
python -m pip install .[docs]"
build-command: "sphinx-build -b html source _build -W"
docs-folder: "doc/"
1 change: 1 addition & 0 deletions src/pandapipes/component_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
from pandapipes.component_models.flow_control_component import *
from pandapipes.component_models.mass_storage_component import *
from pandapipes.component_models.heat_consumer_component import *
from pandapipes.component_models.component_toolbox import *
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# 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 as np

from pandapipes.component_models.abstract_models.branch_wo_internals_models import \
BranchWOInternalsComponent
from pandapipes.idx_branch import LENGTH, K, TEXT, ALPHA
from pandapipes.idx_branch import LENGTH, K, TEXT, ALPHA, D, AREA

try:
import pandaplan.core.pplog as logging
Expand Down Expand Up @@ -60,6 +62,8 @@ def create_pit_branch_entries(cls, net, branch_pit):
branch_wzerolength_pit[:, K] = 1000
branch_wzerolength_pit[:, TEXT] = 293.15
branch_wzerolength_pit[:, ALPHA] = 0
branch_wzerolength_pit[:, D] = 0.1
branch_wzerolength_pit[:, AREA] = branch_wzerolength_pit[:, D] ** 2 * np.pi / 4
return branch_wzerolength_pit

@classmethod
Expand Down
103 changes: 61 additions & 42 deletions src/pandapipes/component_models/abstract_models/circulation_pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

import numpy as np

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
from pandapipes.idx_branch import D, AREA, ACTIVE
from pandapipes.idx_node import PINIT
from pandapipes.pf.pipeflow_setup import get_lookup
from pandapipes.component_models.abstract_models.branch_wzerolength_models import BranchWZeroLengthComponent
from pandapipes.component_models.component_toolbox import set_fixed_node_entries, standard_branch_wo_internals_result_lookup
from pandapipes.idx_branch import D, AREA, BRANCH_TYPE, CIRC, LOAD_VEC_BRANCHES_T, TO_NODE
from pandapipes.idx_node import MDOTSLACKINIT, VAR_MASS_SLACK, JAC_DERIV_MSL
from pandapipes.pf.pipeflow_setup import get_fluid
from pandapipes.pf.result_extraction import extract_branch_results_without_internals

try:
import pandaplan.core.pplog as logging
Expand All @@ -34,13 +33,23 @@ def get_component_input(cls):
def get_result_table(cls, net):
"""
Gets the result table.
:param net: The pandapipes network
:type net: pandapipesNet
:return: (columns, all_float) - the column names and whether they are all float type. Only
if False, returns columns as tuples also specifying the dtypes
:rtype: (list, bool)
"""
return ["mdot_flow_kg_per_s", "deltap_bar"], True
if get_fluid(net).is_gas:
output = ["v_from_m_per_s", "v_to_m_per_s", "v_mean_m_per_s", "p_from_bar", "p_to_bar", "t_from_k",
"t_to_k", "t_outlet_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s", "vdot_norm_m3_per_s",
"normfactor_from", "normfactor_to"]
else:
output = ["v_mean_m_per_s", "p_from_bar", "p_to_bar", "t_from_k", "t_to_k", "t_outlet_k", "mdot_from_kg_per_s",
"mdot_to_kg_per_s", "vdot_m3_per_s"]
output += ['deltat_k', 'qext_w']
return output, True

@classmethod
def active_identifier(cls):
Expand Down Expand Up @@ -72,10 +81,14 @@ 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
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
types = circ_pump_tbl.type.values
p_values = circ_pump_tbl.p_flow_bar.values
t_values = circ_pump_tbl.t_flow_k.values
index_p = set_fixed_node_entries(
net, node_pit, junction, types, p_values, cls.get_connected_node_type(), 'p')
set_fixed_node_entries(net, node_pit, junction, types, t_values, cls.get_connected_node_type(), 't')
node_pit[index_p, JAC_DERIV_MSL] = -1.
return circ_pump_tbl, p_values

@classmethod
def create_pit_branch_entries(cls, net, branch_pit):
Expand All @@ -90,7 +103,39 @@ def create_pit_branch_entries(cls, net, branch_pit):
circ_pump_pit = super().create_pit_branch_entries(net, branch_pit)
circ_pump_pit[:, D] = 0.1
circ_pump_pit[:, AREA] = circ_pump_pit[:, D] ** 2 * np.pi / 4
circ_pump_pit[:, ACTIVE] = False
circ_pump_pit[:, BRANCH_TYPE] = CIRC
return circ_pump_pit

@classmethod
def adaption_after_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options):
"""
Function which creates pit branch entries with a specific table.
:param net: The pandapipes network
:type net: pandapipesNet
:param branch_pit:
:type branch_pit:
:return: No Output.
"""
f, t = idx_lookups[cls.table_name()]
circ_pump_pit = branch_pit[f:t, :]
tn = circ_pump_pit[:, TO_NODE].astype(np.int32)
mask = node_pit[tn, VAR_MASS_SLACK].astype(bool)
node_pit[tn[~mask], MDOTSLACKINIT] = 0
return circ_pump_pit

@classmethod
def adaption_after_derivatives_thermal(cls, net, branch_pit, node_pit, idx_lookups, options):
"""
Function which creates pit branch entries with a specific table.
:param net: The pandapipes network
:type net: pandapipesNet
:param branch_pit:
:type branch_pit:
:return: No Output.
"""
f, t = idx_lookups[cls.table_name()]
circ_pump_pit = branch_pit[f:t, :]
circ_pump_pit[:, LOAD_VEC_BRANCHES_T] = 0

@classmethod
def extract_results(cls, net, options, branch_results, mode):
Expand All @@ -107,34 +152,8 @@ def extract_results(cls, net, options, branch_results, mode):
:type options:
:return: No Output.
"""
circ_pump_tbl = net[cls.table_name()]

if len(circ_pump_tbl) == 0:
return

res_table = net["res_" + cls.table_name()]

branch_pit = net['_pit']['branch']
node_pit = net["_pit"]["node"]

junction_lookup = get_lookup(net, "node", "index")[
cls.get_connected_node_type().table_name()]
fn_col, tn_col = cls.from_to_node_cols()
# get indices in internal structure for flow_junctions in circ_pump tables which are
# "active"
flow_junctions = circ_pump_tbl[tn_col].values
flow_nodes = junction_lookup[flow_junctions]
in_service = circ_pump_tbl.in_service.values
p_grids = np.isin(circ_pump_tbl.type.values, ["p", "pt"]) & in_service
sum_mass_flows, inverse_nodes, counts = get_mass_flow_at_nodes(net, node_pit, branch_pit,
flow_nodes[p_grids], cls)

# positive results mean that the circ_pump feeds in, negative means that the ext grid
# extracts (like a load)
res_table["mdot_flow_kg_per_s"].values[p_grids] = - (sum_mass_flows / counts)[inverse_nodes]

return_junctions = circ_pump_tbl[fn_col].values
return_nodes = junction_lookup[return_junctions]
required_results_hyd, required_results_ht = standard_branch_wo_internals_result_lookup(net)

deltap_bar = node_pit[flow_nodes, PINIT] - node_pit[return_nodes, PINIT]
res_table["deltap_bar"].values[in_service] = deltap_bar[in_service]
extract_branch_results_without_internals(net, branch_results, required_results_hyd, required_results_ht,
cls.table_name(), mode)
40 changes: 15 additions & 25 deletions src/pandapipes/component_models/circulation_pump_mass_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
# 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 as np
from numpy import dtype

from pandapipes.component_models.junction_component import Junction
from pandapipes.component_models.abstract_models.circulation_pump import CirculationPump
from pandapipes.idx_node import LOAD
from pandapipes.pf.internals_toolbox import _sum_by_group
from pandapipes.pf.pipeflow_setup import get_lookup
from pandapipes.pf.pipeflow_setup import get_net_option
from pandapipes.component_models.junction_component import Junction
from pandapipes.idx_branch import JAC_DERIV_DP, JAC_DERIV_DP1, JAC_DERIV_DM, MDOTINIT, \
LOAD_VEC_BRANCHES

try:
import pandaplan.core.pplog as logging
Expand Down Expand Up @@ -51,24 +48,17 @@ def active_identifier(cls):
return "in_service"

@classmethod
def create_pit_node_entries(cls, net, node_pit):
"""
Function which creates pit node entries.
def create_pit_branch_entries(cls, net, branch_pit):
circ_pump_pit = super().create_pit_branch_entries(net, branch_pit)
circ_pump_pit[:, MDOTINIT] = net[cls.table_name()].mdot_flow_kg_per_s.values

:param net: The pandapipes network
:type net: pandapipesNet
:param node_pit:
:type node_pit:
:return: No Output.
"""
circ_pump, _ = super().create_pit_node_entries(net, node_pit)

mf = np.nan_to_num(circ_pump.mdot_flow_kg_per_s.values)
mass_flow_loads = mf * circ_pump.in_service.values
juncts, loads_sum = _sum_by_group(get_net_option(net, "use_numba"),
circ_pump.return_junction.values, mass_flow_loads)
junction_idx_lookups = get_lookup(net, "node", "index")[
cls.get_connected_node_type().table_name()]
index = junction_idx_lookups[juncts]
node_pit[index, LOAD] += loads_sum
@classmethod
def adaption_after_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options):
# set all pressure derivatives to 0 and velocity to 1; load vector must be 0, as no change
# of velocity is allowed during the pipeflow iteration
circ_pump_pit = super().adaption_after_derivatives_hydraulic(net, branch_pit, node_pit, idx_lookups, options)
circ_pump_pit[:, JAC_DERIV_DP] = 0
circ_pump_pit[:, JAC_DERIV_DP1] = 0
circ_pump_pit[:, JAC_DERIV_DM] = 1
circ_pump_pit[:, LOAD_VEC_BRANCHES] = 0

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
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.junction_component import Junction
from pandapipes.idx_branch import JAC_DERIV_DP, JAC_DERIV_DP1, PL

try:
import pandaplan.core.pplog as logging
Expand All @@ -29,14 +29,8 @@ def get_component_input(cls):
:return:
:rtype:
"""
return [("name", dtype(object)),
("return_junction", "u4"),
("flow_junction", "u4"),
("p_flow_bar", "f8"),
("t_flow_k", "f8"),
("plift_bar", "f8"),
("in_service", 'bool'),
("type", dtype(object))]
return [("name", dtype(object)), ("return_junction", "u4"), ("flow_junction", "u4"), ("p_flow_bar", "f8"),
("t_flow_k", "f8"), ("plift_bar", "f8"), ("in_service", 'bool'), ("type", dtype(object))]

@classmethod
def active_identifier(cls):
Expand All @@ -47,19 +41,23 @@ def get_connected_node_type(cls):
return Junction

@classmethod
def create_pit_node_entries(cls, net, node_pit):
def create_pit_branch_entries(cls, net, branch_pit):
"""
Function which creates pit node entries.
Function which creates pit branch entries with a specific table.
:param net: The pandapipes network
:type net: pandapipesNet
:param node_pit:
:type node_pit:
:param branch_pit:
:type branch_pit:
:return: No Output.
"""
circ_pump, press = super().create_pit_node_entries(net, node_pit)
circ_pump_pit = super().create_pit_branch_entries(net, branch_pit)
circ_pump_pit[:, PL] = net[cls.table_name()]['plift_bar'].values
return circ_pump_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")
@classmethod
def adaption_after_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options):
# set all pressure derivatives to 0 and velocity to 1; load vector must be 0, as no change
# of velocity is allowed during the pipeflow iteration
circ_pump_pit = super().adaption_after_derivatives_hydraulic(net, branch_pit, node_pit, idx_lookups, options)
circ_pump_pit[:, JAC_DERIV_DP] = 1
circ_pump_pit[:, JAC_DERIV_DP1] = -1
Loading

0 comments on commit 712f1d0

Please sign in to comment.