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.
divcur.F90 in branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DYN – NEMO

source: branches/dev_r2586_dynamic_mem/NEMOGCM/NEMO/OPA_SRC/DYN/divcur.F90 @ 2625

Last change on this file since 2625 was 2625, checked in by gm, 13 years ago

dynamic mem: #785 ; OPA_SRC mpp compilation: suppression of the USE in_out_manager in lib_mpp + style in DYN

  • Property svn:keywords set to Id
File size: 17.0 KB
Line 
1MODULE divcur
2   !!==============================================================================
3   !!                       ***  MODULE  divcur  ***
4   !! Ocean diagnostic variable : horizontal divergence and relative vorticity
5   !!==============================================================================
6   !! History :  OPA  ! 1987-06  (P. Andrich, D. L Hostis)  Original code
7   !!            4.0  ! 1991-11  (G. Madec)
8   !!            6.0  ! 1993-03  (M. Guyon)  symetrical conditions
9   !!            7.0  ! 1996-01  (G. Madec)  s-coordinates
10   !!            8.0  ! 1997-06  (G. Madec)  lateral boundary cond., lbc
11   !!            8.1  ! 1997-08  (J.M. Molines)  Open boundaries
12   !!            8.2  ! 2000-03  (G. Madec)  no slip accurate
13   !!  NEMO      1.0  ! 2002-09  (G. Madec, E. Durand)  Free form, F90
14   !!             -   ! 2005-01  (J. Chanut) Unstructured open boundaries
15   !!             -   ! 2003-08  (G. Madec)  merged of cur and div, free form, F90
16   !!             -   ! 2005-01  (J. Chanut, A. Sellar) unstructured open boundaries
17   !!            3.3  ! 2010-09  (D.Storkey and E.O'Dea) bug fixes for BDY module
18   !!             -   ! 2010-10  (R. Furner, G. Madec) runoff and cla added directly here
19   !!----------------------------------------------------------------------
20
21   !!----------------------------------------------------------------------
22   !!   div_cur    : Compute the horizontal divergence and relative
23   !!                vorticity fields
24   !!----------------------------------------------------------------------
25   USE oce             ! ocean dynamics and tracers
26   USE dom_oce         ! ocean space and time domain
27   USE sbc_oce, ONLY : ln_rnf   ! surface boundary condition: ocean
28   USE sbcrnf          ! river runoff
29   USE obc_oce         ! ocean lateral open boundary condition
30   USE cla             ! cross land advection             (cla_div routine)
31   USE in_out_manager  ! I/O manager
32   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
33
34   IMPLICIT NONE
35   PRIVATE
36
37   PUBLIC   div_cur    ! routine called by step.F90 and istate.F90
38
39   !! * Substitutions
40#  include "domzgr_substitute.h90"
41#  include "vectopt_loop_substitute.h90"
42   !!----------------------------------------------------------------------
43   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
44   !! $Id$
45   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
46   !!----------------------------------------------------------------------
47CONTAINS
48
49#if defined key_noslip_accurate
50   !!----------------------------------------------------------------------
51   !!   'key_noslip_accurate'   2nd order interior + 4th order at the coast
52   !!----------------------------------------------------------------------
53
54   SUBROUTINE div_cur( kt )
55      !!----------------------------------------------------------------------
56      !!                  ***  ROUTINE div_cur  ***
57      !!
58      !! ** Purpose :   compute the horizontal divergence and the relative
59      !!              vorticity at before and now time-step
60      !!
61      !! ** Method  : I.  divergence :
62      !!         - save the divergence computed at the previous time-step
63      !!      (note that the Asselin filter has not been applied on hdivb)
64      !!         - compute the now divergence given by :
65      !!         hdivn = 1/(e1t*e2t*e3t) ( di[e2u*e3u un] + dj[e1v*e3v vn] )
66      !!      correct hdiv with runoff inflow (div_rnf) and cross land flow (div_cla)
67      !!              II. vorticity :
68      !!         - save the curl computed at the previous time-step
69      !!            rotb = rotn
70      !!      (note that the Asselin time filter has not been applied to rotb)
71      !!         - compute the now curl in tensorial formalism:
72      !!            rotn = 1/(e1f*e2f) ( di[e2v vn] - dj[e1u un] )
73      !!         - Coastal boundary condition: 'key_noslip_accurate' defined,
74      !!      the no-slip boundary condition is computed using Schchepetkin
75      !!      and O'Brien (1996) scheme (i.e. 4th order at the coast).
76      !!      For example, along east coast, the one-sided finite difference
77      !!      approximation used for di[v] is:
78      !!         di[e2v vn] =  1/(e1f*e2f) * ( (e2v vn)(i) + (e2v vn)(i-1) + (e2v vn)(i-2) )
79      !!
80      !! ** Action  : - update hdivb, hdivn, the before & now hor. divergence
81      !!              - update rotb , rotn , the before & now rel. vorticity
82      !!----------------------------------------------------------------------
83      INTEGER, INTENT(in) ::   kt   ! ocean time-step index
84      !
85      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   zwu   ! specific 2D workspace
86      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:) ::   zwv   ! specific 2D workspace
87      !
88      INTEGER ::   ji, jj, jk, jl           ! dummy loop indices
89      INTEGER ::   ii, ij, ijt, iju, ierr   ! local integer
90      REAL(wp) ::  zraur, zdep              ! local scalar
91      !!----------------------------------------------------------------------
92
93      IF( kt == nit000 ) THEN
94         IF(lwp) WRITE(numout,*)
95         IF(lwp) WRITE(numout,*) 'div_cur : horizontal velocity divergence and relative vorticity'
96         IF(lwp) WRITE(numout,*) '~~~~~~~   NOT optimal for auto-tasking case'
97         !
98         ALLOCATE( zwu( jpi, 1:jpj+2) , zwv(-1:jpi+2, jpj) , Stat=ierr )
99         IF( lk_mpp    )   CALL mpp_sum( ierr )
100         IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'div_cur : unable to allocate arrays' )
101      ENDIF
102
103      !                                                ! ===============
104      DO jk = 1, jpkm1                                 ! Horizontal slab
105         !                                             ! ===============
106         !
107         hdivb(:,:,jk) = hdivn(:,:,jk)    ! time swap of div arrays
108         rotb (:,:,jk) = rotn (:,:,jk)    ! time swap of rot arrays
109         !
110         !                                             ! --------
111         ! Horizontal divergence                       !   div
112         !                                             ! --------
113         DO jj = 2, jpjm1
114            DO ji = fs_2, fs_jpim1   ! vector opt.
115               hdivn(ji,jj,jk) =   &
116                  (  e2u(ji,jj)*fse3u(ji,jj,jk) * un(ji,jj,jk) - e2u(ji-1,jj  )*fse3u(ji-1,jj  ,jk) * un(ji-1,jj  ,jk)       &
117                   + e1v(ji,jj)*fse3v(ji,jj,jk) * vn(ji,jj,jk) - e1v(ji  ,jj-1)*fse3v(ji  ,jj-1,jk) * vn(ji  ,jj-1,jk)  )    &
118                  / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
119            END DO
120         END DO
121
122#if defined key_obc
123         IF( Agrif_Root() ) THEN
124            ! open boundaries (div must be zero behind the open boundary)
125            !  mpp remark: The zeroing of hdivn can probably be extended to 1->jpi/jpj for the correct row/column
126            IF( lp_obc_east  )   hdivn(nie0p1:nie1p1,nje0  :nje1  ,jk) = 0.e0      ! east
127            IF( lp_obc_west  )   hdivn(niw0  :niw1  ,njw0  :njw1  ,jk) = 0.e0      ! west
128            IF( lp_obc_north )   hdivn(nin0  :nin1  ,njn0p1:njn1p1,jk) = 0.e0      ! north
129            IF( lp_obc_south )   hdivn(nis0  :nis1  ,njs0  :njs1  ,jk) = 0.e0      ! south
130         ENDIF
131#endif         
132         IF( .NOT. AGRIF_Root() ) THEN
133            IF ((nbondi ==  1).OR.(nbondi == 2)) hdivn(nlci-1 , :     ,jk) = 0.e0      ! east
134            IF ((nbondi == -1).OR.(nbondi == 2)) hdivn(2      , :     ,jk) = 0.e0      ! west
135            IF ((nbondj ==  1).OR.(nbondj == 2)) hdivn(:      ,nlcj-1 ,jk) = 0.e0      ! north
136            IF ((nbondj == -1).OR.(nbondj == 2)) hdivn(:      ,2      ,jk) = 0.e0      ! south
137         ENDIF
138
139         !                                             ! --------
140         ! relative vorticity                          !   rot
141         !                                             ! --------
142         ! contravariant velocity (extended for lateral b.c.)
143         ! inside the model domain
144         DO jj = 1, jpj
145            DO ji = 1, jpi
146               zwu(ji,jj) = e1u(ji,jj) * un(ji,jj,jk)
147               zwv(ji,jj) = e2v(ji,jj) * vn(ji,jj,jk)
148            END DO 
149         END DO 
150 
151         ! East-West boundary conditions
152         IF( nperio == 1 .OR. nperio == 4 .OR. nperio == 6) THEN
153            zwv(  0  ,:) = zwv(jpi-2,:)
154            zwv( -1  ,:) = zwv(jpi-3,:)
155            zwv(jpi+1,:) = zwv(  3  ,:)
156            zwv(jpi+2,:) = zwv(  4  ,:)
157         ELSE
158            zwv(  0  ,:) = 0.e0
159            zwv( -1  ,:) = 0.e0
160            zwv(jpi+1,:) = 0.e0
161            zwv(jpi+2,:) = 0.e0
162         ENDIF
163
164         ! North-South boundary conditions
165         IF( nperio == 3 .OR. nperio == 4 ) THEN
166            ! north fold ( Grid defined with a T-point pivot) ORCA 2 degre
167            zwu(jpi,jpj+1) = 0.e0
168            zwu(jpi,jpj+2) = 0.e0
169            DO ji = 1, jpi-1
170               iju = jpi - ji + 1
171               zwu(ji,jpj+1) = - zwu(iju,jpj-3)
172               zwu(ji,jpj+2) = - zwu(iju,jpj-4)
173            END DO
174         ELSEIF( nperio == 5 .OR. nperio == 6 ) THEN
175            ! north fold ( Grid defined with a F-point pivot) ORCA 0.5 degre\
176            zwu(jpi,jpj+1) = 0.e0
177            zwu(jpi,jpj+2) = 0.e0
178            DO ji = 1, jpi-1
179               iju = jpi - ji
180               zwu(ji,jpj  ) = - zwu(iju,jpj-1)
181               zwu(ji,jpj+1) = - zwu(iju,jpj-2)
182               zwu(ji,jpj+2) = - zwu(iju,jpj-3)
183            END DO
184            DO ji = -1, jpi+2
185               ijt = jpi - ji + 1
186               zwv(ji,jpj) = - zwv(ijt,jpj-2)
187            END DO
188            DO ji = jpi/2+1, jpi+2
189               ijt = jpi - ji + 1
190               zwv(ji,jpjm1) = - zwv(ijt,jpjm1)
191            END DO
192         ELSE
193            ! closed
194            zwu(:,jpj+1) = 0.e0
195            zwu(:,jpj+2) = 0.e0
196         ENDIF
197
198         ! relative vorticity (vertical component of the velocity curl)
199         DO jj = 1, jpjm1
200            DO ji = 1, fs_jpim1   ! vector opt.
201               rotn(ji,jj,jk) = (  zwv(ji+1,jj  ) - zwv(ji,jj)      &
202                  &              - zwu(ji  ,jj+1) + zwu(ji,jj)  ) * fmask(ji,jj,jk) / ( e1f(ji,jj)*e2f(ji,jj) )
203            END DO
204         END DO
205
206         ! second order accurate scheme along straight coast
207         DO jl = 1, npcoa(1,jk)
208            ii = nicoa(jl,1,jk)
209            ij = njcoa(jl,1,jk)
210            rotn(ii,ij,jk) = 1. / ( e1f(ii,ij) * e2f(ii,ij) )   &
211                           * ( + 4. * zwv(ii+1,ij) - zwv(ii+2,ij) + 0.2 * zwv(ii+3,ij) )
212         END DO
213         DO jl = 1, npcoa(2,jk)
214            ii = nicoa(jl,2,jk)
215            ij = njcoa(jl,2,jk)
216            rotn(ii,ij,jk) = 1./(e1f(ii,ij)*e2f(ii,ij))   &
217               *(-4.*zwv(ii,ij)+zwv(ii-1,ij)-0.2*zwv(ii-2,ij))
218         END DO
219         DO jl = 1, npcoa(3,jk)
220            ii = nicoa(jl,3,jk)
221            ij = njcoa(jl,3,jk)
222            rotn(ii,ij,jk) = -1. / ( e1f(ii,ij)*e2f(ii,ij) )   &
223               * ( +4. * zwu(ii,ij+1) - zwu(ii,ij+2) + 0.2 * zwu(ii,ij+3) )
224         END DO
225         DO jl = 1, npcoa(4,jk)
226            ii = nicoa(jl,4,jk)
227            ij = njcoa(jl,4,jk)
228            rotn(ii,ij,jk) = -1. / ( e1f(ii,ij)*e2f(ii,ij) )   &
229               * ( -4. * zwu(ii,ij) + zwu(ii,ij-1) - 0.2 * zwu(ii,ij-2) )
230         END DO
231         !                                             ! ===============
232      END DO                                           !   End of slab
233      !                                                ! ===============
234
235      IF( ln_rnf      )   CALL sbc_rnf_div( hdivn )          ! runoffs (update hdivn field)
236      IF( nn_cla == 1 )   CALL cla_div    ( kt )             ! Cross Land Advection (Update Hor. divergence)
237     
238      ! 4. Lateral boundary conditions on hdivn and rotn
239      ! ---------------------------------=======---======
240      CALL lbc_lnk( hdivn, 'T', 1. )   ;   CALL lbc_lnk( rotn , 'F', 1. )    ! lateral boundary cond. (no sign change)
241      !
242   END SUBROUTINE div_cur
243   
244#else
245   !!----------------------------------------------------------------------
246   !!   Default option                           2nd order centered schemes
247   !!----------------------------------------------------------------------
248
249   SUBROUTINE div_cur( kt )
250      !!----------------------------------------------------------------------
251      !!                  ***  ROUTINE div_cur  ***
252      !!                   
253      !! ** Purpose :   compute the horizontal divergence and the relative
254      !!      vorticity at before and now time-step
255      !!
256      !! ** Method  : - Divergence:
257      !!      - save the divergence computed at the previous time-step
258      !!      (note that the Asselin filter has not been applied on hdivb)
259      !!      - compute the now divergence given by :
260      !!         hdivn = 1/(e1t*e2t*e3t) ( di[e2u*e3u un] + dj[e1v*e3v vn] )
261      !!      correct hdiv with runoff inflow (div_rnf) and cross land flow (div_cla)
262      !!              - Relavtive Vorticity :
263      !!      - save the curl computed at the previous time-step (rotb = rotn)
264      !!      (note that the Asselin time filter has not been applied to rotb)
265      !!      - compute the now curl in tensorial formalism:
266      !!            rotn = 1/(e1f*e2f) ( di[e2v vn] - dj[e1u un] )
267      !!      Note: Coastal boundary condition: lateral friction set through
268      !!      the value of fmask along the coast (see dommsk.F90) and shlat
269      !!      (namelist parameter)
270      !!
271      !! ** Action  : - update hdivb, hdivn, the before & now hor. divergence
272      !!              - update rotb , rotn , the before & now rel. vorticity
273      !!----------------------------------------------------------------------
274      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
275      !
276      INTEGER  ::   ji, jj, jk          ! dummy loop indices
277      REAL(wp) ::  zraur, zdep
278      !!----------------------------------------------------------------------
279
280      IF( kt == nit000 ) THEN
281         IF(lwp) WRITE(numout,*)
282         IF(lwp) WRITE(numout,*) 'div_cur : horizontal velocity divergence and'
283         IF(lwp) WRITE(numout,*) '~~~~~~~   relative vorticity'
284      ENDIF
285
286      !                                                ! ===============
287      DO jk = 1, jpkm1                                 ! Horizontal slab
288         !                                             ! ===============
289         !
290         hdivb(:,:,jk) = hdivn(:,:,jk)    ! time swap of div arrays
291         rotb (:,:,jk) = rotn (:,:,jk)    ! time swap of rot arrays
292         !
293         !                                             ! --------
294         ! Horizontal divergence                       !   div
295         !                                             ! --------
296         DO jj = 2, jpjm1
297            DO ji = fs_2, fs_jpim1   ! vector opt.
298               hdivn(ji,jj,jk) =   &
299                  (  e2u(ji,jj)*fse3u(ji,jj,jk) * un(ji,jj,jk) - e2u(ji-1,jj)*fse3u(ji-1,jj,jk) * un(ji-1,jj,jk)       &
300                   + e1v(ji,jj)*fse3v(ji,jj,jk) * vn(ji,jj,jk) - e1v(ji,jj-1)*fse3v(ji,jj-1,jk) * vn(ji,jj-1,jk)  )    &
301                  / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )
302            END DO 
303         END DO 
304
305#if defined key_obc
306         IF( Agrif_Root() ) THEN
307            ! open boundaries (div must be zero behind the open boundary)
308            !  mpp remark: The zeroing of hdivn can probably be extended to 1->jpi/jpj for the correct row/column
309            IF( lp_obc_east  )   hdivn(nie0p1:nie1p1,nje0  :nje1  ,jk) = 0.e0      ! east
310            IF( lp_obc_west  )   hdivn(niw0  :niw1  ,njw0  :njw1  ,jk) = 0.e0      ! west
311            IF( lp_obc_north )   hdivn(nin0  :nin1  ,njn0p1:njn1p1,jk) = 0.e0      ! north
312            IF( lp_obc_south )   hdivn(nis0  :nis1  ,njs0  :njs1  ,jk) = 0.e0      ! south
313         ENDIF
314#endif         
315         IF( .NOT. AGRIF_Root() ) THEN
316            IF ((nbondi ==  1).OR.(nbondi == 2)) hdivn(nlci-1 , :     ,jk) = 0.e0      ! east
317            IF ((nbondi == -1).OR.(nbondi == 2)) hdivn(2      , :     ,jk) = 0.e0      ! west
318            IF ((nbondj ==  1).OR.(nbondj == 2)) hdivn(:      ,nlcj-1 ,jk) = 0.e0      ! north
319            IF ((nbondj == -1).OR.(nbondj == 2)) hdivn(:      ,2      ,jk) = 0.e0      ! south
320         ENDIF
321
322         !                                             ! --------
323         ! relative vorticity                          !   rot
324         !                                             ! --------
325         DO jj = 1, jpjm1
326            DO ji = 1, fs_jpim1   ! vector opt.
327               rotn(ji,jj,jk) = (  e2v(ji+1,jj  ) * vn(ji+1,jj  ,jk) - e2v(ji,jj) * vn(ji,jj,jk)    &
328                  &              - e1u(ji  ,jj+1) * un(ji  ,jj+1,jk) + e1u(ji,jj) * un(ji,jj,jk)  ) &
329                  &           * fmask(ji,jj,jk) / ( e1f(ji,jj) * e2f(ji,jj) )
330            END DO
331         END DO
332         !                                             ! ===============
333      END DO                                           !   End of slab
334      !                                                ! ===============
335
336      IF( ln_rnf      )   CALL sbc_rnf_div( hdivn )          ! runoffs (update hdivn field)
337      IF( nn_cla == 1 )   CALL cla_div    ( kt )             ! Cross Land Advection (update hdivn field)
338      !
339      CALL lbc_lnk( hdivn, 'T', 1. )   ;   CALL lbc_lnk( rotn , 'F', 1. )     ! lateral boundary cond. (no sign change)
340      !
341   END SUBROUTINE div_cur
342   
343#endif
344   !!======================================================================
345END MODULE divcur
Note: See TracBrowser for help on using the repository browser.