/
pump_component.py
149 lines (127 loc) · 4.8 KB
/
pump_component.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Copyright (c) 2020-2021 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.
from operator import itemgetter
import numpy as np
from numpy import dtype
from pandapipes.component_models.abstract_models import BranchWZeroLengthComponent
from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE
from pandapipes.idx_branch import STD_TYPE, VINIT, D, AREA, TL, \
LOSS_COEFFICIENT as LC, FROM_NODE, TINIT, PL
from pandapipes.idx_node import PINIT, PAMB
from pandapipes.pipeflow_setup import get_net_option, get_fluid
class Pump(BranchWZeroLengthComponent):
"""
"""
@classmethod
def from_to_node_cols(cls):
return "from_junction", "to_junction"
@classmethod
def table_name(cls):
return "pump"
@classmethod
def active_identifier(cls):
return "in_service"
@classmethod
def create_pit_branch_entries(cls, net, pump_pit, node_name):
"""
Function which creates pit branch entries with a specific table.
:param net: The pandapipes network
:type net: pandapipesNet
:param pump_pit:
:type pump_pit:
:param internal_pipe_number:
:type internal_pipe_number:
:return: No Output.
"""
pump_pit = super().create_pit_branch_entries(net, pump_pit, node_name)
std_types_lookup = np.array(list(net.std_type[cls.table_name()].keys()))
std_type, pos = np.where(net[cls.table_name()]['std_type'].values
== std_types_lookup[:, np.newaxis])
pump_pit[pos, STD_TYPE] = std_type
pump_pit[:, D] = 0.1
pump_pit[:, AREA] = pump_pit[:, D] ** 2 * np.pi / 4
pump_pit[:, LC] = 0
@classmethod
def calculate_pressure_lift(cls, net, pump_pit, node_pit):
"""
:param net: The pandapipes network
:type net: pandapipesNet
:param pump_pit:
:type pump_pit:
:param node_pit:
:type node_pit:
:return: power stroke
:rtype: float
"""
area = pump_pit[:, AREA]
idx = pump_pit[:, STD_TYPE].astype(int)
std_types = np.array(list(net.std_type['pump'].keys()))[idx]
from_nodes = pump_pit[:, FROM_NODE].astype(np.int32)
# to_nodes = pump_pit[:, TO_NODE].astype(np.int32)
fluid = get_fluid(net)
p_from = node_pit[from_nodes, PAMB] + node_pit[from_nodes, PINIT]
# p_to = node_pit[to_nodes, PAMB] + node_pit[to_nodes, PINIT]
numerator = NORMAL_PRESSURE * pump_pit[:, TINIT]
v_mps = pump_pit[:, VINIT]
if fluid.is_gas:
# consider volume flow at inlet
normfactor_from = numerator * fluid.get_property("compressibility", p_from) \
/ (p_from * NORMAL_TEMPERATURE)
v_mean = v_mps * normfactor_from
else:
v_mean = v_mps
vol = v_mean * area
fcts = itemgetter(*std_types)(net['std_type']['pump'])
fcts = [fcts] if not isinstance(fcts, tuple) else fcts
pl = np.array(list(map(lambda x, y: x.get_pressure(y), fcts, vol)))
pump_pit[:, PL] = pl
@classmethod
def calculate_temperature_lift(cls, net, pump_pit, node_pit):
"""
:param net:
:type net:
:param pump_pit:
:type pump_pit:
:param node_pit:
:type node_pit:
:return:
:rtype:
"""
pump_pit[:, TL] = 0
@classmethod
def extract_results(cls, net, options, node_name):
"""
Function that extracts certain results.
:param net: The pandapipes network
:type net: pandapipesNet
:param options:
:type options:
:return: No Output.
"""
placement_table, pump_pit, res_table = super().prepare_result_tables(net, options, node_name)
res_table['deltap_bar'].values[placement_table] = pump_pit[:, PL]
@classmethod
def get_component_input(cls):
"""
Get component input.
:return:
:rtype:
"""
return [("name", dtype(object)),
("from_junction", "u4"),
("to_junction", "u4"),
("std_type", dtype(object)),
("in_service", 'bool'),
("type", dtype(object))]
@classmethod
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 ["deltap_bar"], True