Skip to content

Commit 87cba40

Browse files
committed
Support for _d3 and _d4 diagnostics
1 parent aefec49 commit 87cba40

4 files changed

Lines changed: 100 additions & 78 deletions

File tree

config_src/infra/FMS2/MOM_diag_manager_infra.F90

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
module MOM_diag_manager_infra
88

99
! This file is part of MOM6. See LICENSE.md for the license.
10+
#define MAX_DSAMP_LEV 3
1011

1112
use, intrinsic :: iso_fortran_env, only : real64
1213
use diag_axis_mod, only : fms_axis_init=>diag_axis_init
@@ -114,10 +115,10 @@ integer function MOM_diag_axis_init(name, data, units, cart_name, long_name, MOM
114115
MOM_diag_axis_init = fms_axis_init(name, data, units, cart_name, long_name=long_name, &
115116
direction=direction, set_name=set_name, edges=edges, &
116117
domain2=MOM_domain%mpp_domain, domain_position=position)
117-
elseif (coarsening == 2) then
118+
elseif (coarsening <= MAX_DSAMP_LEV) then
118119
MOM_diag_axis_init = fms_axis_init(name, data, units, cart_name, long_name=long_name, &
119120
direction=direction, set_name=set_name, edges=edges, &
120-
domain2=MOM_domain%mpp_domain_d2, domain_position=position)
121+
domain2=MOM_domain%mpp_domain_d(coarsening), domain_position=position)
121122
else
122123
call MOM_error(FATAL, "diag_axis_init called with an invalid value of coarsen.")
123124
endif

config_src/infra/FMS2/MOM_domain_infra.F90

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module MOM_domain_infra
3232

3333
! The `group_pass_type` fields are never accessed, so we keep it as an FMS type
3434
use mpp_domains_mod, only : group_pass_type => mpp_group_update_type
35+
#define MAX_DSAMP_LEV 3
3536

3637
implicit none ; private
3738

