Python for Power Systems

A blog for power systems engineers to learn Python.

Check for Network Solution Convergence

When running a load flow, checking for convergence is simple. There is a dedicated function in the PSS/E API called psspy.solved. How would you do the same thing during a dynamic study?

Dynamic studies can take a long while to run, but if they do not converge near the beginning, then there is no point in continuing the study.

A rough outline of most dynamic studies would look like this:

  • Convert loads and generators
  • Run for 1 second without disturbance
  • Apply fault
  • Run for short time
  • Clear fault
  • Run for 5 seconds

Your studies look similar to this outline. The key is in that final ‘run for 5 seconds’ step. It can take a considerable amount of time to run. If the network solution fails to converge near the start of that 5 second simulation then that time is wasted.

The solution is to look for the convergence monitor output. It’s text that PSS/E writes to the screen to indicate that the solution hasn’t converged.

The manual says this on the issue:

Any convergence failure is reported with an appropriate message, including the final convergence monitor line in the same form as is used by activities SOLV MSLV and TYSL. The simulation then continues as if convergence has been achieved.

Instead of a handy function to check for convergence, we’re forced to read the text output for a specific line about convergence failure. Tedious yes, but not impossible.

Here’s how we’d collect the text output ready for analysis. Firstly, use the StringIO library. It’s a Python library that makes an ordinary string look and act like a file.

1
2
3
4
5
6
7
import StringIO

output = StringIO.StringIO()
output.write("NETWORK NOT CONVERGED")

print output.getvalue()
# prints "NETWORK NOT CONVERGED"

Then we’ll use the silence context manager we wrote in this blog post Silencing PSSE Output to capture the PSSE text into a Python string.

1
2
3
4
5
6
7
8
import StringIO

output = StringIO.StringIO()

with silence(output):
    psspy.run()

result = output.getvalue()

Now let’s check it for the NETWORK NOT CONVERGED string.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import StringIO

output = StringIO.StringIO()

with silence(output):
    psspy.run()

run_output = output.getvalue()

if "NETWORK NOT CONVERGED" in run_output:
    # quit the program.
    raise SystemExit
else:
    print "continuing with study.."

That’s how to check for network convergence during a dynamic simulation. Not as simple as:

1
psspy.solved()

but at least it is possible. I want to give a special thanks to Sheng Goh, power systems engineer at the Australian Energy Market Operator for his help in developing this method.

Note about the examples

The code in these examples won’t run as is – they skip some important steps like setting up your dynamic study. You’ll need to take the ideas (especially the bit about checking for NETWORK NOT CONVERGED) and apply them to your own studies.