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

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

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

revision 1.15 by heimbach, Fri Mar 7 23:51:02 2003 UTC revision 1.46 by jmc, Thu Oct 8 20:06:23 2009 UTC
# Line 1  Line 1 
1  C $Header$  C $Header$
2  C $Name$  C $Name$
3    
4    #include "PACKAGES_CONFIG.h"
5  #include "KPP_OPTIONS.h"  #include "KPP_OPTIONS.h"
6    
7  C-- File kpp_routines.F: subroutines needed to implement  C-- File kpp_routines.F: subroutines needed to implement
# Line 11  C--  o BLDEPTH     - Determine oceanic p Line 12  C--  o BLDEPTH     - Determine oceanic p
12  C--  o WSCALE      - Compute turbulent velocity scales.  C--  o WSCALE      - Compute turbulent velocity scales.
13  C--  o RI_IWMIX    - Compute interior viscosity diffusivity coefficients.  C--  o RI_IWMIX    - Compute interior viscosity diffusivity coefficients.
14  C--  o Z121        - Apply 121 vertical smoothing.  C--  o Z121        - Apply 121 vertical smoothing.
15  C--  o KPP_SMOOTH_HORIZ - Apply horizontal smoothing to KPP array.  C--  o SMOOTH_HORIZ- Apply horizontal smoothing to global array.
 C--  o SMOOTH_HORIZ     - Apply horizontal smoothing to global array.  
16  C--  o BLMIX       - Boundary layer mixing coefficients.  C--  o BLMIX       - Boundary layer mixing coefficients.
17  C--  o ENHANCE     - Enhance diffusivity at boundary layer interface.  C--  o ENHANCE     - Enhance diffusivity at boundary layer interface.
18  C--  o STATEKPP    - Compute buoyancy-related input arrays.  C--  o STATEKPP    - Compute buoyancy-related input arrays.
19    C--  o KPP_DOUBLEDIFF - Compute double diffusive contribution to diffusivities
20    
21  c***********************************************************************  c***********************************************************************
22    
23        SUBROUTINE KPPMIX (        SUBROUTINE KPPMIX (
24       I       mytime, mythid       I       kmtj, shsq, dvsq, ustar, msk
25       I     , kmtj, shsq, dvsq, ustar       I     , bo, bosol
26       I     , bo, bosol, dbloc, Ritop, coriol  #ifdef ALLOW_SALT_PLUME
27       I     , ikey       I     , boplume,SPDepth
28    #endif /* ALLOW_SALT_PLUME */
29         I     , dbloc, Ritop, coriol
30         I     , diffusKzS, diffusKzT
31         I     , ikppkey
32       O     , diffus       O     , diffus
33       U     , ghat       U     , ghat
34       O     , hbl )       O     , hbl
35         I     , myTime, myIter, myThid )
36    
37  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
38  c  c
# Line 47  c--------------------------------------- Line 53  c---------------------------------------
53  #include "SIZE.h"  #include "SIZE.h"
54  #include "EEPARAMS.h"  #include "EEPARAMS.h"
55  #include "PARAMS.h"  #include "PARAMS.h"
 #include "DYNVARS.h"  
 #include "FFIELDS.h"  
56  #include "KPP_PARAMS.h"  #include "KPP_PARAMS.h"
57    #ifdef ALLOW_AUTODIFF
58    # include "tamc.h"
59    #endif
60    
61  c input  c input
62  c     myTime          - current time in simulation  c   myTime :: Current time in simulation
63  c     myThid          - thread number for this instance of the routine  c   myIter :: Current iteration number in simulation
64  c     kmtj   (imt)    - number of vertical layers on this row  c   myThid :: My Thread Id. number
65  c     shsq   (imt,Nr) - (local velocity shear)^2                      ((m/s)^2)  c     kmtj   (imt)     - number of vertical layers on this row
66  c     dvsq   (imt,Nr) - (velocity shear re sfc)^2                     ((m/s)^2)  c     msk    (imt)     - surface mask (=1 if water, =0 otherwise)
67  c     ustar  (imt)    - surface friction velocity                         (m/s)  c     shsq   (imt,Nr)  - (local velocity shear)^2                     ((m/s)^2)
68  c     bo     (imt)    - surface turbulent buoy. forcing               (m^2/s^3)  c     dvsq   (imt,Nr)  - (velocity shear re sfc)^2                    ((m/s)^2)
69  c     bosol  (imt)    - radiative buoyancy forcing                    (m^2/s^3)  c     ustar  (imt)     - surface friction velocity                        (m/s)
70  c     dbloc  (imt,Nr) - local delta buoyancy across interfaces          (m/s^2)  c     bo     (imt)     - surface turbulent buoy. forcing              (m^2/s^3)
71  c     dblocSm(imt,Nr) - horizontally smoothed dbloc                     (m/s^2)  c     bosol  (imt)     - radiative buoyancy forcing                   (m^2/s^3)
72  c                         stored in ghat to save space  c     boplume(imt)     - haline buoyancy forcing                      (m^2/s^3)
73  c     Ritop  (imt,Nr) - numerator of bulk Richardson Number  c     dbloc  (imt,Nr)  - local delta buoyancy across interfaces         (m/s^2)
74  c                         (zref-z) * delta buoyancy w.r.t. surface    ((m/s)^2)  c     dblocSm(imt,Nr)  - horizontally smoothed dbloc                    (m/s^2)
75  c     coriol (imt)    - Coriolis parameter                                (1/s)  c                          stored in ghat to save space
76    c     Ritop  (imt,Nr)  - numerator of bulk Richardson Number
77    c                          (zref-z) * delta buoyancy w.r.t. surface   ((m/s)^2)
78    c     coriol (imt)     - Coriolis parameter                               (1/s)
79    c     diffusKzS(imt,Nr)- background vertical diffusivity for scalars    (m^2/s)
80    c     diffusKzT(imt,Nr)- background vertical diffusivity for theta      (m^2/s)
81  c     note: there is a conversion from 2-D to 1-D for input output variables,  c     note: there is a conversion from 2-D to 1-D for input output variables,
82  c           e.g., hbl(sNx,sNy) -> hbl(imt),  c           e.g., hbl(sNx,sNy) -> hbl(imt),
83  c           where hbl(i,j) -> hbl((j-1)*sNx+i)  c           where hbl(i,j) -> hbl((j-1)*sNx+i)
84    
85        _RL     mytime        _RL     myTime
86        integer mythid        integer myIter
87        integer kmtj  (imt   )        integer myThid
88        _KPP_RL shsq  (imt,Nr)        integer kmtj (imt   )
89        _KPP_RL dvsq  (imt,Nr)        _RL shsq     (imt,Nr)
90        _KPP_RL ustar (imt   )        _RL dvsq     (imt,Nr)
91        _KPP_RL bo    (imt   )        _RL ustar    (imt   )
92        _KPP_RL bosol (imt   )        _RL bo       (imt   )
93        _KPP_RL dbloc (imt,Nr)        _RL bosol    (imt   )
94        _KPP_RL Ritop (imt,Nr)  #ifdef ALLOW_SALT_PLUME
95        _KPP_RL coriol(imt   )        _RL boplume  (imt   )
96          _RL SPDepth  (imt   )
97    #endif /* ALLOW_SALT_PLUME */
98          _RL dbloc    (imt,Nr)
99          _RL Ritop    (imt,Nr)
100          _RL coriol   (imt   )
101          _RS msk      (imt   )
102          _RL diffusKzS(imt,Nr)
103          _RL diffusKzT(imt,Nr)
104    
105        integer ikey        integer ikppkey
106    
107  c output  c output
108  c     diffus (imt,1)  - vertical viscosity coefficient                  (m^2/s)  c     diffus (imt,1)  - vertical viscosity coefficient                  (m^2/s)
# Line 91  c     diffus (imt,3)  - vertical tempera Line 111  c     diffus (imt,3)  - vertical tempera
111  c     ghat   (imt)    - nonlocal transport coefficient                  (s/m^2)  c     ghat   (imt)    - nonlocal transport coefficient                  (s/m^2)
112  c     hbl    (imt)    - mixing layer depth                                  (m)  c     hbl    (imt)    - mixing layer depth                                  (m)
113    
114        _KPP_RL diffus(imt,0:Nrp1,mdiff)        _RL diffus(imt,0:Nrp1,mdiff)
115        _KPP_RL ghat  (imt,Nr)        _RL ghat  (imt,Nr)
116        _KPP_RL hbl   (imt)        _RL hbl   (imt)
117    
118  #ifdef ALLOW_KPP  #ifdef ALLOW_KPP
119    
# Line 107  c     blmc   (imt,Nr,mdiff) - boundary l Line 127  c     blmc   (imt,Nr,mdiff) - boundary l
127  c     sigma  (imt         ) - normalized depth (d / hbl)  c     sigma  (imt         ) - normalized depth (d / hbl)
128  c     Rib    (imt,Nr      ) - bulk Richardson number  c     Rib    (imt,Nr      ) - bulk Richardson number
129    
130        integer kbl   (imt         )        integer kbl(imt         )
131        _KPP_RL bfsfc (imt         )        _RL bfsfc  (imt         )
132        _KPP_RL casea (imt         )        _RL casea  (imt         )
133        _KPP_RL stable(imt         )        _RL stable (imt         )
134        _KPP_RL dkm1  (imt,   mdiff)        _RL dkm1   (imt,   mdiff)
135        _KPP_RL blmc  (imt,Nr,mdiff)        _RL blmc   (imt,Nr,mdiff)
136        _KPP_RL sigma (imt         )        _RL sigma  (imt         )
137        _KPP_RL Rib   (imt,Nr      )        _RL Rib    (imt,Nr      )
138    
139        integer i, k, md        integer i, k, md
140    
# Line 127  c--------------------------------------- Line 147  c---------------------------------------
147    
148  cph(  cph(
149  cph these storings avoid recomp. of Ri_iwmix  cph these storings avoid recomp. of Ri_iwmix
150  CADJ STORE ghat  = comlev1_kpp, key = ikey  CADJ STORE ghat  = comlev1_kpp, key=ikppkey, kind=isbyte
151  CADJ STORE dbloc = comlev1_kpp, key = ikey  CADJ STORE dbloc = comlev1_kpp, key=ikppkey, kind=isbyte
152  cph)  cph)
153        call Ri_iwmix (        call Ri_iwmix (
154       I       kmtj, shsq, dbloc, ghat       I       kmtj, shsq, dbloc, ghat
155       I     , ikey       I     , diffusKzS, diffusKzT
156       O     , diffus )       I     , ikppkey
157         O     , diffus, myThid )
158    
159  cph(  cph(
160  cph these storings avoid recomp. of Ri_iwmix  cph these storings avoid recomp. of Ri_iwmix
161  cph DESPITE TAFs 'not necessary' warning!  cph DESPITE TAFs 'not necessary' warning!
162  CADJ STORE dbloc  = comlev1_kpp, key = ikey  CADJ STORE dbloc  = comlev1_kpp, key=ikppkey, kind=isbyte
163  CADJ STORE shsq   = comlev1_kpp, key = ikey  CADJ STORE shsq   = comlev1_kpp, key=ikppkey, kind=isbyte
164  CADJ STORE ghat   = comlev1_kpp, key = ikey  CADJ STORE ghat   = comlev1_kpp, key=ikppkey, kind=isbyte
165  CADJ STORE diffus = comlev1_kpp, key = ikey  CADJ STORE diffus = comlev1_kpp, key=ikppkey, kind=isbyte
166  cph)  cph)
167    
168  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
# Line 150  c for blmix Line 171  c for blmix
171  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
172    
173        do md = 1, mdiff        do md = 1, mdiff
174           do k=1,Nrp1
175           do i = 1,imt           do i = 1,imt
176              do k=kmtj(i),Nrp1               if(k.ge.kmtj(i))  diffus(i,k,md) = 0.0
                diffus(i,k,md) = 0.0  
