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/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD – NEMO

source: branches/2012/dev_r3309_LOCEAN12_Ediag/NEMOGCM/NEMO/OPA_SRC/TRD/trdtra.F90 @ 3316

Last change on this file since 3316 was 3316, checked in by gm, 12 years ago

Ediag branche: #927 add 3D output for dyn & tracer trends

  • Property svn:keywords set to Id
File size: 10.5 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#if  defined key_trdtra || defined key_trdmld || defined key_trdmld_trc 
10   !!----------------------------------------------------------------------
11   !!   trd_tra       : pre-process the tracer trends and calll trd_mod(_trc)
12   !!   trd_tra_adv   : transform a div(U.T) trend into a U.grad(T) trend
13   !!----------------------------------------------------------------------
14   USE dom_oce        ! ocean domain
15   USE trdmod_oce     ! ocean active mixed layer tracers trends
16   USE trdmod         ! ocean active mixed layer tracers trends
17   USE trdmod_trc     ! ocean passive mixed layer tracers trends
18   USE in_out_manager ! I/O manager
19   USE lib_mpp        ! MPP library
20   USE wrk_nemo       ! Memory allocation
21
22   IMPLICIT NONE
23   PRIVATE
24
25   PUBLIC   trd_tra   ! called by all tra_... modules
26 
27   REAL(wp), ALLOCATABLE, SAVE, DIMENSION(:,:,:) ::   trdtx, trdty, trdt   ! use to store the temperature trends
28
29   !! * Substitutions
30#  include "domzgr_substitute.h90"
31#  include "vectopt_loop_substitute.h90"
32   !!----------------------------------------------------------------------
33   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
34   !! $Id$
35   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
36   !!----------------------------------------------------------------------
37CONTAINS
38
39   INTEGER FUNCTION trd_tra_alloc()
40      !!----------------------------------------------------------------------------
41      !!                  ***  FUNCTION trd_tra_alloc  ***
42      !!----------------------------------------------------------------------------
43      ALLOCATE( trdtx(jpi,jpj,jpk) , trdty(jpi,jpj,jpk) , trdt(jpi,jpj,jpk) , STAT= trd_tra_alloc )
44      !
45      IF( lk_mpp             )   CALL mpp_sum ( trd_tra_alloc )
46      IF( trd_tra_alloc /= 0 )   CALL ctl_warn('trd_tra_alloc: failed to allocate arrays')
47   END FUNCTION trd_tra_alloc
48
49
50   SUBROUTINE trd_tra( kt, ctype, ktra, ktrd, ptrd, pun, ptra )
51      !!---------------------------------------------------------------------
52      !!                  ***  ROUTINE trd_tra  ***
53      !!
54      !! ** Purpose : pre-process tracer trends
55      !!
56      !! ** Method  : - mask the trend
57      !!              - advection (ptra present) converte the incoming flux (U.T)
58      !!              into trend (U.T => -U.grat(T)=div(U.T)-T.div(U)) through a
59      !!              call to trd_tra_adv
60      !!              - 'TRA' case : regroup T & S trends
61      !!              - send the trends to trd_mod(_trc) for further processing
62      !!----------------------------------------------------------------------
63      INTEGER                         , INTENT(in)           ::   kt      ! time step
64      CHARACTER(len=3)                , INTENT(in)           ::   ctype   ! tracers trends type 'TRA'/'TRC'
65      INTEGER                         , INTENT(in)           ::   ktra    ! tracer index
66      INTEGER                         , INTENT(in)           ::   ktrd    ! tracer trend index
67      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in)           ::   ptrd    ! tracer trend  or flux
68      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::   pun     ! now velocity
69      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::   ptra    ! now tracer variable
70      !
71      REAL(wp), POINTER, DIMENSION(:,:,:)  ::  ztrds
72      !!----------------------------------------------------------------------
73      !
74      CALL wrk_alloc( jpi, jpj, jpk, ztrds )
75      !
76      IF( .NOT. ALLOCATED( trdtx ) ) THEN      ! allocate trdtra arrays
77         IF( trd_tra_alloc() /= 0 )   CALL ctl_stop( 'STOP', 'trd_tra : unable to allocate arrays' )
78      ENDIF
79     
80      IF( ctype == 'TRA' .AND. ktra == jp_tem ) THEN   !==  Temperature trend  ==!
81         !
82         IF( PRESENT( ptra ) ) THEN                       ! advection: transform flux into trend
83            SELECT CASE( ktrd )     
84            CASE( jptra_trd_xad )   ;   CALL trd_tra_adv( ptrd, pun, ptra, 'X', trdtx ) 
85            CASE( jptra_trd_yad )   ;   CALL trd_tra_adv( ptrd, pun, ptra, 'Y', trdty ) 
86            CASE( jptra_trd_zad )   ;   CALL trd_tra_adv( ptrd, pun, ptra, 'Z', trdt  ) 
87            END SELECT
88         ELSE                                             ! other trends:
89            trdt(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)                      ! mask & store
90            IF( ktrd == jptra_trd_bbc .OR. ktrd == jptra_trd_qsr ) THEN   ! qsr, bbc: on temperature only
91               ztrds(:,:,:) = 0._wp
92               CALL trd_mod( trdt, ztrds, ktrd, ctype, kt )                  ! send to trd_mod
93            ENDIF
94         ENDIF
95         !
96      ENDIF
97
98      IF( ctype == 'TRA' .AND. ktra == jp_sal ) THEN      !==  Salinity trends  ==!
99         !
100         IF( PRESENT( ptra ) ) THEN      ! advection: transform the advective flux into a trend
101            SELECT CASE( ktrd )          !            and send T & S trends to trd_mod
102            CASE( jptra_trd_xad )   ;   CALL trd_tra_adv( ptrd , pun  , ptra, 'X'  , ztrds ) 
103                                        CALL trd_mod    ( trdtx, ztrds, ktrd, ctype, kt    )
104            CASE( jptra_trd_yad )   ;   CALL trd_tra_adv( ptrd , pun  , ptra, 'Y'  , ztrds ) 
105                                    ;   CALL trd_mod    ( trdty, ztrds, ktrd, ctype, kt    )
106            CASE( jptra_trd_zad )   ;   CALL trd_tra_adv( ptrd , pun  , ptra, 'Z'  , ztrds ) 
107                                        CALL trd_mod    ( trdt , ztrds, ktrd, ctype, kt    )
108            END SELECT
109         ELSE                            ! other trends: mask and send T & S trends to trd_mod
110            ztrds(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)
111            CALL trd_mod( trdt, ztrds, ktrd, ctype, kt ) 
112         ENDIF
113         !
114      ENDIF
115
116      IF( ctype == 'TRC' ) THEN                           !==  passive tracer trend  ==!
117         !
118         IF( PRESENT( ptra ) ) THEN                          ! advection: transform flux into a trend
119            SELECT CASE( ktrd )
120            CASE( jptra_trd_xad )   ;   CALL trd_tra_adv( ptrd , pun , ptra, 'X', ztrds ) 
121            CASE( jptra_trd_yad )   ;   CALL trd_tra_adv( ptrd , pun , ptra, 'Y', ztrds ) 
122            CASE( jptra_trd_zad )   ;   CALL trd_tra_adv( ptrd , pun , ptra, 'Z', ztrds ) 
123            END SELECT
124         ELSE                                                ! other trends: mask
125            ztrds(:,:,:) = ptrd(:,:,:) * tmask(:,:,:)
126         END IF
127         !                                 
128         CALL trd_mod_trc( ztrds, ktra, ktrd, kt )           ! send trend to trd_mod_trc
129         !
130      ENDIF
131      !
132      CALL wrk_dealloc( jpi, jpj, jpk, ztrds )
133      !
134   END SUBROUTINE trd_tra
135
136
137   SUBROUTINE trd_tra_adv( pf, pun, ptn, cdir, ptrd )
138      !!---------------------------------------------------------------------
139      !!                  ***  ROUTINE trd_tra_adv  ***
140      !!
141      !! ** Purpose :   transformed a advective flux into a masked advective trends
142      !!
143      !! ** Method  :   use the following transformation: -div(U.T) = - U grad(T) + T.div(U)
144      !!       i-advective trends = -un. di-1[T] = -( di-1[fi] - tn di-1[un] )
145      !!       j-advective trends = -un. di-1[T] = -( dj-1[fi] - tn dj-1[un] )
146      !!       k-advective trends = -un. di+1[T] = -( dk+1[fi] - tn dk+1[un] )
147      !!                where fi is the incoming advective flux.
148      !!----------------------------------------------------------------------
149      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::   pf      ! advective flux in one direction
150      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::   pun     ! now velocity   in one direction
151      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in   ) ::   ptn     ! now or before tracer
152      CHARACTER(len=1)                , INTENT(in   ) ::   cdir    ! X/Y/Z direction
153      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(  out) ::   ptrd    ! advective trend in one direction
154      !
155      INTEGER  ::   ji, jj, jk   ! dummy loop indices
156      INTEGER  ::   ii, ij, ik   ! index shift as function of the direction
157      !!----------------------------------------------------------------------
158      !
159      SELECT CASE( cdir )      ! shift depending on the direction
160      CASE( 'X' )   ;   ii = 1   ;   ij = 0   ;   ik = 0      ! i-trend
161      CASE( 'Y' )   ;   ii = 0   ;   ij = 1   ;   ik = 0      ! j-trend
162      CASE( 'Z' )   ;   ii = 0   ;   ij = 0   ;   ik =-1      ! k-trend
163      END SELECT
164      !
165      !                        ! set to zero uncomputed values
166      ptrd(jpi,:,:) = 0._wp   ;   ptrd(1,:,:) = 0._wp
167      ptrd(:,jpj,:) = 0._wp   ;   ptrd(:,1,:) = 0._wp
168      ptrd(:,:,jpk) = 0._wp
169      !
170      DO jk = 1, jpkm1         ! advective trend
171         DO jj = 2, jpjm1
172            DO ji = fs_2, fs_jpim1   ! vector opt.
173               ptrd(ji,jj,jk) = - (     pf (ji,jj,jk) - pf (ji-ii,jj-ij,jk-ik)                        &
174                 &                  - ( pun(ji,jj,jk) - pun(ji-ii,jj-ij,jk-ik) ) * ptn(ji,jj,jk)  )   &
175                 &              / ( e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) )  * tmask(ji,jj,jk)
176            END DO
177         END DO
178      END DO
179      !
180   END SUBROUTINE trd_tra_adv
181
182#else
183   !!----------------------------------------------------------------------
184   !!   Default case :          Dummy module           No trend diagnostics
185   !!----------------------------------------------------------------------
186   USE par_oce      ! ocean variables trends
187CONTAINS
188   SUBROUTINE trd_tra( kt, ctype, ktra, ktrd, ptrd, pu, ptra )
189      !!----------------------------------------------------------------------
190      CHARACTER(len=3)                , INTENT(in)           ::  ctype   
191      INTEGER                         , INTENT(in)           ::  kt, ktra, ktrd
192      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in)           ::  ptrd   
193      REAL(wp), DIMENSION(jpi,jpj,jpk), INTENT(in), OPTIONAL ::  pu, ptra    ! Tracer variable
194      WRITE(*,*) 'trd_tra: You should not have seen this print! error ?',   &
195         &   ptrd(1,1,1), ptra(1,1,1), pu(1,1,1), ktrd, ktra, ctype, kt
196   END SUBROUTINE trd_tra
197#endif
198
199   !!======================================================================
200END MODULE trdtra
Note: See TracBrowser for help on using the repository browser.