e2nIEE / pandapipes

@@ -6,13 +6,13 @@
Loading
6 6
7 7
import numpy as np
8 8
from numpy import dtype
9 +
9 10
from pandapipes.component_models.abstract_models import BranchWZeroLengthComponent, TINIT_NODE
10 11
from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE, R_UNIVERSAL, P_CONVERSION
11 12
from pandapipes.idx_branch import STD_TYPE, VINIT, D, AREA, TL, \
12 -
    LOSS_COEFFICIENT as LC, FROM_NODE, TO_NODE, TINIT, PL, LOAD_VEC_NODES, ELEMENT_IDX
13 +
    LOSS_COEFFICIENT as LC, FROM_NODE, TINIT, PL
13 14
from pandapipes.idx_node import PINIT, PAMB
14 -
from pandapipes.internals_toolbox import _sum_by_group
15 -
from pandapipes.pipeflow_setup import get_net_option, get_fluid, get_lookup
15 +
from pandapipes.pipeflow_setup import get_fluid, get_net_option
16 16
17 17
18 18
class Pump(BranchWZeroLengthComponent):
@@ -116,49 +116,32 @@
Loading
116 116
        :type options:
117 117
        :return: No Output.
118 118
        """
119 -
        placement_table, pump_pit, res_table = super().prepare_result_tables(net, options, node_name)
120 -
        res_table['deltap_bar'].values[placement_table] = pump_pit[:, PL]
121 -
122 -
        node_pit = net["_active_pit"]["node"]
123 -
        node_active_idx_lookup = get_lookup(net, "node", "index_active")[node_name]
124 -
        junction_idx_lookup = get_lookup(net, "node", "index")[node_name]
125 -
        from_junction_nodes = node_active_idx_lookup[junction_idx_lookup[
126 -
            net[cls.table_name()]["from_junction"].values[placement_table]]]
127 -
        to_junction_nodes = node_active_idx_lookup[junction_idx_lookup[
128 -
            net[cls.table_name()]["to_junction"].values[placement_table]]]
129 -
130 -
        p_to = node_pit[to_junction_nodes, PINIT]
131 -
        p_from = node_pit[from_junction_nodes, PINIT]
132 -
133 -
        from_nodes = pump_pit[:, FROM_NODE].astype(np.int32)
134 -
        to_nodes = pump_pit[:, TO_NODE].astype(np.int32)
135 -
136 -
        t0 = node_pit[from_nodes, TINIT_NODE]
137 -
        t1 = node_pit[to_nodes, TINIT_NODE]
138 -
        mf = pump_pit[:, LOAD_VEC_NODES]
139 -
        vf = pump_pit[:, LOAD_VEC_NODES] / get_fluid(net).get_density((t0 + t1) / 2)
140 -
141 -
        idx_active = pump_pit[:, ELEMENT_IDX]
142 -
        idx_sort, mf_sum, vf_sum, internal_pipes = \
143 -
            _sum_by_group(idx_active, mf, vf, np.ones_like(idx_active))
144 -
        res_table["mdot_to_kg_per_s"].values[placement_table] = -mf_sum / internal_pipes
145 -
        res_table["mdot_from_kg_per_s"].values[placement_table] = mf_sum / internal_pipes
146 -
        res_table["vdot_norm_m3_per_s"].values[placement_table] = vf_sum / internal_pipes
147 -
148 -
        if net.fluid.is_gas:
149 -
            # calculate ideal compression power
150 -
            compr = get_fluid(net).get_property("compressibility", p_from)
151 -
            molar_mass = net.fluid.get_molar_mass()  # [g/mol]
152 -
            R_spec = 1e3 * R_UNIVERSAL / molar_mass  # [J/(kg * K)]
153 -
            # 'kappa' heat capacity ratio:
154 -
            k = 1.4  # TODO: implement proper calculation of kappa
155 -
            w_real_isentr = (k / (k - 1)) * R_spec * compr * t0 * \
156 -
                            (np.divide(p_to, p_from) ** ((k - 1) / k) - 1)
157 -
            res_table['compr_power_w'].values[placement_table] = \
158 -
                w_real_isentr * abs(mf_sum / internal_pipes)
119 +
        calc_compr_pow = options['calc_compression_power']
120 +
        if calc_compr_pow:
121 +
            placement_table, res_table, pump_pit, node_pit = super().extract_results(net, options, node_name)
122 +
            p_from = res_table['p_from_bar'].values[placement_table]
123 +
            p_to = res_table['p_to_bar'].values[placement_table]
124 +
            from_nodes = pump_pit[:, FROM_NODE].astype(np.int32)
125 +
            t0 = node_pit[from_nodes, TINIT_NODE]
126 +
            vf_sum_int = res_table["vdot_norm_m3_per_s"].values[placement_table]
127 +
            mf_sum_int = res_table["mdot_from_kg_per_s"].values[placement_table]
128 +
            if net.fluid.is_gas:
129 +
                # calculate ideal compression power
130 +
                compr = get_fluid(net).get_property("compressibility", p_from)
131 +
                molar_mass = net.fluid.get_molar_mass()  # [g/mol]
132 +
                R_spec = 1e3 * R_UNIVERSAL / molar_mass  # [J/(kg * K)]
133 +
                # 'kappa' heat capacity ratio:
134 +
                k = 1.4  # TODO: implement proper calculation of kappa
135 +
                w_real_isentr = (k / (k - 1)) * R_spec * compr * t0 * \
136 +
                                (np.divide(p_to, p_from) ** ((k - 1) / k) - 1)
137 +
                res_table['compr_power_mw'].values[placement_table] = \
138 +
                    w_real_isentr * abs(mf_sum_int) / 10**6
139 +
            else:
140 +
                res_table['compr_power_mw'].values[placement_table] = \
141 +
                    pump_pit[:, PL] * P_CONVERSION * vf_sum_int / 10**6
159 142
        else:
160 -
            res_table['compr_power_w'].values[placement_table] = \
161 -
                pump_pit[:, PL] * P_CONVERSION * vf_sum / internal_pipes
143 +
            placement_table, pump_pit, res_table = super().prepare_result_tables(net, options, node_name)
144 +
        res_table['deltap_bar'].values[placement_table] = pump_pit[:, PL]
162 145
163 146
    @classmethod
164 147
    def get_component_input(cls):
@@ -174,7 +157,8 @@
Loading
174 157
                ("to_junction", "u4"),
175 158
                ("std_type", dtype(object)),
176 159
                ("in_service", 'bool'),
177 -
                ("type", dtype(object))]
160 +
                ("type", dtype(object)),
161 +
                ("calc_compr_power", bool)]
178 162
179 163
    @classmethod
180 164
    def get_result_table(cls, net):
@@ -188,6 +172,18 @@
Loading
188 172
                if False, returns columns as tuples also specifying the dtypes
189 173
        :rtype: (list, bool)
190 174
        """