177              end do              end do
178           end do           end do
179        end do        end do
# Line 164  c diagnose the new boundary layer depth Line 185  c diagnose the new boundary layer depth
185  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
186    
187        call bldepth (        call bldepth (
188       I       mytime, mythid       I       kmtj
189       I     , kmtj       I     , dvsq, dbloc, Ritop, ustar, bo, bosol
190       I     , dvsq, dbloc, Ritop, ustar, bo, bosol, coriol  #ifdef ALLOW_SALT_PLUME
191       I     , ikey       I     , boplume,SPDepth
192    #endif /* ALLOW_SALT_PLUME */
193         I     , coriol
194         I     , ikppkey
195       O     , hbl, bfsfc, stable, casea, kbl, Rib, sigma       O     , hbl, bfsfc, stable, casea, kbl, Rib, sigma
196       &     )       I     , myTime, myIter, myThid )
197    
198  CADJ STORE hbl,bfsfc,stable,casea,kbl = comlev1_kpp, key = ikey  CADJ STORE hbl,bfsfc,stable,casea,kbl = comlev1_kpp,
199    CADJ &     key=ikppkey, kind=isbyte
200    
201  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
202  c compute boundary layer diffusivities  c compute boundary layer diffusivities
# Line 179  c--------------------------------------- Line 204  c---------------------------------------
204    
205        call blmix (        call blmix (
206       I       ustar, bfsfc, hbl, stable, casea, diffus, kbl       I       ustar, bfsfc, hbl, stable, casea, diffus, kbl
207       O     , dkm1, blmc, ghat, sigma, ikey       O     , dkm1, blmc, ghat, sigma, ikppkey
208       &     )       I     , myThid )
209  cph(  cph(
210  CADJ STORE dkm1,blmc,ghat = comlev1_kpp, key = ikey  CADJ STORE dkm1,blmc,ghat = comlev1_kpp,
211  CADJ STORE hbl, kbl, diffus, casea = comlev1_kpp, key = ikey  CADJ &     key=ikppkey, kind=isbyte
212    CADJ STORE hbl, kbl, diffus, casea = comlev1_kpp,
213    CADJ &     key=ikppkey, kind=isbyte
214  cph)  cph)
215    
216  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
# Line 193  c--------------------------------------- Line 220  c---------------------------------------
220        call enhance (        call enhance (
221       I       dkm1, hbl, kbl, diffus, casea       I       dkm1, hbl, kbl, diffus, casea
222       U     , ghat       U     , ghat
223       O     , blmc )       O     , blmc
224         I     , myThid )
225    
226  cph(  cph(
227  cph avoids recomp. of enhance  cph avoids recomp. of enhance
228  CADJ STORE blmc = comlev1_kpp, key = ikey  CADJ STORE blmc = comlev1_kpp, key=ikppkey, kind=isbyte
229  cph)  cph)
230    
231  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
232  c combine interior and boundary layer coefficients and nonlocal term  c combine interior and boundary layer coefficients and nonlocal term
233  c !!!NOTE!!! In shallow (2-level) regions and for shallow mixed layers  c !!!NOTE!!! In shallow (2-level) regions and for shallow mixed layers
234  c (< 1 level), diffusivity blmc can become negative.  The max's below  c (< 1 level), diffusivity blmc can become negative.  The max-s below
235  c are a hack until this problem is properly diagnosed and fixed.  c are a hack until this problem is properly diagnosed and fixed.
236  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
237        do k = 1, Nr        do k = 1, Nr
238           do i = 1, imt           do i = 1, imt
239              if (k .lt. kbl(i)) then              if (k .lt. kbl(i)) then
240                 diffus(i,k,1) = max ( blmc(i,k,1), viscAr  )  #ifdef ALLOW_SHELFICE
241                 diffus(i,k,2) = max ( blmc(i,k,2), diffKrS )  C     when there is shelfice on top (msk(i)=0), reset the boundary layer
242                 diffus(i,k,3) = max ( blmc(i,k,3), diffKrT )  C     mixing coefficients blmc to pure Ri-number based mixing
243                   blmc(i,k,1) = max ( blmc(i,k,1)*msk(i),
244         &              diffus(i,k,1) )
245                   blmc(i,k,2) = max ( blmc(i,k,2)*msk(i),
246         &              diffus(i,k,2) )
247                   blmc(i,k,3) = max ( blmc(i,k,3)*msk(i),
248         &              diffus(i,k,3) )
249    #endif /* not ALLOW_SHELFICE */
250                   diffus(i,k,1) = max ( blmc(i,k,1), viscArNr(1) )
251                   diffus(i,k,2) = max ( blmc(i,k,2), diffusKzS(i,Nr) )
252                   diffus(i,k,3) = max ( blmc(i,k,3), diffusKzT(i,Nr) )
253              else              else
254                 ghat(i,k) = 0.                 ghat(i,k) = 0. _d 0
255              endif              endif
256           end do           end do
257        end do        end do
258    
259  #endif /* ALLOW_KPP */  #endif /* ALLOW_KPP */
260    
261        return        return
262        end        end
263    
264  c*************************************************************************  c*************************************************************************
265    
266        subroutine bldepth (        subroutine bldepth (
267       I       mytime, mythid       I       kmtj
268       I     , kmtj       I     , dvsq, dbloc, Ritop, ustar, bo, bosol
269       I     , dvsq, dbloc, Ritop, ustar, bo, bosol, coriol  #ifdef ALLOW_SALT_PLUME
270       I     , ikey       I     , boplume,SPDepth
271    #endif /* ALLOW_SALT_PLUME */
272         I     , coriol
273         I     , ikppkey
274       O     , hbl, bfsfc, stable, casea, kbl, Rib, sigma       O     , hbl, bfsfc, stable, casea, kbl, Rib, sigma
275       &     )       I     , myTime, myIter, myThid )
276    
277  c     the oceanic planetary boundary layer depth, hbl, is determined as  c     the oceanic planetary boundary layer depth, hbl, is determined as
278  c     the shallowest depth where the bulk Richardson number is  c     the shallowest depth where the bulk Richardson number is
# Line 253  c     The water column and the surface f Line 294  c     The water column and the surface f
294  c     stable/ustable forcing conditions, and where hbl is relative  c     stable/ustable forcing conditions, and where hbl is relative
295  c     to grid points (caseA), so that conditional branches can be  c     to grid points (caseA), so that conditional branches can be
296  c     avoided in later subroutines.  c     avoided in later subroutines.
297  c  c
298        IMPLICIT NONE        IMPLICIT NONE
299    
300  #include "SIZE.h"  #include "SIZE.h"
301  #include "EEPARAMS.h"  #include "EEPARAMS.h"
302  #include "PARAMS.h"  #include "PARAMS.h"
303  #include "KPP_PARAMS.h"  #include "KPP_PARAMS.h"
304  #include "FFIELDS.h"  #ifdef ALLOW_AUTODIFF
305    # include "tamc.h"
306    #endif
307    
308  c input  c input
309  c------  c------
310  c myTime    : current time in simulation  c   myTime :: Current time in simulation
311  c myThid    : thread number for this instance of the routine  c   myIter :: Current iteration number in simulation
312    c   myThid :: My Thread Id. number
313  c kmtj      : number of vertical layers  c kmtj      : number of vertical layers
314  c dvsq      : (velocity shear re sfc)^2             ((m/s)^2)  c dvsq      : (velocity shear re sfc)^2             ((m/s)^2)
315  c dbloc     : local delta buoyancy across interfaces  (m/s^2)  c dbloc     : local delta buoyancy across interfaces  (m/s^2)
# Line 275  c             buoyancy with respect to s Line 319  c             buoyancy with respect to s
319  c ustar     : surface friction velocity                 (m/s)  c ustar     : surface friction velocity                 (m/s)
320  c bo        : surface turbulent buoyancy forcing    (m^2/s^3)  c bo        : surface turbulent buoyancy forcing    (m^2/s^3)
321  c bosol     : radiative buoyancy forcing            (m^2/s^3)  c bosol     : radiative buoyancy forcing            (m^2/s^3)
322    c boplume   : haline buoyancy forcing               (m^2/s^3)
323  c coriol    : Coriolis parameter                        (1/s)  c coriol    : Coriolis parameter                        (1/s)
324        _RL     mytime        _RL     myTime
325        integer mythid        integer myIter
326          integer myThid
327        integer kmtj(imt)        integer kmtj(imt)
328        _KPP_RL dvsq  (imt,Nr)        _RL dvsq    (imt,Nr)
329        _KPP_RL dbloc (imt,Nr)        _RL dbloc   (imt,Nr)
330        _KPP_RL Ritop (imt,Nr)        _RL Ritop   (imt,Nr)
331        _KPP_RL ustar (imt)        _RL ustar   (imt)
332        _KPP_RL bo    (imt)        _RL bo      (imt)
333        _KPP_RL bosol (imt)        _RL bosol   (imt)
334        _KPP_RL coriol(imt)        _RL coriol  (imt)
335        integer ikey        integer ikppkey, kkppkey
336    #ifdef ALLOW_SALT_PLUME
337          _RL boplume (imt)
338          _RL SPDepth (imt)
339    #endif /* ALLOW_SALT_PLUME */
340    
341  c  output  c  output
342  c--------  c--------
# Line 297  c casea     : =1 in case A, =0 in case B Line 347  c casea     : =1 in case A, =0 in case B
347  c kbl       : -1 of first grid level below hbl  c kbl       : -1 of first grid level below hbl
348  c Rib       : Bulk Richardson number  c Rib       : Bulk Richardson number
349  c sigma     : normalized depth (d/hbl)  c sigma     : normalized depth (d/hbl)
350        _KPP_RL hbl   (imt)        _RL hbl    (imt)
351        _KPP_RL bfsfc (imt)        _RL bfsfc  (imt)
352        _KPP_RL stable(imt)        _RL stable (imt)
353        _KPP_RL casea (imt)        _RL casea  (imt)
354        integer kbl   (imt)        integer kbl(imt)
355        _KPP_RL Rib   (imt,Nr)        _RL Rib    (imt,Nr)
356        _KPP_RL sigma (imt)        _RL sigma  (imt)
357    
358  #ifdef ALLOW_KPP  #ifdef ALLOW_KPP
359    
360  c  local  c  local
361  c-------  c-------
362  c wm, ws    : turbulent velocity scales         (m/s)  c wm, ws    : turbulent velocity scales         (m/s)
363        _KPP_RL wm(imt), ws(imt)        _RL wm(imt), ws(imt)
364        _RL     worka(imt)        _RL worka(imt)
365          _RL bvsq, vtsq, hekman, hmonob, hlimit, tempVar1, tempVar2
       _KPP_RL bvsq, vtsq, hekman, hmonob, hlimit, tempVar1, tempVar2  
366        integer i, kl        integer i, kl
367    
368        _KPP_RL     p5    , eins        _RL         p5    , eins
369        parameter ( p5=0.5, eins=1.0 )        parameter ( p5=0.5, eins=1.0 )
370        _RL         minusone        _RL         minusone
371        parameter ( minusone=-1.0 )        parameter ( minusone=-1.0 )
372    
373    #ifdef ALLOW_DIAGNOSTICS
374    c     KPPBFSFC - Bo+radiation absorbed to d=hbf*hbl + plume (m^2/s^3)
375          _RL KPPBFSFC(imt,Nr)
376          _RL KPPRi(imt,Nr)
377    #endif /* ALLOW_DIAGNOSTICS */
378    
379  c find bulk Richardson number at every grid level until > Ricr  c find bulk Richardson number at every grid level until > Ricr
380  c  c
381  c note: the reference depth is -epsilon/2.*zgrid(k), but the reference  c note: the reference depth is -epsilon/2.*zgrid(k), but the reference
# Line 333  c       kbl(i)=kmtj(i) and hbl(i)=-zgrid Line 388  c       kbl(i)=kmtj(i) and hbl(i)=-zgrid
388  c     initialize hbl and kbl to bottomed out values  c     initialize hbl and kbl to bottomed out values
389    
390        do i = 1, imt        do i = 1, imt
391           Rib(i,1) = 0.0           Rib(i,1) = 0. _d 0
392           kbl(i) = max(kmtj(i),1)           kbl(i) = max(kmtj(i),1)
393           hbl(i) = -zgrid(kbl(i))           hbl(i) = -zgrid(kbl(i))
394        end do        end do
395    
396    #ifdef ALLOW_DIAGNOSTICS
397          do kl = 1, Nr
398             do i = 1, imt
399                KPPBFSFC(i,kl) = 0. _d 0
400                KPPRi(i,kl) = 0. _d 0
401             enddo
402          enddo
403    #endif /* ALLOW_DIAGNOSTICS */
404    
405        do kl = 2, Nr        do kl = 2, Nr
406    
407    #ifdef ALLOW_AUTODIFF_TAMC
408             kkppkey = (ikppkey-1)*Nr + kl
409    #endif
410    
411  c     compute bfsfc = sw fraction at hbf * zgrid  c     compute bfsfc = sw fraction at hbf * zgrid
412    
413           do i = 1, imt           do i = 1, imt
414              worka(i) = zgrid(kl)              worka(i) = zgrid(kl)
415           end do           end do
416    CADJ store worka = comlev1_kpp_k, key = kkppkey, kind=isbyte
417           call SWFRAC(           call SWFRAC(
418       I        imt, hbf,       I       imt, hbf,
419       I        mytime, mythid,       U       worka,
420       U        worka )       I       myTime, myIter, myThid )
421    CADJ store worka = comlev1_kpp_k, key = kkppkey, kind=isbyte
422    
423           do i = 1, imt           do i = 1, imt
424    
# Line 359  c     use caseA as temporary array Line 429  c     use caseA as temporary array
429  c     compute bfsfc= Bo + radiative contribution down to hbf * hbl  c     compute bfsfc= Bo + radiative contribution down to hbf * hbl
430    
431              bfsfc(i) = bo(i) + bosol(i)*(1. - worka(i))              bfsfc(i) = bo(i) + bosol(i)*(1. - worka(i))
             stable(i) = p5 + sign(p5,bfsfc(i))  
             sigma(i) = stable(i) + (1. - stable(i)) * epsilon  
