CFPRIME DEGV21                                                          DEGV21      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 DEGV21(JSGV)                                           DEGV21      3
CD                                                                      DEGV21      4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TYPE 21 GOVERNOR,   DEGV21      5
CD    USED BY BOTH RUNGE-KUTTA AND TRAPEZOIDAL METHOD.                  DEGV21      6
CD                                                                      DEGV21      7
CD    THE DATA STRUCTURE FOR THIS TYPE OF GOVERNOR IS GIVEN BELOW.      DEGV21      8
CD                                                                      DEGV21      9
CD   9.8 Hydraulic turbine-governor type 21                             DEGV21     10
CD                                                                      DEGV21     11
CD     Governor data                                                    DEGV21     12
CD                                                                      DEGV21     13
CD     DDAT(JGG+ 1)   = PMAX                                            DEGV21     14
CD     DDAT(JGG+ 2)   = R                                               DEGV21     15
CD     DDAT(JGG+ 3)   = TG                                              DEGV21     16
CD     DDAT(JGG+ 4)   = TP                                              DEGV21     17
CD     DDAT(JGG+ 5)   = TD                                              DEGV21     18
CD     DDAT(JGG+ 6)   = DD                                              DEGV21     19
CD     DDAT(JGG+ 7)   = GMAX                                            DEGV21     20
CD     DDAT(JGG+ 8)   = GMIN                                            DEGV21     21
CD     DDAT(JGG+ 9)   = TW                                              DEGV21     22
CD     DDAT(JGG+10)   = VELO                                            DEGV21     23
CD     DDAT(JGG+11)   = VELC                                            DEGV21     24
CD                                                                      DEGV21     25
CD     Governor states                                                  DEGV21     26
CD                                                                      DEGV21     27
CD     XSTATE(JPS+1)  = TP block                    : compulsory        DEGV21     28
CD     XSTATE(JPS+2)  = integrator block            : compulsory        DEGV21     29
CD     XSTATE(JPS+3)  = TD block                    : compulsory        DEGV21     30
CD     XSTATE(JPS+4)  = TW block                    : compulsory        DEGV21     31
CD                                                                      DEGV21     32
CD     Governor Y-variables                                             DEGV21     33
CD                                                                      DEGV21     34
CD     XLDREF(JYP+1)  = load reference signal                           DEGV21     35
CD                                                                      DEGV21     36
      INCLUDE 'PARX.INS'                                                DEGV21     37
      INCLUDE 'CNB3.INS'                                                DEGV21     38
      INCLUDE 'CNB19.INS'                                               DEGV21     39
      INCLUDE 'CNPARX.INS'                                              DEGV21     40
      INCLUDE 'CNXSTA.INS'                                              DEGV21     41
      INCLUDE 'CNQSTA.INS'                                              DEGV21     42
      INCLUDE 'CNMDAT.INS'                                              DEGV21     43
      INCLUDE 'CNEXC.INS'                                               DEGV21     44
C                                                                       DEGV21     45
      INCLUDE 'CNPRGV.INS'                                              DEGV21     46
      INCLUDE 'CNMYVA.INS'                                              DEGV21     47
      INCLUDE 'CNYVAR.INS'                                              DEGV21     48
C                                                                       DEGV21     49
C  HYDRO GOVERNOR                                                       DEGV21     50
C                                                                       DEGV21     51
      JSGV=JSTATE                                                       DEGV21     52
C                                                                       DEGV21     53
C  FEEDBACK BLOCK                                                       DEGV21     54
C                                                                       DEGV21     55
      DSTATE(LSTATE+3)=XSTATE(JSTATE+2)-XSTATE(JSTATE+3)/DDAT(JGG+5)    DEGV21     56
