# How can I get dynamic control on python?

Hello.

I am trying to use python to control generator trip while fault is initialized and cleared. I want to trip the generators if the angle spread runs out of limit after the fault is cleared, but I cannot figure out how to do it on python.

I have been doing this simulation on pss/e interface with excel and matlab. But I think there must be a better way with python only.

https://psspy.org/psse-help-forum/question/1118/dynamic-simulations-using-python/

edit retag close merge delete

Sort by ยป oldest newest most voted

I think for this application it would be best to write a custom USRMDL in Fortran. This is probably more work if you don't know Fortran, but it has the benefit of running in real time and would probably be the most accurate simulation you could achieve.

Another option that I have never tested but may be worth looking at is to try using the CHNVAL function. Pause the simulation at any timestep you would like, check the channel values of your choice, then make any decisions based on that. From the API:

7.24 CHNVAL Use this API to return the present value of the simulation variable assigned to a specified output channel. Python syntax: ierr, rval = chnval(n)

You could also post process, like JervisW suggests.

UPDATE I am not exactly sure what 'angle spread' is, so here is some Fortran code of my interpretation. I assumed it meant measure the bus angle between two buses, if it reached a certain value, then trip a generator. This code trips a bus, not a generator. I am not very experienced with Fortran, and I don't really know PSS/e internal variables and calls that well, but the following code does trip a generator bus if the angle spread between two buses goes above specified threshold.

FORTRAN:

      SUBROUTINE TRIPGEN(II,JJ,KK,LL)
INCLUDE 'COMON4.INS'
C     ICON(II)=BUS 1
C     ICON(II+1)=BUS 2
C     ICON(II+2)=BUS 1 INTERNAL ID
C     ICON(II+3)=BUS 2 INTERNAL ID
C     ICON(II+4)=GEN BUS TO TRIP
C     ICON(II+5)=GEN BUS INTERNAL ID
C     ICON(II+6)=RUN FLAG (1=RUN, 0=DON'T RUN)

REAL*4 ANGA, ANGB
INTEGER*4 IERR

C     INIT CODE HERE
IF ( MODE .EQ. 1  .OR.  KPAUSE .EQ. 2 ) THEN
IF (IFLAG) THEN
CALL BSSEQN(ICON(II+4),ICON(II+5),*7)
1         CALL BSSEQN(ICON(II),ICON(II+2),*8)
2         CALL BSSEQN(ICON(II+1),ICON(II+3),*9)

GO TO 100

7         WRITE ( ITERM, * ) 'BUS NUMBER ', ICON(II+4), ' NOT FOUND'
ICON(II+6)=0
GO TO 1
8         WRITE ( ITERM, * ) 'BUS NUMBER ', ICON(II), ' NOT FOUND'
ICON(II+6)=0
GO TO 2
9         WRITE ( ITERM, * ) 'BUS NUMBER ', ICON(II+1), ' NOT FOUND'
ICON(II+6)=0
ENDIF
10    ENDIF

C     ONLY CALCULATE IF SOLUTION CONVERGED
IF (IFLAG) THEN
GO TO 50
ELSE
GO TO 100
ENDIF

C     RETURN IF ERROR IN BUS NUMBERS
50    IF (ICON(II+6) .EQ. 0) THEN
GO TO 100
ENDIF

C     RUN CODE HERE
IF (MODE .EQ. 2) THEN
CALL BUSDAT(ICON(II),'ANGLED',ANGA,IERR)
CALL BUSDAT(ICON(II+1),'ANGLED',ANGB,IERR)
ANGSPRD = ABS(ANGA-ANGB)
C        WRITE ( ITERM, * ) 'ANGLE SPREAD IS = ', ANGSPRD !USED FOR DEBUG
IF (ANGSPRD .GT. CON(JJ)) THEN
CALL BSDSCN(ICON(II+4))
WRITE ( ITERM, * ) 'ANGLE SPREAD REACHED TOLERANCE, BUS ', ICON(II+4), ' TRIPPED'
ICON(II+6)=0
ENDIF
ENDIF

100   RETURN
END


And here would be ...

more

I like the CHNVAL suggestion, good for finding values that exceed absolute thresholds, you could also take a series of points to get a trend. How does the USRMDL work? Would you write one for each of the generators that need to trip, and monitor a remote angle somewhere?

( 2013-09-12 19:53:18 -0500 )edit

The code I posted could be recalled for each generator/bus combo. You would just need to add a .dyr call for each one.

( 2013-09-13 13:54:18 -0500 )edit

Thank you! Thank you very much! You are so AWESOME! and another thanks to JervisW! You're idea for CHNVAL function has enlightened me!

( 2013-09-15 21:38:42 -0500 )edit

Thanks for the clue. It will be very helpful.

( 2022-03-22 13:18:05 -0500 )edit

I don't have a deep level of experience with Dynamics, so I hope that someone can chime in and correct me if I'm wrong.

• You cannot check the angles with Python while PSS/E is actually running the simulation. That means you'll need to stop simulating for a little bit and check the .out file for the monitored machine angles.

I propose something like this:

1. Run for a short period of time after clearing fault (e.g. 1 second)
2. Check the .out file using dyntools for the machine angle spread
3. Either take action by tripping generators or continuing the study depending on the outcome of #2

Feel free to adjust the timing above, I've only used 1 second as a guide.

more

[hide preview]

## Stats

Seen: 2,140 times

Last updated: Sep 13 '13