191 -
        result_columns = ["deltap_bar", "compr_power_w", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
192 -
                          "vdot_norm_m3_per_s"]
193 -
        return result_columns, True
175 +
        calc_compr_pow = get_net_option(net,'calc_compression_power')
176 +
        if calc_compr_pow:
177 +
            if get_fluid(net).is_gas:
178 +
                output = ["v_from_m_per_s", "v_to_m_per_s", "v_mean_m_per_s", "p_from_bar", "p_to_bar",
179 +
                          "t_from_k", "t_to_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
180 +
                          "vdot_norm_m3_per_s", "reynolds", "lambda", "normfactor_from",
181 +
                          "normfactor_to"]
182 +
            else:
183 +
                output = ["v_mean_m_per_s", "p_from_bar", "p_to_bar", "t_from_k", "t_to_k",
184 +
                          "mdot_from_kg_per_s", "mdot_to_kg_per_s", "vdot_norm_m3_per_s", "reynolds",
185 +
                          "lambda"]
186 +
            output += ["deltap_bar", "compr_power_mw"]
187 +
        else:
188 +
            output = ["deltap_bar"]
189 +
        return output, True

@@ -371,3 +371,4 @@
Loading
371 371
            _sum_by_group(idx_pit, branch_pit[:, LAMBDA], branch_pit[:, RE])
