First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
1 | initial version |
A simple algorithm: for every branch connected to a bus in list BUSES2, write a "branch off" contingency:
path = <path to case>
psspy.case(path+'\\savnw.sav')
ctgfile = path + '\\P2.con'
BUSES2 = [154, 153, 203]
def GetBranches(x):
tobusArray=[]
CktArray=[]
ierr = psspy.inibrn(x,2)
while ierr==0:
ierr, NextBus, NextCkt = psspy.nxtbrn(x)
if ierr == 0:
tobusArray.append(NextBus)
CktArray.append(str(NextCkt))
return tobusArray, CktArray
#_________________________________________________________
temp1 = []
text_file = open(ctgfile,'w')
for StartBus in BUSES2:
temp1.append(StartBus)
tobuses=[]
ckts = []
tobuses,ckts = GetBranches(StartBus)
print('Branches off bus ',StartBus)
print(tobuses, ckts)
for i in range(len(tobuses)):
jbus = tobuses[i]
ickt = ckts[i]
if jbus in temp1:continue # already branch processed!
# write ctg txt
text_file.write('CONTINGENCY Branch_%s-%s-%s\n' %(StartBus, jbus, ickt))
text_file.write('DISCONNECT BRANCH FROM BUS %s TO BUS %s CKT %s\n' %(StartBus, jbus, ickt))
text_file.write('END\n')
text_file.close()