Ejemplo n.º 1
0
    def extract_results(cls, net, options, node_name):
        """
        Function that extracts certain results.

        :param net: The pandapipes network
        :type net: pandapipesNet
        :param options:
        :type options:
        :param node_name:
        :type node_name:
        :return: No Output.
        """
        res_table = super().extract_results(net, options, node_name)

        loads = net[cls.table_name()]

        is_loads = loads.in_service.values
        fj, tj = get_lookup(net, "node", "from_to")[node_name]
        junct_pit = net["_pit"]["node"][fj:tj, :]
        nodes_connected = get_lookup(net, "node", "active")[fj:tj]
        is_juncts = np.isin(loads.junction.values, junct_pit[nodes_connected, ELEMENT_IDX])

        is_calc = is_loads & is_juncts
        res_table["mdot_kg_per_s"].values[is_calc] = loads.mdot_kg_per_s.values[is_calc] \
                                                     * loads.scaling.values[is_calc]
Ejemplo n.º 2
0
    def create_pit_node_entries(cls, net, node_pit, node_name):
        """
        Function which creates pit node entries.

        :param net: The pandapipes network
        :type net: pandapipesNet
        :param node_pit:
        :type node_pit:
        :return: No Output.
        """
        ft_lookup = get_lookup(net, "node", "from_to")
        table_nr = get_table_number(get_lookup(net, "node", "table"),
                                    cls.table_name())
        f, t = ft_lookup[cls.table_name()]

        junctions = net[cls.table_name()]
        junction_pit = node_pit[f:t, :]
        junction_pit[:, :] = np.array([table_nr, 0, L] + [0] * (node_cols - 3))

        junction_pit[:, ELEMENT_IDX] = junctions.index.values
        junction_pit[:, HEIGHT] = junctions.height_m.values
        junction_pit[:, PINIT] = junctions.pn_bar.values
        junction_pit[:, TINIT] = junctions.tfluid_k.values
        junction_pit[:, RHO] = get_fluid(net).get_density(junction_pit[:,
                                                                       TINIT])
        junction_pit[:, PAMB] = p_correction_height_air(junction_pit[:,
                                                                     HEIGHT])
        junction_pit[:, ACTIVE_ND] = junctions.in_service.values
Ejemplo n.º 3
0
    def create_pit_node_entries(cls, net, node_pit, node_name):
        """
        Function which creates pit node entries.

        :param net: The pandapipes network
        :type net: pandapipesNet
        :param node_pit:
        :type node_pit:
        :return: No Output.
        """
        table_lookup = get_lookup(net, "node", "table")
        table_nr = get_table_number(table_lookup, cls.internal_node_name())
        if table_nr is None:
            return None, 0, 0, None, None, None
        ft_lookup = get_lookup(net, "node", "from_to")
        f, t = ft_lookup[cls.internal_node_name()]

        int_node_pit = node_pit[f:t, :]
        int_node_pit[:, :] = np.array([table_nr, 0, L] + [0] * (node_cols - 3))
        int_node_number = cls.get_internal_pipe_number(net) - 1

        int_node_pit[:, ELEMENT_IDX] = np.arange(t - f)

        f_junction, t_junction = ft_lookup[node_name]
        junction_pit = node_pit[f_junction:t_junction, :]
        from_junctions = net[cls.table_name()].from_junction.values.astype(
            np.int32)
        to_junctions = net[cls.table_name()].to_junction.values.astype(
            np.int32)
        return table_nr, int_node_number, int_node_pit, junction_pit, from_junctions, to_junctions
Ejemplo n.º 4
0
    def extract_results(cls, net, options, node_name):
        """
        Function that extracts certain results.

        :param net: The pandapipes network
        :type net: pandapipesNet
        :param options:
        :type options:
        :return: No Output.
        """
        res_table = super().extract_results(net, options, node_name)

        f, t = get_lookup(net, "node", "from_to")[cls.table_name()]
        fa, ta = get_lookup(net, "node", "from_to_active")[cls.table_name()]

        junction_pit = net["_active_pit"]["node"][fa:ta, :]
        junctions_active = get_lookup(net, "node", "active")[f:t]

        if np.any(junction_pit[:, PINIT] < 0):
            warn(
                UserWarning(
                    'Pipeflow converged, however, the results are phyisically incorrect '
                    'as pressure is at the nodes %s are negative' %
                    junction_pit[junction_pit[:, PINIT] < 0, ELEMENT_IDX]))

        res_table["p_bar"].values[junctions_active] = junction_pit[:, PINIT]
        res_table["t_k"].values[junctions_active] = junction_pit[:, TINIT]
Ejemplo n.º 5
0
    def create_pit_branch_entries(cls, net, branch_pit, node_name):
        """
        Function which creates pit branch entries.

        :param net: The pandapipes network
        :type net: pandapipesNet
        :param branch_pit:
        :type branch_pit:
        :param node_name:
        :type node_name:
        :return: No Output.
        """

        f, t = get_lookup(net, "branch", "from_to")[cls.table_name()]
        branch_table_nr = get_table_number(get_lookup(net, "branch", "table"),
                                           cls.table_name())
        branch_component_pit = branch_pit[f:t, :]
        node_pit = net["_pit"]["node"]
        junction_idx_lookup = get_lookup(net, "node", "index")[node_name]
        from_nodes = junction_idx_lookup[net[cls.table_name()]
                                         ["from_junction"].values]
        to_nodes = junction_idx_lookup[net[cls.table_name()]
                                       ["to_junction"].values]
        branch_component_pit[:, :] = np.array([branch_table_nr] + [0] *
                                              (branch_cols - 1))
        branch_component_pit[:, VINIT] = 0.1
        return branch_component_pit, node_pit, from_nodes, to_nodes