@@ -131,7 +132,7 @@ module MOM_domain_infra
131132
character(len=64) :: name !< The name of this domain
132133
type(domain2D), pointer :: mpp_domain => NULL() !< The FMS domain with halos
133134
!! on this processor, centered at h points.
134-
type(domain2D), pointer :: mpp_domain_d2 => NULL() !< A coarse FMS domain with halos
135+
type(domain2D), pointer :: mpp_domain_d(:) => NULL() !< A coarse FMS domain with halos
135136
!! on this processor, centered at h points.
136137
integer :: niglobal !< The total horizontal i-domain size.
137138
integer :: njglobal !< The total horizontal j-domain size.
@@ -1369,14 +1370,14 @@ subroutine create_MOM_domain(MOM_dom, n_global, n_halo, reentrant, tripolar_N, l
13691370
integer, dimension(4) :: global_indices ! The lower and upper global i- and j-index bounds
13701371
integer :: X_FLAGS ! A combination of integers encoding the x-direction grid connectivity.
13711372
integer :: Y_FLAGS ! A combination of integers encoding the y-direction grid connectivity.
1372-
integer :: xhalo_d2, yhalo_d2
1373+
integer :: dl
13731374
character(len=200) :: mesg ! A string for use in error messages
13741375
logical :: mask_table_exists ! Mask_table is present and the file it points to exists
13751376

13761377
if (.not.associated(MOM_dom)) then
13771378
allocate(MOM_dom)
13781379
allocate(MOM_dom%mpp_domain)
1379-
allocate(MOM_dom%mpp_domain_d2)
1380+
do dl=2,MAX_DSAMP_LEV ; allocate(MOM_dom%mpp_domain_d(dl)) ; enddo
13801381
endif
13811382

13821383
MOM_dom%name = "MOM" ; if (present(domain_name)) MOM_dom%name = trim(domain_name)
@@ -1448,7 +1449,9 @@ subroutine create_MOM_domain(MOM_dom, n_global, n_halo, reentrant, tripolar_N, l
14481449
!But that does not work because the downsampled field would not have the correct size to pass the checks, e.g., we get
14491450
!error: downsample_diag_indices_get: peculiar size 28 in i-direction\ndoes not match one of 24 25 26 27
14501451
! call clone_MD_to_d2D(MOM_dom, MOM_dom%mpp_domain_d2, halo_size=(MOM_dom%nihalo/2), coarsen=2)
1451-
call clone_MD_to_d2D(MOM_dom, MOM_dom%mpp_domain_d2, coarsen=2)
1452+
do dl=2,MAX_DSAMP_LEV
1453+
call clone_MD_to_d2D(MOM_dom, MOM_dom%mpp_domain_d(dl), coarsen=dl)
1454+
enddo
14521455
end subroutine create_MOM_domain
14531456

14541457
!> dealloc_MOM_domain deallocates memory associated with a pointer to a MOM_domain_type
@@ -1458,6 +1461,7 @@ subroutine deallocate_MOM_domain(MOM_domain, cursory)
14581461
logical, optional, intent(in) :: cursory !< If true do not deallocate fields associated
14591462
!! with the underlying infrastructure
14601463
logical :: invasive ! If true, deallocate fields associated with the underlying infrastructure
1464+
integer :: dl
14611465

14621466
invasive = .true. ; if (present(cursory)) invasive = .not.cursory
14631467

@@ -1466,9 +1470,11 @@ subroutine deallocate_MOM_domain(MOM_domain, cursory)
14661470
if (invasive) call mpp_deallocate_domain(MOM_domain%mpp_domain)
14671471
deallocate(MOM_domain%mpp_domain)
14681472
endif
1469-
if (associated(MOM_domain%mpp_domain_d2)) then
1470-
if (invasive) call mpp_deallocate_domain(MOM_domain%mpp_domain_d2)
1471-
deallocate(MOM_domain%mpp_domain_d2)
1473+
if (associated(MOM_domain%mpp_domain_d)) then
1474+
if (invasive) then
1475+
do dl=2,MAX_DSAMP_LEV ; call mpp_deallocate_domain(MOM_domain%mpp_domain_d(dl)); enddo
1476+
endif
1477+
deallocate(MOM_domain%mpp_domain_d)
14721478
endif
14731479
if (associated(MOM_domain%maskmap)) deallocate(MOM_domain%maskmap)
14741480
deallocate(MOM_domain)
@@ -1565,7 +1571,7 @@ subroutine clone_MD_to_MD(MD_in, MOM_dom, min_halo, halo_size, symmetric, domain
15651571
integer, dimension(:), allocatable :: exnj ! The extents of the grid for each j-row of the layout.
15661572
! The sum of exni must equal MOM_dom%niglobal.
15671573
integer :: qturns ! The number of quarter turns, restricted to the range of 0 to 3.
1568-
integer :: i, j, nl1, nl2
1574+
integer :: i, j, nl1, nl2, dl
15691575
integer :: io_layout_in(2)
15701576

15711577
qturns = 0
@@ -1580,7 +1586,7 @@ subroutine clone_MD_to_MD(MD_in, MOM_dom, min_halo, halo_size, symmetric, domain
15801586
if (.not.associated(MOM_dom)) then
15811587
allocate(MOM_dom)
15821588
allocate(MOM_dom%mpp_domain)
1583-
allocate(MOM_dom%mpp_domain_d2)
1589+
do dl=2,MAX_DSAMP_LEV ; allocate(MOM_dom%mpp_domain_d(dl)) ; enddo
15841590
endif
15851591

15861592
! Save the extra data for creating other domains of different resolution that overlay this domain
@@ -1702,7 +1708,9 @@ subroutine clone_MD_to_MD(MD_in, MOM_dom, min_halo, halo_size, symmetric, domain
17021708
endif
17031709

17041710
call clone_MD_to_d2D(MOM_dom, MOM_dom%mpp_domain, xextent=exni, yextent=exnj)
1705-
call clone_MD_to_d2D(MOM_dom, MOM_dom%mpp_domain_d2, domain_name=MOM_dom%name, coarsen=2)
1711+
do dl=2,MAX_DSAMP_LEV
1712+
call clone_MD_to_d2D(MOM_dom, MOM_dom%mpp_domain_d(dl), domain_name=MOM_dom%name, coarsen=dl)
1713+
enddo
17061714

17071715
end subroutine clone_MD_to_MD
17081716

@@ -1840,12 +1848,12 @@ subroutine get_domain_extent_MD(Domain, isc, iec, jsc, jec, isd, ied, jsd, jed,
18401848
call mpp_get_compute_domain(Domain%mpp_domain, isc, iec, jsc, jec)
18411849
call mpp_get_data_domain(Domain%mpp_domain, isd, ied, jsd, jed)
18421850
call mpp_get_global_domain(Domain%mpp_domain, isg_, ieg_, jsg_, jeg_)
1843-
elseif (coarsen_lev == 2) then
1844-
if (.not.associated(Domain%mpp_domain_d2)) call MOM_error(FATAL, &
1845-
"get_domain_extent called with coarsen=2, but Domain%mpp_domain_d2 is not associated.")
1846-
call mpp_get_compute_domain(Domain%mpp_domain_d2, isc, iec, jsc, jec)
1847-
call mpp_get_data_domain(Domain%mpp_domain_d2, isd, ied, jsd, jed)
1848-
call mpp_get_global_domain(Domain%mpp_domain_d2, isg_, ieg_, jsg_, jeg_)
1851+
elseif (coarsen_lev <= MAX_DSAMP_LEV) then
1852+
if (.not.associated(Domain%mpp_domain_d)) call MOM_error(FATAL, &
1853+
"get_domain_extent called with coarsen_lev, but Domain%mpp_domain_d(coarsen_lev) is not associated.")
1854+
call mpp_get_compute_domain(Domain%mpp_domain_d(coarsen_lev), isc, iec, jsc, jec)
1855+
call mpp_get_data_domain(Domain%mpp_domain_d(coarsen_lev), isd, ied, jsd, jed)
1856+
call mpp_get_global_domain(Domain%mpp_domain_d(coarsen_lev), isg_, ieg_, jsg_, jeg_)
18491857
else
18501858
call MOM_error(FATAL, "get_domain_extent called with an unsupported level of coarsening.")
18511859
endif

src/core/MOM_grid.F90

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module MOM_grid
1313
implicit none ; private
1414

1515
#include <MOM_memory.h>
16+
#define MAX_DSAMP_LEV 3
1617

1718
public MOM_grid_init, MOM_grid_end, set_derived_metrics, set_first_direction
1819
public isPointInCell, hor_index_type, get_global_grid_size
@@ -27,7 +28,7 @@ module MOM_grid
2728
type(MOM_domain_type), pointer :: Domain => NULL() !< Ocean model domain
2829
type(MOM_domain_type), pointer :: Domain_aux => NULL() !< A non-symmetric auxiliary domain type.
2930
type(hor_index_type) :: HI !< Horizontal index ranges
30-
type(hor_index_type) :: HId2 !< Horizontal index ranges for level-2-downsampling
31+
type(hor_index_type) :: HId(2:MAX_DSAMP_LEV) !< Horizontal index ranges for downsampling, level 2 to MAX_DSAMP_LEV.
3132

3233
integer :: isc !< The start i-index of cell centers within the computational domain
3334
integer :: iec !< The end i-index of cell centers within the computational domain
@@ -235,7 +236,7 @@ subroutine MOM_grid_init(G, param_file, US, HI, global_indexing, bathymetry_at_v
235236
integer :: isd, ied, jsd, jed
236237
integer :: IsdB, IedB, JsdB, JedB
237238
integer :: ied_max, jed_max
238-
integer :: niblock, njblock, nihalo, njhalo, nblocks, n, i, j
239+
integer :: niblock, njblock, nihalo, njhalo, nblocks, n, i, j, dl
239240
logical :: local_indexing ! If false use global index values instead of having
240241
! the data domain on each processor start at 1.
241242
! This include declares and sets the variable "version".
@@ -400,22 +401,25 @@ subroutine MOM_grid_init(G, param_file, US, HI, global_indexing, bathymetry_at_v
400401
if ( G%block(nblocks)%jed+G%block(nblocks)%jdg_offset > G%HI%jed + G%HI%jdg_offset ) &
401402
call MOM_error(FATAL, "MOM_grid_init: G%jed_bk > G%jed")
402403

403-
call get_domain_extent(G%Domain, G%HId2%isc, G%HId2%iec, G%HId2%jsc, G%HId2%jec, &
404-
G%HId2%isd, G%HId2%ied, G%HId2%jsd, G%HId2%jed, &
405-
G%HId2%isg, G%HId2%ieg, G%HId2%jsg, G%HId2%jeg, coarsen=2)
404+
! Initialize the global grid extents for all levels of diagnosics coarsening.
405+
do dl=2,MAX_DSAMP_LEV
406+
call get_domain_extent(G%Domain, G%HId(dl)%isc, G%HId(dl)%iec, G%HId(dl)%jsc, G%HId(dl)%jec, &
407+
G%HId(dl)%isd, G%HId(dl)%ied, G%HId(dl)%jsd, G%HId(dl)%jed, &
408+
G%HId(dl)%isg, G%HId(dl)%ieg, G%HId(dl)%jsg, G%HId(dl)%jeg, coarsen=dl)
406409

407-
! Set array sizes for fields that are discretized at tracer cell boundaries.
408-
G%HId2%IscB = G%HId2%isc ; G%HId2%JscB = G%HId2%jsc
409-
G%HId2%IsdB = G%HId2%isd ; G%HId2%JsdB = G%HId2%jsd
410-
G%HId2%IsgB = G%HId2%isg ; G%HId2%JsgB = G%HId2%jsg
411-
if (G%symmetric) then
412-
G%HId2%IscB = G%HId2%isc-1 ; G%HId2%JscB = G%HId2%jsc-1
413-
G%HId2%IsdB = G%HId2%isd-1 ; G%HId2%JsdB = G%HId2%jsd-1
414-
G%HId2%IsgB = G%HId2%isg-1 ; G%HId2%JsgB = G%HId2%jsg-1
415-
endif
416-
G%HId2%IecB = G%HId2%iec ; G%HId2%JecB = G%HId2%jec
417-
G%HId2%IedB = G%HId2%ied ; G%HId2%JedB = G%HId2%jed
418-
G%HId2%IegB = G%HId2%ieg ; G%HId2%JegB = G%HId2%jeg
410+
! Set array sizes for fields that are discretized at tracer cell boundaries.
411+
G%HId(dl)%IscB = G%HId(dl)%isc ; G%HId(dl)%JscB = G%HId(dl)%jsc
412+
G%HId(dl)%IsdB = G%HId(dl)%isd ; G%HId(dl)%JsdB = G%HId(dl)%jsd
413+
G%HId(dl)%IsgB = G%HId(dl)%isg ; G%HId(dl)%JsgB = G%HId(dl)%jsg
414+
if (G%symmetric) then
415+
G%HId(dl)%IscB = G%HId(dl)%isc-1 ; G%HId(dl)%JscB = G%HId(dl)%jsc-1
416+
G%HId(dl)%IsdB = G%HId(dl)%isd-1 ; G%HId(dl)%JsdB = G%HId(dl)%jsd-1
417+
G%HId(dl)%IsgB = G%HId(dl)%isg-1 ; G%HId(dl)%JsgB = G%HId(dl)%jsg-1
418+
endif
419+
G%HId(dl)%IecB = G%HId(dl)%iec ; G%HId(dl)%JecB = G%HId(dl)%jec
420+
G%HId(dl)%IedB = G%HId(dl)%ied ; G%HId(dl)%JedB = G%HId(dl)%jed
421+
G%HId(dl)%IegB = G%HId(dl)%ieg ; G%HId(dl)%JegB = G%HId(dl)%jeg
422+
enddo
419423

420424
end subroutine MOM_grid_init
421425

0 commit comments

Comments
 (0)