Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

HOW TO CALCULATE FVSI FROM DYNAMIC SIMULATION

Hello Everyone,

i want a code to perform dynamic simulation and calculate FVSI later ... to achieve that i had compile some codes got it from here, but i stuck to complete the code. can you please help me to complete it ..

Much Thanks

*#identify system office and tools function. import os import sys import glob

To idntifty where is psse file inside the computer files

PSSE_PATH = r'C:\Program Files (x86)\PTI\PSSEUniversity33\PSSBIN'

Telling python where to find psse

sys.path.append(PSSE_PATH)

settle the enviorment file

os.environ['PATH'] += ';' + PSSE_PATH

PSSE INITIALIZATION

import psspy import redirect redirect.psse2py() psspy.psseinit()

RUN POWER FLOW CASE

bussystem= r"""C:\Users\user\Desktop\IT\FYP2\Dynamic\shortcourse5bussytem\TEST1.sav""" psspy.case(bussystem)

solve powerflow

psspy.fdns([0,0,0,1,1,0,99,0])

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()

Add dynamics data

psspy.dyre_new(dyrefile="C:\Users\user\Desktop\IT\FYP2\Dynamic\shortcourse5bussytem\daynmictest.dyr")

Add channels by subsystem

BUS VOLTAGE

psspy.chsb(sid=0,all=1, status=[-1,-1,-1,1,13,0])

BUS ANGLE

psspy.chsb(sid=0,all=1, status=[-1,-1,-1,1,1,0])

BUS P&Q

psspy.chsb(sid=0,all=1, status=[-1,-1,-1,1,16,0])

Save snapshot

psspy.snap(sfile="C:\Users\user\Desktop\IT\FYP2\Dynamic\shortcourse5bussytem\daynmictest.snp")

Initialize + RUN DYN FOR 1 SND

psspy.strt(outfile="C:\Users\user\Desktop\IT\FYP2\Dynamic\shortcourse5bussytem\daynmictest.out") psspy.run(tpause=1)

APPLYING BUS FAULT

PRE FAULT CONDITION + CUREATING FAULT

3-phase fault on bus 100 (default bus fault is a 3phase and there is no bus 200)

psspy.distbusfault(ibus=100)

#

DURING FAULT CONDITION RUNNING FOR 1.1 SND

time = 1.1

psspy.run(tpause=time)

#

Clear fault (assuming only part of bus faults)

psspy.distclearfault()

psspy.distbranchtrip(ibus=100, jbus=150, id='1')

#

AFTER FAULT CONDITION

Run to 15 seconds

time = 15

psspy.run(tpause=time)

----------------------------------------------------------------------------------------------------

def array2dict(dictkeys, dictvalues): '''Convert array to dictionary of arrays. psspy.halt()s dictionary as {dictkeys:dictvalues} ''' tmpdict = {} for i in range(len(dictkeys)): tmpdict[dictkeys[i].lower()] = dict_values[i] return tmpdict

----------------------------------------------------------------------------------------------------

def busindexes(busnum, busnumlist): '''Find indexes of a bus in list of buses. psspy.halt()s list with indexes of 'busnum' in 'busnumlist'. ''' busidxes = [] startidx = 0 buscounts = busnumlist.count(busnum) if buscounts: for i in range(buscounts): tmpidx = busnumlist.index(busnum,startidx) busidxes.append(tmpidx) startidx = tmpidx+1 return busidxes

----------------------------------------------------------------------------------------------------

def splitstring_commaspace(tmpstr): '''Split string first at comma and then by space. Example: Input tmpstr = a1 a2, ,a4 a5 ,,,a8,a9 Output strlst = ['a1', 'a2', ' ', 'a4', 'a5', ' ', ' ', 'a8', 'a9'] ''' strlst = [] commalst = tmpstr.split(',') for each in commalst: eachlst = each.split() if eachlst: strlst.extend(eachlst) else: strlst.extend(' ')

return strlst

