9 |
C !INTERFACE: ========================================================== |
C !INTERFACE: ========================================================== |
10 |
SUBROUTINE GAD_CALC_RHS( |
SUBROUTINE GAD_CALC_RHS( |
11 |
I bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown, |
I bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown, |
12 |
I xA,yA,uTrans,vTrans,rTrans,maskUp, |
I xA,yA,uTrans,vTrans,rTrans,rTransKp1,maskUp, |
13 |
|
I uVel, vVel, wVel, |
14 |
I diffKh, diffK4, KappaRT, Tracer, |
I diffKh, diffK4, KappaRT, Tracer, |
15 |
I tracerIdentity, advectionScheme, calcAdvection, |
I tracerIdentity, advectionScheme, |
16 |
|
I calcAdvection, implicitAdvection, |
17 |
U fVerT, gTracer, |
U fVerT, gTracer, |
18 |
I myThid ) |
I myThid ) |
19 |
|
|
42 |
#include "EEPARAMS.h" |
#include "EEPARAMS.h" |
43 |
#include "PARAMS.h" |
#include "PARAMS.h" |
44 |
#include "GRID.h" |
#include "GRID.h" |
|
#include "DYNVARS.h" |
|
45 |
#include "SURFACE.h" |
#include "SURFACE.h" |
46 |
#include "GAD.h" |
#include "GAD.h" |
|
#ifdef ALLOW_PTRACERS |
|
|
#include "PTRACERS_OPTIONS.h" |
|
|
#include "PTRACERS.h" |
|
|
#endif |
|
47 |
|
|
48 |
#ifdef ALLOW_AUTODIFF_TAMC |
#ifdef ALLOW_AUTODIFF_TAMC |
49 |
#include "tamc.h" |
#include "tamc.h" |
51 |
#endif /* ALLOW_AUTODIFF_TAMC */ |
#endif /* ALLOW_AUTODIFF_TAMC */ |
52 |
|
|
53 |
C !INPUT PARAMETERS: =================================================== |
C !INPUT PARAMETERS: =================================================== |
54 |
C bi,bj :: tile indices |
C bi,bj :: tile indices |
55 |
C iMin,iMax,jMin,jMax :: loop range for called routines |
C iMin,iMax :: loop range for called routines |
56 |
C kup :: index into 2 1/2D array, toggles between 1 and 2 |
C jMin,jMax :: loop range for called routines |
57 |
C kdown :: index into 2 1/2D array, toggles between 2 and 1 |
C kup :: index into 2 1/2D array, toggles between 1|2 |
58 |
C kp1 :: =k+1 for k<Nr, =Nr for k=Nr |
C kdown :: index into 2 1/2D array, toggles between 2|1 |
59 |
C xA,yA :: areas of X and Y face of tracer cells |
C kp1 :: =k+1 for k<Nr, =Nr for k=Nr |
60 |
C uTrans,vTrans,rTrans :: 2-D arrays of volume transports at U,V and W points |
C xA,yA :: areas of X and Y face of tracer cells |
61 |
C maskUp :: 2-D array for mask at W points |
C uTrans,vTrans :: 2-D arrays of volume transports at U,V points |
62 |
C diffKh :: horizontal diffusion coefficient |
C rTrans :: 2-D arrays of volume transports at W points |
63 |
C diffK4 :: bi-harmonic diffusion coefficient |
C rTransKp1 :: 2-D array of volume trans at W pts, interf k+1 |
64 |
C KappaRT :: 3-D array for vertical diffusion coefficient |
C maskUp :: 2-D array for mask at W points |
65 |
C Tracer :: tracer field |
C uVel,vVel,wVel :: 3 components of the velcity field (3-D array) |
66 |
C tracerIdentity :: identifier for the tracer (required for KPP and GM) |
C diffKh :: horizontal diffusion coefficient |
67 |
C advectionScheme :: advection scheme to use |
C diffK4 :: bi-harmonic diffusion coefficient |
68 |
C calcAdvection :: =False if Advec terms computed with multiDim scheme |
C KappaRT :: 3-D array for vertical diffusion coefficient |
69 |
C myThid :: thread number |
C Tracer :: tracer field |
70 |
|
C tracerIdentity :: tracer identifier (required for KPP,GM) |
71 |
|
C advectionScheme :: advection scheme to use |
72 |
|
C calcAdvection :: =False if Advec computed with multiDim scheme |
73 |
|
C implicitAdvection:: =True if vertical Advec computed implicitly |
74 |
|
C myThid :: thread number |
75 |
INTEGER bi,bj,iMin,iMax,jMin,jMax |
INTEGER bi,bj,iMin,iMax,jMin,jMax |
76 |
INTEGER k,kUp,kDown,kM1 |
INTEGER k,kUp,kDown,kM1 |
77 |
_RS xA (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RS xA (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
79 |
_RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
80 |
_RL vTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RL vTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
81 |
_RL rTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RL rTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
82 |
|
_RL rTransKp1(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
83 |
_RS maskUp(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RS maskUp(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
84 |
|
_RL uVel (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
85 |
|
_RL vVel (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
86 |
|
_RL wVel (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
87 |
_RL diffKh, diffK4 |
_RL diffKh, diffK4 |
88 |
_RL KappaRT(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
_RL KappaRT(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
89 |
_RL Tracer(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
_RL Tracer(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
90 |
INTEGER tracerIdentity |
INTEGER tracerIdentity |
91 |
INTEGER advectionScheme |
INTEGER advectionScheme |
92 |
LOGICAL calcAdvection |
LOGICAL calcAdvection |
93 |
|
LOGICAL implicitAdvection |
94 |
INTEGER myThid |
INTEGER myThid |
95 |
|
|
96 |
C !OUTPUT PARAMETERS: ================================================== |
C !OUTPUT PARAMETERS: ================================================== |
97 |
C gTracer :: tendancy array |
C gTracer :: tendancy array |
98 |
C fVerT :: 2 1/2D arrays for vertical advective flux |
C fVerT :: 2 1/2D arrays for vertical advective flux |
99 |
_RL gTracer(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
_RL gTracer(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
100 |
_RL fVerT (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2) |
_RL fVerT (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2) |
101 |
|
|
102 |
C !LOCAL VARIABLES: ==================================================== |
C !LOCAL VARIABLES: ==================================================== |
103 |
C i,j :: loop indices |
C i,j :: loop indices |
104 |
C df4 :: used for storing del^2 T for bi-harmonic term |
C df4 :: used for storing del^2 T for bi-harmonic term |
105 |
C fZon :: zonal flux |
C fZon :: zonal flux |
106 |
C fmer :: meridional flux |
C fmer :: meridional flux |
107 |
C af :: advective flux |
C af :: advective flux |
108 |
C df :: diffusive flux |
C df :: diffusive flux |
109 |
C localT :: local copy of tracer field |
C localT :: local copy of tracer field |
110 |
INTEGER i,j |
INTEGER i,j |
111 |
_RL df4 (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RL df4 (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
112 |
_RL fZon (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RL fZon (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
114 |
_RL af (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RL af (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
115 |
_RL df (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RL df (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
116 |
_RL localT(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RL localT(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
117 |
|
_RL advFac, rAdvFac |
118 |
CEOP |
CEOP |
119 |
|
|
120 |
#ifdef ALLOW_AUTODIFF_TAMC |
#ifdef ALLOW_AUTODIFF_TAMC |
123 |
fVerT(1,1,kDown) = fVerT(1,1,kDown) |
fVerT(1,1,kDown) = fVerT(1,1,kDown) |
124 |
#endif |
#endif |
125 |
|
|
126 |
|
advFac = 0. _d 0 |
127 |
|
IF (calcAdvection) advFac = 1. _d 0 |
128 |
|
rAdvFac = rkFac*advFac |
129 |
|
IF (implicitAdvection) rAdvFac = 0. _d 0 |
130 |
|
|
131 |
DO j=1-OLy,sNy+OLy |
DO j=1-OLy,sNy+OLy |
132 |
DO i=1-OLx,sNx+OLx |
DO i=1-OLx,sNx+OLx |
133 |
fZon(i,j) = 0. _d 0 |
fZon(i,j) = 0. _d 0 |
135 |
fVerT(i,j,kUp) = 0. _d 0 |
fVerT(i,j,kUp) = 0. _d 0 |
136 |
df(i,j) = 0. _d 0 |
df(i,j) = 0. _d 0 |
137 |
df4(i,j) = 0. _d 0 |
df4(i,j) = 0. _d 0 |
|
localT(i,j) = 0. _d 0 |
|
138 |
ENDDO |
ENDDO |
139 |
ENDDO |
ENDDO |
140 |
|
|
147 |
|
|
148 |
C-- Unless we have already calculated the advection terms we initialize |
C-- Unless we have already calculated the advection terms we initialize |
149 |
C the tendency to zero. |
C the tendency to zero. |
150 |
IF (calcAdvection) THEN |
C <== now done earlier at the beginning of thermodynamics. |
151 |
DO j=1-Oly,sNy+Oly |
c IF (calcAdvection) THEN |
152 |
DO i=1-Olx,sNx+Olx |
c DO j=1-Oly,sNy+Oly |
153 |
gTracer(i,j,k,bi,bj)=0. _d 0 |
c DO i=1-Olx,sNx+Olx |
154 |
ENDDO |
c gTracer(i,j,k,bi,bj)=0. _d 0 |
155 |
ENDDO |
c ENDDO |
156 |
ENDIF |
c ENDDO |
157 |
|
c ENDIF |
158 |
|
|
159 |
C-- Pre-calculate del^2 T if bi-harmonic coefficient is non-zero |
C-- Pre-calculate del^2 T if bi-harmonic coefficient is non-zero |
160 |
IF (diffK4 .NE. 0.) THEN |
IF (diffK4 .NE. 0.) THEN |
307 |
ENDDO |
ENDDO |
308 |
ENDIF |
ENDIF |
309 |
|
|
|
#ifdef NONLIN_FRSURF |
|
|
C-- Compute vertical flux fVerT(kDown) at interface k+1 (between k & k+1): |
|
|
IF ( calcAdvection .AND. K.EQ.Nr .AND. |
|
|
& useRealFreshWaterFlux .AND. |
|
|
& buoyancyRelation .EQ. 'OCEANICP' ) THEN |
|
|
DO j=1-Oly,sNy+Oly |
|
|
DO i=1-Olx,sNx+Olx |
|
|
fVerT(i,j,kDown) = convertEmP2rUnit*PmEpR(i,j,bi,bj) |
|
|
& *rA(i,j,bi,bj)*maskC(i,j,k,bi,bj)*Tracer(i,j,k,bi,bj) |
|
|
ENDDO |
|
|
ENDDO |
|
|
ENDIF |
|
|
#endif /* NONLIN_FRSURF */ |
|
|
|
|
310 |
C-- Compute vertical flux fVerT(kUp) at interface k (between k-1 & k): |
C-- Compute vertical flux fVerT(kUp) at interface k (between k-1 & k): |
311 |
C- Advective flux in R |
C- Advective flux in R |
312 |
IF (calcAdvection) THEN |
IF (calcAdvection .AND. .NOT.implicitAdvection .AND. K.GE.2) THEN |
|
C Note: wVel needs to be masked |
|
|
IF (K.GE.2) THEN |
|
313 |
C- Compute vertical advective flux in the interior: |
C- Compute vertical advective flux in the interior: |
314 |
IF (advectionScheme.EQ.ENUM_CENTERED_2ND) THEN |
IF (advectionScheme.EQ.ENUM_CENTERED_2ND) THEN |
315 |
CALL GAD_C2_ADV_R(bi,bj,k,rTrans,tracer,af,myThid) |
CALL GAD_C2_ADV_R(bi,bj,k,rTrans,tracer,af,myThid) |
329 |
ELSE |
ELSE |
330 |
STOP 'GAD_CALC_RHS: Bad advectionScheme (R)' |
STOP 'GAD_CALC_RHS: Bad advectionScheme (R)' |
331 |
ENDIF |
ENDIF |
332 |
C- Surface "correction" term at k>1 : |
C- add the advective flux to fVerT |
333 |
DO j=1-Oly,sNy+Oly |
DO j=1-Oly,sNy+Oly |
334 |
DO i=1-Olx,sNx+Olx |
DO i=1-Olx,sNx+Olx |
335 |
af(i,j) = af(i,j) |
fVerT(i,j,kUp) = fVerT(i,j,kUp) + af(i,j) |
|
& + (maskC(i,j,k,bi,bj)-maskC(i,j,k-1,bi,bj))* |
|
|
& rTrans(i,j)*Tracer(i,j,k,bi,bj) |
|
336 |
ENDDO |
ENDDO |
|
ENDDO |
|
|
ELSE |
|
|
C- Surface "correction" term at k=1 : |
|
|
DO j=1-Oly,sNy+Oly |
|
|
DO i=1-Olx,sNx+Olx |
|
|
af(i,j) = rTrans(i,j)*Tracer(i,j,k,bi,bj) |
|
|
ENDDO |
|
|
ENDDO |
|
|
ENDIF |
|
|
C- add the advective flux to fVerT |
|
|
DO j=1-Oly,sNy+Oly |
|
|
DO i=1-Olx,sNx+Olx |
|
|
fVerT(i,j,kUp) = fVerT(i,j,kUp) + af(i,j) |
|
337 |
ENDDO |
ENDDO |
|
ENDDO |
|
338 |
ENDIF |
ENDIF |
339 |
|
|
340 |
C- Diffusive flux in R |
C- Diffusive flux in R |
388 |
I KappaRT, |
I KappaRT, |
389 |
U df ) |
U df ) |
390 |
#ifdef ALLOW_PTRACERS |
#ifdef ALLOW_PTRACERS |
391 |
ELSEIF (tracerIdentity .GE. GAD_TR1 .AND. |
ELSEIF (tracerIdentity .GE. GAD_TR1) THEN |
|
& tracerIdentity .LE. (GAD_TR1+PTRACERS_numInUse-1)) THEN |
|
392 |
CALL KPP_TRANSPORT_PTR( |
CALL KPP_TRANSPORT_PTR( |
393 |
I iMin,iMax,jMin,jMax,bi,bj,k,km1, |
I iMin,iMax,jMin,jMax,bi,bj,k,km1, |
394 |
I tracerIdentity,KappaRT, |
I tracerIdentity-GAD_TR1+1,KappaRT, |
395 |
U df ) |
U df ) |
396 |
#endif |
#endif |
397 |
ELSE |
ELSE |
410 |
DO j=1-Oly,sNy+Oly-1 |
DO j=1-Oly,sNy+Oly-1 |
411 |
DO i=1-Olx,sNx+Olx-1 |
DO i=1-Olx,sNx+Olx-1 |
412 |
gTracer(i,j,k,bi,bj)=gTracer(i,j,k,bi,bj) |
gTracer(i,j,k,bi,bj)=gTracer(i,j,k,bi,bj) |
413 |
& -_recip_hFacC(i,j,k,bi,bj)*recip_drF(k) |
& -_recip_hFacC(i,j,k,bi,bj)*recip_drF(k)*recip_rA(i,j,bi,bj) |
414 |
& *recip_rA(i,j,bi,bj) |
& *( (fZon(i+1,j)-fZon(i,j)) |
415 |
& *( |
& +(fMer(i,j+1)-fMer(i,j)) |
416 |
& +( fZon(i+1,j)-fZon(i,j) ) |
& +(fVerT(i,j,kUp)-fVerT(i,j,kDown))*rkFac |
417 |
& +( fMer(i,j+1)-fMer(i,j) ) |
& -localT(i,j)*( (uTrans(i+1,j)-uTrans(i,j)) |
418 |
& +( fVerT(i,j,kUp)-fVerT(i,j,kDown) )*rkFac |
& +(vTrans(i,j+1)-vTrans(i,j)) |
419 |
|
& +(rTrans(i,j)-rTransKp1(i,j))*rAdvFac |
420 |
|
& )*advFac |
421 |
& ) |
& ) |
422 |
ENDDO |
ENDDO |
423 |
ENDDO |
ENDDO |
424 |
|
|
|
#ifdef NONLIN_FRSURF |
|
|
C-- account for 3.D divergence of the flow in rStar coordinate: |
|
|
IF (calcAdvection .AND. select_rStar.GT.0) THEN |
|
|
DO j=1-Oly,sNy+Oly-1 |
|
|
DO i=1-Olx,sNx+Olx-1 |
|
|
gTracer(i,j,k,bi,bj) = gTracer(i,j,k,bi,bj) |
|
|
& - (rStarExpC(i,j,bi,bj) - 1. _d 0)/deltaTfreesurf |
|
|
& *tracer(i,j,k,bi,bj)*maskC(i,j,k,bi,bj) |
|
|
ENDDO |
|
|
ENDDO |
|
|
ENDIF |
|
|
IF (calcAdvection .AND. select_rStar.LT.0) THEN |
|
|
DO j=1-Oly,sNy+Oly-1 |
|
|
DO i=1-Olx,sNx+Olx-1 |
|
|
gTracer(i,j,k,bi,bj) = gTracer(i,j,k,bi,bj) |
|
|
& - rStarDhCDt(i,j,bi,bj) |
|
|
& *tracer(i,j,k,bi,bj)*maskC(i,j,k,bi,bj) |
|
|
ENDDO |
|
|
ENDDO |
|
|
ENDIF |
|
|
#endif /* NONLIN_FRSURF */ |
|
|
|
|
|
|
|
425 |
RETURN |
RETURN |
426 |
END |
END |