From 7ad72961103f4b436579dc34f78ab43d9d774641 Mon Sep 17 00:00:00 2001 From: alperaltuntas Date: Wed, 28 Aug 2019 15:30:09 -0600 Subject: [PATCH 1/7] remove labeled format specifiers --- config_src/nuopc_driver/mom_cap.F90 | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/config_src/nuopc_driver/mom_cap.F90 b/config_src/nuopc_driver/mom_cap.F90 index 360e8f833d..39ca8c2f66 100644 --- a/config_src/nuopc_driver/mom_cap.F90 +++ b/config_src/nuopc_driver/mom_cap.F90 @@ -1181,6 +1181,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) integer, allocatable :: gindex(:) ! global index space character(len=128) :: fldname character(len=256) :: cvalue + character(len=256) :: frmt ! format specifier for several error msgs character(len=*), parameter :: subname='(MOM_cap:InitializeRealize)' integer :: spatialDim integer :: numOwnedElements @@ -1384,19 +1385,19 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) do n = 1,numOwnedElements diff_lon = abs(lonMesh(n) - lon(n)) if (diff_lon > 1.e-2) then - write(6,100)n,lonMesh(n),lon(n), diff_lon -100 format('ERROR: MOM n, lonMesh(n), lon(n), diff_lon = ',i8,2(f21.13,3x),d21.5) + frmt = "('ERROR: MOM n, lonMesh(n), lon(n), diff_lon = ',i8,2(f21.13,3x),d21.5)" + write(6,frmt)n,lonMesh(n),lon(n), diff_lon !call shr_sys_abort() end if diff_lat = abs(latMesh(n) - lat(n)) if (diff_lat > 1.e-2) then - write(6,101)n,latMesh(n),lat(n), diff_lat -101 format('ERROR: MOM n, latMesh(n), lat(n), diff_lat = ',i8,2(f21.13,3x),d21.5) + frmt = "('ERROR: MOM n, latMesh(n), lat(n), diff_lat = ',i8,2(f21.13,3x),d21.5)" + write(6,frmt)n,latMesh(n),lat(n), diff_lat !call shr_sys_abort() end if if (abs(maskMesh(n) - mask(n)) > 0) then - write(6,102)n,maskMesh(n),mask(n) -102 format('ERROR: MOM n, maskMesh(n), mask(n) = ',3(i8,2x)) + frmt = "('ERROR: MOM n, maskMesh(n), mask(n) = ',3(i8,2x))" + write(6,frmt)n,maskMesh(n),mask(n) !call shr_sys_abort() end if end do From 18c6f1ebb8b3d27c4b666246c4717a9450417196 Mon Sep 17 00:00:00 2001 From: alperaltuntas Date: Wed, 28 Aug 2019 16:59:08 -0600 Subject: [PATCH 2/7] replace hard-coded mesh diff. limit with a param: eps_omesh --- config_src/nuopc_driver/mom_ocean_model_nuopc.F90 | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/config_src/nuopc_driver/mom_ocean_model_nuopc.F90 b/config_src/nuopc_driver/mom_ocean_model_nuopc.F90 index 95b1bcc6e3..abb6bb2679 100644 --- a/config_src/nuopc_driver/mom_ocean_model_nuopc.F90 +++ b/config_src/nuopc_driver/mom_ocean_model_nuopc.F90 @@ -80,6 +80,7 @@ module MOM_ocean_model_nuopc public ocean_public_type_chksum public ocean_model_data_get public get_ocean_grid +public get_eps_omesh !> This interface extracts a named scalar field or array from the ocean surface or public type interface ocean_model_data_get @@ -182,6 +183,9 @@ module MOM_ocean_model_nuopc logical :: diabatic_first !< If true, apply diabatic and thermodynamic !! processes before time stepping the dynamics. + real :: eps_omesh !< Max allowable difference between ESMF mesh and MOM6 + !! domain coordinates + type(directories) :: dirs !< A structure containing several relevant directory paths. type(mech_forcing) :: forces !< A structure with the driving mechanical surface forces type(forcing) :: fluxes !< A structure containing pointers to @@ -327,6 +331,9 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i else ; call MOM_error(FATAL,"ocean_model_init: OCEAN_SURFACE_STAGGER = "// & trim(stagger)//" is invalid.") ; endif + call get_param(param_file, mdl, "EPS_OMESH",OS%eps_omesh, & + "Maximum allowable difference between ESMF mesh and "//& + "MOM6 domain coordinates.", default=1.e-2) call get_param(param_file, mdl, "RESTORE_SALINITY",OS%restore_salinity, & "If true, the coupled driver will add a globally-balanced "//& "fresh-water flux that drives sea-surface salinity "//& @@ -353,7 +360,7 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i OS%press_to_z = 1.0/(Rho0*G_Earth) - call get_param(param_file, mdl, "HFREEZE", HFrz, & + call get_param(param_file, mdl, "HFREEZE", HFrz, & "If HFREEZE > 0, melt potential will be computed. The actual depth "//& "over which melt potential is computed will be min(HFREEZE, OBLD), "//& "where OBLD is the boundary layer depth. If HFREEZE <= 0 (default), "//& @@ -1174,4 +1181,10 @@ subroutine get_ocean_grid(OS, Gridp) return end subroutine get_ocean_grid +!> Returns eps_omesh read from param file +real function get_eps_omesh(OS) + type(ocean_state_type) :: OS + get_eps_omesh = OS%eps_omesh; return +end function + end module MOM_ocean_model_nuopc From 66f808bf8aec38fef9f5d5c293b8e91d7acd6fa5 Mon Sep 17 00:00:00 2001 From: alperaltuntas Date: Wed, 28 Aug 2019 17:20:39 -0600 Subject: [PATCH 3/7] add units to EPS_OMESH --- config_src/nuopc_driver/mom_ocean_model_nuopc.F90 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config_src/nuopc_driver/mom_ocean_model_nuopc.F90 b/config_src/nuopc_driver/mom_ocean_model_nuopc.F90 index abb6bb2679..83dfa0a4f8 100644 --- a/config_src/nuopc_driver/mom_ocean_model_nuopc.F90 +++ b/config_src/nuopc_driver/mom_ocean_model_nuopc.F90 @@ -333,7 +333,8 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i call get_param(param_file, mdl, "EPS_OMESH",OS%eps_omesh, & "Maximum allowable difference between ESMF mesh and "//& - "MOM6 domain coordinates.", default=1.e-2) + "MOM6 domain coordinates in nuopc cap.", & + units="degrees", default=1.e-2) call get_param(param_file, mdl, "RESTORE_SALINITY",OS%restore_salinity, & "If true, the coupled driver will add a globally-balanced "//& "fresh-water flux that drives sea-surface salinity "//& From c698b1a2864b3e2bf6006a5729c876506c5943ae Mon Sep 17 00:00:00 2001 From: alperaltuntas Date: Wed, 28 Aug 2019 17:21:34 -0600 Subject: [PATCH 4/7] call get_eps_omesh and remove hardcoded limit --- config_src/nuopc_driver/mom_cap.F90 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/config_src/nuopc_driver/mom_cap.F90 b/config_src/nuopc_driver/mom_cap.F90 index 39ca8c2f66..642a7eb809 100644 --- a/config_src/nuopc_driver/mom_cap.F90 +++ b/config_src/nuopc_driver/mom_cap.F90 @@ -344,7 +344,8 @@ module MOM_cap_mod use MOM_grid, only: ocean_grid_type, get_global_grid_size use MOM_ocean_model_nuopc, only: ocean_model_restart, ocean_public_type, ocean_state_type use MOM_ocean_model_nuopc, only: ocean_model_init_sfc -use MOM_ocean_model_nuopc, only: ocean_model_init, update_ocean_model, ocean_model_end, get_ocean_grid +use MOM_ocean_model_nuopc, only: ocean_model_init, update_ocean_model, ocean_model_end +use MOM_ocean_model_nuopc, only: get_ocean_grid, get_eps_omesh use MOM_cap_time, only: AlarmInit use MOM_cap_methods, only: mom_import, mom_export, mom_set_geomtype #ifdef CESMCOUPLED @@ -1191,6 +1192,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) real(ESMF_KIND_R8) , pointer :: lon(:), lonMesh(:) integer(ESMF_KIND_I4) , pointer :: mask(:), maskMesh(:) real(ESMF_KIND_R8) :: diff_lon, diff_lat + real :: eps_omesh !-------------------------------- rc = ESMF_SUCCESS @@ -1382,15 +1384,16 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) end do end do + eps_omesh = get_eps_omesh(ocean_state) do n = 1,numOwnedElements diff_lon = abs(lonMesh(n) - lon(n)) - if (diff_lon > 1.e-2) then + if (diff_lon > eps_omesh) then frmt = "('ERROR: MOM n, lonMesh(n), lon(n), diff_lon = ',i8,2(f21.13,3x),d21.5)" write(6,frmt)n,lonMesh(n),lon(n), diff_lon !call shr_sys_abort() end if diff_lat = abs(latMesh(n) - lat(n)) - if (diff_lat > 1.e-2) then + if (diff_lat > eps_omesh) then frmt = "('ERROR: MOM n, latMesh(n), lat(n), diff_lat = ',i8,2(f21.13,3x),d21.5)" write(6,frmt)n,latMesh(n),lat(n), diff_lat !call shr_sys_abort() From d9a00d78175cc034aff47ae4fb0ff4f9f57af897 Mon Sep 17 00:00:00 2001 From: alperaltuntas Date: Wed, 28 Aug 2019 17:41:01 -0600 Subject: [PATCH 5/7] call MOM_error if mesh is inconsistent --- config_src/nuopc_driver/mom_cap.F90 | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/config_src/nuopc_driver/mom_cap.F90 b/config_src/nuopc_driver/mom_cap.F90 index 642a7eb809..25dd9bde76 100644 --- a/config_src/nuopc_driver/mom_cap.F90 +++ b/config_src/nuopc_driver/mom_cap.F90 @@ -322,7 +322,6 @@ module MOM_cap_mod use mpp_domains_mod, only: mpp_get_ntile_count, mpp_get_pelist, mpp_get_global_domain use mpp_domains_mod, only: mpp_get_domain_npes use mpp_io_mod, only: mpp_open, MPP_RDONLY, MPP_ASCII, MPP_OVERWR, MPP_APPEND, mpp_close, MPP_SINGLE -use mpp_mod, only: input_nml_file, mpp_error, FATAL, NOTE, mpp_pe, mpp_npes, mpp_set_current_pelist use mpp_mod, only: stdlog, stdout, mpp_root_pe, mpp_clock_id use mpp_mod, only: mpp_clock_begin, mpp_clock_end, MPP_CLOCK_SYNC use mpp_mod, only: MPP_CLOCK_DETAILED, CLOCK_COMPONENT, MAXPES @@ -339,7 +338,7 @@ module MOM_cap_mod use MOM_file_parser, only: get_param, log_version, param_file_type, close_param_file use MOM_get_input, only: Get_MOM_Input, directories use MOM_domains, only: pass_var -use MOM_error_handler, only: is_root_pe +use MOM_error_handler, only: MOM_error, FATAL, is_root_pe use MOM_ocean_model_nuopc, only: ice_ocean_boundary_type use MOM_grid, only: ocean_grid_type, get_global_grid_size use MOM_ocean_model_nuopc, only: ocean_model_restart, ocean_public_type, ocean_state_type @@ -1182,7 +1181,8 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) integer, allocatable :: gindex(:) ! global index space character(len=128) :: fldname character(len=256) :: cvalue - character(len=256) :: frmt ! format specifier for several error msgs + character(len=256) :: frmt ! format specifier for several error msgs + character(len=512) :: err_msg ! error messages character(len=*), parameter :: subname='(MOM_cap:InitializeRealize)' integer :: spatialDim integer :: numOwnedElements @@ -1388,20 +1388,23 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) do n = 1,numOwnedElements diff_lon = abs(lonMesh(n) - lon(n)) if (diff_lon > eps_omesh) then - frmt = "('ERROR: MOM n, lonMesh(n), lon(n), diff_lon = ',i8,2(f21.13,3x),d21.5)" - write(6,frmt)n,lonMesh(n),lon(n), diff_lon - !call shr_sys_abort() + frmt = "('ERROR: Inconsistent coords - "//& + "MOM n, lonMesh(n), lon(n), diff_lon = ',i8,2(f21.13,3x),d21.5)" + write(err_msg, frmt)n,lonMesh(n),lon(n), diff_lon + call MOM_error(FATAL, err_msg) end if diff_lat = abs(latMesh(n) - lat(n)) if (diff_lat > eps_omesh) then - frmt = "('ERROR: MOM n, latMesh(n), lat(n), diff_lat = ',i8,2(f21.13,3x),d21.5)" - write(6,frmt)n,latMesh(n),lat(n), diff_lat - !call shr_sys_abort() + frmt = "('ERROR: Inconsistent coords - "//& + "MOM n, latMesh(n), lat(n), diff_lat = ',i8,2(f21.13,3x),d21.5)" + write(err_msg, frmt)n,latMesh(n),lat(n), diff_lat + call MOM_error(FATAL, err_msg) end if if (abs(maskMesh(n) - mask(n)) > 0) then - frmt = "('ERROR: MOM n, maskMesh(n), mask(n) = ',3(i8,2x))" - write(6,frmt)n,maskMesh(n),mask(n) - !call shr_sys_abort() + frmt = "('ERROR: Inconsistent masks - "//& + "MOM n, maskMesh(n), mask(n) = ',3(i8,2x))" + write(err_msg, frmt)n,maskMesh(n),mask(n) + call MOM_error(FATAL, err_msg) end if end do From e02b358ad6cb742de74cb84f7d6033ca9ad01779 Mon Sep 17 00:00:00 2001 From: alperaltuntas Date: Thu, 29 Aug 2019 11:46:23 -0600 Subject: [PATCH 6/7] compare mod 360 of diff and eps --- config_src/nuopc_driver/mom_cap.F90 | 2 +- config_src/nuopc_driver/mom_ocean_model_nuopc.F90 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config_src/nuopc_driver/mom_cap.F90 b/config_src/nuopc_driver/mom_cap.F90 index 25dd9bde76..d9400e0560 100644 --- a/config_src/nuopc_driver/mom_cap.F90 +++ b/config_src/nuopc_driver/mom_cap.F90 @@ -1386,7 +1386,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) eps_omesh = get_eps_omesh(ocean_state) do n = 1,numOwnedElements - diff_lon = abs(lonMesh(n) - lon(n)) + diff_lon = abs(mod(lonMesh(n) - lon(n),360.0)) if (diff_lon > eps_omesh) then frmt = "('ERROR: Inconsistent coords - "//& "MOM n, lonMesh(n), lon(n), diff_lon = ',i8,2(f21.13,3x),d21.5)" diff --git a/config_src/nuopc_driver/mom_ocean_model_nuopc.F90 b/config_src/nuopc_driver/mom_ocean_model_nuopc.F90 index 83dfa0a4f8..426c7e9922 100644 --- a/config_src/nuopc_driver/mom_ocean_model_nuopc.F90 +++ b/config_src/nuopc_driver/mom_ocean_model_nuopc.F90 @@ -334,7 +334,7 @@ subroutine ocean_model_init(Ocean_sfc, OS, Time_init, Time_in, gas_fields_ocn, i call get_param(param_file, mdl, "EPS_OMESH",OS%eps_omesh, & "Maximum allowable difference between ESMF mesh and "//& "MOM6 domain coordinates in nuopc cap.", & - units="degrees", default=1.e-2) + units="degrees", default=1.e-4) call get_param(param_file, mdl, "RESTORE_SALINITY",OS%restore_salinity, & "If true, the coupled driver will add a globally-balanced "//& "fresh-water flux that drives sea-surface salinity "//& From 7f7e8c081b6660031c0c6233c8b82c82607cb44f Mon Sep 17 00:00:00 2001 From: alperaltuntas Date: Thu, 29 Aug 2019 15:28:43 -0600 Subject: [PATCH 7/7] Add EPS_OMESH value in error message --- config_src/nuopc_driver/mom_cap.F90 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/config_src/nuopc_driver/mom_cap.F90 b/config_src/nuopc_driver/mom_cap.F90 index d9400e0560..0caee9510e 100644 --- a/config_src/nuopc_driver/mom_cap.F90 +++ b/config_src/nuopc_driver/mom_cap.F90 @@ -1388,20 +1388,22 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc) do n = 1,numOwnedElements diff_lon = abs(mod(lonMesh(n) - lon(n),360.0)) if (diff_lon > eps_omesh) then - frmt = "('ERROR: Inconsistent coords - "//& - "MOM n, lonMesh(n), lon(n), diff_lon = ',i8,2(f21.13,3x),d21.5)" - write(err_msg, frmt)n,lonMesh(n),lon(n), diff_lon + frmt = "('ERROR: Difference between ESMF Mesh and MOM6 domain coords is "//& + "greater than parameter EPS_OMESH. n, lonMesh(n), lon(n), diff_lon, "//& + "EPS_OMESH= ',i8,2(f21.13,3x),2(d21.5))" + write(err_msg, frmt)n,lonMesh(n),lon(n), diff_lon, eps_omesh call MOM_error(FATAL, err_msg) end if diff_lat = abs(latMesh(n) - lat(n)) if (diff_lat > eps_omesh) then - frmt = "('ERROR: Inconsistent coords - "//& - "MOM n, latMesh(n), lat(n), diff_lat = ',i8,2(f21.13,3x),d21.5)" - write(err_msg, frmt)n,latMesh(n),lat(n), diff_lat + frmt = "('ERROR: Difference between ESMF Mesh and MOM6 domain coords is"//& + "greater than parameter EPS_OMESH. n, latMesh(n), lat(n), diff_lat, "//& + "EPS_OMESH= ',i8,2(f21.13,3x),2(d21.5))" + write(err_msg, frmt)n,latMesh(n),lat(n), diff_lat, eps_omesh call MOM_error(FATAL, err_msg) end if if (abs(maskMesh(n) - mask(n)) > 0) then - frmt = "('ERROR: Inconsistent masks - "//& + frmt = "('ERROR: ESMF mesh and MOM6 domain masks are inconsistent! - "//& "MOM n, maskMesh(n), mask(n) = ',3(i8,2x))" write(err_msg, frmt)n,maskMesh(n),mask(n) call MOM_error(FATAL, err_msg)