Skip to content

Commit

Permalink
+Use answer_date to specify remapping in ALE
Browse files Browse the repository at this point in the history
  Replace the answers_2018 arguments with answer_date arguments to specify the
version of expressions in a number of calls from the upper-level ALE modules,
while also adding new answer_date optional arguments to several of the publicly
visible remapping routines, including ALE_remap_scalar, regrid_set_params and
remapping_set_params.  The routine interpolate_grid, which is not called from
outside of the regrid_interp module, is no longer being made publicly visible.
Some comments noting parameters that are not guaranteed to be externally set or
that can not be reset were also added.  All answers are bitwise identical.
  • Loading branch information
Hallberg-NOAA committed Jul 29, 2022
1 parent 8fd1229 commit ecb85cb
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 100 deletions.
60 changes: 39 additions & 21 deletions src/ALE/MOM_ALE.F90
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,11 @@ module MOM_ALE

logical :: remap_after_initialization !< Indicates whether to regrid/remap after initializing the state.

logical :: answers_2018 !< If true, use the order of arithmetic and expressions for remapping
!! that recover the answers from the end of 2018. Otherwise, use more
!! robust and accurate forms of mathematically equivalent expressions.
integer :: answer_date !< The vintage of the expressions and order of arithmetic to use for
!! remapping. Values below 20190101 result in the use of older, less
!! accurate expressions that were in use at the end of 2018. Higher
!! values result inthe use of more robust and accurate forms of
!! mathematically equivalent expressions.

logical :: debug !< If true, write verbose checksums for debugging purposes.
logical :: show_call_tree !< For debugging
Expand Down Expand Up @@ -163,7 +165,11 @@ subroutine ALE_init( param_file, GV, US, max_depth, CS)
character(len=40) :: mdl = "MOM_ALE" ! This module's name.
character(len=80) :: string, vel_string ! Temporary strings
real :: filter_shallow_depth, filter_deep_depth
logical :: default_2018_answers
integer :: default_answer_date ! The default setting for the various ANSWER_DATE flags.
logical :: default_2018_answers ! The default setting for the various 2018_ANSWERS flags.
logical :: answers_2018 ! If true, use the order of arithmetic and expressions for remapping
! that recover the answers from the end of 2018. Otherwise, use more
! robust and accurate forms of mathematically equivalent expressions.
logical :: check_reconstruction
logical :: check_remapping
logical :: force_bounds_in_subcell
Expand Down Expand Up @@ -218,25 +224,33 @@ subroutine ALE_init( param_file, GV, US, max_depth, CS)
call get_param(param_file, mdl, "REMAP_BOUNDARY_EXTRAP", remap_boundary_extrap, &
"If true, values at the interfaces of boundary cells are "//&
"extrapolated instead of piecewise constant", default=.false.)
call get_param(param_file, mdl, "DEFAULT_ANSWER_DATE", default_answer_date, &
"This sets the default value for the various _ANSWER_DATE parameters.", &
default=99991231, do_not_log=.true.)
call get_param(param_file, mdl, "DEFAULT_2018_ANSWERS", default_2018_answers, &
"This sets the default value for the various _2018_ANSWERS parameters.", &
default=.false.)
call get_param(param_file, mdl, "REMAPPING_2018_ANSWERS", CS%answers_2018, &
default=(default_answer_date<20190101))
call get_param(param_file, mdl, "REMAPPING_2018_ANSWERS", answers_2018, &
"If true, use the order of arithmetic and expressions that recover the "//&
"answers from the end of 2018. Otherwise, use updated and more robust "//&
"forms of the same expressions.", default=default_2018_answers)
if (answers_2018) then
CS%answer_date = 20181231
else
CS%answer_date = 20190101
endif
call initialize_remapping( CS%remapCS, string, &
boundary_extrapolation=remap_boundary_extrap, &
check_reconstruction=check_reconstruction, &
check_remapping=check_remapping, &
force_bounds_in_subcell=force_bounds_in_subcell, &
answers_2018=CS%answers_2018)
answer_date=CS%answer_date)
call initialize_remapping( CS%vel_remapCS, vel_string, &
boundary_extrapolation=remap_boundary_extrap, &
check_reconstruction=check_reconstruction, &
check_remapping=check_remapping, &
force_bounds_in_subcell=force_bounds_in_subcell, &
answers_2018=CS%answers_2018)
answer_date=CS%answer_date)

