CFPRIME DCNETS                                                          DCNETS      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 DCNETS (TS)                                            DCNETS      3
CD -------------------------------------------------------------------  DCNETS      4
CD                                                                      DCNETS      5
CD              *****     DCNETS  ROUTINE   *****                       DCNETS      6
CD                                                                      DCNETS      7
CD -------------------------------------------------------------------  DCNETS      8
CD                                                                      DCNETS      9
CD       PURPOSE:  Main DC network and converter solution routine.      DCNETS     10
CD                                                                      DCNETS     11
CD                                                                      DCNETS     12
CD       DEFINITION OF LOCAL VARIABLES:                                 DCNETS     13
CD                 BUS1   -  storage for first bus name.                DCNETS     14
CD                 BUS2   -  storage for second bus name.               DCNETS     15
CD                 CTIMX  -  control time step.                         DCNETS     16
CD          (P)    DELTAT -  ac time step.                              DCNETS     17
CD                 I      - 'do' loop index.                            DCNETS     18
CD                 ITCNT  -  iteration count when another solution is   DCNETS     19
CD                           forced.                                    DCNETS     20
CD                 J      - 'do' loop index.                            DCNETS     21
CD                 N      - 'do' loop index.                            DCNETS     22
CD                 NUM    - 'do' loop index.                            DCNETS     23
CD                 JPOSN   -  storage position for dc information.      DCNETS     24
CD                 PRINT  -  indicates if udc titles are printed.       DCNETS     25
CD                 JSLNVE -  pointer to storage of bus voltage          DCNETS     26
CD                           solution data.                             DCNETS     27
CD                 TIMLX  -  local copy of time.                        DCNETS     28
CD          (P)    TIMX   -  present time.                              DCNETS     29
CD                                                                      DCNETS     30
CD -------------------------------------------------------------------  DCNETS     31
      INCLUDE 'PARX.INS'                                                DCNETS     32
      INCLUDE 'CNPT.INS'                                                DCNETS     33
      INCLUDE 'CNUNIT.INS'                                              DCNETS     34
      INCLUDE 'GRDC01.INS'                                              DCNETS     35
      INCLUDE 'UDCA.INS'                                                DCNETS     36
      INCLUDE 'GRPDCS.INS'                                              DCNETS     37
      INCLUDE 'UDCF.INS'                                                DCNETS     38
      INCLUDE 'UDCG.INS'                                                DCNETS     39
      INCLUDE 'UDCJ.INS'                                                DCNETS     40
      INCLUDE 'CNFLAG.INS'                                              DCNETS     41
      INCLUDE 'CNMSG.INS'                                               DCNETS     42
C                                                                       DCNETS     43
      DOUBLE PRECISION   CTIMX, TIMLX, TIMX                             DCNETS     44
C                                                                       DCNETS     45
      DIMENSION   JSLNVE(NDCN)                                          DCNETS     46
C                                                                       DCNETS     47
      LOGICAL       PRINT, DCHIDE                                       DCNETS     48
      COMMON /DCHID/ DCHIDE                                             DCNETS     49
C                                                                       DCNETS     50
      DOUBLE PRECISION XTIME                                            DCNETS     51
      CHARACTER*8   BUS1, BUS2                                          DCNETS     52
C                                                                       DCNETS     53
C                                                                       DCNETS     54
C---------------------------------------------------------------------  DCNETS     55
C                                                                       DCNETS     56
      LDEB=(JDEB(307).NE.0)                                             DCNETS     57
C                                                                       DCNETS     58
      TIMX=DBLE(TS)                                                     DCNETS     59
      TIMLX = TIMX                                                      DCNETS     60
      PRINT = .FALSE.                                                   DCNETS     61
      DCHIDE = .FALSE.                                                  DCNETS     62
C                                                                       DCNETS     63
C     Determine the solution stepping intervals                         DCNETS     64
C                                                                       DCNETS     65
      CALL CALSTP                                                       DCNETS     66
C                                                                       DCNETS     67
      CTIMX = CTIME                                                     DCNETS     68
C                                                                       DCNETS     69
C                                                                       DCNETS     70
C     The G matrix must be rebuilt if:                                  DCNETS     71
C         1.  Change in ac network.                                     DCNETS     72
C         2.  Change in dc network.                                     DCNETS     73
C         3.  Change in dc time step.                                   DCNETS     74
C         4.  Change in dc damping.                                     DCNETS     75
C         5.  Mode change in dc converter.                              DCNETS     76
C                                                                       DCNETS     77
      IF(HIST)THEN                                                      DCNETS     78
         IF(ACCHNG .OR. DCCHNG .OR. MODCHG)THEN                         DCNETS     79
