예제 #1
0
def get_results(_name):
    results1 = read_voltages(ONSS_HV)
    results2 = read_voltages(ONSS_LV)
    results3 = read_voltages(ONSRE_HDD_6)
    results4 = read_voltages(ONSRE_HDD_5)
    results5 = read_voltages(ONSRE_HDD_4)
    results6 = read_voltages(ONSRE_HDD_3)
    results7 = read_voltages(ONSRE_HDD_2)
    results8 = read_voltages(ONSRE_HDD_1)
    results9 = read_voltages(CNCRT_DB)
    results10 = read_voltages(LNDFAL_HDD)
    results11 = read_voltages(SEABED)
    results12 = read_voltages(OFSS_HV)
    results13 = read_voltages(OFSS_LV)
    res_66kV = read_voltages(ToBus)
    res_WT = read_voltages(WT_bus)
    Pstat, Qstat = read_mach_output(ONSS1_HV, r"1")
    q_wt = read_mach_Q(WT_bus)
    Converged = psspy.solved()
    results = [_name]
    results.append(max_voltages(results1))
    results.append(min(results1))
    results.append(max_voltages(results2))
    results.append(min(results2))
    results.append(max_voltages(results3))
    results.append(min(results3))
    results.append(max_voltages(results4))
    results.append(min(results4))
    results.append(max_voltages(results5))
    results.append(min(results5))
    results.append(max_voltages(results6))
    results.append(min(results6))
    results.append(max_voltages(results7))
    results.append(min(results7))
    results.append(max_voltages(results8))
    results.append(min(results8))
    results.append(max_voltages(results9))
    results.append(min(results9))
    results.append(max_voltages(results10))
    results.append(min(results10))
    results.append(max_voltages(results11))
    results.append(min(results11))
    results.append(max_voltages(results12))
    results.append(min(results12))
    results.append(max_voltages(results13))
    results.append(min(results13))
    results.append(max_voltages(res_66kV))
    results.append(min(res_66kV))
    results.append(max_voltages(res_WT))
    results.append(min(res_WT))
    results.append(max_q(q_wt))
    results.append(min(q_wt))
    results.append(Qstat)
    results.append(Converged)
    result_dict[k] = results
예제 #2
0
 def get_mvar(i):
     """
     Changes the voltage set point at the synchronous machine
     solves the case
     returns the the new reactive power output of the sync machine.
     """
     psspy.plant_data(busno, realar1=i)
     ierr = psspy.fnsl()
     val = psspy.solved()
     if val == 0:
         ierr, mvar = psspy.macdat(busno, str(genid), 'Q')
         return mvar
     else:
         return None
예제 #3
0
def reduceModel(zonebuses):
    # Reduce the model
    psspy.bsys(sid=1, numbus=len(zonebuses), buses=zonebuses)
    psspy.gnet(sid=1, all=0)
    psspy.island()
    psspy.fdns(options=[1, 0, 1, 1, 1, 0, 0, 0])
    psspy.eeqv(sid=1, all=0, status=[0, 0, 0, 0, 1, 0], dval1=0)
    psspy.island()
    ierr = psspy.fdns(options=[1, 0, 1, 1, 1, 0, 0, 0])
    ival = psspy.solved()
    reducedModelName = "reduced"
    print "ival equal to "
    print ival
    if ival == 0:
        psspy.save(reducedModelName)
    else:
        return None
    return reducedModelName
예제 #4
0
            change_load(load_bus_region[1], load_change_region2)
            change_load(load_bus_region[2], load_change_region3)

            change_gen(gen_bus_region[0], loadIncrement_region1)
            change_gen(gen_bus_region[1], loadIncrement_region2)
            change_gen(gen_bus_region[2], loadIncrement_region3)

            savecase = 'ieee118bus_divided_temp.sav'
            psspy.save(savecase)

            # secure or not
            psspy.case(savecase)
            psspy.fnsl()

            # check convergency
            N = psspy.solved()

            [bus_voltage, bus_angle] = powerlib.getMeasurements(response_buses)

            # check voltage violation
            if N == 0:
                # get bus measurements number
                [bus_voltage,
                 bus_angle] = powerlib.getMeasurements(response_buses)
                voltage_violation = 0
                for vol_index in range(0, len(bus_voltage)):
                    if bus_voltage[vol_index] <= 0.844:
                        voltage_violation = 1
                        violation_index = vol_index
                if voltage_violation == 1:
                    secure.append(2)
    ReactivePowerDifference = abs(fromflow[0].imag - fromflow[1].imag)
    RealPowerDifference = abs(fromflow[0].real - fromflow[1].real)

    # Scale up the load at certain percentage
    change_load(ScaleLoadAtBuses,percentage)
    load = aloadreal(0,1,'TOTALACT')
    load = load[0]

