Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 75 additions & 24 deletions mediator/esmFldsExchange_ufs_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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__

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Comment thread
DeniseWorthen marked this conversation as resolved.
Outdated
! - zonal surface stress, meridional surface stress
! - surface latent heat flux,
! - surface sensible heat flux
Expand Down Expand Up @@ -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)
Comment thread
DeniseWorthen marked this conversation as resolved.
Outdated
call addmrg_to(compocn, 'Sa_pslv', mrg_from=compatm, mrg_fld='Sa_pslv', mrg_type='copy')
end if
end if
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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