Skip to content

Commit 8c8e218

Browse files
committed
Refactor horizontally_average_field
Refactored the horizontally_average_field() routine in MOM_diag_remap to work in rescaled units by making use of the unscale arguments to the reproducing_sum() routines. A total of 9 rescaling variables were moved into unscale arguments. All answers and diagnostics are bitwise identical, and no interfaces are changed.
1 parent a4d13e8 commit 8c8e218

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/framework/MOM_diag_remap.F90

+15-16
Original file line numberDiff line numberDiff line change
@@ -820,9 +820,11 @@ subroutine horizontally_average_field(G, GV, isdf, jsdf, h, staggered_in_x, stag
820820
logical, dimension(:), intent(out) :: averaged_mask !< Mask for horizontally averaged field [nondim]
821821

822822
! Local variables
823-
real :: volume(G%isc:G%iec, G%jsc:G%jec, size(field,3)) ! The area [m2], volume [m3] or mass [kg] of each cell.
823+
real :: volume(G%isc:G%iec, G%jsc:G%jec, size(field,3)) ! The area [L2 ~> m2], volume [L2 m ~> m3]
824+
! or mass [L2 kg m-2 ~> kg] of each cell.
824825
real :: stuff(G%isc:G%iec, G%jsc:G%jec, size(field,3)) ! The area, volume or mass-weighted integral of the
825-
! field being averaged in each cell, in [m2 A], [m3 A] or [kg A],
826+
! field being averaged in each cell, in [L2 a ~> m2 A],
827+
! [L2 m a ~> m3 A] or [L2 kg m-2 A ~> kg A],
826828
! depending on the weighting for the averages and whether the
827829
! model makes the Boussinesq approximation.
828830
real, dimension(size(field, 3)) :: vol_sum ! The global sum of the areas [m2], volumes [m3] or mass [kg]
@@ -847,22 +849,21 @@ subroutine horizontally_average_field(G, GV, isdf, jsdf, h, staggered_in_x, stag
847849
stuff_sum(k) = 0.
848850
if (is_extensive) then
849851
do j=G%jsc, G%jec ; do I=G%isc, G%iec
850-
volume(I,j,k) = (G%US%L_to_m**2 * G%areaCu(I,j)) * G%mask2dCu(I,j)
852+
volume(I,j,k) = G%areaCu(I,j) * G%mask2dCu(I,j)
851853
stuff(I,j,k) = volume(I,j,k) * field(I,j,k)
852854
enddo ; enddo
853855
else ! Intensive
854856
do j=G%jsc, G%jec ; do I=G%isc, G%iec
855857
height = 0.5 * (h(i,j,k) + h(i+1,j,k))
856-
volume(I,j,k) = (G%US%L_to_m**2 * G%areaCu(I,j)) &
857-
* (GV%H_to_MKS * height) * G%mask2dCu(I,j)
858+
volume(I,j,k) = G%areaCu(I,j) * (GV%H_to_MKS * height) * G%mask2dCu(I,j)
858859
stuff(I,j,k) = volume(I,j,k) * field(I,j,k)
859860
enddo ; enddo
860861
endif
861862
enddo
862863
else ! Interface
863864
do k=1,nz
864865
do j=G%jsc, G%jec ; do I=G%isc, G%iec
865-
volume(I,j,k) = (G%US%L_to_m**2 * G%areaCu(I,j)) * G%mask2dCu(I,j)
866+
volume(I,j,k) = G%areaCu(I,j) * G%mask2dCu(I,j)
866867
stuff(I,j,k) = volume(I,j,k) * field(I,j,k)
867868
enddo ; enddo
868869
enddo
@@ -873,22 +874,21 @@ subroutine horizontally_average_field(G, GV, isdf, jsdf, h, staggered_in_x, stag
873874
do k=1,nz
874875
if (is_extensive) then
875876
do J=G%jsc, G%jec ; do i=G%isc, G%iec
876-
volume(i,J,k) = (G%US%L_to_m**2 * G%areaCv(i,J)) * G%mask2dCv(i,J)
877+
volume(i,J,k) = G%areaCv(i,J) * G%mask2dCv(i,J)
877878
stuff(i,J,k) = volume(i,J,k) * field(i,J,k)
878879
enddo ; enddo
879880
else ! Intensive
880881
do J=G%jsc, G%jec ; do i=G%isc, G%iec
881882
height = 0.5 * (h(i,j,k) + h(i,j+1,k))
882-
volume(i,J,k) = (G%US%L_to_m**2 * G%areaCv(i,J)) &
883-
* (GV%H_to_MKS * height) * G%mask2dCv(i,J)
883+
volume(i,J,k) = G%areaCv(i,J) * (GV%H_to_MKS * height) * G%mask2dCv(i,J)
884884
stuff(i,J,k) = volume(i,J,k) * field(i,J,k)
885885
enddo ; enddo
886886
endif
887887
enddo
888888
else ! Interface
889889
do k=1,nz
890890
do J=G%jsc, G%jec ; do i=G%isc, G%iec
891-
volume(i,J,k) = (G%US%L_to_m**2 * G%areaCv(i,J)) * G%mask2dCv(i,J)
891+
volume(i,J,k) = G%areaCv(i,J) * G%mask2dCv(i,J)
892892
stuff(i,J,k) = volume(i,J,k) * field(i,J,k)
893893
enddo ; enddo
894894
enddo
@@ -900,7 +900,7 @@ subroutine horizontally_average_field(G, GV, isdf, jsdf, h, staggered_in_x, stag
900900
if (is_extensive) then
901901
do j=G%jsc, G%jec ; do i=G%isc, G%iec
902902
if (h(i,j,k) > 0.) then
903-
volume(i,j,k) = (G%US%L_to_m**2 * G%areaT(i,j)) * G%mask2dT(i,j)
903+
volume(i,j,k) = G%areaT(i,j) * G%mask2dT(i,j)
904904
stuff(i,j,k) = volume(i,j,k) * field(i,j,k)
905905
else
906906
volume(i,j,k) = 0.
@@ -909,16 +909,15 @@ subroutine horizontally_average_field(G, GV, isdf, jsdf, h, staggered_in_x, stag
909909
enddo ; enddo
910910
else ! Intensive
911911
do j=G%jsc, G%jec ; do i=G%isc, G%iec
912-
volume(i,j,k) = (G%US%L_to_m**2 * G%areaT(i,j)) &
913-
* (GV%H_to_MKS * h(i,j,k)) * G%mask2dT(i,j)
912+
volume(i,j,k) = G%areaT(i,j) * (GV%H_to_MKS * h(i,j,k)) * G%mask2dT(i,j)
914913
stuff(i,j,k) = volume(i,j,k) * field(i,j,k)
915914
enddo ; enddo
916915
endif
917916
enddo
918917
else ! Interface
919918
do k=1,nz
920919
do j=G%jsc, G%jec ; do i=G%isc, G%iec
921-
volume(i,j,k) = (G%US%L_to_m**2 * G%areaT(i,j)) * G%mask2dT(i,j)
920+
volume(i,j,k) = G%areaT(i,j) * G%mask2dT(i,j)
922921
stuff(i,j,k) = volume(i,j,k) * field(i,j,k)
923922
enddo ; enddo
924923
enddo
@@ -930,8 +929,8 @@ subroutine horizontally_average_field(G, GV, isdf, jsdf, h, staggered_in_x, stag
930929
! Packing the sums into a single array with a single call to sum across PEs saves reduces
931930
! the costs of communication.
932931
do k=1,nz
933-
sums_EFP(2*k-1) = reproducing_sum_EFP(volume(:,:,k), only_on_PE=.true.)
934-
sums_EFP(2*k) = reproducing_sum_EFP(stuff(:,:,k), only_on_PE=.true.)
932+
sums_EFP(2*k-1) = reproducing_sum_EFP(volume(:,:,k), only_on_PE=.true., unscale=G%US%L_to_m**2)
933+
sums_EFP(2*k) = reproducing_sum_EFP(stuff(:,:,k), only_on_PE=.true., unscale=G%US%L_to_m**2)
935934
enddo
936935
call EFP_sum_across_PEs(sums_EFP, 2*nz)
937936
do k=1,nz

0 commit comments

Comments
 (0)