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/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps/src/TOP – NEMO

source: NEMO/branches/2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps/src/TOP/trcstp.F90 @ 11504

Last change on this file since 11504 was 11504, checked in by davestorkey, 5 years ago

2019/dev_r10721_KERNEL-02_Storkey_Coward_IMMERSE_first_steps : Strip out all references to nn_dttrc
and the trcsub.F90 module. Notes:

  1. This version of the code currently breaks the GYRE_PISCES test in SETTE.
  2. With the removal of this option, TOP should use the OCE time index variables, eg. Nbb_trc -> Nbb, nittrc000 -> nit0000 etc.
  • Property svn:keywords set to Id
File size: 11.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   !! time level indices
41   !!----------------------------------------------------------------------
42   INTEGER, PUBLIC :: Nbb_trc, Nnn_trc, Naa_trc, Nrhs_trc      !! used by trc_init
43
44   !!----------------------------------------------------------------------
45   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
46   !! $Id$
47   !! Software governed by the CeCILL license (see ./LICENSE)
48   !!----------------------------------------------------------------------
49CONTAINS
50
51   SUBROUTINE trc_stp( kt, Kbb_oce, Kmm_oce, Krhs_oce, Kaa_oce )
52      !!-------------------------------------------------------------------
53      !!                     ***  ROUTINE trc_stp  ***
54      !!                     
55      !! ** Purpose :   Time loop of opa for passive tracer
56      !!
57      !! ** Method  :   Compute the passive tracers trends
58      !!                Update the passive tracers
59      !!-------------------------------------------------------------------
60      INTEGER, INTENT( in ) :: kt                  ! ocean time-step index
61      INTEGER, INTENT( in ) :: Kbb_oce, Kmm_oce, Krhs_oce, Kaa_oce ! time level indices
62      !
63      INTEGER ::   jk, jn   ! dummy loop indices
64      REAL(wp)::   ztrai    ! local scalar
65      LOGICAL ::   ll_trcstat ! local logical
66      CHARACTER (len=25) ::   charout   !
67      !!-------------------------------------------------------------------
68      !
69      IF( ln_timing )   CALL timing_start('trc_stp')
70      !
71      IF( ( neuler == 0 .AND. kt == nittrc000 ) .OR. ln_top_euler ) THEN     ! at nittrc000
72         r2dttrc =  rdttrc           ! = rdttrc (use or restarting with Euler time stepping)
73      ENDIF
74      !
75      ll_trcstat  = ( ln_ctl .OR. sn_cfctl%l_trcstat ) .AND. &
76     &              ( ( MOD( kt, sn_cfctl%ptimincr ) == 0 ) .OR. ( kt == nitend ) )
77      IF( kt == nittrc000 .AND. lk_trdmxl_trc )  CALL trd_mxl_trc_init    ! trends: Mixed-layer
78      !
79      IF( .NOT.ln_linssh ) THEN                                           ! update ocean volume due to ssh temporal evolution
80         DO jk = 1, jpk
81            cvol(:,:,jk) = e1e2t(:,:) * e3t(:,:,jk,Kmm_oce) * tmask(:,:,jk)
82         END DO
83         IF ( ln_ctl .OR. kt == nitrst .OR. ( ln_check_mass .AND. kt == nitend )              &
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(:,:,:) )
87      ENDIF
88      !
89      IF( l_trcdm2dc )   CALL trc_mean_qsr( kt )
90      !   
91      IF( Kmm_oce /= Nnn_trc .OR. Kaa_oce /= Naa_trc .OR. Krhs_oce /= Nrhs_trc ) THEN
92         ! The OCE and TRC time indices should be the same always.
93         ! If this is not the case then something has gone wrong.
94         CALL ctl_stop( 'trc_stp : OCE and TRC time indices are different! Something has gone wrong.' )
95      ENDIF
96      !   
97      !
98      IF(ln_ctl) THEN
99         WRITE(charout,FMT="('kt =', I4,'  d/m/y =',I2,I2,I4)") kt, nday, nmonth, nyear
100         CALL prt_ctl_trc_info(charout)
101      ENDIF
102      !
103      tr(:,:,:,:,Nrhs_trc) = 0.e0
104      !
105      CALL trc_rst_opn  ( kt )       ! Open tracer restart file
106      IF( lrst_trc )            CALL trc_rst_cal  ( kt, 'WRITE' )   ! calendar
107      CALL trc_wri      ( kt,          Nnn_trc                    )  ! output of passive tracers with iom I/O manager
108      CALL trc_sms      ( kt, Nbb_trc, Nnn_trc, Nrhs_trc          )  ! tracers: sinks and sources
109      CALL trc_trp      ( kt, Nbb_trc, Nnn_trc, Nrhs_trc, Naa_trc )  ! transport of passive tracers
110      IF( kt == nittrc000 ) THEN
111         CALL iom_close( numrtr )       ! close input tracer restart file
112         IF(lwm) CALL FLUSH( numont )   ! flush namelist output
113      ENDIF
114      IF( lrst_trc )            CALL trc_rst_wri  ( kt, Nbb_trc, Nnn_trc, Nrhs_trc )       ! write tracer restart file
115      IF( lk_trdmxl_trc  )      CALL trd_mxl_trc  ( kt,          Nnn_trc           )       ! trends: Mixed-layer
116      !
117      IF (ll_trcstat) THEN
118         ztrai = 0._wp                                                   !  content of all tracers
119         DO jn = 1, jptra
120            ztrai = ztrai + glob_sum( 'trcstp', tr(:,:,:,jn,Nnn_trc) * cvol(:,:,:)   )
121         END DO
122         IF( lwm ) WRITE(numstr,9300) kt,  ztrai / areatot
123      ENDIF
1249300  FORMAT(i10,D23.16)
125      !
126      IF( ln_timing )   CALL timing_stop('trc_stp')
127      !
128   END SUBROUTINE trc_stp
129
130   SUBROUTINE trc_mean_qsr( kt )
131      !!----------------------------------------------------------------------
132      !!             ***  ROUTINE trc_mean_qsr  ***
133      !!
134      !! ** Purpose :  Compute daily mean qsr for biogeochemical model in case
135      !!               of diurnal cycle
136      !!
137      !! ** Method  : store in TOP the qsr every hour ( or every time-step if the latter
138      !!              is greater than 1 hour ) and then, compute the  mean with
139      !!              a moving average over 24 hours.
140      !!              In coupled mode, the sampling is done at every coupling frequency
141      !!----------------------------------------------------------------------
142      INTEGER, INTENT( in ) ::   kt   ! ocean time-step index
143      !
144      INTEGER  ::   jn   ! dummy loop indices
145      REAL(wp) ::   zkt, zrec     ! local scalars
146      CHARACTER(len=1) ::   cl1   ! 1 character
147      CHARACTER(len=2) ::   cl2   ! 2 characters
148      !!----------------------------------------------------------------------
149      !
150      IF( ln_timing )   CALL timing_start('trc_mean_qsr')
151      !
152      IF( kt == nittrc000 ) THEN
153         IF( ln_cpl )  THEN 
154            rdt_sampl = rday / ncpl_qsr_freq
155            nb_rec_per_day = ncpl_qsr_freq
156         ELSE 
157            rdt_sampl = MAX( 3600., rdttrc )
158            nb_rec_per_day = INT( rday / rdt_sampl )
159         ENDIF
160         !
161         IF(lwp) THEN
162            WRITE(numout,*) 
163            WRITE(numout,*) ' Sampling frequency dt = ', rdt_sampl, 's','   Number of sampling per day  nrec = ', nb_rec_per_day
164            WRITE(numout,*) 
165         ENDIF
166         !
167         ALLOCATE( qsr_arr(jpi,jpj,nb_rec_per_day ) )
168         !
169         !                                            !* Restart: read in restart file
170         IF( ln_rsttr .AND. nn_rsttr /= 0 .AND. iom_varid( numrtr, 'qsr_mean' , ldstop = .FALSE. ) > 0  &
171           &                              .AND. iom_varid( numrtr, 'qsr_arr_1', ldstop = .FALSE. ) > 0  &
172           &                              .AND. iom_varid( numrtr, 'ktdcy'    , ldstop = .FALSE. ) > 0  &
173           &                              .AND. iom_varid( numrtr, 'nrdcy'    , ldstop = .FALSE. ) > 0  ) THEN
174
175            CALL iom_get( numrtr, 'ktdcy', zkt ) 
176            rsecfst = INT( zkt ) * rdttrc
177            IF(lwp) WRITE(numout,*) 'trc_qsr_mean:   qsr_mean read in the restart file at time-step rsecfst =', rsecfst, ' s '
178            CALL iom_get( numrtr, jpdom_autoglo, 'qsr_mean', qsr_mean )   !  A mean of qsr
179            CALL iom_get( numrtr, 'nrdcy', zrec )   !  Number of record per days
180            IF( INT( zrec ) == nb_rec_per_day ) THEN
181               DO jn = 1, nb_rec_per_day 
182                  IF( jn <= 9 )  THEN
183                    WRITE(cl1,'(i1)') jn
184                    CALL iom_get( numrtr, jpdom_autoglo, 'qsr_arr_'//cl1, qsr_arr(:,:,jn) )   !  A mean of qsr
185                  ELSE
186                    WRITE(cl2,'(i2.2)') jn
187                    CALL iom_get( numrtr, jpdom_autoglo, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) )   !  A mean of qsr
188                  ENDIF
189              END DO
190            ELSE
191               DO jn = 1, nb_rec_per_day
192                  qsr_arr(:,:,jn) = qsr_mean(:,:)
193               ENDDO
194            ENDIF
195         ELSE                                         !* no restart: set from nit000 values
196            IF(lwp) WRITE(numout,*) 'trc_qsr_mean:   qsr_mean set to nit000 values'
197            rsecfst  = kt * rdttrc
198            !
199            qsr_mean(:,:) = qsr(:,:)
200            DO jn = 1, nb_rec_per_day
201               qsr_arr(:,:,jn) = qsr_mean(:,:)
202            END DO
203         ENDIF
204         !
205      ENDIF
206      !
207      rseclast = kt * rdttrc
208      !
209      llnew   = ( rseclast - rsecfst ) .ge.  rdt_sampl    !   new shortwave to store
210      IF( llnew ) THEN
211          ktdcy = kt
212          IF( lwp .AND. kt < nittrc000 + 100 ) WRITE(numout,*) ' New shortwave to sample for TOP at time kt = ', ktdcy, &
213             &                      ' time = ', rseclast/3600.,'hours '
214          rsecfst = rseclast
215          DO jn = 1, nb_rec_per_day - 1
216             qsr_arr(:,:,jn) = qsr_arr(:,:,jn+1)
217          ENDDO
218          qsr_arr (:,:,nb_rec_per_day) = qsr(:,:)
219          qsr_mean(:,:                ) = SUM( qsr_arr(:,:,:), 3 ) / nb_rec_per_day
220      ENDIF
221      !
222      IF( lrst_trc ) THEN    !* Write the mean of qsr in restart file
223         IF(lwp) WRITE(numout,*)
224         IF(lwp) WRITE(numout,*) 'trc_mean_qsr : write qsr_mean in restart file  kt =', kt
225         IF(lwp) WRITE(numout,*) '~~~~~~~'
226         zkt  = REAL( ktdcy, wp )
227         zrec = REAL( nb_rec_per_day, wp )
228         CALL iom_rstput( kt, nitrst, numrtw, 'ktdcy', zkt  )
229         CALL iom_rstput( kt, nitrst, numrtw, 'nrdcy', zrec )
230          DO jn = 1, nb_rec_per_day 
231             IF( jn <= 9 )  THEN
232               WRITE(cl1,'(i1)') jn
233               CALL iom_rstput( kt, nitrst, numrtw, 'qsr_arr_'//cl1, qsr_arr(:,:,jn) )
234             ELSE
235               WRITE(cl2,'(i2.2)') jn
236               CALL iom_rstput( kt, nitrst, numrtw, 'qsr_arr_'//cl2, qsr_arr(:,:,jn) )
237             ENDIF
238         END DO
239         CALL iom_rstput( kt, nitrst, numrtw, 'qsr_mean', qsr_mean(:,:) )
240      ENDIF
241      !
242      IF( ln_timing )   CALL timing_stop('trc_mean_qsr')
243      !
244   END SUBROUTINE trc_mean_qsr
245
246#else
247   !!----------------------------------------------------------------------
248   !!   Default key                                     NO passive tracers
249   !!----------------------------------------------------------------------
250CONTAINS
251   SUBROUTINE trc_stp( kt )        ! Empty routine
252      WRITE(*,*) 'trc_stp: You should not have seen this print! error?', kt
253   END SUBROUTINE trc_stp
254#endif
255
256   !!======================================================================
257END MODULE trcstp
Note: See TracBrowser for help on using the repository browser.