def test_add_fluid(): net = pandapipes.create_empty_network() fluid_old = pandapipes.call_lib("air") with pytest.raises(AttributeError, match="no fluid"): pandapipes.get_fluid(net) _add_fluid_to_net(net, fluid_old) fluid_new = pandapipes.create_constant_fluid("arbitrary_gas2", "gas", density=2, compressibility=2) _add_fluid_to_net(net, fluid_new, overwrite=False) assert pandapipes.get_fluid(net) == fluid_old _add_fluid_to_net(net, fluid_new) assert pandapipes.get_fluid(net) == fluid_new net["fluid"] = "Hello" _add_fluid_to_net(net, fluid_new, overwrite=False) assert pandapipes.get_fluid(net) == "Hello" _add_fluid_to_net(net, fluid_new) assert pandapipes.get_fluid(net) == fluid_new
def test_add_fluid(): net = pandapipes.create_empty_network() fluid_old = pandapipes.call_lib("air") try: pandapipes.get_fluid(net) assert False, "should'nt get here" except UserWarning: pass _add_fluid_to_net(net, fluid_old) fluid_new = pandapipes.create_constant_fluid("arbitrary_gas2", "gas", density=2, compressibility=2) _add_fluid_to_net(net, fluid_new, overwrite=False) assert pandapipes.get_fluid(net) == fluid_old _add_fluid_to_net(net, fluid_new) assert pandapipes.get_fluid(net) == fluid_new net["fluid"] = "Hello" _add_fluid_to_net(net, fluid_new, overwrite=False) assert pandapipes.get_fluid(net) == "Hello" _add_fluid_to_net(net, fluid_new) assert pandapipes.get_fluid(net) == fluid_new
def create_fluid_from_lib(net, name, overwrite=True): """ Creates a fluid from library (if there is an entry) and sets net["fluid"] to this value. Currently existing fluids in the library are: "hgas", "lgas", "hydrogen", "water", "air". :param net: The net for which this fluid should be created :type net: pandapipesNet :param name: The name of the fluid that shall be extracted from the fluid lib :type name: str :param overwrite: Flag if a possibly existing fluid in the net shall be overwritten :type overwrite: bool, default True :return: No output :Example: >>> pp.create_fluid_from_lib(net, name="water") """ _add_fluid_to_net(net, call_lib(name), overwrite=overwrite)
def test_pipe_velocity_results(): """ This test verifies the entries in the results table for a pipe network with pipes consisting of more than one section. The basic idea is that the computation is first done with only one section per pipe. Afterwards, the same network is calculated with more nodes. if everything works correctly, the entries in the result table for the velocities (from, to) should be the same. A T-junction is used for the test setup :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_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, 6.0, d, k_mm=.5, sections=1) pandapipes.create_pipe_from_parameters(net, 1, 2, 6.0, d, k_mm=.5, sections=1) pandapipes.create_pipe_from_parameters(net, 1, 3, 6.0, d, k_mm=.5, sections=1) pandapipes.create_ext_grid(net, 0, p_bar=51 - 1.01325, t_k=285.15, type="pt") pandapipes.create_sink(net, 2, mdot_kg_per_s=0.82752 * 45000 / 3600 / 3) pandapipes.create_sink(net, 3, mdot_kg_per_s=0.82752 * 45000 / 3600 / 2) _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) v_1_sec_from = net.res_pipe.v_from_m_per_s v_1_sec_to = net.res_pipe.v_from_m_per_s 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_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, 6.0, d, k_mm=.5, sections=3) pandapipes.create_pipe_from_parameters(net, 1, 2, 6.0, d, k_mm=.5, sections=4) pandapipes.create_pipe_from_parameters(net, 1, 3, 6.0, d, k_mm=.5, sections=2) pandapipes.create_ext_grid(net, 0, p_bar=51 - 1.01325, t_k=285.15, type="pt") pandapipes.create_sink(net, 2, mdot_kg_per_s=0.82752 * 45000 / 3600 / 3) pandapipes.create_sink(net, 3, mdot_kg_per_s=0.82752 * 45000 / 3600 / 2) _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) v_n_sec_from = net.res_pipe.v_from_m_per_s v_n_sec_to = net.res_pipe.v_from_m_per_s diff_from = v_1_sec_from - v_n_sec_from diff_to = v_1_sec_to - v_n_sec_to assert np.all(np.abs(diff_from) < 1e-9) assert np.all(np.abs(diff_to) < 1e-9)
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) _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_MEAN"][:, 0] == 0) pipe_p_data = pipe_results["PINIT"][pipe_p_data_idx, 1] pipe_v_data = pipe_results["VINIT_MEAN"][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)