Skip to content

Commit 76f0668

Browse files
Hallberg-NOAAmarshallward
authored andcommitted
(*)Avoid using RHO_0 in non-Boussinesq averaging
Use GV%H_to_MKS instead of GV%H_to_m when undoing the dimensional rescaling of thicknesses when taking weighted averages in horizontally_average_diag_field, global_layer_mean and global_volume_mean. In Boussinesq mode, these are identical, but in non-Boussinesq mode using GV%H_to_m introduced a multiplication and then division by the Boussinesq reference density, whereas GV%H_to_MKS avoids this by rescaling to a volume or mass-based coordinate depending on the mode. Several comments were also updated to reflect these conditional changes in the units of some internal variables. All expressions are mathematically equivalent, and this does not impact any solutions, but there can be changes in the last bits in some non-Boussinesq averaged diagnostics.
1 parent 541c2f4 commit 76f0668

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/diagnostics/MOM_spatial_means.F90

+11-9
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,13 @@ function global_layer_mean(var, h, G, GV, scale, tmp_scale)
211211
! Local variables
212212
! In the following comments, [A] is used to indicate the arbitrary, possibly rescaled units of the
213213
! input array while [a] indicates the unscaled (e.g., mks) units that can be used with the reproducing sums
214-
real, dimension(G%isc:G%iec,G%jsc:G%jec,SZK_(GV)) :: tmpForSumming ! An unscaled cell integral [a m3]
215-
real, dimension(G%isc:G%iec,G%jsc:G%jec,SZK_(GV)) :: weight ! The volume of each cell, used as a weight [m3]
214+
real, dimension(G%isc:G%iec,G%jsc:G%jec,SZK_(GV)) :: tmpForSumming ! An unscaled cell integral [a m3] or [a kg]
215+
real, dimension(G%isc:G%iec,G%jsc:G%jec,SZK_(GV)) :: weight ! The volume or mass of each cell, depending on
216+
! whether the model is Boussinesq, used as a weight [m3] or [kg]
216217
type(EFP_type), dimension(2*SZK_(GV)) :: laysums
217-
real, dimension(SZK_(GV)) :: global_temp_scalar ! The global integral of the tracer in each layer [a m3]
218-
real, dimension(SZK_(GV)) :: global_weight_scalar ! The global integral of the volume of each layer [m3]
218+
real, dimension(SZK_(GV)) :: global_temp_scalar ! The global integral of the tracer in each layer [a m3] or [a kg]
219+
real, dimension(SZK_(GV)) :: global_weight_scalar ! The global integral of the volume or mass of each
220+
! layer [m3] or [kg]
219221
real :: temp_scale ! A temporary scaling factor [a A-1 ~> 1] or [1]
220222
real :: scalefac ! A scaling factor for the variable [a A-1 ~> 1]
221223
integer :: i, j, k, is, ie, js, je, nz
@@ -226,7 +228,7 @@ function global_layer_mean(var, h, G, GV, scale, tmp_scale)
226228
tmpForSumming(:,:,:) = 0. ; weight(:,:,:) = 0.
227229

228230
do k=1,nz ; do j=js,je ; do i=is,ie
229-
weight(i,j,k) = (GV%H_to_m * h(i,j,k)) * (G%US%L_to_m**2*G%areaT(i,j) * G%mask2dT(i,j))
231+
weight(i,j,k) = (GV%H_to_MKS * h(i,j,k)) * (G%US%L_to_m**2*G%areaT(i,j) * G%mask2dT(i,j))
230232
tmpForSumming(i,j,k) = scalefac * var(i,j,k) * weight(i,j,k)
231233
enddo ; enddo ; enddo
232234

@@ -262,9 +264,9 @@ function global_volume_mean(var, h, G, GV, scale, tmp_scale)
262264
! input array while [a] indicates the unscaled (e.g., mks) units that can be used with the reproducing sums
263265
real :: temp_scale ! A temporary scaling factor [a A-1 ~> 1] or [1]
264266
real :: scalefac ! A scaling factor for the variable [a A-1 ~> 1]
265-
real :: weight_here ! The volume of a grid cell [m3]
266-
real, dimension(SZI_(G),SZJ_(G)) :: tmpForSumming ! The volume integral of the variable in a column [a m3]
267-
real, dimension(SZI_(G),SZJ_(G)) :: sum_weight ! The volume of each column of water [m3]
267+
real :: weight_here ! The volume or mass of a grid cell [m3] or [kg]
268+
real, dimension(SZI_(G),SZJ_(G)) :: tmpForSumming ! The volume integral of the variable in a column [a m3] or [a kg]
269+
real, dimension(SZI_(G),SZJ_(G)) :: sum_weight ! The volume or mass of each column of water [m3] or [kg]
268270
integer :: i, j, k, is, ie, js, je, nz
269271
is = G%isc ; ie = G%iec ; js = G%jsc ; je = G%jec ; nz = GV%ke
270272

