First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
1 | initial version |
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):
# Redirect output from PSSE to Python:
psspy.psseinit(12000)
redirect.psse2py()
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
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()
2 | Code cleanup |
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:
psspy.psseinit(12000)
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
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()