Stop power flow calculations and recover solution if model blows up
Is it possible to create an Automation File (in Python) that tries to run a normal FNSL power flow, but stops, and retrieve original case if the mismatch becomes too large?
The pseudo code of what I want is:
run fnsl
if absolute mismatch > 1 # or some other appropriate value
abort fnsl
print error message: "The power flow blew up".
recover previous power flow results
stop
At the moment, I have to load the .sav case every time my model blows up (which is often). It's cumbersome, and time demanding. I'm doing a lot of manual changes and don't need to store the results, so I don't want to create new .sav-files for every change and load flow I run.
I appreciate any help!
EDIT
One of the things I do a lot of is trying to disconnect different combinations of lines.
- Run power flow
- Disconnect line 1 - Run power flow, OK?
- Disconnect line 2 - Run power flow, OK?
- Disconnect line 3 - Run power flow. Not OK!
- Connect line 1, disconnect line 6. Run power flow, OK?
- Connect line 3, disconnect line 7. Run power flow, Not OK!
- Connect line 2 and 6. Run power flow, OK?
- Turn of generator. Run power flow, OK?
- ... and so on ...
What I want is to make changes in the GUI (in PSS/E), run an automation file that executes fnsl and aborts and restore model if it doesn't converge. I'd prefer not to save the model every time I make a minor adjustment.
Final result (thanks to jconto):
ierr = psspy.save('temp.sav')
if ierr > 0:
print "Couldn't save temp-file"
ierr = psspy.fnsl()
if ierr == 3:
print "Nodes without swing bus. API: tree() may help"
elif ierr != 0:
print "Power flow failed."
ierr = psspy.solved()
if ierr > 0:
psspy.case('temp.sav')
else:
print "Power flow reached convergence"