CFPRIME DEGV20                                                          DEGV20      1
C***********************************************************************RIGHTE      1
C*                                                                     *RIGHTE      2
C*        Extended Transient-Midterm Stability Program (ETMSP)         *RIGHTE      3
C*        ====================================================         *RIGHTE      4
C*                                                                     *RIGHTE      5
C*       Copyright (C) (1993) Electric Power Research Institute        *RIGHTE      6
C*                                                                     *RIGHTE      7
C* EPRI reserves all rights in the software and associated             *RIGHTE      8
C* documentation as delivered. The software and its associated         *RIGHTE      9
C* documention or any portion thereof may not be reproduced in any form*RIGHTE     10
C* whatsoever without the consent of EPRI, except as explicity provided*RIGHTE     11
C* for by license. Licensee shall submit a detailed description to EPRI*RIGHTE     12
C* of any changes or modifications to the software within two (2)      *RIGHTE     13
C* months after such changes or modifications are made. At EPRI's sole *RIGHTE     14
C* discretion, the software, as changed or modified, shall be given a  *RIGHTE     15
C* new designation sufficiently different from its then current        *RIGHTE     16
C* designation as to prevent mistake,confusion, or deception as between*RIGHTE     17
C* the current software as changed or modified.                        *RIGHTE     18
C*                                                                     *RIGHTE     19
C* A license under EPRI's rights in the software can be obtained       *RIGHTE     20
C* directly from EPRI.                                                 *RIGHTE     21
C*                                                                     *RIGHTE     22
C* This program and supporting materials may be independently available*RIGHTE     23
C* from Electric Power Software centre (EPSC) for an appropriate       *RIGHTE     24
C* distribution fee. The EPSC is a service of                          *RIGHTE     25
C*                                                                     *RIGHTE     26
C*                    Power Computing Company                          *RIGHTE     27
C*                    1930 Hi Line                                     *RIGHTE     28
C*                    Dallas, Tx 75207                                 *RIGHTE     29
C*                                                                     *RIGHTE     30
C* NEITHER EPRI, ANY MEMBER OF EPRI, NOR ANY PERSON OR  ORGANIZATION   *RIGHTE     31
C* ACTING ON BEHAVE OF THEM:                                           *RIGHTE     32
C*                                                                     *RIGHTE     33
C* 1. MAKE ANY WARRANTY OR REPRESENTATION WHATSOEVER, EXPRESS OR       *RIGHTE     34
C*    IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR FITNESS OR *RIGHTE     35
C*    ANY PURPOSE WITH RESPECT TO THE SOFTWARE OR ITS ASSOCIATED       *RIGHTE     36
C*    DOCUMENTATION; OR                                                *RIGHTE     37
C*                                                                     *RIGHTE     38
C* 2. ASSUMES ANY LIABILITY WHATSOEVER WITH RESPECT TO ANY USE OF THE  *RIGHTE     39
C*    SOFTWARE OR ITS ASSOCIATED DOCUMENTATION OR ANY PORTION THEREOF  *RIGHTE     40
C*    OR WITH RESPECT TO ANY DAMAGES WHICH MAY RESULT FROM SUCH USE.   *RIGHTE     41
C*                                                                     *RIGHTE     42
C* THIS NOTICE MAY NOT BE REMOVED FROM THE SOFTWARE BY ANY USER        *RIGHTE     43
C* THEREOF.                                                            *RIGHTE     44
C*                                                                     *RIGHTE     45
C***********************************************************************RIGHTE     46
      SUBROUTINE DEGV20(JSGV)                                           DEGV20      3