savfile = 'savnw.sav' print "steadystate30-6-14: %s\n\n"%savfile clnttls = "%6s,%18s,%6s,%18s,%3s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s\n"%('FRMBUS','FROMBUSEXNAME','TOBUS','TOBUSEXNAME','CKT','R(pu)','X(pu)','Z(pu)','ZZ','Vs(pu)','VsVs','Pj','Qj','Qj(pu)','FVSI') print clnttls

sid = -1

flagbus = 1 # in-service flagplant = 1 # in-service flagload = 1 # in-service flagswsh = 1 # in-service flagbrn = 1 # in-service ownerbrn = 1 # use bus ownership, ignored if sid is -ve ties_brn = 5 # ignored if sid is -ve

------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------

Case Title

titleline1, titleline2 = psspy.titldt()

------------------------------------------------------------------------------------------------

Bus Data

Bus Data - Integer

istrings = ['number','type','area','zone','owner','dummy'] ierr, idata = psspy.abusint(sid, flag_bus, istrings) if ierr: print '(1) psspy.abusint error = %d' % ierr psspy.halt() ibuses = array2dict(istrings, idata)

Bus Data - Real

rstrings = ['base','pu','kv','angle','angled','mismatch','omismatch'] ierr, rdata = psspy.abusreal(sid, flagbus, rstrings) if ierr: print '(1) psspy.abusreal error = %d' % ierr psspy.halt() rbuses = array2dict(strings, rdata)

Bus Data - Complex

xstrings = ['voltage','shuntact','oshuntact','shuntnom','oshuntnom','mismatch','omismatch']
ierr, xdata = psspy.abuscplx(sid, flag
bus, xstrings) if ierr: print '(1) psspy.abuscplx error = %d' % ierr psspy.halt() xbuses = array2dict(xstrings, xdata)

Bus Data - Character

cstrings = ['name','exname'] ierr, cdata = psspy.abuschar(sid, flag_bus, cstrings) if ierr: print '(1) psspy.abuschar error = %d' % ierr psspy.halt() cbuses = array2dict(cstrings, cdata)

Store bus data for all buses

ibusesall={};rbusesall={};xbusesall={};cbusesall={}; if sid == -1: ibusesall=ibuses rbusesall=rbuses xbusesall=xbuses cbusesall=cbuses else: ierr, idata = psspy.abusint(-1, flag_bus, istrings) if ierr: print '(2) psspy.abusint error = %d' % ierr psspy.halt() ibusesall = array2dict(istrings, idata)

ierr, rdata = psspy.abusreal(-1, flag_bus, rstrings)
if ierr:
    print '(2) psspy.abusreal error = %d' % ierr
    psspy.halt()
rbusesall = array2dict(rstrings, rdata)

ierr, xdata = psspy.abuscplx(-1, flag_bus, xstrings)
if ierr:
    print '(2) psspy.abuscplx error = %d' % ierr
    psspy.halt()
xbusesall = array2dict(xstrings, xdata)

ierr, cdata = psspy.abuschar(-1, flag_bus, cstrings)
if ierr:
    print '(2) psspy.abuschar error = %d' % ierr
    psspy.halt()
cbusesall = array2dict(cstrings, cdata)

------------------------------------------------------------------------------------------------

Branch Data

Branch Data - Integer

istrings = ['fromnumber','tonumber','status','nmeternumber','owners','own1','own2','own3','own4'] ierr, idata = psspy.abrnint(sid, ownerbrn, tiesbrn, flag_brn,1, istrings) if ierr: print 'psspy.abrnint error = %d' % ierr psspy.halt() ibranch = array2dict(istrings, idata)

Branch Data - Real

