Skip to content

Instantly share code, notes, and snippets.

@jtrain
Created September 26, 2011 07:29
Show Gist options
  • Save jtrain/1241786 to your computer and use it in GitHub Desktop.
Save jtrain/1241786 to your computer and use it in GitHub Desktop.
Example code running in a Python for PSSE transaction
from __future__ import with_statement
import os
from transactions import transaction, psspy, PSSE_EXAMPLES
psspy.throwPsseExceptions = False
def validate_solved():
"""
Return true if the last psse case has solved.
I am counting iteration limit exceeded as not solved in this case.
"""
return psspy.solved() == 0
def change_swing_bus_no_reason():
"""
Change the swing bus to a type 2 for no reason other
than to show the rollback in action.
"""
psspy.bus_data_2(3011, intgar1=2)
def add_new_generator():
"""
Add a new fake generator behind a short line to a new
bus near the swing bus.
"""
psspy.bus_data_2(
3012,
intgar1=2, # type 2 bus.
realar1=22) # base kV.
psspy.branch_data(
i=3011,
j=3012,
ckt='NW',
realar2=0.02) # line reactance X)
psspy.plant_data(
3012)
psspy.machine_data_2(
i=3012,
id="01",
realar1=0, # active gen MW.
realar3=100) # reactive gen max MVAr.
def main():
psspy.psseinit(8000)
psspy.case(os.path.join(PSSE_EXAMPLES, 'savnw.sav'))
# adding the new generator should sovle and pass.
with transaction(validate_solved):
add_new_generator()
psspy.fnsl()
# changing the swing bus shouldn't solve and will be
# rolled back.
with transaction(validate_solved):
change_swing_bus_no_reason()
psspy.fnsl()
print psspy.solved()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment