Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ocean currents variable change from C-grid to A-grid and vice versa #43

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
430 changes: 271 additions & 159 deletions ROMS/Adjoint/ad_def_his.F

Large diffs are not rendered by default.

54 changes: 32 additions & 22 deletions ROMS/Adjoint/ad_step3d_uv.F
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,28 @@ MODULE ad_step3d_uv_mod
! Qsrc !
! !
!=======================================================================
!
USE mod_param
USE mod_coupling
# ifdef DIAGNOSTICS_UV
!! USE mod_diags
# endif
USE mod_forces
USE mod_grid
USE mod_mixing
USE mod_ocean
USE mod_scalars
USE mod_sources
!
USE ad_exchange_2d_mod
USE ad_exchange_3d_mod
USE exchange_3d_mod
# ifdef DISTRIBUTE
USE mp_exchange_mod, ONLY : ad_mp_exchange2d, ad_mp_exchange3d
# endif
USE ad_u3dbc_mod, ONLY : ad_u3dbc_tile
USE ad_v3dbc_mod, ONLY : ad_v3dbc_tile
USE uv_var_change_mod, ONLY : ad_uv_C2A_grid
!
implicit none
!
Expand All @@ -32,15 +54,6 @@ MODULE ad_step3d_uv_mod
SUBROUTINE ad_step3d_uv (ng, tile)
!***********************************************************************
!
USE mod_param
USE mod_coupling
# ifdef DIAGNOSTICS_UV
!! USE mod_diags
# endif
USE mod_forces
USE mod_grid
USE mod_mixing
USE mod_ocean
USE mod_stepping
!
! Imported variable declarations.
Expand Down Expand Up @@ -177,19 +190,6 @@ SUBROUTINE ad_step3d_uv_tile (ng, tile, &
& Huon, ad_Huon, &
& Hvom, ad_Hvom)
!***********************************************************************
!
USE mod_param
USE mod_scalars
USE mod_sources
!
USE ad_exchange_2d_mod
USE ad_exchange_3d_mod
USE exchange_3d_mod
# ifdef DISTRIBUTE
USE mp_exchange_mod, ONLY : ad_mp_exchange2d, ad_mp_exchange3d
# endif
USE ad_u3dbc_mod, ONLY : ad_u3dbc_tile
USE ad_v3dbc_mod, ONLY : ad_v3dbc_tile
!
! Imported variable declarations.
!
Expand Down Expand Up @@ -413,6 +413,16 @@ SUBROUTINE ad_step3d_uv_tile (ng, tile, &
END DO
!
!-----------------------------------------------------------------------
! Compute adjoint 3D momentum (ad_ua, ad_va) at RHO-points (A-Grid)
! for output purposes and data assimilation where the observations
! and state vector is located at the cell-center.
!-----------------------------------------------------------------------
!
!> CALL tl_uv_C2A_grid (ng, tile, iTLM, nnew)
!>
CALL ad_uv_C2A_grid (ng, tile, iTLM, nnew)
!
!-----------------------------------------------------------------------
! Exchange boundary data.
!-----------------------------------------------------------------------
!
Expand Down
275 changes: 187 additions & 88 deletions ROMS/Adjoint/ad_wrt_his.F

Large diffs are not rendered by default.

35 changes: 35 additions & 0 deletions ROMS/Modules/mod_ocean.F
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ MODULE mod_ocean
! rv Right hand side of 3D V-momentum equation (m4/s2). !
! t Tracer type variables (active and passive). !
! u 3D U-momentum component (m/s). !
! ua 3D U-momentun component (m/s) at RHO-points, A-grid. !
! v 3D V-momentum component (m/s). !
! va 3D U-momentun component (m/s) at RHO-points, A-grid. !
! W S-coordinate (omega*Hz/mn) vertical velocity (m3/s). !
#ifdef BIOLOGY
! !
Expand Down Expand Up @@ -109,7 +111,9 @@ MODULE mod_ocean
real(r8), pointer :: rv(:,:,:,:)
real(r8), pointer :: t(:,:,:,:,:)
real(r8), pointer :: u(:,:,:,:)
real(r8), pointer :: ua(:,:,:)
real(r8), pointer :: v(:,:,:,:)
real(r8), pointer :: va(:,:,:)
real(r8), pointer :: W(:,:,:)
# if defined OMEGA_IMPLICIT
real(r8), pointer :: Wi(:,:,:)
Expand Down Expand Up @@ -171,7 +175,9 @@ MODULE mod_ocean
real(r8), pointer :: tl_rv(:,:,:,:)
real(r8), pointer :: tl_t(:,:,:,:,:)
real(r8), pointer :: tl_u(:,:,:,:)
real(r8), pointer :: tl_ua(:,:,:)
real(r8), pointer :: tl_v(:,:,:,:)
real(r8), pointer :: tl_va(:,:,:)
real(r8), pointer :: tl_W(:,:,:)
# if defined OMEGA_IMPLICIT
real(r8), pointer :: tl_Wi(:,:,:)
Expand Down Expand Up @@ -220,7 +226,9 @@ MODULE mod_ocean
real(r8), pointer :: ad_rv(:,:,:,:)
real(r8), pointer :: ad_t(:,:,:,:,:)
real(r8), pointer :: ad_u(:,:,:,:)
real(r8), pointer :: ad_ua(:,:,:)
real(r8), pointer :: ad_v(:,:,:,:)
real(r8), pointer :: ad_va(:,:,:)
real(r8), pointer :: ad_W(:,:,:)
real(r8), pointer :: ad_wvel(:,:,:)

Expand Down Expand Up @@ -434,9 +442,15 @@ SUBROUTINE allocate_ocean (ng, LBi, UBi, LBj, UBj)
allocate ( OCEAN(ng) % u(LBi:UBi,LBj:UBj,N(ng),2) )
Dmem(ng)=Dmem(ng)+2.0_r8*REAL(N(ng),r8)*size2d

allocate ( OCEAN(ng) % ua(LBi:UBi,LBj:UBj,N(ng)) )
Dmem(ng)=Dmem(ng)+REAL(N(ng),r8)*size2d

allocate ( OCEAN(ng) % v(LBi:UBi,LBj:UBj,N(ng),2) )
Dmem(ng)=Dmem(ng)+2.0_r8*REAL(N(ng),r8)*size2d

allocate ( OCEAN(ng) % va(LBi:UBi,LBj:UBj,N(ng)) )
Dmem(ng)=Dmem(ng)+REAL(N(ng),r8)*size2d

allocate ( OCEAN(ng) % W(LBi:UBi,LBj:UBj,0:N(ng)) )
Dmem(ng)=Dmem(ng)+REAL(N(ng)+1,r8)*size2d

Expand Down Expand Up @@ -565,9 +579,15 @@ SUBROUTINE allocate_ocean (ng, LBi, UBi, LBj, UBj)
allocate ( OCEAN(ng) % tl_u(LBi:UBi,LBj:UBj,N(ng),2) )
Dmem(ng)=Dmem(ng)+2.0_r8*REAL(N(ng),r8)*size2d

allocate ( OCEAN(ng) % tl_ua(LBi:UBi,LBj:UBj,N(ng)) )
Dmem(ng)=Dmem(ng)+REAL(N(ng),r8)*size2d

allocate ( OCEAN(ng) % tl_v(LBi:UBi,LBj:UBj,N(ng),2) )
Dmem(ng)=Dmem(ng)+2.0_r8*REAL(N(ng),r8)*size2d

allocate ( OCEAN(ng) % tl_va(LBi:UBi,LBj:UBj,N(ng)) )
Dmem(ng)=Dmem(ng)+REAL(N(ng),r8)*size2d

allocate ( OCEAN(ng) % tl_W(LBi:UBi,LBj:UBj,0:N(ng)) )
Dmem(ng)=Dmem(ng)+REAL(N(ng)+1,r8)*size2d

Expand Down Expand Up @@ -671,9 +691,15 @@ SUBROUTINE allocate_ocean (ng, LBi, UBi, LBj, UBj)
allocate ( OCEAN(ng) % ad_u(LBi:UBi,LBj:UBj,N(ng),2) )
Dmem(ng)=Dmem(ng)+2.0_r8*REAL(N(ng),r8)*size2d

allocate ( OCEAN(ng) % ad_ua(LBi:UBi,LBj:UBj,N(ng)) )
Dmem(ng)=Dmem(ng)+REAL(N(ng),r8)*size2d

allocate ( OCEAN(ng) % ad_v(LBi:UBi,LBj:UBj,N(ng),2) )
Dmem(ng)=Dmem(ng)+2.0_r8*REAL(N(ng),r8)*size2d

allocate ( OCEAN(ng) % ad_va(LBi:UBi,LBj:UBj,N(ng)) )
Dmem(ng)=Dmem(ng)+REAL(N(ng),r8)*size2d

allocate ( OCEAN(ng) % ad_W(LBi:UBi,LBj:UBj,0:N(ng)) )
Dmem(ng)=Dmem(ng)+REAL(N(ng)+1,r8)*size2d

Expand Down Expand Up @@ -1004,6 +1030,9 @@ SUBROUTINE deallocate_ocean (ng)
IF (.not.destroy(ng, OCEAN(ng)%t, MyFile, &
& __LINE__, 'OCEAN(ng)%t')) RETURN

IF (.not.destroy(ng, OCEAN(ng)%ua, MyFile, &
& __LINE__, 'OCEAN(ng)%u')) RETURN

IF (.not.destroy(ng, OCEAN(ng)%u, MyFile, &
& __LINE__, 'OCEAN(ng)%u')) RETURN

Expand Down Expand Up @@ -1610,8 +1639,10 @@ SUBROUTINE initialize_ocean (ng, tile, model)

OCEAN(ng) % u(i,j,k,1) = IniVal
OCEAN(ng) % u(i,j,k,2) = IniVal
OCEAN(ng) % ua(i,j,k) = IniVal
OCEAN(ng) % v(i,j,k,1) = IniVal
OCEAN(ng) % v(i,j,k,2) = IniVal
OCEAN(ng) % va(i,j,k) = IniVal
# if defined WEC
OCEAN(ng) % u_stokes(i,j,k) = IniVal
OCEAN(ng) % v_stokes(i,j,k) = IniVal
Expand Down Expand Up @@ -1715,8 +1746,10 @@ SUBROUTINE initialize_ocean (ng, tile, model)

OCEAN(ng) % tl_u(i,j,k,1) = IniVal
OCEAN(ng) % tl_u(i,j,k,2) = IniVal
OCEAN(ng) % tl_ua(i,j,k) = IniVal
OCEAN(ng) % tl_v(i,j,k,1) = IniVal
OCEAN(ng) % tl_v(i,j,k,2) = IniVal
OCEAN(ng) % tl_va(i,j,k) = IniVal
# if defined FORCING_SV || defined HESSIAN_FSV
OCEAN(ng) % f_u(i,j,k) = IniVal
OCEAN(ng) % f_v(i,j,k) = IniVal
Expand Down Expand Up @@ -1821,8 +1854,10 @@ SUBROUTINE initialize_ocean (ng, tile, model)

OCEAN(ng) % ad_u(i,j,k,1) = IniVal
OCEAN(ng) % ad_u(i,j,k,2) = IniVal
OCEAN(ng) % ad_ua(i,j,k) = IniVal
OCEAN(ng) % ad_v(i,j,k,1) = IniVal
OCEAN(ng) % ad_v(i,j,k,2) = IniVal
OCEAN(ng) % ad_va(i,j,k) = IniVal
OCEAN(ng) % ad_u_sol(i,j,k) = IniVal
OCEAN(ng) % ad_v_sol(i,j,k) = IniVal
# if defined FORCING_SV || defined HESSIAN_FSV
Expand Down
101 changes: 72 additions & 29 deletions ROMS/Nonlinear/set_avg.F
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,31 @@ SUBROUTINE set_avg_tile (ng, tile, &
END DO
END IF

IF (Aout(idu3dE,ng).and.Aout(idv3dN,ng)) THEN
CALL uv_rotate3d (ng, tile, .FALSE., .FALSE., &
& LBi, UBi, LBj, UBj, 1, N(ng), &
& GRID(ng) % CosAngler, &
& GRID(ng) % SinAngler, &
# ifdef MASKING
& GRID(ng)%rmask_full, &
IF (Aout(idu3dE,ng)) THEN
DO k=1,N(ng)
DO j=JstrR,JendR
DO i=IstrR,IendR
AVERAGE(ng)%avgu3dE(i,j,k)=OCEAN(ng)%ua(i,j,k)
# ifdef WET_DRY
AVERAGE(ng)%avgu3dE(i,j,k)=AVERAGE(ng)%avgu3dE(i,j,k)* &
& GRID(ng)%vmask_full(i,j)
# endif
END DO
END DO
END DO
END IF
IF (Aout(idv3dN,ng)) THEN
DO k=1,N(ng)
DO j=JstrR,JendR
DO i=IstrR,IendR
AVERAGE(ng)%avgv3dN(i,j,k)=OCEAN(ng)%va(i,j,k)
# ifdef WET_DRY
AVERAGE(ng)%avgv3dN(i,j,k)=AVERAGE(ng)%avgv3dN(i,j,k)* &
& GRID(ng)%vmask_full(i,j)
# endif
& OCEAN(ng) % u(:,:,:,Nout), &
& OCEAN(ng) % v(:,:,:,Nout), &
& AVERAGE(ng)%avgu3dE, &
& AVERAGE(ng)%avgv3dN)
END DO
END DO
END DO
END IF

IF (Aout(idOvel,ng)) THEN
Expand Down Expand Up @@ -1711,18 +1724,31 @@ SUBROUTINE set_avg_tile (ng, tile, &
END DO
END IF

IF (Aout(idu3dE,ng).and.Aout(idv3dN,ng)) THEN
CALL uv_rotate3d (ng, tile, .TRUE., .FALSE., &
& LBi, UBi, LBj, UBj, 1, N(ng), &
& GRID(ng) % CosAngler, &
& GRID(ng) % SinAngler, &
# ifdef MASKING
& GRID(ng)%rmask_full, &
IF (Aout(idu3dE,ng)) THEN
DO k=1,N(ng)
DO j=JstrR,JendR
DO i=IstrR,IendR
AVERAGE(ng)%avgu3dE(i,j,k)=AVERAGE(ng)%avgu3dE(i,j,k)+ &
# ifdef WET_DRY
& GRID(ng)%umask_full(i,j)* &
# endif
& OCEAN(ng) % u(:,:,:,Nout), &
& OCEAN(ng) % v(:,:,:,Nout), &
& AVERAGE(ng)%avgu3dE, &
& AVERAGE(ng)%avgv3dN)
& OCEAN(ng)%ua(i,j,k)
END DO
END DO
END DO
END IF
IF (Aout(idv3dN,ng)) THEN
DO k=1,N(ng)
DO j=JstrR,JendR
DO i=IstrR,IendR
AVERAGE(ng)%avgv3dN(i,j,k)=AVERAGE(ng)%avgv3dN(i,j,k)+ &
# ifdef WET_DRY
& GRID(ng)%vmask_full(i,j)* &
# endif
& OCEAN(ng)%va(i,j,k)
END DO
END DO
END DO
END IF

IF (Aout(idOvel,ng)) THEN
Expand Down Expand Up @@ -3112,30 +3138,47 @@ SUBROUTINE set_avg_tile (ng, tile, &
END IF
END IF

IF (Aout(idu3dE,ng).and.Aout(idv3dN,ng)) THEN
IF (Aout(idu3dE,ng)) THEN
DO k=1,N(ng)
DO j=Jstr,Jend
DO i=Istr,Iend
DO j=JstrR,JendR
DO i=IstrR,IendR
AVERAGE(ng)%avgu3dE(i,j,k)=rfac(i,j)* &
& AVERAGE(ng)%avgu3dE(i,j,k)
AVERAGE(ng)%avgv3dN(i,j,k)=rfac(i,j)* &
& AVERAGE(ng)%avgv3dN(i,j,k)
END DO
END DO
END DO
IF (EWperiodic(ng).or.NSperiodic(ng)) THEN
CALL exchange_r3d_tile (ng, tile, &
& LBi, UBi, LBj, UBj, 1, N(ng), &
& AVERAGE(ng)%avgu3dE)
# ifdef DISTRIBUTE
CALL mp_exchange3d (ng, tile, iNLM, 1, &
& LBi, UBi, LBj, UBj, 1, N(ng), &
& NghostPoints, &
& EWperiodic(ng), NSperiodic(ng), &
& AVERAGE(ng)%avgu3dE)
# endif
END IF
END IF

IF (Aout(idv3dN,ng)) THEN
DO k=1,N(ng)
DO j=JstrR,JendR
DO i=IstrR,IendR
AVERAGE(ng)%avgv3dN(i,j,k)=rfac(i,j)* &
& AVERAGE(ng)%avgv3dN(i,j,k)
END DO
END DO
END DO
IF (EWperiodic(ng).or.NSperiodic(ng)) THEN
CALL exchange_r3d_tile (ng, tile, &
& LBi, UBi, LBj, UBj, 1, N(ng), &
& AVERAGE(ng)%avgv3dN)
# ifdef DISTRIBUTE
CALL mp_exchange3d (ng, tile, iNLM, 2, &
CALL mp_exchange3d (ng, tile, iNLM, 1, &
& LBi, UBi, LBj, UBj, 1, N(ng), &
& NghostPoints, &
& EWperiodic(ng), NSperiodic(ng), &
& AVERAGE(ng)%avgu3dE, &
& AVERAGE(ng)%avgv3dN)
# endif
END IF
Expand Down
Loading