e2nIEE / pandapipes

Compare f9b7cb0 ... +57 ... fc55461

Coverage Reach
pandapipes/component_models/abstract_models/branch_w_internals_models.py pandapipes/component_models/abstract_models/branch_models.py pandapipes/component_models/abstract_models/branch_wo_internals_models.py pandapipes/component_models/abstract_models/base_component.py pandapipes/component_models/abstract_models/const_flow_models.py pandapipes/component_models/abstract_models/branch_wzerolength_models.py pandapipes/component_models/abstract_models/circulation_pump.py pandapipes/component_models/abstract_models/node_models.py pandapipes/component_models/abstract_models/node_element_models.py pandapipes/component_models/abstract_models/__init__.py pandapipes/component_models/pipe_component.py pandapipes/component_models/pump_component.py pandapipes/component_models/ext_grid_component.py pandapipes/component_models/pressure_control_component.py pandapipes/component_models/junction_component.py pandapipes/component_models/heat_exchanger_component.py pandapipes/component_models/valve_component.py pandapipes/component_models/component_toolbox.py pandapipes/component_models/compressor_component.py pandapipes/component_models/circulation_pump_pressure_component.py pandapipes/component_models/circulation_pump_mass_component.py pandapipes/component_models/sink_component.py pandapipes/component_models/source_component.py pandapipes/component_models/__init__.py pandapipes/pf/pipeflow_setup.py pandapipes/pf/derivative_toolbox_numba.py pandapipes/pf/result_extraction.py pandapipes/pf/build_system_matrix.py pandapipes/pf/derivative_toolbox.py pandapipes/pf/derivative_calculation.py pandapipes/pf/internals_toolbox.py pandapipes/pf/__init__.py pandapipes/plotting/collections.py pandapipes/plotting/patch_makers.py pandapipes/plotting/simple_plot.py pandapipes/plotting/generic_geodata.py pandapipes/plotting/__init__.py pandapipes/plotting/pipeflow_results.py pandapipes/plotting/plotting_toolbox.py pandapipes/multinet/control/controller/multinet_control.py pandapipes/multinet/control/controller/__init__.py pandapipes/multinet/control/run_control_multinet.py pandapipes/multinet/control/__init__.py pandapipes/multinet/timeseries/run_time_series_multinet.py pandapipes/multinet/timeseries/__init__.py pandapipes/multinet/multinet.py pandapipes/multinet/create_multinet.py pandapipes/multinet/__init__.py pandapipes/properties/fluids.py pandapipes/properties/properties_toolbox.py pandapipes/properties/__init__.py pandapipes/networks/simple_water_networks.py pandapipes/networks/simple_gas_networks.py pandapipes/networks/simple_heat_transfer_networks.py pandapipes/networks/nw_aux.py pandapipes/networks/__init__.py pandapipes/create.py pandapipes/toolbox.py pandapipes/pipeflow.py pandapipes/io/io_utils.py pandapipes/io/file_io.py pandapipes/io/convert_format.py pandapipes/io/__init__.py pandapipes/std_types/std_types.py pandapipes/std_types/std_type_class.py pandapipes/std_types/__init__.py pandapipes/topology/create_graph.py pandapipes/topology/graph_searches.py pandapipes/topology/__init__.py pandapipes/timeseries/run_time_series.py pandapipes/timeseries/__init__.py pandapipes/idx_branch.py pandapipes/pandapipes_net.py pandapipes/idx_node.py pandapipes/control/run_control.py pandapipes/control/__init__.py pandapipes/__init__.py pandapipes/constants.py setup.py

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -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

@@ -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,12 @@
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 +
        node_pit[:, TINIT_OLD] = 293
197 +
        branch_pit[:, T_OUT_OLD] = 293
198 +
178 199
    # This loop is left as soon as the solver converged
179 200
    while not get_net_option(net, "converged") and niter <= max_iter:
180 201
        logger.debug("niter %d" % niter)
@@ -197,6 +218,8 @@
Loading
197 218
        logger.debug("T_out_: %s" % t_out.round(4))
198 219
        niter += 1
199 220
221 +
    node_pit[:, TINIT_OLD] = node_pit[:, TINIT]
222 +
    branch_pit[:, T_OUT_OLD] = branch_pit[:, T_OUT]
200 223
    write_internal_results(net, iterations_T=niter, error_T=error_t[niter - 1],
201 224
                           residual_norm_T=residual_norm)
202 225
@@ -271,15 +294,18 @@
Loading
271 294
    branch_pit[mask, TO_NODE_T] = branch_pit[mask, FROM_NODE]
272 295
273 296
    for comp in net['component_list']:
274 -
        comp.calculate_derivatives_thermal(net, branch_pit, node_pit, branch_lookups, options)
297 +
        if issubclass(comp, BranchComponent):
298 +
            comp.calculate_derivatives_thermal(net, branch_pit, node_pit, branch_lookups, options)
275 299
    jacobian, epsilon = build_system_matrix(net, branch_pit, node_pit, True)
276 300
277 301
    t_init_old = node_pit[:, TINIT].copy()
278 302
    t_out_old = branch_pit[:, T_OUT].copy()
279 303
280 304
    x = spsolve(jacobian, epsilon)
281 305
    node_pit[:, TINIT] += x[:len(node_pit)] * options["alpha"]
282 -
    branch_pit[:, T_OUT] += x[len(node_pit):]
306 +
    branch_pit[:, T_OUT] += x[len(node_pit):] * options["alpha"]
307 +
308 +
283 309
284 310
    return branch_pit[:, T_OUT], t_out_old, node_pit[:, TINIT], t_init_old, epsilon
285 311

@@ -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,6 +109,15 @@
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 123

@@ -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):

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Click to load this diff.
Loading diff...

Learn more Showing 6 files with coverage changes found.

Changes in pandapipes/component_models/abstract_models/base_component.py
-1
+1
Loading file...
Changes in pandapipes/pf/pipeflow_setup.py
-4
+4
Loading file...
Changes in pandapipes/pf/result_extraction.py
-6
+6
Loading file...
Changes in pandapipes/pf/derivative_calculation.py
-5
+5
Loading file...
Changes in pandapipes/pf/internals_toolbox.py
-9
+9
Loading file...
Changes in pandapipes/pf/derivative_toolbox_numba.py
-22
+22
Loading file...

59 Commits

-1
-1
+40
+32
+8
-40
-32
-8
Hiding 1 contexual commits
+40
+32
+8
Hiding 8 contexual commits
+1
+1
Hiding 3 contexual commits
Hiding 26 contexual commits
+39
-39
Files Coverage
pandapipes 0.77% 88.12%
setup.py 0.00%
Project Totals (79 files) 87.84%
Loading