MODULE trczdf_iso_vopt !!====================================================================== !! *** MODULE trczdf_iso_vopt *** !! Ocean passive tracers: vertical component of the tracer mixing trend !!====================================================================== !! History : 6.0 ! 90-10 (B. Blanke) Original code !! 7.0 ! 91-11 (G. Madec) !! ! 92-06 (M. Imbard) correction on tracer trend loops !! ! 96-01 (G. Madec) statement function for e3 !! ! 97-05 (G. Madec) vertical component of isopycnal !! ! 97-07 (G. Madec) geopotential diffusion in s-coord !! ! 98-03 (L. Bopp MA Foujols) passive tracer generalisation !! ! 00-05 (MA Foujols) add lbc for tracer trends !! ! 00-06 (O Aumont) correct isopycnal scheme suppress !! ! avt multiple correction !! ! 00-08 (G. Madec) double diffusive mixing !! 8.5 ! 02-08 (G. Madec) F90: Free form and module !! 9.0 ! 04-03 (C. Ethe ) adapted for passive tracers !! ! 06-08 (C. Deltel) Diagnose ML trends for passive tracer !!---------------------------------------------------------------------- #if defined key_top && ( defined key_ldfslp || defined key_esopa ) !!---------------------------------------------------------------------- !! 'key_ldfslp' rotation of the lateral mixing tensor !!---------------------------------------------------------------------- !! trc_zdf_iso_vopt : Update the tracer trend with the vertical part of !! the isopycnal or geopotential s-coord. operator and !! the vertical diffusion. vector optimization, use !! k-j-i loops. !! trc_zdf_iso : !! trc_zdf_zdf : !!---------------------------------------------------------------------- USE oce_trc ! ocean dynamics and tracers variables USE trp_trc ! ocean passive tracers variables USE lbclnk ! ocean lateral boundary conditions (or mpp link) USE trctrp_lec USE prtctl_trc ! Print control for debbuging USE trdmld_trc USE trdmld_trc_oce IMPLICIT NONE PRIVATE PUBLIC trc_zdf_iso_vopt ! routine called by step.F90 REAL(wp), DIMENSION(jpk) :: rdttrc ! vertical profile of 2 x time-step REAL(wp), DIMENSION(:,:,:,:), ALLOCATABLE :: ztrcavg ! workspace arrays !! * Substitutions # include "top_substitute.h90" !!---------------------------------------------------------------------- !! TOP 1.0 , LOCEAN-IPSL (2005) !! $Header: /home/opalod/NEMOCVSROOT/NEMO/TOP_SRC/TRP/trczdf_iso_vopt.F90,v 1.11 2007/02/21 12:55:33 opalod Exp $ !! Software governed by the CeCILL licence (modipsl/doc/NEMO_CeCILL.txt) !!---------------------------------------------------------------------- CONTAINS SUBROUTINE trc_zdf_iso_vopt( kt ) !!---------------------------------------------------------------------- !! *** ROUTINE trc_zdf_iso_vopt *** !! !! ** Purpose : !! ** Method : !! ** Action : !!--------------------------------------------------------------------- INTEGER, INTENT( in ) :: kt ! ocean time-step index CHARACTER (len=22) :: charout !!--------------------------------------------------------------------- IF( kt == nittrc000 ) THEN IF(lwp)WRITE(numout,*) IF(lwp)WRITE(numout,*) 'trc_zdf_iso_vopt : vertical mixing computation' IF(lwp)WRITE(numout,*) '~~~~~~~~~~~~~~~~ is iso-neutral diffusion : implicit vertical time stepping' #if defined key_trcldf_eiv && defined key_diaeiv w_trc_eiv(:,:,:) = 0.e0 #endif ENDIF IF( l_trdtrc ) THEN ALLOCATE( ztrcavg(jpi,jpj,jpk,jptra) ) ztrcavg(:,:,:,:) = 0.e0 ! initialisation step ENDIF ! I. vertical extra-diagonal part of the rotated tensor ! ----------------------------------------------------- CALL trc_zdf_iso( kt ) IF( ln_ctl ) THEN ! print mean trends (used for debugging) WRITE(charout, FMT="('zdf - 1')") CALL prt_ctl_trc_info( charout ) CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' ) ENDIF ! II. vertical diffusion (including the vertical diagonal part of the rotated tensor) ! ---------------------- CALL trc_zdf_zdf( kt ) IF( ln_ctl ) THEN ! print mean trends (used for debugging) WRITE(charout, FMT="('zdf - 2')") CALL prt_ctl_trc_info( charout ) CALL prt_ctl_trc( tab4d=tra, mask=tmask, clinfo=ctrcnm, clinfo2='trd' ) ENDIF IF( l_trdtrc ) DEALLOCATE( ztrcavg ) END SUBROUTINE trc_zdf_iso_vopt SUBROUTINE trc_zdf_zdf( kt ) !!---------------------------------------------------------------------- !! *** ROUTINE trc_zdf_zdf *** !! !! ** Purpose : Compute the trend due to the vertical tracer diffusion !! including the vertical component of lateral mixing (only for 2nd !! order operator, for fourth order it is already computed and add !! to the general trend in traldf.F) and add it to the general trend !! of the tracer equations. !! !! ** Method : The vertical component of the lateral diffusive trends !! is provided by a 2nd order operator rotated along neural or geo- !! potential surfaces to which an eddy induced advection can be !! added. It is computed using before fields (forward in time) and !! isopycnal or geopotential slopes computed in routine ldfslp. !! !! Second part: vertical trend associated with the vertical physics !! =========== (including the vertical flux proportional to dk[t] !! associated with the lateral mixing, through the !! update of avt) !! The vertical diffusion of tracers is given by: !! difft = dz( avt dz(t) ) = 1/e3t dk+1( avt/e3w dk(t) ) !! It is computed using a backward time scheme (t=tra). !! Surface and bottom boundary conditions: no diffusive flux on !! both tracers (bottom, applied through the masked field avt). !! Add this trend to the general trend tra : !! tra = tra + dz( avt dz(t) ) !! (tra = tra + dz( avs dz(t) ) if lk_trc_zdfddm=T ) !! !! Third part: recover avt resulting from the vertical physics !! ========== alone, for further diagnostics (for example to !! compute the turbocline depth in diamld). !! avt = zavt !! (avs = zavs if lk_trc_zdfddm=T ) !! !! 'key_trdtra' defined: trend saved for futher diagnostics. !! !! macro-tasked on vertical slab (jj-loop) !! !! ** Action : - Update tra with before vertical diffusion trend !! - Save the trend in trtrd ('key_trdmld_trc') !!--------------------------------------------------------------------- USE oce, ONLY : zwd => ua, & ! ua, va used as zws => va ! workspace INTEGER, INTENT( in ) :: kt ! ocean time-step index INTEGER :: ji, jj, jk, jn ! dummy loop indices REAL(wp) :: zavi, zrhs ! temporary scalars REAL(wp), DIMENSION(jpi,jpj,jpk) :: & zwi, zwt, zavsi ! temporary workspace arrays # if defined key_trc_diatrd REAL(wp) :: ztra REAL(wp), DIMENSION(jpi,jpj,jpk) :: ztrd # endif REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: ztrtrd !!--------------------------------------------------------------------- ! I. Local constant initialization ! -------------------------------- ! ... time step = 2 rdttra ex IF( ln_trcadv_cen2 .OR. ln_trcadv_tvd ) THEN ! time step = 2 rdttra with Arakawa or TVD advection scheme IF( neuler == 0 .AND. kt == nittrc000 ) THEN rdttrc(:) = rdttra(:) * FLOAT(ndttrc) ! restarting with Euler time stepping ELSEIF( kt <= nittrc000 + ndttrc ) THEN rdttrc(:) = 2. * rdttra(:) * FLOAT(ndttrc) ! leapfrog ENDIF ELSE rdttrc(:) = rdttra(:) * FLOAT(ndttrc) ENDIF IF( l_trdtrc ) ALLOCATE( ztrtrd(jpi,jpj,jpk) ) ! ! =========== DO jn = 1, jptra ! tracer loop ! ! =========== IF( l_trdtrc ) ztrtrd(:,:,:) = tra(:,:,:,jn) ! save trends zwd ( 1, :, : ) = 0.e0 ; zwd ( jpi, :, : ) = 0.e0 zws ( 1, :, : ) = 0.e0 ; zws ( jpi, :, : ) = 0.e0 zwi ( 1, :, : ) = 0.e0 ; zwi ( jpi, :, : ) = 0.e0 zwt ( 1, :, : ) = 0.e0 ; zwt ( jpi, :, : ) = 0.e0 zwt ( :, :, 1 ) = 0.e0 ; zwt ( :, :, jpk ) = 0.e0 zavsi( 1, :, : ) = 0.e0 ; zavsi( jpi, :, : ) = 0.e0 zavsi( :, :, 1 ) = 0.e0 ; zavsi( :, :, jpk ) = 0.e0 # if defined key_trc_diatrd ! save the tra trend ztrd(:,:,:) = tra(:,:,:,jn) # endif ! II. Vertical trend associated with the vertical physics ! ======================================================= ! (including the vertical flux proportional to dk[t] associated ! with the lateral mixing, through the avt update) ! dk[ avt dk[ (t,s) ] ] diffusive trends ! II.0 Matrix construction ! ------------------------ ! update and save of avt (and avs if double diffusive mixing) DO jk = 2, jpkm1 DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 ! vector opt. zavi = fsahtw(ji,jj,jk) * ( & ! vertical mixing coef. due to lateral mixing & wslpi(ji,jj,jk) * wslpi(ji,jj,jk) & & + wslpj(ji,jj,jk) * wslpj(ji,jj,jk) ) zavsi(ji,jj,jk) = fstravs(ji,jj,jk) + zavi ! dd mixing: zavsi = total vertical mixing coef. on tracer END DO END DO END DO ! II.1 Vertical diffusion on tracer ! --------------------------------- ! Rebuild the Matrix as avt /= avs ! Diagonal, inferior, superior (including the bottom boundary condition via avs masked) DO jk = 1, jpkm1 DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 ! vector opt. zwi(ji,jj,jk) = - rdttrc(jk) * zavsi(ji,jj,jk ) / ( fse3t(ji,jj,jk) * fse3w(ji,jj,jk ) ) zws(ji,jj,jk) = - rdttrc(jk) * zavsi(ji,jj,jk+1) / ( fse3t(ji,jj,jk) * fse3w(ji,jj,jk+1) ) zwd(ji,jj,jk) = 1. - zwi(ji,jj,jk) - zws(ji,jj,jk) END DO END DO END DO ! Surface boudary conditions DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 ! vector opt. zwi(ji,jj,1) = 0.e0 zwd(ji,jj,1) = 1. - zws(ji,jj,1) END DO END DO !! Matrix inversion from the first level !!---------------------------------------------------------------------- ! solve m.x = y where m is a tri diagonal matrix ( jpk*jpk ) ! ! ( zwd1 zws1 0 0 0 )( zwx1 ) ( zwy1 ) ! ( zwi2 zwd2 zws2 0 0 )( zwx2 ) ( zwy2 ) ! ( 0 zwi3 zwd3 zws3 0 )( zwx3 )=( zwy3 ) ! ( ... )( ... ) ( ... ) ! ( 0 0 0 zwik zwdk )( zwxk ) ( zwyk ) ! ! m is decomposed in the product of an upper and lower triangular ! matrix ! The 3 diagonal terms are in 2d arrays: zwd, zws, zwi ! The second member is in 2d array zwy ! The solution is in 2d array zwx ! The 3d arry zwt is a work space array ! zwy is used and then used as a work space array : its value is modified! ! first recurrence: Tk = Dk - Ik Sk-1 / Tk-1 (increasing k) DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 zwt(ji,jj,1) = zwd(ji,jj,1) END DO END DO DO jk = 2, jpkm1 DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 zwt(ji,jj,jk) = zwd(ji,jj,jk) - zwi(ji,jj,jk) * zws(ji,jj,jk-1) /zwt(ji,jj,jk-1) END DO END DO END DO ! second recurrence: Zk = Yk - Ik / Tk-1 Zk-1 DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 tra(ji,jj,1,jn) = trb(ji,jj,1,jn) + rdttrc(1) * tra(ji,jj,1,jn) END DO END DO DO jk = 2, jpkm1 DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 zrhs = trb(ji,jj,jk,jn) + rdttrc(jk) * tra(ji,jj,jk,jn) ! zrhs=right hand side tra(ji,jj,jk,jn) = zrhs - zwi(ji,jj,jk) / zwt(ji,jj,jk-1) * tra(ji,jj,jk-1,jn) END DO END DO END DO ! third recurrence: Xk = (Zk - Sk Xk+1 ) / Tk ! Save the masked passive tracer after in tra ! (c a u t i o n: passive tracer not its trend, Leap-frog scheme done it will not be done in tranxt) DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 tra(ji,jj,jpkm1,jn) = tra(ji,jj,jpkm1,jn) / zwt(ji,jj,jpkm1) * tmask(ji,jj,jpkm1) END DO END DO DO jk = jpk-2, 1, -1 DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 tra(ji,jj,jk,jn) = ( tra(ji,jj,jk,jn) - zws(ji,jj,jk) * tra(ji,jj,jk+1,jn) ) / zwt(ji,jj,jk) * tmask(ji,jj,jk) END DO END DO END DO #if defined key_trc_diatrd ! Compute and save the vertical diffusive passive tracer trends # if defined key_trcldf_iso DO jk = 1, jpkm1 DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 ! vector opt. ztra = ( tra(ji,jj,jk,jn) - trb(ji,jj,jk,jn) ) / rdttrc(jk) IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),6) = ztra - ztrd(ji,jj,jk) + trtrd(ji,jj,jk,ikeep(jn),6) END DO END DO END DO # else DO jk = 1, jpkm1 DO jj = 2, jpjm1 DO ji = fs_2, fs_jpim1 ! vector opt. ztra = ( tra(ji,jj,jk,jn) - trb(ji,jj,jk,jn) ) / rdttrc(jk) IF (luttrd(jn)) trtrd(ji,jj,jk,ikeep(jn),6) = ztra - ztrd(ji,jj,jk) END DO END DO END DO # endif #endif ! III. Save vertical trend assoc. with the vertical physics for diagnostics ! ========================================================================= IF( l_trdtrc ) THEN ! III.1) Deduce the full vertical diff. trend (except for vertical eiv advection) ! N.B. tavg & savg contain the contribution from the extra diagonal part ! of the rotated tensor (from trc_zdf_iso). IF( ln_trcldf_iso ) THEN DO jk = 1, jpkm1 ztrtrd(:,:,jk) = ( (tra(:,:,jk,jn) - trb(:,:,jk,jn))/rdttrc(jk) ) - ztrtrd(:,:,jk) & & + ztrcavg(:,:,jk,jn) END DO ELSE DO jk = 1, jpkm1 ztrtrd(:,:,jk) = ( (tra(:,:,jk,jn) - trb(:,:,jk,jn))/rdttrc(jk) ) - ztrtrd(:,:,jk) END DO ENDIF ! III.2) save the trends for diagnostic ! N.B. However the purely vertical diffusion "K_z" (included here) will be deduced ! and removed from this trend before storage. It is stored separately, so as to ! clearly distinguish both contributions (see trd_mld) IF (luttrd(jn)) CALL trd_mod_trc( ztrtrd, jn, jptrc_trd_zdf, kt ) END IF ! ! =========== END DO ! tracer loop ! ! =========== IF( l_trdtrc ) DEALLOCATE( ztrtrd ) END SUBROUTINE trc_zdf_zdf SUBROUTINE trc_zdf_iso ( kt ) !!---------------------------------------------------------------------- !! *** ROUTINE trc_zdf_iso *** !! !! ** Purpose : !! Compute the trend due to the vertical tracer diffusion inclu- !! ding the vertical component of lateral mixing (only for second !! order operator, for fourth order it is already computed and !! add to the general trend in traldf.F) and add it to the general !! trend of the tracer equations. !! !! ** Method : !! The vertical component of the lateral diffusive trends is !! provided by a 2nd order operator rotated along neural or geopo- !! tential surfaces to which an eddy induced advection can be added !! It is computed using before fields (forward in time) and isopyc- !! nal or geopotential slopes computed in routine ldfslp. !! !! First part: vertical trends associated with the lateral mixing !! ========== (excluding the vertical flux proportional to dk[t] ) !! vertical fluxes associated with the rotated lateral mixing: !! zftw =-aht { e2t*wslpi di[ mi(mk(trb)) ] !! + e1t*wslpj dj[ mj(mk(trb)) ] } !! save avt coef. resulting from vertical physics alone in zavt: !! zavt = avt !! update and save in zavt the vertical eddy viscosity coefficient: !! avt = avt + wslpi^2+wslj^2 !! add vertical Eddy Induced advective fluxes (lk_traldf_eiv=T): !! zftw = zftw + { di[aht e2u mi(wslpi)] !! +dj[aht e1v mj(wslpj)] } mk(trb) !! take the horizontal divergence of the fluxes: !! difft = 1/(e1t*e2t*e3t) dk[ zftw ] !! Add this trend to the general trend tra : !! tra = tra + difft !! !! ** Action : !! Update tra arrays with the before vertical diffusion trend !! Save in trtrd arrays the trends if 'key_trdmld_trc' defined !!--------------------------------------------------------------------- USE oce, ONLY : zwx => ua, & ! use ua, va as zwy => va ! workspace arrays INTEGER, INTENT(in) :: kt INTEGER :: ji, jj, jk, jn ! dummy loop indices INTEGER :: iku, ikv REAL(wp) :: ztavg ! temporary scalars REAL(wp) :: zcoef0, zcoef3 ! " " REAL(wp) :: zcoef4 ! " " REAL(wp) :: zbtr, zmku, zmkv ! " " #if defined key_trcldf_eiv REAL(wp) :: zcoeg3, z_hdivn_z ! " " REAL(wp) :: zuwki, zvwki ! " " REAL(wp) :: zuwk, zvwk ! " " #endif REAL(wp) :: ztav REAL(wp), DIMENSION(jpi,jpj,jpk) :: zwz ! temporary workspace arrays REAL(wp), DIMENSION(jpi,jpj,jpk) :: zwt REAL(wp), DIMENSION(jpi,jpj,jpk) :: ztfw REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: ztrtrd !!--------------------------------------------------------------------- IF( l_trdtrc ) ALLOCATE( ztrtrd(jpi,jpj,jpk) ) ! ! =========== DO jn = 1, jptra ! tracer loop ! ! =========== ! 0. Local constant initialization ! -------------------------------- zwx (1,:,:) = 0.e0 ; zwx (jpi,:,:) = 0.e0 zwy (1,:,:) = 0.e0 ; zwy (jpi,:,:) = 0.e0 zwz (1,:,:) = 0.e0 ; zwz (jpi,:,:) = 0.e0 zwt (1,:,:) = 0.e0 ; zwt (jpi,:,:) = 0.e0 ztfw(1,:,:) = 0.e0 ; ztfw(jpi,:,:) = 0.e0 IF( l_trdtrc ) ztrtrd(:,:,:) = tra(:,:,:,jn) ! save trends ztavg = 0.e0 ! I. Vertical trends associated with lateral mixing ! ------------------------------------------------- ! (excluding the vertical flux proportional to dk[t] ) ! I.1 horizontal tracer gradient ! ------------------------------ DO jk = 1, jpkm1 DO jj = 1, jpjm1 DO ji = 1, fs_jpim1 ! vector opt. ! i-gradient of passive tracer at ji zwx (ji,jj,jk) = ( trb(ji+1,jj,jk,jn)-trb(ji,jj,jk,jn) ) * umask(ji,jj,jk) ! j-gradient of passive tracer at jj zwy (ji,jj,jk) = ( trb(ji,jj+1,jk,jn)-trb(ji,jj,jk,jn) ) * vmask(ji,jj,jk) END DO END DO END DO IF( ln_zps ) THEN ! partial steps correction at the bottom ocean level DO jj = 1, jpjm1 DO ji = 1, fs_jpim1 ! vector opt. ! last ocean level iku = MIN( mbathy(ji,jj), mbathy(ji+1,jj ) ) - 1 ikv = MIN( mbathy(ji,jj), mbathy(ji ,jj+1) ) - 1 ! i-gradient of passive tracer zwx (ji,jj,iku) = gtru(ji,jj,jn) ! j-gradient of passive tracer zwy (ji,jj,ikv) = gtrv(ji,jj,jn) END DO END DO ENDIF ! I.2 Vertical fluxes ! ------------------- ! Surface and bottom vertical fluxes set to zero ztfw(:,:, 1 ) = 0.e0 ztfw(:,:,jpk) = 0.e0 ! interior (2=