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

+Add and use optional unscale args to reproducing_sum #767

Merged
Merged
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
9 changes: 5 additions & 4 deletions src/diagnostics/MOM_diagnostics.F90
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ subroutine calculate_diagnostic_fields(u, v, h, uh, vh, tv, ADp, CDp, p_surf, &
if (CS%id_masso > 0) then
mass_cell(:,:) = 0.0
do k=1,nz ; do j=js,je ; do i=is,ie
mass_cell(i,j) = mass_cell(i,j) + (GV%H_to_kg_m2*h(i,j,k)) * US%L_to_m**2*G%areaT(i,j)
mass_cell(i,j) = mass_cell(i,j) + (GV%H_to_RZ*h(i,j,k)) * G%areaT(i,j)
enddo ; enddo ; enddo
masso = reproducing_sum(mass_cell)
masso = reproducing_sum(mass_cell, unscale=US%RZL2_to_kg)
call post_data(CS%id_masso, masso, CS%diag)
endif

Expand Down Expand Up @@ -1644,8 +1644,9 @@ subroutine MOM_diagnostics_init(MIS, ADp, CDp, Time, G, GV, US, param_file, diag
Time, 'Mass per unit area of liquid ocean grid cell', 'kg m-2', conversion=GV%H_to_kg_m2, &
standard_name='sea_water_mass_per_unit_area', v_extensive=.true.)

CS%id_masso = register_scalar_field('ocean_model', 'masso', Time, &
diag, 'Mass of liquid ocean', 'kg', standard_name='sea_water_mass')
CS%id_masso = register_scalar_field('ocean_model', 'masso', Time, diag, &
'Mass of liquid ocean', units='kg', conversion=US%RZL2_to_kg, &
standard_name='sea_water_mass')

CS%id_thkcello = register_diag_field('ocean_model', 'thkcello', diag%axesTL, Time, &
long_name='Cell Thickness', standard_name='cell_thickness', &
Expand Down
144 changes: 68 additions & 76 deletions src/diagnostics/MOM_sum_output.F90

Large diffs are not rendered by default.

169 changes: 110 additions & 59 deletions src/framework/MOM_coms.F90

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/framework/MOM_unit_scaling.F90
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ module MOM_unit_scaling
real :: QRZ_T_to_W_m2 !< Convert heat fluxes from Q R Z T-1 to W m-2 [W T Q-1 R-1 Z-1 m-2 ~> 1]
! Not used enough: real :: kg_m2_to_RZ !< Convert mass loads from kg m-2 to R Z [R Z m2 kg-1 ~> 1]
real :: RZ_to_kg_m2 !< Convert mass loads from R Z to kg m-2 [kg R-1 Z-1 m-2 ~> 1]
real :: RZL2_to_kg !< Convert masses from R Z L2 to kg [kg R-1 Z-1 L-2 ~> 1]
real :: kg_m2s_to_RZ_T !< Convert mass fluxes from kg m-2 s-1 to R Z T-1 [R Z m2 s T-1 kg-1 ~> 1]
real :: RZ_T_to_kg_m2s !< Convert mass fluxes from R Z T-1 to kg m-2 s-1 [T kg R-1 Z-1 m-2 s-1 ~> 1]
real :: RZ3_T3_to_W_m2 !< Convert turbulent kinetic energy fluxes from R Z3 T-3 to W m-2 [W T3 R-1 Z-3 m-2 ~> 1]
Expand Down Expand Up @@ -224,6 +225,8 @@ subroutine set_unit_scaling_combos(US)
! Wind stresses:
US%RLZ_T2_to_Pa = US%R_to_kg_m3 * US%L_T_to_m_s**2 * US%Z_to_L
US%Pa_to_RLZ_T2 = US%kg_m3_to_R * US%m_s_to_L_T**2 * US%L_to_Z
! Masses:
US%RZL2_to_kg = US%R_to_kg_m3 * US%Z_to_m * US%L_to_m**2

end subroutine set_unit_scaling_combos

Expand Down
9 changes: 3 additions & 6 deletions src/initialization/MOM_shared_initialization.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1314,17 +1314,14 @@ subroutine compute_global_grid_integrals(G, US)

! Local variables
real, dimension(G%isc:G%iec, G%jsc:G%jec) :: tmpForSumming ! Masked and unscaled cell areas [m2]
real :: area_scale ! A scaling factor for area into MKS units [m2 L-2 ~> 1]
integer :: i,j

area_scale = US%L_to_m**2
integer :: i, j

tmpForSumming(:,:) = 0.
G%areaT_global = 0.0 ; G%IareaT_global = 0.0
do j=G%jsc,G%jec ; do i=G%isc,G%iec
tmpForSumming(i,j) = area_scale*G%areaT(i,j) * G%mask2dT(i,j)
tmpForSumming(i,j) = G%areaT(i,j) * G%mask2dT(i,j)
enddo ; enddo
G%areaT_global = reproducing_sum(tmpForSumming)
G%areaT_global = US%L_to_m**2 * reproducing_sum(tmpForSumming, unscale=US%L_to_m**2)

if (G%areaT_global == 0.0) &
call MOM_error(FATAL, "compute_global_grid_integrals: zero ocean area (check topography?)")
Expand Down
24 changes: 10 additions & 14 deletions src/tracer/MOM_offline_main.F90
Original file line number Diff line number Diff line change
Expand Up @@ -625,27 +625,24 @@ real function remaining_transport_sum(G, GV, US, uhtr, vhtr, h_new)

! Local variables
real, dimension(SZI_(G),SZJ_(G)) :: trans_rem_col !< The vertical sum of the absolute value of
!! transports through the faces of a column, in MKS units [kg].
!! transports through the faces of a column [R Z L2 ~> kg].
real :: trans_cell !< The sum of the absolute value of the remaining transports through the faces
!! of a tracer cell [H L2 ~> m3 or kg]
real :: HL2_to_kg_scale !< Unit conversion factor to cell mass [kg H-1 L-2 ~> kg m-3 or 1]
integer :: i, j, k, is, ie, js, je, nz

is = G%isc ; ie = G%iec ; js = G%jsc ; je = G%jec ; nz = GV%ke

HL2_to_kg_scale = GV%H_to_kg_m2 * US%L_to_m**2

trans_rem_col(:,:) = 0.0
do k=1,nz ; do j=js,je ; do i=is,ie
trans_cell = (ABS(uhtr(I-1,j,k)) + ABS(uhtr(I,j,k))) + &
(ABS(vhtr(i,J-1,k)) + ABS(vhtr(i,J,k)))
if (trans_cell > max(1.0e-16*h_new(i,j,k), GV%H_subroundoff) * G%areaT(i,j)) &
trans_rem_col(i,j) = trans_rem_col(i,j) + HL2_to_kg_scale * trans_cell
trans_rem_col(i,j) = trans_rem_col(i,j) + GV%H_to_RZ * trans_cell
enddo ; enddo ; enddo

! The factor of 0.5 here is to avoid double-counting because two cells share a face.
remaining_transport_sum = 0.5 * GV%kg_m2_to_H*US%m_to_L**2 * &
reproducing_sum(trans_rem_col, is+(1-G%isd), ie+(1-G%isd), js+(1-G%jsd), je+(1-G%jsd))
remaining_transport_sum = 0.5 * GV%RZ_to_H * reproducing_sum(trans_rem_col, &
is+(1-G%isd), ie+(1-G%isd), js+(1-G%jsd), je+(1-G%jsd), unscale=US%RZL2_to_kg)

end function remaining_transport_sum

Expand Down Expand Up @@ -876,8 +873,8 @@ subroutine offline_advection_layer(fluxes, Time_start, time_interval, G, GV, US,
real, dimension(SZI_(G),SZJB_(G),SZK_(GV)) :: vhtr_sub ! Remaining meridional mass transports [H L2 ~> m3 or kg]

real, dimension(SZI_(G),SZJB_(G)) :: rem_col_flux ! The summed absolute value of the remaining
! fluxes through the faces of a column or within a column, in mks units [kg]
real :: sum_flux ! Globally summed absolute value of fluxes in mks units [kg], which is
! mass fluxes through the faces of a column or within a column [R Z L2 ~> kg]
real :: sum_flux ! Globally summed absolute value of fluxes [R Z L2 ~> kg], which is
! used to keep track of how close to convergence we are.

real, dimension(SZI_(G),SZJ_(G),SZK_(GV)) :: &
Expand All @@ -890,7 +887,6 @@ subroutine offline_advection_layer(fluxes, Time_start, time_interval, G, GV, US,
! Work arrays for temperature and salinity
integer :: iter
real :: dt_iter ! The timestep of each iteration [T ~> s]
real :: HL2_to_kg_scale ! Unit conversion factors to cell mass [kg H-1 L-2 ~> kg m-3 or 1]
character(len=160) :: mesg ! The text of an error message
integer :: i, j, k, is, ie, js, je, isd, ied, jsd, jed, nz
integer :: IsdB, IedB, JsdB, JedB
Expand Down Expand Up @@ -993,22 +989,22 @@ subroutine offline_advection_layer(fluxes, Time_start, time_interval, G, GV, US,
call pass_vector(uhtr,vhtr,G%Domain)

! Calculate how close we are to converging by summing the remaining fluxes at each point
HL2_to_kg_scale = US%L_to_m**2*GV%H_to_kg_m2
rem_col_flux(:,:) = 0.0
do k=1,nz ; do j=js,je ; do i=is,ie
rem_col_flux(i,j) = rem_col_flux(i,j) + HL2_to_kg_scale * &
rem_col_flux(i,j) = rem_col_flux(i,j) + GV%H_to_RZ * &
( (abs(eatr(i,j,k)) + abs(ebtr(i,j,k))) + &
((abs(uhtr(I-1,j,k)) + abs(uhtr(I,j,k))) + &
(abs(vhtr(i,J-1,k)) + abs(vhtr(i,J,k))) ) )
enddo ; enddo ; enddo
sum_flux = reproducing_sum(rem_col_flux, is+(1-G%isd), ie+(1-G%isd), js+(1-G%jsd), je+(1-G%jsd))
sum_flux = reproducing_sum(rem_col_flux, is+(1-G%isd), ie+(1-G%isd), js+(1-G%jsd), je+(1-G%jsd), &
unscale=US%RZL2_to_kg)

if (sum_flux==0) then
write(mesg,*) 'offline_advection_layer: Converged after iteration', iter
call MOM_mesg(mesg)
exit
else
write(mesg,*) "offline_advection_layer: Iteration ", iter, " remaining total fluxes: ", sum_flux
write(mesg,*) "offline_advection_layer: Iteration ", iter, " remaining total fluxes: ", sum_flux*US%RZL2_to_kg
call MOM_mesg(mesg)
endif

Expand Down
10 changes: 3 additions & 7 deletions src/user/tidal_bay_initialization.F90
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ subroutine tidal_bay_set_OBC_data(OBC, CS, G, GV, US, h, Time)
real :: my_flux ! The vlume flux through the face [L2 Z T-1 ~> m3 s-1]
real :: total_area ! The total face area of the OBCs [L Z ~> m2]
real :: PI ! The ratio of the circumference of a circle to its diameter [nondim]
real :: flux_scale ! A scaling factor for the areas [m2 H-1 L-1 ~> nondim or m3 kg-1]
real, allocatable :: my_area(:,:) ! The total OBC inflow area [m2]
real, allocatable :: my_area(:,:) ! The total OBC inflow area [L Z ~> m2]
integer :: i, j, k, is, ie, js, je, isd, ied, jsd, jed, nz, n
integer :: IsdB, IedB, JsdB, JedB
type(OBC_segment_type), pointer :: segment => NULL()
Expand All @@ -94,8 +93,6 @@ subroutine tidal_bay_set_OBC_data(OBC, CS, G, GV, US, h, Time)

allocate(my_area(1:1,js:je))

flux_scale = GV%H_to_m*US%L_to_m

time_sec = US%s_to_T*time_type_to_real(Time)
cff_eta = CS%tide_ssh_amp * sin(2.0*PI*time_sec / CS%tide_period)
my_area = 0.0
Expand All @@ -105,12 +102,11 @@ subroutine tidal_bay_set_OBC_data(OBC, CS, G, GV, US, h, Time)
do j=segment%HI%jsc,segment%HI%jec ; do I=segment%HI%IscB,segment%HI%IecB
if (OBC%segnum_u(I,j) /= OBC_NONE) then
do k=1,nz
! This area has to be in MKS units to work with reproducing_sum.
my_area(1,j) = my_area(1,j) + h(I,j,k)*flux_scale*G%dyCu(I,j)
my_area(1,j) = my_area(1,j) + h(I,j,k)*(GV%H_to_m*US%m_to_Z)*G%dyCu(I,j)
enddo
endif
enddo ; enddo
total_area = US%m_to_Z*US%m_to_L * reproducing_sum(my_area)
total_area = reproducing_sum(my_area, unscale=US%Z_to_m*US%L_to_m)
my_flux = - CS%tide_flow * SIN(2.0*PI*time_sec / CS%tide_period)

do n = 1, OBC%number_of_segments
Expand Down
Loading