Skip to content

Commit e072bc7

Browse files
Merge in latest dev/gfdl updates (#40)
* (*)Fixed dimensional inconsistency in P3M_functions Corrected dimensionally inconsistent expressions in P3M_functions.F90, notably in P3M_limiter and monotonize_cubic and a complete rewrite and simplification of is_cubic_monotonic. Also added comments documenting the units of all real variables in this module, and changed the code to use logical variables in place of integer "booleans", including in the return value from is_cubic_monotonic. These changes will change (fix) the answers when remapping variables with small numerical values, but no answers change in the MOM6-examples test cases. * +Added REMAPPING_2018 runtime option Added a new runtime option, REMAPPING_2018, which if set to false triggers the use of new, more accurate expressions in various parts of the ALE remapping code. By default, the older expressions are used, and all answers are bitwise identical, but there are new optional arguments to various routines related to remapping to trigger the use of new mathematically equivalent expressions. By default all answers are bitwise identical, but there are new and reordered entries in the MOM6_parameter_doc files. * Corrected the formatting of a doxygen comment * Added conversion factors to forcing diagnostics Added conversion factors to 4 mass-flux diagnostics and comments to 4 others on why no conversion factors are needed. All answers are bitwise identical. * Added correct scaling factors to chksum calls Added scale arguments to 5 chksum calls and grouped another two chksum calls while also adding the right scaling argument. All answers are bitwise identical. * +Unscales area before taking global sum Undoes the dimensional scaling of the cell areas before taking their global sum, so that the reproducing sum does not overflow when there is dimensional rescaling. All answers are bitwise identical when there is no rescaling, but this eliminates a source of inadvertent overflows or underflows in the global sums, and there is a new optional argument to compute_global_grid_integrals. * (*)Correct dimensionally inconsistent advective CFL Corrects the dimensionally inconsistent expressions for the CFL number in the tracer advection code, in which a negligible thickness had been added to the cell volume to avoid division by zero. This change does not alter the solutions in the MOM6-examples test cases, but now it permits dimensional rescaling of lengths over a much larger range, and it could change answers if the minimum layer thicknesses are small enough. * Unscale sea level before averaging Unscale interface heights before taking a global average via a reproducing sum in non-Boussinesq mode global diagnostics to permit dimensional consistency testing over a larger range. All answers are bitwise identical. * +Added an optional tmp_scale arg to global_i_mean Added an optional tmp_scale argument to global_i_mean and global_j_mean to specify an internal rescaling of variables being averaged before the reproducing sum. All answers are bitwise identical, but there are new optional arguments to two public interfaces. * Expand consistency testing with i-mean sponges Use tmp_scale when taking the i-mean interface heights for i-mean sponges, to give a greatly expanded range of dimensional consistency testing. All answers are bitwise identical.
1 parent cae4cfd commit e072bc7

18 files changed

+494
-396
lines changed

src/ALE/MOM_ALE.F90

+29-14
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,23 @@ module MOM_ALE
6363

6464
!> ALE control structure
6565
type, public :: ALE_CS ; private
66-
logical :: remap_uv_using_old_alg !< If true, uses the old "remapping via a delta z"
67-
!! method. If False, uses the new method that
68-
!! remaps between grids described by h.
66+
logical :: remap_uv_using_old_alg !< If true, uses the old "remapping via a delta z"
67+
!! method. If False, uses the new method that
68+
!! remaps between grids described by h.
6969

7070
real :: regrid_time_scale !< The time-scale used in blending between the current (old) grid
7171
!! and the target (new) grid [T ~> s]
7272

7373
type(regridding_CS) :: regridCS !< Regridding parameters and work arrays
7474
type(remapping_CS) :: remapCS !< Remapping parameters and work arrays
7575

76-
integer :: nk !< Used only for queries, not directly by this module
76+
integer :: nk !< Used only for queries, not directly by this module
7777

78-
logical :: remap_after_initialization !< Indicates whether to regrid/remap after initializing the state.
78+
logical :: remap_after_initialization !< Indicates whether to regrid/remap after initializing the state.
79+
80+
logical :: answers_2018 !< If true, use the order of arithmetic and expressions for remapping
81+
!! that recover the answers from the end of 2018. Otherwise, use more
82+
!! robust and accurate forms of mathematically equivalent expressions.
7983

8084
logical :: show_call_tree !< For debugging
8185

@@ -145,6 +149,7 @@ subroutine ALE_init( param_file, GV, US, max_depth, CS)
145149
character(len=40) :: mdl = "MOM_ALE" ! This module's name.
146150
character(len=80) :: string ! Temporary strings
147151
real :: filter_shallow_depth, filter_deep_depth
152+
logical :: default_2018_answers
148153
logical :: check_reconstruction
149154
logical :: check_remapping
150155
logical :: force_bounds_in_subcell
@@ -192,11 +197,19 @@ subroutine ALE_init( param_file, GV, US, max_depth, CS)
192197
call get_param(param_file, mdl, "REMAP_BOUNDARY_EXTRAP", remap_boundary_extrap, &
193198
"If true, values at the interfaces of boundary cells are "//&
194199
"extrapolated instead of piecewise constant", default=.false.)
200+
call get_param(param_file, mdl, "DEFAULT_2018_ANSWERS", default_2018_answers, &
201+
"This sets the default value for the various _2018_ANSWERS parameters.", &
202+
default=.true.)
203+
call get_param(param_file, mdl, "REMAPPING_2018_ANSWERS", CS%answers_2018, &
204+
"If true, use the order of arithmetic and expressions that recover the "//&
205+
"answers from the end of 2018. Otherwise, use updated and more robust "//&
206+
"forms of the same expressions.", default=default_2018_answers)
195207
call initialize_remapping( CS%remapCS, string, &
196208
boundary_extrapolation=remap_boundary_extrap, &
197209
check_reconstruction=check_reconstruction, &
198210
check_remapping=check_remapping, &
199-
force_bounds_in_subcell=force_bounds_in_subcell)
211+
force_bounds_in_subcell=force_bounds_in_subcell, &
212+
answers_2018=CS%answers_2018)
200213

