Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is a quick an dirty script that should do what you are requesting. It should distribute the increased MW evenly across all the machines (by percentage), and it also respects PMAX. If PMAX is reached on a machine, it will ignore that machine and the other machines will pick up a bit more. Modify the IGNORE_BUSES and AREA arrays to ignore your specified bus and to choose what areas you would like to include for the generation re-dispatch. Set REQUESTED_MW_INCREASE to the value you desire. This code is far from perfect, but should give you an idea of where to start.

IGNORE_BUSES = [1,2,3...] #Add any buses you want in here
REQUESTED_MW_INCREASE = 50
MW_TOLERANCE = .5 #Tolerance setting
FLAG = 1 #Set to 1 to only look at in-service buses with at least one in service machines
BSYS = 1
AREA = [1,2...] #Set to whatever area(s) you want to adjust

def get_generation():
    err = psspy.bsys(BSYS, 1, 1, 1, AREA)
    err, generator_numbers = psspy.amachint(BSYS,FLAG,['NUMBER'])
    err, generator_pgens = psspy.amachreal(BSYS,FLAG,['PGEN'])
    err, generator_pmaxs = psspy.amachreal(BSYS,FLAG,['PMAX'])
    pgen = 0 
    total_pmax = 0
    for i in range(len(generator_numbers[0])):    
        if generator_numbers[0][i] in IGNORE_BUSES: #SKIP IF IGNORED
            continue
        pgen = pgen + generator_pgens[0][i]
        total_pmax = total_pmax + generator_pmaxs[0][i]
    return pgen, total_pmax

def adjust_generation(percent):
    err = psspy.bsys(BSYS, 1, 1, 1, AREA)
    err, generator_numbers = psspy.amachint(BSYS,FLAG,['NUMBER'])
    err, generator_pgens = psspy.amachreal(BSYS,FLAG,['PGEN'])
    err, generator_pmaxs = psspy.amachreal(BSYS,FLAG,['PMAX'])
    err, generator_ids = psspy.amachchar(BSYS,FLAG,['ID'])
    gen_change = 0
    for i in range(len(generator_numbers[0])):    
        if generator_numbers[0][i] in IGNORE_BUSES: #SKIP IF IGNORED
            continue

        new_mw = generator_pgens[0][i] * percent
        if new_mw > generator_pmaxs[0][i]:
            new_mw = generator_pmaxs[0][i] #SET GEN TO PMAX IF REQUESTED AMOUNT IS GREATER THAN PMAX
            IGNORE_BUSES.append(generator_numbers[0][i]) #IGNORE NOW THAT MAXED

        ierr = psspy.machine_data_2(generator_numbers[0][i],generator_ids[0][i],[],[new_mw]) #CHANGE MW VALUE
        gen_change = gen_change + new_mw - generator_pgens[0][i]
    return gen_change

increase_mw = REQUESTED_MW_INCREASE  
cur_gen, total_pmax = get_generation()
new_gen = cur_gen + increase_mw

while abs(cur_gen - new_gen) > MW_TOLERANCE:    
    #EXIT IF NOT ENOUGH AVAILABLE GENERATION    
    if new_gen > total_pmax:
        print('Not enough available generation')
        break
    percent = new_gen / cur_gen
    change = adjust_generation(percent)    
    increase_mw = increase_mw - change
    cur_gen, total_pmax = get_generation()
    new_gen = cur_gen + increase_mw