C                                                                       DCNETS     80
            IF(.NOT. FILLED)THEN                                        DCNETS     81
C                                                                       DCNETS     82
C              If the LINREF table has not been constructed, then find  DCNETS     83
C              the internal node numbers for all the dc lines.          DCNETS     84
C                                                                       DCNETS     85
               DO 40 I = 1, ICDC                                        DCNETS     86
                  IF(IDC(I) .NE. 0)THEN                                 DCNETS     87
                     JPOSN = IDC(I)                                     DCNETS     88
                     BUS1 = DCCNAM(JPOSN)(1:8)                          DCNETS     89
                     BUS2 = DCCNAM(JPOSN)(9:16)                         DCNETS     90
                     ICONRE(JPOSN,1) = 0                                DCNETS     91
                     ICONRE(JPOSN,2) = 0                                DCNETS     92
                     DO 20 N = 1, NUMNOD                                DCNETS     93
                        IF(BUS1.EQ.IDCNOD(N))  ICONRE(JPOSN,1) = N      DCNETS     94
                        IF(BUS2.EQ.IDCNOD(N))  ICONRE(JPOSN,2) = N      DCNETS     95
20                   CONTINUE                                           DCNETS     96
                  ENDIF                                                 DCNETS     97
40             CONTINUE                                                 DCNETS     98
C                                                                       DCNETS     99
C                                                                       DCNETS    100
C                                                                       DCNETS    101
               DO 80 I = 1, ILDC                                        DCNETS    102
                  IF(IDCL(I) .NE. 0)THEN                                DCNETS    103
                     JPOSN = IDCL(I)                                    DCNETS    104
                     XLDC(JPOSN) = XLDC(JPOSN) * 0.001                  DCNETS    105
                     CDCA(JPOSN) = CDCA(JPOSN) * 0.000001               DCNETS    106
                     CDCB(JPOSN) = CDCB(JPOSN) * 0.000001               DCNETS    107
                     BUS1 = DCLNAM(JPOSN)(1:8)                          DCNETS    108
                     BUS2 = DCLNAM(JPOSN)(9:16)                         DCNETS    109
                     LINREF(JPOSN,1) = 0                                DCNETS    110
                     LINREF(JPOSN,2) = 0                                DCNETS    111
                     DO 60 N = 1, NUMNOD                                DCNETS    112
                        IF(BUS1.EQ.IDCNOD(N))  LINREF(JPOSN,1) = N      DCNETS    113
                        IF(BUS2.EQ.IDCNOD(N))  LINREF(JPOSN,2) = N      DCNETS    114
60                   CONTINUE                                           DCNETS    115
                  ENDIF                                                 DCNETS    116
80             CONTINUE                                                 DCNETS    117
               DO 90 I=1,IBDC                                           DCNETS    118
                  IF(IDCB(I).NE.0) THEN                                 DCNETS    119
                     JPOSN=IDCB(I)                                      DCNETS    120
                     BUS1 = DCBNAM(JPOSN)(1:8)                          DCNETS    121
                     BUS2 = DCBNAM(JPOSN)(9:16)                         DCNETS    122
                     IBRKRE(JPOSN,1) = 0                                DCNETS    123
                     IBRKRE(JPOSN,2) = 0                                DCNETS    124
                     DO 85 N = 1, NUMNOD                                DCNETS    125
                        IF(BUS1.EQ.IDCNOD(N)) IBRKRE(JPOSN,1) = N       DCNETS    126
                        IF(BUS2.EQ.IDCNOD(N)) IBRKRE(JPOSN,2) = N       DCNETS    127
85                   CONTINUE                                           DCNETS    128
                  ENDIF                                                 DCNETS    129
90             CONTINUE                                                 DCNETS    130
            ENDIF                                                       DCNETS    131
C                                                                       DCNETS    132
C           Construct the G matrix.                                     DCNETS    133
C                                                                       DCNETS    134
            CALL GBUILD                                                 DCNETS    135
