New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
zdfbfr.F90 in branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/ZDF – NEMO

source: branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/ZDF/zdfbfr.F90 @ 3229

Last change on this file since 3229 was 3229, checked in by charris, 12 years ago

Added timing calls to most significant routines in LDF, SBC and ZDF.

  • Property svn:keywords set to Id
File size: 13.5 KB
Line 
1MODULE zdfbfr
2   !!======================================================================
3   !!                       ***  MODULE  zdfbfr  ***
4   !! Ocean physics: Bottom friction
5   !!======================================================================
6   !! History :  OPA  ! 1997-06  (G. Madec, A.-M. Treguier)  Original code
7   !!   NEMO     1.0  ! 2002-06  (G. Madec)  F90: Free form and module
8   !!            3.2  ! 2009-09  (A.C.Coward)  Correction to include barotropic contribution
9   !!            3.3  ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
10   !!----------------------------------------------------------------------
11
12   !!----------------------------------------------------------------------
13   !!   zdf_bfr      : update momentum Kz at the ocean bottom due to the type of bottom friction chosen
14   !!   zdf_bfr_init : read in namelist and control the bottom friction parameters.
15   !!   zdf_bfr_2d   : read in namelist and control the bottom friction parameters.
16   !!----------------------------------------------------------------------
17   USE oce             ! ocean dynamics and tracers variables
18   USE dom_oce         ! ocean space and time domain variables
19   USE zdf_oce         ! ocean vertical physics variables
20   USE in_out_manager  ! I/O manager
21   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
22   USE lib_mpp         ! distributed memory computing
23   USE prtctl          ! Print control
24   USE timing          ! Timing
25
26   IMPLICIT NONE
27   PRIVATE
28
29   PUBLIC   zdf_bfr         ! called by step.F90
30   PUBLIC   zdf_bfr_init    ! called by opa.F90
31
32   !                                    !!* Namelist nambfr: bottom friction namelist *
33   INTEGER  ::   nn_bfr    = 0           ! = 0/1/2/3 type of bottom friction
34   REAL(wp) ::   rn_bfri1  = 4.0e-4_wp   ! bottom drag coefficient (linear case)
35   REAL(wp) ::   rn_bfri2  = 1.0e-3_wp   ! bottom drag coefficient (non linear case)
36   REAL(wp) ::   rn_bfeb2  = 2.5e-3_wp   ! background bottom turbulent kinetic energy  [m2/s2]
37   REAL(wp) ::   rn_bfrien = 30._wp      ! local factor to enhance coefficient bfri
38   LOGICAL  ::   ln_bfr2d  = .false.     ! logical switch for 2D enhancement
39   LOGICAL , PUBLIC                            ::  ln_bfrimp = .false.  ! logical switch for implicit bottom friction
40   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::  bfrcoef2d            ! 2D bottom drag coefficient
41
42   !! * Substitutions
43#  include "vectopt_loop_substitute.h90"
44#  include "domzgr_substitute.h90"
45   !!----------------------------------------------------------------------
46   !! NEMO/OPA 4.0 , NEMO Consortium (2011)
47   !! $Id$
48   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
49   !!----------------------------------------------------------------------
50CONTAINS
51
52   INTEGER FUNCTION zdf_bfr_alloc()
53      !!----------------------------------------------------------------------
54      !!                ***  FUNCTION zdf_bfr_alloc  ***
55      !!----------------------------------------------------------------------
56      ALLOCATE( bfrcoef2d(jpi,jpj), STAT=zdf_bfr_alloc )
57      !
58      IF( lk_mpp             )   CALL mpp_sum ( zdf_bfr_alloc )
59      IF( zdf_bfr_alloc /= 0 )   CALL ctl_warn('zdf_bfr_alloc: failed to allocate arrays.')
60   END FUNCTION zdf_bfr_alloc
61
62
63   SUBROUTINE zdf_bfr( kt )
64      !!----------------------------------------------------------------------
65      !!                   ***  ROUTINE zdf_bfr  ***
66      !!                 
67      !! ** Purpose :   compute the bottom friction coefficient.
68      !!
69      !! ** Method  :   Calculate and store part of the momentum trend due   
70      !!              to bottom friction following the chosen friction type
71      !!              (free-slip, linear, or quadratic). The component
72      !!              calculated here is multiplied by the bottom velocity in
73      !!              dyn_bfr to provide the trend term.
74      !!                The coefficients are updated at each time step only
75      !!              in the quadratic case.
76      !!
77      !! ** Action  :   bfrua , bfrva   bottom friction coefficients
78      !!----------------------------------------------------------------------
79      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
80      !!
81      INTEGER  ::   ji, jj       ! dummy loop indices
82      INTEGER  ::   ikbu, ikbv   ! local integers
83      REAL(wp) ::   zvu, zuv, zecu, zecv   ! temporary scalars
84      !!----------------------------------------------------------------------
85      !
86      IF( nn_timing == 1 )  CALL timing_start('zdf_bfr')
87      !
88      IF( nn_bfr == 2 ) THEN                 ! quadratic botton friction
89         ! Calculate and store the quadratic bottom friction coefficient bfrua and bfrva
90         ! where bfrUa = C_d*SQRT(u_bot^2 + v_bot^2 + e_b) {U=[u,v]}
91         ! from these the trend due to bottom friction:  -F_h/e3U  can be calculated
92         ! where -F_h/e3U_bot = bfrUa*Ub/e3U_bot {U=[u,v]}
93         !
94# if defined key_vectopt_loop
95         DO jj = 1, 1
96!CDIR NOVERRCHK
97            DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
98# else
99!CDIR NOVERRCHK
100         DO jj = 2, jpjm1
101!CDIR NOVERRCHK
102            DO ji = 2, jpim1
103# endif
104               ikbu = mbku(ji,jj)         ! ocean bottom level at u- and v-points
105               ikbv = mbkv(ji,jj)         ! (deepest ocean u- and v-points)
106               !
107               zvu  = 0.25 * (  vn(ji,jj  ,ikbu) + vn(ji+1,jj  ,ikbu)     &
108                  &           + vn(ji,jj-1,ikbu) + vn(ji+1,jj-1,ikbu)  )
109               zuv  = 0.25 * (  un(ji,jj  ,ikbv) + un(ji-1,jj  ,ikbv)     &
110                  &           + un(ji,jj+1,ikbv) + un(ji-1,jj+1,ikbv)  )
111               !
112               zecu = SQRT(  un(ji,jj,ikbu) * un(ji,jj,ikbu) + zvu*zvu + rn_bfeb2  )
113               zecv = SQRT(  vn(ji,jj,ikbv) * vn(ji,jj,ikbv) + zuv*zuv + rn_bfeb2  )
114               !
115               bfrua(ji,jj) = - 0.5_wp * ( bfrcoef2d(ji,jj) + bfrcoef2d(ji+1,jj  ) ) * zecu 
116               bfrva(ji,jj) = - 0.5_wp * ( bfrcoef2d(ji,jj) + bfrcoef2d(ji  ,jj+1) ) * zecv
117            END DO
118         END DO
119         !
120         CALL lbc_lnk( bfrua, 'U', 1. )   ;   CALL lbc_lnk( bfrva, 'V', 1. )      ! Lateral boundary condition
121         !
122         IF(ln_ctl)   CALL prt_ctl( tab2d_1=bfrua, clinfo1=' bfr  - u: ', mask1=umask,        &
123            &                       tab2d_2=bfrva, clinfo2=       ' v: ', mask2=vmask,ovlap=1 )
124      ENDIF
125      !
126      IF( nn_timing == 1 )  CALL timing_stop('zdf_bfr')
127      !
128   END SUBROUTINE zdf_bfr
129
130
131   SUBROUTINE zdf_bfr_init
132      !!----------------------------------------------------------------------
133      !!                  ***  ROUTINE zdf_bfr_init  ***
134      !!                   
135      !! ** Purpose :   Initialization of the bottom friction
136      !!
137      !! ** Method  :   Read the nammbf namelist and check their consistency
138      !!              called at the first timestep (nit000)
139      !!----------------------------------------------------------------------
140      USE iom   ! I/O module for ehanced bottom friction file
141      !!
142      INTEGER ::   inum         ! logical unit for enhanced bottom friction file
143      INTEGER ::   ji, jj       ! dummy loop indexes
144      INTEGER ::   ikbu, ikbv   ! temporary integers
145      INTEGER ::   ictu, ictv   !    -          -
146      REAL(wp) ::  zminbfr, zmaxbfr   ! temporary scalars
147      REAL(wp) ::  zfru, zfrv         !    -         -
148      !!
149      NAMELIST/nambfr/ nn_bfr, rn_bfri1, rn_bfri2, rn_bfeb2, ln_bfr2d, rn_bfrien, ln_bfrimp
150      !!----------------------------------------------------------------------
151      !
152      IF( nn_timing == 1 )  CALL timing_start('zdf_bfr_init')
153      !
154      REWIND ( numnam )               !* Read Namelist nam_bfr : bottom momentum boundary condition
155      READ   ( numnam, nambfr )
156
157      !                               !* Parameter control and print
158      IF(lwp) WRITE(numout,*)
159      IF(lwp) WRITE(numout,*) 'zdf_bfr : momentum bottom friction'
160      IF(lwp) WRITE(numout,*) '~~~~~~~'
161      IF(lwp) WRITE(numout,*) '   Namelist nam_bfr : set bottom friction parameters'
162
163      !                              ! allocate zdfbfr arrays
164      IF( zdf_bfr_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'zdf_bfr_init : unable to allocate arrays' )
165
166      !                              ! Make sure ln_zdfexp=.false. when use implicit bfr
167      IF( ln_bfrimp .AND. ln_zdfexp ) THEN
168         IF(lwp) THEN
169            WRITE(numout,*)
170            WRITE(numout,*) 'Implicit bottom friction can only be used when ln_zdfexp=.false.'
171            WRITE(numout,*) '         but you set: ln_bfrimp=.true. and ln_zdfexp=.true.!!!!'
172            WRITE(ctmp1,*)  '         bad ln_bfrimp value = .true.' 
173            CALL ctl_stop( ctmp1 )
174         END IF
175      END IF
176
177      SELECT CASE (nn_bfr)
178      !
179      CASE( 0 )
180         IF(lwp) WRITE(numout,*) '      free-slip '
181         bfrua(:,:) = 0.e0
182         bfrva(:,:) = 0.e0
183         !
184      CASE( 1 )
185         IF(lwp) WRITE(numout,*) '      linear botton friction'
186         IF(lwp) WRITE(numout,*) '      friction coef.   rn_bfri1  = ', rn_bfri1
187         IF( ln_bfr2d ) THEN
188            IF(lwp) WRITE(numout,*) '      read coef. enhancement distribution from file   ln_bfr2d  = ', ln_bfr2d
189            IF(lwp) WRITE(numout,*) '      coef rn_bfri2 enhancement factor                rn_bfrien  = ',rn_bfrien
190         ENDIF
191         !
192         bfrcoef2d(:,:) = rn_bfri1  ! initialize bfrcoef2d to the namelist variable
193         !
194         IF(ln_bfr2d) THEN 
195            ! bfr_coef is a coefficient in [0,1] giving the mask where to apply the bfr enhancement
196            CALL iom_open('bfr_coef.nc',inum)
197            CALL iom_get (inum, jpdom_data, 'bfr_coef',bfrcoef2d,1) ! bfrcoef2d is used as tmp array
198            CALL iom_close(inum)
199            bfrcoef2d(:,:) = rn_bfri1 * ( 1 + rn_bfrien * bfrcoef2d(:,:) )
200         ENDIF
201         bfrua(:,:) = - bfrcoef2d(:,:)
202         bfrva(:,:) = - bfrcoef2d(:,:)
203         !
204      CASE( 2 )
205         IF(lwp) WRITE(numout,*) '      quadratic botton friction'
206         IF(lwp) WRITE(numout,*) '      friction coef.   rn_bfri2  = ', rn_bfri2
207         IF(lwp) WRITE(numout,*) '      background tke   rn_bfeb2  = ', rn_bfeb2
208         IF( ln_bfr2d ) THEN
209            IF(lwp) WRITE(numout,*) '      read coef. enhancement distribution from file   ln_bfr2d  = ', ln_bfr2d
210            IF(lwp) WRITE(numout,*) '      coef rn_bfri2 enhancement factor                rn_bfrien  = ',rn_bfrien
211         ENDIF
212         bfrcoef2d(:,:) = rn_bfri2  ! initialize bfrcoef2d to the namelist variable
213         !
214         IF(ln_bfr2d) THEN 
215            ! bfr_coef is a coefficient in [0,1] giving the mask where to apply the bfr enhancement
216            CALL iom_open('bfr_coef.nc',inum)
217            CALL iom_get (inum, jpdom_data, 'bfr_coef',bfrcoef2d,1) ! bfrcoef2d is used as tmp array
218            CALL iom_close(inum)
219            bfrcoef2d(:,:)= rn_bfri2 * ( 1 + rn_bfrien * bfrcoef2d(:,:) )
220         ENDIF
221         !
222      CASE DEFAULT
223         IF(lwp) WRITE(ctmp1,*) '         bad flag value for nn_bfr = ', nn_bfr
224         CALL ctl_stop( ctmp1 )
225         !
226      END SELECT
227      IF(lwp) WRITE(numout,*) '      implicit bottom friction switch                ln_bfrimp  = ', ln_bfrimp
228      !
229      ! Basic stability check on bottom friction coefficient
230      !
231      ictu = 0               ! counter for stability criterion breaches at U-pts
232      ictv = 0               ! counter for stability criterion breaches at V-pts
233      zminbfr =  1.e10_wp    ! initialise tracker for minimum of bottom friction coefficient
234      zmaxbfr = -1.e10_wp    ! initialise tracker for maximum of bottom friction coefficient
235      !
236#  if defined key_vectopt_loop
237      DO jj = 1, 1
238!CDIR NOVERRCHK
239         DO ji = jpi+2, jpij-jpi-1   ! vector opt. (forced unrolling)
240#  else
241!CDIR NOVERRCHK
242      DO jj = 2, jpjm1
243!CDIR NOVERRCHK
244         DO ji = 2, jpim1
245#  endif
246             ikbu = mbku(ji,jj)       ! deepest ocean level at u- and v-points
247             ikbv = mbkv(ji,jj)
248             zfru = 0.5 * fse3u(ji,jj,ikbu) / rdt
249             zfrv = 0.5 * fse3v(ji,jj,ikbv) / rdt
250             IF( ABS( bfrcoef2d(ji,jj) ) > zfru ) THEN
251                IF( ln_ctl ) THEN
252                   WRITE(numout,*) 'BFR ', narea, nimpp+ji, njmpp+jj, ikbu
253                   WRITE(numout,*) 'BFR ', ABS( bfrcoef2d(ji,jj) ), zfru
254                ENDIF
255                ictu = ictu + 1
256             ENDIF
257             IF( ABS( bfrcoef2d(ji,jj) ) > zfrv ) THEN
258                 IF( ln_ctl ) THEN
259                     WRITE(numout,*) 'BFR ', narea, nimpp+ji, njmpp+jj, ikbv
260                     WRITE(numout,*) 'BFR ', bfrcoef2d(ji,jj), zfrv
261                 ENDIF
262                 ictv = ictv + 1
263             ENDIF
264             zminbfr = MIN(  zminbfr, MIN( zfru, ABS( bfrcoef2d(ji,jj) ) )  )
265             zmaxbfr = MAX(  zmaxbfr, MIN( zfrv, ABS( bfrcoef2d(ji,jj) ) )  )
266         END DO
267      END DO
268      IF( lk_mpp ) THEN
269         CALL mpp_sum( ictu )
270         CALL mpp_sum( ictv )
271         CALL mpp_min( zminbfr )
272         CALL mpp_max( zmaxbfr )
273      ENDIF
274      IF( lwp .AND. ictu + ictv > 0 ) THEN
275         WRITE(numout,*) ' Bottom friction stability check failed at ', ictu, ' U-points '
276         WRITE(numout,*) ' Bottom friction stability check failed at ', ictv, ' V-points '
277         WRITE(numout,*) ' Bottom friction coefficient now ranges from: ', zminbfr, ' to ', zmaxbfr
278         WRITE(numout,*) ' Bottom friction coefficient will be reduced where necessary'
279      ENDIF
280      !
281      IF( nn_timing == 1 )  CALL timing_stop('zdf_bfr_init')
282      !
283   END SUBROUTINE zdf_bfr_init
284
285   !!======================================================================
286END MODULE zdfbfr
Note: See TracBrowser for help on using the repository browser.