MODULE ad_forcing_mod ! !git $Id$ !svn $Id: ad_forcing.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 ! !======================================================================= ! ! ! This routine is used to force the adjoint state equations. ! ! ! !======================================================================= ! implicit none PRIVATE PUBLIC :: ad_forcing CONTAINS ! !*********************************************************************** SUBROUTINE ad_forcing (ng, tile, Kfrc, Nfrc) !*********************************************************************** ! USE mod_param USE mod_ocean USE mod_coupling ! ! Imported variable declarations. ! integer, intent(in) :: ng, tile, Kfrc, Nfrc ! ! Local variable declarations. ! 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 ad_forcing_tile (ng, tile, & & LBi, UBi, LBj, UBj, & & IminS, ImaxS, JminS, JmaxS, & & Kfrc, Nfrc, & & OCEAN(ng) % f_t, & & OCEAN(ng) % f_u, & & OCEAN(ng) % f_v, & & OCEAN(ng) % f_zeta, & & OCEAN(ng) % ad_t, & & OCEAN(ng) % ad_u, & & OCEAN(ng) % ad_v, & & COUPLING(ng) % ad_Zt_avg1, & & OCEAN(ng) % ad_zeta, & & OCEAN(ng) % ad_t_sol, & & OCEAN(ng) % ad_u_sol, & & OCEAN(ng) % ad_v_sol, & & OCEAN(ng) % ad_zeta_sol) RETURN END SUBROUTINE ad_forcing ! !*********************************************************************** SUBROUTINE ad_forcing_tile (ng, tile, & & LBi, UBi, LBj, UBj, & & IminS, ImaxS, JminS, JmaxS, & & Kfrc, Nfrc, & & f_t, f_u, f_v, & & f_zeta, & & ad_t, ad_u, ad_v, & & ad_Zt_avg1, & & ad_zeta, & & ad_t_sol, ad_u_sol, ad_v_sol, & & ad_zeta_sol) !*********************************************************************** ! USE mod_param USE mod_scalars ! ! 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) :: Kfrc integer, intent(in) :: Nfrc ! real(r8), intent(inout) :: f_t(LBi:,LBj:,:,:) real(r8), intent(inout) :: f_u(LBi:,LBj:,:) real(r8), intent(inout) :: f_v(LBi:,LBj:,:) real(r8), intent(inout) :: f_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_Zt_avg1(LBi:,LBj:) real(r8), intent(inout) :: ad_zeta(LBi:,LBj:,:) real(r8), intent(inout) :: ad_t_sol(LBi:,LBj:,:,:) real(r8), intent(inout) :: ad_u_sol(LBi:,LBj:,:) real(r8), intent(inout) :: ad_v_sol(LBi:,LBj:,:) real(r8), intent(inout) :: ad_zeta_sol(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 ! ! ! Adjoint linear free-surface. The two different cases in the ! case of are due to the fact that tl_ini_fields is ! also called on the first timestep. tl_forcing MUST be called ! before tl_ini_fields. ! DO j=JstrR,JendR DO i=IstrR,IendR f_zeta(i,j)=f_zeta(i,j)+ad_Zt_avg1(i,j) END DO END DO ! ! Adjoint linear 3D momentum. ! DO k=1,N(ng) DO j=JstrR,JendR DO i=Istr,IendR f_u(i,j,k)=f_u(i,j,k)+ad_u(i,j,k,Nfrc) END DO END DO DO j=Jstr,JendR DO i=IstrR,IendR f_v(i,j,k)=f_v(i,j,k)+ad_v(i,j,k,Nfrc) END DO END DO END DO ! ! Adjoint linear tracers. ! DO itrc=1,NT(ng) DO k=1,N(ng) DO j=JstrR,JendR DO i=IstrR,IendR f_t(i,j,k,itrc)=f_t(i,j,k,itrc)+ & & ad_t(i,j,k,Nfrc,itrc) END DO END DO END DO END DO RETURN END SUBROUTINE ad_forcing_tile END MODULE ad_forcing_mod