CFPRIME DE7N8                                                           DE7N8       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 DE7N8(VR1,VIM1)                                        DE7N8       3
CD                                                                      DE7N8       4
CD    TO CALCULATE THE DERIVATIVES OF THE STATES OF TYPES 7 AND 8       DE7N8       5
CD    EXCITER, USED BY BOTH RUNGE-KUTTA AND TRAPEZOIDAL METHOD.         DE7N8       6
CD                                                                      DE7N8       7
CD    THE DATA STRUCTURES FOR THESE TYPESOF EXCITERS ARE GIVEN BELOW.   DE7N8       8
CD                                                                      DE7N8       9
CD   3.6 Exciter type 7                                                 DE7N8      10
CD                                                                      DE7N8      11
CD     Exciter data                                                     DE7N8      12
CD                                                                      DE7N8      13
CD     IDDAT(JE+ 1)   = IVTN         : sensing bus number               DE7N8      14
CD     DDAT(JE+ 2)    = KA                                              DE7N8      15
CD     DDAT(JE+ 3)    = TA                                              DE7N8      16
CD     DDAT(JE+ 4)    = KE                                              DE7N8      17
CD     DDAT(JE+ 5)    = TE                                              DE7N8      18
CD     DDAT(JE+ 6)    = LVI                                             DE7N8      19
CD     DDAT(JE+ 7)    = (reserved for future use)                       DE7N8      20
CD     DDAT(JE+ 8)    = (reserved for future use)                       DE7N8      21
CD     DDAT(JE+ 9)    = KC                                              DE7N8      22
CD     DDAT(JE+10)    = KF                                              DE7N8      23
CD     DDAT(JE+11)    = TF                                              DE7N8      24
CD     DDAT(JE+12)    = TC                                              DE7N8      25
CD     DDAT(JE+13)    = TB                                              DE7N8      26
CD     DDAT(JE+14)    = (reserved for future use)                       DE7N8      27
CD     DDAT(JE+15)    = VRMAX                                           DE7N8      28
CD     DDAT(JE+16)    = VRMIN                                           DE7N8      29
CD     DDAT(JE+17)    = EFDMAX                                          DE7N8      30
CD     DDAT(JE+18)    = TR                                              DE7N8      31
CD     DDAT(JE+19)    = RC                                              DE7N8      32
CD     DDAT(JE+20)    = XC                                              DE7N8      33
CD     DDAT(JE+21)    = KP                                              DE7N8      34
CD     DDAT(JE+22)    = KI                                              DE7N8      35
CD                                                                      DE7N8      36
CD     Exciter states                                                   DE7N8      37
CD                                                                      DE7N8      38
CD     XSTATE(JES+1)  = TR block     : compulsory                       DE7N8      39
CD     XSTATE(JES+2)  = TF block     : compulsory                       DE7N8      40
CD     XSTATE(JES+3)  = TB block     : compulsory                       DE7N8      41
CD     XSTATE(JES+4)  = TA block     : compulsory                       DE7N8      42
CD     XSTATE(JES+5)  = TE block     : compulsory                       DE7N8      43
CD                                                                      DE7N8      44
CD     Exciter Y-variables                                              DE7N8      45
CD                                                                      DE7N8      46
CD     VREG(JYE+1)    = VC (input to the TR block)                      DE7N8      47
CD     VREF(JYE+2)    = reference value                                 DE7N8      48
CD                                                                      DE7N8      49
CD   3.7 Exciter type 8                                                 DE7N8      50
CD                                                                      DE7N8      51
CD     Exciter data                                                     DE7N8      52
CD                                                                      DE7N8      53
CD     IDDAT(JE+ 1)   = IVTN         : sensing bus number               DE7N8      54
CD     DDAT(JE+ 2)    = KM                                              DE7N8      55
CD     DDAT(JE+ 3)    = TM                                              DE7N8      56
CD     DDAT(JE+ 4)    = KA                                              DE7N8      57
CD     DDAT(JE+ 5)    = KG                                              DE7N8      58
CD     DDAT(JE+ 6)    = VGMAX                                           DE7N8      59
CD     DDAT(JE+ 7)    = VIMAX                                           DE7N8      60
CD     DDAT(JE+ 8)    = VIMIN                                           DE7N8      61
CD     DDAT(JE+ 9)    = KC                                              DE7N8      62
CD     DDAT(JE+10)    = KF                                              DE7N8      63
CD     DDAT(JE+11)    = TF                                              DE7N8      64
CD     DDAT(JE+12)    = TC                                              DE7N8      65
CD     DDAT(JE+13)    = TB                                              DE7N8      66
CD     DDAT(JE+14)    = TA                                              DE7N8      67
CD     DDAT(JE+15)    = VMMAX                                           DE7N8      68
CD     DDAT(JE+16)    = VMMIN                                           DE7N8      69
CD     DDAT(JE+17)    = EFMAX                                           DE7N8      70
CD     DDAT(JE+18)    = TR                                              DE7N8      71
CD     DDAT(JE+19)    = RC                                              DE7N8      72
CD     DDAT(JE+20)    = XC                                              DE7N8      73
CD     DDAT(JE+21)    = XL                                              DE7N8      74
CD     DDAT(JE+22)    = K1                                              DE7N8      75
CD     DDAT(JE+23)    = KP                                              DE7N8      76
CD     DDAT(JE+24)    = THETAP                                          DE7N8      77
CD     DDAT(JE+25)    = VRMAX                                           DE7N8      78
CD     DDAT(JE+26)    = VRMIN                                           DE7N8      79
CD     DDAT(JE+27)    = VBMAX                                           DE7N8      80
CD                                                                      DE7N8      81
CD     Exciter states                                                   DE7N8      82
CD                                                                      DE7N8      83
CD     XSTATE(JES+1)  = TR block     : compulsory                       DE7N8      84
CD     XSTATE(JES+2)  = TF block     : compulsory                       DE7N8      85
CD     XSTATE(JES+3)  = TB block     : compulsory                       DE7N8      86
CD     XSTATE(JES+4)  = TA block     : compulsory                       DE7N8      87
CD     XSTATE(JES+5)  = TM block     : compulsory                       DE7N8      88
CD                                                                      DE7N8      89
CD     Exciter Y-variables                                              DE7N8      90
CD                                                                      DE7N8      91
CD     VREG(JYE+1)    = VC (input to the TR block)                      DE7N8      92
CD     VREF(JYE+2)    = reference value                                 DE7N8      93
CD                                                                      DE7N8      94
      INCLUDE 'PARX.INS'                                                DE7N8      95
      INCLUDE 'CNPT.INS'                                                DE7N8      96
      INCLUDE 'CNVOLT.INS'                                              DE7N8      97
      INCLUDE 'CNIPTR.INS'                                              DE7N8      98
      INCLUDE 'CNMDAT.INS'                                              DE7N8      99
      INCLUDE 'CNB3.INS'                                                DE7N8     100
      INCLUDE 'CNB5.INS'                                                DE7N8     101
      INCLUDE 'CNB8.INS'                                                DE7N8     102
      INCLUDE 'CNB9.INS'                                                DE7N8     103
      INCLUDE 'CNB10.INS'                                               DE7N8     104
      INCLUDE 'CNB19.INS'                                               DE7N8     105
      INCLUDE 'CNEXC.INS'                                               DE7N8     106
      INCLUDE 'CNXSTA.INS'                                              DE7N8     107
      INCLUDE 'CNQSTA.INS'                                              DE7N8     108
      INCLUDE 'CNMYVA.INS'                                              DE7N8     109
      INCLUDE 'CNYVAR.INS'                                              DE7N8     110
      INCLUDE 'CNUNIT.INS'                                              DE7N8     111
