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.
trazdf_exp_tam.F90 in branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA – NEMO

source: branches/TAM_V3_0/NEMOTAM/OPATAM_SRC/TRA/trazdf_exp_tam.F90 @ 1885

Last change on this file since 1885 was 1885, checked in by rblod, 14 years ago

add TAM sources

  • Property svn:executable set to *
File size: 23.0 KB
Line 
1MODULE trazdf_exp_tam
2#ifdef key_tam
3   !!==============================================================================
4   !!                    ***  MODULE  trazdf_exp_tam  ***
5   !! Ocean active tracers:  vertical component of the tracer mixing trend using
6   !!                        a split-explicit time-stepping
7   !!                        Tangent and Adjoint module
8   !!==============================================================================
9   !! History of the direct module :
10   !!   OPA           !  1990-10  (B. Blanke)  Original code
11   !!            7.0  !  1991-11  (G. Madec)
12   !!                 !  1992-06  (M. Imbard)  correction on tracer trend loops
13   !!                 !  1996-01  (G. Madec)  statement function for e3
14   !!                 !  1997-05  (G. Madec)  vertical component of isopycnal
15   !!                 !  1997-07  (G. Madec)  geopotential diffusion in s-coord
16   !!                 !  2000-08  (G. Madec)  double diffusive mixing
17   !!   NEMO     1.0  !  2002-08  (G. Madec)  F90: Free form and module
18   !!             -   !  2004-08  (C. Talandier) New trends organisation
19   !!             -   !  2005-11  (G. Madec)  New organisation
20   !!            3.0  !  2008-04  (G. Madec)  leap-frog time stepping done in trazdf
21   !! History of the T&A module :
22   !!                 !  2009-01  (A. Vidard) tam of the 2008-04 version
23   !!----------------------------------------------------------------------
24
25   !!----------------------------------------------------------------------
26   !!   tra_zdf_exp_tan  : compute the tracer the vertical diffusion trend using a
27   !!                  split-explicit time stepping and provide the after tracer (tangent)
28   !!   tra_zdf_exp_adj  : compute the tracer the vertical diffusion trend using a
29   !!                  split-explicit time stepping and provide the after tracer (adjoint)
30   !!----------------------------------------------------------------------
31   USE par_kind      , ONLY: & ! Precision variables
32      & wp
33   USE par_oce       , ONLY: & ! Ocean space and time domain variables
34      & jpi,                 &
35      & jpj,                 & 
36      & jpk,                 &
37      & jpim1,               &
38      & jpjm1,               &
39      & jpkm1,               &
40      & jpiglo
41   USE oce_tam       , ONLY: & ! ocean dynamics and active tracers
42      & tb_tl,               &
43      & sb_tl,               &
44      & ta_tl,               &
45      & sa_tl,               &
46      & tb_ad,               &
47      & sb_ad,               &
48      & ta_ad,               &
49      & sa_ad
50   USE dom_oce       , ONLY: & ! ocean space and time domain
51      & e1t,                 &
52      & e2t,                 &
53# if defined key_vvl
54      & e3t_1,               &
55# else
56#  if defined key_zco
57      & e3t_0,               &
58      & e3w_0,               &
59#  else
60      & e3t,                 &
61      & e3w,                 &
62#  endif
63# endif
64      & tmask,               &
65      & lk_vvl,              &
66      & mig,                 &
67      & mjg,                 &
68      & nldi,                &
69      & nldj,                &
70      & nlei,                &
71      & nlej,                &
72      & rdttra
73   USE zdf_oce       , ONLY: & ! ocean vertical physics
74      & avt,                 &
75      & n_zdfexp
76#if defined key_zdfddm
77   USE zdfddm        , ONLY: &
78      & avs
79#endif
80   USE in_out_manager, ONLY: & ! I/O manager
81      & lwp,                 &
82      & numout,              & 
83      & nitend,              & 
84      & nit000
85   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
86      & grid_random
87   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
88      & dot_product
89   USE paresp        , ONLY: & ! Weights for an energy-type scalar product
90      & wesp_t,              &
91      & wesp_s
92   USE tstool_tam    , ONLY: &
93      & prntst_adj,          & !
94      & stdt,                & ! stdev for s-velocity
95      & stds                   !           t-velocity
96
97#if defined key_obc
98   USE obc_oce
99#endif
100
101   IMPLICIT NONE
102   PRIVATE
103
104   PUBLIC   tra_zdf_exp_tan       ! routine called by tra_zdf_tan.F90
105   PUBLIC   tra_zdf_exp_adj       ! routine called by tra_zdf_adj.F90
106   PUBLIC   tra_zdf_exp_adj_tst   ! routine called by tst.F90
107
108   !! * Substitutions
109#  include "domzgr_substitute.h90"
110#  include "zdfddm_substitute.h90"
111#  include "vectopt_loop_substitute.h90"
112   !!----------------------------------------------------------------------
113   !! NEMO/OPA  3.0 , LOCEAN-IPSL (2008)
114   !! $Id: trazdf_exp.F90 1146 2008-06-25 11:42:56Z rblod $
115   !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt)
116   !!----------------------------------------------------------------------
117
118CONTAINS
119
120   SUBROUTINE tra_zdf_exp_tan( kt, p2dt )
121      !!----------------------------------------------------------------------
122      !!                  ***  ROUTINE tra_zdf_exp_tan  ***
123      !!                   
124      !! ** Purpose of the direct routine:
125      !!      Compute the after tracer fields due to the vertical
126      !!      tracer mixing alone, and then due to the whole tracer trend.
127      !!
128      !! ** Method of the direct routine :
129      !!               - The after tracer fields due to the vertical diffusion
130      !!      of tracers alone is given by:
131      !!                zwx = tb + p2dt difft
132      !!      where difft = dz( avt dz(tb) ) = 1/e3t dk+1( avt/e3w dk(tb) )
133      !!           (if lk_zdfddm=T use avs on salinity instead of avt)
134      !!      difft is evaluated with an Euler split-explit scheme using a
135      !!      no flux boundary condition at both surface and bottomi boundaries.
136      !!      (N.B. bottom condition is applied through the masked field avt).
137      !!              - the after tracer fields due to the whole trend is
138      !!      obtained in leap-frog environment by :
139      !!          ta = zwx + p2dt ta
140      !!              - in case of variable level thickness (lk_vvl=T) the
141      !!     the leap-frog is applied on thickness weighted tracer. That is:
142      !!          ta = [ tb*e3tb + e3tn*( zwx - tb + p2dt ta ) ] / e3tn
143      !!
144      !! ** Action : - after tracer fields (ta,sa)
145      !!---------------------------------------------------------------------
146      INTEGER , INTENT(in)                 ::   kt     ! ocean time-step index
147      REAL(wp), INTENT(in), DIMENSION(jpk) ::   p2dt   ! vertical profile of tracer time-step
148      !!
149      INTEGER  ::   ji, jj, jk, jl            ! dummy loop indices
150      REAL(wp) ::   zlavmr, zave3r, ze3tr     ! temporary scalars
151      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwxtl, zwytl, zwztl, zwwtl   ! 3D workspace
152      !!---------------------------------------------------------------------
153
154      IF( kt == nit000 ) THEN
155         IF(lwp) WRITE(numout,*)
156         IF(lwp) WRITE(numout,*) 'tra_zdf_exp_tan : explicit vertical mixing'
157         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~'
158      ENDIF
159
160      ! Initializations
161      ! ---------------
162      zlavmr = 1. / float( n_zdfexp )                           ! Local constant
163      !
164      zwytl(:,:, 1 ) = 0.e0        ;   zwwtl(:,:, 1 ) = 0.e0        ! surface boundary conditions: no flux
165      zwytl(:,:,jpk) = 0.e0        ;   zwwtl(:,:,jpk) = 0.e0        ! bottom  boundary conditions: no flux
166      !
167      zwxtl(:,:,:)   = tb_tl(:,:,:)   ;   zwztl(:,:,:)   = sb_tl(:,:,:)   ! zwx and zwz arrays set to before tracer values
168
169      ! Split-explicit loop  (after tracer due to the vertical diffusion alone)
170      ! -------------------
171      !
172      DO jl = 1, n_zdfexp
173         !                     ! first vertical derivative
174         DO jk = 2, jpk
175            DO jj = 2, jpjm1 
176               DO ji = fs_2, fs_jpim1   ! vector opt.
177                  zave3r = 1.e0 / fse3w(ji,jj,jk) 
178                  zwytl(ji,jj,jk) =   avt(ji,jj,jk) * ( zwxtl(ji,jj,jk-1) - zwxtl(ji,jj,jk) ) * zave3r
179                  zwwtl(ji,jj,jk) = fsavs(ji,jj,jk) * ( zwztl(ji,jj,jk-1) - zwztl(ji,jj,jk) ) * zave3r
180               END DO
181            END DO
182         END DO
183         !
184         DO jk = 1, jpkm1      ! second vertical derivative   ==> tracer at kt+l*2*rdt/n_zdfexp
185            DO jj = 2, jpjm1 
186               DO ji = fs_2, fs_jpim1   ! vector opt.
187                  ze3tr = zlavmr / fse3t(ji,jj,jk)
188                  zwxtl(ji,jj,jk) = zwxtl(ji,jj,jk) + p2dt(jk) * ( zwytl(ji,jj,jk) - zwytl(ji,jj,jk+1) ) * ze3tr
189                  zwztl(ji,jj,jk) = zwztl(ji,jj,jk) + p2dt(jk) * ( zwwtl(ji,jj,jk) - zwwtl(ji,jj,jk+1) ) * ze3tr
190               END DO
191            END DO
192         END DO
193         !
194      END DO
195
196      ! After tracer due to all trends
197      ! ------------------------------
198      IF( lk_vvl ) THEN          ! variable level thickness : leap-frog on tracer*e3t
199         IF(lwp) WRITE(numout,*) "key_vvl net available in tangent yet"
200         CALL abort
201      ELSE                       ! fixed level thickness : leap-frog on tracers
202         DO jk = 1, jpkm1
203            DO jj = 2, jpjm1 
204               DO ji = fs_2, fs_jpim1   ! vector opt.
205                  ta_tl(ji,jj,jk) = ( zwxtl(ji,jj,jk) + p2dt(jk) * ta_tl(ji,jj,jk) ) *tmask(ji,jj,jk)
206                  sa_tl(ji,jj,jk) = ( zwztl(ji,jj,jk) + p2dt(jk) * sa_tl(ji,jj,jk) ) *tmask(ji,jj,jk)
207               END DO
208            END DO
209         END DO
210      ENDIF
211      !
212   END SUBROUTINE tra_zdf_exp_tan
213
214   SUBROUTINE tra_zdf_exp_adj( kt, p2dt )
215      !!----------------------------------------------------------------------
216      !!                  ***  ROUTINE tra_zdf_exp_adj  ***
217      !!                   
218      !! ** Purpose of the direct routine:
219      !!      Compute the after tracer fields due to the vertical
220      !!      tracer mixing alone, and then due to the whole tracer trend.
221      !!
222      !! ** Method of the direct routine :
223      !!               - The after tracer fields due to the vertical diffusion
224      !!      of tracers alone is given by:
225      !!                zwx = tb + p2dt difft
226      !!      where difft = dz( avt dz(tb) ) = 1/e3t dk+1( avt/e3w dk(tb) )
227      !!           (if lk_zdfddm=T use avs on salinity instead of avt)
228      !!      difft is evaluated with an Euler split-explit scheme using a
229      !!      no flux boundary condition at both surface and bottomi boundaries.
230      !!      (N.B. bottom condition is applied through the masked field avt).
231      !!              - the after tracer fields due to the whole trend is
232      !!      obtained in leap-frog environment by :
233      !!          ta = zwx + p2dt ta
234      !!              - in case of variable level thickness (lk_vvl=T) the
235      !!     the leap-frog is applied on thickness weighted tracer. That is:
236      !!          ta = [ tb*e3tb + e3tn*( zwx - tb + p2dt ta ) ] / e3tn
237      !!
238      !! ** Action : - after tracer fields (ta,sa)
239      !!---------------------------------------------------------------------
240      INTEGER , INTENT(in)                 ::   kt     ! ocean time-step index
241      REAL(wp), INTENT(in), DIMENSION(jpk) ::   p2dt   ! vertical profile of tracer time-step
242      !!
243      INTEGER  ::   ji, jj, jk, jl            ! dummy loop indices
244      REAL(wp) ::   zlavmr, zave3r, ze3tr     ! temporary scalars
245      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   zwxad, zwyad, zwzad, zwwad   ! 3D workspace
246      !!---------------------------------------------------------------------
247
248      IF( kt == nit000 ) THEN
249         IF(lwp) WRITE(numout,*)
250         IF(lwp) WRITE(numout,*) 'tra_zdf_exp_adj : explicit vertical mixing'
251         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~~~~~'
252      ENDIF
253
254      ! Initializations
255      ! ---------------
256      zlavmr = 1. / float( n_zdfexp )                           ! Local constant
257      !
258      zwwad(:,:,:) = 0.0_wp       ;   zwxad(:,:,:) = 0.0_wp 
259      zwyad(:,:,:) = 0.0_wp       ;   zwzad(:,:,:) = 0.0_wp
260      ! After tracer due to all trends
261      ! ------------------------------
262      IF( lk_vvl ) THEN          ! variable level thickness : leap-frog on tracer*e3t
263         IF(lwp) WRITE(numout,*) "key_vvl net available in adjoint yet"
264         CALL abort
265      ELSE                       ! fixed level thickness : leap-frog on tracers
266         DO jk = 1, jpkm1
267            DO jj = 2, jpjm1 
268               DO ji = fs_2, fs_jpim1   ! vector opt.
269                  zwxad(ji,jj,jk) = zwxad(ji,jj,jk) + ta_ad(ji,jj,jk) * tmask(ji,jj,jk)
270                  ta_ad(ji,jj,jk) = p2dt(jk) * ta_ad(ji,jj,jk) * tmask(ji,jj,jk)
271                  zwzad(ji,jj,jk) = zwzad(ji,jj,jk) + sa_ad(ji,jj,jk) * tmask(ji,jj,jk)
272                  sa_ad(ji,jj,jk) = p2dt(jk) * sa_ad(ji,jj,jk) * tmask(ji,jj,jk)
273               END DO
274            END DO
275         END DO
276      ENDIF
277      !
278
279      ! Split-explicit loop  (after tracer due to the vertical diffusion alone)
280      ! -------------------
281      !
282      DO jl = 1, n_zdfexp
283         DO jk =  jpkm1, 1, -1      ! second vertical derivative   ==> tracer at kt+l*2*rdt/n_zdfexp
284            DO jj = 2, jpjm1 
285               DO ji = fs_2, fs_jpim1   ! vector opt.
286                  ze3tr = zlavmr / fse3t(ji,jj,jk)
287                  zwyad(ji,jj,jk  ) = zwyad(ji,jj,jk  ) + p2dt(jk) * zwxad(ji,jj,jk) * ze3tr
288                  zwyad(ji,jj,jk+1) = zwyad(ji,jj,jk+1) - p2dt(jk) * zwxad(ji,jj,jk) * ze3tr
289                  zwwad(ji,jj,jk  ) = zwwad(ji,jj,jk  ) + p2dt(jk) * zwzad(ji,jj,jk) * ze3tr
290                  zwwad(ji,jj,jk+1) = zwwad(ji,jj,jk+1) - p2dt(jk) * zwzad(ji,jj,jk) * ze3tr
291               END DO
292            END DO
293         END DO
294         !                     ! first vertical derivative
295         DO jk = jpk, 2, -1
296            DO jj = 2, jpjm1 
297               DO ji = fs_2, fs_jpim1   ! vector opt.
298                  zave3r = 1.e0 / fse3w(ji,jj,jk) 
299                  zwxad(ji,jj,jk-1) = zwxad(ji,jj,jk-1) + avt(ji,jj,jk) * zwyad(ji,jj,jk) * zave3r
300                  zwxad(ji,jj,jk  ) = zwxad(ji,jj,jk  ) - avt(ji,jj,jk) * zwyad(ji,jj,jk) * zave3r
301                  zwyad(ji,jj,jk  ) = 0.0_wp
302                  zwzad(ji,jj,jk-1) = zwzad(ji,jj,jk-1) + fsavs(ji,jj,jk) * zwwad(ji,jj,jk) * zave3r
303                  zwzad(ji,jj,jk  ) = zwzad(ji,jj,jk  ) - fsavs(ji,jj,jk) * zwwad(ji,jj,jk) * zave3r
304                  zwwad(ji,jj,jk  ) = 0.0_wp
305               END DO
306            END DO
307         END DO
308         !
309         !
310      END DO
311
312      tb_ad(:,:,:) = tb_ad(:,:,:) + zwxad(:,:,:) 
313      sb_ad(:,:,:) = sb_ad(:,:,:) + zwzad(:,:,:)
314
315   END SUBROUTINE tra_zdf_exp_adj
316
317   SUBROUTINE tra_zdf_exp_adj_tst( kumadt )
318      !!-----------------------------------------------------------------------
319      !!
320      !!                  ***  ROUTINE tra_zdf_exp_adj_tst ***
321      !!
322      !! ** Purpose : Test the adjoint routine.
323      !!
324      !! ** Method  : Verify the scalar product
325      !!           
326      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
327      !!
328      !!              where  L   = tangent routine
329      !!                     L^T = adjoint routine
330      !!                     W   = diagonal matrix of scale factors
331      !!                     dx  = input perturbation (random field)
332      !!                     dy  = L dx
333      !!
334      !!                   
335      !! History :
336      !!        ! 08-08 (A. Vidard)
337      !!-----------------------------------------------------------------------
338      !! * Modules used
339
340      !! * Arguments
341      INTEGER, INTENT(IN) :: &
342         & kumadt             ! Output unit
343 
344      !! * Local declarations
345      INTEGER ::  &
346         & ji,    &        ! dummy loop indices
347         & jj,    &       
348         & jk     
349      INTEGER, DIMENSION(jpi,jpj) :: &
350         & iseed_2d        ! 2D seed for the random number generator
351      REAL(KIND=wp) ::   &
352         & zsp1,         & ! scalar product involving the tangent routine
353         & zsp2            ! scalar product involving the adjoint routine
354      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
355         & zta_tlin ,     & ! Tangent input
356         & ztb_tlin ,     & ! Tangent input
357#if defined key_obc
358         & ztb_tlout, zsb_tlout, ztb_adin, zsb_adin,  & 
359#endif
360         & zsa_tlin ,     & ! Tangent input
361         & zsb_tlin ,     & ! Tangent input
362         & zta_tlout,     & ! Tangent output
363         & zsa_tlout,     & ! Tangent output
364         & zta_adin ,     & ! Adjoint input
365         & zsa_adin ,     & ! Adjoint input
366         & zta_adout,     & ! Adjoint output
367         & ztb_adout,     & ! Adjoint output
368         & zsa_adout,     & ! Adjoint output
369         & zsb_adout,     & ! Adjoint output
370         & zr             ! 3D random field
371      CHARACTER(LEN=14) :: cl_name
372      ! Allocate memory
373
374      ALLOCATE( &
375         & zta_tlin( jpi,jpj,jpk),     &
376         & zsa_tlin( jpi,jpj,jpk),     &
377         & ztb_tlin( jpi,jpj,jpk),     &
378         & zsb_tlin( jpi,jpj,jpk),     &
379         & zta_tlout(jpi,jpj,jpk),     &
380         & zsa_tlout(jpi,jpj,jpk),     &
381         & zta_adin( jpi,jpj,jpk),     &
382         & zsa_adin( jpi,jpj,jpk),     &
383         & zta_adout(jpi,jpj,jpk),     &
384         & zsa_adout(jpi,jpj,jpk),     &
385         & ztb_adout(jpi,jpj,jpk),     &
386         & zsb_adout(jpi,jpj,jpk),     &
387         & zr(       jpi,jpj,jpk)      &
388         & )
389
390#if defined key_obc
391      ALLOCATE( ztb_tlout(jpi,jpj,jpk),  zsb_tlout(jpi,jpj,jpk),     &
392           &    ztb_adin (jpi,jpj,jpk),  zsb_adin (jpi,jpj,jpk) )
393#endif
394
395      !==================================================================
396      ! 1) dx = ( un_tl, vn_tl, hdivn_tl ) and
397      !    dy = ( hdivb_tl, hdivn_tl )
398      !==================================================================
399
400      !--------------------------------------------------------------------
401      ! Reset the tangent and adjoint variables
402      !--------------------------------------------------------------------
403          zta_tlin( :,:,:) = 0.0_wp
404          ztb_tlin( :,:,:) = 0.0_wp
405          zsa_tlin( :,:,:) = 0.0_wp
406          zsb_tlin( :,:,:) = 0.0_wp
407          zta_tlout(:,:,:) = 0.0_wp
408          zsa_tlout(:,:,:) = 0.0_wp
409          zta_adin( :,:,:) = 0.0_wp
410          zsa_adin( :,:,:) = 0.0_wp
411          zta_adout(:,:,:) = 0.0_wp
412          zsa_adout(:,:,:) = 0.0_wp
413          ztb_adout(:,:,:) = 0.0_wp
414          zsb_adout(:,:,:) = 0.0_wp
415          zr(       :,:,:) = 0.0_wp
416      !--------------------------------------------------------------------
417      ! Initialize the tangent input with random noise: dx
418      !--------------------------------------------------------------------
419
420      DO jj = 1, jpj
421         DO ji = 1, jpi
422            iseed_2d(ji,jj) = - ( 596035 + &
423               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
424         END DO
425      END DO
426      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdt )
427      DO jk = 1, jpk
428        DO jj = nldj, nlej
429           DO ji = nldi, nlei
430              zta_tlin(ji,jj,jk) = zr(ji,jj,jk) 
431           END DO
432        END DO
433     END DO
434
435     DO jj = 1, jpj
436         DO ji = 1, jpi
437            iseed_2d(ji,jj) = - ( 352791 + &
438               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
439         END DO
440      END DO
441      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stdt )
442      DO jk = 1, jpk
443        DO jj = nldj, nlej
444           DO ji = nldi, nlei
445              ztb_tlin(ji,jj,jk) = zr(ji,jj,jk) 
446           END DO
447        END DO
448     END DO
449
450     DO jj = 1, jpj
451         DO ji = 1, jpi
452            iseed_2d(ji,jj) = - ( 142746 + &
453               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
454         END DO
455      END DO
456      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stds )
457      DO jk = 1, jpk
458        DO jj = nldj, nlej
459           DO ji = nldi, nlei
460              zsa_tlin(ji,jj,jk) = zr(ji,jj,jk) 
461           END DO
462        END DO
463     END DO
464     DO jj = 1, jpj
465         DO ji = 1, jpi
466            iseed_2d(ji,jj) = - ( 214934 + &
467               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
468         END DO
469      END DO
470      CALL grid_random( iseed_2d, zr, 'T', 0.0_wp, stds )
471      DO jk = 1, jpk
472        DO jj = nldj, nlej
473           DO ji = nldi, nlei
474              zsb_tlin(ji,jj,jk) = zr(ji,jj,jk) 
475           END DO
476        END DO
477     END DO
478      ta_tl(:,:,:) = zta_tlin(:,:,:)
479      sa_tl(:,:,:) = zsa_tlin(:,:,:)
480      tb_tl(:,:,:) = ztb_tlin(:,:,:)
481      sb_tl(:,:,:) = zsb_tlin(:,:,:)
482      CALL tra_zdf_exp_tan ( nit000, rdttra )
483      zta_tlout(:,:,:) = ta_tl(:,:,:)
484      zsa_tlout(:,:,:) = sa_tl(:,:,:)
485#if defined key_obc
486      ztb_tlout(:,:,:) = tb_tl(:,:,:)
487      zsb_tlout(:,:,:) = sb_tl(:,:,:)     
488#endif
489
490      !--------------------------------------------------------------------
491      ! Initialize the adjoint variables: dy^* = W dy
492      !--------------------------------------------------------------------
493
494      DO jk = 1, jpk
495        DO jj = nldj, nlej
496           DO ji = nldi, nlei
497              zta_adin(ji,jj,jk) = zta_tlout(ji,jj,jk) &
498                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
499                 &               * tmask(ji,jj,jk) * wesp_t(jk)
500              zsa_adin(ji,jj,jk) = zsa_tlout(ji,jj,jk) &
501                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
502                 &               * tmask(ji,jj,jk) * wesp_s(jk)
503#if defined key_obc
504              ztb_adin(ji,jj,jk) = ztb_tlout(ji,jj,jk) &
505                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
506                 &               * tmask(ji,jj,jk) * wesp_t(jk)
507              zsb_adin(ji,jj,jk) = zsb_tlout(ji,jj,jk) &
508                 &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
509                 &               * tmask(ji,jj,jk) * wesp_s(jk)
510           
511#endif
512            END DO
513         END DO
514      END DO
515      !--------------------------------------------------------------------
516      ! Compute the scalar product: ( L dx )^T W dy
517      !--------------------------------------------------------------------
518
519      zsp1 = DOT_PRODUCT( zta_tlout, zta_adin ) &
520         & + DOT_PRODUCT( zsa_tlout, zsa_adin )
521
522#if defined key_obc
523      zsp1 = zsp1 + DOT_PRODUCT( ztb_tlout, ztb_adin ) &
524           &      + DOT_PRODUCT( zsb_tlout, zsb_adin )
525#endif
526
527      !--------------------------------------------------------------------
528      ! Call the adjoint routine: dx^* = L^T dy^*
529      !--------------------------------------------------------------------
530
531      ta_ad(:,:,:) = zta_adin(:,:,:)
532      sa_ad(:,:,:) = zsa_adin(:,:,:)
533
534#if defined key_obc
535      tb_ad(:,:,:) = ztb_adin(:,:,:)
536      sb_ad(:,:,:) = zsb_adin(:,:,:)
537#endif
538     
539      CALL tra_zdf_exp_adj ( nit000, rdttra )
540     
541      zta_adout(:,:,:) = ta_ad(:,:,:)
542      zsa_adout(:,:,:) = sa_ad(:,:,:)
543      ztb_adout(:,:,:) = tb_ad(:,:,:)
544      zsb_adout(:,:,:) = sb_ad(:,:,:)
545
546      zsp2 = DOT_PRODUCT( zta_tlin, zta_adout ) &
547         & + DOT_PRODUCT( zsa_tlin, zsa_adout ) &
548         & + DOT_PRODUCT( ztb_tlin, ztb_adout ) &
549         & + DOT_PRODUCT( zsb_tlin, zsb_adout ) 
550
551      ! 14 char:'12345678901234'
552      cl_name = 'trazdf_exp_adj'
553      CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
554
555      DEALLOCATE(   &
556         & zta_tlin,  &
557         & ztb_tlin,  &
558         & zsa_tlin,  &
559         & zsb_tlin,  &
560         & zta_tlout, &
561         & zsa_tlout, &
562         & zta_adin,  &
563         & zsa_adin,  &
564         & zta_adout, &
565         & ztb_adout, &
566         & zsa_adout, &
567         & zsb_adout, &
568         & zr       &
569         & )
570
571
572
573   END SUBROUTINE tra_zdf_exp_adj_tst
574
575   !!==============================================================================
576#endif
577END MODULE trazdf_exp_tam
Note: See TracBrowser for help on using the repository browser.