/[MITgcm]/MITgcm/pkg/kpp/kpp_routines.F
ViewVC logotype

Annotation of /MITgcm/pkg/kpp/kpp_routines.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.42 - (hide annotations) (download)
Fri Feb 13 21:58:36 2009 UTC (15 years, 4 months ago) by heimbach
Branch: MAIN
CVS Tags: checkpoint61n, checkpoint61o, checkpoint61l, checkpoint61m, checkpoint61j, checkpoint61k
Changes since 1.41: +103 -59 lines
Update tamc.h for single-prec comlev option

1 heimbach 1.42 C $Header: /u/gcmpack/MITgcm/pkg/kpp/kpp_routines.F,v 1.41 2008/10/30 18:51:36 dfer Exp $
2 heimbach 1.10 C $Name: $
3 adcroft 1.1
4 heimbach 1.42 #include "PACKAGES_CONFIG.h"
5 adcroft 1.1 #include "KPP_OPTIONS.h"
6    
7     C-- File kpp_routines.F: subroutines needed to implement
8     C-- KPP vertical mixing scheme
9     C-- Contents
10     C-- o KPPMIX - Main driver and interface routine.
11     C-- o BLDEPTH - Determine oceanic planetary boundary layer depth.
12     C-- o WSCALE - Compute turbulent velocity scales.
13     C-- o RI_IWMIX - Compute interior viscosity diffusivity coefficients.
14     C-- o Z121 - Apply 121 vertical smoothing.
15 dimitri 1.27 C-- o SMOOTH_HORIZ- Apply horizontal smoothing to global array.
16 adcroft 1.1 C-- o BLMIX - Boundary layer mixing coefficients.
17     C-- o ENHANCE - Enhance diffusivity at boundary layer interface.
18     C-- o STATEKPP - Compute buoyancy-related input arrays.
19    
20 heimbach 1.4 c***********************************************************************
21 adcroft 1.1
22     SUBROUTINE KPPMIX (
23 mlosch 1.30 I kmtj, shsq, dvsq, ustar, msk
24 dimitri 1.33 I , bo, bosol
25     #ifdef ALLOW_SALT_PLUME
26     I , boplume,SPDepth
27     #endif /* ALLOW_SALT_PLUME */
28     I , dbloc, Ritop, coriol
29 dimitri 1.26 I , diffusKzS, diffusKzT
30 heimbach 1.16 I , ikppkey
31 adcroft 1.1 O , diffus
32     U , ghat
33 mlosch 1.30 O , hbl
34 jmc 1.31 I , myTime, myIter, myThid )
35 adcroft 1.1
36 heimbach 1.4 c-----------------------------------------------------------------------
37 adcroft 1.1 c
38     c Main driver subroutine for kpp vertical mixing scheme and
39     c interface to greater ocean model
40     c
41     c written by: bill large, june 6, 1994
42     c modified by: jan morzel, june 30, 1994
43     c bill large, august 11, 1994
44     c bill large, january 25, 1995 : "dVsq" and 1d code
45     c detlef stammer, august 1997 : for use with MIT GCM Classic
46     c d. menemenlis, june 1998 : for use with MIT GCM UV
47     c
48     c-----------------------------------------------------------------------
49    
50     IMPLICIT NONE
51    
52 jmc 1.29 #include "SIZE.h"
53     #include "EEPARAMS.h"
54     #include "PARAMS.h"
55     #include "KPP_PARAMS.h"
56 heimbach 1.42 #ifdef ALLOW_AUTODIFF
57     # include "tamc.h"
58     #endif
59 jmc 1.29
60 adcroft 1.1 c input
61 jmc 1.31 c myTime :: Current time in simulation
62     c myIter :: Current iteration number in simulation
63     c myThid :: My Thread Id. number
64 dimitri 1.26 c kmtj (imt) - number of vertical layers on this row
65 mlosch 1.30 c msk (imt) - surface mask (=1 if water, =0 otherwise)
66 dimitri 1.26 c shsq (imt,Nr) - (local velocity shear)^2 ((m/s)^2)
67     c dvsq (imt,Nr) - (velocity shear re sfc)^2 ((m/s)^2)
68     c ustar (imt) - surface friction velocity (m/s)
69     c bo (imt) - surface turbulent buoy. forcing (m^2/s^3)
70     c bosol (imt) - radiative buoyancy forcing (m^2/s^3)
71 dimitri 1.33 c boplume(imt) - haline buoyancy forcing (m^2/s^3)
72 dimitri 1.26 c dbloc (imt,Nr) - local delta buoyancy across interfaces (m/s^2)
73     c dblocSm(imt,Nr) - horizontally smoothed dbloc (m/s^2)
74     c stored in ghat to save space
75     c Ritop (imt,Nr) - numerator of bulk Richardson Number
76     c (zref-z) * delta buoyancy w.r.t. surface ((m/s)^2)
77     c coriol (imt) - Coriolis parameter (1/s)
78     c diffusKzS(imt,Nr)- background vertical diffusivity for scalars (m^2/s)
79     c diffusKzT(imt,Nr)- background vertical diffusivity for theta (m^2/s)
80 adcroft 1.1 c note: there is a conversion from 2-D to 1-D for input output variables,
81     c e.g., hbl(sNx,sNy) -> hbl(imt),
82     c where hbl(i,j) -> hbl((j-1)*sNx+i)
83    
84 jmc 1.31 _RL myTime
85     integer myIter
86     integer myThid
87 dimitri 1.27 integer kmtj (imt )
88     _RL shsq (imt,Nr)
89     _RL dvsq (imt,Nr)
90     _RL ustar (imt )
91     _RL bo (imt )
92     _RL bosol (imt )
93 dimitri 1.33 #ifdef ALLOW_SALT_PLUME
94     _RL boplume (imt )
95     _RL SPDepth (imt )
96     #endif /* ALLOW_SALT_PLUME */
97 dimitri 1.27 _RL dbloc (imt,Nr)
98     _RL Ritop (imt,Nr)
99     _RL coriol (imt )
100 mlosch 1.30 _RS msk (imt )
101 dimitri 1.27 _RL diffusKzS(imt,Nr)
102     _RL diffusKzT(imt,Nr)
103 adcroft 1.1
104 heimbach 1.16 integer ikppkey
105 adcroft 1.1
106     c output
107     c diffus (imt,1) - vertical viscosity coefficient (m^2/s)
108     c diffus (imt,2) - vertical scalar diffusivity (m^2/s)
109     c diffus (imt,3) - vertical temperature diffusivity (m^2/s)
110     c ghat (imt) - nonlocal transport coefficient (s/m^2)
111     c hbl (imt) - mixing layer depth (m)
112    
113 dimitri 1.27 _RL diffus(imt,0:Nrp1,mdiff)
114     _RL ghat (imt,Nr)
115     _RL hbl (imt)
116 adcroft 1.1
117     #ifdef ALLOW_KPP
118    
119     c local
120     c kbl (imt ) - index of first grid level below hbl
121     c bfsfc (imt ) - surface buoyancy forcing (m^2/s^3)
122     c casea (imt ) - 1 in case A; 0 in case B
123     c stable (imt ) - 1 in stable forcing; 0 if unstable
124     c dkm1 (imt, mdiff) - boundary layer diffusivity at kbl-1 level
125     c blmc (imt,Nr,mdiff) - boundary layer mixing coefficients
126     c sigma (imt ) - normalized depth (d / hbl)
127     c Rib (imt,Nr ) - bulk Richardson number
128    
129 dimitri 1.27 integer kbl(imt )
130     _RL bfsfc (imt )
131     _RL casea (imt )
132     _RL stable (imt )
133     _RL dkm1 (imt, mdiff)
134     _RL blmc (imt,Nr,mdiff)
135     _RL sigma (imt )
136     _RL Rib (imt,Nr )
137 adcroft 1.1
138     integer i, k, md
139    
140     c-----------------------------------------------------------------------
141     c compute interior mixing coefficients everywhere, due to constant
142     c internal wave activity, static instability, and local shear
143     c instability.
144     c (ghat is temporary storage for horizontally smoothed dbloc)
145     c-----------------------------------------------------------------------
146    
147 heimbach 1.15 cph(
148     cph these storings avoid recomp. of Ri_iwmix
149 heimbach 1.42 CADJ STORE ghat = comlev1_kpp, key=ikppkey, kind=isbyte
150     CADJ STORE dbloc = comlev1_kpp, key=ikppkey, kind=isbyte
151 heimbach 1.15 cph)
152 adcroft 1.1 call Ri_iwmix (
153     I kmtj, shsq, dbloc, ghat
154 dimitri 1.26 I , diffusKzS, diffusKzT
155 heimbach 1.16 I , ikppkey
156 heimbach 1.32 O , diffus, myThid )
157 adcroft 1.1
158 heimbach 1.15 cph(
159     cph these storings avoid recomp. of Ri_iwmix
160     cph DESPITE TAFs 'not necessary' warning!
161 heimbach 1.42 CADJ STORE dbloc = comlev1_kpp, key=ikppkey, kind=isbyte
162     CADJ STORE shsq = comlev1_kpp, key=ikppkey, kind=isbyte
163     CADJ STORE ghat = comlev1_kpp, key=ikppkey, kind=isbyte
164     CADJ STORE diffus = comlev1_kpp, key=ikppkey, kind=isbyte
165 heimbach 1.15 cph)
166    
167 adcroft 1.1 c-----------------------------------------------------------------------
168     c set seafloor values to zero and fill extra "Nrp1" coefficients
169     c for blmix
170     c-----------------------------------------------------------------------
171    
172     do md = 1, mdiff
173 mlosch 1.34 do k=1,Nrp1
174 adcroft 1.1 do i = 1,imt
175 mlosch 1.34 if(k.ge.kmtj(i)) diffus(i,k,md) = 0.0
176 adcroft 1.1 end do
177     end do
178     end do
179    
180     c-----------------------------------------------------------------------
181     c compute boundary layer mixing coefficients:
182     c
183     c diagnose the new boundary layer depth
184     c-----------------------------------------------------------------------
185    
186     call bldepth (
187 mlosch 1.30 I kmtj
188 dimitri 1.33 I , dvsq, dbloc, Ritop, ustar, bo, bosol
189     #ifdef ALLOW_SALT_PLUME
190     I , boplume,SPDepth
191     #endif /* ALLOW_SALT_PLUME */
192     I , coriol
193 heimbach 1.16 I , ikppkey
194 adcroft 1.1 O , hbl, bfsfc, stable, casea, kbl, Rib, sigma
195 jmc 1.31 I , myTime, myIter, myThid )
196 adcroft 1.1
197 heimbach 1.42 CADJ STORE hbl,bfsfc,stable,casea,kbl = comlev1_kpp,
198     CADJ & key=ikppkey, kind=isbyte
199 adcroft 1.1
200     c-----------------------------------------------------------------------
201     c compute boundary layer diffusivities
202     c-----------------------------------------------------------------------
203    
204     call blmix (
205     I ustar, bfsfc, hbl, stable, casea, diffus, kbl
206 heimbach 1.16 O , dkm1, blmc, ghat, sigma, ikppkey
207 jmc 1.31 I , myThid )
208 heimbach 1.15 cph(
209 heimbach 1.42 CADJ STORE dkm1,blmc,ghat = comlev1_kpp,
210     CADJ & key=ikppkey, kind=isbyte
211     CADJ STORE hbl, kbl, diffus, casea = comlev1_kpp,
212     CADJ & key=ikppkey, kind=isbyte
213 heimbach 1.15 cph)
214 adcroft 1.1
215     c-----------------------------------------------------------------------
216     c enhance diffusivity at interface kbl - 1
217     c-----------------------------------------------------------------------
218    
219     call enhance (
220     I dkm1, hbl, kbl, diffus, casea
221     U , ghat
222 mlosch 1.30 O , blmc
223 jmc 1.31 I , myThid )
224 heimbach 1.15
225     cph(
226     cph avoids recomp. of enhance
227 heimbach 1.42 CADJ STORE blmc = comlev1_kpp, key=ikppkey, kind=isbyte
228 heimbach 1.15 cph)
229 adcroft 1.1
230     c-----------------------------------------------------------------------
231     c combine interior and boundary layer coefficients and nonlocal term
232 dimitri 1.14 c !!!NOTE!!! In shallow (2-level) regions and for shallow mixed layers
233 edhill 1.17 c (< 1 level), diffusivity blmc can become negative. The max-s below
234 dimitri 1.14 c are a hack until this problem is properly diagnosed and fixed.
235 adcroft 1.1 c-----------------------------------------------------------------------
236     do k = 1, Nr
237     do i = 1, imt
238     if (k .lt. kbl(i)) then
239 mlosch 1.30 #ifdef ALLOW_SHELFICE
240     C when there is shelfice on top (msk(i)=0), reset the boundary layer
241     C mixing coefficients blmc to pure Ri-number based mixing
242     blmc(i,k,1) = max ( blmc(i,k,1)*msk(i),
243     & diffus(i,k,1) )
244     blmc(i,k,2) = max ( blmc(i,k,2)*msk(i),
245     & diffus(i,k,2) )
246     blmc(i,k,3) = max ( blmc(i,k,3)*msk(i),
247     & diffus(i,k,3) )
248     #endif /* not ALLOW_SHELFICE */
249 dimitri 1.14 diffus(i,k,1) = max ( blmc(i,k,1), viscAr )
250 dimitri 1.26 diffus(i,k,2) = max ( blmc(i,k,2), diffusKzS(i,Nr) )
251     diffus(i,k,3) = max ( blmc(i,k,3), diffusKzT(i,Nr) )
252 adcroft 1.1 else
253 dfer 1.40 ghat(i,k) = 0. _d 0
254 adcroft 1.1 endif
255     end do
256     end do
257    
258     #endif /* ALLOW_KPP */
259    
260     return
261     end
262    
263     c*************************************************************************
264    
265     subroutine bldepth (
266 mlosch 1.30 I kmtj
267 dimitri 1.33 I , dvsq, dbloc, Ritop, ustar, bo, bosol
268     #ifdef ALLOW_SALT_PLUME
269     I , boplume,SPDepth
270     #endif /* ALLOW_SALT_PLUME */
271     I , coriol
272 heimbach 1.16 I , ikppkey
273 adcroft 1.1 O , hbl, bfsfc, stable, casea, kbl, Rib, sigma
274 jmc 1.31 I , myTime, myIter, myThid )
275 adcroft 1.1
276     c the oceanic planetary boundary layer depth, hbl, is determined as
277     c the shallowest depth where the bulk Richardson number is
278     c equal to the critical value, Ricr.
279     c
280     c bulk Richardson numbers are evaluated by computing velocity and
281     c buoyancy differences between values at zgrid(kl) < 0 and surface
282     c reference values.
283     c in this configuration, the reference values are equal to the
284     c values in the surface layer.
285     c when using a very fine vertical grid, these values should be
286     c computed as the vertical average of velocity and buoyancy from
287     c the surface down to epsilon*zgrid(kl).
288     c
289     c when the bulk Richardson number at k exceeds Ricr, hbl is
290     c linearly interpolated between grid levels zgrid(k) and zgrid(k-1).
291     c
292     c The water column and the surface forcing are diagnosed for
293     c stable/ustable forcing conditions, and where hbl is relative
294     c to grid points (caseA), so that conditional branches can be
295     c avoided in later subroutines.
296     c
297     IMPLICIT NONE
298    
299     #include "SIZE.h"
300 atn 1.37 #include "EEPARAMS.h"
301     #include "PARAMS.h"
302 adcroft 1.1 #include "KPP_PARAMS.h"
303 heimbach 1.42 #ifdef ALLOW_AUTODIFF
304     # include "tamc.h"
305     #endif
306 adcroft 1.1
307     c input
308     c------
309 jmc 1.31 c myTime :: Current time in simulation
310     c myIter :: Current iteration number in simulation
311     c myThid :: My Thread Id. number
312 adcroft 1.1 c kmtj : number of vertical layers
313     c dvsq : (velocity shear re sfc)^2 ((m/s)^2)
314     c dbloc : local delta buoyancy across interfaces (m/s^2)
315     c Ritop : numerator of bulk Richardson Number
316     c =(z-zref)*dbsfc, where dbsfc=delta
317     c buoyancy with respect to surface ((m/s)^2)
318     c ustar : surface friction velocity (m/s)
319     c bo : surface turbulent buoyancy forcing (m^2/s^3)
320     c bosol : radiative buoyancy forcing (m^2/s^3)
321 dimitri 1.33 c boplume : haline buoyancy forcing (m^2/s^3)
322 adcroft 1.1 c coriol : Coriolis parameter (1/s)
323 jmc 1.31 _RL myTime
324     integer myIter
325     integer myThid
326 adcroft 1.1 integer kmtj(imt)
327 dimitri 1.27 _RL dvsq (imt,Nr)
328     _RL dbloc (imt,Nr)
329     _RL Ritop (imt,Nr)
330     _RL ustar (imt)
331     _RL bo (imt)
332     _RL bosol (imt)
333     _RL coriol (imt)
334 heimbach 1.19 integer ikppkey, kkppkey
335 dimitri 1.33 #ifdef ALLOW_SALT_PLUME
336     _RL boplume (imt)
337     _RL SPDepth (imt)
338     #endif /* ALLOW_SALT_PLUME */
339 adcroft 1.1
340     c output
341     c--------
342     c hbl : boundary layer depth (m)
343     c bfsfc : Bo+radiation absorbed to d=hbf*hbl (m^2/s^3)
344     c stable : =1 in stable forcing; =0 unstable
345     c casea : =1 in case A, =0 in case B
346     c kbl : -1 of first grid level below hbl
347     c Rib : Bulk Richardson number
348     c sigma : normalized depth (d/hbl)
349 dimitri 1.27 _RL hbl (imt)
350     _RL bfsfc (imt)
351     _RL stable (imt)
352     _RL casea (imt)
353     integer kbl(imt)
354     _RL Rib (imt,Nr)
355     _RL sigma (imt)
356 adcroft 1.1
357     #ifdef ALLOW_KPP
358    
359     c local
360     c-------
361     c wm, ws : turbulent velocity scales (m/s)
362 dimitri 1.27 _RL wm(imt), ws(imt)
363     _RL worka(imt)
364     _RL bvsq, vtsq, hekman, hmonob, hlimit, tempVar1, tempVar2
365 adcroft 1.1 integer i, kl
366    
367 dimitri 1.27 _RL p5 , eins
368 heimbach 1.4 parameter ( p5=0.5, eins=1.0 )
369     _RL minusone
370     parameter ( minusone=-1.0 )
371 adcroft 1.1
372 atn 1.37 #ifdef ALLOW_DIAGNOSTICS
373     c KPPBFSFC - Bo+radiation absorbed to d=hbf*hbl + plume (m^2/s^3)
374     _RL KPPBFSFC(imt,Nr)
375 dfer 1.40 _RL KPPRi(imt,Nr)
376 atn 1.37 #endif /* ALLOW_DIAGNOSTICS */
377    
378 adcroft 1.1 c find bulk Richardson number at every grid level until > Ricr
379     c
380     c note: the reference depth is -epsilon/2.*zgrid(k), but the reference
381     c u,v,t,s values are simply the surface layer values,
382     c and not the averaged values from 0 to 2*ref.depth,
383     c which is necessary for very fine grids(top layer < 2m thickness)
384     c note: max values when Ricr never satisfied are
385     c kbl(i)=kmtj(i) and hbl(i)=-zgrid(kmtj(i))
386    
387     c initialize hbl and kbl to bottomed out values
388    
389     do i = 1, imt
390 dfer 1.40 Rib(i,1) = 0. _d 0
391 adcroft 1.1 kbl(i) = max(kmtj(i),1)
392     hbl(i) = -zgrid(kbl(i))
393     end do
394    
395 atn 1.37 #ifdef ALLOW_DIAGNOSTICS
396     do kl = 1, Nr
397     do i = 1, imt
398 dfer 1.40 KPPBFSFC(i,kl) = 0. _d 0
399     KPPRi(i,kl) = 0. _d 0
400 atn 1.37 enddo
401     enddo
402     #endif /* ALLOW_DIAGNOSTICS */
403    
404 adcroft 1.1 do kl = 2, Nr
405    
406 heimbach 1.19 #ifdef ALLOW_AUTODIFF_TAMC
407     kkppkey = (ikppkey-1)*Nr + kl
408     #endif
409    
410 adcroft 1.1 c compute bfsfc = sw fraction at hbf * zgrid
411    
412     do i = 1, imt
413 heimbach 1.4 worka(i) = zgrid(kl)
414 adcroft 1.1 end do
415 heimbach 1.42 CADJ store worka = comlev1_kpp_k, key = kkppkey, kind=isbyte
416 adcroft 1.1 call SWFRAC(
417 jmc 1.31 I imt, hbf,
418     U worka,
419     I myTime, myIter, myThid )
420 heimbach 1.42 CADJ store worka = comlev1_kpp_k, key = kkppkey, kind=isbyte
421 heimbach 1.19
422 adcroft 1.1 do i = 1, imt
423    
424     c use caseA as temporary array
425    
426     casea(i) = -zgrid(kl)
427    
428     c compute bfsfc= Bo + radiative contribution down to hbf * hbl
429    
430 heimbach 1.4 bfsfc(i) = bo(i) + bosol(i)*(1. - worka(i))
431 dimitri 1.33
432     end do
433     #ifdef ALLOW_SALT_PLUME
434     c compute bfsfc = plume fraction at hbf * zgrid
435 atn 1.37 IF ( useSALT_PLUME ) THEN
436     do i = 1, imt
437     worka(i) = zgrid(kl)
438     enddo
439     call SALT_PLUME_FRAC(
440     I imt, hbf,SPDepth,
441     U worka,
442     I myTime, myIter, myThid)
443     do i = 1, imt
444     bfsfc(i) = bfsfc(i) + boplume(i)*(1. - worka(i))
445     enddo
446     ENDIF
447     #endif /* ALLOW_SALT_PLUME */
448    
449     #ifdef ALLOW_DIAGNOSTICS
450 dimitri 1.33 do i = 1, imt
451 atn 1.37 KPPBFSFC(i,kl) = bfsfc(i)
452 dimitri 1.33 enddo
453 atn 1.37 #endif /* ALLOW_DIAGNOSTICS */
454 dimitri 1.33
455     do i = 1, imt
456 adcroft 1.1 stable(i) = p5 + sign(p5,bfsfc(i))
457     sigma(i) = stable(i) + (1. - stable(i)) * epsilon
458 dimitri 1.33 enddo
459 adcroft 1.1
460     c-----------------------------------------------------------------------
461     c compute velocity scales at sigma, for hbl= caseA = -zgrid(kl)
462     c-----------------------------------------------------------------------
463    
464     call wscale (
465     I sigma, casea, ustar, bfsfc,
466 mlosch 1.30 O wm, ws, myThid )
467 heimbach 1.42 CADJ store ws = comlev1_kpp_k, key = kkppkey, kind=isbyte
468 adcroft 1.1
469     do i = 1, imt
470    
471     c-----------------------------------------------------------------------
472     c compute the turbulent shear contribution to Rib
473     c-----------------------------------------------------------------------
474    
475     bvsq = p5 *
476     1 ( dbloc(i,kl-1) / (zgrid(kl-1)-zgrid(kl ))+
477     2 dbloc(i,kl ) / (zgrid(kl )-zgrid(kl+1)))
478    
479 dfer 1.40 if (bvsq .eq. 0. _d 0) then
480     vtsq = 0. _d 0
481 adcroft 1.1 else
482     vtsq = -zgrid(kl) * ws(i) * sqrt(abs(bvsq)) * Vtc
483     endif
484    
485     c compute bulk Richardson number at new level
486     c note: Ritop needs to be zero on land and ocean bottom
487     c points so that the following if statement gets triggered
488     c correctly; otherwise, hbl might get set to (big) negative
489     c values, that might exceed the limit for the "exp" function
490     c in "SWFRAC"
491    
492     c
493     c rg: assignment to double precision variable to avoid overflow
494     c ph: test for zero nominator
495     c
496 heimbach 1.4
497     tempVar1 = dvsq(i,kl) + vtsq
498     tempVar2 = max(tempVar1, phepsi)
499     Rib(i,kl) = Ritop(i,kl) / tempVar2
500 dfer 1.40 #ifdef ALLOW_DIAGNOSTICS
501     KPPRi(i,kl) = Rib(i,kl)
502     #endif
503 heimbach 1.4
504 adcroft 1.1 end do
505     end do
506 heimbach 1.10
507 atn 1.37 #ifdef ALLOW_DIAGNOSTICS
508     CALL DIAGNOSTICS_FILL(KPPBFSFC,'KPPbfsfc',0,Nr,0,1,1,myThid)
509 dfer 1.40 CALL DIAGNOSTICS_FILL(KPPRi ,'KPPRi ',0,Nr,0,1,1,myThid)
510 atn 1.37 #endif /* ALLOW_DIAGNOSTICS */
511    
512 heimbach 1.10 cph(
513 edhill 1.17 cph without this store, there is a recomputation error for
514 heimbach 1.10 cph rib in adbldepth (probably partial recomputation problem)
515     CADJ store Rib = comlev1_kpp
516 heimbach 1.42 CADJ & , key=ikppkey, kind=isbyte,
517     CADJ & shape = (/ (sNx+2*OLx)*(sNy+2*OLy),Nr /)
518 heimbach 1.10 cph)
519    
520 adcroft 1.1 do kl = 2, Nr
521     do i = 1, imt
522     if (kbl(i).eq.kmtj(i) .and. Rib(i,kl).gt.Ricr) kbl(i) = kl
523     end do
524     end do
525    
526 heimbach 1.2 CADJ store kbl = comlev1_kpp
527 heimbach 1.42 CADJ & , key=ikppkey, kind=isbyte,
528     CADJ & shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
529 adcroft 1.1
530     do i = 1, imt
531     kl = kbl(i)
532     c linearly interpolate to find hbl where Rib = Ricr
533     if (kl.gt.1 .and. kl.lt.kmtj(i)) then
534 heimbach 1.4 tempVar1 = (Rib(i,kl)-Rib(i,kl-1))
535 adcroft 1.1 hbl(i) = -zgrid(kl-1) + (zgrid(kl-1)-zgrid(kl)) *
536 heimbach 1.4 1 (Ricr - Rib(i,kl-1)) / tempVar1
537 adcroft 1.1 endif
538     end do
539    
540 heimbach 1.2 CADJ store hbl = comlev1_kpp
541 heimbach 1.42 CADJ & , key=ikppkey, kind=isbyte,
542     CADJ & shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
543 adcroft 1.1
544     c-----------------------------------------------------------------------
545     c find stability and buoyancy forcing for boundary layer
546     c-----------------------------------------------------------------------
547    
548 heimbach 1.4 do i = 1, imt
549     worka(i) = hbl(i)
550     end do
551 heimbach 1.19 CADJ store worka = comlev1_kpp
552 heimbach 1.42 CADJ & , key=ikppkey, kind=isbyte,
553     CADJ & shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
554 adcroft 1.1 call SWFRAC(
555 jmc 1.31 I imt, minusone,
556     U worka,
557     I myTime, myIter, myThid )
558 heimbach 1.19 CADJ store worka = comlev1_kpp
559 heimbach 1.42 CADJ & , key=ikppkey, kind=isbyte,
560     CADJ & shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
561 adcroft 1.1
562 heimbach 1.4 do i = 1, imt
563     bfsfc(i) = bo(i) + bosol(i) * (1. - worka(i))
564     end do
565 dimitri 1.33
566     #ifdef ALLOW_SALT_PLUME
567 atn 1.37 IF ( useSALT_PLUME ) THEN
568     do i = 1, imt
569     worka(i) = hbl(i)
570     enddo
571     call SALT_PLUME_FRAC(
572     I imt,minusone,SPDepth,
573     U worka,
574     I myTime, myIter, myThid )
575     do i = 1, imt
576     bfsfc(i) = bfsfc(i) + boplume(i) * (1. - worka(i))
577     enddo
578     ENDIF
579 dimitri 1.33 #endif /* ALLOW_SALT_PLUME */
580 heimbach 1.2 CADJ store bfsfc = comlev1_kpp
581 heimbach 1.42 CADJ & , key=ikppkey, kind=isbyte,
582     CADJ & shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
583 heimbach 1.2
584 heimbach 1.4 c-- ensure bfsfc is never 0
585 adcroft 1.1 do i = 1, imt
586     stable(i) = p5 + sign( p5, bfsfc(i) )
587 heimbach 1.4 bfsfc(i) = sign(eins,bfsfc(i))*max(phepsi,abs(bfsfc(i)))
588     end do
589 adcroft 1.1
590 heimbach 1.10 cph(
591     cph added stable to store list to avoid extensive recomp.
592     CADJ store bfsfc, stable = comlev1_kpp
593 heimbach 1.42 CADJ & , key=ikppkey, kind=isbyte,
594     CADJ & shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
595 heimbach 1.10 cph)
596 adcroft 1.1
597     c-----------------------------------------------------------------------
598     c check hbl limits for hekman or hmonob
599     c ph: test for zero nominator
600     c-----------------------------------------------------------------------
601    
602     do i = 1, imt
603     if (bfsfc(i) .gt. 0.0) then
604     hekman = cekman * ustar(i) / max(abs(Coriol(i)),phepsi)
605     hmonob = cmonob * ustar(i)*ustar(i)*ustar(i)
606     & / vonk / bfsfc(i)
607     hlimit = stable(i) * min(hekman,hmonob)
608     & + (stable(i)-1.) * zgrid(Nr)
609     hbl(i) = min(hbl(i),hlimit)
610 heimbach 1.4 end if
611     end do
612     CADJ store hbl = comlev1_kpp
613 heimbach 1.42 CADJ & , key=ikppkey, kind=isbyte,
614     CADJ & shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
615 heimbach 1.4
616     do i = 1, imt
617     hbl(i) = max(hbl(i),minKPPhbl)
618 adcroft 1.1 kbl(i) = kmtj(i)
619     end do
620    
621 heimbach 1.2 CADJ store hbl = comlev1_kpp
622 heimbach 1.42 CADJ & , key=ikppkey, kind=isbyte,
623     CADJ & shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
624 adcroft 1.1
625     c-----------------------------------------------------------------------
626     c find new kbl
627     c-----------------------------------------------------------------------
628    
629     do kl = 2, Nr
630     do i = 1, imt
631     if ( kbl(i).eq.kmtj(i) .and. (-zgrid(kl)).gt.hbl(i) ) then
632     kbl(i) = kl
633     endif
634     end do
635     end do
636    
637     c-----------------------------------------------------------------------
638     c find stability and buoyancy forcing for final hbl values
639     c-----------------------------------------------------------------------
640    
641 heimbach 1.4 do i = 1, imt
642     worka(i) = hbl(i)
643     end do
644 heimbach 1.19 CADJ store worka = comlev1_kpp
645 heimbach 1.42 CADJ & , key=ikppkey, kind=isbyte,
646     CADJ & shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
647 adcroft 1.1 call SWFRAC(
648 heimbach 1.4 I imt, minusone,
649 jmc 1.31 U worka,
650     I myTime, myIter, myThid )
651 heimbach 1.19 CADJ store worka = comlev1_kpp
652 heimbach 1.42 CADJ & , key=ikppkey, kind=isbyte,
653     CADJ & shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
654 adcroft 1.1
655 heimbach 1.4 do i = 1, imt
656     bfsfc(i) = bo(i) + bosol(i) * (1. - worka(i))
657     end do
658 dimitri 1.33
659     #ifdef ALLOW_SALT_PLUME
660 atn 1.37 IF ( useSALT_PLUME ) THEN
661     do i = 1, imt
662     worka(i) = hbl(i)
663     enddo
664     call SALT_PLUME_FRAC(
665     I imt,minusone,SPDepth,
666     U worka,
667     I myTime, myIter, myThid )
668     do i = 1, imt
669     bfsfc(i) = bfsfc(i) + boplume(i) * (1. - worka(i))
670     enddo
671     ENDIF
672 dimitri 1.33 #endif /* ALLOW_SALT_PLUME */
673 heimbach 1.2 CADJ store bfsfc = comlev1_kpp
674 heimbach 1.42 CADJ & , key=ikppkey, kind=isbyte,
675     CADJ & shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
676 heimbach 1.2
677 heimbach 1.4 c-- ensures bfsfc is never 0
678 adcroft 1.1 do i = 1, imt
679     stable(i) = p5 + sign( p5, bfsfc(i) )
680 heimbach 1.4 bfsfc(i) = sign(eins,bfsfc(i))*max(phepsi,abs(bfsfc(i)))
681 adcroft 1.1 end do
682    
683     c-----------------------------------------------------------------------
684     c determine caseA and caseB
685     c-----------------------------------------------------------------------
686    
687     do i = 1, imt
688     casea(i) = p5 +
689     1 sign(p5, -zgrid(kbl(i)) - p5*hwide(kbl(i)) - hbl(i))
690     end do
691    
692     #endif /* ALLOW_KPP */
693    
694     return
695     end
696    
697     c*************************************************************************
698    
699     subroutine wscale (
700     I sigma, hbl, ustar, bfsfc,
701 mlosch 1.30 O wm, ws,
702     I myThid )
703 adcroft 1.1
704     c compute turbulent velocity scales.
705     c use a 2D-lookup table for wm and ws as functions of ustar and
706     c zetahat (=vonk*sigma*hbl*bfsfc).
707     c
708     c note: the lookup table is only used for unstable conditions
709     c (zehat.le.0), in the stable domain wm (=ws) gets computed
710     c directly.
711     c
712     IMPLICIT NONE
713    
714     #include "SIZE.h"
715     #include "KPP_PARAMS.h"
716    
717     c input
718     c------
719     c sigma : normalized depth (d/hbl)
720     c hbl : boundary layer depth (m)
721     c ustar : surface friction velocity (m/s)
722     c bfsfc : total surface buoyancy flux (m^2/s^3)
723 mlosch 1.30 c myThid : thread number for this instance of the routine
724     integer myThid
725 dimitri 1.27 _RL sigma(imt)
726     _RL hbl (imt)
727     _RL ustar(imt)
728     _RL bfsfc(imt)
729 adcroft 1.1
730     c output
731     c--------
732     c wm, ws : turbulent velocity scales at sigma
733 dimitri 1.27 _RL wm(imt), ws(imt)
734 adcroft 1.1
735     #ifdef ALLOW_KPP
736    
737     c local
738     c------
739     c zehat : = zeta * ustar**3
740 dimitri 1.27 _RL zehat
741 adcroft 1.1
742     integer iz, izp1, ju, i, jup1
743 dimitri 1.27 _RL udiff, zdiff, zfrac, ufrac, fzfrac, wam
744     _RL wbm, was, wbs, u3, tempVar
745 adcroft 1.1
746     c-----------------------------------------------------------------------
747     c use lookup table for zehat < zmax only; otherwise use
748     c stable formulae
749     c-----------------------------------------------------------------------
750    
751     do i = 1, imt
752     zehat = vonk*sigma(i)*hbl(i)*bfsfc(i)
753    
754     if (zehat .le. zmax) then
755    
756     zdiff = zehat - zmin
757     iz = int( zdiff / deltaz )
758     iz = min( iz, nni )
759     iz = max( iz, 0 )
760     izp1 = iz + 1
761 heimbach 1.4
762 adcroft 1.1 udiff = ustar(i) - umin
763     ju = int( udiff / deltau )
764     ju = min( ju, nnj )
765     ju = max( ju, 0 )
766     jup1 = ju + 1
767 heimbach 1.4
768 adcroft 1.1 zfrac = zdiff / deltaz - float(iz)
769     ufrac = udiff / deltau - float(ju)
770 heimbach 1.4
771 adcroft 1.1 fzfrac= 1. - zfrac
772     wam = fzfrac * wmt(iz,jup1) + zfrac * wmt(izp1,jup1)
773     wbm = fzfrac * wmt(iz,ju ) + zfrac * wmt(izp1,ju )
774     wm(i) = (1.-ufrac) * wbm + ufrac * wam
775 heimbach 1.4
776 adcroft 1.1 was = fzfrac * wst(iz,jup1) + zfrac * wst(izp1,jup1)
777     wbs = fzfrac * wst(iz,ju ) + zfrac * wst(izp1,ju )
778     ws(i) = (1.-ufrac) * wbs + ufrac * was
779 heimbach 1.4
780 adcroft 1.1 else
781 heimbach 1.4
782     u3 = ustar(i) * ustar(i) * ustar(i)
783     tempVar = u3 + conc1 * zehat
784     wm(i) = vonk * ustar(i) * u3 / tempVar
785 adcroft 1.1 ws(i) = wm(i)
786 heimbach 1.4
787 adcroft 1.1 endif
788    
789     end do
790    
791     #endif /* ALLOW_KPP */
792    
793     return
794     end
795    
796     c*************************************************************************
797    
798     subroutine Ri_iwmix (
799 jmc 1.31 I kmtj, shsq, dbloc, dblocSm,
800     I diffusKzS, diffusKzT,
801     I ikppkey,
802     O diffus,
803     I myThid )
804 adcroft 1.1
805     c compute interior viscosity diffusivity coefficients due
806     c to shear instability (dependent on a local Richardson number),
807     c to background internal wave activity, and
808     c to static instability (local Richardson number < 0).
809    
810     IMPLICIT NONE
811    
812     #include "SIZE.h"
813     #include "EEPARAMS.h"
814     #include "PARAMS.h"
815     #include "KPP_PARAMS.h"
816 heimbach 1.42 #ifdef ALLOW_AUTODIFF
817     # include "tamc.h"
818     #endif
819 adcroft 1.1
820     c input
821     c kmtj (imt) number of vertical layers on this row
822     c shsq (imt,Nr) (local velocity shear)^2 ((m/s)^2)
823     c dbloc (imt,Nr) local delta buoyancy (m/s^2)
824     c dblocSm(imt,Nr) horizontally smoothed dbloc (m/s^2)
825 dimitri 1.26 c diffusKzS(imt,Nr)- background vertical diffusivity for scalars (m^2/s)
826     c diffusKzT(imt,Nr)- background vertical diffusivity for theta (m^2/s)
827 jmc 1.31 c myThid :: My Thread Id. number
828 dimitri 1.27 integer kmtj (imt)
829     _RL shsq (imt,Nr)
830     _RL dbloc (imt,Nr)
831     _RL dblocSm (imt,Nr)
832 dimitri 1.26 _RL diffusKzS(imt,Nr)
833     _RL diffusKzT(imt,Nr)
834 heimbach 1.16 integer ikppkey
835 jmc 1.31 integer myThid
836 adcroft 1.1
837     c output
838     c diffus(imt,0:Nrp1,1) vertical viscosivity coefficient (m^2/s)
839     c diffus(imt,0:Nrp1,2) vertical scalar diffusivity (m^2/s)
840     c diffus(imt,0:Nrp1,3) vertical temperature diffusivity (m^2/s)
841 dimitri 1.27 _RL diffus(imt,0:Nrp1,3)
842 adcroft 1.1
843     #ifdef ALLOW_KPP
844    
845     c local variables
846     c Rig local Richardson number
847     c fRi, fcon function of Rig
848 dimitri 1.27 _RL Rig
849     _RL fRi, fcon
850     _RL ratio
851 dimitri 1.13 integer i, ki
852 dimitri 1.27 _RL c1, c0
853 adcroft 1.1
854 heimbach 1.5 #ifdef ALLOW_KPP_VERTICALLY_SMOOTH
855 dimitri 1.13 integer mr
856 heimbach 1.5 CADJ INIT kpp_ri_tape_mr = common, 1
857     #endif
858    
859 adcroft 1.1 c constants
860 dfer 1.40 c1 = 1. _d 0
861     c0 = 0. _d 0
862 adcroft 1.1
863     c-----------------------------------------------------------------------
864     c compute interior gradient Ri at all interfaces ki=1,Nr, (not surface)
865     c use diffus(*,*,1) as temporary storage of Ri to be smoothed
866     c use diffus(*,*,2) as temporary storage for Brunt-Vaisala squared
867     c set values at bottom and below to nearest value above bottom
868 heimbach 1.5 #ifdef ALLOW_AUTODIFF_TAMC
869     C break data flow dependence on diffus
870     diffus(1,1,1) = 0.0
871 heimbach 1.19
872     do ki = 1, Nr
873     do i = 1, imt
874     diffus(i,ki,1) = 0.
875     diffus(i,ki,2) = 0.
876     diffus(i,ki,3) = 0.
877     enddo
878     enddo
879 heimbach 1.5 #endif
880 heimbach 1.19
881 adcroft 1.1
882     do ki = 1, Nr
883     do i = 1, imt
884 heimbach 1.9 if (kmtj(i) .LE. 1 ) then
885 adcroft 1.1 diffus(i,ki,1) = 0.
886     diffus(i,ki,2) = 0.
887     elseif (ki .GE. kmtj(i)) then
888     diffus(i,ki,1) = diffus(i,ki-1,1)
889     diffus(i,ki,2) = diffus(i,ki-1,2)
890     else
891     diffus(i,ki,1) = dblocSm(i,ki) * (zgrid(ki)-zgrid(ki+1))
892     & / max( Shsq(i,ki), phepsi )
893     diffus(i,ki,2) = dbloc(i,ki) / (zgrid(ki)-zgrid(ki+1))
894     endif
895     end do
896     end do
897 heimbach 1.42 CADJ store diffus = comlev1_kpp, key=ikppkey, kind=isbyte
898 adcroft 1.1
899     c-----------------------------------------------------------------------
900     c vertically smooth Ri
901 heimbach 1.5 #ifdef ALLOW_KPP_VERTICALLY_SMOOTH
902 adcroft 1.1 do mr = 1, num_v_smooth_Ri
903 heimbach 1.2
904 heimbach 1.5 CADJ store diffus(:,:,1) = kpp_ri_tape_mr
905     CADJ & , key=mr, shape=(/ (sNx+2*OLx)*(sNy+2*OLy),Nr+2 /)
906 heimbach 1.2
907 adcroft 1.1 call z121 (
908 dfer 1.39 U diffus(1,0,1),
909 mlosch 1.30 I myThid )
910 adcroft 1.1 end do
911 heimbach 1.5 #endif
912 adcroft 1.1
913     c-----------------------------------------------------------------------
914     c after smoothing loop
915    
916     do ki = 1, Nr
917     do i = 1, imt
918    
919     c evaluate f of Brunt-Vaisala squared for convection, store in fcon
920    
921     Rig = max ( diffus(i,ki,2) , BVSQcon )
922     ratio = min ( (BVSQcon - Rig) / BVSQcon, c1 )
923     fcon = c1 - ratio * ratio
924     fcon = fcon * fcon * fcon
925    
926     c evaluate f of smooth Ri for shear instability, store in fRi
927    
928     Rig = max ( diffus(i,ki,1), c0 )
929     ratio = min ( Rig / Riinfty , c1 )
930     fRi = c1 - ratio * ratio
931     fRi = fRi * fRi * fRi
932    
933     c ----------------------------------------------------------------------
934     c evaluate diffusivities and viscosity
935     c mixing due to internal waves, and shear and static instability
936 heimbach 1.18
937     #ifndef EXCLUDE_KPP_SHEAR_MIX
938 heimbach 1.22 if ( .NOT. inAdMode ) then
939     diffus(i,ki,1) = viscAr + fcon * difmcon + fRi * difm0
940 dimitri 1.26 diffus(i,ki,2) = diffusKzS(i,ki)+fcon*difscon+fRi*difs0
941     diffus(i,ki,3) = diffusKzT(i,ki)+fcon*diftcon+fRi*dift0
942 heimbach 1.22 else
943     diffus(i,ki,1) = viscAr
944 dimitri 1.26 diffus(i,ki,2) = diffusKzS(i,ki)
945     diffus(i,ki,3) = diffusKzT(i,ki)
946 heimbach 1.22 endif
947 heimbach 1.18 #else
948     diffus(i,ki,1) = viscAr
949 dimitri 1.26 diffus(i,ki,2) = diffusKzS(i,ki)
950     diffus(i,ki,3) = diffusKzT(i,ki)
951 heimbach 1.18 #endif
952 adcroft 1.1
953     end do
954     end do
955    
956     c ------------------------------------------------------------------------
957     c set surface values to 0.0
958    
959     do i = 1, imt
960     diffus(i,0,1) = c0
961     diffus(i,0,2) = c0
962     diffus(i,0,3) = c0
963     end do
964    
965     #endif /* ALLOW_KPP */
966    
967     return
968     end
969    
970     c*************************************************************************
971    
972     subroutine z121 (
973 mlosch 1.30 U v,
974     I myThid )
975 adcroft 1.1
976     c Apply 121 smoothing in k to 2-d array V(i,k=1,Nr)
977     c top (0) value is used as a dummy
978     c bottom (Nrp1) value is set to input value from above.
979    
980 heimbach 1.2 c Note that it is important to exclude from the smoothing any points
981 adcroft 1.1 c that are outside the range of the K(Ri) scheme, ie. >0.8, or <0.0.
982 heimbach 1.2 c Otherwise, there is interference with other physics, especially
983 adcroft 1.1 c penetrative convection.
984    
985     IMPLICIT NONE
986     #include "SIZE.h"
987     #include "KPP_PARAMS.h"
988    
989     c input/output
990     c-------------
991     c v : 2-D array to be smoothed in Nrp1 direction
992 mlosch 1.30 c myThid: thread number for this instance of the routine
993     integer myThid
994 dimitri 1.27 _RL v(imt,0:Nrp1)
995 adcroft 1.1
996     #ifdef ALLOW_KPP
997    
998     c local
999 dimitri 1.27 _RL zwork, zflag
1000     _RL KRi_range(1:Nrp1)
1001 adcroft 1.1 integer i, k, km1, kp1
1002    
1003 dimitri 1.27 _RL p0 , p25 , p5 , p2
1004 heimbach 1.2 parameter ( p0 = 0.0, p25 = 0.25, p5 = 0.5, p2 = 2.0 )
1005    
1006     KRi_range(Nrp1) = p0
1007 adcroft 1.1
1008 heimbach 1.2 #ifdef ALLOW_AUTODIFF_TAMC
1009     C-- dummy assignment to end declaration part for TAMC
1010     i = 0
1011    
1012     C-- HPF directive to help TAMC
1013     CHPF$ INDEPENDENT
1014 heimbach 1.4 CADJ INIT z121tape = common, Nr
1015 heimbach 1.2 #endif /* ALLOW_AUTODIFF_TAMC */
1016 heimbach 1.4
1017 adcroft 1.1 do i = 1, imt
1018    
1019 heimbach 1.4 k = 1
1020     CADJ STORE v(i,k) = z121tape
1021 adcroft 1.1 v(i,Nrp1) = v(i,Nr)
1022    
1023     do k = 1, Nr
1024     KRi_range(k) = p5 + SIGN(p5,v(i,k))
1025     KRi_range(k) = KRi_range(k) *
1026     & ( p5 + SIGN(p5,(Riinfty-v(i,k))) )
1027     end do
1028    
1029     zwork = KRi_range(1) * v(i,1)
1030     v(i,1) = p2 * v(i,1) +
1031     & KRi_range(1) * KRi_range(2) * v(i,2)
1032     zflag = p2 + KRi_range(1) * KRi_range(2)
1033     v(i,1) = v(i,1) / zflag
1034    
1035     do k = 2, Nr
1036 heimbach 1.2 CADJ STORE v(i,k), zwork = z121tape
1037 adcroft 1.1 km1 = k - 1
1038     kp1 = k + 1
1039     zflag = v(i,k)
1040     v(i,k) = p2 * v(i,k) +
1041     & KRi_range(k) * KRi_range(kp1) * v(i,kp1) +
1042     & KRi_range(k) * zwork
1043     zwork = KRi_range(k) * zflag
1044     zflag = p2 + KRi_range(k)*(KRi_range(kp1)+KRi_range(km1))
1045     v(i,k) = v(i,k) / zflag
1046     end do
1047    
1048     end do
1049    
1050     #endif /* ALLOW_KPP */
1051    
1052     return
1053     end
1054    
1055     c*************************************************************************
1056    
1057 heimbach 1.4 subroutine smooth_horiz (
1058 adcroft 1.1 I k, bi, bj,
1059 mlosch 1.30 U fld,
1060     I myThid )
1061 adcroft 1.1
1062 heimbach 1.4 c Apply horizontal smoothing to global _RL 2-D array
1063 adcroft 1.1
1064     IMPLICIT NONE
1065     #include "SIZE.h"
1066 jmc 1.20 #include "GRID.h"
1067 adcroft 1.1 #include "KPP_PARAMS.h"
1068    
1069     c input
1070 heimbach 1.4 c bi, bj : array indices
1071     c k : vertical index used for masking
1072 mlosch 1.30 c myThid : thread number for this instance of the routine
1073     INTEGER myThid
1074 adcroft 1.1 integer k, bi, bj
1075    
1076 heimbach 1.4 c input/output
1077     c fld : 2-D array to be smoothed
1078     _RL fld( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy )
1079 adcroft 1.1
1080     #ifdef ALLOW_KPP
1081    
1082     c local
1083     integer i, j, im1, ip1, jm1, jp1
1084     _RL tempVar
1085 heimbach 1.4 _RL fld_tmp( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy )
1086 adcroft 1.1
1087 heimbach 1.4 integer imin , imax , jmin , jmax
1088     parameter(imin=2-OLx, imax=sNx+OLx-1, jmin=2-OLy, jmax=sNy+OLy-1)
1089 adcroft 1.1
1090 heimbach 1.4 _RL p0 , p5 , p25 , p125 , p0625
1091 adcroft 1.1 parameter( p0=0.0, p5=0.5, p25=0.25, p125=0.125, p0625=0.0625 )
1092    
1093     DO j = jmin, jmax
1094     jm1 = j-1
1095     jp1 = j+1
1096     DO i = imin, imax
1097     im1 = i-1
1098     ip1 = i+1
1099     tempVar =
1100 jmc 1.20 & p25 * maskC(i ,j ,k,bi,bj) +
1101     & p125 * ( maskC(im1,j ,k,bi,bj) +
1102     & maskC(ip1,j ,k,bi,bj) +
1103     & maskC(i ,jm1,k,bi,bj) +
1104     & maskC(i ,jp1,k,bi,bj) ) +
1105     & p0625 * ( maskC(im1,jm1,k,bi,bj) +
1106     & maskC(im1,jp1,k,bi,bj) +
1107     & maskC(ip1,jm1,k,bi,bj) +
1108     & maskC(ip1,jp1,k,bi,bj) )
1109 adcroft 1.1 IF ( tempVar .GE. p25 ) THEN
1110     fld_tmp(i,j) = (
1111 jmc 1.20 & p25 * fld(i ,j )*maskC(i ,j ,k,bi,bj) +
1112     & p125 *(fld(im1,j )*maskC(im1,j ,k,bi,bj) +
1113     & fld(ip1,j )*maskC(ip1,j ,k,bi,bj) +
1114     & fld(i ,jm1)*maskC(i ,jm1,k,bi,bj) +
1115     & fld(i ,jp1)*maskC(i ,jp1,k,bi,bj))+
1116     & p0625*(fld(im1,jm1)*maskC(im1,jm1,k,bi,bj) +
1117     & fld(im1,jp1)*maskC(im1,jp1,k,bi,bj) +
1118     & fld(ip1,jm1)*maskC(ip1,jm1,k,bi,bj) +
1119     & fld(ip1,jp1)*maskC(ip1,jp1,k,bi,bj)))
1120 adcroft 1.1 & / tempVar
1121     ELSE
1122 heimbach 1.4 fld_tmp(i,j) = fld(i,j)
1123 adcroft 1.1 ENDIF
1124     ENDDO
1125     ENDDO
1126    
1127     c transfer smoothed field to output array
1128     DO j = jmin, jmax
1129     DO i = imin, imax
1130 heimbach 1.4 fld(i,j) = fld_tmp(i,j)
1131 adcroft 1.1 ENDDO
1132     ENDDO
1133    
1134     #endif /* ALLOW_KPP */
1135    
1136     return
1137     end
1138    
1139     c*************************************************************************
1140    
1141     subroutine blmix (
1142     I ustar, bfsfc, hbl, stable, casea, diffus, kbl
1143 heimbach 1.16 O , dkm1, blmc, ghat, sigma, ikppkey
1144 jmc 1.31 I , myThid )
1145 adcroft 1.1
1146     c mixing coefficients within boundary layer depend on surface
1147     c forcing and the magnitude and gradient of interior mixing below
1148     c the boundary layer ("matching").
1149     c
1150     c caution: if mixing bottoms out at hbl = -zgrid(Nr) then
1151     c fictitious layer at Nrp1 is needed with small but finite width
1152     c hwide(Nrp1) (eg. epsln = 1.e-20).
1153     c
1154     IMPLICIT NONE
1155    
1156     #include "SIZE.h"
1157     #include "KPP_PARAMS.h"
1158 heimbach 1.42 #ifdef ALLOW_AUTODIFF
1159     # include "tamc.h"
1160     #endif
1161 adcroft 1.1
1162     c input
1163     c ustar (imt) surface friction velocity (m/s)
1164     c bfsfc (imt) surface buoyancy forcing (m^2/s^3)
1165     c hbl (imt) boundary layer depth (m)
1166     c stable(imt) = 1 in stable forcing
1167     c casea (imt) = 1 in case A
1168     c diffus(imt,0:Nrp1,mdiff) vertical diffusivities (m^2/s)
1169 dimitri 1.27 c kbl (imt) -1 of first grid level below hbl
1170 mlosch 1.30 c myThid thread number for this instance of the routine
1171     integer myThid
1172 dimitri 1.27 _RL ustar (imt)
1173     _RL bfsfc (imt)
1174     _RL hbl (imt)
1175     _RL stable(imt)
1176     _RL casea (imt)
1177     _RL diffus(imt,0:Nrp1,mdiff)
1178 adcroft 1.1 integer kbl(imt)
1179    
1180     c output
1181     c dkm1 (imt,mdiff) boundary layer difs at kbl-1 level
1182     c blmc (imt,Nr,mdiff) boundary layer mixing coefficients (m^2/s)
1183     c ghat (imt,Nr) nonlocal scalar transport
1184     c sigma(imt) normalized depth (d / hbl)
1185 dimitri 1.27 _RL dkm1 (imt,mdiff)
1186     _RL blmc (imt,Nr,mdiff)
1187     _RL ghat (imt,Nr)
1188     _RL sigma(imt)
1189 heimbach 1.19 integer ikppkey, kkppkey
1190 adcroft 1.1
1191     #ifdef ALLOW_KPP
1192    
1193     c local
1194 heimbach 1.2 c gat1*(imt) shape function at sigma = 1
1195     c dat1*(imt) derivative of shape function at sigma = 1
1196 adcroft 1.1 c ws(imt), wm(imt) turbulent velocity scales (m/s)
1197 dimitri 1.27 _RL gat1m(imt), gat1s(imt), gat1t(imt)
1198     _RL dat1m(imt), dat1s(imt), dat1t(imt)
1199     _RL ws(imt), wm(imt)
1200 adcroft 1.1 integer i, kn, ki
1201 dimitri 1.27 _RL R, dvdzup, dvdzdn, viscp
1202     _RL difsp, diftp, visch, difsh, difth
1203     _RL f1, sig, a1, a2, a3, delhat
1204     _RL Gm, Gs, Gt
1205     _RL tempVar
1206 adcroft 1.1
1207 dimitri 1.27 _RL p0 , eins
1208 heimbach 1.2 parameter (p0=0.0, eins=1.0)
1209 adcroft 1.1
1210     c-----------------------------------------------------------------------
1211     c compute velocity scales at hbl
1212     c-----------------------------------------------------------------------
1213    
1214     do i = 1, imt
1215     sigma(i) = stable(i) * 1.0 + (1. - stable(i)) * epsilon
1216     end do
1217    
1218 heimbach 1.42 CADJ STORE sigma = comlev1_kpp, key=ikppkey, kind=isbyte
1219 adcroft 1.1 call wscale (
1220     I sigma, hbl, ustar, bfsfc,
1221 mlosch 1.30 O wm, ws, myThid )
1222 heimbach 1.42 CADJ STORE wm = comlev1_kpp, key=ikppkey, kind=isbyte
1223     CADJ STORE ws = comlev1_kpp, key=ikppkey, kind=isbyte
1224 adcroft 1.1
1225     do i = 1, imt
1226 heimbach 1.4 wm(i) = sign(eins,wm(i))*max(phepsi,abs(wm(i)))
1227     ws(i) = sign(eins,ws(i))*max(phepsi,abs(ws(i)))
1228     end do
1229 heimbach 1.42 CADJ STORE wm = comlev1_kpp, key=ikppkey, kind=isbyte
1230     CADJ STORE ws = comlev1_kpp, key=ikppkey, kind=isbyte
1231 heimbach 1.4
1232     do i = 1, imt
1233 adcroft 1.1
1234     kn = int(caseA(i)+phepsi) *(kbl(i) -1) +
1235     $ (1 - int(caseA(i)+phepsi)) * kbl(i)
1236    
1237     c-----------------------------------------------------------------------
1238     c find the interior viscosities and derivatives at hbl(i)
1239     c-----------------------------------------------------------------------
1240    
1241     delhat = 0.5*hwide(kn) - zgrid(kn) - hbl(i)
1242     R = 1.0 - delhat / hwide(kn)
1243     dvdzup = (diffus(i,kn-1,1) - diffus(i,kn ,1)) / hwide(kn)
1244     dvdzdn = (diffus(i,kn ,1) - diffus(i,kn+1,1)) / hwide(kn+1)
1245     viscp = 0.5 * ( (1.-R) * (dvdzup + abs(dvdzup)) +
1246     1 R * (dvdzdn + abs(dvdzdn)) )
1247    
1248     dvdzup = (diffus(i,kn-1,2) - diffus(i,kn ,2)) / hwide(kn)
1249     dvdzdn = (diffus(i,kn ,2) - diffus(i,kn+1,2)) / hwide(kn+1)
1250     difsp = 0.5 * ( (1.-R) * (dvdzup + abs(dvdzup)) +
1251     1 R * (dvdzdn + abs(dvdzdn)) )
1252    
1253     dvdzup = (diffus(i,kn-1,3) - diffus(i,kn ,3)) / hwide(kn)
1254     dvdzdn = (diffus(i,kn ,3) - diffus(i,kn+1,3)) / hwide(kn+1)
1255     diftp = 0.5 * ( (1.-R) * (dvdzup + abs(dvdzup)) +
1256     1 R * (dvdzdn + abs(dvdzdn)) )
1257    
1258     visch = diffus(i,kn,1) + viscp * delhat
1259     difsh = diffus(i,kn,2) + difsp * delhat
1260     difth = diffus(i,kn,3) + diftp * delhat
1261    
1262     f1 = stable(i) * conc1 * bfsfc(i) /
1263     & max(ustar(i)**4,phepsi)
1264 heimbach 1.2 gat1m(i) = visch / hbl(i) / wm(i)
1265     dat1m(i) = -viscp / wm(i) + f1 * visch
1266 adcroft 1.1
1267 heimbach 1.2 gat1s(i) = difsh / hbl(i) / ws(i)
1268     dat1s(i) = -difsp / ws(i) + f1 * difsh
1269 adcroft 1.1
1270 heimbach 1.2 gat1t(i) = difth / hbl(i) / ws(i)
1271     dat1t(i) = -diftp / ws(i) + f1 * difth
1272 adcroft 1.1
1273     end do
1274 heimbach 1.19 #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1275 heimbach 1.42 CADJ STORE gat1m = comlev1_kpp, key=ikppkey, kind=isbyte
1276     CADJ STORE gat1s = comlev1_kpp, key=ikppkey, kind=isbyte
1277     CADJ STORE gat1t = comlev1_kpp, key=ikppkey, kind=isbyte
1278     CADJ STORE dat1m = comlev1_kpp, key=ikppkey, kind=isbyte
1279     CADJ STORE dat1s = comlev1_kpp, key=ikppkey, kind=isbyte
1280     CADJ STORE dat1t = comlev1_kpp, key=ikppkey, kind=isbyte
1281 heimbach 1.19 #endif
1282     do i = 1, imt
1283     dat1m(i) = min(dat1m(i),p0)
1284     dat1s(i) = min(dat1s(i),p0)
1285     dat1t(i) = min(dat1t(i),p0)
1286     end do
1287     #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1288 heimbach 1.42 CADJ STORE dat1m = comlev1_kpp, key=ikppkey, kind=isbyte
1289     CADJ STORE dat1s = comlev1_kpp, key=ikppkey, kind=isbyte
1290     CADJ STORE dat1t = comlev1_kpp, key=ikppkey, kind=isbyte
1291 heimbach 1.19 #endif
1292 adcroft 1.1
1293     do ki = 1, Nr
1294    
1295 heimbach 1.19 #ifdef ALLOW_AUTODIFF_TAMC
1296     kkppkey = (ikppkey-1)*Nr + ki
1297     #endif
1298    
1299 adcroft 1.1 c-----------------------------------------------------------------------
1300     c compute turbulent velocity scales on the interfaces
1301     c-----------------------------------------------------------------------
1302    
1303     do i = 1, imt
1304     sig = (-zgrid(ki) + 0.5 * hwide(ki)) / hbl(i)
1305     sigma(i) = stable(i)*sig + (1.-stable(i))*min(sig,epsilon)
1306     end do
1307 heimbach 1.19 #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1308     CADJ STORE wm = comlev1_kpp_k, key = kkppkey
1309     CADJ STORE ws = comlev1_kpp_k, key = kkppkey
1310     #endif
1311     CADJ STORE sigma = comlev1_kpp_k, key = kkppkey
1312 adcroft 1.1 call wscale (
1313     I sigma, hbl, ustar, bfsfc,
1314 mlosch 1.30 O wm, ws, myThid )
1315 heimbach 1.19 CADJ STORE wm = comlev1_kpp_k, key = kkppkey
1316     CADJ STORE ws = comlev1_kpp_k, key = kkppkey
1317 adcroft 1.1
1318     c-----------------------------------------------------------------------
1319     c compute the dimensionless shape functions at the interfaces
1320     c-----------------------------------------------------------------------
1321    
1322     do i = 1, imt
1323     sig = (-zgrid(ki) + 0.5 * hwide(ki)) / hbl(i)
1324     a1 = sig - 2.
1325     a2 = 3. - 2. * sig
1326     a3 = sig - 1.
1327    
1328 heimbach 1.2 Gm = a1 + a2 * gat1m(i) + a3 * dat1m(i)
1329     Gs = a1 + a2 * gat1s(i) + a3 * dat1s(i)
1330     Gt = a1 + a2 * gat1t(i) + a3 * dat1t(i)
1331 adcroft 1.1
1332     c-----------------------------------------------------------------------
1333     c compute boundary layer diffusivities at the interfaces
1334     c-----------------------------------------------------------------------
1335    
1336 heimbach 1.2 blmc(i,ki,1) = hbl(i) * wm(i) * sig * (1. + sig * Gm)
1337 adcroft 1.1 blmc(i,ki,2) = hbl(i) * ws(i) * sig * (1. + sig * Gs)
1338     blmc(i,ki,3) = hbl(i) * ws(i) * sig * (1. + sig * Gt)
1339    
1340     c-----------------------------------------------------------------------
1341     c nonlocal transport term = ghat * <ws>o
1342     c-----------------------------------------------------------------------
1343 heimbach 1.4
1344     tempVar = ws(i) * hbl(i)
1345     ghat(i,ki) = (1.-stable(i)) * cg / max(phepsi,tempVar)
1346 adcroft 1.1
1347     end do
1348     end do
1349    
1350     c-----------------------------------------------------------------------
1351     c find diffusivities at kbl-1 grid level
1352     c-----------------------------------------------------------------------
1353    
1354     do i = 1, imt
1355     sig = -zgrid(kbl(i)-1) / hbl(i)
1356     sigma(i) = stable(i) * sig
1357     & + (1. - stable(i)) * min(sig,epsilon)
1358     end do
1359    
1360 heimbach 1.19 #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1361 heimbach 1.42 CADJ STORE wm = comlev1_kpp, key=ikppkey, kind=isbyte
1362     CADJ STORE ws = comlev1_kpp, key=ikppkey, kind=isbyte
1363 heimbach 1.19 #endif
1364 heimbach 1.42 CADJ STORE sigma = comlev1_kpp, key=ikppkey, kind=isbyte
1365 adcroft 1.1 call wscale (
1366     I sigma, hbl, ustar, bfsfc,
1367 mlosch 1.30 O wm, ws, myThid )
1368 heimbach 1.42 CADJ STORE wm = comlev1_kpp, key=ikppkey, kind=isbyte
1369     CADJ STORE ws = comlev1_kpp, key=ikppkey, kind=isbyte
1370 adcroft 1.1
1371     do i = 1, imt
1372     sig = -zgrid(kbl(i)-1) / hbl(i)
1373     a1 = sig - 2.
1374     a2 = 3. - 2. * sig
1375     a3 = sig - 1.
1376 heimbach 1.2 Gm = a1 + a2 * gat1m(i) + a3 * dat1m(i)
1377     Gs = a1 + a2 * gat1s(i) + a3 * dat1s(i)
1378     Gt = a1 + a2 * gat1t(i) + a3 * dat1t(i)
1379     dkm1(i,1) = hbl(i) * wm(i) * sig * (1. + sig * Gm)
1380 adcroft 1.1 dkm1(i,2) = hbl(i) * ws(i) * sig * (1. + sig * Gs)
1381     dkm1(i,3) = hbl(i) * ws(i) * sig * (1. + sig * Gt)
1382     end do
1383    
1384     #endif /* ALLOW_KPP */
1385    
1386     return
1387     end
1388    
1389     c*************************************************************************
1390    
1391     subroutine enhance (
1392     I dkm1, hbl, kbl, diffus, casea
1393     U , ghat
1394     O , blmc
1395 mlosch 1.30 & , myThid )
1396 adcroft 1.1
1397     c enhance the diffusivity at the kbl-.5 interface
1398    
1399     IMPLICIT NONE
1400    
1401     #include "SIZE.h"
1402     #include "KPP_PARAMS.h"
1403    
1404     c input
1405     c dkm1(imt,mdiff) bl diffusivity at kbl-1 grid level
1406     c hbl(imt) boundary layer depth (m)
1407     c kbl(imt) grid above hbl
1408     c diffus(imt,0:Nrp1,mdiff) vertical diffusivities (m^2/s)
1409     c casea(imt) = 1 in caseA, = 0 in case B
1410 mlosch 1.30 c myThid thread number for this instance of the routine
1411     integer myThid
1412 dimitri 1.27 _RL dkm1 (imt,mdiff)
1413     _RL hbl (imt)
1414 adcroft 1.1 integer kbl (imt)
1415 dimitri 1.27 _RL diffus(imt,0:Nrp1,mdiff)
1416     _RL casea (imt)
1417 adcroft 1.1
1418     c input/output
1419     c nonlocal transport, modified ghat at kbl(i)-1 interface (s/m**2)
1420 dimitri 1.27 _RL ghat (imt,Nr)
1421 adcroft 1.1
1422     c output
1423     c enhanced bound. layer mixing coeff.
1424 dimitri 1.27 _RL blmc (imt,Nr,mdiff)
1425 adcroft 1.1
1426     #ifdef ALLOW_KPP
1427    
1428     c local
1429     c fraction hbl lies beteen zgrid neighbors
1430 dimitri 1.27 _RL delta
1431 adcroft 1.1 integer ki, i, md
1432 dimitri 1.27 _RL dkmp5, dstar
1433 adcroft 1.1
1434     do i = 1, imt
1435     ki = kbl(i)-1
1436     if ((ki .ge. 1) .and. (ki .lt. Nr)) then
1437     delta = (hbl(i) + zgrid(ki)) / (zgrid(ki) - zgrid(ki+1))
1438     do md = 1, mdiff
1439     dkmp5 = casea(i) * diffus(i,ki,md) +
1440     1 (1.- casea(i)) * blmc (i,ki,md)
1441     dstar = (1.- delta)**2 * dkm1(i,md)
1442     & + delta**2 * dkmp5
1443     blmc(i,ki,md) = (1.- delta)*diffus(i,ki,md)
1444     & + delta*dstar
1445     end do
1446     ghat(i,ki) = (1.- casea(i)) * ghat(i,ki)
1447     endif
1448     end do
1449    
1450     #endif /* ALLOW_KPP */
1451    
1452     return
1453     end
1454    
1455     c*************************************************************************
1456    
1457     SUBROUTINE STATEKPP (
1458 mlosch 1.30 O RHO1, DBLOC, DBSFC, TTALPHA, SSBETA,
1459     I ikppkey, bi, bj, myThid )
1460 adcroft 1.1 c
1461     c-----------------------------------------------------------------------
1462     c "statekpp" computes all necessary input arrays
1463     c for the kpp mixing scheme
1464     c
1465     c input:
1466     c bi, bj = array indices on which to apply calculations
1467     c
1468     c output:
1469     c rho1 = potential density of surface layer (kg/m^3)
1470     c dbloc = local buoyancy gradient at Nr interfaces
1471     c g/rho{k+1,k+1} * [ drho{k,k+1}-drho{k+1,k+1} ] (m/s^2)
1472     c dbsfc = buoyancy difference with respect to the surface
1473     c g * [ drho{1,k}/rho{1,k} - drho{k,k}/rho{k,k} ] (m/s^2)
1474     c ttalpha= thermal expansion coefficient without 1/rho factor
1475     c d(rho) / d(potential temperature) (kg/m^3/C)
1476     c ssbeta = salt expansion coefficient without 1/rho factor
1477     c d(rho) / d(salinity) (kg/m^3/PSU)
1478     c
1479     c see also subroutines find_rho.F find_alpha.F find_beta.F
1480     c
1481     c written by: jan morzel, feb. 10, 1995 (converted from "sigma" version)
1482     c modified by: d. menemenlis, june 1998 : for use with MIT GCM UV
1483     c
1484 dimitri 1.23
1485 adcroft 1.1 c-----------------------------------------------------------------------
1486    
1487     IMPLICIT NONE
1488    
1489     #include "SIZE.h"
1490     #include "EEPARAMS.h"
1491     #include "PARAMS.h"
1492     #include "KPP_PARAMS.h"
1493 adcroft 1.6 #include "DYNVARS.h"
1494 dimitri 1.23 #include "GRID.h"
1495 heimbach 1.42 #ifdef ALLOW_AUTODIFF
1496     # include "tamc.h"
1497     #endif
1498 adcroft 1.1
1499     c-------------- Routine arguments -----------------------------------------
1500     INTEGER bi, bj, myThid
1501 dimitri 1.27 _RL RHO1 ( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy )
1502     _RL DBLOC ( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy, Nr )
1503     _RL DBSFC ( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy, Nr )
1504     _RL TTALPHA( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy, Nrp1 )
1505     _RL SSBETA ( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy, Nrp1 )
1506 adcroft 1.1
1507     #ifdef ALLOW_KPP
1508    
1509     c--------------------------------------------------------------------------
1510     c
1511     c local arrays:
1512     c
1513     c rhok - density of t(k ) & s(k ) at depth k
1514     c rhokm1 - density of t(k-1) & s(k-1) at depth k
1515     c rho1k - density of t(1 ) & s(1 ) at depth k
1516 dimitri 1.23 c work1,2,3 - work arrays for holding horizontal slabs
1517 adcroft 1.1
1518     _RL RHOK (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
1519     _RL RHOKM1(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
1520     _RL RHO1K (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
1521     _RL WORK1 (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
1522     _RL WORK2 (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
1523     _RL WORK3 (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
1524 dimitri 1.23
1525 adcroft 1.1 INTEGER I, J, K
1526 heimbach 1.19 INTEGER ikppkey, kkppkey
1527 adcroft 1.1
1528     c calculate density, alpha, beta in surface layer, and set dbsfc to zero
1529    
1530 heimbach 1.19 kkppkey = (ikppkey-1)*Nr + 1
1531    
1532     #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1533 heimbach 1.42 CADJ STORE theta(:,:,1,bi,bj) = comlev1_kpp_k,
1534     CADJ & key=kkppkey, kind=isbyte
1535     CADJ STORE salt (:,:,1,bi,bj) = comlev1_kpp_k,
1536     CADJ & key=kkppkey, kind=isbyte
1537 heimbach 1.19 #endif /* KPP_AUTODIFF_EXCESSIVE_STORE */
1538 jmc 1.38 CALL FIND_RHO_2D(
1539     I 1-OLx, sNx+OLx, 1-OLy, sNy+OLy, 1,
1540     I theta(1-OLx,1-OLy,1,bi,bj), salt(1-OLx,1-OLy,1,bi,bj),
1541 adcroft 1.1 O WORK1,
1542 jmc 1.38 I 1, bi, bj, myThid )
1543 heimbach 1.19 #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1544 heimbach 1.42 CADJ STORE theta(:,:,1,bi,bj) = comlev1_kpp_k,
1545     CADJ & key=kkppkey, kind=isbyte
1546     CADJ STORE salt (:,:,1,bi,bj) = comlev1_kpp_k,
1547     CADJ & key=kkppkey, kind=isbyte
1548 heimbach 1.19 #endif /* KPP_AUTODIFF_EXCESSIVE_STORE */
1549 adcroft 1.1
1550     call FIND_ALPHA(
1551 dimitri 1.24 I bi, bj, 1-OLx, sNx+OLx, 1-OLy, sNy+OLy, 1, 1,
1552 mlosch 1.30 O WORK2, myThid )
1553 adcroft 1.1
1554     call FIND_BETA(
1555 dimitri 1.24 I bi, bj, 1-OLx, sNx+OLx, 1-OLy, sNy+OLy, 1, 1,
1556 mlosch 1.30 O WORK3, myThid )
1557 adcroft 1.1
1558 dimitri 1.24 DO J = 1-OLy, sNy+OLy
1559     DO I = 1-OLx, sNx+OLx
1560 mlosch 1.12 RHO1(I,J) = WORK1(I,J) + rhoConst
1561 adcroft 1.1 TTALPHA(I,J,1) = WORK2(I,J)
1562     SSBETA(I,J,1) = WORK3(I,J)
1563     DBSFC(I,J,1) = 0.
1564     END DO
1565     END DO
1566    
1567     c calculate alpha, beta, and gradients in interior layers
1568    
1569 heimbach 1.2 CHPF$ INDEPENDENT, NEW (RHOK,RHOKM1,RHO1K,WORK1,WORK2)
1570 adcroft 1.1 DO K = 2, Nr
1571    
1572 heimbach 1.19 kkppkey = (ikppkey-1)*Nr + k
1573    
1574     #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1575 heimbach 1.42 CADJ STORE theta(:,:,k,bi,bj) = comlev1_kpp_k,
1576     CADJ & key=kkppkey, kind=isbyte
1577     CADJ STORE salt (:,:,k,bi,bj) = comlev1_kpp_k,
1578     CADJ & key=kkppkey, kind=isbyte
1579 heimbach 1.19 #endif /* KPP_AUTODIFF_EXCESSIVE_STORE */
1580 jmc 1.38 CALL FIND_RHO_2D(
1581     I 1-OLx, sNx+OLx, 1-OLy, sNy+OLy, k,
1582     I theta(1-OLx,1-OLy,k,bi,bj), salt(1-OLx,1-OLy,k,bi,bj),
1583 adcroft 1.1 O RHOK,
1584 jmc 1.38 I k, bi, bj, myThid )
1585 adcroft 1.1
1586 heimbach 1.19 #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1587 heimbach 1.42 CADJ STORE theta(:,:,k-1,bi,bj) = comlev1_kpp_k,
1588     CADJ & key=kkppkey, kind=isbyte
1589     CADJ STORE salt (:,:,k-1,bi,bj) = comlev1_kpp_k,
1590     CADJ & key=kkppkey, kind=isbyte
1591 heimbach 1.19 #endif /* KPP_AUTODIFF_EXCESSIVE_STORE */
1592 jmc 1.38 CALL FIND_RHO_2D(
1593     I 1-OLx, sNx+OLx, 1-OLy, sNy+OLy, k,
1594     I theta(1-OLx,1-OLy,k-1,bi,bj),salt(1-OLx,1-OLy,k-1,bi,bj),
1595 adcroft 1.1 O RHOKM1,
1596 jmc 1.38 I k-1, bi, bj, myThid )
1597 adcroft 1.1
1598 heimbach 1.19 #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1599 heimbach 1.42 CADJ STORE theta(:,:,1,bi,bj) = comlev1_kpp_k,
1600     CADJ & key=kkppkey, kind=isbyte
1601     CADJ STORE salt (:,:,1,bi,bj) = comlev1_kpp_k,
1602     CADJ & key=kkppkey, kind=isbyte
1603 heimbach 1.19 #endif /* KPP_AUTODIFF_EXCESSIVE_STORE */
1604 jmc 1.38 CALL FIND_RHO_2D(
1605     I 1-OLx, sNx+OLx, 1-OLy, sNy+OLy, k,
1606     I theta(1-OLx,1-OLy,1,bi,bj), salt(1-OLx,1-OLy,1,bi,bj),
1607 adcroft 1.1 O RHO1K,
1608 jmc 1.38 I 1, bi, bj, myThid )
1609 heimbach 1.19
1610     #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1611 heimbach 1.42 CADJ STORE rhok (:,:) = comlev1_kpp_k,
1612     CADJ & key=kkppkey, kind=isbyte
1613     CADJ STORE rhokm1(:,:) = comlev1_kpp_k,
1614     CADJ & key=kkppkey, kind=isbyte
1615     CADJ STORE rho1k (:,:) = comlev1_kpp_k,
1616     CADJ & key=kkppkey, kind=isbyte
1617 heimbach 1.19 #endif /* KPP_AUTODIFF_EXCESSIVE_STORE */
1618 adcroft 1.1
1619     call FIND_ALPHA(
1620 dimitri 1.24 I bi, bj, 1-OLx, sNx+OLx, 1-OLy, sNy+OLy, K, K,
1621 mlosch 1.30 O WORK1, myThid )
1622 adcroft 1.1
1623     call FIND_BETA(
1624 dimitri 1.24 I bi, bj, 1-OLx, sNx+OLx, 1-OLy, sNy+OLy, K, K,
1625 mlosch 1.30 O WORK2, myThid )
1626 adcroft 1.1
1627 dimitri 1.24 DO J = 1-OLy, sNy+OLy
1628     DO I = 1-OLx, sNx+OLx
1629 adcroft 1.1 TTALPHA(I,J,K) = WORK1 (I,J)
1630     SSBETA(I,J,K) = WORK2 (I,J)
1631     DBLOC(I,J,K-1) = gravity * (RHOK(I,J) - RHOKM1(I,J)) /
1632 mlosch 1.12 & (RHOK(I,J) + rhoConst)
1633 adcroft 1.1 DBSFC(I,J,K) = gravity * (RHOK(I,J) - RHO1K (I,J)) /
1634 mlosch 1.12 & (RHOK(I,J) + rhoConst)
1635 adcroft 1.1 END DO
1636     END DO
1637    
1638     END DO
1639    
1640     c compute arrays for K = Nrp1
1641 dimitri 1.24 DO J = 1-OLy, sNy+OLy
1642     DO I = 1-OLx, sNx+OLx
1643 adcroft 1.1 TTALPHA(I,J,Nrp1) = TTALPHA(I,J,Nr)
1644     SSBETA(I,J,Nrp1) = SSBETA(I,J,Nr)
1645     DBLOC(I,J,Nr) = 0.
1646     END DO
1647     END DO
1648    
1649 dimitri 1.23 #ifdef ALLOW_DIAGNOSTICS
1650     IF ( useDiagnostics ) THEN
1651 atn 1.37 CALL DIAGNOSTICS_FILL(DBSFC ,'KPPdbsfc',0,Nr,0,1,1,myThid)
1652     CALL DIAGNOSTICS_FILL(DBLOC ,'KPPdbloc',0,Nr,0,1,1,myThid)
1653 dimitri 1.23 ENDIF
1654     #endif /* ALLOW_DIAGNOSTICS */
1655    
1656 adcroft 1.1 #endif /* ALLOW_KPP */
1657    
1658     RETURN
1659     END

  ViewVC Help
Powered by ViewVC 1.1.22