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.
tradmp.F90 in NEMO/branches/2021/dev_r14116_HPC-10_mcastril_Mixed_Precision_implementation/src/OCE/TRA – NEMO

source: NEMO/branches/2021/dev_r14116_HPC-10_mcastril_Mixed_Precision_implementation/src/OCE/TRA/tradmp.F90 @ 14986

Last change on this file since 14986 was 14986, checked in by sparonuz, 3 years ago

Merge trunk -r14984:HEAD

  • Property svn:keywords set to Id
File size: 12.1 KB
Line 
1MODULE tradmp
2   !!======================================================================
3   !!                       ***  MODULE  tradmp  ***
4   !! Ocean physics: internal restoring trend on active tracers (T and S)
5   !!======================================================================
6   !! History :  OPA  ! 1991-03  (O. Marti, G. Madec)  Original code
7   !!                 ! 1992-06  (M. Imbard)  doctor norme
8   !!                 ! 1998-07  (M. Imbard, G. Madec) ORCA version
9   !!            7.0  ! 2001-02  (M. Imbard)  add distance to coast, Original code
10   !!            8.1  ! 2001-02  (G. Madec, E. Durand)  cleaning
11   !!  NEMO      1.0  ! 2002-08  (G. Madec, E. Durand)  free form + modules
12   !!            3.2  ! 2009-08  (G. Madec, C. Talandier)  DOCTOR norm for namelist parameter
13   !!            3.3  ! 2010-06  (C. Ethe, G. Madec) merge TRA-TRC
14   !!            3.4  ! 2011-04  (G. Madec, C. Ethe) Merge of dtatem and dtasal + suppression of CPP keys
15   !!            3.6  ! 2015-06  (T. Graham)  read restoring coefficient in a file
16   !!            3.7  ! 2015-10  (G. Madec)  remove useless trends arrays
17   !!----------------------------------------------------------------------
18
19   !!----------------------------------------------------------------------
20   !!   tra_dmp_alloc : allocate tradmp arrays
21   !!   tra_dmp       : update the tracer trend with the internal damping
22   !!   tra_dmp_init  : initialization, namlist read, parameters control
23   !!----------------------------------------------------------------------
24   USE oce            ! ocean: variables
25   USE dom_oce        ! ocean: domain variables
26   USE c1d            ! 1D vertical configuration
27   USE trd_oce        ! trends: ocean variables
28   USE trdtra         ! trends manager: tracers
29   USE zdf_oce        ! ocean: vertical physics
30   USE phycst         ! physical constants
31   USE dtatsd         ! data: temperature & salinity
32   USE zdfmxl         ! vertical physics: mixed layer depth
33   !
34   USE in_out_manager ! I/O manager
35   USE iom            ! XIOS
36   USE lib_mpp        ! MPP library
37   USE prtctl         ! Print control
38   USE timing         ! Timing
39
40   IMPLICIT NONE
41   PRIVATE
42
43   PUBLIC   tra_dmp        ! called by step.F90
44   PUBLIC   tra_dmp_init   ! called by nemogcm.F90
45
46   !                                           !!* Namelist namtra_dmp : T & S newtonian damping *
47   LOGICAL            , PUBLIC ::   ln_tradmp   !: internal damping flag
48   INTEGER            , PUBLIC ::   nn_zdmp     !: = 0/1/2 flag for damping in the mixed layer
49   CHARACTER(LEN=200) , PUBLIC ::   cn_resto    !: name of netcdf file containing restoration coefficient field
50   !
51   REAL(wp), PUBLIC, ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   resto    !: restoring coeff. on T and S (s-1)
52
53   !! * Substitutions
54#  include "do_loop_substitute.h90"
55#  include "single_precision_substitute.h90"
56#  include "domzgr_substitute.h90"
57   !!----------------------------------------------------------------------
58   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
59   !! $Id$
60   !! Software governed by the CeCILL license (see ./LICENSE)
61   !!----------------------------------------------------------------------
62CONTAINS
63
64   INTEGER FUNCTION tra_dmp_alloc()
65      !!----------------------------------------------------------------------
66      !!                ***  FUNCTION tra_dmp_alloc  ***
67      !!----------------------------------------------------------------------
68      ALLOCATE( resto(jpi,jpj,jpk), STAT= tra_dmp_alloc )
69      !
70      CALL mpp_sum ( 'tradmp', tra_dmp_alloc )
71      IF( tra_dmp_alloc > 0 )   CALL ctl_warn('tra_dmp_alloc: allocation of arrays failed')
72      !
73   END FUNCTION tra_dmp_alloc
74
75
76   SUBROUTINE tra_dmp( kt, Kbb, Kmm, pts, Krhs )
77      !!----------------------------------------------------------------------
78      !!                   ***  ROUTINE tra_dmp  ***
79      !!
80      !! ** Purpose :   Compute the tracer trend due to a newtonian damping
81      !!      of the tracer field towards given data field and add it to the
82      !!      general tracer trends.
83      !!
84      !! ** Method  :   Newtonian damping towards t_dta and s_dta computed
85      !!      and add to the general tracer trends:
86      !!                     ta = ta + resto * (t_dta - tb)
87      !!                     sa = sa + resto * (s_dta - sb)
88      !!         The trend is computed either throughout the water column
89      !!      (nlmdmp=0) or in area of weak vertical mixing (nlmdmp=1) or
90      !!      below the well mixed layer (nlmdmp=2)
91      !!
92      !! ** Action  : - tsa: tracer trends updated with the damping trend
93      !!----------------------------------------------------------------------
94      INTEGER,                                   INTENT(in   ) :: kt              ! ocean time-step index
95      INTEGER,                                   INTENT(in   ) :: Kbb, Kmm, Krhs  ! time level indices
96      REAL(dp), DIMENSION(jpi,jpj,jpk,jpts,jpt), INTENT(inout) :: pts             ! active tracers and RHS of tracer equation
97      !
98      INTEGER ::   ji, jj, jk, jn   ! dummy loop indices
99      REAL(dp), DIMENSION(A2D(nn_hls),jpk,jpts)     ::  zts_dta
100      REAL(wp), DIMENSION(:,:,:)  , ALLOCATABLE ::  zwrk
101      REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE ::  ztrdts
102      !!----------------------------------------------------------------------
103      !
104      IF( ln_timing )   CALL timing_start('tra_dmp')
105      !
106      IF( l_trdtra .OR. iom_use('hflx_dmp_cea') .OR. iom_use('sflx_dmp_cea') ) THEN   !* Save ta and sa trends
107         ALLOCATE( ztrdts(A2D(nn_hls),jpk,jpts) )
108         DO jn = 1, jpts
109            DO_3D( nn_hls, nn_hls, nn_hls, nn_hls, 1, jpk )
110               ztrdts(ji,jj,jk,jn) = pts(ji,jj,jk,jn,Krhs)
111            END_3D
112         END DO
113      ENDIF
114      !                           !==  input T-S data at kt  ==!
115      CALL dta_tsd( kt, zts_dta )            ! read and interpolates T-S data at kt
116      !
117      SELECT CASE ( nn_zdmp )     !==  type of damping  ==!
118      !
119      CASE( 0 )                        !*  newtonian damping throughout the water column  *!
120         DO jn = 1, jpts
121            DO_3D( 0, 0, 0, 0, 1, jpkm1 )
122               pts(ji,jj,jk,jn,Krhs) = pts(ji,jj,jk,jn,Krhs)           &
123                  &                  + resto(ji,jj,jk) * ( zts_dta(ji,jj,jk,jn) - pts(ji,jj,jk,jn,Kbb) )
124            END_3D
125         END DO
126         !
127      CASE ( 1 )                       !*  no damping in the turbocline (avt > 5 cm2/s)  *!
128         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
129            IF( avt(ji,jj,jk) <= avt_c ) THEN
130               pts(ji,jj,jk,jp_tem,Krhs) = pts(ji,jj,jk,jp_tem,Krhs)   &
131                  &                      + resto(ji,jj,jk) * ( zts_dta(ji,jj,jk,jp_tem) - pts(ji,jj,jk,jp_tem,Kbb) )
132               pts(ji,jj,jk,jp_sal,Krhs) = pts(ji,jj,jk,jp_sal,Krhs)   &
133                  &                      + resto(ji,jj,jk) * ( zts_dta(ji,jj,jk,jp_sal) - pts(ji,jj,jk,jp_sal,Kbb) )
134            ENDIF
135         END_3D
136         !
137      CASE ( 2 )                       !*  no damping in the mixed layer   *!
138         DO_3D( 0, 0, 0, 0, 1, jpkm1 )
139            IF( gdept(ji,jj,jk,Kmm) >= hmlp (ji,jj) ) THEN
140               pts(ji,jj,jk,jp_tem,Krhs) = pts(ji,jj,jk,jp_tem,Krhs)   &
141                  &                      + resto(ji,jj,jk) * ( zts_dta(ji,jj,jk,jp_tem) - pts(ji,jj,jk,jp_tem,Kbb) )
142               pts(ji,jj,jk,jp_sal,Krhs) = pts(ji,jj,jk,jp_sal,Krhs)   &
143                  &                      + resto(ji,jj,jk) * ( zts_dta(ji,jj,jk,jp_sal) - pts(ji,jj,jk,jp_sal,Kbb) )
144            ENDIF
145         END_3D
146         !
147      END SELECT
148      !
149      ! outputs (clem trunk)
150      IF( iom_use('hflx_dmp_cea') .OR. iom_use('sflx_dmp_cea') ) THEN
151         ALLOCATE( zwrk(A2D(nn_hls),jpk) )          ! Needed to handle expressions containing e3t when using key_qco or key_linssh
152         zwrk(:,:,:) = 0._wp
153
154         IF( iom_use('hflx_dmp_cea') ) THEN
155            DO_3D( 0, 0, 0, 0, 1, jpk )
156               zwrk(ji,jj,jk) = ( pts(ji,jj,jk,jp_tem,Krhs) - ztrdts(ji,jj,jk,jp_tem) ) * e3t(ji,jj,jk,Kmm)
157            END_3D
158            CALL iom_put('hflx_dmp_cea', SUM( zwrk(:,:,:), dim=3 ) * rcp * rho0 ) ! W/m2
159         ENDIF
160         IF( iom_use('sflx_dmp_cea') ) THEN
161            DO_3D( 0, 0, 0, 0, 1, jpk )
162               zwrk(ji,jj,jk) = ( pts(ji,jj,jk,jp_sal,Krhs) - ztrdts(ji,jj,jk,jp_sal) ) * e3t(ji,jj,jk,Kmm)
163            END_3D
164            CALL iom_put('sflx_dmp_cea', SUM( zwrk(:,:,:), dim=3 ) * rho0 )       ! g/m2/s
165         ENDIF
166
167         DEALLOCATE( zwrk )
168      ENDIF
169      !
170      IF( l_trdtra )   THEN       ! trend diagnostic
171         ztrdts(:,:,:,:) = pts(:,:,:,:,Krhs) - ztrdts(:,:,:,:)
172         CALL trd_tra( kt, Kmm, Krhs, 'TRA', jp_tem, jptra_dmp, ztrdts(:,:,:,jp_tem) )
173         CALL trd_tra( kt, Kmm, Krhs, 'TRA', jp_sal, jptra_dmp, ztrdts(:,:,:,jp_sal) )
174         DEALLOCATE( ztrdts )
175      ENDIF
176      !                           ! Control print
177IF(sn_cfctl%l_prtctl)   CALL prt_ctl( tab3d_1=CASTWP(pts(:,:,:,jp_tem,Krhs)), clinfo1=' dmp  - Ta: ', mask1=tmask, tab3d_2=CASTWP(pts(:,:,:,jp_sal,Krhs)), clinfo2=       ' Sa: ', mask2=tmask, clinfo3='tra' )
178
179      !
180      IF( ln_timing )   CALL timing_stop('tra_dmp')
181      !
182   END SUBROUTINE tra_dmp
183
184
185   SUBROUTINE tra_dmp_init
186      !!----------------------------------------------------------------------
187      !!                  ***  ROUTINE tra_dmp_init  ***
188      !!
189      !! ** Purpose :   Initialization for the newtonian damping
190      !!
191      !! ** Method  :   read the namtra_dmp namelist and check the parameters
192      !!----------------------------------------------------------------------
193      INTEGER ::   ios, imask   ! local integers
194      !
195      NAMELIST/namtra_dmp/ ln_tradmp, nn_zdmp, cn_resto
196      !!----------------------------------------------------------------------
197      !
198      READ  ( numnam_ref, namtra_dmp, IOSTAT = ios, ERR = 901)
199901   IF( ios /= 0 )   CALL ctl_nam ( ios , 'namtra_dmp in reference namelist' )
200      !
201      READ  ( numnam_cfg, namtra_dmp, IOSTAT = ios, ERR = 902 )
202902   IF( ios >  0 )   CALL ctl_nam ( ios , 'namtra_dmp in configuration namelist' )
203      IF(lwm) WRITE ( numond, namtra_dmp )
204      !
205      IF(lwp) THEN                  ! Namelist print
206         WRITE(numout,*)
207         WRITE(numout,*) 'tra_dmp_init : T and S newtonian relaxation'
208         WRITE(numout,*) '~~~~~~~~~~~~'
209         WRITE(numout,*) '   Namelist namtra_dmp : set relaxation parameters'
210         WRITE(numout,*) '      Apply relaxation   or not       ln_tradmp   = ', ln_tradmp
211         WRITE(numout,*) '         mixed layer damping option      nn_zdmp  = ', nn_zdmp
212         WRITE(numout,*) '         Damping file name               cn_resto = ', cn_resto
213         WRITE(numout,*)
214      ENDIF
215      !
216      IF( ln_tradmp ) THEN
217         !                          ! Allocate arrays
218         IF( tra_dmp_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'tra_dmp_init: unable to allocate arrays' )
219         !
220         SELECT CASE (nn_zdmp)      ! Check values of nn_zdmp
221         CASE ( 0 )   ;   IF(lwp) WRITE(numout,*) '   tracer damping as specified by mask'
222         CASE ( 1 )   ;   IF(lwp) WRITE(numout,*) '   no tracer damping in the mixing layer (kz > 5 cm2/s)'
223         CASE ( 2 )   ;   IF(lwp) WRITE(numout,*) '   no tracer damping in the mixed  layer'
224         CASE DEFAULT
225            CALL ctl_stop('tra_dmp_init : wrong value of nn_zdmp')
226         END SELECT
227         !
228         !!TG: Initialisation of dtatsd - Would it be better to have dmpdta routine
229         !    so can damp to something other than intitial conditions files?
230         !!gm: In principle yes. Nevertheless, we can't anticipate demands that have never been formulated.
231         IF( .NOT.ln_tsd_dmp ) THEN
232            IF(lwp) WRITE(numout,*)
233            IF(lwp) WRITE(numout, *)  '   read T-S data not initialized, we force ln_tsd_dmp=T'
234            CALL dta_tsd_init( ld_tradmp=ln_tradmp )        ! forces the initialisation of T-S data
235         ENDIF
236         !                          ! Read in mask from file
237         CALL iom_open ( cn_resto, imask)
238         CALL iom_get  ( imask, jpdom_auto, 'resto', resto )
239         CALL iom_close( imask )
240      ENDIF
241      !
242   END SUBROUTINE tra_dmp_init
243
244   !!======================================================================
245END MODULE tradmp
Note: See TracBrowser for help on using the repository browser.