Skip to content

Commit

Permalink
Merge pull request #1 from mvertens/feature/fix_wavice_coupling
Browse files Browse the repository at this point in the history
minor fixes for ww3/cice coupling and update of code to cmeps0.14.24.
  • Loading branch information
mvertens authored Apr 26, 2023
2 parents d8ddff5 + e50d27d commit 0bab18a
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 23 deletions.
112 changes: 112 additions & 0 deletions cesm/nuopc_cap_share/shr_lightning_coupling_mod.F90
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
module shr_lightning_coupling_mod

!========================================================================
! Module for handling namelist variables related to lightning coupling
!========================================================================

use ESMF , only : ESMF_VMGetCurrent, ESMF_VM, ESMF_VMGet
use ESMF , only : ESMF_LOGERR_PASSTHRU, ESMF_SUCCESS
use ESMF , only : ESMF_VMBroadCast, ESMF_Logical, assignment(=)
use shr_sys_mod , only : shr_sys_abort
use shr_log_mod , only : shr_log_getLogUnit
use shr_nl_mod , only : shr_nl_find_group_name
use nuopc_shr_methods, only : chkerr

implicit none
private

! !PUBLIC MEMBER FUNCTIONS
public shr_lightning_coupling_readnl ! Read namelist

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

!====================================================================================
CONTAINS
!====================================================================================

subroutine shr_lightning_coupling_readnl(NLFilename, atm_provides_lightning_out)

!========================================================================
! reads lightning_coupling_nl namelist and returns a variable specifying
! if atmosphere model provides lightning flash frequency field to mediator
!========================================================================

! input/output variables
character(len=*), intent(in) :: NLFilename ! Namelist filename
logical, intent(out) :: atm_provides_lightning_out ! if TRUE atm will provide lightning flash frequency

!----- local -----
logical :: atm_provides_lightning
type(ESMF_VM) :: vm
integer :: unitn ! namelist unit number
integer :: ierr ! error code
logical :: exists ! if file exists or not
type(ESMF_Logical):: ltmp(1)
integer :: rc
integer :: localpet
integer :: mpicom
integer :: s_logunit
character(len=*), parameter :: atm_ozone_frequency_not_present = 'NOT_PRESENT'
character(len=*), parameter :: subname = '(shr_lightning_coupling_readnl) '
! ------------------------------------------------------------------

namelist /lightning_coupling_nl/ atm_provides_lightning

rc = ESMF_SUCCESS

atm_provides_lightning_out = .false.
ltmp(1) = .false.

