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/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/DYN – NEMO

source: branches/2011/dev_NEMO_MERGE_2011/NEMOGCM/NEMO/OPA_SRC/DYN/divcur.F90 @ 3194

Last change on this file since 3194 was 3194, checked in by smasson, 13 years ago

bugfix in work array size

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