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/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP – NEMO

source: NEMO/branches/2020/dev_r13327_KERNEL-06_2_techene_e3/src/TOP/trcstp.F90 @ 14018

Last change on this file since 14018 was 14018, checked in by techene, 3 years ago

#2385 branch updated with trunk 13970

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