CFPRIME AEXC6                                                           AEXC6       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 AEXC6(ISTATE,MD,XAD)                                   AEXC6       3
CD                                                                      AEXC6       4
CD    TO FORMULATE THE JACOBIAN MATRICES OF TYPE 6 EXCITER              AEXC6       5
CD    (IEEE TYPE AC2).                                                  AEXC6       6
CD                                                                      AEXC6       7
      INCLUDE 'PARX.INS'                                                AEXC6       8
      INCLUDE 'CNB8.INS'                                                AEXC6       9
      INCLUDE 'CNEXC.INS'                                               AEXC6      10
      INCLUDE 'CNPARX.INS'                                              AEXC6      11
      INCLUDE 'CNMDAT.INS'                                              AEXC6      12
      INCLUDE 'CNXSTA.INS'                                              AEXC6      13
      INCLUDE 'CNMSTA.INS'                                              AEXC6      14
C                                                                       AEXC6      15
      INCLUDE 'CNABAK.INS'                                              AEXC6      16
C                                                                       AEXC6      17
      DIMENSION FIELD(10),IFIELD(10)                                    AEXC6      18
      EQUIVALENCE (FIELD(1),IFIELD(1))                                  AEXC6      19
C                                                                       AEXC6      20
      DO 10 I=2,5                                                       AEXC6      21
         FIELD(I)=0.0                                                   AEXC6      22
  10  CONTINUE                                                          AEXC6      23
C                                                                       AEXC6      24
C     SUBSCRIPTS                                                        AEXC6      25
C                                                                       AEXC6      26
      ISUB1=ISTATE+1                                                    AEXC6      27
      ISUB2=ISTATE+2                                                    AEXC6      28
      ISUB3=ISTATE+3                                                    AEXC6      29
      ISUB4=ISTATE+4                                                    AEXC6      30
      ISUB5=ISTATE+5                                                    AEXC6      31
C                                                                       AEXC6      32
      ICASE=IDDAT(JE+28)                                                AEXC6      33
C                                                                       AEXC6      34
C     TF BLOCK                                                          AEXC6      35
C                                                                       AEXC6      36
      VE=XSTATE(JSTATE+5)                                               AEXC6      37
      BETA=DDAT(JE+4)+DDAT(JE+6)*DDAT(JE+7)                             AEXC6      38
     *     *EXP(DDAT(JE+7)*VE)                                          AEXC6      39
      XDEP=DDAT(JE+22)                                                  AEXC6      40
      ALP5=DDAT(JE+21)-XDEP                                             AEXC6      41
      IF (IDDAT(JE+11).EQ.0) THEN                                       AEXC6      42
         CFTF=0.0                                                       AEXC6      43
      ELSE                                                              AEXC6      44
         CFTF=DDAT(JE+10)/DDAT(JE+11)                                   AEXC6      45
         TFI=1.0/DDAT(JE+11)                                            AEXC6      46
         A(ISUB2,ISUB2)=-TFI                                            AEXC6      47
         A(ISUB2,ISUB5)=BETA*TFI                                        AEXC6      48
C                                                                       AEXC6      49
         FIELD(2)=ALP5*TFI                                              AEXC6      50
C                                                                       AEXC6      51
      END IF                                                            AEXC6      52
C                                                                       AEXC6      53
C     TC, TB BLOCK                                                      AEXC6      54
C                                                                       AEXC6      55
      IF (IDDAT(JE+13).EQ.0) THEN                                       AEXC6      56
         TCTB=1.0                                                       AEXC6      57
      ELSE                                                              AEXC6      58
         TBI=1.0/DDAT(JE+13)                                            AEXC6      59
         TCTB=DDAT(JE+12)*TBI                                           AEXC6      60
         WS1=CFTF*TBI                                                   AEXC6      61
         A(ISUB3,ISUB2)=WS1                                             AEXC6      62
         A(ISUB3,ISUB3)=-TBI                                            AEXC6      63
         A(ISUB3,ISUB5)=-BETA*WS1                                       AEXC6      64
C                                                                       AEXC6      65
         IF (INPUTR.EQ.0) THEN                                          AEXC6      66
            CALL BCBTEM(ISUB3,TBI)                                      AEXC6      67
         ELSE                                                           AEXC6      68
            A(ISUB3,ISUB1)=-TBI                                         AEXC6      69
         END IF                                                         AEXC6      70