CD                                                                      DEGV20      4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TYPE 20 GOVERNOR,   DEGV20      5
CD    USED BY BOTH RUNGE-KUTTA AND TRAPEZOIDAL METHOD.                  DEGV20      6
CD                                                                      DEGV20      7
CD    THE DATA STRUCTURE FOR THIS TYPE OF GOVERNOR IS GIVEN BELOW.      DEGV20      8
CD                                                                      DEGV20      9
CD   9.7 Hydraulic turbine-governor type 20                             DEGV20     10
CD                                                                      DEGV20     11
CD     Governor data                                                    DEGV20     12
CD                                                                      DEGV20     13
CD     DDAT(JGG+ 1)   = KS                                              DEGV20     14
CD     DDAT(JGG+ 2)   = RP                                              DEGV20     15
CD     DDAT(JGG+ 3)   = RT                                              DEGV20     16
CD     DDAT(JGG+ 4)   = TW                                              DEGV20     17
CD     DDAT(JGG+ 5)   = TR                                              DEGV20     18
CD     DDAT(JGG+ 6)   = TG                                              DEGV20     19
CD     DDAT(JGG+ 7)   = PFL                                             DEGV20     20
CD     DDAT(JGG+ 8)   = HEAD                                            DEGV20     21
CD     DDAT(JGG+ 9)   = GFL                                             DEGV20     22
CD     DDAT(JGG+10)   = GNL                                             DEGV20     23
CD     DDAT(JGG+11)   = RMXO                                            DEGV20     24
CD     DDAT(JGG+12)   = RMXC                                            DEGV20     25
CD     DDAT(JGG+13)   = GBF                                             DEGV20     26
CD     DDAT(JGG+14)   = RBFC                                            DEGV20     27
CD     DDAT(JGG+15)   = DB1                                             DEGV20     28
CD                                                                      DEGV20     29
CD     Governor states                                                  DEGV20     30
CD                                                                      DEGV20     31
CD     XSTATE(JPS+1)  = first integrator block      : compulsory        DEGV20     32
CD     XSTATE(JPS+2)  = second integrator block          : compulsory   DEGV20     33
CD     XSTATE(JPS+3)  = TW block                    : compulsory        DEGV20     34
CD     XSTATE(JPS+4)  = TG block                    : compulsory        DEGV20     35
CD                                                                      DEGV20     36
CD     Governor Y-variables                                             DEGV20     37
CD                                                                      DEGV20     38
CD     XLDREF(JYP+1)  = load reference signal                           DEGV20     39
CD                                                                      DEGV20     40
      INCLUDE 'PARX.INS'                                                DEGV20     41
      INCLUDE 'CNB3.INS'                                                DEGV20     42
      INCLUDE 'CNB19.INS'                                               DEGV20     43
      INCLUDE 'CNPARX.INS'                                              DEGV20     44
      INCLUDE 'CNXSTA.INS'                                              DEGV20     45
      INCLUDE 'CNQSTA.INS'                                              DEGV20     46
      INCLUDE 'CNMDAT.INS'                                              DEGV20     47
      INCLUDE 'CNEXC.INS'                                               DEGV20     48
      INCLUDE 'CNPRGV.INS'                                              DEGV20     49
      INCLUDE 'CNMYVA.INS'                                              DEGV20     50
      INCLUDE 'CNYVAR.INS'                                              DEGV20     51
C                                                                       DEGV20     52
C     HYDRO GOVERNOR                                                    DEGV20     53
C                                                                       DEGV20     54
      JSGV=JSTATE                                                       DEGV20     55
C                                                                       DEGV20     56
C     SERVOMOTOR EQUATION                                               DEGV20     57
C                                                                       DEGV20     58
      XSUM=DDAT(JGG+3)*XSTATE(JSTATE+1)-XSTATE(JSTATE+2)/DDAT(JGG+5)    DEGV20     59
      XSUM=-XSUM-XSPU                                                   DEGV20     60
      XSUM=XSUM-DDAT(JGG+2)*(XSTATE(JSTATE+1)-DDAT(JGG+20))             DEGV20     61
      IF (IDDAT(JGG+15).NE.0) THEN                                      DEGV20     62
         DBDX=DDAT(JGG+15)                                              DEGV20     63
         CALL DBAND (XSUM,DBDX,DDAT,JGG,NDAT,15)                        DEGV20     64
      ENDIF                                                             DEGV20     65
      DSTATE(LSTATE+1)=DDAT(JGG+1)*XSUM                                 DEGV20     66
