コード例 #1
0
def test_convert_format(version):
    filename = os.path.join(folder, "example_%s.json" % version)
    if not os.path.isfile(filename):
        raise ValueError("File for version %s does not exist" % version)
    try:
        net = pp.from_json(filename, convert=False)
    except:
        raise UserWarning(
            "Can not load network saved in pandapipes version %s" % version)
    p_bar_old = net.res_junction.p_bar.copy()
    v_mean_m_per_s_old = net.res_pipe.v_mean_m_per_s.copy()
    convert_format(net)
    try:
        pp.pipeflow(net,
                    run_control="controller" in net
                    and len(net.controller) > 0)
    except:
        raise UserWarning("Can not run pipe flow in network "
                          "saved with pandapipes version %s" % version)
    p_res = np.allclose(p_bar_old.values, net.res_junction.p_bar.values)
    v_res = np.allclose(v_mean_m_per_s_old.values,
                        net.res_pipe.v_mean_m_per_s.values)
    if not all([p_res, v_res]):
        raise UserWarning("Pipe flow results mismatch "
                          "with pandapipes version %s" % version)
コード例 #2
0
def test_random_net_and_one_node_net(create_test_net):
    """

    :param create_test_net:
    :type create_test_net:
    :return:
    :rtype:
    """

    net = copy.deepcopy(create_test_net)

    pp.create_fluid_from_lib(net, "water")

    j = create_junction(net, 1, 298.15)
    create_ext_grid(net, j, 1, 298.15)
    create_sink(net, j, 0.01)
    create_source(net, j, 0.02)
    pp.pipeflow(net)

    net = copy.deepcopy(create_test_net)

    pp.create_fluid_from_lib(net, "lgas")

    j = create_junction(net, 1, 298.15)
    create_ext_grid(net, j, 1, 298.15)
    create_sink(net, j, 0.01)
    create_source(net, j, 0.02)
    pp.pipeflow(net)

    assert np.isclose(
        net.res_ext_grid.values[-1] + net.res_sink.values[-1] -
        net.res_source.values[-1], 0)
コード例 #3
0
def test_connectivity_heat3(complex_heat_connectivity_grid):
    net = copy.deepcopy(complex_heat_connectivity_grid)
    net.pipe.at[5, "in_service"] = True
    net.valve.at[12, "opened"] = True
    net.junction.at[5, "in_service"] = False
    pandapipes.pipeflow(net, mode="all", check_connectivity=True)

    assert set(
        net.res_junction.loc[net.res_junction.p_bar.isnull()].index) == set()
    assert set(net.res_junction.loc[net.res_junction.p_bar.notnull()].index) \
           == set(net.junction.index)
    assert set(net.res_pipe.loc[net.res_pipe.v_mean_m_per_s.notnull()].index) \
           == set(net.pipe.loc[net.pipe.in_service].index)
    assert set(net.res_pipe.loc[net.res_pipe.v_mean_m_per_s.isnull()].index) \
           == set(net.pipe.loc[~net.pipe.in_service].index)
    assert set(net.res_valve.loc[
        net.res_valve.v_mean_m_per_s.isnull()].index) == set()
    assert set(net.res_valve.loc[net.res_valve.v_mean_m_per_s.notnull()].index) \
           == set(net.valve.index)
    assert set(
        net.res_sink.loc[net.res_sink.mdot_kg_per_s.isnull()].index) == set()
    assert set(
        net.res_sink.loc[net.res_sink.mdot_kg_per_s.notnull()].index) == set(
            net.sink.index)
    assert set(net.res_source.loc[
        net.res_source.mdot_kg_per_s.isnull()].index) == set()
    assert set(net.res_source.loc[net.res_source.mdot_kg_per_s.notnull()].index) == \
           set(net.source.index)

    assert np.allclose(net.res_ext_grid.mdot_kg_per_s.sum(),
                       -net.res_sink.mdot_kg_per_s.sum() +
                       net.res_source.mdot_kg_per_s.sum(),
                       rtol=1e-10,
                       atol=0)
コード例 #4
0
def test_one_node_net():
    """

    :return:
    :rtype:
    """

    net = create_empty_network(fluid='water')
    j = create_junction(net, 1, 298.15)
    create_ext_grid(net, j, 1, 298.15)
    create_sink(net, j, 0.01)
    create_source(net, j, 0.02)
    pp.pipeflow(net)

    assert np.isclose(
        net.res_ext_grid.values + net.res_sink.values - net.res_source.values,
        0)

    net = create_empty_network(fluid='lgas')
    j = create_junction(net, 1, 298.15)
    create_ext_grid(net, j, 1, 298.15)
    create_sink(net, j, 0.01)
    create_source(net, j, 0.02)
    pp.pipeflow(net)

    assert np.isclose(
        net.res_ext_grid.values + net.res_sink.values - net.res_source.values,
        0)
コード例 #5
0
def test_exclude_unconnected_junction():
    """
    test if unconnected junctions that do not have the highest index are excluded correctly
    (pipeflow fails if reduced_pit does not reindex the reduced nodes correctly)
    :return:
    :rtype:
    """
    net = pandapipes.create_empty_network(fluid="lgas")

    j1 = pandapipes.create_junction(net,
                                    pn_bar=1.05,
                                    tfluid_k=293.15,
                                    name="Junction 1")
    _ = pandapipes.create_junction(net,
                                   pn_bar=1.05,
                                   tfluid_k=293.15,
                                   name="unconnected junction")
    j3 = pandapipes.create_junction(net,
                                    pn_bar=1.05,
                                    tfluid_k=293.15,
                                    name="Junction 3")

    pandapipes.create_ext_grid(net, junction=j1, p_bar=1.1, t_k=293.15)
    pandapipes.create_sink(net, junction=j3, mdot_kg_per_s=0.045)
    pandapipes.create_pipe_from_parameters(net,
                                           from_junction=j1,
                                           to_junction=j3,
                                           length_km=0.1,
                                           diameter_m=0.05)
    pandapipes.pipeflow(net)
    assert net.converged
コード例 #6
0
def test_temperature_internal_nodes_tee_2ab_1zu():
    """

    :return:
    :rtype:
    """
    net = pandapipes.create_empty_network("net", add_stdtypes=False)
    d = 75e-3
    j0 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283)
    j1 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283)
    j2 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283)
    j3 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283)
    pandapipes.create_ext_grid(net, j0, p_bar=5, t_k=350, type="pt")
    pandapipes.create_sink(net, j2, mdot_kg_per_s=1)
    pandapipes.create_sink(net, j3, mdot_kg_per_s=1)

    pandapipes.create_pipe_from_parameters(net, j0, j1, 2.5, d, k_mm=.1, alpha_w_per_m2k=5)
    pandapipes.create_pipe_from_parameters(net, j1, j2, 2.5, d, k_mm=.1, alpha_w_per_m2k=5)
    pandapipes.create_pipe_from_parameters(net, j1, j3, 2.5, d, k_mm=.1, alpha_w_per_m2k=5)

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

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

    data = pd.read_csv(os.path.join(internals_data_path, "Temperature_tee_2ab_1zu_an.csv"),
                       sep=';', header=0, keep_default_na=False)
    temp_an = data["T"]

    temp_pandapipes = net.res_junction["t_k"]
    temp_diff = np.abs(1 - temp_pandapipes / temp_an)

    assert np.all(temp_diff < 0.01)