C                                                                       AEXC6      71
         IUST(1)=ISUB3                                                  AEXC6      72
         GUST(1)=TBI                                                    AEXC6      73
C                                                                       AEXC6      74
         FIELD(3)=-ALP5*WS1                                             AEXC6      75
C                                                                       AEXC6      76
      END IF                                                            AEXC6      77
C                                                                       AEXC6      78
C     TA AND TE BLOCKS                                                  AEXC6      79
C                                                                       AEXC6      80
      TEI=1.0/DDAT(JE+5)                                                AEXC6      81
      IF (IDDAT(JE+3).EQ.0) THEN                                        AEXC6      82
         IF (ICASE.EQ.1) THEN                                           AEXC6      83
            CACBTE=DDAT(JE+2)*DDAT(JE+23)*TEI                           AEXC6      84
            WS1=TCTB*CACBTE                                             AEXC6      85
            A(ISUB5,ISUB2)=WS1*CFTF                                     AEXC6      86
            A(ISUB5,ISUB3)=CACBTE-WS1                                   AEXC6      87
            A(ISUB5,ISUB5)=-BETA*(TEI+DDAT(JE+23)*DDAT(JE+24)*TEI       AEXC6      88
     *                           +A(ISUB5,ISUB2))                       AEXC6      89
C                                                                       AEXC6      90
            IF (INPUTR.EQ.0) THEN                                       AEXC6      91
               CALL BCBTEM(ISUB5,WS1)                                   AEXC6      92
            ELSE                                                        AEXC6      93
               A(ISUB5,ISUB1)=-WS1                                      AEXC6      94
            END IF                                                      AEXC6      95
C                                                                       AEXC6      96
            IF (IUST(1).EQ.0) THEN                                      AEXC6      97
               IUST(1)=ISUB5                                            AEXC6      98
               GUST(1)=WS1                                              AEXC6      99
            ELSE                                                        AEXC6     100
               IUST(2)=ISUB5                                            AEXC6     101
               GUST(2)=WS1                                              AEXC6     102
            END IF                                                      AEXC6     103
C                                                                       AEXC6     104
            FIELD(5)=ALP5*A(ISUB5,ISUB5)/BETA                           AEXC6     105
C                                                                       AEXC6     106
         END IF                                                         AEXC6     107
C                                                                       AEXC6     108
      ELSE                                                              AEXC6     109
C                                                                       AEXC6     110
         TAI=1.0/DDAT(JE+3)                                             AEXC6     111
         CATA=DDAT(JE+2)*TAI                                            AEXC6     112
         WS1=TCTB*CATA                                                  AEXC6     113
         WS2=WS1*CFTF                                                   AEXC6     114
         A(ISUB4,ISUB2)=WS2                                             AEXC6     115
         A(ISUB4,ISUB3)=CATA-WS1                                        AEXC6     116
         A(ISUB4,ISUB4)=-TAI                                            AEXC6     117
         A(ISUB4,ISUB5)=-BETA*WS2                                       AEXC6     118
C                                                                       AEXC6     119
         IF (INPUTR.EQ.0) THEN                                          AEXC6     120
            CALL BCBTEM(ISUB4,WS1)                                      AEXC6     121
         ELSE                                                           AEXC6     122
            A(ISUB4,ISUB1)=-WS1                                         AEXC6     123
         END IF                                                         AEXC6     124
C                                                                       AEXC6     125
         IF (IUST(1).EQ.0) THEN                                         AEXC6     126
            IUST(1)=ISUB4                                               AEXC6     127
            GUST(1)=WS1                                                 AEXC6     128
         ELSE                                                           AEXC6     129
            IUST(2)=ISUB4                                               AEXC6     130
            GUST(2)=WS1                                                 AEXC6     131
         END IF                                                         AEXC6     132
C                                                                       AEXC6     133
         FIELD(4)=-ALP5*WS2                                             AEXC6     134
