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/2014/dev_r4650_UKMO10_Tidally_Meaned_Diagnostics/NEMOGCM/NEMO/OPA_SRC/TRD – NEMO

source: branches/2014/dev_r4650_UKMO10_Tidally_Meaned_Diagnostics/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90 @ 5989

Last change on this file since 5989 was 5989, checked in by deazer, 8 years ago

Merging TMB and 25h diagnostics to head of trunk
added brief documentation

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