C                                                                       DCNETS    136
C           Set up line histories on first execution                    DCNETS    137
C                                                                       DCNETS    138
            IF(.NOT. FILLED)THEN                                        DCNETS    139
               CALL GVHIST                                              DCNETS    140
               CALL VINJCT                                              DCNETS    141
               FILLED = .TRUE.                                          DCNETS    142
C                                                                       DCNETS    143
C              Write dc solution data to binary output file.            DCNETS    144
C                                                                       DCNETS    145
               IF(LDEB)THEN                                             DCNETS    146
                  CALL DCWRIT                                           DCNETS    147
               ENDIF                                                    DCNETS    148
            ENDIF                                                       DCNETS    149
C                                                                       DCNETS    150
C           Factorize the G matix.                                      DCNETS    151
C                                                                       DCNETS    152
            CALL GFACT (JSLNVE)                                         DCNETS    153
C                                                                       DCNETS    154
            DCCHNG = .FALSE.                                            DCNETS    155
            MODCHG = .FALSE.                                            DCNETS    156
C                                                                       DCNETS    157
         ENDIF                                                          DCNETS    158
C                                                                       DCNETS    159
C                                                                       DCNETS    160
C                                                                       DCNETS    161
         IF(ACCHNG)THEN                                                 DCNETS    162
C                                                                       DCNETS    163
C           Calculate Thevenin impedance matrix.                        DCNETS    164
C                                                                       DCNETS    165
C            IF(.NOT. STAND.AND.THEVIN) CALL THEVEN                     DCNETS    166
C                                                                       DCNETS    167
C           Get pointers to injections from solution order set up       DCNETS    168
C                                                                       DCNETS    169
C            CALL SOLPTR                                                DCNETS    170
C                                                                       DCNETS    171
            ACCHNG = .FALSE.                                            DCNETS    172
C                                                                       DCNETS    173
         ENDIF                                                          DCNETS    174
C                                                                       DCNETS    175
C                                                                       DCNETS    176
C        Set flag to indicate to accumulate injection history           DCNETS    177
C                                                                       DCNETS    178
C        HISTI = .TRUE.                                                 DCNETS    179
C                                                                       DCNETS    180
C        Get the correct ac voltages to begin                           DCNETS    181
C                                                                       DCNETS    182
         CALL GETVOL                                                    DCNETS    183
C                                                                       DCNETS    184
      ENDIF                                                             DCNETS    185
C                                                                       DCNETS    186
C     Initialize the line commutation power injection at each ac bus.   DCNETS    187
C                                                                       DCNETS    188
      DO 100 NUM = 1, NACBUS                                            DCNETS    189
      PTHVDC(NUM) = 0.0                                                 DCNETS    190
100   CONTINUE                                                          DCNETS    191
C                                                                       DCNETS    192
C     Do the dc solution NSTEP times before returning to ac             DCNETS    193
C                                                                       DCNETS    194
C                                                                       DCNETS    195
      FRSTAC = .TRUE.                                                   DCNETS    196
      DO 160 I = 1, NDSTEP                                              DCNETS    197
C                                                                       DCNETS    198
C     Call UDC solution                                                 DCNETS    199
C                                                                       DCNETS    200
         FRSTDC = .TRUE.                                                DCNETS    201
C                                                                       DCNETS    202
         DO 120 J = 1, NCSTEP                                           DCNETS    203
            TIMLX = TIMLX + CTIMX                                       DCNETS    204
            TIME = TIMLX                                                DCNETS    205
            IF(DCCHNG)CALL STDCPU                                       DCNETS    206
            CALL CONVOL                                                 DCNETS    207
            CALL UDSOLN                                                 DCNETS    208
            FRSTAC = .FALSE.                                            DCNETS    209
            FRSTDC = .FALSE.                                            DCNETS    210
            NCTP = NCTP + 1                                             DCNETS    211
            IF(NCTP.EQ.NCPSTP.AND..NOT. STAND)THEN                      DCNETS    212
               NCTP = 0                                                 DCNETS    213
C               CALL BINDC (MTAPE, TIMLX, .TRUE., .FALSE.)              DCNETS    214
            ENDIF                                                       DCNETS    215
120      CONTINUE                                                       DCNETS    216
C                                                                       DCNETS    217
      CALL USPRNT(PRINT,IUD6)                                           DCNETS    218
C                                                                       DCNETS    219
      IF(SOLDC)THEN                                                     DCNETS    220
C                                                                       DCNETS    221
C           Get the converter control setpoints                         DCNETS    222
C                                                                       DCNETS    223
            CALL UDORDR                                                 DCNETS    224
