/[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.14 - (hide annotations) (download)
Tue Feb 18 05:33:55 2003 UTC (21 years, 4 months ago) by dimitri
Branch: MAIN
CVS Tags: checkpoint48i_post, checkpoint48f_post, checkpoint48h_post, checkpoint49, checkpoint48g_post
Changes since 1.13: +7 -5 lines
Merging from release1_p12:
o Modifications for using pkg/exf with pkg/seaice
  - improved description of the various forcing configurations
  - added basic radiation bulk formulae to pkg/exf
  - units/sign fix for evap computation in exf_getffields.F
  - updated verification/global_with_exf/results/output.txt
o Added pkg/sbo for computing IERS Special Bureau for the Oceans
  (SBO) core products, including oceanic mass, center-of-mass,
  angular, and bottom pressure (see pkg/sbo/README.sbo).
o Lower bound for viscosity/diffusivity in pkg/kpp/kpp_routines.F
  to avoid negative values in shallow regions.
  - updated verification/natl_box/results/output.txt
  - updated verification/lab_sea/results/output.txt
o MPI gather, scatter: eesupp/src/gather_2d.F and scatter_2d.F
o Added useSingleCpuIO option (see PARAMS.h).
o Updated useSingleCpuIO option in mdsio_writefield.F to
  work with multi-field files, e.g., for single-file pickup.
o pkg/seaice:
  - bug fix in growth.F: QNET for no shortwave case
  - added HeffFile for specifying initial sea-ice thickness
  - changed SEAICE_EXTERNAL_FLUXES wind stress implementation
o Added missing /* */ to CPP comments in pkg/seaice, pkg/exf,
  kpp_transport_t.F, forward_step.F, and the_main_loop.F
o pkg/seaice:
  - adjoint-friendly modifications
  - added a SEAICE_WRITE_PICKUP at end of the_model_main.F

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

  ViewVC Help
Powered by ViewVC 1.1.22