Skip to content

Commit 3a0725d

Browse files
authored
Merge pull request #1457 from herrwang0/fix-topoinit_2
Bugfix: a couple of mask_depth related issues
2 parents ffe1900 + a77817d commit 3a0725d

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/initialization/MOM_grid_initialize.F90

+9-9
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ end function Adcroft_reciprocal
11871187
!> Initializes the grid masks and any metrics that come with masks already applied.
11881188
!!
11891189
!! Initialize_masks sets mask2dT, mask2dCu, mask2dCv, and mask2dBu to mask out
1190-
!! flow over any points which are shallower than Dmin and permit an
1190+
!! flow over any points which are shallower than Dmask and permit an
11911191
!! appropriate treatment of the boundary conditions. mask2dCu and mask2dCv
11921192
!! are 0.0 at any points adjacent to a land point. mask2dBu is 0.0 at
11931193
!! any land or boundary point. For points in the interior, mask2dCu,
@@ -1199,7 +1199,7 @@ subroutine initialize_masks(G, PF, US)
11991199
! Local variables
12001200
real :: m_to_Z_scale ! A unit conversion factor from m to Z.
12011201
real :: m_to_L ! A unit conversion factor [L m-1 ~> nondim]
1202-
real :: Dmin ! The depth for masking in the same units as G%bathyT [Z ~> m].
1202+
real :: Dmask ! The depth for masking in the same units as G%bathyT [Z ~> m].
12031203
real :: min_depth ! The minimum ocean depth in the same units as G%bathyT [Z ~> m].
12041204
real :: mask_depth ! The depth shallower than which to mask a point as land [Z ~> m].
12051205
character(len=40) :: mdl = "MOM_grid_init initialize_masks"
@@ -1226,39 +1226,39 @@ subroutine initialize_masks(G, PF, US)
12261226
'MASKING_DEPTH is larger than MINIMUM_DEPTH and therefore ignored.')
12271227
endif
12281228

1229-
Dmin = min_depth
1230-
if (mask_depth /= -9999.*m_to_Z_scale) Dmin = mask_depth
1229+
Dmask = mask_depth
1230+
if (mask_depth == -9999.*m_to_Z_scale) Dmask = min_depth
12311231

12321232
G%mask2dCu(:,:) = 0.0 ; G%mask2dCv(:,:) = 0.0 ; G%mask2dBu(:,:) = 0.0
12331233

12341234
! Construct the h-point or T-point mask
12351235
do j=G%jsd,G%jed ; do i=G%isd,G%ied
1236-
if (G%bathyT(i,j) <= Dmin) then
1236+
if (G%bathyT(i,j) <= Dmask) then
12371237
G%mask2dT(i,j) = 0.0
12381238
else
12391239
G%mask2dT(i,j) = 1.0
12401240
endif
12411241
enddo ; enddo
12421242

12431243
do j=G%jsd,G%jed ; do I=G%isd,G%ied-1
1244-
if ((G%bathyT(i,j) <= Dmin) .or. (G%bathyT(i+1,j) <= Dmin)) then
1244+
if ((G%bathyT(i,j) <= Dmask) .or. (G%bathyT(i+1,j) <= Dmask)) then
12451245
G%mask2dCu(I,j) = 0.0
12461246
else
12471247
G%mask2dCu(I,j) = 1.0
12481248
endif
12491249
enddo ; enddo
12501250

12511251
do J=G%jsd,G%jed-1 ; do i=G%isd,G%ied
1252-
if ((G%bathyT(i,j) <= Dmin) .or. (G%bathyT(i,j+1) <= Dmin)) then
1252+
if ((G%bathyT(i,j) <= Dmask) .or. (G%bathyT(i,j+1) <= Dmask)) then
12531253
G%mask2dCv(i,J) = 0.0
12541254
else
12551255
G%mask2dCv(i,J) = 1.0
12561256
endif
12571257
enddo ; enddo
12581258

