Ejemplo n.º 1
0
def main():

    t_start = time.time()

    # Get directory of .py file
    dir = os.path.dirname(os.path.abspath(__file__))

    # Create database for faults
    conn = sqlite3.connect('database_faultlocation_5PV.db')
    c = conn.cursor()
    c.execute("""CREATE TABLE IF NOT EXISTS PV5_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)""")

    # Bus_3p_list
    bus3p_list = bus_name_lists()[2]

    # 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"

    # Initialize PV elements
    dssText.Command = "Redirect " + dir + "\\ckt24\\5PV_new.dss"

    # Initialize fault elements
    dssText.Command = "New Fault.fault"

    # Fault resistances
    fault_resistances = [
        "05", "10", "15", "20", "25", "30", "35", "40", "45", "50"
    ]

    print("\nAll LLLG faults for 3p buses\n")
    for bus3p in bus3p_list:
        print("Bus: %s" % bus3p)
        t1 = time.time()
        for r in fault_resistances:
            fault_LLLG(bus3p[0], r, [bus3p[1], bus3p[2]], dssObj, conn, c)
        t2 = time.time()
        print("Time to simulate this bus: %fs\n" % (t2 - t1))

    t_end = time.time()
    print("\n\n\nTotal simulation time: %f\n\n\n" % (t_end - t_start))
Ejemplo n.º 2
0
def main():

    # Get directory of .py file
    dir = os.path.dirname(os.path.abspath(__file__))

    # Buses list
    bus1p_list = bus_name_lists()[0]
    bus2p_list = bus_name_lists()[1]
    bus3p_list = bus_name_lists()[2]

    # Lines list
    l1 = line_name_lists()[0]
    l2 = line_name_lists()[1]
    l3 = line_name_lists()[2]

    # 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"

    # Initialize fault elements
    dssText.Command = "New Fault.fault"

    # Fault resistances
    # fault_resistances = ["05","10","15","20","25","30","35","40","45","50"]
    fault_resistances = ["05", "30"]

    # Print fault in in a bus that has 1p
    bus1p = bus1p_list[100]
    bus1p[3] = "." + str(bus1p[3])
    for r in fault_resistances:
        fault_LG(bus1p[0], bus1p[3], bus1p[3], r, [bus1p[1], bus1p[2]], l1, l2,
                 l3, dssObj)
Ejemplo n.º 3
0
def main():

    # Get directory of .py file
    dir = os.path.dirname(os.path.abspath(__file__))

    # Buses list
    bus1p_list = bus_name_lists()[0]
    bus2p_list = bus_name_lists()[1]
    bus3p_list = bus_name_lists()[2]

    # Lines list
    l1 = line_name_lists()[0]
    l2 = line_name_lists()[1]
    l3 = line_name_lists()[2]

    # 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"

    # Define Fault after vbases, otherwise it bugs pu Voltages in this case
    # Initialize fault elements
    # dssText.Command = "New Fault.fault"

    # Fault resistances
    r = "10"

    # Print fault in a bus that has 3p
    bus3p = bus3p_list[200]
    fault_LLLG(bus3p[0], r, [bus3p[1], bus3p[2]], l1, l2, l3, dssObj)
