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.
trdmod.F90 in trunk/NEMOGCM/NEMO/OPA_SRC/TRD – NEMO

source: trunk/NEMOGCM/NEMO/OPA_SRC/TRD/trdmod.F90 @ 2715

Last change on this file since 2715 was 2715, checked in by rblod, 13 years ago

First attempt to put dynamic allocation on the trunk

  • Property svn:keywords set to Id
File size: 16.9 KB
Line 
1MODULE trdmod
2   !!======================================================================
3   !!                       ***  MODULE  trdmod  ***
4   !! Ocean diagnostics:  ocean tracers and dynamic trends
5   !!=====================================================================
6   !! History :  1.0  !  2004-08  (C. Talandier) Original code
7   !!             -   !  2005-04  (C. Deltel)    Add Asselin trend in the ML budget
8   !!            3.3  ! 2010-10  (C. Ethe, G. Madec) reorganisation of initialisation phase
9   !!----------------------------------------------------------------------
10#if  defined key_trdtra || defined key_trddyn || defined key_trdmld || defined key_trdvor || defined key_esopa
11   !!----------------------------------------------------------------------
12   !!   trd_mod          : Call the trend to be computed
13   !!   trd_mod_init     : Initialization step
14   !!----------------------------------------------------------------------
15   USE oce                     ! ocean dynamics and tracers variables
16   USE dom_oce                 ! ocean space and time domain variables
17   USE zdf_oce                 ! ocean vertical physics variables
18   USE trdmod_oce              ! ocean variables trends
19   USE ldftra_oce              ! ocean active tracers lateral physics
20   USE sbc_oce                 ! surface boundary condition: ocean
21   USE phycst                  ! physical constants
22   USE trdvor                  ! ocean vorticity trends
23   USE trdicp                  ! ocean bassin integral constraints properties
24   USE trdmld                  ! ocean active mixed layer tracers trends
25   USE in_out_manager          ! I/O manager
26   USE lib_mpp         ! MPP library
27
28   IMPLICIT NONE
29   PRIVATE
30
31   REAL(wp) ::   r2dt          ! time-step, = 2 rdttra except at nit000 (=rdttra) if neuler=0
32
33   PUBLIC trd_mod              ! called by all dynXX or traXX modules
34   PUBLIC trd_mod_init         ! called by opa.F90 module
35
36   !! * Substitutions
37#  include "domzgr_substitute.h90"
38#  include "vectopt_loop_substitute.h90"
39   !!----------------------------------------------------------------------
40   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
41   !! $Id$
42   !! Software governed by the CeCILL licence     (NEMOGCM/NEMO_CeCILL.txt)
43   !!----------------------------------------------------------------------
44
45CONTAINS
46
47   SUBROUTINE trd_mod( ptrdx, ptrdy, ktrd, ctype, kt )
48      !!---------------------------------------------------------------------
49      !!                  ***  ROUTINE trd_mod  ***
50      !!
51      !! ** Purpose : Dispatch all trends computation, e.g. vorticity, mld or
52      !!              integral constraints
53      !!----------------------------------------------------------------------
54      USE wrk_nemo, ONLY: wrk_in_use, wrk_not_released
55      USE wrk_nemo, ONLY: ztswu => wrk_2d_1,  &
56                          ztswv => wrk_2d_2,  &
57                          ztbfu => wrk_2d_3,  &
58                          ztbfv => wrk_2d_4,  &
59                          z2dx  => wrk_2d_5,  &
60                          z2dy  => wrk_2d_6
61      !
62      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdx   ! Temperature or U trend
63      REAL(wp), DIMENSION(:,:,:), INTENT(inout) ::   ptrdy   ! Salinity    or V trend
64      CHARACTER(len=3)          , INTENT(in   ) ::   ctype   ! momentum or tracers trends type 'DYN'/'TRA'
65      INTEGER                   , INTENT(in   ) ::   kt      ! time step
66      INTEGER                   , INTENT(in   ) ::   ktrd    ! tracer trend index
67      !!
68      INTEGER ::   ji, jj   ! dummy loop indices
69      !!----------------------------------------------------------------------
70
71      IF(wrk_in_use(2, 1,2,3,4,5,6))THEN
72         CALL ctl_warn('trd_mod: Requested workspace arrays already in use.')   ;   RETURN
73      END IF
74
75      z2dx(:,:) = 0._wp   ;   z2dy(:,:) = 0._wp                            ! initialization of workspace arrays
76
77      IF( neuler == 0 .AND. kt == nit000    ) THEN   ;   r2dt =      rdt   ! = rdtra (restart with Euler time stepping)
78      ELSEIF(               kt <= nit000 + 1) THEN   ;   r2dt = 2. * rdt   ! = 2 rdttra (leapfrog)
79      ENDIF
80
81      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
82      ! I. Integral Constraints Properties for momentum and/or tracers trends
83      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
84
85      IF( ( mod(kt,nn_trd) == 0 .OR. kt == nit000 .OR. kt == nitend) )   THEN
86         !
87         IF( lk_trdtra .AND. ctype == 'TRA' )   THEN       ! active tracer trends
88            SELECT CASE ( ktrd )
89            CASE ( jptra_trd_ldf )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_ldf, ctype )   ! lateral diff
90            CASE ( jptra_trd_zdf )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_zdf, ctype )   ! vertical diff (Kz)
91            CASE ( jptra_trd_bbc )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_bbc, ctype )   ! bottom boundary cond
92            CASE ( jptra_trd_bbl )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_bbl, ctype )   ! bottom boundary layer
93            CASE ( jptra_trd_npc )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_npc, ctype )   ! static instability mixing
94            CASE ( jptra_trd_dmp )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_dmp, ctype )   ! damping
95            CASE ( jptra_trd_qsr )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_qsr, ctype )   ! penetrative solar radiat.
96            CASE ( jptra_trd_nsr )   ;   z2dx(:,:) = ptrdx(:,:,1)   
97                                         z2dy(:,:) = ptrdy(:,:,1)
98                                         CALL trd_icp( z2dx , z2dy , jpicpt_nsr, ctype )   ! non solar radiation
99            CASE ( jptra_trd_xad )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_xad, ctype )   ! x- horiz adv
100            CASE ( jptra_trd_yad )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_yad, ctype )   ! y- horiz adv
101            CASE ( jptra_trd_zad )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpt_zad, ctype )   ! z- vertical adv
102                                         CALL trd_icp( ptrdx, ptrdy, jpicpt_zad, ctype )   
103                                         ! compute the surface flux condition wn(:,:,1)*tn(:,:,1)
104                                         z2dx(:,:) = wn(:,:,1)*tn(:,:,1)/fse3t(:,:,1)
105                                         z2dy(:,:) = wn(:,:,1)*sn(:,:,1)/fse3t(:,:,1)
106                                         CALL trd_icp( z2dx , z2dy , jpicpt_zl1, ctype )   ! 1st z- vertical adv
107            END SELECT
108         END IF
109
110         IF( lk_trddyn .AND. ctype == 'DYN' )   THEN       ! momentum trends
111            !
112            SELECT CASE ( ktrd )
113            CASE ( jpdyn_trd_hpg )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_hpg, ctype )   ! hydrost. pressure grad
114            CASE ( jpdyn_trd_keg )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_keg, ctype )   ! KE gradient
115            CASE ( jpdyn_trd_rvo )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_rvo, ctype )   ! relative vorticity
116            CASE ( jpdyn_trd_pvo )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_pvo, ctype )   ! planetary vorticity
117            CASE ( jpdyn_trd_ldf )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_ldf, ctype )   ! lateral diffusion
118            CASE ( jpdyn_trd_had )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_had, ctype )   ! horizontal advection
119            CASE ( jpdyn_trd_zad )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_zad, ctype )   ! vertical advection
120            CASE ( jpdyn_trd_spg )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_spg, ctype )   ! surface pressure grad.
121            CASE ( jpdyn_trd_dat )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_dat, ctype )   ! damping term
122            CASE ( jpdyn_trd_zdf )                                                         ! vertical diffusion
123               ! subtract surface forcing/bottom friction trends
124               ! from vertical diffusive momentum trends
125               ztswu(:,:) = 0._wp   ;   ztswv(:,:) = 0._wp
126               ztbfu(:,:) = 0._wp   ;   ztbfv(:,:) = 0._wp 
127               DO jj = 2, jpjm1   
128                  DO ji = fs_2, fs_jpim1   ! vector opt.
129                     ! save the surface forcing momentum fluxes
130                     ztswu(ji,jj) = utau(ji,jj) / ( fse3u(ji,jj,1)*rau0 )
131                     ztswv(ji,jj) = vtau(ji,jj) / ( fse3v(ji,jj,1)*rau0 )
132                     ! bottom friction contribution now handled explicitly
133                     ptrdx(ji,jj,1) = ptrdx(ji,jj,1) - ztswu(ji,jj)
134                     ptrdy(ji,jj,1) = ptrdy(ji,jj,1) - ztswv(ji,jj)
135                  END DO
136               END DO
137               !
138               CALL trd_icp( ptrdx, ptrdy, jpicpd_zdf, ctype )   
139               CALL trd_icp( ztswu, ztswv, jpicpd_swf, ctype )                               ! wind stress forcing term
140               ! bottom friction contribution now handled explicitly
141            CASE ( jpdyn_trd_bfr )   ;   CALL trd_icp( ptrdx, ptrdy, jpicpd_bfr, ctype )     ! bottom friction term
142            END SELECT
143            !
144         END IF
145         !
146      END IF
147
148      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
149      ! II. Vorticity trends
150      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
151
152      IF( lk_trdvor .AND. ctype == 'DYN' )   THEN
153         !
154         SELECT CASE ( ktrd ) 
155         CASE ( jpdyn_trd_hpg )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_prg )   ! Hydrostatique Pressure Gradient
156         CASE ( jpdyn_trd_keg )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_keg )   ! KE Gradient
157         CASE ( jpdyn_trd_rvo )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_rvo )   ! Relative Vorticity
158         CASE ( jpdyn_trd_pvo )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_pvo )   ! Planetary Vorticity Term
159         CASE ( jpdyn_trd_ldf )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_ldf )   ! Horizontal Diffusion
160         CASE ( jpdyn_trd_had )   ;   CALL ctl_warn('Vorticity for horizontal advection trend never checked')   
161         CASE ( jpdyn_trd_zad )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_zad )   ! Vertical Advection
162         CASE ( jpdyn_trd_spg )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_spg )   ! Surface Pressure Grad.
163         CASE ( jpdyn_trd_dat )   ;   CALL trd_vor_zint( ptrdx, ptrdy, jpvor_bev )   ! Beta V 
164         CASE ( jpdyn_trd_zdf )                                                      ! Vertical Diffusion
165            ! subtract surface forcing/bottom friction trends
166            ! from vertical diffusive momentum trends
167            ztswu(:,:) = 0.e0   ;   ztswv(:,:) = 0.e0
168            ztbfu(:,:) = 0.e0   ;   ztbfv(:,:) = 0.e0 
169            DO jj = 2, jpjm1   
170               DO ji = fs_2, fs_jpim1   ! vector opt.
171                  ! save the surface forcing momentum fluxes
172                  ztswu(ji,jj) = utau(ji,jj) / ( fse3u(ji,jj,1)*rau0 )
173                  ztswv(ji,jj) = vtau(ji,jj) / ( fse3v(ji,jj,1)*rau0 )
174                  !
175                  ptrdx(ji,jj,1     ) = ptrdx(ji,jj,1     ) - ztswu(ji,jj)
176                  ptrdy(ji,jj,1     ) = ptrdy(ji,jj,1     ) - ztswv(ji,jj)
177               END DO
178            END DO
179            !
180            CALL trd_vor_zint( ptrdx, ptrdy, jpvor_zdf )   
181            CALL trd_vor_zint( ztswu, ztswv, jpvor_swf )                               ! Wind stress forcing term
182         CASE ( jpdyn_trd_bfr )
183            CALL trd_vor_zint( ptrdx, ptrdy, jpvor_bfr )                               ! Bottom friction term
184         END SELECT
185         !
186      ENDIF
187
188      !>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
189      ! III. Mixed layer trends for active tracers
190      !<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
191
192      IF( lk_trdmld .AND. ctype == 'TRA' )   THEN
193         
194         !-----------------------------------------------------------------------------------------------
195         ! W.A.R.N.I.N.G :
196         ! jptra_trd_ldf : called by traldf.F90
197         !                 at this stage we store:
198         !                  - the lateral geopotential diffusion (here, lateral = horizontal)
199         !                  - and the iso-neutral diffusion if activated
200         ! jptra_trd_zdf : called by trazdf.F90
201         !                 * in case of iso-neutral diffusion we store the vertical diffusion component in the
202         !                   lateral trend including the K_z contrib, which will be removed later (see trd_mld)
203         !-----------------------------------------------------------------------------------------------
204
205         SELECT CASE ( ktrd )
206         CASE ( jptra_trd_xad )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_xad, '3D' )   ! merid. advection
207         CASE ( jptra_trd_yad )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_yad, '3D' )   ! zonal  advection
208         CASE ( jptra_trd_zad )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_zad, '3D' )   ! vertical advection
209         CASE ( jptra_trd_ldf )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_ldf, '3D' )   ! lateral diffusive
210         CASE ( jptra_trd_bbl )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_bbl, '3D' )   ! bottom boundary layer
211         CASE ( jptra_trd_zdf )
212            IF( ln_traldf_iso )   THEN
213               CALL trd_mld_zint( ptrdx, ptrdy, jpmld_ldf, '3D' )   ! vertical diffusion (K_z)
214            ELSE
215               CALL trd_mld_zint( ptrdx, ptrdy, jpmld_zdf, '3D' )   ! vertical diffusion (K_z)
216            ENDIF
217         CASE ( jptra_trd_dmp )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_dmp, '3D' )   ! internal 3D restoring (tradmp)
218         CASE ( jptra_trd_qsr )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_for, '3D' )   ! air-sea : penetrative sol radiat
219         CASE ( jptra_trd_nsr )
220            ptrdx(:,:,2:jpk) = 0.e0   ;   ptrdy(:,:,2:jpk) = 0.e0
221            CALL trd_mld_zint( ptrdx, ptrdy, jpmld_for, '2D' )                             ! air-sea : non penetr sol radiat
222         CASE ( jptra_trd_bbc )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_bbc, '3D' )   ! bottom bound cond (geoth flux)
223         CASE ( jptra_trd_atf )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_atf, '3D' )   ! asselin numerical
224         CASE ( jptra_trd_npc )   ;   CALL trd_mld_zint( ptrdx, ptrdy, jpmld_npc, '3D' )   ! non penetr convect adjustment
225         END SELECT
226
227      ENDIF
228      !
229      IF( wrk_not_released(2, 1,2,3,4,5,6) )   CALL ctl_warn('trd_mod: Failed to release workspace arrays.')
230      !
231   END SUBROUTINE trd_mod
232
233#else
234   !!----------------------------------------------------------------------
235   !!   Default case :                                         Empty module
236   !!----------------------------------------------------------------------
237   USE trdmod_oce      ! ocean variables trends
238   USE trdvor          ! ocean vorticity trends
239   USE trdicp          ! ocean bassin integral constraints properties
240   USE trdmld          ! ocean active mixed layer tracers trends
241   !!----------------------------------------------------------------------
242CONTAINS
243   SUBROUTINE trd_mod(ptrd3dx, ptrd3dy, ktrd , ctype, kt )   ! Empty routine
244      REAL(wp) ::   ptrd3dx(:,:,:), ptrd3dy(:,:,:)
245      INTEGER  ::   ktrd, kt                           
246      CHARACTER(len=3) ::  ctype                 
247      WRITE(*,*) 'trd_3d: You should not have seen this print! error ?', ptrd3dx(1,1,1), ptrd3dy(1,1,1)
248      WRITE(*,*) ' "   ": You should not have seen this print! error ?', ktrd, ctype, kt
249   END SUBROUTINE trd_mod
250#endif
251
252   SUBROUTINE trd_mod_init
253      !!----------------------------------------------------------------------
254      !!                  ***  ROUTINE trd_mod_init  ***
255      !!
256      !! ** Purpose :   Initialization of activated trends
257      !!----------------------------------------------------------------------
258      USE in_out_manager          ! I/O manager
259      !!   
260      NAMELIST/namtrd/ nn_trd, nn_ctls, cn_trdrst_in, cn_trdrst_out, ln_trdmld_restart, rn_ucf, ln_trdmld_instant
261      !!----------------------------------------------------------------------
262
263      IF( l_trdtra .OR. l_trddyn )   THEN
264         REWIND( numnam )
265         READ  ( numnam, namtrd )      ! namelist namtrd : trends diagnostic
266
267         IF(lwp) THEN
268            WRITE(numout,*)
269            WRITE(numout,*) ' trd_mod_init : Momentum/Tracers trends'
270            WRITE(numout,*) ' ~~~~~~~~~~~~~'
271            WRITE(numout,*) '   Namelist namtrd : set trends parameters'
272            WRITE(numout,*) '      frequency of trends diagnostics   nn_trd             = ', nn_trd
273            WRITE(numout,*) '      control surface type              nn_ctls            = ', nn_ctls
274            WRITE(numout,*) '      restart for ML diagnostics        ln_trdmld_restart  = ', ln_trdmld_restart
275            WRITE(numout,*) '      instantaneous or mean ML T/S      ln_trdmld_instant  = ', ln_trdmld_instant
276            WRITE(numout,*) '      unit conversion factor            rn_ucf             = ', rn_ucf
277        ENDIF
278      ENDIF
279      !
280      IF( lk_trddyn .OR. lk_trdtra )    CALL trd_icp_init       ! integral constraints trends
281      IF( lk_trdmld                )    CALL trd_mld_init       ! mixed-layer trends (active  tracers) 
282      IF( lk_trdvor                )    CALL trd_vor_init       ! vorticity trends       
283      !
284   END SUBROUTINE trd_mod_init
285
286   !!======================================================================
287END MODULE trdmod
Note: See TracBrowser for help on using the repository browser.