1 |
C $Header: /u/gcmpack/models/MITgcmUV/model/src/calc_gt.F,v 1.32 2001/05/29 14:01:36 adcroft Exp $ |
2 |
C $Name: checkpoint40pre1 $ |
3 |
|
4 |
#include "CPP_OPTIONS.h" |
5 |
|
6 |
#define COSINEMETH_III |
7 |
#undef ISOTROPIC_COS_SCALING |
8 |
|
9 |
CStartOfInterFace |
10 |
SUBROUTINE CALC_GTR1( |
11 |
I bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown, |
12 |
I xA,yA,uTrans,vTrans,rTrans,maskUp, |
13 |
I KappaRT, |
14 |
U fVerT, |
15 |
I myCurrentTime, myThid ) |
16 |
C /==========================================================\ |
17 |
C | SUBROUTINE CALC_GTR1 | |
18 |
C | o Calculate the passive tracer tendency terms. | |
19 |
C |==========================================================| |
20 |
C | A procedure called EXTERNAL_FORCING_TR1 is called from | |
21 |
C | here. These procedures can be used to add per problem | |
22 |
C | heat flux source terms. | |
23 |
C | Note: Although it is slightly counter-intuitive the | |
24 |
C | EXTERNAL_FORCING routine is not the place to put | |
25 |
C | file I/O. Instead files that are required to | |
26 |
C | calculate the external source terms are generally | |
27 |
C | read during the model main loop. This makes the | |
28 |
C | logisitics of multi-processing simpler and also | |
29 |
C | makes the adjoint generation simpler. It also | |
30 |
C | allows for I/O to overlap computation where that | |
31 |
C | is supported by hardware. | |
32 |
C | Aside from the problem specific term the code here | |
33 |
C | forms the tendency terms due to advection and mixing | |
34 |
C | The baseline implementation here uses a centered | |
35 |
C | difference form for the advection term and a tensorial | |
36 |
C | divergence of a flux form for the diffusive term. The | |
37 |
C | diffusive term is formulated so that isopycnal mixing and| |
38 |
C | GM-style subgrid-scale terms can be incorporated b simply| |
39 |
C | setting the diffusion tensor terms appropriately. | |
40 |
C \==========================================================/ |
41 |
IMPLICIT NONE |
42 |
|
43 |
C == GLobal variables == |
44 |
#include "SIZE.h" |
45 |
#include "DYNVARS.h" |
46 |
#include "EEPARAMS.h" |
47 |
#include "PARAMS.h" |
48 |
#include "GRID.h" |
49 |
#include "FFIELDS.h" |
50 |
#include "TR1.h" |
51 |
c #include "GM_ARRAYS.h" |
52 |
|
53 |
|
54 |
C == Routine arguments == |
55 |
C fVerT - Flux of passive tracer (TR1) in the vertical |
56 |
C direction at the upper(U) and lower(D) faces of a cell. |
57 |
C maskUp - Land mask used to denote base of the domain. |
58 |
C xA - Tracer cell face area normal to X |
59 |
C yA - Tracer cell face area normal to X |
60 |
C uTrans - Zonal volume transport through cell face |
61 |
C vTrans - Meridional volume transport through cell face |
62 |
C rTrans - Vertical volume transport through cell face |
63 |
C bi, bj, iMin, iMax, jMin, jMax - Range of points for which calculation |
64 |
C results will be set. |
65 |
C myThid - Instance number for this innvocation of CALC_GTR1 |
66 |
_RL fVerT (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2) |
67 |
_RS xA (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
68 |
_RS yA (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
69 |
_RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
70 |
_RL vTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
71 |
_RL rTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
72 |
_RS maskUp(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
73 |
_RL KappaRT(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
74 |
INTEGER k,kUp,kDown,kM1 |
75 |
INTEGER bi,bj,iMin,iMax,jMin,jMax |
76 |
INTEGER myThid |
77 |
_RL myCurrentTime |
78 |
CEndOfInterface |
79 |
|
80 |
C == Local variables == |
81 |
C I, J, K - Loop counters |
82 |
INTEGER i,j |
83 |
LOGICAL TOP_LAYER |
84 |
_RL afFacT, dfFacT |
85 |
_RL df4 (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
86 |
_RL fZon (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
87 |
_RL fMer (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
88 |
_RL af (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
89 |
_RL df (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
90 |
|
91 |
#ifdef ALLOW_AUTODIFF_TAMC |
92 |
C-- only the kUp part of fverT is set in this subroutine |
93 |
C-- the kDown is still required |
94 |
fVerT(1,1,kDown) = fVerT(1,1,kDown) |
95 |
#endif |
96 |
DO j=1-OLy,sNy+OLy |
97 |
DO i=1-OLx,sNx+OLx |
98 |
fZon(i,j) = 0.0 |
99 |
fMer(i,j) = 0.0 |
100 |
fVerT(i,j,kUp) = 0.0 |
101 |
ENDDO |
102 |
ENDDO |
103 |
|
104 |
afFacT = 1. _d 0 |
105 |
dfFacT = 1. _d 0 |
106 |
TOP_LAYER = K .EQ. 1 |
107 |
|
108 |
C--- Calculate advective and diffusive fluxes between cells. |
109 |
|
110 |
#ifdef INCLUDE_TR1_DIFFUSION_CODE |
111 |
C o Zonal tracer gradient |
112 |
DO j=1-Oly,sNy+Oly |
113 |
DO i=1-Olx+1,sNx+Olx |
114 |
fZon(i,j) = _recip_dxC(i,j,bi,bj)*xA(i,j) |
115 |
& *(tr1(i,j,k,bi,bj)-tr1(i-1,j,k,bi,bj)) |
116 |
#ifdef COSINEMETH_III |
117 |
& *sqCosFacU(j,bi,bj) |
118 |
#endif |
119 |
ENDDO |
120 |
ENDDO |
121 |
C o Meridional tracer gradient |
122 |
DO j=1-Oly+1,sNy+Oly |
123 |
DO i=1-Olx,sNx+Olx |
124 |
fMer(i,j) = _recip_dyC(i,j,bi,bj)*yA(i,j) |
125 |
& *(tr1(i,j,k,bi,bj)-tr1(i,j-1,k,bi,bj)) |
126 |
#ifdef ISOTROPIC_COS_SCALING |
127 |
#ifdef COSINEMETH_III |
128 |
& *sqCosFacV(j,bi,bj) |
129 |
#endif |
130 |
#endif |
131 |
ENDDO |
132 |
ENDDO |
133 |
C-- del^2 of T, needed for bi-harmonic (del^4) term |
134 |
IF (diffK4T .NE. 0.) THEN |
135 |
DO j=1-Oly+1,sNy+Oly-1 |
136 |
DO i=1-Olx+1,sNx+Olx-1 |
137 |
df4(i,j)= _recip_hFacC(i,j,k,bi,bj) |
138 |
& *recip_drF(k)/_rA(i,j,bi,bj) |
139 |
& *( |
140 |
& +( fZon(i+1,j)-fZon(i,j) ) |
141 |
& +( fMer(i,j+1)-fMer(i,j) ) |
142 |
& ) |
143 |
ENDDO |
144 |
ENDDO |
145 |
ENDIF |
146 |
#endif |
147 |
|
148 |
C-- Zonal flux (fZon is at west face of "tr1" cell) |
149 |
#ifdef INCLUDE_TR1_ADVECTION_CODE |
150 |
C o Advective component of zonal flux |
151 |
DO j=jMin,jMax |
152 |
DO i=iMin,iMax |
153 |
af(i,j) = |
154 |
& uTrans(i,j)*(tr1(i,j,k,bi,bj)+tr1(i-1,j,k,bi,bj))*0.5 _d 0 |
155 |
ENDDO |
156 |
ENDDO |
157 |
#endif /* INCLUDE_TR1_ADVECTION_CODE */ |
158 |
#ifdef INCLUDE_TR1_DIFFUSION_CODE |
159 |
C o Diffusive component of zonal flux |
160 |
DO j=jMin,jMax |
161 |
DO i=iMin,iMax |
162 |
df(i,j) = -diffKhT*xA(i,j)*_recip_dxC(i,j,bi,bj)* |
163 |
& (tr1(i,j,k,bi,bj)-tr1(i-1,j,k,bi,bj)) |
164 |
& *CosFacU(j,bi,bj) |
165 |
ENDDO |
166 |
ENDDO |
167 |
#ifdef ALLOW_GMREDI |
168 |
IF (useGMRedi) CALL GMREDI_XTRANSPORT( |
169 |
I iMin,iMax,jMin,jMax,bi,bj,K, |
170 |
I xA,tr1, |
171 |
U df, |
172 |
I myThid) |
173 |
#endif |
174 |
C o Add the bi-harmonic contribution |
175 |
IF (diffK4T .NE. 0.) THEN |
176 |
DO j=jMin,jMax |
177 |
DO i=iMin,iMax |
178 |
df(i,j) = df(i,j) + xA(i,j)* |
179 |
& diffK4T*(df4(i,j)-df4(i-1,j))*_recip_dxC(i,j,bi,bj) |
180 |
#ifdef COSINEMETH_III |
181 |
& *sqCosFacU(j,bi,bj) |
182 |
#else |
183 |
& *CosFacU(j,bi,bj) |
184 |
#endif |
185 |
ENDDO |
186 |
ENDDO |
187 |
ENDIF |
188 |
#endif /* INCLUDE_TR1_DIFFUSION_CODE */ |
189 |
C o Net zonal flux |
190 |
DO j=jMin,jMax |
191 |
DO i=iMin,iMax |
192 |
fZon(i,j) = 0. |
193 |
& _ADT( + afFacT*af(i,j) ) |
194 |
& _LPT( + dfFacT*df(i,j) ) |
195 |
ENDDO |
196 |
ENDDO |
197 |
|
198 |
C-- Meridional flux (fMer is at south face of "tr1" cell) |
199 |
#ifdef INCLUDE_TR1_ADVECTION_CODE |
200 |
C o Advective component of meridional flux |
201 |
DO j=jMin,jMax |
202 |
DO i=iMin,iMax |
203 |
af(i,j) = |
204 |
& vTrans(i,j)*(tr1(i,j,k,bi,bj)+tr1(i,j-1,k,bi,bj))*0.5 _d 0 |
205 |
ENDDO |
206 |
ENDDO |
207 |
#endif /* INCLUDE_TR1_ADVECTION_CODE */ |
208 |
#ifdef INCLUDE_TR1_DIFFUSION_CODE |
209 |
C o Diffusive component of meridional flux |
210 |
DO j=jMin,jMax |
211 |
DO i=iMin,iMax |
212 |
df(i,j) = -diffKhT*yA(i,j)*_recip_dyC(i,j,bi,bj)* |
213 |
& (tr1(i,j,k,bi,bj)-tr1(i,j-1,k,bi,bj)) |
214 |
#ifdef ISOTROPIC_COS_SCALING |
215 |
& *CosFacV(j,bi,bj) |
216 |
#endif |
217 |
ENDDO |
218 |
ENDDO |
219 |
#ifdef ALLOW_GMREDI |
220 |
IF (useGMRedi) CALL GMREDI_YTRANSPORT( |
221 |
I iMin,iMax,jMin,jMax,bi,bj,K, |
222 |
I yA,tr1, |
223 |
U df, |
224 |
I myThid) |
225 |
#endif |
226 |
C o Add the bi-harmonic contribution |
227 |
IF (diffK4T .NE. 0.) THEN |
228 |
DO j=jMin,jMax |
229 |
DO i=iMin,iMax |
230 |
df(i,j) = df(i,j) + yA(i,j)* |
231 |
& diffK4T*(df4(i,j)-df4(i,j-1))*_recip_dyC(i,j,bi,bj) |
232 |
#ifdef ISOTROPIC_COS_SCALING |
233 |
#ifdef COSINEMETH_III |
234 |
& *sqCosFacV(j,bi,bj) |
235 |
#else |
236 |
& *CosFacV(j,bi,bj) |
237 |
#endif |
238 |
#endif |
239 |
ENDDO |
240 |
ENDDO |
241 |
ENDIF |
242 |
#endif /* INCLUDE_TR1_DIFFUSION_CODE */ |
243 |
C o Net meridional flux |
244 |
DO j=jMin,jMax |
245 |
DO i=iMin,iMax |
246 |
fMer(i,j) = 0. |
247 |
& _ADT( + afFacT*af(i,j) ) |
248 |
& _LPT( + dfFacT*df(i,j) ) |
249 |
ENDDO |
250 |
ENDDO |
251 |
|
252 |
C-- Vertical flux ( fVerT(,,kUp) is at upper face of "Tracer" cell ) |
253 |
#ifdef INCLUDE_TR1_ADVECTION_CODE |
254 |
C o Advective component of vertical flux : assume W_bottom=0 (mask) |
255 |
C Note: For K=1 then KM1=1 this gives a barZ(T) = T |
256 |
C (this plays the role of the free-surface correction) |
257 |
IF ( rigidLid .AND. TOP_LAYER) THEN |
258 |
DO j=jMin,jMax |
259 |
DO i=iMin,iMax |
260 |
af(i,j) = 0. |
261 |
ENDDO |
262 |
ENDDO |
263 |
ELSEIF ( rigidLid ) THEN |
264 |
DO j=jMin,jMax |
265 |
DO i=iMin,iMax |
266 |
af(i,j) = rTrans(i,j)* |
267 |
& (tr1(i,j,k,bi,bj)+tr1(i,j,kM1,bi,bj))*0.5 _d 0 |
268 |
ENDDO |
269 |
ENDDO |
270 |
ELSE |
271 |
C- include "free-surface correction" : |
272 |
DO j=jMin,jMax |
273 |
DO i=iMin,iMax |
274 |
af(i,j) = rTrans(i,j)*( |
275 |
& maskC(i,j,kM1,bi,bj)* |
276 |
& (tr1(i,j,k,bi,bj)+tr1(i,j,kM1,bi,bj))*0.5 _d 0 |
277 |
& +(maskC(i,j,k,bi,bj)-maskC(i,j,kM1,bi,bj))* |
278 |
& tr1(i,j,k,bi,bj) ) |
279 |
ENDDO |
280 |
ENDDO |
281 |
ENDIF |
282 |
#endif /* INCLUDE_TR1_ADVECTION_CODE */ |
283 |
#ifdef INCLUDE_TR1_DIFFUSION_CODE |
284 |
C o Diffusive component of vertical flux |
285 |
C Note: For K=1 then KM1=1 and this gives a dT/dr = 0 upper |
286 |
C boundary condition. |
287 |
IF (implicitDiffusion) THEN |
288 |
DO j=jMin,jMax |
289 |
DO i=iMin,iMax |
290 |
df(i,j) = 0. |
291 |
ENDDO |
292 |
ENDDO |
293 |
ELSE |
294 |
DO j=jMin,jMax |
295 |
DO i=iMin,iMax |
296 |
df(i,j) = - _rA(i,j,bi,bj)*( |
297 |
& KappaRT(i,j,k)*recip_drC(k) |
298 |
& *(tr1(i,j,kM1,bi,bj)-tr1(i,j,k,bi,bj))*rkFac |
299 |
& ) |
300 |
ENDDO |
301 |
ENDDO |
302 |
ENDIF |
303 |
#endif /* INCLUDE_TR1_DIFFUSION_CODE */ |
304 |
|
305 |
#ifdef ALLOW_GMREDI |
306 |
IF (useGMRedi) CALL GMREDI_RTRANSPORT( |
307 |
I iMin,iMax,jMin,jMax,bi,bj,K, |
308 |
I maskUp,tr1, |
309 |
U df, |
310 |
I myThid) |
311 |
#endif |
312 |
|
313 |
#ifdef ALLOW_KPP |
314 |
C-- Add non local KPP transport term (ghat) to diffusive T flux. |
315 |
IF (useKPP) CALL KPP_TRANSPORT_T( |
316 |
I iMin,iMax,jMin,jMax,bi,bj,k,km1, |
317 |
I KappaRT, |
318 |
U df ) |
319 |
#endif |
320 |
|
321 |
C o Net vertical flux |
322 |
DO j=jMin,jMax |
323 |
DO i=iMin,iMax |
324 |
c fVerT(i,j,kUp) = afFacT*af(i,j) + dfFacT*df(i,j)*maskUp(i,j) |
325 |
fVerT(i,j,kUp) = 0. |
326 |
& _ADT( +afFacT*af(i,j) ) |
327 |
& _LPT( +dfFacT*df(i,j)*maskUp(i,j) ) |
328 |
ENDDO |
329 |
ENDDO |
330 |
|
331 |
C-- Tendency is minus divergence of the fluxes. |
332 |
C Note. Tendency terms will only be correct for range |
333 |
C i=iMin+1:iMax-1, j=jMin+1:jMax-1. Edge points |
334 |
C will contain valid floating point numbers but |
335 |
C they are not algorithmically correct. These points |
336 |
C are not used. |
337 |
DO j=jMin,jMax |
338 |
DO i=iMin,iMax |
339 |
gtr1(i,j,k,bi,bj)= |
340 |
& -_recip_hFacC(i,j,k,bi,bj)*recip_drF(k) |
341 |
& *recip_rA(i,j,bi,bj) |
342 |
& *( |
343 |
& +( fZon(i+1,j)-fZon(i,j) ) |
344 |
& +( fMer(i,j+1)-fMer(i,j) ) |
345 |
& +( fVerT(i,j,kUp)-fVerT(i,j,kDown) )*rkFac |
346 |
& ) |
347 |
ENDDO |
348 |
ENDDO |
349 |
|
350 |
#ifdef INCLUDE_TR1_FORCING_CODE |
351 |
C-- External thermal forcing term(s) |
352 |
CALL EXTERNAL_FORCING_TR1( |
353 |
I iMin,iMax,jMin,jMax,bi,bj,k, |
354 |
I myCurrentTime,myThid) |
355 |
#endif /* INCLUDE_TR1_FORCING_CODE */ |
356 |
|
357 |
RETURN |
358 |
END |