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.
trcstp.F90 in NEMO/trunk/src/TOP – NEMO

source: NEMO/trunk/src/TOP/trcstp.F90

Last change on this file was 15446, checked in by cetlod, 2 years ago

Minor bugfixes mostly related to PISCES/SED module

  • Property svn:keywords set to Id
File size: 12.8 KB
Line 
1MODULE trcstp
2   !!======================================================================
3   !!                       ***  MODULE trcstp  ***
4   !! Time-stepping    : time loop of opa for passive tracer
5   !!======================================================================
6   !! History :  1.0  !  2004-03  (C. Ethe)  Original
7   !!            4.1  !  2019-08  (A. Coward, D. Storkey) rewrite in preparation for new timestepping scheme
8   !!----------------------------------------------------------------------
9#if defined key_top
10   !!----------------------------------------------------------------------
11   !!   trc_stp       : passive tracer system time-stepping
12   !!----------------------------------------------------------------------
13   USE par_trc        ! need jptra, number of passive tracers
14   USE oce_trc        ! ocean dynamics and active tracers variables
15   USE sbc_oce
16   USE trc
17   USE trctrp         ! passive tracers transport
18   USE trcsms         ! passive tracers sources and sinks
19   USE trcwri
20   USE trcrst
21   USE trdtrc_oce
22   USE trdmxl_trc
23   USE sms_pisces,  ONLY : ln_check_mass
24   !
25   USE prtctl         ! Print control for debbuging
26   USE iom            !
27   USE in_out_manager !
28
29   IMPLICIT NONE
30   PRIVATE
31
32   PUBLIC   trc_stp    ! called by step
33
34   LOGICAL  ::   llnew                   ! ???
35   REAL(wp) ::   rdt_sampl               ! ???
36   INTEGER  ::   nb_rec_per_day, ktdcy   ! ???
37   REAL(wp) ::   rsecfst, rseclast       ! ???
38   REAL(wp), DIMENSION(:,:,:), SAVE, ALLOCATABLE ::   qsr_arr   ! save qsr during TOP time-step
39
40#  include "domzgr_substitute.h90"
41   !!----------------------------------------------------------------------
42   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
43   !! $Id$
44   !! Software governed by the CeCILL license (see ./LICENSE)
45   !!----------------------------------------------------------------------
46CONTAINS
47
48   SUBROUTINE trc_stp( kt, Kbb, Kmm, Krhs, Kaa )
49      !!-------------------------------------------------------------------
50      !!                     ***  ROUTINE trc_stp  ***
51      !!                     
52      !! ** Purpose :   Time loop of opa for passive tracer
53      !!
54      !! ** Method  :   Compute the passive tracers trends
55      !!                Update the passive tracers
56      !!-------------------------------------------------------------------
57      INTEGER, INTENT( in ) :: kt                  ! ocean time-step index
58      INTEGER, INTENT( in ) :: Kbb, Kmm, Krhs, Kaa ! time level indices
59      !
60      INTEGER ::   jk, jn   ! dummy loop indices
61      REAL(wp)::   ztrai    ! local scalar
62      LOGICAL ::   ll_trcstat ! local logical
63      CHARACTER (len=25) ::   charout   !
64      !!-------------------------------------------------------------------
65      !
66      IF( ln_timing )   CALL timing_start('trc_stp')
67      !
68      IF( l_1st_euler .OR. ln_top_euler ) THEN     ! at nittrc000
69         rDt_trc =  rn_Dt           ! = rn_Dt (use or restarting with Euler time stepping)
70      ELSEIF( kt <= nittrc000 + 1 ) THEN                                     ! at nittrc000 or nittrc000+1
71         rDt_trc = 2. * rn_Dt       ! = 2 rn_Dt (leapfrog)
72      ENDIF
73      !
74      ll_trcstat  = ( sn_cfctl%l_trcstat ) .AND. &
75     &              ( ( MOD( kt, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend ) )
76
77      IF( kt == nittrc000 )                      CALL trc_stp_ctl   ! control
78      IF( kt == nittrc000 .AND. lk_trdmxl_trc )  CALL trd_mxl_trc_init    ! trends: Mixed-layer
79      !
80      IF( .NOT.ln_linssh ) THEN                                           ! update ocean volume due to ssh temporal evolution
81         DO jk = 1, jpk
82            cvol(:,:,jk) = e1e2t(:,:) * e3t(:,:,jk,Kmm) * tmask(:,:,jk)
83         END DO
84         IF ( ll_trcstat .OR. kt == nitrst .OR. ( ln_check_mass .AND. kt == nitend )   &
85            & .OR. iom_use( "pno3tot" ) .OR. iom_use( "ppo4tot" ) .OR. iom_use( "psiltot" )   &
86            & .OR. iom_use( "palktot" ) .OR. iom_use( "pfertot" ) )                           &
87            &     areatot = glob_sum( 'trcstp', cvol(:,:,:) )
88      ENDIF
89      !
90      IF( l_trcdm2dc )   CALL trc_mean_qsr( kt )
91      !   
92      !
93      IF(sn_cfctl%l_prttrc) THEN
94         WRITE(charout,FMT="('kt =', I4,'  d/m/y =',I2,I2,I4)") kt, nday, nmonth, nyear
95         CALL prt_ctl_info( charout, cdcomp = 'top' )
96      ENDIF
97      !
98      tr(:,:,:,:,Krhs) = 0._wp
99      !
100      CALL trc_rst_opn  ( kt )                            ! Open tracer restart file
101      IF( lrst_trc )  CALL trc_rst_cal  ( kt, 'WRITE' )   ! calendar
102      CALL trc_wri      ( kt,      Kmm            )       ! output of passive tracers with iom I/O manager
103      CALL trc_sms      ( kt, Kbb, Kmm, Krhs      )       ! tracers: sinks and sources
104#if ! defined key_sed_off
105      CALL trc_trp      ( kt, Kbb, Kmm, Krhs, Kaa )       ! transport of passive tracers
106#endif
107           !
108           ! Note passive tracers have been time-filtered in trc_trp but the time level
109           ! indices will not be swapped until after tra_atf/dyn_atf/ssh_atf in stp. Subsequent calls here
110           ! anticipate this update which will be: Nrhs= Nbb ; Nbb = Nnn ; Nnn = Naa ; Naa = Nrhs
111           ! and use the filtered levels explicitly.
112           !
113      IF( kt == nittrc000 ) THEN
114         CALL iom_close( numrtr )                         ! close input tracer restart file
115         IF(lrxios) CALL iom_context_finalize(      cr_toprst_cxt          )
116         IF(lwm) CALL FLUSH( numont )                     ! flush namelist output
117      ENDIF
118      IF( lrst_trc )            CALL trc_rst_wri  ( kt, Kmm, Kaa, Kbb  )       ! write tracer restart file
119      IF( lk_trdmxl_trc  )      CALL trd_mxl_trc  ( kt,      Kaa       )       ! trends: Mixed-layer
120      !
121      IF( ln_top_euler ) THEN 
122         ! For Euler timestepping for TOP we need to copy the "after" to the "now" fields
123         ! here then after the (leapfrog) swapping of the time-level indices in OCE/step.F90 we have
124         ! "before" fields = "now" fields.
125         tr(:,:,:,:,Kmm) = tr(:,:,:,:,Kaa)
126      ENDIF
127      !
128      IF (ll_trcstat) THEN
129         ztrai = 0._wp                                                   !  content of all tracers
130         DO jn = 1, jptra
131            ztrai = ztrai + glob_sum( 'trcstp', tr(:,:,:,jn,Kaa) * cvol(:,:,:)   )
132         END DO
133         IF( lwm ) WRITE(numstr,9300) kt,  ztrai / areatot
134      ENDIF
1359300  FORMAT(i10,D23.16)
136      !
137      IF( ln_timing )   CALL timing_stop('trc_stp')
138      !
139   END SUBROUTINE trc_stp
140
141
142   SUBROUTINE trc_stp_ctl
143      !!----------------------------------------------------------------------
144      !!                     ***  ROUTINE trc_stp_ctl  ***
145      !! ** Purpose :        Control  + ocean volume
146      !!----------------------------------------------------------------------
147      !
148      ! Define logical parameter ton control dirunal cycle in TOP
149      l_trcdm2dc = ln_dm2dc .OR. ( ln_cpl .AND. ncpl_qsr_freq /= 1 .AND. ncpl_qsr_freq /= 0 )
150      l_trcdm2dc = l_trcdm2dc .AND. .NOT. l_offline
151      !
152      IF( l_trcdm2dc .AND. lwp )   CALL ctl_warn( 'Coupling with passive tracers and used of diurnal cycle.',   &
153         &                           'Computation of a daily mean shortwave for some biogeochemical models ' )
154      !
155   END SUBROUTINE trc_stp_ctl
156
157
158   SUBROUTINE trc_mean_qsr( kt )
159      !!----------------------------------------------------------------------
160      !!             ***  ROUTINE trc_mean_qsr  ***
161      !!
162      !! ** Purpose :  Compute daily mean qsr for biogeochemical model in case
163      !!               of diurnal cycle
164      !!
165      !! ** Method  : store in TOP the qsr every hour ( or every time-step if the latter
166      !!              is greater than 1 hour ) and then, compute the  mean with
167      !!              a moving average over 24 hours.
168      !!              In coupled mode, the sampling is done at every coupling frequency
169      !!----------------------------------------------------------------------
170      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
171      !
172      INTEGER  ::   jn   ! dummy loop indices
173      REAL(wp) ::   zkt, zrec     ! local scalars
174      CHARACTER(len=1) ::   cl1   ! 1 character
175      CHARACTER(len=2) ::   cl2   ! 2 characters
176      !!----------------------------------------------------------------------
177      !
178      IF( ln_timing )   CALL timing_start('trc_mean_qsr')
179      !
180      IF( kt == nittrc000 ) THEN
181         IF( ln_cpl )  THEN 
182            rdt_sampl = rday / ncpl_qsr_freq
183            nb_rec_per_day = ncpl_qsr_freq
184         ELSE 
185            rdt_sampl = MAX( 3600., rn_Dt )
186            nb_rec_per_day = INT( rday / rdt_sampl )
187         ENDIF
188         !
189         IF(lwp) THEN
190            WRITE(numout,*) 
191            WRITE(numout,*) ' Sampling frequency dt = ', rdt_sampl, 's','   Number of sampling per day  nrec = ', nb_rec_per_day
192            WRITE(numout,*) 
193         ENDIF
194         !
195         ALLOCATE( qsr_arr(jpi,jpj,nb_rec_per_day ) )
196         !
197         !                                            !* Restart: read in restart file
198         IF( ln_rsttr .AND. nn_rsttr /= 0 .AND. iom_varid( numrtr, 'qsr_mean' , ldstop = .FALSE. ) > 0  &
199           &                              .AND. iom_varid( numrtr, 'qsr_arr_1', ldstop = .FALSE. ) > 0  &
200           &                              .AND. iom_varid( numrtr, 'ktdcy'    , ldstop = .FALSE. ) > 0  &
201           &                              .AND. iom_varid( numrtr, 'nrdcy'    , ldstop = .FALSE. ) > 0  ) THEN
202            CALL iom_get( numrtr, 'ktdcy', zkt ) 
203            rsecfst = INT( zkt ) * rn_Dt
204            IF(lwp) WRITE(numout,*) 'trc_qsr_mean:   qsr_mean read in the restart file at time-step rsecfst =', rsecfst, ' s '
205            CALL iom_get( numrtr, jpdom_auto, 'qsr_mean', qsr_mean )   !  A mean of qsr
206            CALL iom_get( numrtr, 'nrdcy', zrec )   !  Number of record per days
207            IF( INT( zrec ) == nb_rec_per_day ) THEN
208               DO jn = 1, nb_rec_per_day 
209                  IF( jn <= 9 )  THEN
210                    WRITE(cl1,'(i1)') jn
211                    CALL iom_get( numrtr, jpdom_auto, 'qsr_arr_'//cl1, qsr_arr(:,:,jn) )   !  A mean of qsr
212                  ELSE
213                    WRITE(cl2,'(i2.2)') jn
214                    CALL iom_get( numrtr, jpdom_auto, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) )   !  A mean of qsr
215                  ENDIF
216              END DO
217            ELSE
218               DO jn = 1, nb_rec_per_day
219                  qsr_arr(:,:,jn) = qsr_mean(:,:)
220               ENDDO
221            ENDIF
222         ELSE                                         !* no restart: set from nit000 values
223            IF(lwp) WRITE(numout,*) 'trc_qsr_mean:   qsr_mean set to nit000 values'
224            rsecfst  = kt * rn_Dt
225            !
226            qsr_mean(:,:) = qsr(:,:)
227            DO jn = 1, nb_rec_per_day
228               qsr_arr(:,:,jn) = qsr_mean(:,:)
229            END DO
230         ENDIF
231         !
232      ENDIF
233      !
234      rseclast = kt * rn_Dt
235      !
236      llnew   = ( rseclast - rsecfst ) .ge.  rdt_sampl    !   new shortwave to store
237      IF( llnew ) THEN
238          ktdcy = kt
239          IF( lwp .AND. kt < nittrc000 + 100 ) WRITE(numout,*) ' New shortwave to sample for TOP at time kt = ', ktdcy, &
240             &                      ' time = ', rseclast/3600.,'hours '
241          rsecfst = rseclast
242          DO jn = 1, nb_rec_per_day - 1
243             qsr_arr(:,:,jn) = qsr_arr(:,:,jn+1)
244          ENDDO
245          qsr_arr (:,:,nb_rec_per_day) = qsr(:,:)
246          qsr_mean(:,:                ) = SUM( qsr_arr(:,:,:), 3 ) / nb_rec_per_day
247      ENDIF
248      !
249      IF( lrst_trc ) THEN    !* Write the mean of qsr in restart file
250         IF(lwp) WRITE(numout,*)
251         IF(lwp) WRITE(numout,*) 'trc_mean_qsr : write qsr_mean in restart file  kt =', kt
252         IF(lwp) WRITE(numout,*) '~~~~~~~'
253         zkt  = REAL( ktdcy, wp )
254         zrec = REAL( nb_rec_per_day, wp )
255         CALL iom_rstput( kt, nitrst, numrtw, 'ktdcy', zkt  )
256         CALL iom_rstput( kt, nitrst, numrtw, 'nrdcy', zrec )
257          DO jn = 1, nb_rec_per_day 
258             IF( jn <= 9 )  THEN
259               WRITE(cl1,'(i1)') jn
260               CALL iom_rstput( kt, nitrst, numrtw, 'qsr_arr_'//cl1, qsr_arr(:,:,jn) )
261             ELSE
262               WRITE(cl2,'(i2.2)') jn
263               CALL iom_rstput( kt, nitrst, numrtw, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) )
264             ENDIF
265         END DO
266         CALL iom_rstput( kt, nitrst, numrtw, 'qsr_mean', qsr_mean(:,:) )
267      ENDIF
268      !
269      IF( ln_timing )   CALL timing_stop('trc_mean_qsr')
270      !
271   END SUBROUTINE trc_mean_qsr
272
273#else
274   !!----------------------------------------------------------------------
275   !!   Default key                                     NO passive tracers
276   !!----------------------------------------------------------------------
277CONTAINS
278   SUBROUTINE trc_stp( kt )        ! Empty routine
279      WRITE(*,*) 'trc_stp: You should not have seen this print! error?', kt
280   END SUBROUTINE trc_stp
281#endif
282
283   !!======================================================================
284END MODULE trcstp
Note: See TracBrowser for help on using the repository browser.