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.
trcnxt.F90 in branches/UKMO/r6232_collate_bgc_diagnostics/NEMOGCM/NEMO/TOP_SRC/TRP – NEMO

source: branches/UKMO/r6232_collate_bgc_diagnostics/NEMOGCM/NEMO/TOP_SRC/TRP/trcnxt.F90 @ 11134

Last change on this file since 11134 was 11134, checked in by jcastill, 5 years ago

Full set of changes as in the original branch

File size: 9.7 KB
Line 
1MODULE trcnxt
2   !!======================================================================
3   !!                       ***  MODULE  trcnxt  ***
4   !! Ocean passive tracers:  time stepping on passives tracers
5   !!======================================================================
6   !! History :  7.0  !  1991-11  (G. Madec)  Original code
7   !!                 !  1993-03  (M. Guyon)  symetrical conditions
8   !!                 !  1995-02  (M. Levy)   passive tracers
9   !!                 !  1996-02  (G. Madec & M. Imbard)  opa release 8.0
10   !!            8.0  !  1996-04  (A. Weaver)  Euler forward step
11   !!            8.2  !  1999-02  (G. Madec, N. Grima)  semi-implicit pressure grad.
12   !!  NEMO      1.0  !  2002-08  (G. Madec)  F90: Free form and module
13   !!                 !  2002-08  (G. Madec)  F90: Free form and module
14   !!                 !  2002-11  (C. Talandier, A-M Treguier) Open boundaries
15   !!                 !  2004-03  (C. Ethe) passive tracers
16   !!                 !  2007-02  (C. Deltel) Diagnose ML trends for passive tracers
17   !!            2.0  !  2006-02  (L. Debreu, C. Mazauric) Agrif implementation
18   !!            3.0  !  2008-06  (G. Madec)  time stepping always done in trazdf
19   !!            3.1  !  2009-02  (G. Madec, R. Benshila)  re-introduce the vvl option
20   !!            3.3  !  2010-06  (C. Ethe, G. Madec) Merge TRA-TRC
21   !!----------------------------------------------------------------------
22#if defined key_top
23   !!----------------------------------------------------------------------
24   !!   'key_top'                                                TOP models
25   !!----------------------------------------------------------------------
26   !!   trc_nxt     : time stepping on passive tracers
27   !!----------------------------------------------------------------------
28   USE oce_trc         ! ocean dynamics and tracers variables
29   USE trc             ! ocean passive tracers variables
30   USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
31   USE prtctl_trc      ! Print control for debbuging
32   USE trd_oce
33   USE trdtra
34   USE tranxt
35   USE trcbdy          ! BDY open boundaries
36   USE bdy_par, only: lk_bdy
37   USE iom
38# if defined key_agrif
39   USE agrif_top_interp
40# endif
41
42   IMPLICIT NONE
43   PRIVATE
44
45   PUBLIC   trc_nxt          ! routine called by step.F90
46   PUBLIC   trc_nxt_alloc    ! routine called by nemogcm.F90
47
48   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:) ::   r2dt
49
50   !!----------------------------------------------------------------------
51   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
52   !! $Id$
53   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
54   !!----------------------------------------------------------------------
55CONTAINS
56
57   INTEGER FUNCTION trc_nxt_alloc()
58      !!----------------------------------------------------------------------
59      !!                   ***  ROUTINE trc_nxt_alloc  ***
60      !!----------------------------------------------------------------------
61      ALLOCATE( r2dt(jpk), STAT=trc_nxt_alloc )
62      !
63      IF( trc_nxt_alloc /= 0 )   CALL ctl_warn('trc_nxt_alloc : failed to allocate array')
64      !
65   END FUNCTION trc_nxt_alloc
66
67
68   SUBROUTINE trc_nxt( kt )
69      !!----------------------------------------------------------------------
70      !!                   ***  ROUTINE trcnxt  ***
71      !!
72      !! ** Purpose :   Compute the passive tracers fields at the
73      !!      next time-step from their temporal trends and swap the fields.
74      !!
75      !! ** Method  :   Apply lateral boundary conditions on (ua,va) through
76      !!      call to lbc_lnk routine
77      !!   default:
78      !!      arrays swap
79      !!         (trn) = (tra) ; (tra) = (0,0)
80      !!         (trb) = (trn)
81      !!
82      !!   For Arakawa or TVD Scheme :
83      !!      A Asselin time filter applied on now tracers (trn) to avoid
84      !!      the divergence of two consecutive time-steps and tr arrays
85      !!      to prepare the next time_step:
86      !!         (trb) = (trn) + atfp [ (trb) + (tra) - 2 (trn) ]
87      !!         (trn) = (tra) ; (tra) = (0,0)
88      !!
89      !!
90      !! ** Action  : - update trb, trn
91      !!----------------------------------------------------------------------
92      INTEGER, INTENT( in ) ::   kt     ! ocean time-step index
93      !
94      INTEGER  ::   jk, jn   ! dummy loop indices
95      REAL(wp) ::   zfact            ! temporary scalar
96      CHARACTER (len=22) :: charout
97      REAL(wp), POINTER, DIMENSION(:,:,:,:) ::  ztrdt 
98#if defined key_tracer_budget
99      REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:,:) ::  ztrdt_m1 ! slwa
100#endif
101      !!----------------------------------------------------------------------
102      !
103      IF( nn_timing == 1 )  CALL timing_start('trc_nxt')
104      !
105      IF( kt == nittrc000 .AND. lwp ) THEN
106         WRITE(numout,*)
107         WRITE(numout,*) 'trc_nxt : time stepping on passive tracers'
108      ENDIF
109#if defined key_tracer_budget
110      IF( kt == nittrc000 .AND. l_trdtrc ) THEN
111         ALLOCATE( ztrdt_m1(jpi,jpj,jpk,jptra) )  ! slwa
112         IF( ln_rsttr .AND.    &                     ! Restart: read in restart  file
113            iom_varid( numrtr, 'atf_trend_'//TRIM(ctrcnm(1)), ldstop = .FALSE. ) > 0 ) THEN
114            IF(lwp) WRITE(numout,*) '          nittrc000-nn_dttrc ATF tracer trend read in the restart file'
115            DO jn = 1, jptra
116               CALL iom_get( numrtr, jpdom_autoglo, 'atf_trend_'//TRIM(ctrcnm(jn)), ztrdt_m1(:,:,:,jn) )   ! before tracer trend for atf
117            END DO
118         ELSE         
119           ztrdt_m1=0.0
120         ENDIF
121      ENDIF
122#endif
123
124
125#if defined key_agrif
126      CALL Agrif_trc                   ! AGRIF zoom boundaries
127#endif
128      ! Update after tracer on domain lateral boundaries
129      DO jn = 1, jptra
130         CALL lbc_lnk( tra(:,:,:,jn), 'T', 1. )   
131      END DO
132
133
134      IF( lk_bdy )  CALL trc_bdy( kt )               ! BDY open boundaries
135#if defined key_bdy
136!!      CALL bdy_trc( kt )               ! BDY open boundaries
137#endif
138
139      ! set time step size (Euler/Leapfrog)
140      IF( neuler == 0 .AND. kt ==  nittrc000 ) THEN  ;  r2dt(:) =     rdttrc(:)   ! at nittrc000             (Euler)
141      ELSEIF( kt <= nittrc000 + nn_dttrc )     THEN  ;  r2dt(:) = 2.* rdttrc(:)   ! at nit000 or nit000+1 (Leapfrog)
142      ENDIF
143
144      ! trends computation initialisation
145      IF( l_trdtrc )  THEN
146         CALL wrk_alloc( jpi, jpj, jpk, jptra, ztrdt )  !* store now fields before applying the Asselin filter
147         ztrdt(:,:,:,:)  = trn(:,:,:,:)
148      ENDIF
149      ! Leap-Frog + Asselin filter time stepping
150      IF( neuler == 0 .AND. kt == nittrc000 ) THEN        ! Euler time-stepping at first time-step
151         !                                                ! (only swap)
152         DO jn = 1, jptra
153            DO jk = 1, jpkm1
154               trn(:,:,jk,jn) = tra(:,:,jk,jn)
155            END DO
156         END DO
157         !                                             
158      ELSE
159         ! Leap-Frog + Asselin filter time stepping
160         IF( lk_vvl ) THEN   ;   CALL tra_nxt_vvl( kt, nittrc000, rdttrc, 'TRC', trb, trn, tra,      &
161           &                                                                sbc_trc, sbc_trc_b, jptra )      ! variable volume level (vvl)
162         ELSE                ;   CALL tra_nxt_fix( kt, nittrc000,         'TRC', trb, trn, tra, jptra )      ! fixed    volume level
163         ENDIF
164      ENDIF
165
166      ! trends computation
167      IF( l_trdtrc ) THEN                                      ! trends
168         DO jn = 1, jptra
169            DO jk = 1, jpkm1
170               zfact = 1.e0 / r2dt(jk) 
171               ztrdt(:,:,jk,jn) = ( trb(:,:,jk,jn) - ztrdt(:,:,jk,jn) ) * zfact 
172!slwa          CALL trd_tra( kt, 'TRC', jn, jptra_atf, ztrdt )
173#if defined key_tracer_budget
174               ztrdt(:,:,jk,jn) = ztrdt(:,:,jk,jn) * e1t(:,:) * e2t(:,:) * e3t_n(:,:,jk)  ! slwa vvl
175               !ztrdt(:,:,jk,jn) = ztrdt(:,:,jk,jn) * e1t(:,:) * e2t(:,:) * e3t_0(:,:,jk)  ! slwa CHANGE for vvl
176#endif
177            END DO
178#if defined key_tracer_budget
179! slwa budget code
180              CALL trd_tra( kt, 'TRC', jn, jptra_atf, ztrdt_m1(:,:,:,jn) )
181#else
182              CALL trd_tra( kt, 'TRC', jn, jptra_atf, ztrdt(:,:,:,jn) )
183#endif
184         END DO
185#if defined key_tracer_budget
186        ztrdt_m1(:,:,:,:) = ztrdt(:,:,:,:)    ! need previous time step for budget slwa
187#endif
188         CALL wrk_dealloc( jpi, jpj, jpk, jptra, ztrdt ) 
189      END IF
190
191#if defined key_tracer_budget
192      !                                           Write in the tracer restart file
193      !                                          *******************************
194      IF( lrst_trc ) THEN
195         IF(lwp) WRITE(numout,*)
196         IF(lwp) WRITE(numout,*) 'trc : ATF trend at last time step for tracer budget written in tracer restart file ',   &
197            &                    'at it= ', kt,' date= ', ndastp
198         IF(lwp) WRITE(numout,*) '~~~~'
199         DO jn = 1, jptra
200            CALL iom_rstput( kt, nitrst, numrtw, 'atf_trend_'//TRIM(ctrcnm(jn)), ztrdt_m1(:,:,:,jn) )
201         END DO
202      ENDIF
203#endif
204
205      !
206      IF(ln_ctl)   THEN  ! print mean trends (used for debugging)
207         WRITE(charout, FMT="('nxt')")
208         CALL prt_ctl_trc_info(charout)
209         CALL prt_ctl_trc(tab4d=trn, mask=tmask, clinfo=ctrcnm)
210      ENDIF
211      !
212      IF( nn_timing == 1 )  CALL timing_stop('trc_nxt')
213      !
214   END SUBROUTINE trc_nxt
215
216#else
217   !!----------------------------------------------------------------------
218   !!   Default option                                         Empty module
219   !!----------------------------------------------------------------------
220CONTAINS
221   SUBROUTINE trc_nxt( kt ) 
222      INTEGER, INTENT(in) :: kt
223      WRITE(*,*) 'trc_nxt: You should not have seen this print! error?', kt
224   END SUBROUTINE trc_nxt
225#endif
226   !!======================================================================
227END MODULE trcnxt
Note: See TracBrowser for help on using the repository browser.