File indexing completed on 2024-05-11 05:10:22 UTC
view on githubraw file Latest commit 41c4545f on 2024-05-10 15:00:41 UTC
d5ada4102b Jean*0001 #include "DIAG_OPTIONS.h"
0002
0003
0004
0005
0006
0007
0008 SUBROUTINE DIAGNOSTICS_CALC_PHIVEL(
0009 I listId, md, ndId, ip, im, lm,
bc85e7ab92 Jean*0010 I NrMax,
48a533dac6 Jean*0011 U qtmp1, qtmp2,
d5ada4102b Jean*0012 I myTime, myIter, myThid )
0013
0014
bc85e7ab92 Jean*0015
d5ada4102b Jean*0016
0017
0018 IMPLICIT NONE
0019 #include "SIZE.h"
0020 #include "EEPARAMS.h"
0021 #include "PARAMS.h"
0022 #include "GRID.h"
0023 #include "DIAGNOSTICS_SIZE.h"
0024 #include "DIAGNOSTICS.h"
49d8041f88 Jean*0025 #include "DIAGNOSTICS_CALC.h"
d5ada4102b Jean*0026
0027
0028
0029
0030
0031
0032
0033
bc85e7ab92 Jean*0034
48a533dac6 Jean*0035
0036
d5ada4102b Jean*0037
0038
0039
0040 INTEGER listId, md, ndId, ip, im, lm
bc85e7ab92 Jean*0041 INTEGER NrMax
d5ada4102b Jean*0042 _RL qtmp1(1-OLx:sNx+OLx,1-OLy:sNy+OLy,NrMax,nSx,nSy)
0043 _RL qtmp2(1-OLx:sNx+OLx,1-OLy:sNy+OLy,NrMax,nSx,nSy)
0044 _RL myTime
0045 INTEGER myIter, myThid
48a533dac6 Jean*0046
0047
0048
0049
d5ada4102b Jean*0050
0051
0052
bc85e7ab92 Jean*0053 INTEGER ILNBLNK
0054 EXTERNAL ILNBLNK
d5ada4102b Jean*0055
0056
bc85e7ab92 Jean*0057
0058
0059
0060
0061
0062
d5ada4102b Jean*0063 INTEGER bi, bj
bc85e7ab92 Jean*0064 INTEGER i, j, k
d5ada4102b Jean*0065
48a533dac6 Jean*0066 INTEGER ks
d53cbeab8e Jean*0067 INTEGER numIters, nIterMin
d5ada4102b Jean*0068 LOGICAL normaliseMatrice, diagNormaliseRHS
d53cbeab8e Jean*0069 _RL residCriter, firstResidual, minResidual, lastResidual
d5ada4102b Jean*0070 _RL a2dMax, a2dNorm
bdbdc9dd8f Jean*0071 _RL rhsMax, b2dNorm, x2dNorm
d5ada4102b Jean*0072 _RS aW2d(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
0073 _RS aS2d(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
0074 _RL b2d (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
0075 _RL x2d (1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
bc85e7ab92 Jean*0076 _RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
0077 _RL vTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
0078 _RL psiVel(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy)
0079 _RL psiLoc(2)
0080 INTEGER iL
0081 CHARACTER*(MAX_LEN_FNAM) dataFName
0082 CHARACTER*(MAX_LEN_MBUF) msgBuf
d5ada4102b Jean*0083
0084
0085
5ce5806717 Jean*0086 #ifdef ALLOW_DEBUG
0087 IF (debugMode) CALL DEBUG_ENTER('DIAGNOSTICS_CALC_PHIVEL',myThid)
0088 #endif
0089
bdbdc9dd8f Jean*0090 DO ks = 1,nlevels(listId)
48a533dac6 Jean*0091 k = NINT(levs(ks,listId))
d5ada4102b Jean*0092
0093
0094 a2dMax = 0. _d 0
0095 rhsMax = 0. _d 0
0096 DO bj = myByLo(myThid), myByHi(myThid)
0097 DO bi = myBxLo(myThid), myBxHi(myThid)
0098
a63b8f5615 Jean*0099 DO j = 1-OLy,sNy+OLy
0100 DO i = 1-OLx,sNx+OLx
d5ada4102b Jean*0101 b2d(i,j,bi,bj) = 0.
0102 x2d(i,j,bi,bj) = 0.
0103 ENDDO
0104 ENDDO
0105
c8934cd63f Jean*0106
0107
d5ada4102b Jean*0108 DO j = 1,sNy+1
0109 DO i = 1,sNx+1
0110 aW2d(i,j,bi,bj) = dyG(i,j,bi,bj)*recip_dxC(i,j,bi,bj)
0111 & *drF(k)*hFacW(i,j,k,bi,bj)
c8934cd63f Jean*0112 & *maskInW(i,j,bi,bj)
d5ada4102b Jean*0113 aS2d(i,j,bi,bj) = dxG(i,j,bi,bj)*recip_dyC(i,j,bi,bj)
0114 & *drF(k)*hFacS(i,j,k,bi,bj)
c8934cd63f Jean*0115 & *maskInS(i,j,bi,bj)
d5ada4102b Jean*0116 a2dMax = MAX(a2dMax,aW2d(i,j,bi,bj))
0117 a2dMax = MAX(a2dMax,aS2d(i,j,bi,bj))
0118 ENDDO
0119 ENDDO
0120
bdbdc9dd8f Jean*0121
d5ada4102b Jean*0122 DO j = 1,sNy+1
0123 DO i = 1,sNx+1
bc85e7ab92 Jean*0124 uTrans(i,j,bi,bj) = dyG(i,j,bi,bj)*drF(k)
0125 & *qtmp1(i,j,ks,bi,bj)*maskInW(i,j,bi,bj)
0126 vTrans(i,j,bi,bj) = dxG(i,j,bi,bj)*drF(k)
0127 & *qtmp2(i,j,ks,bi,bj)*maskInS(i,j,bi,bj)
d5ada4102b Jean*0128 ENDDO
0129 ENDDO
bdbdc9dd8f Jean*0130
0131 ENDDO
0132 ENDDO
0133
0134
0135 DO bj = myByLo(myThid), myByHi(myThid)
0136 DO bi = myBxLo(myThid), myBxHi(myThid)
d5ada4102b Jean*0137 DO j = 1,sNy
0138 DO i = 1,sNx
bc85e7ab92 Jean*0139 b2d(i,j,bi,bj) = (
0140 & ( uTrans(i+1,j,bi,bj) - uTrans(i,j,bi,bj) )
0141 & + ( vTrans(i,j+1,bi,bj) - vTrans(i,j,bi,bj) )
d5ada4102b Jean*0142 & )*maskInC(i,j,bi,bj)
0143 ENDDO
0144 ENDDO
0145 ENDDO
0146 ENDDO
0147
c8934cd63f Jean*0148 #ifdef ALLOW_OBCS
2b093fab14 Jean*0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
c8934cd63f Jean*0163 IF ( useOBCS ) THEN
0164 CALL OBCS_DIAG_BALANCE(
0165 U b2d,
0166 I uTrans, vTrans, k,
0167 I myTime, myIter, myThid )
0168 ENDIF
0169 #endif /* ALLOW_OBCS */
0170
d5ada4102b Jean*0171
d53cbeab8e Jean*0172 diagNormaliseRHS = diagCG_resTarget.GT.0.
d5ada4102b Jean*0173 normaliseMatrice = .TRUE.
0174 diagNormaliseRHS = .TRUE.
2b093fab14 Jean*0175 IF ( diagNormaliseRHS ) THEN
0176 DO bj = myByLo(myThid), myByHi(myThid)
0177 DO bi = myBxLo(myThid), myBxHi(myThid)
0178 DO j = 1,sNy
0179 DO i = 1,sNx
41c4545f8f Jean*0180 rhsMax = MAX(ABS(b2d(i,j,bi,bj)),rhsMax)
2b093fab14 Jean*0181 ENDDO
0182 ENDDO
0183 ENDDO
0184 ENDDO
0185 ENDIF
d5ada4102b Jean*0186 a2dNorm = 1. _d 0
bdbdc9dd8f Jean*0187 b2dNorm = 1. _d 0
0188 x2dNorm = 1. _d 0
d5ada4102b Jean*0189 IF ( normaliseMatrice ) THEN
0190 _GLOBAL_MAX_RL( a2dMax, myThid )
49d8041f88 Jean*0191 IF ( a2dMax .GT. 0. _d 0 ) a2dNorm = 1. _d 0/a2dMax
bdbdc9dd8f Jean*0192 b2dNorm = a2dNorm
d5ada4102b Jean*0193 ENDIF
0194 IF ( diagNormaliseRHS ) THEN
0195 _GLOBAL_MAX_RL( rhsMax, myThid )
bdbdc9dd8f Jean*0196 IF ( rhsMax .GT. 0. _d 0 ) THEN
0197 b2dNorm = 1. _d 0/rhsMax
0198 x2dNorm = a2dNorm*rhsMax
0199 ENDIF
d53cbeab8e Jean*0200 residCriter = diagCG_resTarget
d5ada4102b Jean*0201 ELSE
d53cbeab8e Jean*0202 residCriter = a2dNorm * ABS(diagCG_resTarget)
a63b8f5615 Jean*0203 & * globalArea / deltaTMom
d5ada4102b Jean*0204 ENDIF
0205 IF ( normaliseMatrice .OR. diagNormaliseRHS ) THEN
0206 DO bj = myByLo(myThid), myByHi(myThid)
0207 DO bi = myBxLo(myThid), myBxHi(myThid)
0208 DO j = 1,sNy+1
0209 DO i = 1,sNx+1
0210 aW2d(i,j,bi,bj) = aW2d(i,j,bi,bj)*a2dNorm
0211 aS2d(i,j,bi,bj) = aS2d(i,j,bi,bj)*a2dNorm
bdbdc9dd8f Jean*0212 b2d(i,j,bi,bj) = b2d(i,j,bi,bj) *b2dNorm
0213
d5ada4102b Jean*0214 ENDDO
0215 ENDDO
0216 ENDDO
0217 ENDDO
0218 ENDIF
0219
41c4545f8f Jean*0220 IF ( diag_dBugLevel.GE.debLevA .AND. k.EQ.1 ) THEN
d5ada4102b Jean*0221 _BEGIN_MASTER( myThid )
0222 WRITE(standardMessageUnit,'(A,I9,2(A,1P1E13.6),A,1P1E9.2)')
bdbdc9dd8f Jean*0223 & ' diag_cg2d (it=', myIter,') a2dNorm,x2dNorm=', a2dNorm,
0224 & ' ,', x2dNorm, ' ; Criter=', residCriter
d5ada4102b Jean*0225 _END_MASTER( myThid )
0226 ENDIF
0227
d53cbeab8e Jean*0228 numIters = diagCG_maxIters
d5ada4102b Jean*0229 CALL DIAG_CG2D(
0230 I aW2d, aS2d, b2d,
a63b8f5615 Jean*0231 I diagCG_pcOffDFac, residCriter,
d53cbeab8e Jean*0232 O firstResidual, minResidual, lastResidual,
d5ada4102b Jean*0233 U x2d, numIters,
d53cbeab8e Jean*0234 O nIterMin,
0235 I diagCG_prtResFrq, myThid )
d5ada4102b Jean*0236
41c4545f8f Jean*0237 IF ( diag_dBugLevel.GE.debLevA ) THEN
d5ada4102b Jean*0238 _BEGIN_MASTER( myThid )
d53cbeab8e Jean*0239 WRITE(standardMessageUnit,'(A,I4,A,2I6,A,1P3E14.7)')
0240 & ' diag_cg2d : k=', k, ' , it=', nIterMin, numIters,
0241 & ' ; ini,min,last_Res=',firstResidual,minResidual,lastResidual
d5ada4102b Jean*0242 _END_MASTER( myThid )
0243 ENDIF
0244
bc85e7ab92 Jean*0245 _EXCH_XY_RL( x2d, myThid )
d5ada4102b Jean*0246
0247
0248 IF (diagNormaliseRHS) THEN
0249 DO bj = myByLo(myThid), myByHi(myThid)
0250 DO bi = myBxLo(myThid), myBxHi(myThid)
a63b8f5615 Jean*0251 DO j = 1-OLy,sNy+OLy
0252 DO i = 1-OLx,sNx+OLx
bdbdc9dd8f Jean*0253 x2d(i,j,bi,bj) = x2d(i,j,bi,bj)*x2dNorm
d5ada4102b Jean*0254 ENDDO
0255 ENDDO
0256 ENDDO
0257 ENDDO
0258 ENDIF
0259
bc85e7ab92 Jean*0260
0261 DO bj = myByLo(myThid), myByHi(myThid)
0262 DO bi = myBxLo(myThid), myBxHi(myThid)
0263 DO j = 1,sNy+1
0264 DO i = 1,sNx+1
0265 uTrans(i,j,bi,bj) = uTrans(i,j,bi,bj)
0266 & - ( x2d(i,j,bi,bj) - x2d(i-1,j,bi,bj) )
0267 & *recip_dxC(i,j,bi,bj)*dyG(i,j,bi,bj)
0268 & *drF(k)*hFacW(i,j,k,bi,bj)
c8934cd63f Jean*0269 & *maskInW(i,j,bi,bj)
bc85e7ab92 Jean*0270 vTrans(i,j,bi,bj) = vTrans(i,j,bi,bj)
0271 & - ( x2d(i,j,bi,bj) - x2d(i,j-1,bi,bj) )
0272 & *recip_dyC(i,j,bi,bj)*dxG(i,j,bi,bj)
0273 & *drF(k)*hFacS(i,j,k,bi,bj)
c8934cd63f Jean*0274 & *maskInS(i,j,bi,bj)
bc85e7ab92 Jean*0275 ENDDO
0276 ENDDO
0277 ENDDO
0278 ENDDO
0279 CALL DIAG_CALC_PSIVEL(
0280 I k, iPsi0, jPsi0, uTrans, vTrans,
0281 O psiVel, psiLoc,
bdbdc9dd8f Jean*0282 I prtFirstCall, myTime, myIter, myThid )
bc85e7ab92 Jean*0283
bdbdc9dd8f Jean*0284 _BEGIN_MASTER( myThid)
bc85e7ab92 Jean*0285 IF ( useCubedSphereExchange .AND.
0286 & diag_mdsio .AND. myProcId.EQ.0 ) THEN
0287
0288
0289 IF ( diagLoc_ioUnit.EQ.0 ) THEN
0290 CALL MDSFINDUNIT( diagLoc_ioUnit, myThid )
0291 WRITE(dataFName,'(2A,I10.10,A)')
0292 & 'diags_CScorners', '.', nIter0, '.txt'
0293 OPEN( diagLoc_ioUnit, FILE=dataFName, STATUS='unknown' )
0294 iL = ILNBLNK(dataFName)
0295 WRITE(msgBuf,'(2A,I6,2A)') 'DIAGNOSTICS_CALC_PHIVEL: ',
0296 & 'open unit=',diagLoc_ioUnit, ', file: ',dataFName(1:iL)
0297 CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
0298 & SQUEEZE_RIGHT, myThid )
0299 ENDIF
0300 IF ( diagLoc_ioUnit.GT.0 ) THEN
0301 WRITE(diagLoc_ioUnit,'(1P2E18.10,A,2I4,I8,A,2I4,I6,2A)')
0302 & psiLoc, ' #', k, lm, myIter,
0303 & ' :',listId, md, ndId, ' ', cdiag(ndId)
0304
0305
0306
0307
0308
0309 ENDIF
0310 ENDIF
bdbdc9dd8f Jean*0311 IF ( prtFirstCall ) prtFirstCall = .FALSE.
0312 _END_MASTER( myThid)
bc85e7ab92 Jean*0313
0314
0315 DO bj = myByLo(myThid), myByHi(myThid)
0316 DO bi = myBxLo(myThid), myBxHi(myThid)
0317 DO j = 1,sNy+1
0318 DO i = 1,sNx+1
0319 qtmp1(i,j,ks,bi,bj) = x2d(i,j,bi,bj)
0320 qtmp2(i,j,ks,bi,bj) = psiVel(i,j,bi,bj)
0321 ENDDO
0322 ENDDO
0323 ENDDO
0324 ENDDO
0325
d5ada4102b Jean*0326 ENDDO
0327
5ce5806717 Jean*0328 #ifdef ALLOW_DEBUG
0329 IF (debugMode) CALL DEBUG_LEAVE('DIAGNOSTICS_CALC_PHIVEL',myThid)
0330 #endif
0331
d5ada4102b Jean*0332 RETURN
0333 END