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 branches/NERC/dev_r5518_NOC_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC – NEMO

source: branches/NERC/dev_r5518_NOC_MEDUSA_Stable/NEMOGCM/NEMO/TOP_SRC/trcstp.F90 @ 8213

Last change on this file since 8213 was 8213, checked in by jpalmier, 7 years ago

JPALM -- split trcbio - mergeable-ish MEDUSA branch

File size: 8.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   !!----------------------------------------------------------------------
8#if defined key_top
9   !!----------------------------------------------------------------------
10   !!   trc_stp      : passive tracer system time-stepping
11   !!----------------------------------------------------------------------
12   USE oce_trc          ! ocean dynamics and active tracers variables
13   USE sbc_oce
14   USE trc
15   USE trctrp           ! passive tracers transport
16   USE trcsms           ! passive tracers sources and sinks
17   USE prtctl_trc       ! Print control for debbuging
18   USE trcdia
19   USE trcwri
20   USE trcrst
21   USE trdtrc_oce
22   USE trdmxl_trc
23   USE iom
24   USE in_out_manager
25   USE trcsub
26
27   IMPLICIT NONE
28   PRIVATE
29
30   PUBLIC   trc_stp    ! called by step
31
32   REAL(wp), DIMENSION(:,:,:), SAVE, ALLOCATABLE ::   qsr_arr ! save qsr during TOP time-step
33   REAL(wp) :: rdt_sampl
34   INTEGER  :: nb_rec_per_days
35   INTEGER  :: isecfst, iseclast
36   LOGICAL  :: llnew
37
38   !! * Substitutions
39#  include "domzgr_substitute.h90"
40   !!----------------------------------------------------------------------
41   !! NEMO/TOP 3.3 , NEMO Consortium (2010)
42   !! $Id$
43   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
44   !!----------------------------------------------------------------------
45CONTAINS
46
47   SUBROUTINE trc_stp( kt )
48      !!-------------------------------------------------------------------
49      !!                     ***  ROUTINE trc_stp  ***
50      !!                     
51      !! ** Purpose : Time loop of opa for passive tracer
52      !!
53      !! ** Method  :
54      !!              Compute the passive tracers trends
55      !!              Update the passive tracers
56      !!-------------------------------------------------------------------
57
58      USE dom_oce, ONLY: narea
59
60      INTEGER, INTENT( in ) ::  kt      ! ocean time-step index
61      INTEGER               ::  jk, jn  ! dummy loop indices
62      REAL(wp)              ::  ztrai
63      CHARACTER (len=25)    ::  charout 
64
65      !!-------------------------------------------------------------------
66      !
67      IF( nn_timing == 1 )   CALL timing_start('trc_stp')
68      !
69      IF( kt == nittrc000 .AND. lk_trdmxl_trc )  CALL trd_mxl_trc_init    ! trends: Mixed-layer
70      !
71      IF( lk_vvl ) THEN                                                   ! update ocean volume due to ssh temporal evolution
72         DO jk = 1, jpk
73            cvol(:,:,jk) = e1e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk)
74         END DO
75         IF( lk_degrad )  cvol(:,:,:) = cvol(:,:,:) * facvol(:,:,:)       ! degrad option: reduction by facvol
76         areatot         = glob_sum( cvol(:,:,:) )
77      ENDIF
78      !
79      IF( l_trcdm2dc )   CALL trc_mean_qsr( kt )
80      !   
81      IF( nn_dttrc /= 1 )   CALL trc_sub_stp( kt )  ! averaging physical variables for sub-stepping
82      !   
83      IF( MOD( kt , nn_dttrc ) == 0 ) THEN      ! only every nn_dttrc time step
84         !
85         IF(ln_ctl) THEN
86            WRITE(charout,FMT="('kt =', I4,'  d/m/y =',I2,I2,I4)") kt, nday, nmonth, nyear
87            CALL prt_ctl_trc_info(charout)
88         ENDIF
89         !
90         tra(:,:,:,:) = 0.e0
91         !
92                                   CALL trc_rst_opn  ( kt )       ! Open tracer restart file
93         IF( lrst_trc )            CALL trc_rst_cal  ( kt, 'WRITE' )   ! calendar
94         IF( lk_iomput ) THEN  ;   CALL trc_wri      ( kt )       ! output of passive tracers with iom I/O manager
95         ELSE                  ;   CALL trc_dia      ( kt )       ! output of passive tracers with old I/O manager
96         ENDIF
97                                   CALL trc_sms      ( kt )       ! tracers: sinks and sources
98# if defined key_debug_medusa
99         IF(lwp) WRITE(numout,*) ' MEDUSA trc_stp SMS complete at kt =', kt
100         CALL trc_rst_stat
101         CALL trc_rst_tra_stat
102         CALL flush(numout)
103# endif
104                                   CALL trc_trp      ( kt )       ! transport of passive tracers
105         IF( kt == nittrc000 ) THEN
106            CALL iom_close( numrtr )       ! close input tracer restart file
107            IF(lwm) CALL FLUSH( numont )   ! flush namelist output
108         ENDIF
109         IF( lrst_trc )            CALL trc_rst_wri  ( kt )       ! write tracer restart file
110         IF( lk_trdmxl_trc  )      CALL trd_mxl_trc  ( kt )       ! trends: Mixed-layer
111         !
112         IF( nn_dttrc /= 1   )     CALL trc_sub_reset( kt )       ! resetting physical variables when sub-stepping
113         !
114      ENDIF
115      !
116      IF (ln_ctl) THEN 
117         ! The following code is very expensive since it involves multiple
118         ! reproducible global sums over all tracer fields and is potentially 
119         ! called on every timestep. The results it produces are purely for
120         ! informational purposes and do not affect model evolution.
121         ! Hence we restrict its use by protecting it with the ln_ctl RTL
122         ! which should normally only be used under debugging conditions
123         ! and not in operational runs. We also need to restrict output 
124         ! to the master PE since there's no point duplicating the same results
125         ! on all processors.   
126         ztrai = 0._wp                                                   !  content of all tracers
127         DO jn = 1, jptra
128            ztrai = ztrai + glob_sum( trn(:,:,:,jn) * cvol(:,:,:)   )
129         END DO
130         IF( numstr /= -1 ) WRITE(numstr,9300) kt,  ztrai / areatot
1319300     FORMAT(i10,e18.10)
132      ENDIF
133      !
134      IF( nn_timing == 1 )   CALL timing_stop('trc_stp')
135      !
136   END SUBROUTINE trc_stp
137
138   SUBROUTINE trc_mean_qsr( kt )
139      !!----------------------------------------------------------------------
140      !!             ***  ROUTINE trc_mean_qsr  ***
141      !!
142      !! ** Purpose :  Compute daily mean qsr for biogeochemical model in case
143      !!               of diurnal cycle
144      !!
145      !! ** Method  : store in TOP the qsr every hour ( or every time-step the latter
146      !!              is greater than 1 hour ) and then, compute the  mean with
147      !!              a moving average over 24 hours.
148      !!              In coupled mode, the sampling is done at every coupling frequency
149      !!----------------------------------------------------------------------
150      INTEGER, INTENT(in) ::   kt
151      INTEGER  :: jn
152
153      IF( kt == nittrc000 ) THEN
154         IF( ln_cpl )  THEN 
155            rdt_sampl = 86400. / ncpl_qsr_freq
156            nb_rec_per_days = ncpl_qsr_freq
157         ELSE 
158            rdt_sampl = MAX( 3600., rdt * nn_dttrc )
159            nb_rec_per_days = INT( 86400 / rdt_sampl )
160         ENDIF
161         !
162         IF( lwp ) THEN
163            WRITE(numout,*) 
164            WRITE(numout,*) ' Sampling frequency dt = ', rdt_sampl, 's','   Number of sampling per day  nrec = ', nb_rec_per_days
165            WRITE(numout,*) 
166         ENDIF
167         !
168         ALLOCATE( qsr_arr(jpi,jpj,nb_rec_per_days ) )
169         DO jn = 1, nb_rec_per_days
170            qsr_arr(:,:,jn) = qsr(:,:)
171         ENDDO
172         qsr_mean(:,:) = qsr(:,:)
173         !
174         isecfst  = nsec_year + nsec1jan000   !   number of seconds between Jan. 1st 00h of nit000 year and the middle of time step
175         iseclast = isecfst
176         !
177      ENDIF
178      !
179      iseclast = nsec_year + nsec1jan000
180      llnew   = ( iseclast - isecfst )  > INT( rdt_sampl )   !   new shortwave to store
181      IF( kt /= nittrc000 .AND. llnew ) THEN
182          IF( lwp ) WRITE(numout,*) ' New shortwave to sample for TOP at time kt = ', kt, &
183             &                      ' time = ', (iseclast+rdt*nn_dttrc/2.)/3600.,'hours '
184          isecfst = iseclast
185          DO jn = 1, nb_rec_per_days - 1
186             qsr_arr(:,:,jn) = qsr_arr(:,:,jn+1)
187          ENDDO
188          qsr_arr (:,:,nb_rec_per_days) = qsr(:,:)
189          qsr_mean(:,:                ) = SUM( qsr_arr(:,:,:), 3 ) / nb_rec_per_days
190      ENDIF
191      !
192   END SUBROUTINE trc_mean_qsr
193
194#else
195   !!----------------------------------------------------------------------
196   !!   Default key                                     NO passive tracers
197   !!----------------------------------------------------------------------
198CONTAINS
199   SUBROUTINE trc_stp( kt )        ! Empty routine
200      WRITE(*,*) 'trc_stp: You should not have seen this print! error?', kt
201   END SUBROUTINE trc_stp
202#endif
203
204   !!======================================================================
205END MODULE trcstp
Note: See TracBrowser for help on using the repository browser.