C                                                                       DE7N8     112
      LOGICAL LEX8                                                      DE7N8     113
C                                                                       DE7N8     114
      LEX8=(IEXN.EQ.8)                                                  DE7N8     115
      VRMAX=DDAT(JE+15)                                                 DE7N8     116
      VRMIN=DDAT(JE+16)                                                 DE7N8     117
      VEMIN=DDAT(JE+17)                                                 DE7N8     118
C                                                                       DE7N8     119
      IF (LEX8) THEN                                                    DE7N8     120
         VMMAX=DDAT(JE+25)                                              DE7N8     121
         VMMIN=DDAT(JE+26)                                              DE7N8     122
      END IF                                                            DE7N8     123
C                                                                       DE7N8     124
C   RATE FEEDBACK BLOCK                                                 DE7N8     125
C                                                                       DE7N8     126
      XRATE=EFDN                                                        DE7N8     127
C                                                                       DE7N8     128
      IF (IDDAT(JE+11).NE.0) THEN                                       DE7N8     129
         DSTATE(LSTATE+2)=(XRATE-XSTATE(JSTATE+2))/DDAT(JE+11)          DE7N8     130
         V2=DSTATE(LSTATE+2)*DDAT(JE+10)                                DE7N8     131
      ELSE                                                              DE7N8     132
         V2=0.0                                                         DE7N8     133
         DSTATE(LSTATE+2)=0.0                                           DE7N8     134
         XSTATE(JSTATE+2)=XRATE                                         DE7N8     135
      END IF                                                            DE7N8     136