C                                                                       AEXC6     135
         IF (ICASE.EQ.1) THEN                                           AEXC6     136
            A(ISUB5,ISUB4)=DDAT(JE+23)*TEI                              AEXC6     137
            A(ISUB5,ISUB5)=-BETA*(TEI+DDAT(JE+24))                      AEXC6     138
            FIELD(5)=-ALP5*TEI*(1.0+DDAT(JE+23)*DDAT(JE+24))            AEXC6     139
         END IF                                                         AEXC6     140
C                                                                       AEXC6     141
      END IF                                                            AEXC6     142
C                                                                       AEXC6     143
C     CASE 2 (WITH LV GATE ACCEPTING INPUT FROM KL BLOCK)               AEXC6     144
C                                                                       AEXC6     145
      IF (ICASE.EQ.2) THEN                                              AEXC6     146
         A(ISUB5,ISUB5)=-BETA*TEI*(1.0+DDAT(JE+23)*DDAT(JE+25))         AEXC6     147
         FIELD(5)=-ALP5*TEI*(1.0+DDAT(JE+23)*DDAT(JE+25))               AEXC6     148
      END IF                                                            AEXC6     149
C                                                                       AEXC6     150
C     CALCULATE EXCITER CONSTANTS                                       AEXC6     151
C                                                                       AEXC6     152
      VTH=VE-XDEP*CFDN                                                  AEXC6     153
      IF (VTH.EQ.0.0) THEN                                              AEXC6     154
         CIN=0.0                                                        AEXC6     155
      ELSE                                                              AEXC6     156
         CIN=DDAT(JE+9)*CFDN/VTH                                        AEXC6     157
      END IF                                                            AEXC6     158
      IF (CIN.LE.0.433) THEN                                            AEXC6     159
         FEX=1.0-0.58*CIN                                               AEXC6     160
         GAMA=-0.58                                                     AEXC6     161
      ELSE IF (CIN.GE.0.75) THEN                                        AEXC6     162
         FEX=1.732-1.732*CIN                                            AEXC6     163
         GAMA=-1.732                                                    AEXC6     164
      ELSE                                                              AEXC6     165
         FEX=SQRT(0.75-CIN*CIN)                                         AEXC6     166
         GAMA=-CIN/FEX                                                  AEXC6     167
      END IF                                                            AEXC6     168
C                                                                       AEXC6     169
      C15=FEX-GAMA*CIN                                                  AEXC6     170
      CF=GAMA*CIN*VE/CFDN-XDEP*FEX                                      AEXC6     171
C                                                                       AEXC6     172
C     ELIMINATE THE FIELD CURRENT TERM IN STATE EQUATION                AEXC6     173
C                                                                       AEXC6     174
      DO 20 I=2,5                                                       AEXC6     175
         IF (IFIELD(I).EQ.0) GOTO 20                                    AEXC6     176
         II=ISTATE+I                                                    AEXC6     177
         WS1=XAD*FIELD(I)                                               AEXC6     178
C                                                                       AEXC6     179
         DO 30 J=1,MD+1                                                 AEXC6     180
            A(II,J+1)=WS1*FCTM(J)                                       AEXC6     181
  30     CONTINUE                                                       AEXC6     182
C                                                                       AEXC6     183
         BC(II,1)=BC(II,1)+WS1*FCTM(5)                                  AEXC6     184
         BC(II,2)=BC(II,2)+WS1*FCTM(6)                                  AEXC6     185
C                                                                       AEXC6     186
  20  CONTINUE                                                          AEXC6     187
C                                                                       AEXC6     188
C     INTERCONNECTION WITH GENERATOR (OUTPUT EQUATION)                  AEXC6     189
C                                                                       AEXC6     190
      A(3,ISUB5)=CFEXC*C15                                              AEXC6     191
      CF=CF*CFEXC*XAD                                                   AEXC6     192
      DO 120 I=1,MD+1                                                   AEXC6     193
         A(3,I+1)=A(3,I+1)+CF*FCTM(I)                                   AEXC6     194
 120  CONTINUE                                                          AEXC6     195
      BC(3,1)=BC(3,1)+CF*FCTM(5)                                        AEXC6     196
      BC(3,2)=BC(3,2)+CF*FCTM(6)                                        AEXC6     197
C                                                                       AEXC6     198
      ISTATE=ISUB5                                                      AEXC6     199
C                                                                       AEXC6     200
      RETURN                                                            AEXC6     201
      END                                                               AEXC6     202
