From 31afce04b6fe7f70992ff49f08db197debc0c123 Mon Sep 17 00:00:00 2001 From: Robert Hallberg Date: Thu, 16 May 2024 05:51:09 -0400 Subject: [PATCH] (*)Avoid diagnostic seg fault in a 10km deep ocean It was noted in NOAA-GFDL/MOM6/issues/491 that the call to initialize_regridding() for diagnostics gives a segmentation fault when the maximum depth of the ocean is greater than 9250 m unless DIAG_COORD_DEF_Z is explicitly set. This commit fixes this problem by (1) adding an extra layer to the bottom of the hard-coded WOA09 list of diagnostic depths when the ocean is deeper than the 9250 m maximum depth in that file, and (2) changing the default behavior for diagnostic grids to be be uniform when the maximum ocean depth is deeper than 9250 m, for which WOA09 is no longer likely to be a convenient choice. With this change, MOM6 no longer has segmentation faults for the configuration described in issues/491. All solutions are bitwise identical, but some z-space diagnostic grids will be modified in cases that previously had segmentation faults. --- src/ALE/MOM_regridding.F90 | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/ALE/MOM_regridding.F90 b/src/ALE/MOM_regridding.F90 index 8faec6c495..43d3f65a5e 100644 --- a/src/ALE/MOM_regridding.F90 +++ b/src/ALE/MOM_regridding.F90 @@ -211,6 +211,8 @@ subroutine initialize_regridding(CS, GV, US, max_depth, param_file, mdl, coord_m real :: tmpReal ! A temporary variable used in setting other variables [various] real :: P_Ref ! The coordinate variable reference pression [R L2 T-2 ~> Pa] real :: maximum_depth ! The maximum depth of the ocean [m] (not in Z). + real :: dz_extra ! The thickness of an added layer to append to the woa09_dz profile when + ! maximum_depth is large [m] (not in Z). real :: adaptTimeRatio, adaptZoomCoeff ! Temporary variables for input parameters [nondim] real :: adaptBuoyCoeff, adaptAlpha ! Temporary variables for input parameters [nondim] real :: adaptZoom ! The thickness of the near-surface zooming region with the adaptive coordinate [H ~> m or kg m-2] @@ -311,7 +313,7 @@ subroutine initialize_regridding(CS, GV, US, max_depth, param_file, mdl, coord_m param_name = create_coord_param(param_prefix, "DEF", param_suffix) coord_res_param = create_coord_param(param_prefix, "RES", param_suffix) string2 = 'UNIFORM' - if (maximum_depth>3000.) string2='WOA09' ! For convenience + if ((maximum_depth>3000.) .and. (maximum_depth<9250.)) string2='WOA09' ! For convenience endif call get_param(param_file, mdl, param_name, string, & "Determines how to specify the coordinate "//& @@ -458,20 +460,27 @@ subroutine initialize_regridding(CS, GV, US, max_depth, param_file, mdl, coord_m endif elseif (index(trim(string),'WOA09')==1) then if (len_trim(string)==5) then - tmpReal = 0. ; ke = 0 + tmpReal = 0. ; ke = 0 ; dz_extra = 0. do while (tmpReal size(woa09_dz)) then + dz_extra = maximum_depth - tmpReal + exit + endif tmpReal = tmpReal + woa09_dz(ke) enddo elseif (index(trim(string),'WOA09:')==1) then if (len_trim(string)==6) call MOM_error(FATAL,trim(mdl)//', initialize_regridding: '// & 'Expected string of form "WOA09:N" but got "'//trim(string)//'".') ke = extract_integer(string(7:len_trim(string)),'',1) + if (ke>40 .or. ke<1) call MOM_error(FATAL,trim(mdl)//', initialize_regridding: '// & + 'For "WOA05:N" N must 040 .or. ke<1) call MOM_error(FATAL,trim(mdl)//', initialize_regridding: '// & - 'For "WOA05:N" N must 0 size(woa09_dz)) dz(ke) = dz_extra else call MOM_error(FATAL,trim(mdl)//", initialize_regridding: "// & "Unrecognized coordinate configuration"//trim(string))