Skip to content

Commit

Permalink
MEKE diagnostic array fixes
Browse files Browse the repository at this point in the history
This patch fixes the following MEKE diagnostics:

- MEKE_Ue, MEKE_Ub, MEKE_Ut

The diagnostics were computed as inline operations inside post_data,
e.g.:

    post_data(..., sqrt(0, max(0., MEKE*bottomFac2)))

rather than computing the fields explicitly inside of array loops.

This case causing floating point exceptions in Intel compilers, possibly
likely due to evaluations inside of halos.

We resolve these diagnostics by computing the values into a scratch
array which is then passed to post_data.
  • Loading branch information
marshallward authored and gustavo-marques committed Oct 22, 2019
1 parent ebf5ee0 commit 3f041d9
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/parameterizations/lateral/MOM_MEKE.F90
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ subroutine step_forward_MEKE(MEKE, h, SN_u, SN_v, visc, dt, G, GV, US, CS, hu, h
del4MEKE, & ! Time-integrated MEKE tendency arising from the biharmonic of MEKE [L2 T-2 ~> m2 s-2].
LmixScale, & ! Eddy mixing length [L ~> m].
barotrFac2, & ! Ratio of EKE_barotropic / EKE [nondim]
bottomFac2 ! Ratio of EKE_bottom / EKE [nondim]
bottomFac2, & ! Ratio of EKE_bottom / EKE [nondim]
tmp ! Temporary variable for diagnostic computation

real, dimension(SZIB_(G),SZJ_(G)) :: &
MEKE_uflux, & ! The zonal advective and diffusive flux of MEKE with different units in different
Expand Down Expand Up @@ -593,10 +594,29 @@ subroutine step_forward_MEKE(MEKE, h, SN_u, SN_v, visc, dt, G, GV, US, CS, hu, h
endif

! Offer fields for averaging.

if (any([CS%id_Ue, CS%id_Ub, CS%id_Ut] > 0)) &
tmp(:,:) = 0.

if (CS%id_MEKE>0) call post_data(CS%id_MEKE, MEKE%MEKE, CS%diag)
if (CS%id_Ue>0) call post_data(CS%id_Ue, sqrt(max(0.,2.0*MEKE%MEKE)), CS%diag)
if (CS%id_Ub>0) call post_data(CS%id_Ub, sqrt(max(0.,2.0*MEKE%MEKE*bottomFac2)), CS%diag)
if (CS%id_Ut>0) call post_data(CS%id_Ut, sqrt(max(0.,2.0*MEKE%MEKE*barotrFac2)), CS%diag)
if (CS%id_Ue>0) then
do j=js,je ; do i=is,ie
tmp(i,j) = sqrt(max(0., 2. * MEKE%MEKE(i,j)))
enddo ; enddo
call post_data(CS%id_Ue, tmp, CS%diag)
endif
if (CS%id_Ub>0) then
do j=js,je ; do i=is,ie
tmp(i,j) = sqrt(max(0., 2. * MEKE%MEKE(i,j) * bottomFac2(i,j)))
enddo ; enddo
call post_data(CS%id_Ub, tmp, CS%diag)
endif
if (CS%id_Ut>0) then
do j=js,je ; do i=is,ie
tmp(i,j) = sqrt(max(0., 2. * MEKE%MEKE(i,j) * barotrFac2(i,j)))
enddo ; enddo
call post_data(CS%id_Ut, tmp, CS%diag)
endif
if (CS%id_Kh>0) call post_data(CS%id_Kh, MEKE%Kh, CS%diag)
if (CS%id_Ku>0) call post_data(CS%id_Ku, MEKE%Ku, CS%diag)
if (CS%id_Au>0) call post_data(CS%id_Au, MEKE%Au, CS%diag)
Expand Down

0 comments on commit 3f041d9

Please sign in to comment.