##    #switch off the capbank
##    for shunt_bus_num in shunt_bus:
##        switchOffCap(shunt_bus_num)

    # run load flow
    psspy.fdns()
    N = psspy.solved()
    
    if N == 0:

        # measure the voltage at each bus
        psspy.bsys(sid = 1,numbus = len(bus_num), buses = bus_num)
        ierr,bus_voltage = psspy.abusreal(1,1,['PU'])
        bus_voltage = bus_voltage[0]
        psspy.save(savecase)

    else:

        print '### system collapses ###'


 #endregion
예제 #6
0
# Import PSS/E default
_i = psspy.getdefaultint()
_f = psspy.getdefaultreal()
_s = psspy.getdefaultchar()
redirect.psse2py()

# -------------------------------------------------- #
# initiate
psspy.psseinit(2000)  # 2000 bus at most, this number can be changed
# Load and solve the powerflow case
psspy.case(sav_case)
# configure the solver
psspy.fnsl(options1=0, options5=0)
# sikve the power flow case
iVal = psspy.solved()
if iVal == 0:
    print "Met convergence tolerance"
elif iVal == 1:
    print "The iteration limit exceeded"
elif iVal > 1:
    print "Blown up or others"

# ------------------------------------------------- #
# Dynamic Simulation
# Convert gen & load
# convert generators
ierr = psspy.cong(0)

# convert load
for i in [1, 2, 3]:
예제 #7
0
        #Outage column to report

        outage_column = ["Outage"] + [outage[0]] * (len(columns[0]) - 1)

        columns.extend([outage_column])

        #Contingency column to report

        contingency_column = ["N-1"] + [contingency[0]] * (len(columns[0]) - 1)

        columns.extend([contingency_column])

        #Debug, get solution state

        solution_state = psspy.solved()

        #print solution_state, contingency #Debug, prints solution state

        solution_state_column = [
            "Solved"
        ] + [solution_states[solution_state]] * (len(columns[0]) - 1)

        columns.extend([solution_state_column])

        #Line flows when areas are scaled

        for area in areas:

            gen_scale(1, area[1])  #Change generation in Area by +1MW
예제 #8
0
    for j in range(len(toBusList)):

        if i == j:
            continue
        fromBus2 = fromBusList[j]
        toBus2 = toBusList[j]
        cktID2 = cktIDList[j].strip("'").strip()
        branch1ID = str(fromBus1) + ',' + str(toBus1) + ',' + cktID1
        branch2ID = str(fromBus2) + ',' + str(toBus2) + ',' + cktID2

        # read the original raw file and try to solve power flow
        ierr = psspy.read(0, settings['filename'])
        ierr = psspy.branch_chng(
            fromBus1, toBus1, cktID1, [0, _i, _i, _i, _i, _i],
            [_f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f
             ])  # disconnect branch 1
        ierr = psspy.branch_chng(
            fromBus2, toBus2, cktID2, [0, _i, _i, _i, _i, _i],
            [_f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f, _f
             ])  # disconnect branch 2
        ierr = psspy.fnsl(settings['pf_options'])
        converge = psspy.solved()
        if converge != 9:
            string = branch1ID + ';' + branch2ID
            nonIslandEvents.append(string)

with open('OKDoubleBranchOutages.txt', 'w') as f:
    for line in nonIslandEvents:
        f.write(line)
        f.write('\n')
                          '1',
                          realar1=sheet.cell(row=i, column=4).value,
                          realar2=0.01 * sheet.cell(row=i, column=4).value)
        psspy.load_chng_4(5,
                          '1',
                          realar1=sheet.cell(row=i, column=5).value,
                          realar2=0.01 * sheet.cell(row=i, column=5).value)

        print('Changes completed...')
        psspy.rawd_2(
            0, 1, [0, 0, 1, 0, 0, 0, 0], 0,
            "Snap_before_PF.raw")  #save the raw file to convert to CIM
        b = 'h' + str(i - 2) + '_before_PF.raw'
        os.rename("Snap_before_PF.raw", b)
        psspy.fnsl([1, 0, 0, 0, 0, 0, 0, 0])  #solve the power flow
        ival = psspy.solved()  #flag to check power flow convergence
        if ival == 0:
            print('Convergence')
            sheet.cell(row=i, column=7).value = 'Convergence'
            psspy.save('temp.sav')  #save temporarily the solved case
            psspy.case('temp.sav')  #set the saved case as current case
            psspy.rawd_2(
                0, 1, [0, 0, 1, 0, 0, 0, 0], 0,
                "Snap_after_PF.raw")  #save the raw file to convert to CIM
            b = 'h' + str((i - 2)) + '_after_PF.raw'
            os.rename("Snap_after_PF.raw", b)
        else:
            print('No convergence')
            sheet.cell(row=i, column=7).value = 'Non-convergence'

    psspy.close_powerflow()
