@@ -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
3434use mpp_domains_mod, only : group_pass_type = > mpp_group_update_type
35+ #define MAX_DSAMP_LEV 3
3536
3637implicit 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
14521455end 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
17071715end 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
0 commit comments