def test_connectivity_check_island_without_pv_bus(): # Network with islands without pv bus -> all buses in island should be set out of service net = create_cigre_network_mv(with_der=False) iso_buses, iso_p, iso_q = get_isolated(net) assert len(iso_buses) == 0 assert np.isclose(iso_p, 0) assert np.isclose(iso_q, 0) isolated_bus1 = pp.create_bus(net, vn_kv=20., name="isolated Bus1") isolated_bus2 = pp.create_bus(net, vn_kv=20., name="isolated Bus2") pp.create_line(net, isolated_bus2, isolated_bus1, length_km=1, std_type="N2XS(FL)2Y 1x300 RM/35 64/110 kV", name="IsolatedLine") iso_buses, iso_p, iso_q = get_isolated(net) assert len(iso_buses) == 2 assert np.isclose(iso_p, 0) assert np.isclose(iso_q, 0) pp.create_load(net, isolated_bus1, p_kw=200., q_kvar=20) pp.create_sgen(net, isolated_bus2, p_kw=-150., q_kvar=-10) # with pytest.warns(UserWarning): iso_buses, iso_p, iso_q = get_isolated(net) assert len(iso_buses) == 2 assert np.isclose(iso_p, 350) assert np.isclose(iso_q, 30) # with pytest.warns(UserWarning): runpp_with_consistency_checks(net, check_connectivity=True)
def test_recycle_gen(recycle_net): net = recycle_net # update values of gens ps = 0.25 u_set = 0.98 net["gen"].at[0, "p_mw"] = ps net["gen"].at[0, "vm_pu"] = u_set runpp_with_consistency_checks(net, recycle=dict(trafo=False, bus_pq=False, gen=True)) assert np.allclose(net.res_gen.at[0, "p_mw"], ps) assert np.allclose(net.res_gen.at[0, "vm_pu"], u_set) ps = 0.5 u_set = 0.99 net["gen"].at[0, "p_mw"] = ps net["gen"].at[0, "vm_pu"] = u_set runpp_with_consistency_checks(net, recycle=dict(trafo=False, bus_pq=False, gen=True)) assert np.allclose(net.res_gen.at[0, "vm_pu"], u_set) assert np.allclose(net.res_gen.at[0, "p_mw"], ps)
def test_ext_grid(result_test_network, v_tol=1e-6, va_tol=1e-2, i_tol=1e-6, s_tol=5e-3, l_tol=1e-3): net = result_test_network runpp_with_consistency_checks(net, calculate_voltage_angles=True) buses = net.bus[net.bus.zone == "test_ext_grid"] b2 = buses.index[1] ext_grids = [ x for x in net.ext_grid.index if net.ext_grid.bus[x] in buses.index] eg1 = ext_grids[0] eg2 = ext_grids[1] # results from powerfactory p1 = 5.6531650 q1 = -2.1074499 v2 = 1.015506741 va2 = 1.47521433 p2 = 5.8377758 q2 = -2.7786795 assert abs(net.res_ext_grid.p_mw.at[eg1] - (-p1)) assert abs(net.res_ext_grid.q_mvar.at[eg1] - (-q1)) assert abs(net.res_ext_grid.p_mw.at[eg2] - (-p2)) assert abs(net.res_ext_grid.q_mvar.at[eg2] - (-q2)) assert abs(net.res_bus.vm_pu.at[b2] - v2) < v_tol assert abs(net.res_bus.va_degree.at[b2] - va2) < va_tol
def test_connectivity_check_island_with_one_pv_bus(): # Network with islands with one PV bus -> PV bus should be converted to the reference bus net = create_cigre_network_mv(with_der=False) iso_buses, iso_p, iso_q = get_isolated(net) assert len(iso_buses) == 0 assert np.isclose(iso_p, 0) assert np.isclose(iso_q, 0) isolated_bus1 = pp.create_bus(net, vn_kv=20., name="isolated Bus1") isolated_bus2 = pp.create_bus(net, vn_kv=20., name="isolated Bus2") isolated_gen = pp.create_bus(net, vn_kv=20., name="isolated Gen") isolated_pv_bus = pp.create_gen(net, isolated_gen, p_mw=0.35, vm_pu=1.0, name="isolated PV bus") pp.create_line(net, isolated_bus2, isolated_bus1, length_km=1, std_type="N2XS(FL)2Y 1x300 RM/35 64/110 kV", name="IsolatedLine") pp.create_line(net, isolated_gen, isolated_bus1, length_km=1, std_type="N2XS(FL)2Y 1x300 RM/35 64/110 kV", name="IsolatedLineToGen") # with pytest.warns(UserWarning): iso_buses, iso_p, iso_q = get_isolated(net) # assert len(iso_buses) == 0 # assert np.isclose(iso_p, 0) # assert np.isclose(iso_q, 0) # # pp.create_load(net, isolated_bus1, p_mw=0.200., q_mvar=0.020) # pp.create_sgen(net, isolated_bus2, p_mw=0.0150., q_mvar=-0.010) # # iso_buses, iso_p, iso_q = get_isolated(net) # assert len(iso_buses) == 0 # assert np.isclose(iso_p, 0) # assert np.isclose(iso_q, 0) # with pytest.warns(UserWarning): runpp_with_consistency_checks(net, check_connectivity=True)
def test_impedance(result_test_network, v_tol=1e-6, i_tol=1e-6, s_tol=5e-3, l_tol=1e-3): net = result_test_network buses = net.bus[net.bus.zone == "test_impedance"] impedances = [ x for x in net.impedance.index if net.impedance.from_bus[x] in buses.index] runpp_with_consistency_checks(net) buses = net.bus[net.bus.zone == "test_impedance"] impedances = [x for x in net.impedance.index if net.impedance.from_bus[x] in buses.index] runpp_with_consistency_checks(net, trafo_model="t", numba=True) b2 = buses.index[1] b3 = buses.index[2] imp1 = impedances[0] # powerfactory results ifrom = 0.0444417 ito = 0.0029704 pfrom = 1.1237008 qfrom = 1.0618504 pto = -1.000 qto = -0.500 u2 = 1.004242894 u3 = 0.987779091 assert abs(net.res_impedance.p_from_mw.at[imp1] - pfrom) < s_tol assert abs(net.res_impedance.p_to_mw.at[imp1] - pto) < s_tol assert abs(net.res_impedance.q_from_mvar.at[imp1] - qfrom) < s_tol assert abs(net.res_impedance.q_to_mvar.at[imp1] - qto) < s_tol assert abs(net.res_impedance.i_from_ka.at[imp1] - ifrom) < i_tol assert abs(net.res_impedance.i_to_ka.at[imp1] - ito) < i_tol assert abs(net.res_bus.vm_pu.at[b2] - u2) < v_tol assert abs(net.res_bus.vm_pu.at[b3] - u3) < v_tol
def test_impedance(result_test_network): net = result_test_network buses = net.bus[net.bus.zone == "test_impedance"] impedances = [ x for x in net.impedance.index if net.impedance.from_bus[x] in buses.index ] runpp_with_consistency_checks(net, trafo_model="t") b2 = buses.index[1] b3 = buses.index[2] imp1 = impedances[0] # powerfactory results ifrom = 0.0325 ito = 0.0030 pfrom = 1012.6480 qfrom = 506.3231 pto = -999.9960 qto = -499.9971 u2 = 1.00654678 u3 = 0.99397101 assert abs(net.res_impedance.p_from_kw.at[imp1] - pfrom) < 1e-1 assert abs(net.res_impedance.p_to_kw.at[imp1] - pto) < 1e-1 assert abs(net.res_impedance.q_from_kvar.at[imp1] - qfrom) < 1e-1 assert abs(net.res_impedance.q_to_kvar.at[imp1] - qto) < 1e-1 assert abs(net.res_impedance.i_from_ka.at[imp1] - ifrom) < 1e-1 assert abs(net.res_impedance.i_to_ka.at[imp1] - ito) < 1e-1 assert abs(net.res_bus.vm_pu.at[b2] - u2) < 1e-6 assert abs(net.res_bus.vm_pu.at[b3] - u3) < 1e-6
def test_result_iter(): for net in result_test_network_generator(): try: runpp_with_consistency_checks(net, enforce_q_lims=True) except (AssertionError): raise UserWarning("Consistency Error after adding %s" % net.last_added_case) except(LoadflowNotConverged): raise UserWarning("Power flow did not converge after adding %s" % net.last_added_case)
def test_lightsim2grid(): # test several nets for net in result_test_network_generator(): try: runpp_with_consistency_checks(net, lightsim2grid=True) except (AssertionError): raise UserWarning("Consistency Error after adding %s" % net.last_added_case) except (LoadflowNotConverged): raise UserWarning("Power flow did not converge after adding %s" % net.last_added_case)
def test_pypower_algorithms_iter(): alg_to_test = ['fdbx', 'fdxb', 'gs'] for alg in alg_to_test: for net in result_test_network_generator(skip_test_impedance=True): try: runpp_with_consistency_checks(net, enforce_q_lims=True, algorithm=alg) runpp_with_consistency_checks(net, enforce_q_lims=False, algorithm=alg) except (AssertionError): raise UserWarning("Consistency Error after adding %s" % net.last_added_case) except(LoadflowNotConverged): raise UserWarning("Power flow did not converge after adding %s" % net.last_added_case)
def test_oos_bus(): net = pp.create_empty_network() add_test_oos_bus_with_is_element(net) assert runpp_with_consistency_checks(net) # test for pq-node result pp.create_shunt(net, 6, q_kvar=-800) assert runpp_with_consistency_checks(net) # 1test for pv-node result pp.create_gen(net, 4, p_kw=-500) assert runpp_with_consistency_checks(net)
def test_trafo_tap(result_test_network): net = result_test_network runpp_with_consistency_checks(net, trafo_model="t", trafo_loading="current") buses = net.bus[net.bus.zone == "test_trafo_tap"] b2 = buses.index[1] b3 = buses.index[2] assert (1.010114175 - net.res_bus.vm_pu.at[b2]) < 1e-6 assert (0.924072090 - net.res_bus.vm_pu.at[b3]) < 1e-6
def test_recycle_trafo(recycle_net): # test trafo tap change net = recycle_net b4 = pp.create_bus(net, vn_kv=20.) pp.create_transformer(net, 3, b4, std_type="0.4 MVA 10/0.4 kV") net["trafo"].at[0, "tap_pos"] = 0 runpp_with_consistency_checks(net, recycle=dict(trafo=True, bus_pq=False, gen=False)) vm_pu = net.res_bus.at[b4, "vm_pu"] net["trafo"].at[0, "tap_pos"] = 5 runpp_with_consistency_checks(net, recycle=dict(trafo=True, bus_pq=False, gen=False)) assert not np.allclose(vm_pu, net.res_bus.at[b4, "vm_pu"])
def test_recycle(): # Note: Only calls recycle functions and tests if load and gen are updated. # Todo: To fully test the functionality, it must be checked if the recycle methods are being # called or alternatively if the "non-recycle" functions are not being called. net = pp.create_empty_network() b1, b2, ln = add_grid_connection(net) pl = 1200 ql = 1100 ps = -500 u_set = 1.0 b3 = pp.create_bus(net, vn_kv=.4) pp.create_line_from_parameters(net, b2, b3, 12.2, r_ohm_per_km=0.08, x_ohm_per_km=0.12, c_nf_per_km=300, max_i_ka=.2, df=.8) pp.create_load(net, b3, p_kw=pl, q_kvar=ql) pp.create_gen(net, b2, p_kw=ps, vm_pu=u_set) runpp_with_consistency_checks(net, recycle=dict(_is_elements=True, ppc=True, Ybus=True)) # copy.deepcopy(net) # update values pl = 600 ql = 550 ps = -250 u_set = 0.98 net["load"].p_kw.iloc[0] = pl net["load"].q_kvar.iloc[0] = ql net["gen"].p_kw.iloc[0] = ps net["gen"].vm_pu.iloc[0] = u_set runpp_with_consistency_checks(net, recycle=dict(_is_elements=True, ppc=True, Ybus=True)) assert np.allclose(net.res_load.p_kw.iloc[0], pl) assert np.allclose(net.res_load.q_kvar.iloc[0], ql) assert np.allclose(net.res_gen.p_kw.iloc[0], ps) assert np.allclose(net.res_gen.vm_pu.iloc[0], u_set)
def test_trafo3w(result_test_network, v_tol=1e-6, i_tol=1e-6, s_tol=2e-2, l_tol=1e-3): net = result_test_network buses = net.bus[net.bus.zone == "test_trafo3w"] trafos = [ x for x in net.trafo3w.index if net.trafo3w.hv_bus[x] in buses.index ] runpp_with_consistency_checks(net, trafo_model="pi") b2 = buses.index[1] b3 = buses.index[2] b4 = buses.index[3] t3 = trafos[0] uhv = 1.010117166 umv = 0.955501331 ulv = 0.940630980 load = 37.21 qhv = 1.64375 qmv = 0 qlv = 0 ihv = 0.00858590198 imv = 0.20141269123 ilv = 0.15344761586 phv = 300.43 pmv = -200.00 plv = -100.00 assert abs((net.res_bus.vm_pu.at[b2] - uhv)) < v_tol assert abs((net.res_bus.vm_pu.at[b3] - umv)) < v_tol assert abs((net.res_bus.vm_pu.at[b4] - ulv)) < v_tol assert abs((net.res_trafo3w.loading_percent.at[t3] - load)) < l_tol assert abs((net.res_trafo3w.p_hv_kw.at[t3] - phv)) < s_tol assert abs((net.res_trafo3w.p_mv_kw.at[t3] - pmv)) < s_tol assert abs((net.res_trafo3w.p_lv_kw.at[t3] - plv)) < s_tol assert abs((net.res_trafo3w.q_hv_kvar.at[t3] - qhv)) < s_tol assert abs((net.res_trafo3w.q_mv_kvar.at[t3] - qmv)) < s_tol assert abs((net.res_trafo3w.q_lv_kvar.at[t3] - qlv)) < s_tol assert abs((net.res_trafo3w.i_hv_ka.at[t3] - ihv)) < i_tol assert abs((net.res_trafo3w.i_mv_ka.at[t3] - imv)) < i_tol assert abs((net.res_trafo3w.i_lv_ka.at[t3] - ilv)) < i_tol
def test_bus_bus_switch_at_eg(): net = pp.create_empty_network() b1 = pp.create_bus(net, name="bus1", vn_kv=.4) b2 = pp.create_bus(net, name="bus2", vn_kv=.4) b3 = pp.create_bus(net, name="bus3", vn_kv=.4) pp.create_ext_grid(net, b1) pp.create_switch(net, b1, et="b", element=1) pp.create_line(net, b2, b3, 1, name="line1", std_type="NAYY 4x150 SE") pp.create_load(net, b3, p_kw=10, q_kvar=0, name="load1") runpp_with_consistency_checks(net)
def test_recycle_pq(recycle_net): # Calls recycle functions and tests if load is update net = recycle_net pl = 1.2 ql = 0. net["load"].at[0, "q_mvar"] = ql runpp_with_consistency_checks(net, recycle=dict(trafo=False, gen=False, bus_pq=True)) assert np.allclose(net.res_load.at[0, "p_mw"], pl) assert np.allclose(net.res_load.at[0, "q_mvar"], ql) pl = 0.8 ql = 0.55 net.load.at[0, "p_mw"] = pl net["load"].at[0, "q_mvar"] = ql runpp_with_consistency_checks(net, recycle=dict(bus_pq=True, trafo=False, gen=False)) assert np.allclose(net.res_load.p_mw.iloc[0], pl) assert np.allclose(net.res_load.q_mvar.iloc[0], ql)
def test_dc_with_ext_grid_at_one_bus(): net = pp.create_empty_network() b1 = pp.create_bus(net, vn_kv=110) b2 = pp.create_bus(net, vn_kv=110) pp.create_ext_grid(net, b1, vm_pu=1.01) pp.create_ext_grid(net, b2, vm_pu=1.01) pp.create_dcline(net, from_bus=b1, to_bus=b2, p_mw=10, loss_percent=0, loss_mw=0, vm_from_pu=1.01, vm_to_pu=1.01) pp.create_sgen(net, b1, p_mw=10) pp.create_load(net, b2, p_mw=10) runpp_with_consistency_checks(net) assert np.allclose(net.res_ext_grid.p_mw.values, [0, 0])
def test_isolated_in_service_bus_at_oos_line(): net = pp.create_empty_network() b1, b2, l1 = add_grid_connection(net) b = pp.create_bus(net, vn_kv=135) l = pp.create_line(net, b2, b, 0.1, std_type="NAYY 4x150 SE") net.line.loc[l, "in_service"] = False assert runpp_with_consistency_checks(net, init="flat")
def test_isolated_in_service_line(): # ToDo: Fix this net = pp.create_empty_network() _, b2, l1 = add_grid_connection(net) b = pp.create_bus(net, vn_kv=20.) pp.create_line(net, b2, b, 0.1, std_type="NAYY 4x150 SE") net.line.loc[l1, "in_service"] = False assert runpp_with_consistency_checks(net, init="flat")
def test_enforce_qlims(result_test_network, v_tol=1e-6, i_tol=1e-6, s_tol=5e-3, l_tol=1e-3): net = result_test_network buses = net.bus[net.bus.zone == "test_enforce_qlims"] gens = [x for x in net.gen.index if net.gen.bus[x] in buses.index] b2 = buses.index[1] b3 = buses.index[2] g1 = gens[0] # enforce reactive power limits runpp_with_consistency_checks(net, enforce_q_lims=True) # powerfactory results u2 = 1.00607194 u3 = 1.00045091 assert abs(net.res_bus.vm_pu.at[b2] - u2) < v_tol assert abs(net.res_bus.vm_pu.at[b3] - u3) < v_tol assert abs(net.res_gen.q_mvar.at[g1] - net.gen.min_q_mvar.at[g1]) < s_tol
def test_recycle_trafo_bus_gen(recycle_net): # test trafo tap change net = recycle_net b4 = pp.create_bus(net, vn_kv=20.) pp.create_transformer(net, 3, b4, std_type="0.4 MVA 10/0.4 kV") ps = 0.25 u_set = 0.98 pl = 1.2 ql = 0. net["load"].at[0, "p_mw"] = pl net["load"].at[0, "q_mvar"] = ql net["gen"].at[0, "p_mw"] = ps net["gen"].at[0, "vm_pu"] = u_set net["trafo"].at[0, "tap_pos"] = 0 runpp_with_consistency_checks(net, recycle=dict(trafo=True, bus_pq=True, gen=True)) assert np.allclose(net.res_gen.at[0, "p_mw"], ps) assert np.allclose(net.res_gen.at[0, "vm_pu"], u_set) assert np.allclose(net.res_load.at[0, "p_mw"], pl) assert np.allclose(net.res_load.at[0, "q_mvar"], ql) vm_pu = net.res_bus.at[b4, "vm_pu"] ps = 0.5 u_set = 0.99 pl = 1. ql = 0.5 net["load"].at[0, "p_mw"] = pl net["load"].at[0, "q_mvar"] = ql net["gen"].at[0, "p_mw"] = ps net["gen"].at[0, "vm_pu"] = u_set net["trafo"].at[0, "tap_pos"] = 5 runpp_with_consistency_checks(net, recycle=dict(trafo=True, bus_pq=True, gen=True)) assert not np.allclose(vm_pu, net.res_bus.at[b4, "vm_pu"]) assert np.allclose(net.res_gen.at[0, "p_mw"], ps) assert np.allclose(net.res_gen.at[0, "vm_pu"], u_set) assert np.allclose(net.res_load.at[0, "p_mw"], pl) assert np.allclose(net.res_load.at[0, "q_mvar"], ql)
def test_trafo3w(result_test_network): net = result_test_network buses = net.bus[net.bus.zone == "test_trafo3w"] trafos = [ x for x in net.trafo3w.index if net.trafo3w.hv_bus[x] in buses.index ] runpp_with_consistency_checks(net, trafo_model="t") b2 = buses.index[1] b3 = buses.index[2] b4 = buses.index[3] t3 = trafos[0] uhv = 1.00895246 umv = 1.00440765 ulv = 1.00669961 load = 68.261 qhv = 154.60 qmv = -100.00 qlv = -50.00 phv = 551.43 pmv = -300.00 plv = -200.00 assert abs((net.res_bus.vm_pu.at[b2] - uhv)) < 1e-4 assert abs((net.res_bus.vm_pu.at[b3] - umv)) < 1e-4 assert abs((net.res_bus.vm_pu.at[b4] - ulv)) < 1e-4 assert abs((net.res_trafo3w.loading_percent.at[t3] - load)) < 1e-2 assert abs((net.res_trafo3w.p_hv_kw.at[t3] - phv)) < 1 assert abs((net.res_trafo3w.p_mv_kw.at[t3] - pmv)) < 1 assert abs((net.res_trafo3w.p_lv_kw.at[t3] - plv)) < 1 assert abs((net.res_trafo3w.q_hv_kvar.at[t3] - qhv)) < 1 assert abs((net.res_trafo3w.q_mv_kvar.at[t3] - qmv)) < 1 assert abs((net.res_trafo3w.q_lv_kvar.at[t3] - qlv)) < 1 # power transformer loading runpp_with_consistency_checks(net, trafo_model="t", trafo_loading="power") load_p = 68.718 assert abs((net.res_trafo3w.loading_percent.at[t3] - load_p)) < 1e-2
def test_balanced_power_flow_with_unbalanced_loads_and_sgens(): net = pp.create_empty_network(sn_mva=100) make_nw(net, 10, 0, "wye", "Dyn") pp.create_asymmetric_sgen(net, 1, p_a_mw=0.01, p_b_mw=0.02, scaling=0.8) runpp_with_consistency_checks(net) vm_pu = net.res_bus.vm_pu net.asymmetric_load.in_service = False pp.create_load( net, bus=net.asymmetric_load.bus.iloc[0], scaling=net.asymmetric_load.scaling.iloc[0], p_mw=net.asymmetric_load.loc[0, ["p_a_mw", "p_b_mw", "p_c_mw"]].sum(), q_mvar=net.asymmetric_load.loc[ 0, ["q_a_mvar", "q_b_mvar", "q_c_mvar"]].sum()) runpp_with_consistency_checks(net) assert net.res_bus.vm_pu.equals(vm_pu) net.asymmetric_sgen.in_service = False pp.create_sgen( net, bus=net.asymmetric_sgen.bus.iloc[0], scaling=net.asymmetric_sgen.scaling.iloc[0], p_mw=net.asymmetric_sgen.loc[0, ["p_a_mw", "p_b_mw", "p_c_mw"]].sum(), q_mvar=net.asymmetric_sgen.loc[ 0, ["q_a_mvar", "q_b_mvar", "q_c_mvar"]].sum()) runpp_with_consistency_checks(net) assert net.res_bus.vm_pu.equals(vm_pu)
def test_storage_pf(): net = pp.create_empty_network() b1 = pp.create_bus(net, vn_kv=0.4) b2 = pp.create_bus(net, vn_kv=0.4) pp.create_line(net, b1, b2, length_km=5, std_type="NAYY 4x50 SE") pp.create_ext_grid(net, b2) pp.create_load(net, b1, p_kw=10) pp.create_sgen(net, b1, p_kw=-10) # test generator behaviour pp.create_storage(net, b1, p_kw=-10, max_e_kwh=10) res_gen_beh = runpp_with_consistency_checks(net) # test load behaviour net["storage"].p_kw.iloc[0] = 10 res_load_beh = runpp_with_consistency_checks(net) assert res_gen_beh and res_load_beh
def test_minimal_net(): # tests corner-case when the grid only has 1 bus and an ext-grid net = pp.create_empty_network() b = pp.create_bus(net, 110) pp.create_ext_grid(net, b) runpp_with_consistency_checks(net) pp.create_load(net, b, p_mw=0.1) runpp_with_consistency_checks(net) b2 = pp.create_bus(net, 110) pp.create_switch(net, b, b2, 'b') pp.create_sgen(net, b2, p_mw=0.2) runpp_with_consistency_checks(net)
def test_trafo3w_switches(network_with_trafo3ws): net, t3, hv, mv, lv = network_with_trafo3ws # open switch at hv side - t3 is disconnected s1 = pp.create_switch(net, bus=hv, element=t3, et="t3", closed=False) runpp_with_consistency_checks(net) assert np.isnan(net.res_bus.vm_pu.at[mv]) assert np.isnan(net.res_bus.vm_pu.at[lv]) assert np.isnan(net.res_trafo3w.p_hv_mw.at[t3]) == 0 # open switch at mv side - mv is disconnected, lv is connected net.switch.bus.at[s1] = mv runpp_with_consistency_checks(net) assert np.isnan(net.res_bus.vm_pu.at[mv]) assert not np.isnan(net.res_bus.vm_pu.at[lv]) assert net.res_trafo3w.i_lv_ka.at[t3] > 1e-5 assert net.res_trafo3w.i_mv_ka.at[t3] < 1e-5 assert 0.490 < net.res_trafo3w.p_hv_mw.at[t3] < 0.510 # open switch at lv side - lv is disconnected, mv is connected net.switch.bus.at[s1] = lv runpp_with_consistency_checks(net) assert np.isnan(net.res_bus.vm_pu.at[lv]) assert not np.isnan(net.res_bus.vm_pu.at[mv]) assert net.res_trafo3w.i_lv_ka.at[t3] < 1e-5 assert net.res_trafo3w.i_mv_ka.at[t3] > 1e-5 assert 0.790 < net.res_trafo3w.p_hv_mw.at[t3] < 0.810 # open switch at lv and mv side - lv and mv is disconnected, t3 in open loop pp.create_switch(net, bus=mv, element=t3, et="t3", closed=False) runpp_with_consistency_checks(net) assert np.isnan(net.res_bus.vm_pu.at[lv]) assert np.isnan(net.res_bus.vm_pu.at[mv]) assert net.res_trafo3w.i_lv_ka.at[t3] < 1e-5 assert net.res_trafo3w.i_mv_ka.at[t3] < 1e-5 assert 0 < net.res_trafo3w.p_hv_mw.at[t3] < 1
def test_makeYbus(): # tests if makeYbus fails for nets where every bus is connected to each other net = pp.create_empty_network() b1, b2, l1 = add_grid_connection(net) # number of buses to create n_bus = 20 bus_list = [] # generate buses and connect them for _ in range(n_bus): bus_list.append(pp.create_bus(net, vn_kv=20.)) # connect the first bus to slack node create_test_line(net, bus_list[0], b2) # iterate over every bus and add connection to every other bus for bus_1 in bus_list: for bus_2 in bus_list: # add no connection to itself if bus_1 == bus_2: continue create_test_line(net, bus_1, bus_2) assert runpp_with_consistency_checks(net)
def test_storage_pf(): net = pp.create_empty_network() b1 = pp.create_bus(net, vn_kv=0.4) b2 = pp.create_bus(net, vn_kv=0.4) pp.create_line(net, b1, b2, length_km=5, std_type="NAYY 4x50 SE") pp.create_ext_grid(net, b2) pp.create_load(net, b1, p_kw=10) pp.create_sgen(net, b1, p_kw=-10) # test generator behaviour pp.create_storage(net, b1, p_kw=-10, max_e_kwh=10) pp.create_sgen(net, b1, p_kw=-10, in_service=False) res_gen_beh = runpp_with_consistency_checks(net) res_ll_stor = net["res_line"].loading_percent.iloc[0] net["storage"].in_service.iloc[0] = False net["sgen"].in_service.iloc[1] = True runpp_with_consistency_checks(net) res_ll_sgen = net["res_line"].loading_percent.iloc[0] assert np.isclose(res_ll_stor, res_ll_sgen) # test load behaviour pp.create_load(net, b1, p_kw=10, in_service=False) net["storage"].in_service.iloc[0] = True net["storage"].p_kw.iloc[0] = 10 net["sgen"].in_service.iloc[1] = False res_load_beh = runpp_with_consistency_checks(net) res_ll_stor = net["res_line"].loading_percent.iloc[0] net["storage"].in_service.iloc[0] = False net["load"].in_service.iloc[1] = True runpp_with_consistency_checks(net) res_ll_load = net["res_line"].loading_percent.iloc[0] assert np.isclose(res_ll_stor, res_ll_load) assert res_gen_beh and res_load_beh
def two_ext_grids_at_one_bus(): net = pp.create_empty_network() b1 = pp.create_bus(net, vn_kv=110, index=3) b2 = pp.create_bus(net, vn_kv=110, index=5) pp.create_ext_grid(net, b1, vm_pu=1.01, index=2) pp.create_line(net, b1, b2, 1., std_type="305-AL1/39-ST1A 110.0") pp.create_load(net, bus=b2, p_mw=3.5, q_mvar=1) pp.create_gen(net, b1, vm_pu=1.01, p_mw=1) runpp_with_consistency_checks(net) assert net.converged # connect second ext_grid to b1 with different angle but out of service eg2 = pp.create_ext_grid(net, b1, vm_pu=1.01, va_degree=20, index=5, in_service=False) runpp_with_consistency_checks( net) # power flow still converges since eg2 is out of service assert net.converged # error is raised after eg2 is set in service net.ext_grid.in_service.at[eg2] = True with pytest.raises(UserWarning): pp.runpp(net) # error is also raised when eg2 is connected to first ext_grid through bus-bus switch b3 = pp.create_bus(net, vn_kv=110) pp.create_switch(net, b1, b3, et="b") net.ext_grid.bus.at[eg2] = b3 with pytest.raises(UserWarning): pp.runpp(net) # no error is raised when voltage angles are not calculated runpp_with_consistency_checks(net, calculate_voltage_angles=False) assert net.converged # same angle but different voltage magnitude also raises an error net.ext_grid.vm_pu.at[eg2] = 1.02 net.ext_grid.va_degree.at[eg2] = 0 with pytest.raises(UserWarning): pp.runpp(net)
def test_bb_switch(): net = pp.create_empty_network() net = add_test_bus_bus_switch(net) runpp_with_consistency_checks(net)