File indexing completed on 2020-04-22 05:11:27 UTC
view on githubraw file Latest commit 07e78522 on 2020-04-21 13:33:29 UTC
5ca83cd8f7 Dani*0001 #include "STREAMICE_OPTIONS.h"
0002
0003
0004
0005
07e785229e dngo*0006 SUBROUTINE STREAMICE_CG_SOLVE(
5ca83cd8f7 Dani*0007 U cg_Uin,
0008 U cg_Vin,
0009 I cg_Bu,
0010 I cg_Bv,
0011 I A_uu,
0012 I A_uv,
0013 I A_vu,
0014 I A_vv,
07e785229e dngo*0015 I tolerance,
5ca83cd8f7 Dani*0016 O iters,
d2cdb9260d Dani*0017 I maxIter,
5ca83cd8f7 Dani*0018 I myThid )
0019
07e785229e dngo*0020
5ca83cd8f7 Dani*0021
0022
0023
0024
0025 IMPLICIT NONE
0026
0027 #include "SIZE.h"
0028 #include "EEPARAMS.h"
0029 #include "PARAMS.h"
0030 #include "STREAMICE.h"
0031 #include "STREAMICE_CG.h"
0032
07e785229e dngo*0033
0034
0035
0036
0037
0038
0039
0040
5ca83cd8f7 Dani*0041
0042
0043
0044
0045
0046 INTEGER myThid
0047 INTEGER iters
d2cdb9260d Dani*0048 INTEGER maxIter
5ca83cd8f7 Dani*0049 _RL tolerance
0050 _RL cg_Uin (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
0051 _RL cg_Vin (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
0052 _RL cg_Bu (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
0053 _RL cg_Bv (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
07e785229e dngo*0054 _RL
5ca83cd8f7 Dani*0055 & A_uu (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy,-1:1,-1:1),
0056 & A_vu (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy,-1:1,-1:1),
0057 & A_uv (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy,-1:1,-1:1),
0058 & A_vv (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy,-1:1,-1:1)
0059
0060
0061 INTEGER i, j, bi, bj, cg_halo, conv_flag
07e785229e dngo*0062 INTEGER iter, is, js, ie, je, colx, coly
5ca83cd8f7 Dani*0063 _RL dot_p1, dot_p2, alpha_k, beta_k, resid, resid_0
0064 _RL dot_p1_tile (nSx,nSy)
0065 _RL dot_p2_tile (nSx,nSy)
0066 CHARACTER*(MAX_LEN_MBUF) msgBuf
0067
07e785229e dngo*0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
5ca83cd8f7 Dani*0088
0089 #ifdef ALLOW_STREAMICE
0090
0091 CALL TIMER_START ('STREAMICE_CG_SOLVE',myThid)
0092 #ifndef STREAMICE_SERIAL_TRISOLVE
0093
0094 #ifdef ALLOW_PETSC
0095
07e785229e dngo*0096 #ifndef ALLOW_OPENAD
0097 if (streamice_use_petsc.and.petscFlag.eq.1) then
0098 #else
18a089944d Dani*0099 if (streamice_use_petsc) then
07e785229e dngo*0100 #endif
18a089944d Dani*0101
67b4a2b594 Dani*0102 CALL STREAMICE_CG_SOLVE_PETSC(
0103 U cg_Uin,
0104 U cg_Vin,
0105 I cg_Bu,
0106 I cg_Bv,
0107 I A_uu,
0108 I A_uv,
0109 I A_vu,
0110 I A_vv,
0111 I tolerance,
78b0c9990f Dani*0112 I iters,
0113 O maxiter,
67b4a2b594 Dani*0114 I myThid )
5ca83cd8f7 Dani*0115
18a089944d Dani*0116 else
0117
0118 #endif /* ALLOW_PETSC */
5ca83cd8f7 Dani*0119
d2cdb9260d Dani*0120 iters = maxIter
5ca83cd8f7 Dani*0121 conv_flag = 0
0122
0123 DO bj = myByLo(myThid), myByHi(myThid)
0124 DO bi = myBxLo(myThid), myBxHi(myThid)
0125 DO j=1,sNy
0126 DO i=1,sNx
0127 Zu_SI (i,j,bi,bj) = 0. _d 0
0128 Zv_SI (i,j,bi,bj) = 0. _d 0
0129 Ru_SI (i,j,bi,bj) = 0. _d 0
0130 Rv_SI (i,j,bi,bj) = 0. _d 0
0131 Au_SI (i,j,bi,bj) = 0. _d 0
0132 Av_SI (i,j,bi,bj) = 0. _d 0
0133 Du_SI (i,j,bi,bj) = 0. _d 0
0134 Dv_SI (i,j,bi,bj) = 0. _d 0
0135 ENDDO
0136 ENDDO
0137 ENDDO
0138 ENDDO
0139
07e785229e dngo*0140
5ca83cd8f7 Dani*0141
07e785229e dngo*0142
5ca83cd8f7 Dani*0143
0144 DO bj = myByLo(myThid), myByHi(myThid)
0145 DO bi = myBxLo(myThid), myBxHi(myThid)
0146 DO j=1,sNy
0147 DO i=1,sNx
0148 DO colx=-1,1
0149 DO coly=-1,1
07e785229e dngo*0150 Au_SI(i,j,bi,bj) = Au_SI(i,j,bi,bj) +
5ca83cd8f7 Dani*0151 & A_uu(i,j,bi,bj,colx,coly)*
0152 & cg_Uin(i+colx,j+coly,bi,bj)+
07e785229e dngo*0153 & A_uv(i,j,bi,bj,colx,coly)*
5ca83cd8f7 Dani*0154 & cg_Vin(i+colx,j+coly,bi,bj)
0155
07e785229e dngo*0156 Av_SI(i,j,bi,bj) = Av_SI(i,j,bi,bj) +
5ca83cd8f7 Dani*0157 & A_vu(i,j,bi,bj,colx,coly)*
0158 & cg_Uin(i+colx,j+coly,bi,bj)+
07e785229e dngo*0159 & A_vv(i,j,bi,bj,colx,coly)*
5ca83cd8f7 Dani*0160 & cg_Vin(i+colx,j+coly,bi,bj)
0161 ENDDO
0162 ENDDO
0163 ENDDO
0164 ENDDO
0165 ENDDO
0166 ENDDO
0167
0168 _EXCH_XY_RL( Au_SI, myThid )
0169 _EXCH_XY_RL( Av_SI, myThid )
0170
0171 DO bj = myByLo(myThid), myByHi(myThid)
0172 DO bi = myBxLo(myThid), myBxHi(myThid)
0173 DO j=1-OLy,sNy+OLy
0174 DO i=1-OLx,sNx+OLx
0175 Ru_SI(i,j,bi,bj)=cg_Bu(i,j,bi,bj)-
0176 & Au_SI(i,j,bi,bj)
0177 Rv_SI(i,j,bi,bj)=cg_Bv(i,j,bi,bj)-
0178 & Av_SI(i,j,bi,bj)
0179 ENDDO
0180 ENDDO
0181 dot_p1_tile(bi,bj) = 0. _d 0
07e785229e dngo*0182 dot_p2_tile(bi,bj) = 0. _d 0
5ca83cd8f7 Dani*0183 ENDDO
0184 ENDDO
0185
0186 DO bj = myByLo(myThid), myByHi(myThid)
0187 DO bi = myBxLo(myThid), myBxHi(myThid)
0188 DO j=1,sNy
0189 DO i=1,sNx
0190 IF (STREAMICE_umask(i,j,bi,bj).eq.1.0)
0191 & dot_p1_tile(bi,bj)=dot_p1_tile(bi,bj)+Ru_SI(i,j,bi,bj)**2
0192 IF (STREAMICE_vmask(i,j,bi,bj).eq.1.0)
0193 & dot_p1_tile(bi,bj)=dot_p1_tile(bi,bj)+Rv_SI(i,j,bi,bj)**2
0194 ENDDO
0195 ENDDO
0196 ENDDO
0197 ENDDO
0198
07e785229e dngo*0199 CALL GLOBAL_SUM_TILE_RL( dot_p1_tile, dot_p1, myThid )
5ca83cd8f7 Dani*0200 resid_0 = sqrt(dot_p1)
0201
223e7922c4 Dani*0202 DO bj = myByLo(myThid), myByHi(myThid)
0203 DO bi = myBxLo(myThid), myBxHi(myThid)
0204
0205 WRITE(msgBuf,'(A,I1,I1,E14.7)') 'CONJ GRAD INIT RESID LOCAL, ',
0206 & bi,bj, dot_p1_tile(bi,bj)
0207 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
0208 & SQUEEZE_RIGHT , 1)
0209
0210 enddo
0211 enddo
0212
5ca83cd8f7 Dani*0213 WRITE(msgBuf,'(A,E14.7)') 'CONJ GRAD INIT RESID, ',
0214 & resid_0
0215 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
0216 & SQUEEZE_RIGHT , 1)
0217
0218
0219
0220 DO bj = myByLo(myThid), myByHi(myThid)
0221 DO bi = myBxLo(myThid), myBxHi(myThid)
0222 DO j=1-OLy,sNy+OLy
0223 DO i=1-OLx,sNx+OLx
0224 IF (STREAMICE_umask(i,j,bi,bj).eq.1.0)
0225 & Zu_SI(i,j,bi,bj)=Ru_SI(i,j,bi,bj) / DIAGu_SI(i,j,bi,bj)
0226 IF (STREAMICE_vmask(i,j,bi,bj).eq.1.0)
0227 & Zv_SI(i,j,bi,bj)=Rv_SI(i,j,bi,bj) / DIAGv_SI(i,j,bi,bj)
0228 ENDDO
0229 ENDDO
0230 ENDDO
0231 ENDDO
0232
0233 cg_halo = min(OLx-1,OLy-1)
0234 conv_flag = 0
0235
0236 DO bj = myByLo(myThid), myByHi(myThid)
0237 DO bi = myBxLo(myThid), myBxHi(myThid)
0238 DO j=1-OLy,sNy+OLy
0239 DO i=1-OLx,sNx+OLx
07e785229e dngo*0240 Du_SI(i,j,bi,bj)=Zu_SI(i,j,bi,bj)
5ca83cd8f7 Dani*0241 Dv_SI(i,j,bi,bj)=Zv_SI(i,j,bi,bj)
0242 ENDDO
0243 ENDDO
0244 ENDDO
0245 ENDDO
0246
0247 resid = resid_0
0248 iters = 0
07e785229e dngo*0249
5ca83cd8f7 Dani*0250
0251
0252
0253
0254
0255
0256
0257
0258 WRITE(msgBuf,'(A)') 'BEGINNING MAIN CG LOOP'
0259 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
0260 & SQUEEZE_RIGHT , 1)
0261
07e785229e dngo*0262
5ca83cd8f7 Dani*0263
d2cdb9260d Dani*0264 do iter = 1, maxIter
5ca83cd8f7 Dani*0265 if (resid .gt. tolerance*resid_0) then
0266
0267
0268 iters = iters + 1
0269
07e785229e dngo*0270 is = 1 - cg_halo
0271 ie = sNx + cg_halo
0272 js = 1 - cg_halo
5ca83cd8f7 Dani*0273 je = sNy + cg_halo
07e785229e dngo*0274
5ca83cd8f7 Dani*0275 DO bj = myByLo(myThid), myByHi(myThid)
0276 DO bi = myBxLo(myThid), myBxHi(myThid)
0277 DO j=1-OLy,sNy+OLy
07e785229e dngo*0278 DO i=1-OLx,sNx+OLx
5ca83cd8f7 Dani*0279 Au_SI(i,j,bi,bj) = 0. _d 0
0280 Av_SI(i,j,bi,bj) = 0. _d 0
0281 ENDDO
0282 ENDDO
0283 ENDDO
0284 ENDDO
0285
07e785229e dngo*0286
5ca83cd8f7 Dani*0287
07e785229e dngo*0288
5ca83cd8f7 Dani*0289
0290 DO bj = myByLo(myThid), myByHi(myThid)
0291 DO bi = myBxLo(myThid), myBxHi(myThid)
0292 DO j=js,je
0293 DO i=is,ie
0294 DO colx=-1,1
0295 DO coly=-1,1
07e785229e dngo*0296 Au_SI(i,j,bi,bj) = Au_SI(i,j,bi,bj) +
5ca83cd8f7 Dani*0297 & A_uu(i,j,bi,bj,colx,coly)*
0298 & Du_SI(i+colx,j+coly,bi,bj)+
07e785229e dngo*0299 & A_uv(i,j,bi,bj,colx,coly)*
5ca83cd8f7 Dani*0300 & Dv_SI(i+colx,j+coly,bi,bj)
07e785229e dngo*0301 Av_SI(i,j,bi,bj) = Av_SI(i,j,bi,bj) +
5ca83cd8f7 Dani*0302 & A_vu(i,j,bi,bj,colx,coly)*
0303 & Du_SI(i+colx,j+coly,bi,bj)+
07e785229e dngo*0304 & A_vv(i,j,bi,bj,colx,coly)*
5ca83cd8f7 Dani*0305 & Dv_SI(i+colx,j+coly,bi,bj)
0306 ENDDO
0307 ENDDO
0308 ENDDO
0309 ENDDO
0310 ENDDO
0311 ENDDO
0312
07e785229e dngo*0313
0314
0315
0316
0317
0318
0319
0320
0321
0322
0323
0324
0325
5ca83cd8f7 Dani*0326
0327 DO bj = myByLo(myThid), myByHi(myThid)
0328 DO bi = myBxLo(myThid), myBxHi(myThid)
0329 dot_p1_tile(bi,bj) = 0. _d 0
07e785229e dngo*0330 dot_p2_tile(bi,bj) = 0. _d 0
5ca83cd8f7 Dani*0331 ENDDO
0332 ENDDO
0333
0334 DO bj = myByLo(myThid), myByHi(myThid)
0335 DO bi = myBxLo(myThid), myBxHi(myThid)
0336 DO j=1,sNy
0337 DO i=1,sNx
0338 IF (STREAMICE_umask(i,j,bi,bj).eq.1.0) THEN
0339 dot_p1_tile(bi,bj)=dot_p1_tile(bi,bj)+Zu_SI(i,j,bi,bj)*
0340 & Ru_SI(i,j,bi,bj)
0341 dot_p2_tile(bi,bj)=dot_p2_tile(bi,bj)+Du_SI(i,j,bi,bj)*
0342 & Au_SI(i,j,bi,bj)
0343 ENDIF
0344 IF (STREAMICE_vmask(i,j,bi,bj).eq.1.0) THEN
0345 dot_p1_tile(bi,bj)=dot_p1_tile(bi,bj)+Zv_SI(i,j,bi,bj)*
0346 & Rv_SI(i,j,bi,bj)
0347 dot_p2_tile(bi,bj)=dot_p2_tile(bi,bj)+Dv_SI(i,j,bi,bj)*
0348 & Av_SI(i,j,bi,bj)
0349 ENDIF
0350 ENDDO
0351 ENDDO
0352 ENDDO
0353 ENDDO
0354
0355 CALL GLOBAL_SUM_TILE_RL( dot_p1_tile, dot_p1, myThid )
07e785229e dngo*0356 CALL GLOBAL_SUM_TILE_RL( dot_p2_tile, dot_p2, myThid )
5ca83cd8f7 Dani*0357 alpha_k = dot_p1/dot_p2
0358
0359 DO bj = myByLo(myThid), myByHi(myThid)
0360 DO bi = myBxLo(myThid), myBxHi(myThid)
0361 DO j=1-OLy,sNy+OLy
0362 DO i=1-OLx,sNx+OLx
0363
0364 IF (STREAMICE_umask(i,j,bi,bj).eq.1.0) THEN
0365 cg_Uin(i,j,bi,bj)=cg_Uin(i,j,bi,bj)+
0366 & alpha_k*Du_SI(i,j,bi,bj)
0367 Ru_old_SI(i,j,bi,bj) = Ru_SI(i,j,bi,bj)
0368 Zu_old_SI(i,j,bi,bj) = Zu_SI(i,j,bi,bj)
0369 Ru_SI(i,j,bi,bj) = Ru_SI(i,j,bi,bj)-
0370 & alpha_k*Au_SI(i,j,bi,bj)
07e785229e dngo*0371 Zu_SI(i,j,bi,bj) = Ru_SI(i,j,bi,bj) /
5ca83cd8f7 Dani*0372 & DIAGu_SI(i,j,bi,bj)
0373 ENDIF
0374
0375 IF (STREAMICE_vmask(i,j,bi,bj).eq.1.0) THEN
0376 cg_Vin(i,j,bi,bj)=cg_Vin(i,j,bi,bj)+
0377 & alpha_k*Dv_SI(i,j,bi,bj)
0378 Rv_old_SI(i,j,bi,bj) = Rv_SI(i,j,bi,bj)
0379 Zv_old_SI(i,j,bi,bj) = Zv_SI(i,j,bi,bj)
0380 Rv_SI(i,j,bi,bj) = Rv_SI(i,j,bi,bj)-
0381 & alpha_k*Av_SI(i,j,bi,bj)
07e785229e dngo*0382 Zv_SI(i,j,bi,bj) = Rv_SI(i,j,bi,bj) /
5ca83cd8f7 Dani*0383 & DIAGv_SI(i,j,bi,bj)
0384
0385 ENDIF
0386 ENDDO
0387 ENDDO
0388 ENDDO
0389 ENDDO
0390
0391 DO bj = myByLo(myThid), myByHi(myThid)
0392 DO bi = myBxLo(myThid), myBxHi(myThid)
0393 dot_p1_tile(bi,bj) = 0. _d 0
07e785229e dngo*0394 dot_p2_tile(bi,bj) = 0. _d 0
5ca83cd8f7 Dani*0395 ENDDO
0396 ENDDO
0397
0398 DO bj = myByLo(myThid), myByHi(myThid)
0399 DO bi = myBxLo(myThid), myBxHi(myThid)
0400 DO j=1,sNy
0401 DO i=1,sNx
0402
0403 IF (STREAMICE_umask(i,j,bi,bj).eq.1.0) THEN
0404 dot_p1_tile(bi,bj)=dot_p1_tile(bi,bj)+Zu_SI(i,j,bi,bj)*
0405 & Ru_SI(i,j,bi,bj)
0406 dot_p2_tile(bi,bj)=dot_p2_tile(bi,bj)+Zu_old_SI(i,j,bi,bj)*
0407 & Ru_old_SI(i,j,bi,bj)
0408 ENDIF
0409
0410 IF (STREAMICE_vmask(i,j,bi,bj).eq.1.0) THEN
0411 dot_p1_tile(bi,bj)=dot_p1_tile(bi,bj)+Zv_SI(i,j,bi,bj)*
0412 & Rv_SI(i,j,bi,bj)
0413 dot_p2_tile(bi,bj)=dot_p2_tile(bi,bj)+Zv_old_SI(i,j,bi,bj)*
0414 & Rv_old_SI(i,j,bi,bj)
0415 ENDIF
0416
0417 ENDDO
0418 ENDDO
0419 ENDDO
0420 ENDDO
0421
0422 CALL GLOBAL_SUM_TILE_RL( dot_p1_tile, dot_p1, myThid )
0423 CALL GLOBAL_SUM_TILE_RL( dot_p2_tile, dot_p2, myThid )
07e785229e dngo*0424
5ca83cd8f7 Dani*0425 beta_k = dot_p1/dot_p2
0426
0427 DO bj = myByLo(myThid), myByHi(myThid)
0428 DO bi = myBxLo(myThid), myBxHi(myThid)
0429 DO j=1-OLy,sNy+OLy
0430 DO i=1-OLx,sNx+OLx
07e785229e dngo*0431 IF (STREAMICE_umask(i,j,bi,bj).eq.1.0)
5ca83cd8f7 Dani*0432 & Du_SI(i,j,bi,bj)=beta_k*Du_SI(i,j,bi,bj)+
0433 & Zu_SI(i,j,bi,bj)
07e785229e dngo*0434 IF (STREAMICE_vmask(i,j,bi,bj).eq.1.0)
5ca83cd8f7 Dani*0435 & Dv_SI(i,j,bi,bj)=beta_k*Dv_SI(i,j,bi,bj)+
0436 & Zv_SI(i,j,bi,bj)
0437 ENDDO
0438 ENDDO
0439 ENDDO
0440 ENDDO
0441
0442 DO bj = myByLo(myThid), myByHi(myThid)
0443 DO bi = myBxLo(myThid), myBxHi(myThid)
0444 dot_p1_tile(bi,bj) = 0. _d 0
0445 ENDDO
0446 ENDDO
0447
0448 DO bj = myByLo(myThid), myByHi(myThid)
0449 DO bi = myBxLo(myThid), myBxHi(myThid)
0450 DO j=1,sNy
0451 DO i=1,sNx
0452 IF (STREAMICE_umask(i,j,bi,bj).eq.1.0)
0453 & dot_p1_tile(bi,bj)=dot_p1_tile(bi,bj)+Ru_SI(i,j,bi,bj)**2
0454 IF (STREAMICE_vmask(i,j,bi,bj).eq.1.0)
0455 & dot_p1_tile(bi,bj)=dot_p1_tile(bi,bj)+Rv_SI(i,j,bi,bj)**2
0456 ENDDO
0457 ENDDO
0458 ENDDO
0459 ENDDO
0460
07e785229e dngo*0461 CALL GLOBAL_SUM_TILE_RL( dot_p1_tile, dot_p1, myThid )
5ca83cd8f7 Dani*0462 resid = sqrt(dot_p1)
0463
07e785229e dngo*0464
0465
0466
5ca83cd8f7 Dani*0467
0468 cg_halo = cg_halo - 1
0469
0470 if (cg_halo .eq. 0) then
0471 cg_halo = min(OLx-1,OLy-1)
0472 _EXCH_XY_RL( Du_SI, myThid )
0473 _EXCH_XY_RL( Dv_SI, myThid )
0474 _EXCH_XY_RL( Ru_SI, myThid )
0475 _EXCH_XY_RL( Rv_SI, myThid )
0476 _EXCH_XY_RL( cg_Uin, myThid )
0477 _EXCH_XY_RL( cg_Vin, myThid )
0478 endif
0479
0480 endif
0481 enddo
07e785229e dngo*0482
5ca83cd8f7 Dani*0483
0484
07e785229e dngo*0485
d2cdb9260d Dani*0486 IF (iters .lt. maxIter) THEN
5ca83cd8f7 Dani*0487 conv_flag = 1
0488 ENDIF
95afe7199b Dani*0489 PRINT *, "GOT HERE CG ITERATIONS", iters
5ca83cd8f7 Dani*0490
07e785229e dngo*0491
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501
0502
0503
0504
0505
18a089944d Dani*0506
0507 #ifdef ALLOW_PETSC
0508 endif
0509 #endif
5ca83cd8f7 Dani*0510
0511 #else /* STREAMICE_SERIAL_TRISOLVE */
0512
af8b28c42b Dani*0513 iters = 0
0514
07e785229e dngo*0515 CALL STREAMICE_TRIDIAG_SOLVE(
5ca83cd8f7 Dani*0516 U cg_Uin,
0517 U cg_Vin,
0518 U cg_Bu,
0519 I A_uu,
0520 I STREAMICE_umask,
0521 I myThid )
0522
0523 #endif
0524
0525 CALL TIMER_STOP ('STREAMICE_CG_SOLVE',myThid)
0526
0527 #endif
0528 RETURN
0529 END