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.
trcini.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/trcini.F90

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

JPALM -- split trcbio - mergeable-ish MEDUSA branch

File size: 11.3 KB
Line 
1MODULE trcini
2   !!======================================================================
3   !!                         ***  MODULE trcini  ***
4   !! TOP :   Manage the passive tracer initialization
5   !!======================================================================
6   !! History :   -   ! 1991-03 (O. Marti)  original code
7   !!            1.0  ! 2005-03 (O. Aumont, A. El Moussaoui) F90
8   !!            2.0  ! 2005-10 (C. Ethe, G. Madec) revised architecture
9   !!            4.0  ! 2011-01 (A. R. Porter, STFC Daresbury) dynamical allocation
10   !!             -   ! 2014-06 (A. Yool, J. Palmieri) adding MEDUSA-2
11   !!----------------------------------------------------------------------
12#if defined key_top
13   !!----------------------------------------------------------------------
14   !!   'key_top'                                                TOP models
15   !!----------------------------------------------------------------------
16   !!   trc_init  :   Initialization for passive tracer
17   !!   top_alloc :   allocate the TOP arrays
18   !!----------------------------------------------------------------------
19   USE oce_trc         ! shared variables between ocean and passive tracers
20   USE trc             ! passive tracers common variables
21   USE trcrst          ! passive tracers restart
22   USE trcnam          ! Namelist read
23   USE trcini_cfc      ! CFC      initialisation
24   USE trcini_pisces   ! PISCES   initialisation
25   USE trcini_c14b     ! C14 bomb initialisation
26   USE trcini_age      ! AGE      initialisation
27   USE trcini_my_trc   ! MY_TRC   initialisation
28   USE trcini_idtra    ! idealize tracer initialisation
29   USE trcini_medusa   ! MEDUSA   initialisation
30   USE trcdta          ! initialisation from files
31   USE daymod          ! calendar manager
32   USE zpshde          ! partial step: hor. derivative   (zps_hde routine)
33   USE prtctl_trc      ! Print control passive tracers (prt_ctl_trc_init routine)
34   USE trcsub          ! variables to substep passive tracers
35   USE lib_mpp         ! distribued memory computing library
36   USE sbc_oce
37   USE trcice          ! tracers in sea ice
38 
39   IMPLICIT NONE
40   PRIVATE
41   
42   PUBLIC   trc_init   ! called by opa
43
44    !! * Substitutions
45#  include "domzgr_substitute.h90"
46   !!----------------------------------------------------------------------
47   !! NEMO/TOP 4.0 , NEMO Consortium (2011)
48   !! $Id$
49   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
50   !!----------------------------------------------------------------------
51CONTAINS
52   
53   SUBROUTINE trc_init
54      !!---------------------------------------------------------------------
55      !!                     ***  ROUTINE trc_init  ***
56      !!
57      !! ** Purpose :   Initialization of the passive tracer fields
58      !!
59      !! ** Method  : - read namelist
60      !!              - control the consistancy
61      !!              - compute specific initialisations
62      !!              - set initial tracer fields (either read restart
63      !!                or read data or analytical formulation
64      !!---------------------------------------------------------------------
65      INTEGER ::   jk, jn, jl    ! dummy loop indices
66      CHARACTER (len=25) :: charout
67      REAL(wp), POINTER, DIMENSION(:,:,:) ::  ztrcdta   ! 4D  workspace
68      !!---------------------------------------------------------------------
69      !
70      IF( nn_timing == 1 )   CALL timing_start('trc_init')
71      !
72      IF(lwp) WRITE(numout,*)
73      IF(lwp) WRITE(numout,*) 'trc_init : initial set up of the passive tracers'
74      IF(lwp) WRITE(numout,*) '~~~~~~~'
75
76      CALL top_alloc()              ! allocate TOP arrays
77
78      l_trcdm2dc = ln_dm2dc .OR. ( ln_cpl .AND. ncpl_qsr_freq /= 1 )
79      l_trcdm2dc = l_trcdm2dc  .AND. .NOT. lk_offline
80      IF( l_trcdm2dc .AND. lwp ) &
81         &   CALL ctl_warn(' Coupling with passive tracers and used of diurnal cycle. &
82         & Computation of a daily mean shortwave for some biogeochemical models) ')
83
84      IF( nn_cla == 1 )   &
85         &  CALL ctl_stop( ' Cross Land Advection not yet implemented with passive tracer ; nn_cla must be 0' )
86
87      CALL trc_nam      ! read passive tracers namelists
88      !
89      IF(lwp) WRITE(numout,*)
90      !
91      IF( ln_rsttr .AND. .NOT. lk_offline ) CALL trc_rst_cal( nit000, 'READ' )   ! calendar
92      !
93      IF(lwp) WRITE(numout,*)
94                                                              ! masked grid volume
95      !                                                              ! masked grid volume
96      DO jk = 1, jpk
97         cvol(:,:,jk) = e1e2t(:,:) * fse3t(:,:,jk) * tmask(:,:,jk)
98      END DO
99      IF( lk_degrad ) cvol(:,:,:) = cvol(:,:,:) * facvol(:,:,:)      ! degrad option: reduction by facvol
100      !                                                              ! total volume of the ocean
101      areatot = glob_sum( cvol(:,:,:) )
102
103      IF( lk_pisces  )       CALL trc_ini_pisces       ! PISCES  bio-model
104      IF( lk_medusa  )       CALL trc_ini_medusa       ! MEDUSA  tracers
105      IF( lk_idtra   )       CALL trc_ini_idtra        ! Idealize tracers
106      IF( lk_cfc     )       CALL trc_ini_cfc          ! CFC     tracers
107      IF( lk_c14b    )       CALL trc_ini_c14b         ! C14 bomb  tracer
108      IF( lk_age     )       CALL trc_ini_age          ! AGE       tracer
109      IF( lk_my_trc  )       CALL trc_ini_my_trc       ! MY_TRC  tracers
110
111      CALL trc_ice_ini                                 ! Tracers in sea ice
112
113      IF( ln_ctl ) THEN
114         !
115         IF (narea == 1) THEN 
116            ! The tracer.stat file only contains global tracer sum values, if
117            ! it contains anything at all. Hence it only needs to be opened
118            ! and written to on the master PE, not on all PEs. 
119            CALL ctl_opn( numstr, 'tracer.stat', 'REPLACE','FORMATTED',  & 
120                          'SEQUENTIAL', -1, numout, lwp , narea ) 
121         ENDIF 
122         !
123      ENDIF
124
125      IF( ln_trcdta ) THEN
126         CALL trc_dta_init(jptra)
127      ENDIF
128
129      IF( ln_rsttr ) THEN
130        !
131        CALL trc_rst_read              ! restart from a file
132        !
133      ELSE
134        !
135        IF( ln_trcdta .AND. nb_trcdta > 0 ) THEN  ! Initialisation of tracer from a file that may also be used for damping
136            !
137            CALL wrk_alloc( jpi, jpj, jpk, ztrcdta )    ! Memory allocation
138            !
139            DO jn = 1, jptra
140               IF( ln_trc_ini(jn) ) THEN      ! update passive tracers arrays with input data read from file
141                  jl = n_trc_index(jn) 
142                  CALL trc_dta( nit000, sf_trcdta(jl),rf_trfac(jl) )   ! read tracer data at nit000
143                  ztrcdta(:,:,:) = sf_trcdta(jl)%fnow(:,:,:)
144                  trn(:,:,:,jn) = ztrcdta(:,:,:) * tmask(:,:,:) 
145                  IF( .NOT.ln_trcdmp .AND. .NOT.ln_trcdmp_clo ) THEN      !== deallocate data structure   ==!
146                     !                                                    (data used only for initialisation)
147                     IF(lwp) WRITE(numout,*) 'trc_dta: deallocate data arrays as they are only used to initialize the run'
148                                                  DEALLOCATE( sf_trcdta(jl)%fnow )     !  arrays in the structure
149                     IF( sf_trcdta(jl)%ln_tint )  DEALLOCATE( sf_trcdta(jl)%fdta )
150                     !
151                  ENDIF
152               ENDIF
153            ENDDO
154            CALL wrk_dealloc( jpi, jpj, jpk, ztrcdta )
155        ENDIF
156        !
157        trb(:,:,:,:) = trn(:,:,:,:)
158        !
159      ENDIF
160 
161      tra(:,:,:,:) = 0._wp
162      IF( ln_zps .AND. .NOT. lk_c1d .AND. .NOT. ln_isfcav )   &              ! Partial steps: before horizontal gradient of passive
163        &    CALL zps_hde    ( nit000, jptra, trn, gtru, gtrv  )  ! Partial steps: before horizontal gradient
164      IF( ln_zps .AND. .NOT. lk_c1d .AND.       ln_isfcav )   &
165        &    CALL zps_hde_isf( nit000, jptra, trn, pgtu=gtru, pgtv=gtrv, pgtui=gtrui, pgtvi=gtrvi )       ! tracers at the bottom ocean level
166
167
168      !
169      IF( nn_dttrc /= 1 )        CALL trc_sub_ini      ! Initialize variables for substepping passive tracers
170      !
171
172      trai(:) = 0._wp                                                   ! initial content of all tracers
173      DO jn = 1, jptra
174         trai(jn) = trai(jn) + glob_sum( trn(:,:,:,jn) * cvol(:,:,:)   )
175      END DO
176
177      IF(lwp) THEN               ! control print
178         WRITE(numout,*)
179         WRITE(numout,*)
180         WRITE(numout,*) '          *** Total number of passive tracer jptra = ', jptra
181         WRITE(numout,*) '          *** Total volume of ocean                = ', areatot
182         WRITE(numout,*) '          *** Total inital content of all tracers '
183         WRITE(numout,*)
184         DO jn = 1, jptra
185            WRITE(numout,9000) jn, TRIM( ctrcnm(jn) ), trai(jn)
186         ENDDO
187         WRITE(numout,*)
188      ENDIF
189      IF(lwp) WRITE(numout,*)
190      IF(ln_ctl) THEN            ! print mean trends (used for debugging)
191         CALL prt_ctl_trc_init
192         WRITE(charout, FMT="('ini ')")
193         CALL prt_ctl_trc_info( charout )
194         CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
195      ENDIF
196
197      IF(lwp) WRITE(numout,*)
198      IF(lwp) WRITE(numout,*) 'trc_init : passive tracer set up completed'
199      IF(lwp) WRITE(numout,*) '~~~~~~~'
200      IF(lwp) CALL flush(numout)
201# if defined key_debug_medusa
202         CALL trc_rst_stat
203         CALL flush(numout)
204# endif
205
2069000  FORMAT(' tracer nb : ',i2,'      name :',a10,'      initial content :',e18.10)
207      !
208      IF( nn_timing == 1 )   CALL timing_stop('trc_init')
209      !
210   END SUBROUTINE trc_init
211
212
213   SUBROUTINE top_alloc
214      !!----------------------------------------------------------------------
215      !!                     ***  ROUTINE top_alloc  ***
216      !!
217      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
218      !!----------------------------------------------------------------------
219      USE trcadv        , ONLY:   trc_adv_alloc          ! TOP-related alloc routines...
220      USE trc           , ONLY:   trc_alloc
221      USE trcnxt        , ONLY:   trc_nxt_alloc
222      USE trczdf        , ONLY:   trc_zdf_alloc
223      USE trdtrc_oce    , ONLY:   trd_trc_oce_alloc
224#if defined key_trdmxl_trc 
225      USE trdmxl_trc    , ONLY:   trd_mxl_trc_alloc
226#endif
227# if defined key_medusa
228      USE bio_medusa_mod, ONLY:   bio_medusa_alloc
229# endif
230
231      !
232      INTEGER :: ierr
233      !!----------------------------------------------------------------------
234      !
235      ierr =        trc_adv_alloc()          ! Start of TOP-related alloc routines...
236      ierr = ierr + trc_alloc    ()
237      ierr = ierr + trc_nxt_alloc()
238      ierr = ierr + trc_zdf_alloc()
239      ierr = ierr + trd_trc_oce_alloc()
240#if defined key_trdmxl_trc 
241      ierr = ierr + trd_mxl_trc_alloc()
242#endif
243#if defined key_medusa
244      ierr = ierr + bio_medusa_alloc()
245#endif
246      !
247      IF( lk_mpp    )   CALL mpp_sum( ierr )
248      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'top_alloc : unable to allocate standard ocean arrays' )
249      !
250   END SUBROUTINE top_alloc
251
252#else
253   !!----------------------------------------------------------------------
254   !!  Empty module :                                     No passive tracer
255   !!----------------------------------------------------------------------
256CONTAINS
257   SUBROUTINE trc_init                      ! Dummy routine   
258   END SUBROUTINE trc_init
259#endif
260
261   !!======================================================================
262END MODULE trcini
Note: See TracBrowser for help on using the repository browser.