C                                                                       DCNETS    225
C           Calculate converter ac voltages                             DCNETS    226
C                                                                       DCNETS    227
            IF(DCCHNG)CALL STDCPU                                       DCNETS    228
            CALL CONVOL                                                 DCNETS    229
C                                                                       DCNETS    230
C           If there was a mode change or dc change G matrix            DCNETS    231
C           must be rebuilt.                                            DCNETS    232
C                                                                       DCNETS    233
            ITCNT = 0                                                   DCNETS    234
C                                                                       DCNETS    235
140         CONTINUE                                                    DCNETS    236
            IF( DCCHNG .OR. MODCHG)THEN                                 DCNETS    237
               IF(MODCHG) SORTED = .FALSE.                              DCNETS    238
               CALL STDCPU                                              DCNETS    239
               CALL GBUILD                                              DCNETS    240
               CALL GFACT (JSLNVE)                                      DCNETS    241
               DCCHNG = .FALSE.                                         DCNETS    242
               MODCHG = .FALSE.                                         DCNETS    243
            ENDIF                                                       DCNETS    244
C                                                                       DCNETS    245
C           Build injection vector.                                     DCNETS    246
C                                                                       DCNETS    247
            CALL VINJCT                                                 DCNETS    248
C                                                                       DCNETS    249
C                                                                       DCNETS    250
C           Solve for voltage vector.                                   DCNETS    251
C                                                                       DCNETS    252
            CALL SNODEV (JSLNVE)                                        DCNETS    253
C                                                                       DCNETS    254
C           Calculate basic converter variables                         DCNETS    255
C                                                                       DCNETS    256
            COMFAL = .FALSE.                                            DCNETS    257
            NEGCUR = .FALSE.                                            DCNETS    258
C                                                                       DCNETS    259
            XTIME=TIME                                                  DCNETS    260
            CALL SDEVIC(XTIME)                                          DCNETS    261
C                                                                       DCNETS    262
            IF(NEGCUR)THEN                                              DCNETS    263
               MODCHG = .TRUE.                                          DCNETS    264
               NEGCUR = .FALSE.                                         DCNETS    265
            ENDIF                                                       DCNETS    266
C                                                                       DCNETS    267
            IF(COMFAL)THEN                                              DCNETS    268
               MODCHG = .TRUE.                                          DCNETS    269
               COMFAL = .FALSE.                                         DCNETS    270
            ENDIF                                                       DCNETS    271
C                                                                       DCNETS    272
            IF(MODCHG)THEN                                              DCNETS    273
               ITCNT = ITCNT + 1                                        DCNETS    274
               IF(ITCNT.GT.2) THEN                                      DCNETS    275
                  WRITE (MSG(1),9000) ITCNT                             DCNETS    276
                  CALL PRTMSG(1)                                        DCNETS    277
               ENDIF                                                    DCNETS    278
               IF(ITCNT .GT. 5)THEN                                     DCNETS    279
               MSG(1)='FAILURE IN DC SOLUTION...TOO MANY ITERATIONS'    DCNETS    280
               CALL ASTOP(MSG(1),54)                                    DCNETS    281
               ENDIF                                                    DCNETS    282
               GOTO 140                                                 DCNETS    283
            ENDIF                                                       DCNETS    284
C                                                                       DCNETS    285
C                                                                       DCNETS    286
C           Calculate the real and reactive power flows for the         DCNETS    287
C           converters.                                                 DCNETS    288
C                                                                       DCNETS    289
            INIT = 1                                                    DCNETS    290
            CALL SPOWER(INIT)                                           DCNETS    291
C                                                                       DCNETS    292
C                                                                       DCNETS    293
C           Calculate the history terms for line models.                DCNETS    294
C                                                                       DCNETS    295
            CALL HLINE                                                  DCNETS    296
C                                                                       DCNETS    297
C           Calculate the total line commutation current injection      DCNETS    298
C           for each ac bus.                                            DCNETS    299
C                                                                       DCNETS    300
            CALL BINJCT                                                 DCNETS    301
C                                                                       DCNETS    302
C           Update converter bus voltages from Thevenin equivalent.     DCNETS    303
C                                                                       DCNETS    304
C            IF(THEVIN) CALL TVUPDT                                     DCNETS    305
C                                                                       DCNETS    306
C           Write dc solution data to output file.                      DCNETS    307
C                                                                       DCNETS    308
            IF(LDEB) CALL DCWRIT                                        DCNETS    309
            NDTP = NDTP + 1                                             DCNETS    310
            IF(NDTP.EQ.NDPSTP.AND..NOT. STAND)THEN                      DCNETS    311
               NDTP = 0                                                 DCNETS    312
