From fb421092ec451197b626ecd18d865951e42c028f Mon Sep 17 00:00:00 2001 From: Denise Worthen Date: Tue, 23 Dec 2025 08:22:12 -0500 Subject: [PATCH 1/2] add optional mapfiles when available * mapfiles are unused unless file names are provided by config --- mediator/esmFldsExchange_ufs_mod.F90 | 99 +++++++++++++++++++++------- 1 file changed, 75 insertions(+), 24 deletions(-) diff --git a/mediator/esmFldsExchange_ufs_mod.F90 b/mediator/esmFldsExchange_ufs_mod.F90 index bc6fa86e5..11fd25110 100644 --- a/mediator/esmFldsExchange_ufs_mod.F90 +++ b/mediator/esmFldsExchange_ufs_mod.F90 @@ -6,6 +6,11 @@ module esmFldsExchange_ufs_mod ! mapping and merging !--------------------------------------------------------------------- + use ESMF + use NUOPC + use med_utils_mod , only : chkerr => med_utils_chkerr + use med_kind_mod , only : CX=>SHR_KIND_CX, CS=>SHR_KIND_CS, CL=>SHR_KIND_CL, R8=>SHR_KIND_R8 + implicit none public @@ -14,6 +19,14 @@ module esmFldsExchange_ufs_mod integer :: atm2lnd_maptype integer :: lnd2atm_maptype + ! optional mapping files + character(len=CL) :: a2oi_bilnr + character(len=CL) :: a2oi_patch + character(len=CL) :: a2oi_consf + character(len=CL) :: a2w_bilnr + character(len=CL) :: w2oi_bilnr_nstod + character(len=CL) :: oi2w_bilnr_nstod + character(*), parameter :: u_FILE_u = & __FILE__ @@ -23,10 +36,6 @@ module esmFldsExchange_ufs_mod subroutine esmFldsExchange_ufs(gcomp, phase, rc) - use ESMF - use NUOPC - use med_kind_mod , only : CX=>SHR_KIND_CX, CS=>SHR_KIND_CS, CL=>SHR_KIND_CL, R8=>SHR_KIND_R8 - use med_utils_mod , only : chkerr => med_utils_chkerr use med_methods_mod , only : fldchk => med_methods_FB_FldChk use med_internalstate_mod , only : InternalState use med_internalstate_mod , only : compmed, compatm, compocn, compice, complnd, compwav, ncomps @@ -76,7 +85,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) if (chkerr(rc,__LINE__,u_FILE_u)) return ! Set maptype according to coupling_mode - if (trim(coupling_mode) == 'ufs.nfrac' .or. trim(coupling_mode) == 'ufs.nfrac.aoflux') then + if (trim(coupling_mode) == 'ufs.nfrac') then maptype = mapnstod_consf else maptype = mapconsf @@ -101,6 +110,22 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) end if end if + ! to ocn/ice + a2oi_bilnr = get_mapfile(gcomp, 'map_a2oi_bilnr', rc) + if (chkerr(rc,__LINE__,u_FILE_u)) return + a2oi_patch = get_mapfile(gcomp, 'map_a2oi_patch', rc) + if (chkerr(rc,__LINE__,u_FILE_u)) return + a2oi_consf = get_mapfile(gcomp, 'map_a2oi_consf', rc) + if (chkerr(rc,__LINE__,u_FILE_u)) return + w2oi_bilnr_nstod = get_mapfile(gcomp, 'map_w2oi_bilnr_nstod', rc) + if (chkerr(rc,__LINE__,u_FILE_u)) return + + ! to wav + a2w_bilnr = get_mapfile(gcomp, 'map_a2w_bilnr', rc) + if (chkerr(rc,__LINE__,u_FILE_u)) return + oi2w_bilnr_nstod = get_mapfile(gcomp, 'map_oi2w_bilnr_nstod', rc) + if (chkerr(rc,__LINE__,u_FILE_u)) return + if (trim(coupling_mode) == 'ufs.nfrac.aoflux' .or. trim(coupling_mode) == 'ufs.frac.aoflux') then med_aoflux_to_ocn = .true. else @@ -159,7 +184,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) call addfld_from(compatm , fldname) else if ( fldchk(is_local%wrap%FBImp(compatm,compatm), fldname, rc=rc)) then - call addmap_from(compatm, fldname, compocn, mapbilnr, 'one', 'unset') + call addmap_from(compatm, fldname, compocn, mapbilnr, 'one', a2oi_bilnr) end if end if end do @@ -318,7 +343,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) deallocate(flds) end if - ! to atm: unmerged from mediator, merge will be done under UFSATM/CCPP composite step + ! to atm: unmerged from mediator, merge will be done under FV3/CCPP composite step ! - zonal surface stress, meridional surface stress ! - surface latent heat flux, ! - surface sensible heat flux @@ -370,7 +395,9 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) else if ( fldchk(is_local%wrap%FBexp(compocn) , 'Sa_pslv', rc=rc) .and. & fldchk(is_local%wrap%FBImp(compatm,compatm), 'Sa_pslv', rc=rc)) then - call addmap_from(compatm, 'Sa_pslv', compocn, maptype, 'one', 'unset') + !TODO: this should be bilinear + !call addmap_from(compatm, 'Sa_pslv', compocn, mapbilnr, 'one', a2oi_bilnr) + call addmap_from(compatm, 'Sa_pslv', compocn, maptype, 'one', a2oi_consf) call addmrg_to(compocn, 'Sa_pslv', mrg_from=compatm, mrg_fld='Sa_pslv', mrg_type='copy') end if end if @@ -405,7 +432,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) else if ( fldchk(is_local%wrap%FBexp(compocn) , trim(oflds(n)), rc=rc) .and. & fldchk(is_local%wrap%FBImp(compatm,compatm), trim(aflds(n)), rc=rc)) then - call addmap_from(compatm, trim(aflds(n)), compocn, maptype, 'one', 'unset') + call addmap_from(compatm, trim(aflds(n)), compocn, maptype, 'one', a2oi_consf) end if end if end do @@ -440,7 +467,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) else if ( fldchk(is_local%wrap%FBexp(compocn) , fldname, rc=rc) .and. & fldchk(is_local%wrap%FBImp(compatm,compatm), fldname, rc=rc)) then - call addmap_from(compatm, fldname, compocn, maptype, 'one', 'unset') + call addmap_from(compatm, fldname, compocn, maptype, 'one', a2oi_consf) call addmrg_to(compocn, fldname, & mrg_from=compatm, mrg_fld=fldname, mrg_type='copy_with_weights', mrg_fracname='ofrac') end if @@ -475,9 +502,9 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) fldchk(is_local%wrap%FBImp(compatm,compatm), 'Faxa_'//fldname, rc=rc)) then call addmap_from(compice, 'Fioi_'//fldname, compocn, mapfcopy, 'unset', 'unset') if (mapuv_with_cart3d) then - call addmap_from(compatm, 'Faxa_'//fldname, compocn, mapconsf_uv3d, 'aofrac', 'unset') + call addmap_from(compatm, 'Faxa_'//fldname, compocn, mapconsf_uv3d, 'aofrac', a2oi_consf) else - call addmap_from(compatm, 'Faxa_'//fldname, compocn, mapconsf_aofrac, 'aofrac', 'unset') + call addmap_from(compatm, 'Faxa_'//fldname, compocn, mapconsf_aofrac, 'aofrac', a2oi_consf) end if call addmrg_to(compocn, 'Foxx_'//fldname, & mrg_from=compice, mrg_fld='Fioi_'//fldname, mrg_type='merge', mrg_fracname='ifrac') @@ -511,7 +538,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) else if ( fldchk(is_local%wrap%FBexp(compocn) , 'Foxx_lwnet', rc=rc) .and. & fldchk(is_local%wrap%FBImp(compatm,compatm), 'Faxa_lwnet', rc=rc)) then - call addmap_from(compatm, 'Faxa_lwnet', compocn, mapconsf_aofrac, 'aofrac', 'unset') + call addmap_from(compatm, 'Faxa_lwnet', compocn, mapconsf_aofrac, 'aofrac', a2oi_consf) call addmrg_to(compocn, 'Foxx_lwnet', & mrg_from=compatm, mrg_fld='Faxa_lwnet', mrg_type='copy_with_weights', mrg_fracname='ofrac') end if @@ -535,7 +562,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) else if ( fldchk(is_local%wrap%FBexp(compocn) , 'Foxx_sen', rc=rc) .and. & fldchk(is_local%wrap%FBImp(compatm,compatm), 'Faxa_sen', rc=rc)) then - call addmap_from(compatm, 'Faxa_sen', compocn, mapconsf_aofrac, 'aofrac', 'unset') + call addmap_from(compatm, 'Faxa_sen', compocn, mapconsf_aofrac, 'aofrac', a2oi_consf) call addmrg_to(compocn, 'Foxx_sen', & mrg_from=compatm, mrg_fld='Faxa_sen', mrg_type='copy_with_weights', mrg_fracname='ofrac') end if @@ -559,7 +586,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) else if ( fldchk(is_local%wrap%FBexp(compocn) , 'Foxx_evap', rc=rc) .and. & fldchk(is_local%wrap%FBImp(compatm,compatm), 'Faxa_evap' , rc=rc)) then - call addmap_from(compatm, 'Faxa_evap', compocn, mapconsf_aofrac, 'aofrac', 'unset') + call addmap_from(compatm, 'Faxa_evap', compocn, mapconsf_aofrac, 'aofrac', a2oi_consf) call addmrg_to(compocn, 'Foxx_evap', & mrg_from=compatm, mrg_fld='Faxa_evap', mrg_type='copy_with_weights', mrg_fracname='ofrac') end if @@ -603,7 +630,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) else if ( fldchk(is_local%wrap%FBexp(compocn) , fldname, rc=rc) .and. & fldchk(is_local%wrap%FBImp(compwav,compwav), fldname, rc=rc)) then - call addmap_from(compwav, fldname, compocn, mapbilnr_nstod, 'one', 'unset') + call addmap_from(compwav, fldname, compocn, mapbilnr_nstod, 'one', w2oi_bilnr_nstod) call addmrg_to(compocn, fldname, mrg_from=compwav, mrg_fld=fldname, mrg_type='copy') end if end if @@ -636,7 +663,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) else if ( fldchk(is_local%wrap%FBexp(compice) , fldname, rc=rc) .and. & fldchk(is_local%wrap%FBImp(compatm,compatm), fldname, rc=rc)) then - call addmap_from(compatm, fldname, compice, maptype, 'one', 'unset') + call addmap_from(compatm, fldname, compice, maptype, 'one', a2oi_consf) call addmrg_to(compice, fldname, mrg_from=compatm, mrg_fld=fldname, mrg_type='copy') end if end if @@ -662,7 +689,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) else if ( fldchk(is_local%wrap%FBexp(compice) , fldname, rc=rc) .and. & fldchk(is_local%wrap%FBImp(compatm,compatm), fldname, rc=rc)) then - call addmap_from(compatm, fldname, compice, mapbilnr, 'one', 'unset') + call addmap_from(compatm, fldname, compice, mapbilnr, 'one', a2oi_bilnr) call addmrg_to(compice, fldname, mrg_from=compatm, mrg_fld=fldname, mrg_type='copy') end if end if @@ -682,9 +709,9 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) if ( fldchk(is_local%wrap%FBexp(compice) , fldname, rc=rc) .and. & fldchk(is_local%wrap%FBImp(compatm,compatm), fldname, rc=rc)) then if (mapuv_with_cart3d) then - call addmap_from(compatm, fldname, compice, mappatch_uv3d, 'one', 'unset') + call addmap_from(compatm, fldname, compice, mappatch_uv3d, 'one', a2oi_patch) else - call addmap_from(compatm, fldname, compice, mappatch, 'one', 'unset') + call addmap_from(compatm, fldname, compice, mappatch, 'one', a2oi_patch) end if call addmrg_to(compice, fldname, mrg_from=compatm, mrg_fld=fldname, mrg_type='copy') end if @@ -728,7 +755,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) else if ( fldchk(is_local%wrap%FBExp(compice) , 'Sw_elevation_spectrum', rc=rc) .and. & fldchk(is_local%wrap%FBImp(compwav,compwav), 'Sw_elevation_spectrum', rc=rc)) then - call addmap_from(compwav, 'Sw_elevation_spectrum', compice, mapbilnr_nstod, 'one', 'unset') + call addmap_from(compwav, 'Sw_elevation_spectrum', compice, mapbilnr_nstod, 'one', w2oi_bilnr_nstod) call addmrg_to(compice, 'Sw_elevation_spectrum', mrg_from=compwav, & mrg_fld='Sw_elevation_spectrum', mrg_type='copy') end if @@ -753,7 +780,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) else if ( fldchk(is_local%wrap%FBexp(compwav) , fldname, rc=rc) .and. & fldchk(is_local%wrap%FBImp(compatm,compatm), fldname, rc=rc)) then - call addmap_from(compatm, fldname, compwav, mapbilnr, 'one', 'unset') + call addmap_from(compatm, fldname, compwav, mapbilnr, 'one', a2w_bilnr) call addmrg_to(compwav, fldname, mrg_from=compatm, mrg_fld=fldname, mrg_type='copy') end if end if @@ -776,7 +803,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) else if ( fldchk(is_local%wrap%FBexp(compwav) , fldname, rc=rc) .and. & fldchk(is_local%wrap%FBImp(compice,compice), fldname, rc=rc)) then - call addmap_from(compice, fldname, compwav, mapbilnr_nstod , 'one', 'unset') + call addmap_from(compice, fldname, compwav, mapbilnr_nstod , 'one', oi2w_bilnr_nstod) call addmrg_to(compwav, fldname, mrg_from=compice, mrg_fld=fldname, mrg_type='copy') end if end if @@ -799,7 +826,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) else if ( fldchk(is_local%wrap%FBexp(compwav) , fldname, rc=rc) .and. & fldchk(is_local%wrap%FBImp(compocn,compocn), fldname, rc=rc)) then - call addmap_from(compocn, fldname, compwav, mapbilnr_nstod , 'one', 'unset') + call addmap_from(compocn, fldname, compwav, mapbilnr_nstod , 'one', oi2w_bilnr_nstod) call addmrg_to(compwav, fldname, mrg_from=compocn, mrg_fld=fldname, mrg_type='copy') end if end if @@ -866,4 +893,28 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) end subroutine esmFldsExchange_ufs + function get_mapfile(gcomp, attribute_name, rc) result(mapfile) + + type(ESMF_GridComp), intent(in) :: gcomp + character(len=*) , intent(in) :: attribute_name + integer , intent(inout) :: rc + character(len=CL) :: mapfile + + logical :: isPresent, isSet + character(len=CL) :: cvalue + !-------------------------------------- + + rc = ESMF_SUCCESS + + mapfile = 'unset' + call NUOPC_CompAttributeGet(gcomp, name=attribute_name, isPresent=isPresent, isSet=isSet, rc=rc) + if (chkerr(rc,__LINE__,u_FILE_u)) return + if (isPresent .and. isSet) then + call NUOPC_CompAttributeGet(gcomp, name=attribute_name, value=cvalue, rc=rc) + if (chkerr(rc,__LINE__,u_FILE_u)) return + mapfile = trim(cvalue) + end if + + end function get_mapfile + end module esmFldsExchange_ufs_mod From ab1a124d328a62b21be6b0bc967ec6c26fd2541c Mon Sep 17 00:00:00 2001 From: Denise Worthen Date: Wed, 14 Jan 2026 14:11:11 -0500 Subject: [PATCH 2/2] fix comment and add bilinear mapfile for Sa_pslv --- mediator/esmFldsExchange_ufs_mod.F90 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mediator/esmFldsExchange_ufs_mod.F90 b/mediator/esmFldsExchange_ufs_mod.F90 index 11fd25110..919ec34ff 100644 --- a/mediator/esmFldsExchange_ufs_mod.F90 +++ b/mediator/esmFldsExchange_ufs_mod.F90 @@ -343,7 +343,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) deallocate(flds) end if - ! to atm: unmerged from mediator, merge will be done under FV3/CCPP composite step + ! to atm: unmerged from mediator, merge will be done under UFSATM/CCPP composite step ! - zonal surface stress, meridional surface stress ! - surface latent heat flux, ! - surface sensible heat flux @@ -395,9 +395,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc) else if ( fldchk(is_local%wrap%FBexp(compocn) , 'Sa_pslv', rc=rc) .and. & fldchk(is_local%wrap%FBImp(compatm,compatm), 'Sa_pslv', rc=rc)) then - !TODO: this should be bilinear - !call addmap_from(compatm, 'Sa_pslv', compocn, mapbilnr, 'one', a2oi_bilnr) - call addmap_from(compatm, 'Sa_pslv', compocn, maptype, 'one', a2oi_consf) + call addmap_from(compatm, 'Sa_pslv', compocn, mapbilnr, 'one', a2oi_bilnr) call addmrg_to(compocn, 'Sa_pslv', mrg_from=compatm, mrg_fld='Sa_pslv', mrg_type='copy') end if end if