def make_A(Y_series, Y_shunt, pq, pv, pqpv): # create system matrix A of the model 4 of the Wallace article N = len(Y_shunt) NPQ = len(pq) NPV = len(pv) NPQPV = NPQ + NPV dij_y = dia_matrix((Y_shunt, zeros(1)), shape=(N, N)).tocsc() dij = dia_matrix((ones(N), zeros(1)), shape=(N, N)).tocsc() G = Y_series.real B = Y_series.imag A1 = (G + dij_y.real)[pqpv, :][:, pqpv] A2 = (B - dij_y.imag)[pqpv, :][:, pqpv] M = (B - dij_y.imag) M[:, pv] = zeros((N, 1)) APQ3 = M[pq, :][:, pqpv] M = (G + dij_y.imag) M[:, pv] = zeros((N, 1)) APQ4 = M[pq, :][:, pqpv] APV3 = (2 * dij)[pv, :][:, pqpv] APV4 = csc_matrix((NPV, NPQPV)) A = sp_vstack((sp_hstack((A1, A2)), sp_hstack( (APQ3, APQ4)), sp_hstack((APV3, APV4)))).tocsc() print("\ndij_y:\n", dij_y.toarray()) print("\ndij:\n", dij.toarray()) print("\nA1:\n", A1.toarray()) print("\nA2:\n", A2.toarray()) print("\nAPQ3:\n", APQ3.toarray()) print("\nAPQ4:\n", APQ4.toarray()) print("\nAPV3:\n", APV3.toarray()) print("\nAPV4:\n", APV4.toarray()) return A, NPQPV
def make_A2(Y_series, Y_shunt, pq, pv, pqpv, types): """ Args: Y_series: series admittances matrix Y_shunt: shunt admittances vector pq: pv: Returns: """ # create system matrix A of the model 4 of the Wallace article NPQ = len(pq) NPV = len(pv) NPQPV = NPQ + NPV dij_y = dia_matrix((Y_shunt[pqpv], zeros(1)), shape=(NPQPV, NPQPV)).tocsc() dij_pv = coo_matrix((ones(NPV) * 2, (linspace(0, NPV - 1, NPV), pv)), shape=(NPV, NPQPV)).tocsc() G = Y_series.real[pqpv, :][:, pqpv] B = Y_series.imag[pqpv, :][:, pqpv] Gpq = csc_matrix((NPQ, NPQPV)) Bpq = csc_matrix((NPQ, NPQPV)) dij_y_pq = csc_matrix((NPQ, NPQPV), dtype=complex_type) ii = 0 for i, ti in enumerate(types): if ti == 1: jj = 0 for j, tj in enumerate(types): if tj == 1: Gpq[ii, jj] = Y_series.real[i, j] Bpq[ii, jj] = Y_series.imag[i, j] if ii == jj: dij_y_pq[ii, jj] = Y_shunt[i] if tj == 1 or tj == 2: jj += 1 ii += 1 print('G:\n', Y_series.real.toarray()) print('B:\n', Y_series.imag.toarray()) print('dij_y_pq:\n', dij_y_pq.toarray()) A1 = G + dij_y.real print('\nA1:\n', G.toarray(), '\n+\n', dij_y.real.toarray()) A2 = B - dij_y.imag print('\nA2:\n', B.toarray(), '\n-\n', dij_y.imag.toarray()) APQ3 = Bpq - dij_y_pq.imag print('\nA_PQ3:\n', Bpq.toarray(), '\n-\n', dij_y_pq.imag.toarray()) APQ4 = Gpq + dij_y_pq.real print('\nA_PQ4:\n', Gpq.toarray(), '\n+\n', dij_y_pq.real.toarray()) APV3 = dij_pv print('\nA_PV3:\n', dij_pv.toarray()) APV4 = csc_matrix((NPV, NPQPV)) print('\nA_PV4:\n', APV4.toarray()) A = sp_vstack((sp_hstack((A1, A2)), sp_hstack( (APQ3, APQ4)), sp_hstack((APV3, APV4)))).tocsc() return A, NPQPV