def Contingency_Files(idv_files):
idev = [a for a in listdir(idv_files) if isfile(join(idv_files, a))]
idev_infile = []
for i in idev:
idev_infile.append(os.path.splitext(i)[0])
return idev_infile
def Converted_Files(cnv_files):
cnv = [b for b in listdir(cnv_files) if isfile(join(cnv_files, b))]
cnv_infile = []
for j in cnv:
cnv_infile.append(os.path.splitext(j)[0])
return cnv_infile
def Snapshot_Files(snp_files):
snp = [c for c in listdir(snp_files) if isfile(join(snp_files, c))]
snp_infile = []
for k in snp:
snp_infile.append(os.path.splitext(k)[0])
return snp_infile
def log_out(directory):
try:
if not os.path.exists(directory):
os.makedirs(directory)
except OSError:
print ('Error: Creating directory. ' + directory)
#*************************Main Program************************#
#*************************************************************#
#if __name__ == '__main__':
import os, sys
from os import listdir
from os.path import isfile, join
from os.path import splitext
import time
#*******************Define Working Directory******************#
study_folder = r"""D:/Studies/BBB/"""
idv_files = r"""D:/Studies/BBB/contingency/"""
cnv_files = r"""D:/Studies/BBB/converted/"""
snp_files = r"""D:/Studies/BBB/snapshot/"""
#************************Set PSS/E Path***********************#
pssedir = r"""C:\Program Files (x86)\PTI\PSSE32\PSSBIN"""
sys.path.append (pssedir)
os.environ["PATH"] = os.environ["PATH"] + ";" + pssedir
#*********************Import psspy modules********************#
import psspy
import redirect
_i = psspy.getdefaultint()
_f = psspy.getdefaultreal()
_c = psspy.getdefaultchar()
#***************Redirect PSS/E Output to Python***************#
redirect.psse2py()
#************************Initialize PSS/E*********************#
psspy.psseinit(150000)
#*********************Run Dynamic Simulation******************#
for x, y in zip(Converted_Files(cnv_files),Snapshot_Files(snp_files)):
log_out(x)
for z in Contingency_Files(idv_files):
print 'Simulation executed at time ', time.ctime()
print 'The snapshot file is ', y + '.'
print 'The case file is ', x + '.'
print 'The Fault ID is ', z + '.'
print 'Processing dynamic simulation for Fault ID ', z + '...'
psspy.progress_output(2, study_folder + x + "/" + z + '.pdev', [0,0])
psspy.prompt_output(2, study_folder + x + "/" + z + '.odev', [0,0])
try:
psspy.rstr(snp_files + y + '.snp')
except:
print 'Error while opening the file ', y
sys.exit(0)
psspy.powerflowmode()
try:
psspy.case(cnv_files + x + '.cnv')
except:
print 'Error while opening the file ', x
sys.exit(0)
psspy.ordr(0)
psspy.fact()
psspy.tysl(0)
psspy.dynamicsmode(0)
psspy.strt(1, study_folder + x + "/" + z + '.out')
psspy.runrspnsfile(idv_files + z + '.idv')
psspy.run(1,15,60,3,0)
psspy.progress_output(1,'', [0,0])
psspy.prompt_output(1,'', [0,0])
print 'Simulation finished at time ', time.ctime()
print 'Dynamic simulation for Fault ID ', z + ' complete! \n\n'
print 'Total Simulation finished at time ', time.ctime()
print '\nEnd of Dynamic Simulation \n'