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 @ 2636

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

dynamic mem: #785 ; move ctl_stop & warn in lib_mpp to avoid a circular dependency + ctl_stop improvment

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