201214
call get_param(param_file, mdl, "REMAP_AFTER_INITIALIZATION", CS%remap_after_initialization, &
202215
"If true, applies regridding and remapping immediately after "//&
@@ -220,7 +233,7 @@ subroutine ALE_init( param_file, GV, US, max_depth, CS)
220233
"REGRID_FILTER_SHALLOW_DEPTH the filter weights adopt a cubic profile.", &
221234
units="m", default=0., scale=GV%m_to_H)
222235
call set_regrid_params(CS%regridCS, depth_of_time_filter_shallow=filter_shallow_depth, &
223-
depth_of_time_filter_deep=filter_deep_depth)
236+
depth_of_time_filter_deep=filter_deep_depth)
224237
call get_param(param_file, mdl, "REGRID_USE_OLD_DIRECTION", local_logical, &
225238
"If true, the regridding ntegrates upwards from the bottom for "//&
226239
"interface positions, much as the main model does. If false "//&
@@ -1089,13 +1102,13 @@ subroutine pressure_gradient_ppm( CS, S_t, S_b, T_t, T_b, G, GV, tv, h, bdry_ext
10891102

10901103
! Local variables
10911104
integer :: i, j, k
1092-
real :: hTmp(GV%ke)
1093-
real :: tmp(GV%ke)
1105+
real :: hTmp(GV%ke) ! A 1-d copy of h [H ~> m or kg m-2]
1106+
real :: tmp(GV%ke) ! A 1-d copy of a column of temperature [degC] or salinity [ppt]
10941107
real, dimension(CS%nk,2) :: &
1095-
ppol_E !Edge value of polynomial
1108+
ppol_E ! Edge value of polynomial in [degC] or [ppt]
10961109
real, dimension(CS%nk,3) :: &
1097-
ppol_coefs !Coefficients of polynomial
1098-
real :: h_neglect, h_neglect_edge
1110+
ppol_coefs ! Coefficients of polynomial, all in [degC] or [ppt]
1111+
real :: h_neglect, h_neglect_edge ! Tiny thicknesses [H ~> m or kg m-2]
10991112

11001113
!### Try replacing both of these with GV%H_subroundoff
11011114
if (GV%Boussinesq) then
@@ -1116,7 +1129,8 @@ subroutine pressure_gradient_ppm( CS, S_t, S_b, T_t, T_b, G, GV, tv, h, bdry_ext
11161129
ppol_E(:,:) = 0.0
11171130
ppol_coefs(:,:) = 0.0
11181131
!### Try to replace the following value of h_neglect with GV%H_subroundoff.
1119-
call edge_values_implicit_h4( GV%ke, hTmp, tmp, ppol_E, h_neglect=h_neglect_edge )
1132+
call edge_values_implicit_h4( GV%ke, hTmp, tmp, ppol_E, h_neglect=h_neglect_edge, &
1133+
answers_2018=CS%answers_2018 )
11201134
call PPM_reconstruction( GV%ke, hTmp, tmp, ppol_E, ppol_coefs, h_neglect )
11211135
if (bdry_extrap) &
11221136
call PPM_boundary_extrapolation( GV%ke, hTmp, tmp, ppol_E, ppol_coefs, h_neglect )
@@ -1131,7 +1145,8 @@ subroutine pressure_gradient_ppm( CS, S_t, S_b, T_t, T_b, G, GV, tv, h, bdry_ext
11311145
ppol_coefs(:,:) = 0.0
11321146
tmp(:) = tv%T(i,j,:)
11331147
!### Try to replace the following value of h_neglect with GV%H_subroundoff.
1134-
call edge_values_implicit_h4( GV%ke, hTmp, tmp, ppol_E, h_neglect=1.0e-10*GV%m_to_H )
1148+
call edge_values_implicit_h4( GV%ke, hTmp, tmp, ppol_E, h_neglect=1.0e-10*GV%m_to_H, &
1149+
answers_2018=CS%answers_2018 )
11351150
call PPM_reconstruction( GV%ke, hTmp, tmp, ppol_E, ppol_coefs, h_neglect )
11361151
if (bdry_extrap) &
11371152
call PPM_boundary_extrapolation(GV%ke, hTmp, tmp, ppol_E, ppol_coefs, h_neglect )

src/ALE/MOM_remapping.F90

+23-14
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ module MOM_remapping
3333
logical :: check_remapping = .false.
3434
!> If true, the intermediate values used in remapping are forced to be bounded.
3535
logical :: force_bounds_in_subcell = .false.
36+
!> If true use older, less acccurate expressions.
37+
logical :: answers_2018 = .true.
3638
end type
3739

3840
! The following routines are visible to the outside world
@@ -84,13 +86,14 @@ module MOM_remapping
8486

8587
!> Set parameters within remapping object
8688
subroutine remapping_set_param(CS, remapping_scheme, boundary_extrapolation, &
87-
check_reconstruction, check_remapping, force_bounds_in_subcell)
89+
check_reconstruction, check_remapping, force_bounds_in_subcell, answers_2018)
8890
type(remapping_CS), intent(inout) :: CS !< Remapping control structure
8991
character(len=*), optional, intent(in) :: remapping_scheme !< Remapping scheme to use
9092
logical, optional, intent(in) :: boundary_extrapolation !< Indicate to extrapolate in boundary cells
9193
logical, optional, intent(in) :: check_reconstruction !< Indicate to check reconstructions
9294
logical, optional, intent(in) :: check_remapping !< Indicate to check results of remapping
9395
logical, optional, intent(in) :: force_bounds_in_subcell !< Force subcells values to be bounded
96+
logical, optional, intent(in) :: answers_2018 !< If true use older, less acccurate expressions.
9497

9598
if (present(remapping_scheme)) then
9699
call setReconstructionType( remapping_scheme, CS )
@@ -107,6 +110,9 @@ subroutine remapping_set_param(CS, remapping_scheme, boundary_extrapolation, &
107110
if (present(force_bounds_in_subcell)) then
108111
CS%force_bounds_in_subcell = force_bounds_in_subcell
109112
endif
113+
if (present(answers_2018)) then
114+
CS%answers_2018 = answers_2018
115+
endif
110116
end subroutine remapping_set_param
111117

112118
subroutine extract_member_remapping_CS(CS, remapping_scheme, degree, boundary_extrapolation, check_reconstruction, &
@@ -392,31 +398,31 @@ subroutine build_reconstructions_1d( CS, n0, h0, u0, ppoly_r_coefs, &
392398
endif
393399
iMethod = INTEGRATION_PLM
394400
case ( REMAPPING_PPM_H4 )
395-
call edge_values_explicit_h4( n0, h0, u0, ppoly_r_E, h_neglect_edge )
401+
call edge_values_explicit_h4( n0, h0, u0, ppoly_r_E, h_neglect_edge, answers_2018=CS%answers_2018 )
396402
call PPM_reconstruction( n0, h0, u0, ppoly_r_E, ppoly_r_coefs, h_neglect )
397403
if ( CS%boundary_extrapolation ) then
398404
call PPM_boundary_extrapolation( n0, h0, u0, ppoly_r_E, ppoly_r_coefs, h_neglect )
399405
endif
400406
iMethod = INTEGRATION_PPM
401407
case ( REMAPPING_PPM_IH4 )
402-
call edge_values_implicit_h4( n0, h0, u0, ppoly_r_E, h_neglect_edge )
408+
call edge_values_implicit_h4( n0, h0, u0, ppoly_r_E, h_neglect_edge, answers_2018=CS%answers_2018 )
403409
call PPM_reconstruction( n0, h0, u0, ppoly_r_E, ppoly_r_coefs, h_neglect )
404410
if ( CS%boundary_extrapolation ) then
405411
call PPM_boundary_extrapolation( n0, h0, u0, ppoly_r_E, ppoly_r_coefs, h_neglect )
406412
endif
407413
iMethod = INTEGRATION_PPM
408414
case ( REMAPPING_PQM_IH4IH3 )
409-
call edge_values_implicit_h4( n0, h0, u0, ppoly_r_E, h_neglect_edge )
410-
call edge_slopes_implicit_h3( n0, h0, u0, ppoly_r_S, h_neglect )
415+
call edge_values_implicit_h4( n0, h0, u0, ppoly_r_E, h_neglect_edge, answers_2018=CS%answers_2018 )
416+
call edge_slopes_implicit_h3( n0, h0, u0, ppoly_r_S, h_neglect, answers_2018=CS%answers_2018 )
411417
call PQM_reconstruction( n0, h0, u0, ppoly_r_E, ppoly_r_S, ppoly_r_coefs, h_neglect )
412418
if ( CS%boundary_extrapolation ) then
413419
call PQM_boundary_extrapolation_v1( n0, h0, u0, ppoly_r_E, ppoly_r_S, &
414420
ppoly_r_coefs, h_neglect )
415421
endif
416422
iMethod = INTEGRATION_PQM
417423
case ( REMAPPING_PQM_IH6IH5 )
418-
call edge_values_implicit_h6( n0, h0, u0, ppoly_r_E, h_neglect_edge )
419-
call edge_slopes_implicit_h5( n0, h0, u0, ppoly_r_S, h_neglect )
424+
call edge_values_implicit_h6( n0, h0, u0, ppoly_r_E, h_neglect_edge, answers_2018=CS%answers_2018 )
425+
call edge_slopes_implicit_h5( n0, h0, u0, ppoly_r_S, h_neglect, answers_2018=CS%answers_2018 )
420426
call PQM_reconstruction( n0, h0, u0, ppoly_r_E, ppoly_r_S, ppoly_r_coefs, h_neglect )
421427
if ( CS%boundary_extrapolation ) then
422428
call PQM_boundary_extrapolation_v1( n0, h0, u0, ppoly_r_E, ppoly_r_S, &
@@ -1537,19 +1543,20 @@ end subroutine dzFromH1H2
15371543

15381544
!> Constructor for remapping control structure
15391545
subroutine initialize_remapping( CS, remapping_scheme, boundary_extrapolation, &
1540-
check_reconstruction, check_remapping, force_bounds_in_subcell)
1546+
check_reconstruction, check_remapping, force_bounds_in_subcell, answers_2018)
15411547
! Arguments
15421548
type(remapping_CS), intent(inout) :: CS !< Remapping control structure
15431549
character(len=*), intent(in) :: remapping_scheme !< Remapping scheme to use
15441550
logical, optional, intent(in) :: boundary_extrapolation !< Indicate to extrapolate in boundary cells
15451551
logical, optional, intent(in) :: check_reconstruction !< Indicate to check reconstructions
15461552
logical, optional, intent(in) :: check_remapping !< Indicate to check results of remapping
15471553
logical, optional, intent(in) :: force_bounds_in_subcell !< Force subcells values to be bounded
1554+
logical, optional, intent(in) :: answers_2018 !< If true use older, less acccurate expressions.
15481555

1549-
! Note that remapping_scheme is mandatory fir initialize_remapping()
1556+
! Note that remapping_scheme is mandatory for initialize_remapping()
15501557
call remapping_set_param(CS, remapping_scheme=remapping_scheme, boundary_extrapolation=boundary_extrapolation, &
15511558
check_reconstruction=check_reconstruction, check_remapping=check_remapping, &
1552-
force_bounds_in_subcell=force_bounds_in_subcell)
1559+
force_bounds_in_subcell=force_bounds_in_subcell, answers_2018=answers_2018)
15531560

15541561
end subroutine initialize_remapping
15551562

@@ -1615,13 +1622,15 @@ logical function remapping_unit_tests(verbose)
16151622
data h2 /6*0.5/ ! 6 uniform layers with total depth of 3
16161623
type(remapping_CS) :: CS !< Remapping control structure
16171624
real, allocatable, dimension(:,:) :: ppoly0_E, ppoly0_S, ppoly0_coefs
1625+
logical :: answers_2018 ! If true use older, less acccurate expressions.
16181626
integer :: i
16191627
real :: err, h_neglect, h_neglect_edge
16201628
logical :: thisTest, v
16211629

16221630
v = verbose
16231631
h_neglect = hNeglect_dflt
16241632
h_neglect_edge = 1.0e-10
1633+
answers_2018 = .true.
16251634

16261635
write(*,*) '==== MOM_remapping: remapping_unit_tests ================='
16271636
remapping_unit_tests = .false. ! Normally return false
@@ -1643,7 +1652,7 @@ logical function remapping_unit_tests(verbose)
16431652
remapping_unit_tests = remapping_unit_tests .or. thisTest
16441653

16451654
thisTest = .false.
1646-
call initialize_remapping(CS, 'PPM_H4')
1655+
call initialize_remapping(CS, 'PPM_H4', answers_2018=answers_2018)
16471656
if (verbose) write(*,*) 'h0 (test data)'
16481657
if (verbose) call dumpGrid(n0,h0,x0,u0)
16491658

@@ -1667,7 +1676,7 @@ logical function remapping_unit_tests(verbose)
16671676
ppoly0_S(:,:) = 0.0
16681677
ppoly0_coefs(:,:) = 0.0
16691678

1670-
call edge_values_explicit_h4( n0, h0, u0, ppoly0_E, h_neglect=1e-10 )
1679+
call edge_values_explicit_h4( n0, h0, u0, ppoly0_E, h_neglect=1e-10, answers_2018=answers_2018 )
16711680
call PPM_reconstruction( n0, h0, u0, ppoly0_E, ppoly0_coefs, h_neglect )
16721681
call PPM_boundary_extrapolation( n0, h0, u0, ppoly0_E, ppoly0_coefs, h_neglect )
16731682
u1(:) = 0.
@@ -1798,7 +1807,7 @@ logical function remapping_unit_tests(verbose)
17981807
test_answer(v, 3, ppoly0_coefs(:,2), (/0.,4.,0./), 'Non-uniform line PLM: P1')
17991808

18001809
call edge_values_explicit_h4( 5, (/1.,1.,1.,1.,1./), (/1.,3.,5.,7.,9./), ppoly0_E, &
1801-
h_neglect=1e-10 )
1810+
h_neglect=1e-10, answers_2018=answers_2018 )
18021811
! The next two tests currently fail due to roundoff.
18031812
thisTest = test_answer(v, 5, ppoly0_E(:,1), (/0.,2.,4.,6.,8./), 'Line H4: left edges')
18041813
thisTest = test_answer(v, 5, ppoly0_E(:,2), (/2.,4.,6.,8.,10./), 'Line H4: right edges')
@@ -1814,7 +1823,7 @@ logical function remapping_unit_tests(verbose)
18141823
test_answer(v, 5, ppoly0_coefs(:,3), (/0.,0.,0.,0.,0./), 'Line PPM: P2')
18151824

18161825
call edge_values_explicit_h4( 5, (/1.,1.,1.,1.,1./), (/1.,1.,7.,19.,37./), ppoly0_E, &
1817-
h_neglect=1e-10 )
1826+
h_neglect=1e-10, answers_2018=answers_2018 )
18181827
! The next two tests currently fail due to roundoff.
18191828
thisTest = test_answer(v, 5, ppoly0_E(:,1), (/3.,0.,3.,12.,27./), 'Parabola H4: left edges')
18201829
thisTest = test_answer(v, 5, ppoly0_E(:,2), (/0.,3.,12.,27.,48./), 'Parabola H4: right edges')

0 commit comments

Comments
 (0)