432    
433           end do           end do
434    #ifdef ALLOW_SALT_PLUME
435    c     compute bfsfc = plume fraction at hbf * zgrid
436             IF ( useSALT_PLUME ) THEN
437               do i = 1, imt
438                  worka(i) = zgrid(kl)
439               enddo
440               call SALT_PLUME_FRAC(
441         I         imt, hbf,SPDepth,
442         U         worka,
443         I         myTime, myIter, myThid)
444               do i = 1, imt
445                  bfsfc(i) = bfsfc(i) + boplume(i)*(1. - worka(i))
446               enddo
447             ENDIF
448    #endif /* ALLOW_SALT_PLUME */
449    
450    #ifdef ALLOW_DIAGNOSTICS
451             do i = 1, imt
452                KPPBFSFC(i,kl) = bfsfc(i)
453             enddo
454    #endif /* ALLOW_DIAGNOSTICS */
455    
456             do i = 1, imt
457                stable(i) = p5 + sign(p5,bfsfc(i))
458                sigma(i) = stable(i) + (1. - stable(i)) * epsilon
459             enddo
460    
461  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
462  c     compute velocity scales at sigma, for hbl= caseA = -zgrid(kl)  c     compute velocity scales at sigma, for hbl= caseA = -zgrid(kl)
463  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
464    
465           call wscale (           call wscale (
466       I        sigma, casea, ustar, bfsfc,       I        sigma, casea, ustar, bfsfc,
467       O        wm, ws )       O        wm, ws, myThid )
468    CADJ store ws = comlev1_kpp_k, key = kkppkey, kind=isbyte
469    
470           do i = 1, imt           do i = 1, imt
471    
# Line 382  c--------------------------------------- Line 477  c---------------------------------------
477       1           ( dbloc(i,kl-1) / (zgrid(kl-1)-zgrid(kl  ))+       1           ( dbloc(i,kl-1) / (zgrid(kl-1)-zgrid(kl  ))+
478       2             dbloc(i,kl  ) / (zgrid(kl  )-zgrid(kl+1)))       2             dbloc(i,kl  ) / (zgrid(kl  )-zgrid(kl+1)))
479    
480              if (bvsq .eq. 0.) then              if (bvsq .eq. 0. _d 0) then
481                vtsq = 0.0                vtsq = 0. _d 0
482              else              else
483                vtsq = -zgrid(kl) * ws(i) * sqrt(abs(bvsq)) * Vtc                vtsq = -zgrid(kl) * ws(i) * sqrt(abs(bvsq)) * Vtc
484              endif              endif
# Line 400  c     rg: assignment to double precision Line 495  c     rg: assignment to double precision
495  c     ph: test for zero nominator  c     ph: test for zero nominator
496  c  c
497    
498              tempVar1  = dvsq(i,kl) + vtsq                        tempVar1  = dvsq(i,kl) + vtsq
499              tempVar2 = max(tempVar1, phepsi)              tempVar2 = max(tempVar1, phepsi)
500              Rib(i,kl) = Ritop(i,kl) / tempVar2              Rib(i,kl) = Ritop(i,kl) / tempVar2
501    #ifdef ALLOW_DIAGNOSTICS
502                KPPRi(i,kl) = Rib(i,kl)
503    #endif
504    
505           end do           end do
506        end do        end do
507    
508    #ifdef ALLOW_DIAGNOSTICS
509             CALL DIAGNOSTICS_FILL(KPPBFSFC,'KPPbfsfc',0,Nr,0,1,1,myThid)
510             CALL DIAGNOSTICS_FILL(KPPRi   ,'KPPRi   ',0,Nr,0,1,1,myThid)
511    #endif /* ALLOW_DIAGNOSTICS */
512    
513  cph(  cph(
514  cph  without this store, there's a recomputation error for  cph  without this store, there is a recomputation error for
515  cph  rib in adbldepth (probably partial recomputation problem)      cph  rib in adbldepth (probably partial recomputation problem)
516  CADJ store Rib = comlev1_kpp  CADJ store Rib = comlev1_kpp
517  CADJ &   , key = ikey, shape = (/ (sNx+2*OLx)*(sNy+2*OLy),Nr /)  CADJ &   , key=ikppkey, kind=isbyte,
518    CADJ &     shape = (/ (sNx+2*OLx)*(sNy+2*OLy),Nr /)
519  cph)  cph)
520    
521        do kl = 2, Nr        do kl = 2, Nr
# Line 421  cph) Line 525  cph)
525        end do        end do
526    
527  CADJ store kbl = comlev1_kpp  CADJ store kbl = comlev1_kpp
528  CADJ &   , key = ikey, shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)  CADJ &   , key=ikppkey, kind=isbyte,
529    CADJ &     shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
530    
531        do i = 1, imt        do i = 1, imt
532           kl = kbl(i)           kl = kbl(i)
# Line 434  c     linearly interpolate to find hbl w Line 539  c     linearly interpolate to find hbl w
539        end do        end do
540    
541  CADJ store hbl = comlev1_kpp  CADJ store hbl = comlev1_kpp
542  CADJ &   , key = ikey, shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)  CADJ &   , key=ikppkey, kind=isbyte,
543    CADJ &     shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
544    
545  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
546  c     find stability and buoyancy forcing for boundary layer  c     find stability and buoyancy forcing for boundary layer
# Line 443  c--------------------------------------- Line 549  c---------------------------------------
549        do i = 1, imt        do i = 1, imt
550           worka(i) = hbl(i)           worka(i) = hbl(i)
551        end do        end do
552    CADJ store worka = comlev1_kpp
553    CADJ &   , key=ikppkey, kind=isbyte,
554    CADJ &     shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
555        call SWFRAC(        call SWFRAC(
556       I     imt, minusone,       I       imt, minusone,
557       I     mytime, mythid,       U       worka,
558       U     worka )       I       myTime, myIter, myThid )
559    CADJ store worka = comlev1_kpp
560    CADJ &   , key=ikppkey, kind=isbyte,
561    CADJ &     shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
562    
563        do i = 1, imt        do i = 1, imt
564           bfsfc(i)  = bo(i) + bosol(i) * (1. - worka(i))           bfsfc(i)  = bo(i) + bosol(i) * (1. - worka(i))
565        end do        end do
566    
567    #ifdef ALLOW_SALT_PLUME
568          IF ( useSALT_PLUME ) THEN
569            do i = 1, imt
570               worka(i) = hbl(i)
571            enddo
572            call SALT_PLUME_FRAC(
573         I         imt,minusone,SPDepth,
574         U         worka,
575         I         myTime, myIter, myThid )
576            do i = 1, imt
577               bfsfc(i) = bfsfc(i) + boplume(i) * (1. - worka(i))
578            enddo
579          ENDIF
580    #endif /* ALLOW_SALT_PLUME */
581  CADJ store bfsfc = comlev1_kpp  CADJ store bfsfc = comlev1_kpp
582  CADJ &   , key = ikey, shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)  CADJ &   , key=ikppkey, kind=isbyte,
583    CADJ &     shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
584    
585  c--   ensure bfsfc is never 0  c--   ensure bfsfc is never 0
586        do i = 1, imt        do i = 1, imt
# Line 463  c--   ensure bfsfc is never 0 Line 591  c--   ensure bfsfc is never 0
591  cph(  cph(
592  cph  added stable to store list to avoid extensive recomp.  cph  added stable to store list to avoid extensive recomp.
593  CADJ store bfsfc, stable = comlev1_kpp  CADJ store bfsfc, stable = comlev1_kpp
594  CADJ &   , key = ikey, shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)  CADJ &   , key=ikppkey, kind=isbyte,
595    CADJ &     shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
596  cph)  cph)
597    
598  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
# Line 471  c check hbl limits for hekman or hmonob Line 600  c check hbl limits for hekman or hmonob
600  c     ph: test for zero nominator  c     ph: test for zero nominator
601  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
602    
603          IF ( LimitHblStable ) THEN
604        do i = 1, imt        do i = 1, imt
605           if (bfsfc(i) .gt. 0.0) then           if (bfsfc(i) .gt. 0.0) then
606              hekman = cekman * ustar(i) / max(abs(Coriol(i)),phepsi)              hekman = cekman * ustar(i) / max(abs(Coriol(i)),phepsi)
# Line 481  c--------------------------------------- Line 611  c---------------------------------------
611              hbl(i) = min(hbl(i),hlimit)              hbl(i) = min(hbl(i),hlimit)
612           end if           end if
613        end do        end do
614          ENDIF
615    
616  CADJ store hbl = comlev1_kpp  CADJ store hbl = comlev1_kpp
617  CADJ &   , key = ikey, shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)  CADJ &   , key=ikppkey, kind=isbyte,
618    CADJ &     shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
619    
620        do i = 1, imt        do i = 1, imt
621           hbl(i) = max(hbl(i),minKPPhbl)           hbl(i) = max(hbl(i),minKPPhbl)
# Line 490  CADJ &   , key = ikey, shape = (/ (sNx+2 Line 623  CADJ &   , key = ikey, shape = (/ (sNx+2
623        end do        end do
624    
625  CADJ store hbl = comlev1_kpp  CADJ store hbl = comlev1_kpp
626  CADJ &   , key = ikey, shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)  CADJ &   , key=ikppkey, kind=isbyte,
627    CADJ &     shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
628    
629  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
630  c      find new kbl  c      find new kbl
# Line 511  c--------------------------------------- Line 645  c---------------------------------------
645        do i = 1, imt        do i = 1, imt
646           worka(i) = hbl(i)           worka(i) = hbl(i)
647        end do        end do
648    CADJ store worka = comlev1_kpp
649    CADJ &   , key=ikppkey, kind=isbyte,
650    CADJ &     shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
651        call SWFRAC(        call SWFRAC(
652       I     imt, minusone,       I     imt, minusone,
653       I     mytime, mythid,       U     worka,
654       U     worka )       I     myTime, myIter, myThid )
655    CADJ store worka = comlev1_kpp
656    CADJ &   , key=ikppkey, kind=isbyte,
657    CADJ &     shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
658    
659        do i = 1, imt        do i = 1, imt
660           bfsfc(i) = bo(i) + bosol(i) * (1. - worka(i))           bfsfc(i) = bo(i) + bosol(i) * (1. - worka(i))
661        end do        end do
662    
663    #ifdef ALLOW_SALT_PLUME
664          IF ( useSALT_PLUME ) THEN
665            do i = 1, imt
666               worka(i) = hbl(i)
667            enddo
668            call SALT_PLUME_FRAC(
669         I         imt,minusone,SPDepth,
670         U         worka,
671         I         myTime, myIter, myThid )
672            do i = 1, imt
673               bfsfc(i) = bfsfc(i) + boplume(i) * (1. - worka(i))
674            enddo
675          ENDIF
676    #endif /* ALLOW_SALT_PLUME */
677  CADJ store bfsfc = comlev1_kpp  CADJ store bfsfc = comlev1_kpp
678  CADJ &   , key = ikey, shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)  CADJ &   , key=ikppkey, kind=isbyte,
679    CADJ &     shape = (/ (sNx+2*OLx)*(sNy+2*OLy) /)
680    
681  c--   ensures bfsfc is never 0  c--   ensures bfsfc is never 0
682        do i = 1, imt        do i = 1, imt
# Line 546  c*************************************** Line 702  c***************************************
702    
703        subroutine wscale (        subroutine wscale (
704       I     sigma, hbl, ustar, bfsfc,       I     sigma, hbl, ustar, bfsfc,
705       O     wm, ws )       O     wm, ws,
706         I     myThid )
707    
708  c     compute turbulent velocity scales.  c     compute turbulent velocity scales.
709  c     use a 2D-lookup table for wm and ws as functions of ustar and  c     use a 2D-lookup table for wm and ws as functions of ustar and
# Line 555  c Line 712  c
712  c     note: the lookup table is only used for unstable conditions  c     note: the lookup table is only used for unstable conditions
713  c     (zehat.le.0), in the stable domain wm (=ws) gets computed  c     (zehat.le.0), in the stable domain wm (=ws) gets computed
714  c     directly.  c     directly.
715  c  c
716        IMPLICIT NONE        IMPLICIT NONE
717    
718  #include "SIZE.h"  #include "SIZE.h"
# Line 567  c sigma   : normalized depth (d/hbl) Line 724  c sigma   : normalized depth (d/hbl)
724  c hbl     : boundary layer depth (m)  c hbl     : boundary layer depth (m)
725  c ustar   : surface friction velocity         (m/s)  c ustar   : surface friction velocity         (m/s)
726  c bfsfc   : total surface buoyancy flux       (m^2/s^3)  c bfsfc   : total surface buoyancy flux       (m^2/s^3)
727        _KPP_RL sigma(imt)  c myThid  : thread number for this instance of the routine
728        _KPP_RL hbl  (imt)        integer myThid
729        _KPP_RL ustar(imt)        _RL sigma(imt)
730        _KPP_RL bfsfc(imt)        _RL hbl  (imt)
731          _RL ustar(imt)
732          _RL bfsfc(imt)
733    
734  c  output  c  output
735  c--------  c--------
736  c wm, ws  : turbulent velocity scales at sigma  c wm, ws  : turbulent velocity scales at sigma
737        _KPP_RL wm(imt), ws(imt)        _RL wm(imt), ws(imt)
738    
739  #ifdef ALLOW_KPP  #ifdef ALLOW_KPP
740    
741  c local  c local
742  c------  c------
743  c zehat   : = zeta *  ustar**3  c zehat   : = zeta *  ustar**3
744        _KPP_RL zehat        _RL zehat
745    
746        integer iz, izp1, ju, i, jup1        integer iz, izp1, ju, i, jup1
747        _KPP_RL udiff, zdiff, zfrac, ufrac, fzfrac, wam        _RL udiff, zdiff, zfrac, ufrac, fzfrac, wam
748        _KPP_RL wbm, was, wbs, u3, tempVar        _RL wbm, was, wbs, u3, tempVar
749    
750  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
751  c use lookup table for zehat < zmax only; otherwise use  c use lookup table for zehat < zmax only; otherwise use
# Line 630  c--------------------------------------- Line 789  c---------------------------------------
789              ws(i) = wm(i)              ws(i) = wm(i)
790    
791           endif           endif
792    
793        end do        end do
794    
795  #endif /* ALLOW_KPP */  #endif /* ALLOW_KPP */
796    
797        return        return
798        end        end
799    
800  c*************************************************************************  c*************************************************************************
801    
802        subroutine Ri_iwmix (        subroutine Ri_iwmix (
803       I       kmtj, shsq, dbloc, dblocSm       I       kmtj, shsq, dbloc, dblocSm,
804       I     , ikey       I       diffusKzS, diffusKzT,
805       O     , diffus )       I       ikppkey,
806         O       diffus,
807         I       myThid )
808    
809  c     compute interior viscosity diffusivity coefficients due  c     compute interior viscosity diffusivity coefficients due
810  c     to shear instability (dependent on a local Richardson number),  c     to shear instability (dependent on a local Richardson number),
# Line 656  c     to static instability (local Richa Line 817  c     to static instability (local Richa
817  #include "EEPARAMS.h"  #include "EEPARAMS.h"
818  #include "PARAMS.h"  #include "PARAMS.h"
819  #include "KPP_PARAMS.h"  #include "KPP_PARAMS.h"
820    #ifdef ALLOW_AUTODIFF
821    # include "tamc.h"
822    #endif
823    
824  c  input  c  input
825  c     kmtj   (imt)         number of vertical layers on this row  c     kmtj   (imt)         number of vertical layers on this row
826  c     shsq   (imt,Nr)      (local velocity shear)^2               ((m/s)^2)  c     shsq   (imt,Nr)      (local velocity shear)^2               ((m/s)^2)
827  c     dbloc  (imt,Nr)      local delta buoyancy                     (m/s^2)  c     dbloc  (imt,Nr)      local delta buoyancy                     (m/s^2)
828  c     dblocSm(imt,Nr)      horizontally smoothed dbloc              (m/s^2)  c     dblocSm(imt,Nr)      horizontally smoothed dbloc              (m/s^2)
829        integer kmtj   (imt)  c     diffusKzS(imt,Nr)- background vertical diffusivity for scalars    (m^2/s)
830        _KPP_RL shsq   (imt,Nr)  c     diffusKzT(imt,Nr)- background vertical diffusivity for theta      (m^2/s)
831        _KPP_RL dbloc  (imt,Nr)  c     myThid :: My Thread Id. number
832        _KPP_RL dblocSm(imt,Nr)        integer kmtj (imt)
833        integer ikey        _RL shsq     (imt,Nr)
834          _RL dbloc    (imt,Nr)
835          _RL dblocSm  (imt,Nr)
836          _RL diffusKzS(imt,Nr)
837          _RL diffusKzT(imt,Nr)
838          integer ikppkey
839          integer myThid
840    
841  c output  c output
842  c     diffus(imt,0:Nrp1,1)  vertical viscosivity coefficient        (m^2/s)  c     diffus(imt,0:Nrp1,1)  vertical viscosivity coefficient        (m^2/s)
843  c     diffus(imt,0:Nrp1,2)  vertical scalar diffusivity             (m^2/s)  c     diffus(imt,0:Nrp1,2)  vertical scalar diffusivity             (m^2/s)
844  c     diffus(imt,0:Nrp1,3)  vertical temperature diffusivity        (m^2/s)  c     diffus(imt,0:Nrp1,3)  vertical temperature diffusivity        (m^2/s)
845        _KPP_RL diffus(imt,0:Nrp1,3)        _RL diffus(imt,0:Nrp1,3)
846    
847  #ifdef ALLOW_KPP  #ifdef ALLOW_KPP
848    
849  c local variables  c local variables
850  c     Rig                   local Richardson number  c     Rig                   local Richardson number
851  c     fRi, fcon             function of Rig  c     fRi, fcon             function of Rig
852        _KPP_RL Rig        _RL Rig
853        _KPP_RL fRi, fcon        _RL fRi, fcon
854        _KPP_RL ratio        _RL ratio
855        integer i, ki        integer i, ki, kp1
856        _KPP_RL c1, c0        _RL c1, c0
857    
858  #ifdef ALLOW_KPP_VERTICALLY_SMOOTH  #ifdef ALLOW_KPP_VERTICALLY_SMOOTH
859        integer mr        integer mr
# Line 691  CADJ INIT kpp_ri_tape_mr = common, 1 Line 861  CADJ INIT kpp_ri_tape_mr = common, 1
861  #endif  #endif
862    
863  c constants  c constants
864        c1 = 1.0        c1 = 1. _d 0
865        c0 = 0.0        c0 = 0. _d 0
866    
867  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
868  c     compute interior gradient Ri at all interfaces ki=1,Nr, (not surface)  c     compute interior gradient Ri at all interfaces ki=1,Nr, (not surface)
# Line 702  c     set values at bottom and below to Line 872  c     set values at bottom and below to
872  #ifdef ALLOW_AUTODIFF_TAMC  #ifdef ALLOW_AUTODIFF_TAMC
873  C     break data flow dependence on diffus  C     break data flow dependence on diffus
874        diffus(1,1,1) = 0.0        diffus(1,1,1) = 0.0
875    
876          do ki = 1, Nr
877             do i = 1, imt
878                diffus(i,ki,1) = 0.
879                diffus(i,ki,2) = 0.
880                diffus(i,ki,3) = 0.
881             enddo
882          enddo
883  #endif  #endif
884    
885    
886        do ki = 1, Nr        do ki = 1, Nr
887           do i = 1, imt           do i = 1, imt
888              if     (kmtj(i) .LE. 1      ) then              if     (kmtj(i) .LE. 1      ) then
# Line 719  C     break data flow dependence on diff Line 898  C     break data flow dependence on diff
898              endif              endif
899           end do           end do
900        end do        end do
901    CADJ store diffus = comlev1_kpp, key=ikppkey, kind=isbyte
902    
903  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
904  c     vertically smooth Ri  c     vertically smooth Ri
# Line 729  CADJ store diffus(:,:,1) = kpp_ri_tape_m Line 909  CADJ store diffus(:,:,1) = kpp_ri_tape_m
909  CADJ &  , key=mr, shape=(/ (sNx+2*OLx)*(sNy+2*OLy),Nr+2 /)  CADJ &  , key=mr, shape=(/ (sNx+2*OLx)*(sNy+2*OLy),Nr+2 /)
910    
911           call z121 (           call z121 (
912       U     diffus(1,0,1))       U     diffus(1,0,1),
913         I     myThid )
914        end do        end do
915  #endif  #endif
916    
# Line 738  c                           after smooth Line 919  c                           after smooth
919    
920        do ki = 1, Nr        do ki = 1, Nr
921           do i = 1, imt           do i = 1, imt
922    
923  c  evaluate f of Brunt-Vaisala squared for convection, store in fcon  c  evaluate f of Brunt-Vaisala squared for convection, store in fcon
924    
925              Rig   = max ( diffus(i,ki,2) , BVSQcon )              Rig   = max ( diffus(i,ki,2) , BVSQcon )
926              ratio = min ( (BVSQcon - Rig) / BVSQcon, c1 )              ratio = min ( (BVSQcon - Rig) / BVSQcon, c1 )
927              fcon  = c1 - ratio * ratio              fcon  = c1 - ratio * ratio
928              fcon  = fcon * fcon * fcon              fcon  = fcon * fcon * fcon
929    
930  c  evaluate f of smooth Ri for shear instability, store in fRi  c  evaluate f of smooth Ri for shear instability, store in fRi
931    
932              Rig  = max ( diffus(i,ki,1), c0 )              Rig  = max ( diffus(i,ki,1), c0 )
933              ratio = min ( Rig / Riinfty , c1 )              ratio = min ( Rig / Riinfty , c1 )
934              fRi   = c1 - ratio * ratio              fRi   = c1 - ratio * ratio
935              fRi   = fRi * fRi * fRi              fRi   = fRi * fRi * fRi
936    
937  c ----------------------------------------------------------------------  c ----------------------------------------------------------------------
938  c            evaluate diffusivities and viscosity  c            evaluate diffusivities and viscosity
939  c    mixing due to internal waves, and shear and static instability  c    mixing due to internal waves, and shear and static instability
940    
941              diffus(i,ki,1) = viscAr + fcon * difmcon + fRi * difm0              kp1 = MIN(ki+1,Nr)
942              diffus(i,ki,2) = diffKrS + fcon * difscon + fRi * difs0  #ifndef EXCLUDE_KPP_SHEAR_MIX
943              diffus(i,ki,3) = diffKrT + fcon * difscon + fRi * difs0              if ( .NOT. inAdMode ) then
944                   diffus(i,ki,1) = viscArNr(1) + fcon*difmcon + fRi*difm0
945                   diffus(i,ki,2) = diffusKzS(i,kp1)+fcon*difscon+fRi*difs0
946                   diffus(i,ki,3) = diffusKzT(i,kp1)+fcon*diftcon+fRi*dift0
947                else
948                   diffus(i,ki,1) = viscArnr(1)
949                   diffus(i,ki,2) = diffusKzS(i,kp1)
950                   diffus(i,ki,3) = diffusKzT(i,kp1)
951                endif
952    #else
953                diffus(i,ki,1) = viscArNr(1)
954                diffus(i,ki,2) = diffusKzS(i,kp1)
955                diffus(i,ki,3) = diffusKzT(i,kp1)
956    #endif
957    
958           end do           end do
959        end do        end do
960    
961  c ------------------------------------------------------------------------  c ------------------------------------------------------------------------
962  c         set surface values to 0.0  c         set surface values to 0.0
963    
964        do i = 1, imt        do i = 1, imt
965           diffus(i,0,1) = c0           diffus(i,0,1) = c0
966           diffus(i,0,2) = c0           diffus(i,0,2) = c0
# Line 774  c         set surface values to 0.0 Line 968  c         set surface values to 0.0
968        end do        end do
969    
970  #endif /* ALLOW_KPP */  #endif /* ALLOW_KPP */
971    
972        return        return
973        end        end
974    
975  c*************************************************************************  c*************************************************************************
976    
977        subroutine z121 (        subroutine z121 (
978       U     v )       U     v,
979         I     myThid )
980    
981  c     Apply 121 smoothing in k to 2-d array V(i,k=1,Nr)  c     Apply 121 smoothing in k to 2-d array V(i,k=1,Nr)
982  c     top (0) value is used as a dummy  c     top (0) value is used as a dummy
# Line 796  c     penetrative convection. Line 991  c     penetrative convection.
991  #include "SIZE.h"  #include "SIZE.h"
992  #include "KPP_PARAMS.h"  #include "KPP_PARAMS.h"
993    
994  c input/output  c input/output
995  c-------------  c-------------
996  c v     : 2-D array to be smoothed in Nrp1 direction  c v     : 2-D array to be smoothed in Nrp1 direction
997        _KPP_RL v(imt,0:Nrp1)  c myThid: thread number for this instance of the routine
998          integer myThid
999          _RL v(imt,0:Nrp1)
1000    
1001  #ifdef ALLOW_KPP  #ifdef ALLOW_KPP
1002    
1003  c local  c local
1004        _KPP_RL zwork, zflag        _RL zwork, zflag
1005        _KPP_RL KRi_range(1:Nrp1)        _RL KRi_range(1:Nrp1)
1006        integer i, k, km1, kp1        integer i, k, km1, kp1
1007    
1008        _KPP_RL     p0      , p25       , p5      , p2        _RL         p0      , p25       , p5      , p2
1009        parameter ( p0 = 0.0, p25 = 0.25, p5 = 0.5, p2 = 2.0 )        parameter ( p0 = 0.0, p25 = 0.25, p5 = 0.5, p2 = 2.0 )
1010    
1011        KRi_range(Nrp1) = p0        KRi_range(Nrp1) = p0
# Line 862  CADJ STORE v(i,k), zwork = z121tape Line 1059  CADJ STORE v(i,k), zwork = z121tape
1059    
1060  c*************************************************************************  c*************************************************************************
1061    
       subroutine kpp_smooth_horiz (  
      I     k, bi, bj,  
      U     fld )  
   
 c     Apply horizontal smoothing to KPP array  
   
       IMPLICIT NONE  
 #include "SIZE.h"  
 #include "KPP_PARAMS.h"  
   
 c     input  
 c     bi, bj : array indices  
 c     k      : vertical index used for masking  
       integer k, bi, bj  
   
 c     input/output  
 c     fld    : 2-D array to be smoothed  
       _KPP_RL fld( ibot:itop, jbot:jtop )  
   
 #ifdef ALLOW_KPP  
   
 c     local  
       integer i, j, im1, ip1, jm1, jp1  
       _KPP_RL tempVar  
       _KPP_RL fld_tmp( ibot:itop, jbot:jtop )  
   
       integer    imin       , imax       , jmin       , jmax  
       parameter( imin=ibot+1, imax=itop-1, jmin=jbot+1, jmax=jtop-1 )  
   
       _KPP_RL    p0    , p5    , p25     , p125      , p0625  
       parameter( p0=0.0, p5=0.5, p25=0.25, p125=0.125, p0625=0.0625 )  
   
       DO j = jmin, jmax  
          jm1 = j-1  
          jp1 = j+1  
          DO i = imin, imax  
             im1 = i-1  
             ip1 = i+1  
             tempVar =  
      &           p25   *   pMask(i  ,j  ,k,bi,bj)   +  
      &           p125  * ( pMask(im1,j  ,k,bi,bj)   +  
      &                     pMask(ip1,j  ,k,bi,bj)   +  
      &                     pMask(i  ,jm1,k,bi,bj)   +  
      &                     pMask(i  ,jp1,k,bi,bj) ) +  
      &           p0625 * ( pMask(im1,jm1,k,bi,bj)   +  
      &                     pMask(im1,jp1,k,bi,bj)   +  
      &                     pMask(ip1,jm1,k,bi,bj)   +  
      &                     pMask(ip1,jp1,k,bi,bj) )  
             IF ( tempVar .GE. p25 ) THEN  
                fld_tmp(i,j) = (  
      &              p25  * fld(i  ,j  )*pMask(i  ,j  ,k,bi,bj) +  
      &              p125 *(fld(im1,j  )*pMask(im1,j  ,k,bi,bj) +  
      &                     fld(ip1,j  )*pMask(ip1,j  ,k,bi,bj) +  
      &                     fld(i  ,jm1)*pMask(i  ,jm1,k,bi,bj) +  
      &                     fld(i  ,jp1)*pMask(i  ,jp1,k,bi,bj))+  
      &              p0625*(fld(im1,jm1)*pMask(im1,jm1,k,bi,bj) +  
      &                     fld(im1,jp1)*pMask(im1,jp1,k,bi,bj) +  
      &                     fld(ip1,jm1)*pMask(ip1,jm1,k,bi,bj) +  
      &                     fld(ip1,jp1)*pMask(ip1,jp1,k,bi,bj)))  
      &              / tempVar  
             ELSE  
                fld_tmp(i,j) = fld(i,j)  
             ENDIF  
          ENDDO  
       ENDDO  
   
 c     transfer smoothed field to output array  
       DO j = jmin, jmax  
          DO i = imin, imax  
             fld(i,j) = fld_tmp(i,j)  
          ENDDO  
       ENDDO  
   
 #endif /* ALLOW_KPP */  
   
       return  
       end  
   
 c*************************************************************************  
   
