Skip to content

Commit 5f825db

Browse files
authored
Merge branch 'vijaysm/fix-rof-mesh-usage' (PR #8479)
Fix the ERS.MOS_USRDAT.RMOSNLDAS* cases that were using the wrong ROF mesh file. We now also perform an additional validation check to determine whether the ROF mesh is in either the SCRIP format for unstructured grids or a domain file format, so we can use the appropriate option to read the grid in parallel through MOAB. We can potentially try to decipher this at the MOAB layer as well, redirecting to SCRIP vs. Domain reader to achieve an equivalent effect. [BFB]
2 parents e53a32f + 43b6704 commit 5f825db

2 files changed

Lines changed: 82 additions & 5 deletions

File tree

components/mosart/cime_config/testdefs/testmods_dirs/mosart/sediment/user_nl_mosart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
frivinp_rtm = '$DIN_LOC_ROOT/rof/mosart/MOSART_NLDAS_8th_20160426_20210609d_rslp.nc'
2-
frivinp_mesh = '$DIN_LOC_ROOT/share/meshes/rof/MOSART_global_8th.scrip.20180211c.nc'
2+
frivinp_mesh = '$DIN_LOC_ROOT/share/domains/domain.clm/domain.lnd.nldas2_0224x0464_c110415.nc'
33
sediflag = .true.
44
parafile = '$DIN_LOC_ROOT/rof/mosart/US_reservoir_8th_NLDAS3_updated.nc'
55
routingmethod = 2

driver-moab/main/cplcomp_exchange_mod.F90

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,73 @@ subroutine cplcomp_moab_init_ice(infodata, comp, id_old, id_join, mpicom_old, mp
856856

857857
end subroutine cplcomp_moab_init_ice
858858

859+
subroutine cplcomp_moab_pick_load_options(filename, ropts, ierr)
860+
! Inspect filename's netCDF contents and choose MOAB load options that match
861+
! the file's grid format. MOAB's parallel readers couple format to partition
862+
! method: NCHelperScrip handles SCRIP files and supports RCBZOLTAN; NCHelperDomain
863+
! handles CESM domain files (xc/yc/xv/yv) and supports only SQIJ-family partitions.
864+
!
865+
! Detection (in order):
866+
! - 'grid_size' dimension present => SCRIP (structured or unstructured)
867+
! - 'xc' or 'yc' variable, or 'ni'+'nj' dims => CESM domain
868+
! (variable names xc/yc/lon/lat vary across files, but the ni/nj dim pair
869+
! is the canonical CESM/CIME domain-file layout that NCHelperDomain expects)
870+
! Returns ierr /= 0 for unrecognized formats; caller decides whether to abort.
871+
use pio, only: file_desc_t, iosystem_desc_t, &
872+
pio_openfile, pio_closefile, pio_nowrite, &
873+
pio_inq_dimid, pio_inq_varid, pio_seterrorhandling, &
874+
PIO_BCAST_ERROR, PIO_INTERNAL_ERROR, PIO_NOERR
875+
use shr_pio_mod, only: shr_pio_getiosys, shr_pio_getiotype
876+
877+
character(len=*), intent(in) :: filename
878+
character(len=*), intent(out) :: ropts
879+
integer, intent(out) :: ierr
880+
881+
type(file_desc_t) :: pioid
882+
type(iosystem_desc_t), pointer :: iosys
883+
integer :: rcode, iotype, dimid_grid_size, dimid_ni, dimid_nj, varid_xc, varid_yc
884+
logical :: is_scrip, is_cesm_domain
885+
logical :: has_ni, has_nj, has_xc, has_yc
886+
887+
ierr = 0
888+
is_scrip = .false.
889+
is_cesm_domain = .false.
890+
891+
iosys => shr_pio_getiosys(CPLID)
892+
iotype = shr_pio_getiotype(CPLID)
893+
rcode = pio_openfile(iosys, pioid, iotype, trim(filename), pio_nowrite)
894+
if (rcode /= PIO_NOERR) then
895+
ierr = 1
896+
return
897+
endif
898+
899+
call pio_seterrorhandling(pioid, PIO_BCAST_ERROR)
900+
901+
! SCRIP marker: 'grid_size' dimension
902+
rcode = pio_inq_dimid(pioid, 'grid_size', dimid_grid_size)
903+
if (rcode == PIO_NOERR) then
904+
is_scrip = .true.
905+
else
906+
! CESM domain markers: any of xc, yc variables OR ni+nj dimension pair
907+
has_xc = (pio_inq_varid(pioid, 'xc', varid_xc) == PIO_NOERR)
908+
has_yc = (pio_inq_varid(pioid, 'yc', varid_yc) == PIO_NOERR)
909+
has_ni = (pio_inq_dimid(pioid, 'ni', dimid_ni) == PIO_NOERR)
910+
has_nj = (pio_inq_dimid(pioid, 'nj', dimid_nj) == PIO_NOERR)
911+
if (has_xc .or. has_yc .or. (has_ni .and. has_nj)) is_cesm_domain = .true.
912+
endif
913+
914+
call pio_seterrorhandling(pioid, PIO_INTERNAL_ERROR)
915+
call pio_closefile(pioid)
916+
917+
if (is_scrip) then
918+
ropts = 'PARALLEL=READ_PART;PARTITION_METHOD=RCBZOLTAN'
919+
else if (is_cesm_domain) then
920+
ropts = 'PARALLEL=READ_PART;PARTITION_METHOD=SQIJ;VARIABLE=;REPARTITION;NO_CULLING'
921+
else
922+
ierr = 2
923+
endif
924+
end subroutine cplcomp_moab_pick_load_options
925+
859926
subroutine cplcomp_moab_init_rof(infodata, comp, id_old, id_join, mpicom_old, mpicom_new, mpicom_join, dead_comps, partMethod, subname)
860927

861928
use iMOAB, only: iMOAB_WriteMesh, iMOAB_GetMeshInfo
@@ -919,12 +986,22 @@ subroutine cplcomp_moab_init_rof(infodata, comp, id_old, id_join, mpicom_old, mp
919986
! load mesh from scrip file passed from river model, if domain file is not available
920987
call seq_infodata_GetData(infodata,rof_mesh=rtm_mesh,rof_domain=rof_domain)
921988
if ( trim(rof_domain) == 'none' ) then
922-
outfile = trim(rtm_mesh)//C_NULL_CHAR
923-
ropts = 'PARALLEL=READ_PART;PARTITION_METHOD=RCBZOLTAN'//C_NULL_CHAR
989+
outfile = trim(rtm_mesh)
924990
else
925-
outfile = trim(rof_domain)//C_NULL_CHAR
926-
ropts = 'PARALLEL=READ_PART;PARTITION_METHOD=SQIJ;VARIABLE=;REPARTITION'//C_NULL_CHAR
991+
outfile = trim(rof_domain)
992+
endif
993+
! Pick MOAB load options based on actual file format. MOSART's frivinp_mesh
994+
! may be either a SCRIP-format mesh (structured or unstructured, handled by
995+
! NCHelperScrip with RCBZOLTAN) or a CESM domain file (xc/yc/xv/yv, handled
996+
! by NCHelperDomain with SQIJ-family partitions). The two readers don't share
997+
! partition-method support, so the right options depend on the file format.
998+
call cplcomp_moab_pick_load_options(trim(outfile), ropts, ierr)
999+
if (ierr /= 0) then
1000+
write(logunit,*) subname,' cannot determine MOAB load options for ', trim(outfile)
1001+
call shr_sys_abort(subname//' ERROR: unrecognized ROF mesh file format: '//trim(outfile))
9271002
endif
1003+
outfile = trim(outfile)//C_NULL_CHAR
1004+
ropts = trim(ropts)//C_NULL_CHAR
9281005
nghlay = 0 ! no ghost layers
9291006
if (seq_comm_iamroot(CPLID)) then
9301007
write(logunit,'(A)') subname//' loading rof from file '//trim(outfile) &

0 commit comments

Comments
 (0)