コード例 #7
0
def test_pump_from_regression_parameteres():
    """

        :return:
        :rtype:
        """
    net = pandapipes.create_empty_network("net", add_stdtypes=False)

    j1 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)
    j2 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)
    j3 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)
    j4 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)

    pandapipes.create_pipe_from_parameters(net,
                                           j1,
                                           j2,
                                           k_mm=1.,
                                           length_km=0.43380,
                                           diameter_m=0.1022)
    pandapipes.create_pipe_from_parameters(net,
                                           j3,
                                           j4,
                                           k_mm=1.,
                                           length_km=0.26370,
                                           diameter_m=0.1022)
    pandapipes.create_ext_grid(net, j1, 5, 283.15, type="p")
    pandapipes.create_pump_from_parameters(net,
                                           j2,
                                           j3,
                                           'P1',
                                           regression_parameters=[
                                               -1.48620799e-04,
                                               -1.29656785e-02, 6.10000000e+00
                                           ])
    pandapipes.create_sink(net, j4, 0.02333)

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

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

    data = pd.read_csv(os.path.join(internals_data_path, "test_pump.csv"),
                       sep=';')

    res_junction = net.res_junction.p_bar.values
    res_pipe = net.res_pipe.v_mean_m_per_s.values

    p_diff = np.abs(1 - res_junction / data['p'].dropna().values)
    v_diff = np.abs(1 - res_pipe / data['v'].dropna().values)

    assert np.all(p_diff < 0.01)
    assert np.all(v_diff < 0.01)
コード例 #8
0
def test_hydraulic_only():
    """

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

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

    pp.pipeflow(net,
                stop_condition="tol",
                iter=70,
                friction_model="nikuradse",
                transient=False,
                nonlinear_method="automatic",
                tol_p=1e-4,
                tol_v=1e-4)

    data = pd.read_csv(os.path.join(data_path, "hydraulics.csv"),
                       sep=';',
                       header=0,
                       keep_default_na=False)

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

    v_an = data.loc[0, "pv"]
    p_an = data.loc[1:3, "pv"]

    p_pandapipes = node_pit[:, PINIT]
    v_pandapipes = branch_pit[:, VINIT]

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

    assert np.all(p_diff < 0.01)
    assert (np.all(v_diff < 0.05))
コード例 #9
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)
コード例 #10
0
def test_set_user_pf_options(create_test_net):
    """

    :param create_test_net:
    :type create_test_net:
    :return:
    :rtype:
    """
    net = copy.deepcopy(create_test_net)
    pandapipes.create_fluid_from_lib(net, "lgas")

    necessary_options = {'mode': 'hydraulics'}
    pandapipes.pipeflow(net, **necessary_options)

    old_options = net._options.copy()
    test_options = {key: i for i, key in enumerate(old_options.keys())}

    pandapipes.pipeflow_setup.set_user_pf_options(net,
                                                  hello='bye',
                                                  **test_options)
    test_options.update({'hello': 'bye'})
    test_options.update({'hyd_flag': True})

    assert net.user_pf_options == test_options

    # remove what is in user_pf_options and add hello=world
    pandapipes.pipeflow_setup.set_user_pf_options(net,
                                                  reset=True,
                                                  hello='world')
    assert net.user_pf_options == {'hello': 'world'}

    # check if 'hello' is added to net._options, but other options are untouched
    pandapipes.pipeflow(net, **necessary_options)
    assert 'hello' in net._options.keys() and net._options['hello'] == 'world'
    net._options.pop('hello')
    assert net._options == old_options

    # check if user_pf_options can be deleted and net._options is as it was before
    pandapipes.pipeflow_setup.set_user_pf_options(net,
                                                  reset=True,
                                                  hello='world')
    pandapipes.pipeflow_setup.set_user_pf_options(net, reset=True)
    assert net.user_pf_options == {}
    pandapipes.pipeflow(net, **necessary_options)
    assert 'hello' not in net._options.keys()

    # see if user arguments overrule user_pf_options, but other user_pf_options still have the
    # priority
    pandapipes.pipeflow_setup.set_user_pf_options(net,
                                                  reset=True,
                                                  tol_p=1e-6,
                                                  tol_v=1e-6)
    pandapipes.pipeflow(net, tol_p=1e-8, **necessary_options)
    assert net.user_pf_options['tol_p'] == 1e-6
    assert net._options['tol_p'] == 1e-8
    assert net._options['tol_v'] == 1e-6
コード例 #11
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))
コード例 #12
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]))
コード例 #13
0
ファイル: test_pump.py プロジェクト: nsanina/pandapipes
def test_pump_bypass_high_vdot():
    """
    High flow: pressure lift not <0, always >=0
        :return:
        :rtype:
        """
    net = pandapipes.create_empty_network("net", add_stdtypes=True)

    j1 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)
    j2 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)
    j3 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)
    j4 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)

    pandapipes.create_pipe(net,
                           j1,
                           j2,
                           std_type='2000_ST<16',
                           k_mm=0.1,
                           length_km=0.1)
    pandapipes.create_pipe(net,
                           j3,
                           j4,
                           std_type='2000_ST<16',
                           k_mm=0.1,
                           length_km=0.1)
    pandapipes.create_ext_grid(net, j1, 5, 283.15, type="p")
    pandapipes.create_pump(net, j2, j3, std_type='P1')
    pandapipes.create_sink(net, j4, 1000)

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

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

    assert net.res_pump.deltap_bar.isin([0]).all()
    assert np.isclose(net.res_junction.loc[1, "p_bar"],
                      net.res_junction.loc[2, "p_bar"])
コード例 #14
0
ファイル: test_pump.py プロジェクト: nsanina/pandapipes
def test_pump_bypass_on_reverse_flow():
    """
    reverse flow = no pressure lift
        :return:
        :rtype:
        """
    net = pandapipes.create_empty_network("net", add_stdtypes=True)

    j1 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)
    j2 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)
    j3 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)
    j4 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)

    pandapipes.create_pipe(net,
                           j1,
                           j2,
                           std_type='125_PE_80_SDR_11',
                           k_mm=1.,
                           length_km=10)
    pandapipes.create_pipe(net,
                           j3,
                           j4,
                           std_type='125_PE_80_SDR_11',
                           k_mm=1.,
                           length_km=12)
    pandapipes.create_ext_grid(net, j1, 5, 283.15, type="p")
    pandapipes.create_pump(net, j2, j3, std_type='P1')
    pandapipes.create_source(net, j4, 0.02333)

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

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

    assert net.res_pump.deltap_bar.isin([0]).all()
    assert np.isclose(net.res_junction.loc[1, "p_bar"],
                      net.res_junction.loc[2, "p_bar"])
コード例 #15
0
def test_ext_grid_sorting():
    net = pandapipes.create_empty_network(fluid="hgas")
    j1 = pandapipes.create_junction(net, 1, 293.15, index=1)
    j2 = pandapipes.create_junction(net, 1, 293.15, index=2)
    j3 = pandapipes.create_junction(net, 1, 293.15, index=4)
    j4 = pandapipes.create_junction(net, 1, 293.15, index=5)
    j5 = pandapipes.create_junction(net, 1, 293.15, index=6)
    j6 = pandapipes.create_junction(net, 1, 293.15, index=7)

    pandapipes.create_ext_grid(net, j2, 1, 285.15, type="pt")
    pandapipes.create_ext_grid(net, j3, 1, 285.15, type="pt")
    pandapipes.create_ext_grid(net, j5, 1, 285.15, type="t")
    pandapipes.create_ext_grid(net, j1, 1, 285.15, type="pt")
    pandapipes.create_ext_grid(net, j1, 1, 285.15, type="pt")

    pandapipes.create_pipe_from_parameters(net, j1, j4, 0.1, 0.1)
    pandapipes.create_pipe_from_parameters(net, j2, j5, 0.1, 0.1)
    pandapipes.create_pipe_from_parameters(net, j3, j6, 0.1, 0.1)

    pandapipes.create_sink(net, j4, mdot_kg_per_s=0.1)
    pandapipes.create_sink(net, j5, mdot_kg_per_s=0.1)
    pandapipes.create_sink(net, j6, mdot_kg_per_s=0.1)
    pandapipes.create_sink(net, j2, mdot_kg_per_s=0.02)

    pandapipes.pipeflow(net)

    assert np.isclose(net.res_ext_grid.at[0, "mdot_kg_per_s"],
                      -0.12,
                      atol=1e-12,
                      rtol=1e-12)
    assert np.isclose(net.res_ext_grid.at[1, "mdot_kg_per_s"],
                      -0.1,
                      atol=1e-12,
                      rtol=1e-12)
    assert np.isnan(net.res_ext_grid.at[2, "mdot_kg_per_s"])
    assert np.isclose(net.res_ext_grid.at[3, "mdot_kg_per_s"],
                      -0.05,
                      atol=1e-12,
                      rtol=1e-12)
    assert np.isclose(net.res_ext_grid.at[4, "mdot_kg_per_s"],
                      -0.05,
                      atol=1e-12,
                      rtol=1e-12)
コード例 #16
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)
コード例 #17
0
ファイル: test_ext_grid.py プロジェクト: slolow/pandapipes
def test_p_type():
    """

    :return:
    :rtype:
    """
    net = pandapipes.create_empty_network("net")
    d = 75e-3
    pandapipes.create_junction(net, pn_bar=5, tfluid_k=293.15)
    pandapipes.create_junction(net, pn_bar=5, tfluid_k=293.15)
    pandapipes.create_pipe_from_parameters(net,
                                           0,
                                           1,
                                           10,
                                           diameter_m=d,
                                           k_mm=0.1,
                                           sections=1)
    pandapipes.create_ext_grid(net, 0, p_bar=5, t_k=285.15, type="p")
    pandapipes.create_sink(net, 1, mdot_kg_per_s=1)
    pandapipes.create_fluid_from_lib(net, name="water")
    pandapipes.pipeflow(net,
                        stop_condition="tol",
                        iter=70,
                        friction_model="nikuradse",
                        transient=False,
                        nonlinear_method="automatic",
                        tol_p=1e-4,
                        tol_v=1e-4)

    data = pd.read_csv(os.path.join(internals_data_path, "ext_grid_p.csv"),
                       sep=';',
                       header=0,
                       keep_default_na=False)
    p_comp = data["p"]
    p_pandapipes = net.res_junction["p_bar"][0]

    p_diff = np.abs(1 - p_pandapipes / p_comp.loc[0])

    assert np.all(p_diff < 0.01)
コード例 #18
0
def test_heat_exchanger():
    """

        :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_heat_exchanger(net, 0, 1, d, qext_w=20000)
    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)

    data = pd.read_csv(os.path.join(internals_data_path,
                                    "heat_exchanger_test.csv"),
                       sep=';',
                       header=0,
                       keep_default_na=False)
    temp_an = data["T1"]

    t_pan = net.res_junction.t_k

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

    assert np.all(temp_diff < 0.01)
