1
|
|
# Copyright (c) 2020 by Fraunhofer Institute for Energy Economics
|
2
|
|
# and Energy System Technology (IEE), Kassel. All rights reserved.
|
3
|
|
# Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
4
|
|
|
5
|
1
|
from warnings import warn
|
6
|
|
|
7
|
1
|
import numpy as np
|
8
|
1
|
from numpy import dtype
|
9
|
1
|
from pandapipes.component_models.abstract_models import NodeComponent
|
10
|
1
|
from pandapipes.component_models.auxiliaries.component_toolbox import p_correction_height_air
|
11
|
1
|
from pandapipes.idx_node import L, ELEMENT_IDX, RHO, PINIT, node_cols, HEIGHT, TINIT, PAMB, \
|
12
|
|
ACTIVE as ACTIVE_ND
|
13
|
1
|
from pandapipes.pipeflow_setup import add_table_lookup, get_table_number, \
|
14
|
|
get_lookup
|
15
|
1
|
from pandapipes.properties.fluids import get_fluid
|
16
|
|
|
17
|
|
|
18
|
1
|
class Junction(NodeComponent):
|
19
|
|
"""
|
20
|
|
|
21
|
|
"""
|
22
|
|
|
23
|
1
|
@classmethod
|
24
|
|
def table_name(cls):
|
25
|
1
|
return "junction"
|
26
|
|
|
27
|
1
|
@classmethod
|
28
|
|
def create_node_lookups(cls, net, ft_lookups, table_lookup, idx_lookups, current_start,
|
29
|
|
current_table, internal_nodes_lookup):
|
30
|
|
"""
|
31
|
|
Function which creates node lookups.
|
32
|
|
|
33
|
|
:param net: The pandapipes network
|
34
|
|
:type net: pandapipesNet
|
35
|
|
:param ft_lookups:
|
36
|
|
:type ft_lookups:
|
37
|
|
:param table_lookup:
|
38
|
|
:type table_lookup:
|
39
|
|
:param idx_lookups:
|
40
|
|
:type idx_lookups:
|
41
|
|
:param current_start:
|
42
|
|
:type current_start:
|
43
|
|
:param current_table:
|
44
|
|
:type current_table:
|
45
|
|
:param internal_nodes_lookup:
|
46
|
|
:type internal_nodes_lookup:
|
47
|
|
:return:
|
48
|
|
:rtype:
|
49
|
|
"""
|
50
|
1
|
table_indices = net[cls.table_name()].index
|
51
|
1
|
table_len = len(table_indices)
|
52
|
1
|
end = current_start + table_len
|
53
|
1
|
ft_lookups[cls.table_name()] = (current_start, end)
|
54
|
1
|
add_table_lookup(table_lookup, cls.table_name(), current_table)
|
55
|
1
|
if not table_len:
|
56
|
0
|
idx_lookups[cls.table_name()] = np.array([], dtype=np.int32)
|
57
|
0
|
idx_lookups[cls.table_name()][table_indices] = np.arange(table_len) + current_start
|
58
|
|
else:
|
59
|
1
|
idx_lookups[cls.table_name()] = -np.ones(table_indices.max() + 1, dtype=np.int32)
|
60
|
1
|
idx_lookups[cls.table_name()][table_indices] = np.arange(table_len) + current_start
|
61
|
1
|
return end, current_table + 1
|
62
|
|
|
63
|
1
|
@classmethod
|
64
|
|
def create_pit_node_entries(cls, net, node_pit, node_name):
|
65
|
|
"""
|
66
|
|
Function which creates pit node entries.
|
67
|
|
|
68
|
|
:param net: The pandapipes network
|
69
|
|
:type net: pandapipesNet
|
70
|
|
:param node_pit:
|
71
|
|
:type node_pit:
|
72
|
|
:param node_name:
|
73
|
|
:type node_name:
|
74
|
|
:return: No Output.
|
75
|
|
"""
|
76
|
1
|
ft_lookup = get_lookup(net, "node", "from_to")
|
77
|
1
|
table_nr = get_table_number(get_lookup(net, "node", "table"), cls.table_name())
|
78
|
1
|
f, t = ft_lookup[cls.table_name()]
|
79
|
|
|
80
|
1
|
junctions = net[cls.table_name()]
|
81
|
1
|
junction_pit = node_pit[f:t, :]
|
82
|
1
|
junction_pit[:, :] = np.array([table_nr, 0, L] + [0] * (node_cols - 3))
|
83
|
|
|
84
|
1
|
junction_pit[:, ELEMENT_IDX] = junctions.index.values
|
85
|
1
|
junction_pit[:, HEIGHT] = junctions.height_m.values
|
86
|
1
|
junction_pit[:, PINIT] = junctions.pn_bar.values
|
87
|
1
|
junction_pit[:, TINIT] = junctions.tfluid_k.values
|
88
|
1
|
junction_pit[:, RHO] = get_fluid(net).get_density(junction_pit[:, TINIT])
|
89
|
1
|
junction_pit[:, PAMB] = p_correction_height_air(junction_pit[:, HEIGHT])
|
90
|
1
|
junction_pit[:, ACTIVE_ND] = junctions.in_service.values
|
91
|
|
|
92
|
1
|
@classmethod
|
93
|
|
def extract_results(cls, net, options, node_name):
|
94
|
|
"""
|
95
|
|
Function that extracts certain results.
|
96
|
|
|
97
|
|
:param net: The pandapipes network
|
98
|
|
:type net: pandapipesNet
|
99
|
|
:param options:
|
100
|
|
:type options:
|
101
|
|
:param node_name:
|
102
|
|
:type node_name:
|
103
|
|
:return: No Output.
|
104
|
|
"""
|
105
|
1
|
res_table = super().extract_results(net, options, node_name)
|
106
|
|
|
107
|
1
|
f, t = get_lookup(net, "node", "from_to")[cls.table_name()]
|
108
|
1
|
fa, ta = get_lookup(net, "node", "from_to_active")[cls.table_name()]
|
109
|
|
|
110
|
1
|
junction_pit = net["_active_pit"]["node"][fa:ta, :]
|
111
|
1
|
junctions_active = get_lookup(net, "node", "active")[f:t]
|
112
|
|
|
113
|
1
|
if np.any(junction_pit[:, PINIT] < 0):
|
114
|
0
|
warn(UserWarning('Pipeflow converged, however, the results are phyisically incorrect '
|
115
|
|
'as pressure is at the nodes %s are negative'
|
116
|
|
% junction_pit[junction_pit[:, PINIT] < 0, ELEMENT_IDX]))
|
117
|
|
|
118
|
1
|
res_table["p_bar"].values[junctions_active] = junction_pit[:, PINIT]
|
119
|
1
|
res_table["t_k"].values[junctions_active] = junction_pit[:, TINIT]
|
120
|
|
|
121
|
1
|
@classmethod
|
122
|
|
def get_component_input(cls):
|
123
|
|
"""
|
124
|
|
|
125
|
|
:return:
|
126
|
|
:rtype:
|
127
|
|
"""
|
128
|
1
|
return [('name', dtype(object)),
|
129
|
|
('pn_bar', 'f8'),
|
130
|
|
("tfluid_k", 'f8'),
|
131
|
|
("height_m", 'f8'),
|
132
|
|
('in_service', 'bool'),
|
133
|
|
('type', dtype(object))]
|
134
|
|
|
135
|
1
|
@classmethod
|
136
|
|
def geodata(cls):
|
137
|
|
"""
|
138
|
|
|
139
|
|
:return:
|
140
|
|
:rtype:
|
141
|
|
"""
|
142
|
1
|
return [("x", "f8"), ("y", "f8")]
|
143
|
|
|
144
|
1
|
@classmethod
|
145
|
|
def get_result_table(cls, net):
|
146
|
|
"""
|
147
|
|
|
148
|
|
:param net: The pandapipes network
|
149
|
|
:type net: pandapipesNet
|
150
|
|
:return: (columns, all_float) - the column names and whether they are all float type. Only
|
151
|
|
if False, returns columns as tuples also specifying the dtypes
|
152
|
|
:rtype: (list, bool)
|
153
|
|
"""
|
154
|
1
|
return ["p_bar", "t_k"], True
|