C               CALL BINDC (MTAPE, TIMLX, .FALSE., .TRUE.)              DCNETS    313
            ENDIF                                                       DCNETS    314
C                                                                       DCNETS    315
         ENDIF                                                          DCNETS    316
C                                                                       DCNETS    317
         FRSTAC = .FALSE.                                               DCNETS    318
C                                                                       DCNETS    319
160   CONTINUE                                                          DCNETS    320
C                                                                       DCNETS    321
C     The effect of the current injection on the ac solution.           DCNETS    322
C                                                                       DCNETS    323
      IF(SOLDC) CALL DCEFCT                                             DCNETS    324
C                                                                       DCNETS    325
C                                                                       DCNETS    326
C---------------------------------------------------------------------  DCNETS    327
C                                                                       DCNETS    328
      RETURN                                                            DCNETS    329
C                                                                       DCNETS    330
C---------------------------------------------------------------------  DCNETS    331
C                                                                       DCNETS    332
 9000 FORMAT(' *** CALCULATION ITERATION ',I2,' FOR DC SOLUTION')       DCNETS    333
C                                                                       DCNETS    334
C---------------------------------------------------------------------  DCNETS    335
C                                                                       DCNETS    336
      END                                                               DCNETS    337
      SUBROUTINE DCNET1                                                 DCNETS    338
CD -------------------------------------------------------------------  DCNETS    339
CD                                                                      DCNETS    340
CD              *****     DCNET1  ROUTINE   *****                       DCNETS    341
CD                                                                      DCNETS    342
CD -------------------------------------------------------------------  DCNETS    343
CD                                                                      DCNETS    344
CD       PURPOSE: Simlified DC Converter Solution Routine.              DCNETS    345
CD                It uses a decoupled converter model, where            DCNETS    346
CD                P and Q injections are functions of the               DCNETS    347
CD                converter ac voltage only, i.e., converters           DCNETS    348
CD                represented like a kind of nonlinear load.            DCNETS    349
CD                                                                      DCNETS    350
CD                                                                      DCNETS    351
CD -------------------------------------------------------------------  DCNETS    352
      INCLUDE 'PARX.INS'                                                DCNETS    353
      INCLUDE 'CNPT.INS'                                                DCNETS    354
      INCLUDE 'GRPDCS.INS'                                              DCNETS    355
      INCLUDE 'UDCG.INS'                                                DCNETS    356
C                                                                       DCNETS    357
C---------------------------------------------------------------------  DCNETS    358
C                                                                       DCNETS    359
C     Get the correct ac voltages to begin                              DCNETS    360
C                                                                       DCNETS    361
      CALL GETVOL                                                       DCNETS    362
C                                                                       DCNETS    363
C     Initialize the line commutation power injection at each ac bus.   DCNETS    364
C                                                                       DCNETS    365
      DO 170 NUM = 1, NACBUS                                            DCNETS    366
      PTHVDC(NUM) = 0.0                                                 DCNETS    367
  170 CONTINUE                                                          DCNETS    368
C                                                                       DCNETS    369
C     Calculate the real and reactive power flows for the converters.   DCNETS    370
C                                                                       DCNETS    371
      INIT = 1                                                          DCNETS    372
      CALL SPOWER(INIT)                                                 DCNETS    373
C                                                                       DCNETS    374
C     Calculate the total line commutation current injection            DCNETS    375
C     for each ac bus.                                                  DCNETS    376
C                                                                       DCNETS    377
      CALL BINJCT                                                       DCNETS    378
C                                                                       DCNETS    379
C     The effect of the current injection on the ac solution.           DCNETS    380
C                                                                       DCNETS    381
      NDSTEP=1                                                          DCNETS    382
      CALL DCEFCT                                                       DCNETS    383
C                                                                       DCNETS    384
C---------------------------------------------------------------------  DCNETS    385
C                                                                       DCNETS    386
      RETURN                                                            DCNETS    387
C                                                                       DCNETS    388
C---------------------------------------------------------------------  DCNETS    389
C                                                                       DCNETS    390
      END                                                               DCNETS    391