예제 #10
0
파일: n44.py 프로젝트: espenfb/SmartTS_Lab
    def update_raw_files(self, to_excel=True, out_dir=None):
        """Function for updating the psse case file.
        Args:
            to_excel(default=True): If a summary should be written to excel
            out_dir: The directory where the results are stored
        """
        if not out_dir:
            out_dir = os.getcwd()

        redirect.psse2py()
        psspy.throwPsseExceptions = True
        nbuses = 50000  # max no of buses
        ierr = psspy.psseinit(nbuses)
        psspy.case(self.basecase)

        if to_excel:
            self.create_excel_sheet()
            self.to_excel = True
        else:
            self.sheet = None

        for i, col in zip(range(0, 24), range(2, 2 + 24 * 3, 3)):
            # Represent HVDC links as load and some other exchanges as well
            print('Changing additional loads...')

            row = 15
            for load in self.ex_as_load:
                self.load_change(load, i, to_excel, row, col)
                row = row + 1

            print('Changing interarea exchanges...')
            row = 3
            for area, info in self.area_info.items():
                country = area[0:2]
                # Changing interarea exchanges
                exchange = self.calculate_exchange(info, area, i)
                self.area_data(info.number, info.bus, exchange, area, row,
                               col + 2)
                # Changing areas production and consumption
                self.change_prod_con(info.number,
                                     self.data[country]["PS"][area][i],
                                     self.data[country]["FB"][area][i],
                                     info.pf,
                                     tol=4,
                                     row=row,
                                     column=col)
                row = row + 1

            print('Changes completed...')
            # Save the raw file to convert to CIM
            psspy.rawd_2(0, 1, [0, 0, 1, 0, 0, 0, 0], 0, "Snap_before_PF.raw")
            b = os.path.join(out_dir, 'h' + str(
                (col - 1) / 3) + '_before_PF.raw')
            os.rename("Snap_before_PF.raw", b)
            # Solve the power flow
            psspy.fnsl([1, 2, 0, 0, 1, 0, 0, 0])
            ival = psspy.solved()  # flag to check power flow convergence
            if ival == 0:
                print('Convergence')
                if self.to_excel:
                    self.sheet.cell(row=42, column=col).value = 'Convergence'

                temp_fname = os.path.join(out_dir, "temp.sav")
                print(temp_fname)

                psspy.save(temp_fname)  # save temporarily the solved case
                psspy.case(temp_fname)  # set the saved case as current case

                # save the raw file to convert to CIM
                raw_fname = os.path.join(out_dir, "Snap_after_PF.raw")
                psspy.rawd_2(0, 1, [0, 0, 1, 0, 0, 0, 0], 0, raw_fname)
                b = os.path.join(out_dir, 'h' + str(i) + '_after_PF.raw')
                os.rename(raw_fname, b)

                if self.to_excel:
                    # Merge cells
                    self.sheet.merge_cells(start_row=1,
                                           start_column=col,
                                           end_row=1,
                                           end_column=col + 2)

                    self.sheet.cell(
                        row=2,
                        column=col).alignment = (Alignment(wrapText=True))
                    self.sheet.cell(row=2, column=col +
                                    1).alignment = (Alignment(wrapText=True))
                    self.sheet.cell(row=2, column=col +
                                    2).alignment = (Alignment(wrapText=True))
                    self.sheet.cell(
                        row=14,
                        column=col).alignment = (Alignment(wrapText=True))
                    self.sheet.cell(row=14, column=col +
                                    1).alignment = (Alignment(wrapText=True))
                    self.sheet.cell(
                        row=30,
                        column=col).alignment = (Alignment(wrapText=True))
                    self.sheet.cell(row=30, column=col +
                                    1).alignment = (Alignment(wrapText=True))

                    # Headers for data from nordpool
                    self.sheet.cell(row=1,
                                    column=col).value = ('hour ' + str(i))
                    self.sheet.cell(
                        row=2,
                        column=col).value = ('Scheduled\nProduction\n[MWh]')
                    self.sheet.cell(
                        row=2, column=col +
                        1).value = ('Scheduled\nConsumption\n[MWh]')
                    self.sheet.cell(row=2, column=col +
                                    2).value = ('Scheduled\nExchange\n[MWh]')

                    # Headers for exchanges represented as loads
                    self.sheet.cell(row=14,
                                    column=col).value = ('Active Power\n[MW]')
                    self.sheet.cell(row=14, column=col +
                                    1).value = ('Reactive Power\n[MW]')

                    # Headers for results after PSS/E
                    self.sheet.cell(
                        row=30, column=col).value = ('PSSE\nProduction\n[MWh]')
                    self.sheet.cell(row=30, column=col +
                                    1).value = ('PSSE\nConsumption\n[MWh]')
                    self.sheet.cell(row=30, column=col +
                                    2).value = ('PSSE\nExchange\n[MWh]')

                    row = 31
                    for _, info in self.area_info.items():
                        # to get the area production complex power
                        ierr = psspy.ardat(info.number, 'GEN')
                        self.sheet.cell(row=row, column=col).value = (round(
                            ierr[1].real, 0))

                        # to get the area consumption complex power
                        ierr = psspy.ardat(info.number, 'LOAD')
                        self.sheet.cell(row=row,
                                        column=col + 1).value = (round(
                                            ierr[1].real, 0))
                        row += 1

                    # to get the value of the areas active power interchange
                    ierr, intch = psspy.aareareal(-1, 1, 'PINT')
                    for r in range(0, len(intch[0])):
                        self.sheet.cell(row=31 + r,
                                        column=col + 2).value = round(
                                            intch[0][r].real, 0)

                    # limits check
                    ierr, busvoltages = psspy.abusreal(sid=-1, string="PU")
                    if any(x < 0.95 or x > 1.05 for x in busvoltages[0]):
                        self.sheet.cell(
                            row=43, column=col).value = ('Bus voltage problem')
                    ierr, machPGen = psspy.amachreal(sid=-1, string="PGEN")
                    ierr, machPMax = psspy.amachreal(sid=-1, string="PMAX")
                    ierr, machPMin = psspy.amachreal(sid=-1, string="PMIN")
                    ierr, machQGen = psspy.amachreal(sid=-1, string="QGEN")
                    ierr, machQMax = psspy.amachreal(sid=-1, string="QMAX")
                    ierr, machQMin = psspy.amachreal(sid=-1, string="QMIN")
                    ierr, machS = psspy.amachreal(sid=-1, string="MVA")
                    ierr, machMbase = psspy.amachreal(sid=-1, string="MBASE")
                    for l in range(0, len(machPGen[0])):
                        if (machPGen[0][l] <= machPMin[0][l]
                                or machPGen[0][l] >= machPMax[0][l]):
                            self.sheet.cell(row=45, column=col).value = (
                                'Generator active power output problem')
                for m in range(0, len(machQGen[0])):
                    if (machQGen[0][m] <= machQMin[0][m]
                            or machQGen[0][m] >= machQMax[0][m]):
                        self.sheet.cell(row=46, column=col).value = (
                            'Generator reactive power output problem')
                        break
                for n in range(0, len(machS[0])):
                    if machS[0][n] >= machMbase[0][n]:
                        self.sheet.cell(row=47, column=col).value = (
                            'Generator overloading problem')
                        break
                ierr, brflowA = psspy.aflowreal(sid=-1, string="PCTCORPRATEA")
                if any(x >= 100 for x in brflowA[0]):
                    self.sheet.cell(row=48, column=col).value = (
                        'Branch overloading problem (Rate A)')
                ierr, brflowB = psspy.aflowreal(sid=-1, string="PCTCORPRATEB")
                if any(x >= 100 for x in brflowB[0]):
                    self.sheet.cell(row=48, column=col).value = (
                        'Branch overloading problem (Rate B)')
                ierr, brflowC = psspy.aflowreal(sid=-1, string="PCTCORPRATEC")
                if any(x >= 100 for x in brflowC[0]):
                    self.sheet.cell(row=48, column=col).value = (
                        'Branch overloading problem (Rate C)')
            else:
                print('No convergence')
                self.sheet.cell(row=43, column=col).value = 'No convergence'

        psspy.close_powerflow()

        # save the Excel file with all data
        self.wb.save(os.path.join(out_dir, 'PSSE_in_out.xlsx'))
        os.remove(temp_fname)
