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 pandapipes.component_models.abstract_models.branch_models import BranchComponent
7 1
from pandapipes.idx_branch import FROM_NODE, TO_NODE, TINIT, ELEMENT_IDX, RHO, ETA, CP, ACTIVE
8 1
from pandapipes.idx_node import TINIT as TINIT_NODE, L, node_cols
9 1
from pandapipes.pipeflow_setup import add_table_lookup, get_lookup, get_table_number
10 1
from pandapipes.properties.fluids import get_fluid
11

12 1
try:
13 1
    import pplog as logging
14 1
except ImportError:
15 1
    import logging
16

17 1
logger = logging.getLogger(__name__)
18

19

20 1
class BranchWInternalsComponent(BranchComponent):
21
    """
22

23
    """
24

25 1
    @classmethod
26
    def internal_node_name(cls):
27 0
        return NotImplementedError
28

29 1
    @classmethod
30
    def create_node_lookups(cls, net, ft_lookups, table_lookup, idx_lookups, current_start,
31
                            current_table, internal_nodes_lookup):
32
        """
33
        Function which creates node lookups.
34

35
        :param net: The pandapipes network
36
        :type net: pandapipesNet
37
        :param ft_lookups:
38
        :type ft_lookups:
39
        :param table_lookup:
40
        :type table_lookup:
41
        :param idx_lookups:
42
        :type idx_lookups:
43
        :param current_start:
44
        :type current_start:
45
        :param current_table:
46
        :type current_table:
47
        :param internal_nodes_lookup:
48
        :type internal_nodes_lookup:
49
        :return:
50
        :rtype:
51
        """
52 1
        internal_nodes = cls.get_internal_pipe_number(net) - 1
53 1
        end = current_start
54 1
        ft_lookups[cls.table_name()] = None
55 1
        if np.any(internal_nodes > 0):
56 1
            int_nodes_num = int(np.sum(internal_nodes))
57 1
            internal_pipes = internal_nodes + 1
58 1
            int_pipes_num = int(np.sum(internal_pipes))
59 1
            end = current_start + int_nodes_num
60 1
            add_table_lookup(table_lookup, cls.internal_node_name(), current_table)
61 1
            ft_lookups[cls.internal_node_name()] = (current_start, end)
62 1
            return end, current_table + 1, internal_nodes, internal_pipes, int_nodes_num, int_pipes_num
63
        else:
64 1
            return end, current_table + 1, 0, 0, 0, 0
65

66 1
    @classmethod
67
    def create_branch_lookups(cls, net, ft_lookups, table_lookup, idx_lookups, current_table,
68
                              current_start):
69
        """
70
        Function which creates branch lookups.
71

72
        :param net: The pandapipes network
73
        :type net: pandapipesNet
74
        :param ft_lookups:
75
        :type ft_lookups:
76
        :param table_lookup:
77
        :type table_lookup:
78
        :param idx_lookups:
79
        :type idx_lookups:
80
        :param current_table:
81
        :type current_table:
82
        :param current_start:
83
        :type current_start:
84
        :return:
85
        :rtype:
86
        """
87 1
        end = current_start + int(np.sum(cls.get_internal_pipe_number(net)))
88 1
        ft_lookups[cls.table_name()] = (current_start, end)
89 1
        add_table_lookup(table_lookup, cls.table_name(), current_table)
90 1
        return end, current_table + 1
91

92 1
    @classmethod
93
    def create_pit_node_entries(cls, net, node_pit, node_name):
94
        """
95
        Function which creates pit node entries.
96

97
        :param net: The pandapipes network
98
        :type net: pandapipesNet
99
        :param node_pit:
100
        :type node_pit:
101
        :return: No Output.
102
        """
103 1
        table_lookup = get_lookup(net, "node", "table")
104 1
        table_nr = get_table_number(table_lookup, cls.internal_node_name())
105 1
        if table_nr is None:
106 1
            return None, 0, 0, None, None, None
107 1
        ft_lookup = get_lookup(net, "node", "from_to")
