rwl / PYPOWER

Port of MATPOWER to Python
http://rwl.github.io/PYPOWER/api/
Other
340 stars 113 forks source link

DC power flow error with Scipy version 0.15 #16

Open rwl opened 9 years ago

rwl commented 9 years ago

As reported by Puneet on the mailing list:

When I try to run DC power flow I get following error:

PYPOWER Version 4.1.2, 27-Oct-2014 -- DC Power Flow

Traceback (most recent call last): File "<pyshell#15>", line 1, in rundcpf(mpc) File "C:\Python27\lib\site-packages\pypower\rundcpf.py", line 39, in rundcpf return runpf(casedata, ppopt, fname, solvedcase) File "C:\Python27\lib\site-packages\pypower\runpf.py", line 139, in runpf Va = dcpf(B, Pbus, Va0, ref, pv, pq) File "C:\Python27\lib\site-packages\pypower\dcpf.py", line 46, in dcpf Va[pvpq] = spsolve(B[pvpq.T, pvpq], Pbus[pvpq] - B[pvpq.T, ref] * Va0[ref]) File "C:\Python27\lib\site-packages\scipy\sparse\linalg\dsolve\linsolve.py", line 108, in spsolve % (A.shape, b.shape[0])) ValueError: matrix - rhs dimension mismatch ((8, 8) - 1)

Based on this error it seems that latest Scipy version (0.15) is not compatible with PyPower.

rwl commented 9 years ago

Solution proposed by Puneet on the mailing list:

Finally I have found the error. There is a bug in the dc power flow function of the Pypower Version 4.1.2. In the "dcpf.py" function in the statement:

Va[pvpq] = spsolve(B[pvpq.T, pvpq], Pbus[pvpq] - B[pvpq.T, ref] * Va0[ref])

The second argument to the spsolve function is a row vector instead of the column vector. The shape[0] command in the spsolve thus produces matrix dimension error. Just transposing it resolves the error.

proggy commented 7 years ago

Bug still exists in Pypower 5.0.1, suggested patch works.