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 operator import itemgetter
8

9 1
from pandapipes.component_models.abstract_models import BranchWZeroLengthComponent
10

11 1
from pandapipes.idx_node import PINIT, PAMB
12 1
from pandapipes.idx_branch import STD_TYPE, VINIT, D, AREA, TL, \
13
    LOSS_COEFFICIENT as LC, FROM_NODE, TO_NODE, TINIT, PL
14

15 1
from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE
16

17 1
from pandapipes.pipeflow_setup import get_net_option, get_fluid
18

19

20 1
class Pump(BranchWZeroLengthComponent):
21
    """
22

23
    """
24

25 1
    @classmethod
26
    def table_name(cls):
27 1
        return "pump"
28

29 1
    @classmethod
30
    def active_identifier(cls):
31 1
        return "in_service"
32

33 1
    @classmethod
34
    def create_pit_branch_entries(cls, net, pump_pit, node_name):
35
        """
36
        Function which creates pit branch entries with a specific table.
37
        :param net: The pandapipes network
38
        :type net: pandapipesNet
39
        :param pump_pit:
40
        :type pump_pit:
41
        :param internal_pipe_number:
42
        :type internal_pipe_number:
43
        :return: No Output.
44
        """
45 1
        pump_pit = super().create_pit_branch_entries(net, pump_pit, node_name)
46 1
        std_types_lookup = np.array(list(net.std_type[cls.table_name()].keys()))
47 1
        std_type, pos = np.where(net[cls.table_name()]['std_type'].values
48
                                 == std_types_lookup[:, np.newaxis])
49 1
        pump_pit[pos, STD_TYPE] = std_type
50 1
        pump_pit[:, D] = 0.1
51 1
        pump_pit[:, AREA] = pump_pit[:, D] ** 2 * np.pi / 4
52 1
        pump_pit[:, LC] = 0
53

54 1
    @classmethod
55
    def calculate_pressure_lift(cls, net, pump_pit, node_pit):
56
        """
57

58
        :param net: The pandapipes network
59
        :type net: pandapipesNet
60
        :param pump_pit:
61
        :type pump_pit:
62
        :param node_pit:
63
        :type node_pit:
64
        :return: power stroke
65
        :rtype: float
66
        """
67 1
        area = pump_pit[:, AREA]
68 1
        idx = pump_pit[:, STD_TYPE].astype(int)
69 1
        std_types = np.array(list(net.std_type['pump'].keys()))[idx]
70 1
        p_scale = get_net_option(net, "p_scale")
71 1
        from_nodes = pump_pit[:, FROM_NODE].astype(np.int32)
72 1
        to_nodes = pump_pit[:, TO_NODE].astype(np.int32)
73 1
        fluid = get_fluid(net)
74 1
        p_from = node_pit[from_nodes, PAMB] + node_pit[from_nodes, PINIT] * p_scale
75
        # p_to = node_pit[to_nodes, PAMB] + node_pit[to_nodes, PINIT] * p_scale
76 1
        numerator = NORMAL_PRESSURE * pump_pit[:, TINIT]
77 1
        v_mps = pump_pit[:, VINIT]
78 1
        if fluid.is_gas:
79
            # consider volume flow at inlet
80 1
            normfactor_from = numerator * fluid.get_property("compressibility", p_from) \
81
                              / (p_from * NORMAL_TEMPERATURE)
82 1
            v_mean = v_mps * normfactor_from
83
        else:
84 1
            v_mean = v_mps
85 1
        vol = v_mean * area
86 1
        fcts = itemgetter(*std_types)(net['std_type']['pump'])
87 1
        fcts = [fcts] if not isinstance(fcts, tuple) else fcts
88 1
        pl = np.array(list(map(lambda x, y: x.get_pressure(y), fcts, vol)))
89 1
        pump_pit[:, PL] = pl
90

91 1
    @classmethod
92
    def calculate_temperature_lift(cls, net, pump_pit, node_pit):
93
        """
94

95
        :param net:
96
        :type net:
97
        :param pump_pit:
98
        :type pump_pit:
99
        :param node_pit:
100
        :type node_pit:
101
        :return:
102
        :rtype:
103
        """
104 0
        pump_pit[:, TL] = 0
105

106 1
    @classmethod
107
    def extract_results(cls, net, options, node_name):
108
        """
109
        Function that extracts certain results.
110

111
        :param net: The pandapipes network
112
        :type net: pandapipesNet
113
        :param options:
114
        :type options:
115
        :return: No Output.
116
        """
117 1
        placement_table, pump_pit, res_table = super().extract_results(net, options, node_name)
118 1
        res_table['deltap_bar'].values[placement_table] = pump_pit[:, PL]
119

120 1
    @classmethod
121
    def get_component_input(cls):
122
        """
123

124
        Get component input.
125

126
        :return:
127
        :rtype:
128
        """
129 1
        return [("name", dtype(object)),
130
                ("from_junction", "u4"),
131
                ("to_junction", "u4"),
132
                ("std_type", dtype(object)),
133
                ("in_service", 'bool'),
134
                ("type", dtype(object))]
135

136 1
    @classmethod
137
    def get_result_table(cls, net):
138
        """
139

140
        Gets the result table.
141

142
        :param net: The pandapipes network
143
        :type net: pandapipesNet
144
        :return: (columns, all_float) - the column names and whether they are all float type. Only
145
                if False, returns columns as tuples also specifying the dtypes
146
        :rtype: (list, bool)
147
        """
148 1
        return ["deltap_bar"], True

Read our documentation on viewing source code .

Loading