C                                                                       DEGV21     57
      XSUM=XLDREF(JYP+1)-XSPU-XSTATE(JSTATE+2)*DDAT(JGG+2)-             DEGV21     58
     +DSTATE(LSTATE+3)*DDAT(JGG+6)                                      DEGV21     59
      XSUM=XSUM/DDAT(JGG+3)                                             DEGV21     60
C                                                                       DEGV21     61
C  PILOT VALVE                                                          DEGV21     62
C                                                                       DEGV21     63
      IF (IDDAT(JGG+4).NE.0) THEN                                       DEGV21     64
         DSTATE(LSTATE+1)=(XSUM-XSTATE(JSTATE+1))/DDAT(JGG+4)           DEGV21     65
      ELSE                                                              DEGV21     66
         DSTATE(LSTATE+1)=0.0                                           DEGV21     67
         XSTATE(JSTATE+1)=XSUM                                          DEGV21     68
      ENDIF                                                             DEGV21     69
C                                                                       DEGV21     70
      IF (XSTATE(JSTATE+1).GE.DDAT(JGG+10)) THEN                        DEGV21     71
         XSTATE(JSTATE+1)=DDAT(JGG+10)                                  DEGV21     72
         IF (DSTATE(LSTATE+1).GT.0.0) THEN                              DEGV21     73
            DSTATE(LSTATE+1)=0.0                                        DEGV21     74
            QSTATE(JSTATE+1)=0.0                                        DEGV21     75
         END IF                                                         DEGV21     76
      ELSE IF (XSTATE(JSTATE+1).LE.DDAT(JGG+11)) THEN                   DEGV21     77
         XSTATE(JSTATE+1)=DDAT(JGG+11)                                  DEGV21     78
         IF (DSTATE(LSTATE+1).LT.0.0) THEN                              DEGV21     79
            DSTATE(LSTATE+1)=0.0                                        DEGV21     80
            QSTATE(JSTATE+1)=0.0                                        DEGV21     81
         END IF                                                         DEGV21     82
      END IF                                                            DEGV21     83
C                                                                       DEGV21     84
C  GATE SERVO                                                           DEGV21     85
C                                                                       DEGV21     86
      DSTATE(LSTATE+2)=XSTATE(JSTATE+1)                                 DEGV21     87
C                                                                       DEGV21     88
      IF (XSTATE(JSTATE+2).GE.DDAT(JGG+7)) THEN                         DEGV21     89
         XSTATE(JSTATE+2)=DDAT(JGG+7)                                   DEGV21     90
         IF (DSTATE(LSTATE+2).GT.0.0) THEN                              DEGV21     91
            DSTATE(LSTATE+2)=0.0                                        DEGV21     92
            QSTATE(JSTATE+2)=0.0                                        DEGV21     93
         END IF                                                         DEGV21     94
      ELSE IF (XSTATE(JSTATE+2).LE.DDAT(JGG+8)) THEN                    DEGV21     95
         XSTATE(JSTATE+2)=DDAT(JGG+8)                                   DEGV21     96
         IF (DSTATE(LSTATE+2).LT.0.0) THEN                              DEGV21     97
            DSTATE(LSTATE+2)=0.0                                        DEGV21     98
            QSTATE(JSTATE+2)=0.0                                        DEGV21     99
         END IF                                                         DEGV21    100
      END IF                                                            DEGV21    101
C                                                                       DEGV21    102
C  TURBINE                                                              DEGV21    103
C                                                                       DEGV21    104
      DSTATE(LSTATE+4)=(XSTATE(JSTATE+2)-DSTATE(LSTATE+2)*DDAT(JGG+9)   DEGV21    105
     +-XSTATE(JSTATE+4))*2.0/DDAT(JGG+9)                                DEGV21    106
C                                                                       DEGV21    107
C                                                                       DEGV21    108
      LSTATE=LSTATE+4                                                   DEGV21    109
C                                                                       DEGV21    110
      RETURN                                                            DEGV21    111
C                                                                       DEGV21    112
      END                                                               DEGV21    113
