Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMEPS PR for CDEPS Inline implementation #420

Merged
merged 35 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d86f405
initial work for inline cdeps
uturuncoglu Oct 25, 2023
5510ad7
more work for cdeps inline
uturuncoglu Oct 27, 2023
6438f3d
more work for inline
uturuncoglu Nov 2, 2023
bcee457
use esmf config file to get stream information
uturuncoglu Nov 7, 2023
96c81b6
more work for inline capability
uturuncoglu Nov 7, 2023
794e691
enabling setting source and destination mask for interpolation
uturuncoglu Nov 9, 2023
17b127d
more work for cdeps inline
uturuncoglu Nov 11, 2023
f9ac7af
more work for cmeps and cdeps inline integration
uturuncoglu Nov 12, 2023
b0af4aa
add atm->ocn direction for cdeps inline capability
uturuncoglu Nov 15, 2023
1296a90
activate cdeps inline capability for atm->wav
uturuncoglu Nov 16, 2023
53bae53
add flag to track lake freezing for clm lake (#105)
JiliDong-NOAA Dec 21, 2023
cdb819b
feature to use all data in the first coupling timestep
uturuncoglu Dec 28, 2023
8652157
Merge remote-tracking branch 'upstream/main' into feature/inline
uturuncoglu Dec 29, 2023
f8f7ba7
Changes for physics reorganization (#103)
dustinswales Jan 3, 2024
d56c50c
fix for gust additions in the aoflux
uturuncoglu Jan 5, 2024
4d08b94
Merge remote-tracking branch 'fork/emc/develop' into feature/inline
uturuncoglu Jan 5, 2024
55c8900
mods for regional mom6 configuration
uturuncoglu Jan 15, 2024
6979bbd
fix for sw bands calculation for cases without sea-ice
uturuncoglu Jan 17, 2024
10e46c3
more work for regional mom6 coupling
uturuncoglu Jan 19, 2024
ad1e9a2
update for hafs.mom6
uturuncoglu Jan 19, 2024
a1cbcbc
switch TOTAL to SELECT for other interpolation types too
uturuncoglu Jan 20, 2024
fb993eb
fix from Denise for crash when diagnose is on by initializing
uturuncoglu Jan 25, 2024
13ed059
Updates for component land model (#98)
uturuncoglu Jan 26, 2024
8c10846
fix issue arised in CESM testing
uturuncoglu Jan 27, 2024
ea995f6
Merge remote-tracking branch 'noaa-emc/emc/develop' into feature/inline
uturuncoglu Jan 28, 2024
64e1c27
fix Faxa_rainc issue when add_gusts is turned on
uturuncoglu Jan 29, 2024
09dfd3c
fix comments mean -> inst and minor typo
uturuncoglu Jan 29, 2024
c4f5082
minor fix - remove trim
uturuncoglu Jan 30, 2024
e155c9a
srt does not work with most recent cime, cmeps requires most recent c…
jedwards4b Jan 30, 2024
43953e8
fix srt test
jedwards4b Jan 30, 2024
682a497
fix cime checkout
jedwards4b Jan 30, 2024
87c473c
turn off tmate
jedwards4b Jan 30, 2024
1290140
fix path
jedwards4b Jan 30, 2024
455b2be
debug workflow
jedwards4b Jan 31, 2024
170adbe
give format a length
jedwards4b Jan 31, 2024
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
4 changes: 1 addition & 3 deletions cesm/driver/ensemble_driver.F90
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ subroutine SetModelServices(ensemble_driver, rc)
integer :: pio_asyncio_stride
integer :: pio_asyncio_rootpe
integer :: Global_Comm
character(len=CL) :: start_type ! Type of startup
character(len=CL) :: start_type ! Type of startup
character(len=7) :: drvrinst
character(len=5) :: inst_suffix
character(len=CX) :: msgstr
Expand Down Expand Up @@ -377,10 +377,8 @@ subroutine SetModelServices(ensemble_driver, rc)
endif
call shr_log_setLogUnit (logunit)
! Create a clock for each driver instance

call esm_time_clockInit(ensemble_driver, driver, logunit, localpet==petList(1), rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

enddo
inst = localPet/(ntasks_per_member+pio_asyncio_ntasks) + 1

Expand Down
1 change: 1 addition & 0 deletions cesm/driver/esm.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,7 @@ subroutine esm_finalize(driver, rc)

call ESMF_LogWrite(trim(subname)//": called", ESMF_LOGMSG_INFO)
rc = ESMF_SUCCESS

call shr_log_setLogunit(logunit)
call ESMF_GridCompGet(driver, vm=vm, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
Expand Down
1 change: 0 additions & 1 deletion cesm/driver/esm_time_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ subroutine esm_time_clockInit(ensemble_driver, instance_driver, logunit, maintas
call ESMF_TimeSet( RefTime, yy=yr, mm=mon, dd=day, s=ref_tod, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return


call ESMF_TimeIntervalSet( TimeStep, s=dtime_drv, rc=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return

Expand Down
363 changes: 242 additions & 121 deletions mediator/esmFldsExchange_hafs_mod.F90

Large diffs are not rendered by default.

70 changes: 44 additions & 26 deletions mediator/esmFldsExchange_ufs_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,6 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc)
call addfld_ocnalb('So_anidf')
end if

! Advertise the ocean albedos. These are not sent to the ATM in UFS.
if (phase == 'advertise') then
call addfld_ocnalb('So_avsdr')
call addfld_ocnalb('So_avsdf')
call addfld_ocnalb('So_anidr')
call addfld_ocnalb('So_anidf')
end if

!=====================================================================
! FIELDS TO ATMOSPHERE (compatm)
!=====================================================================
Expand Down Expand Up @@ -242,18 +234,46 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc)
end if
end if

! to atm: unmerged surface temperatures from lnd
if (phase == 'advertise') then
if (is_local%wrap%comp_present(complnd) .and. is_local%wrap%comp_present(compatm)) then
call addfld_from(complnd , 'Sl_t')
call addfld_to(compatm , 'Sl_t')
! to atm: unmerged flux components from lnd
if (is_local%wrap%comp_present(complnd) .and. is_local%wrap%comp_present(compatm)) then
allocate(flds(6))
flds = (/ 'lat ', 'sen ', 'evap', 'gflx', 'roff', 'soff' /)
if (phase == 'advertise') then
do n = 1,size(flds)
call addfld_from(complnd, 'Fall_'//trim(flds(n)))
call addfld_to(compatm, 'Fall_'//trim(flds(n)))
end do
else
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 addmrg_to(compatm, 'Fall_'//trim(flds(n)), mrg_from=complnd, mrg_fld='Fall_'//trim(flds(n)), mrg_type='copy')
end if
end do
end if
else
if ( fldchk(is_local%wrap%FBexp(compatm) , 'Sl_t', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(complnd,complnd), 'Sl_t', rc=rc)) then
call addmap_from(complnd, 'Sl_t', compatm, maptype, 'lfrin', 'unset')
call addmrg_to(compatm, 'Sl_t', mrg_from=complnd, mrg_fld='Sl_t', mrg_type='copy')
deallocate(flds)
end if

! to atm: unmerged state variables from lnd
if (is_local%wrap%comp_present(complnd) .and. is_local%wrap%comp_present(compatm)) then
allocate(flds(7))
flds = (/ 'sfrac', 'tref ', 'qref ', 'q ', 'cmm ', 'chh ', 'zvfun' /)
if (phase == 'advertise') then
do n = 1,size(flds)
call addfld_from(complnd, 'Sl_'//trim(flds(n)))
call addfld_to(compatm, 'Sl_'//trim(flds(n)))
end do
else
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 addmrg_to(compatm, 'Sl_'//trim(flds(n)), mrg_from=complnd, mrg_fld='Sl_'//trim(flds(n)), mrg_type='copy')
end if
end do
end if
deallocate(flds)
end if

! to atm: unmerged from mediator, merge will be done under FV3/CCPP composite step
Expand Down Expand Up @@ -724,18 +744,16 @@ subroutine esmFldsExchange_ufs(gcomp, phase, rc)
if ( trim(coupling_mode) == 'ufs.nfrac.aoflux') then
allocate(flds(21))
flds = (/'Sa_z ', 'Sa_topo ', 'Sa_tbot ', 'Sa_pbot ', &
'Sa_shum ', 'Sa_u ', 'Sa_v ', 'Faxa_lwdn ', &
'Sa_ptem ', 'Sa_dens ', 'Faxa_swdn ', 'Sa_pslv ', &
'Faxa_snowc', 'Faxa_snowl', 'Faxa_rainc', 'Faxa_rainl', &
'Faxa_swndr', 'Faxa_swndf', 'Faxa_swvdr', 'Faxa_swvdf', &
'Faxa_swnet'/)
'Sa_shum ', 'Sa_u ', 'Sa_v ', 'Sa_pslv ', &
'Faxa_lwdn ', 'Faxa_swdn ', 'Faxa_snowc', 'Faxa_snowl', &
'Faxa_rainc', 'Faxa_rainl', 'Faxa_rain ', 'Faxa_swnet'/)
else
allocate(flds(18))
flds = (/'Sa_z ', 'Sa_ta ', 'Sa_pslv ', 'Sa_qa ', &
'Sa_ua ', 'Sa_va ', 'Faxa_swdn ', 'Faxa_lwdn ', &
'Faxa_swnet', 'Faxa_rain ', 'Sa_prsl ', 'vfrac ', &
'Sa_u ', 'Sa_v ', 'Faxa_swdn ', 'Faxa_lwdn ', &
'Faxa_swnet', 'Faxa_rain ', 'Sa_prsl ', 'Sa_vfrac ', &
'Faxa_snow ', 'Faxa_rainc', 'Sa_tskn ', 'Sa_exner ', &
'Sa_ustar ', 'zorl ' /)
'Sa_ustar ', 'Sa_zorl ' /)
end if
do n = 1,size(flds)
fldname = trim(flds(n))
Expand Down
37 changes: 33 additions & 4 deletions mediator/med.F90
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ subroutine SetServices(gcomp, rc)
use med_diag_mod , only: med_phases_diag_ice_ice2med, med_phases_diag_ice_med2ice
use med_fraction_mod , only: med_fraction_init, med_fraction_set
use med_phases_profile_mod , only: med_phases_profile
#ifdef CDEPS_INLINE
jedwards4b marked this conversation as resolved.
Show resolved Hide resolved
use med_phases_cdeps_mod , only: med_phases_cdeps_run
#endif

! input/output variables
type(ESMF_GridComp) :: gcomp
Expand Down Expand Up @@ -505,6 +508,19 @@ subroutine SetServices(gcomp, rc)
specPhaselabel="med_phases_diag_print", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

#ifdef CDEPS_INLINE
!------------------
! phase routine for cdeps inline capabilty
!------------------

call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_cdeps_run"/), userRoutine=mediator_routine_Run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_Advance, &
specPhaseLabel="med_phases_cdeps_run", specRoutine=med_phases_cdeps_run, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
#endif

!------------------
! attach specializing method(s)
! -> NUOPC specializes by default --->>> first need to remove the default
Expand Down Expand Up @@ -934,6 +950,22 @@ subroutine AdvertiseFields(gcomp, importState, exportState, clock, rc)
endif
endif

! Should terget component use all data for first time step?
uturuncoglu marked this conversation as resolved.
Show resolved Hide resolved
do ncomp = 1,ncomps
if (ncomp /= compmed) then
call NUOPC_CompAttributeGet(gcomp, name=trim(compname(ncomp))//"_use_data_first_import", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue, *) is_local%wrap%med_data_force_first(ncomp)
else
is_local%wrap%med_data_force_first(ncomp) = .false.
endif
if (maintask) then
write(logunit,*) trim(compname(ncomp))//'_use_data_first_import is ', is_local%wrap%med_data_force_first(ncomp)
endif
end if
end do

if (profile_memory) call ESMF_VMLogMemInfo("Leaving "//trim(subname))
call ESMF_LogWrite(trim(subname)//": done", ESMF_LOGMSG_INFO)

Expand Down Expand Up @@ -1023,7 +1055,6 @@ subroutine ModifyDecompofMesh(gcomp, importState, exportState, clock, rc)
type(InternalState) :: is_local
integer :: n1
character(len=*), parameter :: subname = '('//__FILE__//':ModifyDecompofMesh)'

!-----------------------------------------------------------

call ESMF_LogWrite(trim(subname)//": called", ESMF_LOGMSG_INFO)
Expand Down Expand Up @@ -1352,7 +1383,6 @@ subroutine RealizeFieldsWithTransferAccept(gcomp, importState, exportState, cloc
type(InternalState) :: is_local
integer :: n1
character(len=*), parameter :: subname = '('//__FILE__//':RealizeFieldsWithTransferAccept)'

!-----------------------------------------------------------

call ESMF_LogWrite(trim(subname)//": called", ESMF_LOGMSG_INFO)
Expand Down Expand Up @@ -1805,7 +1835,7 @@ subroutine DataInitialize(gcomp, rc)
else if (trim(coupling_mode(1:3)) == 'ufs') then
call esmFldsExchange_ufs(gcomp, phase='initialize', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
else if (trim(coupling_mode) == 'hafs') then
else if (trim(coupling_mode(1:4)) == 'hafs') then
jedwards4b marked this conversation as resolved.
Show resolved Hide resolved
call esmFldsExchange_hafs(gcomp, phase='initialize', rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
Expand Down Expand Up @@ -2222,7 +2252,6 @@ subroutine SetRunClock(gcomp, rc)
integer :: stop_n, stop_ymd
logical, save :: stopalarmcreated=.false.
character(len=*), parameter :: subname = '('//__FILE__//':SetRunClock)'

!-----------------------------------------------------------

rc = ESMF_SUCCESS
Expand Down
37 changes: 27 additions & 10 deletions mediator/med_internalstate_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module med_internalstate_mod

integer, public :: logunit ! logunit for mediator log output
integer, public :: diagunit ! diagunit for budget output (med main only)
logical, public :: maintask=.false. ! is this the maintask
logical, public :: maintask = .false. ! is this the maintask
integer, public :: med_id ! needed currently in med_io_mod and set in esm.F90

! Components
Expand Down Expand Up @@ -47,7 +47,7 @@ module med_internalstate_mod
character(len=CS), public :: glc_name = ''

! Coupling mode
character(len=CS), public :: coupling_mode ! valid values are [cesm,ufs.nfrac,ufs.frac,ufs.nfrac.aoflux,ufs.frac.aoflux,hafs]
character(len=CS), public :: coupling_mode ! valid values are [cesm,ufs.nfrac,ufs.frac,ufs.nfrac.aoflux,ufs.frac.aoflux,hafs,hafs.mom6]

! Atmosphere-ocean flux algorithm
character(len=CS), public :: aoflux_code ! valid values are [cesm,ccpp]
Expand Down Expand Up @@ -119,10 +119,12 @@ module med_internalstate_mod
type InternalStateStruct

! Present/allowed coupling/active coupling logical flags
logical, pointer :: comp_present(:) ! comp present flag
logical, pointer :: med_coupling_active(:,:) ! computes the active coupling
integer :: num_icesheets ! obtained from attribute
logical :: ocn2glc_coupling = .false. ! obtained from attribute
logical, pointer :: comp_present(:) ! comp present flag
logical, pointer :: med_coupling_active(:,:) ! computes the active coupling
logical, pointer :: med_data_active(:,:) ! uses stream data to provide background fill
logical, pointer :: med_data_force_first(:) ! force to use stream data for first coupling timestep
integer :: num_icesheets ! obtained from attribute
logical :: ocn2glc_coupling = .false. ! obtained from attribute
logical :: lnd2glc_coupling = .false.
logical :: accum_lnd2glc = .false.

Expand All @@ -147,10 +149,10 @@ module med_internalstate_mod
! FBImp(n,n) = NState_Imp(n), copied in connector post phase
! FBImp(n,k) is the FBImp(n,n) interpolated to grid k
! Import/export States and field bundles (the field bundles have the scalar fields removed)
type(ESMF_State) , pointer :: NStateImp(:) ! Import data from various component, on their grid
type(ESMF_State) , pointer :: NStateExp(:) ! Export data to various component, on their grid
type(ESMF_FieldBundle) , pointer :: FBImp(:,:) ! Import data from various components interpolated to various grids
type(ESMF_FieldBundle) , pointer :: FBExp(:) ! Export data for various components, on their grid
type(ESMF_State) , pointer :: NStateImp(:) ! Import data from various component, on their grid
type(ESMF_State) , pointer :: NStateExp(:) ! Export data to various component, on their grid
type(ESMF_FieldBundle) , pointer :: FBImp(:,:) ! Import data from various components interpolated to various grids
type(ESMF_FieldBundle) , pointer :: FBExp(:) ! Export data for various components, on their grid

! Mediator field bundles for ocean albedo
type(ESMF_FieldBundle) :: FBMed_ocnalb_o ! Ocn albedo on ocn grid
Expand All @@ -173,6 +175,9 @@ module med_internalstate_mod
! Fractions
type(ESMF_FieldBundle), pointer :: FBfrac(:) ! Fraction data for various components, on their grid

! Data
type(ESMF_FieldBundle) , pointer :: FBData(:) ! Background data for various components, on their grid, provided by CDEPS inline

! Accumulators for export field bundles
type(ESMF_FieldBundle) :: FBExpAccumOcn ! Accumulator for Ocn export on Ocn grid
integer :: ExpAccumOcnCnt = 0 ! Accumulator counter for FBExpAccumOcn
Expand Down Expand Up @@ -303,6 +308,8 @@ subroutine med_internalstate_init(gcomp, rc)

! Allocate memory now that ncomps is determined
allocate(is_local%wrap%med_coupling_active(ncomps,ncomps))
allocate(is_local%wrap%med_data_active(ncomps,ncomps))
allocate(is_local%wrap%med_data_force_first(ncomps))
allocate(is_local%wrap%nx(ncomps))
allocate(is_local%wrap%ny(ncomps))
allocate(is_local%wrap%NStateImp(ncomps))
Expand All @@ -316,6 +323,7 @@ subroutine med_internalstate_init(gcomp, rc)
allocate(is_local%wrap%packed_data(ncomps,ncomps,nmappers))
allocate(is_local%wrap%FBfrac(ncomps))
allocate(is_local%wrap%FBArea(ncomps))
allocate(is_local%wrap%FBData(ncomps))
allocate(is_local%wrap%mesh_info(ncomps))

! Determine component names
Expand Down Expand Up @@ -364,6 +372,15 @@ subroutine med_internalstate_init(gcomp, rc)
write(msgString,*) trim(subname)//': Mediator dststatus_print is ',dststatus_print
call ESMF_LogWrite(trim(msgString), ESMF_LOGMSG_INFO)

! Initialize flag for background fill using data
is_local%wrap%med_data_active(:,:) = .false.
is_local%wrap%med_data_active(compocn,compatm) = .true.
is_local%wrap%med_data_active(compatm,compocn) = .true.
is_local%wrap%med_data_active(compatm,compwav) = .true.

! Initialize flag to force using data in first coupling time step
is_local%wrap%med_data_force_first(:) = .false.

end subroutine med_internalstate_init

!=====================================================================
Expand Down
Loading
Loading