2

Dynamic simulations using Python

I've been following an example from the PSSE "Program Application Guide" to run a dynamic simulation where a fault is initialized and cleared.

I now want to do similar simulations from Python not PSSE, but I can't figure out how to do it.

The example goes as follows:

  1. Steady state initialization (t < 0-)
  2. 3-phase fault at bus 200, large admittance to ground (t < 0.1s)
  3. Fault clearance (zero admittance to ground), branch 100-200 is out. (t < 3s)

I have very limited knowledge about both PSSE and Python, so any tips and tricks (best practice) would be most welcome!

What is the correct way of creating faults? The equivalent of ALTR in PSSE? How can I plot the results afterwards? (Choose channels etc. etc.)

The (unfinished) code I have now is included below. It's plain to see that it's no good, but I don't what the correct way to do it is. Also, I don't know how to check if it works (besides noting that I don't get errors).

import os,sys
PYTHONPATH = r'C:\Program Files (x86)\PTI\PSSE32\PSSBIN'
MODELFOLDER = r'C:\Program Files (x86)\PTI\PSSE32\MODELDRW'

sys.path.append(PYTHONPATH)
os.environ['PATH'] += ';' + PYTHONPATH
## Numpy of matplotlib maa lastes ned for aa brukes:
## http://www.whit.com.au/blog/python-libraries-for-psse-python-training/

# import numpy as np
# import matplotlib.pyplot as plt
import psspy
import redirect
import dyntools

# Redirect output from PSSE to Python:
redirect.psse2py()

# Last case:
CASE = r"C:\Program Files (x86)\PTI\PSSE32\EXAMPLE\savnw.sav"
psspy.psseinit(12000)
psspy.case(CASE)

ierr = psspy.dyre_add(dyrefile="C:\Program Files (x86)\PTI\PSSE32\EXAMPLE\savnw.dyr")
ierr = psspy.rstr("C:\Program Files (x86)\PTI\PSSE32\EXAMPLE\savnw.snp")
# Convert generators:
ierr = psspy.cong()
# Convert loads:
ierr, rlods = psspy.conl(all=1,apiopt=2, status1=0, loadin1=100,loadin2=0, loadin3 = 0, loadin4 = 100)

ierr = psspy.fact()
ierr = psspy.strt(outfile="C:\Program Files (x86)\PTI\PSSE32\EXAMPLE\python_test.out")

Btw, the complete path name is written, because it can't find the files if I don't.

Transmission Impossible's avatar
71
Transmission Impossible
asked 2013-09-06 07:59:15 -0500, updated 2013-09-06 08:00:52 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

4

I have never used the dyntools toolbox before, but here is an example of how to do a simulation like your example using just the functions in the standard psspy API. You were on the right track, but missing a few steps.

import os,sys
PYTHONPATH = r'C:\Program Files (x86)\PTI\PSSE32\PSSBIN'
MODELFOLDER = r'C:\Program Files (x86)\PTI\PSSE32\MODELDRW'

sys.path.append(PYTHONPATH)
os.environ['PATH'] += ';' + PYTHONPATH

import psspy
import redirect

# Redirect output from PSSE to Python:
redirect.psse2py()

# Last case:
CASE = r"C:\Program Files (x86)\PTI\PSSE32\EXAMPLE\savnw.sav"
psspy.psseinit(12000)
psspy.case(CASE)

# Convert loads (3 step process):
psspy.conl(-1,1,1)
psspy.conl(-1,1,2,[0,0],[100,0,0,100])
psspy.conl(-1,1,3)

# Convert generators:
psspy.cong()

# Solve for dynamics
psspy.ordr()
psspy.fact()
psspy.tysl()

# Save converted case
case_root = os.path.splitext(CASE)[0]
psspy.save(case_root + "_C.sav")

# Add dynamics data
psspy.dyre_new(dyrefile="C:\Program Files (x86)\PTI\PSSE32\EXAMPLE\savnw.dyr")

# Add channels by subsystem
#   BUS VOLTAGE
psspy.chsb(sid=0,all=1, status=[-1,-1,-1,1,13,0])
#   MACHINE SPEED
psspy.chsb(sid=0,all=1, status=[-1,-1,-1,1,7,0])

# Add channels individually
#   BRANCH MVA
psspy.branch_mva_channel([-1,-1,-1,3001,3002],'1')

# Save snapshot
psspy.snap(sfile="C:\Program Files (x86)\PTI\PSSE32\EXAMPLE\python_test.snp")

# Initialize
psspy.strt(outfile="C:\Program Files (x86)\PTI\PSSE32\EXAMPLE\python_test_1.out")
psspy.run(tpause=0)

# 3-phase fault on bus 201 (default bus fault is a 3phase and there is no bus 200)
psspy.dist_bus_fault(ibus=201)

# Run to 3 cycles
time = 3.0/60.0
psspy.run(tpause=time)

# Clear fault (assuming only part of bus faults)
psspy.dist_clear_fault()
psspy.dist_branch_trip(ibus=201, jbus=151, id='1')

# Run to 20 seconds
time = 20
psspy.run(tpause=time)

#-----------------------------

# Run 2nd fault if you want
psspy.case(case_root + "_C.sav")
psspy.rstr(sfile="C:\Program Files (x86)\PTI\PSSE32\EXAMPLE\python_test.snp")

# Initialize
psspy.strt(outfile="C:\Program Files (x86)\PTI\PSSE32\EXAMPLE\python_test_2.out")
psspy.run(tpause=0)

# 1-phase fault branch 3001 to 3003
psspy.dist_branch_fault(ibus=3001, jbus=3003, id='1',units=1,values=[352,-2389])

# Run to 4 cycles
time = 4.0/60.0
psspy.run(tpause=time)

# Clear fault
psspy.dist_clear_fault()
psspy.dist_branch_trip(ibus=3001, jbus=3003, id='1')

# Run to 20 seconds
time = 20
psspy.run(tpause=time)


# Halt
psspy.pssehalt_2()

Hopefully that is enough to get you started. There is so much more you can do and this is a pretty basic example and doesn't cover adding any user dynamic model. I suggest poking around the API manual in Chapter 4 to see what is available dynamics wise and also the POM to see what these functions do.

EBahr's avatar
420
EBahr
answered 2013-09-06 13:11:18 -0500, updated 2013-12-17 09:09:47 -0500
edit flag offensive 0 remove flag delete link

Comments

Dear EBahr,you have done so excellent! Could you help me? I want to read the standard psspy API for learn the functions and to use psse btter. unfortunately I do not know how can I get it or where to get it,my email is bob1026@163.com. Thanks a lot!

Bob's avatar Bob (2013-09-24 22:56:11 -0500) edit

@Bob, if you have PSSE installed it will be located in your PTI directory (ie for rev 32 it is under C:\Program Files (x86)\PTI\PSSE32\DOCS\PSSEAPI)

EBahr's avatar EBahr (2013-09-25 08:15:28 -0500) edit

@EBahr thanks. May I have the pleasure to know your email,I want to learn from you and communicate with you, best wishes.

Bob's avatar Bob (2013-09-25 08:52:09 -0500) edit

@EBahr -- In this code you used the command psspy.open() instead of psspy.case(). Was there a reason for this? I do not see the .open() API anywhere in the manual. I am having problems saving and reloading dynamic studies......

wassup_doc's avatar wassup_doc (2013-12-13 10:36:09 -0500) edit

@EBahr -- The machine dynamic variables (speed, etc.) are either not saved when I do psspy.snap() or they are not loaded when I do psspy.rstr(). Any help with the correct process to save a simulation mid-study and reload would be appreciated. I can formulate this as a new question if necessary.

wassup_doc's avatar wassup_doc (2013-12-13 10:38:56 -0500) edit
add a comment see more comments
0

A careful study of the example python script 'dyntools_demo' in the EXAMPLES directory can be a big help. Just run the script and look at output. Then try and identify which part of the code corresponds to which part of the output.

amaity's avatar
586
amaity
answered 2013-09-09 20:10:51 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments

Your Answer

Login/Signup to Answer