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

source: trunk/NEMOGCM/NEMO/TOP_SRC/trcini.F90 @ 7738

Last change on this file since 7738 was 7698, checked in by mocavero, 7 years ago

update trunk with OpenMP parallelization

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