def __init__(self): # psse self._psspy = psspy psspy.psseinit(0) psspy.report_output(6, '', []) psspy.progress_output(6, '', []) psspy.alert_output(6, '', []) psspy.prompt_output(6, '', []) return None
def run_savnw_simulation(datapath, outfile1, outfile2, outfile3, prgfile): import psspy psspy.psseinit() savfile = 'Converted_NETS-NYPS 68 Bus System_C.sav' snpfile = 'NETS-NYPS 68 Bus System.snp' if datapath: savfile = os.path.join(datapath, savfile) snpfile = os.path.join(datapath, snpfile) #why produce these two kinds of files? psspy.lines_per_page_one_device(1, 90) psspy.progress_output(2, prgfile, [0, 0]) ierr = psspy.case(savfile) if ierr: psspy.progress_output(1, "", [0, 0]) print(" psspy.case Error") return ierr = psspy.rstr(snpfile) if ierr: psspy.progress_output(1, "", [0, 0]) print(" psspy.rstr Error") return # fault + line trip psspy.strt(0, outfile1) psspy.run(0, 1.0, 1000, 1, 0) psspy.dist_bus_fault(52, 1, 138.0, [0.0, -0.2E+10]) psspy.run(0, 1.1, 1000, 1, 0) psspy.dist_clear_fault(1) psspy.dist_branch_trip(52, 55, '1') psspy.run(0, 1.2, 1000, 1, 0) psspy.dist_machine_trip(1, '1') psspy.run(0, 5.0, 1000, 1, 0) # line trip (with faults) + generator trip psspy.case(savfile) psspy.rstr(snpfile) psspy.strt(0, outfile2) psspy.run(0, 1.0, 1000, 1, 0) psspy.dist_bus_fault(52, 1, 138.0, [0.0, -0.2E+10]) psspy.run(0, 1.1, 1000, 1, 0) psspy.dist_clear_fault(1) psspy.run(0, 1.2, 1000, 1, 0) psspy.dist_machine_trip(8, '1') psspy.run(0, 5.0, 1000, 1, 0) psspy.case(savfile) psspy.rstr(snpfile) psspy.strt(0, outfile3) psspy.run(0, 1.0, 1000, 1, 0) psspy.dist_branch_trip(32, 33, '1') psspy.run(0, 5.0, 1000, 1, 0) psspy.lines_per_page_one_device(2, 10000000) psspy.progress_output(1, "", [0, 0])
def run_savnw_simulation(datapath, outfile1, outfile2, outfile3, prgfile): import psspy psspy.psseinit() savfile = 'savcnv.sav' snpfile = 'savnw.snp' if datapath: savfile = os.path.join(datapath, savfile) snpfile = os.path.join(datapath, snpfile) psspy.lines_per_page_one_device(1, 90) psspy.progress_output(2, prgfile, [0, 0]) ierr = psspy.case(savfile) if ierr: psspy.progress_output(1, "", [0, 0]) print(" psspy.case Error") return ierr = psspy.rstr(snpfile) if ierr: psspy.progress_output(1, "", [0, 0]) print(" psspy.rstr Error") return psspy.strt(0, outfile1) psspy.run(0, 1.0, 1000, 1, 0) psspy.dist_bus_fault(154, 1, 230.0, [0.0, -0.2E+10]) psspy.run(0, 1.05, 1000, 1, 0) psspy.dist_clear_fault(1) psspy.run(0, 5.0, 1000, 1, 0) psspy.case(savfile) psspy.rstr(snpfile) psspy.strt(0, outfile2) psspy.run(0, 1.0, 1000, 1, 0) psspy.dist_machine_trip(3018, '1') psspy.run(0, 5.0, 1000, 1, 0) psspy.case(savfile) psspy.rstr(snpfile) psspy.strt(0, outfile3) psspy.run(0, 1.0, 1000, 1, 0) psspy.dist_branch_trip(3005, 3007, '1') psspy.run(0, 5.0, 1000, 1, 0) psspy.lines_per_page_one_device(2, 10000000) psspy.progress_output(1, "", [0, 0])
def inicia_psse(print_alert_psse=False): """ :param print_alert_psse: Para indicar si en la consal debe aparecer las alaertas de PSSE :return: """ # start = time.clock() # Guardamos el stdout consola = sys.stdout # Abrimos archivo nulo (no existe) sys.stdout = open(os.devnull, 'w') #Redireccion de los mensajes de PSS/E a Python redirect.psse2py() #Inicializacion del numero de nudos en memoria del PSS/E psspy.psseinit(150000) # Redirigimos el stdout a la consola sys.stdout = consola if print_alert_psse: psspy.prompt_output(6, "", [0, 0]) psspy.alert_output(6, "", [0, 0]) psspy.progress_output(6, "", [0, 0])
def run_savnw_simulation(datapath, outfile, prgfile): import psspy psspy.psseinit() savfile = 'Converted_NETS-NYPS 68 Bus System_C.sav' snpfile = 'NETS-NYPS 68 Bus System.snp' if datapath: savfile = os.path.join(datapath, savfile) snpfile = os.path.join(datapath, snpfile) psspy.lines_per_page_one_device(1,90) psspy.progress_output(2,prgfile,[0,0]) # directly output to file ierr = psspy.case(savfile) if ierr: psspy.progress_output(1,"",[0,0]) print(" psspy.case Error") return ierr = psspy.rstr(snpfile) if ierr: psspy.progress_output(1,"",[0,0]) print(" psspy.rstr Error") return # branches ibus,jbus,id=read_rawdata.branch_bus() for i,gener in enumerate(all_gener): psspy.case(savfile) psspy.rstr(snpfile) psspy.strt(0,outfile[i]) psspy.run(0, 1.0,1000,1,0) dist_branch_fault(ibus[i], jbus[i], id[i]) psspy.run(0, 1.2,1000,1,0) psspy.dist_clear_fault(1) psspy.run(0, 5.0,1000,1,0) psspy.lines_per_page_one_device(2,10000000)#Integer DEVICE Indicates which of the four output devices is to be processed (input; #1 for disk files. #2 for the report window. #3 for the first primary hard copy output device. #4 for the second primary hard copy output device. psspy.progress_output(1,"",[0,0]) return outfile,prgfile
def run_savnw_simulation(datapath, outfile, prgfile): import psspy psspy.psseinit() savfile = 'Converted_NETS-NYPS 68 Bus System_C.sav' snpfile = 'NETS-NYPS 68 Bus System.snp' if datapath: savfile = os.path.join(datapath, savfile) snpfile = os.path.join(datapath, snpfile) psspy.lines_per_page_one_device(1, 90) psspy.progress_output(2, prgfile, [0, 0]) # directly output to file #psspy.chsb(0,1,[-1,-1,-1,1,13,0]) ierr = psspy.case(savfile) if ierr: psspy.progress_output(1, "", [0, 0]) print(" psspy.case Error") return ierr = psspy.rstr(snpfile) if ierr: psspy.progress_output(1, "", [0, 0]) print(" psspy.rstr Error") return # run generator trip automatically for i in range(16): psspy.case(savfile) psspy.rstr(snpfile) psspy.strt(0, outfile[i]) #psspy.chsb(0,1,[-1,-1,-1,1,13,0]) psspy.run(0, 1.0, 1000, 1, 0) psspy.dist_machine_trip(i + 1, '1') psspy.run(0, 5.0, 1000, 1, 0) psspy.lines_per_page_one_device( 2, 10000000 ) #Integer DEVICE Indicates which of the four output devices is to be processed (input; #1 for disk files. #2 for the report window. #3 for the first primary hard copy output device. #4 for the second primary hard copy output device. psspy.progress_output(1, "", [0, 0]) return outfile, prgfile
for i in range(len(execution_sequence)): if skip_ref_accc and i == 0: execution_sequence[i] = 0 else: execution_sequence[i] = 1 run_accc_ref_case = execution_sequence[0] generate_sav_files = execution_sequence[1] run_accc = execution_sequence[2] results_comparison = execution_sequence[3] if record_output == 1: psspy.lines_per_page_one_device(1, 1000000) psspy.progress_output(2, r"""output_record.txt""", [0, 0]) print(results_comparison + run_accc + generate_sav_files + run_accc_ref_case) if (results_comparison + run_accc + generate_sav_files + run_accc_ref_case) <= 1: if generate_sav_files and skip_project_case_generation == 0: for i in range(len(injection_levels)): PSSE_functions.load_case(path_to_case, case_name_without_project) PSSE_functions.run_power_flow() if disconnect_gen_list: allowed_gen_scale_margin_disconnect = PSSE_functions.allowed_gen_scale_margin(
def runSimulation(self): """Runs the simulation by crating an instance of psspy, loading the raw and dyr data, applying the disturbance and controling PEV output power. Finally plots in native PSS/E or export to matlab.""" sufix = str(self._disturbance) + "_" + str(self._control) conec_file = trash_dir + "\\CC1_" + sufix + ".out" conet_file = trash_dir + "\\CT1_" + sufix + ".out" compile_file = trash_dir + "\\compile_" + sufix + ".out" psspy.psseinit(49) #suppress output if required, else redirect it to python if self._suppress_output: psspy.report_output(6, "", [0, 0]) psspy.progress_output(6, "", [0, 0]) #psspy.progress_output(2,r"""pot.txt""",[0,0]) else: #redirect psse output to python import redirect redirect.psse2py() #---------------------- #read in case data psspy.read(0, self._power_system_object._raw_filename) #solve the power flow psspy.fdns([0, 0, 0, 1, 1, 1, 99, 0]) #---------------------- #convert all generators psspy.cong(0) #---------------------- #conv_standard_loads #change the vector of numbers to get constant current, admittance or power conversion utils.convertLoads([0.0, 100.0, 0.0, 100.0]) #convert the PEVs to constant power loads utils.convertPEVs() #---------------------------------------- #read in dynamics data psspy.dyre_new([1, 1, 1, 1], self._power_system_object._dyr_filename, "", "", "") #solve power flow with dynamics tysl - and fact devices (was in tutorial) - not sure if we need it though psspy.fact() psspy.tysl(1) #set up pre designated channels self._channels.setUpChannels() #designate channel output_file psspy.strt(0, self._channels._channel_file) self._performDynamicSimulation() if self._plot: self._channels.plot(self._channels._channels_to_include) if self._export_to_matlab: description = sufix.replace(" ", "_").replace(".", "_").replace("=", "__") self._channels.exportToMatlab( matlab_dir + "\\" + description + ".m", description, True, True, self._export_figures) if self._export_figures: import win32com.client h = win32com.client.Dispatch('matlab.application') h.Execute("cd('" + os.getcwd() + "\\" + matlab_dir + "');") h.Execute(description) #clean up try: os.remove(conec_file) except: pass try: os.remove(conet_file) except: pass try: os.remove(compile_file) except: pass return self._channels
0, #disable area exchange 0, #disable phase-shift 0, #disable dc-tap 0, #disable switched shunts 0, #do not flat start 0, #apply var limits immediately 0, #disable non-div solution ] } psse_log = 'savnw.log' redirect.psse2py() psspy.psseinit(buses=80000) psspy.report_output(2, psse_log, [0, 0]) psspy.progress_output(2, psse_log, [0, 0]) psspy.alert_output(2, psse_log, [0, 0]) psspy.prompt_output(2, psse_log, [0, 0]) _i = psspy.getdefaultint() _f = psspy.getdefaultreal() _s = psspy.getdefaultchar() print "\n Reading raw file:", settings['filename'] ierr = psspy.read(0, settings['filename']) # get a list of all the non-transformer branches ierr, brnchs = psspy.abrnint( _i, _i, _i, _i, _i, ['FROMNUMBER', 'TONUMBER']) # page 1789 of API book ierr, carray = psspy.abrnchar( _i, _i, _i, _i, _i, ['ID']) # get the character ids (page 1798 of API book) fromBusList = brnchs[0] toBusList = brnchs[1]
def run_savnw_simulation(datapath, outfile1, outfile2, outfile3, prgfile): import psspy psspy.psseinit() savfile = 'savcnv.sav' snpfile = 'savnw.snp' if datapath: savfile = os.path.join(datapath, savfile) snpfile = os.path.join(datapath, snpfile) psspy.lines_per_page_one_device(1,90) psspy.progress_output(2,prgfile,[0,0]) # directly output to file ierr = psspy.case(savfile) if ierr: psspy.progress_output(1,"",[0,0]) print(" psspy.case Error") return ierr = psspy.rstr(snpfile) if ierr: psspy.progress_output(1,"",[0,0]) print(" psspy.rstr Error") return # fault + line trip psspy.strt(0,outfile1) psspy.chsb(0,1, [-1,-1,-1,1,13,0]) psspy.run(0, 1.0,1000,1,0)# start from 1 second, 1000 steps, and 1 writing for 1 output step psspy.dist_bus_fault(154,1, 230.0,[0.0,-0.2E+10]) # ibus, units, voltage kv psspy.run(0, 1.1,1000,1,0)# start from 1.1 second, 1000 steps, and 1 writing for 1 output step psspy.dist_clear_fault(1) psspy.dist_branch_trip(3005,3007,'1') psspy.run(0,1.2,1000,1,0) psspy.dist_machine_trip(3018,'1') psspy.run(0, 5.0,1000,1,0) # line trip (with faults) + generator trip psspy.case(savfile) psspy.rstr(snpfile) psspy.strt(0,outfile2) psspy.chsb(0,1, [-1,-1,-1,1,13,0]) psspy.run(0, 1.0,1000,1,0) psspy.dist_bus_fault(3005,1,230.0,[0.0,-0.2E+10]) psspy.run(0,1.1,1000,1,0) psspy.dist_clear_fault(1) psspy.run(0,1.2,1000,1,0) psspy.dist_machine_trip(3018,'1') psspy.run(0, 5.0,1000,1,0) psspy.case(savfile) psspy.rstr(snpfile) psspy.strt(0,outfile3) psspy.chsb(0,1, [-1,-1,-1,1,13,0]) psspy.run(0, 1.0,1000,1,0) psspy.dist_branch_trip(3005,3007,'1') psspy.run(0, 5.0,1000,1,0) psspy.lines_per_page_one_device(2,10000000) psspy.progress_output(1,"",[0,0])
def changeLoad(raw, start, end, step, newdir): """ New raw files are created for each percentage step in [start,end]. The current step defines the percentage scaling up (or down) factor for load and generation """ # convert the raw file to another one where all the load is constant power raw_conp = raw.replace('.raw', '') + '_conp.raw' redirect.psse2py() psspy.psseinit(buses=80000) # ignore the output psspy.report_output(6, '', [0, 0]) psspy.progress_output(6, '', [0, 0]) psspy.alert_output(6, '', [0, 0]) psspy.prompt_output(6, '', [0, 0]) # read the raw file and convert all the loads to constant power ierr = psspy.read(0, raw) # multi-line command to convert the loads to 100% constant power psspy.conl(0, 1, 1, [1, 0], [0.0, 0.0, 0.0, 0.0]) psspy.conl(0, 1, 2, [1, 0], [0.0, 0.0, 0.0, 0.0]) psspy.conl(0, 1, 3, [1, 0], [0.0, 0.0, 0.0, 0.0]) ierr = psspy.rawd_2(0, 1, [1, 1, 1, 0, 0, 0, 0], 0, raw_conp) # run change Load on the constant power load raw file rawBusDataDict = getBusData(raw_conp) # create a new directory to put the files in currentdir = os.getcwd() if not os.path.exists(newdir): os.mkdir(newdir) output_dir = currentdir + '/' + newdir #genDiscount = 0.90 # ratio of the actual increase in generation genDiscount = 1.0 lossRatio = 0.0 # gen scale-up factor: (scalePercent + (scalePercent-100)*lossRatio)/100 ############################################ # create new raw files with scaled up loads and generation for scalePercent in range(start, end + step, step): scalePercent = float( scalePercent) # float is needed, otherwise 101/100 returns 1 scalePercentInt = int( scalePercent) # integer value needed to append to filename scalePercentStr = str(scalePercentInt) # variables to store load data loadBusList = [] # list of load buses (string) loadPList = [] # list of Pload values (string) loadQList = [] # list of Qload values (string) loadPListInt = [] # list of Pload values (float) loadQListInt = [] # list of Qload values (float) #loadBusListInt = [] # list of load buses (int) # variables to store gen data genBusList = [] #genBusListInt = [] genPList = [] genMVAList = [] genMVAListInt = [] genPListInt = [] raw_name = raw_conp.replace('.raw', '') out_file = raw_name + scalePercentStr + '.raw' # output file out_path = output_dir + '/' + out_file impLoadBuses = [ ] # enter specified load buses to scale, if empty all loads are scaled incLoss = ( scalePercent - 100 ) * lossRatio # Additional percentage increase in Pgen (to account for losses) ############################################# #Read raw file with open(raw_conp, 'r') as f: filecontent = f.read() filelines = filecontent.split('\n') ## Get start and end indices of load and gen info ######################################### loadStartIndex = filelines.index( '0 / END OF BUS DATA, BEGIN LOAD DATA') + 1 loadEndIndex = filelines.index( '0 / END OF LOAD DATA, BEGIN FIXED SHUNT DATA') genStartIndex = filelines.index( '0 / END OF FIXED SHUNT DATA, BEGIN GENERATOR DATA') + 1 genEndIndex = filelines.index( '0 / END OF GENERATOR DATA, BEGIN BRANCH DATA') ############################################################################## totalPincr = 0.0 totalQincr = 0.0 percentIncr = (scalePercent - 100.0) / 100 # increment in percentage newPConList = [] newQConList = [] newIPList = [] newIQList = [] newZPList = [] newZQList = [] # Extract load info for i in range(loadStartIndex, loadEndIndex): words = filelines[i].split(',') loadBus = words[0].strip() #loadBusList.append(words[0].strip()) loadPCon = float(words[5].strip()) loadQCon = float(words[6].strip()) loadIP = float(words[7].strip()) loadIQ = float(words[8].strip()) loadZP = float(words[9].strip()) loadZQ = float(words[10].strip()) # calculate the total MW (MVAr) increase in load loadBusVolt = float(rawBusDataDict[loadBus].voltpu) Pincr = percentIncr * ( loadPCon + loadIP * loadBusVolt + loadZP * loadBusVolt**2 ) # this equation is provided in PAGV1 page 293 Qincr = percentIncr * (loadQCon + loadIQ * loadBusVolt + loadZQ * loadBusVolt**2) totalPincr += Pincr totalQincr += Qincr ### # new load values newPConList.append(loadPCon * scalePercent / 100) newQConList.append(loadQCon * scalePercent / 100) newIPList.append(loadIP * scalePercent / 100) newIQList.append(loadIQ * scalePercent / 100) newZPList.append(loadZP * scalePercent / 100) newZQList.append(loadZQ * scalePercent / 100) """ loadPList.append(words[5].strip()) # adding P value (constant power) loadQList.append(words[6].strip()) # adding Q value (constant power) loadIPList.append(words[7].strip()) # constant current P loadIQList.append(words[7].strip()) # constant current Q loadZPList.append(words[9].strip()) # adding P value (constant admittance) loadZQList.append(words[10].strip()) # adding Q value (constant admittance) """ # get total MW gen totalGenMW = 0.0 # total generation excluding the swing bus for i in range(genStartIndex, genEndIndex): words = filelines[i].split(',') GenBus = words[0].strip() if rawBusDataDict[GenBus].type == '3': continue PGen = float(words[2].strip()) totalGenMW += PGen # get new MW Gen GenMWDict = {} # dictionary to hold new PGen values for i in range(genStartIndex, genEndIndex): words = filelines[i].split(',') Bus = words[0].strip() if rawBusDataDict[Bus].type == '3': continue macID = words[1].strip() key = Bus + macID PGen = float(words[2].strip()) genIncr = PGen / totalGenMW * totalPincr newPGen = (PGen + genIncr) * genDiscount GenMVA = float(words[8].strip()) if newPGen < GenMVA: GenMWDict[key] = newPGen else: GenMWDict[key] = GenMVA # generate the new raw file with open(out_path, 'w') as f: # copy everything before load data for i in range(loadStartIndex): f.write(filelines[i]) f.write('\n') # modify the load data j = 0 for i in range(loadStartIndex, loadEndIndex): words = filelines[i].split(',') # change the constant MVA values words[5] = '%.3f' % newPConList[j] words[6] = '%.3f' % newQConList[j] words[5] = words[5].rjust(10) words[6] = words[6].rjust(10) # change the constant current values words[7] = '%.3f' % newIPList[j] words[8] = '%.3f' % newIQList[j] words[7] = words[7].rjust(10) words[8] = words[8].rjust(10) # change the constant impedance values words[9] = '%.3f' % newZPList[j] words[10] = '%.3f' % newZQList[j] words[9] = words[9].rjust(10) words[10] = words[10].rjust(10) # construct a whole string by inserting commas between the words list filelines[i] = reconstructLine2(words) f.write(filelines[i]) f.write('\n') # increment the load list index j += 1 # copy the shunt data, which is in between the load and gen data for i in range(loadEndIndex, genStartIndex): f.write(filelines[i]) f.write('\n') # update and write the gen data for i in range(genStartIndex, genEndIndex): words = filelines[i].split(',') Bus = words[0].strip() if rawBusDataDict[Bus].type == '3': f.write(filelines[i]) f.write('\n') continue macID = words[1].strip() key = Bus + macID newPGen = GenMWDict[key] words[2] = '%.3f' % newPGen words[2] = words[2].rjust(10) # construct a whole string by inserting commas between the words list filelines[i] = reconstructLine2(words) f.write(filelines[i]) f.write('\n') # copy the rest of the raw data for i in range(genEndIndex, len(filelines)): f.write(filelines[i]) f.write('\n') # solves each of the newly generated raw files and saves them output_dir = currentdir + '/' + newdir NewRawFiles = os.listdir(output_dir) PathList = [(output_dir + '/' + f) for f in NewRawFiles] redirect.psse2py() psspy.psseinit(buses=80000) _i = psspy.getdefaultint() _f = psspy.getdefaultreal() _s = psspy.getdefaultchar() for i in range(len(PathList)): #Settings. CONFIGURE THIS settings = { # use the same raw data in PSS/E and TS3ph ##################################### 'filename': PathList[i], #use the same raw data in PSS/E and TS3ph ################################################################################ 'dyr_file': '', 'out_file': 'output2.out', 'pf_options': [ 0, #disable taps 0, #disable area exchange 0, #disable phase-shift 0, #disable dc-tap 0, #disable switched shunts 0, #do not flat start 0, #apply var limits immediately 0, #disable non-div solution ] } psse_log = output_dir + '/' + 'log' + NewRawFiles[i].replace( '.raw', '.txt') psspy.report_output(2, psse_log, [0, 0]) psspy.progress_output(2, psse_log, [0, 0]) psspy.alert_output(2, psse_log, [0, 0]) psspy.prompt_output(2, psse_log, [0, 0]) print "\n Reading raw file:", settings['filename'] ierr = psspy.read(0, settings['filename']) ierr = psspy.fnsl(settings['pf_options']) converge = psspy.solved() if converge == 0: ierr = psspy.rawd_2(0, 1, [1, 1, 1, 0, 0, 0, 0], 0, PathList[i]) else: # file does not converge, remove raw file, keep log file os.remove(PathList[i]) """
def run_savnw_simulation(datapath, outfile1, outfile2, outfile3, prgfile): _F1_start=100 _F1_end=100+70*1/60.0; _F2_start = 300 _F2_end = 400; _runto=300; import psspy psspy.psseinit() savfile = 'IEEE 9 Bus_modifiedj4ab.sav' snpfile = 'IEEE 9 Bus_modifiedj4ab.snp' _i = psspy.getdefaultint() _f = psspy.getdefaultreal() _s = psspy.getdefaultchar() INTGAR = [_i] * 7 REALAR = [_f] * 8 if datapath: savfile = os.path.join(datapath, savfile) snpfile = os.path.join(datapath, snpfile) psspy.lines_per_page_one_device(1,90) psspy.progress_output(2,prgfile,[0,0]) #Use this API to specify the progress output device. ierr = psspy.case(savfile) #Use this API to open a PSSE Saved Case file and transfers its data into the PSSE working case if ierr: psspy.progress_output(1,"",[0,0]) print(" psspy.case Error") return ierr = psspy.rstr(snpfile)#Use this API to read a dynamics Snapshot File into PSSE working memory (activity RSTR). if ierr: psspy.progress_output(1,"",[0,0]) print(" psspy.rstr Error") return psspy.strt(0,outfile1) #strt(option, outfile) #Use this API to initialize a PSSE dynamic simulation for state-space simulations (i.e., in preparation for activity RUN) and to specify the Channel Output File into which the output channel values are to be recorded during the dynamic simulation (activity STRT). psspy.run(0, _F1_start,5000,1,0) #Use this API to calculate PSSE state-space dynamic simulations (activity RUN). #psspy.dist_bus_fault(8,1, 230.0,[0.0,-0.2E+10]) #Use this API routine to apply a fault at a bus during dynamic simulations. (Note: use DIST_BUS_FAULT_2 if phase voltages are to be calculated during the simulation.) businfo = subsystem_info('bus', ['NUMBER', 'NAME', 'PU'], sid=-1) print businfo psspy.dist_branch_fault(8,9, '1',3,0.0,[0.0,0.000001]) ##psspy.dist_branch_trip(8, 7, '1') ##psspy.load_chng_5(11, r"""1""", [0, _i, _i, _i, _i, _i, _i], [_f, _f, _f, _f, _f, _f, _f, _f]) businfo = subsystem_info('bus', ['NUMBER', 'NAME', 'PU'], sid=-1) print businfo psspy.run(0, _F1_end+1.5*1/60,5000,1,0) businfo = subsystem_info('bus', ['NUMBER', 'NAME', 'PU'], sid=-1) print businfo #psspy.dist_branch_close(8,7,'1') ## psspy.load_chng_5(11, r"""1""", [1, _i, _i, _i, _i, _i, _i], [_f, _f, _f, _f, _f, _f, _f, _f]) psspy.dist_clear_fault(1) psspy.run(0, _F1_end+2.0, 5000, 1, 0) businfo = subsystem_info('bus', ['NUMBER', 'NAME', 'PU'], sid=-1) print businfo #psspy.dist_clear_fault(1) #Use this API to clear a fault during dynamic simulations. The fault must have previously been applied using one of the following APIs: psspy.run(0, _runto,5000,1,0) #trigger machine # psspy.case(savfile) #Use this API to open a PSSE Saved Case file and transfers its data into the PSSE working case # psspy.rstr(snpfile) #Use this API to read a dynamics Snapshot File into PSSE working memory (activity RSTR). # psspy.strt(0,outfile2) # psspy.run(0, 1.0,1000,1,0) # psspy.dist_machine_trip(2,'1') # psspy.run(0, 10.0,1000,1,0) #trigger line # psspy.case(savfile) # psspy.rstr(snpfile) # psspy.strt(0,outfile3) # psspy.run(0, 1.0,1000,1,0) # psspy.dist_branch_trip(7,8,'1') # psspy.run(0, 10.0,1000,1,0) psspy.lines_per_page_one_device(2,10000000) psspy.progress_output(1,"",[0,0])
def runSimulation(self): """Runs the simulation by crating an instance of psspy, loading the raw and dyr data, applying the disturbance and controling PEV output power. Finally plots in native PSS/E or export to matlab.""" sufix = str(self._disturbance)+"_"+str(self._control) conec_file = trash_dir+"\\CC1_"+sufix+".out" conet_file = trash_dir+"\\CT1_"+sufix+".out" compile_file = trash_dir+"\\compile_"+sufix+".out" psspy.psseinit(49) #suppress output if required, else redirect it to python if self._suppress_output: psspy.report_output(6,"",[0,0]) psspy.progress_output(6,"",[0,0]) #psspy.progress_output(2,r"""pot.txt""",[0,0]) else: #redirect psse output to python import redirect redirect.psse2py() #---------------------- #read in case data psspy.read(0,self._power_system_object._raw_filename) #solve the power flow psspy.fdns([0,0,0,1,1,1,99,0]) #---------------------- #convert all generators psspy.cong(0) #---------------------- #conv_standard_loads #change the vector of numbers to get constant current, admittance or power conversion utils.convertLoads([0.0,100.0,0.0,100.0]) #convert the PEVs to constant power loads utils.convertPEVs() #---------------------------------------- #read in dynamics data psspy.dyre_new([1,1,1,1],self._power_system_object._dyr_filename,"","","") #solve power flow with dynamics tysl - and fact devices (was in tutorial) - not sure if we need it though psspy.fact() psspy.tysl(1) #set up pre designated channels self._channels.setUpChannels() #designate channel output_file psspy.strt(0,self._channels._channel_file) self._performDynamicSimulation() if self._plot: self._channels.plot(self._channels._channels_to_include) if self._export_to_matlab: description = sufix.replace(" ","_").replace(".","_").replace("=","__") self._channels.exportToMatlab(matlab_dir+"\\"+description+".m",description,True,True,self._export_figures) if self._export_figures: import win32com.client h = win32com.client.Dispatch('matlab.application') h.Execute ("cd('"+os.getcwd()+"\\"+matlab_dir+"');") h.Execute (description) #clean up try: os.remove(conec_file) except: pass try: os.remove(conet_file) except: pass try: os.remove(compile_file) except: pass return self._channels
def main(): startTime = time.time() totalRealPowerLeftUniform = [] totalImagPowerLeftUniform = [] totalRealPowerLeftRollout = [] totalImagPowerLeftRollout = [] totalRealPowerLeftRollout1 = [] totalImagPowerLeftRollout1 = [] totalRealPowerLeftSelective = [] totalImagPowerLeftSelective = [] rewardUniform = [] rewardRollout0 = [] rewardRollout1 = [] rewardSelective = [] worstUniform = [] worstRollout = [] worstRollout1 = [] worstSelective = [] fileName = 'realPowerComparison.csv' fileName2 = 'imagPowerComparison.csv' for i in range(0,50): psspy.lines_per_page_one_device(1,10000) psspy.progress_output(2,r"""output""",[0,0]) case_file = 'caseNumber_' + str(i) + '.sav' my_r = generate_reward_list(19, case_file) print my_r load_un, rarray_un, max_loads, bus_ids = begin_uniform_loadshed(case_file) percentOfLoadsSurviving(max_loads, load_un, totalImagPowerLeftUniform, totalRealPowerLeftUniform, rarray_un[0], worstUniform) load_single, rarray_single, max_loads, bus_ids = begin_policy_rollout(case_file, 0, my_r) percentOfLoadsSurviving(max_loads, load_single, totalImagPowerLeftRollout, totalRealPowerLeftRollout, rarray_single[0], worstRollout) #load_single1, rarray_single1, max_loads1, bus_ids1 = begin_policy_rollout(case_file, 1, my_r) # percentOfLoadsSurviving(max_loads1, load_single1, totalImagPowerLeftRollout1, totalRealPowerLeftRollout1, rarray_single1[0], worstRollout1) load_sel, rarray_sel, max_loads, bus_ids = begin_selective_loadshed(case_file) percentOfLoadsSurviving(max_loads, load_sel, totalImagPowerLeftSelective, totalRealPowerLeftSelective, rarray_sel[0], worstSelective) print("TIME") print(time.time() - startTime) print my_r rewardUniform.append(reward(rarray_un, load_un, max_loads, bus_ids, my_r)) rewardRollout0.append(reward(rarray_single, load_single, max_loads, bus_ids, my_r)) rewardSelective.append(reward(rarray_sel, load_sel, max_loads, bus_ids, my_r)) #rewardRollout1.append(reward(rarray_single1, load_single1, max_loads, bus_ids, my_r)) print(load_single) print(max_loads) print(reward(rarray_single, load_single, max_loads, bus_ids, my_r)) #print(rarray_un), sum(map(float, load_un))/sum(map(float, max_loads)) #load_single, rarray_single, max_loads, bus_ids = begin_policy_rollout(case_file, 1) ''' load_roll, rarray_roll, max_loads, bus_ids = begin_policy_rollout(case_file, 0) load_sel, rarray_sel, max_loads, bus_ids = begin_selective_loadshed(case_file) print(reward(rarray_un, load_un, max_loads, bus_ids, [1.0 for x in range(len(load_un[0]))])) print(reward(rarray_roll, load_roll, max_loads, bus_ids, [1.0 for x in range(len(load_un[0]))])) print(reward(rarray_sel, load_sel, max_loads, bus_ids, [1.0 for x in range(len(load_un[0]))])) print(load_sel) #steadyStateChangeInitSolution() #Basic case to solve the case with no dynamcis print totalImagPowerLeftUniform print totalRealPowerLeftUniform print worstUniform, worstRollout #print min(worstUniform), min(worstRollout), min(worstRollout1), min(worstSelective) ''' with open(fileName, "a") as fp: wr = csv.writer(fp, dialect='excel') wr.writerow('Uniform') wr.writerow(totalRealPowerLeftUniform) wr.writerow('Rollout0') wr.writerow(totalRealPowerLeftRollout) #wr.writerow('Rollout1') #wr.writerow(totalRealPowerLeftRollout1) wr.writerow('Selective') wr.writerow(totalRealPowerLeftSelective) wr.writerow('Rewards:') wr.writerow(rewardUniform) wr.writerow(rewardRollout0) #wr.writerow(rewardRollout1) wr.writerow(rewardSelective) with open(fileName2, "a") as fp: wr = csv.writer(fp, dialect='excel') wr.writerow('Uniform') wr.writerow(totalImagPowerLeftUniform) wr.writerow('Rollout0') wr.writerow(totalImagPowerLeftRollout) #wr.writerow('Rollout1') #wr.writerow(totalImagPowerLeftRollout1) wr.writerow('Selective') wr.writerow(totalImagPowerLeftSelective)
# Select working path ########################################################## #os.chdir(r"C:\Users\bikiran_remote\Desktop\NewCAPECleanOld") ################################################################################ # Local imports import redirect import psspy import dyntools import csv planningRaw = 'hls18v1dyn_1219.raw' psse_log = 'log_planning_multTFLoad.txt' redirect.psse2py() psspy.psseinit(buses=80000) # Silence all psse outputs psspy.report_output(2, psse_log, [0, 0]) psspy.progress_output(6, psse_log, [0, 0]) #ignored psspy.alert_output(6, psse_log, [0, 0]) #ignored psspy.prompt_output(6, psse_log, [0, 0]) #ignored ############################## ierr = psspy.read(0, planningRaw) # File:"C:\Users\bikiran_remote\Desktop\report_bus_data.py", generated on MON, MAR 05 2018 19:33, release 33.03.00 for bus in LoadSet: ierr = psspy.bsys(1, 0, [0.0, 0.0], 0, [], 1, [int(bus)], 0, [], 0, []) # PAGE 1373 of API book ierr = psspy.lamp(1, 0) # page 258 of API book """ with open(psse_log,'r') as f: filecontent = f.read() fileLines = filecontent.split('\n')
import psspy import redirect import numpy import math import matplotlib as mpl import matplotlib.pyplot as plt import dyntools # OPEN PSS _i = psspy.getdefaultint() _f = psspy.getdefaultreal() _s = psspy.getdefaultchar() redirect.psse2py() psspy.psseinit(50000) ierr = psspy.progress_output(6, ' ', [0, 0]) # disable output ierr = psspy.prompt_output(6, ' ', [0, 0]) # disable output ierr = psspy.report_output(6, ' ', [0, 0]) # disable output # Set Simulation Path. LoadScenario = "SimplifiedSystem" ClauseName = "5.2.5.1 Reactive Power Capability" ProgramPath = "F:/PosDoc Projects/11_Industrial Projects/NEOEN_HW/P_SimulationProgram/" GridInfoPath = "F:/PosDoc Projects/11_Industrial Projects/NEOEN_HW/NEM_files/" + LoadScenario + "/" HuaweiModelPath = "F:/PosDoc Projects/11_Industrial Projects/NEOEN_HW/D_HuaweiModels/34" OutputFilePath = ProgramPath + "SimulationOutput.out" FigurePath = "F:/PosDoc Projects/11_Industrial Projects/NEOEN_HW/R_Results/" PowerFlowFileName = 'NEOEN Western Downs Solar Farm_C3WV_3.raw' # Initialize
import psse34 import psspy from psspy import _i # MakeCnvSnp_.py # VARs definition study = 'ieee39_flat' mysav = 'ieee39_v33' mydyr = 'ieee39.dyr' simtime = 10.0 title1 = 'ieee39' title2 = 'flatstart' conl = 'Conl.idv' channels = 'channels.idv' mylog = '%s.log'%study # psspy.progress_output(2,mylog,[0,0]) psspy.report_output(2,mylog,[0,0]) psspy.progress(' \n') psspy.progress('***************************************\n') psspy.progress('* MakeCnvSnp %s \n'%study) psspy.progress('*\n') psspy.progress('***************************************\n') psspy.case(mysav) #psspy.runrspnsfile(re_add) #adds RE topology psspy.runrspnsfile(conl) psspy.fnsl((_i,0,_i,_i,_i,_i,_i,0)) psspy.cong(0) psspy.ordr(0) psspy.fact() psspy.tysl(0)