def Cartesianbii( Bi , e , Gi , f , i ): lengthArray = [ len(Gi) , len(e) , len(Bi) , len(f) ] length = isSameLength( lengthArray ) bii = 0 for j in range(0,length): bii = bii + ( Gi[j]*f[j] + Bi[j]*e[j] ) return bii[0,0]
def CartesianQi( G , e , B , f , i ): lengthArray = [ len(G[i].T) , len(e) , len(B[i].T) , len(f) ] length = isSameLength( lengthArray ) Qi = 0 for j in range(0,length): Qi = Qi + f[i]*( G[i,j]*e[j] - B[i,j]*f[j] ) - e[i]*( G[i,j]*f[j] + B[i,j]*e[j] ) return Qi[0,0]
def Cartesianaii( Gi , e , Bi , f , i ): lengthArray = [ len(Gi) , len(e) , len(Bi) , len(f) ] length = isSameLength( lengthArray ) aii = 0 for j in range(0,length): aii = aii + ( Gi[j,0]*e[j] - Bi[j,0]*f[j] ) return aii[0,0]
def CartesianPi( G , e , B , f , i ): lengthArray = [ len(G[i].T) , len(e) , len(B[i].T) , len(f) ] length = isSameLength( lengthArray ) Pi = 0 for j in range(0,length): Pi = Pi + e[i]*( G[i,j]*e[j] - B[i,j]*f[j] ) + f[i]*( G[i,j]*f[j] + B[i,j]*e[j] ) return Pi[0,0]
def PolarQi( U , G , B , delta , i ): lengthArray = [ len(G[i]) , len(U) , len(B[i]) , len(delta[i]) ] length = isSameLength( lengthArray ) Qi = 0 for j in range(0,length): tempDelta = delta[i][j]*np.pi/180 Qi = Qi + U[j]*( G[i][j]*np.sin(tempDelta) - B[i][j]*np.cos(tempDelta) ) Qi = Qi*U[i] return Qi[0,0]
def PolarPi( U , G , B , delta , i ): lengthArray = [ len(G[i]) , len(U) , len(B[i]) , len(delta[i]) ] length = isSameLength( lengthArray ) Pi = 0 for j in range(0,length): tempDelta = delta[i][j]*np.pi/180 Pi = Pi + U[j]*( G[i][j]*np.cos(tempDelta) + B[i][j]*np.sin(tempDelta) ) Pi = Pi*U[i] return Pi[0,0]
def PolarJii( U , Gi , Bi , deltai , i ): lengthArray = [ len(U) , len(Gi) , len(Bi) , len(deltai) ] length = isSameLength( lengthArray ) Jii = 0 for j in range(0,length): tempDelta = deltai[j]*np.pi/180 Jii = Jii + U[j]*( Gi[j]*np.cos(tempDelta)+Bi[j]*np.sin(tempDelta) ) tempDelta = deltai[i]*np.pi/180 Jii = Jii - U[i]*( Gi[i]*np.cos(tempDelta)+Bi[i]*np.sin(tempDelta) ) Jii = U[i]*Jii return Jii[0,0]
def getJacobianMatrix(G, B, U, UAccu, isPolar=False): """Get Jacobian Matrix from original Bus Admittance Matrix Args: G: matrix, Bus Admittance Matrix B: matrix, U: matrix, isPolar: boolean, (False by default) Indicate whether node-voltage equations are polar form, if False, these equations are rectangular form. Returns: matrix, Generated Jacobian Matrix @TODO: The doc """ order = errors.isSameLength([errors.isSquareMatrix(G), errors.isSquareMatrix(B), U.shape[0]]) """ @TODO: UAccu index 0 problem """ subOrder = UAccu.shape[0] subOrder = 0 tempJacMat = [] if isPolar == False: upperBound1 = int(order - subOrder) upperBound2 = int(order) for i in range(1, upperBound1): tempArray = [] for j in range(1, upperBound2): tempArray.append(jpA.CartesianHijA(B, U[:, 0], G, U[:, 1], i, j)) tempArray.append(jpA.CartesianNijA(B, U[:, 0], G, U[:, 1], i, j)) tempJacMat.append(tempArray) tempArray = [] for j in range(1, upperBound2): tempArray.append(jpA.CartesianJijA(B, U[:, 0], G, U[:, 1], i, j)) tempArray.append(jpA.CartesianLijA(B, U[:, 0], G, U[:, 1], i, j)) tempJacMat.append(tempArray) for i in range(upperBound1, upperBound2): tempArray = [] for j in range(1, upperBound2): tempArray.append(jpA.CartesianHijA(B, U[:, 0], G, U[:, 1], i, j)) tempArray.append(jpA.CartesianNijA(B, U[:, 0], G, U[:, 1], i, j)) tempJacMat.append(tempArray) tempArray = [] for j in range(1, upperBound2): tempArray.append(jpA.CartesianRijA(U[:, 1], i, j)) tempArray.append(jpA.CartesianSijA(U[:, 0], i, j)) tempJacMat.append(tempArray) """ @TODO: The polar coordinate part """ jacMat = np.matrix(tempJacMat) return jacMat
def difff(P, Q, B, G, U, UAccu): """ @TODO: doc @TODO: subOrder = 0 @TODO: polar system """ order = errors.isSameLength( [errors.isSquareMatrix(B), errors.isSquareMatrix(G), U.shape[0], P.shape[0] + 1, Q.shape[0] + 1] ) subOrder = UAccu.shape[0] subOrder = 0 deltaf = [] upperBound1 = int(order - subOrder) upperBound2 = int(order) for i in range(1, upperBound1): deltaf.append((P[i - 1] - nve.CartesianPi(G, U[:, 0], B, U[:, 1], i))[0, 0]) deltaf.append((Q[i - 1] - nve.CartesianQi(G, U[:, 0], B, U[:, 1], i))[0, 0]) for i in range(upperBound1, upperBound2): deltaf.append((P[i - upperBound1] - nve.CartesianPi(G, U[:, 0], B, U[:, 1], i))[0, 0]) deltaf.append(UAccu[i - upperBound1] ** 2 - U[i, 0] ** 2 - U[i, 1] ** 2) return np.matrix(deltaf).T