From ebd60a3e7cd2096ad2dbc43678187591c4fc261f Mon Sep 17 00:00:00 2001 From: sdrauz Date: Fri, 8 Sep 2023 13:45:59 +0200 Subject: [PATCH 1/5] - define calculate_thermal_derivative more gobally - rename TINIT in TINIT_IN and T_OUT in TINIT_OUT in Branch --- .../abstract_models/base_component.py | 46 +++---------- .../abstract_models/branch_models.py | 69 +------------------ .../branch_w_internals_models.py | 10 +-- .../branch_wo_internals_models.py | 10 +-- .../abstract_models/circulation_pump.py | 4 -- .../circulation_pump_mass_component.py | 3 - .../circulation_pump_pressure_component.py | 4 -- .../flow_control_component.py | 20 +----- .../heat_exchanger_component.py | 17 +---- pandapipes/component_models/pipe_component.py | 27 ++------ .../pressure_control_component.py | 17 +---- pandapipes/component_models/pump_component.py | 21 +----- .../component_models/valve_component.py | 17 +---- pandapipes/idx_branch.py | 4 +- pandapipes/pf/derivative_calculation.py | 43 ++++++++++-- pandapipes/pf/derivative_toolbox.py | 6 +- pandapipes/pf/derivative_toolbox_numba.py | 6 +- pandapipes/pf/result_extraction.py | 10 +-- pandapipes/pipeflow.py | 19 +++-- .../pipeflow_openmodelica_comparison.py | 2 +- .../test_pipeflow_analytic_comparison.py | 4 +- tutorials/temperature_calculation.ipynb | 2 +- 22 files changed, 98 insertions(+), 263 deletions(-) diff --git a/pandapipes/component_models/abstract_models/base_component.py b/pandapipes/component_models/abstract_models/base_component.py index b5ce3a601..350755c37 100644 --- a/pandapipes/component_models/abstract_models/base_component.py +++ b/pandapipes/component_models/abstract_models/base_component.py @@ -78,6 +78,15 @@ def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lo def adaption_after_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options): pass + @classmethod + def adaption_before_derivatives_thermal(cls, net, branch_pit, node_pit, idx_lookups, options): + pass + + @classmethod + def adaption_after_derivatives_thermal(cls, net, branch_pit, node_pit, idx_lookups, options): + pass + + @classmethod def create_node_lookups(cls, net, ft_lookups, table_lookup, idx_lookups, current_start, current_table, internal_nodes_lookup): @@ -151,40 +160,3 @@ def create_pit_branch_entries(cls, net, branch_pit): """ pass - @classmethod - def calculate_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options): - """ - Function which creates derivatives. - - :param net: The pandapipes network - :type net: pandapipesNet - :param branch_pit: - :type branch_pit: - :param node_pit: - :type node_pit: - :param idx_lookups: - :type idx_lookups: - :param options: - :type options: - :return: No Output. - """ - pass - - @classmethod - def calculate_derivatives_thermal(cls, net, branch_pit, node_pit, idx_lookups, options): - """ - Function which creates derivatives. - - :param net: The pandapipes network - :type net: pandapipesNet - :param branch_pit: - :type branch_pit: - :param node_pit: - :type node_pit: - :param idx_lookups: - :type idx_lookups: - :param options: - :type options: - :return: No Output. - """ - pass diff --git a/pandapipes/component_models/abstract_models/branch_models.py b/pandapipes/component_models/abstract_models/branch_models.py index 4eeac9cc6..f9d98d6e8 100644 --- a/pandapipes/component_models/abstract_models/branch_models.py +++ b/pandapipes/component_models/abstract_models/branch_models.py @@ -5,10 +5,7 @@ import numpy as np from pandapipes.component_models.abstract_models.base_component import Component -from pandapipes.idx_branch import LENGTH, D, AREA, RHO, VINIT, ALPHA, QEXT, TEXT, branch_cols, \ - T_OUT, CP, VINIT_T, FROM_NODE_T, TL, \ - JAC_DERIV_DT, JAC_DERIV_DT1, JAC_DERIV_DT_NODE, LOAD_VEC_BRANCHES_T, LOAD_VEC_NODES_T -from pandapipes.idx_node import TINIT as TINIT_NODE +from pandapipes.idx_branch import VINIT, branch_cols from pandapipes.pf.pipeflow_setup import get_table_number, get_lookup try: @@ -94,70 +91,6 @@ def create_pit_branch_entries(cls, net, branch_pit): branch_component_pit[:, VINIT] = 0.1 return branch_component_pit, node_pit, from_nodes, to_nodes - @classmethod - def calculate_derivatives_thermal(cls, net, branch_pit, node_pit, idx_lookups, options): - """ - Function which creates derivatives of the temperature. - - :param net: - :type net: - :param branch_pit: - :type branch_pit: - :param node_pit: - :type node_pit: - :param idx_lookups: - :type idx_lookups: - :param options: - :type options: - :return: No Output. - """ - f, t = idx_lookups[cls.table_name()] - branch_component_pit = branch_pit[f:t, :] - cp = branch_component_pit[:, CP] - rho = branch_component_pit[:, RHO] - v_init = branch_component_pit[:, VINIT_T] - from_nodes = branch_component_pit[:, FROM_NODE_T].astype(np.int32) - t_init_i = node_pit[from_nodes, TINIT_NODE] - t_init_i1 = branch_component_pit[:, T_OUT] - t_amb = branch_component_pit[:, TEXT] - area = branch_component_pit[:, AREA] - length = branch_component_pit[:, LENGTH] - alpha = branch_component_pit[:, ALPHA] * np.pi * branch_component_pit[:, D] - cls.calculate_temperature_lift(net, branch_component_pit, node_pit) - tl = branch_component_pit[:, TL] - qext = branch_component_pit[:, QEXT] - t_m = (t_init_i1 + t_init_i) / 2 - - branch_component_pit[:, LOAD_VEC_BRANCHES_T] = \ - -(rho * area * cp * v_init * (-t_init_i + t_init_i1 - tl) - - alpha * (t_amb - t_m) * length + qext) - - branch_component_pit[:, JAC_DERIV_DT] = - rho * area * cp * v_init + alpha / 2 * length - branch_component_pit[:, JAC_DERIV_DT1] = rho * area * cp * v_init + alpha / 2 * length - - branch_component_pit[:, JAC_DERIV_DT_NODE] = rho * v_init * branch_component_pit[:, AREA] - branch_component_pit[:, LOAD_VEC_NODES_T] = rho * v_init * branch_component_pit[:, AREA] \ - * t_init_i1 - - @classmethod - def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options): - pass - - @classmethod - def calculate_temperature_lift(cls, net, branch_component_pit, node_pit): - """ - - :param net: - :type net: - :param branch_component_pit: - :type branch_component_pit: - :param node_pit: - :type node_pit: - :return: - :rtype: - """ - raise NotImplementedError - @classmethod def extract_results(cls, net, options, branch_results, mode): raise NotImplementedError diff --git a/pandapipes/component_models/abstract_models/branch_w_internals_models.py b/pandapipes/component_models/abstract_models/branch_w_internals_models.py index 1b88f0eac..fa7a579e4 100644 --- a/pandapipes/component_models/abstract_models/branch_w_internals_models.py +++ b/pandapipes/component_models/abstract_models/branch_w_internals_models.py @@ -6,7 +6,7 @@ from pandapipes.component_models.abstract_models.branch_models import BranchComponent from pandapipes.component_models.component_toolbox import set_entry_check_repeat -from pandapipes.idx_branch import ACTIVE, FROM_NODE, TO_NODE, TINIT, RHO, ETA, CP, ELEMENT_IDX +from pandapipes.idx_branch import ACTIVE, FROM_NODE, TO_NODE, TINIT_IN, RHO, ETA, CP, ELEMENT_IDX from pandapipes.idx_node import L, node_cols, TINIT as TINIT_NODE from pandapipes.pf.pipeflow_setup import add_table_lookup, get_lookup, get_table_number from pandapipes.properties.fluids import get_fluid @@ -196,12 +196,12 @@ def create_pit_branch_entries(cls, net, branch_pit): internal_pipe_number, has_internals) branch_w_internals_pit[:, FROM_NODE] = from_nodes branch_w_internals_pit[:, TO_NODE] = to_nodes - branch_w_internals_pit[:, TINIT] = (node_pit[from_nodes, TINIT_NODE] + node_pit[ + branch_w_internals_pit[:, TINIT_IN] = (node_pit[from_nodes, TINIT_NODE] + node_pit[ to_nodes, TINIT_NODE]) / 2 fluid = get_fluid(net) - branch_w_internals_pit[:, RHO] = fluid.get_density(branch_w_internals_pit[:, TINIT]) - branch_w_internals_pit[:, ETA] = fluid.get_viscosity(branch_w_internals_pit[:, TINIT]) - branch_w_internals_pit[:, CP] = fluid.get_heat_capacity(branch_w_internals_pit[:, TINIT]) + branch_w_internals_pit[:, RHO] = fluid.get_density(branch_w_internals_pit[:, TINIT_IN]) + branch_w_internals_pit[:, ETA] = fluid.get_viscosity(branch_w_internals_pit[:, TINIT_IN]) + branch_w_internals_pit[:, CP] = fluid.get_heat_capacity(branch_w_internals_pit[:, TINIT_IN]) return branch_w_internals_pit, internal_pipe_number diff --git a/pandapipes/component_models/abstract_models/branch_wo_internals_models.py b/pandapipes/component_models/abstract_models/branch_wo_internals_models.py index 106895d50..6872e6df2 100644 --- a/pandapipes/component_models/abstract_models/branch_wo_internals_models.py +++ b/pandapipes/component_models/abstract_models/branch_wo_internals_models.py @@ -4,7 +4,7 @@ from pandapipes.component_models.abstract_models.branch_models import BranchComponent -from pandapipes.idx_branch import FROM_NODE, TO_NODE, TINIT, ELEMENT_IDX, RHO, ETA, CP, ACTIVE +from pandapipes.idx_branch import FROM_NODE, TO_NODE, TINIT_IN, ELEMENT_IDX, RHO, ETA, CP, ACTIVE from pandapipes.idx_node import TINIT as TINIT_NODE from pandapipes.pf.pipeflow_setup import add_table_lookup @@ -82,12 +82,12 @@ def create_pit_branch_entries(cls, net, branch_pit): branch_wo_internals_pit[:, ELEMENT_IDX] = net[cls.table_name()].index.values branch_wo_internals_pit[:, FROM_NODE] = from_nodes branch_wo_internals_pit[:, TO_NODE] = to_nodes - branch_wo_internals_pit[:, TINIT] = (node_pit[from_nodes, TINIT_NODE] + branch_wo_internals_pit[:, TINIT_IN] = (node_pit[from_nodes, TINIT_NODE] + node_pit[to_nodes, TINIT_NODE]) / 2 fluid = get_fluid(net) - branch_wo_internals_pit[:, RHO] = fluid.get_density(branch_wo_internals_pit[:, TINIT]) - branch_wo_internals_pit[:, ETA] = fluid.get_viscosity(branch_wo_internals_pit[:, TINIT]) - branch_wo_internals_pit[:, CP] = fluid.get_heat_capacity(branch_wo_internals_pit[:, TINIT]) + branch_wo_internals_pit[:, RHO] = fluid.get_density(branch_wo_internals_pit[:, TINIT_IN]) + branch_wo_internals_pit[:, ETA] = fluid.get_viscosity(branch_wo_internals_pit[:, TINIT_IN]) + branch_wo_internals_pit[:, CP] = fluid.get_heat_capacity(branch_wo_internals_pit[:, TINIT_IN]) branch_wo_internals_pit[:, ACTIVE] = net[cls.table_name()][cls.active_identifier()].values return branch_wo_internals_pit diff --git a/pandapipes/component_models/abstract_models/circulation_pump.py b/pandapipes/component_models/abstract_models/circulation_pump.py index 767dc3368..3c3e338de 100644 --- a/pandapipes/component_models/abstract_models/circulation_pump.py +++ b/pandapipes/component_models/abstract_models/circulation_pump.py @@ -92,10 +92,6 @@ def create_pit_branch_entries(cls, net, branch_pit): circ_pump_pit[:, AREA] = circ_pump_pit[:, D] ** 2 * np.pi / 4 circ_pump_pit[:, ACTIVE] = False - @classmethod - def calculate_temperature_lift(cls, net, pipe_pit, node_pit): - raise NotImplementedError - @classmethod def extract_results(cls, net, options, branch_results, mode): """ diff --git a/pandapipes/component_models/circulation_pump_mass_component.py b/pandapipes/component_models/circulation_pump_mass_component.py index d18e299d3..699d1e416 100644 --- a/pandapipes/component_models/circulation_pump_mass_component.py +++ b/pandapipes/component_models/circulation_pump_mass_component.py @@ -72,6 +72,3 @@ def create_pit_node_entries(cls, net, node_pit): index = junction_idx_lookups[juncts] node_pit[index, LOAD] += loads_sum - @classmethod - def calculate_temperature_lift(cls, net, pipe_pit, node_pit): - pass diff --git a/pandapipes/component_models/circulation_pump_pressure_component.py b/pandapipes/component_models/circulation_pump_pressure_component.py index c1ef5abd3..6cfbf2eb9 100644 --- a/pandapipes/component_models/circulation_pump_pressure_component.py +++ b/pandapipes/component_models/circulation_pump_pressure_component.py @@ -63,7 +63,3 @@ def create_pit_node_entries(cls, net, node_pit): p_in = press - circ_pump.plift_bar.values set_fixed_node_entries(net, node_pit, junction, circ_pump.type.values, p_in, None, cls.get_connected_node_type(), "p") - - @classmethod - def calculate_temperature_lift(cls, net, pipe_pit, node_pit): - pass diff --git a/pandapipes/component_models/flow_control_component.py b/pandapipes/component_models/flow_control_component.py index 739e5ada2..33b2d3714 100644 --- a/pandapipes/component_models/flow_control_component.py +++ b/pandapipes/component_models/flow_control_component.py @@ -8,7 +8,7 @@ from pandapipes.component_models.abstract_models import BranchWZeroLengthComponent, get_fluid from pandapipes.component_models.component_toolbox import standard_branch_wo_internals_result_lookup from pandapipes.component_models.junction_component import Junction -from pandapipes.idx_branch import D, AREA, TL, JAC_DERIV_DP, JAC_DERIV_DP1, JAC_DERIV_DV, VINIT, \ +from pandapipes.idx_branch import D, AREA, JAC_DERIV_DP, JAC_DERIV_DP1, JAC_DERIV_DV, VINIT, \ RHO, LOAD_VEC_BRANCHES, ELEMENT_IDX from pandapipes.pf.result_extraction import extract_branch_results_without_internals @@ -50,9 +50,6 @@ def create_pit_branch_entries(cls, net, branch_pit): fc_pit[:, VINIT] = net[cls.table_name()].controlled_mdot_kg_per_s.values / \ (fc_pit[:, AREA] * fc_pit[:, RHO]) - @classmethod - def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options): - pass @classmethod def adaption_after_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lookups, options): @@ -68,21 +65,6 @@ def adaption_after_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_loo fc_pit[active, JAC_DERIV_DV] = 1 fc_pit[active, LOAD_VEC_BRANCHES] = 0 - @classmethod - def calculate_temperature_lift(cls, net, branch_component_pit, node_pit): - """ - - :param net: - :type net: - :param branch_component_pit: - :type branch_component_pit: - :param node_pit: - :type node_pit: - :return: - :rtype: - """ - branch_component_pit[:, TL] = 0 - @classmethod def extract_results(cls, net, options, branch_results, mode): required_results_hyd, required_results_ht = standard_branch_wo_internals_result_lookup(net) diff --git a/pandapipes/component_models/heat_exchanger_component.py b/pandapipes/component_models/heat_exchanger_component.py index 6304bb4dd..5bc6dae3c 100644 --- a/pandapipes/component_models/heat_exchanger_component.py +++ b/pandapipes/component_models/heat_exchanger_component.py @@ -9,7 +9,7 @@ from pandapipes.component_models.abstract_models.branch_wzerolength_models import \ BranchWZeroLengthComponent from pandapipes.component_models.junction_component import Junction -from pandapipes.idx_branch import TL, ALPHA, TEXT, QEXT, T_OUT, D, AREA, LOSS_COEFFICIENT as LC +from pandapipes.idx_branch import TL, ALPHA, TEXT, QEXT, TINIT_OUT, D, AREA, LOSS_COEFFICIENT as LC from pandapipes.pf.pipeflow_setup import get_fluid from pandapipes.pf.result_extraction import extract_branch_results_without_internals @@ -58,7 +58,6 @@ def create_pit_branch_entries(cls, net, branch_pit): heat_exchanger_pit[:, ALPHA] = 0 heat_exchanger_pit[:, QEXT] = net[cls.table_name()].qext_w.values heat_exchanger_pit[:, TEXT] = 293.15 - heat_exchanger_pit[:, T_OUT] = 307 @classmethod def extract_results(cls, net, options, branch_results, mode): @@ -81,20 +80,6 @@ def extract_results(cls, net, options, branch_results, mode): extract_branch_results_without_internals(net, branch_results, required_results_hyd, required_results_ht, cls.table_name(), mode) - @classmethod - def calculate_temperature_lift(cls, net, branch_component_pit, node_pit): - """ - - :param net: - :type net: - :param branch_component_pit: - :type branch_component_pit: - :param node_pit: - :type node_pit: - :return: - :rtype: - """ - branch_component_pit[:, TL] = 0 @classmethod def get_component_input(cls): diff --git a/pandapipes/component_models/pipe_component.py b/pandapipes/component_models/pipe_component.py index af399f15c..600f06726 100644 --- a/pandapipes/component_models/pipe_component.py +++ b/pandapipes/component_models/pipe_component.py @@ -11,7 +11,7 @@ from pandapipes.component_models.junction_component import Junction from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE from pandapipes.idx_branch import FROM_NODE, TO_NODE, LENGTH, D, AREA, K, \ - VINIT, ALPHA, QEXT, TEXT, LOSS_COEFFICIENT as LC, T_OUT, TL + VINIT, ALPHA, QEXT, TEXT, LOSS_COEFFICIENT as LC, TINIT_OUT from pandapipes.idx_node import PINIT, HEIGHT, TINIT as TINIT_NODE, \ RHO as RHO_NODES, PAMB, ACTIVE as ACTIVE_ND from pandapipes.pf.pipeflow_setup import get_fluid, get_lookup @@ -153,24 +153,9 @@ def create_pit_branch_entries(cls, net, branch_pit): node_pit = net["_pit"]["node"] to_nodes = pipe_pit[:, TO_NODE].astype(np.int32) - pipe_pit[:, T_OUT] = node_pit[to_nodes, TINIT_NODE] + pipe_pit[:, TINIT_OUT] = node_pit[to_nodes, TINIT_NODE] pipe_pit[:, AREA] = pipe_pit[:, D] ** 2 * np.pi / 4 - @classmethod - def calculate_temperature_lift(cls, net, branch_component_pit, node_pit): - """ - - :param net: - :type net: - :param branch_component_pit: - :type branch_component_pit: - :param node_pit: - :type node_pit: - :return: - :rtype: - """ - branch_component_pit[:, TL] = 0 - @classmethod def extract_results(cls, net, options, branch_results, mode): res_nodes_from_hyd = [("p_from_bar", "p_from"), ("mdot_from_kg_per_s", "mf_from")] @@ -221,7 +206,7 @@ def get_internal_results(cls, net, pipe): v_pipe_idx = np.repeat(pipe, internal_sections[pipe]) pipe_results = dict() pipe_results["PINIT"] = np.zeros((len(p_node_idx), 2), dtype=np.float64) - pipe_results["TINIT"] = np.zeros((len(p_node_idx), 2), dtype=np.float64) + pipe_results["TINIT_IN"] = np.zeros((len(p_node_idx), 2), dtype=np.float64) pipe_results["VINIT_FROM"] = np.zeros((len(v_pipe_idx), 2), dtype=np.float64) pipe_results["VINIT_TO"] = np.zeros((len(v_pipe_idx), 2), dtype=np.float64) pipe_results["VINIT_MEAN"] = np.zeros((len(v_pipe_idx), 2), dtype=np.float64) @@ -287,8 +272,8 @@ def get_internal_results(cls, net, pipe): pipe_results["PINIT"][:, 0] = p_node_idx pipe_results["PINIT"][:, 1] = p_node_data - pipe_results["TINIT"][:, 0] = p_node_idx - pipe_results["TINIT"][:, 1] = t_node_data + pipe_results["TINIT_IN"][:, 0] = p_node_idx + pipe_results["TINIT_IN"][:, 1] = t_node_data else: logger.warning("For at least one pipe no internal data is available.") @@ -362,7 +347,7 @@ def plot_pipe(cls, net, pipe, pipe_results): pipe_p_data_idx = np.where(pipe_results["PINIT"][:, 0] == pipe) pipe_v_data_idx = np.where(pipe_results["VINIT_MEAN"][:, 0] == pipe) pipe_p_data = pipe_results["PINIT"][pipe_p_data_idx, 1] - pipe_t_data = pipe_results["TINIT"][pipe_p_data_idx, 1] + pipe_t_data = pipe_results["TINIT_IN"][pipe_p_data_idx, 1] pipe_v_data = pipe_results["VINIT_MEAN"][pipe_v_data_idx, 1] node_pit = net["_pit"]["node"] diff --git a/pandapipes/component_models/pressure_control_component.py b/pandapipes/component_models/pressure_control_component.py index 89d2f220f..e582925bb 100644 --- a/pandapipes/component_models/pressure_control_component.py +++ b/pandapipes/component_models/pressure_control_component.py @@ -8,7 +8,7 @@ from pandapipes.component_models.abstract_models.branch_wzerolength_models import \ BranchWZeroLengthComponent from pandapipes.component_models.junction_component import Junction -from pandapipes.idx_branch import D, AREA, TL, \ +from pandapipes.idx_branch import D, AREA, \ JAC_DERIV_DP, JAC_DERIV_DP1, JAC_DERIV_DV, BRANCH_TYPE, LOSS_COEFFICIENT as LC from pandapipes.idx_node import PINIT, NODE_TYPE, PC from pandapipes.pf.pipeflow_setup import get_lookup @@ -79,21 +79,6 @@ def adaption_after_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_loo press_pit[pc_branch, JAC_DERIV_DP1] = 0 press_pit[pc_branch, JAC_DERIV_DV] = 0 - @classmethod - def calculate_temperature_lift(cls, net, branch_component_pit, node_pit): - """ - - :param net: - :type net: - :param branch_component_pit: - :type branch_component_pit: - :param node_pit: - :type node_pit: - :return: - :rtype: - """ - branch_component_pit[:, TL] = 0 - @classmethod def extract_results(cls, net, options, branch_results, mode): """ diff --git a/pandapipes/component_models/pump_component.py b/pandapipes/component_models/pump_component.py index 3de660002..5a3b23606 100644 --- a/pandapipes/component_models/pump_component.py +++ b/pandapipes/component_models/pump_component.py @@ -11,8 +11,8 @@ from pandapipes.component_models.abstract_models.branch_wzerolength_models import \ BranchWZeroLengthComponent from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE, R_UNIVERSAL, P_CONVERSION -from pandapipes.idx_branch import STD_TYPE, VINIT, D, AREA, TL, LOSS_COEFFICIENT as LC, FROM_NODE, \ - TINIT, PL +from pandapipes.idx_branch import STD_TYPE, VINIT, D, AREA, LOSS_COEFFICIENT as LC, FROM_NODE, \ + TINIT_IN, PL from pandapipes.idx_node import PINIT, PAMB, TINIT as TINIT_NODE from pandapipes.pf.pipeflow_setup import get_fluid, get_net_option, get_lookup from pandapipes.pf.result_extraction import extract_branch_results_without_internals @@ -79,7 +79,7 @@ def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lo fluid = get_fluid(net) p_from = node_pit[from_nodes, PAMB] + node_pit[from_nodes, PINIT] # p_to = node_pit[to_nodes, PAMB] + node_pit[to_nodes, PINIT] - numerator = NORMAL_PRESSURE * pump_pit[:, TINIT] + numerator = NORMAL_PRESSURE * pump_pit[:, TINIT_IN] v_mps = pump_pit[:, VINIT] if fluid.is_gas: # consider volume flow at inlet @@ -95,21 +95,6 @@ def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lo pl = np.array(list(map(lambda x, y: x.get_pressure(y), fcts, vol))) pump_pit[:, PL] = pl - @classmethod - def calculate_temperature_lift(cls, net, branch_component_pit, node_pit): - """ - - :param net: - :type net: - :param branch_component_pit: - :type branch_component_pit: - :param node_pit: - :type node_pit: - :return: - :rtype: - """ - branch_component_pit[:, TL] = 0 - @classmethod def extract_results(cls, net, options, branch_results, mode): """ diff --git a/pandapipes/component_models/valve_component.py b/pandapipes/component_models/valve_component.py index 6c32676c0..ff2b9451e 100644 --- a/pandapipes/component_models/valve_component.py +++ b/pandapipes/component_models/valve_component.py @@ -9,7 +9,7 @@ from pandapipes.component_models.abstract_models.branch_wzerolength_models import \ BranchWZeroLengthComponent from pandapipes.component_models.junction_component import Junction -from pandapipes.idx_branch import D, AREA, LOSS_COEFFICIENT as LC, TL +from pandapipes.idx_branch import D, AREA, LOSS_COEFFICIENT as LC from pandapipes.pf.result_extraction import extract_branch_results_without_internals from pandapipes.properties.fluids import get_fluid @@ -52,21 +52,6 @@ def create_pit_branch_entries(cls, net, branch_pit): valve_pit[:, AREA] = valve_pit[:, D] ** 2 * np.pi / 4 valve_pit[:, LC] = net[cls.table_name()].loss_coefficient.values - @classmethod - def calculate_temperature_lift(cls, net, branch_component_pit, node_pit): - """ - - :param net: - :type net: - :param branch_component_pit: - :type branch_component_pit: - :param node_pit: - :type node_pit: - :return: - :rtype: - """ - branch_component_pit[:, TL] = 0 - @classmethod def get_component_input(cls): """ diff --git a/pandapipes/idx_branch.py b/pandapipes/idx_branch.py index 2b59f2360..0db7397e0 100644 --- a/pandapipes/idx_branch.py +++ b/pandapipes/idx_branch.py @@ -17,7 +17,7 @@ RHO = 8 # Density in [kg/m^3 ETA = 9 # Dynamic viscosity in [Pas] K = 10 # Pipe roughness in [m] -TINIT = 11 # Temperature in [K] +TINIT_IN = 11 # Temperature in [K] VINIT = 12 # velocity in [m/s] RE = 13 # Reynolds number LAMBDA = 14 # Lambda @@ -33,7 +33,7 @@ JAC_DERIV_DT = 24 JAC_DERIV_DT1 = 25 LOAD_VEC_BRANCHES_T = 26 -T_OUT = 27 # Internal slot for outlet pipe temperature +TINIT_OUT = 27 # Internal slot for outlet pipe temperature JAC_DERIV_DT_NODE = 28 # Slot for the derivative fpr T for the nodes connected to branch LOAD_VEC_NODES_T = 29 VINIT_T = 30 diff --git a/pandapipes/pf/derivative_calculation.py b/pandapipes/pf/derivative_calculation.py index 800834370..95f051771 100644 --- a/pandapipes/pf/derivative_calculation.py +++ b/pandapipes/pf/derivative_calculation.py @@ -1,8 +1,10 @@ import numpy as np -from pandapipes.idx_branch import LENGTH, ETA, RHO, D, K, RE, LAMBDA, TINIT, LOAD_VEC_BRANCHES, \ +from pandapipes.idx_branch import LENGTH, ETA, RHO, D, K, RE, LAMBDA, TINIT_IN, LOAD_VEC_BRANCHES, \ JAC_DERIV_DV, JAC_DERIV_DP, JAC_DERIV_DP1, LOAD_VEC_NODES, JAC_DERIV_DV_NODE, VINIT, \ - FROM_NODE, TO_NODE + FROM_NODE, TO_NODE, CP, VINIT_T, FROM_NODE_T, TINIT_OUT, TEXT, AREA, ALPHA, TL, QEXT, LOAD_VEC_NODES_T, \ + LOAD_VEC_BRANCHES_T, JAC_DERIV_DT, JAC_DERIV_DT1, JAC_DERIV_DT_NODE +from pandapipes.idx_node import TINIT as TINIT_NODE from pandapipes.properties.fluids import get_fluid @@ -35,7 +37,7 @@ def calculate_derivatives_hydraulic(net, branch_pit, node_pit, options): to_nodes = branch_pit[:, TO_NODE].astype(np.int32) tinit_branch, height_difference, p_init_i_abs, p_init_i1_abs = \ get_derived_values(node_pit, from_nodes, to_nodes, options["use_numba"]) - branch_pit[:, TINIT] = tinit_branch + branch_pit[:, TINIT_IN] = tinit_branch if not gas_mode: if options["use_numba"]: @@ -73,6 +75,33 @@ def calculate_derivatives_hydraulic(net, branch_pit, node_pit, options): branch_pit[:, JAC_DERIV_DV_NODE] = df_dv_nodes +def calculate_derivatives_thermal(net, branch_pit, node_pit, options): + cp = branch_pit[:, CP] + rho = branch_pit[:, RHO] + v_init = branch_pit[:, VINIT_T] + from_nodes = branch_pit[:, FROM_NODE_T].astype(np.int32) + t_init_i = node_pit[from_nodes, TINIT_NODE] + t_init_i1 = branch_pit[:, TINIT_OUT] + t_amb = branch_pit[:, TEXT] + area = branch_pit[:, AREA] + length = branch_pit[:, LENGTH] + alpha = branch_pit[:, ALPHA] * np.pi * branch_pit[:, D] + tl = branch_pit[:, TL] + qext = branch_pit[:, QEXT] + t_m = (t_init_i1 + t_init_i) / 2 + + branch_pit[:, LOAD_VEC_BRANCHES_T] = \ + -(rho * area * cp * v_init * (-t_init_i + t_init_i1 - tl) + - alpha * (t_amb - t_m) * length + qext) + + branch_pit[:, JAC_DERIV_DT] = - rho * area * cp * v_init + alpha / 2 * length + branch_pit[:, JAC_DERIV_DT1] = rho * area * cp * v_init + alpha / 2 * length + + branch_pit[:, JAC_DERIV_DT_NODE] = rho * v_init * branch_pit[:, AREA] + branch_pit[:, LOAD_VEC_NODES_T] = rho * v_init * branch_pit[:, AREA] \ + * t_init_i1 + + def get_derived_values(node_pit, from_nodes, to_nodes, use_numba): if use_numba: from pandapipes.pf.derivative_toolbox_numba import calc_derived_values_numba @@ -110,11 +139,11 @@ def calc_lambda(v, eta, rho, d, k, gas_mode, friction_model, lengths, options): """ if options["use_numba"]: from pandapipes.pf.derivative_toolbox_numba import calc_lambda_nikuradse_incomp_numba as \ - calc_lambda_nikuradse_incomp, colebrook_numba as colebrook,\ + calc_lambda_nikuradse_incomp, colebrook_numba as colebrook, \ calc_lambda_nikuradse_comp_numba as calc_lambda_nikuradse_comp else: from pandapipes.pf.derivative_toolbox import calc_lambda_nikuradse_incomp_np as \ - calc_lambda_nikuradse_incomp, colebrook_np as colebrook,\ + calc_lambda_nikuradse_incomp, colebrook_np as colebrook, \ calc_lambda_nikuradse_comp_np as calc_lambda_nikuradse_comp if gas_mode: re, lambda_laminar, lambda_nikuradse = calc_lambda_nikuradse_comp(v, d, k, eta, rho) @@ -134,7 +163,7 @@ def calc_lambda(v, eta, rho, d, k, gas_mode, friction_model, lengths, options): "argument to the pipeflow.") return lambda_colebrook, re elif friction_model == "swamee-jain": - lambda_swamee_jain = 0.25 / ((np.log10(k/(3.7*d) + 5.74/(re**0.9)))**2) + lambda_swamee_jain = 0.25 / ((np.log10(k / (3.7 * d) + 5.74 / (re ** 0.9))) ** 2) return lambda_swamee_jain, re else: # lambda_tot = np.where(re > 2300, lambda_laminar + lambda_nikuradse, lambda_laminar) @@ -182,7 +211,7 @@ def calc_der_lambda(v, eta, rho, d, k, friction_model, lambda_pipe): return lambda_colebrook_der elif friction_model == "swamee-jain": - param = k/(3.7*d) + 5.74 * (np.abs(eta))**0.9 / ((np.abs(rho*v_corr*d))**0.9) + param = k / (3.7 * d) + 5.74 * (np.abs(eta)) ** 0.9 / ((np.abs(rho * v_corr * d)) ** 0.9) # 0.5 / (log(10) * log(param)^3 * param) * 5.166 * abs(eta)^0.9 / (abs(rho * d)^0.9 # * abs(v_corr)^1.9) lambda_swamee_jain_der = 0.5 / np.log(10) / (np.log(param) ** 3) / param * 5.166 \ diff --git a/pandapipes/pf/derivative_toolbox.py b/pandapipes/pf/derivative_toolbox.py index e681c71fa..fd26b06f3 100644 --- a/pandapipes/pf/derivative_toolbox.py +++ b/pandapipes/pf/derivative_toolbox.py @@ -7,7 +7,7 @@ from pandapipes.constants import P_CONVERSION, GRAVITATION_CONSTANT, NORMAL_PRESSURE, \ NORMAL_TEMPERATURE -from pandapipes.idx_branch import LENGTH, LAMBDA, D, LOSS_COEFFICIENT as LC, RHO, PL, AREA, TINIT, \ +from pandapipes.idx_branch import LENGTH, LAMBDA, D, LOSS_COEFFICIENT as LC, RHO, PL, AREA, TINIT_IN, \ VINIT from pandapipes.idx_node import HEIGHT, PINIT, PAMB, TINIT as TINIT_NODE @@ -41,11 +41,11 @@ def derivatives_hydraulic_comp_np(branch_pit, lambda_, der_lambda, p_init_i_abs, p_sum = p_init_i_abs + p_init_i1_abs p_sum_div = np.divide(1, p_sum) - const_lambda = np.divide(NORMAL_PRESSURE * branch_pit[:, RHO] * branch_pit[:, TINIT], + const_lambda = np.divide(NORMAL_PRESSURE * branch_pit[:, RHO] * branch_pit[:, TINIT_IN], NORMAL_TEMPERATURE * P_CONVERSION) const_height = np.divide( branch_pit[:, RHO] * NORMAL_TEMPERATURE * GRAVITATION_CONSTANT * height_difference, - 2 * NORMAL_PRESSURE * branch_pit[:, TINIT] * P_CONVERSION) + 2 * NORMAL_PRESSURE * branch_pit[:, TINIT_IN] * P_CONVERSION) friction_term = np.divide(lambda_ * branch_pit[:, LENGTH], branch_pit[:, D]) + branch_pit[:, LC] load_vec = p_diff + branch_pit[:, PL] + const_height * p_sum \ diff --git a/pandapipes/pf/derivative_toolbox_numba.py b/pandapipes/pf/derivative_toolbox_numba.py index a3b7f3eb8..1cd990a00 100644 --- a/pandapipes/pf/derivative_toolbox_numba.py +++ b/pandapipes/pf/derivative_toolbox_numba.py @@ -3,7 +3,7 @@ from pandapipes.constants import P_CONVERSION, GRAVITATION_CONSTANT, NORMAL_PRESSURE, \ NORMAL_TEMPERATURE -from pandapipes.idx_branch import LENGTH, LAMBDA, D, LOSS_COEFFICIENT as LC, RHO, PL, AREA, TINIT, \ +from pandapipes.idx_branch import LENGTH, LAMBDA, D, LOSS_COEFFICIENT as LC, RHO, PL, AREA, TINIT_IN, \ VINIT from pandapipes.idx_node import HEIGHT, PAMB, PINIT, TINIT as TINIT_NODE @@ -64,11 +64,11 @@ def derivatives_hydraulic_comp_numba(branch_pit, lambda_, der_lambda, p_init_i_a p_sum = p_init_i_abs[i] + p_init_i1_abs[i] p_sum_div = np.divide(1, p_sum) - const_lambda = np.divide(NORMAL_PRESSURE * branch_pit[i][RHO] * branch_pit[i][TINIT], + const_lambda = np.divide(NORMAL_PRESSURE * branch_pit[i][RHO] * branch_pit[i][TINIT_IN], NORMAL_TEMPERATURE * P_CONVERSION) const_height = np.divide( branch_pit[i][RHO] * NORMAL_TEMPERATURE * GRAVITATION_CONSTANT * height_difference[i], - 2 * NORMAL_PRESSURE * branch_pit[i][TINIT] * P_CONVERSION) + 2 * NORMAL_PRESSURE * branch_pit[i][TINIT_IN] * P_CONVERSION) friction_term = np.divide(lambda_[i] * branch_pit[i][LENGTH], branch_pit[i][D]) + branch_pit[i][LC] diff --git a/pandapipes/pf/result_extraction.py b/pandapipes/pf/result_extraction.py index 1782a9f4c..e58e6ea59 100644 --- a/pandapipes/pf/result_extraction.py +++ b/pandapipes/pf/result_extraction.py @@ -2,7 +2,7 @@ from pandapipes.constants import NORMAL_PRESSURE, NORMAL_TEMPERATURE from pandapipes.idx_branch import ELEMENT_IDX, FROM_NODE, TO_NODE, LOAD_VEC_NODES, VINIT, RE, \ - LAMBDA, TINIT, FROM_NODE_T, TO_NODE_T, PL, T_OUT + LAMBDA, TINIT_IN, FROM_NODE_T, TO_NODE_T, PL, TINIT_OUT from pandapipes.idx_node import TABLE_IDX as TABLE_IDX_NODE, PINIT, PAMB, TINIT as TINIT_NODE from pandapipes.pf.internals_toolbox import _sum_by_group from pandapipes.pf.pipeflow_setup import get_table_number, get_lookup, get_net_option @@ -77,7 +77,7 @@ def get_branch_results_gas(net, branch_pit, node_pit, from_nodes, to_nodes, v_mp / (p_abs_from[mask] ** 2 - p_abs_to[mask] ** 2) fluid = get_fluid(net) - numerator = NORMAL_PRESSURE * branch_pit[:, TINIT] / NORMAL_TEMPERATURE + numerator = NORMAL_PRESSURE * branch_pit[:, TINIT_IN] / NORMAL_TEMPERATURE normfactor_from = numerator * fluid.get_property("compressibility", p_abs_from) / p_abs_from normfactor_to = numerator * fluid.get_property("compressibility", p_abs_to) / p_abs_to normfactor_mean = numerator * fluid.get_property("compressibility", p_abs_mean) / p_abs_mean @@ -131,7 +131,7 @@ def get_gas_vel_numba(branch_pit, comp_from, comp_to, comp_mean, p_abs_from, p_a [np.empty_like(v_mps) for _ in range(6)] for i in range(len(v_mps)): - numerator = np.divide(NORMAL_PRESSURE * branch_pit[i, TINIT], NORMAL_TEMPERATURE) + numerator = np.divide(NORMAL_PRESSURE * branch_pit[i, TINIT_IN], NORMAL_TEMPERATURE) normfactor_from[i] = np.divide(numerator * comp_from[i], p_abs_from[i]) normfactor_to[i] = np.divide(numerator * comp_to[i], p_abs_to[i]) normfactor_mean[i] = np.divide(numerator * comp_mean[i], p_abs_mean[i]) @@ -273,8 +273,8 @@ def extract_results_active_pit(net, mode="hydraulics"): if i not in [not_affected_node_col]]) rows_nodes = np.arange(net["_pit"]["node"].shape[0])[nodes_connected] - result_branch_col = VINIT if mode == "hydraulics" else T_OUT - not_affected_branch_col = T_OUT if mode == "hydraulics" else VINIT + result_branch_col = VINIT if mode == "hydraulics" else TINIT_OUT + not_affected_branch_col = TINIT_OUT if mode == "hydraulics" else VINIT copied_branch_cols = np.array([i for i in range(net["_pit"]["branch"].shape[1]) if i not in [FROM_NODE, TO_NODE, FROM_NODE_T, TO_NODE_T, not_affected_branch_col]]) diff --git a/pandapipes/pipeflow.py b/pandapipes/pipeflow.py index 1dc89367a..f26c63663 100644 --- a/pandapipes/pipeflow.py +++ b/pandapipes/pipeflow.py @@ -7,10 +7,10 @@ from pandapower.auxiliary import ppException from scipy.sparse.linalg import spsolve -from pandapipes.idx_branch import FROM_NODE, TO_NODE, FROM_NODE_T, TO_NODE_T, VINIT, T_OUT, VINIT_T +from pandapipes.idx_branch import FROM_NODE, TO_NODE, FROM_NODE_T, TO_NODE_T, VINIT, TINIT_OUT, VINIT_T from pandapipes.idx_node import PINIT, TINIT from pandapipes.pf.build_system_matrix import build_system_matrix -from pandapipes.pf.derivative_calculation import calculate_derivatives_hydraulic +from pandapipes.pf.derivative_calculation import calculate_derivatives_hydraulic, calculate_derivatives_thermal from pandapipes.pf.pipeflow_setup import get_net_option, get_net_options, set_net_option, \ init_options, create_internal_results, write_internal_results, get_lookup, create_lookups, \ initialize_pit, reduce_pit, set_user_pf_options, init_all_result_tables, \ @@ -269,17 +269,22 @@ def solve_temperature(net): branch_pit[mask, TO_NODE_T] = branch_pit[mask, FROM_NODE] for comp in net['component_list']: - comp.calculate_derivatives_thermal(net, branch_pit, node_pit, branch_lookups, options) + comp.adaption_before_derivatives_thermal( + net, branch_pit, node_pit, branch_lookups, options) + calculate_derivatives_thermal(net, branch_pit, node_pit, options) + for comp in net['component_list']: + comp.adaption_after_derivatives_thermal( + net, branch_pit, node_pit, branch_lookups, options) jacobian, epsilon = build_system_matrix(net, branch_pit, node_pit, True) t_init_old = node_pit[:, TINIT].copy() - t_out_old = branch_pit[:, T_OUT].copy() + t_out_old = branch_pit[:, TINIT_OUT].copy() x = spsolve(jacobian, epsilon) node_pit[:, TINIT] += x[:len(node_pit)] * options["alpha"] - branch_pit[:, T_OUT] += x[len(node_pit):] + branch_pit[:, TINIT_OUT] += x[len(node_pit):] - return branch_pit[:, T_OUT], t_out_old, node_pit[:, TINIT], t_init_old, epsilon + return branch_pit[:, TINIT_OUT], t_out_old, node_pit[:, TINIT], t_init_old, epsilon def set_damping_factor(net, niter, error): @@ -313,7 +318,7 @@ def set_damping_factor(net, niter, error): def finalize_iteration(net, niter, error_1, error_2, residual_norm, nonlinear_method, tol_1, tol_2, tol_res, vals_1_old, vals_2_old, hydraulic_mode=True): - col1, col2 = (PINIT, VINIT) if hydraulic_mode else (TINIT, T_OUT) + col1, col2 = (PINIT, VINIT) if hydraulic_mode else (TINIT, TINIT_OUT) # Control of damping factor if nonlinear_method == "automatic": diff --git a/pandapipes/test/openmodelica_comparison/pipeflow_openmodelica_comparison.py b/pandapipes/test/openmodelica_comparison/pipeflow_openmodelica_comparison.py index 28c021296..25d6db078 100644 --- a/pandapipes/test/openmodelica_comparison/pipeflow_openmodelica_comparison.py +++ b/pandapipes/test/openmodelica_comparison/pipeflow_openmodelica_comparison.py @@ -254,7 +254,7 @@ def retrieve_temperature_liquid(net): for j in range(num_of_pipes): pipe_res = Pipe.get_internal_results(net, [j]) - T_mean_pandapipes[j] = st.mean(pipe_res["TINIT"][:, 1]) + T_mean_pandapipes[j] = st.mean(pipe_res["TINIT_IN"][:, 1]) T_diff_mean = np.abs(1 - T_mean_pandapipes / T_mean_om) T_diff_abs = np.abs(T_mean_om - T_mean_pandapipes) diff --git a/pandapipes/test/pipeflow_internals/test_pipeflow_analytic_comparison.py b/pandapipes/test/pipeflow_internals/test_pipeflow_analytic_comparison.py index 3ad196701..2e0045c08 100644 --- a/pandapipes/test/pipeflow_internals/test_pipeflow_analytic_comparison.py +++ b/pandapipes/test/pipeflow_internals/test_pipeflow_analytic_comparison.py @@ -99,8 +99,8 @@ def test_temperature_internal_nodes_single_pipe(use_numba): header=0, keep_default_na=False) temp_an = data["T"] - pipe_temp_data_idx = np.where(pipe_results["TINIT"][:, 0] == 0) - pipe_temp_data = pipe_results["TINIT"][pipe_temp_data_idx, 1] + pipe_temp_data_idx = np.where(pipe_results["TINIT_IN"][:, 0] == 0) + pipe_temp_data = pipe_results["TINIT_IN"][pipe_temp_data_idx, 1] node_pit = net["_pit"]["node"] diff --git a/tutorials/temperature_calculation.ipynb b/tutorials/temperature_calculation.ipynb index f5e24e463..03526ceb9 100644 --- a/tutorials/temperature_calculation.ipynb +++ b/tutorials/temperature_calculation.ipynb @@ -201,7 +201,7 @@ "metadata": {}, "outputs": [], "source": [ - "pipe_1_results[\"TINIT\"]" + "pipe_1_results[\"TINIT_IN\"]" ] }, { From 4a6528f9a1d2fb2dadc6caf5a2b24d76ce150d3b Mon Sep 17 00:00:00 2001 From: sdrauz Date: Wed, 13 Sep 2023 20:39:53 +0200 Subject: [PATCH 2/5] change the names TINIT and T_OUT back --- .../abstract_models/branch_w_internals_models.py | 10 +++++----- .../abstract_models/branch_wo_internals_models.py | 10 +++++----- .../component_models/heat_exchanger_component.py | 2 +- pandapipes/component_models/pipe_component.py | 12 ++++++------ pandapipes/component_models/pump_component.py | 4 ++-- pandapipes/idx_branch.py | 4 ++-- pandapipes/pf/derivative_calculation.py | 4 ++-- pandapipes/pf/derivative_toolbox.py | 6 +++--- pandapipes/pf/derivative_toolbox_numba.py | 6 +++--- pandapipes/pf/result_extraction.py | 10 +++++----- pandapipes/pipeflow.py | 10 +++++----- .../pipeflow_openmodelica_comparison.py | 2 +- .../test_pipeflow_analytic_comparison.py | 4 ++-- tutorials/temperature_calculation.ipynb | 2 +- 14 files changed, 43 insertions(+), 43 deletions(-) diff --git a/pandapipes/component_models/abstract_models/branch_w_internals_models.py b/pandapipes/component_models/abstract_models/branch_w_internals_models.py index fa7a579e4..1b88f0eac 100644 --- a/pandapipes/component_models/abstract_models/branch_w_internals_models.py +++ b/pandapipes/component_models/abstract_models/branch_w_internals_models.py @@ -6,7 +6,7 @@ from pandapipes.component_models.abstract_models.branch_models import BranchComponent from pandapipes.component_models.component_toolbox import set_entry_check_repeat -from pandapipes.idx_branch import ACTIVE, FROM_NODE, TO_NODE, TINIT_IN, RHO, ETA, CP, ELEMENT_IDX +from pandapipes.idx_branch import ACTIVE, FROM_NODE, TO_NODE, TINIT, RHO, ETA, CP, ELEMENT_IDX from pandapipes.idx_node import L, node_cols, TINIT as TINIT_NODE from pandapipes.pf.pipeflow_setup import add_table_lookup, get_lookup, get_table_number from pandapipes.properties.fluids import get_fluid @@ -196,12 +196,12 @@ def create_pit_branch_entries(cls, net, branch_pit): internal_pipe_number, has_internals) branch_w_internals_pit[:, FROM_NODE] = from_nodes branch_w_internals_pit[:, TO_NODE] = to_nodes - branch_w_internals_pit[:, TINIT_IN] = (node_pit[from_nodes, TINIT_NODE] + node_pit[ + branch_w_internals_pit[:, TINIT] = (node_pit[from_nodes, TINIT_NODE] + node_pit[ to_nodes, TINIT_NODE]) / 2 fluid = get_fluid(net) - branch_w_internals_pit[:, RHO] = fluid.get_density(branch_w_internals_pit[:, TINIT_IN]) - branch_w_internals_pit[:, ETA] = fluid.get_viscosity(branch_w_internals_pit[:, TINIT_IN]) - branch_w_internals_pit[:, CP] = fluid.get_heat_capacity(branch_w_internals_pit[:, TINIT_IN]) + branch_w_internals_pit[:, RHO] = fluid.get_density(branch_w_internals_pit[:, TINIT]) + branch_w_internals_pit[:, ETA] = fluid.get_viscosity(branch_w_internals_pit[:, TINIT]) + branch_w_internals_pit[:, CP] = fluid.get_heat_capacity(branch_w_internals_pit[:, TINIT]) return branch_w_internals_pit, internal_pipe_number diff --git a/pandapipes/component_models/abstract_models/branch_wo_internals_models.py b/pandapipes/component_models/abstract_models/branch_wo_internals_models.py index 6872e6df2..106895d50 100644 --- a/pandapipes/component_models/abstract_models/branch_wo_internals_models.py +++ b/pandapipes/component_models/abstract_models/branch_wo_internals_models.py @@ -4,7 +4,7 @@ from pandapipes.component_models.abstract_models.branch_models import BranchComponent -from pandapipes.idx_branch import FROM_NODE, TO_NODE, TINIT_IN, ELEMENT_IDX, RHO, ETA, CP, ACTIVE +from pandapipes.idx_branch import FROM_NODE, TO_NODE, TINIT, ELEMENT_IDX, RHO, ETA, CP, ACTIVE from pandapipes.idx_node import TINIT as TINIT_NODE from pandapipes.pf.pipeflow_setup import add_table_lookup @@ -82,12 +82,12 @@ def create_pit_branch_entries(cls, net, branch_pit): branch_wo_internals_pit[:, ELEMENT_IDX] = net[cls.table_name()].index.values branch_wo_internals_pit[:, FROM_NODE] = from_nodes branch_wo_internals_pit[:, TO_NODE] = to_nodes - branch_wo_internals_pit[:, TINIT_IN] = (node_pit[from_nodes, TINIT_NODE] + branch_wo_internals_pit[:, TINIT] = (node_pit[from_nodes, TINIT_NODE] + node_pit[to_nodes, TINIT_NODE]) / 2 fluid = get_fluid(net) - branch_wo_internals_pit[:, RHO] = fluid.get_density(branch_wo_internals_pit[:, TINIT_IN]) - branch_wo_internals_pit[:, ETA] = fluid.get_viscosity(branch_wo_internals_pit[:, TINIT_IN]) - branch_wo_internals_pit[:, CP] = fluid.get_heat_capacity(branch_wo_internals_pit[:, TINIT_IN]) + branch_wo_internals_pit[:, RHO] = fluid.get_density(branch_wo_internals_pit[:, TINIT]) + branch_wo_internals_pit[:, ETA] = fluid.get_viscosity(branch_wo_internals_pit[:, TINIT]) + branch_wo_internals_pit[:, CP] = fluid.get_heat_capacity(branch_wo_internals_pit[:, TINIT]) branch_wo_internals_pit[:, ACTIVE] = net[cls.table_name()][cls.active_identifier()].values return branch_wo_internals_pit diff --git a/pandapipes/component_models/heat_exchanger_component.py b/pandapipes/component_models/heat_exchanger_component.py index 5bc6dae3c..55f15e86e 100644 --- a/pandapipes/component_models/heat_exchanger_component.py +++ b/pandapipes/component_models/heat_exchanger_component.py @@ -9,7 +9,7 @@ from pandapipes.component_models.abstract_models.branch_wzerolength_models import \ BranchWZeroLengthComponent from pandapipes.component_models.junction_component import Junction -from pandapipes.idx_branch import TL, ALPHA, TEXT, QEXT, TINIT_OUT, D, AREA, LOSS_COEFFICIENT as LC +from pandapipes.idx_branch import TL, ALPHA, TEXT, QEXT, T_OUT, D, AREA, LOSS_COEFFICIENT as LC from pandapipes.pf.pipeflow_setup import get_fluid from pandapipes.pf.result_extraction import extract_branch_results_without_internals diff --git a/pandapipes/component_models/pipe_component.py b/pandapipes/component_models/pipe_component.py index 600f06726..6d93d1b80 100644 --- a/pandapipes/component_models/pipe_component.py +++ b/pandapipes/component_models/pipe_component.py @@ -11,7 +11,7 @@ from pandapipes.component_models.junction_component import Junction from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE from pandapipes.idx_branch import FROM_NODE, TO_NODE, LENGTH, D, AREA, K, \ - VINIT, ALPHA, QEXT, TEXT, LOSS_COEFFICIENT as LC, TINIT_OUT + VINIT, ALPHA, QEXT, TEXT, LOSS_COEFFICIENT as LC, T_OUT, from pandapipes.idx_node import PINIT, HEIGHT, TINIT as TINIT_NODE, \ RHO as RHO_NODES, PAMB, ACTIVE as ACTIVE_ND from pandapipes.pf.pipeflow_setup import get_fluid, get_lookup @@ -153,7 +153,7 @@ def create_pit_branch_entries(cls, net, branch_pit): node_pit = net["_pit"]["node"] to_nodes = pipe_pit[:, TO_NODE].astype(np.int32) - pipe_pit[:, TINIT_OUT] = node_pit[to_nodes, TINIT_NODE] + pipe_pit[:, T_OUT] = node_pit[to_nodes, TINIT_NODE] pipe_pit[:, AREA] = pipe_pit[:, D] ** 2 * np.pi / 4 @classmethod @@ -206,7 +206,7 @@ def get_internal_results(cls, net, pipe): v_pipe_idx = np.repeat(pipe, internal_sections[pipe]) pipe_results = dict() pipe_results["PINIT"] = np.zeros((len(p_node_idx), 2), dtype=np.float64) - pipe_results["TINIT_IN"] = np.zeros((len(p_node_idx), 2), dtype=np.float64) + pipe_results["TINIT"] = np.zeros((len(p_node_idx), 2), dtype=np.float64) pipe_results["VINIT_FROM"] = np.zeros((len(v_pipe_idx), 2), dtype=np.float64) pipe_results["VINIT_TO"] = np.zeros((len(v_pipe_idx), 2), dtype=np.float64) pipe_results["VINIT_MEAN"] = np.zeros((len(v_pipe_idx), 2), dtype=np.float64) @@ -272,8 +272,8 @@ def get_internal_results(cls, net, pipe): pipe_results["PINIT"][:, 0] = p_node_idx pipe_results["PINIT"][:, 1] = p_node_data - pipe_results["TINIT_IN"][:, 0] = p_node_idx - pipe_results["TINIT_IN"][:, 1] = t_node_data + pipe_results["TINIT"][:, 0] = p_node_idx + pipe_results["TINIT"][:, 1] = t_node_data else: logger.warning("For at least one pipe no internal data is available.") @@ -347,7 +347,7 @@ def plot_pipe(cls, net, pipe, pipe_results): pipe_p_data_idx = np.where(pipe_results["PINIT"][:, 0] == pipe) pipe_v_data_idx = np.where(pipe_results["VINIT_MEAN"][:, 0] == pipe) pipe_p_data = pipe_results["PINIT"][pipe_p_data_idx, 1] - pipe_t_data = pipe_results["TINIT_IN"][pipe_p_data_idx, 1] + pipe_t_data = pipe_results["TINIT"][pipe_p_data_idx, 1] pipe_v_data = pipe_results["VINIT_MEAN"][pipe_v_data_idx, 1] node_pit = net["_pit"]["node"] diff --git a/pandapipes/component_models/pump_component.py b/pandapipes/component_models/pump_component.py index 5a3b23606..3f4b69ff2 100644 --- a/pandapipes/component_models/pump_component.py +++ b/pandapipes/component_models/pump_component.py @@ -12,7 +12,7 @@ BranchWZeroLengthComponent from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE, R_UNIVERSAL, P_CONVERSION from pandapipes.idx_branch import STD_TYPE, VINIT, D, AREA, LOSS_COEFFICIENT as LC, FROM_NODE, \ - TINIT_IN, PL + TINIT, PL from pandapipes.idx_node import PINIT, PAMB, TINIT as TINIT_NODE from pandapipes.pf.pipeflow_setup import get_fluid, get_net_option, get_lookup from pandapipes.pf.result_extraction import extract_branch_results_without_internals @@ -79,7 +79,7 @@ def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lo fluid = get_fluid(net) p_from = node_pit[from_nodes, PAMB] + node_pit[from_nodes, PINIT] # p_to = node_pit[to_nodes, PAMB] + node_pit[to_nodes, PINIT] - numerator = NORMAL_PRESSURE * pump_pit[:, TINIT_IN] + numerator = NORMAL_PRESSURE * pump_pit[:, TINIT] v_mps = pump_pit[:, VINIT] if fluid.is_gas: # consider volume flow at inlet diff --git a/pandapipes/idx_branch.py b/pandapipes/idx_branch.py index 0db7397e0..2b59f2360 100644 --- a/pandapipes/idx_branch.py +++ b/pandapipes/idx_branch.py @@ -17,7 +17,7 @@ RHO = 8 # Density in [kg/m^3 ETA = 9 # Dynamic viscosity in [Pas] K = 10 # Pipe roughness in [m] -TINIT_IN = 11 # Temperature in [K] +TINIT = 11 # Temperature in [K] VINIT = 12 # velocity in [m/s] RE = 13 # Reynolds number LAMBDA = 14 # Lambda @@ -33,7 +33,7 @@ JAC_DERIV_DT = 24 JAC_DERIV_DT1 = 25 LOAD_VEC_BRANCHES_T = 26 -TINIT_OUT = 27 # Internal slot for outlet pipe temperature +T_OUT = 27 # Internal slot for outlet pipe temperature JAC_DERIV_DT_NODE = 28 # Slot for the derivative fpr T for the nodes connected to branch LOAD_VEC_NODES_T = 29 VINIT_T = 30 diff --git a/pandapipes/pf/derivative_calculation.py b/pandapipes/pf/derivative_calculation.py index 95f051771..12463db7a 100644 --- a/pandapipes/pf/derivative_calculation.py +++ b/pandapipes/pf/derivative_calculation.py @@ -1,6 +1,6 @@ import numpy as np -from pandapipes.idx_branch import LENGTH, ETA, RHO, D, K, RE, LAMBDA, TINIT_IN, LOAD_VEC_BRANCHES, \ +from pandapipes.idx_branch import LENGTH, ETA, RHO, D, K, RE, LAMBDA, TINIT, LOAD_VEC_BRANCHES, \ JAC_DERIV_DV, JAC_DERIV_DP, JAC_DERIV_DP1, LOAD_VEC_NODES, JAC_DERIV_DV_NODE, VINIT, \ FROM_NODE, TO_NODE, CP, VINIT_T, FROM_NODE_T, TINIT_OUT, TEXT, AREA, ALPHA, TL, QEXT, LOAD_VEC_NODES_T, \ LOAD_VEC_BRANCHES_T, JAC_DERIV_DT, JAC_DERIV_DT1, JAC_DERIV_DT_NODE @@ -37,7 +37,7 @@ def calculate_derivatives_hydraulic(net, branch_pit, node_pit, options): to_nodes = branch_pit[:, TO_NODE].astype(np.int32) tinit_branch, height_difference, p_init_i_abs, p_init_i1_abs = \ get_derived_values(node_pit, from_nodes, to_nodes, options["use_numba"]) - branch_pit[:, TINIT_IN] = tinit_branch + branch_pit[:, TINIT] = tinit_branch if not gas_mode: if options["use_numba"]: diff --git a/pandapipes/pf/derivative_toolbox.py b/pandapipes/pf/derivative_toolbox.py index fd26b06f3..e681c71fa 100644 --- a/pandapipes/pf/derivative_toolbox.py +++ b/pandapipes/pf/derivative_toolbox.py @@ -7,7 +7,7 @@ from pandapipes.constants import P_CONVERSION, GRAVITATION_CONSTANT, NORMAL_PRESSURE, \ NORMAL_TEMPERATURE -from pandapipes.idx_branch import LENGTH, LAMBDA, D, LOSS_COEFFICIENT as LC, RHO, PL, AREA, TINIT_IN, \ +from pandapipes.idx_branch import LENGTH, LAMBDA, D, LOSS_COEFFICIENT as LC, RHO, PL, AREA, TINIT, \ VINIT from pandapipes.idx_node import HEIGHT, PINIT, PAMB, TINIT as TINIT_NODE @@ -41,11 +41,11 @@ def derivatives_hydraulic_comp_np(branch_pit, lambda_, der_lambda, p_init_i_abs, p_sum = p_init_i_abs + p_init_i1_abs p_sum_div = np.divide(1, p_sum) - const_lambda = np.divide(NORMAL_PRESSURE * branch_pit[:, RHO] * branch_pit[:, TINIT_IN], + const_lambda = np.divide(NORMAL_PRESSURE * branch_pit[:, RHO] * branch_pit[:, TINIT], NORMAL_TEMPERATURE * P_CONVERSION) const_height = np.divide( branch_pit[:, RHO] * NORMAL_TEMPERATURE * GRAVITATION_CONSTANT * height_difference, - 2 * NORMAL_PRESSURE * branch_pit[:, TINIT_IN] * P_CONVERSION) + 2 * NORMAL_PRESSURE * branch_pit[:, TINIT] * P_CONVERSION) friction_term = np.divide(lambda_ * branch_pit[:, LENGTH], branch_pit[:, D]) + branch_pit[:, LC] load_vec = p_diff + branch_pit[:, PL] + const_height * p_sum \ diff --git a/pandapipes/pf/derivative_toolbox_numba.py b/pandapipes/pf/derivative_toolbox_numba.py index 1cd990a00..a3b7f3eb8 100644 --- a/pandapipes/pf/derivative_toolbox_numba.py +++ b/pandapipes/pf/derivative_toolbox_numba.py @@ -3,7 +3,7 @@ from pandapipes.constants import P_CONVERSION, GRAVITATION_CONSTANT, NORMAL_PRESSURE, \ NORMAL_TEMPERATURE -from pandapipes.idx_branch import LENGTH, LAMBDA, D, LOSS_COEFFICIENT as LC, RHO, PL, AREA, TINIT_IN, \ +from pandapipes.idx_branch import LENGTH, LAMBDA, D, LOSS_COEFFICIENT as LC, RHO, PL, AREA, TINIT, \ VINIT from pandapipes.idx_node import HEIGHT, PAMB, PINIT, TINIT as TINIT_NODE @@ -64,11 +64,11 @@ def derivatives_hydraulic_comp_numba(branch_pit, lambda_, der_lambda, p_init_i_a p_sum = p_init_i_abs[i] + p_init_i1_abs[i] p_sum_div = np.divide(1, p_sum) - const_lambda = np.divide(NORMAL_PRESSURE * branch_pit[i][RHO] * branch_pit[i][TINIT_IN], + const_lambda = np.divide(NORMAL_PRESSURE * branch_pit[i][RHO] * branch_pit[i][TINIT], NORMAL_TEMPERATURE * P_CONVERSION) const_height = np.divide( branch_pit[i][RHO] * NORMAL_TEMPERATURE * GRAVITATION_CONSTANT * height_difference[i], - 2 * NORMAL_PRESSURE * branch_pit[i][TINIT_IN] * P_CONVERSION) + 2 * NORMAL_PRESSURE * branch_pit[i][TINIT] * P_CONVERSION) friction_term = np.divide(lambda_[i] * branch_pit[i][LENGTH], branch_pit[i][D]) + branch_pit[i][LC] diff --git a/pandapipes/pf/result_extraction.py b/pandapipes/pf/result_extraction.py index e58e6ea59..1782a9f4c 100644 --- a/pandapipes/pf/result_extraction.py +++ b/pandapipes/pf/result_extraction.py @@ -2,7 +2,7 @@ from pandapipes.constants import NORMAL_PRESSURE, NORMAL_TEMPERATURE from pandapipes.idx_branch import ELEMENT_IDX, FROM_NODE, TO_NODE, LOAD_VEC_NODES, VINIT, RE, \ - LAMBDA, TINIT_IN, FROM_NODE_T, TO_NODE_T, PL, TINIT_OUT + LAMBDA, TINIT, FROM_NODE_T, TO_NODE_T, PL, T_OUT from pandapipes.idx_node import TABLE_IDX as TABLE_IDX_NODE, PINIT, PAMB, TINIT as TINIT_NODE from pandapipes.pf.internals_toolbox import _sum_by_group from pandapipes.pf.pipeflow_setup import get_table_number, get_lookup, get_net_option @@ -77,7 +77,7 @@ def get_branch_results_gas(net, branch_pit, node_pit, from_nodes, to_nodes, v_mp / (p_abs_from[mask] ** 2 - p_abs_to[mask] ** 2) fluid = get_fluid(net) - numerator = NORMAL_PRESSURE * branch_pit[:, TINIT_IN] / NORMAL_TEMPERATURE + numerator = NORMAL_PRESSURE * branch_pit[:, TINIT] / NORMAL_TEMPERATURE normfactor_from = numerator * fluid.get_property("compressibility", p_abs_from) / p_abs_from normfactor_to = numerator * fluid.get_property("compressibility", p_abs_to) / p_abs_to normfactor_mean = numerator * fluid.get_property("compressibility", p_abs_mean) / p_abs_mean @@ -131,7 +131,7 @@ def get_gas_vel_numba(branch_pit, comp_from, comp_to, comp_mean, p_abs_from, p_a [np.empty_like(v_mps) for _ in range(6)] for i in range(len(v_mps)): - numerator = np.divide(NORMAL_PRESSURE * branch_pit[i, TINIT_IN], NORMAL_TEMPERATURE) + numerator = np.divide(NORMAL_PRESSURE * branch_pit[i, TINIT], NORMAL_TEMPERATURE) normfactor_from[i] = np.divide(numerator * comp_from[i], p_abs_from[i]) normfactor_to[i] = np.divide(numerator * comp_to[i], p_abs_to[i]) normfactor_mean[i] = np.divide(numerator * comp_mean[i], p_abs_mean[i]) @@ -273,8 +273,8 @@ def extract_results_active_pit(net, mode="hydraulics"): if i not in [not_affected_node_col]]) rows_nodes = np.arange(net["_pit"]["node"].shape[0])[nodes_connected] - result_branch_col = VINIT if mode == "hydraulics" else TINIT_OUT - not_affected_branch_col = TINIT_OUT if mode == "hydraulics" else VINIT + result_branch_col = VINIT if mode == "hydraulics" else T_OUT + not_affected_branch_col = T_OUT if mode == "hydraulics" else VINIT copied_branch_cols = np.array([i for i in range(net["_pit"]["branch"].shape[1]) if i not in [FROM_NODE, TO_NODE, FROM_NODE_T, TO_NODE_T, not_affected_branch_col]]) diff --git a/pandapipes/pipeflow.py b/pandapipes/pipeflow.py index f26c63663..710764ef4 100644 --- a/pandapipes/pipeflow.py +++ b/pandapipes/pipeflow.py @@ -7,7 +7,7 @@ from pandapower.auxiliary import ppException from scipy.sparse.linalg import spsolve -from pandapipes.idx_branch import FROM_NODE, TO_NODE, FROM_NODE_T, TO_NODE_T, VINIT, TINIT_OUT, VINIT_T +from pandapipes.idx_branch import FROM_NODE, TO_NODE, FROM_NODE_T, TO_NODE_T, VINIT, T_OUT, VINIT_T from pandapipes.idx_node import PINIT, TINIT from pandapipes.pf.build_system_matrix import build_system_matrix from pandapipes.pf.derivative_calculation import calculate_derivatives_hydraulic, calculate_derivatives_thermal @@ -278,13 +278,13 @@ def solve_temperature(net): jacobian, epsilon = build_system_matrix(net, branch_pit, node_pit, True) t_init_old = node_pit[:, TINIT].copy() - t_out_old = branch_pit[:, TINIT_OUT].copy() + t_out_old = branch_pit[:, T_OUT].copy() x = spsolve(jacobian, epsilon) node_pit[:, TINIT] += x[:len(node_pit)] * options["alpha"] - branch_pit[:, TINIT_OUT] += x[len(node_pit):] + branch_pit[:, T_OUT] += x[len(node_pit):] - return branch_pit[:, TINIT_OUT], t_out_old, node_pit[:, TINIT], t_init_old, epsilon + return branch_pit[:, T_OUT], t_out_old, node_pit[:, TINIT], t_init_old, epsilon def set_damping_factor(net, niter, error): @@ -318,7 +318,7 @@ def set_damping_factor(net, niter, error): def finalize_iteration(net, niter, error_1, error_2, residual_norm, nonlinear_method, tol_1, tol_2, tol_res, vals_1_old, vals_2_old, hydraulic_mode=True): - col1, col2 = (PINIT, VINIT) if hydraulic_mode else (TINIT, TINIT_OUT) + col1, col2 = (PINIT, VINIT) if hydraulic_mode else (TINIT, T_OUT) # Control of damping factor if nonlinear_method == "automatic": diff --git a/pandapipes/test/openmodelica_comparison/pipeflow_openmodelica_comparison.py b/pandapipes/test/openmodelica_comparison/pipeflow_openmodelica_comparison.py index 25d6db078..28c021296 100644 --- a/pandapipes/test/openmodelica_comparison/pipeflow_openmodelica_comparison.py +++ b/pandapipes/test/openmodelica_comparison/pipeflow_openmodelica_comparison.py @@ -254,7 +254,7 @@ def retrieve_temperature_liquid(net): for j in range(num_of_pipes): pipe_res = Pipe.get_internal_results(net, [j]) - T_mean_pandapipes[j] = st.mean(pipe_res["TINIT_IN"][:, 1]) + T_mean_pandapipes[j] = st.mean(pipe_res["TINIT"][:, 1]) T_diff_mean = np.abs(1 - T_mean_pandapipes / T_mean_om) T_diff_abs = np.abs(T_mean_om - T_mean_pandapipes) diff --git a/pandapipes/test/pipeflow_internals/test_pipeflow_analytic_comparison.py b/pandapipes/test/pipeflow_internals/test_pipeflow_analytic_comparison.py index 2e0045c08..3ad196701 100644 --- a/pandapipes/test/pipeflow_internals/test_pipeflow_analytic_comparison.py +++ b/pandapipes/test/pipeflow_internals/test_pipeflow_analytic_comparison.py @@ -99,8 +99,8 @@ def test_temperature_internal_nodes_single_pipe(use_numba): header=0, keep_default_na=False) temp_an = data["T"] - pipe_temp_data_idx = np.where(pipe_results["TINIT_IN"][:, 0] == 0) - pipe_temp_data = pipe_results["TINIT_IN"][pipe_temp_data_idx, 1] + pipe_temp_data_idx = np.where(pipe_results["TINIT"][:, 0] == 0) + pipe_temp_data = pipe_results["TINIT"][pipe_temp_data_idx, 1] node_pit = net["_pit"]["node"] diff --git a/tutorials/temperature_calculation.ipynb b/tutorials/temperature_calculation.ipynb index 03526ceb9..f5e24e463 100644 --- a/tutorials/temperature_calculation.ipynb +++ b/tutorials/temperature_calculation.ipynb @@ -201,7 +201,7 @@ "metadata": {}, "outputs": [], "source": [ - "pipe_1_results[\"TINIT_IN\"]" + "pipe_1_results[\"TINIT\"]" ] }, { From 214a98778aa3ae5dca86f7d699f4671a76e471ba Mon Sep 17 00:00:00 2001 From: sdrauz Date: Wed, 13 Sep 2023 20:55:03 +0200 Subject: [PATCH 3/5] bugfix --- pandapipes/component_models/pipe_component.py | 2 +- pandapipes/pf/derivative_calculation.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandapipes/component_models/pipe_component.py b/pandapipes/component_models/pipe_component.py index 6d93d1b80..c2671c524 100644 --- a/pandapipes/component_models/pipe_component.py +++ b/pandapipes/component_models/pipe_component.py @@ -11,7 +11,7 @@ from pandapipes.component_models.junction_component import Junction from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE from pandapipes.idx_branch import FROM_NODE, TO_NODE, LENGTH, D, AREA, K, \ - VINIT, ALPHA, QEXT, TEXT, LOSS_COEFFICIENT as LC, T_OUT, + VINIT, ALPHA, QEXT, TEXT, LOSS_COEFFICIENT as LC, T_OUT from pandapipes.idx_node import PINIT, HEIGHT, TINIT as TINIT_NODE, \ RHO as RHO_NODES, PAMB, ACTIVE as ACTIVE_ND from pandapipes.pf.pipeflow_setup import get_fluid, get_lookup diff --git a/pandapipes/pf/derivative_calculation.py b/pandapipes/pf/derivative_calculation.py index 12463db7a..baa47c34f 100644 --- a/pandapipes/pf/derivative_calculation.py +++ b/pandapipes/pf/derivative_calculation.py @@ -2,7 +2,7 @@ from pandapipes.idx_branch import LENGTH, ETA, RHO, D, K, RE, LAMBDA, TINIT, LOAD_VEC_BRANCHES, \ JAC_DERIV_DV, JAC_DERIV_DP, JAC_DERIV_DP1, LOAD_VEC_NODES, JAC_DERIV_DV_NODE, VINIT, \ - FROM_NODE, TO_NODE, CP, VINIT_T, FROM_NODE_T, TINIT_OUT, TEXT, AREA, ALPHA, TL, QEXT, LOAD_VEC_NODES_T, \ + FROM_NODE, TO_NODE, CP, VINIT_T, FROM_NODE_T, T_OUT, TEXT, AREA, ALPHA, TL, QEXT, LOAD_VEC_NODES_T, \ LOAD_VEC_BRANCHES_T, JAC_DERIV_DT, JAC_DERIV_DT1, JAC_DERIV_DT_NODE from pandapipes.idx_node import TINIT as TINIT_NODE from pandapipes.properties.fluids import get_fluid @@ -81,7 +81,7 @@ def calculate_derivatives_thermal(net, branch_pit, node_pit, options): v_init = branch_pit[:, VINIT_T] from_nodes = branch_pit[:, FROM_NODE_T].astype(np.int32) t_init_i = node_pit[from_nodes, TINIT_NODE] - t_init_i1 = branch_pit[:, TINIT_OUT] + t_init_i1 = branch_pit[:, T_OUT] t_amb = branch_pit[:, TEXT] area = branch_pit[:, AREA] length = branch_pit[:, LENGTH] From 1f040ee3cceb65cf6b86d09cc2f46fcf5a645cc9 Mon Sep 17 00:00:00 2001 From: sdrauz Date: Fri, 15 Sep 2023 17:36:51 +0200 Subject: [PATCH 4/5] removing TINIT from branch variable as it is no solver variable --- .../branch_w_internals_models.py | 13 ++--- .../branch_wo_internals_models.py | 12 ++-- .../heat_exchanger_component.py | 2 +- pandapipes/component_models/pipe_component.py | 5 +- pandapipes/component_models/pump_component.py | 7 ++- pandapipes/idx_branch.py | 55 +++++++++---------- pandapipes/pf/derivative_calculation.py | 5 +- pandapipes/pf/derivative_toolbox.py | 13 +++-- pandapipes/pf/derivative_toolbox_numba.py | 17 ++++-- pandapipes/pf/result_extraction.py | 32 +++++++---- .../pipeflow_internals/test_pipeflow_modes.py | 2 +- 11 files changed, 87 insertions(+), 76 deletions(-) diff --git a/pandapipes/component_models/abstract_models/branch_w_internals_models.py b/pandapipes/component_models/abstract_models/branch_w_internals_models.py index 1b88f0eac..c7d5c2b5c 100644 --- a/pandapipes/component_models/abstract_models/branch_w_internals_models.py +++ b/pandapipes/component_models/abstract_models/branch_w_internals_models.py @@ -6,7 +6,7 @@ from pandapipes.component_models.abstract_models.branch_models import BranchComponent from pandapipes.component_models.component_toolbox import set_entry_check_repeat -from pandapipes.idx_branch import ACTIVE, FROM_NODE, TO_NODE, TINIT, RHO, ETA, CP, ELEMENT_IDX +from pandapipes.idx_branch import ACTIVE, FROM_NODE, TO_NODE, RHO, ETA, CP, ELEMENT_IDX, T_OUT from pandapipes.idx_node import L, node_cols, TINIT as TINIT_NODE from pandapipes.pf.pipeflow_setup import add_table_lookup, get_lookup, get_table_number from pandapipes.properties.fluids import get_fluid @@ -196,13 +196,12 @@ def create_pit_branch_entries(cls, net, branch_pit): internal_pipe_number, has_internals) branch_w_internals_pit[:, FROM_NODE] = from_nodes branch_w_internals_pit[:, TO_NODE] = to_nodes - branch_w_internals_pit[:, TINIT] = (node_pit[from_nodes, TINIT_NODE] + node_pit[ - to_nodes, TINIT_NODE]) / 2 + branch_w_internals_pit[:, T_OUT] = node_pit[to_nodes, TINIT_NODE] + tm = (node_pit[from_nodes, TINIT_NODE] + branch_w_internals_pit[:, T_OUT]) / 2 fluid = get_fluid(net) - branch_w_internals_pit[:, RHO] = fluid.get_density(branch_w_internals_pit[:, TINIT]) - branch_w_internals_pit[:, ETA] = fluid.get_viscosity(branch_w_internals_pit[:, TINIT]) - branch_w_internals_pit[:, CP] = fluid.get_heat_capacity(branch_w_internals_pit[:, TINIT]) - + branch_w_internals_pit[:, RHO] = fluid.get_density(tm) + branch_w_internals_pit[:, ETA] = fluid.get_viscosity(tm) + branch_w_internals_pit[:, CP] = fluid.get_heat_capacity(tm) return branch_w_internals_pit, internal_pipe_number @classmethod diff --git a/pandapipes/component_models/abstract_models/branch_wo_internals_models.py b/pandapipes/component_models/abstract_models/branch_wo_internals_models.py index 106895d50..b66d01567 100644 --- a/pandapipes/component_models/abstract_models/branch_wo_internals_models.py +++ b/pandapipes/component_models/abstract_models/branch_wo_internals_models.py @@ -4,7 +4,7 @@ from pandapipes.component_models.abstract_models.branch_models import BranchComponent -from pandapipes.idx_branch import FROM_NODE, TO_NODE, TINIT, ELEMENT_IDX, RHO, ETA, CP, ACTIVE +from pandapipes.idx_branch import FROM_NODE, TO_NODE, T_OUT, ELEMENT_IDX, RHO, ETA, CP, ACTIVE from pandapipes.idx_node import TINIT as TINIT_NODE from pandapipes.pf.pipeflow_setup import add_table_lookup @@ -82,12 +82,12 @@ def create_pit_branch_entries(cls, net, branch_pit): branch_wo_internals_pit[:, ELEMENT_IDX] = net[cls.table_name()].index.values branch_wo_internals_pit[:, FROM_NODE] = from_nodes branch_wo_internals_pit[:, TO_NODE] = to_nodes - branch_wo_internals_pit[:, TINIT] = (node_pit[from_nodes, TINIT_NODE] - + node_pit[to_nodes, TINIT_NODE]) / 2 + branch_wo_internals_pit[:, T_OUT] = node_pit[to_nodes, TINIT_NODE] + tm = (node_pit[from_nodes, TINIT_NODE] + branch_wo_internals_pit[:, T_OUT]) / 2 fluid = get_fluid(net) - branch_wo_internals_pit[:, RHO] = fluid.get_density(branch_wo_internals_pit[:, TINIT]) - branch_wo_internals_pit[:, ETA] = fluid.get_viscosity(branch_wo_internals_pit[:, TINIT]) - branch_wo_internals_pit[:, CP] = fluid.get_heat_capacity(branch_wo_internals_pit[:, TINIT]) + branch_wo_internals_pit[:, RHO] = fluid.get_density(tm) + branch_wo_internals_pit[:, ETA] = fluid.get_viscosity(tm) + branch_wo_internals_pit[:, CP] = fluid.get_heat_capacity(tm) branch_wo_internals_pit[:, ACTIVE] = net[cls.table_name()][cls.active_identifier()].values return branch_wo_internals_pit diff --git a/pandapipes/component_models/heat_exchanger_component.py b/pandapipes/component_models/heat_exchanger_component.py index 55f15e86e..3270d9db1 100644 --- a/pandapipes/component_models/heat_exchanger_component.py +++ b/pandapipes/component_models/heat_exchanger_component.py @@ -9,7 +9,7 @@ from pandapipes.component_models.abstract_models.branch_wzerolength_models import \ BranchWZeroLengthComponent from pandapipes.component_models.junction_component import Junction -from pandapipes.idx_branch import TL, ALPHA, TEXT, QEXT, T_OUT, D, AREA, LOSS_COEFFICIENT as LC +from pandapipes.idx_branch import ALPHA, TEXT, QEXT, D, AREA, LOSS_COEFFICIENT as LC from pandapipes.pf.pipeflow_setup import get_fluid from pandapipes.pf.result_extraction import extract_branch_results_without_internals diff --git a/pandapipes/component_models/pipe_component.py b/pandapipes/component_models/pipe_component.py index c2671c524..99b2f098a 100644 --- a/pandapipes/component_models/pipe_component.py +++ b/pandapipes/component_models/pipe_component.py @@ -11,7 +11,7 @@ from pandapipes.component_models.junction_component import Junction from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE from pandapipes.idx_branch import FROM_NODE, TO_NODE, LENGTH, D, AREA, K, \ - VINIT, ALPHA, QEXT, TEXT, LOSS_COEFFICIENT as LC, T_OUT + VINIT, ALPHA, QEXT, TEXT, LOSS_COEFFICIENT as LC from pandapipes.idx_node import PINIT, HEIGHT, TINIT as TINIT_NODE, \ RHO as RHO_NODES, PAMB, ACTIVE as ACTIVE_ND from pandapipes.pf.pipeflow_setup import get_fluid, get_lookup @@ -151,9 +151,6 @@ def create_pit_branch_entries(cls, net, branch_pit): set_entry_check_repeat( pipe_pit, LC, net[tbl].loss_coefficient.values, internal_pipe_number, has_internals) - node_pit = net["_pit"]["node"] - to_nodes = pipe_pit[:, TO_NODE].astype(np.int32) - pipe_pit[:, T_OUT] = node_pit[to_nodes, TINIT_NODE] pipe_pit[:, AREA] = pipe_pit[:, D] ** 2 * np.pi / 4 @classmethod diff --git a/pandapipes/component_models/pump_component.py b/pandapipes/component_models/pump_component.py index b24b83669..aa7f6a34c 100644 --- a/pandapipes/component_models/pump_component.py +++ b/pandapipes/component_models/pump_component.py @@ -12,7 +12,7 @@ from pandapipes.component_models.component_toolbox import get_component_array from pandapipes.component_models.junction_component import Junction from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE, R_UNIVERSAL, P_CONVERSION -from pandapipes.idx_branch import VINIT, D, AREA, LOSS_COEFFICIENT as LC, FROM_NODE, TINIT, PL +from pandapipes.idx_branch import VINIT, D, AREA, LOSS_COEFFICIENT as LC, FROM_NODE, T_OUT, PL from pandapipes.idx_node import PINIT, PAMB, TINIT as TINIT_NODE from pandapipes.pf.pipeflow_setup import get_fluid, get_net_option, get_lookup from pandapipes.pf.result_extraction import extract_branch_results_without_internals @@ -102,11 +102,12 @@ def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lo fluid = get_fluid(net) p_from = node_pit[from_nodes, PAMB] + node_pit[from_nodes, PINIT] # p_to = node_pit[to_nodes, PAMB] + node_pit[to_nodes, PINIT] - numerator = NORMAL_PRESSURE * pump_branch_pit[:, TINIT] + t_from = node_pit[from_nodes, TINIT_NODE] + numerator_from = NORMAL_PRESSURE * t_from v_mps = pump_branch_pit[:, VINIT] if fluid.is_gas: # consider volume flow at inlet - normfactor_from = numerator * fluid.get_property("compressibility", p_from) \ + normfactor_from = numerator_from * fluid.get_property("compressibility", p_from) \ / (p_from * NORMAL_TEMPERATURE) v_mean = v_mps * normfactor_from else: diff --git a/pandapipes/idx_branch.py b/pandapipes/idx_branch.py index 0f40fbd61..57a08ce6c 100644 --- a/pandapipes/idx_branch.py +++ b/pandapipes/idx_branch.py @@ -17,32 +17,31 @@ RHO = 8 # Density in [kg/m^3 ETA = 9 # Dynamic viscosity in [Pas] K = 10 # Pipe roughness in [m] -TINIT = 11 # Temperature in [K] -VINIT = 12 # velocity in [m/s] -RE = 13 # Reynolds number -LAMBDA = 14 # Lambda -JAC_DERIV_DV = 15 # Slot for the derivative by velocity -JAC_DERIV_DP = 16 # Slot for the derivative by pressure from_node -JAC_DERIV_DP1 = 17 # Slot for the derivative by pressure to_node -LOAD_VEC_BRANCHES = 18 # Slot for the load vector for the branches -JAC_DERIV_DV_NODE = 19 # Slot for the derivative by velocity for the nodes connected to branch -LOAD_VEC_NODES = 20 # Slot for the load vector of the nodes connected to branch -LOSS_COEFFICIENT = 21 -CP = 22 # Slot for fluid heat capacity values -ALPHA = 23 # Slot for heat transfer coefficient -JAC_DERIV_DT = 24 -JAC_DERIV_DT1 = 25 -LOAD_VEC_BRANCHES_T = 26 -T_OUT = 27 # Internal slot for outlet pipe temperature -JAC_DERIV_DT_NODE = 28 # Slot for the derivative fpr T for the nodes connected to branch -LOAD_VEC_NODES_T = 29 -VINIT_T = 30 -FROM_NODE_T = 31 -TO_NODE_T = 32 -QEXT = 33 # heat input in [W] -TEXT = 34 -PL = 35 -TL = 36 # Temperature lift [K] -BRANCH_TYPE = 37 # branch type relevant for the pressure controller +VINIT = 11 # velocity in [m/s] +RE = 12 # Reynolds number +LAMBDA = 13 # Lambda +JAC_DERIV_DV = 14 # Slot for the derivative by velocity +JAC_DERIV_DP = 15 # Slot for the derivative by pressure from_node +JAC_DERIV_DP1 = 16 # Slot for the derivative by pressure to_node +LOAD_VEC_BRANCHES = 17 # Slot for the load vector for the branches +JAC_DERIV_DV_NODE = 18 # Slot for the derivative by velocity for the nodes connected to branch +LOAD_VEC_NODES = 19 # Slot for the load vector of the nodes connected to branch +LOSS_COEFFICIENT = 20 +CP = 21 # Slot for fluid heat capacity values +ALPHA = 22 # Slot for heat transfer coefficient +JAC_DERIV_DT = 23 +JAC_DERIV_DT1 = 24 +LOAD_VEC_BRANCHES_T = 25 +T_OUT = 26 # Internal slot for outlet pipe temperature +JAC_DERIV_DT_NODE = 27 # Slot for the derivative fpr T for the nodes connected to branch +LOAD_VEC_NODES_T = 28 +VINIT_T = 29 +FROM_NODE_T = 30 +TO_NODE_T = 31 +QEXT = 32 # heat input in [W] +TEXT = 33 +PL = 34 +TL = 35 # Temperature lift [K] +BRANCH_TYPE = 36 # branch type relevant for the pressure controller -branch_cols = 38 +branch_cols = 37 diff --git a/pandapipes/pf/derivative_calculation.py b/pandapipes/pf/derivative_calculation.py index baa47c34f..79f148194 100644 --- a/pandapipes/pf/derivative_calculation.py +++ b/pandapipes/pf/derivative_calculation.py @@ -1,6 +1,6 @@ import numpy as np -from pandapipes.idx_branch import LENGTH, ETA, RHO, D, K, RE, LAMBDA, TINIT, LOAD_VEC_BRANCHES, \ +from pandapipes.idx_branch import LENGTH, ETA, RHO, D, K, RE, LAMBDA, LOAD_VEC_BRANCHES, \ JAC_DERIV_DV, JAC_DERIV_DP, JAC_DERIV_DP1, LOAD_VEC_NODES, JAC_DERIV_DV_NODE, VINIT, \ FROM_NODE, TO_NODE, CP, VINIT_T, FROM_NODE_T, T_OUT, TEXT, AREA, ALPHA, TL, QEXT, LOAD_VEC_NODES_T, \ LOAD_VEC_BRANCHES_T, JAC_DERIV_DT, JAC_DERIV_DT1, JAC_DERIV_DT_NODE @@ -37,7 +37,6 @@ def calculate_derivatives_hydraulic(net, branch_pit, node_pit, options): to_nodes = branch_pit[:, TO_NODE].astype(np.int32) tinit_branch, height_difference, p_init_i_abs, p_init_i1_abs = \ get_derived_values(node_pit, from_nodes, to_nodes, options["use_numba"]) - branch_pit[:, TINIT] = tinit_branch if not gas_mode: if options["use_numba"]: @@ -64,7 +63,7 @@ def calculate_derivatives_hydraulic(net, branch_pit, node_pit, options): der_comp = fluid.get_der_compressibility() * der_p_m der_comp1 = fluid.get_der_compressibility() * der_p_m1 load_vec, load_vec_nodes, df_dv, df_dv_nodes, df_dp, df_dp1 = derivatives_hydraulic_comp( - branch_pit, lambda_, der_lambda, p_init_i_abs, p_init_i1_abs, height_difference, + node_pit, branch_pit, lambda_, der_lambda, p_init_i_abs, p_init_i1_abs, height_difference, comp_fact, der_comp, der_comp1) branch_pit[:, LOAD_VEC_BRANCHES] = load_vec diff --git a/pandapipes/pf/derivative_toolbox.py b/pandapipes/pf/derivative_toolbox.py index e681c71fa..605064639 100644 --- a/pandapipes/pf/derivative_toolbox.py +++ b/pandapipes/pf/derivative_toolbox.py @@ -7,8 +7,8 @@ from pandapipes.constants import P_CONVERSION, GRAVITATION_CONSTANT, NORMAL_PRESSURE, \ NORMAL_TEMPERATURE -from pandapipes.idx_branch import LENGTH, LAMBDA, D, LOSS_COEFFICIENT as LC, RHO, PL, AREA, TINIT, \ - VINIT +from pandapipes.idx_branch import LENGTH, LAMBDA, D, LOSS_COEFFICIENT as LC, RHO, PL, AREA, \ + VINIT, T_OUT, FROM_NODE from pandapipes.idx_node import HEIGHT, PINIT, PAMB, TINIT as TINIT_NODE @@ -32,7 +32,7 @@ def derivatives_hydraulic_incomp_np(branch_pit, der_lambda, p_init_i_abs, p_init return load_vec, load_vec_nodes, df_dv, df_dv_nodes, df_dp, df_dp1 -def derivatives_hydraulic_comp_np(branch_pit, lambda_, der_lambda, p_init_i_abs, p_init_i1_abs, +def derivatives_hydraulic_comp_np(node_pit, branch_pit, lambda_, der_lambda, p_init_i_abs, p_init_i1_abs, height_difference, comp_fact, der_comp, der_comp1): # Formulas for gas pressure loss according to laminar version v_init_abs = np.abs(branch_pit[:, VINIT]) @@ -40,12 +40,13 @@ def derivatives_hydraulic_comp_np(branch_pit, lambda_, der_lambda, p_init_i_abs, p_diff = p_init_i_abs - p_init_i1_abs p_sum = p_init_i_abs + p_init_i1_abs p_sum_div = np.divide(1, p_sum) - - const_lambda = np.divide(NORMAL_PRESSURE * branch_pit[:, RHO] * branch_pit[:, TINIT], + from_nodes = branch_pit[:, FROM_NODE].astype(np.int32) + tm = (node_pit[from_nodes, TINIT_NODE] + branch_pit[:, T_OUT]) / 2 + const_lambda = np.divide(NORMAL_PRESSURE * branch_pit[:, RHO] * tm, NORMAL_TEMPERATURE * P_CONVERSION) const_height = np.divide( branch_pit[:, RHO] * NORMAL_TEMPERATURE * GRAVITATION_CONSTANT * height_difference, - 2 * NORMAL_PRESSURE * branch_pit[:, TINIT] * P_CONVERSION) + 2 * NORMAL_PRESSURE * tm * P_CONVERSION) friction_term = np.divide(lambda_ * branch_pit[:, LENGTH], branch_pit[:, D]) + branch_pit[:, LC] load_vec = p_diff + branch_pit[:, PL] + const_height * p_sum \ diff --git a/pandapipes/pf/derivative_toolbox_numba.py b/pandapipes/pf/derivative_toolbox_numba.py index a3b7f3eb8..3e125a114 100644 --- a/pandapipes/pf/derivative_toolbox_numba.py +++ b/pandapipes/pf/derivative_toolbox_numba.py @@ -3,8 +3,8 @@ from pandapipes.constants import P_CONVERSION, GRAVITATION_CONSTANT, NORMAL_PRESSURE, \ NORMAL_TEMPERATURE -from pandapipes.idx_branch import LENGTH, LAMBDA, D, LOSS_COEFFICIENT as LC, RHO, PL, AREA, TINIT, \ - VINIT +from pandapipes.idx_branch import LENGTH, LAMBDA, D, LOSS_COEFFICIENT as LC, RHO, PL, AREA, \ + VINIT, FROM_NODE, TO_NODE from pandapipes.idx_node import HEIGHT, PAMB, PINIT, TINIT as TINIT_NODE try: @@ -43,9 +43,9 @@ def derivatives_hydraulic_incomp_numba(branch_pit, der_lambda, p_init_i_abs, p_i return load_vec, load_vec_nodes, df_dv, df_dv_nodes, df_dp, df_dp1 -@jit((float64[:, :], float64[:], float64[:], float64[:], float64[:], float64[:], float64[:], +@jit((float64[:, :], float64[:, :], float64[:], float64[:], float64[:], float64[:], float64[:], float64[:], float64[:], float64[:]), nopython=True, cache=False) -def derivatives_hydraulic_comp_numba(branch_pit, lambda_, der_lambda, p_init_i_abs, p_init_i1_abs, +def derivatives_hydraulic_comp_numba(node_pit, branch_pit, lambda_, der_lambda, p_init_i_abs, p_init_i1_abs, height_difference, comp_fact, der_comp, der_comp1): le = lambda_.shape[0] load_vec = np.zeros_like(lambda_) @@ -54,6 +54,8 @@ def derivatives_hydraulic_comp_numba(branch_pit, lambda_, der_lambda, p_init_i_a df_dp1 = np.zeros_like(lambda_) * (-1) load_vec_nodes = np.zeros_like(der_lambda) df_dv_nodes = np.zeros_like(der_lambda) + from_nodes = branch_pit[:, FROM_NODE].astype(np.int32) + to_nodes = branch_pit[:, TO_NODE].astype(np.int32) # Formulas for gas pressure loss according to laminar version for i in range(le): @@ -63,12 +65,15 @@ def derivatives_hydraulic_comp_numba(branch_pit, lambda_, der_lambda, p_init_i_a p_diff = p_init_i_abs[i] - p_init_i1_abs[i] p_sum = p_init_i_abs[i] + p_init_i1_abs[i] p_sum_div = np.divide(1, p_sum) + fn = from_nodes[i] + tn = to_nodes[i] + tm = (node_pit[fn, TINIT_NODE] + node_pit[tn, TINIT_NODE]) / 2 - const_lambda = np.divide(NORMAL_PRESSURE * branch_pit[i][RHO] * branch_pit[i][TINIT], + const_lambda = np.divide(NORMAL_PRESSURE * branch_pit[i][RHO] * tm, NORMAL_TEMPERATURE * P_CONVERSION) const_height = np.divide( branch_pit[i][RHO] * NORMAL_TEMPERATURE * GRAVITATION_CONSTANT * height_difference[i], - 2 * NORMAL_PRESSURE * branch_pit[i][TINIT] * P_CONVERSION) + 2 * NORMAL_PRESSURE * tm * P_CONVERSION) friction_term = np.divide(lambda_[i] * branch_pit[i][LENGTH], branch_pit[i][D]) + branch_pit[i][LC] diff --git a/pandapipes/pf/result_extraction.py b/pandapipes/pf/result_extraction.py index 1782a9f4c..7bf8bf1cf 100644 --- a/pandapipes/pf/result_extraction.py +++ b/pandapipes/pf/result_extraction.py @@ -2,7 +2,7 @@ from pandapipes.constants import NORMAL_PRESSURE, NORMAL_TEMPERATURE from pandapipes.idx_branch import ELEMENT_IDX, FROM_NODE, TO_NODE, LOAD_VEC_NODES, VINIT, RE, \ - LAMBDA, TINIT, FROM_NODE_T, TO_NODE_T, PL, T_OUT + LAMBDA, FROM_NODE_T, TO_NODE_T, PL, T_OUT from pandapipes.idx_node import TABLE_IDX as TABLE_IDX_NODE, PINIT, PAMB, TINIT as TINIT_NODE from pandapipes.pf.internals_toolbox import _sum_by_group from pandapipes.pf.pipeflow_setup import get_table_number, get_lookup, get_net_option @@ -77,9 +77,15 @@ def get_branch_results_gas(net, branch_pit, node_pit, from_nodes, to_nodes, v_mp / (p_abs_from[mask] ** 2 - p_abs_to[mask] ** 2) fluid = get_fluid(net) - numerator = NORMAL_PRESSURE * branch_pit[:, TINIT] / NORMAL_TEMPERATURE - normfactor_from = numerator * fluid.get_property("compressibility", p_abs_from) / p_abs_from - normfactor_to = numerator * fluid.get_property("compressibility", p_abs_to) / p_abs_to + t_from = node_pit[from_nodes, TINIT_NODE] + t_to = branch_pit[:, T_OUT] + tm = (t_from + t_to) / 2 + numerator_from = NORMAL_PRESSURE * t_from / NORMAL_TEMPERATURE + numerator_to = NORMAL_PRESSURE * t_to / NORMAL_TEMPERATURE + numerator = NORMAL_PRESSURE * tm / NORMAL_TEMPERATURE + + normfactor_from = numerator_from * fluid.get_property("compressibility", p_abs_from) / p_abs_from + normfactor_to = numerator_to * fluid.get_property("compressibility", p_abs_to) / p_abs_to normfactor_mean = numerator * fluid.get_property("compressibility", p_abs_mean) / p_abs_mean v_gas_from = v_mps * normfactor_from @@ -101,7 +107,7 @@ def get_branch_results_gas_numba(net, branch_pit, node_pit, from_nodes, to_nodes comp_mean = fluid.get_property("compressibility", p_abs_mean) v_gas_from, v_gas_to, v_gas_mean, normfactor_from, normfactor_to, normfactor_mean = \ - get_gas_vel_numba(branch_pit, comp_from, comp_to, comp_mean, p_abs_from, p_abs_to, + get_gas_vel_numba(node_pit, branch_pit, comp_from, comp_to, comp_mean, p_abs_from, p_abs_to, p_abs_mean, v_mps) return v_gas_from, v_gas_to, v_gas_mean, p_abs_from, p_abs_to, p_abs_mean, normfactor_from, \ @@ -125,15 +131,19 @@ def get_pressures_numba(node_pit, from_nodes, to_nodes, v_mps, p_from, p_to): @jit(nopython=True) -def get_gas_vel_numba(branch_pit, comp_from, comp_to, comp_mean, p_abs_from, p_abs_to, p_abs_mean, - v_mps): +def get_gas_vel_numba(node_pit, branch_pit, comp_from, comp_to, comp_mean, p_abs_from, p_abs_to, p_abs_mean, v_mps): v_gas_from, v_gas_to, v_gas_mean, normfactor_from, normfactor_to, normfactor_mean = \ [np.empty_like(v_mps) for _ in range(6)] - + from_nodes = branch_pit[:, FROM_NODE].astype(np.int32) for i in range(len(v_mps)): - numerator = np.divide(NORMAL_PRESSURE * branch_pit[i, TINIT], NORMAL_TEMPERATURE) - normfactor_from[i] = np.divide(numerator * comp_from[i], p_abs_from[i]) - normfactor_to[i] = np.divide(numerator * comp_to[i], p_abs_to[i]) + t_from = node_pit[from_nodes[i], TINIT_NODE] + t_to = branch_pit[i, T_OUT] + tm = (t_from + t_to) / 2 + numerator_from = np.divide(NORMAL_PRESSURE * t_from, NORMAL_TEMPERATURE) + numerator_to = np.divide(NORMAL_PRESSURE * t_to, NORMAL_TEMPERATURE) + numerator = np.divide(NORMAL_PRESSURE * tm, NORMAL_TEMPERATURE) + normfactor_from[i] = np.divide(numerator_from * comp_from[i], p_abs_from[i]) + normfactor_to[i] = np.divide(numerator_to * comp_to[i], p_abs_to[i]) normfactor_mean[i] = np.divide(numerator * comp_mean[i], p_abs_mean[i]) v_gas_from[i] = v_mps[i] * normfactor_from[i] v_gas_to[i] = v_mps[i] * normfactor_to[i] diff --git a/pandapipes/test/pipeflow_internals/test_pipeflow_modes.py b/pandapipes/test/pipeflow_internals/test_pipeflow_modes.py index 8daa84d14..f08d49397 100644 --- a/pandapipes/test/pipeflow_internals/test_pipeflow_modes.py +++ b/pandapipes/test/pipeflow_internals/test_pipeflow_modes.py @@ -95,7 +95,7 @@ def test_heat_only(use_numba): nonlinear_method="automatic", mode="hydraulics", use_numba=use_numba) p = ntw._pit["node"][:, 5] - v = ntw._pit["branch"][:, 12] + v = ntw._pit["branch"][:, 11] u = np.concatenate((p, v)) pandapipes.pipeflow(ntw, sol_vec=u, stop_condition="tol", iter=50, friction_model="nikuradse", From 4244569068e86f2803f76f544eafd0bbcd586f05 Mon Sep 17 00:00:00 2001 From: sdrauz Date: Fri, 29 Sep 2023 13:33:18 +0200 Subject: [PATCH 5/5] renaming T_OUT in TOUTINIT, making test/pipeflow more stable --- .../abstract_models/branch_w_internals_models.py | 6 +++--- .../abstract_models/branch_wo_internals_models.py | 6 +++--- .../component_models/heat_exchanger_component.py | 3 ++- pandapipes/component_models/pump_component.py | 8 ++++---- pandapipes/idx_branch.py | 2 +- pandapipes/pf/derivative_calculation.py | 4 ++-- pandapipes/pf/derivative_toolbox.py | 4 ++-- pandapipes/pf/result_extraction.py | 10 +++++----- pandapipes/pipeflow.py | 10 +++++----- .../test/pipeflow_internals/test_pipeflow_modes.py | 4 ++-- 10 files changed, 29 insertions(+), 28 deletions(-) diff --git a/pandapipes/component_models/abstract_models/branch_w_internals_models.py b/pandapipes/component_models/abstract_models/branch_w_internals_models.py index c7d5c2b5c..0478254a9 100644 --- a/pandapipes/component_models/abstract_models/branch_w_internals_models.py +++ b/pandapipes/component_models/abstract_models/branch_w_internals_models.py @@ -6,7 +6,7 @@ from pandapipes.component_models.abstract_models.branch_models import BranchComponent from pandapipes.component_models.component_toolbox import set_entry_check_repeat -from pandapipes.idx_branch import ACTIVE, FROM_NODE, TO_NODE, RHO, ETA, CP, ELEMENT_IDX, T_OUT +from pandapipes.idx_branch import ACTIVE, FROM_NODE, TO_NODE, RHO, ETA, CP, ELEMENT_IDX, TOUTINIT from pandapipes.idx_node import L, node_cols, TINIT as TINIT_NODE from pandapipes.pf.pipeflow_setup import add_table_lookup, get_lookup, get_table_number from pandapipes.properties.fluids import get_fluid @@ -196,8 +196,8 @@ def create_pit_branch_entries(cls, net, branch_pit): internal_pipe_number, has_internals) branch_w_internals_pit[:, FROM_NODE] = from_nodes branch_w_internals_pit[:, TO_NODE] = to_nodes - branch_w_internals_pit[:, T_OUT] = node_pit[to_nodes, TINIT_NODE] - tm = (node_pit[from_nodes, TINIT_NODE] + branch_w_internals_pit[:, T_OUT]) / 2 + branch_w_internals_pit[:, TOUTINIT] = node_pit[to_nodes, TINIT_NODE] + tm = (node_pit[from_nodes, TINIT_NODE] + branch_w_internals_pit[:, TOUTINIT]) / 2 fluid = get_fluid(net) branch_w_internals_pit[:, RHO] = fluid.get_density(tm) branch_w_internals_pit[:, ETA] = fluid.get_viscosity(tm) diff --git a/pandapipes/component_models/abstract_models/branch_wo_internals_models.py b/pandapipes/component_models/abstract_models/branch_wo_internals_models.py index b66d01567..2867c241b 100644 --- a/pandapipes/component_models/abstract_models/branch_wo_internals_models.py +++ b/pandapipes/component_models/abstract_models/branch_wo_internals_models.py @@ -4,7 +4,7 @@ from pandapipes.component_models.abstract_models.branch_models import BranchComponent -from pandapipes.idx_branch import FROM_NODE, TO_NODE, T_OUT, ELEMENT_IDX, RHO, ETA, CP, ACTIVE +from pandapipes.idx_branch import FROM_NODE, TO_NODE, TOUTINIT, ELEMENT_IDX, RHO, ETA, CP, ACTIVE from pandapipes.idx_node import TINIT as TINIT_NODE from pandapipes.pf.pipeflow_setup import add_table_lookup @@ -82,8 +82,8 @@ def create_pit_branch_entries(cls, net, branch_pit): branch_wo_internals_pit[:, ELEMENT_IDX] = net[cls.table_name()].index.values branch_wo_internals_pit[:, FROM_NODE] = from_nodes branch_wo_internals_pit[:, TO_NODE] = to_nodes - branch_wo_internals_pit[:, T_OUT] = node_pit[to_nodes, TINIT_NODE] - tm = (node_pit[from_nodes, TINIT_NODE] + branch_wo_internals_pit[:, T_OUT]) / 2 + branch_wo_internals_pit[:, TOUTINIT] = node_pit[to_nodes, TINIT_NODE] + tm = (node_pit[from_nodes, TINIT_NODE] + branch_wo_internals_pit[:, TOUTINIT]) / 2 fluid = get_fluid(net) branch_wo_internals_pit[:, RHO] = fluid.get_density(tm) branch_wo_internals_pit[:, ETA] = fluid.get_viscosity(tm) diff --git a/pandapipes/component_models/heat_exchanger_component.py b/pandapipes/component_models/heat_exchanger_component.py index 3270d9db1..d958fda94 100644 --- a/pandapipes/component_models/heat_exchanger_component.py +++ b/pandapipes/component_models/heat_exchanger_component.py @@ -9,7 +9,7 @@ from pandapipes.component_models.abstract_models.branch_wzerolength_models import \ BranchWZeroLengthComponent from pandapipes.component_models.junction_component import Junction -from pandapipes.idx_branch import ALPHA, TEXT, QEXT, D, AREA, LOSS_COEFFICIENT as LC +from pandapipes.idx_branch import ALPHA, TEXT, QEXT, D, AREA, LOSS_COEFFICIENT as LC, TOUTINIT from pandapipes.pf.pipeflow_setup import get_fluid from pandapipes.pf.result_extraction import extract_branch_results_without_internals @@ -58,6 +58,7 @@ def create_pit_branch_entries(cls, net, branch_pit): heat_exchanger_pit[:, ALPHA] = 0 heat_exchanger_pit[:, QEXT] = net[cls.table_name()].qext_w.values heat_exchanger_pit[:, TEXT] = 293.15 + heat_exchanger_pit[:, TOUTINIT] = 307 @classmethod def extract_results(cls, net, options, branch_results, mode): diff --git a/pandapipes/component_models/pump_component.py b/pandapipes/component_models/pump_component.py index aa7f6a34c..715332f69 100644 --- a/pandapipes/component_models/pump_component.py +++ b/pandapipes/component_models/pump_component.py @@ -12,7 +12,7 @@ from pandapipes.component_models.component_toolbox import get_component_array from pandapipes.component_models.junction_component import Junction from pandapipes.constants import NORMAL_TEMPERATURE, NORMAL_PRESSURE, R_UNIVERSAL, P_CONVERSION -from pandapipes.idx_branch import VINIT, D, AREA, LOSS_COEFFICIENT as LC, FROM_NODE, T_OUT, PL +from pandapipes.idx_branch import VINIT, D, AREA, LOSS_COEFFICIENT as LC, FROM_NODE, PL from pandapipes.idx_node import PINIT, PAMB, TINIT as TINIT_NODE from pandapipes.pf.pipeflow_setup import get_fluid, get_net_option, get_lookup from pandapipes.pf.result_extraction import extract_branch_results_without_internals @@ -109,10 +109,10 @@ def adaption_before_derivatives_hydraulic(cls, net, branch_pit, node_pit, idx_lo # consider volume flow at inlet normfactor_from = numerator_from * fluid.get_property("compressibility", p_from) \ / (p_from * NORMAL_TEMPERATURE) - v_mean = v_mps * normfactor_from + v_from = v_mps * normfactor_from else: - v_mean = v_mps - vol = v_mean * area + v_from = v_mps + vol = v_from * area if len(std_types): fcts = itemgetter(*std_types)(net['std_types']['pump']) fcts = [fcts] if not isinstance(fcts, tuple) else fcts diff --git a/pandapipes/idx_branch.py b/pandapipes/idx_branch.py index 57a08ce6c..c4e3c1632 100644 --- a/pandapipes/idx_branch.py +++ b/pandapipes/idx_branch.py @@ -32,7 +32,7 @@ JAC_DERIV_DT = 23 JAC_DERIV_DT1 = 24 LOAD_VEC_BRANCHES_T = 25 -T_OUT = 26 # Internal slot for outlet pipe temperature +TOUTINIT = 26 # Internal slot for outlet pipe temperature JAC_DERIV_DT_NODE = 27 # Slot for the derivative fpr T for the nodes connected to branch LOAD_VEC_NODES_T = 28 VINIT_T = 29 diff --git a/pandapipes/pf/derivative_calculation.py b/pandapipes/pf/derivative_calculation.py index 79f148194..7298adbd8 100644 --- a/pandapipes/pf/derivative_calculation.py +++ b/pandapipes/pf/derivative_calculation.py @@ -2,7 +2,7 @@ from pandapipes.idx_branch import LENGTH, ETA, RHO, D, K, RE, LAMBDA, LOAD_VEC_BRANCHES, \ JAC_DERIV_DV, JAC_DERIV_DP, JAC_DERIV_DP1, LOAD_VEC_NODES, JAC_DERIV_DV_NODE, VINIT, \ - FROM_NODE, TO_NODE, CP, VINIT_T, FROM_NODE_T, T_OUT, TEXT, AREA, ALPHA, TL, QEXT, LOAD_VEC_NODES_T, \ + FROM_NODE, TO_NODE, CP, VINIT_T, FROM_NODE_T, TOUTINIT, TEXT, AREA, ALPHA, TL, QEXT, LOAD_VEC_NODES_T, \ LOAD_VEC_BRANCHES_T, JAC_DERIV_DT, JAC_DERIV_DT1, JAC_DERIV_DT_NODE from pandapipes.idx_node import TINIT as TINIT_NODE from pandapipes.properties.fluids import get_fluid @@ -80,7 +80,7 @@ def calculate_derivatives_thermal(net, branch_pit, node_pit, options): v_init = branch_pit[:, VINIT_T] from_nodes = branch_pit[:, FROM_NODE_T].astype(np.int32) t_init_i = node_pit[from_nodes, TINIT_NODE] - t_init_i1 = branch_pit[:, T_OUT] + t_init_i1 = branch_pit[:, TOUTINIT] t_amb = branch_pit[:, TEXT] area = branch_pit[:, AREA] length = branch_pit[:, LENGTH] diff --git a/pandapipes/pf/derivative_toolbox.py b/pandapipes/pf/derivative_toolbox.py index 605064639..8ee435712 100644 --- a/pandapipes/pf/derivative_toolbox.py +++ b/pandapipes/pf/derivative_toolbox.py @@ -8,7 +8,7 @@ from pandapipes.constants import P_CONVERSION, GRAVITATION_CONSTANT, NORMAL_PRESSURE, \ NORMAL_TEMPERATURE from pandapipes.idx_branch import LENGTH, LAMBDA, D, LOSS_COEFFICIENT as LC, RHO, PL, AREA, \ - VINIT, T_OUT, FROM_NODE + VINIT, TOUTINIT, FROM_NODE from pandapipes.idx_node import HEIGHT, PINIT, PAMB, TINIT as TINIT_NODE @@ -41,7 +41,7 @@ def derivatives_hydraulic_comp_np(node_pit, branch_pit, lambda_, der_lambda, p_i p_sum = p_init_i_abs + p_init_i1_abs p_sum_div = np.divide(1, p_sum) from_nodes = branch_pit[:, FROM_NODE].astype(np.int32) - tm = (node_pit[from_nodes, TINIT_NODE] + branch_pit[:, T_OUT]) / 2 + tm = (node_pit[from_nodes, TINIT_NODE] + branch_pit[:, TOUTINIT]) / 2 const_lambda = np.divide(NORMAL_PRESSURE * branch_pit[:, RHO] * tm, NORMAL_TEMPERATURE * P_CONVERSION) const_height = np.divide( diff --git a/pandapipes/pf/result_extraction.py b/pandapipes/pf/result_extraction.py index 7bf8bf1cf..037ffc790 100644 --- a/pandapipes/pf/result_extraction.py +++ b/pandapipes/pf/result_extraction.py @@ -2,7 +2,7 @@ from pandapipes.constants import NORMAL_PRESSURE, NORMAL_TEMPERATURE from pandapipes.idx_branch import ELEMENT_IDX, FROM_NODE, TO_NODE, LOAD_VEC_NODES, VINIT, RE, \ - LAMBDA, FROM_NODE_T, TO_NODE_T, PL, T_OUT + LAMBDA, FROM_NODE_T, TO_NODE_T, PL, TOUTINIT from pandapipes.idx_node import TABLE_IDX as TABLE_IDX_NODE, PINIT, PAMB, TINIT as TINIT_NODE from pandapipes.pf.internals_toolbox import _sum_by_group from pandapipes.pf.pipeflow_setup import get_table_number, get_lookup, get_net_option @@ -78,7 +78,7 @@ def get_branch_results_gas(net, branch_pit, node_pit, from_nodes, to_nodes, v_mp fluid = get_fluid(net) t_from = node_pit[from_nodes, TINIT_NODE] - t_to = branch_pit[:, T_OUT] + t_to = branch_pit[:, TOUTINIT] tm = (t_from + t_to) / 2 numerator_from = NORMAL_PRESSURE * t_from / NORMAL_TEMPERATURE numerator_to = NORMAL_PRESSURE * t_to / NORMAL_TEMPERATURE @@ -137,7 +137,7 @@ def get_gas_vel_numba(node_pit, branch_pit, comp_from, comp_to, comp_mean, p_abs from_nodes = branch_pit[:, FROM_NODE].astype(np.int32) for i in range(len(v_mps)): t_from = node_pit[from_nodes[i], TINIT_NODE] - t_to = branch_pit[i, T_OUT] + t_to = branch_pit[i, TOUTINIT] tm = (t_from + t_to) / 2 numerator_from = np.divide(NORMAL_PRESSURE * t_from, NORMAL_TEMPERATURE) numerator_to = np.divide(NORMAL_PRESSURE * t_to, NORMAL_TEMPERATURE) @@ -283,8 +283,8 @@ def extract_results_active_pit(net, mode="hydraulics"): if i not in [not_affected_node_col]]) rows_nodes = np.arange(net["_pit"]["node"].shape[0])[nodes_connected] - result_branch_col = VINIT if mode == "hydraulics" else T_OUT - not_affected_branch_col = T_OUT if mode == "hydraulics" else VINIT + result_branch_col = VINIT if mode == "hydraulics" else TOUTINIT + not_affected_branch_col = TOUTINIT if mode == "hydraulics" else VINIT copied_branch_cols = np.array([i for i in range(net["_pit"]["branch"].shape[1]) if i not in [FROM_NODE, TO_NODE, FROM_NODE_T, TO_NODE_T, not_affected_branch_col]]) diff --git a/pandapipes/pipeflow.py b/pandapipes/pipeflow.py index 710764ef4..aa9f49947 100644 --- a/pandapipes/pipeflow.py +++ b/pandapipes/pipeflow.py @@ -7,7 +7,7 @@ from pandapower.auxiliary import ppException from scipy.sparse.linalg import spsolve -from pandapipes.idx_branch import FROM_NODE, TO_NODE, FROM_NODE_T, TO_NODE_T, VINIT, T_OUT, VINIT_T +from pandapipes.idx_branch import FROM_NODE, TO_NODE, FROM_NODE_T, TO_NODE_T, VINIT, TOUTINIT, VINIT_T from pandapipes.idx_node import PINIT, TINIT from pandapipes.pf.build_system_matrix import build_system_matrix from pandapipes.pf.derivative_calculation import calculate_derivatives_hydraulic, calculate_derivatives_thermal @@ -278,13 +278,13 @@ def solve_temperature(net): jacobian, epsilon = build_system_matrix(net, branch_pit, node_pit, True) t_init_old = node_pit[:, TINIT].copy() - t_out_old = branch_pit[:, T_OUT].copy() + t_out_old = branch_pit[:, TOUTINIT].copy() x = spsolve(jacobian, epsilon) node_pit[:, TINIT] += x[:len(node_pit)] * options["alpha"] - branch_pit[:, T_OUT] += x[len(node_pit):] + branch_pit[:, TOUTINIT] += x[len(node_pit):] - return branch_pit[:, T_OUT], t_out_old, node_pit[:, TINIT], t_init_old, epsilon + return branch_pit[:, TOUTINIT], t_out_old, node_pit[:, TINIT], t_init_old, epsilon def set_damping_factor(net, niter, error): @@ -318,7 +318,7 @@ def set_damping_factor(net, niter, error): def finalize_iteration(net, niter, error_1, error_2, residual_norm, nonlinear_method, tol_1, tol_2, tol_res, vals_1_old, vals_2_old, hydraulic_mode=True): - col1, col2 = (PINIT, VINIT) if hydraulic_mode else (TINIT, T_OUT) + col1, col2 = (PINIT, VINIT) if hydraulic_mode else (TINIT, TOUTINIT) # Control of damping factor if nonlinear_method == "automatic": diff --git a/pandapipes/test/pipeflow_internals/test_pipeflow_modes.py b/pandapipes/test/pipeflow_internals/test_pipeflow_modes.py index f08d49397..d722711ab 100644 --- a/pandapipes/test/pipeflow_internals/test_pipeflow_modes.py +++ b/pandapipes/test/pipeflow_internals/test_pipeflow_modes.py @@ -94,8 +94,8 @@ def test_heat_only(use_numba): pandapipes.pipeflow(ntw, stop_condition="tol", iter=50, friction_model="nikuradse", nonlinear_method="automatic", mode="hydraulics", use_numba=use_numba) - p = ntw._pit["node"][:, 5] - v = ntw._pit["branch"][:, 11] + p = ntw._pit["node"][:, PINIT] + v = ntw._pit["branch"][:, VINIT] u = np.concatenate((p, v)) pandapipes.pipeflow(ntw, sol_vec=u, stop_condition="tol", iter=50, friction_model="nikuradse",