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

source: branches/TAM_V3_2_2/NEMOTAM/OPATAM_SRC/TRA/traqsr_tam.F90 @ 3032

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

first import of NEMOTAM 3.2.2

File size: 30.8 KB
Line 
1MODULE traqsr_tam
2#ifdef key_tam
3   !!======================================================================
4   !!                       ***  MODULE  traqsr_tam  ***
5   !! Ocean physics: solar radiation penetration in the top ocean levels
6   !!                Tangent and Adjoint Module
7   !!======================================================================
8   !! History :  OPA  !  1990-10  (B. Blanke)  Original code
9   !!            7.0  !  1991-11  (G. Madec)
10   !!                 !  1996-01  (G. Madec)  s-coordinates
11   !!   NEMO     1.0  !  2002-06  (G. Madec)  F90: Free form and module
12   !!             -   !  2005-11  (G. Madec) zco, zps, sco coordinate
13   !!            3.2  !  2009-04  (G. Madec & NEMO team)
14   !! History of the TAM:
15   !!                 !  2008-05  (A. Vidard) Skeleton
16   !!            3.0  !  2008-09  (A. Vidard)   TAM of the 2005-11 version
17   !!            3.2  !  2010-03  (F. Vigilant) TAM of the 2009-11 version
18   !!----------------------------------------------------------------------
19
20   !!----------------------------------------------------------------------
21   !!   tra_qsr      : trend due to the solar radiation penetration
22   !!   tra_qsr_init : solar radiation penetration initialization
23   !!----------------------------------------------------------------------
24   USE par_kind      , ONLY: & ! Precision variables
25      & wp
26   USE par_oce       , ONLY: &
27      & jpi,                 &
28      & jpj,                 &
29      & jpk,                 &
30      & jpim1,               &
31      & jpjm1,               &
32      & jpkm1,               &
33      & jpiglo
34   USE oce_tam       , ONLY: & ! ocean dynamics and active tracers
35      & ta_tl,               &
36      & ta_ad
37   USE dom_oce       , ONLY: & ! ocean space and time domain
38      & tmask,               &
39      & ln_zco,              &
40      & ln_sco,              &
41      & ln_zps,              &
42      & e1t,                 &
43      & e2t,                 &
44#if ! defined key_zco
45      & e3t,                 &
46#endif
47      & e3t_0,               &
48      & gdepw_0,             &
49      & mig,                 &
50      & mjg,                 &
51      & nldi,                &
52      & nldj,                &
53      & nlei,                &
54      & nlej
55   USE in_out_manager, ONLY: & ! I/O manager
56      & lwp,                 &
57      & numout,              & 
58      & nit000,              & 
59      & nitend 
60   USE fldread                 ! read input fields
61   USE sbc_oce       , ONLY: & ! thermohaline fluxes
62      & qsr
63   USE sbc_oce_tam   , ONLY: & ! thermohaline fluxes
64      & qsr_tl,              &
65      & qsr_ad
66   USE phycst        , ONLY: & ! physical constants
67      & ro0cpr
68   USE prtctl        , ONLY: & ! Print control
69      & prt_ctl
70   USE gridrandom    , ONLY: & ! Random Gaussian noise on grids
71      & grid_random
72   USE dotprodfld    , ONLY: & ! Computes dot product for 3D and 2D fields
73      & dot_product
74   USE traqsr        , ONLY: & ! Solar radiation penetration
75      & ln_traqsr,           &
76      & ln_qsr_rgb,          &
77      & ln_qsr_2bd,          &
78      & ln_qsr_bio,          &
79      & tra_qsr_init,        &
80      & rn_abs,              &
81      & rn_si0,              &
82      & rn_si1,              &
83      & rn_si2,              &
84      & nn_chldta,           &
85      & sf_chl,              &
86      & nksr,                &
87      & rkrgb
88   USE trc_oce       , ONLY: & ! share SMS/Ocean variables
89      & etot3,               &
90      & lk_qsr_bio
91   USE trc_oce_tam   , ONLY: & ! share SMS/Ocean variables
92      & trc_oce_tam_init,    &
93      & etot3_tl,            &
94      & etot3_ad
95   USE tstool_tam    , ONLY: &
96      & prntst_adj,          &
97      & stdqsr,              &
98      & stdt
99   IMPLICIT NONE
100   PRIVATE
101
102   PUBLIC   tra_qsr_tan      ! routine called by step_tam.F90 (ln_traqsr=T)
103   PUBLIC   tra_qsr_adj      ! routine called by step_tam.F90 (ln_traqsr=T)
104   PUBLIC   tra_qsr_adj_tst  ! routine called by tst.F90
105
106   !! * Substitutions
107#  include "domzgr_substitute.h90"
108#  include "vectopt_loop_substitute.h90"
109
110CONTAINS
111
112   SUBROUTINE tra_qsr_tan( kt )
113      !!----------------------------------------------------------------------
114      !!                  ***  ROUTINE tra_qsr_tan  ***
115      !!
116      !! ** Purpose :   Compute the temperature trend due to the solar radiation
117      !!      penetration and add it to the general temperature trend.
118      !!
119      !! ** Method  : The profile of the solar radiation within the ocean is defined
120      !!      through 2 wavebands (rn_si0,rn_si1) or 3 wavebands (RGB) and a ratio rn_abs
121      !!      Considering the 2 wavebands case:
122      !!         I(k) = Qsr*( rn_abs*EXP(z(k)/rn_si0) + (1.-rn_abs)*EXP(z(k)/rn_si1) )
123      !!         The temperature trend associated with the solar radiation penetration
124      !!         is given by : zta = 1/e3t dk[ I ] / (rau0*Cp)
125      !!         At the bottom, boudary condition for the radiation is no flux :
126      !!      all heat which has not been absorbed in the above levels is put
127      !!      in the last ocean level.
128      !!         In z-coordinate case, the computation is only done down to the
129      !!      level where I(k) < 1.e-15 W/m2. In addition, the coefficients
130      !!      used for the computation are calculated one for once as they
131      !!      depends on k only.
132      !!
133      !! ** Action  : - update ta with the penetrative solar radiation trend
134      !!
135      !! Reference  : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
136      !!              Lengaigne et al. 2007, Clim. Dyn., V28, 5, 503-516.
137      !!----------------------------------------------------------------------
138      INTEGER, INTENT(in) ::   kt        ! ocean time-step
139      !
140      !!
141      INTEGER  ::    ji, jj, jk          ! dummy loop indexes
142      INTEGER  ::   irgb                 ! temporary integers
143      REAL(wp) ::   zchl, zcoef, zsi0r   ! temporary scalars
144      REAL(wp) ::   zc0tl, zc1tl, zc2tl, zc3tl   !    -         -
145      REAL(wp), DIMENSION(jpi,jpj)     ::   zekb, zekg, zekr                      ! 2D workspace
146      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze0tl, ze1tl , ze2tl, ze3tl, zeatl    ! 3D workspace
147      !!----------------------------------------------------------------------
148
149      IF( kt == nit000 ) THEN
150         IF(lwp) WRITE(numout,*)
151         IF(lwp) WRITE(numout,*) 'tra_qsr_tan : penetration of the surface solar radiation'
152         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
153         CALL tra_qsr_init
154         CALL tra_qsr_init_tan
155         IF( .NOT.ln_traqsr )   RETURN
156      ENDIF
157      !                                           ! ============================================== !
158      IF( lk_qsr_bio .AND. ln_qsr_bio ) THEN      !  bio-model fluxes  : all vertical coordinates  !
159         !                                        ! ============================================== !
160         DO jk = 1, jpkm1
161            DO jj = 2, jpjm1
162               DO ji = fs_2, fs_jpim1   ! vector opt.
163                  ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) + ro0cpr * ( etot3_tl(ji,jj,jk) - etot3_tl(ji,jj,jk+1) ) / fse3t(ji,jj,jk) 
164               END DO
165            END DO
166         END DO
167         !                                        ! ============================================== !
168      ELSE                                        !  Ocean alone :
169         !                                        ! ============================================== !
170         !
171         !                                                ! ------------------------- !
172         IF( ln_qsr_rgb) THEN                             !  R-G-B  light penetration !
173            !                                             ! ------------------------- !
174            ! Set chlorophyl concentration
175            IF( nn_chldta ==1 ) THEN                             !*  Variable Chlorophyll
176               !
177               CALL fld_read( kt, 1, sf_chl )                         ! Read Chl data and provides it at the current time step
178               !         
179!CDIR COLLAPSE
180!CDIR NOVERRCHK
181               DO jj = 1, jpj                                         ! Separation in R-G-B depending of the surface Chl
182!CDIR NOVERRCHK
183                  DO ji = 1, jpi
184                     zchl = MIN( 10.0_wp , MAX( 0.03_wp, sf_chl(1)%fnow(ji,jj) ) )
185                     irgb = NINT( 41 + 20.*LOG10(zchl) + 1.e-15 )
186                     zekb(ji,jj) = rkrgb(1,irgb)
187                     zekg(ji,jj) = rkrgb(2,irgb)
188                     zekr(ji,jj) = rkrgb(3,irgb)
189                  END DO
190               END DO
191               !
192               zsi0r = 1.0_wp / rn_si0
193               zcoef  = ( 1.0_wp - rn_abs ) / 3.0_wp                        ! equi-partition in R-G-B
194               ze0tl(:,:,1) = rn_abs  * qsr_tl(:,:)
195               ze1tl(:,:,1) = zcoef * qsr_tl(:,:)
196               ze2tl(:,:,1) = zcoef * qsr_tl(:,:)
197               ze3tl(:,:,1) = zcoef * qsr_tl(:,:)
198               zeatl(:,:,1) =         qsr_tl(:,:)
199               !
200               DO jk = 2, nksr+1
201!CDIR NOVERRCHK
202                  DO jj = 1, jpj
203!CDIR NOVERRCHK   
204                     DO ji = 1, jpi
205                        zc0tl = ze0tl(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zsi0r     )
206                        zc1tl = ze1tl(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekb(ji,jj) )
207                        zc2tl = ze2tl(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekg(ji,jj) )
208                        zc3tl = ze3tl(ji,jj,jk-1) * EXP( - fse3t(ji,jj,jk-1) * zekr(ji,jj) )
209                        ze0tl(ji,jj,jk) = zc0tl
210                        ze1tl(ji,jj,jk) = zc1tl
211                        ze2tl(ji,jj,jk) = zc2tl
212                        ze3tl(ji,jj,jk) = zc3tl
213                        zeatl(ji,jj,jk) = ( zc0tl + zc1tl + zc2tl + zc3tl ) * tmask(ji,jj,jk)
214                     END DO
215                  END DO
216               END DO
217               !
218               DO jk = 1, nksr                                        ! compute and add qsr trend to ta
219                  ta_tl(:,:,jk) = ta_tl(:,:,jk) + ro0cpr * ( zeatl(:,:,jk) - zeatl(:,:,jk+1) ) / fse3t(:,:,jk)
220               END DO
221               zeatl(:,:,nksr+1:jpk) = 0.0_wp     ! below 400m set to zero
222               !
223            ELSE                                                 !*  Constant Chlorophyll
224               DO jk = 1, nksr
225                  ta_tl(:,:,jk) = ta_tl(:,:,jk) + etot3_tl(:,:,jk) * qsr(:,:) + etot3(:,:,jk) * qsr_tl(:,:)
226               END DO
227            ENDIF
228
229         ENDIF
230         !                                                ! ------------------------- !
231         IF( ln_qsr_2bd ) THEN                            !  2 band light penetration !
232            !                                             ! ------------------------- !
233            !
234            DO jk = 1, nksr
235               DO jj = 2, jpjm1
236                  DO ji = fs_2, fs_jpim1   ! vector opt.
237                     ta_tl(ji,jj,jk) = ta_tl(ji,jj,jk) + etot3_tl(ji,jj,jk) * qsr(ji,jj) + etot3(ji,jj,jk) * qsr_tl(ji,jj)
238                  END DO
239               END DO
240            END DO
241            !
242         ENDIF
243         !
244      ENDIF
245      !
246   END SUBROUTINE tra_qsr_tan
247   SUBROUTINE tra_qsr_adj( kt )
248      !!----------------------------------------------------------------------
249      !!                  ***  ROUTINE tra_qsr_adj  ***
250      !!
251      !! ** Purpose :   Compute the temperature trend due to the solar radiation
252      !!      penetration and add it to the general temperature trend.
253      !!
254      !! ** Method  : The profile of the solar radiation within the ocean is defined
255      !!      through 2 wavebands (rn_si0,rn_si1) or 3 wavebands (RGB) and a ratio rn_abs
256      !!      Considering the 2 wavebands case:
257      !!         I(k) = Qsr*( rn_abs*EXP(z(k)/rn_si0) + (1.-rn_abs)*EXP(z(k)/rn_si1) )
258      !!         The temperature trend associated with the solar radiation penetration
259      !!         is given by : zta = 1/e3t dk[ I ] / (rau0*Cp)
260      !!         At the bottom, boudary condition for the radiation is no flux :
261      !!      all heat which has not been absorbed in the above levels is put
262      !!      in the last ocean level.
263      !!         In z-coordinate case, the computation is only done down to the
264      !!      level where I(k) < 1.e-15 W/m2. In addition, the coefficients
265      !!      used for the computation are calculated one for once as they
266      !!      depends on k only.
267      !!
268      !! ** Action  : - update ta with the penetrative solar radiation trend
269      !!
270      !! Reference  : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
271      !!              Lengaigne et al. 2007, Clim. Dyn., V28, 5, 503-516.
272      !!----------------------------------------------------------------------
273      !!
274      INTEGER, INTENT(in) ::   kt     ! ocean time-step
275      !
276      !!
277      INTEGER  ::    ji, jj, jk       ! dummy loop indexes
278      INTEGER  ::   irgb                 ! temporary integers
279      REAL(wp) ::   zchl, zcoef, zsi0r   ! temporary scalars
280      REAL(wp) ::   zc0ad, zc1ad, zc2ad, zc3ad   !    -         -
281      REAL(wp), DIMENSION(jpi,jpj)     ::   zekb, zekg, zekr                      ! 2D workspace
282      REAL(wp), DIMENSION(jpi,jpj,jpk) ::   ze0ad, ze1ad , ze2ad, ze3ad, zeaad    ! 3D workspace
283      !!----------------------------------------------------------------------
284      IF( kt == nitend ) THEN
285         IF(lwp) WRITE(numout,*)
286         IF(lwp) WRITE(numout,*) 'tra_qsr_adj : penetration of the surface solar radiation'
287         IF(lwp) WRITE(numout,*) '~~~~~~~~~~~'
288         CALL tra_qsr_init
289         IF( .NOT.ln_traqsr )   RETURN
290      ENDIF
291      !                                           ! ============================================== !
292      IF( lk_qsr_bio .AND. ln_qsr_bio ) THEN      !  bio-model fluxes  : all vertical coordinates  !
293         !                                        ! ============================================== !
294         DO jk = jpkm1, 1, -1
295            DO jj = 2, jpjm1
296               DO ji = fs_2, fs_jpim1   ! vector opt.
297                  etot3_ad(ji,jj,jk)   = etot3_ad(ji,jj,jk  ) + ro0cpr * ta_ad(ji,jj,jk) / fse3t(ji,jj,jk)
298                  etot3_ad(ji,jj,jk+1) = etot3_ad(ji,jj,jk+1) - ro0cpr * ta_ad(ji,jj,jk) / fse3t(ji,jj,jk)
299               END DO
300            END DO
301         END DO
302         !                                        ! ============================================== !
303      ELSE                                        !  Ocean alone :
304         !                                        ! ============================================== !
305         !
306         !                                                ! ------------------------- !
307         IF( ln_qsr_2bd ) THEN                            !  2 band light penetration !
308            !                                             ! ------------------------- !
309            !
310            DO jk = 1, nksr
311               DO jj = 2, jpjm1
312                  DO ji = fs_2, fs_jpim1   ! vector opt.
313                     etot3_ad(ji,jj,jk) = etot3_ad(ji,jj,jk) + ta_ad(ji,jj,jk) *  qsr(ji,jj)
314                     qsr_ad(ji,jj     ) = qsr_ad(ji,jj     ) + ta_ad(ji,jj,jk) * etot3(ji,jj,jk)   
315                  END DO
316               END DO
317            END DO
318            !
319         ENDIF
320         !
321         !                                                ! ------------------------- !
322         IF( ln_qsr_rgb) THEN                             !  R-G-B  light penetration !
323            !                                             ! ------------------------- !
324            ! Set chlorophyl concentration
325            IF( nn_chldta ==1 ) THEN                             !*  Variable Chlorophyll
326               zc0ad = 0.0_wp; zc1ad = 0.0_wp; zc2ad = 0.0_wp; zc3ad = 0.0_wp
327               ze0ad(:,:,:) = 0.0_wp; ze1ad(:,:,:) = 0.0_wp; ze2ad(:,:,:) = 0.0_wp; ze3ad(:,:,:) = 0.0_wp
328               zeaad(:,:,:) = 0.0_wp
329               !
330               CALL fld_read( kt, 1, sf_chl )                         ! Read Chl data and provides it at the current time step
331               !         
332!CDIR COLLAPSE
333!CDIR NOVERRCHK
334               DO jj = 1, jpj                                         ! Separation in R-G-B depending of the surface Chl
335!CDIR NOVERRCHK
336                  DO ji = 1, jpi
337                     zchl = MIN( 10.0_wp , MAX( 0.03_wp, sf_chl(1)%fnow(ji,jj) ) )
338                     irgb = NINT( 41 + 20.*LOG10(zchl) + 1.e-15 )
339                     zekb(ji,jj) = rkrgb(1,irgb)
340                     zekg(ji,jj) = rkrgb(2,irgb)
341                     zekr(ji,jj) = rkrgb(3,irgb)
342                  END DO
343               END DO
344               !
345               zsi0r = 1.0_wp / rn_si0
346               zcoef  = ( 1.0_wp - rn_abs ) / 3.0_wp
347
348               zeaad(:,:,nksr+1:jpk) = 0.0_wp     ! below 400m set to zero
349               !
350               DO jk = 1, nksr                                        ! compute and add qsr trend to ta
351                  zeaad(:,:,jk  ) =   ro0cpr * ta_ad(:,:,jk) / fse3t(:,:,jk)
352                  zeaad(:,:,jk+1) = - ro0cpr * ta_ad(:,:,jk) / fse3t(:,:,jk)                 
353               END DO
354               !
355               DO jk = nksr+1, 2, -1
356!CDIR NOVERRCHK
357                  DO jj = 1, jpj
358!CDIR NOVERRCHK   
359                     DO ji = 1, jpi
360                        zc0ad = zc0ad + zeaad(ji,jj,jk) * tmask(ji,jj,jk)
361                        zc1ad = zc1ad + zeaad(ji,jj,jk) * tmask(ji,jj,jk)
362                        zc2ad = zc2ad + zeaad(ji,jj,jk) * tmask(ji,jj,jk)
363                        zc3ad = zc3ad + zeaad(ji,jj,jk) * tmask(ji,jj,jk)
364                        zeaad(ji,jj,jk) = 0.0_wp
365                        zc0ad = zc0ad + ze0ad(ji,jj,jk)
366                        zc1ad = zc1ad + ze1ad(ji,jj,jk)
367                        zc2ad = zc2ad + ze2ad(ji,jj,jk)
368                        zc3ad = zc3ad + ze3ad(ji,jj,jk)
369                        ze0ad(ji,jj,jk) = 0.0_wp
370                        ze1ad(ji,jj,jk) = 0.0_wp
371                        ze2ad(ji,jj,jk) = 0.0_wp
372                        ze3ad(ji,jj,jk) = 0.0_wp
373                        ze0ad(ji,jj,jk-1) = ze0ad(ji,jj,jk-1) + zc0ad * EXP( - fse3t(ji,jj,jk-1) * zsi0r     )
374                        ze1ad(ji,jj,jk-1) = ze1ad(ji,jj,jk-1) + zc1ad * EXP( - fse3t(ji,jj,jk-1) * zekb(ji,jj) )
375                        ze2ad(ji,jj,jk-1) = ze2ad(ji,jj,jk-1) + zc2ad * EXP( - fse3t(ji,jj,jk-1) * zekg(ji,jj) )
376                        ze3ad(ji,jj,jk-1) = ze3ad(ji,jj,jk-1) + zc3ad * EXP( - fse3t(ji,jj,jk-1) * zekr(ji,jj) )
377                        zc0ad = 0.0_wp
378                        zc1ad = 0.0_wp
379                        zc2ad = 0.0_wp
380                        zc3ad = 0.0_wp
381                     END DO
382                  END DO
383               END DO
384               !
385               qsr_ad(:,:) = qsr_ad(:,:) + zeaad(:,:,1)
386               qsr_ad(:,:) = qsr_ad(:,:) + zcoef  * ze3ad(:,:,1)
387               qsr_ad(:,:) = qsr_ad(:,:) + zcoef  * ze2ad(:,:,1)               
388               qsr_ad(:,:) = qsr_ad(:,:) + zcoef  * ze1ad(:,:,1)               
389               qsr_ad(:,:) = qsr_ad(:,:) + rn_abs * ze0ad(:,:,1)
390               !
391            ELSE                                                 !*  Constant Chlorophyll
392               DO jk = 1, nksr
393                  etot3_ad(:,:,jk) = etot3_ad(:,:,jk) + ta_ad(:,:,jk) * qsr(:,:)
394                  qsr_ad(  :,:   ) = qsr_ad(  :,:   ) + ta_ad(:,:,jk) * etot3(:,:,jk)
395               END DO
396            ENDIF
397         ENDIF
398      ENDIF
399
400      IF( kt == nit000 ) THEN
401         CALL tra_qsr_init_adj
402      ENDIF
403
404   END SUBROUTINE tra_qsr_adj
405   SUBROUTINE tra_qsr_adj_tst ( kumadt ) 
406      !!-----------------------------------------------------------------------
407      !!
408      !!          ***  ROUTINE tra_sbc_adj_tst : TEST OF tra_sbc_adj  ***
409      !!
410      !! ** Purpose : Test the adjoint routine.
411      !!
412      !! ** Method  : Verify the scalar product
413      !!           
414      !!                 ( L dx )^T W dy  =  dx^T L^T W dy
415      !!
416      !!              where  L   = tangent routine
417      !!                     L^T = adjoint routine
418      !!                     W   = diagonal matrix of scale factors
419      !!                     dx  = input perturbation (random field)
420      !!                     dy  = L dx
421      !!
422      !! History :
423      !!        ! 08-08 (A. Vidard)
424      !!-----------------------------------------------------------------------
425      !! * Modules used
426
427      !! * Arguments
428      INTEGER, INTENT(IN) :: &
429         & kumadt             ! Output unit
430 
431      INTEGER ::  &
432         & jstp,  &
433         & ji,    &        ! dummy loop indices
434         & jj,    &       
435         & jk     
436      INTEGER, DIMENSION(jpi,jpj) :: &
437         & iseed_2d        ! 2D seed for the random number generator
438
439      !! * Local declarations
440      REAL(KIND=wp), DIMENSION(:,:,:), ALLOCATABLE :: &
441         & zta_tlin,     &! Tangent input : after temperature
442         & zta_tlout,    &! Tangent output: after temperature
443         & zta_adout,    &! Adjoint output: after temperature
444         & zta_adin,     &! Adjoint input : after temperature
445         & zetot3_tlin,  &! Tangent input
446         & zetot3_adout, &! Adjoint output
447         & zta,          & ! temporary after temperature
448         & zetot3          ! temporary
449      REAL(KIND=wp), DIMENSION(:,:), ALLOCATABLE :: &
450         & zqsr_tlin,    &! Tangent input : solar radiation (w/m2)
451         & zqsr_adout,   &! Adjoint output: solar radiation (w/m2)
452         & zqsr           ! temporary solar radiation (w/m2)
453      REAL(KIND=wp) ::       &
454         & zsp1,             & ! scalar product involving the tangent routine
455         & zsp2,             & ! scalar product involving the adjoint routine
456         & zsp2_1,           & ! scalar product involving the adjoint routine
457         & zsp2_2,           & ! scalar product involving the adjoint routine
458         & zsp2_3              ! scalar product involving the adjoint routine
459      CHARACTER(LEN=14) :: &
460         & cl_name
461
462      ALLOCATE( & 
463         & zta_tlin(jpi,jpj,jpk),     &
464         & zta_tlout(jpi,jpj,jpk),    &
465         & zta_adout(jpi,jpj,jpk),    &
466         & zta_adin(jpi,jpj,jpk),     &
467         & zta(jpi,jpj,jpk),          &
468         & zqsr_tlin(jpi,jpj),        &
469         & zqsr_adout(jpi,jpj),       &
470         & zetot3_tlin(jpi,jpj,jpk),  &
471         & zetot3_adout(jpi,jpj,jpk), &
472         & zqsr(jpi,jpj),             &
473         & zetot3(jpi,jpj,jpk)        &
474         & )
475      ! Initialize the reference state
476      qsr(:,:) = 1.0_wp ! ???
477      !Initialize etot3 to non-zero value until traj(nit000-1) is fixed
478      etot3(:,:,1) = 2.e-8   ; etot3(:,:,2) = 1.5e-9; etot3(:,:,3) = 8.5e-10
479      etot3(:,:,4) = 5.4e-10 ; etot3(:,:,5) = 3.5e-10; etot3(:,:,6:jpk) = 0.0_wp 
480      ! Initialize random field standard deviations
481      !=============================================================
482      ! 1) dx = ( T ) and dy = ( T )
483      !=============================================================
484
485      CALL trc_oce_tam_init( 0 )
486
487      !--------------------------------------------------------------------
488      ! Reset the tangent and adjoint variables
489      !--------------------------------------------------------------------
490      zta_tlin(:,:,:)     = 0.0_wp     
491      zta_tlout(:,:,:)    = 0.0_wp   
492      zta_adout(:,:,:)    = 0.0_wp   
493      zta_adin(:,:,:)     = 0.0_wp     
494      zqsr_adout(:,:)     = 0.0_wp       
495      zqsr_tlin(:,:)      = 0.0_wp 
496      zetot3_tlin(:,:,:)  = 0.0_wp
497      zetot3_adout(:,:,:) = 0.0_wp 
498      ta_ad(:,:,:)        = 0.0_wp
499      qsr_ad(:,:)         = 0.0_wp
500      etot3_ad(:,:,:)     = 0.0_wp
501     
502      DO jj = 1, jpj
503         DO ji = 1, jpi
504            iseed_2d(ji,jj) = - ( 358606 + &
505               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
506         END DO
507      END DO
508      CALL grid_random( iseed_2d, zqsr, 'T', 0.0_wp, stdqsr )
509      DO jj = 1, jpj
510         DO ji = 1, jpi
511            iseed_2d(ji,jj) = - ( 232567 + &
512               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
513         END DO
514      END DO
515      CALL grid_random( iseed_2d, zta, 'T', 0.0_wp, stdt )
516      DO jj = 1, jpj
517         DO ji = 1, jpi
518            iseed_2d(ji,jj) = - ( 148379 + &
519               &                  mig(ji) + ( mjg(jj) - 1 ) * jpiglo )
520         END DO
521      END DO
522      CALL grid_random( iseed_2d, zetot3, 'T', 0.0_wp, stdt )
523      DO jk = 1, jpk
524         DO jj = nldj, nlej
525            DO ji = nldi, nlei
526               zta_tlin(ji,jj,jk) = zta(ji,jj,jk)
527            END DO
528         END DO
529      END DO
530      DO jk = 1, jpk
531         DO jj = nldj, nlej
532            DO ji = nldi, nlei
533               zetot3_tlin(ji,jj,jk) = zetot3(ji,jj,jk)
534            END DO
535         END DO
536      END DO
537      DO jj = nldj, nlej
538         DO ji = nldi, nlei
539            zqsr_tlin(ji,jj)  = zqsr(ji,jj)
540         END DO
541      END DO
542      ! Test for time steps nit000 and nit000 + 1 (the matrix changes)
543      DO jstp = nit000, nit000 + 1
544         !--------------------------------------------------------------------
545         ! Call the tangent routine: dy = L dx
546         !--------------------------------------------------------------------
547         
548         ta_tl(:,:,:)    = zta_tlin(:,:,:)
549         etot3_tl(:,:,:) = zetot3_tlin(:,:,:)
550         qsr_tl(:,:)     = zqsr_tlin(:,:)
551     
552         CALL tra_qsr_tan( jstp )
553         
554         zta_tlout(:,:,:) = ta_tl(:,:,:)
555         
556         !--------------------------------------------------------------------
557         ! Initialize the adjoint variables: dy^* = W dy
558         !--------------------------------------------------------------------
559     
560         DO jk = 1, jpk
561            DO jj = nldj, nlej
562               DO ji = nldi, nlei
563                  zta_adin(ji,jj,jk) = zta_tlout(ji,jj,jk) &
564                     &               * e1t(ji,jj) * e2t(ji,jj) * fse3t(ji,jj,jk) &
565                     &               * tmask(ji,jj,jk)
566               END DO
567            END DO
568         END DO
569
570         !--------------------------------------------------------------------
571         ! Compute the scalar product: ( L dx )^T W dy
572         !--------------------------------------------------------------------
573
574         zsp1 = DOT_PRODUCT( zta_tlout, zta_adin )
575
576         !--------------------------------------------------------------------
577         ! Call the adjoint routine: dx^* = L^T dy^*
578         !--------------------------------------------------------------------
579
580         etot3_ad(:,:,:)  = 0.0_wp
581         qsr_ad(:,:)      = 0.0_wp       
582         ta_ad(:,:,:)     = zta_adin(:,:,:)
583         
584         CALL tra_qsr_adj( jstp )
585
586         zta_adout(:,:,:)    = ta_ad(:,:,:)
587         zetot3_adout(:,:,:) = etot3_ad(:,:,:)
588         zqsr_adout(:,:)     = qsr_ad(:,:)
589     
590         !--------------------------------------------------------------------
591         ! Compute the scalar product: dx^T L^T W dy
592         !--------------------------------------------------------------------
593
594         zsp2_1 = DOT_PRODUCT( zta_tlin    , zta_adout   )
595         zsp2_2 = DOT_PRODUCT( zqsr_tlin   , zqsr_adout  )
596         zsp2_3 = DOT_PRODUCT( zetot3_tlin , zetot3_adout  )
597     
598         zsp2 = zsp2_1 + zsp2_2 + zsp2_3
599     
600         ! Compare the scalar products
601     
602         ! 14 char:   '12345678901234'
603         IF (jstp == nit000) THEN
604            cl_name = 'tra_qsr_adj  1'
605         ELSE
606            cl_name = 'tra_qsr_adj  2'
607         END IF
608         CALL prntst_adj( cl_name, kumadt, zsp1, zsp2 )
609      END DO
610     
611      DEALLOCATE( & 
612         & zta_tlin,     &
613         & zta_tlout,    &
614         & zta_adout,    &
615         & zta_adin,     &
616         & zta,          &
617         & zqsr_adout,   &
618         & zqsr_tlin,    &
619         & zqsr          &
620         & )
621
622      !
623   END SUBROUTINE tra_qsr_adj_tst
624   SUBROUTINE tra_qsr_init_tan
625      !!----------------------------------------------------------------------
626      !!                  ***  ROUTINE tra_qsr_init_tan  ***
627      !!
628      !! ** Purpose :   Initialization for the penetrative solar radiation
629      !!
630      !! ** Method  :   The profile of solar radiation within the ocean is set
631      !!      from two length scale of penetration (rn_si0,rn_si1) and a ratio
632      !!      (rn_abs). These parameters are read in the namtra_qsr namelist. The
633      !!      default values correspond to clear water (type I in Jerlov'
634      !!      (1968) classification.
635      !!         called by tra_qsr at the first timestep (nit000)
636      !!
637      !! ** Action  : - initialize rn_si0, rn_si1 and rn_abs
638      !!
639      !! Reference : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
640      !!----------------------------------------------------------------------
641
642      IF( ln_traqsr  ) THEN      !  Initialisation of Light Penetration  ! 
643         !                       ! ===================================== !
644         !
645         !                                ! ---------------------------------- !
646         IF( ln_qsr_rgb ) THEN            !  Red-Green-Blue light penetration  !
647            !                             ! ---------------------------------- !
648            etot3_tl(:,:,:) = 0.0_wp               
649            !
650         ENDIF
651            !                             ! ---------------------------------- !
652         IF( ln_qsr_2bd ) THEN            !    2 bands    light penetration    !
653            !                             ! ---------------------------------- !
654            etot3_tl(:,:,:) = 0.0_wp               
655            !
656         ENDIF
657         !
658      ENDIF
659      !
660   END SUBROUTINE tra_qsr_init_tan
661   SUBROUTINE tra_qsr_init_adj
662      !!----------------------------------------------------------------------
663      !!                  ***  ROUTINE tra_qsr_init_adj  ***
664      !!
665      !! ** Purpose :   Initialization for the penetrative solar radiation
666      !!
667      !! ** Method  :   The profile of solar radiation within the ocean is set
668      !!      from two length scale of penetration (rn_si0,rn_si1) and a ratio
669      !!      (rn_abs). These parameters are read in the namtra_qsr namelist. The
670      !!      default values correspond to clear water (type I in Jerlov'
671      !!      (1968) classification.
672      !!         called by tra_qsr at the first timestep (nit000)
673      !!
674      !! ** Action  : - initialize rn_si0, rn_si1 and rn_abs
675      !!
676      !! Reference : Jerlov, N. G., 1968 Optical Oceanography, Elsevier, 194pp.
677      !!----------------------------------------------------------------------
678
679      IF( ln_traqsr  ) THEN      !  Initialisation of Light Penetration  ! 
680         !                       ! ===================================== !
681         !
682         !                                ! ---------------------------------- !
683         IF( ln_qsr_rgb ) THEN            !  Red-Green-Blue light penetration  !
684            !                             ! ---------------------------------- !
685            etot3_ad(:,:,:) = 0.0_wp               
686            !
687         ENDIF
688            !                             ! ---------------------------------- !
689         IF( ln_qsr_2bd ) THEN            !    2 bands    light penetration    !
690            !                             ! ---------------------------------- !
691            etot3_ad(:,:,:) = 0.0_wp               
692            !
693         ENDIF
694         !
695      ENDIF
696      !
697  END SUBROUTINE tra_qsr_init_adj
698
699   !!======================================================================
700#endif
701END MODULE traqsr_tam
Note: See TracBrowser for help on using the repository browser.