Ejemplo n.º 4
0
def buses_criteria_pu_var():

    # Get directory of .py file
    dir = os.path.dirname(os.path.abspath(__file__))

    flag_noPV = 0
    flag_PV = 1

    # Bus_1p_list
    bus1p_list = bus_name_lists()[0]
    for i in range(len(bus1p_list)):
        if i == 0:
            bus1p_listn = [bus1p_list[0][0]]
        else:
            bus1p_listn.append(bus1p_list[i][0])

    # Bus_2p_list
    bus2p_list = bus_name_lists()[1]
    for i in range(len(bus2p_list)):
        if i == 0:
            bus2p_listn = [bus2p_list[0][0]]
        else:
            bus2p_listn.append(bus2p_list[i][0])

    # Bus_3p_list
    bus3p_list = bus_name_lists()[2]
    for i in range(len(bus3p_list)):
        if i == 0:
            bus3p_listn = [bus3p_list[0][0]]
        else:
            bus3p_listn.append(bus3p_list[i][0])

    hours = ["9", "10", "11", "12", "13", "14", "15", "16", "17"]

    PV_powers_Vlimit = []  # Bus voltage variation criteria

    print("Running circuit comparisons for voltage pu variations\n")
    t_start = time.time()

    for season in ["Spring", "Summer", "Autumn", "Winter"]:

        for hour in hours:

            PV_power = 500
            power_iteration = "run again"
            while power_iteration == "run again":

                for flag in [flag_noPV, flag_PV]:

                    # 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"

                    # 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
                    if flag == flag_PV:
                        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
                    if flag == flag_PV:

                        voltages_list1p_PV = []
                        voltages_list2p_PV = []
                        voltages_list3p_PV = []

                        for buses1p in bus1p_listn:
                            voltages_list1p_PV.append(V(buses1p, dssCircuit))
                        for buses2p in bus2p_listn:
                            voltages_list2p_PV.append(V(buses2p, dssCircuit))
                        for buses3p in bus3p_listn:
                            voltages_list3p_PV.append(V(buses3p, dssCircuit))

                    if flag == flag_noPV:

                        voltages_list1p_noPV = []
                        voltages_list2p_noPV = []
                        voltages_list3p_noPV = []

                        for buses1p in bus1p_listn:
                            voltages_list1p_noPV.append(V(buses1p, dssCircuit))
                        for buses2p in bus2p_listn:
                            voltages_list2p_noPV.append(V(buses2p, dssCircuit))
                        for buses3p in bus3p_listn:
                            voltages_list3p_noPV.append(V(buses3p, dssCircuit))

                pu_limit = 0.01

                V_flag = 0
                for i in range(len(voltages_list1p_noPV)):
                    if abs(voltages_list1p_PV[i][0] -
                           voltages_list1p_noPV[i][0]) > pu_limit:
                        V_flag = 1
                for i in range(len(voltages_list2p_noPV)):
                    if abs(voltages_list2p_PV[i][0] -
                           voltages_list2p_noPV[i][0]) > pu_limit:
                        V_flag = 1
                    elif abs(voltages_list2p_PV[i][2] -
                             voltages_list2p_noPV[i][2]) > pu_limit:
                        V_flag = 1
                for i in range(len(voltages_list3p_noPV)):
                    if abs(voltages_list3p_PV[i][0] -
                           voltages_list3p_noPV[i][0]) > pu_limit:
                        V_flag = 1
                    elif abs(voltages_list3p_PV[i][2] -
                             voltages_list3p_noPV[i][2]) > pu_limit:
                        V_flag = 1
                    elif abs(voltages_list3p_PV[i][0] -
                             voltages_list3p_noPV[i][0]) > pu_limit:
                        V_flag = 1

                if V_flag == 1:
                    PV_powers_Vlimit.append([season, hour, PV_power - 500])
                    power_iteration = "stop running"

                if PV_power == 9000:
                    PV_powers_Vlimit.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_Vlimit)
    print()
    PV_powers_Vlimit = [int(e[-1]) for e in PV_powers_Vlimit]
    print("Minimum value: %d kW" % min(PV_powers_Vlimit))
    print()

    t_end = time.time()
    print("Total simulation time \
    (voltage pu variation comparisons): %f" % (t_end - t_start))
Ejemplo n.º 5
0
def main():

    t_start = time.time()

    # Get directory of .py file
    dir = os.path.dirname(os.path.abspath(__file__))

    # Create database for faults
    conn = sqlite3.connect('database_faultlocation_339PV.db')
    c = conn.cursor()
    c.execute("""CREATE TABLE IF NOT EXISTS PV339_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)""")

    # Bus_3p_list
    bus3p_list = bus_name_lists()[2]

    # List with transformers info
    xfmr_list = transformer_list()

    # 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"

    # Initialize PV elements
    dssText.Command = "Redirect " + dir + "\\ckt24\\339PV_new.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 PVSystem.PV"+str(i)\
