CFPRIME GDEVIC                                                          GDEVIC      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  GDEVIC                                                GDEVIC      3
CD -------------------------------------------------------------------  GDEVIC      4
CD                                                                      GDEVIC      5
CD              *****     GDEVICD ROUTINE   *****                       GDEVIC      6
CD                                                                      GDEVIC      7
CD -------------------------------------------------------------------  GDEVIC      8
CD                                                                      GDEVIC      9
CD       PURPOSE:  To control building of converter contributions to    GDEVIC     10
CD                 G matrix.                                            GDEVIC     11
CD                                                                      GDEVIC     12
CD                                                                      GDEVIC     13
CD       DEFINITION OF LOCAL VARIABLES:                                 GDEVIC     14
CD                 JCOL    -  matrix column number.                     GDEVIC     15
CD                 I      - 'do' loop index.                            GDEVIC     16
CD                 J      - 'do' loop index.                            GDEVIC     17
CD                 JPOSN   -  storage position for dc information.      GDEVIC     18
CD                 JROW    -  matrix row number.                        GDEVIC     19
CD                                                                      GDEVIC     20
CD -------------------------------------------------------------------  GDEVIC     21
      INCLUDE 'PARX.INS'                                                GDEVIC     22
      INCLUDE 'GRDC01.INS'                                              GDEVIC     23
      INCLUDE 'UDCJ.INS'                                                GDEVIC     24
C                                                                       GDEVIC     25
C---------------------------------------------------------------------  GDEVIC     26
C                                                                       GDEVIC     27
      IF(.NOT. SORTED)THEN                                              GDEVIC     28
C                                                                       GDEVIC     29
C        Sort converters and breakers so that the voltage controlled    GDEVIC     30
c        devices are evaluated last.                                    GDEVIC     31
C                                                                       GDEVIC     32
         DO 20 I = 1, ICDC                                              GDEVIC     33
            IDCSRT(I) = 0                                               GDEVIC     34
20       CONTINUE                                                       GDEVIC     35
C                                                                       GDEVIC     36
         DO 30 I= 1, IBDC                                               GDEVIC     37
            IDBSRT(I) = 0                                               GDEVIC     38
30       CONTINUE                                                       GDEVIC     39
C                                                                       GDEVIC     40
         N = 0                                                          GDEVIC     41
         DO 40 I = 1, ICDC                                              GDEVIC     42
            JPOSN = IDC(I)                                              GDEVIC     43
            IF(UMODE(JPOSN).EQ.'ALPHA' .OR. UMODE(JPOSN).EQ.'GAMMA'     GDEVIC     44
     1         .OR. UMODE(JPOSN).EQ.'CURRENT') THEN                     GDEVIC     45
               IF(UMOD2(JPOSN).EQ.'ALPHA' .OR. UMOD2(JPOSN).EQ.'GAMMA'  GDEVIC     46
     1            .OR. UMOD2(JPOSN).EQ.'CURRENT'                        GDEVIC     47
     2            .OR. UMOD2(JPOSN).EQ.'BLOCK'                          GDEVIC     48
     3            .OR. UMOD2(JPOSN).EQ.'NONE') THEN                     GDEVIC     49
                  N = N + 1                                             GDEVIC     50
                  IDCSRT(N) = JPOSN                                     GDEVIC     51
               END IF                                                   GDEVIC     52
            ELSEIF(UMODE(JPOSN).EQ.'BLOCK') THEN                        GDEVIC     53
               N = N + 1                                                GDEVIC     54
               IDCSRT(N) = JPOSN                                        GDEVIC     55
            END IF                                                      GDEVIC     56
40       CONTINUE                                                       GDEVIC     57
         IDCPTR = N                                                     GDEVIC     58
         DO 60 I = 1, ICDC                                              GDEVIC     59
            JPOSN = IDC(I)                                              GDEVIC     60
            IF(UMODE(JPOSN).EQ.'VOLTAGE'                                GDEVIC     61
     1         .OR. UMODE(JPOSN).EQ.'BYPASS'                            GDEVIC     62
     2         .OR. UMODE(JPOSN).EQ.'COMFAIL') THEN                     GDEVIC     63
               N = N + 1                                                GDEVIC     64
               IDCSRT(N) = JPOSN                                        GDEVIC     65
            ELSEIF(UMODE(JPOSN).NE.'BLOCK') THEN                        GDEVIC     66
               IF(UMOD2(JPOSN).EQ.'VOLTAGE'                             GDEVIC     67
     1            .OR. UMOD2(JPOSN).EQ.'BYPASS'                         GDEVIC     68
     2            .OR. UMOD2(JPOSN).EQ.'COMFAIL') THEN                  GDEVIC     69
                  N = N + 1                                             GDEVIC     70
                  IDCSRT(N) = JPOSN                                     GDEVIC     71
               END IF                                                   GDEVIC     72
            END IF                                                      GDEVIC     73
60       CONTINUE                                                       GDEVIC     74
C                                                                       GDEVIC     75
C     Now sort the breakers.                                            GDEVIC     76
C                                                                       GDEVIC     77
         N = 0                                                          GDEVIC     78
         DO 70 I = 1, IBDC                                              GDEVIC     79
            JPOSN = IDCB(I)                                             GDEVIC     80
            IF(IBSTAT(JPOSN).EQ.IOPEND) THEN                            GDEVIC     81
C                                                                       GDEVIC     82
C     Open breakers are modelled as current controlled devices.         GDEVIC     83
C                                                                       GDEVIC     84
               N = N + 1                                                GDEVIC     85
               IDBSRT(N) = JPOSN                                        GDEVIC     86
            END IF                                                      GDEVIC     87
