Ask Your Question
0

PSSE dynamic simulation on multiple processor cores

asked 2014-03-21 15:07:42 -0600

Yagna gravatar image

updated 2014-03-24 07:12:31 -0600

I would like a sample script that uses 'multiprocessing' python module for running PSSE dynamic simulation on multiple cores parallely. @EBahr Could you please share your script that implements multiprocessing python module ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-04-02 15:05:07 -0600

EBahr gravatar image

updated 2014-04-03 10:09:48 -0600

Here is something incredibly basic, but hopefully it will get you started. This will run the same fault on the same case in 5 simultaneous processes. Hopefully you can figure out how to make it work with what you want to do. For example, if you wanted to run multiple different faults on the same base case, you could create a function for each fault (ie run_fault_1, run_fault_2, etc), then scrap the for loop and start a new thread for each fault function.

import os,sys
PYTHONPATH = r'C:\Program Files (x86)\PTI\PSSE33\PSSBIN'
MODELFOLDER = r'C:\Program Files (x86)\PTI\PSSE33\MODELDRW'

sys.path.append(PYTHONPATH)
os.environ['PATH'] += ';' + PYTHONPATH

import psspy
import redirect
import multiprocessing

def main():
    # Redirect output from PSSE to Python:
    redirect.psse2py()

    # Last case:
    CASE = r"C:\Program Files (x86)\PTI\PSSE33\EXAMPLE\savnw.sav"
    psspy.psseinit(12000)
    psspy.case(CASE)

    # Convert loads (3 step process):
    psspy.conl(-1,1,1)
    psspy.conl(-1,1,2,[0,0],[100,0,0,100])
    psspy.conl(-1,1,3)

    # Convert generators:
    psspy.cong()

    # Solve for dynamics
    psspy.ordr()
    psspy.fact()
    psspy.tysl()

    # Save converted case
    case_root = os.path.splitext(CASE)[0]
    psspy.save(case_root + "_C.sav")

    # Add dynamics data
    psspy.dyre_new(dyrefile="C:\Program Files (x86)\PTI\PSSE33\EXAMPLE\savnw.dyr")

    # Add channels by subsystem
    #   BUS VOLTAGE
    psspy.chsb(sid=0,all=1, status=[-1,-1,-1,1,13,0])
    #   MACHINE SPEED
    psspy.chsb(sid=0,all=1, status=[-1,-1,-1,1,7,0])

    # Add channels individually
    #   BRANCH MVA
    psspy.branch_mva_channel([-1,-1,-1,3001,3002],'1')

    # Save snapshot
    psspy.snap(sfile="C:\Program Files (x86)\PTI\PSSE33\EXAMPLE\python_test.snp")

    # Run multiprocessed faults
    for i in range (5):
        arguments = (case_root + "_C.sav", 
                "C:\Program Files (x86)\PTI\PSSE33\EXAMPLE\python_test.snp",
                case_root + "_" + `i` + ".out",
                case_root + "_" + `i` + ".log")

        # Start new thread
        p = multiprocessing.Process(target = run_fault, args = arguments)      
        p.start()    

def run_fault(case, snp, out, log):
    # Initialize PSSE
    psspy.psseinit(12000)

    # Redirect output from PSSE to Python      
    redirect.psse2py()

    # Create log    
    psspy.report_output(2,log,[0,0])
    psspy.prompt_output(2,log,[2,0])
    psspy.progress_output(2,log,[2,0])

    # Load case
    psspy.case(case)
    psspy.rstr(snp)

    # Initialize case
    psspy.strt(outfile=out)
    psspy.run(tpause=0)

    # 1-phase fault branch 3001 to 3003
    psspy.dist_branch_fault(ibus=3001, jbus=3003, id='1',units=1,values=[352,-2389])

    # Run to 4 cycles
    time = 4.0/60.0
    psspy.run(tpause=time)

    # Clear fault
    psspy.dist_clear_fault()
    psspy.dist_branch_trip(ibus=3001, jbus=3003, id='1')

    # Run to 20 seconds
    time = 20
    psspy.run(tpause=time)

    psspy.pssehalt_2()    

if __name__ == "__main__":
    main()
edit flag offensive delete link more

Comments

Excellent 'core' code.

jconto gravatar imagejconto ( 2014-04-02 21:48:56 -0600 )edit

@EBahr Works like a charm! I was using the Pool.map() method and it was a bit sloppy. This method cranks up all the cores to 100% throughout the simulation. Thanks for sharing! :)

Yagna gravatar imageYagna ( 2014-04-03 08:54:16 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Question Tools

1 follower

Stats

Asked: 2014-03-21 15:07:42 -0600

Seen: 1,939 times

Last updated: Apr 03 '14