def case_as_data(casename): ''' Loads the case according to its name. Possible names are: ['case4gs', 'case6ww', 'case9', 'case9Q', 'case14', 'case24_ieee_rts', 'case30', 'case30Q', 'case30pwl', 'case39', 'case57', 'case118', 'case300', 'case30_userfcns']. ''' # list of available cases cases = [ 'case4gs', 'case6ww', 'case9', 'case9Q', 'case14', 'case24_ieee_rts', 'case30', 'case30Q', 'case30pwl', 'case39', 'case57', 'case118', 'case300', 'case30_userfcns' ] if casename not in cases: print('Case not found, defaults to case9') casename_ = 'case9' else: casename_ = casename case_path = join('pypower', casename_) data = ext2int(loadcase(case_path)) return data
def getYfromPyPower(self): sysN, sysopt = opf_args.opf_args2(self.sys) sysN = pyp.ext2int(sysN) #sysopt = pyp.ppoption(sysopt, OPF_ALG=0, VERBOSE=3) om = pyp.opf_setup(sysN, sysopt) sysN = om.get_ppc() baseMVA = sysN['baseMVA'] branch = sysN['branch'] bus = sysN['bus'] Y, Yf, Yt = pyp.makeYbus(baseMVA, bus, branch) return Y, Yf, Yt
def get_Jac(ppc, ppopt, results): ppc = ext2int(ppc) baseMVA, bus, gen, branch = \ ppc["baseMVA"], ppc["bus"], ppc["gen"], ppc["branch"] Ybus, Yf, Yt = makeYbus(baseMVA, bus, branch) #print(Ybus.shape) #print(Yf.shape) #print(Yt.shape) x = results['x'] om = opf_setup(ppc, ppopt) g, geq, dg, dgeq = opf_consfcn(x, om, Ybus, Yf, Yt, ppopt) return dg.T, dgeq.T
def _get_param(self): # delect the disturbances not defined in the set_disturb, and renumber the new disturbance set. for d_type in {1, 2, 3, 4}: i_d_all = list() for i_d in range(len(self.casedata['disturbance'][d_type])): if (d_type, self.casedata['disturbance'][d_type][i_d, 0] ) in self.set_disturb: i_d_all.append(i_d) self.casedata['disturbance'][d_type] = self.casedata[ 'disturbance'][d_type][i_d_all, :] for i_d in range(len(self.casedata['disturbance'][d_type])): self.casedata['disturbance'][d_type][i_d, 0] = i_d + 1 if len(self.casedata['disturbance'][d_type]) == 0: del self.casedata['disturbance'][d_type] # parameters if len(self.casedata['bus']) >= 200 or len(self.casedata['bus']) == 59: opt = ppoption(PF_TOL=1e-12, PF_MAX_IT=20) else: opt = ppoption(PF_TOL=1e-13, PF_MAX_IT=20) s_pf = runpf(self.casedata, opt) pcc_y = ext2int(self.casedata) Ybus = makeYbus(pcc_y["baseMVA"], pcc_y["bus"], pcc_y["branch"])[0].toarray() n_bus = len(Ybus) B_0 = np.imag(Ybus) for i in range(len(B_0)): B_0[i, i] = 0 pg_0 = np.zeros(n_bus) pg_0[(s_pf[0]['gen'][:, 0] - 1).astype(int)] = s_pf[0]['gen'][:, 1] i_gen = self.casedata['gen'][:, 0].astype(int).tolist() i_non_0 = (np.where(self.casedata['bus'][:, 2] == 0)[0] + 1).tolist() i_non = list(set(i_non_0).difference(set(i_gen))) i_load_0 = list( set(self.casedata['bus'][:, 0].astype(int).tolist()).difference( set(i_gen))) i_load = list(set(i_load_0).difference(set(i_non))) self.Ybus = Ybus self.n_bus = n_bus self.B_0 = B_0 self.v_0 = s_pf[0]['bus'][:, 7] self.theta_0 = np.radians(s_pf[0]['bus'][:, 8]) self.pl_0 = s_pf[0]['bus'][:, 2] / 100.0 self.pg_0 = pg_0 / 100.0 self.w_0 = np.zeros(self.n_bus) self.i_gen = i_gen self.i_non = i_non self.i_load = i_load self.i_gl = i_gen + i_load self.i_all = self.casedata['bus'][:, 0].astype(int).tolist() self.theta_gl_0 = self.theta_0[(np.array(self.i_gl) - 1).tolist()] # initial values and bounds of optimization variables self.m_0, self.m_l, self.m_u = dict(), dict(), dict() self.d_0, self.d_l, self.d_u = dict(), dict(), dict() self.M = self.casedata['bus'][:, 13].tolist() self.D = self.casedata['bus'][:, 14].tolist() for i in self.i_gen: i_gc = np.where(self.casedata['gencontrol'][:, 0] == i)[0] i_bus = np.where(self.casedata['bus'][:, 0] == i)[0][0] self.m_0[i] = self.M[i_bus] self.m_l[i] = self.casedata['gencontrol'][i_gc, 2][0] self.m_u[i] = self.casedata['gencontrol'][i_gc, 3][0] self.d_0[i] = self.D[i_bus] self.d_l[i] = self.casedata['gencontrol'][i_gc, 4][0] self.d_u[i] = self.casedata['gencontrol'][i_gc, 5][0] # set of index for each kind of branch, used for computing the objective function self.ind_branch = list( ) # index set [(ind_bus_from, ind_bus_to)] of all branch for i_b in self.casedata['branch'][:, [0, 1]]: self.ind_branch.append((int(i_b[0]), int(i_b[1]))) set_k_i = list() # list of (k,i) of all disturbances and time elements for k0 in self.casedata['disturbance'].keys(): if k0 != 9: for k1 in self.casedata['disturbance'][k0][:, 0]: for i in range( 1, self.casedata['param_disc']['time_ele'][k0] + 1): set_k_i.append(((int(k0), int(k1)), i)) self.set_k_i = set_k_i
pOption.remove(bestIdx) pIdx.append(bestIdx) pilotBus = [lIdx[i] for i in pIdx] return pilotBus if __name__ == '__main__': print('-----------Start-----------') ppc, success = runpf(case9()) ppc = ext2int(ppc) baseMVA = ppc['baseMVA'] bus = ppc['bus'] branch = ppc['branch'] Ybus, Yf, Yt = makeYbus(baseMVA, bus, branch) vm = bus[:, VM] va = 2 * np.pi * bus[:, VA] V = vm * np.exp(1j * va) gIdx = [0, 1, 2] lIdx = [3, 4, 5, 6, 7, 8] nPilot = 2 pilotBus = findPilot(Ybus, V, gIdx, lIdx, nPilot)