First time here? We are a friendly community of Power Systems Engineers. Check out the FAQ!
1 | initial version |
I just wrote this a couple hours ago for a similar problem. So it can probably be cleaned up:
def get_next_free_busnum():
"""
get the next free bus number
"""
# find largest bus number
sid = 1
ierr = psspy.bsys(
sid=sid,
usekv=1,
basekv=[0, 1000],
)
ierr, all_buses = psspy.abusint(
sid=sid,
flag=1,
string=["NUMBER"]
)
all_buses = all_buses[0]
busnum = max(all_buses) + 1
return busnum
2 | No.2 Revision |
I just wrote this a couple hours ago for a similar problem. So it can probably be cleaned up:
def get_next_free_busnum():
"""
get the next free bus number
"""
# find largest bus number
sid = 1
ierr = psspy.bsys(
sid=sid,
usekv=1,
basekv=[0, 1000],
)
ierr, all_buses = psspy.abusint(
sid=sid,
flag=1,
string=["NUMBER"]
)
all_buses = all_buses[0]
busnum = max(all_buses) + 1
return busnum
I guess you could do something smart like:
busnum = min(set(range(15000)) - set(all_buses))
# where 15000 is highest busnum you want to use
This will return 0, which I'm not sure is a valid number or not.
3 | Replaced "all bus subsystem" with the -1 shortcut |
I just wrote this a couple hours ago for a similar problem. So it can probably be cleaned up:
def get_next_free_busnum():
"""
get the next free bus number
"""
# find largest bus number
sid = 1
ierr = psspy.bsys(
sid=sid,
usekv=1,
basekv=[0, 1000],
)
ierr, all_buses = psspy.abusint(
sid=sid,
sid=-1, # all buses in the case.
flag=1,
string=["NUMBER"]
)
all_buses = all_buses[0]
busnum = max(all_buses) + 1
return busnum
I guess you could do something smart like:
busnum = min(set(range(15000)) - set(all_buses))
# where 15000 is highest busnum you want to use
This will return 0, which I'm not sure is a valid number or not.
4 | Transpose the resultant "all_buses" 2D array. |
I just wrote this a couple hours ago for a similar problem. So it can probably be cleaned up:
def get_next_free_busnum():
"""
get the next free bus number
"""
# find largest bus number
ierr, all_buses = psspy.abusint(
sid=-1, # all buses in the case.
flag=1,
string=["NUMBER"]
)
# transpose from 2D array to 1D list.
all_buses = all_buses[0]
zip(*all_buses)[0]
busnum = max(all_buses) + 1
return busnum
I guess you could do something smart like:
busnum = min(set(range(15000)) - set(all_buses))
# where 15000 is highest busnum you want to use
This will return 0, which I'm not sure is a valid number or not.
5 | Check for all buses, not just in service. |
I just wrote this a couple hours ago for a similar problem. So it can probably be cleaned up:
def get_next_free_busnum():
"""
get the next free bus number
"""
# find largest bus number
ierr, all_buses = psspy.abusint(
sid=-1, # all buses in the case.
flag=1,
flag=2, # in-service and out-of-service buses
string=["NUMBER"]
)
# transpose from 2D array to 1D list.
all_buses = zip(*all_buses)[0]
busnum = max(all_buses) + 1
return busnum
I guess you could do something smart like:
busnum = min(set(range(15000)) - set(all_buses))
# where 15000 is highest busnum you want to use
This will return 0, which I'm not sure is a valid number or not.