rstrings = ['amps','pucur','pctrate','pctratea','pctrateb','pctratec','pctmvarate', 'pctmvaratea','pctmvarateb',#'pctmvaratec', 'fract1','fract2','fract3','fract4','rate','ratea','rateb','ratec', 'p','q','mva','ploss','qloss', 'op','oq','omva','oploss','oqloss' ] ierr, rdata = psspy.abrnreal(sid, ownerbrn, tiesbrn, flagbrn,1, rstrings) if ierr: print 'psspy.abrnreal error = %d' % ierr psspy.halt() rbranch = array2dict(rstrings, rdata)

Branch Data - Complex

xstrings = ['rx','pq','pqloss','opq','opqloss'] ierr, xdata = psspy.abrncplx(sid, ownerbrn, tiesbrn, flag_brn,1, xstrings) if ierr: print 'psspy.abrncplx error = %d' % ierr psspy.halt() xbranch = array2dict(xstrings, xdata)

Branch Data - Character

cstrings = ['id','fromname','fromexname','toname','toexname','nmetername','nmeterexname'] ierr, cdata = psspy.abrnchar(sid, ownerbrn, tiesbrn, flag_brn,1, cstrings) if ierr: print 'psspy.abrnchar error = %d' % ierr psspy.halt() cbranch = array2dict(cstrings, cdata)

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

for i in range(len(ibuses['number'])): bus = ibuses['number'][i]

flowfrombusidxes = busindexes(bus,ibranch['fromnumber'])

for idx in flowfrombusidxes:
    b   = ibranch['fromnumber'][idx]
    fbn = cbranch['fromexname'][idx]
    tb  = ibranch['tonumber'][idx]
    tbn = cbranch['toexname'][idx]
    ckt = cbranch['id'][idx]
    r   = abs(xbranch['rx'][idx].real)
    x   = xbranch['rx'][idx].imag

    frombusidx = busindexes(ibranch['fromnumber'][idx],ibusesall['number'])
    vs = rbusesall['pu'][frombusidx[0]]

    ps = rbranch['p'][idx]
    qs = rbranch['q'][idx]

    from math import sqrt
    z = sqrt(r*r+x*x)
    z2  = pow(z,2)
    vs2 = pow(vs,2)
    qsj = abs(qs/100)
    fvsi= (4*z2*qsj)/(vs2*x)

    print "%(b)6d,%(fbn)18s,%(tb)6d,%(tbn)18s,%(ckt)3s,%(r)8.6f,%(x)8.6f,%(z)8.6f,%(z2)8.6f,%(vs)8.4f,%(vs2)8.4f,%(ps)8.2f,%(qs)8.2f,%(qsj)8.2f,%(fvsi)8.4f\n"%vars() *
click to hide/show revision 2
No.2 Revision

HOW TO CALCULATE FVSI FROM DYNAMIC SIMULATION

Hello Everyone,

i want a code to perform dynamic simulation and calculate FVSI later ... to achieve that i had compile some codes got it from here, but i stuck to complete the code. can you please help me to complete it ..

Much Thanks

*#identify system office and tools function.
import os
import sys
import glob

To glob #To idntifty where is psse file inside the computer files

files PSSE_PATH = r'C:\Program Files (x86)\PTI\PSSEUniversity33\PSSBIN'

Telling (x86)\PTI\PSSEUniversity33\PSSBIN' #Telling python where to find psse

sys.path.append(PSSE_PATH)

settle psse sys.path.append(PSSE_PATH) #settle the enviorment file

file os.environ['PATH'] += ';' + PSSE_PATH

PSSE INITIALIZATION

PSSE_PATH #PSSE INITIALIZATION import psspy import redirect redirect.psse2py() psspy.psseinit()

psspy.psseinit() # RUN POWER FLOW CASE

CASE bussystem= r"""C:\Users\user\Desktop\IT\FYP2\Dynamic\shortcourse5bussytem\TEST1.sav""" psspy.case(bussystem)

solve powerflow

psspy.fdns([0,0,0,1,1,0,99,0])

psspy.case(bussystem) #solve powerflow psspy.fdns([0,0,0,1,1,0,99,0]) # Convert loads (3 step process):

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

psspy.conl(-1,1,3) # Convert generators:

psspy.cong()

generators: psspy.cong() # Solve for dynamics

dynamics psspy.ordr() psspy.fact() psspy.tysl()

psspy.tysl() # Add dynamics data

psspy.dyre_new(dyrefile="C:\Users\user\Desktop\IT\FYP2\Dynamic\shortcourse5bussytem\daynmictest.dyr")

data psspy.dyre_new(dyrefile="C:\Users\user\Desktop\IT\FYP2\Dynamic\shortcourse5bussytem\daynmictest.dyr") # Add channels by subsystem

subsystem # BUS VOLTAGE

VOLTAGE psspy.chsb(sid=0,all=1, status=[-1,-1,-1,1,13,0])

status=[-1,-1,-1,1,13,0]) # BUS ANGLE