C                                                                       DE7N8     137
      VSUM=VREF(JYE+2)-V1-V2                                            DE7N8     138
      IF (ISTABN.GT.0) VSUM=VSUM+VSS(JYS+1)                             DE7N8     139
      IF (IUALN.NE.0.AND.LVUEL.EQ.1) VSUM=VSUM+VUAL(JYU+1)              DE7N8     140
      IF (ITEBN.NE.0) VSUM=VSUM+TEB(JYTB+1)                             DE7N8     141
      IF (IMXLN.NE.0) VSUM=VSUM-VMXL(JYMX+1)                            DE7N8     142
C                                                                       DE7N8     143
C     LEAD/LAG BLOCK FOR                                                DE7N8     144
C                                                                       DE7N8     145
      IF (LEX8) THEN                                                    DE7N8     146
         IF (VSUM.GT.DDAT(JE+7)) THEN                                   DE7N8     147
            VSUM=DDAT(JE+7)                                             DE7N8     148
         ELSE IF (VSUM.LT.DDAT(JE+8)) THEN                              DE7N8     149
            VSUM=DDAT(JE+8)                                             DE7N8     150
         END IF                                                         DE7N8     151
      END IF                                                            DE7N8     152
C                                                                       DE7N8     153
C     ALTERNATE VUEL CONNECTION POINT                                   DE7N8     154
C                                                                       DE7N8     155
      IF (IUALN.NE.0.AND.LVUEL.EQ.2) THEN                               DE7N8     156
         IF (VSUM.LT.VUAL(JYU+1)) VSUM=VUAL(JYU+1)                      DE7N8     157
      END IF                                                            DE7N8     158
C                                                                       DE7N8     159
      IF (LEX8) VSUM=VSUM*DDAT(JE+4)                                    DE7N8     160
      IF (IDDAT(JE+13).NE.0) THEN                                       DE7N8     161
C                                                                       DE7N8     162
C   TB NE 0.0                                                           DE7N8     163
C                                                                       DE7N8     164
         DSTATE(LSTATE+3)=(VSUM-XSTATE(JSTATE+3))/DDAT(JE+13)           DE7N8     165
         V3=XSTATE(JSTATE+3)+DDAT(JE+12)*DSTATE(LSTATE+3)               DE7N8     166
      ELSE                                                              DE7N8     167
C                                                                       DE7N8     168
C   TB = 0                                                              DE7N8     169
C                                                                       DE7N8     170
         V3=VSUM                                                        DE7N8     171
         DSTATE(LSTATE+3)=0.0                                           DE7N8     172
         XSTATE(JSTATE+3)=V3                                            DE7N8     173
      END IF                                                            DE7N8     174
C                                                                       DE7N8     175
      NXS=3                                                             DE7N8     176
C                                                                       DE7N8     177
C  IEX = 8                                                              DE7N8     178
C                                                                       DE7N8     179
      IF (LEX8) THEN                                                    DE7N8     180
         NXS=NXS+1                                                      DE7N8     181
         IF (IDDAT(JE+14).NE.0) THEN                                    DE7N8     182
            DSTATE(LSTATE+NXS)=(V3-XSTATE(JSTATE+NXS))/DDAT(JE+14)      DE7N8     183
            V3=XSTATE(JSTATE+NXS)                                       DE7N8     184
         ELSE                                                           DE7N8     185
           DSTATE(LSTATE+NXS)=0.0                                       DE7N8     186
