def _simulateANumberofSteps(self,start_time,duration,num_steps,control): if num_steps == 0: num_steps = 1 step_duration = duration*1.0/num_steps for i in range(0,int(num_steps)): step_end_time = step_duration*(i+1)+start_time psspy.run(0,step_end_time,1000,1,0) control.exhibitControl(step_end_time) return start_time+duration
def _simulateANumberofSteps(self, start_time, duration, num_steps, control): if num_steps == 0: num_steps = 1 step_duration = duration * 1.0 / num_steps for i in range(0, int(num_steps)): step_end_time = step_duration * (i + 1) + start_time psspy.run(0, step_end_time, 1000, 1, 0) control.exhibitControl(step_end_time) return start_time + duration
def Islanding(Time_Trip, Time_Reconnect, End_Time, Out_File): psspy.strt(0,Out_File) #Start our case and specify our output file psspy.run(0,0.0,1,1,0) #Run until 0 seconds psspy.run(0, 10,1,1,0) #Run until 50 seconds psspy.dist_branch_trip(323,325,r"""1""") #Open branch between main grid and microgrid psspy.change_channel_out_file(Out_File) #Resume our output file psspy.run(0, 10,1,1,0) #Run until 100 seconds psspy.dist_branch_trip(223,318,r"""1""") #Open branch between main grid and microgrid psspy.change_channel_out_file(Out_File) #Resume our output file psspy.run(0, 10,1,1,0) #Run until 100 seconds psspy.dist_branch_trip(121,325,r"""1""") #Open branch between main grid and microgrid psspy.change_channel_out_file(Out_File) #Resume our output file psspy.run(0, 10,1,1,0) #Run until 100 seconds
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
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
# Set the time step for the dynamic simulation psspy.dynamics_solution_params(realar=[_f, _f, 0.005, _f, _f, _f, _f, _f]) psspy.machine_array_channel([1, 2, 5500]) # Monitor Skien Power (as 5101 Hasle does not have any machine to measure frequency) psspy.machine_array_channel([2, 7, 5500]) # Monitor Skien Frequency (as 5101 Hasle does not have any machine to measure frequency) load = load_models.Load(3359) # Create a load consisting of Ringhals ierr = psspy.strt(outfile=outputfile) # Tell PSS/E to write to the output file # Simulation---------------------------------------------------------------------------------------------------------------------------------- if ierr == 0: # nprt: number of time steps between writing to screen # nplt: number of time steps between writing to output file psspy.run(tpause=0, nprt=0, nplt=0) # run the simulation load.step(1120) # Do a 1120MW load step in Ringhals psspy.run(tpause=120) # Pause the simulation after 120 seconds else: print(ierr) # Read the output file chnf = dyntools.CHNF(outputfile) # assign the data to variables sh_ttl, ch_id, ch_data = chnf.get_data() # Do the plotting plt.figure(1) plt.plot(ch_data['time'], ch_data[1]) # Kvilldal Power
psspy.ordr(0) # Order the matrix: ORDR psspy.fact() # Factorize the matrix: FACT psspy.tysl(0) # TYSL psspy.bus_frequency_channel([1, 969], r"""System frequency""") psspy.voltage_channel([2, -1, -1, 969], r"""IB_Voltage""") psspy.voltage_channel([3, -1, -1, 100], r"""UUT_Voltage""") psspy.voltage_channel([4, -1, -1, 106], r"""POC_Voltage""") psspy.machine_array_channel([5, 2, 100], r"""1""", r"""UUT_Pelec""") psspy.machine_array_channel([6, 3, 100], r"""1""", r"""UUT_Qelec""") psspy.branch_p_and_q_channel([7, -1, -1, 105, 106], r"""1""", [r"""POC_Flow""", ""]) psspy.machine_array_channel([9, 9, 100], r"""1""", r"""UUT_IDcmd""") psspy.machine_array_channel([10, 12, 100], r"""1""", r"""UUT_IQcmd""") psspy.machine_array_channel([11, 8, 100], r"""1""", r"""PPC_Pcmd""") psspy.machine_array_channel([12, 5, 100], r"""1""", r"""PPC_Qcmd""") [ierr, var_ppc_conp] = psspy.mdlind(100, '1', 'EXC', 'CON') [ierr, var_ppc_setp] = psspy.mdlind(100, '1', 'EXC', 'VAR') [ierr, var_ppc_mode] = psspy.mdlind(100, '1', 'EXC', 'ICON') [ierr, var_inv_con] = psspy.mdlind(100, '1', 'GEN', 'CON') [ierr, var_inv_var] = psspy.mdlind(100, '1', 'GEN', 'VAR') [ierr, var_inv_mod] = psspy.mdlind(100, '1', 'GEN', 'ICON') # Run dynamic simulations psspy.strt_2([0, 0], OutputFilePath) psspy.run(0, 1.0, 1000, 5, 5) psspy.dist_bus_fault(107, 1, 132.0, [fault_G, fault_B]) psspy.run(0, (1.0 + Tflt), 1000, 5, 5) psspy.dist_clear_fault(1) psspy.run(0, 10, 1000, 5, 5)
psspy.voltage_and_angle_channel( [8, -1, -1, 400], [r"""POC_Voltage Mag""", r"""POC Voltage Ang"""]) psspy.cong(0) psspy.conl(0, 1, 1, [0, 0], [0.0, 0.0, 0.1, 0.0]) psspy.conl(0, 1, 2, [0, 0], [0.0, 0.0, 0.1, 0.0]) psspy.conl(0, 1, 3, [0, 0], [0.0, 0.0, 0.1, 0.0]) psspy.ordr(1) psspy.fact() psspy.tysl(1) #psspy.change_plmod_con(600, r"""1""", r"""GENCLS""", 1, 8.0) OutputFilePath = ProgramPath + ClauseName + str( test_no) + "_Simulation.outx" # start simulation psspy.strt_2([0, 0], OutputFilePath) psspy.run(0, 2, 500, 1, 1) psspy.dist_branch_fault(400, 46660, r"""1""", 3, 275.0, [r_f[test_no], x_f[test_no]]) test_name = 'Test_' + str(test_no + 31) psspy.run(0, 2.0 + fault_time, 500, 1, 1) psspy.dist_clear_fault(1) psspy.run(0, 5, 500, 1, 1) # start draw curves # new folder if necessary GraphPath = FigurePath + ClauseName + '/' if not os.path.exists(GraphPath): os.makedirs(GraphPath) # read data curves chnfobj = dyntools.CHNF(OutputFilePath)
psspy.conl(1, 0, 2, [0, 0], [86.63, 25.19, -378.97, 347.97]) psspy.bsys(1, 0, [0.0, 0.0], 0, [], 1, [45082], 0, [], 0, []) psspy.conl(1, 0, 2, [0, 0], [51.36, 59.32, -228.04, 254.01]) psspy.bsys(1, 0, [0.0, 0.0], 0, [], 9, [40320, 40340, 40350, 40970, 40980, 40990, 41050, 41071, 41120], 0, [], 0, []) psspy.conl(1, 0, 2, [0, 0], [100.0, 0.0, 0.0, 100.0]) psspy.conl(0, 1, 2, [0, 0], [100.0, 0.0, -306.02, 303.0]) psspy.conl(0, 1, 3, [0, 0], [100.0, 0.0, -306.02, 303.0]) psspy.ordr(0) psspy.fact() psspy.tysl(0) psspy.bsys(0, 0, [0.4, 500.], 0, [], 0, [], 0, [], 0, []) psspy.strt_2([0, 0], OutputFilePath) psspy.run(0, 0.5, 1000, 1, 0) psspy.change_var(var_ppc_setp + 68, 1.05) psspy.change_var(var_ppc_setp + 10, 100) psspy.run(0, 1, 1000, 1, 0) # psspy.change_var(var_ppc_setp + 68, 1.05) # psspy.run(0, 3, 1000, 1, 0) for i in range(0, 1): if i == 0: psspy.branch_chng_3( 400, 950, r"""1""", [_i, _i, _i, _i, _i, _i], [_f, 0.204585 * 0.09, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f], [_f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f], "") psspy.seq_branch_data_3( 400, 950, r"""1""", _i,
[ierr, var_ppc_conp] = psspy.mdlind(100, '1', 'EXC', 'CON') [ierr, var_ppc_setp] = psspy.mdlind(100, '1', 'EXC', 'VAR') [ierr, var_ppc_mode] = psspy.mdlind(100, '1', 'EXC', 'ICON') [ierr, var_inv_con] = psspy.mdlind(100, '1', 'GEN', 'CON') [ierr, var_inv_var] = psspy.mdlind(100, '1', 'GEN', 'VAR') [ierr, var_inv_mod] = psspy.mdlind(100, '1', 'GEN', 'ICON') psspy.strt_2([0, 0], OutputFilePath) J_vals = [] L_vals = [] Pset_vals = [] ierr, J1 = psspy.mdlind(100, '1', 'EXC', 'CON') ierr, L1 = psspy.mdlind(100, '1', 'EXC', 'VAR') ierr, Pset1 = psspy.dsrval('VAR', L1 + VAR_PPCPini) J_vals.append(J1) L_vals.append(L1) Pset_vals.append(Pset1) # Run dynamic simulations psspy.run(0, 5.0, 1000, 5, 5) psspy.change_plmod_con(100, r"""1""", r"""SMAPPC130""", 19, Pset_vals[0] * (1 - dPref)) psspy.run(0, 10.0, 1000, 5, 5) psspy.change_plmod_con(100, r"""1""", r"""SMAPPC130""", 19, Pset_vals[0] * (1 - dPref*2)) psspy.run(0, 15.0, 1000, 5, 5) psspy.change_plmod_con(100, r"""1""", r"""SMAPPC130""", 19, Pset_vals[0] * (1 - dPref*3)) psspy.run(0, 20.0, 1000, 5, 5) psspy.change_plmod_con(100, r"""1""", r"""SMAPPC130""", 19, Pset_vals[0] * (1 - dPref*4)) psspy.run(0, 25.0, 1000, 5, 5) psspy.change_plmod_con(100, r"""1""", r"""SMAPPC130""", 19, Pset_vals[0]) psspy.run(0, 40.0, 1000, 5, 5)
# psspy.change_con(var_inv1_con+16,0.10) # Not Final # # psspy.change_con(var_inv1_con+12,-0.35) # Inverter Con, Looks good # psspy.change_con(var_inv1_con+13, 0.59) # Inverter Con, Looks good # # psspy.change_con(var_inv2_con+15,0.85) # Not Final # psspy.change_con(var_inv2_con+16,0.10) # Not Final # # psspy.change_con(var_inv2_con+12,-0.35) # Inverter Con, Looks good # psspy.change_con(var_inv2_con+13, 0.59) # Inverter Con, Looks good # # # start simulation psspy.strt_2([0,0], OutputFilePath) psspy.run(0, 1, 1000, 1, 0) psspy.change_var(var_ppc_setp+68,1.05) psspy.change_var(var_ppc_setp+10,85) psspy.run(0,5, 1000, 1, 0) psspy.change_var(var_ppc_setp+10,68) psspy.run(0, 55, 1000, 1, 0) psspy.change_var(var_ppc_setp+10,85) psspy.run(0, 105, 1000, 1, 0) # psspy.change_var(var_ppc_setp+10,65) # psspy.run(0, 130, 1000, 1, 0) # psspy.change_var(var_ppc_setp+10,85) # # psspy.run(0,180,1000,1,0)
psspy.voltage_channel([2, -1, -1, 101], r"""Inverter Voltage Mag.""") psspy.voltage_channel([3, -1, -1, 400], r"""WD SF POC Voltage Mag.""") psspy.branch_p_and_q_channel( [4, -1, -1, 400, 46660], r"""1""", [r"""P Injection""", r"""Q Injection"""]) ierr = psspy.machine_array_channel([7, 2, 101], r"""1""", r"""Pelec 100""") ierr = psspy.machine_array_channel([8, 3, 101], r"""1""", r"""Qelec 100""") # ierr = psspy.state_channel([9, var_inv_stt + 6], r"""Inverter Voltage Measurement""") # start simulation psspy.strt_2([0, 0], OutputFilePath) psspy.run(0, 1, 1000, 1, 0) psspy.run(0, 5, 1000, 1, 0) psspy.two_winding_chng_5( 500, 46660, r"""1""", [_i, _i, _i, _i, _i, _i, _i, _i, 500, _i, _i, 0, _i, _i, _i], [ _f, _f, _f, _f, _f, _f, vref[k], _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f ], [_f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f], "", "") psspy.run(0, 20, 1000, 1, 0) # start draw curves # new folder if necessary if ActivePowerSetpoint[i] == 0: PName = r"""P = 0%""" if ActivePowerSetpoint[i] == 50: PName = r"""P = 50%"""
0.0) # FRT_VOLFILMOD psspy.change_plmod_con(100, r"""1""", r"""SMASC161""", 31, 0.115) # HVRT 1-J+30 psspy.change_plmod_con(100, r"""1""", r"""SMASC161""", 32, 0.095) # HVRT 1-J+31 psspy.strt_2([0, 0], OutputFilePath) J_vals = [] L_vals = [] Vset_vals = [] ierr, J1 = psspy.mdlind(100, '1', 'EXC', 'CON') ierr, L1 = psspy.mdlind(100, '1', 'EXC', 'VAR') ierr, vset1 = psspy.dsrval('VAR', L1 + VAR_PPCVini) J_vals.append(J1) L_vals.append(L1) Vset_vals.append(vset1) # Run dynamic simulations psspy.run(0, 1.0, 1000, 5, 5) psspy.change_plmod_con(100, r"""1""", r"""SMAPPC130""", 11, float(Vset_vals[0]) - dVref) psspy.run(0, 10.0, 1000, 5, 5) psspy.change_plmod_con(100, r"""1""", r"""SMAPPC130""", 11, float(Vset_vals[0])) psspy.run(0, 20.0, 1000, 5, 5) psspy.change_plmod_con(100, r"""1""", r"""SMAPPC130""", 11, float(Vset_vals[0]) + dVref) psspy.run(0, 30.0, 1000, 5, 5) psspy.change_plmod_con(100, r"""1""", r"""SMAPPC130""", 11, float(Vset_vals[0])) psspy.run(0, 40.0, 1000, 5, 5)
[r"""P Injection""", r"""Q Injection"""]) ierr = psspy.machine_array_channel([7, 2, 101], r"""1""", r"""Pelec 101""") ierr = psspy.machine_array_channel([8, 3, 101], r"""1""", r"""Qelec 101""") psspy.cong(0) psspy.conl(0, 1, 1, [0, 0], [0.0, 0.0, 0.1, 0.0]) psspy.conl(0, 1, 2, [0, 0], [0.0, 0.0, 0.1, 0.0]) psspy.conl(0, 1, 3, [0, 0], [0.0, 0.0, 0.1, 0.0]) psspy.ordr(1) psspy.fact() psspy.tysl(1) psspy.change_plmod_con(600, r"""1""", r"""GENCLS""", 1, 8.0) # start simulation psspy.strt_2([0, 0], OutputFilePath) psspy.run(0, 1, 1000, 1, 0) if fault_type == 1: # three phase fault psspy.dist_bus_fault(500, 3, 275.0, [0, 0.0]) fault_name = 'T10_3-phase_DD' fault_time = 0.430 if fault_type == 2: # two phase psspy.dist_scmu_fault_2([0, 0, 2, 500, _i], [0.0, 0.0, 0.0, 0.0]) fault_name = 'T11_2-phase_DD' fault_time = 0.430 if fault_type == 3: # single phase psspy.dist_scmu_fault_2([0, 0, 1, 500, _i], [0.0, 0.0, 0.0, 0.0]) fault_name = 'T12_s-phase_DD' fault_time = 0.430
def main(): try: ''' Drives a PSS/E Dynamic simulation and returns values ''' ##### Get everything set up on the PSSE side redirect.psse2py() #output = StringIO.StringIO() with silence(): psspy.psseinit(buses=80000) _i = psspy.getdefaultint() _f = psspy.getdefaultreal() _s = psspy.getdefaultchar() """ # Redirect any psse outputs to psse_log psspy.report_output(2,psse_log,[0,0]) psspy.progress_output(2,psse_log,[0,0]) #ignored psspy.alert_output(2,psse_log,[0,0]) #ignored psspy.prompt_output(2,psse_log,[0,0]) #ignored """ k = 1 for rawFile in RawFileList: # get the percentage loading from the raw file name if rawFile == 'savnw_conp.raw': PL = '100' else: rawFileName = rawFile.replace('.raw', '') PL = rawFileName[-3:] #Parameters. CONFIGURE THIS settings = { # use the same raw data in PSS/E and TS3ph ##################################### 'filename': rawFile, #use the same raw data in PSS/E and TS3ph ################################################################################ 'dyr_file': dyrFile, '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 ] } ##### Load Raw Datafile and do power flow print "\n Reading raw file:", settings['filename'] # " Reading raw file: {0:s}".format('text') FaultRpu = 1e-06 Sbase = 100.0 #FaultBusNomVolt = float(BusDataDict[FaultBus].NominalVolt) #Zbase = FaultBusNomVolt**2/Sbase # float since Sbase is a float #Rohm = FaultRpu*Zbase # fault impedance in ohms ########################## # run nested loops to see if there are any abnormal low voltages simCount = 0 # to keep track of how many simulations are already done croppedHVLineSet = list(HVLineSet) for line1 in croppedHVLineSet: for line2 in croppedHVLineSet: # stability_indicator = 1 # Bus_issues = [] # list of buses where issues (low voltage or high dv_dt) are reported # the lines cannot be the same if line1 == line2: continue # part to ensure there is no duplication of events currentSet = line1 + ';' + line2 currentSetReverse = line2 + ';' + line1 # if case causes topology inconsistencies, continue if currentSet in topology_inconsistent_set or currentSetReverse in topology_inconsistent_set: continue line1Elements = line1.split(',') line2Elements = line2.split(',') # Line 1 params L1Bus1 = int(line1Elements[0]) L1Bus2 = int(line1Elements[1]) L1cktID = line1Elements[2].strip("'").strip() # Line 2 params L2Bus1 = int(line2Elements[0]) L2Bus2 = int(line2Elements[1]) L2cktID = line2Elements[2].strip("'").strip() FaultBusList = [L2Bus1, L2Bus2] # apply faults at both buses for FaultBus in FaultBusList: output = StringIO.StringIO() with silence(): ierr = psspy.read(0, settings['filename']) #This is for the power flow. I'll use the solved case instead ierr = psspy.fnsl(settings['pf_options']) ##### Prepare case for dynamic simulation # Load conversion (multiple-step) psspy.conl(_i, _i, 1, [0, _i], [_f, _f, _f, _f]) # all constant power load to constant current, constant reactive power load to constant admittance # standard practice for dynamic simulations, constant MVA load is not acceptable psspy.conl(1, 1, 2, [_i, _i], [100.0, 0.0, 0.0, 100.0]) psspy.conl(_i, _i, 3, [_i, _i], [_f, _f, _f, _f]) ierr = psspy.cong(0) #converting generators ierr = psspy.ordr( 0 ) #order the network nodes to maintain sparsity ierr = psspy.fact( ) #factorise the network admittance matrix ierr = psspy.tysl(0) #solving the converted case ierr = psspy.dynamicsmode(0) #enter dynamics mode print "\n Reading dyr file:", settings['dyr_file'] ierr = psspy.dyre_new([1, 1, 1, 1], settings['dyr_file']) ierr = psspy.docu(0, 1, [ 0, 3, 1 ]) #print the starting point of state variables # select time step ############################################################## ierr = psspy.dynamics_solution_params( [_i, _i, _i, _i, _i, _i, _i, _i], [ _f, _f, 0.00833333333333333, _f, _f, _f, _f, _f ], 'out_file') # the number here is the time step ################################################################################ ##### select channels ierr = psspy.delete_all_plot_channels( ) # clear channels # get all the bus voltages, angles and frequencies for bus in BusDataDict: bus = int(bus) ierr = psspy.voltage_and_angle_channel( [-1, -1, -1, bus]) ierr = psspy.bus_frequency_channel([-1, bus]) eventStr = PL + '/' + line1 + ';' + line2 + '/F' + str( FaultBus) print 'Event: {}'.format(eventStr) # get the nominal voltages as well as the fault impedance in ohms FaultBusNomVolt = float( BusDataDict[str(FaultBus)].NominalVolt) Zbase = FaultBusNomVolt**2 / Sbase # float since Sbase is a float Rohm = FaultRpu * Zbase # fault impedance in ohms # run simulation till just before the fault ResultsDict = {} #output = StringIO.StringIO() with silence(output): ierr = psspy.strt(0, settings['out_file']) ierr = psspy.run(0, 0.1, 1, 1, 1) ierr = psspy.dist_branch_trip( L1Bus1, L1Bus2, L1cktID) #output = StringIO.StringIO() with silence(output): ierr = psspy.run(0, 0.2, 1, 1, 1) #fault on time outputStr = output.getvalue() if "Network not converged" in outputStr: print 'For ' + eventStr + ':' print 'Network did not converge between branch 1 trip and fault application, skipping...' continue ####### # check for convergence during fault #output = StringIO.StringIO() with silence(output): ierr = psspy.dist_bus_fault( FaultBus, 3, 0.0, [Rohm, 0.0]) ierr = psspy.run(0, 0.3, 1, 1, 1) #fault off time ierr = psspy.dist_clear_fault(1) outputStr = output.getvalue() if "Network not converged" in outputStr: print 'For ' + eventStr + ':' print 'Network did not converge during fault, skipping...' continue # check for convergence between fault clearance and second branch trip #output = StringIO.StringIO() with silence(output): ierr = psspy.run(0, 0.31, 1, 1, 1) #fault off time ierr = psspy.dist_branch_trip( L2Bus1, L2Bus2, L2cktID) ierr = psspy.run(0, 0.35, 1, 1, 1) #fault off time # check for non-convergence #output = StringIO.StringIO() outputStr = output.getvalue() if "Network not converged" in outputStr: print 'For ' + eventStr + ':' print 'Network did not converge between fault clearance and branch 2 trip, skipping...' continue # select run time ############################################################## output = StringIO.StringIO() with silence(output): ierr = psspy.run( 0, 10.0, 1, 1, 1 ) #exit time (second argument is the end time) ################################################################################ # check for non-convergence outputStr = output.getvalue() if "Network not converged" in outputStr: print 'For ' + eventStr + ':' print 'Network did not converge sometime after 2nd branch trip, skipping...' continue outputData = dyntools.CHNF(settings['out_file']) data = outputData.get_data() channelDict = data[ 1] # dictionary where the value is the channel description valueDict = data[ 2] # dictionary where the values are the signal values, keys match that of channelDict tme = valueDict['time'] # get time ResultsDict['time'] = tme for key in channelDict: if key == 'time': continue signalDescr = channelDict[key] words = signalDescr.split() signalType = words[0].strip() bus = words[1].strip() #print Bus + ' ' + signalType if bus not in ResultsDict: ResultsDict[bus] = Results() if signalType == 'VOLT': ResultsDict[bus].volt = valueDict[key] elif signalType == 'ANGL': ResultsDict[bus].angle = valueDict[key] elif signalType == 'FREQ': ResultsDict[bus].freq = valueDict[key] EventsDict[eventStr] = ResultsDict simCount += 1 print 'Simulation ' + str(simCount) + ' out of ' + str( totalSims) # Uncomment next two lines if you want to see the output #with open('output'+str(k) + '.txt','w') as f: # f.write(outputStr) k += 1 save_obj(EventsDict, 'EventData') except Exception: traceback.print_exc(file=logfile) sys.exit(0)
bus1 = tfElements[0].strip() bus2 = tfElements[1].strip() bus3 = tfElements[2].strip() cktID = tfElements[3].strip("'").strip() eventStr = 'R{}/T{}'.format(PL, tf) #cktID = GenDict[genbus] output = StringIO.StringIO() with silence(output): # load the sav and snp file psspy.case(savFile) psspy.rstr(snpFile) #output = StringIO.StringIO() with silence(output): ierr = psspy.strt(0, settings['out_file']) ierr = psspy.run(0, 0.1, 1, 1, 1) ierr = psspy.dist_branch_trip( int(bus1), int(bus2), cktID) # this line can be used for 2 winding tf as well #output = StringIO.StringIO() with silence(output): ierr = psspy.run(0, totSimTime, 1, 1, 1) #simulation end time outputStr = output.getvalue() if "Network not converged" in outputStr: print('For ' + eventStr + ':') print('Network did not converge after tf trip, skipping...') continue outputData = dyntools.CHNF(settings['out_file'])
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 runPSSESimBatches(simList, dyrFile, objName): import sys, os # add psspy to the system path sys.path.append(r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN") os.environ['PATH'] = (r"C:\Program Files (x86)\PTI\PSSE33\PSSBIN;" + os.environ['PATH']) from contextlib import contextmanager import StringIO from getBusDataFn import getBusData @contextmanager def silence(file_object=None): #Discard stdout (i.e. write to null device) or #optionally write to given file-like object. if file_object is None: file_object = open(os.devnull, 'w') old_stdout = sys.stdout try: sys.stdout = file_object yield finally: sys.stdout = old_stdout if file_object is None: file_object.close() # Local imports import redirect import psspy import dyntools # getting the raw file ##### Get everything set up on the PSSE side redirect.psse2py() #output = StringIO.StringIO() with silence(): psspy.psseinit(buses=80000) _i = psspy.getdefaultint() _f = psspy.getdefaultreal() _s = psspy.getdefaultchar() # some important parameters FaultRpu = 1e-06 Sbase = 100.0 EventsDict = {} for event in simList: eventWords = event.split('/') RawFileIndicator = eventWords[0].strip() linesOutage = eventWords[1].strip() FaultBus = eventWords[2].strip()[ 1:] # exclude the 'F' at the beginning # get the raw file if RawFileIndicator == '100': rawFile = 'savnw_conp.raw' else: rawFile = 'savnw_conp{}.raw'.format(RawFileIndicator) #Parameters. CONFIGURE THIS settings = { # use the same raw data in PSS/E and TS3ph ##################################### 'filename': rawFile, #use the same raw data in PSS/E and TS3ph ################################################################################ 'dyr_file': dyrFile, '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 ] } output = StringIO.StringIO() with silence(output): ierr = psspy.read(0, settings['filename']) #This is for the power flow. I'll use the solved case instead ierr = psspy.fnsl(settings['pf_options']) ##### Prepare case for dynamic simulation # Load conversion (multiple-step) psspy.conl(_i, _i, 1, [0, _i], [_f, _f, _f, _f]) # all constant power load to constant current, constant reactive power load to constant admittance # standard practice for dynamic simulations, constant MVA load is not acceptable psspy.conl(1, 1, 2, [_i, _i], [100.0, 0.0, 0.0, 100.0]) psspy.conl(_i, _i, 3, [_i, _i], [_f, _f, _f, _f]) ierr = psspy.cong(0) #converting generators ierr = psspy.ordr(0) #order the network nodes to maintain sparsity ierr = psspy.fact() #factorise the network admittance matrix ierr = psspy.tysl(0) #solving the converted case ierr = psspy.dynamicsmode(0) #enter dynamics mode print "\n Reading dyr file:", settings['dyr_file'] ierr = psspy.dyre_new([1, 1, 1, 1], settings['dyr_file']) ierr = psspy.docu( 0, 1, [0, 3, 1]) #print the starting point of state variables # select time step ############################################################## ierr = psspy.dynamics_solution_params( [_i, _i, _i, _i, _i, _i, _i, _i], [_f, _f, 0.00833333333333333, _f, _f, _f, _f, _f], 'out_file') # the number here is the time step ################################################################################ ##### select channels ierr = psspy.delete_all_plot_channels() # clear channels BusDataDict = getBusData(rawFile) # get all the bus voltages, angles and frequencies for bus in BusDataDict: bus = int(bus) ierr = psspy.voltage_and_angle_channel([-1, -1, -1, bus]) ierr = psspy.bus_frequency_channel([-1, bus]) print 'Event: {}'.format(event) # get the nominal voltages as well as the fault impedance in ohms FaultBusNomVolt = float(BusDataDict[str(FaultBus)].NominalVolt) Zbase = FaultBusNomVolt**2 / Sbase # float since Sbase is a float Rohm = FaultRpu * Zbase # fault impedance in ohms # run simulation till just before the fault ResultsDict = {} # get the line params line1Elements = linesOutage.split(';')[0].strip() line2Elements = linesOutage.split(';')[1].strip() # Line 1 params line1 = line1Elements.split(',') L1Bus1 = int(line1[0].strip()) L1Bus2 = int(line1[1].strip()) L1cktID = line1[2].strip("'").strip() #print L1Bus1 #print L1Bus2 #print L1cktID # Line 2 params line2 = line2Elements.split(',') L2Bus1 = int(line2[0].strip()) L2Bus2 = int(line2[1].strip()) L2cktID = line2[2].strip("'").strip() #print L2Bus1 #print L2Bus2 #print L2cktID #output = StringIO.StringIO() with silence(output): ierr = psspy.strt(0, settings['out_file']) ierr = psspy.run(0, 0.1, 1, 1, 1) ierr = psspy.dist_branch_trip(L1Bus1, L1Bus2, L1cktID) #output = StringIO.StringIO() with silence(output): ierr = psspy.run(0, 0.2, 1, 1, 1) #fault on time outputStr = output.getvalue() if "Network not converged" in outputStr: print 'For ' + event + ':' print 'Network did not converge between branch 1 trip and fault application, skipping...' continue ####### # check for convergence during fault #output = StringIO.StringIO() with silence(output): ierr = psspy.dist_bus_fault(int(FaultBus), 3, 0.0, [Rohm, 0.0]) ierr = psspy.run(0, 0.3, 1, 1, 1) #fault off time ierr = psspy.dist_clear_fault(1) outputStr = output.getvalue() if "Network not converged" in outputStr: print 'For ' + event + ':' print 'Network did not converge during fault, skipping...' continue # check for convergence between fault clearance and second branch trip #output = StringIO.StringIO() with silence(output): ierr = psspy.run(0, 0.31, 1, 1, 1) #fault off time ierr = psspy.dist_branch_trip(L2Bus1, L2Bus2, L2cktID) ierr = psspy.run(0, 0.35, 1, 1, 1) #fault off time # check for non-convergence #output = StringIO.StringIO() outputStr = output.getvalue() if "Network not converged" in outputStr: print 'For ' + event + ':' print 'Network did not converge between fault clearance and branch 2 trip, skipping...' continue # select run time ############################################################## #output = StringIO.StringIO() with silence(output): ierr = psspy.run(0, 10.0, 1, 1, 1) #exit time (second argument is the end time) ################################################################################ # check for non-convergence outputStr = output.getvalue() if "Network not converged" in outputStr: print 'For ' + event + ':' print 'Network did not converge sometime after 2nd branch trip, skipping...' continue # write to output file #with open('outputTmp.txt','w') as f: # f.write(outputStr) outputData = dyntools.CHNF(settings['out_file']) data = outputData.get_data() channelDict = data[ 1] # dictionary where the value is the channel description valueDict = data[ 2] # dictionary where the values are the signal values, keys match that of channelDict tme = valueDict['time'] # get time ResultsDict['time'] = tme for key in channelDict: if key == 'time': continue signalDescr = channelDict[key] words = signalDescr.split() signalType = words[0].strip() bus = words[1].strip() #print Bus + ' ' + signalType if bus not in ResultsDict: ResultsDict[bus] = Results() if signalType == 'VOLT': ResultsDict[bus].volt = valueDict[key] elif signalType == 'ANGL': ResultsDict[bus].angle = valueDict[key] elif signalType == 'FREQ': ResultsDict[bus].freq = valueDict[key] EventsDict[event] = ResultsDict return EventsDict
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])
# psspy.change_con(var_inv1_con+15,0.85) # Not Final # psspy.change_con(var_inv1_con+16,0.10) # Not Final # # psspy.change_con(var_inv1_con+12,-0.35) # Inverter Con, Looks good # psspy.change_con(var_inv1_con+13, 0.59) # Inverter Con, Looks good # # psspy.change_con(var_inv2_con+15,0.85) # Not Final # psspy.change_con(var_inv2_con+16,0.10) # Not Final # # psspy.change_con(var_inv2_con+12,-0.35) # Inverter Con, Looks good # psspy.change_con(var_inv2_con+13, 0.59) # Inverter Con, Looks good # # # start simulation psspy.strt_2([0, 0], OutputFilePath) psspy.run(0, 1, 1000, 1, 0) psspy.change_var(var_ppc_setp + 68, 1.01) psspy.change_var(var_ppc_setp + 10, 85) psspy.run(0, 5, 1000, 1, 0) psspy.change_var(var_ppc_setp + 10, 30) psspy.run(0, 75, 1000, 1, 0) psspy.change_var(var_ppc_setp + 10, 50) psspy.run(0, 110, 1000, 1, 0) psspy.change_var(var_ppc_setp + 10, 65) psspy.run(0, 130, 1000, 1, 0) psspy.change_var(var_ppc_setp + 10, 85) psspy.run(0, 180, 1000, 1, 0)
psspy.change_plmod_icon(500, r"""1""", r"""GPMPPC""", 2, 20) #ori=5 psspy.change_plmod_icon(500, r"""1""", r"""GPMPPC""", 3, 50) #ori=5 psspy.change_plmod_icon(500, r"""1""", r"""GPMPPC""", 4, 2) #ori=3 psspy.change_plmod_con(500, r"""1""", r"""GPMPPC""", 23, 0.003) #ori=0.003 psspy.change_plmod_con(500, r"""1""", r"""GPMPPC""", 24, 0.5) # droop ori=5% psspy.change_plmod_con(500, r"""1""", r"""GPMPPC""", 2, 0.02) # proportional gain ori=0.001 psspy.change_plmod_con(500, r"""1""", r"""GPMPPC""", 3, 0.25) # integral gain ori=0.15 psspy.change_plmod_con(500, r"""1""", r"""GPMPPC""", 5, 0.5) #PPC reactive power UB #ori=1 psspy.change_plmod_con(500, r"""1""", r"""GPMPPC""", 6, -0.3) #PPC reactive power LB #ori=1 psspy.strt_2([0, 0], OutputFilePath) psspy.run(0, 0.2, 1000, 1, 0) psspy.change_var(var_ppc_setp + 68, 1.05) psspy.change_var(var_ppc_setp + 10, 85) # psspy.change_var(var_ppc_setp + 11, 0) psspy.run(0, 5, 1000, 1, 0) for fault_type in [1]: # psspy.change_var(var_ppc_setp + 68, 1.05) # psspy.run(0, 3, 1000, 1, 0) for i in range(0, 4): if i == 0: psspy.branch_chng_3( 400, 950, r"""1""", [_i, _i, _i, _i, _i, _i], [_f, 0.204585 * 0.01, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f],
# psspy.conl(0, 1, 3, [0, 0], [0.0, 0.0, 0.1, 0.0]) psspy.ordr(1) psspy.fact() psspy.tysl(1) # psspy.change_plmod_icon(101,r"""1""",r"""HWS2000""",1,0) # psspy.change_plmod_icon(102,r"""1""",r"""HWS2000""",1,0) # psspy.change_plmod_icon(103,r"""1""",r"""HWS2000""",1,0) # psspy.change_plmod_icon(104,r"""1""",r"""HWS2000""",1,0) # psspy.change_plmod_icon(101,r"""1""",r"""HWS2000""",2,0) # psspy.change_plmod_icon(102,r"""1""",r"""HWS2000""",2,0) # psspy.change_plmod_icon(103,r"""1""",r"""HWS2000""",2,0) # psspy.change_plmod_icon(104,r"""1""",r"""HWS2000""",2,0) #psspy.change_plmod_icon(101,r"""1""",r"""GPMPPC""",4,0) # start simulation psspy.strt_2([0, 0], OutputFilePath) psspy.run(0, 1, 1000, 1, 0) psspy.load_data_3(600, r"""1""", [_i, _i, _i, _i, _i], [312, 20, _f, _f, _f, _f]) #0.08pu/s to 0.02pu psspy.run(0, 1.25, 1000, 1, 0) psspy.load_data_3(600, r"""1""", [_i, _i, _i, _i, _i], [220, 20, _f, _f, _f, _f]) #0.02pu/s to 0.04pu psspy.run(0, 2.25, 1000, 1, 0) psspy.run(0, 4, 1000, 1, 0) # start draw curves # new folder if necessary GraphPath = FigurePath + ClauseName + '/' + testName if not os.path.exists(GraphPath): os.makedirs(GraphPath) # read data curves chnfobj = dyntools.CHNF(OutputFilePath) short_title, chanid, chandata = chnfobj.get_data() freq_data = numpy.array(chandata[1])
psspy.conl(1, 0, 2, [0, 0], [86.63, 25.19, -378.97, 347.97]) psspy.bsys(1, 0, [0.0, 0.0], 0, [], 1, [45082], 0, [], 0, []) psspy.conl(1, 0, 2, [0, 0], [51.36, 59.32, -228.04, 254.01]) psspy.bsys(1, 0, [0.0, 0.0], 0, [], 9, [40320, 40340, 40350, 40970, 40980, 40990, 41050, 41071, 41120], 0, [], 0, []) psspy.conl(1, 0, 2, [0, 0], [100.0, 0.0, 0.0, 100.0]) psspy.conl(0, 1, 2, [0, 0], [100.0, 0.0, -306.02, 303.0]) psspy.conl(0, 1, 3, [0, 0], [100.0, 0.0, -306.02, 303.0]) psspy.ordr(0) psspy.fact() psspy.tysl(0) psspy.bsys(0, 0, [0.4, 500.], 0, [], 0, [], 0, [], 0, []) # start simulation psspy.strt_2([0,0], OutputFilePath) psspy.run(0, 1, 1000, 1, 0) ## psspy.change_var(var_ppc_setp+10,115) ## psspy.change_var(var_ppc_setp+11,-25) psspy.run(0, 5, 1000, 1, 0) if fault_type == 1: # three phase psspy.dist_branch_fault(Branch_Outage_List_Start[i], Branch_Outage_List_End[i], '1', 1, Branch_kV[i], [0.0, -0.2E+10]) fault_name = 'ThreePhase' if Branch_kV[i] == 330 or Branch_kV[i] == 275: fault_time = 0.120 if Branch_kV[i] == 132: fault_time = 0.500 if fault_type == 2: # single phase, no path to ground, line-to-ground, breaker @ bus i, psspy.dist_spcb_fault(Branch_Outage_List_Start[i], Branch_Outage_List_End[i], '1', [3, 0, 1, 1, 0, 0], [0.5, 0.0, 0.000001, 0.0, 0.0])
def Run_SIM(x,dyr_file,out_file): #inputs are strings\ dyre = r"""C:\Users\psse\Desktop\Phylicia\Error and Accuracy Tracking Project Sp18\RTS96\%s""" %dyr_file out = r"""C:\Users\psse\Desktop\Phylicia\Error and Accuracy Tracking Project Sp18\RTS96\Channels\opt_%s.out""" %out_file print dyr_file ierr = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1] #checking for errors output = StringIO.StringIO() with silence(output): ierr[0] = psspy.psseinit(200000) #need to have this high, otherwise there are not enough output channels ierr[1] = psspy.case(r"""C:\Users\psse\Desktop\Phylicia\Error and Accuracy Tracking Project Sp18\RTS96\RTS96DYN.sav""") ierr[2] = psspy.fdns([0,0,0,1,1,0,99,0]) ierr[3] = psspy.cong(0) ierr[4] = psspy.conl(0,1,1,[0,0],[ 100.0,0.0,0.0, 100.0]) ierr[5] = psspy.conl(0,1,2,[0,0],[ 100.0,0.0,0.0, 100.0]) ierr[6] = psspy.conl(0,1,3,[0,0],[ 100.0,0.0,0.0, 100.0]) ierr[7] = psspy.ordr(0) ierr[8] = psspy.fact() ierr[9] = psspy.tysl(0) ierr[10] = psspy.dyre_new([1,1,1,1],dyre,"","","") ierr[11] = psspy.chsb(0,1,[-1,-1,-1,1,13,0]) #record voltage ierr[12] = psspy.chsb(0,1,[-1,-1,-1,1,12,0]) #record frequency ierr[13] = psspy.chsb(0,1,[-1,-1,-1,1,1,0]) #angle ierr[14] = psspy.chsb(0,1,[-1,-1,-1,1,16,0]) #line P & Q ierr[15] = psspy.strt_2([0,0],out) ierr[16] = psspy.run(0, 0.1,1,1,0) #ierr[17] = psspy.dist_branch_fault(217,218,r"""1""",1, 230.0,[0.0,-0.2E+10]) #Line Fault, NaN (network no good) #ierr[17] = psspy.dist_bus_fault(211,1, 230.0,[0.0,-0.2E+10]) #bus Fault, NaN (network no good) #a = int(x[0]) #b = int(x[1]) #ierr[17] = psspy.branch_chng_3(a,b,r"""1""",[0,_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f],"") #Line Outage x = int(x) print "before machine change" ierr[17] = psspy.machine_chng_2(x,r"""1""",[0,_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f]) #Generator Outage print "after machine change" ierr[18] = psspy.change_channel_out_file(out) ierr[19] = psspy.run(0, 0.5,1,1,0) #this was 10 psspy.dist_clear_fault(1) psspy.change_channel_out_file(out) psspy.run(1, 10.0,1,1,0) ierr[20] = psspy.delete_all_plot_channels() print "completed simulation" print ierr run_output = output.getvalue() current_error = 0 if "Network not converged" in run_output: print "Network not converged" #need to have something in if statement otherwise you get an indentation error result = 0 #this will go out to a if condition to rerun the program with a different selection of buses at this accuracy current_error = 1 #raise SystemExit #this will quit the program elif "NaN" in run_output: print "NaN, network is no good" result = 0 #this will go out to a if condition to rerun the program with a different selection of buses at this accuracy current_error = 1 #raise SystemExit #this will quit the program if current_error == 0 and "INITIAL CONDITIONS CHECK O.K." in run_output: print "continuing with study..." #Gather the data and output to excel data = dyntools.CHNF(out) #getting data from channel.out file d,e,z=data.get_data() #gathering data from data in dictionary format #Concatenate data so all data from one simulation is in one file c = 1 #must start at 1, not zero #Save Frequency and Voltage while c < 726: if c < 100: #Record Angle v=z[c] new_v = ", ".join(str(i) for i in v) #this removes the brackets at the beginning and end of the list so can be processed in matlab a = np.matrix(new_v) #make it into a matrix if c ==1: ang_all = np.copy(a) else: ang_all = np.concatenate((ang_all,a),axis=0) #changed to concatenate vertically to test them all individually if c > 99 and c < 173: #Record Frequency v=z[c] new_v = ", ".join(str(i) for i in v) #this removes the brackets at the beginning and end of the list so can be processed in matlab f = np.matrix(new_v) #make it into a matrix if c ==100: f_all = np.copy(f) else: f_all = np.concatenate((f_all,f),axis=0) #changed to concatenate vertically to test them all individually if c > 172 and c < 246: #Record voltage magnitude v=z[c] new_v = ", ".join(str(i) for i in v) #this removes the brackets at the beginning and end of the list so can be processed in matlab f = np.matrix(new_v) #make it into a matrix if c == 173: all = np.copy(f) else: all = np.concatenate((all,f),axis=0) #changed to concatenate vertically to test them all individually if c > 245 and c < 726: #Record P and Q if float(c/2) == int(c/2): #P , even numbers v=z[c] new_v = ", ".join(str(i) for i in v) #this removes the brackets at the beginning and end of the list so can be processed in matlab f = np.matrix(new_v) #make it into a matrix if c == 246: P_all = np.copy(f) else: P_all = np.concatenate((P_all,f),axis=0) #changed to concatenate vertically to test them all individually else: #Q, odd numbers v=z[c] new_v = ", ".join(str(i) for i in v) #this removes the brackets at the beginning and end of the list so can be processed in matlab f = np.matrix(new_v) #make it into a matrix if c == 247: Q_all = np.copy(f) else: Q_all = np.concatenate((Q_all,f),axis=0) #changed to concatenate vertically to test them all individually c = c+1 result = [all, f_all, ang_all, P_all, Q_all] #0 is voltage, 1 is frequency return result
# convert load , do not change psspy.cong(0) psspy.conl(0, 1, 1, [0, 0], [100.0, 0.0, 0.0, 100.0]) psspy.conl(0, 1, 2, [0, 0], [100.0, 0.0, 0.0, 100.0]) psspy.conl(0, 1, 3, [0, 0], [100.0, 0.0, 0.0, 100.0]) psspy.ordr(0) # ! Order the matrix: ORDR psspy.fact() # ! Factorize the matrix: FACT psspy.tysl(0) # ! TYSL psspy.bus_frequency_channel([1, 969], r"""System frequency""") psspy.voltage_channel([2, -1, -1, 969], r"""IB_Voltage""") psspy.voltage_and_angle_channel([3, -1, -1, 100], [r"""UUT_Voltage""", r"""UUT_Angle"""]) psspy.voltage_and_angle_channel([5, -1, -1, 106], [r"""POC_Voltage""", r"""POC_Angle"""]) psspy.machine_array_channel([7, 2, 100], r"""1""", r"""UUT_Pelec""") psspy.machine_array_channel([8, 3, 100], r"""1""", r"""UUT_Qelec""") psspy.branch_p_and_q_channel([9, -1, -1, 105, 106], r"""1""", [r"""POC_Flow""", ""]) psspy.machine_array_channel([11, 9, 100], r"""1""", r"""UUT_IDcmd""") psspy.machine_array_channel([12, 12, 100], r"""1""", r"""UUT_IQcmd""") psspy.machine_array_channel([13, 8, 100], r"""1""", r"""PPC_Pcmd""") psspy.machine_array_channel([14, 5, 100], r"""1""", r"""PPC_Qcmd""") psspy.strt_2([0, 0], OutputFilePath) psspy.run(0, 1.0, 1000, 5, 5) psspy.two_winding_data_3(bus_flt, bus_IDTRF, r"""1""", realari6=20) psspy.run(0, 6.0, 1000, 5, 5) psspy.two_winding_data_3(bus_flt, bus_IDTRF, r"""1""", realari6=0) psspy.run(0, 11.0, 1000, 5, 5) psspy.two_winding_data_3(bus_flt, bus_IDTRF, r"""1""", realari6=-20) psspy.run(0, 16.0, 1000, 5, 5) psspy.two_winding_data_3(bus_flt, bus_IDTRF, r"""1""", realari6=0) psspy.run(0, 20.0, 1000, 5, 5)
# save converted case psspy.save(r'{0}\savnw_C.sav'.format(example_path)) # Load dynamics ierr = psspy.dyre_new([_i, _i, _i, _i], dyr_case, _s, _s, _s) # Set output channels psspy.chsb(sid=0, all=1, status=[-1, -1, -1, 1, 12, 0]) # # Save snapshot psspy.snap(sfile=r'{0}\PythonDynTest.snp'.format(example_path)) # Initialize and run the dynamic scenario psspy.strt(option=0, outfile=out_file) psspy.run(0, 1, 0, 0, 0) # 3-phase fault on bus 151 (default bus fault is a 3phase and there is no bus 151) psspy.dist_bus_fault(ibus=151) # Run to 3 cycles time = 3.0 / 60.0 psspy.run(0, 1 + time, 0, 0, 0) # Clear fault (assuming only part of bus faults) psspy.dist_clear_fault() psspy.dist_branch_trip(ibus=151, jbus=201, id='1') # Run to 10 seconds time = 10 psspy.run(0, time, 0, 0, 0)
[ierr, var_inv1_var]= psspy.mdlind(500,'1','GEN','VAR') [ierr, var_inv1_mod]= psspy.mdlind(500,'1','GEN','ICON') # psspy.change_plmod_con(500,r"""1""",r"""GPMPPC""",26, 0.85) # # psspy.change_plmod_con(500,r"""1""",r"""GPMPPC""",27, 1.15) # psspy.change_con(var_ppc_conp+1, 0.01) #Proportional gain of reactive power PI controller 0.001 0.05 # psspy.change_con(var_ppc_conp+2, 0.05) # Integral gain of reactive power PI controller 0.015 0.4 # psspy.change_con(var_ppc_conp+23, 0.4) # Integral gain of reactive power PI controller 0.015 0.4 # # psspy.change_plmod_con(500,r"""1""",r"""GPMPPC""",2, 0.002) # # psspy.change_plmod_con(500,r"""1""",r"""GPMPPC""",3, 0.3) # psspy.change_plmod_icon(500,r"""1""",r"""GPMPPC""",4,2) psspy.strt_2([0,0], OutputFilePath) psspy.run(0, 1, 1000, 1, 0) psspy.change_var(var_ppc_setp+68,1.05) psspy.change_var(var_ppc_setp+10,85) # psspy.change_var(var_ppc_setp+11,0) psspy.run(0, 10, 1000, 1, 0) psspy.two_winding_chng_5(900,950,r"""1""",[_i,_i,_i,_i,_i,_i,_i,_i,900,_i,_i,0,_i,_i,_i],[_f,_f,_f, 0.90/1.05,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f],"","") psspy.run(0, 15, 1000, 1, 0) psspy.two_winding_chng_5(900,950,r"""1""",[_i,_i,_i,_i,_i,_i,_i,_i,900,_i,_i,0,_i,_i,_i],[_f,_f,_f, 1.05/1.05,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f],"","") psspy.run(0, 20, 1000, 1, 0) psspy.two_winding_chng_5(900,950,r"""1""",[_i,_i,_i,_i,_i,_i,_i,_i,900,_i,_i,0,_i,_i,_i],[_f,_f,_f, 0.80/1.05,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f],"","") psspy.run(0, 25, 1000, 1, 0) psspy.two_winding_chng_5(900,950,r"""1""",[_i,_i,_i,_i,_i,_i,_i,_i,900,_i,_i,0,_i,_i,_i],[_f,_f,_f, 1.05/1.05,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f],"","") psspy.run(0, 30, 1000, 1, 0)
# Line 2 params L2Bus1 = int(line2Elements[0]) L2Bus2 = int(line2Elements[1]) L2cktID = line2Elements[2].strip("'").strip() # get the nominal voltages as well as the fault impedance in ohms FaultBusNomVolt = float(BusDataDict[str(FaultBus)].NominalVolt) Zbase = FaultBusNomVolt**2/Sbase # float since Sbase is a float Rohm = FaultRpu*Zbase # fault impedance in ohms #print Rohm # run simulation ierr = psspy.strt(0,settings['out_file']) ierr = psspy.run(0,1.0,1,1,1) ierr = psspy.dist_branch_trip(L1Bus1, L1Bus2, L1cktID) # trip branch output = StringIO.StringIO() # reset output with silence(output): ierr = psspy.run(0,2.0,1,1,1) #fault on time outputStr = output.getvalue() if "Network not converged" in outputStr: print 'Case does not converge after branch outage before fault' #print outputStr ####### output = StringIO.StringIO()
ierr = psspy.machine_array_channel([7, 2, 101], r"""1""", r"""Pelec 101""") ierr = psspy.machine_array_channel([8, 3, 101], r"""1""", r"""Qelec 101""") ierr = psspy.machine_array_channel([9, 2, 102], r"""1""", r"""Pelec 102""") ierr = psspy.machine_array_channel([10, 3, 102], r"""1""", r"""Qelec 102""") ierr = psspy.machine_array_channel([11, 2, 103], r"""1""", r"""Pelec 103""") ierr = psspy.machine_array_channel([12, 3, 103], r"""1""", r"""Qelec 103""") ierr = psspy.machine_array_channel([13, 2, 104], r"""1""", r"""Pelec 104""") ierr = psspy.machine_array_channel([14, 3, 104], r"""1""", r"""Qelec 104""") #ierr = psspy.state_channel([9, var_inv_stt + 6], r"""Inverter Voltage Measurement""") # start simulation ## psspy.change_con(var_ppc_conp+1,0.1) ## psspy.change_con(var_ppc_conp+2,1.5) ## psspy.change_con(var_ppc_conp+3,0.6) psspy.strt_2([0, 0], OutputFilePath) psspy.run(0, 5, 1000, 1, 0) # [ierr, POC_v_pu] = busdat(400 ,'PU') psspy.change_var(var_ppc_setp + 68, 1.0) psspy.run(0, 20, 1000, 1, 0) psspy.change_var(var_ppc_setp + 68, 0.95) psspy.run(0, 50, 1000, 1, 0) psspy.change_var(var_ppc_setp + 68, 1.0) psspy.run(0, 80, 1000, 1, 0) psspy.change_var(var_ppc_setp + 68, 1.05) psspy.run(0, 110, 1000, 1, 0) psspy.change_var(var_ppc_setp + 68, 1.0) psspy.run(0, 140, 1000, 1, 0) # start draw curves # new folder if necessary
print('Event: {}'.format(event)) # get the nominal voltages as well as the fault impedance in ohms FaultBusNomVolt = float(BusDataDict[str(FaultBus)].NominalVolt) Zbase = FaultBusNomVolt**2/Sbase # float since Sbase is a float Rohm = FaultRpu*Zbase # fault impedance in ohms # run simulation till just before the fault output = StringIO.StringIO() with silence(output): # load the sav and snp file psspy.case(savFile) psspy.rstr(snpFile) #output = StringIO.StringIO() with silence(output): ierr = psspy.strt(0,out_file) ierr = psspy.run(0,0.1,1,1,1) ierr = psspy.dist_branch_trip(L1Bus1, L1Bus2, L1cktID) #output = StringIO.StringIO() with silence(output): ierr = psspy.run(0,0.2,1,1,1) #fault on time outputStr = output.getvalue() if "Network not converged" in outputStr: print('For ' + event + ':') print('Network did not converge between branch 1 trip and fault application, skipping...') continue ####### # check for convergence during fault #output = StringIO.StringIO()
[r"""P Injection""", r"""Q Injection"""]) ierr = psspy.machine_array_channel([7, 2, 101], r"""1""", r"""Pelec 101""") ierr = psspy.machine_array_channel([8, 3, 101], r"""1""", r"""Qelec 101""") ierr = psspy.machine_array_channel([9, 2, 102], r"""1""", r"""Pelec 102""") ierr = psspy.machine_array_channel([10, 3, 102], r"""1""", r"""Qelec 102""") ierr = psspy.machine_array_channel([11, 2, 103], r"""1""", r"""Pelec 103""") ierr = psspy.machine_array_channel([12, 3, 103], r"""1""", r"""Qelec 103""") ierr = psspy.machine_array_channel([13, 2, 104], r"""1""", r"""Pelec 104""") ierr = psspy.machine_array_channel([14, 3, 104], r"""1""", r"""Qelec 104""") #ierr = psspy.state_channel([15, var_inv_stt + 6], r"""Inverter Voltage Measurement""") psspy.var_channel([15, var_ppc_setp + 68], r"""Voltage Setpoint""") psspy.change_plmod_icon(101, r"""1""", r"""HWS2000""", 4, 1) # start simulation psspy.strt_2([0, 0], OutputFilePath) psspy.run(0, 5, 1000, 1, 0) psspy.change_var(var_ppc_setp + 68, 1.05) psspy.run(0, 25, 1000, 1, 0) psspy.change_var(var_ppc_setp + 68, 1.06) psspy.run(0, 45, 1000, 1, 0) psspy.change_var(var_ppc_setp + 68, 1.05) psspy.run(0, 65, 1000, 1, 0) psspy.change_var(var_ppc_setp + 68, 1.04) psspy.run(0, 85, 1000, 1, 0) psspy.change_var(var_ppc_setp + 68, 1.03) psspy.run(0, 105, 1000, 1, 0) # start draw curves # new folder if necessary GraphPath = FigurePath + ClauseName