ANGLE psspy.chsb(sid=0,all=1, status=[-1,-1,-1,1,1,0])

status=[-1,-1,-1,1,1,0]) # BUS P&Q

P&Q psspy.chsb(sid=0,all=1, status=[-1,-1,-1,1,16,0])

status=[-1,-1,-1,1,16,0]) # Save snapshot

psspy.snap(sfile="C:\Users\user\Desktop\IT\FYP2\Dynamic\shortcourse5bussytem\daynmictest.snp")

snapshot psspy.snap(sfile="C:\Users\user\Desktop\IT\FYP2\Dynamic\shortcourse5bussytem\daynmictest.snp") # Initialize + RUN DYN FOR 1 SND

SND psspy.strt(outfile="C:\Users\user\Desktop\IT\FYP2\Dynamic\shortcourse5bussytem\daynmictest.out") psspy.run(tpause=1)

APPLYING psspy.run(tpause=1) ####APPLYING BUS FAULT

PRE FAULT ####PRE FAULT CONDITION + CUREATING FAULT

3-phase FAULT ###3-phase fault on bus 100 (default bus fault is a 3phase and there is no bus 200)

psspy.distbusfault(ibus=100)

#

200) ##psspy.dist_bus_fault(ibus=100) ## ### DURING FAULT CONDITION RUNNING FOR 1.1 SND

time = 1.1

psspy.run(tpause=time)

#

SND ##time = 1.1 ##psspy.run(tpause=time) ## ### Clear fault (assuming only part of bus faults)

psspy.distclearfault()

psspy.distbranchtrip(ibus=100, faults) ####psspy.dist_clear_fault() ##psspy.dist_branch_trip(ibus=100, jbus=150, id='1')

#

AFTER id='1') ## ####AFTER FAULT CONDITION

CONDITION ### Run to 15 seconds

time = 15

psspy.run(tpause=time)

----------------------------------------------------------------------------------------------------

seconds ##time = 15 ##psspy.run(tpause=time) # ---------------------------------------------------------------------------------------------------- def array2dict(dictkeys, dictvalues): array2dict(dict_keys, dict_values): '''Convert array to dictionary of arrays. psspy.halt()s dictionary as {dictkeys:dictvalues} {dict_keys:dict_values} ''' tmpdict = {} for i in range(len(dictkeys)): tmpdict[dictkeys[i].lower()] range(len(dict_keys)): tmpdict[dict_keys[i].lower()] = dict_values[i] return tmpdict

----------------------------------------------------------------------------------------------------

tmpdict # ---------------------------------------------------------------------------------------------------- def busindexes(busnum, busnumlist): '''Find indexes of a bus in list of buses. psspy.halt()s list with indexes of 'busnum' in 'busnumlist'. ''' busidxes = [] startidx = 0 buscounts = busnumlist.count(busnum) if buscounts: for i in range(buscounts): tmpidx = busnumlist.index(busnum,startidx) busidxes.append(tmpidx) startidx = tmpidx+1 return busidxes

----------------------------------------------------------------------------------------------------

busidxes # ---------------------------------------------------------------------------------------------------- def splitstring_commaspace(tmpstr): '''Split string first at comma and then by space. Example: Input tmpstr = a1 a2, ,a4 a5 ,,,a8,a9 Output strlst = ['a1', 'a2', ' ', 'a4', 'a5', ' ', ' ', 'a8', 'a9'] ''' strlst = [] commalst = tmpstr.split(',') for each in commalst: eachlst = each.split() if eachlst: strlst.extend(eachlst) else: strlst.extend(' ')

