def disconnect_gens(df_disconnect_gen): delta_gen_change_down = 0 for index, row in df_disconnect_gen.iterrows(): gen_bus = row["Bus number"] gen_id = row["Id"] #disconnect gen psspy.machine_chng_2(gen_bus, str(gen_id), [0, _i, _i, _i, _i, 0], [ _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, 1.0 ]) return
def add_new_gen(gen_bus, P_inj, Q_max, Q_min): psspy.bus_data_3(gen_bus, [1, 1, 1, 1], [0.0, 1.0, 0.0, 1.1, 0.9, 1.1, 0.9], "") psspy.bus_chng_3(gen_bus, [2, _i, _i, _i], [_f, _f, _f, _f, _f, _f, _f], _s) psspy.plant_data(gen_bus, 0, [1.0, 100.0]) psspy.machine_data_2(gen_bus, r"""1""", [1, 1, 0, 0, 0, 0], [ 0.0, 0.0, 9999.0, -9999.0, 9999.0, -9999.0, 100.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ]) psspy.machine_chng_2(gen_bus, r"""1""", [_i, _i, _i, _i, _i, 1], [ P_inj, _f, Q_max, Q_min, P_inj, 0.0, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f ]) return
Bus_Nam[Bus_Num.index(Fault_Equipment_End[i])] + ' ' + Equipment_ID[i]) ierr, whatever = psspy.three_wnd_imped_chng_4( Fault_Equipment_Start[i], Fault_Equipment_End[i], Third_Bus_Record[i], Equipment_ID[i], [_i, _i, _i, _i, _i, _i, _i, 0, _i, _i, _i, _i, _i], [ _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f ], _s, _s) if Fault_Equipment_Type[i] == 'GE': # disconnect generator Event_Name.append('Output=' + str(4 * P_setpoint) + 'MW' + ' ' + 'Gen Outage - ' + Bus_Nam[Bus_Num.index(Fault_Equipment_Start[i])]) ierr = psspy.machine_chng_2(Fault_Equipment_Start[i], 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 ]) if Fault_Equipment_Type[i] == 'SH': # disconnect switched shunt Event_Name.append('Output=' + str(4 * P_setpoint) + 'MW' + ' ' + 'Shunt Capacitor Outage - ' + Bus_Nam[Bus_Num.index(Fault_Equipment_Start[i])]) ierr = psspy.switched_shunt_chng_3( Fault_Equipment_Start[i], [_i, _i, _i, _i, _i, _i, _i, _i, _i, _i, 0, _i], [_f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f], _s) if Fault_Equipment_Type[i] == 'QL': # clearn Q Load Event_Name.append('Output=' + str(4 * P_setpoint) + 'MW' + ' ' + 'Shunt Capacitor Outage - ' + Bus_Nam[Bus_Num.index(Fault_Equipment_Start[i])]) ierr = psspy.load_chng_5(Fault_Equipment_Start[i], r"""1""",
# Initialize psspy.case(GridInfoPath+file_name+".sav") # psspy.rstr(GridInfoPath+file_name+".snp") psspy.resq(GridInfoPath + "/" + file_name + ".seq") psspy.dyre_new([1, 1, 1, 1], GridInfoPath + "/" + file_name + ".dyr", "", "", "") psspy.addmodellibrary(HuaweiModelPath+'HWS2000_psse34.dll') psspy.addmodellibrary(HuaweiModelPath+'MOD_GPM_PPC_V13_34.dll') psspy.addmodellibrary(HuaweiModelPath+'MOD_GPM_SB_V7.dll') psspy.plant_chng_3(500,0,_i,[ 1.05,_f]) psspy.plant_chng_3(1000,0,_i,[ 1.047,_f]) psspy.dynamics_solution_param_2([_i,_i,_i,_i,_i,_i,_i,_i],[0.300,_f, 0.001,0.004,_f,_f,_f,_f]) psspy.machine_data_2(500, r"""1""", [_i, _i, _i, _i, _i, _i],[87, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f]) psspy.two_winding_chng_5(700,800,r"""1""",[_i,_i,_i,_i,_i,_i,_i,_i,800,_i,_i,1,_i,_i,_i],[_f,_f,_f, 1.0,_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],r"""SS-TF-1""", r"""YNYN0""") psspy.machine_chng_2(500,r"""1""",[_i,_i,_i,_i,_i,_i],[_f,0.0,0,0,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f]) psspy.fnsl([0,0,0,1,0,0,99,0]) # convert load , do not change psspy.cong(0) psspy.bus_frequency_channel([1,1000],r"""System frequency""") ierr=psspy.machine_array_channel([2,4,500],r"""1""",r"""Inverter Terminal Voltage""") ierr=psspy.voltage_channel([3,-1,-1,800],r"""WISF PoC Voltage""") psspy.branch_p_and_q_channel([4,-1,-1,800,900],r"""1""",[r"""P Injection""",r"""Q Injection"""]) psspy.branch_p_and_q_channel([6,-1,-1,500,600],r"""1""",[r"""P Injection""",r"""Q Injection"""]) # ierr=psspy.machine_array_channel([6,2,500],r"""1""",r"""Pelec Inverter""") # ierr=psspy.machine_array_channel([7,3,500],r"""1""",r"""Qelec Inverter""") [ierr, var_ppc_conp] = psspy.mdlind(500, '1', 'EXC', 'CON') [ierr, var_ppc_setp] = psspy.mdlind(500, '1', 'EXC', 'VAR')
for P_Gen_1 in numpy.arange(0, S_1 * derate + 0.01, 2): psspy.read(0, GridInfoPath + file_name) psspy.plant_data_3(SMIB_bus_no, 0, _i, [terminalv, _f]) # ierr = psspy.fdns([1, 0, 0, 1, 1, 0, 99, 0]) P_BESS = P_Gen_1 / (S_1 * derate + 0.01) * P_BESS_max Q_Gen_1 = max( -50.16, -math.sqrt( max((S_1 * S_1 * derate * derate - P_Gen_1 * P_Gen_1), 0))) Q_Gen_BESS = max( -9.26, -math.sqrt( max(S_BESS * S_BESS * derate * derate - P_BESS * P_BESS, 0))) psspy.machine_chng_2(100, r"""1""", [_i, _i, _i, _i, _i, _i], [ P_Gen_1, Q_Gen_1, Q_Gen_1, Q_Gen_1, S_1, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f ]) psspy.machine_chng_2(200, r"""1""", [_i, _i, _i, _i, _i, _i], [ P_BESS, Q_Gen_BESS, Q_Gen_BESS, Q_Gen_BESS, S_BESS, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f ]) # psspy.machine_chng_2(200, r"""1""", [_i, _i, _i, _i, _i, _i], [P_BESS, _f, _f, _f, S_BESS, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f]) psspy.plant_data_3(SMIB_bus_no, 0, _i, [terminalv, _f]) # fixed slope decoupled Newton-Raphson power flow calculation, 1_tap, 2_area_interchange, 3_phase_shift, 4_dc_tap, 5_switched shunt,6_flat_start, 7_Var_limit,8__non-divergent solution ierr = psspy.fdns([1, 0, 0, 1, 1, 0, 99, 0]) #brnmsc: return real branch flow values ierr, pval = psspy.brnmsc(POC_bus_gen, POC_bus_grid, '1', 'P') # POC_P_value
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
def change_gen_output(bus_nbr, gen_id, new_P_out): psspy.machine_chng_2(bus_nbr, str(gen_id), [_i, _i, _i, _i, _i, _i], [ new_P_out, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f ]) return
vgenidtmp = carray[0] # this array has all the generator's ID, string ierr, rarray = psspy.amachreal(-1, 4, 'PMAX') vgenpmaxtmp = rarray[0] # this array has all the generator's Pmax, MW ierr, rarray = psspy.amachreal(-1, 4, 'PMIN') vgenpmintmp = rarray[0] # this array has all the generator's Pmin, MW geninfotmp = zip(vgenpmaxtmp, vgenpmintmp) genbusdicttmp = {} gendroop = {} for igentmp in range(0, len(vgenbusnotmp)): genbuskeytmp = str( vgenbusnotmp[igentmp]) + '-' + vgenidtmp[igentmp].strip() genbusdicttmp.update({genbuskeytmp: geninfotmp[igentmp]}) # Set Mbase to 100 for all machines ierr = psspy.machine_chng_2(vgenbusnotmp[igentmp], vgenidtmp[igentmp], realar7=100.0) #shutil.copyfile (fileINL, fileINL[:-4]+'_org.inl') #first keep a copy of the original inl file fileINLorg = fileINL[:-4] + '_org.inl' if os.path.exists(fileINLorg): os.remove(fileINLorg) os.rename(fileINL, fileINLorg) else: os.rename(fileINL, fileINLorg) finlorg = open(fileINLorg) inllines = finlorg.readlines() finldst = open(fileINL, 'w')
psspy.dynamics_solution_params(realar=[_f, _f, 0.005, _f, _f, _f, _f, _f]) psspy.machine_array_channel([1, 2, 6000]) # Monitor Kvilldal Power psspy.machine_array_channel([2, 7, 6000]) # Monitor Kvilldal Frequency load = load_models.Load(6500) # Create a load consisting of Trondheim ierr = psspy.strt(outfile=outputfile) # Tell PSS/E to write to the output file # Simulation---------------------------------------------------------------------------------------------------------------------------------- if ierr == 0: # If output file can be opened??? CHECK THIS psspy.run(0, 0.1,1,1,0) psspy.machine_chng_2(5600,r"""1""",[0,_i,_i,_i,_i,_i],[ 261.115, 289.52,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f]) psspy.machine_chng_2(5600,r"""2""",[0,_i,_i,_i,_i,_i],[ 261.115, 289.52,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f]) psspy.run(0, 0.3,1,1,0) #psspy.machine_chng_2(5600,r"""3""",[0,_i,_i,_i,_i,_i],[ 278.17, 473.175,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f]) #psspy.machine_chng_2(5600,r"""1""",[1,_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f]) #psspy.machine_chng_2(5600,r"""2""",[1,_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f]) #psspy.machine_chng_2(5600,r"""3""",[1,_i,_i,_i,_i,_i],[_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f,_f]) #psspy.run(0, 1.0,1,1,0) else: print(ierr) # Read the putput file
for i in range(num_groups): psspy.dscn(ONSS_HV[i]) psspy.dscn(ONSS_LV[i]) psspy.dscn(OFSS_HV[i]) psspy.dscn(OFSS_LV[i]) psspy.dscn(ONSRE_HDD_6[i]) psspy.dscn(ONSRE_HDD_5[i]) psspy.dscn(ONSRE_HDD_4[i]) psspy.dscn(ONSRE_HDD_3[i]) psspy.dscn(ONSRE_HDD_2[i]) psspy.dscn(ONSRE_HDD_1[i]) psspy.dscn(CNCRT_DB[i]) psspy.dscn(LNDFAL_HDD[i]) psspy.dscn(SEABED[i]) psspy.machine_chng_2( ONSS_HV[i], r"""1""", [0, _i, _i, _i, _i, _i], [0.0, 0.0, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f]) psspy.shunt_chng(ONSS_LV[i], r"""1""", 0, [_f, _f]) psspy.shunt_chng(ONSS_LV[i], r"""2""", 0, [_f, _f]) psspy.shunt_chng(ONSS_LV[i], r"""3""", 0, [_f, _f]) psspy.shunt_chng(ONSS_LV[i], r"""4""", 0, [_f, _f]) psspy.shunt_chng(ONSS_LV[i], r"""5""", 0, [_f, _f]) psspy.shunt_chng(ONSS_LV[i], r"""6""", 0, [_f, _f]) psspy.shunt_chng(ONSS_LV[i], r"""7""", 0, [_f, _f]) psspy.shunt_chng(ONSS_LV[i], r"""8""", 0, [_f, _f]) psspy.shunt_chng(OFSS_HV[i], r"""1""", 0, [_f, _f]) psspy.fnsl([0, 0, 0, 1, 1, 0, 0, 0]) psspy.fnsl([0, 0, 0, 1, 1, 0, 0, 0]) ################################################################################################ #functions