MODULE ini_adjust_mod ! !git $Id$ !svn $Id: ini_adjust.F 1180 2023-07-13 02:42:10Z arango $ !================================================== Hernan G. Arango === ! Copyright (c) 2002-2023 The ROMS/TOMS Group Andrew M. Moore ! ! Licensed under a MIT/X style license ! ! See License_ROMS.md ! !======================================================================= ! ! ! These routines adjust and perturb state initial conditions. ! ! ! !======================================================================= ! implicit none ! PRIVATE PUBLIC :: ini_adjust PUBLIC :: load_ADtoTL PUBLIC :: load_TLtoAD ! CONTAINS ! ! SUBROUTINE ini_adjust (ng, tile, Linp, Lout) ! !======================================================================= ! ! ! This routine adds convolved to adjoint solutions to nonlinear ! ! conditions. The boundary condition and barotropic/baroclinic ! ! coupling, if any, are processed latter in routine "ini_fields" ! ! before time-stepping. ! ! ! ! On Input: ! ! ! ! ng Nested grid number. ! ! Linp Tangent linear state time index to add. ! ! Lout Nonlinear state time index to update. ! ! tile Domain partition. ! ! ! !======================================================================= ! USE mod_param USE mod_grid USE mod_ocean ! ! Imported variable declarations. ! integer, intent(in) :: ng, tile, Linp, Lout ! ! Local variable declarations. ! character (len=*), parameter :: MyFile = & & "ROMS/Utility/ini_adjust.F" ! integer :: IminS, ImaxS, JminS, JmaxS integer :: LBi, UBi, LBj, UBj, LBij, UBij ! ! Set horizontal starting and ending indices for automatic private ! storage arrays. ! IminS=BOUNDS(ng)%Istr(tile)-3 ImaxS=BOUNDS(ng)%Iend(tile)+3 JminS=BOUNDS(ng)%Jstr(tile)-3 JmaxS=BOUNDS(ng)%Jend(tile)+3 ! ! Determine array lower and upper bounds in the I- and J-directions. ! LBi=BOUNDS(ng)%LBi(tile) UBi=BOUNDS(ng)%UBi(tile) LBj=BOUNDS(ng)%LBj(tile) UBj=BOUNDS(ng)%UBj(tile) ! ! Set array lower and upper bounds for MIN(I,J) directions and ! MAX(I,J) directions. ! LBij=BOUNDS(ng)%LBij UBij=BOUNDS(ng)%UBij ! CALL wclock_on (ng, iNLM, 7, 336, MyFile) CALL ini_adjust_tile (ng, tile, & & LBi, UBi, LBj, UBj, & & IminS, ImaxS, JminS, JmaxS, & & Linp, Lout, & & GRID(ng) % rmask, & & GRID(ng) % umask, & & GRID(ng) % vmask, & & OCEAN(ng) % ad_t, & & OCEAN(ng) % ad_u, & & OCEAN(ng) % ad_v, & & OCEAN(ng) % ad_ubar, & & OCEAN(ng) % ad_vbar, & & OCEAN(ng) % ad_zeta, & & OCEAN(ng) % t, & & OCEAN(ng) % u, & & OCEAN(ng) % v, & & OCEAN(ng) % ubar, & & OCEAN(ng) % vbar, & & OCEAN(ng) % zeta) CALL wclock_off (ng, iNLM, 7, 364, MyFile) ! RETURN END SUBROUTINE ini_adjust ! !*********************************************************************** SUBROUTINE ini_adjust_tile (ng, tile, & & LBi, UBi, LBj, UBj, & & IminS, ImaxS, JminS, JmaxS, & & Linp, Lout, & & rmask, umask, vmask, & & ad_t, ad_u, ad_v, & & ad_ubar, ad_vbar, ad_zeta, & & t, u, v, & & ubar, vbar, zeta) !*********************************************************************** ! USE mod_param ! ! Imported variable declarations. ! integer, intent(in) :: ng, tile integer, intent(in) :: LBi, UBi, LBj, UBj integer, intent(in) :: IminS, ImaxS, JminS, JmaxS integer, intent(in) :: Linp, Lout ! real(r8), intent(in) :: rmask(LBi:,LBj:) real(r8), intent(in) :: umask(LBi:,LBj:) real(r8), intent(in) :: vmask(LBi:,LBj:) real(r8), intent(in) :: ad_t(LBi:,LBj:,:,:,:) real(r8), intent(in) :: ad_u(LBi:,LBj:,:,:) real(r8), intent(in) :: ad_v(LBi:,LBj:,:,:) real(r8), intent(in) :: ad_ubar(LBi:,LBj:,:) real(r8), intent(in) :: ad_vbar(LBi:,LBj:,:) real(r8), intent(in) :: ad_zeta(LBi:,LBj:,:) real(r8), intent(inout) :: t(LBi:,LBj:,:,:,:) real(r8), intent(inout) :: u(LBi:,LBj:,:,:) real(r8), intent(inout) :: v(LBi:,LBj:,:,:) real(r8), intent(inout) :: ubar(LBi:,LBj:,:) real(r8), intent(inout) :: vbar(LBi:,LBj:,:) real(r8), intent(inout) :: zeta(LBi:,LBj:,:) ! ! Local variable declarations. ! integer :: i, j integer :: itrc, k ! !----------------------------------------------------------------------- ! Set lower and upper tile bounds and staggered variables bounds for ! this horizontal domain partition. Notice that if tile=-1, it will ! set the values for the global grid. !----------------------------------------------------------------------- ! integer :: Istr, IstrB, IstrP, IstrR, IstrT, IstrM, IstrU integer :: Iend, IendB, IendP, IendR, IendT integer :: Jstr, JstrB, JstrP, JstrR, JstrT, JstrM, JstrV integer :: Jend, JendB, JendP, JendR, JendT integer :: Istrm3, Istrm2, Istrm1, IstrUm2, IstrUm1 integer :: Iendp1, Iendp2, Iendp2i, Iendp3 integer :: Jstrm3, Jstrm2, Jstrm1, JstrVm2, JstrVm1 integer :: Jendp1, Jendp2, Jendp2i, Jendp3 ! Istr =BOUNDS(ng) % Istr (tile) IstrB =BOUNDS(ng) % IstrB (tile) IstrM =BOUNDS(ng) % IstrM (tile) IstrP =BOUNDS(ng) % IstrP (tile) IstrR =BOUNDS(ng) % IstrR (tile) IstrT =BOUNDS(ng) % IstrT (tile) IstrU =BOUNDS(ng) % IstrU (tile) Iend =BOUNDS(ng) % Iend (tile) IendB =BOUNDS(ng) % IendB (tile) IendP =BOUNDS(ng) % IendP (tile) IendR =BOUNDS(ng) % IendR (tile) IendT =BOUNDS(ng) % IendT (tile) Jstr =BOUNDS(ng) % Jstr (tile) JstrB =BOUNDS(ng) % JstrB (tile) JstrM =BOUNDS(ng) % JstrM (tile) JstrP =BOUNDS(ng) % JstrP (tile) JstrR =BOUNDS(ng) % JstrR (tile) JstrT =BOUNDS(ng) % JstrT (tile) JstrV =BOUNDS(ng) % JstrV (tile) Jend =BOUNDS(ng) % Jend (tile) JendB =BOUNDS(ng) % JendB (tile) JendP =BOUNDS(ng) % JendP (tile) JendR =BOUNDS(ng) % JendR (tile) JendT =BOUNDS(ng) % JendT (tile) ! Istrm3 =BOUNDS(ng) % Istrm3 (tile) ! Istr-3 Istrm2 =BOUNDS(ng) % Istrm2 (tile) ! Istr-2 Istrm1 =BOUNDS(ng) % Istrm1 (tile) ! Istr-1 IstrUm2=BOUNDS(ng) % IstrUm2(tile) ! IstrU-2 IstrUm1=BOUNDS(ng) % IstrUm1(tile) ! IstrU-1 Iendp1 =BOUNDS(ng) % Iendp1 (tile) ! Iend+1 Iendp2 =BOUNDS(ng) % Iendp2 (tile) ! Iend+2 Iendp2i=BOUNDS(ng) % Iendp2i(tile) ! Iend+2 interior Iendp3 =BOUNDS(ng) % Iendp3 (tile) ! Iend+3 Jstrm3 =BOUNDS(ng) % Jstrm3 (tile) ! Jstr-3 Jstrm2 =BOUNDS(ng) % Jstrm2 (tile) ! Jstr-2 Jstrm1 =BOUNDS(ng) % Jstrm1 (tile) ! Jstr-1 JstrVm2=BOUNDS(ng) % JstrVm2(tile) ! JstrV-2 JstrVm1=BOUNDS(ng) % JstrVm1(tile) ! JstrV-1 Jendp1 =BOUNDS(ng) % Jendp1 (tile) ! Jend+1 Jendp2 =BOUNDS(ng) % Jendp2 (tile) ! Jend+2 Jendp2i=BOUNDS(ng) % Jendp2i(tile) ! Jend+2 interior Jendp3 =BOUNDS(ng) % Jendp3 (tile) ! Jend+3 ! !----------------------------------------------------------------------- ! Adjust initial conditions for 2D state variables by adding tangent ! linear increments from data assimilation. !----------------------------------------------------------------------- ! DO j=JstrT,JendT DO i=IstrT,IendT zeta(i,j,Lout)=zeta(i,j,Lout)+ad_zeta(i,j,Linp) zeta(i,j,Lout)=zeta(i,j,Lout)*rmask(i,j) END DO END DO ! !----------------------------------------------------------------------- ! Adjust initial conditions for 3D state variables by adding tangent ! linear increments from data assimilation. !----------------------------------------------------------------------- ! DO k=1,N(ng) DO j=JstrT,JendT DO i=IstrP,IendT u(i,j,k,Lout)=u(i,j,k,Lout)+ad_u(i,j,k,Linp) u(i,j,k,Lout)=u(i,j,k,Lout)*umask(i,j) END DO END DO DO j=JstrP,JendT DO i=IstrT,IendT v(i,j,k,Lout)=v(i,j,k,Lout)+ad_v(i,j,k,Linp) v(i,j,k,Lout)=v(i,j,k,Lout)*vmask(i,j) END DO END DO END DO DO itrc=1,NT(ng) DO k=1,N(ng) DO j=JstrT,JendT DO i=IstrT,IendT t(i,j,k,Lout,itrc)=t(i,j,k,Lout,itrc)+ & & ad_t(i,j,k,Linp,itrc) t(i,j,k,Lout,itrc)=t(i,j,k,Lout,itrc)*rmask(i,j) END DO END DO END DO END DO ! RETURN END SUBROUTINE ini_adjust_tile ! SUBROUTINE load_ADtoTL (ng, tile, Linp, Lout, add) ! !======================================================================= ! ! ! This routine loads or adds Linp adjoint state variables into Lout ! ! Lout tangent linear state variables. ! ! ! ! On Input: ! ! ! ! ng Nested grid number. ! ! tile Domain partition. ! ! Linp Tangent linear state time index to add. ! ! Lout Nonlinear state time index to update. ! ! add Logical switch to add to imported values. ! ! ! !======================================================================= ! USE mod_param USE mod_grid USE mod_ocean ! ! Imported variable declarations. ! logical, intent(in) :: add integer, intent(in) :: ng, tile, Linp, Lout ! ! Local variable declarations. ! character (len=*), parameter :: MyFile = & & "ROMS/Utility/ini_adjust.F"//", load_ADtoTL" integer :: IminS, ImaxS, JminS, JmaxS integer :: LBi, UBi, LBj, UBj, LBij, UBij ! ! Set horizontal starting and ending indices for automatic private ! storage arrays. ! IminS=BOUNDS(ng)%Istr(tile)-3 ImaxS=BOUNDS(ng)%Iend(tile)+3 JminS=BOUNDS(ng)%Jstr(tile)-3 JmaxS=BOUNDS(ng)%Jend(tile)+3 ! ! Determine array lower and upper bounds in the I- and J-directions. ! LBi=BOUNDS(ng)%LBi(tile) UBi=BOUNDS(ng)%UBi(tile) LBj=BOUNDS(ng)%LBj(tile) UBj=BOUNDS(ng)%UBj(tile) ! ! Set array lower and upper bounds for MIN(I,J) directions and ! MAX(I,J) directions. ! LBij=BOUNDS(ng)%LBij UBij=BOUNDS(ng)%UBij ! CALL wclock_on (ng, iTLM, 7, 854, MyFile) CALL load_ADtoTL_tile (ng, tile, & & LBi, UBi, LBj, UBj, LBij, UBij, & & IminS, ImaxS, JminS, JmaxS, & & Linp, Lout, add, & & GRID(ng) % rmask, & & GRID(ng) % umask, & & GRID(ng) % vmask, & & OCEAN(ng) % ad_t, & & OCEAN(ng) % ad_u, & & OCEAN(ng) % ad_v, & & OCEAN(ng) % ad_zeta, & & OCEAN(ng) % tl_t, & & OCEAN(ng) % tl_u, & & OCEAN(ng) % tl_v, & & OCEAN(ng) % tl_zeta) CALL wclock_off (ng, iTLM, 7, 926, MyFile) ! RETURN END SUBROUTINE load_ADtoTL ! !*********************************************************************** SUBROUTINE load_ADtoTL_tile (ng, tile, & & LBi, UBi, LBj, UBj, LBij, UBij, & & IminS, ImaxS, JminS, JmaxS, & & Linp, Lout, add, & & rmask, umask, vmask, & & ad_t, ad_u, ad_v, & & ad_zeta, & & tl_t, tl_u, tl_v, & & tl_zeta) !*********************************************************************** ! USE mod_param USE mod_ncparam ! USE state_addition_mod, ONLY : state_addition USE state_copy_mod, ONLY : state_copy ! ! Imported variable declarations. ! logical, intent(in) :: add integer, intent(in) :: ng, tile integer, intent(in) :: LBi, UBi, LBj, UBj, LBij, UBij integer, intent(in) :: IminS, ImaxS, JminS, JmaxS integer, intent(in) :: Linp, Lout ! real(r8), intent(in) :: rmask(LBi:,LBj:) real(r8), intent(in) :: umask(LBi:,LBj:) real(r8), intent(in) :: vmask(LBi:,LBj:) real(r8), intent(inout) :: ad_t(LBi:,LBj:,:,:,:) real(r8), intent(inout) :: ad_u(LBi:,LBj:,:,:) real(r8), intent(inout) :: ad_v(LBi:,LBj:,:,:) real(r8), intent(inout) :: ad_zeta(LBi:,LBj:,:) real(r8), intent(inout) :: tl_t(LBi:,LBj:,:,:,:) real(r8), intent(inout) :: tl_u(LBi:,LBj:,:,:) real(r8), intent(inout) :: tl_v(LBi:,LBj:,:,:) real(r8), intent(inout) :: tl_zeta(LBi:,LBj:,:) ! ! Local variable declarations. ! integer :: i, j, k integer :: ib, ir, it real(r8) :: fac1, fac2 ! !----------------------------------------------------------------------- ! Set lower and upper tile bounds and staggered variables bounds for ! this horizontal domain partition. Notice that if tile=-1, it will ! set the values for the global grid. !----------------------------------------------------------------------- ! integer :: Istr, IstrB, IstrP, IstrR, IstrT, IstrM, IstrU integer :: Iend, IendB, IendP, IendR, IendT integer :: Jstr, JstrB, JstrP, JstrR, JstrT, JstrM, JstrV integer :: Jend, JendB, JendP, JendR, JendT integer :: Istrm3, Istrm2, Istrm1, IstrUm2, IstrUm1 integer :: Iendp1, Iendp2, Iendp2i, Iendp3 integer :: Jstrm3, Jstrm2, Jstrm1, JstrVm2, JstrVm1 integer :: Jendp1, Jendp2, Jendp2i, Jendp3 ! Istr =BOUNDS(ng) % Istr (tile) IstrB =BOUNDS(ng) % IstrB (tile) IstrM =BOUNDS(ng) % IstrM (tile) IstrP =BOUNDS(ng) % IstrP (tile) IstrR =BOUNDS(ng) % IstrR (tile) IstrT =BOUNDS(ng) % IstrT (tile) IstrU =BOUNDS(ng) % IstrU (tile) Iend =BOUNDS(ng) % Iend (tile) IendB =BOUNDS(ng) % IendB (tile) IendP =BOUNDS(ng) % IendP (tile) IendR =BOUNDS(ng) % IendR (tile) IendT =BOUNDS(ng) % IendT (tile) Jstr =BOUNDS(ng) % Jstr (tile) JstrB =BOUNDS(ng) % JstrB (tile) JstrM =BOUNDS(ng) % JstrM (tile) JstrP =BOUNDS(ng) % JstrP (tile) JstrR =BOUNDS(ng) % JstrR (tile) JstrT =BOUNDS(ng) % JstrT (tile) JstrV =BOUNDS(ng) % JstrV (tile) Jend =BOUNDS(ng) % Jend (tile) JendB =BOUNDS(ng) % JendB (tile) JendP =BOUNDS(ng) % JendP (tile) JendR =BOUNDS(ng) % JendR (tile) JendT =BOUNDS(ng) % JendT (tile) ! Istrm3 =BOUNDS(ng) % Istrm3 (tile) ! Istr-3 Istrm2 =BOUNDS(ng) % Istrm2 (tile) ! Istr-2 Istrm1 =BOUNDS(ng) % Istrm1 (tile) ! Istr-1 IstrUm2=BOUNDS(ng) % IstrUm2(tile) ! IstrU-2 IstrUm1=BOUNDS(ng) % IstrUm1(tile) ! IstrU-1 Iendp1 =BOUNDS(ng) % Iendp1 (tile) ! Iend+1 Iendp2 =BOUNDS(ng) % Iendp2 (tile) ! Iend+2 Iendp2i=BOUNDS(ng) % Iendp2i(tile) ! Iend+2 interior Iendp3 =BOUNDS(ng) % Iendp3 (tile) ! Iend+3 Jstrm3 =BOUNDS(ng) % Jstrm3 (tile) ! Jstr-3 Jstrm2 =BOUNDS(ng) % Jstrm2 (tile) ! Jstr-2 Jstrm1 =BOUNDS(ng) % Jstrm1 (tile) ! Jstr-1 JstrVm2=BOUNDS(ng) % JstrVm2(tile) ! JstrV-2 JstrVm1=BOUNDS(ng) % JstrVm1(tile) ! JstrV-1 Jendp1 =BOUNDS(ng) % Jendp1 (tile) ! Jend+1 Jendp2 =BOUNDS(ng) % Jendp2 (tile) ! Jend+2 Jendp2i=BOUNDS(ng) % Jendp2i(tile) ! Jend+2 interior Jendp3 =BOUNDS(ng) % Jendp3 (tile) ! Jend+3 ! !----------------------------------------------------------------------- ! Multiply by land-sea mask - fail safe. Notice that if add=.FALSE. the ! "state_addition" routine is not called and the state arrays are not ! masked. !----------------------------------------------------------------------- ! ! Free-surface. ! DO j=JstrT,JendT DO i=IstrT,IendT ad_zeta(i,j,Linp)=ad_zeta(i,j,Linp)*rmask(i,j) END DO END DO ! ! 3D U-momentum component. ! DO k=1,N(ng) DO j=JstrT,JendT DO i=IstrP,IendT ad_u(i,j,k,Linp)=ad_u(i,j,k,Linp)*umask(i,j) END DO END DO END DO ! ! 3D V-momentum component. ! DO k=1,N(ng) DO j=JstrP,JendT DO i=IstrT,IendT ad_v(i,j,k,Linp)=ad_v(i,j,k,Linp)*vmask(i,j) END DO END DO END DO ! ! Tracers. ! DO it=1,NT(ng) DO k=1,N(ng) DO j=JstrT,JendT DO i=IstrT,IendT ad_t(i,j,k,Linp,it)=ad_t(i,j,k,Linp,it)*rmask(i,j) END DO END DO END DO END DO ! !----------------------------------------------------------------------- ! Load or add adjoint state variables into tangent linear state ! variables. !----------------------------------------------------------------------- ! ! Add adjoint state to tangent linear state. ! ! tl_var(Lout) = fac1 * tl_var(Lout) + fac2 * ad_var(Linp) ! IF (add) THEN fac1=1.0_r8 fac2=1.0_r8 CALL state_addition (ng, tile, & & LBi, UBi, LBj, UBj, LBij, UBij, & & Lout, Linp, Lout, fac1, fac2, & & rmask, umask, vmask, & & tl_t, ad_t, & & tl_u, ad_u, & & tl_v, ad_v, & & tl_zeta, ad_zeta) ! ! Otherwise, copy adjoint state into tangent linear state. ! ! tl_var(Lout) = ad_var(Linp) ! ELSE CALL state_copy (ng, tile, & & LBi, UBi, LBj, UBj, LBij, UBij, & & Linp, Lout, & & tl_t, ad_t, & & tl_u, ad_u, & & tl_v, ad_v, & & tl_zeta, ad_zeta) END IF ! RETURN END SUBROUTINE load_ADtoTL_tile ! SUBROUTINE load_TLtoAD (ng, tile, Linp, Lout, add) ! !======================================================================= ! ! ! This routine loads or adds Linp tangent linear state variables into ! ! Lout adjoint state variables. ! ! ! ! On Input: ! ! ! ! ng Nested grid number. ! ! tile Domain partition. ! ! Linp Tangent linear state time index to add. ! ! Lout Nonlinear state time index to update. ! ! add Logical switch to add to imported values. ! ! ! !======================================================================= ! USE mod_param USE mod_grid USE mod_ocean ! ! Imported variable declarations. ! logical, intent(in) :: add integer, intent(in) :: ng, tile, Linp, Lout ! ! Local variable declarations. ! character (len=*), parameter :: MyFile = & & "ROMS/Utility/ini_adjust.F"//", load_TLtoAD" integer :: IminS, ImaxS, JminS, JmaxS integer :: LBi, UBi, LBj, UBj, LBij, UBij ! ! Set horizontal starting and ending indices for automatic private ! storage arrays. ! IminS=BOUNDS(ng)%Istr(tile)-3 ImaxS=BOUNDS(ng)%Iend(tile)+3 JminS=BOUNDS(ng)%Jstr(tile)-3 JmaxS=BOUNDS(ng)%Jend(tile)+3 ! ! Determine array lower and upper bounds in the I- and J-directions. ! LBi=BOUNDS(ng)%LBi(tile) UBi=BOUNDS(ng)%UBi(tile) LBj=BOUNDS(ng)%LBj(tile) UBj=BOUNDS(ng)%UBj(tile) ! ! Set array lower and upper bounds for MIN(I,J) directions and ! MAX(I,J) directions. ! LBij=BOUNDS(ng)%LBij UBij=BOUNDS(ng)%UBij ! CALL wclock_on (ng, iADM, 7, 1670, MyFile) CALL load_TLtoAD_tile (ng, tile, & & LBi, UBi, LBj, UBj, LBij, UBij, & & IminS, ImaxS, JminS, JmaxS, & & Linp, Lout, add, & & GRID(ng) % rmask, & & GRID(ng) % umask, & & GRID(ng) % vmask, & & OCEAN(ng) % tl_t, & & OCEAN(ng) % tl_u, & & OCEAN(ng) % tl_v, & & OCEAN(ng) % tl_zeta, & & OCEAN(ng) % ad_t, & & OCEAN(ng) % ad_u, & & OCEAN(ng) % ad_v, & & OCEAN(ng) % ad_zeta) CALL wclock_off (ng, iADM, 7, 1742, MyFile) ! RETURN END SUBROUTINE load_TLtoAD ! !*********************************************************************** SUBROUTINE load_TLtoAD_tile (ng, tile, & & LBi, UBi, LBj, UBj, LBij, UBij, & & IminS, ImaxS, JminS, JmaxS, & & Linp, Lout, add, & & rmask, umask, vmask, & & tl_t, tl_u, tl_v, & & tl_zeta, & & ad_t, ad_u, ad_v, & & ad_zeta) !*********************************************************************** ! USE mod_param USE mod_ncparam ! USE state_addition_mod, ONLY : state_addition USE state_copy_mod, ONLY : state_copy ! ! Imported variable declarations. ! logical, intent(in) :: add integer, intent(in) :: ng, tile integer, intent(in) :: LBi, UBi, LBj, UBj, LBij, UBij integer, intent(in) :: IminS, ImaxS, JminS, JmaxS integer, intent(in) :: Linp, Lout ! real(r8), intent(in) :: rmask(LBi:,LBj:) real(r8), intent(in) :: umask(LBi:,LBj:) real(r8), intent(in) :: vmask(LBi:,LBj:) real(r8), intent(inout) :: tl_t(LBi:,LBj:,:,:,:) real(r8), intent(inout) :: tl_u(LBi:,LBj:,:,:) real(r8), intent(inout) :: tl_v(LBi:,LBj:,:,:) real(r8), intent(inout) :: tl_zeta(LBi:,LBj:,:) real(r8), intent(inout) :: ad_t(LBi:,LBj:,:,:,:) real(r8), intent(inout) :: ad_u(LBi:,LBj:,:,:) real(r8), intent(inout) :: ad_v(LBi:,LBj:,:,:) real(r8), intent(inout) :: ad_zeta(LBi:,LBj:,:) ! ! Local variable declarations. ! integer :: i, j, k integer :: ib, ir, it real(r8) :: fac1, fac2 ! !----------------------------------------------------------------------- ! Set lower and upper tile bounds and staggered variables bounds for ! this horizontal domain partition. Notice that if tile=-1, it will ! set the values for the global grid. !----------------------------------------------------------------------- ! integer :: Istr, IstrB, IstrP, IstrR, IstrT, IstrM, IstrU integer :: Iend, IendB, IendP, IendR, IendT integer :: Jstr, JstrB, JstrP, JstrR, JstrT, JstrM, JstrV integer :: Jend, JendB, JendP, JendR, JendT integer :: Istrm3, Istrm2, Istrm1, IstrUm2, IstrUm1 integer :: Iendp1, Iendp2, Iendp2i, Iendp3 integer :: Jstrm3, Jstrm2, Jstrm1, JstrVm2, JstrVm1 integer :: Jendp1, Jendp2, Jendp2i, Jendp3 ! Istr =BOUNDS(ng) % Istr (tile) IstrB =BOUNDS(ng) % IstrB (tile) IstrM =BOUNDS(ng) % IstrM (tile) IstrP =BOUNDS(ng) % IstrP (tile) IstrR =BOUNDS(ng) % IstrR (tile) IstrT =BOUNDS(ng) % IstrT (tile) IstrU =BOUNDS(ng) % IstrU (tile) Iend =BOUNDS(ng) % Iend (tile) IendB =BOUNDS(ng) % IendB (tile) IendP =BOUNDS(ng) % IendP (tile) IendR =BOUNDS(ng) % IendR (tile) IendT =BOUNDS(ng) % IendT (tile) Jstr =BOUNDS(ng) % Jstr (tile) JstrB =BOUNDS(ng) % JstrB (tile) JstrM =BOUNDS(ng) % JstrM (tile) JstrP =BOUNDS(ng) % JstrP (tile) JstrR =BOUNDS(ng) % JstrR (tile) JstrT =BOUNDS(ng) % JstrT (tile) JstrV =BOUNDS(ng) % JstrV (tile) Jend =BOUNDS(ng) % Jend (tile) JendB =BOUNDS(ng) % JendB (tile) JendP =BOUNDS(ng) % JendP (tile) JendR =BOUNDS(ng) % JendR (tile) JendT =BOUNDS(ng) % JendT (tile) ! Istrm3 =BOUNDS(ng) % Istrm3 (tile) ! Istr-3 Istrm2 =BOUNDS(ng) % Istrm2 (tile) ! Istr-2 Istrm1 =BOUNDS(ng) % Istrm1 (tile) ! Istr-1 IstrUm2=BOUNDS(ng) % IstrUm2(tile) ! IstrU-2 IstrUm1=BOUNDS(ng) % IstrUm1(tile) ! IstrU-1 Iendp1 =BOUNDS(ng) % Iendp1 (tile) ! Iend+1 Iendp2 =BOUNDS(ng) % Iendp2 (tile) ! Iend+2 Iendp2i=BOUNDS(ng) % Iendp2i(tile) ! Iend+2 interior Iendp3 =BOUNDS(ng) % Iendp3 (tile) ! Iend+3 Jstrm3 =BOUNDS(ng) % Jstrm3 (tile) ! Jstr-3 Jstrm2 =BOUNDS(ng) % Jstrm2 (tile) ! Jstr-2 Jstrm1 =BOUNDS(ng) % Jstrm1 (tile) ! Jstr-1 JstrVm2=BOUNDS(ng) % JstrVm2(tile) ! JstrV-2 JstrVm1=BOUNDS(ng) % JstrVm1(tile) ! JstrV-1 Jendp1 =BOUNDS(ng) % Jendp1 (tile) ! Jend+1 Jendp2 =BOUNDS(ng) % Jendp2 (tile) ! Jend+2 Jendp2i=BOUNDS(ng) % Jendp2i(tile) ! Jend+2 interior Jendp3 =BOUNDS(ng) % Jendp3 (tile) ! Jend+3 ! !----------------------------------------------------------------------- ! Multiply by land-sea mask - fail safe. Notice that if add=.FALSE. the ! "state_addition" routine is not called and the state arrays are not ! masked. !----------------------------------------------------------------------- ! ! Free-surface. ! DO j=JstrT,JendT DO i=IstrT,IendT tl_zeta(i,j,Linp)=tl_zeta(i,j,Linp)*rmask(i,j) END DO END DO ! ! 3D U-momentum component. ! DO k=1,N(ng) DO j=JstrT,JendT DO i=IstrP,IendT tl_u(i,j,k,Linp)=tl_u(i,j,k,Linp)*umask(i,j) END DO END DO END DO ! ! 3D V-momentum component. ! DO k=1,N(ng) DO j=JstrP,JendT DO i=IstrT,IendT tl_v(i,j,k,Linp)=tl_v(i,j,k,Linp)*vmask(i,j) END DO END DO END DO ! ! Tracers. ! DO it=1,NT(ng) DO k=1,N(ng) DO j=JstrT,JendT DO i=IstrT,IendT tl_t(i,j,k,Linp,it)=tl_t(i,j,k,Linp,it)*rmask(i,j) END DO END DO END DO END DO ! !----------------------------------------------------------------------- ! Load or add tangent linear state variables into adjoint state ! variables. !----------------------------------------------------------------------- ! ! Add tangent linear state to adjoint state. ! ! ad_var(Lout) = fac1 * ad_var(Lout) + fac2 * tl_var(Linp) ! IF (add) THEN fac1=1.0_r8 fac2=1.0_r8 CALL state_addition (ng, tile, & & LBi, UBi, LBj, UBj, LBij, UBij, & & Lout, Linp, Lout, fac1, fac2, & & rmask, umask, vmask, & & ad_t, tl_t, & & ad_u, tl_u, & & ad_v, tl_v, & & ad_zeta, tl_zeta) ! ! Otherwise, copy tangent linear state into adjoint state. ! ! ad_var(Lout) = tl_var(Linp) ! ELSE CALL state_copy (ng, tile, & & LBi, UBi, LBj, UBj, LBij, UBij, & & Linp, Lout, & & ad_t, tl_t, & & ad_u, tl_u, & & ad_v, tl_v, & & ad_zeta, tl_zeta) END IF ! RETURN END SUBROUTINE load_TLtoAD_tile END MODULE ini_adjust_mod