12591259
do J=G%jsd,G%jed-1 ; do I=G%isd,G%ied-1
1260-
if ((G%bathyT(i+1,j) <= Dmin) .or. (G%bathyT(i+1,j+1) <= Dmin) .or. &
1261-
(G%bathyT(i,j) <= Dmin) .or. (G%bathyT(i,j+1) <= Dmin)) then
1260+
if ((G%bathyT(i+1,j) <= Dmask) .or. (G%bathyT(i+1,j+1) <= Dmask) .or. &
1261+
(G%bathyT(i,j) <= Dmask) .or. (G%bathyT(i,j+1) <= Dmask)) then
12621262
G%mask2dBu(I,J) = 0.0
12631263
else
12641264
G%mask2dBu(I,J) = 1.0

src/initialization/MOM_shared_initialization.F90

+17-2
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ subroutine apply_topography_edits_from_file(D, G, param_file, US)
195195
character(len=200) :: topo_edits_file, inputdir ! Strings for file/path
196196
character(len=40) :: mdl = "apply_topography_edits_from_file" ! This subroutine's name.
197197
integer :: i, j, n, ncid, n_edits, i_file, j_file, ndims, sizes(8)
198-
logical :: found
199198
logical :: topo_edits_change_mask
199+
real :: min_depth, mask_depth
200200

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

@@ -210,6 +210,17 @@ subroutine apply_topography_edits_from_file(D, G, param_file, US)
210210
call get_param(param_file, mdl, "ALLOW_LANDMASK_CHANGES", topo_edits_change_mask, &
211211
"If true, allow topography overrides to change land mask.", &
212212
default=.false.)
213+
call get_param(param_file, mdl, "MINIMUM_DEPTH", min_depth, &
214+
"If MASKING_DEPTH is unspecified, then anything shallower than "//&
215+
"MINIMUM_DEPTH is assumed to be land and all fluxes are masked out. "//&
216+
"If MASKING_DEPTH is specified, then all depths shallower than "//&
217+
"MINIMUM_DEPTH but deeper than MASKING_DEPTH are rounded to MINIMUM_DEPTH.", &
218+
units="m", default=0.0, scale=m_to_Z)
219+
call get_param(param_file, mdl, "MASKING_DEPTH", mask_depth, &
220+
"The depth below which to mask points as land points, for which all "//&
221+
"fluxes are zeroed out. MASKING_DEPTH needs to be smaller than MINIMUM_DEPTH", &
222+
units="m", default=-9999.0, scale=m_to_Z)
223+
if (mask_depth == -9999.*m_to_Z) mask_depth = min_depth
213224

214225
if (len_trim(topo_edits_file)==0) return
215226

@@ -249,7 +260,7 @@ subroutine apply_topography_edits_from_file(D, G, param_file, US)
249260
i = ig(n) - G%isd_global + 2 ! +1 for python indexing and +1 for ig-isd_global+1
250261
j = jg(n) - G%jsd_global + 2
251262
if (i>=G%isc .and. i<=G%iec .and. j>=G%jsc .and. j<=G%jec) then
252-
if (new_depth(n)/=0.) then
263+
if (new_depth(n)*m_to_Z /= mask_depth) then
253264
write(stdout,'(a,3i5,f8.2,a,f8.2,2i4)') &
254265
'Ocean topography edit: ', n, ig(n), jg(n), D(i,j)/m_to_Z, '->', abs(new_depth(n)), i, j
255266
D(i,j) = abs(m_to_Z*new_depth(n)) ! Allows for height-file edits (i.e. converts negatives)
@@ -434,6 +445,10 @@ subroutine limit_topography(D, G, param_file, max_depth, US)
434445
do j=G%jsd,G%jed ; do i=G%isd,G%ied
435446
if (D(i,j) > mask_depth) then
436447
D(i,j) = min( max( D(i,j), min_depth ), max_depth )
448+
else
449+
! This statement is required for cases with masked-out PEs over the land,
450+
! to remove the large initialized values (-9e30) from the halos.
451+
D(i,j) = mask_depth
437452
endif
438453
enddo ; enddo
439454
endif

0 commit comments

Comments
 (0)