C                                                                       DEGV20     67
C     LIMITS ON GATE RATE                                               DEGV20     68
C                                                                       DEGV20     69
      IF(DSTATE(LSTATE+1).GT.DDAT(JGG+11))THEN                          DEGV20     70
      DSTATE(LSTATE+1)=DDAT(JGG+11)                                     DEGV20     71
      ELSEIF(DSTATE(LSTATE+1).LT.DDAT(JGG+12))THEN                      DEGV20     72
      DSTATE(LSTATE+1)=DDAT(JGG+12)                                     DEGV20     73
      ENDIF                                                             DEGV20     74
      IF (DSTATE(LSTATE+1).GT.0.0.AND.XSTATE(JSTATE+1).GE.1.0) THEN     DEGV20     75
         DSTATE(LSTATE+1)=0.0                                           DEGV20     76
         QSTATE(JSTATE+1)=0.0                                           DEGV20     77
      ELSE IF (DSTATE(LSTATE+1).LT.0.0.AND.XSTATE(JSTATE+1).LE.0.0) THENDEGV20     78
         DSTATE(LSTATE+1)=0.0                                           DEGV20     79
         QSTATE(JSTATE+1)=0.0                                           DEGV20     80
      END IF                                                            DEGV20     81
C                                                                       DEGV20     82
C     BUFFER ZONE                                                       DEGV20     83
C                                                                       DEGV20     84
      IF (XSTATE(JSTATE+1).LT.DDAT(JGG+13))THEN                         DEGV20     85
      IF(DSTATE(LSTATE+1).LT.DDAT(JGG+14)) DSTATE(LSTATE+1)=DDAT(JGG+14)DEGV20     86
      ENDIF                                                             DEGV20     87
C                                                                       DEGV20     88
C     GOVERNOR EQUATION                                                 DEGV20     89
C                                                                       DEGV20     90
      DSTATE(LSTATE+2)=XSTATE(JSTATE+1)*DDAT(JGG+3)-XSTATE(JSTATE+2)    DEGV20     91
     +/DDAT(JGG+5)                                                      DEGV20     92
C                                                                       DEGV20     93
C     IDEAL GATE EQUATION                                               DEGV20     94
C                                                                       DEGV20     95
      IF (IDDAT(JGG+6).NE.0) THEN                                       DEGV20     96
         DSTATE(LSTATE+4)=(XSTATE(JSTATE+1)*DDAT(JGG+18)-               DEGV20     97
     +   XSTATE(JSTATE+4))/DDAT(JGG+6)                                  DEGV20     98
      ELSE                                                              DEGV20     99
         DSTATE(LSTATE+4)=0.0                                           DEGV20    100
         XSTATE(JSTATE+4)=XSTATE(JSTATE+1)*DDAT(JGG+18)                 DEGV20    101
      ENDIF                                                             DEGV20    102
C                                                                       DEGV20    103
C     WATER COLUMN EQUATION                                             DEGV20    104
C                                                                       DEGV20    105
      UDG=XSTATE(JSTATE+3)/XSTATE(JSTATE+4)                             DEGV20    106
      UDG=UDG*UDG                                                       DEGV20    107
      DSTATE(LSTATE+3)=(DDAT(JGG+8)-UDG)/DDAT(JGG+4)                    DEGV20    108
C                                                                       DEGV20    109
      LSTATE=LSTATE+4                                                   DEGV20    110
C                                                                       DEGV20    111
      RETURN                                                            DEGV20    112
C                                                                       DEGV20    113
      END                                                               DEGV20    114
