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.
dynspg_fsc_atsk.F90 in trunk/NEMO/OPA_SRC/DYN – NEMO

source: trunk/NEMO/OPA_SRC/DYN/dynspg_fsc_atsk.F90 @ 313

Last change on this file since 313 was 258, checked in by opalod, 19 years ago

nemo_v1_update_004 : CT : Integration of the control print option for debugging work

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 18.2 KB
Line 
1MODULE dynspg_fsc_atsk
2   !!======================================================================
3   !!                  ***  MODULE  dynspg_fsc_atsk  ***
4   !! Ocean dynamics:  surface pressure gradient trend
5   !!======================================================================
6#if ( defined key_dynspg_fsc && defined key_autotasking )   ||   defined key_esopa
7   !!----------------------------------------------------------------------
8   !!   'key_dynspg_fsc' & 'key_autotasking'   free surface cst volume
9   !!                                                   j-k-i loop (j-slab)
10   !!----------------------------------------------------------------------
11   !!   dyn_spg_fsc_atsk : Update the momentum trend with the surface pressure
12   !!                      gradient for the free surf. constant volume case
13   !!                      with auto-tasking (j-slab) (no vectior opt.)
14   !!----------------------------------------------------------------------
15   !!   OPA 9.0 , LOCEAN-IPSL (2005)
16   !! $Header$
17   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
18   !!----------------------------------------------------------------------
19   !! * Modules used
20   USE oce             ! ocean dynamics and tracers
21   USE dom_oce         ! ocean space and time domain
22   USE zdf_oce         ! ocean vertical physics
23   USE trdmod          ! ocean dynamics trends
24   USE trdmod_oce      ! ocean variables trends
25   USE in_out_manager  ! I/O manager
26   USE phycst          ! physical constant
27   USE ocesbc          ! Ocean Surface Boundary condition
28   USE flxrnf          ! ocean runoffs
29   USE sol_oce         ! ocean elliptic solver
30   USE solpcg          ! preconditionned conjugate gradient solver
31   USE solsor          ! Successive Over-relaxation solver
32   USE solfet          ! FETI solver
33   USE obc_oce         ! Lateral open boundary condition
34   USE obcdyn          ! ocean open boundary condition (obc_dyn routines)
35   USE obcvol          ! ocean open boundary condition (obc_vol routines)
36   USE lib_mpp         ! distributed memory computing library
37   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
38   USE cla_dynspg      ! cross land advection
39   USE prtctl          ! Print control
40
41   IMPLICIT NONE
42   PRIVATE
43
44   !! * Accessibility
45   PUBLIC dyn_spg_fsc_atsk        ! routine called by step.F90
46
47   !! * Shares module variables
48   LOGICAL, PUBLIC, PARAMETER ::   lk_dynspg_fsc_tsk = .TRUE.    !: free surf. cst vol. flag
49
50   !! * Substitutions
51#  include "domzgr_substitute.h90"
52   !!----------------------------------------------------------------------
53   !!   OPA 9.0 , LOCEAN-IPSL (2005)
54   !! $Header$
55   !! This software is governed by the CeCILL licence see modipsl/doc/NEMO_CeCILL.txt
56   !!----------------------------------------------------------------------
57
58CONTAINS
59
60   SUBROUTINE dyn_spg_fsc_atsk( kt, kindic )
61      !!----------------------------------------------------------------------
62      !!                  ***  routine dyn_spg_fsc_atsk  ***
63      !!
64      !! ** Purpose :   Compute the now trend due to the surface pressure
65      !!      gradient for free surface formulation with a constant ocean
66      !!      volume case, add it to the general trend of momentum equation.
67      !!
68      !! ** Method  :   Free surface formulation. The surface pressure gradient
69      !!      is given by:
70      !!         spgu = 1/rau0 d/dx(ps) =  1/e1u di( etn + rnu btda )
71      !!         spgv = 1/rau0 d/dy(ps) =  1/e2v dj( etn + rnu btda )
72      !!      where etn is the free surface elevation and btda is the after
73      !!      of the free surface elevation
74      !!       -1- compute the after sea surface elevation from the cinematic
75      !!      surface boundary condition:
76      !!              zssha = sshb + 2 rdt ( wn - emp )
77      !!           Time filter applied on now sea surface elevation to avoid
78      !!      the divergence of two consecutive time-steps and swap of free
79      !!      surface arrays to start the next time step:
80      !!              sshb = sshn + atfp * [ sshb + zssha - 2 sshn ]
81      !!              sshn = zssha
82      !!       -2- evaluate the surface presure trend (including the addi-
83      !!      tional force) in three steps:
84      !!        a- compute the right hand side of the elliptic equation:
85      !!            gcb = 1/(e1t e2t) [ di(e2u spgu) + dj(e1v spgv) ]
86      !!         where (spgu,spgv) are given by:
87      !!            spgu = vertical sum[ e3u (ub+ 2 rdt ua ) ]
88      !!                 - grav 2 rdt hu /e1u di[sshn + emp]
89      !!            spgv = vertical sum[ e3v (vb+ 2 rdt va) ]
90      !!                 - grav 2 rdt hv /e2v dj[sshn + emp]
91      !!         and define the first guess from previous computation :
92      !!            zbtd = btda
93      !!            btda = 2 zbtd - btdb
94      !!            btdb = zbtd
95      !!        b- compute the relative accuracy to be reached by the
96      !!         iterative solver
97      !!        c- apply the solver by a call to sol... routine
98      !!       -3- compute and add the free surface pressure gradient inclu-
99      !!      ding the additional force used to stabilize the equation.
100      !!      several slabs used ('key-autotasking')
101      !!
102      !! ** Action : - Update (ua,va) with the surf. pressure gradient trend
103      !!             - Save the trends in (ztdua,ztdva) ('key_trddyn')
104      !!
105      !! References :
106      !!      Roullet and Madec 1999, JGR.
107      !!
108      !! History :
109      !!        !  98-05 (G. Roullet)  Original code
110      !!        !  98-10 (G. Madec, M. Imbard)  release 8.2
111      !!   8.5  !  02-08 (G. Madec)  F90: Free form and module
112      !!        !  02-11 (C. Talandier, A-M Treguier) Open boundaries
113      !!   9.0  !  04-08 (C. Talandier) New trends organization
114      !!---------------------------------------------------------------------
115      !! * Modules used     
116      USE oce, ONLY :    ztdua => ta,      & ! use ta as 3D workspace   
117                         ztdva => sa         ! use sa as 3D workspace   
118
119      !! * Arguments
120      INTEGER, INTENT( in ) ::   kt          ! ocean time-step index
121      INTEGER, INTENT( out ) ::   kindic     ! solver convergence flag
122                                             ! if the solver doesn t converge
123                                             ! the flag is < 0
124      !! * Local declarations
125      INTEGER  ::   ji, jj, jk               ! dummy loop indices
126      REAL(wp) ::   &              ! temporary scalars
127         z2dt, z2dtg, zraur, znugdt, znurau,   &
128         zssha, zspgu, zspgv,                  &
129         zgcb, zbtd, ztdgu, ztdgv, zgwgt
130      !!----------------------------------------------------------------------
131
132      IF( kt == nit000 ) THEN
133         IF(lwp) WRITE(numout,*)
134         IF(lwp) WRITE(numout,*) 'dyn_spg_fsc_atsk : surface pressure gradient trend'
135         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~~~  (free surface constant volume, autotasking case)'
136
137         ! set to zero free surface specific arrays
138         spgu(:,:) = 0.e0      ! surface pressure gradient (i-direction)
139         spgv(:,:) = 0.e0      ! surface pressure gradient (j-direction)
140      ENDIF
141
142      ! 0. Local constant initialization
143      ! --------------------------------
144      ! time step: leap-frog
145      z2dt = 2. * rdt
146      ! time step: Euler if restart from rest
147      IF( neuler == 0 .AND. kt == nit000 ) z2dt = rdt
148      ! coefficients
149      z2dtg  = grav * z2dt
150      zraur  = 1. / rauw
151      znugdt =  rnu * grav * z2dt
152      znurau =  znugdt * zraur
153      IF( lk_mpp ) THEN
154         ! Mpp : export boundary values of to neighboring processors
155         !!bug ???  why only in mpp?  is it really needed???
156         CALL lbc_lnk( ua, 'U' , -1. )
157         CALL lbc_lnk( va, 'V' , -1. )
158      ENDIF
159
160      !                                                ! ===============
161      DO jj = 2, jpjm1                                 !  Vertical slab
162         !                                             ! ===============
163         ! 1. Surface pressure gradient (now)
164         ! ----------------------------
165         DO ji = 2, jpim1
166            zspgu =   - grav * ( sshn(ji+1,jj) - sshn(ji,jj) ) / e1u(ji,jj)
167            zspgv =   - grav * ( sshn(ji,jj+1) - sshn(ji,jj) ) / e2v(ji,jj)
168            spgu(ji,jj) = zspgu
169            spgv(ji,jj) = zspgv
170         END DO 
171
172         ! 2. Add the surface pressure trend to the general trend
173         ! ------------------------------------------------------
174         DO jk = 1, jpkm1
175            DO ji = 2, jpim1
176               ua(ji,jj,jk) = ua(ji,jj,jk) + spgu(ji,jj)
177               va(ji,jj,jk) = va(ji,jj,jk) + spgv(ji,jj)
178            END DO
179         END DO
180         !                                             ! ===============
181      END DO                                           !   End of slab
182      !                                                ! ===============
183
184      ! Save the surface pressure gradient trend for diagnostics
185      IF( l_trddyn )   THEN
186         DO jk = 1, jpkm1
187            ztdua(:,:,jk) = spgu(:,:) 
188            ztdva(:,:,jk) = spgv(:,:) 
189         END DO
190      ENDIF
191
192      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
193
194      !                                                ! ===============
195      DO jj = 2, jpjm1                                 !  Vertical slab
196         !                                             ! ===============
197
198         ! 1. Evaluate the masked next velocity
199         ! ------------------------------------
200         !     (effect of the additional force not included)
201
202         DO jk = 1, jpkm1
203            DO ji = 2, jpim1
204               ua(ji,jj,jk) = ( ub(ji,jj,jk) + z2dt * ua(ji,jj,jk) ) * umask(ji,jj,jk)
205               va(ji,jj,jk) = ( vb(ji,jj,jk) + z2dt * va(ji,jj,jk) ) * vmask(ji,jj,jk)
206            END DO
207         END DO
208
209         !                                             ! ===============
210      END DO                                           !   End of slab
211      !                                                ! ===============
212
213#if defined key_obc
214         ! Update velocities on each open boundary with the radiation algorithm
215         CALL obc_dyn( kt )
216         ! Correction of the barotropic componant velocity to control the volume of the system
217         CALL obc_vol( kt )
218#endif
219#if defined key_orca_r2
220      IF( n_cla == 1 )   CALL dyn_spg_cla( kt )      ! Cross Land Advection (Update (ua,va))
221#endif
222
223      !                                                ! ===============
224      DO jj = 2, jpjm1                                 !  Vertical slab
225         !                                             ! ===============
226
227         ! 2. compute the next vertically averaged velocity
228         ! ------------------------------------------------
229         !     (effect of the additional force not included)
230         ! initialize to zero
231         DO ji = 2, jpim1
232            spgu(ji,jj) = 0.e0
233            spgv(ji,jj) = 0.e0
234         END DO
235
236         ! vertical sum
237         DO jk = 1, jpk
238            DO ji = 2, jpim1
239               spgu(ji,jj) = spgu(ji,jj) + fse3u(ji,jj,jk) * ua(ji,jj,jk)
240               spgv(ji,jj) = spgv(ji,jj) + fse3v(ji,jj,jk) * va(ji,jj,jk)
241            END DO
242         END DO
243
244         ! transport: multiplied by the horizontal scale factor
245         DO ji = 2, jpim1
246            spgu(ji,jj) = spgu(ji,jj) * e2u(ji,jj)
247            spgv(ji,jj) = spgv(ji,jj) * e1v(ji,jj)
248         END DO
249
250         !                                             ! ===============
251      END DO                                           !   End of slab
252      !                                                ! ===============
253
254      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
255     
256      ! Boundary conditions on (spgu,spgv)
257      CALL lbc_lnk( spgu, 'U', -1. )
258      CALL lbc_lnk( spgv, 'V', -1. )
259
260      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
261
262      ! 3. Right hand side of the elliptic equation and first guess
263      ! -----------------------------------------------------------
264      DO jj = 2, jpjm1
265         DO ji = 2, jpim1
266            ! Divergence of the after vertically averaged velocity
267            zgcb =  spgu(ji,jj) - spgu(ji-1,jj)   &
268                  + spgv(ji,jj) - spgv(ji,jj-1)
269            gcb(ji,jj) = gcdprc(ji,jj) * zgcb
270            ! First guess of the after barotropic transport divergence
271            zbtd = gcx(ji,jj)
272            gcx (ji,jj) = 2. * zbtd   - gcxb(ji,jj)
273            gcxb(ji,jj) =      zbtd
274         END DO
275      END DO
276
277      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
278     
279      ! 4. Relative precision (computation on one processor)
280      ! ---------------------
281      rnorme =0.
282      DO jj = 1, jpj
283         DO ji = 1, jpi
284            zgwgt  = gcdmat(ji,jj) * gcb(ji,jj)
285            rnorme = rnorme + gcb(ji,jj) * zgwgt
286         END DO
287      END DO
288      IF( lk_mpp )   CALL mpp_sum( rnorme )   ! sum over the global domain
289
290      epsr = eps * eps * rnorme
291      ncut = 0
292      ! if rnorme is 0, the solution is 0, the solver isn't called
293      IF( rnorme == 0.e0 ) THEN
294         gcx(:,:) = 0.e0
295         res   = 0.e0
296         niter = 0
297         ncut  = 999
298      ENDIF
299     
300      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
301     
302      ! 5. Evaluate the next transport divergence
303      ! -----------------------------------------
304      !    Iterarive solver for the elliptic equation (except IF sol.=0)
305      !    (output in gcx with boundary conditions applied)
306      kindic = 0
307      IF( ncut == 0 ) THEN
308         IF( nsolv == 1 ) THEN         ! diagonal preconditioned conjuguate gradient
309            CALL sol_pcg( kindic )
310         ELSEIF( nsolv == 2 ) THEN     ! successive-over-relaxation
311            CALL sol_sor( kindic )
312         ELSEIF( nsolv == 3 ) THEN     ! FETI solver
313            CALL sol_fet( kindic )
314         ELSE                          ! e r r o r in nsolv namelist parameter
315            IF(lwp) WRITE(numout,cform_err)
316            IF(lwp) WRITE(numout,*) ' dyn_spg_fsc_atsk : e r r o r, nsolv = 1, 2 or 3'
317            IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~~~~~~                not = ', nsolv
318            nstop = nstop + 1
319         ENDIF
320      ENDIF
321
322      !,,,,,,,,,,,,,,,,,,,,,,,,,,,,,synchro,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
323
324      !                                                ! ===============
325      DO jj = 2, jpjm1                                 !  Vertical slab
326         !                                             ! ===============
327         
328         ! 6. Transport divergence gradient multiplied by z2dt
329         ! -----------------------------------------------====
330         DO ji = 2, jpim1
331            ! trend of Transport divergence gradient
332            ztdgu = znugdt * (gcx(ji+1,jj  ) - gcx(ji,jj) ) / e1u(ji,jj)
333            ztdgv = znugdt * (gcx(ji  ,jj+1) - gcx(ji,jj) ) / e2v(ji,jj)
334            ! multiplied by z2dt
335#if defined key_obc
336            ! caution : grad D = 0 along open boundaries
337            spgu(ji,jj) = z2dt * ztdgu * obcumask(ji,jj)
338            spgv(ji,jj) = z2dt * ztdgv * obcvmask(ji,jj)
339#else
340            spgu(ji,jj) = z2dt * ztdgu
341            spgv(ji,jj) = z2dt * ztdgv
342#endif
343         END DO
344         
345         ! 7.  Add the trends multiplied by z2dt to the after velocity
346         ! -----------------------------------------------------------
347         !     ( c a u t i o n : (ua,va) here are the after velocity not the
348         !                       trend, the leap-frog time stepping will not
349         !                       be done in dynnxt.F routine)
350         DO jk = 1, jpkm1
351            DO ji = 2, jpim1
352               ua(ji,jj,jk) = (ua(ji,jj,jk) + spgu(ji,jj)) * umask(ji,jj,jk)
353               va(ji,jj,jk) = (va(ji,jj,jk) + spgv(ji,jj)) * vmask(ji,jj,jk)
354            END DO
355         END DO
356
357         IF(ln_ctl) THEN         ! print sum trends (used for debugging)
358            CALL prt_ctl(tab3d_1=ua, clinfo1=' spg  - Ua: ', mask1=umask, &
359               &         tab3d_2=va, clinfo2=' Va: ', mask2=vmask)
360         ENDIF
361
362         ! 8. Sea surface elevation time stepping
363         ! --------------------------------------
364         ! Euler (forward) time stepping, no time filter
365         IF( neuler == 0 .AND. kt == nit000 ) THEN
366            DO ji = 1, jpi
367               ! after free surface elevation
368               zssha = sshb(ji,jj) + rdt * ( wn(ji,jj,1) - emp(ji,jj) * zraur ) * tmask(ji,jj,1)
369               ! swap of arrays
370               sshb(ji,jj) = sshn(ji,jj)
371               sshn(ji,jj) = zssha
372            END DO
373         ELSE
374            ! Leap-frog time stepping and time filter
375            DO ji = 1, jpi
376               ! after free surface elevation
377               zssha = sshb(ji,jj) + z2dt * ( wn(ji,jj,1) - emp(ji,jj) * zraur ) * tmask(ji,jj,1)
378               ! time filter and array swap
379               sshb(ji,jj) = atfp * ( sshb(ji,jj) + zssha ) + atfp1 * sshn(ji,jj)
380               sshn(ji,jj) = zssha
381            END DO
382         ENDIF
383         !                                             ! ===============
384      END DO                                           !   End of slab
385      !                                                ! ===============
386
387      ! save the surface pressure gradient trends for diagnostic
388      ! momentum trends
389      IF( l_trddyn )   THEN
390         DO jk = 1, jpkm1
391            ztdua(:,:,jk) = ztdua(:,:,jk) + spgu(:,:)/z2dt 
392            ztdva(:,:,jk) = ztdva(:,:,jk) + spgv(:,:)/z2dt 
393         END DO
394
395         CALL trd_mod(ztdua, ztdva, jpdtdspg, 'DYN', kt)
396      ENDIF
397     
398      !Boundary conditions on sshn
399      CALL lbc_lnk( sshn, 'T', 1. )
400
401      IF(ln_ctl) THEN         ! print sum trends (used for debugging)
402         CALL prt_ctl(tab2d_1=sshn, clinfo1=' spg  - ssh: ', mask1=tmask)
403      ENDIF
404
405
406   END SUBROUTINE dyn_spg_fsc_atsk
407
408#else
409   !!----------------------------------------------------------------------
410   !!   Default case :                                         Empty module
411   !!----------------------------------------------------------------------
412   LOGICAL, PUBLIC, PARAMETER ::   lk_dynspg_fsc_tsk = .FALSE.   !: free surf. cst vol. flag
413CONTAINS
414   SUBROUTINE dyn_spg_fsc_atsk( kt, kindic )      ! Empty module
415      WRITE(*,*) 'dyn_spg_fsc_atsk: You should not have seen this print! error?', kt, kindic
416   END SUBROUTINE dyn_spg_fsc_atsk
417#endif
418   
419   !!======================================================================
420END MODULE dynspg_fsc_atsk
Note: See TracBrowser for help on using the repository browser.