')

    return strlst

savfile = 'savnw.sav' print "steadystate30-6-14: %s\n\n"%savfile clnttls = "%6s,%18s,%6s,%18s,%3s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s\n"%('FRMBUS','FROMBUSEXNAME','TOBUS','TOBUSEXNAME','CKT','R(pu)','X(pu)','Z(pu)','ZZ','Vs(pu)','VsVs','Pj','Qj','Qj(pu)','FVSI') "%6s,%18s,%6s,%18s,%3s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s,%8s\n"%('FRMBUS','FROMBUSEXNAME','TOBUS','TOBUSEXNAME','CKT','R(pu)','X(pu)','Z(pu)','Z*Z','Vs(pu)','Vs*Vs','Pj','Qj','Qj(pu)','FVSI') print clnttls

clnttls sid = -1

flagbus flag_bus = 1 # in-service flagplant flag_plant = 1 # in-service flagload flag_load = 1 # in-service flagswsh flag_swsh = 1 # in-service flagbrn flag_brn = 1 # in-service ownerbrn owner_brn = 1 # use bus ownership, ignored if sid is -ve ties_brn = 5 # ignored if sid is -ve

------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------

-ve # ------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------ # Case Title

Title titleline1, titleline2 = psspy.titldt()

------------------------------------------------------------------------------------------------

psspy.titldt() # ------------------------------------------------------------------------------------------------ # Bus Data

Data # Bus Data - Integer

Integer istrings = ['number','type','area','zone','owner','dummy'] ierr, idata = psspy.abusint(sid, flag_bus, istrings) if ierr: print '(1) psspy.abusint error = %d' % ierr psspy.halt() ibuses = array2dict(istrings, idata)

idata) # Bus Data - Real

Real rstrings = ['base','pu','kv','angle','angled','mismatch','omismatch'] ['base','pu','kv','angle','angled','mismatch','o_mismatch'] ierr, rdata = psspy.abusreal(sid, flagbus, flag_bus, rstrings) if ierr: print '(1) psspy.abusreal error = %d' % ierr psspy.halt() rbuses = array2dict(strings, rdata)

# Bus Data - Complex

Complex xstrings = ['voltage','shuntact','oshuntact','shuntnom','oshuntnom','mismatch','omismatch']
['voltage','shuntact','o_shuntact','shuntnom','o_shuntnom','mismatch','o_mismatch'] ierr, xdata = psspy.abuscplx(sid, flagbus, flag_bus, xstrings) if ierr: print '(1) psspy.abuscplx error = %d' % ierr psspy.halt() xbuses = array2dict(xstrings, xdata)

xdata) # Bus Data - Character

Character cstrings = ['name','exname'] ierr, cdata = psspy.abuschar(sid, flag_bus, cstrings) if ierr: print '(1) psspy.abuschar error = %d' % ierr psspy.halt() cbuses = array2dict(cstrings, cdata)

cdata) # Store bus data for all buses

buses ibusesall={};rbusesall={};xbusesall={};cbusesall={}; if sid == -1: ibusesall=ibuses rbusesall=rbuses xbusesall=xbuses cbusesall=cbuses else: ierr, idata = psspy.abusint(-1, flag_bus, istrings) if ierr: print '(2) psspy.abusint error = %d' % ierr psspy.halt() ibusesall = array2dict(istrings, idata)

idata)

    ierr, rdata = psspy.abusreal(-1, flag_bus, rstrings)
 if ierr:
     print '(2) psspy.abusreal error = %d' % ierr
     psspy.halt()
 rbusesall = array2dict(rstrings, rdata)

 ierr, xdata = psspy.abuscplx(-1, flag_bus, xstrings)
 if ierr:
     print '(2) psspy.abuscplx error = %d' % ierr
     psspy.halt()
 xbusesall = array2dict(xstrings, xdata)

 ierr, cdata = psspy.abuschar(-1, flag_bus, cstrings)
 if ierr:
     print '(2) psspy.abuschar error = %d' % ierr
     psspy.halt()
 cbusesall = array2dict(cstrings, cdata)