예제 #11
0
def changeLoad(raw, start, end, step, newdir):
    """ 
        New raw files are created for each percentage step in [start,end]. 
        The current step defines the percentage scaling up (or down) factor for load and generation
    """

    # convert the raw file to another one where all the load is constant power
    raw_conp = raw.replace('.raw', '') + '_conp.raw'
    redirect.psse2py()
    psspy.psseinit(buses=80000)

    # ignore the output
    psspy.report_output(6, '', [0, 0])
    psspy.progress_output(6, '', [0, 0])
    psspy.alert_output(6, '', [0, 0])
    psspy.prompt_output(6, '', [0, 0])

    # read the raw file and convert all the loads to constant power
    ierr = psspy.read(0, raw)

    # multi-line command to convert the loads to 100% constant power
    psspy.conl(0, 1, 1, [1, 0], [0.0, 0.0, 0.0, 0.0])
    psspy.conl(0, 1, 2, [1, 0], [0.0, 0.0, 0.0, 0.0])
    psspy.conl(0, 1, 3, [1, 0], [0.0, 0.0, 0.0, 0.0])
    ierr = psspy.rawd_2(0, 1, [1, 1, 1, 0, 0, 0, 0], 0, raw_conp)
    # run change Load on the constant power load raw file

    rawBusDataDict = getBusData(raw_conp)
    # create a new directory to put the files in
    currentdir = os.getcwd()

    if not os.path.exists(newdir):
        os.mkdir(newdir)
    output_dir = currentdir + '/' + newdir
    #genDiscount = 0.90 # ratio of the actual increase in generation
    genDiscount = 1.0
    lossRatio = 0.0  # gen scale-up factor: (scalePercent + (scalePercent-100)*lossRatio)/100
    ############################################

    # create new raw files with scaled up loads and generation
    for scalePercent in range(start, end + step, step):
        scalePercent = float(
            scalePercent)  # float is needed, otherwise 101/100 returns 1

        scalePercentInt = int(
            scalePercent)  # integer value needed to append to filename
        scalePercentStr = str(scalePercentInt)

        # variables to store load data
        loadBusList = []  # list of load buses (string)
        loadPList = []  # list of Pload values (string)
        loadQList = []  # list of Qload values (string)
        loadPListInt = []  # list of Pload values (float)
        loadQListInt = []  # list of Qload values (float)
        #loadBusListInt = [] # list of load buses (int)

        # variables to store gen data
        genBusList = []
        #genBusListInt = []
        genPList = []
        genMVAList = []
        genMVAListInt = []
        genPListInt = []

        raw_name = raw_conp.replace('.raw', '')
        out_file = raw_name + scalePercentStr + '.raw'  # output file
        out_path = output_dir + '/' + out_file
        impLoadBuses = [
        ]  # enter specified load buses to scale, if empty all loads are scaled
        incLoss = (
            scalePercent - 100
        ) * lossRatio  # Additional percentage increase in Pgen (to account for losses)
        #############################################

        #Read raw file
        with open(raw_conp, 'r') as f:
            filecontent = f.read()
            filelines = filecontent.split('\n')

            ## Get start and end indices of load and gen info
            #########################################
            loadStartIndex = filelines.index(
                '0 / END OF BUS DATA, BEGIN LOAD DATA') + 1
            loadEndIndex = filelines.index(
                '0 / END OF LOAD DATA, BEGIN FIXED SHUNT DATA')

            genStartIndex = filelines.index(
                '0 / END OF FIXED SHUNT DATA, BEGIN GENERATOR DATA') + 1
            genEndIndex = filelines.index(
                '0 / END OF GENERATOR DATA, BEGIN BRANCH DATA')
            ##############################################################################

            totalPincr = 0.0
            totalQincr = 0.0
            percentIncr = (scalePercent -
                           100.0) / 100  # increment in percentage

            newPConList = []
            newQConList = []
            newIPList = []
            newIQList = []
            newZPList = []
            newZQList = []
            # Extract load info
            for i in range(loadStartIndex, loadEndIndex):
                words = filelines[i].split(',')
                loadBus = words[0].strip()
                #loadBusList.append(words[0].strip())
                loadPCon = float(words[5].strip())
                loadQCon = float(words[6].strip())
                loadIP = float(words[7].strip())
                loadIQ = float(words[8].strip())
                loadZP = float(words[9].strip())
                loadZQ = float(words[10].strip())

                # calculate the total MW (MVAr) increase in load
                loadBusVolt = float(rawBusDataDict[loadBus].voltpu)

                Pincr = percentIncr * (
                    loadPCon + loadIP * loadBusVolt + loadZP * loadBusVolt**2
                )  # this equation is provided in PAGV1 page 293
                Qincr = percentIncr * (loadQCon + loadIQ * loadBusVolt +
                                       loadZQ * loadBusVolt**2)
                totalPincr += Pincr
                totalQincr += Qincr
                ###

                # new load values
                newPConList.append(loadPCon * scalePercent / 100)
                newQConList.append(loadQCon * scalePercent / 100)
                newIPList.append(loadIP * scalePercent / 100)
                newIQList.append(loadIQ * scalePercent / 100)
                newZPList.append(loadZP * scalePercent / 100)
                newZQList.append(loadZQ * scalePercent / 100)
                """
                loadPList.append(words[5].strip()) # adding P value (constant power)
                loadQList.append(words[6].strip()) # adding Q value (constant power)
                loadIPList.append(words[7].strip()) # constant current P
                loadIQList.append(words[7].strip()) # constant current Q
                loadZPList.append(words[9].strip()) # adding P value (constant admittance)
                loadZQList.append(words[10].strip()) # adding Q value (constant admittance)
                """

            # get total MW gen
            totalGenMW = 0.0  # total generation excluding the swing bus
            for i in range(genStartIndex, genEndIndex):
                words = filelines[i].split(',')
                GenBus = words[0].strip()
                if rawBusDataDict[GenBus].type == '3':
                    continue
                PGen = float(words[2].strip())
                totalGenMW += PGen

            # get new MW Gen
            GenMWDict = {}  # dictionary to hold new PGen values
            for i in range(genStartIndex, genEndIndex):
                words = filelines[i].split(',')
                Bus = words[0].strip()
                if rawBusDataDict[Bus].type == '3':
                    continue
                macID = words[1].strip()
                key = Bus + macID
                PGen = float(words[2].strip())
                genIncr = PGen / totalGenMW * totalPincr
                newPGen = (PGen + genIncr) * genDiscount
                GenMVA = float(words[8].strip())
                if newPGen < GenMVA:
                    GenMWDict[key] = newPGen
                else:
                    GenMWDict[key] = GenMVA

        #  generate the new raw file
        with open(out_path, 'w') as f:
            # copy everything before load data
            for i in range(loadStartIndex):
                f.write(filelines[i])
                f.write('\n')

            # modify the load data
            j = 0
            for i in range(loadStartIndex, loadEndIndex):
                words = filelines[i].split(',')

                # change the constant MVA values
                words[5] = '%.3f' % newPConList[j]
                words[6] = '%.3f' % newQConList[j]
                words[5] = words[5].rjust(10)
                words[6] = words[6].rjust(10)

                # change the constant current values
                words[7] = '%.3f' % newIPList[j]
                words[8] = '%.3f' % newIQList[j]
                words[7] = words[7].rjust(10)
                words[8] = words[8].rjust(10)

                # change the constant impedance values
                words[9] = '%.3f' % newZPList[j]
                words[10] = '%.3f' % newZQList[j]
                words[9] = words[9].rjust(10)
                words[10] = words[10].rjust(10)

                # construct a whole string by inserting commas between the words list
                filelines[i] = reconstructLine2(words)
                f.write(filelines[i])
                f.write('\n')
                # increment the load list index
                j += 1

            # copy the shunt data, which is in between the load and gen data
            for i in range(loadEndIndex, genStartIndex):
                f.write(filelines[i])
                f.write('\n')

            # update and write the gen data
            for i in range(genStartIndex, genEndIndex):
                words = filelines[i].split(',')
                Bus = words[0].strip()

                if rawBusDataDict[Bus].type == '3':
                    f.write(filelines[i])
                    f.write('\n')
                    continue
                macID = words[1].strip()
                key = Bus + macID
                newPGen = GenMWDict[key]

                words[2] = '%.3f' % newPGen
                words[2] = words[2].rjust(10)

                # construct a whole string by inserting commas between the words list
                filelines[i] = reconstructLine2(words)
                f.write(filelines[i])
                f.write('\n')

                # copy the rest of the raw data
            for i in range(genEndIndex, len(filelines)):
                f.write(filelines[i])
                f.write('\n')

    # solves each of the newly generated raw files and saves them
    output_dir = currentdir + '/' + newdir
    NewRawFiles = os.listdir(output_dir)
    PathList = [(output_dir + '/' + f) for f in NewRawFiles]

    redirect.psse2py()
    psspy.psseinit(buses=80000)

    _i = psspy.getdefaultint()
    _f = psspy.getdefaultreal()
    _s = psspy.getdefaultchar()

    for i in range(len(PathList)):
        #Settings. CONFIGURE THIS
        settings = {
            # use the same raw data in PSS/E and TS3ph #####################################
            'filename':
            PathList[i],  #use the same raw data in PSS/E and TS3ph
            ################################################################################
            'dyr_file':
            '',
            'out_file':
            'output2.out',
            'pf_options': [
                0,  #disable taps
                0,  #disable area exchange
                0,  #disable phase-shift
                0,  #disable dc-tap
                0,  #disable switched shunts
                0,  #do not flat start
                0,  #apply var limits immediately
                0,  #disable non-div solution
            ]
        }

        psse_log = output_dir + '/' + 'log' + NewRawFiles[i].replace(
            '.raw', '.txt')
        psspy.report_output(2, psse_log, [0, 0])
        psspy.progress_output(2, psse_log, [0, 0])
        psspy.alert_output(2, psse_log, [0, 0])
        psspy.prompt_output(2, psse_log, [0, 0])

        print "\n Reading raw file:", settings['filename']
        ierr = psspy.read(0, settings['filename'])
        ierr = psspy.fnsl(settings['pf_options'])
        converge = psspy.solved()
        if converge == 0:
            ierr = psspy.rawd_2(0, 1, [1, 1, 1, 0, 0, 0, 0], 0, PathList[i])
        else:  # file does not converge, remove raw file, keep log file
            os.remove(PathList[i])
        """
예제 #12
0
psspy.fdns([1,0,0,1,1,0,0,0])
psspy.fdns([1,0,0,1,1,0,0,0])


#########################################################################################
Converged = 1
count = 1
while (Converged == 1):
    psspy.fdns([1,0,0,1,1,0,0,0])
    psspy.fdns([1,0,0,1,1,0,0,0])
    psspy.fnsl([1,0,0,1,1,0,0,0])
    psspy.fnsl([1,0,0,1,1,0,0,0])
    psspy.fnsl([1,0,0,1,1,0,0,0])
    psspy.fnsl([1,0,0,1,1,0,0,0])
    psspy.fnsl([1,0,0,1,1,0,0,0])
    Converged = psspy.solved()
    count = count + 1
    if count > 5:
        print ( "Case is non-convergent.")
        time.sleep(10)
        sys.exit()



Column_Lables = ['Vset_STAT (pu)','V_OnHV (pu)','V_OnLV (pu)','Tr_ONS_1','Tr_ONS_2','Tr_OFS_1','Tr_OFS_2','I_land (%)','I_cncr_duct_1 (%)','I_onsh_1 (%)','I_cncr_duct_2 (%)','I_onsh_2 (%)','I_cncr_duct_3 (%)','I_onsh_3 (%)','I_cncr_duct_4 (%)','I_lnd_HDD (%)','I_Sea (%)','I_Jtube','ONS_XFO (%)','OFS_XFO (%)','P_POI (MW)','Q_POI (MVar)','PF','Cnvg.','Reactors (nos.)','Q_stat1_final (MVar)','Q_stat2_final (MVar)','V_ofs_cab_min (PU)','V_ofs_cab_max (PU)','V_66kV_min (PU)','V_66kV_max (PU)','V_0.72_kV_min (PU)','V_0.72_kV_max (PU)','Qs_WTs_min (MVAr)','Qs_WTs_max (MVAr)'] # UPDATE_Q_WT # UPDATE_XFO_LOADING


myxls.set_range(1,1,[Column_Lables],
                transpose=False,fontStyle='bold', fontName=None, fontSize=None, fontColor=None, wrapText=False,
                numberFormat=None, sheet="RPS")