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

Recover topography clipping when not specifying MINIMUM_DEPTH #1517

Merged
merged 2 commits into from
Oct 12, 2021
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
11 changes: 3 additions & 8 deletions src/initialization/MOM_grid_initialize.F90
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module MOM_grid_initialize
use MOM_domains, only : To_North, To_South, To_East, To_West
use MOM_domains, only : MOM_domain_type, clone_MOM_domain, deallocate_MOM_domain
use MOM_dyn_horgrid, only : dyn_horgrid_type, set_derived_dyn_horgrid
use MOM_error_handler, only : MOM_error, MOM_mesg, FATAL, WARNING, is_root_pe
use MOM_error_handler, only : MOM_error, MOM_mesg, FATAL, is_root_pe
use MOM_error_handler, only : callTree_enter, callTree_leave
use MOM_file_parser, only : get_param, log_param, log_version, param_file_type
use MOM_io, only : MOM_read_data, slasher, file_exists, stdout
Expand Down Expand Up @@ -1219,15 +1219,10 @@ subroutine initialize_masks(G, PF, US)
units="m", default=0.0, scale=m_to_Z_scale)
call get_param(PF, mdl, "MASKING_DEPTH", mask_depth, &
"The depth below which to mask points as land points, for which all "//&
"fluxes are zeroed out. MASKING_DEPTH needs to be smaller than MINIMUM_DEPTH", &
"fluxes are zeroed out. MASKING_DEPTH is ignored if it has the special "//&
"default value.", &
units="m", default=-9999.0, scale=m_to_Z_scale)

if (mask_depth > min_depth) then
mask_depth = -9999.0*m_to_Z_scale
call MOM_error(WARNING, "MOM_grid_init: initialize_masks "//&
'MASKING_DEPTH is larger than MINIMUM_DEPTH and therefore ignored.')
endif

Dmask = mask_depth
if (mask_depth == -9999.*m_to_Z_scale) Dmask = min_depth

Expand Down
48 changes: 28 additions & 20 deletions src/initialization/MOM_shared_initialization.F90
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ subroutine apply_topography_edits_from_file(D, G, param_file, US)
character(len=40) :: mdl = "apply_topography_edits_from_file" ! This subroutine's name.
integer :: i, j, n, ncid, n_edits, i_file, j_file, ndims, sizes(8)
logical :: topo_edits_change_mask
real :: min_depth, mask_depth
real :: min_depth ! The shallowest value of wet points [Z ~> m]
real :: mask_depth ! The depth defining the land-sea boundary [Z ~> m]

call callTree_enter(trim(mdl)//"(), MOM_shared_initialization.F90")

Expand All @@ -218,7 +219,8 @@ subroutine apply_topography_edits_from_file(D, G, param_file, US)
units="m", default=0.0, scale=m_to_Z)
call get_param(param_file, mdl, "MASKING_DEPTH", mask_depth, &
"The depth below which to mask points as land points, for which all "//&
"fluxes are zeroed out. MASKING_DEPTH needs to be smaller than MINIMUM_DEPTH", &
"fluxes are zeroed out. MASKING_DEPTH is ignored if it has the special "//&
"default value.", &
units="m", default=-9999.0, scale=m_to_Z)
if (mask_depth == -9999.*m_to_Z) mask_depth = min_depth

Expand Down Expand Up @@ -408,7 +410,8 @@ subroutine limit_topography(D, G, param_file, max_depth, US)
real :: m_to_Z ! A dimensional rescaling factor.
integer :: i, j
character(len=40) :: mdl = "limit_topography" ! This subroutine's name.
real :: min_depth, mask_depth
real :: min_depth ! The shallowest value of wet points [Z ~> m]
real :: mask_depth ! The depth defining the land-sea boundary [Z ~> m]

call callTree_enter(trim(mdl)//"(), MOM_shared_initialization.F90")

Expand All @@ -421,34 +424,39 @@ subroutine limit_topography(D, G, param_file, max_depth, US)
"MINIMUM_DEPTH but deeper than MASKING_DEPTH are rounded to MINIMUM_DEPTH.", &
units="m", default=0.0, scale=m_to_Z)
call get_param(param_file, mdl, "MASKING_DEPTH", mask_depth, &
"The depth below which to mask the ocean as land.", &
"The depth below which to mask points as land points, for which all "//&
"fluxes are zeroed out. MASKING_DEPTH is ignored if it has the special "//&
"default value.", &
units="m", default=-9999.0, scale=m_to_Z, do_not_log=.true.)

if (mask_depth > min_depth) then
mask_depth = -9999.0*m_to_Z
call MOM_error(WARNING, "MOM_shared_initialization: limit_topography "//&
'MASKING_DEPTH is larger than MINIMUM_DEPTH and therefore ignored.')
endif

! Make sure that min_depth < D(x,y) < max_depth for ocean points
! TBD: The following f.p. equivalence uses a special value. Originally, any negative value
! indicated the branch. We should create a logical flag to indicate this branch.
if (mask_depth == -9999.*m_to_Z) then
if (min_depth > 0.0) then ! This is retained to avoid answer changes (over the land points) in the test cases.
do j=G%jsd,G%jed ; do i=G%isd,G%ied
D(i,j) = min( max( D(i,j), 0.5*min_depth ), max_depth )
enddo ; enddo
else
do j=G%jsd,G%jed ; do i=G%isd,G%ied
D(i,j) = min( max( D(i,j), min_depth ), max_depth )
enddo ; enddo
if (min_depth<0.) then
call MOM_error(FATAL, trim(mdl)//": MINIMUM_DEPTH<0 does not work as expected "//&
"unless MASKING_DEPTH has been set appropriately. Set a meaningful "//&
"MASKING_DEPTH to enabled negative depths (land elevations) and to "//&
"enable flooding.")
endif
! This is the old path way. The 0.5*min_depth is obscure and is retained to be
! backward reproducible. If you are looking at the following line you should probably
! set MASKING_DEPTH. This path way does not work for negative depths, i.e. flooding.
do j=G%jsd,G%jed ; do i=G%isd,G%ied
D(i,j) = min( max( D(i,j), 0.5*min_depth ), max_depth )
enddo ; enddo
else
! This is the preferred path way.
! mask_depth has a meaningful value; anything shallower than mask_depth is land.
! If min_depth<mask_depth (which happens when using positive depths and not changing
! MINIMUM_DEPTH) then the shallower is used to modify and determine values on land points.
do j=G%jsd,G%jed ; do i=G%isd,G%ied
if (D(i,j) > mask_depth) then
if (D(i,j) > min(min_depth,mask_depth)) then
D(i,j) = min( max( D(i,j), min_depth ), max_depth )
else
! This statement is required for cases with masked-out PEs over the land,
! to remove the large initialized values (-9e30) from the halos.
D(i,j) = mask_depth
D(i,j) = min(min_depth,mask_depth)
endif
enddo ; enddo
endif
Expand Down