def fault_LL(faultbus, faultphases, phases, r, buscoords, dssObj, conn, c): """LL fault simulation in bus and results """ # Get directory of .py file dir = os.path.dirname(os.path.abspath(__file__)) dssText = dssObj.Text dssCircuit = dssObj.ActiveCircuit dssBus = dssCircuit.ActiveBus dssText.Command = "Edit Fault.fault phases=1 bus1="+faultbus \ +faultphases[0]+" bus2="+faultbus+faultphases[1]+" r="+r for season in ["Spring", "Summer", "Autumn", "Winter"]: dssText.Command = "Edit Loadshape.LS_PhaseA" \ +" mult=(file=LS_PhaseA_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_PhaseB" \ +" mult=(file=LS_PhaseB_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_PhaseC" \ +" mult=(file=LS_PhaseC_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_ThreePhase" \ +" mult=(file=LS_ThreePhase_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.Other_Bus_Load" \ +" mult=(file=Other_Bus_Load_"+season+"Day.txt)" dssText.Command = "Redirect " + dir + "\\5PV_" + season + ".dss" for hour in [9, 10, 11, 12, 13, 14, 15, 16, 17]: dssText.Command = "Redirect " + dir + "\\ckt24_vbases.dss" dssText.Command = "Solve mode=daily number=1 hour=" + str(hour) Vsub = V("SubXfmr_LSB", dssCircuit) Csub = C("Transformer.SUBXFMR", dssCircuit) c.execute( """INSERT INTO PV5_faultloc_db (fault_type, season, hour, bus, buscoordX, buscoordY, fault_resistance, busphases, faultphases, Vsub_mag1, Vsub_ang1, Vsub_mag2, Vsub_ang2, Vsub_mag3, Vsub_ang3, Isub_mag1, Isub_ang1, Isub_mag2, Isub_ang2, Isub_mag3, Isub_ang3) VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""", ("LL", season, int(hour), faultbus, float( buscoords[0]), float(buscoords[1]), int(r), phases, faultphases[0] + faultphases[1], float3(Vsub[0]), float3(Vsub[1]), float3(Vsub[2]), float3( Vsub[3]), float3(Vsub[4]), float3(Vsub[5]), float3( Csub[8]), float3(Csub[9]), float3(Csub[10]), float3(Csub[11]), float3(Csub[12]), float3(Csub[13]))) conn.commit() return
def lines_criteria(): # Get directory of .py file dir = os.path.dirname(os.path.abspath(__file__)) flag_noPV = 0 flag_PV = 1 # Make lists with line names # Line_1p_list line1p_list = line_name_lists()[0] for i in range(len(line1p_list)): if i == 0: line1p_listn = [line1p_list[0][0]] else: line1p_listn.append(line1p_list[i][0]) # Line_2p_list line2p_list = line_name_lists()[1] for i in range(len(line2p_list)): if i == 0: line2p_listn = [line2p_list[0][0]] else: line2p_listn.append(line2p_list[i][0]) # Line_3p_list line3p_list = line_name_lists()[2] for i in range(len(line3p_list)): if i == 0: line3p_listn = [line3p_list[0][0]] else: line3p_listn.append(line3p_list[i][0]) # Hours of interest when solving the circuit # hours = [list(range(24)) # for i in range(len(hours)): # hours[i] = str(hours[i])] hours = ["9", "10", "11", "12", "13", "14", "15", "16", "17"] PV_powers_Climit = [] # Line currents criteria print("Running circuit comparisons for currents - lines criteria\n") t_start = time.time() # hours = [list(range(24)) # for i in range(len(hours)): # hours[i] = str(hours[i])] # Start the DSS dssObj = win32com.client.Dispatch("OpenDSSEngine.DSS") if dssObj.Start(0) == False: sys.exit("DSS failed to start") else: #Assign a variable to each of the interfaces dssText = dssObj.Text dssCircuit = dssObj.ActiveCircuit dssSolution = dssCircuit.Solution # Clear the DSS dssObj.ClearAll() # Load circuit dssText.Command = "Compile " + dir + "\\ckt24\\ckt24.dss" # Solve circuit in different loadshapes, season based dssText.Command = "Edit Loadshape.LS_PhaseA" \ +" mult=(file=LS_PhaseA_SummerDay.txt)" dssText.Command = "Edit Loadshape.LS_PhaseB" \ +" mult=(file=LS_PhaseB_SummerDay.txt)" dssText.Command = "Edit Loadshape.LS_PhaseC" \ +" mult=(file=LS_PhaseC_SummerDay.txt)" dssText.Command = "Edit Loadshape.LS_ThreePhase" \ +" mult=(file=LS_ThreePhase_SummerDay.txt)" dssText.Command = "Edit Loadshape.Other_Bus_Load" \ +" mult=(file=Other_Bus_Load_SummerDay.txt)" # Set and calculate voltage bases dssText.Command = "Redirect " + dir + "\\ckt24\\ckt24_vbases.dss" # Solve circuit dssText.Command = "Solve mode=daily number=1 hour=15" currents_list1p_noPV = [] currents_list2p_noPV = [] currents_list3p_noPV = [] for line1p in line1p_listn: dssCircuit.SetActiveElement("Line." + line1p) currents_list1p_noPV.append(dssCircuit.ActiveElement.NormalAmps) for line2p in line2p_listn: dssCircuit.SetActiveElement("Line." + line2p) currents_list2p_noPV.append(dssCircuit.ActiveElement.NormalAmps) for line3p in line3p_listn: dssCircuit.SetActiveElement("Line." + line3p) currents_list3p_noPV.append(dssCircuit.ActiveElement.NormalAmps) hours = ["9", "10", "11", "12", "13", "14", "15", "16", "17"] PV_powers_Climit = [] for season in ["Spring", "Summer", "Autumn", "Winter"]: for hour in hours: PV_power = 500 power_iteration = "run again" while power_iteration == "run again": # Clear the DSS dssObj.ClearAll() # Load circuit dssText.Command = "Compile " + dir + "\\ckt24\\ckt24.dss" # Set and calculate voltage bases dssText.Command = "Redirect " + dir + "\\ckt24\\ckt24_vbases.dss" # Solve circuit in different loadshapes, season based dssText.Command = "Edit Loadshape.LS_PhaseA" \ +" mult=(file=LS_PhaseA_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_PhaseB" \ +" mult=(file=LS_PhaseB_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_PhaseC" \ +" mult=(file=LS_PhaseC_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_ThreePhase" \ +" mult=(file=LS_ThreePhase_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.Other_Bus_Load" \ +" mult=(file=Other_Bus_Load_"+season+"Day.txt)" # Change PVSystem parameters to get max power dssText.Command = \ "Redirect "+dir+"\\ckt24\\5PV_new.dss" dssText.Command = "Redirect " + dir + "\\ckt24\\5PV_" + season + ".dss" dssText.Command = "Edit PVSystem.PV1 kVA=" \ +str(PV_power)+" pmpp="+str(PV_power) dssText.Command = "Edit PVSystem.PV2 kVA=" \ +str(PV_power)+" pmpp="+str(PV_power) dssText.Command = "Edit PVSystem.PV3 kVA=" \ +str(PV_power)+" pmpp="+str(PV_power) dssText.Command = "Edit PVSystem.PV4 kVA=" \ +str(PV_power)+" pmpp="+str(PV_power) dssText.Command = "Edit PVSystem.PV5 kVA=" \ +str(PV_power)+" pmpp="+str(PV_power) dssText.Command = "Edit Transformer.pv_up1 kVA=" \ +str(PV_power) dssText.Command = "Edit Transformer.pv_up2 kVA=" \ +str(PV_power) dssText.Command = "Edit Transformer.pv_up3 kVA=" \ +str(PV_power) dssText.Command = "Edit Transformer.pv_up4 kVA=" \ +str(PV_power) dssText.Command = "Edit Transformer.pv_up5 kVA=" \ +str(PV_power) # Set and calculate voltage bases dssText.Command = "Redirect " + dir + "\\ckt24\\ckt24_vbases.dss" # Solve circuit dssText.Command = "Solve mode=daily number=1 hour=" + hour # Results list currents_list1p_PV = [] currents_list2p_PV = [] currents_list3p_PV = [] for lines1p in line1p_listn: currents_list1p_PV.append(C("Line." + lines1p, dssCircuit)) for lines2p in line2p_listn: currents_list2p_PV.append(C("Line." + lines2p, dssCircuit)) for lines3p in line3p_listn: currents_list3p_PV.append(C("Line." + lines3p, dssCircuit)) C_flag = 0 safe_factor = 0.8 for i in range(len(currents_list1p_noPV)): if abs(currents_list1p_PV[i][0]) > \ safe_factor*abs(currents_list1p_noPV[i]): C_flag = 1 for i in range(len(currents_list2p_noPV)): if abs(currents_list2p_PV[i][0]) > \ safe_factor*abs(currents_list2p_noPV[i]): C_flag = 1 if abs(currents_list2p_PV[i][2]) > \ safe_factor*abs(currents_list2p_noPV[i]): C_flag = 1 for i in range(len(currents_list3p_noPV)): if abs(currents_list3p_PV[i][0]) > \ safe_factor*abs(currents_list3p_noPV[i]): C_flag = 1 if abs(currents_list3p_PV[i][2]) > \ safe_factor*abs(currents_list3p_noPV[i]): C_flag = 1 if abs(currents_list3p_PV[i][4]) > \ safe_factor*abs(currents_list3p_noPV[i]): C_flag = 1 if C_flag == 1: PV_powers_Climit.append([season, hour, PV_power - 500]) power_iteration = "stop running" if PV_power == 9000: PV_powers_Climit.append([season, hour, "max_iter_9000"]) power_iteration = "stop running" PV_power = PV_power + 500 print("Running simulation of season %s, hour %s..." % (season, hour)) print() print("List with season, hour and maximum power for PVSystem:") print(PV_powers_Climit) print() PV_powers_Climit = [int(e[-1]) for e in PV_powers_Climit] print("Minimum value: %d kW" % min(PV_powers_Climit)) print() t_end = time.time() print("Total simulation time (current comparisons - " "lines criteria): %f" % (t_end - t_start))
def fault_LLLG(faultbus, r, buscoords, xfmr_list, dssObj, conn, c): """LLLG fault simulation in bus and results """ # Get directory of .py file dir = os.path.dirname(os.path.abspath(__file__)) dssText = dssObj.Text dssCircuit = dssObj.ActiveCircuit dssBus = dssCircuit.ActiveBus dssText.Command = "Edit Fault.fault phases=3 bus1=" + faultbus + ".1.2.3 r=" + r for season in ["Spring", "Summer", "Autumn", "Winter"]: if season == "Spring": irrad = "0.981" if season == "Summer": irrad = "0.944" if season == "Autumn": irrad = "0.923" if season == "Winter": irrad = "0.950" dssText.Command = "Edit Loadshape.LS_PhaseA" \ +" mult=(file=LS_PhaseA_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_PhaseB" \ +" mult=(file=LS_PhaseB_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_PhaseC" \ +" mult=(file=LS_PhaseC_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_ThreePhase" \ +" mult=(file=LS_ThreePhase_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.Other_Bus_Load" \ +" mult=(file=Other_Bus_Load_"+season+"Day.txt)" dssText.Command = "Redirect " + dir + "\\339PV_" + season + ".dss" for i in range(len(xfmr_list)): bus_pv = xfmr_list[i][6] kv_pv = xfmr_list[i][7] phase = str(xfmr_list[i][1]) dssText.Command = "Edit PVSystem.PV"+str(i)\ +" phases=1 bus1="+bus_pv+"."+phase+" kv="+kv_pv+" kVA=15"\ +" irrad="+irrad+" pmpp=15 temperature=25 pf=1"\ +" %cutin=5 %cutout=5 effcurve=MyEff P-tCurve=MyPvst"\ +" Daily=MyIrrad Tdaily=Mytemp" for hour in [9, 10, 11, 12, 13, 14, 15, 16, 17]: dssText.Command = "Redirect " + dir + "\\ckt24_vbases.dss" dssText.Command = "Solve mode=daily number=1 hour=" + str(hour) Vsub = V("SubXfmr_LSB", dssCircuit) Csub = C("Transformer.SUBXFMR", dssCircuit) c.execute( """INSERT INTO PV339_faultloc_db (fault_type, season, hour, bus, buscoordX, buscoordY, fault_resistance, busphases, faultphases, Vsub_mag1, Vsub_ang1, Vsub_mag2, Vsub_ang2, Vsub_mag3, Vsub_ang3, Isub_mag1, Isub_ang1, Isub_mag2, Isub_ang2, Isub_mag3, Isub_ang3) VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""", ("LLLG", season, int(hour), faultbus, float( buscoords[0]), float(buscoords[1]), int(r), ".1.2.3", ".1.2.3", float3(Vsub[0]), float3(Vsub[1]), float3(Vsub[2]), float3(Vsub[3]), float3(Vsub[4]), float3(Vsub[5]), float3(Csub[8]), float3(Csub[9]), float3(Csub[10]), float3(Csub[11]), float3(Csub[12]), float3(Csub[13]))) conn.commit() return
def fault_LLG(faultbus, faultphases, phases, r, buscoords, dssObj, conn, c): """LLG fault simulation in bus and results """ # Get directory of .py file dir = os.path.dirname(os.path.abspath(__file__)) # Create database for faults conn = sqlite3.connect('database_faultlocation_1PV.db') c = conn.cursor() c.execute("""CREATE TABLE IF NOT EXISTS PV1_faultloc_db ( fault_type TEXT, season TEXT, hour INT, bus TEXT, buscoordX REAL, buscoordY REAL, fault_resistance INT, busphases TEXT, faultphases TEXT, Vsub_mag1 REAL, Vsub_ang1 REAL, Vsub_mag2 REAL, Vsub_ang2 REAL, Vsub_mag3 REAL, Vsub_ang3 REAL, Isub_mag1 REAL, Isub_ang1 REAL, Isub_mag2 REAL, Isub_ang2 REAL, Isub_mag3 REAL, Isub_ang3 REAL)""") dssText = dssObj.Text dssCircuit = dssObj.ActiveCircuit dssBus = dssCircuit.ActiveBus dssText.Command = "Edit Fault.fault phases=2 bus1="+faultbus \ +faultphases[0]+faultphases[0]+" bus2="+faultbus+faultphases[1] \ +".0"+" Gmatrix=[10000|0 "+str(1/float(r))+"|-10000 0 10000|0 " \ +str(-1/float(r))+" 0 "+str(1/float(r))+"]" for season in ["Spring", "Summer", "Autumn", "Winter"]: dssText.Command = "Edit Loadshape.LS_PhaseA" \ +" mult=(file=LS_PhaseA_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_PhaseB" \ +" mult=(file=LS_PhaseB_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_PhaseC" \ +" mult=(file=LS_PhaseC_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_ThreePhase" \ +" mult=(file=LS_ThreePhase_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.Other_Bus_Load" \ +" mult=(file=Other_Bus_Load_"+season+"Day.txt)" dssText.Command = "Redirect " + dir + "\\1PV_" + season + ".dss" for hour in [9, 10, 11, 12, 13, 14, 15, 16, 17]: dssText.Command = "Redirect " + dir + "\\ckt24_vbases.dss" dssText.Command = "Solve mode=daily number=1 hour=" + str(hour) Vsub = V("SubXfmr_LSB", dssCircuit) Csub = C("Transformer.SUBXFMR", dssCircuit) c.execute( """INSERT INTO PV1_faultloc_db (fault_type, season, hour, bus, buscoordX, buscoordY, fault_resistance, busphases, faultphases, Vsub_mag1, Vsub_ang1, Vsub_mag2, Vsub_ang2, Vsub_mag3, Vsub_ang3, Isub_mag1, Isub_ang1, Isub_mag2, Isub_ang2, Isub_mag3, Isub_ang3) VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""", ("LLG", season, int(hour), faultbus, float( buscoords[0]), float(buscoords[1]), int(r), phases, faultphases[0] + faultphases[1], float3(Vsub[0]), float3(Vsub[1]), float3(Vsub[2]), float3( Vsub[3]), float3(Vsub[4]), float3(Vsub[5]), float3( Csub[8]), float3(Csub[9]), float3(Csub[10]), float3(Csub[11]), float3(Csub[12]), float3(Csub[13]))) conn.commit() return
def main(): t_start = time.time() # Get directory of .py file dir = os.path.dirname(os.path.abspath(__file__)) # Bus_1p_list bus1p_list = bus_name_lists()[0] # Bus_2p_list bus2p_list = bus_name_lists()[1] # Bus_3p_list bus3p_list = bus_name_lists()[2] print("Running circuit solution\n") t_start = time.time() # Start the DSS dssObj = win32com.client.Dispatch("OpenDSSEngine.DSS") if dssObj.Start(0) == False: sys.exit("DSS failed to start") else: #Assign a variable to each of the interfaces for easier access dssText = dssObj.Text dssCircuit = dssObj.ActiveCircuit dssSolution = dssCircuit.Solution # Clear the DSS dssObj.ClearAll() # Load circuit dssText.Command = "Compile " + dir + "\\ckt24\\ckt24.dss" # Solve circuit in different loadshapes, according to seasons dssText.Command = "Redirect " + dir + "\\ckt24\\1PV_new.dss" for season in ["Spring", "Summer", "Autumn", "Winter"]: dssText.Command = "Edit Loadshape.LS_PhaseA" \ +" mult=(file=LS_PhaseA_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_PhaseB" \ +" mult=(file=LS_PhaseB_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_PhaseC" \ +" mult=(file=LS_PhaseC_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_ThreePhase" \ +" mult=(file=LS_ThreePhase_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.Other_Bus_Load" \ +" mult=(file=Other_Bus_Load_"+season+"Day.txt)" dssText.Command = "Redirect " + dir + "\\ckt24\\1PV_" + season + ".dss" for hour in [9, 10, 11, 12, 13, 14, 15, 16, 17]: # Set and calculate voltage bases dssText.Command = "Redirect " + dir + "\\ckt24\\ckt24_vbases.dss" dssText.Command = "Solve mode=daily number=1 hour=" + str(hour) # Results list results_list = [[season, hour], V("SourceBus", dssCircuit), V("SubXfmr_LSB", dssCircuit), C("Vsource.source", dssCircuit), C("Transformer.SUBXFMR", dssCircuit)] with open(dir+"\\ckt24_solve.txt","a") \ as filehandler: json.dump(results_list, filehandler) filehandler.write("\n") t_end = time.time() print("Total simulation time: %f" % (t_end - t_start))
def main(): t_start = time.time() # Get directory of .py file dir = os.path.dirname(os.path.abspath(__file__)) # Bus_1p_list bus1p_list = bus_name_lists()[0] # Bus_2p_list bus2p_list = bus_name_lists()[1] # Bus_3p_list bus3p_list = bus_name_lists()[2] # List with transformers info xfmr_list = transformer_list() print("Running circuit solution\n") t_start = time.time() # Start the DSS dssObj = win32com.client.Dispatch("OpenDSSEngine.DSS") if dssObj.Start(0) == False: sys.exit("DSS failed to start") else: #Assign a variable to each of the interfaces for easier access dssText = dssObj.Text dssCircuit = dssObj.ActiveCircuit dssSolution = dssCircuit.Solution # Clear the DSS dssObj.ClearAll() # Load circuit dssText.Command = "Compile " + dir + "\\ckt24\\ckt24.dss" new_edit = "New " # Solve circuit in different loadshapes, according to seasons dssText.Command = "Redirect " + dir + "\\ckt24\\339PV_new.dss" for season in ["Spring", "Summer", "Autumn", "Winter"]: if season == "Spring": irrad = "0.981" if season == "Summer": irrad = "0.944" if season == "Autumn": irrad = "0.923" if season == "Winter": irrad = "0.950" dssText.Command = "Edit Loadshape.LS_PhaseA" \ +" mult=(file=LS_PhaseA_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_PhaseB" \ +" mult=(file=LS_PhaseB_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_PhaseC" \ +" mult=(file=LS_PhaseC_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.LS_ThreePhase" \ +" mult=(file=LS_ThreePhase_"+season+"Day.txt)" dssText.Command = "Edit Loadshape.Other_Bus_Load" \ +" mult=(file=Other_Bus_Load_"+season+"Day.txt)" dssText.Command = "Redirect " + dir + "\\ckt24\\339PV_" + season + ".dss" for i in range(len(xfmr_list)): bus_pv = xfmr_list[i][6] kv_pv = xfmr_list[i][7] phase = str(xfmr_list[i][1]) dssText.Command = new_edit+"PVSystem.PV"+str(i)\ +" phases=1 bus1="+bus_pv+"."+phase+" kv="+kv_pv+" kVA=15"\ +" irrad="+irrad+" pmpp=15 temperature=25 pf=1"\ +" %cutin=5 %cutout=5 effcurve=MyEff P-tCurve=MyPvst"\ +" Daily=MyIrrad Tdaily=Mytemp" if new_edit == "New ": new_edit = "Edit " for hour in [9, 10, 11, 12, 13, 14, 15, 16, 17]: # Set and calculate voltage bases dssText.Command = "Redirect " + dir + "\\ckt24\\ckt24_vbases.dss" dssText.Command = "Solve mode=daily number=1 hour=" + str(hour) # Results list results_list = [[season, hour], V("SourceBus", dssCircuit), V("SubXfmr_LSB", dssCircuit), C("Vsource.source", dssCircuit), C("Transformer.SUBXFMR", dssCircuit)] with open(dir+"\\ckt24_solve.txt","a") \ as filehandler: json.dump(results_list, filehandler) filehandler.write("\n") t_end = time.time() print("Total simulation time: %f" % (t_end - t_start))