Ejemplo n.º 6
0
    def prepare_result_tables(cls, net, options, node_name):
        res_table = super().extract_results(net, options, node_name)

        f, t = get_lookup(net, "branch", "from_to")[cls.table_name()]
        fa, ta = get_lookup(net, "branch", "from_to_active")[cls.table_name()]

        placement_table = np.argsort(net[cls.table_name()].index.values)
        idx_pit = net["_pit"]["branch"][f:t, ELEMENT_IDX]
        pipe_considered = get_lookup(net, "branch", "active")[f:t]
        _, active_pipes = _sum_by_group(idx_pit, pipe_considered.astype(np.int32))
        active_pipes = active_pipes > 0.99
        placement_table = placement_table[active_pipes]
        branch_pit = net["_active_pit"]["branch"][fa:ta, :]
        return placement_table, branch_pit, res_table
Ejemplo n.º 7
0
    def create_pit_branch_entries(cls, net, branch_winternals_pit, node_name):
        """
        Function which creates pit branch entries.

        :param net: The pandapipes network
        :type net: pandapipesNet
        :param branch_pit:
        :type branch_pit:
        :return: No Output.
        """
        branch_winternals_pit, node_pit, from_nodes, to_nodes\
            = super().create_pit_branch_entries(net, branch_winternals_pit, node_name)

        internal_pipe_number = cls.get_internal_pipe_number(net)
        node_ft_lookups = get_lookup(net, "node", "from_to")

        if cls.internal_node_name() in node_ft_lookups:
            pipe_nodes_from, pipe_nodes_to = node_ft_lookups[cls.internal_node_name()]
            pipe_nodes_idx = np.arange(pipe_nodes_from, pipe_nodes_to)
            insert_places = np.repeat(np.arange(len(from_nodes)), internal_pipe_number - 1)
            from_nodes = np.insert(from_nodes, insert_places + 1, pipe_nodes_idx)
            to_nodes = np.insert(to_nodes, insert_places, pipe_nodes_idx)

        branch_winternals_pit[:, ELEMENT_IDX] = np.repeat(net[cls.table_name()].index.values, internal_pipe_number)
        branch_winternals_pit[:, FROM_NODE] = from_nodes
        branch_winternals_pit[:, TO_NODE] = to_nodes
        branch_winternals_pit[:, TINIT] = (node_pit[from_nodes, TINIT_NODE] + node_pit[to_nodes, TINIT_NODE]) / 2
        fluid = get_fluid(net)
        branch_winternals_pit[:, RHO] = fluid.get_density(branch_winternals_pit[:, TINIT])
        branch_winternals_pit[:, ETA] = fluid.get_viscosity(branch_winternals_pit[:, TINIT])
        branch_winternals_pit[:, CP] = fluid.get_heat_capacity(branch_winternals_pit[:, TINIT])
        branch_winternals_pit[:, ACTIVE] = np.repeat(net[cls.table_name()][cls.active_identifier()].values,
                                           internal_pipe_number)

        return branch_winternals_pit, internal_pipe_number
Ejemplo n.º 8
0
def solve_hydraulics(net):
    """
    Create and solve the linearized system of equations (based on a jacobian in form of a scipy
    sparse matrix and a load vector in form of a numpy array) in order to calculate the hydraulic
    magnitudes (pressure and velocity) for the network nodes and branches.

    :param net: The pandapipesNet for which to solve the hydraulic matrix
    :type net: pandapipesNet
    :return:

    """
    options = net["_options"]
    branch_pit = net["_active_pit"]["branch"]
    node_pit = net["_active_pit"]["node"]

    branch_lookups = get_lookup(net, "branch", "from_to_active")
    for comp in net['component_list']:
        if issubclass(comp, BranchComponent):
            comp.calculate_derivatives_hydraulic(net, branch_pit, node_pit, branch_lookups, options)
    jacobian, epsilon = build_system_matrix(net, branch_pit, node_pit, False)

    v_init_old = branch_pit[:, VINIT].copy()
    p_init_old = node_pit[:, PINIT].copy()

    x = spsolve(jacobian, epsilon)
    branch_pit[:, VINIT] += x[len(node_pit):]
    node_pit[:, PINIT] += x[:len(node_pit)] * options["alpha"]

    return branch_pit[:, VINIT], node_pit[:, PINIT], v_init_old, p_init_old, epsilon
Ejemplo n.º 9
0
    def create_pit_node_entries(cls, net, node_pit, node_name):
        """
        Function which creates pit node entries.

        :param net: The pandapipes network
        :type net: pandapipesNet
        :param node_pit:
        :type node_pit:
        :return: No Output.
        """
        circ_pump, press = super().create_pit_node_entries(
            net, node_pit, node_name)

        junction_idx_lookups = get_lookup(net, "node", "index")[node_name]
        juncts_p, press_sum, number = _sum_by_group(
            circ_pump.to_junction.values, press - circ_pump.plift_bar.values,
            np.ones_like(press, dtype=np.int32))

        index_p = junction_idx_lookups[juncts_p]
        node_pit[index_p, PINIT] = press_sum / number
        node_pit[index_p, NODE_TYPE] = P
        node_pit[index_p, EXT_GRID_OCCURENCE] += number

        net["_lookups"]["ext_grid"] = np.array(
            list(set(np.concatenate([net["_lookups"]["ext_grid"], index_p]))))
