1 |
C $Header: /u/gcmpack/MITgcm/pkg/generic_advdiff/gad_calc_rhs.F,v 1.39 2006/02/26 01:56:27 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "GAD_OPTIONS.h" |
5 |
|
6 |
CBOP |
7 |
C !ROUTINE: GAD_CALC_RHS |
8 |
|
9 |
C !INTERFACE: ========================================================== |
10 |
SUBROUTINE GAD_CALC_RHS( |
11 |
I bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown, |
12 |
I xA,yA,uTrans,vTrans,rTrans,rTransKp1,maskUp, |
13 |
I uVel, vVel, wVel, |
14 |
I diffKh, diffK4, KappaR, TracerN, TracAB, |
15 |
I tracerIdentity, advectionScheme, vertAdvecScheme, |
16 |
I calcAdvection, implicitAdvection, applyAB_onTracer, |
17 |
U fVerT, gTracer, |
18 |
I myTime, myIter, myThid ) |
19 |
|
20 |
C !DESCRIPTION: |
21 |
C Calculates the tendency of a tracer due to advection and diffusion. |
22 |
C It calculates the fluxes in each direction indepentently and then |
23 |
C sets the tendency to the divergence of these fluxes. The advective |
24 |
C fluxes are only calculated here when using the linear advection schemes |
25 |
C otherwise only the diffusive and parameterized fluxes are calculated. |
26 |
C |
27 |
C Contributions to the flux are calculated and added: |
28 |
C \begin{equation*} |
29 |
C {\bf F} = {\bf F}_{adv} + {\bf F}_{diff} +{\bf F}_{GM} + {\bf F}_{KPP} |
30 |
C \end{equation*} |
31 |
C |
32 |
C The tendency is the divergence of the fluxes: |
33 |
C \begin{equation*} |
34 |
C G_\theta = G_\theta + \nabla \cdot {\bf F} |
35 |
C \end{equation*} |
36 |
C |
37 |
C The tendency is assumed to contain data on entry. |
38 |
|
39 |
C !USES: =============================================================== |
40 |
IMPLICIT NONE |
41 |
#include "SIZE.h" |
42 |
#include "EEPARAMS.h" |
43 |
#include "PARAMS.h" |
44 |
#include "GRID.h" |
45 |
#include "SURFACE.h" |
46 |
#include "GAD.h" |
47 |
|
48 |
#ifdef ALLOW_AUTODIFF_TAMC |
49 |
#include "tamc.h" |
50 |
#include "tamc_keys.h" |
51 |
#endif /* ALLOW_AUTODIFF_TAMC */ |
52 |
|
53 |
C !INPUT PARAMETERS: =================================================== |
54 |
C bi,bj :: tile indices |
55 |
C iMin,iMax :: loop range for called routines |
56 |
C jMin,jMax :: loop range for called routines |
57 |
C kup :: index into 2 1/2D array, toggles between 1|2 |
58 |
C kdown :: index into 2 1/2D array, toggles between 2|1 |
59 |
C kp1 :: =k+1 for k<Nr, =Nr for k=Nr |
60 |
C xA,yA :: areas of X and Y face of tracer cells |
61 |
C uTrans,vTrans :: 2-D arrays of volume transports at U,V points |
62 |
C rTrans :: 2-D arrays of volume transports at W points |
63 |
C rTransKp1 :: 2-D array of volume trans at W pts, interf k+1 |
64 |
C maskUp :: 2-D array for mask at W points |
65 |
C uVel,vVel,wVel :: 3 components of the velcity field (3-D array) |
66 |
C diffKh :: horizontal diffusion coefficient |
67 |
C diffK4 :: bi-harmonic diffusion coefficient |
68 |
C KappaR :: 2-D array for vertical diffusion coefficient, interf k |
69 |
C TracerN :: tracer field @ time-step n (Note: only used |
70 |
C if applying AB on tracer field rather than on tendency gTr) |
71 |
C TracAB :: current tracer field (@ time-step n if applying AB on gTr |
72 |
C or extrapolated fwd in time to n+1/2 if applying AB on Tr) |
73 |
C tracerIdentity :: tracer identifier (required for KPP,GM) |
74 |
C advectionScheme :: advection scheme to use (Horizontal plane) |
75 |
C vertAdvecScheme :: advection scheme to use (Vertical direction) |
76 |
C calcAdvection :: =False if Advec computed with multiDim scheme |
77 |
C implicitAdvection:: =True if vertical Advec computed implicitly |
78 |
C applyAB_onTracer :: apply Adams-Bashforth on Tracer (rather than on gTr) |
79 |
C myTime :: current time |
80 |
C myIter :: iteration number |
81 |
C myThid :: thread number |
82 |
INTEGER bi,bj,iMin,iMax,jMin,jMax |
83 |
INTEGER k,kUp,kDown,kM1 |
84 |
_RS xA (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
85 |
_RS yA (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
86 |
_RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
87 |
_RL vTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
88 |
_RL rTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
89 |
_RL rTransKp1(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
90 |
_RS maskUp(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
91 |
_RL uVel (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
92 |
_RL vVel (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
93 |
_RL wVel (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
94 |
_RL diffKh, diffK4 |
95 |
_RL KappaR(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
96 |
_RL TracerN(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
97 |
_RL TracAB (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
98 |
INTEGER tracerIdentity |
99 |
INTEGER advectionScheme, vertAdvecScheme |
100 |
LOGICAL calcAdvection |
101 |
LOGICAL implicitAdvection, applyAB_onTracer |
102 |
_RL myTime |
103 |
INTEGER myIter, myThid |
104 |
|
105 |
C !OUTPUT PARAMETERS: ================================================== |
106 |
C gTracer :: tendency array |
107 |
C fVerT :: 2 1/2D arrays for vertical advective flux |
108 |
_RL gTracer(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
109 |
_RL fVerT (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2) |
110 |
|
111 |
C !LOCAL VARIABLES: ==================================================== |
112 |
C i,j :: loop indices |
113 |
C df4 :: used for storing del^2 T for bi-harmonic term |
114 |
C fZon :: zonal flux |
115 |
C fMer :: meridional flux |
116 |
C af :: advective flux |
117 |
C df :: diffusive flux |
118 |
C localT :: local copy of tracer field |
119 |
C locABT :: local copy of (AB-extrapolated) tracer field |
120 |
#ifdef ALLOW_DIAGNOSTICS |
121 |
CHARACTER*8 diagName |
122 |
CHARACTER*4 GAD_DIAG_SUFX, diagSufx |
123 |
EXTERNAL GAD_DIAG_SUFX |
124 |
#endif |
125 |
INTEGER i,j |
126 |
_RL df4 (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
127 |
_RL fZon (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
128 |
_RL fMer (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
129 |
_RL af (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
130 |
_RL df (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
131 |
_RL localT(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
132 |
_RL locABT(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
133 |
_RL advFac, rAdvFac |
134 |
CEOP |
135 |
|
136 |
#ifdef ALLOW_AUTODIFF_TAMC |
137 |
C-- only the kUp part of fverT is set in this subroutine |
138 |
C-- the kDown is still required |
139 |
fVerT(1,1,kDown) = fVerT(1,1,kDown) |
140 |
#endif |
141 |
|
142 |
#ifdef ALLOW_DIAGNOSTICS |
143 |
C-- Set diagnostic suffix for the current tracer |
144 |
IF ( useDiagnostics ) THEN |
145 |
diagSufx = GAD_DIAG_SUFX( tracerIdentity, myThid ) |
146 |
ENDIF |
147 |
#endif |
148 |
|
149 |
advFac = 0. _d 0 |
150 |
IF (calcAdvection) advFac = 1. _d 0 |
151 |
rAdvFac = rkSign*advFac |
152 |
IF (implicitAdvection) rAdvFac = 0. _d 0 |
153 |
|
154 |
DO j=1-OLy,sNy+OLy |
155 |
DO i=1-OLx,sNx+OLx |
156 |
fZon(i,j) = 0. _d 0 |
157 |
fMer(i,j) = 0. _d 0 |
158 |
fVerT(i,j,kUp) = 0. _d 0 |
159 |
df(i,j) = 0. _d 0 |
160 |
df4(i,j) = 0. _d 0 |
161 |
ENDDO |
162 |
ENDDO |
163 |
|
164 |
C-- Make local copy of tracer array |
165 |
IF ( applyAB_onTracer ) THEN |
166 |
DO j=1-OLy,sNy+OLy |
167 |
DO i=1-OLx,sNx+OLx |
168 |
localT(i,j)=TracerN(i,j,k,bi,bj) |
169 |
locABT(i,j)= TracAB(i,j,k,bi,bj) |
170 |
ENDDO |
171 |
ENDDO |
172 |
ELSE |
173 |
DO j=1-OLy,sNy+OLy |
174 |
DO i=1-OLx,sNx+OLx |
175 |
localT(i,j)= TracAB(i,j,k,bi,bj) |
176 |
locABT(i,j)= TracAB(i,j,k,bi,bj) |
177 |
ENDDO |
178 |
ENDDO |
179 |
ENDIF |
180 |
|
181 |
C-- Unless we have already calculated the advection terms we initialize |
182 |
C the tendency to zero. |
183 |
C <== now done earlier at the beginning of thermodynamics. |
184 |
c IF (calcAdvection) THEN |
185 |
c DO j=1-Oly,sNy+Oly |
186 |
c DO i=1-Olx,sNx+Olx |
187 |
c gTracer(i,j,k,bi,bj)=0. _d 0 |
188 |
c ENDDO |
189 |
c ENDDO |
190 |
c ENDIF |
191 |
|
192 |
C-- Pre-calculate del^2 T if bi-harmonic coefficient is non-zero |
193 |
IF (diffK4 .NE. 0.) THEN |
194 |
CALL GAD_GRAD_X(bi,bj,k,xA,localT,fZon,myThid) |
195 |
CALL GAD_GRAD_Y(bi,bj,k,yA,localT,fMer,myThid) |
196 |
CALL GAD_DEL2(bi,bj,k,fZon,fMer,df4,myThid) |
197 |
ENDIF |
198 |
|
199 |
C-- Initialize net flux in X direction |
200 |
DO j=1-Oly,sNy+Oly |
201 |
DO i=1-Olx,sNx+Olx |
202 |
fZon(i,j) = 0. _d 0 |
203 |
ENDDO |
204 |
ENDDO |
205 |
|
206 |
C- Advective flux in X |
207 |
IF (calcAdvection) THEN |
208 |
IF (advectionScheme.EQ.ENUM_CENTERED_2ND) THEN |
209 |
CALL GAD_C2_ADV_X(bi,bj,k,uTrans,locABT,af,myThid) |
210 |
ELSEIF ( advectionScheme.EQ.ENUM_UPWIND_1RST |
211 |
& .OR. advectionScheme.EQ.ENUM_DST2 ) THEN |
212 |
CALL GAD_DST2U1_ADV_X( bi,bj,k, advectionScheme, |
213 |
I dTtracerLev(k), uTrans, uVel, locABT, |
214 |
O af, myThid ) |
215 |
ELSEIF (advectionScheme.EQ.ENUM_FLUX_LIMIT) THEN |
216 |
CALL GAD_FLUXLIMIT_ADV_X( bi,bj,k, dTtracerLev(k), |
217 |
I uTrans, uVel, maskW(1-Olx,1-Oly,k,bi,bj), locABT, |
218 |
O af, myThid ) |
219 |
ELSEIF (advectionScheme.EQ.ENUM_UPWIND_3RD ) THEN |
220 |
CALL GAD_U3_ADV_X(bi,bj,k,uTrans,locABT,af,myThid) |
221 |
ELSEIF (advectionScheme.EQ.ENUM_CENTERED_4TH) THEN |
222 |
CALL GAD_C4_ADV_X(bi,bj,k,uTrans,locABT,af,myThid) |
223 |
ELSEIF (advectionScheme.EQ.ENUM_DST3 ) THEN |
224 |
CALL GAD_DST3_ADV_X( bi,bj,k, dTtracerLev(k), |
225 |
I uTrans, uVel, maskW(1-Olx,1-Oly,k,bi,bj), locABT, |
226 |
O af, myThid ) |
227 |
ELSEIF (advectionScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN |
228 |
IF ( inAdMode ) THEN |
229 |
cph This block is to trick the adjoint: |
230 |
cph IF inAdExact=.FALSE., we want to use DST3 |
231 |
cph with limiters in forward, but without limiters in reverse. |
232 |
CALL GAD_DST3_ADV_X( bi,bj,k, dTtracerLev(k), |
233 |
I uTrans, uVel, maskW(1-Olx,1-Oly,k,bi,bj), locABT, |
234 |
O af, myThid ) |
235 |
ELSE |
236 |
CALL GAD_DST3FL_ADV_X( bi,bj,k, dTtracerLev(k), |
237 |
I uTrans, uVel, maskW(1-Olx,1-Oly,k,bi,bj), locABT, |
238 |
O af, myThid ) |
239 |
ENDIF |
240 |
ELSE |
241 |
STOP 'GAD_CALC_RHS: Bad advectionScheme (X)' |
242 |
ENDIF |
243 |
DO j=1-Oly,sNy+Oly |
244 |
DO i=1-Olx,sNx+Olx |
245 |
fZon(i,j) = fZon(i,j) + af(i,j) |
246 |
ENDDO |
247 |
ENDDO |
248 |
#ifdef ALLOW_DIAGNOSTICS |
249 |
IF ( useDiagnostics ) THEN |
250 |
diagName = 'ADVx'//diagSufx |
251 |
CALL DIAGNOSTICS_FILL(af,diagName, k,1, 2,bi,bj, myThid) |
252 |
ENDIF |
253 |
#endif |
254 |
ENDIF |
255 |
|
256 |
C- Diffusive flux in X |
257 |
IF (diffKh.NE.0.) THEN |
258 |
CALL GAD_DIFF_X(bi,bj,k,xA,diffKh,localT,df,myThid) |
259 |
ELSE |
260 |
DO j=1-Oly,sNy+Oly |
261 |
DO i=1-Olx,sNx+Olx |
262 |
df(i,j) = 0. _d 0 |
263 |
ENDDO |
264 |
ENDDO |
265 |
ENDIF |
266 |
|
267 |
C- Add bi-harmonic diffusive flux in X |
268 |
IF (diffK4 .NE. 0.) THEN |
269 |
CALL GAD_BIHARM_X(bi,bj,k,xA,df4,diffK4,df,myThid) |
270 |
ENDIF |
271 |
|
272 |
#ifdef ALLOW_GMREDI |
273 |
C- GM/Redi flux in X |
274 |
IF (useGMRedi) THEN |
275 |
C *note* should update GMREDI_XTRANSPORT to set df *aja* |
276 |
IF ( applyAB_onTracer ) THEN |
277 |
CALL GMREDI_XTRANSPORT( |
278 |
I iMin,iMax,jMin,jMax,bi,bj,k, |
279 |
I xA,TracerN,tracerIdentity, |
280 |
U df, |
281 |
I myThid) |
282 |
ELSE |
283 |
CALL GMREDI_XTRANSPORT( |
284 |
I iMin,iMax,jMin,jMax,bi,bj,k, |
285 |
I xA,TracAB, tracerIdentity, |
286 |
U df, |
287 |
I myThid) |
288 |
ENDIF |
289 |
ENDIF |
290 |
#endif |
291 |
DO j=1-Oly,sNy+Oly |
292 |
DO i=1-Olx,sNx+Olx |
293 |
fZon(i,j) = fZon(i,j) + df(i,j) |
294 |
ENDDO |
295 |
ENDDO |
296 |
|
297 |
#ifdef ALLOW_DIAGNOSTICS |
298 |
C- Diagnostics of Tracer flux in X dir (mainly Diffusive term), |
299 |
C excluding advective terms: |
300 |
IF ( useDiagnostics .AND. |
301 |
& (diffKh.NE.0. .OR. diffK4 .NE.0. .OR. useGMRedi) ) THEN |
302 |
diagName = 'DIFx'//diagSufx |
303 |
CALL DIAGNOSTICS_FILL(df,diagName, k,1, 2,bi,bj, myThid) |
304 |
ENDIF |
305 |
#endif |
306 |
|
307 |
C-- Initialize net flux in Y direction |
308 |
DO j=1-Oly,sNy+Oly |
309 |
DO i=1-Olx,sNx+Olx |
310 |
fMer(i,j) = 0. _d 0 |
311 |
ENDDO |
312 |
ENDDO |
313 |
|
314 |
C- Advective flux in Y |
315 |
IF (calcAdvection) THEN |
316 |
IF (advectionScheme.EQ.ENUM_CENTERED_2ND) THEN |
317 |
CALL GAD_C2_ADV_Y(bi,bj,k,vTrans,locABT,af,myThid) |
318 |
ELSEIF ( advectionScheme.EQ.ENUM_UPWIND_1RST |
319 |
& .OR. advectionScheme.EQ.ENUM_DST2 ) THEN |
320 |
CALL GAD_DST2U1_ADV_Y( bi,bj,k, advectionScheme, |
321 |
I dTtracerLev(k), vTrans, vVel, locABT, |
322 |
O af, myThid ) |
323 |
ELSEIF (advectionScheme.EQ.ENUM_FLUX_LIMIT) THEN |
324 |
CALL GAD_FLUXLIMIT_ADV_Y( bi,bj,k, dTtracerLev(k), |
325 |
I vTrans, vVel, maskS(1-Olx,1-Oly,k,bi,bj), locABT, |
326 |
O af, myThid ) |
327 |
ELSEIF (advectionScheme.EQ.ENUM_UPWIND_3RD ) THEN |
328 |
CALL GAD_U3_ADV_Y(bi,bj,k,vTrans,locABT,af,myThid) |
329 |
ELSEIF (advectionScheme.EQ.ENUM_CENTERED_4TH) THEN |
330 |
CALL GAD_C4_ADV_Y(bi,bj,k,vTrans,locABT,af,myThid) |
331 |
ELSEIF (advectionScheme.EQ.ENUM_DST3 ) THEN |
332 |
CALL GAD_DST3_ADV_Y( bi,bj,k, dTtracerLev(k), |
333 |
I vTrans, vVel, maskS(1-Olx,1-Oly,k,bi,bj), locABT, |
334 |
O af, myThid ) |
335 |
ELSEIF (advectionScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN |
336 |
IF ( inAdMode ) THEN |
337 |
cph This block is to trick the adjoint: |
338 |
cph IF inAdExact=.FALSE., we want to use DST3 |
339 |
cph with limiters in forward, but without limiters in reverse. |
340 |
CALL GAD_DST3_ADV_Y( bi,bj,k, dTtracerLev(k), |
341 |
I vTrans, vVel, maskS(1-Olx,1-Oly,k,bi,bj), locABT, |
342 |
O af, myThid ) |
343 |
ELSE |
344 |
CALL GAD_DST3FL_ADV_Y( bi,bj,k, dTtracerLev(k), |
345 |
I vTrans, vVel, maskS(1-Olx,1-Oly,k,bi,bj), locABT, |
346 |
O af, myThid ) |
347 |
ENDIF |
348 |
ELSE |
349 |
STOP 'GAD_CALC_RHS: Bad advectionScheme (Y)' |
350 |
ENDIF |
351 |
DO j=1-Oly,sNy+Oly |
352 |
DO i=1-Olx,sNx+Olx |
353 |
fMer(i,j) = fMer(i,j) + af(i,j) |
354 |
ENDDO |
355 |
ENDDO |
356 |
#ifdef ALLOW_DIAGNOSTICS |
357 |
IF ( useDiagnostics ) THEN |
358 |
diagName = 'ADVy'//diagSufx |
359 |
CALL DIAGNOSTICS_FILL(af,diagName, k,1, 2,bi,bj, myThid) |
360 |
ENDIF |
361 |
#endif |
362 |
ENDIF |
363 |
|
364 |
C- Diffusive flux in Y |
365 |
IF (diffKh.NE.0.) THEN |
366 |
CALL GAD_DIFF_Y(bi,bj,k,yA,diffKh,localT,df,myThid) |
367 |
ELSE |
368 |
DO j=1-Oly,sNy+Oly |
369 |
DO i=1-Olx,sNx+Olx |
370 |
df(i,j) = 0. _d 0 |
371 |
ENDDO |
372 |
ENDDO |
373 |
ENDIF |
374 |
|
375 |
C- Add bi-harmonic flux in Y |
376 |
IF (diffK4 .NE. 0.) THEN |
377 |
CALL GAD_BIHARM_Y(bi,bj,k,yA,df4,diffK4,df,myThid) |
378 |
ENDIF |
379 |
|
380 |
#ifdef ALLOW_GMREDI |
381 |
C- GM/Redi flux in Y |
382 |
IF (useGMRedi) THEN |
383 |
C *note* should update GMREDI_YTRANSPORT to set df *aja* |
384 |
IF ( applyAB_onTracer ) THEN |
385 |
CALL GMREDI_YTRANSPORT( |
386 |
I iMin,iMax,jMin,jMax,bi,bj,k, |
387 |
I yA,TracerN,tracerIdentity, |
388 |
U df, |
389 |
I myThid) |
390 |
ELSE |
391 |
CALL GMREDI_YTRANSPORT( |
392 |
I iMin,iMax,jMin,jMax,bi,bj,k, |
393 |
I yA,TracAB, tracerIdentity, |
394 |
U df, |
395 |
I myThid) |
396 |
ENDIF |
397 |
ENDIF |
398 |
#endif |
399 |
DO j=1-Oly,sNy+Oly |
400 |
DO i=1-Olx,sNx+Olx |
401 |
fMer(i,j) = fMer(i,j) + df(i,j) |
402 |
ENDDO |
403 |
ENDDO |
404 |
|
405 |
#ifdef ALLOW_DIAGNOSTICS |
406 |
C- Diagnostics of Tracer flux in Y dir (mainly Diffusive terms), |
407 |
C excluding advective terms: |
408 |
IF ( useDiagnostics .AND. |
409 |
& (diffKh.NE.0. .OR. diffK4 .NE.0. .OR. useGMRedi) ) THEN |
410 |
diagName = 'DIFy'//diagSufx |
411 |
CALL DIAGNOSTICS_FILL(df,diagName, k,1, 2,bi,bj, myThid) |
412 |
ENDIF |
413 |
#endif |
414 |
|
415 |
C-- Compute vertical flux fVerT(kUp) at interface k (between k-1 & k): |
416 |
C- Advective flux in R |
417 |
#ifdef ALLOW_AIM |
418 |
C- a hack to prevent Water-Vapor vert.transport into the stratospheric level Nr |
419 |
IF (calcAdvection .AND. .NOT.implicitAdvection .AND. k.GE.2 .AND. |
420 |
& (.NOT.useAIM .OR.tracerIdentity.NE.GAD_SALINITY .OR.k.LT.Nr) |
421 |
& ) THEN |
422 |
#else |
423 |
IF (calcAdvection .AND. .NOT.implicitAdvection .AND. k.GE.2) THEN |
424 |
#endif |
425 |
C- Compute vertical advective flux in the interior: |
426 |
IF (vertAdvecScheme.EQ.ENUM_CENTERED_2ND) THEN |
427 |
CALL GAD_C2_ADV_R(bi,bj,k,rTrans,TracAB,af,myThid) |
428 |
ELSEIF ( vertAdvecScheme.EQ.ENUM_UPWIND_1RST |
429 |
& .OR. vertAdvecScheme.EQ.ENUM_DST2 ) THEN |
430 |
CALL GAD_DST2U1_ADV_R( bi,bj,k, vertAdvecScheme, |
431 |
I dTtracerLev(k),rTrans,wVel,TracAB(1-Olx,1-Oly,1,bi,bj), |
432 |
O af, myThid ) |
433 |
ELSEIF (vertAdvecScheme.EQ.ENUM_FLUX_LIMIT) THEN |
434 |
CALL GAD_FLUXLIMIT_ADV_R( bi,bj,k, |
435 |
I dTtracerLev(k),rTrans,wVel,TracAB(1-Olx,1-Oly,1,bi,bj), |
436 |
O af, myThid ) |
437 |
ELSEIF (vertAdvecScheme.EQ.ENUM_UPWIND_3RD ) THEN |
438 |
CALL GAD_U3_ADV_R(bi,bj,k,rTrans,TracAB,af,myThid) |
439 |
ELSEIF (vertAdvecScheme.EQ.ENUM_CENTERED_4TH) THEN |
440 |
CALL GAD_C4_ADV_R(bi,bj,k,rTrans,TracAB,af,myThid) |
441 |
ELSEIF (vertAdvecScheme.EQ.ENUM_DST3 ) THEN |
442 |
CALL GAD_DST3_ADV_R( bi,bj,k, |
443 |
I dTtracerLev(k),rTrans,wVel,TracAB(1-Olx,1-Oly,1,bi,bj), |
444 |
O af, myThid ) |
445 |
ELSEIF (vertAdvecScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN |
446 |
cph This block is to trick the adjoint: |
447 |
cph IF inAdExact=.FALSE., we want to use DST3 |
448 |
cph with limiters in forward, but without limiters in reverse. |
449 |
IF ( inAdMode ) THEN |
450 |
CALL GAD_DST3_ADV_R( bi,bj,k, |
451 |
I dTtracerLev(k),rTrans,wVel,TracAB(1-Olx,1-Oly,1,bi,bj), |
452 |
O af, myThid ) |
453 |
ELSE |
454 |
CALL GAD_DST3FL_ADV_R( bi,bj,k, |
455 |
I dTtracerLev(k),rTrans,wVel,TracAB(1-Olx,1-Oly,1,bi,bj), |
456 |
O af, myThid ) |
457 |
ENDIF |
458 |
ELSE |
459 |
STOP 'GAD_CALC_RHS: Bad vertAdvecScheme (R)' |
460 |
ENDIF |
461 |
C- add the advective flux to fVerT |
462 |
DO j=1-Oly,sNy+Oly |
463 |
DO i=1-Olx,sNx+Olx |
464 |
fVerT(i,j,kUp) = fVerT(i,j,kUp) + af(i,j) |
465 |
ENDDO |
466 |
ENDDO |
467 |
#ifdef ALLOW_DIAGNOSTICS |
468 |
IF ( useDiagnostics ) THEN |
469 |
diagName = 'ADVr'//diagSufx |
470 |
CALL DIAGNOSTICS_FILL(af,diagName, k,1, 2,bi,bj, myThid) |
471 |
C- note: needs to explicitly increment the counter since DIAGNOSTICS_FILL |
472 |
C does it only if k=1 (never the case here) |
473 |
IF ( k.EQ.2 ) CALL DIAGNOSTICS_COUNT(diagName,bi,bj,myThid) |
474 |
ENDIF |
475 |
#endif |
476 |
ENDIF |
477 |
|
478 |
C- Diffusive flux in R |
479 |
C Note: For K=1 then KM1=1 and this gives a dT/dr = 0 upper |
480 |
C boundary condition. |
481 |
IF (implicitDiffusion) THEN |
482 |
DO j=1-Oly,sNy+Oly |
483 |
DO i=1-Olx,sNx+Olx |
484 |
df(i,j) = 0. _d 0 |
485 |
ENDDO |
486 |
ENDDO |
487 |
ELSE |
488 |
IF ( applyAB_onTracer ) THEN |
489 |
CALL GAD_DIFF_R(bi,bj,k,KappaR,TracerN,df,myThid) |
490 |
ELSE |
491 |
CALL GAD_DIFF_R(bi,bj,k,KappaR,TracAB, df,myThid) |
492 |
ENDIF |
493 |
ENDIF |
494 |
|
495 |
#ifdef ALLOW_GMREDI |
496 |
C- GM/Redi flux in R |
497 |
IF (useGMRedi) THEN |
498 |
C *note* should update GMREDI_RTRANSPORT to set df *aja* |
499 |
IF ( applyAB_onTracer ) THEN |
500 |
CALL GMREDI_RTRANSPORT( |
501 |
I iMin,iMax,jMin,jMax,bi,bj,k, |
502 |
I TracerN,tracerIdentity, |
503 |
U df, |
504 |
I myThid) |
505 |
ELSE |
506 |
CALL GMREDI_RTRANSPORT( |
507 |
I iMin,iMax,jMin,jMax,bi,bj,k, |
508 |
I TracAB, tracerIdentity, |
509 |
U df, |
510 |
I myThid) |
511 |
ENDIF |
512 |
ENDIF |
513 |
#endif |
514 |
|
515 |
DO j=1-Oly,sNy+Oly |
516 |
DO i=1-Olx,sNx+Olx |
517 |
fVerT(i,j,kUp) = fVerT(i,j,kUp) + df(i,j)*maskUp(i,j) |
518 |
ENDDO |
519 |
ENDDO |
520 |
|
521 |
#ifdef ALLOW_DIAGNOSTICS |
522 |
C- Diagnostics of Tracer flux in R dir (mainly Diffusive terms), |
523 |
C Explicit terms only & excluding advective terms: |
524 |
IF ( useDiagnostics .AND. |
525 |
& (.NOT.implicitDiffusion .OR. useGMRedi) ) THEN |
526 |
diagName = 'DFrE'//diagSufx |
527 |
CALL DIAGNOSTICS_FILL(df,diagName, k,1, 2,bi,bj, myThid) |
528 |
ENDIF |
529 |
#endif |
530 |
|
531 |
#ifdef ALLOW_KPP |
532 |
C- Set non local KPP transport term (ghat): |
533 |
IF ( useKPP .AND. k.GE.2 ) THEN |
534 |
DO j=1-Oly,sNy+Oly |
535 |
DO i=1-Olx,sNx+Olx |
536 |
df(i,j) = 0. _d 0 |
537 |
ENDDO |
538 |
ENDDO |
539 |
IF (tracerIdentity.EQ.GAD_TEMPERATURE) THEN |
540 |
CALL KPP_TRANSPORT_T( |
541 |
I iMin,iMax,jMin,jMax,bi,bj,k,km1, |
542 |
O df ) |
543 |
ELSEIF (tracerIdentity.EQ.GAD_SALINITY) THEN |
544 |
CALL KPP_TRANSPORT_S( |
545 |
I iMin,iMax,jMin,jMax,bi,bj,k,km1, |
546 |
O df ) |
547 |
#ifdef ALLOW_PTRACERS |
548 |
ELSEIF (tracerIdentity .GE. GAD_TR1) THEN |
549 |
CALL KPP_TRANSPORT_PTR( |
550 |
I iMin,iMax,jMin,jMax,bi,bj,k,km1, |
551 |
I tracerIdentity-GAD_TR1+1, |
552 |
O df ) |
553 |
#endif |
554 |
ELSE |
555 |
PRINT*,'invalid tracer indentity: ', tracerIdentity |
556 |
STOP 'GAD_CALC_RHS: Ooops' |
557 |
ENDIF |
558 |
DO j=1-Oly,sNy+Oly |
559 |
DO i=1-Olx,sNx+Olx |
560 |
fVerT(i,j,kUp) = fVerT(i,j,kUp) + df(i,j)*maskUp(i,j) |
561 |
ENDDO |
562 |
ENDDO |
563 |
ENDIF |
564 |
#endif |
565 |
|
566 |
C-- Divergence of fluxes |
567 |
DO j=1-Oly,sNy+Oly-1 |
568 |
DO i=1-Olx,sNx+Olx-1 |
569 |
gTracer(i,j,k,bi,bj)=gTracer(i,j,k,bi,bj) |
570 |
& -_recip_hFacC(i,j,k,bi,bj)*recip_drF(k)*recip_rA(i,j,bi,bj) |
571 |
& *( (fZon(i+1,j)-fZon(i,j)) |
572 |
& +(fMer(i,j+1)-fMer(i,j)) |
573 |
& +(fVerT(i,j,kDown)-fVerT(i,j,kUp))*rkSign |
574 |
& -localT(i,j)*( (uTrans(i+1,j)-uTrans(i,j)) |
575 |
& +(vTrans(i,j+1)-vTrans(i,j)) |
576 |
& +(rTransKp1(i,j)-rTrans(i,j))*rAdvFac |
577 |
& )*advFac |
578 |
& ) |
579 |
ENDDO |
580 |
ENDDO |
581 |
|
582 |
#ifdef ALLOW_DEBUG |
583 |
IF ( debugLevel .GE. debLevB |
584 |
& .AND. tracerIdentity.EQ.GAD_TEMPERATURE |
585 |
& .AND. k.EQ.2 .AND. myIter.EQ.1+nIter0 |
586 |
& .AND. nPx.EQ.1 .AND. nPy.EQ.1 |
587 |
& .AND. useCubedSphereExchange ) THEN |
588 |
CALL DEBUG_CS_CORNER_UV( ' fZon,fMer from GAD_CALC_RHS', |
589 |
& fZon,fMer, k, standardMessageUnit,bi,bj,myThid ) |
590 |
ENDIF |
591 |
#endif /* ALLOW_DEBUG */ |
592 |
|
593 |
RETURN |
594 |
END |