1062        subroutine smooth_horiz (        subroutine smooth_horiz (
1063       I     k, bi, bj,       I     k, bi, bj,
1064       U     fld )       U     fld,
1065         I     myThid )
1066    
1067  c     Apply horizontal smoothing to global _RL 2-D array  c     Apply horizontal smoothing to global _RL 2-D array
1068    
1069        IMPLICIT NONE        IMPLICIT NONE
1070  #include "SIZE.h"  #include "SIZE.h"
1071    #include "GRID.h"
1072  #include "KPP_PARAMS.h"  #include "KPP_PARAMS.h"
1073    
1074  c     input  c     input
1075  c     bi, bj : array indices  c     bi, bj : array indices
1076  c     k      : vertical index used for masking  c     k      : vertical index used for masking
1077    c     myThid : thread number for this instance of the routine
1078          INTEGER myThid
1079        integer k, bi, bj        integer k, bi, bj
1080    
1081  c     input/output  c     input/output
# Line 981  c     local Line 1102  c     local
1102              im1 = i-1              im1 = i-1
1103              ip1 = i+1              ip1 = i+1
1104              tempVar =              tempVar =
1105       &           p25   *   pMask(i  ,j  ,k,bi,bj)   +       &           p25   *   maskC(i  ,j  ,k,bi,bj)   +
1106       &           p125  * ( pMask(im1,j  ,k,bi,bj)   +       &           p125  * ( maskC(im1,j  ,k,bi,bj)   +
1107       &                     pMask(ip1,j  ,k,bi,bj)   +       &                     maskC(ip1,j  ,k,bi,bj)   +
1108       &                     pMask(i  ,jm1,k,bi,bj)   +       &                     maskC(i  ,jm1,k,bi,bj)   +
1109       &                     pMask(i  ,jp1,k,bi,bj) ) +       &                     maskC(i  ,jp1,k,bi,bj) ) +
1110       &           p0625 * ( pMask(im1,jm1,k,bi,bj)   +       &           p0625 * ( maskC(im1,jm1,k,bi,bj)   +
1111       &                     pMask(im1,jp1,k,bi,bj)   +       &                     maskC(im1,jp1,k,bi,bj)   +
1112       &                     pMask(ip1,jm1,k,bi,bj)   +       &                     maskC(ip1,jm1,k,bi,bj)   +
1113       &                     pMask(ip1,jp1,k,bi,bj) )       &                     maskC(ip1,jp1,k,bi,bj) )
1114              IF ( tempVar .GE. p25 ) THEN              IF ( tempVar .GE. p25 ) THEN
1115                 fld_tmp(i,j) = (                 fld_tmp(i,j) = (
1116       &              p25  * fld(i  ,j  )*pMask(i  ,j  ,k,bi,bj) +       &              p25  * fld(i  ,j  )*maskC(i  ,j  ,k,bi,bj) +
1117       &              p125 *(fld(im1,j  )*pMask(im1,j  ,k,bi,bj) +       &              p125 *(fld(im1,j  )*maskC(im1,j  ,k,bi,bj) +
1118       &                     fld(ip1,j  )*pMask(ip1,j  ,k,bi,bj) +       &                     fld(ip1,j  )*maskC(ip1,j  ,k,bi,bj) +
1119       &                     fld(i  ,jm1)*pMask(i  ,jm1,k,bi,bj) +       &                     fld(i  ,jm1)*maskC(i  ,jm1,k,bi,bj) +
1120       &                     fld(i  ,jp1)*pMask(i  ,jp1,k,bi,bj))+       &                     fld(i  ,jp1)*maskC(i  ,jp1,k,bi,bj))+
1121       &              p0625*(fld(im1,jm1)*pMask(im1,jm1,k,bi,bj) +       &              p0625*(fld(im1,jm1)*maskC(im1,jm1,k,bi,bj) +
1122       &                     fld(im1,jp1)*pMask(im1,jp1,k,bi,bj) +       &                     fld(im1,jp1)*maskC(im1,jp1,k,bi,bj) +
1123       &                     fld(ip1,jm1)*pMask(ip1,jm1,k,bi,bj) +       &                     fld(ip1,jm1)*maskC(ip1,jm1,k,bi,bj) +
1124       &                     fld(ip1,jp1)*pMask(ip1,jp1,k,bi,bj)))       &                     fld(ip1,jp1)*maskC(ip1,jp1,k,bi,bj)))
1125       &              / tempVar       &              / tempVar
1126              ELSE              ELSE
1127                 fld_tmp(i,j) = fld(i,j)                 fld_tmp(i,j) = fld(i,j)
# Line 1024  c*************************************** Line 1145  c***************************************
1145    
1146        subroutine blmix (        subroutine blmix (
1147       I       ustar, bfsfc, hbl, stable, casea, diffus, kbl       I       ustar, bfsfc, hbl, stable, casea, diffus, kbl
1148       O     , dkm1, blmc, ghat, sigma, ikey       O     , dkm1, blmc, ghat, sigma, ikppkey
1149       &     )       I     , myThid )
1150    
1151  c     mixing coefficients within boundary layer depend on surface  c     mixing coefficients within boundary layer depend on surface
1152  c     forcing and the magnitude and gradient of interior mixing below  c     forcing and the magnitude and gradient of interior mixing below
# Line 1039  c Line 1160  c
1160    
1161  #include "SIZE.h"  #include "SIZE.h"
1162  #include "KPP_PARAMS.h"  #include "KPP_PARAMS.h"
1163    #ifdef ALLOW_AUTODIFF
1164    # include "tamc.h"
1165    #endif
1166    
1167  c input  c input
1168  c     ustar (imt)                 surface friction velocity             (m/s)  c     ustar (imt)                 surface friction velocity             (m/s)
# Line 1047  c     hbl   (imt)                 bounda Line 1171  c     hbl   (imt)                 bounda
1171  c     stable(imt)                 = 1 in stable forcing  c     stable(imt)                 = 1 in stable forcing
1172  c     casea (imt)                 = 1 in case A  c     casea (imt)                 = 1 in case A
1173  c     diffus(imt,0:Nrp1,mdiff)    vertical diffusivities              (m^2/s)  c     diffus(imt,0:Nrp1,mdiff)    vertical diffusivities              (m^2/s)
1174  c     kbl(imt)                    -1 of first grid level below hbl  c     kbl   (imt)                 -1 of first grid level below hbl
1175        _KPP_RL ustar (imt)  c     myThid               thread number for this instance of the routine
1176        _KPP_RL bfsfc (imt)        integer myThid
1177        _KPP_RL hbl   (imt)        _RL ustar (imt)
1178        _KPP_RL stable(imt)        _RL bfsfc (imt)
1179        _KPP_RL casea (imt)        _RL hbl   (imt)
1180        _KPP_RL diffus(imt,0:Nrp1,mdiff)        _RL stable(imt)
1181          _RL casea (imt)
1182          _RL diffus(imt,0:Nrp1,mdiff)
1183        integer kbl(imt)        integer kbl(imt)
1184    
1185  c output  c output
# Line 1061  c     dkm1 (imt,mdiff)            bounda Line 1187  c     dkm1 (imt,mdiff)            bounda
1187  c     blmc (imt,Nr,mdiff)         boundary layer mixing coefficients  (m^2/s)  c     blmc (imt,Nr,mdiff)         boundary layer mixing coefficients  (m^2/s)
1188  c     ghat (imt,Nr)               nonlocal scalar transport  c     ghat (imt,Nr)               nonlocal scalar transport
1189  c     sigma(imt)                  normalized depth (d / hbl)  c     sigma(imt)                  normalized depth (d / hbl)
1190        _KPP_RL dkm1 (imt,mdiff)        _RL dkm1 (imt,mdiff)
1191        _KPP_RL blmc (imt,Nr,mdiff)        _RL blmc (imt,Nr,mdiff)
1192        _KPP_RL ghat (imt,Nr)        _RL ghat (imt,Nr)
1193        _KPP_RL sigma(imt)        _RL sigma(imt)
1194        integer ikey        integer ikppkey, kkppkey
1195    
1196  #ifdef ALLOW_KPP  #ifdef ALLOW_KPP
1197    
# Line 1073  c  local Line 1199  c  local
1199  c     gat1*(imt)                 shape function at sigma = 1  c     gat1*(imt)                 shape function at sigma = 1
1200  c     dat1*(imt)                 derivative of shape function at sigma = 1  c     dat1*(imt)                 derivative of shape function at sigma = 1
1201  c     ws(imt), wm(imt)           turbulent velocity scales             (m/s)  c     ws(imt), wm(imt)           turbulent velocity scales             (m/s)
1202        _KPP_RL gat1m(imt), gat1s(imt), gat1t(imt)        _RL gat1m(imt), gat1s(imt), gat1t(imt)
1203        _KPP_RL dat1m(imt), dat1s(imt), dat1t(imt)        _RL dat1m(imt), dat1s(imt), dat1t(imt)
1204        _KPP_RL ws(imt), wm(imt)        _RL ws(imt), wm(imt)
1205        integer i, kn, ki        integer i, kn, ki
1206        _KPP_RL R, dvdzup, dvdzdn, viscp        _RL R, dvdzup, dvdzdn, viscp
1207        _KPP_RL difsp, diftp, visch, difsh, difth        _RL difsp, diftp, visch, difsh, difth
1208        _KPP_RL f1, sig, a1, a2, a3, delhat        _RL f1, sig, a1, a2, a3, delhat
1209        _KPP_RL Gm, Gs, Gt        _RL Gm, Gs, Gt
1210        _KPP_RL tempVar        _RL tempVar
1211    
1212        _KPP_RL    p0    , eins        _RL    p0    , eins
1213        parameter (p0=0.0, eins=1.0)        parameter (p0=0.0, eins=1.0)
1214    
1215  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
# Line 1094  c--------------------------------------- Line 1220  c---------------------------------------
1220           sigma(i) = stable(i) * 1.0 + (1. - stable(i)) * epsilon           sigma(i) = stable(i) * 1.0 + (1. - stable(i)) * epsilon
1221        end do        end do
1222    
1223    CADJ STORE sigma = comlev1_kpp, key=ikppkey, kind=isbyte
1224        call wscale (        call wscale (
1225       I        sigma, hbl, ustar, bfsfc,       I        sigma, hbl, ustar, bfsfc,
1226       O        wm, ws )       O        wm, ws, myThid )
1227    CADJ STORE wm = comlev1_kpp, key=ikppkey, kind=isbyte
1228    CADJ STORE ws = comlev1_kpp, key=ikppkey, kind=isbyte
1229    
1230        do i = 1, imt        do i = 1, imt
1231           wm(i) = sign(eins,wm(i))*max(phepsi,abs(wm(i)))           wm(i) = sign(eins,wm(i))*max(phepsi,abs(wm(i)))
1232           ws(i) = sign(eins,ws(i))*max(phepsi,abs(ws(i)))           ws(i) = sign(eins,ws(i))*max(phepsi,abs(ws(i)))
1233        end do        end do
1234  CADJ STORE wm = comlev1_kpp, key = ikey  CADJ STORE wm = comlev1_kpp, key=ikppkey, kind=isbyte
1235  CADJ STORE ws = comlev1_kpp, key = ikey  CADJ STORE ws = comlev1_kpp, key=ikppkey, kind=isbyte
1236    
1237        do i = 1, imt        do i = 1, imt
1238    
# Line 1135  c--------------------------------------- Line 1264  c---------------------------------------
1264           difsh  = diffus(i,kn,2) + difsp * delhat           difsh  = diffus(i,kn,2) + difsp * delhat
1265           difth  = diffus(i,kn,3) + diftp * delhat           difth  = diffus(i,kn,3) + diftp * delhat
1266    
1267           f1 = stable(i) * conc1 * bfsfc(i) /           f1 = stable(i) * conc1 * bfsfc(i) /
1268       &        max(ustar(i)**4,phepsi)       &        max(ustar(i)**4,phepsi)
1269           gat1m(i) = visch / hbl(i) / wm(i)           gat1m(i) = visch / hbl(i) / wm(i)
1270           dat1m(i) = -viscp / wm(i) + f1 * visch           dat1m(i) = -viscp / wm(i) + f1 * visch
1271           dat1m(i) = min(dat1m(i),p0)  
   