Ejemplo n.º 10
0
def test_connectivity_hydraulic2(create_test_net):
    net = copy.deepcopy(create_test_net)

    net.junction.in_service = True
    net.pipe.in_service = True
    net.valve.opened = True

    pandapipes.create_fluid_from_lib(net, "water")

    pandapipes.pipeflow(net,
                        iter=100,
                        tol_p=1e-7,
                        tol_v=1e-7,
                        friction_model="nikuradse")

    pandapipes.create_junction(net, 1., 293.15)
    pandapipes.create_junction(net, 1., 293.15)
    j = pandapipes.create_junction(net, 1., 293.15)
    pandapipes.create_junction(net, 1, 293.15)
    pandapipes.create_junction(net, 1, 293.15)

    pandapipes.create_pipe_from_parameters(net, 0, j, 0.1, 0.1)

    pandapipes.create_sink(net, j, 0.1)

    pandapipes.pipeflow(net,
                        iter=100,
                        tol_p=1e-7,
                        tol_v=1e-7,
                        friction_model="nikuradse")

    active_branches = get_lookup(net, "branch", "active")
    active_nodes = get_lookup(net, "node", "active")

    assert np.all(active_nodes == np.array([
        True, True, True, True, True, True, True, False, False, True, False,
        False, True, True, True
    ]))
    assert np.all(active_branches)

    assert not np.all(
        np.isnan(net.res_junction.loc[[0, 1, 2, 3, 4, 5, 9], :].values))
    assert not np.all(np.isnan(net.res_pipe.values))
    assert np.any(np.isnan(net.res_junction.loc[[7, 8, 10, 11], :].values))
Ejemplo n.º 11
0
def test_connectivity_hydraulic(create_test_net):
    """

    :param create_test_net:
    :type create_test_net:
    :return:
    :rtype:
    """
    net = copy.deepcopy(create_test_net)

    net.junction.in_service = True
    net.pipe.in_service = [True, False, False, True, True]

    pandapipes.create_fluid_from_lib(net, "water")

    pandapipes.pipeflow(net,
                        iter=100,
                        tol_p=1e-7,
                        tol_v=1e-7,
                        friction_model="nikuradse")

    assert np.all(np.isnan(net.res_junction.loc[[2, 5, 6], :].values))
    assert np.all(np.isnan(net.res_pipe.loc[[1, 2, 3], :].values))
    assert not np.any(np.isnan(net.res_junction.loc[[0, 1, 3, 4], :].values))
    assert not np.any(
        np.isnan(net.res_pipe.loc[
            [0, 4], ["v_mean_m_per_s", "p_from_bar", "p_to_bar"]].values))
    assert not np.any(
        np.isnan(net.res_sink.loc[[0, 2], "mdot_kg_per_s"].values))
    assert np.all(np.isnan(net.res_sink.loc[[1, 3, 4],
                                            "mdot_kg_per_s"].values))

    assert np.allclose(net.res_ext_grid.mdot_kg_per_s.sum(),
                       -net.res_sink.mdot_kg_per_s.sum(),
                       rtol=1e-10,
                       atol=0)

    active_branches = get_lookup(net, "branch", "active")
    active_nodes = get_lookup(net, "node", "active")

    assert np.all(active_nodes == np.array(
        [True, True, False, True, True, False, False, False, False, True]))
    assert np.all(active_branches == np.array(
        [True, False, False, False, False, False, True, True, True, False]))
Ejemplo n.º 12
0
def test_gas_internal_nodes():
    """

    :return:
    :rtype:
    """
    net = pandapipes.create_empty_network("net", add_stdtypes=False)
    d = 209.1e-3
    pandapipes.create_junction(net, pn_bar=51, tfluid_k=285.15)
    pandapipes.create_junction(net, pn_bar=51, tfluid_k=285.15)
    pandapipes.create_pipe_from_parameters(net, 0, 1, 12.0, d, k_mm=.5, sections=12)
    pandapipes.create_ext_grid(net, 0, p_bar=51 - 1.01325, t_k=285.15, type="pt")
    pandapipes.create_sink(net, 1, mdot_kg_per_s=0.82752 * 45000 / 3600)
    pandapipes.add_fluid_to_net(net, pandapipes.create_constant_fluid(
        name="natural_gas", fluid_type="gas", viscosity=11.93e-6, heat_capacity=2185,
        compressibility=1, der_compressibility=0, density=0.82752
    ))
    pandapipes.pipeflow(net, stop_condition="tol", iter=70, friction_model="nikuradse",
                        transient=False, nonlinear_method="automatic", tol_p=1e-4, tol_v=1e-4)

    pipe_results = Pipe.get_internal_results(net, [0])

    data = pd.read_csv(os.path.join(internals_data_path, "gas_sections_an.csv"), sep=';', header=0,
                       keep_default_na=False)
    p_an = data["p1"] / 1e5
    v_an = data["v"]
    v_an = v_an.drop([0])

    pipe_p_data_idx = np.where(pipe_results["PINIT"][:, 0] == 0)
    pipe_v_data_idx = np.where(pipe_results["VINIT"][:, 0] == 0)
    pipe_p_data = pipe_results["PINIT"][pipe_p_data_idx, 1]
    pipe_v_data = pipe_results["VINIT"][pipe_v_data_idx, 1]

    node_pit = net["_pit"]["node"]

    junction_idx_lookup = get_lookup(net, "node", "index")[Junction.table_name()]
    from_junction_nodes = junction_idx_lookup[net["pipe"]["from_junction"].values]
    to_junction_nodes = junction_idx_lookup[net["pipe"]["to_junction"].values]

    p_pandapipes = np.zeros(len(pipe_p_data[0]) + 2)
    p_pandapipes[0] = node_pit[from_junction_nodes[0], PINIT]
    p_pandapipes[1:-1] = pipe_p_data[:]
    p_pandapipes[-1] = node_pit[to_junction_nodes[0], PINIT]
    p_pandapipes = p_pandapipes + 1.01325
    v_pandapipes = pipe_v_data[0, :]

    p_diff = np.abs(1 - p_pandapipes / p_an)
    v_diff = np.abs(v_an - v_pandapipes)

    assert np.all(p_diff < 0.01)
    assert np.all(v_diff < 0.4)