+" phases=1 bus1="+bus_pv+"."+phase+" kv="+kv_pv+" kVA=15"\
+" irrad=0.981 pmpp=15 temperature=25 pf=1"\
+" %cutin=5 %cutout=5 effcurve=MyEff P-tCurve=MyPvst"\
+" Daily=MyIrrad Tdaily=Mytemp"

    # Initialize fault elements
    dssText.Command = "New Fault.fault"

    # Fault resistances
    fault_resistances = [
        "05", "10", "15", "20", "25", "30", "35", "40", "45", "50"
    ]

    print("\nAll LLLG faults for 3p buses\n")
    for bus3p in bus3p_list:
        print("Bus: %s" % bus3p)
        t1 = time.time()
        for r in fault_resistances:
            fault_LLLG(bus3p[0], r, [bus3p[1], bus3p[2]], xfmr_list, dssObj,
                       conn, c)
        t2 = time.time()
        print("Time to simulate this bus: %fs\n" % (t2 - t1))

    t_end = time.time()
    print("\n\n\nTotal simulation time: %f\n\n\n" % (t_end - t_start))
Ejemplo n.º 6
0
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))
Ejemplo n.º 8
0
def plot_zones():

    ckt24_buses.ckt24_plot()

    bus1p, bus2p, bus3p = bus_name_lists()

    # Take bus coordinates max and min
    xmax = 11746421.02
    xmin = 11746421.02
    ymax = 3714090.755
    ymin = 3714090.755


    for bus in [bus1p, bus2p, bus3p]:
        for row in bus:
            if ymax < float(row[2]):
                ymax = float(row[2])
            if ymin > float(row[2]):
                ymin = float(row[2])
            if xmax < float(row[1]):
                xmax = float(row[1])
            if xmin > float(row[1]):
                xmin = float(row[1])

    x_step = (xmax - xmin)/5
    y_step = (ymax - ymin)/5

    def lineplot(p1,p2):
        x = [p1[0],p2[0]]
        y = [p1[1],p2[1]]
        pylab.plot(x,y,color='k',linewidth=2)

    # zone 1 x axis
    lineplot([xmin,ymin+1.3*y_step],[xmin+x_step,ymin+1.3*y_step])
    lineplot([xmin+x_step,ymin+1.43*y_step],[xmin+2*x_step,ymin+1.43*y_step])

    # zone 2 x axis
    lineplot([xmin+2*x_step,ymin+2*y_step],[xmin+3.72*x_step,ymin+2*y_step])

    # zone 2 y axis
    lineplot([xmin+2*x_step,ymin],[xmin+2*x_step,ymin+2*y_step])

    # zone 3 y axis
    lineplot([xmin+3.72*x_step,ymin],[xmin+3.72*x_step,ymin+5*y_step])

    # zone 5 x axias
    lineplot([xmin+1.6*x_step,ymin+2.85*y_step],
    [xmin+3.72*x_step,ymin+2.85*y_step])

    # zones 1 and 6 y axis
    lineplot([xmin+x_step,ymin+1.3*y_step],[xmin+x_step,ymin+2.1*y_step])

    # zone 6 inclined line
    lineplot([xmin+x_step,ymin+2.1*y_step],[xmin+1.6*x_step,ymin+2.85*y_step])
    m = ((ymin+2.85*y_step) - (ymin+2.1*y_step)) / \
    ((xmin+1.6*x_step) - (xmin+x_step))
    b = (ymin+2.1*y_step) - (m*(xmin+x_step))

    # zone 6 "knee"
    lineplot([xmin+1.6*x_step,ymin+2.85*y_step],
    [xmin+1.6*x_step,ymin+3.2*y_step])
    lineplot([xmin+1.6*x_step,ymin+3.2*y_step],
    [xmin+1.25*x_step,ymin+3.2*y_step])
    lineplot([xmin+1.25*x_step,ymin+3.2*y_step],
    [xmin+1.25*x_step,ymin+5*y_step])

    # borders
    lineplot([xmin,ymin],[xmax,ymin])
    lineplot([xmin,ymin],[xmin,ymax])
    lineplot([xmax,ymin],[xmax,ymax])
    lineplot([xmin,ymax],[xmax,ymax])

    substation, = pylab.plot([11735514.42],[3709460.816],'k^',
    markersize=10, label='Substation')
    blue_patch = mpatches.Patch(color='blue', label='Three-phase lines')
    green_patch = mpatches.Patch(color='green', label='Two-phase lines')
    red_patch = mpatches.Patch(color='red', label='One-phase lines')
    # pylab.legend(handles=[substation, blue_patch, green_patch, red_patch])
    pylab.title("ckt24 separated in zones for machine learning fault location")
    pylab.show()