@@ -273,7 +275,7 @@ function global_volume_mean(var, h, G, GV, scale, tmp_scale)
273275
tmpForSumming(:,:) = 0. ; sum_weight(:,:) = 0.
274276

275277
do k=1,nz ; do j=js,je ; do i=is,ie
276-
weight_here = (GV%H_to_m * h(i,j,k)) * (G%US%L_to_m**2*G%areaT(i,j) * G%mask2dT(i,j))
278+
weight_here = (GV%H_to_MKS * h(i,j,k)) * (G%US%L_to_m**2*G%areaT(i,j) * G%mask2dT(i,j))
277279
tmpForSumming(i,j) = tmpForSumming(i,j) + scalefac * var(i,j,k) * weight_here
278280
sum_weight(i,j) = sum_weight(i,j) + weight_here
279281
enddo ; enddo ; enddo

src/framework/MOM_diag_remap.F90

+12-5
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,15 @@ subroutine horizontally_average_diag_field(G, GV, h, staggered_in_x, staggered_i
658658
logical, dimension(:), intent(inout) :: averaged_mask !< Mask for horizontally averaged field [nondim]
659659

660660
! Local variables
661-
real, dimension(G%isc:G%iec, G%jsc:G%jec, size(field,3)) :: volume, stuff
662-
real, dimension(size(field, 3)) :: vol_sum, stuff_sum ! nz+1 is needed for interface averages
661+
real :: volume(G%isc:G%iec, G%jsc:G%jec, size(field,3)) ! The area [m2], volume [m3] or mass [kg] of each cell.
662+
real :: stuff(G%isc:G%iec, G%jsc:G%jec, size(field,3)) ! The area, volume or mass-weighted integral of the
663+
! field being averaged in each cell, in [m2 A], [m3 A] or [kg A],
664+
! depending on the weighting for the averages and whether the
665+
! model makes the Boussinesq approximation.
666+
real, dimension(size(field, 3)) :: vol_sum ! The global sum of the areas [m2], volumes [m3] or mass [kg]
667+
! in the cells that used in the weighted averages.
668+
real, dimension(size(field, 3)) :: stuff_sum ! The global sum of the weighted field in all cells, in
669+
! [A m2], [A m3] or [A kg]
663670
type(EFP_type), dimension(2*size(field,3)) :: sums_EFP ! Sums of volume or stuff by layer
664671
real :: height ! An average thickness attributed to an velocity point [H ~> m or kg m-2]
665672
integer :: i, j, k, nz
@@ -688,7 +695,7 @@ subroutine horizontally_average_diag_field(G, GV, h, staggered_in_x, staggered_i
688695
I1 = i - G%isdB + 1
689696
height = 0.5 * (h(i,j,k) + h(i+1,j,k))
690697
volume(I,j,k) = (G%US%L_to_m**2 * G%areaCu(I,j)) &
691-
* (GV%H_to_m * height) * G%mask2dCu(I,j)
698+
* (GV%H_to_MKS * height) * G%mask2dCu(I,j)
692699
stuff(I,j,k) = volume(I,j,k) * field(I1,j,k)
693700
enddo ; enddo
694701
endif
@@ -717,7 +724,7 @@ subroutine horizontally_average_diag_field(G, GV, h, staggered_in_x, staggered_i
717724
J1 = J - G%jsdB + 1
718725
height = 0.5 * (h(i,j,k) + h(i,j+1,k))
719726
volume(i,J,k) = (G%US%L_to_m**2 * G%areaCv(i,J)) &
720-
* (GV%H_to_m * height) * G%mask2dCv(i,J)
727+
* (GV%H_to_MKS * height) * G%mask2dCv(i,J)
721728
stuff(i,J,k) = volume(i,J,k) * field(i,J1,k)
722729
enddo ; enddo
723730
endif
@@ -748,7 +755,7 @@ subroutine horizontally_average_diag_field(G, GV, h, staggered_in_x, staggered_i
748755
else ! Intensive
749756
do j=G%jsc, G%jec ; do i=G%isc, G%iec
750757
volume(i,j,k) = (G%US%L_to_m**2 * G%areaT(i,j)) &
751-
* (GV%H_to_m * h(i,j,k)) * G%mask2dT(i,j)
758+
* (GV%H_to_MKS * h(i,j,k)) * G%mask2dT(i,j)
752759
stuff(i,j,k) = volume(i,j,k) * field(i,j,k)
753760
enddo ; enddo
754761
endif

0 commit comments

Comments
 (0)