call get_param(param_file, mdl, "PARTIAL_CELL_VELOCITY_REMAP", CS%partial_cell_vel_remap, &
"If true, use partial cell thicknesses at velocity points that are masked out "//&
Expand Down Expand Up @@ -590,8 +604,8 @@ subroutine ALE_offline_inputs(CS, G, GV, h, tv, Reg, uhtr, vhtr, Kd, debug, OBC)
endif
enddo ; enddo

call ALE_remap_scalar(CS%remapCS, G, GV, nk, h, tv%T, h_new, tv%T, answers_2018=CS%answers_2018)
call ALE_remap_scalar(CS%remapCS, G, GV, nk, h, tv%S, h_new, tv%S, answers_2018=CS%answers_2018)
call ALE_remap_scalar(CS%remapCS, G, GV, nk, h, tv%T, h_new, tv%T, answer_date=CS%answer_date)
call ALE_remap_scalar(CS%remapCS, G, GV, nk, h, tv%S, h_new, tv%S, answer_date=CS%answer_date)

if (debug) call MOM_tracer_chkinv("After ALE_offline_inputs", G, GV, h_new, Reg%Tr, Reg%ntr)

Expand Down Expand Up @@ -742,7 +756,7 @@ subroutine ALE_regrid_accelerated(CS, G, GV, h, tv, n_itt, u, v, OBC, Reg, dt, d
if (present(dt)) &
call ALE_update_regrid_weights(dt, CS)

if (.not. CS%answers_2018) then
if (CS%answer_date >= 20190101) then
h_neglect = GV%H_subroundoff ; h_neglect_edge = GV%H_subroundoff
elseif (GV%Boussinesq) then
h_neglect = GV%m_to_H * 1.0e-30 ; h_neglect_edge = GV%m_to_H * 1.0e-10
Expand Down Expand Up @@ -843,7 +857,7 @@ subroutine remap_all_state_vars(CS, G, GV, h_old, h_new, Reg, OBC, &
"and u/v are to be remapped")
endif

if (.not.CS%answers_2018) then
if (CS%answer_date >= 20190101) then
h_neglect = GV%H_subroundoff ; h_neglect_edge = GV%H_subroundoff
elseif (GV%Boussinesq) then
h_neglect = GV%m_to_H*1.0e-30 ; h_neglect_edge = GV%m_to_H*1.0e-10
Expand Down Expand Up @@ -1092,7 +1106,8 @@ end subroutine mask_near_bottom_vel
!> Remaps a single scalar between grids described by thicknesses h_src and h_dst.
!! h_dst must be dimensioned as a model array with GV%ke layers while h_src can
!! have an arbitrary number of layers specified by nk_src.
subroutine ALE_remap_scalar(CS, G, GV, nk_src, h_src, s_src, h_dst, s_dst, all_cells, old_remap, answers_2018 )
subroutine ALE_remap_scalar(CS, G, GV, nk_src, h_src, s_src, h_dst, s_dst, all_cells, old_remap, &
answers_2018, answer_date )
type(remapping_CS), intent(in) :: CS !< Remapping control structure
type(ocean_grid_type), intent(in) :: G !< Ocean grid structure
type(verticalGrid_type), intent(in) :: GV !< Ocean vertical grid structure
Expand All @@ -1112,6 +1127,8 @@ subroutine ALE_remap_scalar(CS, G, GV, nk_src, h_src, s_src, h_dst, s_dst, all_c
!! and expressions that recover the answers for
!! remapping from the end of 2018. Otherwise,
!! use more robust forms of the same expressions.
integer, optional, intent(in) :: answer_date !< The vintage of the expressions to use
!! for remapping
! Local variables
integer :: i, j, k, n_points
real :: dx(GV%ke+1)
Expand All @@ -1124,6 +1141,7 @@ subroutine ALE_remap_scalar(CS, G, GV, nk_src, h_src, s_src, h_dst, s_dst, all_c
if (present(old_remap)) use_remapping_core_w = old_remap
n_points = nk_src
use_2018_remap = .true. ; if (present(answers_2018)) use_2018_remap = answers_2018
if (present(answer_date)) use_2018_remap = (answer_date < 20190101)

if (.not.use_2018_remap) then
h_neglect = GV%H_subroundoff ; h_neglect_edge = GV%H_subroundoff
Expand Down Expand Up @@ -1206,7 +1224,7 @@ subroutine ALE_PLM_edge_values( CS, G, GV, h, Q, bdry_extrap, Q_t, Q_b )
real :: mslp
real :: h_neglect

if (.not.CS%answers_2018) then
if (CS%answer_date >= 20190101) then
h_neglect = GV%H_subroundoff
elseif (GV%Boussinesq) then
h_neglect = GV%m_to_H*1.0e-30
Expand Down Expand Up @@ -1275,7 +1293,7 @@ subroutine TS_PPM_edge_values( CS, S_t, S_b, T_t, T_b, G, GV, tv, h, bdry_extrap
ppol_coefs ! Coefficients of polynomial, all in [degC] or [ppt]
real :: h_neglect, h_neglect_edge ! Tiny thicknesses [H ~> m or kg m-2]

if (.not.CS%answers_2018) then
if (CS%answer_date >= 20190101) then
h_neglect = GV%H_subroundoff ; h_neglect_edge = GV%H_subroundoff
elseif (GV%Boussinesq) then
h_neglect = GV%m_to_H*1.0e-30 ; h_neglect_edge = GV%m_to_H*1.0e-10
Expand All @@ -1295,9 +1313,9 @@ subroutine TS_PPM_edge_values( CS, S_t, S_b, T_t, T_b, G, GV, tv, h, bdry_extrap
ppol_E(:,:) = 0.0
ppol_coefs(:,:) = 0.0
call edge_values_implicit_h4( GV%ke, hTmp, tmp, ppol_E, h_neglect=h_neglect_edge, &
answers_2018=CS%answers_2018 )
answer_date=CS%answer_date )
call PPM_reconstruction( GV%ke, hTmp, tmp, ppol_E, ppol_coefs, h_neglect, &
answers_2018=CS%answers_2018 )
answer_date=CS%answer_date )
if (bdry_extrap) &
call PPM_boundary_extrapolation( GV%ke, hTmp, tmp, ppol_E, ppol_coefs, h_neglect )

Expand All @@ -1310,15 +1328,15 @@ subroutine TS_PPM_edge_values( CS, S_t, S_b, T_t, T_b, G, GV, tv, h, bdry_extrap
ppol_E(:,:) = 0.0
ppol_coefs(:,:) = 0.0
tmp(:) = tv%T(i,j,:)
if (CS%answers_2018) then
if (CS%answer_date < 20190101) then
call edge_values_implicit_h4( GV%ke, hTmp, tmp, ppol_E, h_neglect=1.0e-10*GV%m_to_H, &
answers_2018=CS%answers_2018 )
answer_date=CS%answer_date )
else
call edge_values_implicit_h4( GV%ke, hTmp, tmp, ppol_E, h_neglect=GV%H_subroundoff, &
answers_2018=CS%answers_2018 )
answer_date=CS%answer_date )
endif
call PPM_reconstruction( GV%ke, hTmp, tmp, ppol_E, ppol_coefs, h_neglect, &
answers_2018=CS%answers_2018 )
answer_date=CS%answer_date )
if (bdry_extrap) &
call PPM_boundary_extrapolation(GV%ke, hTmp, tmp, ppol_E, ppol_coefs, h_neglect )

Expand Down
36 changes: 25 additions & 11 deletions src/ALE/MOM_regridding.F90
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ module MOM_regridding
!! If false, integrate from the bottom upward, as does the rest of the model.
logical :: integrate_downward_for_e = .true.

!> If true, use the order of arithmetic and expressions that recover the remapping answers from 2018.
!! If false, use more robust forms of the same remapping expressions.
logical :: remap_answers_2018 = .true.
!> The vintage of the order of arithmetic and expressions to use for remapping.
!! Values below 20190101 recover the remapping answers from 2018.
!! Higher values use more robust forms of the same remapping expressions.
integer :: remap_answer_date = 20181231 !### Change to 99991231?

logical :: use_hybgen_unmix = .false. !< If true, use the hybgen unmixing code before remapping

Expand Down Expand Up @@ -204,7 +205,9 @@ subroutine initialize_regridding(CS, GV, US, max_depth, param_file, mdl, coord_m
character(len=12) :: expected_units, alt_units ! Temporary strings
logical :: tmpLogical, fix_haloclines, do_sum, main_parameters
logical :: coord_is_state_dependent, ierr
logical :: default_2018_answers, remap_answers_2018
integer :: default_answer_date ! The default setting for the various ANSWER_DATE flags.
logical :: default_2018_answers ! The default setting for the various 2018_ANSWERS flags.
logical :: remap_answers_2018
real :: filt_len, strat_tol, tmpReal, P_Ref
real :: maximum_depth ! The maximum depth of the ocean [m] (not in Z).
real :: dz_fixed_sfc, Rho_avg_depth, nlay_sfc_int
Expand Down Expand Up @@ -264,9 +267,12 @@ subroutine initialize_regridding(CS, GV, US, max_depth, param_file, mdl, coord_m
trim(regriddingInterpSchemeDoc), default=trim(string2))
call set_regrid_params(CS, interp_scheme=string)

call get_param(param_file, mdl, "DEFAULT_ANSWER_DATE", default_answer_date, &
"This sets the default value for the various _ANSWER_DATE parameters.", &
default=99991231, do_not_log=.true.)
call get_param(param_file, mdl, "DEFAULT_2018_ANSWERS", default_2018_answers, &
"This sets the default value for the various _2018_ANSWERS parameters.", &
default=.false.)
default=(default_answer_date<20190101))
call get_param(param_file, mdl, "REMAPPING_2018_ANSWERS", remap_answers_2018, &
"If true, use the order of arithmetic and expressions that recover the "//&
"answers from the end of 2018. Otherwise, use updated and more robust "//&
Expand Down Expand Up @@ -1381,7 +1387,7 @@ subroutine build_rho_grid( G, GV, US, h, tv, dzInterface, remapCS, CS, frac_shel
#endif
logical :: ice_shelf

if (.not.CS%remap_answers_2018) then
if (CS%remap_answer_date >= 20190101) then
h_neglect = GV%H_subroundoff ; h_neglect_edge = GV%H_subroundoff
elseif (GV%Boussinesq) then
h_neglect = GV%m_to_H*1.0e-30 ; h_neglect_edge = GV%m_to_H*1.0e-10
Expand Down Expand Up @@ -1524,7 +1530,7 @@ subroutine build_grid_HyCOM1( G, GV, US, h, tv, h_new, dzInterface, CS, frac_she
real :: z_top_col, totalThickness
logical :: ice_shelf

if (.not.CS%remap_answers_2018) then
if (CS%remap_answer_date >= 20190101) then
h_neglect = GV%H_subroundoff ; h_neglect_edge = GV%H_subroundoff
elseif (GV%Boussinesq) then
h_neglect = GV%m_to_H*1.0e-30 ; h_neglect_edge = GV%m_to_H*1.0e-10
Expand Down Expand Up @@ -1676,7 +1682,7 @@ subroutine build_grid_SLight(G, GV, US, h, tv, dzInterface, CS)
integer :: i, j, k, nz
real :: h_neglect, h_neglect_edge

if (.not.CS%remap_answers_2018) then
if (CS%remap_answer_date >= 20190101) then
h_neglect = GV%H_subroundoff ; h_neglect_edge = GV%H_subroundoff
elseif (GV%Boussinesq) then
h_neglect = GV%m_to_H*1.0e-30 ; h_neglect_edge = GV%m_to_H*1.0e-10
Expand Down Expand Up @@ -2352,8 +2358,8 @@ end function getCoordinateShortName
subroutine set_regrid_params( CS, boundary_extrapolation, min_thickness, old_grid_weight, &
interp_scheme, depth_of_time_filter_shallow, depth_of_time_filter_deep, &
compress_fraction, ref_pressure, dz_min_surface, nz_fixed_surface, Rho_ML_avg_depth, &
nlay_ML_to_interior, fix_haloclines, halocline_filt_len, &
halocline_strat_tol, integrate_downward_for_e, remap_answers_2018, &
nlay_ML_to_interior, fix_haloclines, halocline_filt_len, halocline_strat_tol, &
integrate_downward_for_e, remap_answers_2018, remap_answer_date, &
adaptTimeRatio, adaptZoom, adaptZoomCoeff, adaptBuoyCoeff, adaptAlpha, adaptDoMin, adaptDrho0)
type(regridding_CS), intent(inout) :: CS !< Regridding control structure
logical, optional, intent(in) :: boundary_extrapolation !< Extrapolate in boundary cells
Expand Down Expand Up @@ -2383,6 +2389,7 @@ subroutine set_regrid_params( CS, boundary_extrapolation, min_thickness, old_gri
logical, optional, intent(in) :: remap_answers_2018 !< If true, use the order of arithmetic and expressions
!! that recover the remapping answers from 2018. Otherwise
!! use more robust but mathematically equivalent expressions.
integer, optional, intent(in) :: remap_answer_date !< The vintage of the expressions to use for remapping
real, optional, intent(in) :: adaptTimeRatio !< Ratio of the ALE timestep to the grid timescale [nondim].
real, optional, intent(in) :: adaptZoom !< Depth of near-surface zooming region [H ~> m or kg m-2].
real, optional, intent(in) :: adaptZoomCoeff !< Coefficient of near-surface zooming diffusivity [nondim].
Expand Down Expand Up @@ -2413,7 +2420,14 @@ subroutine set_regrid_params( CS, boundary_extrapolation, min_thickness, old_gri
if (present(compress_fraction)) CS%compressibility_fraction = compress_fraction
if (present(ref_pressure)) CS%ref_pressure = ref_pressure
if (present(integrate_downward_for_e)) CS%integrate_downward_for_e = integrate_downward_for_e
if (present(remap_answers_2018)) CS%remap_answers_2018 = remap_answers_2018
if (present(remap_answers_2018)) then
if (remap_answers_2018) then
CS%remap_answer_date = 20181231
else
CS%remap_answer_date = 20190101
endif
endif
if (present(remap_answer_date)) CS%remap_answer_date = remap_answer_date

select case (CS%regridding_scheme)
case (REGRIDDING_ZSTAR)
Expand Down
Loading

0 comments on commit ecb85cb

Please sign in to comment.