Skip to content

Commit

Permalink
Merge pull request #648 from EPrade/feature/t_outlet
Browse files Browse the repository at this point in the history
t_outlet in pipe results
  • Loading branch information
EPrade authored Aug 27, 2024
2 parents aac49d6 + f215fb3 commit 66a6670
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 36 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] variable "u_w_per_m2k" to std_type pipe
- [ADDED] standard district heating pipe types
- [ADDED] support for Python 3.12
- [ADDED] t_outlet_k to result tables of branch components
- [CHANGED] switched from setup.py to pyproject.toml
- [CHANGED] variable "alpha_w_per_m2k" to "u_w_per_m2k"
- [FIXED] Pressure plot not working for circ pump
Expand Down
2 changes: 1 addition & 1 deletion src/pandapipes/component_models/component_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def standard_branch_wo_internals_result_lookup(net):
("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")]
required_results_ht = [("t_from_k", "temp_from"), ("t_to_k", "temp_to"), ("t_outlet_k", "t_outlet")]

if get_fluid(net).is_gas:
required_results_hyd.extend([
Expand Down
4 changes: 2 additions & 2 deletions src/pandapipes/component_models/flow_control_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ def get_result_table(cls, net):
"""
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", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
"t_from_k", "t_to_k", "t_outlet_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
"vdot_norm_m3_per_s", "reynolds", "lambda", "normfactor_from",
"normfactor_to"]
else:
output = ["v_mean_m_per_s", "p_from_bar", "p_to_bar", "t_from_k", "t_to_k",
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_norm_m3_per_s", "reynolds",
"lambda"]
return output, True
4 changes: 2 additions & 2 deletions src/pandapipes/component_models/heat_consumer_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ def get_result_table(cls, net):
"""
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", "mdot_from_kg_per_s", "mdot_to_kg_per_s", "vdot_norm_m3_per_s", "reynolds", "lambda",
"t_to_k", "t_outlet_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s", "vdot_norm_m3_per_s", "reynolds", "lambda",
"normfactor_from", "normfactor_to"]
else:
output = ["v_mean_m_per_s", "p_from_bar", "p_to_bar", "t_from_k", "t_to_k", "mdot_from_kg_per_s",
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_norm_m3_per_s", "reynolds", "lambda"]
output += ['deltat_k', 'qext_w']
return output, True
Expand Down
4 changes: 2 additions & 2 deletions src/pandapipes/component_models/heat_exchanger_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ def get_result_table(cls, net):
"""
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", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
"t_from_k", "t_to_k", "t_outlet_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
"vdot_norm_m3_per_s", "reynolds", "lambda", "normfactor_from",
"normfactor_to"]
else:
output = ["v_mean_m_per_s", "p_from_bar", "p_to_bar", "t_from_k", "t_to_k",
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_norm_m3_per_s", "reynolds",
"lambda"]
return output, True
9 changes: 5 additions & 4 deletions src/pandapipes/component_models/pipe_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def extract_results(cls, net, options, branch_results, mode):
res_nodes_to_ht = [("t_to_k", "temp_to")]
res_mean_hyd = [("vdot_norm_m3_per_s", "vf"), ("lambda", "lambda"),
("reynolds", "reynolds")]
res_branch_ht = [("t_outlet_k", "t_outlet")]

if get_fluid(net).is_gas:
res_nodes_from_hyd.extend([("v_from_m_per_s", "v_gas_from"),
Expand All @@ -148,11 +149,11 @@ def extract_results(cls, net, options, branch_results, mode):
if np.any(cls.get_internal_pipe_number(net) > 1):
extract_branch_results_with_internals(
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, [],
res_nodes_to_hyd, res_nodes_to_ht, res_mean_hyd, res_branch_ht, [],
cls.get_connected_node_type().table_name(), mode)
else:
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
required_results_ht = res_nodes_from_ht + res_nodes_to_ht + res_branch_ht
extract_branch_results_without_internals(
net, branch_results, required_results_hyd, required_results_ht, cls.table_name(),
mode
Expand Down Expand Up @@ -294,11 +295,11 @@ def get_result_table(cls, net):
"""
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", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
"t_from_k", "t_to_k", "t_outlet_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
"vdot_norm_m3_per_s", "reynolds", "lambda", "normfactor_from",
"normfactor_to"]
else:
output = ["v_mean_m_per_s", "p_from_bar", "p_to_bar", "t_from_k", "t_to_k",
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_norm_m3_per_s", "reynolds",
"lambda"]
return output, True
Expand Down
6 changes: 3 additions & 3 deletions src/pandapipes/component_models/pressure_control_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def extract_results(cls, net, options, branch_results, mode):
("p_from_bar", "p_from"), ("p_to_bar", "p_to"), ("mdot_from_kg_per_s", "mf_from"),
("mdot_to_kg_per_s", "mf_to"), ("vdot_norm_m3_per_s", "vf")
]
required_results_ht = [("t_from_k", "temp_from"), ("t_to_k", "temp_to")]
required_results_ht = [("t_from_k", "temp_from"), ("t_to_k", "temp_to"), ("t_outlet_k", "t_outlet")]

