Skip to content

Commit 3c4525a

Browse files
committed
Add sym power validation test
Signed-off-by: furqan463 <[email protected]>
1 parent 1fdb9ea commit 3c4525a

File tree

1 file changed

+103
-2
lines changed

1 file changed

+103
-2
lines changed

tests/validation/converters/test_pandapower_converter_output.py

Lines changed: 103 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,27 @@ def _get_total_powers_3ph(net):
306306
else:
307307
s_load_sym = complex128()
308308

309-
s_load = s_load_sym + s_load_asym
309+
if "res_motor_3ph" in net:
310+
s_motor = net.res_motor_3ph.loc[:, "p_mw"].sum() + 1j * net.res_motor_3ph.loc[:, "q_mvar"].sum()
311+
else:
312+
s_motor = complex128()
313+
314+
if "res_ward_3ph" in net:
315+
s_ward = (
316+
net.res_ward_3ph.loc[:, ["p_a_mw", "p_b_mw", "p_c_mw"]].sum().sum()
317+
+ 1j * net.res_ward_3ph.loc[:, ["q_a_mvar", "q_b_mvar", "q_c_mvar"]].sum().sum()
318+
)
319+
else:
320+
s_ward = complex128()
321+
322+
# TODO: enable res_shunt_3ph when implemented, right now the table exists but columns not defined.
323+
# if "res_shunt_3ph" in net:
324+
# print(net.res_shunt_3ph)
325+
# s_shunt = net.res_shunt_3ph.loc[:, "p_mw"].sum() + 1j * net.res_shunt_3ph.loc[:, "q_mvar"].sum()
326+
# else:
327+
s_shunt = complex128()
328+
329+
s_load = s_load_sym + s_load_asym + s_motor + s_ward + s_shunt
310330

311331
if "res_line_3ph" in net:
312332
s_loss_line = (
@@ -316,7 +336,7 @@ def _get_total_powers_3ph(net):
316336
else:
317337
s_loss_line = complex128()
318338

319-
if "res_line_3ph" in net:
339+
if "res_trafo_3ph" in net:
320340
s_loss_trafo = (
321341
net.res_trafo_3ph.loc[:, ["p_a_l_mw", "p_b_l_mw", "p_c_l_mw"]].sum().sum()
322342
+ 1j * net.res_trafo_3ph.loc[:, ["q_a_l_mvar", "q_b_l_mvar", "q_c_l_mvar"]].sum().sum()
@@ -356,3 +376,84 @@ def run_pf_asym_with_pgm(net):
356376
run_pf_asym_with_pgm(net)
357377
s_ext_grid, s_load, s_loss = _get_total_powers_3ph(net)
358378
assert isclose(s_ext_grid, (s_load + s_loss))
379+
380+
381+
def _get_total_powers(net):
382+
"""
383+
Calculates total complex power for sources, loads and losses
384+
Input: Pandapower Network
385+
Output: [s_ext_grid, s_load, s_loss]
386+
"""
387+
from numpy import complex128
388+
389+
s_ext_grid = net.res_ext_grid.loc[:, "p_mw"].sum() + 1j * net.res_ext_grid.loc[:, "q_mvar"].sum()
390+
391+
if "res_asymmetric_load" in net:
392+
s_load_asym = net.res_asymmetric_load.loc[:, "p_mw"].sum() + 1j * net.res_asymmetric_load.loc[:, "q_mvar"].sum()
393+
else:
394+
s_load_asym = complex128()
395+
396+
if "res_load" in net:
397+
s_load_sym = net.res_load.loc[:, "p_mw"].sum() + 1j * net.res_load.loc[:, "q_mvar"].sum()
398+
else:
399+
s_load_sym = complex128()
400+
401+
if "res_motor" in net:
402+
s_motor = net.res_motor.loc[:, "p_mw"].sum() + 1j * net.res_motor.loc[:, "q_mvar"].sum()
403+
else:
404+
s_motor = complex128()
405+
406+
if "res_ward" in net:
407+
s_ward = net.res_ward.loc[:, "p_mw"].sum() + 1j * net.res_ward.loc[:, "q_mvar"].sum()
408+
else:
409+
s_ward = complex128()
410+
411+
if "res_shunt" in net:
412+
s_shunt = net.res_shunt.loc[:, "p_mw"].sum() + 1j * net.res_shunt.loc[:, "q_mvar"].sum()
413+
else:
414+
s_shunt = complex128()
415+
416+
s_load = s_load_sym + s_load_asym + s_motor + s_ward + s_shunt
417+
418+
if "res_line" in net:
419+
s_loss_line = net.res_line.loc[:, "pl_mw"].sum() + 1j * net.res_line.loc[:, "ql_mvar"].sum()
420+
else:
421+
s_loss_line = complex128()
422+
423+
if "res_trafo" in net:
424+
s_loss_trafo = net.res_trafo.loc[:, "pl_mw"].sum() + 1j * net.res_trafo.loc[:, "ql_mvar"].sum()
425+
else:
426+
s_loss_trafo = complex128()
427+
428+
s_loss = s_loss_line + s_loss_trafo
429+
return [s_ext_grid, s_load, s_loss]
430+
431+
432+
def test_output_data__powers():
433+
def run_pf_sym_with_pgm(net):
434+
from pandapower.results import reset_results
435+
from power_grid_model import PowerGridModel
436+
437+
reset_results(net, "pf")
438+
pgm_converter = PandaPowerConverter()
439+
input_data, _ = pgm_converter.load_input_data(net, make_extra_info=False)
440+
pgm = PowerGridModel(input_data)
441+
output_data = pgm.calculate_power_flow(symmetric=True)
442+
output_tables = pgm_converter.convert(output_data)
443+
for table in output_tables.keys():
444+
net[table] = output_tables[table]
445+
446+
from numpy import isclose
447+
from pandapower.networks import ieee_european_lv_asymmetric
448+
449+
net = ieee_european_lv_asymmetric()
450+
run_pf_sym_with_pgm(net)
451+
s_ext_grid, s_load, s_loss = _get_total_powers(net)
452+
assert isclose(s_ext_grid, (s_load + s_loss))
453+
454+
pp.create_motor(net, 100, 0.1, 0.9)
455+
pp.create_ward(net, 200, 0.1, 0.05, 0.1, 0.05)
456+
pp.create_shunt_as_capacitor(net, 150, 0.09, 0)
457+
run_pf_sym_with_pgm(net)
458+
s_ext_grid, s_load, s_loss = _get_total_powers(net)
459+
assert isclose(s_ext_grid, (s_load + s_loss))

0 commit comments

Comments
 (0)