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
|
import numpy as np
|
6
|
1
|
from numpy import dtype
|
7
|
1
|
from pandapipes.component_models.abstract_models.node_element_models import NodeElementComponent
|
8
|
1
|
from pandapipes.idx_node import LOAD, ELEMENT_IDX
|
9
|
1
|
from pandapipes.internals_toolbox import _sum_by_group
|
10
|
1
|
from pandapipes.pipeflow_setup import get_lookup
|
11
|
|
|
12
|
|
|
13
|
1
|
class ConstFlow(NodeElementComponent):
|
14
|
|
|
15
|
1
|
@classmethod
|
16
|
|
def sign(cls):
|
17
|
0
|
raise NotImplementedError()
|
18
|
|
|
19
|
1
|
@classmethod
|
20
|
|
def create_pit_node_entries(cls, net, node_pit, node_name):
|
21
|
|
"""
|
22
|
|
Function which creates pit node entries.
|
23
|
|
|
24
|
|
:param net: The pandapipes network
|
25
|
|
:type net: pandapipesNet
|
26
|
|
:param node_pit:
|
27
|
|
:type node_pit:
|
28
|
|
:param node_name:
|
29
|
|
:type node_name:
|
30
|
|
:return: No Output.
|
31
|
|
"""
|
32
|
1
|
loads = net[cls.table_name()]
|
33
|
1
|
helper = loads.in_service.values * loads.scaling.values * cls.sign()
|
34
|
1
|
mf = np.nan_to_num(loads.mdot_kg_per_s.values)
|
35
|
1
|
mass_flow_loads = mf * helper
|
36
|
1
|
juncts, loads_sum = _sum_by_group(loads.junction.values, mass_flow_loads)
|
37
|
1
|
junction_idx_lookups = get_lookup(net, "node", "index")[node_name]
|
38
|
1
|
index = junction_idx_lookups[juncts]
|
39
|
1
|
node_pit[index, LOAD] += loads_sum
|
40
|
|
|
41
|
1
|
@classmethod
|
42
|
|
def extract_results(cls, net, options, node_name):
|
43
|
|
"""
|
44
|
|
Function that extracts certain results.
|
45
|
|
|
46
|
|
:param net: The pandapipes network
|
47
|
|
:type net: pandapipesNet
|
48
|
|
:param options:
|
49
|
|
:type options:
|
50
|
|
:param node_name:
|
51
|
|
:type node_name:
|
52
|
|
:return: No Output.
|
53
|
|
"""
|
54
|
1
|
res_table = super().extract_results(net, options, node_name)
|
55
|
|
|
56
|
1
|
loads = net[cls.table_name()]
|
57
|
|
|
58
|
1
|
is_loads = loads.in_service.values
|
59
|
1
|
fj, tj = get_lookup(net, "node", "from_to")[node_name]
|
60
|
1
|
junct_pit = net["_pit"]["node"][fj:tj, :]
|
61
|
1
|
nodes_connected = get_lookup(net, "node", "active")[fj:tj]
|
62
|
1
|
is_juncts = np.isin(loads.junction.values, junct_pit[nodes_connected, ELEMENT_IDX])
|
63
|
|
|
64
|
1
|
is_calc = is_loads & is_juncts
|
65
|
1
|
res_table["mdot_kg_per_s"].values[is_calc] = loads.mdot_kg_per_s.values[is_calc] \
|
66
|
|
* loads.scaling.values[is_calc]
|
67
|
|
|
68
|
1
|
@classmethod
|
69
|
|
def get_component_input(cls):
|
70
|
|
"""
|
71
|
|
|
72
|
|
:return:
|
73
|
|
:rtype:
|
74
|
|
"""
|
75
|
1
|
return [("name", dtype(object)),
|
76
|
|
("junction", "u4"),
|
77
|
|
("mdot_kg_per_s", "f8"),
|
78
|
|
("scaling", "f8"),
|
79
|
|
("in_service", "bool"),
|
80
|
|
("type", dtype(object))]
|
81
|
|
|
82
|
1
|
@classmethod
|
83
|
|
def get_result_table(cls, net):
|
84
|
|
"""Get results.
|
85
|
|
|
86
|
|
:param net: The pandapipes network
|
87
|
|
:type net: pandapipesNet
|
88
|
|
:return: (columns, all_float) - the column names and whether they are all float type. Only
|
89
|
|
if False, returns columns as tuples also specifying the dtypes
|
90
|
|
:rtype: (list, bool)
|
91
|
|
"""
|
92
|
1
|
return ["mdot_kg_per_s"], True
|