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_r12472_ASINTER-05_Masson_CurrentFeedback/src/TOP – NEMO

source: NEMO/branches/2020/dev_r12472_ASINTER-05_Masson_CurrentFeedback/src/TOP/trcstp.F90 @ 13189

Last change on this file since 13189 was 13189, checked in by smasson, 4 years ago

dev_r12472_ASINTER-05_Masson_CurrentFeedback: update with trunk@13136, see #2156

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