@@ -34,6 +34,7 @@ module MOM_domain_infra
3434
3535! The `group_pass_type` fields are never accessed, so we keep it as an FMS type
3636use mpp_domains_mod, only : group_pass_type = > mpp_group_update_type
37+ #define MAX_DSAMP_LEV 3
3738
3839implicit none ; private
3940
@@ -133,7 +134,7 @@ module MOM_domain_infra
133134 character (len= 64 ) :: name ! < The name of this domain
134135 type (domain2D), pointer :: mpp_domain = > NULL () ! < The FMS domain with halos
135136 ! ! on this processor, centered at h points.
136- type (domain2D), pointer :: mpp_domain_d2 = > NULL () ! < A coarse FMS domain with halos
137+ type (domain2D), pointer :: mpp_domain_d(:) = > NULL () ! < A coarse FMS domain with halos
137138 ! ! on this processor, centered at h points.
138139 integer :: niglobal ! < The total horizontal i-domain size.
139140 integer :: njglobal ! < The total horizontal j-domain size.
@@ -1371,14 +1372,14 @@ subroutine create_MOM_domain(MOM_dom, n_global, n_halo, reentrant, tripolar_N, l
13711372 integer , dimension (4 ) :: global_indices ! The lower and upper global i- and j-index bounds
13721373 integer :: X_FLAGS ! A combination of integers encoding the x-direction grid connectivity.
13731374 integer :: Y_FLAGS ! A combination of integers encoding the y-direction grid connectivity.
1374- integer :: xhalo_d2, yhalo_d2
1375+ integer :: dl
13751376 character (len= 200 ) :: mesg ! A string for use in error messages
13761377 logical :: mask_table_exists ! Mask_table is present and the file it points to exists
13771378
13781379 if (.not. associated (MOM_dom)) then
13791380 allocate (MOM_dom)
13801381 allocate (MOM_dom% mpp_domain)
1381- allocate (MOM_dom% mpp_domain_d2)
1382+ do dl = 2 ,MAX_DSAMP_LEV ; allocate (MOM_dom% mpp_domain_d(dl)) ; enddo
13821383 endif
13831384
13841385 MOM_dom% name = " MOM" ; if (present (domain_name)) MOM_dom% name = trim (domain_name)
@@ -1446,11 +1447,12 @@ subroutine create_MOM_domain(MOM_dom, n_global, n_halo, reentrant, tripolar_N, l
14461447
14471448 call clone_MD_to_d2D(MOM_dom, MOM_dom% mpp_domain)
14481449
1449- ! For downsampled domain, recommend a halo of 1 (or 0?) since we're not doing wide-stencil computations.
1450- ! But that does not work because the downsampled field would not have the correct size to pass the checks, e.g., we get
1451- ! error: downsample_diag_indices_get: peculiar size 28 in i-direction\ndoes not match one of 24 25 26 27
1452- ! call clone_MD_to_d2D(MOM_dom, MOM_dom%mpp_domain_d2, halo_size=(MOM_dom%nihalo/2), coarsen=2)
1453- call clone_MD_to_d2D(MOM_dom, MOM_dom% mpp_domain_d2, coarsen= 2 )
1450+ do dl= 2 ,MAX_DSAMP_LEV
1451+ ! Downsample diagnostics calculations do not need halos.
1452+ call clone_MD_to_d2D(MOM_dom, MOM_dom% mpp_domain_d(dl), coarsen= dl, halo_size= 0 , &
1453+ domain_name= " MOM_domain_d" // char (48 + dl))
1454+ enddo
1455+
14541456end subroutine create_MOM_domain
14551457
14561458! > dealloc_MOM_domain deallocates memory associated with a pointer to a MOM_domain_type
@@ -1460,6 +1462,7 @@ subroutine deallocate_MOM_domain(MOM_domain, cursory)
14601462 logical , optional , intent (in ) :: cursory ! < If true do not deallocate fields associated
14611463 ! ! with the underlying infrastructure
14621464 logical :: invasive ! If true, deallocate fields associated with the underlying infrastructure
1465+ integer :: dl
14631466
14641467 invasive = .true. ; if (present (cursory)) invasive = .not. cursory
14651468
@@ -1468,9 +1471,11 @@ subroutine deallocate_MOM_domain(MOM_domain, cursory)
14681471 if (invasive) call mpp_deallocate_domain(MOM_domain% mpp_domain)
14691472 deallocate (MOM_domain% mpp_domain)
14701473 endif
1471- if (associated (MOM_domain% mpp_domain_d2)) then
1472- if (invasive) call mpp_deallocate_domain(MOM_domain% mpp_domain_d2)
1473- deallocate (MOM_domain% mpp_domain_d2)
1474+ if (associated (MOM_domain% mpp_domain_d)) then
1475+ if (invasive) then
1476+ do dl= 2 ,MAX_DSAMP_LEV ; call mpp_deallocate_domain(MOM_domain% mpp_domain_d(dl)); enddo
1477+ endif
1478+ deallocate (MOM_domain% mpp_domain_d)
14741479 endif
14751480 if (associated (MOM_domain% maskmap)) deallocate (MOM_domain% maskmap)
14761481 deallocate (MOM_domain)
@@ -1567,7 +1572,7 @@ subroutine clone_MD_to_MD(MD_in, MOM_dom, min_halo, halo_size, symmetric, domain
15671572 integer , dimension (:), allocatable :: exnj ! The extents of the grid for each j-row of the layout.
15681573 ! The sum of exni must equal MOM_dom%niglobal.
15691574 integer :: qturns ! The number of quarter turns, restricted to the range of 0 to 3.
1570- integer :: i, j, nl1, nl2
1575+ integer :: i, j, nl1, nl2, dl
15711576 integer :: io_layout_in(2 )
15721577
15731578 qturns = 0
@@ -1582,7 +1587,7 @@ subroutine clone_MD_to_MD(MD_in, MOM_dom, min_halo, halo_size, symmetric, domain
15821587 if (.not. associated (MOM_dom)) then
15831588 allocate (MOM_dom)
15841589 allocate (MOM_dom% mpp_domain)
1585- allocate (MOM_dom% mpp_domain_d2)
1590+ do dl = 2 ,MAX_DSAMP_LEV ; allocate (MOM_dom% mpp_domain_d(dl)) ; enddo
15861591 endif
15871592
15881593! Save the extra data for creating other domains of different resolution that overlay this domain
@@ -1704,7 +1709,11 @@ subroutine clone_MD_to_MD(MD_in, MOM_dom, min_halo, halo_size, symmetric, domain
17041709 endif
17051710
17061711 call clone_MD_to_d2D(MOM_dom, MOM_dom% mpp_domain, xextent= exni, yextent= exnj)
1707- call clone_MD_to_d2D(MOM_dom, MOM_dom% mpp_domain_d2, domain_name= MOM_dom% name, coarsen= 2 )
1712+ do dl= 2 ,MAX_DSAMP_LEV
1713+ ! Downsample diagnostics calculations do not need halos.
1714+ call clone_MD_to_d2D(MOM_dom, MOM_dom% mpp_domain_d(dl), coarsen= dl, halo_size= 0 , &
1715+ domain_name= " MOM_domain_d" // char (48 + dl))
1716+ enddo
17081717
17091718end subroutine clone_MD_to_MD
17101719
@@ -1842,12 +1851,12 @@ subroutine get_domain_extent_MD(Domain, isc, iec, jsc, jec, isd, ied, jsd, jed,
18421851 call mpp_get_compute_domain(Domain% mpp_domain, isc, iec, jsc, jec)
18431852 call mpp_get_data_domain(Domain% mpp_domain, isd, ied, jsd, jed)
18441853 call mpp_get_global_domain(Domain% mpp_domain, isg_, ieg_, jsg_, jeg_)
1845- elseif (coarsen_lev == 2 ) then
1846- if (.not. associated (Domain% mpp_domain_d2 )) call MOM_error(FATAL, &
1847- " get_domain_extent called with coarsen=2 , but Domain%mpp_domain_d2 is not associated." )
1848- call mpp_get_compute_domain(Domain% mpp_domain_d2 , isc, iec, jsc, jec)
1849- call mpp_get_data_domain(Domain% mpp_domain_d2 , isd, ied, jsd, jed)
1850- call mpp_get_global_domain(Domain% mpp_domain_d2 , isg_, ieg_, jsg_, jeg_)
1854+ elseif (coarsen_lev < = MAX_DSAMP_LEV ) then
1855+ if (.not. associated (Domain% mpp_domain_d )) call MOM_error(FATAL, &
1856+ " get_domain_extent called with coarsen_lev , but Domain%mpp_domain_d(coarsen_lev) is not associated." )
1857+ call mpp_get_compute_domain(Domain% mpp_domain_d(coarsen_lev) , isc, iec, jsc, jec)
1858+ call mpp_get_data_domain(Domain% mpp_domain_d(coarsen_lev) , isd, ied, jsd, jed)
1859+ call mpp_get_global_domain(Domain% mpp_domain_d(coarsen_lev) , isg_, ieg_, jsg_, jeg_)
18511860 else
18521861 call MOM_error(FATAL, " get_domain_extent called with an unsupported level of coarsening." )
18531862 endif
0 commit comments