if get_fluid(net).is_gas:
required_results_hyd.extend([
Expand Down Expand Up @@ -150,10 +150,10 @@ def get_result_table(cls, net):
"""
if get_fluid(net).is_gas:
output = ["v_from_m_per_s", "v_to_m_per_s", "p_from_bar", "p_to_bar",
"t_from_k", "t_to_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
"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",
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_norm_m3_per_s"]
output += ["deltap_bar"]
return output, True
6 changes: 3 additions & 3 deletions src/pandapipes/component_models/pump_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def extract_results(cls, net, options, branch_results, mode):
("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"), ("deltap_bar", "pl"),
]
required_results_ht = [("t_from_k", "temp_from"), ("t_to_k", "temp_to")]
required_results_ht = [("t_from_k", "temp_from"), ("t_to_k", "temp_to"), ("t_outlet_k", "t_outlet")]

if get_fluid(net).is_gas:
required_results_hyd.extend([
Expand Down Expand Up @@ -219,12 +219,12 @@ def get_result_table(cls, net):
output = ["deltap_bar",
"v_from_m_per_s", "v_to_m_per_s",
"p_from_bar", "p_to_bar",
"t_from_k", "t_to_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
"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"]
# TODO: inwieweit sind diese Angaben bei imaginärem Durchmesser sinnvoll?
else:
output = ["deltap_bar", "v_mean_m_per_s", "p_from_bar", "p_to_bar", "t_from_k",
"t_to_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s", "vdot_norm_m3_per_s"]
"t_to_k", "t_outlet_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s", "vdot_norm_m3_per_s"]
if calc_compr_pow:
output += ["compr_power_mw"]

Expand Down
4 changes: 2 additions & 2 deletions src/pandapipes/component_models/valve_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ def get_result_table(cls, net):
"""
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", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
"t_from_k", "t_to_k", "t_outlet_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
"vdot_norm_m3_per_s", "reynolds", "lambda", "normfactor_from",
"normfactor_to"]
else:
output = ["v_mean_m_per_s", "p_from_bar", "p_to_bar", "t_from_k", "t_to_k",
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_norm_m3_per_s", "reynolds",
"lambda"]
return output, True
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def get_result_table(cls, net):
"p_to_bar",
"t_from_k",
"t_to_k",
"t_outlet_k",
"p_from_mw",
"p_to_mw",
"mdot_from_kg_per_s",
Expand All @@ -110,6 +111,7 @@ def get_result_table(cls, net):
"p_to_bar",
"t_from_k",
"t_to_k",
"t_outlet_k",
"p_from_mw",
"p_to_mw",
"mdot_from_kg_per_s",
Expand Down
46 changes: 29 additions & 17 deletions src/pandapipes/pf/result_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,22 @@ def extract_all_results(net, calculation_mode):
"""
branch_pit = net["_pit"]["branch"]
node_pit = net["_pit"]["node"]
v_mps, mf, vf, from_nodes, to_nodes, temp_from, temp_to, reynolds, _lambda, p_from, p_to, pl = \
get_basic_branch_results(net, branch_pit, node_pit)
branch_results = {"v_mps": v_mps, "mf_from": mf, "mf_to": -mf, "vf": vf, "p_from": p_from,
"p_to": p_to, "from_nodes": from_nodes, "to_nodes": to_nodes,
"temp_from": temp_from, "temp_to": temp_to, "reynolds": reynolds,
"lambda": _lambda, "pl": pl}
branch_results = get_basic_branch_results(net, branch_pit, node_pit)
if get_fluid(net).is_gas:
if get_net_option(net, "use_numba"):
v_gas_from, v_gas_to, v_gas_mean, p_abs_from, p_abs_to, p_abs_mean, normfactor_from, \
normfactor_to, normfactor_mean = get_branch_results_gas_numba(
net, branch_pit, node_pit, from_nodes, to_nodes, v_mps, p_from, p_to)
net, branch_pit, node_pit, branch_results['from_nodes'], branch_results['to_nodes'],
branch_results['v_mps'], branch_results['p_from'], branch_results['p_to'])
else:
v_gas_from, v_gas_to, v_gas_mean, p_abs_from, p_abs_to, p_abs_mean, normfactor_from, \
normfactor_to, normfactor_mean = get_branch_results_gas(
net, branch_pit, node_pit, from_nodes, to_nodes, v_mps, p_from, p_to)
net, branch_pit, node_pit, branch_results['from_nodes'], branch_results['to_nodes'],
branch_results['v_mps'], branch_results['p_from'], branch_results['p_to'])
gas_branch_results = {
"v_gas_from": v_gas_from, "v_gas_to": v_gas_to, "v_gas_mean": v_gas_mean,
"p_from": p_from, "p_to": p_to, "p_abs_from": p_abs_from, "p_abs_to": p_abs_to,
"p_abs_mean": p_abs_mean, "normfactor_from": normfactor_from,
"p_from": branch_results['p_from'], "p_to": branch_results['p_to'], "p_abs_from": p_abs_from,
"p_abs_to": p_abs_to, "p_abs_mean": p_abs_mean, "normfactor_from": normfactor_from,
"normfactor_to": normfactor_to, "normfactor_mean": normfactor_mean
}
branch_results.update(gas_branch_results)
Expand All @@ -62,9 +59,13 @@ def get_basic_branch_results(net, branch_pit, node_pit):
t1 = node_pit[to_nodes, TINIT_NODE]
vf = branch_pit[:, MDOTINIT] / get_fluid(net).get_density(NORMAL_TEMPERATURE)
v = branch_pit[:, MDOTINIT] / fluid.get_density(NORMAL_TEMPERATURE) / branch_pit[:, AREA]
return v, branch_pit[:, MDOTINIT], vf, from_nodes, to_nodes, t0, t1, branch_pit[:, RE], \
branch_pit[:, LAMBDA], node_pit[from_nodes, PINIT], node_pit[to_nodes, PINIT], \
branch_pit[:, PL]
t_outlet = branch_pit[:, TOUTINIT]
branch_results = {"v_mps": v, "mf_from": branch_pit[:, MDOTINIT], "mf_to": -branch_pit[:, MDOTINIT],
"vf": vf, "p_from": node_pit[from_nodes, PINIT], "p_to": node_pit[to_nodes, PINIT],
"from_nodes": from_nodes, "to_nodes": to_nodes, "temp_from": t0, "temp_to": t1,
"reynolds": branch_pit[:, RE], "lambda": branch_pit[:, LAMBDA], "pl": branch_pit[:, PL],
"t_outlet": t_outlet}
return branch_results


def get_branch_results_gas(net, branch_pit, node_pit, from_nodes, to_nodes, v_mps, p_from, p_to):
Expand Down Expand Up @@ -155,7 +156,7 @@ def get_gas_vel_numba(node_pit, branch_pit, comp_from, comp_to, comp_mean, p_abs
def extract_branch_results_with_internals(net, branch_results, table_name,
res_nodes_from_hydraulics, res_nodes_from_heat,
res_nodes_to_hydraulics, res_nodes_to_heat,
res_mean_hydraulics, res_mean_heat, node_name,
res_mean_hydraulics, res_branch_ht, res_mean_heat, node_name,
simulation_mode):
# the result table to write results to
res_table = net["res_" + table_name]
Expand All @@ -175,9 +176,9 @@ def extract_branch_results_with_internals(net, branch_results, table_name,
# the id of the external node table inside the node_pit (mostly this is "junction": 0)
ext_node_tbl_idx = get_table_number(get_lookup(net, "node", "table"), node_name)

for (result_mode, res_nodes_from, res_nodes_to, res_mean) in [
("hydraulics", res_nodes_from_hydraulics, res_nodes_to_hydraulics, res_mean_hydraulics),
("heat", res_nodes_from_heat, res_nodes_to_heat, res_mean_heat)
for (result_mode, res_nodes_from, res_nodes_to, res_mean, res_branch) in [
("hydraulics", res_nodes_from_hydraulics, res_nodes_to_hydraulics, res_mean_hydraulics, []),
("heat", res_nodes_from_heat, res_nodes_to_heat, res_mean_heat, res_branch_ht)
]:
if result_mode == "hydraulics" and simulation_mode == "heat":
continue
Expand Down Expand Up @@ -212,6 +213,17 @@ def extract_branch_results_with_internals(net, branch_results, table_name,

for i, (res_name, entry) in enumerate(res_mean_hydraulics):
res_table[res_name].values[pt] = res[i + 3][connected_ind] / num_internals
if len(res_branch) > 0:
use_numba = get_net_option(net, "use_numba")
_, sections, connected_sum = _sum_by_group(use_numba, idx_pit, np.ones_like(idx_pit),
comp_connected.astype(np.int32))
connected_ind = connected_sum > 0.99
indices_last_section = (np.cumsum(sections) - 1).astype(int)[connected_ind]
# hint: idx_pit[placement_table] should result in the indices as ordered in the table
pt = placement_table[connected_ind]

for i, (res_name, entry) in enumerate(res_branch):
res_table[res_name].values[pt] = branch_results[entry][indices_last_section]


def extract_branch_results_without_internals(net, branch_results, required_results_hydraulic,
Expand Down

0 comments on commit 66a6670

Please sign in to comment.