CFPRIME DEGV04                                                          DEGV04      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 DEGV04(JSGV)                                           DEGV04      3
CD                                                                      DEGV04      4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TYPE 4 GOVERNOR,    DEGV04      5
CD    USED BY BOTH RUNGE-KUTTA AND TRAPEZOIDAL METHOD.                  DEGV04      6
CD                                                                      DEGV04      7
CD    THE DATA STRUCTURE FOR THIS TYPE OF GOVERNOR IS GIVEN BELOW.      DEGV04      8
CD                                                                      DEGV04      9
CD   9.3 Prime-mover turbine-governor model types 4 and 5               DEGV04     10
CD                                                                      DEGV04     11
CD     Governor data                                                    DEGV04     12
CD                                                                      DEGV04     13
CD     DDAT(JGG+ 1)   = K1                                              DEGV04     14
CD     DDAT(JGG+ 2)   = T1                                              DEGV04     15
CD     DDAT(JGG+ 3)   = T2                                              DEGV04     16
CD     DDAT(JGG+ 4)   = T3                                              DEGV04     17
CD     DDAT(JGG+ 5)   = RMAX                                            DEGV04     18
CD     DDAT(JGG+ 6)   = RMIN                                            DEGV04     19
CD     DDAT(JGG+ 7)   = PMAX                                            DEGV04     20
CD     DDAT(JGG+ 8)   = (reserved for future use)                       DEGV04     21
CD     DDAT(JGG+ 9)   = T4                                              DEGV04     22
CD     DDAT(JGG+10)   = T5                                              DEGV04     23
CD     DDAT(JGG+11)   = T6                                              DEGV04     24
CD     DDAT(JGG+12)   = T7                                              DEGV04     25
CD     DDAT(JGG+13)   = K2                                              DEGV04     26
CD     DDAT(JGG+14)   = K3                                              DEGV04     27
CD     DDAT(JGG+15)   = K4                                              DEGV04     28
CD     DDAT(JGG+16)   = (reserved for future use)                       DEGV04     29
CD     DDAT(JGGP1+ 1) = K6                                              DEGV04     30
CD     DDAT(JGGP1+ 2) = K7                                              DEGV04     31
CD     DDAT(JGGP1+ 3) = K8                                              DEGV04     32
CD                                                                      DEGV04     33
CD     Governor states                                                  DEGV04     34
CD                                                                      DEGV04     35
CD     XSTATE(JPS+ 1) = T1 block                    : compulsory        DEGV04     36
CD     XSTATE(JPS+ 2) = integrator block            : compulsory        DEGV04     37
CD     XSTATE(JPS+ 3) = T4 block                    : compulsory        DEGV04     38
CD     XSTATE(JPS+ 4) = T5 block                    : compulsory        DEGV04     39
CD     XSTATE(JPS+ 5) = T6 block                    : compulsory        DEGV04     40
CD     XSTATE(JPS+ 6) = T7 block                    : compulsory        DEGV04     41
CD     XSTATE(JPS+ 7) = (reserved for future use)                       DEGV04     42
CD                                                                      DEGV04     43
CD     Governor Y-variables                                             DEGV04     44
CD                                                                      DEGV04     45
CD     XLDREF(JYP+ 1) = load reference signal                           DEGV04     46
CD     CVP(JYP+2)     = governor output for turbine control             DEGV04     47
CD     BLRPR(JYP+3)   = boiler pressure output                          DEGV04     48
CD     PDEM(JYP+4)    = power demand from AGC control                   DEGV04     49
CD     PSET(JYP+5)    = set point for boiler pressure control           DEGV04     50
CD                                                                      DEGV04     51
      INCLUDE 'PARX.INS'                                                DEGV04     52
      INCLUDE 'CNB3.INS'                                                DEGV04     53
      INCLUDE 'CNB8.INS'                                                DEGV04     54
      INCLUDE 'CNB10.INS'                                               DEGV04     55
      INCLUDE 'CNB19.INS'                                               DEGV04     56
      INCLUDE 'CNPARX.INS'                                              DEGV04     57
      INCLUDE 'CNXSTA.INS'                                              DEGV04     58
      INCLUDE 'CNQSTA.INS'                                              DEGV04     59
      INCLUDE 'CNMDAT.INS'                                              DEGV04     60
      INCLUDE 'CNEXC.INS'                                               DEGV04     61