!--- Open and read namelist ---
if ( len_trim(NLFilename) == 0 ) then
call shr_sys_abort( subname//'ERROR: nlfilename not set' )
end if
call shr_log_getLogUnit(s_logunit)
call ESMF_VMGetCurrent(vm, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

call ESMF_VMGet(vm, localPet=localpet, mpiCommunicator=mpicom, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

if (localpet==0) then
! ------------------------------------------------------------------------
! Set default values in case namelist file doesn't exist, lightning_coupling_nl group
! doesn't exist within the file, or a given variable isn't present in the namelist
! group in the file.
! ------------------------------------------------------------------------
atm_provides_lightning = .false.

! ------------------------------------------------------------------------
! Read namelist file
! ------------------------------------------------------------------------
inquire( file=trim(NLFileName), exist=exists)
if ( exists ) then
open(newunit=unitn, file=trim(NLFilename), status='old' )
write(s_logunit,'(a)') subname,'Read in lightning_coupling_nl namelist from: ', trim(NLFilename)
call shr_nl_find_group_name(unitn, 'lightning_coupling_nl', ierr)
if (ierr == 0) then
! Note that ierr /= 0 means no namelist is present.
read(unitn, lightning_coupling_nl, iostat=ierr)
if (ierr > 0) then
call shr_sys_abort(subname//'problem reading lightning_coupling_nl')
end if
end if
close( unitn )
end if

ltmp(1) = atm_provides_lightning

end if

! ------------------------------------------------------------------------
! Broadcast values to all tasks
! ------------------------------------------------------------------------
call ESMF_VMBroadcast(vm, ltmp, count=1, rootPet=0, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return

atm_provides_lightning_out = ltmp(1)

end subroutine shr_lightning_coupling_readnl

end module shr_lightning_coupling_mod
8 changes: 2 additions & 6 deletions cime_config/buildnml
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,13 @@ def _create_drv_namelists(case, infile, confdir, nmlgen, files):
elif case.get_value("RUN_TYPE") == "branch":
config["run_type"] = "branch"

config['wav_ice_coupling'] = config['COMP_WAV'] == 'ww3dev' and config['COMP_ICE'] == 'cice'

# ----------------------------------------------------
# Initialize namelist defaults
# ----------------------------------------------------
nmlgen.init_defaults(infile, config, skip_default_for_groups=["modelio"])

# --------------------------------
# Set default wav-ice coupling (assumes cice6 as the ice component
# --------------------------------
if case.get_value("COMP_WAV") == "ww3dev" and case.get_value("COMP_ICE") == "cice":
nmlgen.add_default("wavice_coupling", value=".true.")

# --------------------------------
# Overwrite: set brnch_retain_casename
# --------------------------------
Expand Down
8 changes: 8 additions & 0 deletions cime_config/config_component_cesm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,15 @@
<value compset="_CAM">CO2A</value>
<value compset="_DATM">none</value>
<value compset="_DATM%CPLHIST.+POP\d">CO2A</value>
<value compset="_DATM%CPLHIST.+BLOM%ECO">CO2A</value>
<value compset="^OMIP_DATM%IAF.*_POP2%[^_]*ECO">CO2A</value>
<value compset="^OMIP_DATM%JRA.*_POP2%[^_]*ECO">CO2A</value>
<value compset="HIST.*_DATM.*_CLM">CO2A</value>
<value compset="SSP.*_DATM.*_CLM">CO2A</value>
<value compset="_BGC%BPRP">CO2C</value>
<value compset="_BGC%BDRD">CO2C</value>
<value compset="20TR_DATM%IAF.*_BLOM%ECO">CO2A</value>
<value compset="20TR_DATM%JRA.*_BLOM%ECO">CO2A</value>
</values>
<group>run_coupling</group>
<file>env_run.xml</file>
Expand Down Expand Up @@ -232,6 +235,11 @@
<!-- =================================================== -->
<!-- TODO: why is this here? -->
<value compset="_DLND.*_CISM\d">1</value>
<!-- =================================================== -->
<!-- N compsets -->
<!-- =================================================== -->
<value compset="_DATM.*_BLOM">24</value>
<value compset="_BLOM" grid="oi%tnx0.25v">48</value>
</values>
<group>run_coupling</group>
<file>env_run.xml</file>
Expand Down
17 changes: 10 additions & 7 deletions cime_config/namelist_definition_drv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2156,25 +2156,25 @@
<value samegrid_atm_lnd='true'>idmap</value>
</values>
</entry>
<entry id="lnd2rof_map">
<entry id="lnd2rof_map" modify_via_xml="LND2ROF_FMAPNAME">
<type>char</type>
<category>mapping</category>
<input_pathname>abs</input_pathname>
<group>MED_attributes</group>
<desc>lnd to rof mapping, 'unset' or 'idmap' are normal possible values</desc>
<desc>lnd to rof mapping, 'unset' or 'idmap' are normal possible values (mapping file given for mizuRoute grids)</desc>
<values>
<value>unset</value>
<value>$LND2ROF_FMAPNAME</value>
<value samegrid_lnd_rof='true'>idmap</value>
</values>
</entry>
<entry id="rof2lnd_map">
<entry id="rof2lnd_map" modify_via_xml="ROF2LND_FMAPNAME">
<type>char</type>
<category>mapping</category>
<input_pathname>abs</input_pathname>
<group>MED_attributes</group>
<desc>rof to lnd mapping, 'unset' or 'idmap' are normal possible values</desc>
<desc>rof to lnd mapping, 'unset' or 'idmap' are normal possible values (mapping file given for mizuRoute grids)</desc>
<values>
<value>unset</value>
<value>$ROF2LND_FMAPNAME</value>
<value samegrid_lnd_rof='true'>idmap</value>
</values>
</entry>
Expand Down Expand Up @@ -2371,6 +2371,7 @@
</desc>
<values>
<value COMP_OCN="pop">4</value>
<value COMP_OCN="blom">4</value>
<value>0</value>
</values>
</entry>
Expand Down Expand Up @@ -3899,7 +3900,7 @@
</values>
</entry>

<entry id="wavice_coupling">
<entry id="wav_coupling_to_cice">
<type>logical</type>
<category>expdef</category>
<group>ALLCOMP_attributes</group>
Expand All @@ -3908,6 +3909,8 @@
</desc>
<values>
<value>.false.</value>
<!-- The following is not set as a default for now -->
<!-- <value wav_coupling_to_cice='on'>.true.</value> -->
</values>
</entry>

Expand Down
15 changes: 14 additions & 1 deletion cime_config/namelist_definition_drv_flds.xml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
</entry>

<!-- ======================================================================================== -->
<!-- Ozone control -->
<!-- Ozone control -->
<!-- ======================================================================================== -->

<entry id="atm_ozone_frequency">
Expand All @@ -157,4 +157,17 @@
</desc>
</entry>

<!-- ======================================================================================== -->
<!-- Lightning -->
<!-- ======================================================================================== -->

<entry id="atm_provides_lightning">
<type>logical</type>
<category>lightning_coupling</category>
<group>lightning_coupling_nl</group>
<desc>
If TRUE atmosphere model will provide prognosed lightning flash frequency (flashes per minute).
</desc>
</entry>

</entry_id>
26 changes: 20 additions & 6 deletions mediator/esmFldsExchange_cesm_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,17 @@ subroutine esmFldsExchange_cesm(gcomp, phase, rc)
type(InternalState) :: is_local
integer :: n, ns
character(len=CL) :: cvalue
logical :: wavice_coupling
character(len=CS) :: name
logical :: wav_coupling_to_cice
logical :: ocn2glc_coupling
character(len=*) , parameter :: subname=' (esmFldsExchange_cesm) '
!--------------------------------------

rc = ESMF_SUCCESS

call NUOPC_CompAttributeGet(gcomp, name='wavice_coupling', value=cvalue, rc=rc)
call NUOPC_CompAttributeGet(gcomp, name='wav_coupling_to_cice', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) wavice_coupling
read(cvalue,*) wav_coupling_to_cice

call NUOPC_CompAttributeGet(gcomp, name='ocn2glc_coupling', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
Expand Down Expand Up @@ -399,6 +400,19 @@ subroutine esmFldsExchange_cesm(gcomp, phase, rc)
end if
end if
! ---------------------------------------------------------------------
! to lnd: cld to grnd lightning flash freq
! ---------------------------------------------------------------------
if (phase == 'advertise') then
call addfld_from(compatm, 'Sa_lightning')
call addfld_to(complnd, 'Sa_lightning')
else
if ( fldchk(is_local%wrap%FBexp(complnd) , 'Sa_lightning', rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm ), 'Sa_lightning', rc=rc)) then
call addmap_from(compatm, 'Sa_lightning', complnd, mapbilnr, 'one', atm2lnd_map)
call addmrg_to(complnd, 'Sa_lightning', mrg_from=compatm, mrg_fld='Sa_lightning', mrg_type='copy')
end if
end if
! ---------------------------------------------------------------------
! to lnd: temperature at the lowest model level from atm
! ---------------------------------------------------------------------
if (phase == 'advertise') then
Expand Down Expand Up @@ -2818,7 +2832,7 @@ subroutine esmFldsExchange_cesm(gcomp, phase, rc)
! ---------------------------------------------------------------------
! to ice: wave elevation spectrum (field with ungridded dimensions)
! ---------------------------------------------------------------------
if (wavice_coupling) then
if (wav_coupling_to_cice) then
if (phase == 'advertise') then
call addfld_from(compwav, 'Sw_elevation_spectrum')
call addfld_to(compice, 'Sw_elevation_spectrum')
Expand Down Expand Up @@ -2853,7 +2867,7 @@ subroutine esmFldsExchange_cesm(gcomp, phase, rc)
!----------------------------------------------------------
! to wav: ice thickness from ice
!----------------------------------------------------------
if (wavice_coupling) then
if (wav_coupling_to_cice) then
if (phase == 'advertise') then
call addfld_from(compice, 'Si_thick')
call addfld_to(compwav, 'Si_thick')
Expand All @@ -2868,7 +2882,7 @@ subroutine esmFldsExchange_cesm(gcomp, phase, rc)
!----------------------------------------------------------
! to wav: ice floe diameter from ice
!----------------------------------------------------------
if (wavice_coupling) then
if (wav_coupling_to_cice) then
if (phase == 'advertise') then
call addfld_from(compice, 'Si_floediam')
call addfld_to(compwav, 'Si_floediam')
Expand Down
6 changes: 5 additions & 1 deletion mediator/fd_cesm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@
canonical_units: mol/mol
description: atmosphere export - O3 in the lowest model layer (prognosed or prescribed)
#
- standard_name: Sa_lightning
canonical_units: /min
description: atmosphere export - lightning flash freqency
#
- standard_name: Sa_topo
alias: inst_surface_height
canonical_units: m
Expand Down Expand Up @@ -745,7 +749,7 @@
description: sea-ice export - ice thickness
#
- standard_name: Si_floediam
canonical_units: m
canonical_units: m
description: sea-ice export - ice floe diameter
#
#-----------------------------------
Expand Down
6 changes: 4 additions & 2 deletions mediator/med_phases_aofluxes_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,7 @@ subroutine med_aofluxes_init_xgrid(gcomp, aoflux_in, aoflux_out, rc)
type(ESMF_Mesh) :: xch_mesh
real(r8), pointer :: dataptr(:)
integer :: fieldcount
integer :: stp ! srcTermProcessing is declared inout and must have variable not constant
type(ESMF_CoordSys_Flag) :: coordSys
real(ESMF_KIND_R8) ,allocatable :: garea(:)
character(len=*),parameter :: subname=' (med_aofluxes_init_xgrid) '
Expand Down Expand Up @@ -870,11 +871,12 @@ subroutine med_aofluxes_init_xgrid(gcomp, aoflux_in, aoflux_out, rc)
regridmethod=ESMF_REGRIDMETHOD_CONSERVE_2ND, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (trim(coupling_mode) == 'cesm') then
stp = 1
call ESMF_FieldRegridStore(field_a, field_x, routehandle=rh_agrid2xgrid_bilinr, &
regridmethod=ESMF_REGRIDMETHOD_BILINEAR, dstMaskValues=(/0/), rc=rc)
regridmethod=ESMF_REGRIDMETHOD_BILINEAR, dstMaskValues=(/0/), srcTermProcessing=stp, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_FieldRegridStore(field_a, field_x, routehandle=rh_agrid2xgrid_patch, &
regridmethod=ESMF_REGRIDMETHOD_PATCH, dstMaskValues=(/0/), rc=rc)
regridmethod=ESMF_REGRIDMETHOD_PATCH, dstMaskValues=(/0/), srcTermProcessing=stp, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
end if

Expand Down

0 comments on commit 0bab18a

Please sign in to comment.