def transformers_criteria():

    # Get directory of .py file
    dir = os.path.dirname(os.path.abspath(__file__))

    flag_noPV = 0
    flag_PV = 1

    # Make lists with bus names and line names

    # Bus_1p_list
    bus1p_list = bus_name_lists()[0]
    for i in range(len(bus1p_list)):
        if i == 0:
            bus1p_listn = [bus1p_list[0][0]]
        else:
            bus1p_listn.append(bus1p_list[i][0])

    # Bus_2p_list
    bus2p_list = bus_name_lists()[1]
    for i in range(len(bus2p_list)):
        if i == 0:
            bus2p_listn = [bus2p_list[0][0]]
        else:
            bus2p_listn.append(bus2p_list[i][0])

    # Bus_3p_list
    bus3p_list = bus_name_lists()[2]
    for i in range(len(bus3p_list)):
        if i == 0:
            bus3p_listn = [bus3p_list[0][0]]
        else:
            bus3p_listn.append(bus3p_list[i][0])

    # 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 = ["9","10","11","12","13","14","15","16","17"]

    PV_powers_Plimit = [] # Transformers kva criteria

    print("Running circuit comparisons for powers - transformers criteria\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
        dssText = dssObj.Text
        dssCircuit = dssObj.ActiveCircuit
        dssSolution = dssCircuit.Solution

    # Clear the DSS
    dssObj.ClearAll()

    # Load circuit
    dssText.Command = "Compile "+dir+"\\ckt24\\ckt24.dss"

    # Transformers nominal kva list
    transformer_kva_nominal = []
    all_elements = dssCircuit.AllElementNames
    transformer_list = [s for s in all_elements if "Transformer" in s]

    # Remove transformers that work over nominal kva in circuit without PV
    # from transformer_list and put them into another list
    transformer_list.remove("Transformer.05410_g2100dl9800")
    transformer_list.remove("Transformer.05410_g2100en2200")
    transformer_list.remove("Transformer.05410_g2100gi2700")
    transformer_list.remove("Transformer.05410_g2100nj7400")
    transformer_list.remove("Transformer.05410_g2101bc7200")
    transformer_list.remove("Transformer.05410_g2102cc0600")



    transformer_list_exceptions = []
    transformer_list_exceptions.append("Transformer.05410_g2100dl9800")
    transformer_list_exceptions.append("Transformer.05410_g2100en2200")
    transformer_list_exceptions.append("Transformer.05410_g2100gi2700")
    transformer_list_exceptions.append("Transformer.05410_g2100nj7400")
    transformer_list_exceptions.append("Transformer.05410_g2101bc7200")
    transformer_list_exceptions.append("Transformer.05410_g2102cc0600")



    for i in range(len(transformer_list)):
        dssCircuit.SetActiveElement(transformer_list[i])
        dssCircuit.Transformers.Name = \
        transformer_list[i].replace("Transformer.","")
        transformer_kva_nominal.append(dssCircuit.Transformers.kva)


    hours = ["9","10","11","12","13","14","15","16","17"]

    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 "+flag_PV+"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\\1PV_new.dss"
                dssText.Command = "Redirect "+dir+"1PV_"+season+".dss"
                dssText.Command = "Edit PVSystem.PV1 kVA=" \
                +str(PV_power)+" pmpp="+str(PV_power)

                dssText.Command = "Edit Transformer.pv_up1 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
                transformer_kva_PV = []

                for transformer in transformer_list:
                    transformer_kva_PV.append(P(transformer, dssCircuit))

                safe_factor = 1
                P_flag = 0
                for i in range(len(transformer_list)):
                    if len(transformer_kva_PV[i]) == 8:
                        if  (abs(transformer_kva_PV[i][0]))> \
                        safe_factor*abs(transformer_kva_nominal[i]):
                            P_flag = 1

                    elif len(transformer_kva_PV[i]) == 16:
                        if  (abs(transformer_kva_PV[i][0])+ \
                        abs(transformer_kva_PV[i][2])+ \
                        abs(transformer_kva_PV[i][4]))> \
                        safe_factor*abs(transformer_kva_nominal[i]):
                            P_flag = 1


                if P_flag==1:
                    PV_powers_Plimit.append([season,hour,PV_power-500])
                    power_iteration = "stop running"

                if PV_power == 22500:
                    PV_powers_Plimit.append([season,hour,"max_iter_22500"])
                    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_Plimit)
    print()
    PV_powers_Plimit = [int(e[-1]) for e in PV_powers_Plimit]
    print("Minimum value: %d kW" % min(PV_powers_Plimit))
    print()


    t_end = time.time()
    print("Total simulation time (power comparisons - "
    "transformers criteria): %f" % (t_end - t_start))
