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/2015/dev_merge_2015/NEMOGCM/NEMO/OPA_SRC/TRD – NEMO

source: branches/2015/dev_merge_2015/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90 @ 6060

Last change on this file since 6060 was 6060, checked in by timgraham, 8 years ago

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