e2nIEE / pandapipes

@@ -11,7 +11,7 @@
Loading
11 11
from pandapipes.idx_branch import FROM_NODE, TO_NODE, branch_cols, \
12 12
    ACTIVE as ACTIVE_BR
13 13
from pandapipes.idx_node import NODE_TYPE, P, NODE_TYPE_T, node_cols, T, ACTIVE as ACTIVE_ND, \
14 -
    TABLE_IDX as TABLE_IDX_ND, ELEMENT_IDX as ELEMENT_IDX_ND, PC
14 +
    TABLE_IDX as TABLE_IDX_ND, ELEMENT_IDX as ELEMENT_IDX_ND
15 15
from pandapipes.properties.fluids import get_fluid
16 16
17 17
try:
@@ -32,11 +32,11 @@
Loading
32 32
33 33
default_options = {"friction_model": "nikuradse", "converged": False, "tol_p": 1e-4, "tol_v": 1e-4,
34 34
                   "tol_T": 1e-3, "tol_res": 1e-3, "iter": 10, "error_flag": False, "alpha": 1,
35 -
                   "nonlinear_method": "constant", "mode": "hydraulics",
36 -
                   "ambient_temperature": 293, "check_connectivity": True,
37 -
                   "max_iter_colebrook": 100, "only_update_hydraulic_matrix": False,
38 -
                   "reuse_internal_data": False, "use_numba": True,
39 -
                   "quit_on_inconsistency_connectivity": False, "calc_compression_power": True}
35 +
                   "nonlinear_method": "constant", "mode": "hydraulics", "ambient_temperature": 293,
36 +
                   "check_connectivity": True, "use_numba": True, "max_iter_colebrook": 100,
37 +
                   "only_update_hydraulic_matrix": False, "reuse_internal_data": False,
38 +
                   "quit_on_inconsistency_connectivity": False, "calc_compression_power": True,
39 +
                   "transient": False, "time_step": None, "dt": 60}
40 40
41 41
42 42
def get_net_option(net, option_name):

@@ -24,5 +24,6 @@
Loading
24 24
NODE_TYPE_T = 11
25 25
EXT_GRID_OCCURENCE = 12
26 26
EXT_GRID_OCCURENCE_T = 13
27 +
TINIT_OLD = 14
27 28
28 -
node_cols = 14
29 +
node_cols = 15

@@ -5,13 +5,16 @@
Loading
5 5
from warnings import warn
6 6
7 7
import numpy as np
8 +
import pandas as pd
8 9
from numpy import dtype
10 +
9 11
from pandapipes.component_models.abstract_models.node_models import NodeComponent
10 12
from pandapipes.component_models.component_toolbox import p_correction_height_air
11 13
from pandapipes.idx_node import L, ELEMENT_IDX, RHO, PINIT, node_cols, HEIGHT, TINIT, PAMB, \
12 14
    ACTIVE as ACTIVE_ND
13 15
from pandapipes.pf.pipeflow_setup import add_table_lookup, get_table_number, \
14 16
    get_lookup
