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

Add Wave slow loop coupling and Field Exchanges for waves in nems #266

Merged
merged 30 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
233a89b
add fix for file writing when dststatus_print=true
DeniseWorthen Sep 7, 2021
c26a1b6
Merge remote-tracking branch 'escomp/master' into feature/updcmeps
DeniseWorthen Sep 21, 2021
aae1fe9
Merge remote-tracking branch 'escomp/master' into feature/updcmeps
DeniseWorthen Oct 13, 2021
a0011cb
Merge remote-tracking branch 'MV/feature/cism_bugfixes' into feature/…
DeniseWorthen Oct 15, 2021
843a1f1
add u10m,v10m from atm->wav
DeniseWorthen Oct 21, 2021
f0fa04c
add wave->atm field
DeniseWorthen Oct 27, 2021
5beead0
Update CMEPS (#58)
DeniseWorthen Oct 29, 2021
be3b1bb
Merge branch 'NOAA-EMC:emc/develop' into feature/wavcoupling
DeniseWorthen Oct 29, 2021
16364c2
add more wav coupling fields
DeniseWorthen Oct 29, 2021
fff8fbc
change mapping for z0
DeniseWorthen Oct 29, 2021
8be8da0
add -> wav in post atm and post ocn
DeniseWorthen Oct 30, 2021
8ec7328
add unity norm for wave
DeniseWorthen Oct 30, 2021
6b59926
current tested changes for wave coupling
DeniseWorthen Nov 12, 2021
7a44b63
fix merge of stokes to ocn
DeniseWorthen Nov 14, 2021
8b117b4
Update CMEPS (#60)
DeniseWorthen Dec 16, 2021
cd2ae27
Merge branch 'NOAA-EMC:emc/develop' into feature/wavcoupling
DeniseWorthen Dec 16, 2021
b873989
change Sw_zo to Sw_z0 for hafs
DeniseWorthen Dec 21, 2021
5fb8561
switch src/dst masks for wave
DeniseWorthen Dec 23, 2021
84a17b7
tidy up, remove commented out code blocks
DeniseWorthen Dec 27, 2021
94ead4a
initial commit for waves in slow loop
DeniseWorthen Dec 31, 2021
1a27645
compile fixes
DeniseWorthen Dec 31, 2021
5cfe6c2
add retrieval of wav accum values on restart
DeniseWorthen Jan 3, 2022
5640b6b
Merge remote-tracking branch 'escomp/master' into feature/wavslowbs1
DeniseWorthen Jan 12, 2022
907a966
remove extra ice->atm mapping in post ice
DeniseWorthen Jan 12, 2022
e442504
fix compile errors
DeniseWorthen Jan 17, 2022
dcf29bf
Merge remote-tracking branch 'escomp/master' into feature/wavslowbs1
DeniseWorthen Jan 20, 2022
40be8c3
simplify src/dst masking for nems
DeniseWorthen Jan 21, 2022
963557d
fix nx,ny for compwav for writing accumWav
DeniseWorthen Jan 22, 2022
6066d50
insert conditional for waves in nems
DeniseWorthen Jan 22, 2022
3c5d32d
fixes for cesm run sequence
Jan 31, 2022
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 cime_config/runseq/runseq_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ def gen_runseq(case, coupling_times):
runseq.add_action("MED med_phases_prep_ice" , med_to_ice)
runseq.add_action("MED -> ICE :remapMethod=redist" , med_to_ice)

runseq.add_action("MED med_phases_prep_wav" , med_to_wav)
runseq.add_action("MED med_phases_prep_wav_accum" , med_to_wav)
runseq.add_action("MED med_phases_prep_wav_avg" , med_to_wav)
runseq.add_action("MED -> WAV :remapMethod=redist" , med_to_wav)

runseq.add_action("MED med_phases_prep_rof" , med_to_rof and not rof_outer_loop)
Expand Down
4 changes: 2 additions & 2 deletions mediator/esmFldsExchange_hafs_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ subroutine esmFldsExchange_hafs_advt(gcomp, phase, rc)
! ---------------------------------------------------------------------
if (hafs_attr%atm_present .and. hafs_attr%wav_present) then
allocate(S_flds(1))
S_flds = (/'Sw_zo'/) ! wave_z0_roughness_length
S_flds = (/'Sw_z0'/) ! wave_z0_roughness_length
do n = 1,size(S_flds)
fldname = trim(S_flds(n))
call addfld(fldListFr(compwav)%flds, trim(fldname))
Expand Down Expand Up @@ -385,7 +385,7 @@ subroutine esmFldsExchange_hafs_init(gcomp, phase, rc)
! ---------------------------------------------------------------------
if (hafs_attr%atm_present .and. hafs_attr%wav_present) then
allocate(S_flds(1))
S_flds = (/'Sw_zo'/) ! wave_z0_roughness_length
S_flds = (/'Sw_z0'/) ! wave_z0_roughness_length
do n = 1,size(S_flds)
fldname = trim(S_flds(n))
if (fldchk(is_local%wrap%FBExp(compatm),trim(fldname),rc=rc) .and. &
Expand Down
75 changes: 74 additions & 1 deletion mediator/esmFldsExchange_nems_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ subroutine esmFldsExchange_nems(gcomp, phase, rc)
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_internalstate_mod , only : InternalState
use med_internalstate_mod , only : mastertask, logunit
use med_internalstate_mod , only : compmed, compatm, compocn, compice, comprof, ncomps
use med_internalstate_mod , only : compmed, compatm, compocn, compice, comprof, compwav, ncomps
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
Expand All @@ -42,6 +43,7 @@ subroutine esmFldsExchange_nems(gcomp, phase, rc)
integer , intent(inout) :: rc

! local variables:
type(InternalState) :: is_local
integer :: i, n, maptype
character(len=CX) :: msgString
character(len=CL) :: cvalue
Expand All @@ -52,6 +54,10 @@ subroutine esmFldsExchange_nems(gcomp, phase, rc)

rc = ESMF_SUCCESS

nullify(is_local%wrap)
call ESMF_GridCompGetInternalState(gcomp, is_local, rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

! Set maptype according to coupling_mode
if (trim(coupling_mode) == 'nems_orig' .or. trim(coupling_mode) == 'nems_orig_data') then
maptype = mapnstod_consf
Expand Down Expand Up @@ -159,6 +165,16 @@ subroutine esmFldsExchange_nems(gcomp, phase, rc)
call addmap(fldListFr(compocn)%flds, 'So_t', compatm, maptype, 'ofrac', 'unset')
call addmrg(fldListTo(compatm)%flds, 'So_t', mrg_from=compocn, mrg_fld='So_t', mrg_type='copy')

! temporary conditional to avoid conflicts of advertised fields
! when waves are passing through connectors
if (is_local%wrap%comp_present(compwav)) then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, we were also using these type conditionals in the HAFS specific field exchange file. I think it would be nice to unify those files to single one in the future. I think the conditional could also include the name of the component.

Copy link
Collaborator Author

@DeniseWorthen DeniseWorthen Jan 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the use in hafs is not quite the same. For both hafs and cesm, there are two calls to the fldsExchange, one for advertise and one for initialize. The conditionals I see in the hafs and cesm fldExchanges are related to that---in both cases at the initialize call you're doing the addmap,addmerge only if the field is in the expFB and also present in the impFB. I do think it would be nice to have a cleaner way of doing all that checking though.

But for the nems modes, esmFieldsExchange_nems is only called once (for phase=advertise) and the addmap and addmerge are done then. There is no checking for whether the fields are present or not. I did consider this as an issue, and refactored the esmfFieldsExchange_nems to do both an advertise and an initialize phase like for hafs and cesm. But I still had the same issue---with waves going through the connectors, having the mediator also trying to advertise those same fields (even if they're not connected) broke reproducibility. So this conditional completely removes the advertisement of fields if the mediator is not in use for the waves.

! to atm: surface roughness length from wav
call addfld(fldListFr(compwav)%flds, 'Sw_z0')
call addfld(fldListTo(compatm)%flds, 'Sw_z0')
call addmap(fldListFr(compwav)%flds, 'Sw_z0', compatm, mapnstod_consf, 'one', 'unset')
call addmrg(fldListTo(compatm)%flds, 'Sw_z0', mrg_from=compwav, mrg_fld='Sw_z0', mrg_type='copy')
end if

!=====================================================================
! FIELDS TO OCEAN (compocn)
!=====================================================================
Expand Down Expand Up @@ -291,6 +307,23 @@ subroutine esmFldsExchange_nems(gcomp, phase, rc)
end do
deallocate(flds)

! temporary conditional to avoid conflicts of advertised fields
! when waves are passing through connectors
if (is_local%wrap%comp_present(compwav)) then
! to ocn: partitioned stokes drift from wav
allocate(flds(6))
flds = (/'Sw_ustokes1', 'Sw_ustokes2', 'Sw_ustokes3', &
'Sw_vstokes1', 'Sw_vstokes2', 'Sw_vstokes3'/)
do n = 1,size(flds)
fldname = trim(flds(n))
call addfld(fldListTo(compocn)%flds, trim(fldname))
call addfld(fldListFr(compwav)%flds, trim(fldname))
call addmap(fldListFr(compwav)%flds, trim(fldname), compocn, mapfcopy, 'unset', 'unset')
call addmrg(fldListTo(compocn)%flds, trim(fldname), mrg_from=compwav, mrg_fld=trim(fldname), mrg_type='copy')
end do
deallocate(flds)
end if

!=====================================================================
! FIELDS TO ICE (compice)
!=====================================================================
Expand Down Expand Up @@ -353,6 +386,46 @@ subroutine esmFldsExchange_nems(gcomp, phase, rc)
end do
deallocate(flds)

!=====================================================================
! FIELDS TO WAV (compwav)
!=====================================================================

! temporary conditional to avoid conflicts of advertised fields
! when waves are passing through connectors
if (is_local%wrap%comp_present(compwav)) then
! to wav - 10m winds and bottom temperature from atm
allocate(flds(3))
flds = (/'Sa_u10m', 'Sa_v10m', 'Sa_tbot'/)
do n = 1,size(flds)
fldname = trim(flds(n))
call addfld(fldListFr(compatm)%flds, trim(fldname))
call addfld(fldListTo(compwav)%flds, trim(fldname))
call addmap(fldListFr(compatm)%flds, trim(fldname), compwav, mapnstod_consf, 'one', 'unset')
call addmrg(fldListTo(compwav)%flds, trim(fldname), mrg_from=compatm, mrg_fld=trim(fldname), mrg_type='copy')
end do
deallocate(flds)

! to wav: sea ice fraction
call addfld(fldListTo(compwav)%flds, 'Si_ifrac')
call addfld(fldListFr(compice)%flds, 'Si_ifrac')
call addmap(fldListFr(compice)%flds, 'Si_ifrac', compwav, mapfcopy , 'unset', 'unset')
call addmrg(fldListTo(compwav)%flds, 'Si_ifrac', mrg_from=compice, mrg_fld='Si_ifrac', mrg_type='copy')

! to wav: zonal sea water velocity from ocn
! to wav: meridional sea water velocity from ocn
! to wav: surface temperature from ocn
allocate(flds(3))
flds = (/'So_u', 'So_v', 'So_t'/)
do n = 1,size(flds)
fldname = trim(flds(n))
call addfld(fldListTo(compwav)%flds, trim(fldname))
call addfld(fldListFr(compocn)%flds, trim(fldname))
call addmap(fldListFr(compocn)%flds, trim(fldname), compwav, mapfcopy , 'unset', 'unset')
call addmrg(fldListTo(compwav)%flds, trim(fldname), mrg_from=compocn, mrg_fld=trim(fldname), mrg_type='copy')
end do
deallocate(flds)
end if

end subroutine esmFldsExchange_nems

end module esmFldsExchange_nems_mod
38 changes: 30 additions & 8 deletions mediator/med.F90
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ subroutine SetServices(gcomp, rc)
use med_phases_prep_atm_mod , only: med_phases_prep_atm
use med_phases_prep_ice_mod , only: med_phases_prep_ice
use med_phases_prep_lnd_mod , only: med_phases_prep_lnd
use med_phases_prep_wav_mod , only: med_phases_prep_wav
use med_phases_prep_wav_mod , only: med_phases_prep_wav_accum
use med_phases_prep_wav_mod , only: med_phases_prep_wav_avg
use med_phases_prep_glc_mod , only: med_phases_prep_glc
use med_phases_prep_rof_mod , only: med_phases_prep_rof
use med_phases_prep_ocn_mod , only: med_phases_prep_ocn_accum
Expand Down Expand Up @@ -343,10 +344,20 @@ subroutine SetServices(gcomp, rc)
!------------------

call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_prep_wav"/), userRoutine=mediator_routine_Run, rc=rc)
phaseLabelList=(/"med_phases_prep_wav_accum"/), 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_prep_wav", specRoutine=med_phases_prep_wav, rc=rc)
specPhaseLabel="med_phases_prep_wav_accum", specRoutine=med_phases_prep_wav_accum, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call NUOPC_CompSpecialize(gcomp, specLabel=mediator_label_TimestampExport, &
specPhaselabel="med_phases_prep_wav_accum", specRoutine=NUOPC_NoOp, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
phaseLabelList=(/"med_phases_prep_wav_avg"/), 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_prep_wav_avg", specRoutine=med_phases_prep_wav_avg, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call NUOPC_CompSetEntryPoint(gcomp, ESMF_METHOD_RUN, &
Expand Down Expand Up @@ -638,7 +649,7 @@ subroutine InitializeIPDv03p1(gcomp, importState, exportState, clock, rc)
! TransferOfferGeomObject Attribute.

use ESMF , only : ESMF_GridComp, ESMF_State, ESMF_Clock, ESMF_SUCCESS, ESMF_LogFoundAllocError
use ESMF , only : ESMF_StateIsCreated
use ESMF , only : ESMF_StateIsCreated
use ESMF , only : ESMF_LogMsg_Info, ESMF_LogWrite
use ESMF , only : ESMF_END_ABORT, ESMF_Finalize, ESMF_MAXSTR
use NUOPC , only : NUOPC_AddNamespace, NUOPC_Advertise, NUOPC_AddNestedState
Expand Down Expand Up @@ -1498,6 +1509,7 @@ subroutine DataInitialize(gcomp, rc)
use med_fraction_mod , only : med_fraction_init, med_fraction_set
use med_phases_restart_mod , only : med_phases_restart_read
use med_phases_prep_ocn_mod , only : med_phases_prep_ocn_init
use med_phases_prep_wav_mod , only : med_phases_prep_wav_init
use med_phases_prep_rof_mod , only : med_phases_prep_rof_init
use med_phases_prep_glc_mod , only : med_phases_prep_glc_init
use med_phases_prep_atm_mod , only : med_phases_prep_atm
Expand Down Expand Up @@ -1784,6 +1796,16 @@ subroutine DataInitialize(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

!---------------------------------------
! Initialize wav export accumulation field bundle
!---------------------------------------
if ( is_local%wrap%comp_present(compwav) .and. &
ESMF_StateIsCreated(is_local%wrap%NStateImp(compwav),rc=rc) .and. &
ESMF_StateIsCreated(is_local%wrap%NStateExp(compwav),rc=rc)) then
call med_phases_prep_wav_init(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

!---------------------------------------
! Initialize glc module field bundles here if appropriate
!---------------------------------------
Expand Down Expand Up @@ -2059,12 +2081,12 @@ subroutine DataInitialize(gcomp, rc)
! Call post routines as part of initialization
!---------------------------------------
if (is_local%wrap%comp_present(compatm)) then
! map atm->ocn, atm->ice, atm->lnd
! map atm->ocn, atm->ice, atm->lnd, atm->wav
call med_phases_post_atm(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
if (is_local%wrap%comp_present(compice)) then
! call set ice_frac and map ice->atm and ice->ocn
! call set ice_frac and map ice->ocn and ice->wav
call med_phases_post_ice(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
Expand All @@ -2079,7 +2101,7 @@ subroutine DataInitialize(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
if (is_local%wrap%comp_present(compocn)) then
! map initial ocn->ice
! map initial ocn->ice, ocn->wav
call med_phases_post_ocn(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
Expand All @@ -2089,7 +2111,7 @@ subroutine DataInitialize(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
if (is_local%wrap%comp_present(compwav)) then
! map initial wav->ocn and wav->ice
! map initial wav->ocn, wav->ice, wav->atm
call med_phases_post_wav(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
Expand Down
6 changes: 4 additions & 2 deletions mediator/med_internalstate_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ module med_internalstate_mod
type(ESMF_FieldBundle), pointer :: FBfrac(:) ! Fraction data for various components, on their grid

! Accumulators for export field bundles
type(ESMF_FieldBundle) :: FBExpAccumOcn ! Accumulator for various components export on their grid
integer :: ExpAccumOcnCnt = 0 ! Accumulator counter for each FBExpAccum
type(ESMF_FieldBundle) :: FBExpAccumOcn ! Accumulator for Ocn export on Ocn grid
integer :: ExpAccumOcnCnt = 0 ! Accumulator counter for FBExpAccumOcn
type(ESMF_FieldBundle) :: FBExpAccumWav ! Accumulator for Wav export on Wav grid
integer :: ExpAccumWavCnt = 0 ! Accumulator counter for FBExpAccumWav

! Component Mesh info
type(mesh_info_type) , pointer :: mesh_info(:)
Expand Down
Loading