70       CONTINUE                                                       GDEVIC     88
         IDBPTR = N                                                     GDEVIC     89
         DO 75 I = 1, IBDC                                              GDEVIC     90
            JPOSN = IDCB(I)                                             GDEVIC     91
            IF(IBSTAT(JPOSN).NE.IOPEND) THEN                            GDEVIC     92
C                                                                       GDEVIC     93
C     Closed or opening breakers are treated as voltage controlled      GDEVIC     94
C     devices.                                                          GDEVIC     95
C                                                                       GDEVIC     96
               N = N + 1                                                GDEVIC     97
               IDBSRT(N) = JPOSN                                        GDEVIC     98
            END IF                                                      GDEVIC     99
75       CONTINUE                                                       GDEVIC    100
C                                                                       GDEVIC    101
         SORTED = .TRUE.                                                GDEVIC    102
      END IF                                                            GDEVIC    103
C                                                                       GDEVIC    104
C                                                                       GDEVIC    105
C                                                                       GDEVIC    106
      DO 80 I = 1, IDCPTR                                               GDEVIC    107
         IF(IDCSRT(I) .NE. 0)THEN                                       GDEVIC    108
C                                                                       GDEVIC    109
            JPOSN = IDCSRT(I)                                           GDEVIC    110
C                                                                       GDEVIC    111
C           Converter is either alpha, gamma, or current controlled.    GDEVIC    112
C           Blocked converter is current controlled to zero.            GDEVIC    113
C                                                                       GDEVIC    114
            IF(UMOD2(JPOSN).EQ.'NONE') THEN                             GDEVIC    115
C                                                                       GDEVIC    116
C              line commutated converter                                GDEVIC    117
C                                                                       GDEVIC    118
               CALL GCNOTV (JPOSN, UMODE(JPOSN))                        GDEVIC    119
            ELSE                                                        GDEVIC    120
C                                                                       GDEVIC    121
C              self commutated converter                                GDEVIC    122
C                                                                       GDEVIC    123
               IF(UMODE(JPOSN).EQ.'BLOCK'                               GDEVIC    124
     1            .OR.UMOD2(JPOSN).EQ.'BLOCK') THEN                     GDEVIC    125
                  CALL GCNOTV (JPOSN, 'BLOCK')                          GDEVIC    126
               ELSE                                                     GDEVIC    127
                  CALL GCNOTV (JPOSN, 'CURRENT')                        GDEVIC    128
               ENDIF                                                    GDEVIC    129
            ENDIF                                                       GDEVIC    130
         END IF                                                         GDEVIC    131
80    CONTINUE                                                          GDEVIC    132
C                                                                       GDEVIC    133
C     No resistance is added to the g matrix for current controlled     GDEVIC    134
C     breakers.                                                         GDEVIC    135
C                                                                       GDEVIC    136
C                                                                       GDEVIC    137
C     Make a copy of G matrix before Voltage control added              GDEVIC    138
C                                                                       GDEVIC    139
      DO 120 JROW = 1, ISIZEG                                           GDEVIC    140
         DO 100 JCOL = 1, ISIZEG                                        GDEVIC    141
            GMSAVE(JROW,JCOL) = GMATRX(JROW,JCOL)                       GDEVIC    142
100      CONTINUE                                                       GDEVIC    143
120   CONTINUE                                                          GDEVIC    144
C                                                                       GDEVIC    145
      DO 140 I = IDCPTR+1, ICDC                                         GDEVIC    146
         IF(IDCSRT(I) .NE. 0)THEN                                       GDEVIC    147
            JPOSN = IDCSRT(I)                                           GDEVIC    148
C                                                                       GDEVIC    149
C           Converter is voltage controlled.                            GDEVIC    150
C           Bypassed or failed converter has voltage of 0.              GDEVIC    151
C                                                                       GDEVIC    152
            IF(UMODE(JPOSN).EQ.'VOLTAGE') THEN                          GDEVIC    153
               IF(UMOD2(JPOSN).EQ.'BYPASS'                              GDEVIC    154
     2            .OR. UMOD2(JPOSN).EQ.'COMFAIL') THEN                  GDEVIC    155
                  CALL GCVOLT (JPOSN, UMOD2(JPOSN))                     GDEVIC    156
               ELSE                                                     GDEVIC    157
                  CALL GCVOLT (JPOSN, UMODE(JPOSN))                     GDEVIC    158
               ENDIF                                                    GDEVIC    159
            ELSE                                                        GDEVIC    160
               CALL GCVOLT (JPOSN, UMODE(JPOSN))                        GDEVIC    161
            ENDIF                                                       GDEVIC    162
C                                                                       GDEVIC    163
         END IF                                                         GDEVIC    164
140   CONTINUE                                                          GDEVIC    165
C                                                                       GDEVIC    166
C     Add the voltage controlled breakers to the G matrix.              GDEVIC    167
C                                                                       GDEVIC    168
      DO 160 I = IDBPTR+1, IBDC                                         GDEVIC    169
         IF(IDBSRT(I) .NE. 0)THEN                                       GDEVIC    170
            JPOSN = IDBSRT(I)                                           GDEVIC    171
C                                                                       GDEVIC    172
            CALL GBVOLT (JPOSN)                                         GDEVIC    173
C                                                                       GDEVIC    174
         END IF                                                         GDEVIC    175
160   CONTINUE                                                          GDEVIC    176
C                                                                       GDEVIC    177
C---------------------------------------------------------------------  GDEVIC    178
C                                                                       GDEVIC    179
      RETURN                                                            GDEVIC    180
C                                                                       GDEVIC    181
C---------------------------------------------------------------------  GDEVIC    182
C                                                                       GDEVIC    183
      END                                                               GDEVIC    184
