Skip to content

Commit

Permalink
use redist if atm and lnd has same grid (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
uturuncoglu authored Jan 28, 2025
1 parent b5d1cc1 commit cdbed6c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
21 changes: 17 additions & 4 deletions mediator/esmFldsExchange_ufs_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ module esmFldsExchange_ufs_mod

public :: esmFldsExchange_ufs

integer :: atm2lnd_maptype
integer :: lnd2atm_maptype

character(*), parameter :: u_FILE_u = &
__FILE__

Expand All @@ -30,7 +33,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc)
use med_internalstate_mod , only : mapbilnr, mapconsf, mapconsd, mappatch
use med_internalstate_mod , only : mapfcopy, mapnstod, mapnstod_consd, mapnstod_consf
use med_internalstate_mod , only : mapconsf_aofrac, mapbilnr_nstod
use med_internalstate_mod , only : coupling_mode, mapnames
use med_internalstate_mod , only : coupling_mode, mapnames, samegrid_atmlnd
use esmFlds , only : med_fldList_type
use esmFlds , only : addfld_to => med_fldList_addfld_to
use esmFlds , only : addmrg_to => med_fldList_addmrg_to
Expand Down Expand Up @@ -92,6 +95,16 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc)
med_aoflux_to_ocn = .false.
end if

! determine if atm and lnd have the same mesh
if (phase == 'advertise') then
atm2lnd_maptype = maptype
lnd2atm_maptype = maptype
if (samegrid_atmlnd) then
atm2lnd_maptype = mapfcopy
lnd2atm_maptype = mapfcopy
end if
end if

!=====================================================================
! scalar information
!=====================================================================
Expand Down Expand Up @@ -258,7 +271,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc)
do n = 1,size(flds)
if ( fldchk(is_local%wrap%FBexp(compatm) , 'Fall_'//trim(flds(n)), rc=rc) .and. &
fldchk(is_local%wrap%FBImp(complnd,complnd), 'Fall_'//trim(flds(n)), rc=rc)) then
call addmap_from(complnd, 'Fall_'//trim(flds(n)), compatm, maptype, 'lfrac', 'unset')
call addmap_from(complnd, 'Fall_'//trim(flds(n)), compatm, lnd2atm_maptype, 'lfrac', 'unset')
call addmrg_to(compatm, 'Fall_'//trim(flds(n)), mrg_from=complnd, mrg_fld='Fall_'//trim(flds(n)), mrg_type='copy')
end if
end do
Expand All @@ -279,7 +292,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc)
do n = 1,size(flds)
if ( fldchk(is_local%wrap%FBexp(compatm) , 'Sl_'//trim(flds(n)), rc=rc) .and. &
fldchk(is_local%wrap%FBImp(complnd,complnd), 'Sl_'//trim(flds(n)), rc=rc)) then
call addmap_from(complnd, 'Sl_'//trim(flds(n)), compatm, maptype, 'lfrac', 'unset')
call addmap_from(complnd, 'Sl_'//trim(flds(n)), compatm, lnd2atm_maptype, 'lfrac', 'unset')
call addmrg_to(compatm, 'Sl_'//trim(flds(n)), mrg_from=complnd, mrg_fld='Sl_'//trim(flds(n)), mrg_type='copy')
end if
end do
Expand Down Expand Up @@ -776,7 +789,7 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc)
else
if ( fldchk(is_local%wrap%FBexp(complnd) , fldname, rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm), fldname, rc=rc)) then
call addmap_from(compatm, fldname, complnd, maptype, 'one', 'unset')
call addmap_from(compatm, fldname, complnd, atm2lnd_maptype, 'one', 'unset')
call addmrg_to(complnd, fldname, mrg_from=compatm, mrg_fld=fldname, mrg_type='copy')
end if
end if
Expand Down
17 changes: 17 additions & 0 deletions mediator/med_internalstate_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,23 @@ subroutine med_internalstate_init(gcomp, rc)
samegrid_atmlnd = .true.
end if

! flexibility to overwrite samegrid_atmlnd option
call NUOPC_CompAttributeGet(gcomp, name='samegrid_atmlnd', value=cvalue, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (isPresent .and. isSet) then
if (trim(cvalue) == '.true.' .or. trim(cvalue) == 'true') then
samegrid_atmlnd = .true.
else
samegrid_atmlnd = .false.
end if
end if

if (maintask) then
write(logunit,'(a,l)') trim(subname)//' atm and lnd is on same grid = ', samegrid_atmlnd
end if

! See med_fraction_mod for the following definitions
if (samegrid_atmlnd) then
map_fracname_lnd2atm = 'lfrin' ! in fraclist_a
Expand Down

0 comments on commit cdbed6c

Please sign in to comment.