C           XSTATE(JSTATE+NXS)=V3                                       DE7N8     187
         END IF                                                         DE7N8     188
         IF (V3.GE.DDAT(JE+25)) THEN                                    DE7N8     189
            V3=DDAT(JE+25)                                              DE7N8     190
            IF (DSTATE(LSTATE+NXS).GT.0.0) THEN                         DE7N8     191
               DSTATE(LSTATE+NXS)=0.0                                   DE7N8     192
               QSTATE(JSTATE+NXS)=0.0                                   DE7N8     193
            END IF                                                      DE7N8     194
         ELSE IF (V3.LE.DDAT(JE+26)) THEN                               DE7N8     195
            V3=DDAT(JE+26)                                              DE7N8     196
            IF (DSTATE(LSTATE+NXS).LT.0.0) THEN                         DE7N8     197
               DSTATE(LSTATE+NXS)=0.0                                   DE7N8     198
               QSTATE(JSTATE+NXS)=0.0                                   DE7N8     199
            END IF                                                      DE7N8     200
         END IF                                                         DE7N8     201
         XSTATE(JSTATE+NXS)=V3                                          DE7N8     202
         VG=EFDN*DDAT(JE+5)                                             DE7N8     203
         IF (VG.GT.DDAT(JE+6)) VG=DDAT(JE+6)                            DE7N8     204
         V3=V3-VG                                                       DE7N8     205
      END IF                                                            DE7N8     206
C                                                                       DE7N8     207
C   AMPILIFIER BLOCK                                                    DE7N8     208
C                                                                       DE7N8     209
      NXS=NXS+1                                                         DE7N8     210
      IF (IDDAT(JE+3).NE.0) THEN                                        DE7N8     211
C                                                                       DE7N8     212
C   TA.NE.0                                                             DE7N8     213
C                                                                       DE7N8     214
         DSTATE(LSTATE+NXS)=(DDAT(JE+2)*V3-XSTATE(JSTATE+NXS))          DE7N8     215
     1                      /DDAT(JE+3)                                 DE7N8     216
         VR=XSTATE(JSTATE+NXS)                                          DE7N8     217
      ELSE                                                              DE7N8     218
C                                                                       DE7N8     219
C   TA.EQ.0                                                             DE7N8     220
C                                                                       DE7N8     221
         VR=DDAT(JE+2)*V3                                               DE7N8     222
         DSTATE(LSTATE+NXS)=0.                                          DE7N8     223
C         XSTATE(JSTATE+NXS)=VR                                         DE7N8     224
C                                                                       DE7N8     225
      END IF                                                            DE7N8     226
C                                                                       DE7N8     227
      IF (VR.GE.VRMAX) THEN                                             DE7N8     228
         VR=VRMAX                                                       DE7N8     229
         IF (DSTATE(LSTATE+NXS).GT.0.0) THEN                            DE7N8     230
            DSTATE(LSTATE+NXS)=0.0                                      DE7N8     231
            QSTATE(JSTATE+NXS)=0.0                                      DE7N8     232
         END IF                                                         DE7N8     233
      ELSE IF (VR.LE.VRMIN) THEN                                        DE7N8     234
         VR=VRMIN                                                       DE7N8     235
         IF (DSTATE(LSTATE+NXS).LT.0.0) THEN                            DE7N8     236
            DSTATE(LSTATE+NXS)=0.0                                      DE7N8     237
            QSTATE(JSTATE+NXS)=0.0                                      DE7N8     238
         END IF                                                         DE7N8     239
      END IF                                                            DE7N8     240
      XSTATE(JSTATE+NXS)=VR                                             DE7N8     241
C                                                                       DE7N8     242
      VINPT=VR                                                          DE7N8     243
CCCCC                                                                   DE7N8     244
      XVARB=XSTATE(JSTATE+NXS)                                          DE7N8     245
      REFMX=0.99*DDAT(JE+15)                                            DE7N8     246
CCCCC                                                                   DE7N8     247
C                                                                       DE7N8     248
      IF (.NOT.LEX8) THEN                                               DE7N8     249
C                                                                       DE7N8     250
C        COMPOUND SOURCE VOLTAGE                                        DE7N8     251
C                                                                       DE7N8     252
C        IEX = 7                                                        DE7N8     253
C                                                                       DE7N8     254
         VSC1=VR1*DDAT(JE+21)-CQGN*DDAT(JE+22)                          DE7N8     255
         VSC2=VIM1*DDAT(JE+21)+CDGN*DDAT(JE+22)                         DE7N8     256
         VSC=SQRT(VSC1*VSC1+VSC2*VSC2)                                  DE7N8     257
         XIN=DDAT(JE+9)*CFDN/VSC                                        DE7N8     258
         IF (XIN.GT.0.750) THEN                                         DE7N8     259
            FIN=1.732*(1.0-XIN)                                         DE7N8     260
         ELSE IF (XIN.GT.0.433) THEN                                    DE7N8     261
            FIN=SQRT(0.75-XIN*XIN)                                      DE7N8     262
         ELSE                                                           DE7N8     263
            FIN=1.0-0.577*XIN                                           DE7N8     264
         END IF                                                         DE7N8     265
