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/UKMO/dev_isf_divg_corr_GO6_package_r9385/NEMOGCM/NEMO/OPA_SRC/DYN – NEMO

source: branches/UKMO/dev_isf_divg_corr_GO6_package_r9385/NEMOGCM/NEMO/OPA_SRC/DYN/divcur.F90 @ 9630

Last change on this file since 9630 was 9630, checked in by antsia, 6 years ago

Code for divergence correction

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