1272           gat1s(i) = difsh  / hbl(i) / ws(i)           gat1s(i) = difsh  / hbl(i) / ws(i)
1273           dat1s(i) = -difsp / ws(i) + f1 * difsh           dat1s(i) = -difsp / ws(i) + f1 * difsh
1274           dat1s(i) = min(dat1s(i),p0)  
   
1275           gat1t(i) = difth /  hbl(i) / ws(i)           gat1t(i) = difth /  hbl(i) / ws(i)
1276           dat1t(i) = -diftp / ws(i) + f1 * difth           dat1t(i) = -diftp / ws(i) + f1 * difth
1277    
1278          end do
1279    #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1280    CADJ STORE gat1m = comlev1_kpp, key=ikppkey, kind=isbyte
1281    CADJ STORE gat1s = comlev1_kpp, key=ikppkey, kind=isbyte
1282    CADJ STORE gat1t = comlev1_kpp, key=ikppkey, kind=isbyte
1283    CADJ STORE dat1m = comlev1_kpp, key=ikppkey, kind=isbyte
1284    CADJ STORE dat1s = comlev1_kpp, key=ikppkey, kind=isbyte
1285    CADJ STORE dat1t = comlev1_kpp, key=ikppkey, kind=isbyte
1286    #endif
1287          do i = 1, imt
1288             dat1m(i) = min(dat1m(i),p0)
1289             dat1s(i) = min(dat1s(i),p0)
1290           dat1t(i) = min(dat1t(i),p0)           dat1t(i) = min(dat1t(i),p0)
   
