Beispiel #1
0
def test_create_sources_raise_except(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    # standard
    j1 = pandapipes.create_junction(net, 3, 273)
    j2 = pandapipes.create_junction(net, 3, 273)
    j3 = pandapipes.create_junction(net, 3, 273)

    with pytest.raises(
            UserWarning,
            match=r"Cannot attach to junctions \{3, 4, 5\}, they do not "
            r"exist"):
        pandapipes.create_sources(net,
                                  junctions=[3, 4, 5],
                                  mdot_kg_per_s=[0, 0.1, 0.2],
                                  scaling=[1., 1., 0.5],
                                  name=["source%d" % s for s in range(3)],
                                  new_col=[1, 3, 5])

    sg = pandapipes.create_sources(net,
                                   junctions=[j1, j2, j3],
                                   mdot_kg_per_s=[0, 0.1, 0.2],
                                   scaling=[1., 1., 0.5],
                                   name=["source%d" % s for s in range(3)],
                                   new_col=[1, 3, 5])
    with pytest.raises(UserWarning,
                       match=r"Sources with indexes \[0 1 2\] already exist."):
        pandapipes.create_sources(net,
                                  junctions=[j1, j2, j3],
                                  mdot_kg_per_s=[0, 0.1, 0.2],
                                  scaling=[1., 1., 0.5],
                                  name=["source%d" % s for s in range(3)],
                                  new_col=[1, 3, 5],
                                  index=sg)
Beispiel #2
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)
Beispiel #3
0
def test_create_valve(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    pandapipes.create_junction(net, 1, 293, index=8, geodata=(0, 1))
    pandapipes.create_junction(net, 1, 293, index=9, geodata=(2, 2))
    pandapipes.create_valve(net, 8, 9, 0.4, True, index=2)

    try:
        pandapipes.create_valve(net, 8, 9, 0.4, True, index=2)
        assert False, "Shouldn't make valve, index exists!"
    except UserWarning:
        assert True
    try:
        pandapipes.create_valve(net, 8, 10, 0.4, True)
        assert False, "Shouldn't make valve, non-existent to_junction!"
    except UserWarning:
        assert True
    try:
        pandapipes.create_valve(net,
                                8,
                                9,
                                0.4,
                                True,
                                geodata=[(0, 1), (1, 1), (2, 2)])
        assert False, "Shouldn't make valve, geodata not possible!"
    except ValueError:
        assert True
def test_default_input_tables():
    net = pandapipes.create_empty_network()

    junction_input = list(copy.deepcopy(net.junction.columns))
    pandapipes.create_junction(net, pn_bar=5, tfluid_k=283)
    junction_input_create = list(net.junction.columns)
    assert junction_input == junction_input_create, "Input does not equal Table in create-function"

    junction_input = list(copy.deepcopy(net.junction.columns))
    pandapipes.create_junction(net, pn_bar=5, tfluid_k=283, hallo=2)
    junction_input_create = list(net.junction.columns)
    assert junction_input != junction_input_create, "Input equals create-table, but they shouldn't"

    pipe_input = list(copy.deepcopy(net.pipe.columns))
    pandapipes.create_pipe_from_parameters(net,
                                           0,
                                           1,
                                           6,
                                           diameter_m=0.2,
                                           k_mm=.1,
                                           sections=6,
                                           alpha_w_per_m2k=5)
    pipe_input_create = list(net.pipe.columns)
    assert pipe_input == pipe_input_create, "Input does not equal Table in create-function"

    ext_grid_input = list(copy.deepcopy(net.ext_grid.columns))
    pandapipes.create_ext_grid(net, 0, p_bar=5, t_k=330, type="pt")
    ext_grid_input_create = list(net.ext_grid.columns)
    assert ext_grid_input == ext_grid_input_create, "Input does not equal Table in create-function"
Beispiel #5
0
def test_create_valves_raise_except(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    j1 = pandapipes.create_junction(net, 3, 273)
    j2 = pandapipes.create_junction(net, 3, 273)
    j3 = pandapipes.create_junction(net, 3, 273)

    with pytest.raises(UserWarning,
                       match=r"trying to attach to non existing junctions"):
        pandapipes.create_valves(net, [1, 3], [4, 5],
                                 diameter_m=0.8,
                                 opened=False,
                                 name="test",
                                 loss_coefficient=0.3)

    pandapipes.create_valves(net, [j1, j1], [j2, j3],
                             diameter_m=0.8,
                             opened=False,
                             name="test",
                             loss_coefficient=0.3,
                             index=[0, 1])
    with pytest.raises(UserWarning,
                       match=r"with indexes \[0 1\] already exist"):
        pandapipes.create_valves(net, [j1, j1], [j2, j3],
                                 diameter_m=0.8,
                                 opened=False,
                                 name="test",
                                 loss_coefficient=0.3,
                                 index=[0, 1])
Beispiel #6
0
def test_create_sources(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    # standard
    j1 = pandapipes.create_junction(net, 3, 273)
    j2 = pandapipes.create_junction(net, 3, 273)
    j3 = pandapipes.create_junction(net, 3, 273)
    pandapipes.create_sources(net,
                              junctions=[j1, j2, j3],
                              mdot_kg_per_s=[0, 0.1, 0.2],
                              scaling=[1., 1., 0.5],
                              name=["source%d" % s for s in range(3)],
                              new_col=[1, 3, 5])

    assert (net.source.junction.at[0] == j1)
    assert (net.source.junction.at[1] == j2)
    assert (net.source.junction.at[2] == j3)
    assert (net.source.mdot_kg_per_s.at[0] == 0)
    assert (net.source.mdot_kg_per_s.at[1] == 0.1)
    assert (net.source.mdot_kg_per_s.at[2] == 0.2)
    assert (net.source.scaling.at[0] == 1)
    assert (net.source.scaling.at[1] == 1)
    assert (net.source.scaling.at[2] == 0.5)
    assert (all(net.source.in_service.values == True))
    assert (all(net.source.type.values == "source"))
    assert (all(net.source.new_col.values == [1, 3, 5]))
Beispiel #7
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
Beispiel #8
0
def test_create_pipe_from_parameters(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    pandapipes.create_junction(net, 1, 293, index=8, geodata=(0, 1))
    pandapipes.create_junction(net, 1, 293, index=9, geodata=(2, 2))
    pandapipes.create_pipe_from_parameters(net,
                                           8,
                                           9,
                                           0.3,
                                           0.4,
                                           index=2,
                                           geodata=[(0, 1), (1, 1), (2, 2)])

    try:
        pandapipes.create_pipe_from_parameters(net, 8, 9, 0.3, 0.4, index=2)
        assert False, "Shouldn't make pipe, index exists!"
    except UserWarning:
        assert True
    try:
        pandapipes.create_pipe_from_parameters(net, 8, 10, 0.3, 0.4)
        assert False, "Shouldn't make pipe, non-existent to_junction!"
    except UserWarning:
        assert True
    try:
        pandapipes.create_pipe_from_parameters(net,
                                               8,
                                               9,
                                               0.3,
                                               0.4,
                                               std_type="blah")
        assert False, "Shouldn't make pipe, wrong statement!"
    except UserWarning:
        assert True
Beispiel #9
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)
Beispiel #10
0
def test_create_source(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    pandapipes.create_junction(net, 1, 293, index=8)
    pandapipes.create_junction(net, 1, 293, index=9)
    pandapipes.create_source(net, 9, mdot_kg_per_s=0.1, index=2)

    with pytest.raises(UserWarning):
        pandapipes.create_source(net, junction=10, mdot_kg_per_s=0.1)
    with pytest.raises(UserWarning):
        pandapipes.create_source(net, junction=9, mdot_kg_per_s=0.1, index=2)
Beispiel #11
0
def test_create_ext_grid(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    pandapipes.create_junction(net, 1, 293, index=8)
    pandapipes.create_junction(net, 1, 293, index=9)
    pandapipes.create_ext_grid(net, 9, p_bar=1, t_k=295, index=2)

    with pytest.raises(UserWarning):
        pandapipes.create_ext_grid(net, junction=10, p_bar=1, t_k=295)
    with pytest.raises(UserWarning):
        pandapipes.create_ext_grid(net, junction=9, p_bar=1, t_k=295, index=2)
Beispiel #12
0
def test_create_heat_exchanger(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    pandapipes.create_junction(net, 1, 293, index=8, geodata=(0, 1))
    pandapipes.create_junction(net, 1, 293, index=9, geodata=(2, 2))
    pandapipes.create_heat_exchanger(net, 8, 9, 0.3, qext_w=200, index=2)

    with pytest.raises(UserWarning):
        pandapipes.create_heat_exchanger(net, 8, 10, 0.3, qext_w=200)
    with pytest.raises(UserWarning):
        pandapipes.create_heat_exchanger(net, 8, 9, 0.3, qext_w=200, index=2)
def test_additional_tables():
    net = pandapipes.create_empty_network()
    pandapipes.create_junction(net, pn_bar=5, tfluid_k=283)
    pandapipes.create_junction(net, pn_bar=5, tfluid_k=283)

    pandapipes.add_new_component(net, Sink)
    sink_input = list(copy.deepcopy(net.sink.columns))
    pandapipes.create_sink(net, 1, mdot_kg_per_s=1)
    sink_input_create = list(net.sink.columns)
    assert sink_input == sink_input_create, "Input does not equal create-table"

    pandapipes.add_new_component(net, Source)
    source_input = list(copy.deepcopy(net.source.columns))
    pandapipes.create_source(net, 1, mdot_kg_per_s=1)
    source_input_create = list(net.source.columns)
    assert source_input == source_input_create, "Input does not equal create-table"

    pandapipes.add_new_component(net, Pump)
    pump_input = list(copy.deepcopy(net.pump.columns))
    pandapipes.create_pump_from_parameters(net, 0, 1, 'P4', [6.1, 5.8, 4],
                                           [0, 19, 83], 2)
    pump_input_create = list(net.pump.columns)
    assert pump_input == pump_input_create, "Input does not equal create-table"

    pandapipes.add_new_component(net, CirculationPumpMass)
    pumpcircmass_input = list(copy.deepcopy(net.circ_pump_mass.columns))
    pandapipes.create_circ_pump_const_mass_flow(net,
                                                0,
                                                1,
                                                5,
                                                5,
                                                300,
                                                type='pt')
    pumpcircmass_input_create = list(net.circ_pump_mass.columns)
    assert pumpcircmass_input == pumpcircmass_input_create, "Input does not equal create-table"

    pandapipes.add_new_component(net, CirculationPumpPressure)
    pumpcircpres_input = list(copy.deepcopy(net.circ_pump_pressure.columns))
    pandapipes.create_circ_pump_const_pressure(net, 0, 1, 5, 2, 300, type='pt')
    pumpcircpres_input_create = list(net.circ_pump_pressure.columns)
    assert pumpcircpres_input == pumpcircpres_input_create, "Input does not equal create-table"

    pandapipes.add_new_component(net, Valve)
    valve_input = list(copy.deepcopy(net.valve.columns))
    pandapipes.create_valve(net, 0, 1, diameter_m=0.1, opened=False)
    valve_input_create = list(net.valve.columns)
    assert valve_input == valve_input_create, "Input does not equal create-table"

    pandapipes.add_new_component(net, HeatExchanger)
    hex_input = list(copy.deepcopy(net.heat_exchanger.columns))
    pandapipes.create_heat_exchanger(net, 0, 1, 0.2, qext_w=20000)
    hex_input_create = list(net.heat_exchanger.columns)
    assert hex_input == hex_input_create, "Input does not equal create-table"
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))
Beispiel #15
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)
Beispiel #16
0
def test_create_pump_from_parameters(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    pandapipes.create_junction(net, 1, 293, index=8, geodata=(0, 1))
    pandapipes.create_junction(net, 1, 293, index=9, geodata=(2, 2))
    pandapipes.create_pump_from_parameters(net,
                                           8,
                                           9,
                                           "pump1",
                                           pressure_list=[0, 1, 2, 3],
                                           flowrate_list=[0, 1, 2, 3],
                                           reg_polynomial_degree=1,
                                           index=2)

    try:
        pandapipes.create_pump_from_parameters(net,
                                               8,
                                               9,
                                               "pump1",
                                               pressure_list=[0, 1, 2, 3],
                                               flowrate_list=[0, 1, 2, 3],
                                               reg_polynomial_degree=1,
                                               index=2)
        assert False, "Shouldn't make pump, index exists!"
    except UserWarning:
        assert True
    try:
        pandapipes.create_pump_from_parameters(net,
                                               8,
                                               10,
                                               "pump1",
                                               pressure_list=[0, 1, 2, 3],
                                               flowrate_list=[0, 1, 2, 3],
                                               reg_polynomial_degree=1,
                                               index=2)
        assert False, "Shouldn't make pump, non-existent to_junction!"
    except UserWarning:
        assert True
    try:
        pandapipes.create_pump_from_parameters(net,
                                               8,
                                               9,
                                               "pump1",
                                               pressure_list=[0, 1, 2, 3],
                                               flowrate_list=[0, 1, 2, 3],
                                               reg_polynomial_degree=1,
                                               geodata=[(0, 1), (1, 1),
                                                        (2, 2)])
        assert False, "Shouldn't make pump, geodata not possible!"
    except ValueError:
        assert True
Beispiel #17
0
def test_create_pipes_raise_except(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    j1 = pandapipes.create_junction(net, 3, 273)
    j2 = pandapipes.create_junction(net, 3, 273)
    j3 = pandapipes.create_junction(net, 3, 273)

    with pytest.raises(UserWarning,
                       match=r"trying to attach to non existing junctions"):
        pandapipes.create_pipes(net, [1, 3], [4, 5],
                                std_type="80_GGG",
                                length_km=5,
                                in_service=False,
                                geodata=[(10, 10), (20, 20)],
                                name="test",
                                k_mm=0.01,
                                loss_coefficient=0.3,
                                sections=2,
                                alpha_w_per_m2k=0.1,
                                text_k=273,
                                qext_w=0.01)

    pandapipes.create_pipes(net, [j1, j1], [j2, j3],
                            std_type="80_GGG",
                            length_km=5,
                            in_service=False,
                            geodata=[(10, 10), (20, 20)],
                            name="test",
                            k_mm=0.01,
                            loss_coefficient=0.3,
                            sections=2,
                            alpha_w_per_m2k=0.1,
                            text_k=273,
                            qext_w=0.01,
                            index=[0, 1])
    with pytest.raises(UserWarning,
                       match=r"with indexes \[0 1\] already exist"):
        pandapipes.create_pipes(net, [j1, j1], [j2, j3],
                                std_type="80_GGG",
                                length_km=5,
                                in_service=False,
                                geodata=[(10, 10), (20, 20)],
                                name="test",
                                k_mm=0.01,
                                loss_coefficient=0.3,
                                sections=2,
                                alpha_w_per_m2k=0.1,
                                text_k=273,
                                qext_w=0.01,
                                index=[0, 1])
Beispiel #18
0
def test_create_ext_grid(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    pandapipes.create_junction(net, 1, 293, index=8)
    pandapipes.create_junction(net, 1, 293, index=9)
    pandapipes.create_ext_grid(net, 9, p_bar=1, t_k=295, index=2)

    try:
        pandapipes.create_ext_grid(net, junction=10, p_bar=1, t_k=295)
        assert False, "Shouldn't make ext_grid!"
    except UserWarning:
        assert True
    try:
        pandapipes.create_ext_grid(net, junction=9, p_bar=1, t_k=295, index=2)
        assert False, "Shouldn't make ext_grid!"
    except UserWarning:
        assert True
Beispiel #19
0
def test_create_heat_exchanger(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    pandapipes.create_junction(net, 1, 293, index=8, geodata=(0, 1))
    pandapipes.create_junction(net, 1, 293, index=9, geodata=(2, 2))
    pandapipes.create_heat_exchanger(net, 8, 9, 0.3, qext_w=200, index=2)

    try:
        pandapipes.create_heat_exchanger(net, 8, 10, 0.3, qext_w=200)
        assert False, "Shouldn't make heat exchanger!"
    except UserWarning:
        assert True
    try:
        pandapipes.create_heat_exchanger(net, 8, 9, 0.3, qext_w=200, index=2)
        assert False, "Shouldn't make heat exchanger!"
    except UserWarning:
        assert True
Beispiel #20
0
def test_create_source(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    pandapipes.create_junction(net, 1, 293, index=8)
    pandapipes.create_junction(net, 1, 293, index=9)
    pandapipes.create_source(net, 9, mdot_kg_per_s=0.1, index=2)

    try:
        pandapipes.create_source(net, junction=10, mdot_kg_per_s=0.1)
        assert False, "Shouldn't make source!"
    except UserWarning:
        assert True
    try:
        pandapipes.create_source(net, junction=9, mdot_kg_per_s=0.1, index=2)
        assert False, "Shouldn't make source!"
    except UserWarning:
        assert True
Beispiel #21
0
def test_create_valve(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    pandapipes.create_junction(net, 1, 293, index=8, geodata=(0, 1))
    pandapipes.create_junction(net, 1, 293, index=9, geodata=(2, 2))
    pandapipes.create_valve(net, 8, 9, 0.4, True, index=2)

    with pytest.raises(UserWarning):
        pandapipes.create_valve(net, 8, 9, 0.4, True, index=2)
    with pytest.raises(UserWarning):
        pandapipes.create_valve(net, 8, 10, 0.4, True)
    with pytest.raises(ValueError):
        pandapipes.create_valve(net,
                                8,
                                9,
                                0.4,
                                True,
                                geodata=[(0, 1), (1, 1), (2, 2)])
Beispiel #22
0
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"])
Beispiel #23
0
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"])
Beispiel #24
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)
Beispiel #25
0
def test_create_pump_from_parameters(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    pandapipes.create_junction(net, 1, 293, index=8, geodata=(0, 1))
    pandapipes.create_junction(net, 1, 293, index=9, geodata=(2, 2))
    pandapipes.create_pump_from_parameters(net,
                                           8,
                                           9,
                                           "pump1",
                                           pressure_list=[0, 1, 2, 3],
                                           flowrate_list=[0, 1, 2, 3],
                                           reg_polynomial_degree=1,
                                           index=2)

    with pytest.raises(UserWarning):
        pandapipes.create_pump_from_parameters(net,
                                               8,
                                               9,
                                               "pump1",
                                               pressure_list=[0, 1, 2, 3],
                                               flowrate_list=[0, 1, 2, 3],
                                               reg_polynomial_degree=1,
                                               index=2)
    with pytest.raises(UserWarning):
        pandapipes.create_pump_from_parameters(net,
                                               8,
                                               10,
                                               "pump1",
                                               pressure_list=[0, 1, 2, 3],
                                               flowrate_list=[0, 1, 2, 3],
                                               reg_polynomial_degree=1,
                                               index=2)
    with pytest.raises(ValueError):
        pandapipes.create_pump_from_parameters(net,
                                               8,
                                               9,
                                               "pump1",
                                               pressure_list=[0, 1, 2, 3],
                                               flowrate_list=[0, 1, 2, 3],
                                               reg_polynomial_degree=1,
                                               geodata=[(0, 1), (1, 1),
                                                        (2, 2)])
Beispiel #26
0
def test_create_junction(create_empty_net):
    net = copy.deepcopy(create_empty_net)
    pandapipes.create_junction(net, 1, 293, index=8)
    with pytest.raises(UserWarning):
        pandapipes.create_junction(net, 1, 293, index=8)
    with pytest.raises(UserWarning):
        pandapipes.create_junction(net, 1, 293, geodata=(1, 2, 3))
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)
Beispiel #28
0
def net_plotting():
    net = pandapipes.create_empty_network(fluid="lgas")

    # create network elements, such as junctions, external grid, pipes, valves, sinks and sources
    junction1 = pandapipes.create_junction(net, pn_bar=1.05, tfluid_k=293.15,
                                           name="Connection to External Grid", geodata=(0, 0))
    junction2 = pandapipes.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 2",
                                           geodata=(2, 0))
    junction3 = pandapipes.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 3",
                                           geodata=(7, 4))
    junction4 = pandapipes.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 4",
                                           geodata=(7, -4))
    junction5 = pandapipes.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 5",
                                           geodata=(5, 3))
    junction6 = pandapipes.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 6",
                                           geodata=(5, -3))
    junction7 = pandapipes.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 7",
                                           geodata=(9, -4))
    junction8 = pandapipes.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name="Junction 7",
                                           geodata=(9, 4))

    pandapipes.create_ext_grid(net, junction=junction1, p_bar=1.1, t_k=293.15,
                               name="Grid Connection")
    pandapipes.create_pipe_from_parameters(net, from_junction=junction1, to_junction=junction2,
                                           length_km=10, diameter_m=0.3, name="Pipe 1",
                                           geodata=[(0, 0), (2, 0)])
    pandapipes.create_pipe_from_parameters(net, from_junction=junction2, to_junction=junction3,
                                           length_km=2, diameter_m=0.3, name="Pipe 2",
                                           geodata=[(2, 0), (2, 4), (7, 4)])
    pandapipes.create_pipe_from_parameters(net, from_junction=junction2, to_junction=junction4,
                                           length_km=2.5, diameter_m=0.3, name="Pipe 3",
                                           geodata=[(2, 0), (2, -4), (7, -4)])
    pandapipes.create_pipe_from_parameters(net, from_junction=junction3, to_junction=junction5,
                                           length_km=1, diameter_m=0.3, name="Pipe 4",
                                           geodata=[(7, 4), (7, 3), (5, 3)])
    pandapipes.create_pipe_from_parameters(net, from_junction=junction4, to_junction=junction6,
                                           length_km=1, diameter_m=0.3, name="Pipe 5",
                                           geodata=[(7, -4), (7, -3), (5, -3)])
    pandapipes.create_pipe_from_parameters(net, from_junction=junction7, to_junction=junction8,
                                           length_km=1, diameter_m=0.3, name="Pipe 6",
                                           geodata=[(9, -4), (9, 4)])
    pandapipes.create_valve(net, from_junction=junction5, to_junction=junction6, diameter_m=0.05,
                            opened=True)
    pandapipes.create_heat_exchanger(net, junction3, junction8, diameter_m=0.3, qext_w=20000)
    pandapipes.create_sink(net, junction=junction4, mdot_kg_per_s=0.545, name="Sink 1")
    pandapipes.create_source(net, junction=junction3, mdot_kg_per_s=0.234)
    pandapipes.create_pump_from_parameters(net, junction4, junction7, 'P1')

    return net
Beispiel #29
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))
Beispiel #30
0
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)