17 +
from pandapipes.pf.pipeflow_setup import get_net_option
15 18
from pandapipes.properties.fluids import get_fluid
16 19
17 20
@@ -106,9 +109,17 @@
Loading
106 109
        """
107 110
        res_table = net["res_" + cls.table_name()]
108 111
112 +
        if get_net_option(net, "transient"):
113 +
            # output, all_float = cls.get_result_table(net)
114 +
            if "res_internal" not in net:
115 +
                net["res_internal"] = pd.DataFrame(
116 +
                    np.NAN, columns=["t_k"], index=np.arange(len(net["_active_pit"]["node"][:, 8])),
117 +
                    dtype=np.float64
118 +
                )
119 +
            net["res_internal"]["t_k"] = net["_active_pit"]["node"][:, TINIT]
120 +
109 121
        f, t = get_lookup(net, "node", "from_to")[cls.table_name()]
110 122
        fa, ta = get_lookup(net, "node", "from_to_active")[cls.table_name()]
111 -
112 123
        junction_pit = net["_active_pit"]["node"][fa:ta, :]
113 124
        junctions_active = get_lookup(net, "node", "active")[f:t]
114 125

@@ -6,10 +6,11 @@
Loading
6 6
7 7
from pandapipes.component_models.abstract_models.base_component import Component
8 8
from pandapipes.idx_branch import LENGTH, D, AREA, RHO, VINIT, ALPHA, QEXT, TEXT, branch_cols, \
9 -
    T_OUT, CP, VINIT_T, FROM_NODE_T, TL, \
10 -
    JAC_DERIV_DT, JAC_DERIV_DT1, JAC_DERIV_DT_NODE, LOAD_VEC_BRANCHES_T, LOAD_VEC_NODES_T
9 +
    T_OUT, CP, VINIT_T, FROM_NODE_T, TL, JAC_DERIV_DT, JAC_DERIV_DT1, JAC_DERIV_DT_NODE, \
10 +
    LOAD_VEC_BRANCHES_T, LOAD_VEC_NODES_T
11 +
from pandapipes.idx_branch import T_OUT_OLD
11 12
from pandapipes.idx_node import TINIT as TINIT_NODE
12 -
from pandapipes.pf.pipeflow_setup import get_table_number, get_lookup
13 +
from pandapipes.pf.pipeflow_setup import get_table_number, get_lookup, get_net_option
13 14
14 15
try:
15 16
    import pandaplan.core.pplog as logging
@@ -125,18 +126,41 @@
Loading
125 126
        cls.calculate_temperature_lift(net, branch_component_pit, node_pit)
126 127
        tl = branch_component_pit[:, TL]
127 128
        qext = branch_component_pit[:, QEXT]
128 -
        t_m = (t_init_i1 + t_init_i) / 2
129 129
130 -
        branch_component_pit[:, LOAD_VEC_BRANCHES_T] = \
131 -
            -(rho * area * cp * v_init * (-t_init_i + t_init_i1 - tl)
132 -
              - alpha * (t_amb - t_m) * length + qext)
130 +
        transient = get_net_option(net, "transient")
133 131
134 -
        branch_component_pit[:, JAC_DERIV_DT] = - rho * area * cp * v_init + alpha / 2 * length
135 -
        branch_component_pit[:, JAC_DERIV_DT1] = rho * area * cp * v_init + alpha / 2 * length
132 +
        tvor = branch_pit[:, T_OUT_OLD]
133 +
134 +
        delta_t = get_net_option(net, "dt")
135 +
136 +
        if transient:
137 +
            t_m = t_init_i1  # (t_init_i1 + t_init_i) / 2
138 +
            branch_component_pit[:, LOAD_VEC_BRANCHES_T] = \
139 +
                -(rho * area * cp * (t_m - tvor) * (1 / delta_t) + rho * area * cp * v_init * (
140 +
                            -t_init_i + t_init_i1 - tl) / length
141 +
                  - alpha * (t_amb - t_m) + qext)
142 +
143 +
            branch_component_pit[:, JAC_DERIV_DT] = - rho * area * cp * v_init / length + alpha \
144 +
                                                    + rho * area * cp / delta_t
145 +
            branch_component_pit[:, JAC_DERIV_DT1] = rho * area * cp * v_init / length + 0 * alpha \
146 +
                                                     + rho * area * cp / delta_t
147 +
148 +
            branch_component_pit[:, JAC_DERIV_DT_NODE] = rho * v_init \
149 +
                                                         * branch_component_pit[:, AREA]
150 +
            branch_component_pit[:, LOAD_VEC_NODES_T] = rho * v_init \
151 +
                                                        * branch_component_pit[:, AREA] * t_init_i1
152 +
        else:
153 +
            t_m = (t_init_i1 + t_init_i) / 2
154 +
            branch_component_pit[:, LOAD_VEC_BRANCHES_T] = \
155 +
                -(rho * area * cp * v_init * (-t_init_i + t_init_i1 - tl)
156 +
                  - alpha * (t_amb - t_m) * length + qext)
157 +
158 +
            branch_component_pit[:, JAC_DERIV_DT] = - rho * area * cp * v_init + alpha / 2 * length
159 +
            branch_component_pit[:, JAC_DERIV_DT1] = rho * area * cp * v_init + alpha / 2 * length
136 160
137 161
        branch_component_pit[:, JAC_DERIV_DT_NODE] = rho * v_init * branch_component_pit[:, AREA]
138 -
        branch_component_pit[:, LOAD_VEC_NODES_T] = rho * v_init * branch_component_pit[:, AREA] \
139 -
                                                    * t_init_i1
162 +
        branch_component_pit[:, LOAD_VEC_NODES_T] = rho * v_init \
163 +
                                                    * branch_component_pit[:, AREA] * t_init_i1
140 164
141 165
    @classmethod
142 166
    def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options):

@@ -4,19 +4,18 @@
Loading
4 4
5 5
import numpy as np
6 6
from numpy import linalg
7 -
from pandapower.auxiliary import ppException
8 -
from scipy.sparse.linalg import spsolve
9 -
7 +
from pandapipes.component_models.abstract_models import BranchComponent
10 8
from pandapipes.idx_branch import ACTIVE as ACTIVE_BR, FROM_NODE, TO_NODE, FROM_NODE_T, \
11 -
    TO_NODE_T, VINIT, T_OUT, VINIT_T
12 -
from pandapipes.idx_node import PINIT, TINIT, ACTIVE as ACTIVE_ND
9 +
    TO_NODE_T, VINIT, T_OUT, VINIT_T, T_OUT_OLD
10 +
from pandapipes.idx_node import PINIT, TINIT, TINIT_OLD, ACTIVE as ACTIVE_ND
13 11
from pandapipes.pf.build_system_matrix import build_system_matrix
14 12
from pandapipes.pf.derivative_calculation import calculate_derivatives_hydraulic
15 13
from pandapipes.pf.pipeflow_setup import get_net_option, get_net_options, set_net_option, \
16 -
    init_options, create_internal_results, write_internal_results, get_lookup, create_lookups, \
17 -
    initialize_pit, check_connectivity, reduce_pit, \
18 -
    set_user_pf_options, init_all_result_tables
14 +
    init_options, create_internal_results, write_internal_results, get_lookup, create_lookups,\
15 +
    initialize_pit, check_connectivity, reduce_pit, set_user_pf_options, init_all_result_tables
19 16
from pandapipes.pf.result_extraction import extract_all_results, extract_results_active_pit
17 +
from pandapower.auxiliary import ppException
18 +
from scipy.sparse.linalg import spsolve
20 19
21 20
try:
22 21
    import pandaplan.core.pplog as logging
@@ -64,21 +63,33 @@
Loading
64 63
65 64
    # Init physical constants and options
66 65
    init_options(net, local_params)
66 +
    calculation_mode = get_net_option(net, "mode")
67 67
68 68
    # init result tables
69 69
    net["converged"] = False
70 70
    init_all_result_tables(net)
71 71
72 -
    create_lookups(net)
73 -
    node_pit, branch_pit = initialize_pit(net)
72 +
    # TODO: a really bad solution, should be passed in from outside!
73 +
    if get_net_option(net, "transient"):
74 +
        if get_net_option(net, "time_step") is None:
75 +
            set_net_option(net, "time_step", 0)
76 +
    if get_net_option(net, "transient") and get_net_option(net, "time_step") != 0:
77 +
        branch_pit = net["_active_pit"]["branch"]
78 +
        node_pit = net["_active_pit"]["node"]
79 +
    else:
80 +
        create_lookups(net)
81 +
        node_pit, branch_pit = initialize_pit(net)
74 82
    if (len(node_pit) == 0) & (len(branch_pit) == 0):
75 83
        logger.warning("There are no node and branch entries defined. This might mean that your net"
76 84
                       " is empty")
77 85
        return
86 +
78 87
    calculation_mode = get_net_option(net, "mode")
79 88
    calculate_hydraulics = calculation_mode in ["hydraulics", "all"]
80 89
    calculate_heat = calculation_mode in ["heat", "all"]
81 90
91 +
    # TODO: This is not necessary in every time step, but we need the result! The result of the
92 +
    #       connectivity check is curnetly not saved anywhere!
82 93
    if get_net_option(net, "check_connectivity"):
83 94
        nodes_connected, branches_connected = check_connectivity(
84 95
            net, branch_pit, node_pit, check_heat=calculate_heat)
@@ -111,6 +122,10 @@
Loading
111 122
    extract_results_active_pit(net, node_pit, branch_pit, nodes_connected, branches_connected)
112 123
    extract_all_results(net, nodes_connected, branches_connected)
113 124
125 +
    # TODO: a really bad solution, should be passed in from outside!
126 +
    if get_net_option(net, "transient"):
127 +
        set_net_option(net, "time_step", get_net_option(net, "time_step") + 1)
128 +
114 129
115 130
def hydraulics(net):
116 131
    max_iter, nonlinear_method, tol_p, tol_v, tol_res = get_net_options(
@@ -175,6 +190,14 @@
Loading
175 190
    set_net_option(net, "converged", False)
176 191
    niter = 0
177 192
193 +
    branch_pit = net["_active_pit"]["branch"]
194 +
    node_pit = net["_active_pit"]["node"]
195 +
    if get_net_option(net, "time_step") == 0:
196 +
197 +
        node_pit[:, TINIT_OLD] = 293
198 +
        branch_pit[:, T_OUT_OLD] = 293
199 +
200 +
178 201
    # This loop is left as soon as the solver converged
179 202
    while not get_net_option(net, "converged") and niter <= max_iter:
180 203
        logger.debug("niter %d" % niter)
@@ -197,6 +220,8 @@
Loading
197 220
        logger.debug("T_out_: %s" % t_out.round(4))
198 221
        niter += 1
199 222
223 +
    node_pit[:, TINIT_OLD] = node_pit[:, TINIT]
224 +
    branch_pit[:, T_OUT_OLD] = branch_pit[:, T_OUT]
200 225
    write_internal_results(net, iterations_T=niter, error_T=error_t[niter - 1],
201 226
                           residual_norm_T=residual_norm)
202 227
@@ -271,7 +296,8 @@
Loading
271 296
    branch_pit[mask, TO_NODE_T] = branch_pit[mask, FROM_NODE]
272 297
273 298
    for comp in net['component_list']:
274 -
        comp.calculate_derivatives_thermal(net, branch_pit, node_pit, branch_lookups, options)
299 +
        if issubclass(comp, BranchComponent):
300 +
            comp.calculate_derivatives_thermal(net, branch_pit, node_pit, branch_lookups, options)
275 301
    jacobian, epsilon = build_system_matrix(net, branch_pit, node_pit, True)
276 302
277 303
    t_init_old = node_pit[:, TINIT].copy()
@@ -279,7 +305,9 @@
Loading
279 305
280 306
    x = spsolve(jacobian, epsilon)
281 307
    node_pit[:, TINIT] += x[:len(node_pit)] * options["alpha"]
282 -
    branch_pit[:, T_OUT] += x[len(node_pit):]
308 +
    branch_pit[:, T_OUT] += x[len(node_pit):] * options["alpha"]
309 +
310 +
283 311
284 312
    return branch_pit[:, T_OUT], t_out_old, node_pit[:, TINIT], t_init_old, epsilon
285 313

@@ -109,7 +109,36 @@
Loading
109 109
    return _sum_by_group_np(indices, *values)
110 110
111 111
112 -
def select_from_pit(table_index_array, input_array, data):
112 +
# TODO: not sure which function is the correct one!
113 +
# def select_from_pit(table_index_array, input_array, data):
114 +
#     """
115 +
#         Auxiliary function to retrieve values from a table like a pit. Each data entry corresponds
116 +
#         to a table_index_array entry. Example: velocities are indexed by the corresponding
117 +
#         from_nodes stored in the pipe pit.
118 +
#
119 +
#         The function inputs another array which consists of some table_index_array entries the user
120 +
#         wants to retrieve. The function is used in pandapipes results evaluation. The input array is
121 +
#         the list of from_junction entries, corresponding only to the junction elements, not
122 +
#         containing additional pipe nodes. The table_index_array is the complete list of from_nodes
123 +
#         consisting of junction element entries and additional pipe section nodes. Data corresponds
124 +
#         to the gas velocities.
125 +
#
126 +
#         :param table_index_array:
127 +
#         :type table_index_array:
128 +
#         :param input_array:
129 +
#         :type input_array:
130 +
#         :param data:
131 +
#         :type data:
132 +
#         :return:
133 +
#         :rtype:
134 +
#         """
135 +
#     sorter = np.argsort(table_index_array)
136 +
#     indices = sorter[np.searchsorted(table_index_array, input_array, sorter=sorter)]
137 +
#
138 +
#     return data[indices]
139 +
140 +
141 +
def select_from_pit(idx_active, table_index_array, input_array, data):
113 142
    """
114 143
        Auxiliary function to retrieve values from a table like a pit. Each data entry corresponds
115 144
        to a table_index_array entry. Example: velocities are indexed by the corresponding
@@ -122,6 +151,8 @@
Loading
122 151
        consisting of junction element entries and additional pipe section nodes. Data corresponds
123 152
        to the gas velocities.
124 153
154 +
        idx_active necessary for sorting, as the input_array order does not correspond to the order of pipes
155 +
125 156
        :param table_index_array:
126 157
        :type table_index_array:
127 158
        :param input_array:
@@ -131,10 +162,14 @@
Loading
131 162
        :return:
132 163
        :rtype:
133 164
        """