C                                                                       DEGV04     62
      INCLUDE 'CNPRGV.INS'                                              DEGV04     63
      INCLUDE 'CNMYVA.INS'                                              DEGV04     64
      INCLUDE 'CNYVAR.INS'                                              DEGV04     65
C                                                                       DEGV04     66
C                                                                       DEGV04     67
      JSGV=JSTATE                                                       DEGV04     68
      IGSTAN=ICONTA(10,N)                                               DEGV04     69
      IF (IGSTAN.NE.0) JYPS=MYVAR(6,N)                                  DEGV04     70
      PDGN=PDG(JYG+2)                                                   DEGV04     71
C                                                                       DEGV04     72
      IF (IGVN.EQ.5.OR.IGVN.EQ.35) RETURN                               DEGV04     73
C                                                                       DEGV04     74
C     TYPE 4                                                            DEGV04     75
C                                                                       DEGV04     76
C      IF (IGV(ICO+14).EQ.5) PDGN=PDGN+PDG(1,N+1)                       DEGV04     77
      IF (ICONTA(2,N+1).EQ.5.OR.ICONTA(2,N+1).EQ.35) THEN               DEGV04     78
         JYGNP1=MYVAR(1,N+1)                                            DEGV04     79
         PDGN=PDGN+PDG(JYGNP1+2)                                        DEGV04     80
      ENDIF                                                             DEGV04     81
      NDV=6                                                             DEGV04     82
      IF(IDDAT(JGG+2).NE.0)THEN                                         DEGV04     83
      DSTATE(LSTATE+1)=(DDAT(JGG+1)*XSPU-XSTATE(JSTATE+1))/DDAT(JGG+2)  DEGV04     84
      XSG1=XSTATE(JSTATE+1)+DDAT(JGG+3)*DSTATE(LSTATE+1)                DEGV04     85
      ELSE                                                              DEGV04     86
      DSTATE(LSTATE+1)=0.0                                              DEGV04     87
      XSG1=DDAT(JGG+1)*XSPU                                             DEGV04     88
      XSTATE(JSTATE+1)=XSG1                                             DEGV04     89
      ENDIF                                                             DEGV04     90
C                                                                       DEGV04     91
      XSUM=XLDREF(JYP+1)-XSG1-XSTATE(JSTATE+2)                          DEGV04     92