372 372
        res_table["lambda"].values[placement_table] = lambda_sum / internal_pipes
373 373
        res_table["reynolds"].values[placement_table] = reynolds_sum / internal_pipes
374 +
        return placement_table, res_table, branch_pit, node_pit

@@ -114,9 +114,9 @@
Loading
114 114
        :type node_name:
115 115
        :return: No Output.
116 116
        """
117 -
        placement_table, pc_pit, res_table = cls.prepare_result_tables(net, options, node_name)
118 117
119 -
        node_pit = net["_active_pit"]["node"]
118 +
        placement_table, res_table, pc_pit, node_pit = super().extract_results(net, options, node_name)
119 +
120 120
        node_active_idx_lookup = get_lookup(net, "node", "index_active")[node_name]
121 121
        junction_idx_lookup = get_lookup(net, "node", "index")[node_name]
122 122
        from_junction_nodes = node_active_idx_lookup[junction_idx_lookup[
@@ -128,20 +128,7 @@
Loading
128 128
        p_from = node_pit[from_junction_nodes, PINIT]
129 129
        res_table['deltap_bar'].values[placement_table] = p_to - p_from
130 130
131 -
        from_nodes = pc_pit[:, FROM_NODE].astype(np.int32)
132 -
        to_nodes = pc_pit[:, TO_NODE].astype(np.int32)
133 -
134 -
        t0 = node_pit[from_nodes, TINIT_NODE]
135 -
        t1 = node_pit[to_nodes, TINIT_NODE]
136 -
        mf = pc_pit[:, LOAD_VEC_NODES]
137 -
        vf = pc_pit[:, LOAD_VEC_NODES] / get_fluid(net).get_density((t0 + t1) / 2)
138 -
139 -
        idx_active = pc_pit[:, ELEMENT_IDX]
140 -
        idx_sort, mf_sum, vf_sum, internal_pipes = \
141 -
            _sum_by_group(idx_active, mf, vf, np.ones_like(idx_active))
142 -
        res_table["mdot_to_kg_per_s"].values[placement_table] = -mf_sum / internal_pipes
143 -
        res_table["mdot_from_kg_per_s"].values[placement_table] = mf_sum / internal_pipes
144 -
        res_table["vdot_norm_m3_per_s"].values[placement_table] = vf_sum / internal_pipes
131 +
        return placement_table, res_table, pc_pit
145 132
146 133
    @classmethod
147 134
    def get_component_input(cls):
@@ -174,6 +161,14 @@
Loading
174 161
                if False, returns columns as tuples also specifying the dtypes
175 162
        :rtype: (list, bool)
176 163
        """
177 -
        result_columns = ["deltap_bar", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
178 -
                          "vdot_norm_m3_per_s"]
179 -
        return result_columns, True
164 +
        if get_fluid(net).is_gas:
165 +
            output = ["v_from_m_per_s", "v_to_m_per_s", "v_mean_m_per_s", "p_from_bar", "p_to_bar",
166 +
                      "t_from_k", "t_to_k", "mdot_from_kg_per_s", "mdot_to_kg_per_s",
167 +
                      "vdot_norm_m3_per_s", "reynolds", "lambda", "normfactor_from",
168 +
                      "normfactor_to"]
169 +
        else:
170 +
            output = ["v_mean_m_per_s", "p_from_bar", "p_to_bar", "t_from_k", "t_to_k",
171 +
                      "mdot_from_kg_per_s", "mdot_to_kg_per_s", "vdot_norm_m3_per_s", "reynolds",
172 +
                      "lambda"]
173 +
        output += ["deltap_bar"]
174 +
        return output, True
Files Coverage
pandapipes 91.41%
setup.py 0.00%
Project Totals (76 files) 91.09%

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading