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/2016/dev_r6519_HPC_4/NEMOGCM/NEMO/TOP_SRC – NEMO

source: branches/2016/dev_r6519_HPC_4/NEMOGCM/NEMO/TOP_SRC/trcini.F90 @ 7512

Last change on this file since 7512 was 7508, checked in by mocavero, 8 years ago

changes on code duplication and workshare construct

  • Property svn:keywords set to Id
File size: 13.1 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   !!----------------------------------------------------------------------
11#if defined key_top
12   !!----------------------------------------------------------------------
13   !!   'key_top'                                                TOP models
14   !!----------------------------------------------------------------------
15   !!   trc_init  :   Initialization for passive tracer
16   !!   top_alloc :   allocate the TOP arrays
17   !!----------------------------------------------------------------------
18   USE oce_trc         ! shared variables between ocean and passive tracers
19   USE trc             ! passive tracers common variables
20   USE trcnam          ! Namelist read
21   USE daymod          ! calendar manager
22   USE prtctl_trc      ! Print control passive tracers (prt_ctl_trc_init routine)
23   USE trcsub          ! variables to substep passive tracers
24   USE trcrst
25   USE lib_mpp         ! distribued memory computing library
26   USE sbc_oce
27   USE trcice          ! tracers in sea ice
28   USE trcbc,   only : trc_bc_init ! generalized Boundary Conditions
29 
30   IMPLICIT NONE
31   PRIVATE
32   
33   PUBLIC   trc_init   ! called by opa
34
35   !!----------------------------------------------------------------------
36   !! NEMO/TOP 4.0 , NEMO Consortium (2011)
37   !! $Id$
38   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
39   !!----------------------------------------------------------------------
40CONTAINS
41   
42   SUBROUTINE trc_init
43      !!---------------------------------------------------------------------
44      !!                     ***  ROUTINE trc_init  ***
45      !!
46      !! ** Purpose :   Initialization of the passive tracer fields
47      !!
48      !! ** Method  : - read namelist
49      !!              - control the consistancy
50      !!              - compute specific initialisations
51      !!              - set initial tracer fields (either read restart
52      !!                or read data or analytical formulation
53      !!---------------------------------------------------------------------
54      !
55      IF( nn_timing == 1 )   CALL timing_start('trc_init')
56      !
57      IF(lwp) WRITE(numout,*)
58      IF(lwp) WRITE(numout,*) 'trc_init : initial set up of the passive tracers'
59      IF(lwp) WRITE(numout,*) '~~~~~~~'
60
61      !
62      CALL top_alloc()   ! allocate TOP arrays
63      !
64      CALL trc_ini_ctl   ! control
65      !
66      CALL trc_nam       ! read passive tracers namelists
67      !
68      IF(lwp) WRITE(numout,*)
69      !
70      IF( ln_rsttr .AND. .NOT. lk_offline ) CALL trc_rst_cal( nit000, 'READ' )   ! calendar
71      !
72      IF(lwp) WRITE(numout,*)
73      !
74      CALL trc_ini_sms   ! SMS
75      !
76      CALL trc_ini_trp   ! passive tracers transport
77      !
78      CALL trc_ice_ini   ! Tracers in sea ice
79      !
80      IF( lwp )  &
81         &  CALL ctl_opn( numstr, 'tracer.stat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, lwp , narea )
82      !
83      CALL trc_ini_state  !  passive tracers initialisation : from a restart or from clim
84      !
85      IF( nn_dttrc /= 1 )        CALL trc_sub_ini      ! Initialize variables for substepping passive tracers
86      !
87      CALL trc_ini_inv   ! Inventories
88      !
89      IF( nn_timing == 1 )   CALL timing_stop('trc_init')
90      !
91   END SUBROUTINE trc_init
92
93
94   SUBROUTINE trc_ini_ctl
95      !!----------------------------------------------------------------------
96      !!                     ***  ROUTINE trc_ini_ctl  ***
97      !! ** Purpose :        Control  + ocean volume
98      !!----------------------------------------------------------------------
99      INTEGER ::   jk    ! dummy loop indices
100      !
101      ! Define logical parameter ton control dirunal cycle in TOP
102      l_trcdm2dc = ln_dm2dc .OR. ( ln_cpl .AND. ncpl_qsr_freq /= 1 )
103      l_trcdm2dc = l_trcdm2dc  .AND. .NOT. lk_offline
104      IF( l_trcdm2dc .AND. lwp )   CALL ctl_warn( 'Coupling with passive tracers and used of diurnal cycle.',   &
105         &                           'Computation of a daily mean shortwave for some biogeochemical models ' )
106      !
107   END SUBROUTINE trc_ini_ctl
108
109
110   SUBROUTINE trc_ini_inv
111      !!----------------------------------------------------------------------
112      !!                     ***  ROUTINE trc_ini_stat  ***
113      !! ** Purpose :      passive tracers inventories at initialsation phase
114      !!----------------------------------------------------------------------
115      INTEGER ::  jk, jn, jj, ji    ! dummy loop indices
116      CHARACTER (len=25) :: charout
117      !!----------------------------------------------------------------------
118      !                                                              ! masked grid volume
119!$OMP PARALLEL DO schedule(static) private(jk)
120      DO jk = 1, jpk
121         cvol(:,:,jk) = e1e2t(:,:) * e3t_n(:,:,jk) * tmask(:,:,jk)
122      END DO
123      IF( lk_degrad ) THEN 
124!$OMP PARALLEL DO schedule(static) private(jk,jj,ji)
125      DO jk = 1, jpk
126         DO jj = 1, jpj
127            DO ji = 1, jpi
128               cvol(ji,jj,jk) = cvol(ji,jj,jk) * facvol(ji,jj,jk)    ! degrad option: reduction by facvol
129            END DO
130         END DO
131      END DO
132      END IF
133      !                                                              ! total volume of the ocean
134      areatot = glob_sum( cvol(:,:,:) )
135      !
136      trai(:) = 0._wp                                                   ! initial content of all tracers
137      DO jn = 1, jptra
138         trai(jn) = trai(jn) + glob_sum( trn(:,:,:,jn) * cvol(:,:,:)   )
139      END DO
140
141      IF(lwp) THEN               ! control print
142         WRITE(numout,*)
143         WRITE(numout,*)
144         WRITE(numout,*) '          *** Total number of passive tracer jptra = ', jptra
145         WRITE(numout,*) '          *** Total volume of ocean                = ', areatot
146         WRITE(numout,*) '          *** Total inital content of all tracers '
147         WRITE(numout,*)
148         DO jn = 1, jptra
149            WRITE(numout,9000) jn, TRIM( ctrcnm(jn) ), trai(jn)
150         ENDDO
151         WRITE(numout,*)
152      ENDIF
153      IF(lwp) WRITE(numout,*)
154      IF(ln_ctl) THEN            ! print mean trends (used for debugging)
155         CALL prt_ctl_trc_init
156         WRITE(charout, FMT="('ini ')")
157         CALL prt_ctl_trc_info( charout )
158         CALL prt_ctl_trc( tab4d=trn, mask=tmask, clinfo=ctrcnm )
159      ENDIF
1609000  FORMAT(' tracer nb : ',i2,'      name :',a10,'      initial content :',e18.10)
161      !
162   END SUBROUTINE trc_ini_inv
163
164
165   SUBROUTINE trc_ini_sms
166      !!----------------------------------------------------------------------
167      !!                     ***  ROUTINE trc_ini_sms  ***
168      !! ** Purpose :   SMS initialisation
169      !!----------------------------------------------------------------------
170      USE trcini_cfc      ! CFC      initialisation
171      USE trcini_pisces   ! PISCES   initialisation
172      USE trcini_c14b     ! C14 bomb initialisation
173      USE trcini_my_trc   ! MY_TRC   initialisation
174      !!----------------------------------------------------------------------
175      IF( lk_pisces  )       CALL trc_ini_pisces       ! PISCES  bio-model
176      IF( lk_cfc     )       CALL trc_ini_cfc          ! CFC     tracers
177      IF( lk_c14b    )       CALL trc_ini_c14b         ! C14 bomb  tracer
178      IF( lk_my_trc  )       CALL trc_ini_my_trc       ! MY_TRC  tracers
179      !
180   END SUBROUTINE trc_ini_sms
181
182   SUBROUTINE trc_ini_trp
183      !!----------------------------------------------------------------------
184      !!                     ***  ROUTINE trc_ini_trp  ***
185      !!
186      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
187      !!----------------------------------------------------------------------
188      USE trcdmp , ONLY:  trc_dmp_ini
189      USE trcadv , ONLY:  trc_adv_ini
190      USE trcldf , ONLY:  trc_ldf_ini
191      USE trczdf , ONLY:  trc_zdf_ini
192      USE trcrad , ONLY:  trc_rad_ini
193      !
194      INTEGER :: ierr
195      !!----------------------------------------------------------------------
196      !
197      IF( ln_trcdmp )  CALL  trc_dmp_ini          ! damping
198                       CALL  trc_adv_ini          ! advection
199                       CALL  trc_ldf_ini          ! lateral diffusion
200                       CALL  trc_zdf_ini          ! vertical diffusion
201                       CALL  trc_rad_ini          ! positivity of passive tracers
202      !
203   END SUBROUTINE trc_ini_trp
204
205
206   SUBROUTINE trc_ini_state
207      !!----------------------------------------------------------------------
208      !!                     ***  ROUTINE trc_ini_state ***
209      !! ** Purpose :          Initialisation of passive tracer concentration
210      !!----------------------------------------------------------------------
211      USE zpshde          ! partial step: hor. derivative   (zps_hde routine)
212      USE trcrst          ! passive tracers restart
213      USE trcdta          ! initialisation from files
214      !
215      INTEGER ::   jk, jn, jl, jj, ji    ! dummy loop indices
216      !!----------------------------------------------------------------------
217      !
218      ! Initialisation of tracers Initial Conditions
219      IF( ln_trcdta )      CALL trc_dta_init(jptra)
220
221      ! Initialisation of tracers Boundary Conditions
222      IF( lk_my_trc )     CALL trc_bc_init(jptra)
223
224      IF( ln_rsttr ) THEN
225        !
226        CALL trc_rst_read              ! restart from a file
227        !
228      ELSE
229        !
230        IF( ln_trcdta .AND. nb_trcdta > 0 ) THEN  ! Initialisation of tracer from a file that may also be used for damping
231            !
232           DO jn = 1, jptra
233               IF( ln_trc_ini(jn) ) THEN      ! update passive tracers arrays with input data read from file
234                  jl = n_trc_index(jn) 
235                  CALL trc_dta( nit000, sf_trcdta(jl) )   ! read tracer data at nit000
236!$OMP PARALLEL DO schedule(static) private(jk,jj,ji)
237                  DO jk = 1, jpk
238                     DO jj = 1, jpj
239                        DO ji = 1, jpi
240                           trn(ji,jj,jk,jn) = sf_trcdta(jl)%fnow(ji,jj,jk) * tmask(ji,jj,jk) * rf_trfac(jl)
241                        END DO
242                     END DO
243                  END DO
244                  !
245                  IF( .NOT.ln_trcdmp .AND. .NOT.ln_trcdmp_clo ) THEN      !== deallocate data structure   ==!
246                     !                                                    (data used only for initialisation)
247                     IF(lwp) WRITE(numout,*) 'trc_dta: deallocate data arrays as they are only used to initialize the run'
248                                                  DEALLOCATE( sf_trcdta(jl)%fnow )     !  arrays in the structure
249                     IF( sf_trcdta(jl)%ln_tint )  DEALLOCATE( sf_trcdta(jl)%fdta )
250                     !
251                  ENDIF
252               ENDIF
253            ENDDO
254            !
255        ENDIF
256        !
257      DO jn = 1, jptra
258!$OMP PARALLEL DO schedule(static) private(jk,jj,ji)
259         DO jk = 1, jpk
260            DO jj = 1, jpj
261               DO ji = 1, jpi
262                  trb(ji,jj,jk,jn) = trn(ji,jj,jk,jn)
263               END DO
264            END DO
265         END DO
266      END DO
267        !
268      ENDIF
269 
270      DO jn = 1, jptra
271!$OMP PARALLEL DO schedule(static) private(jk,jj,ji)
272         DO jk = 1, jpk
273            DO jj = 1, jpj
274               DO ji = 1, jpi
275                  tra(ji,jj,jk,jn) = 0._wp
276               END DO
277            END DO
278         END DO
279      END DO
280      !                                                         ! Partial top/bottom cell: GRADh(trn)
281   END SUBROUTINE trc_ini_state
282
283   SUBROUTINE top_alloc
284      !!----------------------------------------------------------------------
285      !!                     ***  ROUTINE top_alloc  ***
286      !!
287      !! ** Purpose :   Allocate all the dynamic arrays of the OPA modules
288      !!----------------------------------------------------------------------
289      USE trc           , ONLY:   trc_alloc
290      USE trdtrc_oce    , ONLY:   trd_trc_oce_alloc
291#if defined key_trdmxl_trc 
292      USE trdmxl_trc    , ONLY:   trd_mxl_trc_alloc
293#endif
294      !
295      INTEGER :: ierr
296      !!----------------------------------------------------------------------
297      !
298      ierr =        trc_alloc()
299      ierr = ierr + trd_trc_oce_alloc()
300#if defined key_trdmxl_trc 
301      ierr = ierr + trd_mxl_trc_alloc()
302#endif
303      !
304      IF( lk_mpp    )   CALL mpp_sum( ierr )
305      IF( ierr /= 0 )   CALL ctl_stop( 'STOP', 'top_alloc : unable to allocate standard ocean arrays' )
306      !
307   END SUBROUTINE top_alloc
308
309#else
310   !!----------------------------------------------------------------------
311   !!  Empty module :                                     No passive tracer
312   !!----------------------------------------------------------------------
313CONTAINS
314   SUBROUTINE trc_init                      ! Dummy routine   
315   END SUBROUTINE trc_init
316#endif
317
318   !!======================================================================
319END MODULE trcini
Note: See TracBrowser for help on using the repository browser.