Skip to content

Commit

Permalink
CorAd: dvdx, dudy
Browse files Browse the repository at this point in the history
First porting of strain functions.  So far so good.
  • Loading branch information
marshallward committed Jan 28, 2025
1 parent e76abe0 commit ce6c8cd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/MOM.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2644,6 +2644,7 @@ subroutine initialize_MOM(Time, Time_init, param_file, dirs, CS, &
call copy_dyngrid_to_MOM_grid(dG_in, G_in, US)

!$omp target enter data map(to: G)
!$omp target enter data map(to: G%dxCu, G%dyCv)
!$omp target enter data map(to: G%IdxCu, G%IdyCv)
!$omp target enter data map(to: G%mask2dT)
!$omp target enter data map(to: G%areaT)
Expand Down
24 changes: 24 additions & 0 deletions src/core/MOM_CoriolisAdv.F90
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,25 @@ subroutine CorAdCalc(u, v, h, uh, vh, CAu, CAv, OBC, AD, G, GV, US, CS, pbv, Wav
!!!!$OMP parallel do default(private) shared(u,v,h,uh,vh,CAu,CAv,G,GV,CS,AD,Area_h,Area_q,&
!!!!$OMP RV,PV,is,ie,js,je,Isq,Ieq,Jsq,Jeq,nz,vol_neglect,h_tiny,OBC,eps_vel, &
!!!!$OMP pbv, Stokes_VF)

!$omp target enter data map(alloc: dvdx, dudy)
!$omp target enter data map(alloc: dvSdx, duSdy) if (Stokes_VF)
! TODO: Don't allocate if diagnostics are disabled

! TODO: Do this outside of the function
!$omp target enter data map(to: u, v)

do k=1,nz

! Here the second order accurate layer potential vorticities, q,
! are calculated. hq is second order accurate in space. Relative
! vorticity is second order accurate everywhere with free slip b.c.s,
! but only first order accurate at boundaries with no slip b.c.s.
! First calculate the contributions to the circulation around the q-point.
!$omp target
if (Stokes_VF) then
if (CS%id_CAuS>0 .or. CS%id_CAvS>0) then
!$omp parallel loop collapse(2)
do J=Jsq-1,Jeq+1 ; do I=Isq-1,Ieq+1
dvSdx(I,J) = (-Waves%us_y(i+1,J,k)*G%dyCv(i+1,J)) - &
(-Waves%us_y(i,J,k)*G%dyCv(i,J))
Expand All @@ -315,24 +325,32 @@ subroutine CorAdCalc(u, v, h, uh, vh, CAu, CAv, OBC, AD, G, GV, US, CS, pbv, Wav
enddo; enddo
endif
if (.not. Waves%Passive_Stokes_VF) then
!$omp parallel loop collapse(2)
do J=Jsq-1,Jeq+1 ; do I=Isq-1,Ieq+1
dvdx(I,J) = ((v(i+1,J,k)-Waves%us_y(i+1,J,k))*G%dyCv(i+1,J)) - &
((v(i,J,k)-Waves%us_y(i,J,k))*G%dyCv(i,J))
dudy(I,J) = ((u(I,j+1,k)-Waves%us_x(I,j+1,k))*G%dxCu(I,j+1)) - &
((u(I,j,k)-Waves%us_x(I,j,k))*G%dxCu(I,j))
enddo; enddo
else
!$omp parallel loop collapse(2)
do J=Jsq-1,Jeq+1 ; do I=Isq-1,Ieq+1
dvdx(I,J) = (v(i+1,J,k)*G%dyCv(i+1,J)) - (v(i,J,k)*G%dyCv(i,J))
dudy(I,J) = (u(I,j+1,k)*G%dxCu(I,j+1)) - (u(I,j,k)*G%dxCu(I,j))
enddo; enddo
endif
else
!$omp parallel loop collapse(2)
do J=Jsq-1,Jeq+1 ; do I=Isq-1,Ieq+1
dvdx(I,J) = (v(i+1,J,k)*G%dyCv(i+1,J)) - (v(i,J,k)*G%dyCv(i,J))
dudy(I,J) = (u(I,j+1,k)*G%dxCu(I,j+1)) - (u(I,j,k)*G%dxCu(I,j))
enddo; enddo
endif
!$omp end target

!$omp target update from(dvdx, dudy)
!$omp target update from(dvSdx, duSdy) if (Stokes_VF)

do J=Jsq-1,Jeq+1 ; do i=Isq-1,Ieq+2
hArea_v(i,J) = 0.5*((Area_h(i,j) * h(i,j,k)) + (Area_h(i,j+1) * h(i,j+1,k)))
enddo ; enddo
Expand Down Expand Up @@ -940,6 +958,12 @@ subroutine CorAdCalc(u, v, h, uh, vh, CAu, CAv, OBC, AD, G, GV, US, CS, pbv, Wav

enddo ! k-loop.

!$omp target exit data map(delete: dvdx, dudy)
!$omp target exit data map(delete: dvSdx, duSdy) if (Stokes_VF)

! TODO: Move outside function
!$omp target exit data map(delete: u, v)

! Here the various Coriolis-related derived quantities are offered for averaging.
if (query_averaging_enabled(CS%diag)) then
if (CS%id_rv > 0) call post_data(CS%id_rv, RV, CS%diag)
Expand Down

0 comments on commit ce6c8cd

Please sign in to comment.