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.
trcadv.F90 in NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/src/TOP/TRP – NEMO

source: NEMO/branches/2020/dev_r14116_HPC-04_mcastril_Mixed_Precision_implementation_final/src/TOP/TRP/trcadv.F90 @ 14219

Last change on this file since 14219 was 14219, checked in by mcastril, 4 years ago

Add Mixed Precision support by Oriol Tintó

  • Property svn:keywords set to Id
File size: 15.6 KB
Line 
1MODULE trcadv
2   !!==============================================================================
3   !!                       ***  MODULE  trcadv  ***
4   !! Ocean passive tracers:  advection trend
5   !!==============================================================================
6   !! History :  2.0  !  2005-11  (G. Madec)  Original code
7   !!            3.0  !  2010-06  (C. Ethe)   Adapted to passive tracers
8   !!            3.7  !  2014-05  (G. Madec, C. Ethe)  Add 2nd/4th order cases for CEN and FCT schemes
9   !!            4.0  !  2017-09  (G. Madec)  remove vertical time-splitting option
10   !!----------------------------------------------------------------------
11#if defined key_top
12   !!----------------------------------------------------------------------
13   !!   'key_top'                                                TOP models
14   !!----------------------------------------------------------------------
15   !!   trc_adv       : compute ocean tracer advection trend
16   !!   trc_adv_ini   : control the different options of advection scheme
17   !!----------------------------------------------------------------------
18   USE par_trc        ! need jptra, number of passive tracers
19   USE oce_trc        ! ocean dynamics and active tracers
20   USE trc            ! ocean passive tracers variables
21   USE sbcwave        ! wave module
22   USE sbc_oce        ! surface boundary condition: ocean
23   USE traadv_cen     ! centered scheme           (tra_adv_cen  routine)
24   USE traadv_fct     ! FCT      scheme           (tra_adv_fct  routine)
25   USE traadv_fct_lf  ! FCT      scheme           (tra_adv_fct  routine - loop fusion version)
26   USE traadv_mus     ! MUSCL    scheme           (tra_adv_mus  routine)
27   USE traadv_mus_lf  ! MUSCL    scheme           (tra_adv_mus  routine - loop fusion version)
28   USE traadv_ubs     ! UBS      scheme           (tra_adv_ubs  routine)
29   USE traadv_qck     ! QUICKEST scheme           (tra_adv_qck  routine)
30   USE tramle         ! ML eddy induced transport (tra_adv_mle  routine)
31   USE ldftra         ! lateral diffusion: eddy diffusivity & EIV coeff.
32   USE ldfslp         ! Lateral diffusion: slopes of neutral surfaces
33   !
34   USE prtctl         ! control print
35   USE timing         ! Timing
36
37   IMPLICIT NONE
38   PRIVATE
39
40   PUBLIC   trc_adv       ! called by trctrp.F90
41   PUBLIC   trc_adv_ini   ! called by trcini.F90
42
43   !                            !!* Namelist namtrc_adv *
44   LOGICAL ::   ln_trcadv_OFF    ! no advection on passive tracers
45   LOGICAL ::   ln_trcadv_cen    ! centered scheme flag
46   INTEGER ::      nn_cen_h, nn_cen_v   ! =2/4 : horizontal and vertical choices of the order of CEN scheme
47   LOGICAL ::   ln_trcadv_fct    ! FCT scheme flag
48   INTEGER ::      nn_fct_h, nn_fct_v   ! =2/4 : horizontal and vertical choices of the order of FCT scheme
49   LOGICAL ::   ln_trcadv_mus    ! MUSCL scheme flag
50   LOGICAL ::      ln_mus_ups           ! use upstream scheme in vivcinity of river mouths
51   LOGICAL ::   ln_trcadv_ubs    ! UBS scheme flag
52   INTEGER ::      nn_ubs_v             ! =2/4 : vertical choice of the order of UBS scheme
53   LOGICAL ::   ln_trcadv_qck    ! QUICKEST scheme flag
54
55   INTEGER ::   nadv             ! choice of the type of advection scheme
56   !                             ! associated indices:
57   INTEGER, PARAMETER ::   np_NO_adv  = 0   ! no T-S advection
58   INTEGER, PARAMETER ::   np_CEN     = 1   ! 2nd/4th order centered scheme
59   INTEGER, PARAMETER ::   np_FCT     = 2   ! 2nd/4th order Flux Corrected Transport scheme
60   INTEGER, PARAMETER ::   np_MUS     = 3   ! MUSCL scheme
61   INTEGER, PARAMETER ::   np_UBS     = 4   ! 3rd order Upstream Biased Scheme
62   INTEGER, PARAMETER ::   np_QCK     = 5   ! QUICK scheme
63   
64#  include "domzgr_substitute.h90"
65#  include "single_precision_substitute.h90"
66   !!----------------------------------------------------------------------
67   !! NEMO/TOP 4.0 , NEMO Consortium (2018)
68   !! $Id$
69   !! Software governed by the CeCILL license (see ./LICENSE)
70   !!----------------------------------------------------------------------
71CONTAINS
72
73   SUBROUTINE trc_adv( kt, Kbb, Kmm, ptr, Krhs  )
74      !!----------------------------------------------------------------------
75      !!                  ***  ROUTINE trc_adv  ***
76      !!
77      !! ** Purpose :   compute the ocean tracer advection trend.
78      !!
79      !! ** Method  : - Update after tracers (tr(Krhs)) with the advection term following nadv
80      !!----------------------------------------------------------------------
81      INTEGER                                   , INTENT(in)    :: kt   ! ocean time-step index
82      INTEGER                                   , INTENT(in)    :: Kbb, Kmm, Krhs ! time level indices
83      REAL(dp), DIMENSION(jpi,jpj,jpk,jptra,jpt), INTENT(inout) :: ptr            ! passive tracers and RHS of tracer equation
84      !
85      INTEGER ::   jk   ! dummy loop index
86      CHARACTER (len=22) ::   charout
87      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zuu, zvv, zww  ! effective velocity
88      !!----------------------------------------------------------------------
89      !
90      IF( ln_timing )   CALL timing_start('trc_adv')
91      !
92      !                                         !==  effective transport  ==!
93      IF( l_offline ) THEN
94         zuu(:,:,:) = uu(:,:,:,Kmm)                ! already in (uu(Kmm),vv(Kmm),ww)
95         zvv(:,:,:) = vv(:,:,:,Kmm)
96         zww(:,:,:) = ww(:,:,:)
97      ELSE                                         ! build the effective transport
98         zuu(:,:,jpk) = 0._wp
99         zvv(:,:,jpk) = 0._wp
100         zww(:,:,jpk) = 0._wp
101         IF( ln_wave .AND. ln_sdw )  THEN
102            DO jk = 1, jpkm1                                                       ! eulerian transport + Stokes Drift
103               zuu(:,:,jk) = e2u  (:,:) * e3u(:,:,jk,Kmm) * ( uu(:,:,jk,Kmm) + usd(:,:,jk) )
104               zvv(:,:,jk) = e1v  (:,:) * e3v(:,:,jk,Kmm) * ( vv(:,:,jk,Kmm) + vsd(:,:,jk) )
105               zww(:,:,jk) = e1e2t(:,:)                   * ( ww(:,:,jk) + wsd(:,:,jk) )
106            END DO
107         ELSE
108            DO jk = 1, jpkm1
109               zuu(:,:,jk) = e2u  (:,:) * e3u(:,:,jk,Kmm) * uu(:,:,jk,Kmm)                   ! eulerian transport
110               zvv(:,:,jk) = e1v  (:,:) * e3v(:,:,jk,Kmm) * vv(:,:,jk,Kmm)
111               zww(:,:,jk) = e1e2t(:,:)                   * ww(:,:,jk)
112            END DO
113         ENDIF
114         !
115         IF( ln_vvl_ztilde .OR. ln_vvl_layer ) THEN                                 ! add z-tilde and/or vvl corrections
116            zuu(:,:,:) = zuu(:,:,:) + un_td(:,:,:)
117            zvv(:,:,:) = zvv(:,:,:) + vn_td(:,:,:)
118         ENDIF
119         !
120         IF( ln_ldfeiv .AND. .NOT. ln_traldf_triad )   & 
121            &              CALL ldf_eiv_trp( kt, nittrc000, zuu, zvv, zww, 'TRC', Kmm, Krhs )  ! add the eiv transport
122         !
123         IF( ln_mle    )   CALL tra_mle_trp( kt, nittrc000, zuu, zvv, zww, 'TRC', Kmm       )  ! add the mle transport
124         !
125      ENDIF
126      !
127      SELECT CASE ( nadv )                      !==  compute advection trend and add it to general trend  ==!
128      !
129      CASE ( np_CEN )                                 ! Centered : 2nd / 4th order
130         IF (nn_hls.EQ.2) CALL lbc_lnk( 'trcadv', ptr(:,:,:,:,Kmm), 'T', 1._wp)
131         CALL tra_adv_cen( kt, nittrc000,'TRC',          zuu, zvv, zww,      Kmm, ptr, jptra, Krhs, nn_cen_h, nn_cen_v )
132      CASE ( np_FCT )                                 ! FCT      : 2nd / 4th order
133         IF (nn_hls.EQ.2) THEN
134            CALL lbc_lnk_multi( 'trcadv', ptr(:,:,:,:,Kbb), 'T', 1._wp, ptr(:,:,:,:,Kmm), 'T', 1._wp)
135            CALL lbc_lnk_multi( 'traadv', zuu(:,:,:), 'U', -1._wp, zvv(:,:,:), 'V', -1._wp, zww(:,:,:), 'W', 1._wp)
136#if defined key_loop_fusion
137            CALL tra_adv_fct_lf( kt, nittrc000,'TRC', rDt_trc, zuu, zvv, zww, Kbb, Kmm, ptr, jptra, Krhs, nn_fct_h, nn_fct_v )
138#else
139            CALL tra_adv_fct( kt, nittrc000,'TRC', rDt_trc, zuu, zvv, zww, Kbb, Kmm, ptr, jptra, Krhs, nn_fct_h, nn_fct_v )
140#endif
141         ELSE
142            CALL tra_adv_fct( kt, nittrc000,'TRC', rDt_trc, zuu, zvv, zww, Kbb, Kmm, ptr, jptra, Krhs, nn_fct_h, nn_fct_v )
143         END IF
144      CASE ( np_MUS )                                 ! MUSCL
145         IF (nn_hls.EQ.2) THEN
146            IF (nn_hls.EQ.2) CALL lbc_lnk( 'trcadv', ptr(:,:,:,:,Kbb), 'T', 1._wp)
147#if defined key_loop_fusion
148            CALL tra_adv_mus_lf( kt, nittrc000,'TRC', rDt_trc, zuu, zvv, zww, Kbb, Kmm, ptr, jptra, Krhs, ln_mus_ups ) 
149#else
150            CALL tra_adv_mus( kt, nittrc000,'TRC', rDt_trc, zuu, zvv, zww, Kbb, Kmm, ptr, jptra, Krhs, ln_mus_ups ) 
151#endif
152         ELSE
153            CALL tra_adv_mus( kt, nittrc000,'TRC', rDt_trc, zuu, zvv, zww, Kbb, Kmm, ptr, jptra, Krhs, ln_mus_ups ) 
154         END IF
155      CASE ( np_UBS )                                 ! UBS
156         IF (nn_hls.EQ.2) CALL lbc_lnk( 'trcadv', ptr(:,:,:,:,Kbb), 'T', 1._wp)
157         CALL tra_adv_ubs( kt, nittrc000,'TRC', rDt_trc, zuu, zvv, zww, Kbb, Kmm, ptr, jptra, Krhs, nn_ubs_v           )
158      CASE ( np_QCK )                                 ! QUICKEST
159         IF (nn_hls.EQ.2) THEN
160            CALL lbc_lnk_multi( 'trcadv', zuu(:,:,:), 'U', -1._wp, zvv(:,:,:), 'V', -1._wp)
161            CALL lbc_lnk( 'traadv', ptr(:,:,:,:,Kbb), 'T', 1._wp)
162         END IF
163         CALL tra_adv_qck( kt, nittrc000,'TRC', rDt_trc, zuu, zvv, zww, Kbb, Kmm, ptr, jptra, Krhs                     )
164      !
165      END SELECT
166      !                 
167      IF( sn_cfctl%l_prttrc ) THEN        !== print mean trends (used for debugging)
168         WRITE(charout, FMT="('adv ')")
169         CALL prt_ctl_info( charout, cdcomp = 'top' )
170         CALL prt_ctl( tab4d_1=CASTWP(tr(:,:,:,:,Krhs)), mask1=tmask, clinfo=ctrcnm, clinfo3='trd' )
171      END IF
172      !
173      IF( ln_timing )   CALL timing_stop('trc_adv')
174      !
175   END SUBROUTINE trc_adv
176
177
178   SUBROUTINE trc_adv_ini
179      !!---------------------------------------------------------------------
180      !!                  ***  ROUTINE trc_adv_ini  ***
181      !!               
182      !! ** Purpose :   Control the consistency between namelist options for
183      !!              passive tracer advection schemes and set nadv
184      !!----------------------------------------------------------------------
185      INTEGER ::   ioptio, ios   ! Local integer
186      !!
187      NAMELIST/namtrc_adv/ ln_trcadv_OFF,                        &   ! No advection
188         &                 ln_trcadv_cen, nn_cen_h, nn_cen_v,    &   ! CEN
189         &                 ln_trcadv_fct, nn_fct_h, nn_fct_v,    &   ! FCT
190         &                 ln_trcadv_mus, ln_mus_ups,            &   ! MUSCL
191         &                 ln_trcadv_ubs,           nn_ubs_v,    &   ! UBS
192         &                 ln_trcadv_qck                             ! QCK
193      !!----------------------------------------------------------------------
194      !
195      !                                !==  Namelist  ==!
196      READ  ( numnat_ref, namtrc_adv, IOSTAT = ios, ERR = 901)
197901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtrc_adv in reference namelist' )
198      READ  ( numnat_cfg, namtrc_adv, IOSTAT = ios, ERR = 902 )
199902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtrc_adv in configuration namelist' )
200      IF(lwm) WRITE ( numont, namtrc_adv )
201      !
202      IF(lwp) THEN                           ! Namelist print
203         WRITE(numout,*)
204         WRITE(numout,*) 'trc_adv_ini : choice/control of the tracer advection scheme'
205         WRITE(numout,*) '~~~~~~~~~~~'
206         WRITE(numout,*) '   Namelist namtrc_adv : chose a advection scheme for tracers'
207         WRITE(numout,*) '      No advection on passive tracers           ln_trcadv_OFF = ', ln_trcadv_OFF
208         WRITE(numout,*) '      centered scheme                           ln_trcadv_cen = ', ln_trcadv_cen
209         WRITE(numout,*) '            horizontal 2nd/4th order               nn_cen_h   = ', nn_fct_h
210         WRITE(numout,*) '            vertical   2nd/4th order               nn_cen_v   = ', nn_fct_v
211         WRITE(numout,*) '      Flux Corrected Transport scheme           ln_trcadv_fct = ', ln_trcadv_fct
212         WRITE(numout,*) '            horizontal 2nd/4th order               nn_fct_h   = ', nn_fct_h
213         WRITE(numout,*) '            vertical   2nd/4th order               nn_fct_v   = ', nn_fct_v
214         WRITE(numout,*) '      MUSCL scheme                              ln_trcadv_mus = ', ln_trcadv_mus
215         WRITE(numout,*) '            + upstream scheme near river mouths    ln_mus_ups = ', ln_mus_ups
216         WRITE(numout,*) '      UBS scheme                                ln_trcadv_ubs = ', ln_trcadv_ubs
217         WRITE(numout,*) '            vertical   2nd/4th order               nn_ubs_v   = ', nn_ubs_v
218         WRITE(numout,*) '      QUICKEST scheme                           ln_trcadv_qck = ', ln_trcadv_qck
219      ENDIF
220      !
221      !                                !==  Parameter control & set nadv ==!
222      ioptio = 0
223      IF( ln_trcadv_OFF ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_NO_adv   ;   ENDIF
224      IF( ln_trcadv_cen ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_CEN      ;   ENDIF
225      IF( ln_trcadv_fct ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_FCT      ;   ENDIF
226      IF( ln_trcadv_mus ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_MUS      ;   ENDIF
227      IF( ln_trcadv_ubs ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_UBS      ;   ENDIF
228      IF( ln_trcadv_qck ) THEN   ;   ioptio = ioptio + 1   ;   nadv = np_QCK      ;   ENDIF
229      !
230      IF( ioptio /= 1 )   CALL ctl_stop( 'trc_adv_ini: Choose ONE advection option in namelist namtrc_adv' )
231      !
232      IF( ln_trcadv_cen .AND. ( nn_cen_h /= 2 .AND. nn_cen_h /= 4 )   &
233                        .AND. ( nn_cen_v /= 2 .AND. nn_cen_v /= 4 )   ) THEN
234        CALL ctl_stop( 'trc_adv_ini: CEN scheme, choose 2nd or 4th order' )
235      ENDIF
236      IF( ln_trcadv_fct .AND. ( nn_fct_h /= 2 .AND. nn_fct_h /= 4 )   &
237                        .AND. ( nn_fct_v /= 2 .AND. nn_fct_v /= 4 )   ) THEN
238        CALL ctl_stop( 'trc_adv_ini: FCT scheme, choose 2nd or 4th order' )
239      ENDIF
240      IF( ln_trcadv_ubs .AND. ( nn_ubs_v /= 2 .AND. nn_ubs_v /= 4 )   ) THEN
241        CALL ctl_stop( 'trc_adv_ini: UBS scheme, choose 2nd or 4th order' )
242      ENDIF
243      IF( ln_trcadv_ubs .AND. nn_ubs_v == 4 ) THEN
244         CALL ctl_warn( 'trc_adv_ini: UBS scheme, only 2nd FCT scheme available on the vertical. It will be used' )
245      ENDIF
246      IF( ln_isfcav ) THEN                                                       ! ice-shelf cavities
247         IF(  ln_trcadv_cen .AND. nn_cen_v == 4    .OR.   &                            ! NO 4th order with ISF
248            & ln_trcadv_fct .AND. nn_fct_v == 4   )   CALL ctl_stop( 'tra_adv_ini: 4th order COMPACT scheme not allowed with ISF' )
249      ENDIF
250      !
251      !                                !==  Print the choice  ==! 
252      IF(lwp) THEN
253         WRITE(numout,*)
254         SELECT CASE ( nadv )
255         CASE( np_NO_adv  )   ;   WRITE(numout,*) '      ===>>   NO passive tracer advection'
256         CASE( np_CEN     )   ;   WRITE(numout,*) '      ===>>   CEN      scheme is used. Horizontal order: ', nn_cen_h,   &
257            &                                                                     ' Vertical   order: ', nn_cen_v
258         CASE( np_FCT     )   ;   WRITE(numout,*) '      ===>>   FCT      scheme is used. Horizontal order: ', nn_fct_h,   &
259            &                                                                      ' Vertical   order: ', nn_fct_v
260         CASE( np_MUS     )   ;   WRITE(numout,*) '      ===>>   MUSCL    scheme is used'
261         CASE( np_UBS     )   ;   WRITE(numout,*) '      ===>>   UBS      scheme is used'
262         CASE( np_QCK     )   ;   WRITE(numout,*) '      ===>>   QUICKEST scheme is used'
263         END SELECT
264      ENDIF
265      !
266   END SUBROUTINE trc_adv_ini
267   
268#endif
269
270  !!======================================================================
271END MODULE trcadv
Note: See TracBrowser for help on using the repository browser.