Ejemplo n.º 10
0
def main():

    # Get directory of .py file
    dir = os.path.dirname(os.path.abspath(__file__))

    # Make lists with bus names

    # Bus_1p_list
    bus1p_list = bus_name_lists()[0]
    for i in range(len(bus1p_list)):
        if i == 0:
            bus1p_listn = [bus1p_list[0][0]]
        else:
            bus1p_listn.append(bus1p_list[i][0])

    # Bus_2p_list
    bus2p_list = bus_name_lists()[1]
    for i in range(len(bus2p_list)):
        if i == 0:
            bus2p_listn = [bus2p_list[0][0]]
        else:
            bus2p_listn.append(bus2p_list[i][0])

    # Bus_3p_list
    bus3p_list = bus_name_lists()[2]
    for i in range(len(bus3p_list)):
        if i == 0:
            bus3p_listn = [bus3p_list[0][0]]
        else:
            bus3p_listn.append(bus3p_list[i][0])

    # 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"

    # Min and max pu voltage in bus of the circuit in hours and seasons
    min_pu_list = []
    max_pu_list = []

    for season in ["Spring", "Summer", "Autumn", "Winter"]:

        # 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)"

        # Set and calculate voltage bases
        dssText.Command = "Redirect " + dir + "\\ckt24\\ckt24_vbases.dss"

        hours = ["9", "10", "11", "12", "13", "14", "15", "16", "17"]

        for hour in hours:

            min_pu = 1.05
            max_pu = 0

            # Solve circuit
            dssText.Command = "Solve mode=daily number=1 hour=" + hour

            for bus in bus1p_listn:
                # print(V(bus,dssCircuit))
                # print(bus)
                if min_pu > V(bus, dssCircuit)[0]:
                    min_pu = V(bus, dssCircuit)[0]
                if max_pu < V(bus, dssCircuit)[0]:
                    max_pu = V(bus, dssCircuit)[0]

            for bus in bus2p_listn:
                # print(V(bus,dssCircuit))
                # print(bus)
                for i in [0, 2]:
                    if min_pu > V(bus, dssCircuit)[i]:
                        min_pu = V(bus, dssCircuit)[i]
                    if max_pu < V(bus, dssCircuit)[i]:
                        max_pu = V(bus, dssCircuit)[i]

            for bus in bus3p_listn:
                # print(V(bus,dssCircuit))
                # print(bus)
                for i in [0, 2, 4]:
                    if min_pu > V(bus, dssCircuit)[i]:
                        min_pu = V(bus, dssCircuit)[i]
                    if max_pu < V(bus, dssCircuit)[i]:
                        max_pu = V(bus, dssCircuit)[i]

            min_pu_list.append(min_pu)
            max_pu_list.append(max_pu)

    print("min pu voltage:")
    print(min(min_pu_list))
    print()
    print("max pu voltage:")
    print(max(max_pu_list))