20 |
C | C*P* comments indicating place holders for which code is | |
C | C*P* comments indicating place holders for which code is | |
21 |
C | presently being developed. | |
C | presently being developed. | |
22 |
C \==========================================================/ |
C \==========================================================/ |
23 |
|
c |
24 |
|
c changed: Patrick Heimbach heimbach@mit.edu 6-Jun-2000 |
25 |
|
c - computation of ikey wrong for nTx,nTy > 1 |
26 |
|
c and/or nsx,nsy > 1: act1 and act2 were |
27 |
|
c mixed up. |
28 |
|
|
29 |
IMPLICIT NONE |
IMPLICIT NONE |
30 |
|
|
31 |
C == Global variables === |
C == Global variables === |
35 |
#include "PARAMS.h" |
#include "PARAMS.h" |
36 |
#include "DYNVARS.h" |
#include "DYNVARS.h" |
37 |
#include "GRID.h" |
#include "GRID.h" |
38 |
#ifdef ALLOW_KPP |
|
39 |
#include "KPPMIX.h" |
#ifdef ALLOW_AUTODIFF_TAMC |
40 |
|
#include "tamc.h" |
41 |
|
#include "tamc_keys.h" |
42 |
#endif |
#endif |
43 |
|
|
44 |
C == Routine arguments == |
C == Routine arguments == |
85 |
C anomaly. |
C anomaly. |
86 |
C etaSurfX, - Holds surface elevation gradient in X and Y. |
C etaSurfX, - Holds surface elevation gradient in X and Y. |
87 |
C etaSurfY |
C etaSurfY |
|
C K13, K23, K33 - Non-zero elements of small-angle approximation |
|
|
C diffusion tensor. |
|
|
C KapGM - Spatially varying Visbeck et. al mixing coeff. |
|
88 |
C KappaRT, - Total diffusion in vertical for T and S. |
C KappaRT, - Total diffusion in vertical for T and S. |
89 |
C KappaRS (background + spatially varying, isopycnal term). |
C KappaRS (background + spatially varying, isopycnal term). |
90 |
C iMin, iMax - Ranges and sub-block indices on which calculations |
C iMin, iMax - Ranges and sub-block indices on which calculations |
121 |
_RL rhotmp (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RL rhotmp (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
122 |
_RL etaSurfX(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RL etaSurfX(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
123 |
_RL etaSurfY(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RL etaSurfY(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
|
_RL K13 (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
|
|
_RL K23 (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
|
|
_RL K33 (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
|
|
_RL KapGM (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
|
124 |
_RL KappaRT (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr) |
_RL KappaRT (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr) |
125 |
_RL KappaRS (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr) |
_RL KappaRS (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr) |
126 |
_RL KappaRU (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr) |
_RL KappaRU (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr) |
127 |
_RL KappaRV (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr) |
_RL KappaRV (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr) |
128 |
|
_RL sigmaX (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
129 |
|
_RL sigmaY (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
130 |
|
_RL sigmaR (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
131 |
|
|
132 |
#ifdef INCLUDE_CONVECT_CALL |
C This is currently also used by IVDC and Diagnostics |
133 |
|
C #ifdef INCLUDE_CONVECT_CALL |
134 |
_RL ConvectCount (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
_RL ConvectCount (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
135 |
#endif |
C #endif |
136 |
|
|
137 |
INTEGER iMin, iMax |
INTEGER iMin, iMax |
138 |
INTEGER jMin, jMax |
INTEGER jMin, jMax |
141 |
INTEGER k, kM1, kUp, kDown |
INTEGER k, kM1, kUp, kDown |
142 |
LOGICAL BOTTOM_LAYER |
LOGICAL BOTTOM_LAYER |
143 |
|
|
144 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
145 |
|
INTEGER isbyte |
146 |
|
PARAMETER( isbyte = 4 ) |
147 |
|
|
148 |
|
INTEGER act1, act2, act3, act4 |
149 |
|
INTEGER max1, max2, max3 |
150 |
|
INTEGER iikey, kkey |
151 |
|
INTEGER maximpl |
152 |
|
#endif |
153 |
|
|
154 |
C--- The algorithm... |
C--- The algorithm... |
155 |
C |
C |
156 |
C "Correction Step" |
C "Correction Step" |
196 |
C (1 + dt * K * d_zz) salt[n] = salt* |
C (1 + dt * K * d_zz) salt[n] = salt* |
197 |
C--- |
C--- |
198 |
|
|
199 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
200 |
|
C-- dummy statement to end declaration part |
201 |
|
ikey = 1 |
202 |
|
#endif |
203 |
|
|
204 |
C-- Set up work arrays with valid (i.e. not NaN) values |
C-- Set up work arrays with valid (i.e. not NaN) values |
205 |
C These inital values do not alter the numerical results. They |
C These inital values do not alter the numerical results. They |
206 |
C just ensure that all memory references are to valid floating |
C just ensure that all memory references are to valid floating |
221 |
fMer(i,j) = 0. _d 0 |
fMer(i,j) = 0. _d 0 |
222 |
DO K=1,Nr |
DO K=1,Nr |
223 |
phiHyd (i,j,k) = 0. _d 0 |
phiHyd (i,j,k) = 0. _d 0 |
|
K13(i,j,k) = 0. _d 0 |
|
|
K23(i,j,k) = 0. _d 0 |
|
|
K33(i,j,k) = 0. _d 0 |
|
224 |
KappaRU(i,j,k) = 0. _d 0 |
KappaRU(i,j,k) = 0. _d 0 |
225 |
KappaRV(i,j,k) = 0. _d 0 |
KappaRV(i,j,k) = 0. _d 0 |
226 |
|
sigmaX(i,j,k) = 0. _d 0 |
227 |
|
sigmaY(i,j,k) = 0. _d 0 |
228 |
|
sigmaR(i,j,k) = 0. _d 0 |
229 |
ENDDO |
ENDDO |
230 |
rhoKM1 (i,j) = 0. _d 0 |
rhoKM1 (i,j) = 0. _d 0 |
231 |
rhok (i,j) = 0. _d 0 |
rhok (i,j) = 0. _d 0 |
238 |
ENDDO |
ENDDO |
239 |
|
|
240 |
|
|
241 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
242 |
|
C-- HPF directive to help TAMC |
243 |
|
!HPF$ INDEPENDENT |
244 |
|
#endif |
245 |
|
|
246 |
DO bj=myByLo(myThid),myByHi(myThid) |
DO bj=myByLo(myThid),myByHi(myThid) |
247 |
|
|
248 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
249 |
|
C-- HPF directive to help TAMC |
250 |
|
!HPF$ INDEPENDENT, NEW (rTrans,rVel,fVerT,fVerS,fVerU,fVerV |
251 |
|
!HPF$& ,phiHyd, |
252 |
|
!HPF$& ,utrans,vtrans,maskc,xA,yA |
253 |
|
!HPF$& ,KappaRT,KappaRS,KappaRU,KappaRV |
254 |
|
!HPF$& ) |
255 |
|
#endif |
256 |
|
|
257 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
DO bi=myBxLo(myThid),myBxHi(myThid) |
258 |
|
|
259 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
260 |
|
act1 = bi - myBxLo(myThid) |
261 |
|
max1 = myBxHi(myThid) - myBxLo(myThid) + 1 |
262 |
|
|
263 |
|
act2 = bj - myByLo(myThid) |
264 |
|
max2 = myByHi(myThid) - myByLo(myThid) + 1 |
265 |
|
|
266 |
|
act3 = myThid - 1 |
267 |
|
max3 = nTx*nTy |
268 |
|
|
269 |
|
act4 = ikey_dynamics - 1 |
270 |
|
|
271 |
|
ikey = (act1 + 1) + act2*max1 |
272 |
|
& + act3*max1*max2 |
273 |
|
& + act4*max1*max2*max3 |
274 |
|
#endif |
275 |
|
|
276 |
C-- Set up work arrays that need valid initial values |
C-- Set up work arrays that need valid initial values |
277 |
DO j=1-OLy,sNy+OLy |
DO j=1-OLy,sNy+OLy |
278 |
DO i=1-OLx,sNx+OLx |
DO i=1-OLx,sNx+OLx |
288 |
fVerV (i,j,1) = 0. _d 0 |
fVerV (i,j,1) = 0. _d 0 |
289 |
fVerV (i,j,2) = 0. _d 0 |
fVerV (i,j,2) = 0. _d 0 |
290 |
phiHyd(i,j,1) = 0. _d 0 |
phiHyd(i,j,1) = 0. _d 0 |
|
K13 (i,j,1) = 0. _d 0 |
|
|
K23 (i,j,1) = 0. _d 0 |
|
|
K33 (i,j,1) = 0. _d 0 |
|
|
KapGM (i,j) = GMkbackground |
|
291 |
ENDDO |
ENDDO |
292 |
ENDDO |
ENDDO |
293 |
|
|
322 |
CALL CORRECTION_STEP( |
CALL CORRECTION_STEP( |
323 |
I bi,bj,iMin,iMax,jMin,jMax,K, |
I bi,bj,iMin,iMax,jMin,jMax,K, |
324 |
I etaSurfX,etaSurfY,myTime,myThid) |
I etaSurfX,etaSurfY,myTime,myThid) |
325 |
|
|
326 |
#ifdef ALLOW_OBCS |
#ifdef ALLOW_OBCS |
327 |
IF (openBoundaries) CALL APPLY_OBCS1( bi, bj, K, myThid ) |
IF (openBoundaries) THEN |
328 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
329 |
|
CADJ STORE uvel (:,:,k,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
330 |
|
CADJ STORE vvel (:,:,k,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
331 |
|
CADJ STORE theta(:,:,k,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
332 |
|
CADJ STORE salt(:,:,k,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
333 |
|
#endif |
334 |
|
CALL APPLY_OBCS1( bi, bj, K, myThid ) |
335 |
|
END IF |
336 |
#endif |
#endif |
337 |
|
|
338 |
IF ( .NOT. BOTTOM_LAYER ) THEN |
IF ( .NOT. BOTTOM_LAYER ) THEN |
339 |
C-- Update fields in layer below according to tendency terms |
C-- Update fields in layer below according to tendency terms |
340 |
CALL CORRECTION_STEP( |
CALL CORRECTION_STEP( |
341 |
I bi,bj,iMin,iMax,jMin,jMax,K+1, |
I bi,bj,iMin,iMax,jMin,jMax,K+1, |
342 |
I etaSurfX,etaSurfY,myTime,myThid) |
I etaSurfX,etaSurfY,myTime,myThid) |
343 |
#ifdef ALLOW_OBCS |
#ifdef ALLOW_OBCS |
344 |
IF (openBoundaries) CALL APPLY_OBCS1( bi, bj, K+1, myThid ) |
IF (openBoundaries) THEN |
345 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
346 |
|
CADJ STORE uvel (:,:,k,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
347 |
|
CADJ STORE vvel (:,:,k,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
348 |
|
CADJ STORE theta(:,:,k,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
349 |
|
CADJ STORE salt(:,:,k,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
350 |
|
#endif |
351 |
|
CALL APPLY_OBCS1( bi, bj, K+1, myThid ) |
352 |
|
END IF |
353 |
#endif |
#endif |
354 |
ENDIF |
ENDIF |
355 |
#endif |
#endif |
356 |
C-- Density of 1st level (below W(1)) reference to level 1 |
C-- Density of 1st level (below W(1)) reference to level 1 |
357 |
#ifdef INCLUDE_FIND_RHO_CALL |
#ifdef INCLUDE_FIND_RHO_CALL |
358 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
359 |
|
CADJ STORE theta(:,:,k,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
360 |
|
CADJ STORE salt (:,:,k,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
361 |
|
#endif |
362 |
CALL FIND_RHO( |
CALL FIND_RHO( |
363 |
I bi, bj, iMin, iMax, jMin, jMax, K, K, eosType, |
I bi, bj, iMin, iMax, jMin, jMax, K, K, eosType, |
364 |
O rhoKm1, |
O rhoKm1, |
366 |
#endif |
#endif |
367 |
|
|
368 |
IF ( (.NOT. BOTTOM_LAYER) |
IF ( (.NOT. BOTTOM_LAYER) |
|
#ifdef ALLOW_KPP |
|
|
& .AND. (.NOT.usingKPPmixing) ! CONVECT not needed with KPP mixing |
|
|
#endif |
|
369 |
& ) THEN |
& ) THEN |
370 |
C-- Check static stability with layer below |
C-- Check static stability with layer below |
371 |
C-- and mix as needed. |
C-- and mix as needed. |
372 |
#ifdef INCLUDE_FIND_RHO_CALL |
#ifdef INCLUDE_FIND_RHO_CALL |
373 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
374 |
|
CADJ STORE theta(:,:,k,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
375 |
|
CADJ STORE salt (:,:,k,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
376 |
|
#endif |
377 |
CALL FIND_RHO( |
CALL FIND_RHO( |
378 |
I bi, bj, iMin, iMax, jMin, jMax, K+1, K, eosType, |
I bi, bj, iMin, iMax, jMin, jMax, K+1, K, eosType, |
379 |
O rhoKp1, |
O rhoKp1, |
380 |
I myThid ) |
I myThid ) |
381 |
#endif |
#endif |
382 |
|
|
383 |
#ifdef INCLUDE_CONVECT_CALL |
#ifdef INCLUDE_CONVECT_CALL |
384 |
|
|
385 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
386 |
|
CADJ STORE rhoKm1(:,:) = comlev1_2d, key = ikey, byte = isbyte |
387 |
|
CADJ STORE rhoKp1(:,:) = comlev1_2d, key = ikey, byte = isbyte |
388 |
|
#endif |
389 |
CALL CONVECT( |
CALL CONVECT( |
390 |
I bi,bj,iMin,iMax,jMin,jMax,K+1,rhoKm1,rhoKp1, |
I bi,bj,iMin,iMax,jMin,jMax,K+1,rhoKm1,rhoKp1, |
391 |
U ConvectCount, |
U ConvectCount, |
392 |
I myTime,myIter,myThid) |
I myTime,myIter,myThid) |
393 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
394 |
|
CADJ STORE theta(:,:,k+1,bi,bj),theta(:,:,k,bi,bj) |
395 |
|
CADJ & = comlev1_2d, key = ikey, byte = isbyte |
396 |
|
CADJ STORE salt (:,:,k+1,bi,bj),salt (:,:,k,bi,bj) |
397 |
|
CADJ & = comlev1_2d, key = ikey, byte = isbyte |
398 |
#endif |
#endif |
399 |
|
|
400 |
|
#endif |
401 |
|
|
402 |
C-- Implicit Vertical Diffusion for Convection |
C-- Implicit Vertical Diffusion for Convection |
403 |
IF (ivdc_kappa.NE.0.) CALL CALC_IVDC( |
IF (ivdc_kappa.NE.0.) CALL CALC_IVDC( |
404 |
I bi,bj,iMin,iMax,jMin,jMax,K+1,rhoKm1,rhoKp1, |
I bi,bj,iMin,iMax,jMin,jMax,K+1,rhoKm1,rhoKp1, |
405 |
U ConvectCount, KappaRT, KappaRS, |
U ConvectCount, KappaRT, KappaRS, |
406 |
I myTime,myIter,myThid) |
I myTime,myIter,myThid) |
407 |
|
CRG: do we need do store STORE KappaRT, KappaRS ? |
408 |
|
|
409 |
C-- Recompute density after mixing |
C-- Recompute density after mixing |
410 |
#ifdef INCLUDE_FIND_RHO_CALL |
#ifdef INCLUDE_FIND_RHO_CALL |
411 |
CALL FIND_RHO( |
CALL FIND_RHO( |
425 |
I bi,bj,iMin,iMax,jMin,jMax,K,buoyKm1,buoyKm1, |
I bi,bj,iMin,iMax,jMin,jMax,K,buoyKm1,buoyKm1, |
426 |
U phiHyd, |
U phiHyd, |
427 |
I myThid ) |
I myThid ) |
428 |
|
CALL GRAD_SIGMA( |
429 |
|
I bi, bj, iMin, iMax, jMin, jMax, K, |
430 |
|
I rhoKm1, rhoKm1, rhoKm1, |
431 |
|
O sigmaX, sigmaY, sigmaR, |
432 |
|
I myThid ) |
433 |
|
|
434 |
|
C-- Start of downward loop |
435 |
DO K=2,Nr |
DO K=2,Nr |
436 |
|
|
437 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
438 |
|
kkey = (ikey-1)*(Nr-2+1) + (k-2) + 1 |
439 |
|
#endif |
440 |
|
|
441 |
BOTTOM_LAYER = K .EQ. Nr |
BOTTOM_LAYER = K .EQ. Nr |
442 |
|
|
443 |
#ifdef DO_PIPELINED_CORRECTION_STEP |
#ifdef DO_PIPELINED_CORRECTION_STEP |
444 |
IF ( .NOT. BOTTOM_LAYER ) THEN |
IF ( .NOT. BOTTOM_LAYER ) THEN |
445 |
C-- Update fields in layer below according to tendency terms |
C-- Update fields in layer below according to tendency terms |
447 |
I bi,bj,iMin,iMax,jMin,jMax,K+1, |
I bi,bj,iMin,iMax,jMin,jMax,K+1, |
448 |
I etaSurfX,etaSurfY,myTime,myThid) |
I etaSurfX,etaSurfY,myTime,myThid) |
449 |
#ifdef ALLOW_OBCS |
#ifdef ALLOW_OBCS |
450 |
IF (openBoundaries) CALL APPLY_OBCS1( bi, bj, K+1, myThid ) |
IF (openBoundaries) THEN |
451 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
452 |
|
CADJ STORE uvel (:,:,k,bi,bj) = comlev1_3d, key = kkey, byte = isbyte |
453 |
|
CADJ STORE vvel (:,:,k,bi,bj) = comlev1_3d, key = kkey, byte = isbyte |
454 |
|
CADJ STORE theta(:,:,k,bi,bj) = comlev1_3d, key = kkey, byte = isbyte |
455 |
|
CADJ STORE salt(:,:,k,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
456 |
|
#endif |
457 |
|
CALL APPLY_OBCS1( bi, bj, K+1, myThid ) |
458 |
|
END IF |
459 |
#endif |
#endif |
460 |
ENDIF |
ENDIF |
461 |
#endif |
#endif |
462 |
|
|
463 |
C-- Density of K level (below W(K)) reference to K level |
C-- Density of K level (below W(K)) reference to K level |
464 |
#ifdef INCLUDE_FIND_RHO_CALL |
#ifdef INCLUDE_FIND_RHO_CALL |
465 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
466 |
|
CADJ STORE theta(:,:,k,bi,bj) = comlev1_3d, key = kkey, byte = isbyte |
467 |
|
CADJ STORE salt (:,:,k,bi,bj) = comlev1_3d, key = kkey, byte = isbyte |
468 |
|
#endif |
469 |
CALL FIND_RHO( |
CALL FIND_RHO( |
470 |
I bi, bj, iMin, iMax, jMin, jMax, K, K, eosType, |
I bi, bj, iMin, iMax, jMin, jMax, K, K, eosType, |
471 |
O rhoK, |
O rhoK, |
472 |
I myThid ) |
I myThid ) |
473 |
#endif |
#endif |
474 |
IF ( (.NOT. BOTTOM_LAYER) |
IF ( (.NOT. BOTTOM_LAYER) |
|
#ifdef ALLOW_KPP |
|
|
& .AND. (.NOT.usingKPPmixing) ! CONVECT not needed with KPP mixing |
|
|
#endif |
|
475 |
& ) THEN |
& ) THEN |
476 |
C-- Check static stability with layer below and mix as needed. |
C-- Check static stability with layer below and mix as needed. |
477 |
C-- Density of K+1 level (below W(K+1)) reference to K level. |
C-- Density of K+1 level (below W(K+1)) reference to K level. |
478 |
#ifdef INCLUDE_FIND_RHO_CALL |
#ifdef INCLUDE_FIND_RHO_CALL |
479 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
480 |
|
CADJ STORE theta(:,:,k,bi,bj) = comlev1_3d, key = kkey, byte = isbyte |
481 |
|
CADJ STORE salt (:,:,k,bi,bj) = comlev1_3d, key = kkey, byte = isbyte |
482 |
|
#endif |
483 |
CALL FIND_RHO( |
CALL FIND_RHO( |
484 |
I bi, bj, iMin, iMax, jMin, jMax, K+1, K, eosType, |
I bi, bj, iMin, iMax, jMin, jMax, K+1, K, eosType, |
485 |
O rhoKp1, |
O rhoKp1, |
486 |
I myThid ) |
I myThid ) |
487 |
#endif |
#endif |
488 |
|
|
489 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
490 |
|
CADJ STORE rhok (:,:) = comlev1_3d, key = kkey, byte = isbyte |
491 |
|
CADJ STORE rhoKm1(:,:) = comlev1_3d, key = kkey, byte = isbyte |
492 |
|
CADJ STORE rhoKp1(:,:) = comlev1_3d, key = kkey, byte = isbyte |
493 |
|
#endif |
494 |
|
|
495 |
#ifdef INCLUDE_CONVECT_CALL |
#ifdef INCLUDE_CONVECT_CALL |
496 |
CALL CONVECT( |
CALL CONVECT( |
497 |
I bi,bj,iMin,iMax,jMin,jMax,K+1,rhoK,rhoKp1, |
I bi,bj,iMin,iMax,jMin,jMax,K+1,rhoK,rhoKp1, |
498 |
U ConvectCount, |
U ConvectCount, |
499 |
I myTime,myIter,myThid) |
I myTime,myIter,myThid) |
500 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
501 |
|
CADJ STORE theta(:,:,k+1,bi,bj),theta(:,:,k,bi,bj) |
502 |
|
CADJ & = comlev1_3d, key = kkey, byte = isbyte |
503 |
|
CADJ STORE salt (:,:,k+1,bi,bj),salt (:,:,k,bi,bj) |
504 |
|
CADJ & = comlev1_3d, key = kkey, byte = isbyte |
505 |
|
#endif |
506 |
#endif |
#endif |
507 |
|
|
508 |
C-- Implicit Vertical Diffusion for Convection |
C-- Implicit Vertical Diffusion for Convection |
509 |
IF (ivdc_kappa.NE.0.) CALL CALC_IVDC( |
IF (ivdc_kappa.NE.0.) THEN |
510 |
|
CALL CALC_IVDC( |
511 |
I bi,bj,iMin,iMax,jMin,jMax,K+1,rhoKm1,rhoKp1, |
I bi,bj,iMin,iMax,jMin,jMax,K+1,rhoKm1,rhoKp1, |
512 |
U ConvectCount, KappaRT, KappaRS, |
U ConvectCount, KappaRT, KappaRS, |
513 |
I myTime,myIter,myThid) |
I myTime,myIter,myThid) |
514 |
|
CRG: do we need do store STORE KappaRT, KappaRS ? |
515 |
|
END IF |
516 |
|
|
517 |
C-- Recompute density after mixing |
C-- Recompute density after mixing |
518 |
#ifdef INCLUDE_FIND_RHO_CALL |
#ifdef INCLUDE_FIND_RHO_CALL |
519 |
CALL FIND_RHO( |
CALL FIND_RHO( |
540 |
O rhoTmp, |
O rhoTmp, |
541 |
I myThid ) |
I myThid ) |
542 |
#endif |
#endif |
543 |
#ifdef INCLUDE_CALC_ISOSLOPES_CALL |
CALL GRAD_SIGMA( |
544 |
CALL CALC_ISOSLOPES( |
I bi, bj, iMin, iMax, jMin, jMax, K, |
545 |
I bi, bj, iMin, iMax, jMin, jMax, K, |
I rhoK, rhotmp, rhoK, |
546 |
I rhoKm1, rhoK, rhotmp, |
O sigmaX, sigmaY, sigmaR, |
547 |
O K13, K23, K33, KapGM, |
I myThid ) |
548 |
I myThid ) |
|
549 |
#endif |
|
550 |
DO J=jMin,jMax |
DO J=jMin,jMax |
551 |
DO I=iMin,iMax |
DO I=iMin,iMax |
552 |
#ifdef INCLUDE_FIND_RHO_CALL |
#ifdef INCLUDE_FIND_RHO_CALL |
555 |
buoyKm1(I,J) = buoyK(I,J) |
buoyKm1(I,J) = buoyK(I,J) |
556 |
ENDDO |
ENDDO |
557 |
ENDDO |
ENDDO |
558 |
ENDDO ! K |
ENDDO |
559 |
|
C-- end of k loop |
560 |
|
|
561 |
|
#ifdef ALLOW_GMREDI |
562 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
563 |
|
CADJ STORE rhoTmp(:,:) = comlev1_3d, key = kkey, byte = isbyte |
564 |
|
CADJ STORE rhok (:,:) = comlev1_3d, key = kkey, byte = isbyte |
565 |
|
CADJ STORE rhoKm1(:,:) = comlev1_3d, key = kkey, byte = isbyte |
566 |
|
#endif |
567 |
|
DO K=1, Nr |
568 |
|
IF (use_GMRedi) CALL GMREDI_CALC_TENSOR( |
569 |
|
I bi, bj, iMin, iMax, jMin, jMax, K, |
570 |
|
I sigmaX, sigmaY, sigmaR, |
571 |
|
I myThid ) |
572 |
|
ENDDO |
573 |
|
#endif |
574 |
|
|
575 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
576 |
|
CADJ STORE theta(:,:,:,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
577 |
|
CADJ STORE salt (:,:,:,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
578 |
|
CADJ STORE uvel (:,:,:,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
579 |
|
CADJ STORE vvel (:,:,:,bi,bj) = comlev1_2d, key = ikey, byte = isbyte |
580 |
|
#endif |
581 |
|
|
582 |
#ifdef ALLOW_KPP |
#ifdef ALLOW_KPP |
583 |
C-- Compute KPP mixing coefficients |
C-- Compute KPP mixing coefficients |
584 |
IF (usingKPPmixing) THEN |
CALL TIMER_START('KPP_CALC [DYNAMICS]', myThid) |
585 |
CALL TIMER_START('KVMIX (FIND KPP COEFFICIENTS) [DYNAMICS]' |
CALL KPP_CALC( |
|
I , myThid) |
|
|
CALL KVMIX( |
|
586 |
I bi, bj, myTime, myThid ) |
I bi, bj, myTime, myThid ) |
587 |
CALL TIMER_STOP ('KVMIX (FIND KPP COEFFICIENTS) [DYNAMICS]' |
CALL TIMER_STOP ('KPP_CALC [DYNAMICS]', myThid) |
|
I , myThid) |
|
|
ENDIF |
|
588 |
#endif |
#endif |
589 |
|
|
590 |
|
C-- Start of upward loop |
591 |
DO K = Nr, 1, -1 |
DO K = Nr, 1, -1 |
592 |
|
|
593 |
kM1 =max(1,k-1) ! Points to level above k (=k-1) |
kM1 =max(1,k-1) ! Points to level above k (=k-1) |
594 |
kUp =1+MOD(k+1,2) ! Cycles through 1,2 to point to layer above |
kUp =1+MOD(k+1,2) ! Cycles through 1,2 to point to layer above |
595 |
kDown=1+MOD(k,2) ! Cycles through 2,1 to point to current layer |
kDown=1+MOD(k,2) ! Cycles through 2,1 to point to current layer |
596 |
|
|
597 |
iMin = 1-OLx+2 |
iMin = 1-OLx+2 |
598 |
iMax = sNx+OLx-1 |
iMax = sNx+OLx-1 |
599 |
jMin = 1-OLy+2 |
jMin = 1-OLy+2 |
600 |
jMax = sNy+OLy-1 |
jMax = sNy+OLy-1 |
601 |
|
|
602 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
603 |
|
kkey = (ikey-1)*(Nr-1+1) + (k-1) + 1 |
604 |
|
#endif |
605 |
|
|
606 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
607 |
|
CADJ STORE rvel (:,:,kDown) = comlev1_3d, key = kkey, byte = isbyte |
608 |
|
CADJ STORE rTrans(:,:) = comlev1_3d, key = kkey, byte = isbyte |
609 |
|
CADJ STORE KappaRT(:,:,:) = comlev1_3d, key = kkey, byte = isbyte |
610 |
|
CADJ STORE KappaRS(:,:,:) = comlev1_3d, key = kkey, byte = isbyte |
611 |
|
#endif |
612 |
|
|
613 |
C-- Get temporary terms used by tendency routines |
C-- Get temporary terms used by tendency routines |
614 |
CALL CALC_COMMON_FACTORS ( |
CALL CALC_COMMON_FACTORS ( |
615 |
I bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown, |
I bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown, |
616 |
O xA,yA,uTrans,vTrans,rTrans,rVel,maskC,maskUp, |
O xA,yA,uTrans,vTrans,rTrans,rVel,maskC,maskUp, |
617 |
I myThid) |
I myThid) |
618 |
|
|
619 |
#ifdef ALLOW_OBCS |
#ifdef ALLOW_OBCS |
620 |
IF (openBoundaries) THEN |
IF (openBoundaries) THEN |
621 |
CALL APPLY_OBCS3( bi, bj, K, Kup, rTrans, rVel, myThid ) |
CALL APPLY_OBCS3( bi, bj, K, Kup, rTrans, rVel, myThid ) |
622 |
ENDIF |
ENDIF |
623 |
#endif |
#endif |
624 |
|
|
625 |
#ifdef INCLUDE_CALC_DIFFUSIVITY_CALL |
#ifdef INCLUDE_CALC_DIFFUSIVITY_CALL |
626 |
C-- Calculate the total vertical diffusivity |
C-- Calculate the total vertical diffusivity |
627 |
CALL CALC_DIFFUSIVITY( |
CALL CALC_DIFFUSIVITY( |
628 |
I bi,bj,iMin,iMax,jMin,jMax,K, |
I bi,bj,iMin,iMax,jMin,jMax,K, |
629 |
I maskC,maskUp,KapGM,K33, |
I maskC,maskUp, |
630 |
O KappaRT,KappaRS,KappaRU,KappaRV, |
O KappaRT,KappaRS,KappaRU,KappaRV, |
631 |
I myThid) |
I myThid) |
632 |
#endif |
#endif |
639 |
U aTerm,xTerm,cTerm,mTerm,pTerm, |
U aTerm,xTerm,cTerm,mTerm,pTerm, |
640 |
U fZon, fMer, fVerU, fVerV, |
U fZon, fMer, fVerU, fVerV, |
641 |
I myTime, myThid) |
I myTime, myThid) |
642 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
643 |
|
#ifdef INCLUDE_CD_CODE |
644 |
|
ELSE |
645 |
|
DO j=1-OLy,sNy+OLy |
646 |
|
DO i=1-OLx,sNx+OLx |
647 |
|
guCD(i,j,k,bi,bj) = 0.0 |
648 |
|
gvCD(i,j,k,bi,bj) = 0.0 |
649 |
|
END DO |
650 |
|
END DO |
651 |
|
#endif |
652 |
|
#endif |
653 |
ENDIF |
ENDIF |
654 |
C-- Calculate active tracer tendencies |
C-- Calculate active tracer tendencies |
655 |
IF ( tempStepping ) THEN |
IF ( tempStepping ) THEN |
656 |
CALL CALC_GT( |
CALL CALC_GT( |
657 |
I bi,bj,iMin,iMax,jMin,jMax, k,kM1,kUp,kDown, |
I bi,bj,iMin,iMax,jMin,jMax, k,kM1,kUp,kDown, |
658 |
I xA,yA,uTrans,vTrans,rTrans,maskUp,maskC, |
I xA,yA,uTrans,vTrans,rTrans,maskUp,maskC, |
659 |
I K13,K23,KappaRT,KapGM, |
I KappaRT, |
660 |
U aTerm,xTerm,fZon,fMer,fVerT, |
U aTerm,xTerm,fZon,fMer,fVerT, |
661 |
I myTime, myThid) |
I myTime, myThid) |
662 |
ENDIF |
ENDIF |
664 |
CALL CALC_GS( |
CALL CALC_GS( |
665 |
I bi,bj,iMin,iMax,jMin,jMax, k,kM1,kUp,kDown, |
I bi,bj,iMin,iMax,jMin,jMax, k,kM1,kUp,kDown, |
666 |
I xA,yA,uTrans,vTrans,rTrans,maskUp,maskC, |
I xA,yA,uTrans,vTrans,rTrans,maskUp,maskC, |
667 |
I K13,K23,KappaRS,KapGM, |
I KappaRS, |
668 |
U aTerm,xTerm,fZon,fMer,fVerS, |
U aTerm,xTerm,fZon,fMer,fVerS, |
669 |
I myTime, myThid) |
I myTime, myThid) |
670 |
ENDIF |
ENDIF |
681 |
I myIter, myThid) |
I myIter, myThid) |
682 |
#ifdef ALLOW_OBCS |
#ifdef ALLOW_OBCS |
683 |
C-- Apply open boundary conditions |
C-- Apply open boundary conditions |
684 |
IF (openBoundaries) CALL APPLY_OBCS2( bi, bj, K, myThid ) |
IF (openBoundaries) THEN |
685 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
686 |
|
CADJ STORE gunm1(:,:,k,bi,bj) = comlev1_3d, key = kkey, byte = isbyte |
687 |
|
CADJ STORE gvnm1(:,:,k,bi,bj) = comlev1_3d, key = kkey, byte = isbyte |
688 |
|
CADJ STORE gwnm1(:,:,k,bi,bj) = comlev1_3d, key = kkey, byte = isbyte |
689 |
|
#endif |
690 |
|
CALL APPLY_OBCS2( bi, bj, K, myThid ) |
691 |
|
END IF |
692 |
#endif |
#endif |
693 |
C-- Freeze water |
C-- Freeze water |
694 |
IF (allowFreezing) |
IF (allowFreezing) THEN |
695 |
& CALL FREEZE( bi, bj, iMin, iMax, jMin, jMax, K, myThid ) |
#ifdef ALLOW_AUTODIFF_TAMC |
696 |
|
CADJ STORE gTNm1(:,:,k,bi,bj) = comlev1_3d, key = kkey, byte = isbyte |
697 |
|
#endif |
698 |
|
CALL FREEZE( bi, bj, iMin, iMax, jMin, jMax, K, myThid ) |
699 |
|
END IF |
700 |
|
|
701 |
#ifdef DIVG_IN_DYNAMICS |
#ifdef DIVG_IN_DYNAMICS |
702 |
C-- Diagnose barotropic divergence of predicted fields |
C-- Diagnose barotropic divergence of predicted fields |
711 |
IF (taveFreq.GT.0.) THEN |
IF (taveFreq.GT.0.) THEN |
712 |
CALL DO_TIME_AVERAGES( |
CALL DO_TIME_AVERAGES( |
713 |
I myTime, myIter, bi, bj, K, kUp, kDown, |
I myTime, myIter, bi, bj, K, kUp, kDown, |
714 |
I K13, K23, rVel, KapGM, ConvectCount, |
I rVel, ConvectCount, |
715 |
I myThid ) |
I myThid ) |
716 |
ENDIF |
ENDIF |
717 |
#endif |
#endif |
719 |
|
|
720 |
ENDDO ! K |
ENDDO ! K |
721 |
|
|
722 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
723 |
|
maximpl = 6 |
724 |
|
iikey = (ikey-1)*maximpl |
725 |
|
#endif |
726 |
|
|
727 |
C-- Implicit diffusion |
C-- Implicit diffusion |
728 |
IF (implicitDiffusion) THEN |
IF (implicitDiffusion) THEN |
729 |
IF (tempStepping) CALL IMPLDIFF( |
|
730 |
|
IF (tempStepping) THEN |
731 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
732 |
|
idkey = iikey + 1 |
733 |
|
#endif |
734 |
|
CALL IMPLDIFF( |
735 |
I bi, bj, iMin, iMax, jMin, jMax, |
I bi, bj, iMin, iMax, jMin, jMax, |
736 |
I deltaTtracer, KappaRT,recip_HFacC, |
I deltaTtracer, KappaRT,recip_HFacC, |
737 |
U gTNm1, |
U gTNm1, |
738 |
I myThid ) |
I myThid ) |
739 |
IF (saltStepping) CALL IMPLDIFF( |
END IF |
740 |
|
|
741 |
|
IF (saltStepping) THEN |
742 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
743 |
|
idkey = iikey + 2 |
744 |
|
#endif |
745 |
|
CALL IMPLDIFF( |
746 |
I bi, bj, iMin, iMax, jMin, jMax, |
I bi, bj, iMin, iMax, jMin, jMax, |
747 |
I deltaTtracer, KappaRS,recip_HFacC, |
I deltaTtracer, KappaRS,recip_HFacC, |
748 |
U gSNm1, |
U gSNm1, |
749 |
I myThid ) |
I myThid ) |
750 |
|
END IF |
751 |
|
|
752 |
ENDIF ! implicitDiffusion |
ENDIF ! implicitDiffusion |
753 |
|
|
754 |
C-- Implicit viscosity |
C-- Implicit viscosity |
755 |
IF (implicitViscosity) THEN |
IF (implicitViscosity) THEN |
756 |
|
|
757 |
IF (momStepping) THEN |
IF (momStepping) THEN |
758 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
759 |
|
idkey = iikey + 3 |
760 |
|
#endif |
761 |
CALL IMPLDIFF( |
CALL IMPLDIFF( |
762 |
I bi, bj, iMin, iMax, jMin, jMax, |
I bi, bj, iMin, iMax, jMin, jMax, |
763 |
I deltaTmom, KappaRU,recip_HFacW, |
I deltaTmom, KappaRU,recip_HFacW, |
764 |
U gUNm1, |
U gUNm1, |
765 |
I myThid ) |
I myThid ) |
766 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
767 |
|
idkey = iikey + 4 |
768 |
|
#endif |
769 |
CALL IMPLDIFF( |
CALL IMPLDIFF( |
770 |
I bi, bj, iMin, iMax, jMin, jMax, |
I bi, bj, iMin, iMax, jMin, jMax, |
771 |
I deltaTmom, KappaRV,recip_HFacS, |
I deltaTmom, KappaRV,recip_HFacS, |
772 |
U gVNm1, |
U gVNm1, |
773 |
I myThid ) |
I myThid ) |
774 |
|
|
775 |
#ifdef INCLUDE_CD_CODE |
#ifdef INCLUDE_CD_CODE |
776 |
|
|
777 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
778 |
|
idkey = iikey + 5 |
779 |
|
#endif |
780 |
CALL IMPLDIFF( |
CALL IMPLDIFF( |
781 |
I bi, bj, iMin, iMax, jMin, jMax, |
I bi, bj, iMin, iMax, jMin, jMax, |
782 |
I deltaTmom, KappaRU,recip_HFacW, |
I deltaTmom, KappaRU,recip_HFacW, |
783 |
U vVelD, |
U vVelD, |
784 |
I myThid ) |
I myThid ) |
785 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
786 |
|
idkey = iikey + 6 |
787 |
|
#endif |
788 |
CALL IMPLDIFF( |
CALL IMPLDIFF( |
789 |
I bi, bj, iMin, iMax, jMin, jMax, |
I bi, bj, iMin, iMax, jMin, jMax, |
790 |
I deltaTmom, KappaRV,recip_HFacS, |
I deltaTmom, KappaRV,recip_HFacS, |
791 |
U uVelD, |
U uVelD, |
792 |
I myThid ) |
I myThid ) |
793 |
|
|
794 |
#endif |
#endif |
795 |
|
|
796 |
ENDIF ! momStepping |
ENDIF ! momStepping |
797 |
ENDIF ! implicitViscosity |
ENDIF ! implicitViscosity |
798 |
|
|
811 |
C write(0,*) 'dynamics: rVel(2) ', |
C write(0,*) 'dynamics: rVel(2) ', |
812 |
C & minval(rVel(1:sNx,1:sNy,2),mask=rVel(1:sNx,1:sNy,2).NE.0.), |
C & minval(rVel(1:sNx,1:sNy,2),mask=rVel(1:sNx,1:sNy,2).NE.0.), |
813 |
C & maxval(rVel(1:sNx,1:sNy,2),mask=rVel(1:sNx,1:sNy,2).NE.0.) |
C & maxval(rVel(1:sNx,1:sNy,2),mask=rVel(1:sNx,1:sNy,2).NE.0.) |
|
cblk write(0,*) 'dynamics: K13',minval(K13(1:sNx,1:sNy,:)), |
|
|
cblk & maxval(K13(1:sNx,1:sNy,:)) |
|
|
cblk write(0,*) 'dynamics: K23',minval(K23(1:sNx,1:sNy,:)), |
|
|
cblk & maxval(K23(1:sNx,1:sNy,:)) |
|
|
cblk write(0,*) 'dynamics: K33',minval(K33(1:sNx,1:sNy,:)), |
|
|
cblk & maxval(K33(1:sNx,1:sNy,:)) |
|
814 |
C write(0,*) 'dynamics: gT ',minval(gT(1:sNx,1:sNy,:,:,:)), |
C write(0,*) 'dynamics: gT ',minval(gT(1:sNx,1:sNy,:,:,:)), |
815 |
C & maxval(gT(1:sNx,1:sNy,:,:,:)) |
C & maxval(gT(1:sNx,1:sNy,:,:,:)) |
816 |
C write(0,*) 'dynamics: T ',minval(Theta(1:sNx,1:sNy,:,:,:)), |
C write(0,*) 'dynamics: T ',minval(Theta(1:sNx,1:sNy,:,:,:)), |