1 |
C $Header: /u/gcmpack/MITgcm/model/src/thermodynamics.F,v 1.160 2016/08/23 12:32:44 mlosch Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "PACKAGES_CONFIG.h" |
5 |
#include "CPP_OPTIONS.h" |
6 |
#ifdef ALLOW_AUTODIFF |
7 |
# include "AUTODIFF_OPTIONS.h" |
8 |
#endif |
9 |
#if (defined ALLOW_PTRACERS) && (!defined ALLOW_LONGSTEP) |
10 |
# define DO_PTRACERS_HERE |
11 |
#endif |
12 |
|
13 |
#ifdef ALLOW_AUTODIFF |
14 |
# ifdef ALLOW_GMREDI |
15 |
# include "GMREDI_OPTIONS.h" |
16 |
# endif |
17 |
# ifdef ALLOW_KPP |
18 |
# include "KPP_OPTIONS.h" |
19 |
# endif |
20 |
#endif /* ALLOW_AUTODIFF */ |
21 |
|
22 |
CBOP |
23 |
C !ROUTINE: THERMODYNAMICS |
24 |
C !INTERFACE: |
25 |
SUBROUTINE THERMODYNAMICS(myTime, myIter, myThid) |
26 |
C !DESCRIPTION: \bv |
27 |
C *==========================================================* |
28 |
C | SUBROUTINE THERMODYNAMICS |
29 |
C | o Controlling routine for the prognostic part of the |
30 |
C | thermo-dynamics. |
31 |
C *=========================================================== |
32 |
C \ev |
33 |
|
34 |
C !USES: |
35 |
IMPLICIT NONE |
36 |
C == Global variables === |
37 |
#include "SIZE.h" |
38 |
#include "EEPARAMS.h" |
39 |
#include "PARAMS.h" |
40 |
#include "RESTART.h" |
41 |
#include "DYNVARS.h" |
42 |
#include "GRID.h" |
43 |
#include "SURFACE.h" |
44 |
#include "FFIELDS.h" |
45 |
#ifdef ALLOW_GENERIC_ADVDIFF |
46 |
# include "GAD.h" |
47 |
#endif |
48 |
#ifdef DO_PTRACERS_HERE |
49 |
# include "PTRACERS_SIZE.h" |
50 |
# include "PTRACERS_PARAMS.h" |
51 |
# include "PTRACERS_FIELDS.h" |
52 |
#endif |
53 |
|
54 |
#ifdef ALLOW_AUTODIFF |
55 |
# include "tamc.h" |
56 |
# include "tamc_keys.h" |
57 |
# include "EOS.h" |
58 |
# ifdef ALLOW_KPP |
59 |
# include "KPP.h" |
60 |
# endif |
61 |
# ifdef ALLOW_GMREDI |
62 |
# include "GMREDI.h" |
63 |
# endif |
64 |
# ifdef ALLOW_EBM |
65 |
# include "EBM.h" |
66 |
# endif |
67 |
# ifdef ALLOW_SALT_PLUME |
68 |
# include "SALT_PLUME.h" |
69 |
# endif |
70 |
#endif /* ALLOW_AUTODIFF */ |
71 |
|
72 |
C !INPUT/OUTPUT PARAMETERS: |
73 |
C == Routine arguments == |
74 |
C myTime :: Current time in simulation |
75 |
C myIter :: Current iteration number in simulation |
76 |
C myThid :: Thread number for this instance of the routine. |
77 |
_RL myTime |
78 |
INTEGER myIter |
79 |
INTEGER myThid |
80 |
|
81 |
#ifdef ALLOW_GENERIC_ADVDIFF |
82 |
# ifdef ALLOW_MONITOR |
83 |
C !FUNCTIONS: |
84 |
LOGICAL DIFFERENT_MULTIPLE |
85 |
EXTERNAL DIFFERENT_MULTIPLE |
86 |
# endif /* ALLOW_MONITOR */ |
87 |
|
88 |
C !LOCAL VARIABLES: |
89 |
C == Local variables |
90 |
C uFld,vFld,wFld :: Local copy of velocity field (3 components) |
91 |
C kappaRk :: Total diffusion in vertical, all levels, 1 tracer |
92 |
C recip_hFacNew :: reciprocal of futur time-step hFacC |
93 |
C bi, bj :: Tile indices |
94 |
C i, j, k :: loop indices |
95 |
_RL uFld (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
96 |
_RL vFld (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
97 |
_RL wFld (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
98 |
_RL kappaRk (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
99 |
_RS recip_hFacNew(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
100 |
INTEGER bi, bj |
101 |
INTEGER i, j, k |
102 |
# ifdef ALLOW_MONITOR |
103 |
LOGICAL monOutputCFL |
104 |
_RL wrTime |
105 |
_RL trAdvCFL(3,nSx,nSy) |
106 |
# endif /* ALLOW_MONITOR */ |
107 |
CEOP |
108 |
|
109 |
#ifdef ALLOW_DEBUG |
110 |
IF (debugMode) CALL DEBUG_ENTER('THERMODYNAMICS',myThid) |
111 |
#endif |
112 |
|
113 |
# ifdef ALLOW_MONITOR |
114 |
monOutputCFL = .FALSE. |
115 |
IF ( monitorSelect.GE.2 ) THEN |
116 |
wrTime = myTime |
117 |
IF ( .NOT.staggerTimeStep ) wrTime = myTime + deltaTClock |
118 |
monOutputCFL = |
119 |
& DIFFERENT_MULTIPLE( monitorFreq, wrTime, deltaTClock ) |
120 |
ENDIF |
121 |
# endif /* ALLOW_MONITOR */ |
122 |
|
123 |
#ifdef ALLOW_AUTODIFF_TAMC |
124 |
C-- dummy statement to end declaration part |
125 |
ikey = 1 |
126 |
itdkey = 1 |
127 |
#endif /* ALLOW_AUTODIFF_TAMC */ |
128 |
|
129 |
#ifdef ALLOW_AUTODIFF_TAMC |
130 |
C-- HPF directive to help TAMC |
131 |
CHPF$ INDEPENDENT |
132 |
#endif /* ALLOW_AUTODIFF_TAMC */ |
133 |
|
134 |
C-- Compute correction at the surface for Lin Free Surf. |
135 |
#ifdef ALLOW_AUTODIFF |
136 |
TsurfCor = 0. _d 0 |
137 |
SsurfCor = 0. _d 0 |
138 |
#endif |
139 |
IF ( linFSConserveTr ) THEN |
140 |
#ifdef ALLOW_AUTODIFF_TAMC |
141 |
CADJ STORE theta,salt,wvel = comlev1, key = ikey_dynamics, byte=isbyte |
142 |
#endif |
143 |
CALL CALC_WSURF_TR( theta, salt, wVel, |
144 |
& myTime, myIter, myThid ) |
145 |
ENDIF |
146 |
#ifdef ALLOW_LAYERS |
147 |
IF ( useLayers ) THEN |
148 |
CALL LAYERS_WSURF_TR( theta, salt, wVel, |
149 |
& myTime, myIter, myThid ) |
150 |
ENDIF |
151 |
#endif /* ALLOW_LAYERS */ |
152 |
|
153 |
#ifdef DO_PTRACERS_HERE |
154 |
#ifdef ALLOW_AUTODIFF |
155 |
DO k=1,PTRACERS_numInUse |
156 |
meanSurfCorPTr(k) = 0.0 _d 0 |
157 |
ENDDO |
158 |
#endif |
159 |
IF ( PTRACERS_calcSurfCor ) THEN |
160 |
#ifdef ALLOW_AUTODIFF_TAMC |
161 |
CADJ STORE ptracer = comlev1, key = ikey_dynamics, byte=isbyte |
162 |
#endif |
163 |
CALL PTRACERS_CALC_WSURF_TR(wVel,myTime,myIter,myThid) |
164 |
ENDIF |
165 |
#endif /* DO_PTRACERS_HERE */ |
166 |
|
167 |
DO bj=myByLo(myThid),myByHi(myThid) |
168 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
169 |
|
170 |
#ifdef ALLOW_AUTODIFF_TAMC |
171 |
act1 = bi - myBxLo(myThid) |
172 |
max1 = myBxHi(myThid) - myBxLo(myThid) + 1 |
173 |
act2 = bj - myByLo(myThid) |
174 |
max2 = myByHi(myThid) - myByLo(myThid) + 1 |
175 |
act3 = myThid - 1 |
176 |
max3 = nTx*nTy |
177 |
act4 = ikey_dynamics - 1 |
178 |
itdkey = (act1 + 1) + act2*max1 |
179 |
& + act3*max1*max2 |
180 |
& + act4*max1*max2*max3 |
181 |
#endif /* ALLOW_AUTODIFF_TAMC */ |
182 |
|
183 |
C-- Set up work arrays with valid (i.e. not NaN) values |
184 |
C These inital values do not alter the numerical results. They |
185 |
C just ensure that all memory references are to valid floating |
186 |
C point numbers. This prevents spurious hardware signals due to |
187 |
C uninitialised but inert locations. |
188 |
|
189 |
DO k=1,Nr |
190 |
DO j=1-OLy,sNy+OLy |
191 |
DO i=1-OLx,sNx+OLx |
192 |
recip_hFacNew(i,j,k) = 0. _d 0 |
193 |
C This is currently also used by IVDC and Diagnostics |
194 |
kappaRk(i,j,k) = 0. _d 0 |
195 |
ENDDO |
196 |
ENDDO |
197 |
ENDDO |
198 |
|
199 |
C-- Compute new reciprocal hFac for implicit calculation |
200 |
#ifdef NONLIN_FRSURF |
201 |
IF ( nonlinFreeSurf.GT.0 ) THEN |
202 |
IF ( select_rStar.GT.0 ) THEN |
203 |
# ifndef DISABLE_RSTAR_CODE |
204 |
DO k=1,Nr |
205 |
DO j=1-OLy,sNy+OLy |
206 |
DO i=1-OLx,sNx+OLx |
207 |
recip_hFacNew(i,j,k) = recip_hFacC(i,j,k,bi,bj) |
208 |
& / rStarExpC(i,j,bi,bj) |
209 |
ENDDO |
210 |
ENDDO |
211 |
ENDDO |
212 |
# endif /* DISABLE_RSTAR_CODE */ |
213 |
ELSEIF ( selectSigmaCoord.NE.0 ) THEN |
214 |
# ifndef DISABLE_SIGMA_CODE |
215 |
DO k=1,Nr |
216 |
DO j=1-OLy,sNy+OLy |
217 |
DO i=1-OLx,sNx+OLx |
218 |
recip_hFacNew(i,j,k) = recip_hFacC(i,j,k,bi,bj) |
219 |
& /( 1. _d 0 + dEtaHdt(i,j,bi,bj)*deltaTFreeSurf |
220 |
& *dBHybSigF(k)*recip_drF(k) |
221 |
& *recip_hFacC(i,j,k,bi,bj) |
222 |
& ) |
223 |
ENDDO |
224 |
ENDDO |
225 |
ENDDO |
226 |
# endif /* DISABLE_RSTAR_CODE */ |
227 |
ELSE |
228 |
DO k=1,Nr |
229 |
DO j=1-OLy,sNy+OLy |
230 |
DO i=1-OLx,sNx+OLx |
231 |
IF ( k.EQ.kSurfC(i,j,bi,bj) ) THEN |
232 |
recip_hFacNew(i,j,k) = 1. _d 0 / hFac_surfC(i,j,bi,bj) |
233 |
ELSE |
234 |
recip_hFacNew(i,j,k) = recip_hFacC(i,j,k,bi,bj) |
235 |
ENDIF |
236 |
ENDDO |
237 |
ENDDO |
238 |
ENDDO |
239 |
ENDIF |
240 |
ELSE |
241 |
#endif /* NONLIN_FRSURF */ |
242 |
DO k=1,Nr |
243 |
DO j=1-OLy,sNy+OLy |
244 |
DO i=1-OLx,sNx+OLx |
245 |
recip_hFacNew(i,j,k) = _recip_hFacC(i,j,k,bi,bj) |
246 |
ENDDO |
247 |
ENDDO |
248 |
ENDDO |
249 |
#ifdef NONLIN_FRSURF |
250 |
ENDIF |
251 |
#endif /* NONLIN_FRSURF */ |
252 |
|
253 |
C-- Set up 3-D velocity field that we use to advect tracers: |
254 |
C- just do a local copy: |
255 |
DO k=1,Nr |
256 |
DO j=1-OLy,sNy+OLy |
257 |
DO i=1-OLx,sNx+OLx |
258 |
uFld(i,j,k) = uVel(i,j,k,bi,bj) |
259 |
vFld(i,j,k) = vVel(i,j,k,bi,bj) |
260 |
wFld(i,j,k) = wVel(i,j,k,bi,bj) |
261 |
ENDDO |
262 |
ENDDO |
263 |
ENDDO |
264 |
#ifdef ALLOW_GMREDI |
265 |
C- add Bolus velocity to Eulerian-mean velocity: |
266 |
IF (useGMRedi) THEN |
267 |
CALL GMREDI_RESIDUAL_FLOW( |
268 |
U uFld, vFld, wFld, |
269 |
I bi, bj, myIter, myThid ) |
270 |
ENDIF |
271 |
#endif /* ALLOW_GMREDI */ |
272 |
#ifdef ALLOW_MONITOR |
273 |
IF ( monOutputCFL ) THEN |
274 |
CALL MON_CALC_ADVCFL_TILE( Nr, bi, bj, |
275 |
I uFld, vFld, wFld, dTtracerLev, |
276 |
O trAdvCFL(1,bi,bj), |
277 |
I myIter, myThid ) |
278 |
c WRITE(standardMessageUnit,'(A,I8,2I3,A,1P3E14.6)') |
279 |
c & ' trAdv_CFL: it,bi,bj=', myIter,bi,bj, |
280 |
c & ' , CFL =', (trAdvCFL(i,bi,bj),i=1,3) |
281 |
ENDIF |
282 |
#endif /* ALLOW_MONITOR */ |
283 |
|
284 |
C- Apply AB on T,S : moved inside TEMP/SALT_INTEGRATE |
285 |
|
286 |
#ifdef ALLOW_AUTODIFF_TAMC |
287 |
CADJ STORE recip_hFacNew(:,:,:) = comlev1_bibj , key=itdkey, byte=isbyte |
288 |
CADJ STORE uFld (:,:,:) = comlev1_bibj, key=itdkey, byte=isbyte |
289 |
CADJ STORE vFld (:,:,:) = comlev1_bibj, key=itdkey, byte=isbyte |
290 |
CADJ STORE wFld (:,:,:) = comlev1_bibj, key=itdkey, byte=isbyte |
291 |
CADJ STORE theta(:,:,:,bi,bj) = comlev1_bibj, key=itdkey, byte=isbyte |
292 |
CADJ STORE salt (:,:,:,bi,bj) = comlev1_bibj, key=itdkey, byte=isbyte |
293 |
# ifdef ALLOW_SALT_PLUME |
294 |
CADJ STORE saltPlumeFlux(:,:,bi,bj) = |
295 |
CADJ & comlev1_bibj, key=itdkey,kind = isbyte |
296 |
CADJ STORE saltPlumeDepth(:,:,bi,bj) = |
297 |
CADJ & comlev1_bibj, key=itdkey,kind = isbyte |
298 |
# endif |
299 |
# if ((defined NONLIN_FRSURF) || (defined ALLOW_DEPTH_CONTROL)) && (defined ALLOW_GMREDI) |
300 |
# ifdef GM_NON_UNITY_DIAGONAL |
301 |
CADJ STORE kux(:,:,:,bi,bj) = comlev1_bibj, key=itdkey, byte=isbyte |
302 |
CADJ STORE kvy(:,:,:,bi,bj) = comlev1_bibj, key=itdkey, byte=isbyte |
303 |
# endif |
304 |
# ifdef GM_EXTRA_DIAGONAL |
305 |
CADJ STORE kuz(:,:,:,bi,bj) = comlev1_bibj, key=itdkey, byte=isbyte |
306 |
CADJ STORE kvz(:,:,:,bi,bj) = comlev1_bibj, key=itdkey, byte=isbyte |
307 |
# endif |
308 |
# endif |
309 |
#endif /* ALLOW_AUTODIFF_TAMC */ |
310 |
|
311 |
C-- Calculate active tracer tendencies and step forward in time. |
312 |
C Active tracer arrays are updated while adjustments (filters, |
313 |
C conv.adjustment) are applied later in TRACERS_CORRECTION_STEP. |
314 |
|
315 |
IF ( tempStepping ) THEN |
316 |
#ifdef ALLOW_DEBUG |
317 |
IF (debugMode) CALL DEBUG_CALL('TEMP_INTEGRATE',myThid) |
318 |
#endif |
319 |
CALL TEMP_INTEGRATE( |
320 |
I bi, bj, recip_hFacNew, |
321 |
I uFld, vFld, wFld, |
322 |
U kappaRk, |
323 |
I myTime, myIter, myThid ) |
324 |
ENDIF |
325 |
|
326 |
IF ( saltStepping ) THEN |
327 |
#ifdef ALLOW_DEBUG |
328 |
IF (debugMode) CALL DEBUG_CALL('SALT_INTEGRATE',myThid) |
329 |
#endif |
330 |
CALL SALT_INTEGRATE( |
331 |
I bi, bj, recip_hFacNew, |
332 |
I uFld, vFld, wFld, |
333 |
U kappaRk, |
334 |
I myTime, myIter, myThid ) |
335 |
ENDIF |
336 |
|
337 |
#ifdef DO_PTRACERS_HERE |
338 |
C-- Calculate passive tracer tendencies and step forward in time. |
339 |
C Passive tracer arrays are updated while adjustments (filters, |
340 |
C conv.adjustment) are applied later in TRACERS_CORRECTION_STEP. |
341 |
C Also apply open boundary conditions for each passive tracer |
342 |
IF ( usePTRACERS ) THEN |
343 |
#ifdef ALLOW_DEBUG |
344 |
IF (debugMode) CALL DEBUG_CALL('PTRACERS_INTEGRATE',myThid) |
345 |
#endif |
346 |
CALL PTRACERS_INTEGRATE( |
347 |
I bi, bj, recip_hFacNew, |
348 |
I uFld, vFld, wFld, |
349 |
U kappaRk, |
350 |
I myTime, myIter, myThid ) |
351 |
ENDIF |
352 |
#endif /* DO_PTRACERS_HERE */ |
353 |
|
354 |
#ifdef ALLOW_OBCS |
355 |
C-- Apply open boundary conditions |
356 |
IF ( useOBCS ) THEN |
357 |
CALL OBCS_APPLY_TS( bi, bj, 0, theta, salt, myThid ) |
358 |
ENDIF |
359 |
#endif /* ALLOW_OBCS */ |
360 |
|
361 |
#ifdef ALLOW_FRICTION_HEATING |
362 |
#ifdef ALLOW_DIAGNOSTICS |
363 |
IF ( addFrictionHeating .AND. useDiagnostics ) THEN |
364 |
CALL DIAGNOSTICS_FILL_RS( frictionHeating, 'HeatDiss', |
365 |
& 0, Nr, 1, bi, bj, myThid ) |
366 |
ENDIF |
367 |
#endif /* ALLOW_DIAGNOSTICS */ |
368 |
C- Reset frictionHeating to zero |
369 |
IF ( addFrictionHeating .AND. .NOT.staggerTimeStep ) THEN |
370 |
DO k=1,Nr |
371 |
DO j=1-OLy,sNy+OLy |
372 |
DO i=1-OLx,sNx+OLx |
373 |
frictionHeating(i,j,k,bi,bj) = 0. _d 0 |
374 |
ENDDO |
375 |
ENDDO |
376 |
ENDDO |
377 |
ENDIF |
378 |
#endif /* ALLOW_FRICTION_HEATING */ |
379 |
|
380 |
C-- end bi,bj loops. |
381 |
ENDDO |
382 |
ENDDO |
383 |
|
384 |
#ifdef ALLOW_MONITOR |
385 |
IF ( monOutputCFL ) THEN |
386 |
CALL MON_CALC_ADVCFL_GLOB( |
387 |
I trAdvCFL, myIter, myThid ) |
388 |
ENDIF |
389 |
#endif /* ALLOW_MONITOR */ |
390 |
|
391 |
#ifdef ALLOW_DEBUG |
392 |
IF ( debugLevel.GE.debLevD ) THEN |
393 |
CALL DEBUG_STATS_RL(Nr,uVel,'Uvel (THERMODYNAMICS)',myThid) |
394 |
CALL DEBUG_STATS_RL(Nr,vVel,'Vvel (THERMODYNAMICS)',myThid) |
395 |
CALL DEBUG_STATS_RL(Nr,wVel,'Wvel (THERMODYNAMICS)',myThid) |
396 |
CALL DEBUG_STATS_RL(Nr,theta,'Theta (THERMODYNAMICS)',myThid) |
397 |
CALL DEBUG_STATS_RL(Nr,salt,'Salt (THERMODYNAMICS)',myThid) |
398 |
#ifndef ALLOW_ADAMSBASHFORTH_3 |
399 |
CALL DEBUG_STATS_RL(Nr,gtNm1,'GtNm1 (THERMODYNAMICS)',myThid) |
400 |
CALL DEBUG_STATS_RL(Nr,gsNm1,'GsNm1 (THERMODYNAMICS)',myThid) |
401 |
#endif |
402 |
#ifdef DO_PTRACERS_HERE |
403 |
IF ( usePTRACERS ) THEN |
404 |
CALL PTRACERS_DEBUG(myThid) |
405 |
ENDIF |
406 |
#endif /* DO_PTRACERS_HERE */ |
407 |
ENDIF |
408 |
#endif /* ALLOW_DEBUG */ |
409 |
|
410 |
#ifdef ALLOW_DEBUG |
411 |
IF (debugMode) CALL DEBUG_LEAVE('THERMODYNAMICS',myThid) |
412 |
#endif |
413 |
|
414 |
#endif /* ALLOW_GENERIC_ADVDIFF */ |
415 |
|
416 |
RETURN |
417 |
END |