108 1
        f, t = ft_lookup[cls.internal_node_name()]
109

110 1
        int_node_pit = node_pit[f:t, :]
111 1
        int_node_pit[:, :] = np.array([table_nr, 0, L] + [0] * (node_cols - 3))
112 1
        int_node_number = cls.get_internal_pipe_number(net) - 1
113

114 1
        int_node_pit[:, ELEMENT_IDX] = np.arange(t - f)
115

116 1
        f_junction, t_junction = ft_lookup[node_name]
117 1
        junction_pit = node_pit[f_junction:t_junction, :]
118 1
        from_junctions = net[cls.table_name()].from_junction.values.astype(np.int32)
119 1
        to_junctions = net[cls.table_name()].to_junction.values.astype(np.int32)
120 1
        return table_nr, int_node_number, int_node_pit, junction_pit, from_junctions, to_junctions
121

122 1
    @classmethod
123
    def create_pit_branch_entries(cls, net, branch_winternals_pit, node_name):
124
        """
125
        Function which creates pit branch entries.
126

127
        :param net: The pandapipes network
128
        :type net: pandapipesNet
129
        :param branch_pit:
130
        :type branch_pit:
131
        :return: No Output.
132
        """
133 1
        branch_winternals_pit, node_pit, from_nodes, to_nodes \
134
            = super().create_pit_branch_entries(net, branch_winternals_pit, node_name)
135

136 1
        internal_pipe_number = cls.get_internal_pipe_number(net)
137 1
        node_ft_lookups = get_lookup(net, "node", "from_to")
138

139 1
        if cls.internal_node_name() in node_ft_lookups:
140 1
            pipe_nodes_from, pipe_nodes_to = node_ft_lookups[cls.internal_node_name()]
141 1
            pipe_nodes_idx = np.arange(pipe_nodes_from, pipe_nodes_to)
142 1
            insert_places = np.repeat(np.arange(len(from_nodes)), internal_pipe_number - 1)
143 1
            from_nodes = np.insert(from_nodes, insert_places + 1, pipe_nodes_idx)
144 1
            to_nodes = np.insert(to_nodes, insert_places, pipe_nodes_idx)
145

146 1
        branch_winternals_pit[:, ELEMENT_IDX] = np.repeat(net[cls.table_name()].index.values,
147
                                                          internal_pipe_number)
148 1
        branch_winternals_pit[:, FROM_NODE] = from_nodes
149 1
        branch_winternals_pit[:, TO_NODE] = to_nodes
150 1
        branch_winternals_pit[:, TINIT] = (node_pit[from_nodes, TINIT_NODE] + node_pit[
151
            to_nodes, TINIT_NODE]) / 2
152 1
        fluid = get_fluid(net)
153 1
        branch_winternals_pit[:, RHO] = fluid.get_density(branch_winternals_pit[:, TINIT])
154 1
        branch_winternals_pit[:, ETA] = fluid.get_viscosity(branch_winternals_pit[:, TINIT])
155 1
        branch_winternals_pit[:, CP] = fluid.get_heat_capacity(branch_winternals_pit[:, TINIT])
156 1
        branch_winternals_pit[:, ACTIVE] = \
157
            np.repeat(net[cls.table_name()][cls.active_identifier()].values,internal_pipe_number)
158

159 1
        return branch_winternals_pit, internal_pipe_number
160

161 1
    @classmethod
162
    def get_internal_pipe_number(cls, net):
163
        """
164

165
        :param net: The pandapipes network
166
        :type net: pandapipesNet
167
        :return:
168
        :rtype:
169
        """
170 1
        return net[cls.table_name()].sections.values
171

172 1
    @classmethod
173
    def get_internal_results(cls, net, branch):
174
        """
175

176
        :param net:
177
        :type net:
178
        :param pipe:
179
        :type pipe:
180
        :return:
181
        :rtype:
182
        """
183 0
        raise NotImplementedError

Read our documentation on viewing source code .

Loading