1291        end do        end do
1292    #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1293    CADJ STORE dat1m = comlev1_kpp, key=ikppkey, kind=isbyte
1294    CADJ STORE dat1s = comlev1_kpp, key=ikppkey, kind=isbyte
1295    CADJ STORE dat1t = comlev1_kpp, key=ikppkey, kind=isbyte
1296    #endif
1297    
1298        do ki = 1, Nr        do ki = 1, Nr
1299    
1300    #ifdef ALLOW_AUTODIFF_TAMC
1301             kkppkey = (ikppkey-1)*Nr + ki
1302    #endif
1303    
1304  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
1305  c     compute turbulent velocity scales on the interfaces  c     compute turbulent velocity scales on the interfaces
1306  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
# Line 1161  c--------------------------------------- Line 1309  c---------------------------------------
1309              sig      = (-zgrid(ki) + 0.5 * hwide(ki)) / hbl(i)              sig      = (-zgrid(ki) + 0.5 * hwide(ki)) / hbl(i)
1310              sigma(i) = stable(i)*sig + (1.-stable(i))*min(sig,epsilon)              sigma(i) = stable(i)*sig + (1.-stable(i))*min(sig,epsilon)
1311           end do           end do
1312    #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1313    CADJ STORE wm = comlev1_kpp_k, key = kkppkey
1314    CADJ STORE ws = comlev1_kpp_k, key = kkppkey
1315    #endif
1316    CADJ STORE sigma = comlev1_kpp_k, key = kkppkey
1317           call wscale (           call wscale (
1318       I        sigma, hbl, ustar, bfsfc,       I        sigma, hbl, ustar, bfsfc,
1319       O        wm, ws )       O        wm, ws, myThid )
1320    CADJ STORE wm = comlev1_kpp_k, key = kkppkey
1321    CADJ STORE ws = comlev1_kpp_k, key = kkppkey
1322    
1323  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
1324  c     compute the dimensionless shape functions at the interfaces  c     compute the dimensionless shape functions at the interfaces
# Line 1193  c--------------------------------------- Line 1348  c---------------------------------------
1348    
1349              tempVar = ws(i) * hbl(i)              tempVar = ws(i) * hbl(i)
1350              ghat(i,ki) = (1.-stable(i)) * cg / max(phepsi,tempVar)              ghat(i,ki) = (1.-stable(i)) * cg / max(phepsi,tempVar)
1351    
1352           end do           end do
1353        end do        end do
1354    
# Line 1203  c--------------------------------------- Line 1358  c---------------------------------------
1358    
1359        do i = 1, imt        do i = 1, imt
1360           sig      = -zgrid(kbl(i)-1) / hbl(i)           sig      = -zgrid(kbl(i)-1) / hbl(i)
1361           sigma(i) = stable(i) * sig           sigma(i) = stable(i) * sig
1362       &            + (1. - stable(i)) * min(sig,epsilon)       &            + (1. - stable(i)) * min(sig,epsilon)
1363        end do        end do
1364    
1365    #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1366    CADJ STORE wm = comlev1_kpp, key=ikppkey, kind=isbyte
1367    CADJ STORE ws = comlev1_kpp, key=ikppkey, kind=isbyte
1368    #endif
1369    CADJ STORE sigma = comlev1_kpp, key=ikppkey, kind=isbyte
1370        call wscale (        call wscale (
1371       I        sigma, hbl, ustar, bfsfc,       I        sigma, hbl, ustar, bfsfc,
1372       O        wm, ws )       O        wm, ws, myThid )
1373    CADJ STORE wm = comlev1_kpp, key=ikppkey, kind=isbyte
1374    CADJ STORE ws = comlev1_kpp, key=ikppkey, kind=isbyte
1375    
1376        do i = 1, imt        do i = 1, imt
1377           sig = -zgrid(kbl(i)-1) / hbl(i)           sig = -zgrid(kbl(i)-1) / hbl(i)
# Line 1226  c--------------------------------------- Line 1388  c---------------------------------------
1388    
1389  #endif /* ALLOW_KPP */  #endif /* ALLOW_KPP */
1390    
1391        return        return
1392        end        end
1393    
1394  c*************************************************************************  c*************************************************************************
1395    
1396        subroutine enhance (        subroutine enhance (
1397       I       dkm1, hbl, kbl, diffus, casea       I       dkm1, hbl, kbl, diffus, casea
1398       U     , ghat       U     , ghat
1399       O     , blmc       O     , blmc
1400       &     )       &     , myThid )
1401    
1402  c enhance the diffusivity at the kbl-.5 interface  c enhance the diffusivity at the kbl-.5 interface
1403    
# Line 1250  c     hbl(imt)                  boundary Line 1412  c     hbl(imt)                  boundary
1412  c     kbl(imt)                  grid above hbl  c     kbl(imt)                  grid above hbl
1413  c     diffus(imt,0:Nrp1,mdiff) vertical diffusivities           (m^2/s)  c     diffus(imt,0:Nrp1,mdiff) vertical diffusivities           (m^2/s)
1414  c     casea(imt)                = 1 in caseA, = 0 in case B  c     casea(imt)                = 1 in caseA, = 0 in case B
1415        _KPP_RL dkm1  (imt,mdiff)  c     myThid                    thread number for this instance of the routine
1416        _KPP_RL hbl   (imt)        integer   myThid
1417          _RL dkm1  (imt,mdiff)
1418          _RL hbl   (imt)
1419        integer kbl   (imt)        integer kbl   (imt)
1420        _KPP_RL diffus(imt,0:Nrp1,mdiff)        _RL diffus(imt,0:Nrp1,mdiff)
1421        _KPP_RL casea (imt)        _RL casea (imt)
1422    
1423  c input/output  c input/output
1424  c     nonlocal transport, modified ghat at kbl(i)-1 interface    (s/m**2)  c     nonlocal transport, modified ghat at kbl(i)-1 interface    (s/m**2)
1425        _KPP_RL ghat (imt,Nr)        _RL ghat (imt,Nr)
1426    
1427  c output  c output
1428  c     enhanced bound. layer mixing coeff.  c     enhanced bound. layer mixing coeff.
1429        _KPP_RL blmc  (imt,Nr,mdiff)        _RL blmc  (imt,Nr,mdiff)
1430    
1431  #ifdef ALLOW_KPP  #ifdef ALLOW_KPP
1432    
1433  c local  c local
1434  c     fraction hbl lies beteen zgrid neighbors  c     fraction hbl lies beteen zgrid neighbors
1435        _KPP_RL delta        _RL delta
1436        integer ki, i, md        integer ki, i, md
1437        _KPP_RL dkmp5, dstar        _RL dkmp5, dstar
1438    
1439        do i = 1, imt        do i = 1, imt
1440           ki = kbl(i)-1           ki = kbl(i)-1
# Line 1290  c     fraction hbl lies beteen zgrid nei Line 1454  c     fraction hbl lies beteen zgrid nei
1454    
1455  #endif /* ALLOW_KPP */  #endif /* ALLOW_KPP */
1456    
1457        return        return
1458        end        end
1459    
1460  c*************************************************************************  c*************************************************************************
1461    
1462        SUBROUTINE STATEKPP (        SUBROUTINE STATEKPP (
1463       I     bi, bj, myThid,       O     RHO1, DBLOC, DBSFC, TTALPHA, SSBETA,
1464       O     RHO1, DBLOC, DBSFC, TTALPHA, SSBETA)       I     ikppkey, bi, bj, myThid )
1465  c  c
1466  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
1467  c     "statekpp" computes all necessary input arrays  c     "statekpp" computes all necessary input arrays
# Line 1322  c Line 1486  c
1486  c     written  by: jan morzel,   feb. 10, 1995 (converted from "sigma" version)  c     written  by: jan morzel,   feb. 10, 1995 (converted from "sigma" version)
1487  c     modified by: d. menemenlis,    june 1998 : for use with MIT GCM UV  c     modified by: d. menemenlis,    june 1998 : for use with MIT GCM UV
1488  c  c
1489    
1490  c-----------------------------------------------------------------------  c-----------------------------------------------------------------------
1491    
1492        IMPLICIT NONE        IMPLICIT NONE
# Line 1331  c--------------------------------------- Line 1496  c---------------------------------------
1496  #include "PARAMS.h"  #include "PARAMS.h"
1497  #include "KPP_PARAMS.h"  #include "KPP_PARAMS.h"
1498  #include "DYNVARS.h"  #include "DYNVARS.h"
1499    #include "GRID.h"
1500    #ifdef ALLOW_AUTODIFF
1501    # include "tamc.h"
1502    #endif
1503    
1504  c-------------- Routine arguments -----------------------------------------  c-------------- Routine arguments -----------------------------------------
1505        INTEGER bi, bj, myThid        INTEGER bi, bj, myThid
1506        _KPP_RL RHO1   ( ibot:itop, jbot:jtop       )        _RL RHO1   ( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy       )
1507        _KPP_RL DBLOC  ( ibot:itop, jbot:jtop, Nr   )        _RL DBLOC  ( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy, Nr   )
1508        _KPP_RL DBSFC  ( ibot:itop, jbot:jtop, Nr   )        _RL DBSFC  ( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy, Nr   )
1509        _KPP_RL TTALPHA( ibot:itop, jbot:jtop, Nrp1 )        _RL TTALPHA( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy, Nrp1 )
1510        _KPP_RL SSBETA ( ibot:itop, jbot:jtop, Nrp1 )        _RL SSBETA ( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy, Nrp1 )
1511    
1512  #ifdef ALLOW_KPP  #ifdef ALLOW_KPP
1513    
# Line 1349  c Line 1518  c
1518  c     rhok         - density of t(k  ) & s(k  ) at depth k  c     rhok         - density of t(k  ) & s(k  ) at depth k
1519  c     rhokm1       - density of t(k-1) & s(k-1) at depth k  c     rhokm1       - density of t(k-1) & s(k-1) at depth k
1520  c     rho1k        - density of t(1  ) & s(1  ) at depth k  c     rho1k        - density of t(1  ) & s(1  ) at depth k
1521  c     work1, work2 - work arrays for holding horizontal slabs  c     work1,2,3    - work arrays for holding horizontal slabs
1522    
1523        _RL RHOK  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL RHOK  (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
1524        _RL RHOKM1(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL RHOKM1(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
# Line 1357  c     work1, work2 - work arrays for hol Line 1526  c     work1, work2 - work arrays for hol
1526        _RL WORK1 (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL WORK1 (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
1527        _RL WORK2 (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL WORK2 (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
1528        _RL WORK3 (1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL WORK3 (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
1529    
1530        INTEGER I, J, K        INTEGER I, J, K
1531          INTEGER ikppkey, kkppkey
1532    
1533  c calculate density, alpha, beta in surface layer, and set dbsfc to zero  c calculate density, alpha, beta in surface layer, and set dbsfc to zero
1534    
1535        call FIND_RHO(        kkppkey = (ikppkey-1)*Nr + 1
1536       I     bi, bj, ibot, itop, jbot, jtop, 1, 1,  
1537       I     theta, salt,  #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1538    CADJ STORE theta(:,:,1,bi,bj) = comlev1_kpp_k,
1539    CADJ &     key=kkppkey, kind=isbyte
1540    CADJ STORE salt (:,:,1,bi,bj) = comlev1_kpp_k,
1541    CADJ &     key=kkppkey, kind=isbyte
1542    #endif /* KPP_AUTODIFF_EXCESSIVE_STORE */
1543          CALL FIND_RHO_2D(
1544         I     1-OLx, sNx+OLx, 1-OLy, sNy+OLy, 1,
1545         I     theta(1-OLx,1-OLy,1,bi,bj), salt(1-OLx,1-OLy,1,bi,bj),
1546       O     WORK1,       O     WORK1,
1547       I     myThid )       I     1, bi, bj, myThid )
1548    #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1549    CADJ STORE theta(:,:,1,bi,bj) = comlev1_kpp_k,
1550    CADJ &     key=kkppkey, kind=isbyte
1551    CADJ STORE salt (:,:,1,bi,bj) = comlev1_kpp_k,
1552    CADJ &     key=kkppkey, kind=isbyte
1553    #endif /* KPP_AUTODIFF_EXCESSIVE_STORE */
1554    
1555        call FIND_ALPHA(        call FIND_ALPHA(
1556       I     bi, bj, ibot, itop, jbot, jtop, 1, 1,       I     bi, bj, 1-OLx, sNx+OLx, 1-OLy, sNy+OLy, 1, 1,
1557       O     WORK2 )       O     WORK2, myThid )
1558    
1559        call FIND_BETA(        call FIND_BETA(
1560       I     bi, bj, ibot, itop, jbot, jtop, 1, 1,       I     bi, bj, 1-OLx, sNx+OLx, 1-OLy, sNy+OLy, 1, 1,
1561       O     WORK3 )       O     WORK3, myThid )
1562    
1563        DO J = jbot, jtop        DO J = 1-OLy, sNy+OLy
1564           DO I = ibot, itop           DO I = 1-OLx, sNx+OLx
1565              RHO1(I,J)      = WORK1(I,J) + rhoConst              RHO1(I,J)      = WORK1(I,J) + rhoConst
1566              TTALPHA(I,J,1) = WORK2(I,J)              TTALPHA(I,J,1) = WORK2(I,J)
1567              SSBETA(I,J,1)  = WORK3(I,J)              SSBETA(I,J,1)  = WORK3(I,J)
# Line 1389  c calculate alpha, beta, and gradients i Line 1574  c calculate alpha, beta, and gradients i
1574  CHPF$  INDEPENDENT, NEW (RHOK,RHOKM1,RHO1K,WORK1,WORK2)  CHPF$  INDEPENDENT, NEW (RHOK,RHOKM1,RHO1K,WORK1,WORK2)
1575        DO K = 2, Nr        DO K = 2, Nr
1576    
1577           call FIND_RHO(        kkppkey = (ikppkey-1)*Nr + k
1578       I        bi, bj, ibot, itop, jbot, jtop, K, K,  
1579       I        theta, salt,  #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1580    CADJ STORE theta(:,:,k,bi,bj) = comlev1_kpp_k,
1581    CADJ &     key=kkppkey, kind=isbyte
1582    CADJ STORE salt (:,:,k,bi,bj) = comlev1_kpp_k,
1583    CADJ &     key=kkppkey, kind=isbyte
1584    #endif /* KPP_AUTODIFF_EXCESSIVE_STORE */
1585             CALL FIND_RHO_2D(
1586         I        1-OLx, sNx+OLx, 1-OLy, sNy+OLy, k,
1587         I        theta(1-OLx,1-OLy,k,bi,bj), salt(1-OLx,1-OLy,k,bi,bj),
1588       O        RHOK,       O        RHOK,
1589       I        myThid )       I        k, bi, bj, myThid )
1590    
1591           call FIND_RHO(  #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1592       I        bi, bj, ibot, itop, jbot, jtop, K-1, K,  CADJ STORE theta(:,:,k-1,bi,bj) = comlev1_kpp_k,
1593       I        theta, salt,  CADJ &     key=kkppkey, kind=isbyte
1594    CADJ STORE salt (:,:,k-1,bi,bj) = comlev1_kpp_k,
1595    CADJ &     key=kkppkey, kind=isbyte
1596    #endif /* KPP_AUTODIFF_EXCESSIVE_STORE */
1597             CALL FIND_RHO_2D(
1598         I        1-OLx, sNx+OLx, 1-OLy, sNy+OLy, k,
1599         I        theta(1-OLx,1-OLy,k-1,bi,bj),salt(1-OLx,1-OLy,k-1,bi,bj),
1600       O        RHOKM1,       O        RHOKM1,
1601       I        myThid )       I        k-1, bi, bj, myThid )
1602    
1603           call FIND_RHO(  #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1604       I        bi, bj, ibot, itop, jbot, jtop, 1, K,  CADJ STORE theta(:,:,1,bi,bj) = comlev1_kpp_k,
1605       I        theta, salt,  CADJ &     key=kkppkey, kind=isbyte
1606    CADJ STORE salt (:,:,1,bi,bj) = comlev1_kpp_k,
1607    CADJ &     key=kkppkey, kind=isbyte
1608    #endif /* KPP_AUTODIFF_EXCESSIVE_STORE */
1609             CALL FIND_RHO_2D(
1610         I        1-OLx, sNx+OLx, 1-OLy, sNy+OLy, k,
1611         I        theta(1-OLx,1-OLy,1,bi,bj), salt(1-OLx,1-OLy,1,bi,bj),
1612       O        RHO1K,       O        RHO1K,
1613       I        myThid )       I        1, bi, bj, myThid )
1614    
1615    #ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1616    CADJ STORE rhok  (:,:)          = comlev1_kpp_k,
1617    CADJ &     key=kkppkey, kind=isbyte
1618    CADJ STORE rhokm1(:,:)          = comlev1_kpp_k,
1619    CADJ &     key=kkppkey, kind=isbyte
1620    CADJ STORE rho1k (:,:)          = comlev1_kpp_k,
1621    CADJ &     key=kkppkey, kind=isbyte
1622    #endif /* KPP_AUTODIFF_EXCESSIVE_STORE */
1623    
1624           call FIND_ALPHA(           call FIND_ALPHA(
1625       I        bi, bj, ibot, itop, jbot, jtop, K, K,       I        bi, bj, 1-OLx, sNx+OLx, 1-OLy, sNy+OLy, K, K,
1626       O        WORK1 )       O        WORK1, myThid )
1627    
1628           call FIND_BETA(           call FIND_BETA(
1629       I        bi, bj, ibot, itop, jbot, jtop, K, K,       I        bi, bj, 1-OLx, sNx+OLx, 1-OLy, sNy+OLy, K, K,
1630       O        WORK2 )       O        WORK2, myThid )
1631    
1632           DO J = jbot, jtop           DO J = 1-OLy, sNy+OLy
1633              DO I = ibot, itop              DO I = 1-OLx, sNx+OLx
1634                 TTALPHA(I,J,K) = WORK1 (I,J)                 TTALPHA(I,J,K) = WORK1 (I,J)
1635                 SSBETA(I,J,K)  = WORK2 (I,J)                 SSBETA(I,J,K)  = WORK2 (I,J)
1636                 DBLOC(I,J,K-1) = gravity * (RHOK(I,J) - RHOKM1(I,J)) /                 DBLOC(I,J,K-1) = gravity * (RHOK(I,J) - RHOKM1(I,J)) /
# Line 1429  CHPF$  INDEPENDENT, NEW (RHOK,RHOKM1,RHO Line 1643  CHPF$  INDEPENDENT, NEW (RHOK,RHOKM1,RHO
1643        END DO        END DO
1644    
1645  c     compute arrays for K = Nrp1  c     compute arrays for K = Nrp1
1646        DO J = jbot, jtop        DO J = 1-OLy, sNy+OLy
1647           DO I = ibot, itop           DO I = 1-OLx, sNx+OLx
1648              TTALPHA(I,J,Nrp1) = TTALPHA(I,J,Nr)              TTALPHA(I,J,Nrp1) = TTALPHA(I,J,Nr)
1649              SSBETA(I,J,Nrp1)  = SSBETA(I,J,Nr)              SSBETA(I,J,Nrp1)  = SSBETA(I,J,Nr)
1650              DBLOC(I,J,Nr)     = 0.              DBLOC(I,J,Nr)     = 0.
1651           END DO           END DO
1652        END DO        END DO
1653    
1654    #ifdef ALLOW_DIAGNOSTICS
1655          IF ( useDiagnostics ) THEN
1656             CALL DIAGNOSTICS_FILL(DBSFC ,'KPPdbsfc',0,Nr,0,1,1,myThid)
1657             CALL DIAGNOSTICS_FILL(DBLOC ,'KPPdbloc',0,Nr,0,1,1,myThid)
1658          ENDIF
1659    #endif /* ALLOW_DIAGNOSTICS */
1660    
1661    #endif /* ALLOW_KPP */
1662    
1663          RETURN
1664          END
1665    
1666    
1667    c*************************************************************************
1668    
1669          SUBROUTINE KPP_DOUBLEDIFF (
1670         I     TTALPHA, SSBETA,
1671         U     kappaRT,
1672         U     kappaRS,
1673         I     ikppkey, imin, imax, jmin, jmax, bi, bj, myThid )
1674    c
1675    c-----------------------------------------------------------------------
1676    c     "KPP_DOUBLEDIFF" adds the double diffusive contributions
1677    C     as Rrho-dependent parameterizations to kappaRT and kappaRS
1678    c
1679    c     input:
1680    c     bi, bj  = array indices on which to apply calculations
1681    c     imin, imax, jmin, jmax = array boundaries
1682    c     ikppkey = key for TAMC/TAF automatic differentiation
1683    c     myThid  = thread id
1684    c
1685    c      ttalpha= thermal expansion coefficient without 1/rho factor
1686    c               d(rho) / d(potential temperature)                    (kg/m^3/C)
1687    c      ssbeta = salt expansion coefficient without 1/rho factor
1688    c               d(rho) / d(salinity)                               (kg/m^3/PSU)
1689    c     output: updated
1690    c     kappaRT/S :: background diffusivities for temperature and salinity
1691    c
1692    c     written  by: martin losch,   sept. 15, 2009
1693    c
1694    
1695    c-----------------------------------------------------------------------
1696    
1697          IMPLICIT NONE
1698    
1699    #include "SIZE.h"
1700    #include "EEPARAMS.h"
1701    #include "PARAMS.h"
1702    #include "KPP_PARAMS.h"
1703    #include "DYNVARS.h"
1704    #include "GRID.h"
1705    #ifdef ALLOW_AUTODIFF
1706    # include "tamc.h"
1707    #endif
1708    
1709    c-------------- Routine arguments -----------------------------------------
1710          INTEGER ikppkey, imin, imax, jmin, jmax, bi, bj, myThid
1711    
1712          _RL TTALPHA( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy, Nrp1 )
1713          _RL SSBETA ( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy, Nrp1 )
1714          _RL KappaRT( 1-Olx:sNx+Olx, 1-Oly:sNy+Oly, Nr   )
1715          _RL KappaRS( 1-Olx:sNx+Olx, 1-Oly:sNy+Oly, Nr   )
1716    
1717    
1718    #ifdef ALLOW_KPP
1719    
1720    C--------------------------------------------------------------------------
1721    C
1722    C     local variables
1723    C     I,J,K :: loop indices
1724    C     kkppkey :: key for TAMC/TAF automatic differentiation
1725    C
1726          INTEGER I, J, K
1727          INTEGER kkppkey
1728    C     alphaDT   :: d\rho/d\theta * d\theta
1729    C     betaDS    :: d\rho/dsalt * dsalt
1730    C     Rrho      :: "density ratio" R_{\rho} = \alpha dT/dz / \beta dS/dz
1731    C     nuddt/s   :: double diffusive diffusivities
1732    C     numol     :: molecular diffusivity
1733    C     rFac      :: abbreviation for 1/(R_{\rho0}-1)
1734    
1735          _RL alphaDT ( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy )
1736          _RL betaDS  ( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy )
1737          _RL nuddt   ( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy )
1738          _RL nudds   ( 1-OLx:sNx+OLx, 1-OLy:sNy+OLy )
1739          _RL Rrho
1740          _RL numol, rFac, nutmp
1741          INTEGER Km1
1742    
1743    C     set some constants here
1744          numol = 1.5 _d -06
1745          rFac  = 1. _d 0 / (Rrho0 - 1. _d 0 )
1746    C
1747          kkppkey = (ikppkey-1)*Nr + 1
1748    
1749    CML#ifdef KPP_AUTODIFF_EXCESSIVE_STORE
1750    CMLCADJ STORE theta(:,:,1,bi,bj) = comlev1_kpp_k,
1751    CMLCADJ &     key=kkppkey, kind=isbyte
1752    CMLCADJ STORE salt (:,:,1,bi,bj) = comlev1_kpp_k,
1753    CMLCADJ &     key=kkppkey, kind=isbyte
1754    CML#endif /* KPP_AUTODIFF_EXCESSIVE_STORE */
1755    
1756          DO K = 1, Nr
1757           Km1 = MAX(K-1,1)
1758           DO J = 1-Oly, sNy+Oly
1759            DO I = 1-Olx, sNx+Olx
1760             alphaDT(I,J) = ( theta(I,J,Km1,bi,bj)-theta(I,J,K,bi,bj) )
1761         &        * 0.5 _d 0 * ABS( TTALPHA(I,J,Km1) + TTALPHA(I,J,K) )
1762             betaDS(I,J)  = ( salt(I,J,Km1,bi,bj)-salt(I,J,K,bi,bj) )
1763         &        * 0.5 _d 0 * ( SSBETA(I,J,Km1) + SSBETA(I,J,K) )
1764             nuddt(I,J) = 0. _d 0
1765             nudds(I,J) = 0. _d 0
1766            ENDDO
1767           ENDDO
1768           IF ( K .GT. 1 ) THEN
1769            DO J = jMin, jMax
1770             DO I = iMin, iMax
1771              Rrho  = 0. _d 0
1772    C     Now we have many different cases
1773    C     a. alphaDT > 0 and betaDS > 0 => salt fingering
1774    C        (salinity destabilizes)
1775              IF (      alphaDT(I,J) .GT. betaDS(I,J)
1776         &         .AND. betaDS(I,J) .GT. 0. _d 0 ) THEN
1777               Rrho = MIN( alphaDT(I,J)/betaDS(I,J), Rrho0 )
1778    C     Large et al. 1994, eq. 31a
1779    C          nudds(I,J) = dsfmax * ( 1. _d 0 - (Rrho - 1. _d 0) * rFac )**3
1780               nutmp      =          ( 1. _d 0 - (Rrho - 1. _d 0) * rFac )
1781               nudds(I,J) = dsfmax * nutmp * nutmp * nutmp
1782    C     Large et al. 1994, eq. 31c
1783               nuddt(I,J) = 0.7 _d 0 * nudds(I,J)
1784              ELSEIF (   alphaDT(I,J) .LT. 0. _d 0
1785         &          .AND. betaDS(I,J) .LT. 0. _d 0
1786         &          .AND.alphaDT(I,J) .GT. betaDS(I,J) ) THEN
1787    C     b. alphaDT < 0 and betaDS < 0 => semi-convection, diffusive convection
1788    C        (temperature destabilizes)
1789    C     for Rrho >= 1 the water column is statically unstable and we never
1790    C     reach this point
1791               Rrho = alphaDT(I,J)/betaDS(I,J)
1792    C     Large et al. 1994, eq. 32
1793               nuddt(I,J) = numol * 0.909 _d 0
1794         &          * exp ( 4.6 _d 0 * exp (
1795         &          - 5.4 _d 0 * ( 1. _d 0/Rrho - 1. _d 0 ) ) )
1796    CMLC     or
1797    CMLC     Large et al. 1994, eq. 33
1798    CML         nuddt(I,J) = numol * 8.7 _d 0 * Rrho**1.1
1799    C     Large et al. 1994, eqs. 34
1800               nudds(I,J) = nuddt(I,J) * MAX( 0.15 _d 0 * Rrho,
1801         &          1.85 _d 0 * Rrho - 0.85 _d 0 )
1802              ELSE
1803    C     Do nothing, because in this case the water colume is unstable
1804    C     => double diffusive processes are negligible and mixing due
1805    C     to shear instability will dominate
1806              ENDIF
1807             ENDDO
1808            ENDDO
1809    C     ENDIF ( K .GT. 1 )
1810           ENDIF
1811    C
1812           DO J = 1-Oly, sNy+Oly
1813            DO I = 1-Olx, sNx+Olx
1814             kappaRT(I,J,K) = kappaRT(I,J,K) + nuddt(I,J)
1815             kappaRS(I,J,K) = kappaRS(I,J,K) + nudds(I,J)
1816            ENDDO
1817           ENDDO
1818    #ifdef ALLOW_DIAGNOSTICS
1819           IF ( useDiagnostics ) THEN
1820            CALL DIAGNOSTICS_FILL(nuddt,'KPPnuddt',k,1,2,bi,bj,myThid)
1821            CALL DIAGNOSTICS_FILL(nudds,'KPPnudds',k,1,2,bi,bj,myThid)
1822           ENDIF
1823    #endif /* ALLOW_DIAGNOSTICS */
1824    C     end of K-loop
1825          ENDDO
1826  #endif /* ALLOW_KPP */  #endif /* ALLOW_KPP */
1827    
1828        RETURN        RETURN

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.46

  ViewVC Help
Powered by ViewVC 1.1.22