Ask Your Question
1

Do you know a code to find how many buses away are two buses in a power flow?

asked 2020-04-10 03:33:58 -0500

PH-profile gravatar image

I am trying to find how many buses are two buses in a power flow case.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2020-04-15 04:23:23 -0500

perolofl gravatar image

Below I present a function (getlevelsapart) that returns the number of levels between two buses. For example, using the savnw network, call the function to calculate the levels between bus 3011 and 3005:

n = getlevelsapart(3011,3005)

Here, the function will return 3.

Similarly, the levels between bus 3011 and bus 206 is 7.

n = getlevelsapart(3011,206)

Definition of function getlevelsapart:

def getlevelsapart(ibus,jbus,flag=2,ms=True):
    """ Returns number of levels between ibus and jbus
    connected with branch, 2W or 3W.
    ibus: number of startnode
    jbus: number of endnode
    flag: 1= use also connection out of service, 2= only in-service connection
    ms: True= use multisection line definition, False = ignore multi-section line 

    Returns None if there is no AC network between ibus and jbus
    """
    if psspy.busexs(ibus) == 1:
        print 'Error getlevelsapart: Start bus %s does not exist' % ibus
        return None
    if psspy.busexs(jbus) == 1:
        print 'Error getlevelsapart: End bus %s does not exist' % jbus
        return None
    busdict = {ibus:0}  # dict with level for each analysed bus
    nextbuses = [ibus] # start search at ibus
    # For each level out into the grid
    for level in range(99999):
        searchbuses = list(nextbuses) # buses for next level search
        nextbuses = {}  # New buses at next level
        # For each start node at this level
        for bus in searchbuses:
            if ms: ierr = psspy.inibrx(bus, 2)
            else: ierr = psspy.inibrn(bus, 2)
            while ierr==0: # for every connection to bus
                ierr,tbus,kbus,ickt = psspy.nxtbrn3(bus)
                if ierr>0: break
                if kbus==0: # branch or 2W
                    ier2,st = psspy.brnint(bus,tbus,ickt,'STATUS')
                else: # 3W
                    ier2, st = psspy.tr3int(bus, tbus, kbus, ickt, 'STATUS')
                if flag==1 or st==1: 
                    if tbus not in busdict: # tbus at next level
                        busdict[tbus] = level+1
                        nextbuses[tbus] = level+1
                    if kbus>0:
                        if kbus not in busdict:  # kbus at next level
                            busdict[kbus] = level+1
                            nextbuses[kbus] = level+1

            if jbus in nextbuses: return level+1   # jbus found

        if len(nextbuses) == 0:  # No more levels found
            print 'No AC connection between bus %s [%s] and bus %s [%s]' % (ibus,psspy.notona(ibus)[1],jbus,psspy.notona(jbus)[1])
            return None
edit flag offensive delete link more

Comments

Hi Thanks for this function and examples. Can I request how to define this function (where in PSSE?) and where (IDV file?) to use this function? Can I use it directly in PSSE command window? Can we have equivalent BAT command? Can you pls advice? Thanks

Ajith gravatar imageAjith ( 2024-09-11 02:46:26 -0500 )edit

This is a Python function and shall be inserted in a Python script, together with a call of the function, as described above. The function definition must be before the function call.

perolofl gravatar imageperolofl ( 2024-09-11 12:12:40 -0500 )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

3 followers

Stats

Asked: 2020-04-10 03:33:58 -0500

Seen: 1,648 times

Last updated: Apr 15 '20