CFPRIME DSTA12                                                          DSTA12      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 DSTA12(NXS)                                            DSTA12      3
CD                                                                      DSTA12      4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TYPE 12 STABILIZER, DSTA12      5
CD    USED BY BOTH RUNGE-KUTTA AND TRAPEZOIDAL METHOD.                  DSTA12      6
CD                                                                      DSTA12      7
CD    THE DATA STRUCTURE OF THEI TYPE OF STABILIZER IS GIVEN BELOW.     DSTA12      8
CD                                                                      DSTA12      9
CD   4.11 Stabilizer type 12                                            DSTA12     10
CD                                                                      DSTA12     11
CD     Stabilizer data                                                  DSTA12     12
CD                                                                      DSTA12     13
CD     IDDAT(JS+ 1)   = BUSR1        : sensing bus number for signal #1 DSTA12     14
CD     IDDAT(JS+ 2)   = TYPE1        : type of input for signal #1:     DSTA12     15
CD                                     = 1 rotor speed                  DSTA12     16
CD                                     = 2 acceleration power           DSTA12     17
CD                                     = 3 bus frequency                DSTA12     18
CD                                     = 4 electrical power             DSTA12     19
CD                                     = 5 bus voltage magnitude        DSTA12     20
CD                                     = 6 voltage deviation from steadyDSTA12     21
CD                                        state value                   DSTA12     22
CD     IDDAT(JS+3)    = BUSR2        : sensing bus number for input #2  DSTA12     23
CD     IDDAT(JS+4)    = TYPE2        : type of input for signal #2:     DSTA12     24
CD                                     = 1 rotor speed                  DSTA12     25
CD                                     = 2 acceleration power           DSTA12     26
CD                                     = 3 bus frequency                DSTA12     27
CD                                     = 4 electrical power             DSTA12     28
CD                                     = 5 bus voltage magnitude        DSTA12     29
CD                                     = 6 voltage deviation from steadyDSTA12     30
CD                                        state value                   DSTA12     31
CD     DDAT(JS+ 5)    = K1                                              DSTA12     32
CD     DDAT(JS+ 6)    = T1                                              DSTA12     33
CD     DDAT(JS+ 7)    = K2                                              DSTA12     34
CD     DDAT(JS+ 8)    = T2                                              DSTA12     35
CD     DDAT(JS+ 9)    = T'Q0                                            DSTA12     36
CD     DDAT(JS+10)    = TQ0                                             DSTA12     37
CD     DDAT(JS+11)    = T'Q1                                            DSTA12     38
CD     DDAT(JS+12)    = TQ1                                             DSTA12     39
CD     DDAT(JS+13)    = T'Q2                                            DSTA12     40
CD     DDAT(JS+14)    = TQ2                                             DSTA12     41
CD     DDAT(JS+15)    = T'Q3                                            DSTA12     42
CD     DDAT(JS+16)    = TQ3                                             DSTA12     43
CD     DDAT(JS+17)    = VSMAX                                           DSTA12     44
CD     DDAT(JS+18)    = VSMIN                                           DSTA12     45
CD     DDAT(JS+19)    = TF                                              DSTA12     46
CD     DDAT(JS+20)    = RC                                              DSTA12     47
CD     DDAT(JS+21)    = XC                                              DSTA12     48
CD     DDAT(JS+22)    = VCU                                             DSTA12     49
CD     DDAT(JS+23)    = VCL                                             DSTA12     50
CD     DDAT(JS+24)    = PTHR                                            DSTA12     51
CD                                                                      DSTA12     52
CD     Stabilizer states                                                DSTA12     53
CD                                                                      DSTA12     54
CD     XSTATE(JSS+1)  = TF block if input is bus frequency              DSTA12     55
CD                                                  : optional          DSTA12     56
CD     XSTATE(JSS+2)  = T1 block                    : optional          DSTA12     57
CD     XSTATE(JSS+3)  = T2 block                    : optional          DSTA12     58
CD     XSTATE(JSS+4)  = TQ0 block                   : optional          DSTA12     59
CD     XSTATE(JSS+5)  = TQ1 block                   : optional          DSTA12     60
CD     XSTATE(JSS+6)  = TQ2 block                   : optional          DSTA12     61
CD     XSTATE(JSS+7)  = TQ3 block                   : optional          DSTA12     62
CD                                                                      DSTA12     63
CD     Stabilizer Y-variables                                           DSTA12     64
CD                                                                      DSTA12     65
CD     VSS(JYS+1)     = stabilizer output                               DSTA12     66
CD                                                                      DSTA12     67
      INCLUDE 'PARX.INS'                                                DSTA12     68
      INCLUDE 'CNMDAT.INS'                                              DSTA12     69
      INCLUDE 'CNEXC.INS'                                               DSTA12     70
      INCLUDE 'CNXSTA.INS'                                              DSTA12     71
      INCLUDE 'CNYVAR.INS'                                              DSTA12     72
      INCLUDE 'CNFLAG.INS'                                              DSTA12     73
      INCLUDE 'CNPARX.INS'                                              DSTA12     74
      INCLUDE 'CNUNIT.INS'                                              DSTA12     75
