Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion mediator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ set(SRCFILES esmFldsExchange_cesm_mod.F90 med_fraction_mod.F90
med_phases_post_ocn_mod.F90 med_phases_ocnalb_mod.F90
med_phases_post_atm_mod.F90 med_phases_post_ice_mod.F90
med_phases_post_lnd_mod.F90 med_phases_post_glc_mod.F90
med_phases_post_rof_mod.F90 med_phases_post_wav_mod.F90)
med_phases_post_rof_mod.F90 med_phases_post_wav_mod.F90
med_ufs_trace_wrapper.F90)

foreach(FILE ${SRCFILES})
if(EXISTS "${CASEROOT}/SourceMods/src.cmeps/${FILE}")
Expand Down
483 changes: 187 additions & 296 deletions mediator/esmFldsExchange_hafs_mod.F90

Large diffs are not rendered by default.

127 changes: 91 additions & 36 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 @@ -256,19 +281,25 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc)
end do
deallocate(flds)

! to atm: unmerged surface temperatures from ocn
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compocn) .and. is_local%wrap%comp_present(compatm)) then
call addfld_from(compocn , 'So_t')
call addfld_to(compatm , 'So_t')
end if
else
if ( fldchk(is_local%wrap%FBexp(compatm) , 'So_t', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compocn,compocn), 'So_t', rc=rc)) then
call addmap_from(compocn, 'So_t', compatm, maptype, 'ofrac', 'unset')
call addmrg_to(compatm, 'So_t', mrg_from=compocn, mrg_fld='So_t', mrg_type='copy')
! to atm: unmerged surface temperatures and currents from ocn
allocate(flds(3))
flds = (/'So_t', 'So_u', 'So_v'/)
do n = 1,size(flds)
fldname = trim(flds(n))
if (phase == 'advertise') then
if (is_local%wrap%comp_present(compocn) .and. is_local%wrap%comp_present(compatm)) then
call addfld_from(compocn , fldname)
call addfld_to(compatm , fldname)
end if
else
if ( fldchk(is_local%wrap%FBexp(compatm) , fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compocn,compocn), fldname, rc=rc)) then
call addmap_from(compocn, fldname, compatm, maptype, 'ofrac', 'unset')
call addmrg_to(compatm, fldname, mrg_from=compocn, mrg_fld=fldname, mrg_type='copy')
end if
end if
end if
end do
deallocate(flds)

! to atm: unmerged flux components from lnd
if (is_local%wrap%comp_present(complnd) .and. is_local%wrap%comp_present(compatm)) then
Expand Down Expand Up @@ -312,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
Expand Down Expand Up @@ -364,7 +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
call addmap_from(compatm, 'Sa_pslv', compocn, maptype, 'one', 'unset')
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
Expand Down Expand Up @@ -399,7 +430,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 @@ -434,7 +465,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 @@ -469,9 +500,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 @@ -505,7 +536,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 @@ -529,7 +560,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 @@ -553,7 +584,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 @@ -597,7 +628,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 @@ -630,7 +661,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 @@ -656,7 +687,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 @@ -676,9 +707,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 @@ -722,7 +753,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 @@ -747,7 +778,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 @@ -770,7 +801,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 @@ -793,7 +824,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 @@ -860,4 +891,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
Loading
Loading