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.
trdtra.F90 in branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/OPA_SRC/TRD – NEMO

source: branches/2016/dev_v3_6_STABLE_r6506_AGRIF_LIM3/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90 @ 7158

Last change on this file since 7158 was 7158, checked in by clem, 7 years ago

debug branch

  • Property svn:keywords set to Id
File size: 19.3 KB
Line 
1MODULE trdtra
2   !!======================================================================
3   !!                       ***  MODULE  trdtra  ***
4   !! Ocean diagnostics:  ocean tracers trends pre-processing
5   !!=====================================================================
6   !! History :  3.3  !  2010-06  (C. Ethe) creation for the TRA/TRC merge
7   !!            3.5  !  2012-02  (G. Madec) update the comments
8   !!----------------------------------------------------------------------
9
10   !!----------------------------------------------------------------------
11   !!   trd_tra       : pre-process the tracer trends
12   !!   trd_tra_adv   : transform a div(U.T) trend into a U.grad(T) trend
13   !!   trd_tra_mng   : tracer trend manager: dispatch to the diagnostic modules
14   !!   trd_tra_iom   : output 3D tracer trends using IOM
15   !!----------------------------------------------------------------------
16   USE oce            ! ocean dynamics and tracers variables
17   USE dom_oce        ! ocean domain
18   USE sbc_oce        ! surface boundary condition: ocean
19   USE zdf_oce        ! ocean vertical physics
20   USE trd_oce        ! trends: ocean variables
21   USE trdtrc         ! ocean passive mixed layer tracers trends
22   USE trdglo         ! trends: global domain averaged
23   USE trdpen         ! trends: Potential ENergy
24   USE trdmxl         ! ocean active mixed layer tracers trends
25   USE ldftra_oce     ! ocean active tracers lateral physics
26   USE zdfddm         ! vertical physics: double diffusion
27   USE phycst         ! physical constants
28   USE in_out_manager ! I/O manager
29   USE iom            ! I/O manager library
30   USE lib_mpp        ! MPP library
31   USE wrk_nemo       ! Memory allocation
32
33   IMPLICIT NONE
34   PRIVATE
35
36   PUBLIC   trd_tra   ! called by all tra_... modules
37
38   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   trdtx, trdty, trdt   ! use to store the temperature trends
39
40   !! * Substitutions
41#  include "domzgr_substitute.h90"
42#  include "zdfddm_substitute.h90"
43#  include "vectopt_loop_substitute.h90"
44   !!----------------------------------------------------------------------
45   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
46   !! $Id$
47   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
48   !!----------------------------------------------------------------------
49CONTAINS
50
51   INTEGER FUNCTION trd_tra_alloc()
52      !!---------------------------------------------------------------------
53      !!                  ***  FUNCTION trd_tra_alloc  ***
54      !!---------------------------------------------------------------------
55      ALLOCATE( trdtx(jpi,jpj,jpk) , trdty(jpi,jpj,jpk) , trdt(jpi,jpj,jpk) , STAT= trd_tra_alloc )
56      !
57      IF( lk_mpp             )   CALL mpp_sum ( trd_tra_alloc )
58      IF( trd_tra_alloc /= 0 )   CALL ctl_warn('trd_tra_alloc: failed to allocate arrays')
59   END FUNCTION trd_tra_alloc
60
61
62   SUBROUTINE trd_tra( kt, ctype, ktra, ktrd, ptrd, pun, ptra )
63      !!---------------------------------------------------------------------
64      !!                  ***  ROUTINE trd_tra  ***
65      !!
66      !! ** Purpose : pre-process tracer trends
67      !!
68      !! ** Method  : - mask the trend
69      !!              - advection (ptra present) converte the incoming flux (U.T)
70      !!              into trend (U.T => -U.grat(T)=div(U.T)-T.div(U)) through a
71      !!              call to trd_tra_adv
72      !!              - 'TRA' case : regroup T & S trends
73      !!              - send the trends to trd_tra_mng (trdtrc) for further processing
74      !!----------------------------------------------------------------------
75      INTEGER                         , INTENT(in)           ::   kt      ! time step
76      CHARACTER(len=3)                , INTENT(in)           ::   ctype   ! tracers trends type 'TRA'/'TRC'
77      INTEGER                         , INTENT(in)           ::   ktra    ! tracer index
78      INTEGER                         , INTENT(in)           ::   ktrd    ! tracer trend index
79      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in)           ::   ptrd    ! tracer trend  or flux
80      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::   pun     ! now velocity
81      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::   ptra    ! now tracer variable
82      !
83      INTEGER  ::   jk   ! loop indices
84      REAL(wp), POINTER, DIMENSION(:,:,:)  ::   zwt, zws, ztrdt, ztrds   ! 3D workspace
85      !!----------------------------------------------------------------------
86      !
87      CALL wrk_alloc( jpi, jpj, jpk, ztrds )
88      !     
89      IF( .NOT. ALLOCATED( trdtx ) ) THEN      ! allocate trdtra arrays
90         IF( trd_tra_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'trd_tra : unable to allocate arrays' )
91      ENDIF
92
93      IF( ctype == 'TRA' .AND. ktra == jp_tem ) THEN   !==  Temperature trend  ==!
94         !
95         SELECT CASE( ktrd )
96         !                            ! advection: transform the advective flux into a trend
97         CASE( jptra_xad )   ;   CALL trd_tra_adv( ptrd, pun, ptra, 'X', trdtx ) 
98         CASE( jptra_yad )   ;   CALL trd_tra_adv( ptrd, pun, ptra, 'Y', trdty ) 
99         CASE( jptra_zad )   ;   CALL trd_tra_adv( ptrd, pun, ptra, 'Z', trdt  ) 
100         CASE( jptra_bbc,    &        ! qsr, bbc: on temperature only, send to trd_tra_mng
101            &  jptra_qsr )   ;   trdt(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)
102                                 ztrds(:,:,:) = 0._wp
103                                 CALL trd_tra_mng( trdt, ztrds, ktrd, kt )
104         CASE DEFAULT                 ! other trends: masked trends
105            trdt(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)              ! mask & store
106         END SELECT
107         !
108      ENDIF
109
110      IF( ctype == 'TRA' .AND. ktra == jp_sal ) THEN      !==  Salinity trends  ==!
111         !
112         SELECT CASE( ktrd )
113         !                            ! advection: transform the advective flux into a trend
114         !                            !            and send T & S trends to trd_tra_mng
115         CASE( jptra_xad  )   ;   CALL trd_tra_adv( ptrd , pun  , ptra, 'X'  , ztrds ) 
116                                  CALL trd_tra_mng( trdtx, ztrds, ktrd, kt   )
117         CASE( jptra_yad  )   ;   CALL trd_tra_adv( ptrd , pun  , ptra, 'Y'  , ztrds ) 
118                                  CALL trd_tra_mng( trdty, ztrds, ktrd, kt   )
119         CASE( jptra_zad  )   ;   CALL trd_tra_adv( ptrd , pun  , ptra, 'Z'  , ztrds ) 
120                                  CALL trd_tra_mng( trdt , ztrds, ktrd, kt   )
121         CASE( jptra_zdfp )           ! diagnose the "PURE" Kz trend (here: just before the swap)
122            !                         ! iso-neutral diffusion case otherwise jptra_zdf is "PURE"
123            CALL wrk_alloc( jpi, jpj, jpk, zwt, zws, ztrdt )
124            !
125            zwt(:,:, 1 ) = 0._wp   ;   zws(:,:, 1 ) = 0._wp            ! vertical diffusive fluxes
126            zwt(:,:,jpk) = 0._wp   ;   zws(:,:,jpk) = 0._wp
127            DO jk = 2, jpk
128               zwt(:,:,jk) =   avt(:,:,jk) * ( tsa(:,:,jk-1,jp_tem) - tsa(:,:,jk,jp_tem) ) / fse3w(:,:,jk) * tmask(:,:,jk)
129               zws(:,:,jk) = fsavs(:,:,jk) * ( tsa(:,:,jk-1,jp_sal) - tsa(:,:,jk,jp_sal) ) / fse3w(:,:,jk) * tmask(:,:,jk)
130            END DO
131            !
132            ztrdt(:,:,jpk) = 0._wp   ;   ztrds(:,:,jpk) = 0._wp
133            DO jk = 1, jpkm1
134               ztrdt(:,:,jk) = ( zwt(:,:,jk) - zwt(:,:,jk+1) ) / fse3t(:,:,jk)
135               ztrds(:,:,jk) = ( zws(:,:,jk) - zws(:,:,jk+1) ) / fse3t(:,:,jk) 
136            END DO
137            CALL trd_tra_mng( ztrdt, ztrds, jptra_zdfp, kt ) 
138            !
139            CALL wrk_dealloc( jpi, jpj, jpk, zwt, zws, ztrdt )
140            !
141         CASE DEFAULT                 ! other trends: mask and send T & S trends to trd_tra_mng
142            ztrds(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)
143            CALL trd_tra_mng( trdt, ztrds, ktrd, kt ) 
144         END SELECT
145      ENDIF
146
147      IF( ctype == 'TRC' ) THEN                           !==  passive tracer trend  ==!
148         !
149         SELECT CASE( ktrd )
150         !                            ! advection: transform the advective flux into a masked trend
151         CASE( jptra_xad )   ;   CALL trd_tra_adv( ptrd , pun , ptra, 'X', ztrds ) 
152         CASE( jptra_yad )   ;   CALL trd_tra_adv( ptrd , pun , ptra, 'Y', ztrds ) 
153         CASE( jptra_zad )   ;   CALL trd_tra_adv( ptrd , pun , ptra, 'Z', ztrds ) 
154         CASE DEFAULT                 ! other trends: just masked
155                                 ztrds(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)
156         END SELECT
157         !                            ! send trend to trd_trc
158         CALL trd_trc( ztrds, ktra, ktrd, kt ) 
159         !
160      ENDIF
161      !
162      CALL wrk_dealloc( jpi, jpj, jpk, ztrds )
163      !
164   END SUBROUTINE trd_tra
165
166
167   SUBROUTINE trd_tra_adv( pf, pun, ptn, cdir, ptrd )
168      !!---------------------------------------------------------------------
169      !!                  ***  ROUTINE trd_tra_adv  ***
170      !!
171      !! ** Purpose :   transformed a advective flux into a masked advective trends
172      !!
173      !! ** Method  :   use the following transformation: -div(U.T) = - U grad(T) + T.div(U)
174      !!       i-advective trends = -un. di-1[T] = -( di-1[fi] - tn di-1[un] )
175      !!       j-advective trends = -un. di-1[T] = -( dj-1[fi] - tn dj-1[un] )
176      !!       k-advective trends = -un. di+1[T] = -( dk+1[fi] - tn dk+1[un] )
177      !!                where fi is the incoming advective flux.
178      !!----------------------------------------------------------------------
179      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::   pf      ! advective flux in one direction
180      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::   pun     ! now velocity   in one direction
181      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::   ptn     ! now or before tracer
182      CHARACTER(len=1)                , INTENT(in   ) ::   cdir    ! X/Y/Z direction
183      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(  out) ::   ptrd    ! advective trend in one direction
184      !
185      INTEGER  ::   ji, jj, jk   ! dummy loop indices
186      INTEGER  ::   ii, ij, ik   ! index shift as function of the direction
187      !!----------------------------------------------------------------------
188      !
189      SELECT CASE( cdir )      ! shift depending on the direction
190      CASE( 'X' )   ;   ii = 1   ;   ij = 0   ;   ik = 0      ! i-trend
191      CASE( 'Y' )   ;   ii = 0   ;   ij = 1   ;   ik = 0      ! j-trend
192      CASE( 'Z' )   ;   ii = 0   ;   ij = 0   ;   ik =-1      ! k-trend
193      END SELECT
194      !
195      !                        ! set to zero uncomputed values
196      ptrd(jpi,:,:) = 0._wp   ;   ptrd(1,:,:) = 0._wp
197      ptrd(:,jpj,:) = 0._wp   ;   ptrd(:,1,:) = 0._wp
198      ptrd(:,:,jpk) = 0._wp
199      !
200      DO jk = 1, jpkm1         ! advective trend
201         DO jj = 2, jpjm1
202            DO ji = fs_2, fs_jpim1   ! vector opt.
203               ptrd(ji,jj,jk) = - (     pf (ji,jj,jk) - pf (ji-ii,jj-ij,jk-ik)                        &
204                 &                  - ( pun(ji,jj,jk) - pun(ji-ii,jj-ij,jk-ik) ) * ptn(ji,jj,jk)  )   &
205                 &              / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )  * tmask(ji,jj,jk)
206            END DO
207         END DO
208      END DO
209      !
210   END SUBROUTINE trd_tra_adv
211
212
213   SUBROUTINE trd_tra_mng( ptrdx, ptrdy, ktrd, kt )
214      !!---------------------------------------------------------------------
215      !!                  ***  ROUTINE trd_tra_mng  ***
216      !!
217      !! ** Purpose :   Dispatch all tracer trends computation, e.g. 3D output,
218      !!                integral constraints, potential energy, and/or
219      !!                mixed layer budget.
220      !!----------------------------------------------------------------------
221      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend
222      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdy   ! Salinity    or V trend
223      INTEGER                   , INTENT(in   ) ::   ktrd    ! tracer trend index
224      INTEGER                   , INTENT(in   ) ::   kt      ! time step
225      !!----------------------------------------------------------------------
226
227      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt      ! = rdtra (restart with Euler time stepping)
228      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt      ! = 2 rdt (leapfrog)
229      ENDIF
230
231      !                   ! 3D output of tracers trends using IOM interface
232      IF( ln_tra_trd )   CALL trd_tra_iom ( ptrdx, ptrdy, ktrd, kt )
233
234      !                   ! Integral Constraints Properties for tracers trends                                       !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
235      IF( ln_glo_trd )   CALL trd_glo( ptrdx, ptrdy, ktrd, 'TRA', kt )
236
237      !                   ! Potential ENergy trends
238      IF( ln_PE_trd  )   CALL trd_pen( ptrdx, ptrdy, ktrd, kt, r2dt )
239
240      !                   ! Mixed layer trends for active tracers
241      IF( ln_tra_mxl )   THEN   
242         !-----------------------------------------------------------------------------------------------
243         ! W.A.R.N.I.N.G :
244         ! jptra_ldf : called by traldf.F90
245         !                 at this stage we store:
246         !                  - the lateral geopotential diffusion (here, lateral = horizontal)
247         !                  - and the iso-neutral diffusion if activated
248         ! jptra_zdf : called by trazdf.F90
249         !                 * in case of iso-neutral diffusion we store the vertical diffusion component in the
250         !                   lateral trend including the K_z contrib, which will be removed later (see trd_mxl)
251         !-----------------------------------------------------------------------------------------------
252
253         SELECT CASE ( ktrd )
254         CASE ( jptra_xad )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_xad, '3D' )   ! zonal    advection
255         CASE ( jptra_yad )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_yad, '3D' )   ! merid.   advection
256         CASE ( jptra_zad )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_zad, '3D' )   ! vertical advection
257         CASE ( jptra_ldf )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_ldf, '3D' )   ! lateral  diffusion
258         CASE ( jptra_bbl )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_bbl, '3D' )   ! bottom boundary layer
259         CASE ( jptra_zdf )
260            IF( ln_traldf_iso ) THEN ; CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_ldf, '3D' )   ! lateral  diffusion (K_z)
261            ELSE                   ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_zdf, '3D' )   ! vertical diffusion (K_z)
262            ENDIF
263         CASE ( jptra_dmp )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_dmp, '3D' )   ! internal 3D restoring (tradmp)
264         CASE ( jptra_qsr )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_for, '3D' )   ! air-sea : penetrative sol radiat
265         CASE ( jptra_nsr )        ;   ptrdx(:,:,2:jpk) = 0._wp   ;   ptrdy(:,:,2:jpk) = 0._wp
266                                       CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_for, '2D' )   ! air-sea : non penetr sol radiation
267         CASE ( jptra_bbc )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_bbc, '3D' )   ! bottom bound cond (geoth flux)
268         CASE ( jptra_npc )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_npc, '3D' )   ! non penetr convect adjustment
269         CASE ( jptra_atf )        ;   CALL trd_mxl_zint( ptrdx, ptrdy, jpmxl_atf, '3D' )   ! asselin time filter (last trend)
270                                   !
271                                       CALL trd_mxl( kt, r2dt )                             ! trends: Mixed-layer (output)
272         END SELECT
273         !
274      ENDIF
275      !
276   END SUBROUTINE trd_tra_mng
277
278
279   SUBROUTINE trd_tra_iom( ptrdx, ptrdy, ktrd, kt )
280      !!---------------------------------------------------------------------
281      !!                  ***  ROUTINE trd_tra_iom  ***
282      !!
283      !! ** Purpose :   output 3D tracer trends using IOM
284      !!----------------------------------------------------------------------
285      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend
286      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdy   ! Salinity    or V trend
287      INTEGER                   , INTENT(in   ) ::   ktrd    ! tracer trend index
288      INTEGER                   , INTENT(in   ) ::   kt      ! time step
289      !!
290      INTEGER ::   ji, jj, jk   ! dummy loop indices
291      INTEGER ::   ikbu, ikbv   ! local integers
292      REAL(wp), POINTER, DIMENSION(:,:)   ::   z2dx, z2dy   ! 2D workspace
293      !!----------------------------------------------------------------------
294      !
295!!gm Rq: mask the trends already masked in trd_tra, but lbc_lnk should probably be added
296      !
297      SELECT CASE( ktrd )
298      CASE( jptra_xad  )   ;   CALL iom_put( "ttrd_xad" , ptrdx )        ! x- horizontal advection
299                               CALL iom_put( "strd_xad" , ptrdy )
300      CASE( jptra_yad  )   ;   CALL iom_put( "ttrd_yad" , ptrdx )        ! y- horizontal advection
301                               CALL iom_put( "strd_yad" , ptrdy )
302      CASE( jptra_zad  )   ;   CALL iom_put( "ttrd_zad" , ptrdx )        ! z- vertical   advection
303                               CALL iom_put( "strd_zad" , ptrdy )
304                               IF( .NOT. lk_vvl ) THEN                   ! cst volume : adv flux through z=0 surface
305                                  CALL wrk_alloc( jpi, jpj, z2dx, z2dy )
306                                  z2dx(:,:) = wn(:,:,1) * tsn(:,:,1,jp_tem) / fse3t(:,:,1)
307                                  z2dy(:,:) = wn(:,:,1) * tsn(:,:,1,jp_sal) / fse3t(:,:,1)
308                                  CALL iom_put( "ttrd_sad", z2dx )
309                                  CALL iom_put( "strd_sad", z2dy )
310                                  CALL wrk_dealloc( jpi, jpj, z2dx, z2dy )
311                               ENDIF
312      CASE( jptra_ldf  )   ;   CALL iom_put( "ttrd_ldf" , ptrdx )        ! lateral diffusion
313                               CALL iom_put( "strd_ldf" , ptrdy )
314      CASE( jptra_zdf  )   ;   CALL iom_put( "ttrd_zdf" , ptrdx )        ! vertical diffusion (including Kz contribution)
315                               CALL iom_put( "strd_zdf" , ptrdy )
316      CASE( jptra_zdfp )   ;   CALL iom_put( "ttrd_zdfp", ptrdx )        ! PURE vertical diffusion (no isoneutral contribution)
317                               CALL iom_put( "strd_zdfp", ptrdy )
318      CASE( jptra_dmp  )   ;   CALL iom_put( "ttrd_dmp" , ptrdx )        ! internal restoring (damping)
319                               CALL iom_put( "strd_dmp" , ptrdy )
320      CASE( jptra_bbl  )   ;   CALL iom_put( "ttrd_bbl" , ptrdx )        ! bottom boundary layer
321                               CALL iom_put( "strd_bbl" , ptrdy )
322      CASE( jptra_npc  )   ;   CALL iom_put( "ttrd_npc" , ptrdx )        ! static instability mixing
323                               CALL iom_put( "strd_npc" , ptrdy )
324      CASE( jptra_nsr  )   ;   CALL iom_put( "ttrd_qns" , ptrdx )        ! surface forcing + runoff (ln_rnf=T)
325                               CALL iom_put( "strd_cdt" , ptrdy )
326      CASE( jptra_qsr  )   ;   CALL iom_put( "ttrd_qsr" , ptrdx )        ! penetrative solar radiat. (only on temperature)
327      CASE( jptra_bbc  )   ;   CALL iom_put( "ttrd_bbc" , ptrdx )        ! geothermal heating   (only on temperature)
328      CASE( jptra_atf  )   ;   CALL iom_put( "ttrd_atf" , ptrdx )        ! asselin time Filter
329                               CALL iom_put( "strd_atf" , ptrdy )
330      END SELECT
331      !
332   END SUBROUTINE trd_tra_iom
333
334   !!======================================================================
335END MODULE trdtra
Note: See TracBrowser for help on using the repository browser.