コード例 #19
0
def test_inservice_water(create_test_net):
    """

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

    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_pipe.loc[~net.pipe.in_service, :].values))
    assert np.all(np.isnan(net.res_valve.loc[~net.valve.opened, :].values))
    assert np.all(
        np.isnan(net.res_junction.loc[~net.junction.in_service, :].values))

    oos_sinks = np.isin(net.sink.junction.values, net.junction.index[~net.junction.in_service]) \
                | ~net.sink.in_service.values
    assert np.all(np.isnan(net.res_sink.loc[oos_sinks, :].values))

    assert not any(
        np.isnan(net.res_pipe.v_mean_m_per_s.loc[net.pipe.in_service].values))
    assert not any(
        np.isnan(net.res_valve.v_mean_m_per_s.loc[net.valve.opened].values))
    assert not any(
        np.isnan(net.res_junction.p_bar.loc[net.junction.in_service].values))
    assert not np.any(np.isnan(net.res_sink.loc[~oos_sinks, :].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)
コード例 #20
0
def test_connectivity_heat1(complex_heat_connectivity_grid):
    net = copy.deepcopy(complex_heat_connectivity_grid)
    pandapipes.pipeflow(net, mode="all", check_connectivity=True)

    assert set(
        net.res_junction.loc[net.res_junction.p_bar.notnull()].index) == {
            8, 9, 10
        }
    assert set(net.res_junction.loc[net.res_junction.p_bar.isnull()].index) \
           == set(net.junction.index) - {8, 9, 10}
    assert set(
        net.res_pipe.loc[net.res_pipe.v_mean_m_per_s.notnull()].index) == {
            1, 2
        }
    assert set(net.res_pipe.loc[net.res_pipe.v_mean_m_per_s.isnull()].index) \
           == set(net.pipe.index) - {1, 2}
    assert set(net.res_valve.loc[
        net.res_valve.v_mean_m_per_s.notnull()].index) == set()
    assert set(net.res_valve.loc[net.res_valve.v_mean_m_per_s.isnull()].index) \
           == set(net.valve.index)
    assert set(
        net.res_sink.loc[net.res_sink.mdot_kg_per_s.isnull()].index) == {
            3, 4, 5
        }
    assert set(net.res_sink.loc[net.res_sink.mdot_kg_per_s.notnull()].index) == \
           set(net.sink.index) - {3, 4, 5}
    assert set(net.res_source.loc[net.res_source.mdot_kg_per_s.isnull()].index) == \
           set(net.source.index)
    assert set(net.res_source.loc[
        net.res_source.mdot_kg_per_s.notnull()].index) == set()

    assert np.allclose(net.res_ext_grid.mdot_kg_per_s.sum(),
                       -net.res_sink.mdot_kg_per_s.sum() +
                       net.res_source.mdot_kg_per_s.sum(),
                       rtol=1e-10,
                       atol=0)
コード例 #21
0
def test_schutterwald():
    net = networks.schutterwald(True, None)
    pp.pipeflow(net)
    assert net.converged

    net2 = networks.schutterwald(False, None)
    assert net2.sink.empty
    assert len(net2.pipe.loc[net2.pipe.type == "house_connection"]) == 0
    pp.pipeflow(net2)
    assert net2.converged

    net3 = networks.schutterwald(True, 30)
    assert len(net3.sink) == 1506
    assert net3.pipe.loc[net3.pipe.in_service & (net3.pipe.type == "house_connection"),
                         "length_km"].max() <= 0.03
    pp.pipeflow(net3)
    assert net3.converged
コード例 #22
0
def test_heat_only():
    net = pp.create_empty_network("net")
    d = 75e-3
    pp.create_junction(net, pn_bar=5, tfluid_k=283)
    pp.create_junction(net, pn_bar=5, tfluid_k=283)
    pp.create_pipe_from_parameters(net, 0, 1, 6, diameter_m=d, k_mm=.1, sections=6,
                                   alpha_w_per_m2k=5)
    pp.create_ext_grid(net, 0, p_bar=5, t_k=330, type="pt")
    pp.create_sink(net, 1, mdot_kg_per_s=1)

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

    pp.pipeflow(net, stop_condition="tol", iter=70, friction_model="nikuradse",
                 nonlinear_method="automatic", mode="all")

    ntw = pp.create_empty_network("net")
    d = 75e-3
    pp.create_junction(ntw, pn_bar=5, tfluid_k=283)
    pp.create_junction(ntw, pn_bar=5, tfluid_k=283)
    pp.create_pipe_from_parameters(ntw, 0, 1, 6, diameter_m=d, k_mm=.1, sections=6,
                                   alpha_w_per_m2k=5)
    pp.create_ext_grid(ntw, 0, p_bar=5, t_k=330, type="pt")
    pp.create_sink(ntw, 1, mdot_kg_per_s=1)

    pp.create_fluid_from_lib(ntw, "water", overwrite=True)


    pp.pipeflow(ntw, stop_condition="tol", iter=50, friction_model="nikuradse",
                nonlinear_method="automatic", mode="hydraulics")

    p = ntw._pit["node"][:, 5]
    v = ntw._pit["branch"][:, 12]
    u = np.concatenate((p, v))


    pp.pipeflow(ntw, sol_vec = u, stop_condition="tol", iter=50, friction_model="nikuradse",
                 nonlinear_method="automatic", mode = "heat")

    T_net = net.res_junction.t_k
    T_ntw = ntw.res_junction.t_k

    T_diff = np.abs(1 - T_net / T_ntw)

    assert np.all(T_diff < 0.01)
コード例 #23
0
ファイル: test_ext_grid.py プロジェクト: slolow/pandapipes
def test_t_type_single_pipe():
    """

    :return:
    :rtype:
    """
    net = pandapipes.create_empty_network("net")
    d = 75e-3

    j0 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283)
    j1 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283)
    pandapipes.create_ext_grid(net, j0, 5, 645, type="pt")
    pandapipes.create_sink(net, j1, 1)
    pandapipes.create_pipe_from_parameters(net,
                                           j0,
                                           j1,
                                           6,
                                           diameter_m=d,
                                           k_mm=.1,
                                           sections=1,
                                           alpha_w_per_m2k=5)

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

    temp = net.res_junction.t_k.values

    net2 = pandapipes.create_empty_network("net")
    d = 75e-3

    j0 = pandapipes.create_junction(net2, pn_bar=5, tfluid_k=283)
    j1 = pandapipes.create_junction(net2, pn_bar=5, tfluid_k=283)
    pandapipes.create_ext_grid(net2, j0, 5, 645, type="p")
    pandapipes.create_ext_grid(net2, j1, 100, 323.15, type="t")
    pandapipes.create_sink(net2, j1, 1)

    pandapipes.create_pipe_from_parameters(net2,
                                           j0,
                                           j1,
                                           6,
                                           diameter_m=d,
                                           k_mm=.1,
                                           sections=1,
                                           alpha_w_per_m2k=5)
    pandapipes.create_fluid_from_lib(net2, "water", overwrite=True)
    pandapipes.pipeflow(net2,
                        stop_condition="tol",
                        iter=70,
                        friction_model="nikuradse",
                        transient=False,
                        nonlinear_method="automatic",
                        tol_p=1e-4,
                        tol_v=1e-4,
                        mode="all")

    temp2 = net2.res_junction.t_k.values

    temp_diff = np.abs(1 - temp / temp2)

    assert np.all(temp_diff < 0.01)
コード例 #24
0
def test_valve():
    """

        :return:
        :rtype:
        """
    net = pandapipes.create_empty_network("net", add_stdtypes=True)

    j0 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15, index=5)
    j1 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15, index=3)
    j2 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15, index=6)
    j3 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15, index=9)
    j4 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15, index=20)
    j5 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15, index=45)
    j6 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15, index=4)
    j7 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15, index=8)

    pandapipes.create_ext_grid(net, j0, 5, 283.15, type="p")

    pandapipes.create_pipe_from_parameters(net,
                                           j0,
                                           j1,
                                           diameter_m=.1,
                                           k=0.1,
                                           length_km=1.)
    pandapipes.create_pipe_from_parameters(net,
                                           j3,
                                           j4,
                                           diameter_m=.1,
                                           k=0.1,
                                           length_km=.5)
    pandapipes.create_pipe_from_parameters(net,
                                           j2,
                                           j4,
                                           diameter_m=.1,
                                           k=0.1,
                                           length_km=.5)
    pandapipes.create_pipe_from_parameters(net,
                                           j5,
                                           j4,
                                           diameter_m=.1,
                                           k=0.1,
                                           length_km=.35)
    pandapipes.create_pipe_from_parameters(net,
                                           j1,
                                           j6,
                                           diameter_m=.1,
                                           k=0.1,
                                           length_km=.1,
                                           loss_coefficient=9000)
    pandapipes.create_pipe_from_parameters(net,
                                           j1,
                                           j7,
                                           diameter_m=.1,
                                           k=0.1,
                                           length_km=.1,
                                           loss_coefficient=9000)

    pandapipes.create_valve(net, j6, j2, diameter_m=0.1, opened=False)
    pandapipes.create_valve(net, j7, j3, diameter_m=0.1, opened=True)

    pandapipes.create_sink(net, j5, 0.11667)

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

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

    data = pd.read_csv(os.path.join(internals_data_path, "test_valve.csv"),
                       sep=';')
    data_p = data['p'].dropna(inplace=False)
    data_v = data['v'].dropna(inplace=False)

    res_junction = net.res_junction.p_bar.values
    res_pipe = net.res_pipe.v_mean_m_per_s.values
    zeros = res_pipe == 0
    test_zeros = data_v.values == 0
    check_zeros = zeros == test_zeros

    assert np.all(check_zeros)

    p_diff = np.abs(1 - res_junction / data_p[data_p != 0].values)
    v_diff = np.abs(1 - res_pipe[res_pipe != 0] / data_v[data_v != 0].values)

    assert np.all(p_diff < 0.01)
    assert np.all(v_diff < 0.01)
コード例 #25
0
def pipeflow_openmodelica_comparison(net,
                                     log_results=True,
                                     friction_model='colebrook',
                                     only_update_hydraulic_matrix=False):

    pp.pipeflow(net,
                stop_condition="tol",
                iter=100,
                tol_p=1e-7,
                tol_v=1e-7,
                friction_model=friction_model,
                only_update_hydraulic_matrix=only_update_hydraulic_matrix)

    p_om = net.junction.p_om
    p_valid = pd.notnull(p_om)
    p_om = p_om.loc[p_valid]

    if get_fluid(net).is_gas:
        if 'pipe' in net:
            v_diff_from_pipe, v_diff_to_pipe, v_diff_mean_pipe, v_diff_abs_pipe, \
            v_mean_pandapipes_pipe, v_om_pipe = retrieve_velocity_gas(net, 'pipe')
        else:
            v_diff_abs_pipe = pd.Series()
            v_om_pipe = pd.Series()
            v_mean_pandapipes_pipe = pd.Series()
            v_diff_from_pipe = pd.Series()
            v_diff_to_pipe = pd.Series()
            v_diff_mean_pipe = pd.Series()

        diff_results_v_pipe = pd.DataFrame({
            "diff_v_from_pipe": v_diff_from_pipe,
            "diff_v_to_pipe": v_diff_to_pipe,
            "diff_v_mean_pipe": v_diff_mean_pipe,
            "diff_v_abs_pipe": v_diff_abs_pipe
        })

        if 'valve' in net:
            v_diff_from_valve, v_diff_to_valve, v_diff_mean_valve, v_diff_abs_valve, \
            v_mean_pandapipes_valve, v_om_valve = retrieve_velocity_gas(net, 'valve')
        else:
            v_diff_abs_valve = pd.Series()
            v_om_valve = pd.Series()
            v_mean_pandapipes_valve = pd.Series()
            v_diff_from_valve = pd.Series()
            v_diff_to_valve = pd.Series()
            v_diff_mean_valve = pd.Series()

        diff_results_v_valve = pd.DataFrame({
            "diff_v_from_valve":
            v_diff_from_valve,
            "diff_v_to_valve":
            v_diff_to_valve,
            "diff_v_mean_valve":
            v_diff_mean_valve,
            "diff_v_abs_valve":
            v_diff_abs_valve
        })
    else:
        if 'pipe' in net:
            v_diff_mean_pipe, v_diff_abs_pipe, v_mean_pandapipes_pipe, v_om_pipe = \
                retrieve_velocity_liquid(net, element = "pipe")
        else:
            v_diff_abs_pipe = pd.Series()
            v_om_pipe = pd.Series()
            v_mean_pandapipes_pipe = pd.Series()
            v_diff_mean_pipe = pd.Series()

        if 'valve' in net:
            v_diff_mean_valve, v_diff_abs_valve, v_mean_pandapipes_valve, v_om_pipe = \
                retrieve_velocity_liquid(net, element = "valve")
        else:
            v_diff_abs_valve = pd.Series()
            v_om_valve = pd.Series()
            v_mean_pandapipes_valve = pd.Series()
            v_diff_mean_valve = pd.Series()

        diff_results_v_pipe = pd.DataFrame({
            "diff_v_mean_pipe": v_diff_mean_pipe,
            "diff_v_abs_pipe": v_diff_abs_pipe
        })
        diff_results_v_valve = pd.DataFrame({
            "diff_v_mean_valve":
            v_diff_mean_valve,
            "diff_v_abs_valve":
            v_diff_abs_valve
        })

    v_diff_abs = v_diff_abs_pipe.append(v_diff_abs_valve, ignore_index=True)
    v_diff_abs.dropna(inplace=True)

    p_pandapipes = net.res_junction.p_bar.loc[p_valid].values.astype(
        np.float64).round(4)
    p_diff = np.abs(1 - p_pandapipes / p_om)

    p_diff = pd.Series(p_diff, range(len(p_diff)))
    v_diff_abs = pd.Series(v_diff_abs, range(len(v_diff_abs)))
    '''
    print("\n p_diff = \n", p_diff)
    print("\n v_diff_abs = \n", v_diff_abs)

    print("\n p_diff < 0.01 = \n", p_diff < 0.01)
    print("\n v_diff_abs < 0.05 = \n", v_diff_abs < 0.05)
    '''

    if log_results:
        logger.info("p_OM %s" % p_om)
        logger.info("p_PP %s" % p_pandapipes)
        logger.info("v_OM_pipe %s" % v_om_pipe)
        logger.info("v_PP_valve %s" % v_om_valve)
        logger.info("v_PP_pipe %s" % v_mean_pandapipes_pipe)
        logger.info("v_PP_valve %s" % v_mean_pandapipes_valve)

        logger.info("Druckdifferenz: %s" % p_diff)
        logger.info("Geschwindigkeitsdifferenz Rohr: \n %s" %
                    diff_results_v_pipe)
        logger.info("Geschwindigkeitsdifferenz Ventil: \n %s" %
                    diff_results_v_valve)

    return p_diff, v_diff_abs
コード例 #26
0
def pipeflow_openmodelica_comparison(net,
                                     log_results=True,
                                     friction_model='colebrook',
                                     mode='hydraulics',
                                     only_update_hydraulic_matrix=False):
    """
        Comparison of the calculations of OpenModelica and pandapipes.

        :param net: converted OpenModelica network
        :type net: pandapipesNet
        :param log_results:
        :type log_results: bool, True
        :param friction_model:
        :type friction_model: str, "colebrook"
        :param mode:
        :type mode: str, "nomral"
        :param only_update_hydraulic_matrix:
        :type only_update_hydraulic_matrix: bool, False
        :return: p_diff, v_diff_abs
        :rtype: one-dimensional ndarray with axis labels
    """
    pp.pipeflow(net,
                stop_condition="tol",
                iter=100,
                tol_p=1e-7,
                tol_v=1e-7,
                friction_model=friction_model,
                mode=mode,
                only_update_hydraulic_matrix=only_update_hydraulic_matrix)

    print(net.res_junction)
    print(net.res_pipe)

    p_om = net.junction.p_om
    p_valid = pd.notnull(p_om)
    p_om = p_om.loc[p_valid]

    if get_fluid(net).is_gas:
        if 'pipe' in net:
            v_diff_from_pipe, v_diff_to_pipe, v_diff_mean_pipe, v_diff_abs_pipe, \
            v_mean_pandapipes_pipe, v_om_pipe = retrieve_velocity_gas(net, 'pipe')
        else:
            v_diff_abs_pipe = pd.Series()
            v_om_pipe = pd.Series()
            v_mean_pandapipes_pipe = pd.Series()
            v_diff_from_pipe = pd.Series()
            v_diff_to_pipe = pd.Series()
            v_diff_mean_pipe = pd.Series()

        diff_results_v_pipe = pd.DataFrame({
            "diff_v_from_pipe": v_diff_from_pipe,
            "diff_v_to_pipe": v_diff_to_pipe,
            "diff_v_mean_pipe": v_diff_mean_pipe,
            "diff_v_abs_pipe": v_diff_abs_pipe
        })

        if 'valve' in net:
            v_diff_from_valve, v_diff_to_valve, v_diff_mean_valve, v_diff_abs_valve, \
            v_mean_pandapipes_valve, v_om_valve = retrieve_velocity_gas(net, 'valve')
        else:
            v_diff_abs_valve = pd.Series()
            v_om_valve = pd.Series()
            v_mean_pandapipes_valve = pd.Series()
            v_diff_from_valve = pd.Series()
            v_diff_to_valve = pd.Series()
            v_diff_mean_valve = pd.Series()

        diff_results_v_valve = pd.DataFrame({
            "diff_v_from_valve":
            v_diff_from_valve,
            "diff_v_to_valve":
            v_diff_to_valve,
            "diff_v_mean_valve":
            v_diff_mean_valve,
            "diff_v_abs_valve":
            v_diff_abs_valve
        })
    else:
        if 'pipe' in net:
            v_diff_mean_pipe, v_diff_abs_pipe, v_mean_pandapipes_pipe, v_om_pipe = \
                retrieve_velocity_liquid(net, element="pipe")

            if mode != "hydraulics":
                T_diff_mean_pipe, T_diff_abs_pipe, T_mean_pandapipes_pipe, T_om_pipe = \
                    retrieve_temperature_liquid(net)
        else:
            v_diff_abs_pipe = pd.Series()
            v_om_pipe = pd.Series()
            v_mean_pandapipes_pipe = pd.Series()
            v_diff_mean_pipe = pd.Series()

            if mode != "hydraulics":
                T_diff_abs_pipe = pd.Series()
                T_om_pipe = pd.Series()
                T_mean_pandapipes_pipe = pd.Series()
                T_diff_mean_pipe = pd.Series()

        if 'valve' in net:
            v_diff_mean_valve, v_diff_abs_valve, v_mean_pandapipes_valve, v_om_valve = \
                retrieve_velocity_liquid(net, element="valve")
        else:
            v_diff_abs_valve = pd.Series()
            v_om_valve = pd.Series()
            v_mean_pandapipes_valve = pd.Series()
            v_diff_mean_valve = pd.Series()

        diff_results_v_pipe = pd.DataFrame({
            "diff_v_mean_pipe": v_diff_mean_pipe,
            "diff_v_abs_pipe": v_diff_abs_pipe
        })
        diff_results_v_valve = pd.DataFrame({
            "diff_v_mean_valve":
            v_diff_mean_valve,
            "diff_v_abs_valve":
            v_diff_abs_valve
        })

    v_diff_abs = v_diff_abs_pipe.append(v_diff_abs_valve, ignore_index=True)
    v_diff_abs.dropna(inplace=True)

    p_pandapipes = net.res_junction.p_bar.loc[p_valid].values.astype(
        np.float64).round(4)
    p_diff = np.abs(1 - p_pandapipes / p_om)

    p_diff = pd.Series(p_diff, range(len(p_diff)))
    v_diff_abs = pd.Series(v_diff_abs, range(len(v_diff_abs)))
    '''
    print("\n p_diff = \n", p_diff)
    print("\n v_diff_abs = \n", v_diff_abs)

    print("\n p_diff < 0.01 = \n", p_diff < 0.01)
    print("\n v_diff_abs < 0.05 = \n", v_diff_abs < 0.05)
    '''

    if log_results:
        logger.info("p_om %s" % p_om)
        logger.info("p_PP %s" % p_pandapipes)
        logger.info("v_om_pipe %s" % v_om_pipe)
        logger.info("v_PP_valve %s" % v_om_valve)
        logger.info("v_PP_pipe %s" % v_mean_pandapipes_pipe)
        logger.info("v_PP_valve %s" % v_mean_pandapipes_valve)

        logger.info("pressure difference: %s" % p_diff)
        logger.info("velocity difference pipe: \n %s" % diff_results_v_pipe)
        logger.info("velocity difference valve: \n %s" % diff_results_v_valve)

    if mode == "hydraulics":
        return p_diff, v_diff_abs
    else:
        return p_diff, v_diff_abs, T_diff_mean_pipe
コード例 #27
0
net = pp.create_empty_network(fluid="lgas")

# create junction
j1 = pp.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 1")
j2 = pp.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 2")
j3 = pp.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 3")

# create junction elements
ext_grid = pp.create_ext_grid(net,
                              junction=j1,
                              p_bar=1.1,
                              t_k=293.15,
                              name="Grid Connection")
sink = pp.create_sink(net, junction=j3, mdot_kg_per_s=0.045, name="Sink")

# create branch elements
pipe = pp.create_pipe_from_parameters(net,
                                      from_junction=j1,
                                      to_junction=j2,
                                      length_km=0.1,
                                      diameter_m=0.05,
                                      name="Pipe")
valve = pp.create_valve(net,
                        from_junction=j2,
                        to_junction=j3,
                        diameter_m=0.05,
                        opened=True,
                        name="Valve")

pp.pipeflow(net)
コード例 #28
0
def pipeflow_stanet_comparison(net,
                               log_results=True,
                               friction_model='nikuradse',
                               only_update_hydraulic_matrix=False,
                               **kwargs):
    """

    :param net:
    :type net:
    :param log_results:
    :type log_results:
    :param plot_net:
    :type plot_net:
    :param friction_model:
    :type friction_model:
    :param only_update_hydraulic_matrix:
    :type only_update_hydraulic_matrix:
    :return:
    :rtype:
    """
    pandapipes.pipeflow(
        net,
        mode='hydraulics',
        stop_condition="tol",
        iter=100,
        tol_p=1e-7,
        tol_v=1e-7,
        friction_model=friction_model,
        only_update_hydraulic_matrix=only_update_hydraulic_matrix,
        **kwargs)

    p_stanet = net.junction.p_stanet
    p_valid = pd.notnull(p_stanet)
    p_stanet = p_stanet.loc[p_valid]

    if get_fluid(net).is_gas:
        if 'pipe' in net:
            v_diff_from_pipe, v_diff_to_pipe, v_diff_mean_pipe, v_diff_abs_pipe, \
            v_mean_pandapipes_pipe, v_stanet_pipe = retrieve_velocity_gas(net, 'pipe')
        else:
            v_diff_abs_pipe = pd.Series(dtype="float64")
            v_stanet_pipe = pd.Series(dtype="float64")
            v_mean_pandapipes_pipe = pd.Series(dtype="float64")
            v_diff_from_pipe = pd.Series(dtype="float64")
            v_diff_to_pipe = pd.Series(dtype="float64")
            v_diff_mean_pipe = pd.Series(dtype="float64")

        diff_results_v_pipe = pd.DataFrame({
            "diff_v_from_pipe": v_diff_from_pipe,
            "diff_v_to_pipe": v_diff_to_pipe,
            "diff_v_mean_pipe": v_diff_mean_pipe,
            "diff_v_abs_pipe": v_diff_abs_pipe
        })

        if 'valve' in net:
            v_diff_from_valve, v_diff_to_valve, v_diff_mean_valve, v_diff_abs_valve, \
            v_mean_pandapipes_valve, v_stanet_valve = retrieve_velocity_gas(net, 'valve')
        else:
            v_diff_abs_valve = pd.Series(dtype="float64")
            v_stanet_valve = pd.Series(dtype="float64")
            v_mean_pandapipes_valve = pd.Series(dtype="float64")
            v_diff_from_valve = pd.Series(dtype="float64")
            v_diff_to_valve = pd.Series(dtype="float64")
            v_diff_mean_valve = pd.Series(dtype="float64")

        diff_results_v_valve = pd.DataFrame({
            "diff_v_from_valve":
            v_diff_from_valve,
            "diff_v_to_valve":
            v_diff_to_valve,
            "diff_v_mean_valve":
            v_diff_mean_valve,
            "diff_v_abs_valve":
            v_diff_abs_valve
        })

    else:
        if 'pipe' in net:
            v_diff_mean_pipe, v_diff_abs_pipe, v_mean_pandapipes_pipe, v_stanet_pipe = \
                retrieve_velocity_liquid(net, 'pipe')
        else:
            v_diff_abs_pipe = pd.Series(dtype="float64")
            v_stanet_pipe = pd.Series(dtype="float64")
            v_mean_pandapipes_pipe = pd.Series(dtype="float64")
            v_diff_mean_pipe = pd.Series(dtype="float64")

        if 'valve' in net:
            v_diff_mean_valve, v_diff_abs_valve, v_mean_pandapipes_valve, v_stanet_valve = \
                retrieve_velocity_liquid(net, 'valve')
        else:
            v_diff_abs_valve = pd.Series(dtype="float64")
            v_stanet_valve = pd.Series(dtype="float64")
            v_mean_pandapipes_valve = pd.Series(dtype="float64")
            v_diff_mean_valve = pd.Series(dtype="float64")

        diff_results_v_pipe = pd.DataFrame({
            "diff_v_mean_pipe": v_diff_mean_pipe,
            "diff_v_abs_pipe": v_diff_abs_pipe
        })
        diff_results_v_valve = pd.DataFrame({
            "diff_v_mean_valve":
            v_diff_mean_valve,
            "diff_v_abs_valve":
            v_diff_abs_valve
        })

    p_pandapipes = net.res_junction.p_bar.loc[p_valid].values
    p_diff = np.abs(1 - p_pandapipes / p_stanet)
    v_diff_abs = v_diff_abs_pipe.append(v_diff_abs_valve, ignore_index=True)
    v_diff_abs.dropna(inplace=True)

    # Avoiding division by zero

    if log_results:
        logger.info("p_sta %s" % p_stanet)
        logger.info("p_PP %s" % p_pandapipes)
        logger.info("v_sta_pipe %s" % v_stanet_pipe)
        logger.info("v_sta_valve %s" % v_stanet_valve)
        logger.info("v_PP_pipe %s" % v_mean_pandapipes_pipe)
        logger.info("v_PP_valve %s" % v_mean_pandapipes_valve)

        logger.info("Druckdifferenz: %s" % p_diff)
        logger.info("Geschwindigkeitsdifferenz Rohr: \n %s" %
                    diff_results_v_pipe)
        logger.info("Geschwindigkeitsdifferenz Ventil: \n %s" %
                    diff_results_v_valve)

    return p_diff, v_diff_abs
コード例 #29
0
def release_control_test_network():
    # empty net
    net = pp.create_empty_network("net", add_stdtypes=False)

    # fluid
    pp.create_fluid_from_lib(net, "water", overwrite=True)

    # junctions
    pp.create_junction(net, pn_bar=3, tfluid_k=293, height_m=0, name="Junction 0", index=None, in_service=True,
                       type="junction", geodata=None)
    pp.create_junction(net, pn_bar=3, tfluid_k=293, height_m=0, name="Junction 1")
    pp.create_junction(net, pn_bar=3, tfluid_k=293, height_m=0, name="Junction 2")
    pp.create_junction(net, pn_bar=3, tfluid_k=293, height_m=0, name="Junction 3")
    pp.create_junction(net, pn_bar=3, tfluid_k=293, height_m=0, name="Junction 4")
    pp.create_junction(net, pn_bar=3, tfluid_k=293, height_m=0, name="Junction 5")
    pp.create_junction(net, pn_bar=3, tfluid_k=293, height_m=0, name="Junction 6")
    pp.create_junction(net, pn_bar=3, tfluid_k=293, height_m=0, name="Junction 7")
    pp.create_junction(net, pn_bar=3, tfluid_k=293, height_m=0, name="Junction 8")
    pp.create_junction(net, pn_bar=3, tfluid_k=293, height_m=0, name="Junction 9")
    pp.create_junction(net, pn_bar=3, tfluid_k=293, height_m=0, name="Junction 10")
    pp.create_junction(net, pn_bar=3, tfluid_k=293, height_m=0, name="Junction 11")
    pp.create_junction(net, pn_bar=3, tfluid_k=293, height_m=0, name="Junction 12")

    # pipes
    pp.create_pipe_from_parameters(net, from_junction=0, to_junction=8, length_km=3, diameter_m=0.01, k_mm=1,
                                   loss_coefficient=0, sections=10, alpha_w_per_m2k=10, text_k=293,
                                   qext_w=0., name="Pipe 0", index=None, geodata=None, in_service=True, type="pipe")
    pp.create_pipe_from_parameters(net, 9, 2, length_km=6, diameter_m=0.075, k_mm=.1, sections=10,
                                   alpha_w_per_m2k=3,
                                   name="Pipe 1")
    pp.create_pipe_from_parameters(net, 2, 12, length_km=5, diameter_m=0.06, k_mm=.1, sections=10,
                                   alpha_w_per_m2k=20,
                                   name="Pipe 2")
    pp.create_pipe_from_parameters(net, 4, 12, length_km=0.1, diameter_m=0.07, k_mm=.1, sections=10,
                                   alpha_w_per_m2k=2,
                                   name="Pipe 3")
    pp.create_pipe_from_parameters(net, 5, 3, length_km=1, diameter_m=0.09, k_mm=.1, sections=10, alpha_w_per_m2k=3,
                                   name="Pipe 4")
    pp.create_pipe_from_parameters(net, 4, 11, length_km=2.5, diameter_m=0.08, k_mm=.1, sections=10,
                                   alpha_w_per_m2k=15,
                                   name="Pipe 5")
    pp.create_pipe_from_parameters(net, 7, 6, length_km=4.5, diameter_m=0.085, k_mm=.1, sections=10,
                                   alpha_w_per_m2k=2.5, name="Pipe 6")
    pp.create_pipe_from_parameters(net, 1, 7, length_km=4, diameter_m=0.03, k_mm=.1, sections=10, alpha_w_per_m2k=1,
                                   name="Pipe 7")

    # external grids
    pp.create_ext_grid(net, junction=0, p_bar=3, t_k=300, name="External Grid 0", in_service=True, index=None,
                       type="pt")
    pp.create_ext_grid(net, 1, p_bar=5, t_k=350, name="External Grid 1", type="pt")

    # sinks
    pp.create_sink(net, junction=2, mdot_kg_per_s=0.2, scaling=1., name="Sink 0", index=None, in_service=True,
                   type="sink")
    pp.create_sink(net, 3, mdot_kg_per_s=0.1, name="Sink 1")
    pp.create_sink(net, 4, mdot_kg_per_s=0.5, name="Sink 2")
    pp.create_sink(net, 5, mdot_kg_per_s=0.07, name="Sink 3")
    pp.create_sink(net, 6, mdot_kg_per_s=0.09, name="Sink 4")
    pp.create_sink(net, 7, mdot_kg_per_s=0.1, name="Sink 5")

    # sources
    pp.create_source(net, junction=8, mdot_kg_per_s=0.1, scaling=1., name="Source 0", index=None, in_service=True,
                     type="source")
    pp.create_source(net, junction=9, mdot_kg_per_s=0.03, name="Source 1")
    pp.create_source(net, junction=10, mdot_kg_per_s=0.04, name="Source 2")
    pp.create_source(net, junction=11, mdot_kg_per_s=0.09, name="Source 3")

    # valves
    pp.create_valve(net, from_junction=8, to_junction=9, diameter_m=0.1, opened=True, loss_coefficient=0,
                    name="Valve 0", index=None, type="valve")
    pp.create_valve(net, 9, 4, diameter_m=0.05, opened=True, name="Valve 1")

    # pump
    pp.create_pump_from_parameters(net, from_junction=8, to_junction=3, new_std_type_name="Pump",
                                   pressure_list=[6.1, 5.8, 4],
                                   flowrate_list=[0, 19, 83], reg_polynomial_degree=2,
                                   poly_coefficents=None, name=None, index=None, in_service=True,
                                   type="pump")

    # circulation pump mass
    pp.create_circ_pump_const_mass_flow(net, from_junction=3, to_junction=4, p_bar=6, mdot_kg_per_s=1,
                                        t_k=290, name="Circ. Pump Mass", index=None, in_service=True,
                                        type="pt")

    # circulation pump pressure
    pp.create_circ_pump_const_pressure(net, from_junction=11, to_junction=5, p_bar=5, plift_bar=2,
                                       t_k=290, name="Circ. Pump Pressure", index=None, in_service=True, type="pt")

    # heat exchanger
    pp.create_heat_exchanger(net, from_junction=10, to_junction=6, diameter_m=0.08, qext_w=50, loss_coefficient=0,
                             name="Heat Exchanger 0", index=None, in_service=True, type="heat_exchanger")
    pp.create_heat_exchanger(net, from_junction=4, to_junction=10, diameter_m=0.08, qext_w=28000,
                             loss_coefficient=0,
                             name="Heat Exchanger 1", index=None, in_service=True, type="heat_exchanger")
    # time series
    profiles_sink = pd.read_csv(os.path.join(pp_dir, 'test', 'api', 'release_cycle',
                                             'release_control_test_sink_profiles.csv'), index_col=0)
    profiles_source = pd.read_csv(os.path.join(pp_dir, 'test', 'api', 'release_cycle',
                                               'release_control_test_source_profiles.csv'), index_col=0)
    ds_sink = DFData(profiles_sink)
    ds_source = DFData(profiles_source)

    const_sink = control.ConstControl(net, element='sink', variable='mdot_kg_per_s',
                                      element_index=net.sink.index.values, data_source=ds_sink,
                                      profile_name=net.sink.index.values.astype(str))
    const_source = control.ConstControl(net, element='source', variable='mdot_kg_per_s',
                                        element_index=net.source.index.values,
                                        data_source=ds_source,
                                        profile_name=net.source.index.values.astype(str))

    const_sink.initial_run = False
    const_source.initial_run = False

    pp.pipeflow(net)

    pp.to_json(net, os.path.join(path, 'example_%s.json' % pp.__version__))

    return net
コード例 #30
0
def test_circulation_pump_constant_mass():
    """
        :return:
        :rtype:
        """
    net = pandapipes.create_empty_network("net", add_stdtypes=False)

    j1 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)
    j2 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)
    j3 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)
    j4 = pandapipes.create_junction(net, pn_bar=5, tfluid_k=283.15)

    pandapipes.create_pipe_from_parameters(net,
                                           j1,
                                           j2,
                                           k_mm=1.,
                                           length_km=0.43380,
                                           diameter_m=0.1022)
    pandapipes.create_pipe_from_parameters(net,
                                           j3,
                                           j4,
                                           k_mm=1.,
                                           length_km=0.26370,
                                           diameter_m=0.1022)
    pandapipes.create_circ_pump_const_mass_flow(net,
                                                j1,
                                                j4,
                                                5,
                                                5,
                                                300,
                                                type='pt')
    pandapipes.create_heat_exchanger(net, j2, j3, 0.1, qext_w=200000)
    pandapipes.create_sink(net, j1, 2)
    pandapipes.create_source(net, j4, 2)

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

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

    data = pd.read_csv(os.path.join(internals_data_path,
                                    "test_circ_pump_mass.csv"),
                       sep=';')

    res_junction = net.res_junction
    res_pipe = net.res_pipe.v_mean_m_per_s.values
    res_pump = net.res_circ_pump_mass

    p_diff = np.abs(1 - res_junction.p_bar.values / data['p'].dropna().values)
    t_diff = np.abs(1 - res_junction.t_k.values / data['t'].dropna().values)
    v_diff = np.abs(1 - res_pipe / data['v'].dropna().values)
    mdot_diff = np.abs(1 - res_pump['mdot_kg_per_s'].values /
                       data['mdot'].dropna().values)
    deltap_diff = np.abs(1 - res_pump['deltap_bar'].values /
                         data['deltap'].dropna().values)

    assert np.all(p_diff < 0.01)
    assert np.all(t_diff < 0.01)
    assert np.all(v_diff < 0.01)
    assert np.all(mdot_diff < 0.01)
    assert np.all(deltap_diff < 0.01)