C                                                                       DSTA12     76
*IF DEBUG                                                               DSTA12     77
         LDEB=(JDEB(51).NE.0)                                           DSTA12     78
*ENDIF                                                                  DSTA12     79
C                                                                       DSTA12     80
      NXS=KSTATE                                                        DSTA12     81
C                                                                       DSTA12     82
C   TYPE 12 STABILIZER (PTI MODEL)                                      DSTA12     83
C                                                                       DSTA12     84
*IF DEBUG                                                               DSTA12     85
           IF(LDEB)WRITE(IUD6,1220)N,LSTATE,JSTATE,VSI1                 DSTA12     86
*ENDIF                                                                  DSTA12     87
        VSI1=VSI1*DDAT(JS+5)                                            DSTA12     88
C-  FIRST INPUT BLOCK                                                   DSTA12     89
        IF(IDDAT(JS+6).NE.0)THEN                                        DSTA12     90
           KSTATE=KSTATE+1                                              DSTA12     91
           DSTATE(LSTATE+KSTATE)=(VSI1-XSTATE(JSTATE+KSTATE))           DSTA12     92
     +     /DDAT(JS+6)                                                  DSTA12     93
           VSI1=XSTATE(JSTATE+KSTATE)                                   DSTA12     94
        ENDIF                                                           DSTA12     95
C-  SECOND INPUT BLOCK                                                  DSTA12     96
        VSI2=VSI2*DDAT(JS+7)                                            DSTA12     97
        IF(IDDAT(JS+8).NE.0)THEN                                        DSTA12     98
           KSTATE=KSTATE+1                                              DSTA12     99
           DSTATE(LSTATE+KSTATE)=(VSI2-XSTATE(JSTATE+KSTATE))           DSTA12    100
     +     /DDAT(JS+8)                                                  DSTA12    101
           VSI2=XSTATE(JSTATE+KSTATE)                                   DSTA12    102
        ENDIF                                                           DSTA12    103
C-  SUMMING JUNCTION                                                    DSTA12    104
        VSX=VSI1+VSI2                                                   DSTA12    105
*IF DEBUG                                                               DSTA12    106
          IF(LDEB)WRITE(IUD6,1230)VSI1,VSI2,VSX                         DSTA12    107
*ENDIF                                                                  DSTA12    108
C-  TQ0 - TQ1 - TQ2 - TQ3 BRANCH                                        DSTA12    109
C   TQ0 BLOCK                                                           DSTA12    110
        IF(IDDAT(JS+10).NE.0)THEN                                       DSTA12    111
           KSTATE=KSTATE+1                                              DSTA12    112
           DSTATE(LSTATE+KSTATE)=(VSX-XSTATE(JSTATE+KSTATE))/DDAT(JS+10)DSTA12    113
           IF(IDDAT(JS+9).NE.0)THEN                                     DSTA12    114
              VSX=DDAT(JS+9)*DSTATE(LSTATE+KSTATE)                      DSTA12    115
           ELSE                                                         DSTA12    116
              VSX=XSTATE(JSTATE+KSTATE)                                 DSTA12    117
           ENDIF                                                        DSTA12    118
*IF DEBUG                                                               DSTA12    119
           IF(LDEB)WRITE(IUD6,1240)VSX                                  DSTA12    120
*ENDIF                                                                  DSTA12    121
        ENDIF                                                           DSTA12    122
C   TQ1 BLOCK                                                           DSTA12    123
        IF(IDDAT(JS+12).NE.0)THEN                                       DSTA12    124
           KSTATE=KSTATE+1                                              DSTA12    125
           DSTATE(LSTATE+KSTATE)=(VSX-XSTATE(JSTATE+KSTATE))/DDAT(JS+12)DSTA12    126
           VSX=XSTATE(JSTATE+KSTATE)+DDAT(JS+11)*DSTATE(LSTATE+KSTATE)  DSTA12    127
*IF DEBUG                                                               DSTA12    128
           IF(LDEB)WRITE(IUD6,1250)VSX                                  DSTA12    129
*ENDIF                                                                  DSTA12    130
        ENDIF                                                           DSTA12    131
C   TQ2 BLOCK                                                           DSTA12    132
        IF(IDDAT(JS+14).NE.0)THEN                                       DSTA12    133
           KSTATE=KSTATE+1                                              DSTA12    134
           DSTATE(LSTATE+KSTATE)=(VSX-XSTATE(JSTATE+KSTATE))/DDAT(JS+14)DSTA12    135
           VSX=XSTATE(JSTATE+KSTATE)+DDAT(JS+13)*DSTATE(LSTATE+KSTATE)  DSTA12    136
