e2nIEE / pandapower

Convenient Power System Modelling and Analysis based on PYPOWER and pandas
https://www.pandapower.org
Other
847 stars 478 forks source link

`net.res_bus['p_mw']` and `net.res_bus['q_mvar']` do not match `net._ppc['internal']['Sbus']` #1851

Open christian-cahig opened 1 year ago

christian-cahig commented 1 year ago

Issue Report Checklist

Problem Description

I was doing power flow with the 1888RTE power system test case as follows.

import pandapower as pp
import pandapower.networks as pn
import numpy as np

net = pn.case1888rte(ref_bus_idx=1246) # Default reference bus
pp.runpp(net, calculate_voltage_angles=True)

Out of curiosity, I checked how net.res_bus['p_mw'] and net.res_bus['q_mvar'] (in per-unit values) relate to net._ppc['internal']['Sbus'],

Sbus_ppc = net._ppc['internal']['Sbus']
Pbus_res = net.res_bus['p_mw'] / net._ppc['internal']['baseMVA']
Qbus_res = net.res_bus['q_mvar'] / net._ppc['internal']['baseMVA']

expecting that they should be (at least approximately) equal. It turns out they are not:

>> np.allclose(-Sbus_ppc.real, Pbus_res), np.allclose(-Sbus_ppc.imag, Qbus_res)
(False, False)
>> np.linalg.norm(-Sbus_ppc.real-Pbus_res, ord=np.Inf), np.linalg.norm(-Sbus_ppc.imag-Qbus_res, ord=np.Inf)
(9.90900993480918, 2.735374118364189)

I also tried comparing net.res_bus values to the net injections calculated via the voltage phasors and the admittance matrix, i.e.,

Sbus_eqn = net._ppc['internal']['V'] * (net._ppc['internal']['Ybus'].dot(net._ppc['internal']['V']).conj())

and got lucky with the active component:

>> np.allclose(-Sbus_eqn.real, Pbus_res), np.allclose(-Sbus_eqn.imag, Qbus_res)
(True, False)
>>  np.linalg.norm(-Sbus_eqn.real-Pbus_res, ord=np.Inf), np.linalg.norm(-Sbus_eqn.imag-Qbus_res, ord=np.Inf)
(8.139267038131948e-12, 2.322358397032247)

For completeness, I also compared the net injections via net._ppc['internal']['Sbus'] and those calculated:

>> np.allclose(Sbus_ppc.real, Sbus_eqn.real), np.allclose(Sbus_ppc.imag, Sbus_eqn.imag)
(False, False)
>> np.linalg.norm(Sbus_eqn.real-Sbus_ppc.real, ord=np.Inf), np.linalg.norm(Sbus_eqn.imag-Sbus_ppc.imag, ord=np.Inf)
(9.90900993480918, 2.735374118364189)

Help is much appreciated.

Versions

rbolgaryn commented 1 year ago

Dear @christian-cahig ,

this is an interesting observation, thank you.

AnkurArohi commented 1 year ago

@christian-cahig Are you sure that the comparision being made are for the same bus indices/ same bus? It could be that the S , P, Q are maybe not for the same bus, I think that the indexing sequence for the bus could be important in this case. I mean to say , _ppc and res_bus indexing could be different/ have a different starting value 0 or 1 (offset)