Ejemplo n.º 13
0
    def plot_pipe(cls, net, pipe, pipe_results):
        """

        :param net: The pandapipes network
        :type net: pandapipesNet
        :param pipe:
        :type pipe:
        :param pipe_results:
        :type pipe_results:
        :return: No Output.
        """
        pipe_p_data_idx = np.where(pipe_results["PINIT"][:, 0] == pipe)
        pipe_v_data_idx = np.where(pipe_results["VINIT"][:, 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_v_data = pipe_results["VINIT"][pipe_v_data_idx, 1]
        node_pit = net["_pit"]["node"]

        junction_idx_lookup = get_lookup(net, "node",
                                         "index")[Junction.table_name()]
        from_junction_nodes = junction_idx_lookup[net[cls.table_name]
                                                  ["from_junction"].values]
        to_junction_nodes = junction_idx_lookup[net[cls.table_name]
                                                ["to_junction"].values]

        p_values = np.zeros(len(pipe_p_data[0]) + 2)
        p_values[0] = node_pit[from_junction_nodes[pipe], PINIT]
        p_values[1:-1] = pipe_p_data[:]
        p_values[-1] = node_pit[to_junction_nodes[pipe], PINIT]

        t_values = np.zeros(len(pipe_t_data[0]) + 2)
        t_values[0] = node_pit[from_junction_nodes[pipe], TINIT_NODE]
        t_values[1:-1] = pipe_t_data[:]
        t_values[-1] = node_pit[to_junction_nodes[pipe], TINIT_NODE]

        v_values = pipe_v_data[0, :]

        x_pt = np.linspace(0, net.pipe["length_km"], len(p_values))
        x_v = np.linspace(0, net.pipe["length_km"], len(v_values))
        f, axes = plt.subplots(3, 1, sharex="all")
        axes[0].plot(x_pt, p_values)
        axes[0].set_title("Pressure [bar]")
        axes[1].plot(x_v, v_values)
        axes[1].set_title("Velocity [m/s]")
        axes[2].plot(x_pt, t_values)
        axes[2].set_title("Temperature [K]")

        plt.show()
Ejemplo n.º 14
0
    def extract_results(cls, net, options, node_name):
        """
        Function that extracts certain results.

        :param net: The pandapipes network
        :type net: pandapipesNet
        :param options:
        :type options:
        :param node_name:
        :type node_name:
        :return: No Output.
        """
        ext_grids = net[cls.table_name()]

        if len(ext_grids) == 0:
            return

        res_table = super().extract_results(net, options, node_name)

        branch_pit = net['_pit']['branch']
        node_pit = net["_pit"]["node"]

        p_grids = np.isin(ext_grids.type.values, ["p", "pt"])
        junction = cls.get_connected_junction(net)
        eg_nodes = get_lookup(net, "node", "index")[node_name][np.array(
            junction.values[p_grids])]
        node_uni, inverse_nodes, counts = np.unique(eg_nodes,
                                                    return_counts=True,
                                                    return_inverse=True)
        eg_from_branches = np.isin(branch_pit[:, FROM_NODE], node_uni)
        eg_to_branches = np.isin(branch_pit[:, TO_NODE], node_uni)
        from_nodes = branch_pit[eg_from_branches, FROM_NODE]
        to_nodes = branch_pit[eg_to_branches, TO_NODE]
        mass_flow_from = branch_pit[eg_from_branches, LOAD_VEC_NODES]
        mass_flow_to = branch_pit[eg_to_branches, LOAD_VEC_NODES]
        loads = node_pit[node_uni, LOAD]
        all_index_nodes = np.concatenate([from_nodes, to_nodes, node_uni])
        all_mass_flows = np.concatenate(
            [-mass_flow_from, mass_flow_to, -loads])
        nodes, sum_mass_flows = _sum_by_group(all_index_nodes, all_mass_flows)

        # positive results mean that the ext_grid feeds in, negative means that the ext grid
        # extracts (like a load)
        res_table["mdot_kg_per_s"].values[p_grids] = \
            cls.sign() * (sum_mass_flows / counts)[inverse_nodes]
        return res_table, ext_grids, node_uni, node_pit, branch_pit
Ejemplo n.º 15
0
    def create_pit_node_entries(cls, net, node_pit, node_name):
        """
        Function which creates pit node entries.

        :param net: The pandapipes network
        :type net: pandapipesNet
        :param node_pit:
        :type node_pit:
        :return: No Output.
        """
        loads = net[cls.table_name()]
        helper = loads.in_service.values * loads.scaling.values * cls.sign()
        mf = np.nan_to_num(loads.mdot_kg_per_s.values)
        mass_flow_loads = mf * helper
        juncts, loads_sum = _sum_by_group(loads.junction.values, mass_flow_loads)
        junction_idx_lookups = get_lookup(net, "node", "index")[node_name]
        index = junction_idx_lookups[juncts]
        node_pit[index, LOAD] += loads_sum
Ejemplo n.º 16
0
    def create_pit_node_entries(cls, net, node_pit, node_name):
        """
        Function which creates pit node entries.

        :param net: The pandapipes network
        :type net: pandapipesNet
        :param node_pit:
        :type node_pit:
        :return: No Output.
        """
        circ_pump, press = super().create_pit_node_entries(net, node_pit, node_name)

        mf = np.nan_to_num(circ_pump.mdot_kg_per_s.values)
        mass_flow_loads = mf * circ_pump.in_service.values
        juncts, loads_sum = _sum_by_group(circ_pump.to_junction.values, mass_flow_loads)
        junction_idx_lookups = get_lookup(net, "node", "index")[node_name]
        index = junction_idx_lookups[juncts]
        node_pit[index, LOAD] += loads_sum
Ejemplo n.º 17
0
def solve_temperature(net):
    """
    This function contains the procedure to build and solve a linearized system of equation based on
    an underlying net and the necessary graph data structures. Temperature values are calculated.
    Returned are the solution vectors for the new iteration, the original solution vectors and a
    vector containing component indices for the system matrix entries

    :param net: The pandapipesNet for which to solve the temperature matrix
    :type net: pandapipesNet
    :return: branch_pit

    """

    options = net["_options"]
    branch_pit = net["_active_pit"]["branch"]
    node_pit = net["_active_pit"]["node"]
    branch_lookups = get_lookup(net, "branch", "from_to_active")

    # Negative velocity values are turned to positive ones (including exchange of from_node and
    # to_node for temperature calculation
    branch_pit[:, VINIT_T] = branch_pit[:, VINIT]
    branch_pit[:, FROM_NODE_T] = branch_pit[:, FROM_NODE]
    branch_pit[:, TO_NODE_T] = branch_pit[:, TO_NODE]
    mask = branch_pit[:, VINIT] < 0
    branch_pit[mask, VINIT_T] = -branch_pit[mask, VINIT]
    branch_pit[mask, FROM_NODE_T] = branch_pit[mask, TO_NODE]
    branch_pit[mask, TO_NODE_T] = branch_pit[mask, FROM_NODE]

    for comp in net['component_list']:
        if issubclass(comp, BranchComponent):
            comp.calculate_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()

    x = spsolve(jacobian, epsilon)
    node_pit[:, TINIT] += x[:len(node_pit)] * options["alpha"]
    branch_pit[:, T_OUT] += x[len(node_pit):]

    return branch_pit[:,
                      T_OUT], t_out_old, node_pit[:,
                                                  TINIT], t_init_old, epsilon
Ejemplo n.º 18
0
def test_temperature_internal_nodes_single_pipe():
    """

    :return:
    :rtype:
    """
    net = pandapipes.create_empty_network("net", add_stdtypes=False)
    d = 75e-3
    pandapipes.create_junction(net, pn_bar=5, tfluid_k=283)
    pandapipes.create_junction(net, pn_bar=5, tfluid_k=283)
    pandapipes.create_pipe_from_parameters(net, 0, 1, 6, d, k_mm=.1, sections=6, alpha_w_per_m2k=5)
    pandapipes.create_ext_grid(net, 0, p_bar=5, t_k=330, type="pt")
    pandapipes.create_sink(net, 1, mdot_kg_per_s=1)

    pandapipes.create_fluid_from_lib(net, "water", overwrite=True)

    pandapipes.pipeflow(net, stop_condition="tol", iter=3, friction_model="nikuradse",
                        mode="all", transient=False, nonlinear_method="automatic", tol_p=1e-4,
                        tol_v=1e-4)

    pipe_results = Pipe.get_internal_results(net, [0])

    data = pd.read_csv(os.path.join(internals_data_path, "Temperature_one_pipe_an.csv"), sep=';',
                       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]

    node_pit = net["_pit"]["node"]

    junction_idx_lookup = get_lookup(net, "node", "index")[Junction.table_name()]
    from_junction_nodes = junction_idx_lookup[net["pipe"]["from_junction"].values]
    to_junction_nodes = junction_idx_lookup[net["pipe"]["to_junction"].values]

    temp_pandapipes = np.zeros(len(pipe_temp_data[0]) + 2)
    temp_pandapipes[0] = node_pit[from_junction_nodes[0], TINIT]
    temp_pandapipes[1:-1] = pipe_temp_data[:]
    temp_pandapipes[-1] = node_pit[to_junction_nodes[0], TINIT]

    temp_diff = np.abs(1 - temp_pandapipes / temp_an)

    assert np.all(temp_diff < 0.01)
Ejemplo n.º 19
0
    def extract_results(cls, net, options, node_name):
        """
        Function that extracts certain results.

        :param net: The pandapipes network
        :type net: pandapipesNet
        :param options:
        :type options:
        :return: No Output.
        """
        res_table, circ_pump, index_nodes_from, node_pit, branch_pit = \
            super().extract_results(net, options, node_name)

        index_juncts_to = circ_pump.to_junction.values
        junct_uni_to = np.array(list(set(index_juncts_to)))
        index_nodes_to = get_lookup(net, "node",
                                    "index")[node_name][junct_uni_to]

        deltap_bar = node_pit[index_nodes_from,
                              PINIT] - node_pit[index_nodes_to, PINIT]
        res_table["deltap_bar"].values[:] = deltap_bar
Ejemplo n.º 20
0
    def create_pit_node_entries(cls, net, node_pit, node_name):
        """
        Function which creates pit node entries.

        :param net: The pandapipes network
        :type net: pandapipesNet
        :param node_pit:
        :type node_pit:
        :param node_name:
        :type node_name:
        :return: No Output.
        """
        ext_grids = net[cls.table_name()]

        p_mask = np.where(np.isin(ext_grids.type.values, ["p", "pt"]))
        press = ext_grids.p_bar.values[p_mask] * ext_grids.in_service.values[
            p_mask]
        junction_idx_lookups = get_lookup(net, "node", "index")[node_name]
        junction = cls.get_connected_junction(net)
        juncts_p, press_sum, number = _sum_by_group(
            junction.values[p_mask], press, np.ones_like(press,
                                                         dtype=np.int32))
        index_p = junction_idx_lookups[juncts_p]
        node_pit[index_p, PINIT] = press_sum / number
        node_pit[index_p, NODE_TYPE] = P
        node_pit[index_p, EXT_GRID_OCCURENCE] += number

        t_mask = np.where(np.isin(ext_grids.type.values, ["t", "pt"]))
        t_k = ext_grids.t_k.values[t_mask] * ext_grids.in_service.values[t_mask]
        juncts_t, t_sum, number = _sum_by_group(
            junction.values[t_mask], t_k, np.ones_like(t_k, dtype=np.int32))
        index = junction_idx_lookups[juncts_t]
        node_pit[index, TINIT] = t_sum / number
        node_pit[index, NODE_TYPE_T] = T
        node_pit[index, EXT_GRID_OCCURENCE_T] += number

        net["_lookups"]["ext_grid"] = \
            np.array(list(set(np.concatenate([net["_lookups"]["ext_grid"], index_p])))) if \
            "ext_grid" in net['_lookups'] else index_p
        return ext_grids, press
Ejemplo n.º 21
0
    def extract_results(cls, net, options, node_name):
        """
        Function that extracts certain results.

        :param net: The pandapipes network
        :type net: pandapipesNet
        :param options:
        :type options:
        :return: No Output.
        """
        placement_table, heat_exchanger_pit, res_table = \
            super().extract_results(net, options, node_name)

        node_pit = net["_active_pit"]["node"]
        node_active_idx_lookup = get_lookup(net, "node", "index_active")[node_name]
        junction_idx_lookup = get_lookup(net, "node", "index")[node_name]
        from_junction_nodes = node_active_idx_lookup[junction_idx_lookup[
            net[cls.table_name()]["from_junction"].values[placement_table]]]
        to_junction_nodes = node_active_idx_lookup[junction_idx_lookup[
            net[cls.table_name()]["to_junction"].values[placement_table]]]
        p_scale = get_net_option(net, "p_scale")
        from_nodes = heat_exchanger_pit[:, FROM_NODE].astype(np.int32)
        to_nodes = heat_exchanger_pit[:, TO_NODE].astype(np.int32)
        fluid = get_fluid(net)

        v_mps = heat_exchanger_pit[:, VINIT]

        t0 = node_pit[from_nodes, TINIT_NODE]
        t1 = node_pit[to_nodes, TINIT_NODE]
        mf = heat_exchanger_pit[:, LOAD_VEC_NODES]
        vf = heat_exchanger_pit[:, LOAD_VEC_NODES] / get_fluid(net).get_density((t0 + t1) / 2)

        idx_active = heat_exchanger_pit[:, ELEMENT_IDX]
        idx_sort, v_sum, mf_sum, vf_sum = \
            _sum_by_group(idx_active, v_mps, mf, vf)

        if fluid.is_gas:
            # derived from the ideal gas law
            p_from = node_pit[from_nodes, PAMB] + node_pit[from_nodes, PINIT] * p_scale
            p_to = node_pit[to_nodes, PAMB] + node_pit[to_nodes, PINIT] * p_scale
            numerator = NORMAL_PRESSURE * heat_exchanger_pit[:, TINIT]
            normfactor_from = numerator * fluid.get_property("compressibility", p_from) \
                              / (p_from * NORMAL_TEMPERATURE)
            normfactor_to = numerator * fluid.get_property("compressibility", p_to) \
                            / (p_to * NORMAL_TEMPERATURE)
            v_gas_from = v_mps * normfactor_from
            v_gas_to = v_mps * normfactor_to
            mask = p_from != p_to
            p_mean = np.empty_like(p_to)
            p_mean[~mask] = p_from[~mask]
            p_mean[mask] = 2 / 3 * (p_from[mask] ** 3 - p_to[mask] ** 3) \
                           / (p_from[mask] ** 2 - p_to[mask] ** 2)
            normfactor_mean = numerator * fluid.get_property("compressibility", p_mean) \
                              / (p_mean * NORMAL_TEMPERATURE)
            v_gas_mean = v_mps * normfactor_mean

            idx_sort, v_gas_from_sum, v_gas_to_sum, v_gas_mean_sum, nf_from_sum, nf_to_sum, \
            internal_pipes = _sum_by_group(
                idx_active, v_gas_from, v_gas_to, v_gas_mean, normfactor_from, normfactor_to,
                np.ones_like(idx_active))

            res_table["v_from_m_per_s"].values[placement_table] = v_gas_from_sum / internal_pipes
            res_table["v_to_m_per_s"].values[placement_table] = v_gas_to_sum / internal_pipes
            res_table["v_mean_m_per_s"].values[placement_table] = v_gas_mean_sum / internal_pipes
            res_table["normfactor_from"].values[placement_table] = nf_from_sum / internal_pipes
            res_table["normfactor_to"].values[placement_table] = nf_to_sum / internal_pipes
        else:
            res_table["v_mean_m_per_s"].values[placement_table] = v_sum

        res_table["p_from_bar"].values[placement_table] = node_pit[from_junction_nodes, PINIT]
        res_table["p_to_bar"].values[placement_table] = node_pit[to_junction_nodes, PINIT]
        res_table["t_from_k"].values[placement_table] = node_pit[from_junction_nodes, TINIT_NODE]
        res_table["t_to_k"].values[placement_table] = node_pit[to_junction_nodes, TINIT_NODE]
        res_table["mdot_to_kg_per_s"].values[placement_table] = -mf_sum
        res_table["mdot_from_kg_per_s"].values[placement_table] = mf_sum
        res_table["vdot_norm_m3_per_s"].values[placement_table] = vf_sum
        idx_pit = heat_exchanger_pit[:, ELEMENT_IDX]
        idx_sort, lambda_sum, reynolds_sum, = \
            _sum_by_group(idx_pit, heat_exchanger_pit[:, LAMBDA], heat_exchanger_pit[:, RE])
        res_table["lambda"].values[placement_table] = lambda_sum
        res_table["reynolds"].values[placement_table] = reynolds_sum
Ejemplo n.º 22
0
    def extract_results(cls, net, options, node_name):
        placement_table, branch_pit, res_table = cls.prepare_result_tables(
            net, options, node_name)

        node_pit = net["_active_pit"]["node"]
        node_active_idx_lookup = get_lookup(net, "node",
                                            "index_active")[node_name]
        junction_idx_lookup = get_lookup(net, "node", "index")[node_name]
        from_junction_nodes = node_active_idx_lookup[junction_idx_lookup[net[
            cls.table_name()]["from_junction"].values[placement_table]]]
        to_junction_nodes = node_active_idx_lookup[junction_idx_lookup[net[
            cls.table_name()]["to_junction"].values[placement_table]]]

        from_nodes = branch_pit[:, FROM_NODE].astype(np.int32)
        to_nodes = branch_pit[:, TO_NODE].astype(np.int32)
        p_scale = get_net_option(net, "p_scale")
        fluid = get_fluid(net)

        v_mps = branch_pit[:, VINIT]

        t0 = node_pit[from_nodes, TINIT_NODE]
        t1 = node_pit[to_nodes, TINIT_NODE]
        mf = branch_pit[:, LOAD_VEC_NODES]
        vf = branch_pit[:, LOAD_VEC_NODES] / get_fluid(net).get_density(
            (t0 + t1) / 2)

        idx_active = branch_pit[:, ELEMENT_IDX]
        _, v_sum, mf_sum, vf_sum, internal_pipes = \
            _sum_by_group(idx_active, v_mps, mf, vf, np.ones_like(idx_active))

        if fluid.is_gas:
            # derived from the ideal gas law
            p_from = node_pit[from_nodes,
                              PAMB] + node_pit[from_nodes, PINIT] * p_scale
            p_to = node_pit[to_nodes,
                            PAMB] + node_pit[to_nodes, PINIT] * p_scale
            numerator = NORMAL_PRESSURE * branch_pit[:, TINIT]
            normfactor_from = numerator * fluid.get_property("compressibility", p_from) \
                              / (p_from * NORMAL_TEMPERATURE)
            normfactor_to = numerator * fluid.get_property("compressibility", p_to) \
                            / (p_to * NORMAL_TEMPERATURE)
            v_gas_from = v_mps * normfactor_from
            v_gas_to = v_mps * normfactor_to
            mask = ~np.isclose(p_from, p_to)
            p_mean = np.empty_like(p_to)
            p_mean[~mask] = p_from[~mask]
            p_mean[mask] = 2 / 3 * (p_from[mask] ** 3 - p_to[mask] ** 3) \
                           / (p_from[mask] ** 2 - p_to[mask] ** 2)
            normfactor_mean = numerator * fluid.get_property("compressibility", p_mean) \
                              / (p_mean * NORMAL_TEMPERATURE)
            v_gas_mean = v_mps * normfactor_mean

            _, _, _, v_gas_mean_sum, nf_from_sum, nf_to_sum, \
            internal_pipes = _sum_by_group(idx_active, v_gas_from, v_gas_to, v_gas_mean,
                                           normfactor_from, normfactor_to,
                                           np.ones_like(idx_active))

            v_gas_from_ordered = select_from_pit(from_nodes,
                                                 from_junction_nodes,
                                                 v_gas_from)
            v_gas_to_ordered = select_from_pit(to_nodes, to_junction_nodes,
                                               v_gas_to)

            res_table["v_from_m_per_s"].values[
                placement_table] = v_gas_from_ordered
            res_table["v_to_m_per_s"].values[
                placement_table] = v_gas_to_ordered
            res_table["v_mean_m_per_s"].values[
                placement_table] = v_gas_mean_sum / internal_pipes
            res_table["normfactor_from"].values[
                placement_table] = nf_from_sum / internal_pipes
            res_table["normfactor_to"].values[
                placement_table] = nf_to_sum / internal_pipes
        else:
            res_table["v_mean_m_per_s"].values[
                placement_table] = v_sum / internal_pipes

        res_table["p_from_bar"].values[placement_table] = node_pit[
            from_junction_nodes, PINIT]
        res_table["p_to_bar"].values[placement_table] = node_pit[
            to_junction_nodes, PINIT]
        res_table["t_from_k"].values[placement_table] = node_pit[
            from_junction_nodes, TINIT_NODE]
        res_table["t_to_k"].values[placement_table] = node_pit[
            to_junction_nodes, TINIT_NODE]
        res_table["mdot_to_kg_per_s"].values[
            placement_table] = -mf_sum / internal_pipes
        res_table["mdot_from_kg_per_s"].values[
            placement_table] = mf_sum / internal_pipes
        res_table["vdot_norm_m3_per_s"].values[
            placement_table] = vf_sum / internal_pipes
        idx_pit = branch_pit[:, ELEMENT_IDX]
        _, lambda_sum, reynolds_sum, = \
            _sum_by_group(idx_pit, branch_pit[:, LAMBDA], branch_pit[:, RE])
        res_table["lambda"].values[
            placement_table] = lambda_sum / internal_pipes
        res_table["reynolds"].values[
            placement_table] = reynolds_sum / internal_pipes
Ejemplo n.º 23
0
    def get_internal_results(cls, net, pipe):
        """

        :param net: The pandapipes network
        :type net: pandapipesNet
        :param pipe:
        :type pipe:
        :return: pipe_results
        :rtype:
        """
        internal_sections = cls.get_internal_pipe_number(net)
        internal_p_nodes = internal_sections - 1
        p_node_idx = np.repeat(pipe, internal_p_nodes[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["VINIT"] = np.zeros((len(v_pipe_idx), 2),
                                         dtype=np.float64)

        if np.all(internal_sections[pipe] >= 2):
            fluid = get_fluid(net)
            f, t = get_lookup(net, "branch", "from_to")[cls.table_name()]
            pipe_pit = net["_pit"]["branch"][f:t, :]
            node_pit = net["_pit"]["node"]
            int_p_lookup = net["_lookups"]["internal_nodes_lookup"]["TPINIT"]
            int_v_lookup = net["_lookups"]["internal_nodes_lookup"]["VINIT"]

            selected_indices_p = []
            selected_indices_v = []
            for i in pipe:
                selected_indices_p.append(
                    np.where(int_p_lookup[:, 0] == i, True, False))
                selected_indices_v.append(
                    np.where(int_v_lookup[:, 0] == i, True, False))

            selected_indices_p_final = np.logical_or.reduce(
                selected_indices_p[:])
            selected_indices_v_final = np.logical_or.reduce(
                selected_indices_v[:])
            # a = np.where(int_p_lookup[:,0] ==  True, False)
            # b = np.where(int_v_lookup[:, 0] == v_pipe_idx, True, False)
            p_nodes = int_p_lookup[:, 1][selected_indices_p_final]
            v_nodes = int_v_lookup[:, 1][selected_indices_v_final]

            v_pipe_data = pipe_pit[v_nodes, VINIT]
            p_node_data = node_pit[p_nodes, PINIT]
            t_node_data = node_pit[p_nodes, TINIT_NODE]

            gas_mode = fluid.is_gas

            if gas_mode:
                p_scale = get_net_option(net, "p_scale")

                from_nodes = pipe_pit[v_nodes, FROM_NODE].astype(np.int32)
                to_nodes = pipe_pit[v_nodes, TO_NODE].astype(np.int32)
                p_from = node_pit[from_nodes,
                                  PAMB] + node_pit[from_nodes, PINIT] * p_scale
                p_to = node_pit[to_nodes,
                                PAMB] + node_pit[to_nodes, PINIT] * p_scale
                p_mean = np.where(
                    p_from == p_to, p_from,
                    2 / 3 * (p_from**3 - p_to**3) / (p_from**2 - p_to**2))
                numerator = NORMAL_PRESSURE * node_pit[v_nodes, TINIT_NODE]
                normfactor = numerator * fluid.get_property("compressibility", p_mean) \
                             / (p_mean * NORMAL_TEMPERATURE)

                v_pipe_data = v_pipe_data * normfactor

            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["VINIT"][:, 0] = v_pipe_idx
            pipe_results["VINIT"][:, 1] = v_pipe_data
        else:
            logger.warning(
                "For at least one pipe no internal data is available.")

        return pipe_results