134 -
    sorter = np.argsort(table_index_array)
135 -
    indices = sorter[np.searchsorted(table_index_array, input_array, sorter=sorter)]
136 165
137 -
    return data[indices]
166 +
    input_array = np.unique(input_array)
167 +
    x, result = np.where(table_index_array==input_array[:,np.newaxis])
168 +
169 +
    pipidxsort = np.argsort(idx_active[result])
170 +
    data = data[result]
171 +
    return data[pipidxsort]
172 +
138 173
139 174
140 175
@jit(nopython=True)

@@ -42,5 +42,6 @@
Loading
42 42
TL = 37  # Temperature lift [K]
43 43
BRANCH_TYPE = 38  # branch type relevant for the pressure controller
44 44
PRESSURE_RATIO = 39  # boost ratio for compressors with proportional pressure lift
45 +
T_OUT_OLD = 40
45 46
46 -
branch_cols = 40
47 +
branch_cols = 41

@@ -6,6 +6,7 @@
Loading
6 6
import pandas as pd
7 7
from pandapipes.constants import NORMAL_PRESSURE, TEMP_GRADIENT_KPM, AVG_TEMPERATURE_K, \
8 8
    HEIGHT_EXPONENT
9 +
from pandapipes.pf.pipeflow_setup import get_net_option
9 10
10 11
11 12
def p_correction_height_air(height):
Files Coverage
pandapipes 88.12%
setup.py 0.00%
Project Totals (79 files) 87.84%

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