C                                                                       DEGV04     93
      IF(IGSTAN.EQ.1) XSUM=XSUM+GSS(JYPS+1)                             DEGV04     94
      IF(IDDAT(JGG+4).NE.0)XSUM=XSUM/DDAT(JGG+4)                        DEGV04     95
      IF(XSUM.GT.DDAT(JGG+5))THEN                                       DEGV04     96
      XSUM=DDAT(JGG+5)                                                  DEGV04     97
      ELSEIF(XSUM.LT.DDAT(JGG+6))THEN                                   DEGV04     98
      XSUM=DDAT(JGG+6)                                                  DEGV04     99
      ENDIF                                                             DEGV04    100
      DSTATE(LSTATE+2)=XSUM                                             DEGV04    101
      PGV=XSTATE(JSTATE+2)                                              DEGV04    102
      IF (PGV.GE.1.0) THEN                                              DEGV04    103
         PGV=1.0                                                        DEGV04    104
         IF (DSTATE(LSTATE+2).GT.0.0) THEN                              DEGV04    105
            DSTATE(LSTATE+2)=0.0                                        DEGV04    106
            QSTATE(JSTATE+2)=0.0                                        DEGV04    107
         END IF                                                         DEGV04    108
      ELSE IF (PGV.LE.0.0) THEN                                         DEGV04    109
         PGV=0.0                                                        DEGV04    110
         IF (DSTATE(LSTATE+2).LT.0.0) THEN                              DEGV04    111
            DSTATE(LSTATE+2)=0.0                                        DEGV04    112
            QSTATE(JSTATE+2)=0.0                                        DEGV04    113
         END IF                                                         DEGV04    114
      END IF                                                            DEGV04    115
      IF (IDDAT(JGG+9).NE.0)THEN                                        DEGV04    116
      DSTATE(LSTATE+3)=(PGV-XSTATE(JSTATE+3))/DDAT(JGG+9)               DEGV04    117
      ELSE                                                              DEGV04    118
      DSTATE(LSTATE+3)=0.0                                              DEGV04    119
      XSTATE(JSTATE+3)=PGV                                              DEGV04    120
      ENDIF                                                             DEGV04    121
      IF (IDDAT(JGG+10).NE.0)THEN                                       DEGV04    122
      DSTATE(LSTATE+4)=(XSTATE(JSTATE+3)-XSTATE(JSTATE+4))/DDAT(JGG+10) DEGV04    123
      ELSE                                                              DEGV04    124
      DSTATE(LSTATE+4)=0.0                                              DEGV04    125
      XSTATE(JSTATE+4)=XSTATE(JSTATE+3)                                 DEGV04    126
      ENDIF                                                             DEGV04    127
      IF(IDDAT(JGG+11).NE.0)THEN                                        DEGV04    128
      DSTATE(LSTATE+5)=(XSTATE(JSTATE+4)-XSTATE(JSTATE+5))/DDAT(JGG+11) DEGV04    129
      ELSE                                                              DEGV04    130
      DSTATE(LSTATE+5)=0.0                                              DEGV04    131
      XSTATE(JSTATE+5)=XSTATE(JSTATE+4)                                 DEGV04    132
      ENDIF                                                             DEGV04    133
      IF (IDDAT(JGG+12).NE.0)THEN                                       DEGV04    134
      DSTATE(LSTATE+6)=(XSTATE(JSTATE+5)-XSTATE(JSTATE+6))/DDAT(JGG+12) DEGV04    135
      ELSE                                                              DEGV04    136
      DSTATE(LSTATE+6)=0.0                                              DEGV04    137
      XSTATE(JSTATE+6)=XSTATE(JSTATE+5)                                 DEGV04    138
C                                                                       DEGV04    139
      NDV=5                                                             DEGV04    140
C                                                                       DEGV04    141
      ENDIF                                                             DEGV04    142
C                                                                       DEGV04    143
      IGVN5 = ICONTA(2,N+1)                                             DEGV04    144
      IF (IGVN5 .EQ.5.OR.IGVN5.EQ.35) THEN                              DEGV04    145
        JGV5=JCONTA(2,N+1)                                              DEGV04    146
        IDDAT(JGV5)=JSTATE+2                                            DEGV04    147
      END IF                                                            DEGV04    148
C                                                                       DEGV04    149
C  GOVERNOR STABILIZER                                                  DEGV04    150
C                                                                       DEGV04    151
      IF(IGSTAN.NE.0)THEN                                               DEGV04    152
      XSUM=DDAT(JGS+1)*XSTATE(IDOMG)+PDGN*DDAT(JGS+2)+DDAT(JGS+3)*      DEGV04    153
     $CVP(JYP+2)                                                        DEGV04    154
      NDVS=7                                                            DEGV04    155
      DSTATE(LSTATE+7)=XSUM-XSTATE(JSTATE+7)*DDAT(JGS+4)                DEGV04    156
      GSS(JYPS+1)=DSTATE(LSTATE+7)                                      DEGV04    157
      IF(GSS(JYPS+1).GT.DDAT(JGS+5))THEN                                DEGV04    158
      GSS(JYPS+1)=DDAT(JGS+5)                                           DEGV04    159
      ELSEIF(GSS(JYPS+1).LT.DDAT(JGS+6))THEN                            DEGV04    160
      GSS(JYPS+1)=DDAT(JGS+6)                                           DEGV04    161
      ENDIF                                                             DEGV04    162
      ENDIF                                                             DEGV04    163
C                                                                       DEGV04    164
      LSTATE=LSTATE+7                                                   DEGV04    165
C                                                                       DEGV04    166
740   CONTINUE                                                          DEGV04    167
      RETURN                                                            DEGV04    168
C                                                                       DEGV04    169
      END                                                               DEGV04    170