------------------------------------------------------------------------------------------------

# ------------------------------------------------------------------------------------------------ # Branch Data

Data # Branch Data - Integer

Integer istrings = ['fromnumber','tonumber','status','nmeternumber','owners','own1','own2','own3','own4'] ierr, idata = psspy.abrnint(sid, ownerbrn, tiesbrn, owner_brn, ties_brn, flag_brn,1, istrings) if ierr: print 'psspy.abrnint error = %d' % ierr psspy.halt() ibranch = array2dict(istrings, idata)

idata) # Branch Data - Real

Real rstrings = ['amps','pucur','pctrate','pctratea','pctrateb','pctratec','pctmvarate', 'pctmvaratea','pctmvarateb',#'pctmvaratec', 'fract1','fract2','fract3','fract4','rate','ratea','rateb','ratec', 'p','q','mva','ploss','qloss', 'op','oq','omva','oploss','oqloss' 'o_p','o_q','o_mva','o_ploss','o_qloss' ] ierr, rdata = psspy.abrnreal(sid, ownerbrn, tiesbrn, flagbrn,1, owner_brn, ties_brn, flag_brn,1, rstrings) if ierr: print 'psspy.abrnreal error = %d' % ierr psspy.halt() rbranch = array2dict(rstrings, rdata)

rdata) # Branch Data - Complex

Complex xstrings = ['rx','pq','pqloss','opq','opqloss'] ['rx','pq','pqloss','o_pq','o_pqloss'] ierr, xdata = psspy.abrncplx(sid, ownerbrn, tiesbrn, owner_brn, ties_brn, flag_brn,1, xstrings) if ierr: print 'psspy.abrncplx error = %d' % ierr psspy.halt() xbranch = array2dict(xstrings, xdata)

xdata) # Branch Data - Character

Character cstrings = ['id','fromname','fromexname','toname','toexname','nmetername','nmeterexname'] ierr, cdata = psspy.abrnchar(sid, ownerbrn, tiesbrn, owner_brn, ties_brn, flag_brn,1, cstrings) if ierr: print 'psspy.abrnchar error = %d' % ierr psspy.halt() cbranch = array2dict(cstrings, cdata)

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

cdata) #$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ for i in range(len(ibuses['number'])): bus = ibuses['number'][i]

ibuses['number'][i]

    flowfrombusidxes = busindexes(bus,ibranch['fromnumber'])

 for idx in flowfrombusidxes:
     b   = ibranch['fromnumber'][idx]
     fbn = cbranch['fromexname'][idx]
     tb  = ibranch['tonumber'][idx]
     tbn = cbranch['toexname'][idx]
     ckt = cbranch['id'][idx]
     r   = abs(xbranch['rx'][idx].real)
     x   = xbranch['rx'][idx].imag

     frombusidx = busindexes(ibranch['fromnumber'][idx],ibusesall['number'])
     vs = rbusesall['pu'][frombusidx[0]]

     ps = rbranch['p'][idx]
     qs = rbranch['q'][idx]

     from math import sqrt
     z = sqrt(r*r+x*x)
     z2  = pow(z,2)
     vs2 = pow(vs,2)
     qsj = abs(qs/100)
     fvsi= (4*z2*qsj)/(vs2*x)

     print "%(b)6d,%(fbn)18s,%(tb)6d,%(tbn)18s,%(ckt)3s,%(r)8.6f,%(x)8.6f,%(z)8.6f,%(z2)8.6f,%(vs)8.4f,%(vs2)8.4f,%(ps)8.2f,%(qs)8.2f,%(qsj)8.2f,%(fvsi)8.4f\n"%vars() *