Problem with alignment in newtonpf

32 views
Skip to first unread message

christos...@gmail.com

unread,
Apr 25, 2016, 12:41:31 PM4/25/16
to pypower
Hello to everyone! 

if i send this, 

V, converged, i = newtonpf(Y_bus2, Injection_Vector2, Voltage_Vector2, Slack_Bus_Index, PV_Bus_Index_Array, np.asarray(PQ_Bus_Index_Array), ppopt = None)

i take this: 


  File "<ipython-input-103-cec7e5ebdab8>", line 1, in <module>
    V, converged, i = newtonpf(Y_bus2, Injection_Vector2, Voltage_Vector2, Slack_Bus_Index, PV_Bus_Index_Array, np.asarray(PQ_Bus_Index_Array), ppopt = None)
  File "C:\Python27\lib\site-packages\pypower\newtonpf.py", line 88, in newtonpf
    dS_dVm, dS_dVa = dSbus_dV(Ybus, V)
  File "C:\Python27\lib\site-packages\pypower\dSbus_dV.py", line 63, in dSbus_dV
    Ibus = Ybus * asmatrix(V).T
  File "C:\Python27\lib\site-packages\numpy\matrixlib\defmatrix.py", line 347, in __rmul__
    return N.dot(other, self)

ValueError: shapes (15,15) and (1,15) not aligned: 15 (dim 1) != 1 (dim 0)


Voltage vector is type, ndarray (15,1) so if i transpose with 

V, converged, i = newtonpf(Y_bus2, Injection_Vector2, Voltage_Vector2.T, Slack_Bus_Index, PV_Bus_Index_Array, np.asarray(PQ_Bus_Index_Array), ppopt = None)

i take

Traceback (most recent call last):

  File "<ipython-input-104-facad8187c25>", line 1, in <module>
    V, converged, i = newtonpf(Y_bus2, Injection_Vector2, Voltage_Vector2.T, Slack_Bus_Index, PV_Bus_Index_Array, np.asarray(PQ_Bus_Index_Array), ppopt = None)
  File "C:\Python27\lib\site-packages\pypower\newtonpf.py", line 88, in newtonpf
    dS_dVm, dS_dVa = dSbus_dV(Ybus, V)
  File "C:\Python27\lib\site-packages\pypower\dSbus_dV.py", line 69, in dSbus_dV
    dS_dVm = diagV * conj(Ybus * diagVnorm) + conj(diagIbus) * diagVnorm
  File "C:\Python27\lib\site-packages\numpy\matrixlib\defmatrix.py", line 347, in __rmul__
    return N.dot(other, self)

ValueError: shapes (15,15) and (1,1) not aligned: 15 (dim 1) != 1 (dim 0)


Any help, please?Just for information, PV_Bus_Index_Array is an empty list, and Slack_Bus_Index is an integer. 

Thank you, 
Christos 



christos...@gmail.com

unread,
Apr 25, 2016, 12:41:31 PM4/25/16
to pypower
Hello to everyone, 

I have the following problem: 
  

  File "<ipython-input-80-eef312a6d54b>", line 1, in <module>
    V, converged, i = newtonpf(Y_bus2, Injection_Vector2, Voltage_Vector2, Slack_Bus_Index, PV_Bus_Index_Array, PQ_Bus_Index_Array, ppopt = None)


  File "C:\Python27\lib\site-packages\pypower\newtonpf.py", line 88, in newtonpf
    dS_dVm, dS_dVa = dSbus_dV(Ybus, V)

  File "C:\Python27\lib\site-packages\pypower\dSbus_dV.py", line 63, in dSbus_dV
    Ibus = Ybus * asmatrix(V).T

  File "C:\Python27\lib\site-packages\numpy\matrixlib\defmatrix.py", line 347, in __rmul__
    return N.dot(other, self)

ValueError: shapes (15,15) and (1,15) not aligned: 15 (dim 1) != 1 (dim 0)

If i send this, 

V, converged, i = newtonpf(Y_bus2, Injection_Vector2, Voltage_Vector2.T, Slack_Bus_Index, PV_Bus_Index_Array, PQ_Bus_Index_Array, ppopt = None)

then: 


  File "<ipython-input-81-8f77f83c7a52>", line 1, in <module>
    V, converged, i = newtonpf(Y_bus2, Injection_Vector2, Voltage_Vector2.T, Slack_Bus_Index, PV_Bus_Index_Array, PQ_Bus_Index_Array, ppopt = None)

  File "C:\Python27\lib\site-packages\pypower\newtonpf.py", line 88, in newtonpf
    dS_dVm, dS_dVa = dSbus_dV(Ybus, V)

  File "C:\Python27\lib\site-packages\pypower\dSbus_dV.py", line 69, in dSbus_dV
    dS_dVm = diagV * conj(Ybus * diagVnorm) + conj(diagIbus) * diagVnorm

  File "C:\Python27\lib\site-packages\numpy\matrixlib\defmatrix.py", line 347, in __rmul__
    return N.dot(other, self)

ValueError: shapes (15,15) and (1,1) not aligned: 15 (dim 1) != 1 (dim 0)



I guess I miss something with the vectors in this call of the function, maybe the following is helpful:

My voltage & injection vectors are type: numpy.ndarray (15,1)

type(Slack_Bus_Index) int

type(PV_Bus_Index_Array) list
(empty list)


type(PQ_Bus_Index_Array) list

Thank you for your time, 
Christos 


christos...@gmail.com

unread,
Apr 27, 2016, 6:21:12 AM4/27/16
to pypower, christos...@gmail.com

Hello to everyone again, 


So i checked a bit the implementation matlab and the corresponding in python of the inside function ( def dSbus_dV(Ybus, V)  ) of the newtonpf and I have noticed that the implementation is not the same. 

If the matrix is not sparse (like my case), then the commands are:  

Ibus = Ybus * asmatrix(V).T

        diagV = asmatrix(diag(V))
        diagIbus = asmatrix(diag( asarray(Ibus).flatten() ))
        diagVnorm = asmatrix(diag(V / abs(V)))

    dS_dVm = diagV * conj(Ybus * diagVnorm) + conj(diagIbus) * diagVnorm
    dS_dVa = 1j * diagV * conj(diagIbus - Ybus * diagV)

So first in order to perform the first line, in the newtonpf definition the parametere of the initial voltage vector should be sent as transpose (I did this). This however in matlab is not needed since the multiplication is performed outside and in the initial form of the vector. 

After that, the problem in my code is in the following line: 

dS_dVm = diagV * conj(Ybus * diagVnorm) + conj(diagIbus) * diagVnorm

Since Ybys for my case is (15,15) and diagVnorm is MATRIX (1,1) then 

Ybus * diagVnorm can not be performed. 

So is that a real error in the script or i am mistaken? Any proposals? 

Best, 
Christos

Reply all
Reply to author
Forward
0 new messages