Ask Your Question
0

Batch Fault Simulation using looping in python

asked 2017-02-11 07:50:20 -0600

lmcqueen gravatar image

I wonder if someone else had done a batch run of simulation iterating over a set of fault disturbances using python looping. This can be easily done in idev file where you will just put @input commands to call on several idev files which are sets of fault/disturbances to be simulated.

Anyone with sample codes?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2017-02-15 08:27:28 -0600

Power_System_Engineer gravatar image

This is how I run my dynamic simulations with multiple fault files and converted models.

Here's a simple way to do it - Others may have better codes than this, but this works well for me. Of course you could add additional details in between as you wish but it should get what you are asking for. workdir and flt are folders but you could specifically assign what workdir path is or completely forget it and have everything input/output from your main folder.

Reading and storing all fault files in flt folder

    mypath_ = work_dir + "/flt"
    flt_file = [a for a in listdir(mypath_) if isfile(join(mypath_, a))]

    #splitting up file extensions
    flt_infile = []
    for r in flt_file:
            flt_infile.append(os.path.splitext(r)[0])

    print 'FAULT_DEF = ' , flt_infile
    print (" \n")

Reading and storing all converted cases convlf folder

    mypath = work_dir + "/convlf"
    clf_file = [g for g in listdir(mypath) if isfile(join(mypath, g))]

    #splitting up the .sav extension
    clf_infile = []
    for t in clf_file:
            clf_infile.append(os.path.splitext(t)[0])

    print 'CONVLF_DEF = ' , clf_infile
    print (" \n")

Looping through all cases and flt files

    flt_flag = 0     #1 = idv files, 0 = python files
    dist_run = 20.0     #20 seconds run

    for x in clf_infile:
        for y in flt_infile:

            psspy.case(work_dir + "/convlf/" + x + ".sav")
            psspy.rstr(work_dir + "/snap/" + snapfile + ".snp")

            psspy.strt(option = 0,
                       outfile = work_dir + "/bin/" + x + "-" + y + ".out"
                       )

            # run disturbance in steady state for 0.1 sec
            psspy.run(option = 0,
                      tpause = flat_start,
                      nprt = 0,
                      nplt = 1,
                      crtplt = 0
                      )

            # run disturbance and clear fault
            if flt_flag == 0:
                    execfile(work_dir + "/flt/" + y + ".py")

            else:
                    psspy.runrspnsfile(work_dir + "/flt/" + y + ".idv")

            # finish 20 second run
            psspy.run(option = 0, 
                      tpause = dist_run,
                      nprt = 0,
                      nplt = 1,
                      crtplt = 0
                      )
edit flag offensive delete link more

Comments

Hello, Your first two codes are very helpful to me. Thank you.

lmcqueen gravatar imagelmcqueen ( 2017-02-23 04:23:09 -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

4 followers

Stats

Asked: 2017-02-11 07:50:20 -0600

Seen: 1,471 times

Last updated: Feb 15 '17