C                                                                       DE7N8     266
C     NOTE THAT BOTH THE SUMMATION (TYPE ST2) AND THE MULTIPLER         DE7N8     267
C     (TYPE ST2A) ARE SUPPORTED HERE                                    DE7N8     268
C                                                                       DE7N8     269
         IF (DDAT(JE+6).GT.0.5) THEN                                    DE7N8     270
            VEIN=VINPT+VSC*FIN-DDAT(JE+4)*XSTATE(JSTATE+5)              DE7N8     271
         ELSE                                                           DE7N8     272
            VEIN=VINPT*VSC*FIN-DDAT(JE+4)*XSTATE(JSTATE+5)              DE7N8     273
         END IF                                                         DE7N8     274
C                                                                       DE7N8     275
         DSTATE(LSTATE+5)=VEIN/DDAT(JE+5)                               DE7N8     276
         VE=XSTATE(JSTATE+5)                                            DE7N8     277
         IF (VE.GE.VEMIN) THEN                                          DE7N8     278
            VE=VEMIN                                                    DE7N8     279
            IF (DSTATE(LSTATE+5).GT.0.0) THEN                           DE7N8     280
               DSTATE(LSTATE+5)=0.0                                     DE7N8     281
               QSTATE(JSTATE+5)=0.0                                     DE7N8     282
            END IF                                                      DE7N8     283
         ELSE IF (VE.LE.0.0) THEN                                       DE7N8     284
            VE=0.0                                                      DE7N8     285
            IF (DSTATE(LSTATE+5).LT.0.0) THEN                           DE7N8     286
               DSTATE(LSTATE+5)=0.0                                     DE7N8     287
               QSTATE(JSTATE+5)=0.0                                     DE7N8     288
            END IF                                                      DE7N8     289
         END IF                                                         DE7N8     290
C                                                                       DE7N8     291
         EFD(JYG+4)=VE                                                  DE7N8     292
C                                                                       DE7N8     293
      ELSE                                                              DE7N8     294
C                                                                       DE7N8     295
C  IEX = 8                                                              DE7N8     296
C                                                                       DE7N8     297
         XKPR=DDAT(JE+23)*COS(DDAT(JE+24))                              DE7N8     298
         XKPI=DDAT(JE+23)*SIN(DDAT(JE+24))                              DE7N8     299
         VSC1=VR1*XKPR-VIM1*XKPI-CQGN*(DDAT(JE+22)                      DE7N8     300
     1       +XKPR*DDAT(JE+21))-CDGN*XKPI*DDAT(JE+21)                   DE7N8     301
         VSC2=VR1*XKPI+VIM1*XKPR+CDGN*(DDAT(JE+22)                      DE7N8     302
     1       +XKPR*DDAT(JE+21))-CQGN*XKPI*DDAT(JE+21)                   DE7N8     303
         VSC=SQRT(VSC1*VSC1+VSC2*VSC2)                                  DE7N8     304
         XIN=DDAT(JE+9)*CFDN/VSC                                        DE7N8     305
         IF (XIN.GT.0.750) THEN                                         DE7N8     306
            FIN=1.732*(1.0-XIN)                                         DE7N8     307
         ELSE IF (XIN.GT.0.433) THEN                                    DE7N8     308
            FIN=SQRT(0.75-XIN**2)                                       DE7N8     309
         ELSE                                                           DE7N8     310
           FIN=1.0-0.577*XIN                                            DE7N8     311
         END IF                                                         DE7N8     312
C                                                                       DE7N8     313
         VBF=VSC*FIN                                                    DE7N8     314
         IF (VBF.GT.DDAT(JE+27)) VBF=DDAT(JE+27)                        DE7N8     315
         EFD(JYG+4)=VINPT*VBF                                           DE7N8     316
C                                                                       DE7N8     317
         IF (EFD(JYG+4).GT.VEMIN) EFD(JYG+4)=VEMIN                      DE7N8     318
C                                                                       DE7N8     319
      END IF                                                            DE7N8     320
C                                                                       DE7N8     321
      LSTATE=LSTATE+5                                                   DE7N8     322
C                                                                       DE7N8     323
      RETURN                                                            DE7N8     324
C                                                                       DE7N8     325
      END                                                               DE7N8     326