*IF DEBUG                                                               DSTA12    137
           IF(LDEB)WRITE(IUD6,1260)VSX                                  DSTA12    138
*ENDIF                                                                  DSTA12    139
        ENDIF                                                           DSTA12    140
C   TQ3 BLOCK                                                           DSTA12    141
        IF(IDDAT(JS+16).NE.0)THEN                                       DSTA12    142
           KSTATE=KSTATE+1                                              DSTA12    143
           DSTATE(LSTATE+KSTATE)=(VSX-XSTATE(JSTATE+KSTATE))/DDAT(JS+16)DSTA12    144
           VSX=XSTATE(JSTATE+KSTATE)+DDAT(JS+15)*DSTATE(LSTATE+KSTATE)  DSTA12    145
*IF DEBUG                                                               DSTA12    146
           IF(LDEB)WRITE(IUD6,1270)VSX                                  DSTA12    147
*ENDIF                                                                  DSTA12    148
        ENDIF                                                           DSTA12    149
C-  LIMITER                                                             DSTA12    150
        IF(VSX.GT.DDAT(JS+17)) VSX=DDAT(JS+17)                          DSTA12    151
        IF(VSX.LT.DDAT(JS+18)) VSX=DDAT(JS+18)                          DSTA12    152
C-  OUTPUT CONTROL SWITCH                                               DSTA12    153
        IF (VREG(JYE+1).GT.DDAT(JS+22).OR.                              DSTA12    154
     *     VREG(JYE+1).LT.DDAT(JS+23)) THEN                             DSTA12    155
           VSX=0.0                                                      DSTA12    156
           IDDAT(JS+31)=0                                               DSTA12    157
        ELSE                                                            DSTA12    158
           IDDAT(JS+31)=1                                               DSTA12    159
        END IF                                                          DSTA12    160
C                                                                       DSTA12    161
        VSS(JYS+1)=VSX                                                  DSTA12    162
        NXS=KSTATE                                                      DSTA12    163
*IF DEBUG                                                               DSTA12    164
        IF(LDEB)THEN                                                    DSTA12    165
            WRITE(IUD6,1130)N,(DSTATE(LSTATE+KKK),KKK=1,KSTATE)         DSTA12    166
            WRITE(IUD6,1140)N,JYS,VSX,(XSTATE(JSTATE+KKK),KKK=1,KSTATE) DSTA12    167
        ENDIF                                                           DSTA12    168
*ENDIF                                                                  DSTA12    169
C                                                                       DSTA12    170
      LSTATE=LSTATE+NXS                                                 DSTA12    171
      JSTATE=JSTATE+NXS                                                 DSTA12    172
C                                                                       DSTA12    173
*IF DEBUG                                                               DSTA12    174
      IF(LDEB)WRITE(IUD6,1100) JS,LSTATE,(IDDAT(JS+LK),LK=1,2)          DSTA12    175
     &,(DDAT(JS+LK),LK=3,17)                                            DSTA12    176
*ENDIF                                                                  DSTA12    177
C                                                                       DSTA12    178
      RETURN                                                            DSTA12    179
C                                                                       DSTA12    180
 1100 FORMAT(1X,'DB-DSTAB:JS,LSTATE,DDAT(1:17) ',2I5,2X,2I5,/,          DSTA12    181
     & (8X,10G12.5))                                                    DSTA12    182
 1130 FORMAT(' DSTATE ',I10,6F15.9)                                     DSTA12    183
 1140 FORMAT(' XSTATE ',2I10,6F15.9)                                    DSTA12    184
 1220 FORMAT(' N,LSTATE,JSTATE AND INPUT TO THE STABILIZER ',           DSTA12    185
     &3I10,F15.9)                                                       DSTA12    186
 1230 FORMAT(' SUMMING JUNCTION SIGNALS VSI1,VSI2,VSX ',                DSTA12    187
     &3F15.9)                                                           DSTA12    188
 1240 FORMAT(' OUTPUT SIGNAL FOR THE TQ BLOCK ',F15.9)                  DSTA12    189
 1250 FORMAT(' OUTPUT SIGNAL FOR THE TQ1 BLOCK ',F15.9)                 DSTA12    190
 1260 FORMAT(' OUTPUT SIGNAL FOR THE TQ2 BLOCK ',F15.9)                 DSTA12    191
 1270 FORMAT(' OUTPUT SIGNAL FOR THE TQ3 BLOCK ',F15.9)                 DSTA12    192
C                                                                       DSTA12    193
      END                                                               DSTA12    194
