Skip to content

Commit

Permalink
Merge pull request e2nIEE#540 from dlohmeier/connectivity_separate
Browse files Browse the repository at this point in the history
Separation of thermal connectivity check
  • Loading branch information
dlohmeier authored Sep 1, 2023
2 parents 98d8cdf + 926bc32 commit 513ef67
Show file tree
Hide file tree
Showing 23 changed files with 498 additions and 330 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Change Log
- [ADDED] multiple creation of heat exchanger
- [ADDED] support Python 3.11 (now included in test pipeline)
- [CHANGED] dropped support for Python 3.7 (no longer included in test pipeline)
- [CHANGED] connectivity check now separated by hydraulics and heat_transfer calculation, so that also results can differ in some rows (NaN or not)
- [CHANGED] dynamic creation of lookups for getting pit as pandas tables
- [FIXED] in STANET converter: bug fix for heat exchanger creation and external temperatures of pipes added
- [REMOVED] broken travis badge removed from readme
Expand Down
8 changes: 3 additions & 5 deletions pandapipes/component_models/abstract_models/base_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def init_results(cls, net):
return res_table

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
def extract_results(cls, net, options, branch_results, mode):
"""
Function that extracts certain results.
Expand All @@ -43,10 +43,8 @@ def extract_results(cls, net, options, branch_results, nodes_connected, branches
:type options:
:param branch_results:
:type branch_results:
:param nodes_connected:
:type nodes_connected:
:param branches_connected:
:type branches_connected:
:param mode:
:type mode:
:return: No Output.
"""
raise NotImplementedError
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,5 @@ def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
raise NotImplementedError

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
def extract_results(cls, net, options, branch_results, mode):
raise NotImplementedError
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def get_internal_pipe_number(cls, net):
return np.array(net[cls.table_name()].sections.values)

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
def extract_results(cls, net, options, branch_results, mode):
raise NotImplementedError

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ def get_connected_node_type(cls):
raise NotImplementedError

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
def extract_results(cls, net, options, branch_results, mode):
raise NotImplementedError
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def create_pit_branch_entries(cls, net, branch_pit):
return branch_wzerolength_pit

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
def extract_results(cls, net, options, branch_results, mode):
raise NotImplementedError

@classmethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,12 @@ def calculate_temperature_lift(cls, net, pipe_pit, node_pit):
raise NotImplementedError

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
def extract_results(cls, net, options, branch_results, mode):
"""
Function that extracts certain results.
:param nodes_connected:
:type nodes_connected:
:param branches_connected:
:type branches_connected:
:param mode:
:type mode:
:param branch_results:
:type branch_results:
:param net: The pandapipes network
Expand Down
12 changes: 5 additions & 7 deletions pandapipes/component_models/abstract_models/const_flow_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,12 @@ def create_pit_node_entries(cls, net, node_pit):
node_pit[index, LOAD] += loads_sum

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
def extract_results(cls, net, options, branch_results, mode):
"""
Function that extracts certain results.
:param nodes_connected:
:type nodes_connected:
:param branches_connected:
:type branches_connected:
:param mode:
:type mode:
:param branch_results:
:type branch_results:
:param net: The pandapipes network
Expand All @@ -74,8 +72,8 @@ def extract_results(cls, net, options, branch_results, nodes_connected, branches
is_loads = loads.in_service.values
fj, tj = get_lookup(net, "node", "from_to")[cls.get_connected_node_type().table_name()]
junct_pit = net["_pit"]["node"][fj:tj, :]
nodes_connected = get_lookup(net, "node", "active")[fj:tj]
is_juncts = np.isin(loads.junction.values, junct_pit[nodes_connected, ELEMENT_IDX])
nodes_connected_hyd = get_lookup(net, "node", "active_hydraulics")[fj:tj]
is_juncts = np.isin(loads.junction.values, junct_pit[nodes_connected_hyd, ELEMENT_IDX])

is_calc = is_loads & is_juncts
res_table["mdot_kg_per_s"].values[is_calc] = loads.mdot_kg_per_s.values[is_calc] \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ def create_pit_node_entries(cls, net, node_pit):
raise NotImplementedError

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
def extract_results(cls, net, options, branch_results, mode):
raise NotImplementedError
2 changes: 1 addition & 1 deletion pandapipes/component_models/abstract_models/node_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ def get_result_table(cls, net):
raise NotImplementedError

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
def extract_results(cls, net, options, branch_results, mode):
raise NotImplementedError
21 changes: 21 additions & 0 deletions pandapipes/component_models/component_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
import pandas as pd

from pandapipes import get_fluid
from pandapipes.constants import NORMAL_PRESSURE, TEMP_GRADIENT_KPM, AVG_TEMPERATURE_K, \
HEIGHT_EXPONENT
from pandapipes.idx_branch import LOAD_VEC_NODES, FROM_NODE, TO_NODE
Expand Down Expand Up @@ -177,3 +178,23 @@ def get_mass_flow_at_nodes(net, node_pit, branch_pit, eg_nodes, comp):
raise UserWarning("In component %s: Something went wrong with the mass flow balance. "
"Please report this error at github." % comp.__name__)
return sum_mass_flows, inverse_nodes, counts


def standard_branch_wo_internals_result_lookup(net):
required_results_hyd = [
("p_from_bar", "p_from"), ("p_to_bar", "p_to"), ("mdot_to_kg_per_s", "mf_to"),
("mdot_from_kg_per_s", "mf_from"), ("vdot_norm_m3_per_s", "vf"), ("lambda", "lambda"),
("reynolds", "reynolds")
]
required_results_ht = [("t_from_k", "temp_from"), ("t_to_k", "temp_to")]

if get_fluid(net).is_gas:
required_results_hyd.extend([
("v_from_m_per_s", "v_gas_from"), ("v_to_m_per_s", "v_gas_to"),
("v_mean_m_per_s", "v_gas_mean"), ("normfactor_from", "normfactor_from"),
("normfactor_to", "normfactor_to")
])
else:
required_results_hyd.extend([("v_mean_m_per_s", "v_mps")])

return required_results_hyd, required_results_ht
8 changes: 3 additions & 5 deletions pandapipes/component_models/ext_grid_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,18 @@ def create_pit_node_entries(cls, net, node_pit):
return ext_grids, press

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
def extract_results(cls, net, options, branch_results, mode):
"""
Function that extracts certain results.
:param nodes_connected:
:type nodes_connected:
:param branches_connected:
:type branches_connected:
:param branch_results:
:type branch_results:
:param net: The pandapipes network
:type net: pandapipesNet
:param options:
:type options:
:param mode:
:type mode:
:return: No Output.
"""
ext_grids = net[cls.table_name()]
Expand Down
24 changes: 6 additions & 18 deletions pandapipes/component_models/flow_control_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import numpy as np
from numpy import dtype

from pandapipes.component_models.junction_component import Junction
from pandapipes.component_models.abstract_models import BranchWZeroLengthComponent, get_fluid
from pandapipes.component_models.component_toolbox import standard_branch_wo_internals_result_lookup
from pandapipes.component_models.junction_component import Junction
from pandapipes.idx_branch import D, AREA, TL, JAC_DERIV_DP, JAC_DERIV_DP1, JAC_DERIV_DV, VINIT, \
RHO, LOAD_VEC_BRANCHES, ELEMENT_IDX
from pandapipes.pf.result_extraction import extract_branch_results_without_internals
Expand Down Expand Up @@ -83,24 +84,11 @@ def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
branch_component_pit[:, TL] = 0

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
required_results = [
("p_from_bar", "p_from"), ("p_to_bar", "p_to"), ("t_from_k", "temp_from"),
("t_to_k", "temp_to"), ("mdot_to_kg_per_s", "mf_to"), ("mdot_from_kg_per_s", "mf_from"),
("vdot_norm_m3_per_s", "vf"), ("lambda", "lambda"), ("reynolds", "reynolds")
]

if get_fluid(net).is_gas:
required_results.extend([
("v_from_m_per_s", "v_gas_from"), ("v_to_m_per_s", "v_gas_to"),
("v_mean_m_per_s", "v_gas_mean"), ("normfactor_from", "normfactor_from"),
("normfactor_to", "normfactor_to")
])
else:
required_results.extend([("v_mean_m_per_s", "v_mps")])
def extract_results(cls, net, options, branch_results, mode):
required_results_hyd, required_results_ht = standard_branch_wo_internals_result_lookup(net)

extract_branch_results_without_internals(net, branch_results, required_results,
cls.table_name(), branches_connected)
extract_branch_results_without_internals(net, branch_results, required_results_hyd,
required_results_ht, cls.table_name(), mode)

@classmethod
def get_component_input(cls):
Expand Down
34 changes: 18 additions & 16 deletions pandapipes/component_models/heat_exchanger_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy as np
from numpy import dtype

from pandapipes.component_models import standard_branch_wo_internals_result_lookup
from pandapipes.component_models.abstract_models.branch_wzerolength_models import \
BranchWZeroLengthComponent
from pandapipes.component_models.junction_component import Junction
Expand Down Expand Up @@ -60,24 +61,25 @@ def create_pit_branch_entries(cls, net, branch_pit):
heat_exchanger_pit[:, T_OUT] = 307

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
required_results = [
("p_from_bar", "p_from"), ("p_to_bar", "p_to"), ("t_from_k", "temp_from"),
("t_to_k", "temp_to"), ("mdot_to_kg_per_s", "mf_to"), ("mdot_from_kg_per_s", "mf_from"),
("vdot_norm_m3_per_s", "vf"), ("lambda", "lambda"), ("reynolds", "reynolds")
]
def extract_results(cls, net, options, branch_results, mode):
"""
Class method to extract pipeflow results from the internal structure into the results table.
if get_fluid(net).is_gas:
required_results.extend([
("v_from_m_per_s", "v_gas_from"), ("v_to_m_per_s", "v_gas_to"),
("v_mean_m_per_s", "v_gas_mean"), ("normfactor_from", "normfactor_from"),
("normfactor_to", "normfactor_to")
])
else:
required_results.extend([("v_mean_m_per_s", "v_mps")])
:param net: The pandapipes network
:type net: pandapipesNet
:param options: pipeflow options
:type options: dict
:param branch_results: important branch results
:type branch_results: dict
:param mode: simulation mode
:type mode: str
:return: No Output.
:rtype: None
"""
required_results_hyd, required_results_ht = standard_branch_wo_internals_result_lookup(net)

extract_branch_results_without_internals(net, branch_results, required_results,
cls.table_name(), branches_connected)
extract_branch_results_without_internals(net, branch_results, required_results_hyd,
required_results_ht, cls.table_name(), mode)

@classmethod
def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
Expand Down
45 changes: 26 additions & 19 deletions pandapipes/component_models/junction_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,37 +88,44 @@ def create_pit_node_entries(cls, net, node_pit):
junction_pit[:, ACTIVE_ND] = junctions.in_service.values

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
def extract_results(cls, net, options, branch_results, mode):
"""
Function that extracts certain results.
:param nodes_connected:
:type nodes_connected:
:param branches_connected:
:type branches_connected:
:param branch_results:
:type branch_results:
:param mode:
:type mode:
:param net: The pandapipes network
:type net: pandapipesNet
:param options:
:type options:
:param branch_results:
:type branch_results:
:param mode:
:type mode:
:return: No Output.
"""
res_table = net["res_" + cls.table_name()]

f, t = get_lookup(net, "node", "from_to")[cls.table_name()]
fa, ta = get_lookup(net, "node", "from_to_active")[cls.table_name()]

junction_pit = net["_active_pit"]["node"][fa:ta, :]
junctions_active = get_lookup(net, "node", "active")[f:t]

if np.any(junction_pit[:, PINIT] < 0):
warn(UserWarning('Pipeflow converged, however, the results are physically incorrect '
'as pressure is negative at nodes %s'
% junction_pit[junction_pit[:, PINIT] < 0, ELEMENT_IDX]))

res_table["p_bar"].values[junctions_active] = junction_pit[:, PINIT]
res_table["t_k"].values[junctions_active] = junction_pit[:, TINIT]
junction_pit = net["_pit"]["node"][f:t, :]

if mode in ["hydraulics", "all"]:
junctions_connected_hydraulic = get_lookup(net, "node", "active_hydraulics")[f:t]

if np.any(junction_pit[junctions_connected_hydraulic, PINIT] < 0):
warn(UserWarning('Pipeflow converged, however, the results are physically incorrect '
'as pressure is negative at nodes %s'
% junction_pit[junction_pit[:, PINIT] < 0, ELEMENT_IDX]))

# res_table["p_bar"].values[junctions_connected_hydraulic] = junction_pit[:, PINIT]
# if mode == "hydraulics":
# res_table["t_k"].values[junctions_connected_hydraulic] = junction_pit[:, TINIT]
#
# if mode in ["heat", "all"]:
# junctions_connected_ht = get_lookup(net, "node", "active_heat_transfer")[f:t]
# res_table["t_k"].values[junctions_connected_ht] = junction_pit[:, TINIT]
res_table["p_bar"].values[:] = junction_pit[:, PINIT]
res_table["t_k"].values[:] = junction_pit[:, TINIT]

@classmethod
def get_component_input(cls):
Expand Down
37 changes: 22 additions & 15 deletions pandapipes/component_models/pipe_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,28 +172,35 @@ def calculate_temperature_lift(cls, net, branch_component_pit, node_pit):
branch_component_pit[:, TL] = 0

@classmethod
def extract_results(cls, net, options, branch_results, nodes_connected, branches_connected):
res_nodes_from = [("p_from_bar", "p_from"), ("t_from_k", "temp_from"),
("mdot_from_kg_per_s", "mf_from")]
res_nodes_to = [("p_to_bar", "p_to"), ("t_to_k", "temp_to"), ("mdot_to_kg_per_s", "mf_to")]
res_mean = [("vdot_norm_m3_per_s", "vf"), ("lambda", "lambda"), ("reynolds", "reynolds")]
def extract_results(cls, net, options, branch_results, mode):
res_nodes_from_hyd = [("p_from_bar", "p_from"), ("mdot_from_kg_per_s", "mf_from")]
res_nodes_from_ht = [("t_from_k", "temp_from")]
res_nodes_to_hyd = [("p_to_bar", "p_to"), ("mdot_to_kg_per_s", "mf_to")]
res_nodes_to_ht = [("t_to_k", "temp_to")]
res_mean_hyd = [("vdot_norm_m3_per_s", "vf"), ("lambda", "lambda"),
("reynolds", "reynolds")]

if get_fluid(net).is_gas:
res_nodes_from.extend(
[("v_from_m_per_s", "v_gas_from"), ("normfactor_from", "normfactor_from")])
res_nodes_to.extend([("v_to_m_per_s", "v_gas_to"), ("normfactor_to", "normfactor_to")])
res_mean.extend([("v_mean_m_per_s", "v_gas_mean")])
res_nodes_from_hyd.extend([("v_from_m_per_s", "v_gas_from"),
("normfactor_from", "normfactor_from")])
res_nodes_to_hyd.extend([("v_to_m_per_s", "v_gas_to"),
("normfactor_to", "normfactor_to")])
res_mean_hyd.extend([("v_mean_m_per_s", "v_gas_mean")])
else:
res_mean.extend([("v_mean_m_per_s", "v_mps")])
res_mean_hyd.extend([("v_mean_m_per_s", "v_mps")])

if np.any(cls.get_internal_pipe_number(net) > 1):
extract_branch_results_with_internals(
net, branch_results, cls.table_name(), res_nodes_from, res_nodes_to, res_mean,
cls.get_connected_node_type().table_name(), branches_connected)
net, branch_results, cls.table_name(), res_nodes_from_hyd, res_nodes_from_ht,
res_nodes_to_hyd, res_nodes_to_ht, res_mean_hyd, [],
cls.get_connected_node_type().table_name(), mode)
else:
required_results = res_nodes_from + res_nodes_to + res_mean
extract_branch_results_without_internals(net, branch_results, required_results,
cls.table_name(), branches_connected)
required_results_hyd = res_nodes_from_hyd + res_nodes_to_hyd + res_mean_hyd
required_results_ht = res_nodes_from_ht + res_nodes_to_ht
extract_branch_results_without_internals(
net, branch_results, required_results_hyd, required_results_ht, cls.table_name(),
mode
)

@classmethod
def get_internal_results(cls, net, pipe):
Expand Down
Loading

0 comments on commit 513ef67

Please sign in to comment.