Skip to content
Draft
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
285 changes: 285 additions & 0 deletions mediator/esmFldsExchange_coastal_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module esmFldsExchange_coastal_mod
use med_internalstate_mod , only : compatm
use med_internalstate_mod , only : compocn
use med_internalstate_mod , only : compwav
use med_internalstate_mod , only : compice
use med_internalstate_mod , only : ncomps
use med_internalstate_mod , only : coupling_mode

Expand Down Expand Up @@ -38,10 +39,17 @@ module esmFldsExchange_coastal_mod
character(len=CX) :: ocn2wav_smap = 'unset'
character(len=CX) :: wav2ocn_smap = 'unset'
character(len=CX) :: wav2atm_smap = 'unset'

character(len=CX) :: atm2ice_smap = 'unset'
character(len=CX) :: ocn2ice_smap = 'unset'
character(len=CX) :: ice2ocn_smap = 'unset'
character(len=CX) :: ice2atm_smap = 'unset'

character(len=CS) :: mapnorm = 'one'
logical :: atm_present = .false.
logical :: ocn_present = .false.
logical :: wav_present = .false.
logical :: ice_present = .false.
end type

!===============================================================================
Expand Down Expand Up @@ -140,11 +148,23 @@ subroutine esmFldsExchange_coastal_advt(gcomp, phase, rc)
! to med: masks from components
!----------------------------------------------------------
call addfld_from(compocn, 'So_omask')
call addfld_from(compice, 'Si_imask')

!----------------------------------------------------------
! to med: frac from components
!----------------------------------------------------------
call addfld_to(compatm, 'So_ofrac')

if (coastal_attr%ice_present .and. coastal_attr%atm_present) then
call addfld_from(compice , 'Si_ifrac')
call addfld_to(compatm , 'Si_ifrac')

end if

if (coastal_attr%ice_present .and. coastal_attr%ocn_present) then
call addfld_from(compice , 'Si_ifrac')
call addfld_to(compocn , 'Si_ifrac')
end if

!=====================================================================
! FIELDS TO OCEAN (compocn)
Expand Down Expand Up @@ -236,6 +256,84 @@ subroutine esmFldsExchange_coastal_advt(gcomp, phase, rc)
deallocate(S_flds)
end if

! ---------------------------------------------------------------------
! to ice: atm fields
! ---------------------------------------------------------------------
if (coastal_attr%atm_present .and. coastal_attr%ice_present) then
allocate(S_flds(14))
Copy link
Collaborator

Choose a reason for hiding this comment

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

@SmithJos13 You have 13 field but the size is 14. Please check also other sections. They must be consistent.

S_flds = (/'Sa_u ', & ! inst_zonalv_wind_height10m
'Sa_v ', & ! inst_merid_wind_height10m
'Sa_z ', & ! lowest atmospheric height
'Sa_tbot ', & ! tenperature at lowest atm level
'Sa_shum ', & ! Specific Humidity
'Sa_pbot ', & ! pressure bottom
'Faxa_snow ', & ! Snow
'Faxa_rain ', & ! Rain
'Faxa_swvdr', & ! Short-wave
'Faxa_swvdf', & ! Short-wave
'Faxa_swndr', & ! Short-wave
'Faxa_swndf', & ! Short-wave
'Faxa_swnet', & ! Short-wave net
'Faxa_lwdn ' /) ! Long-wave

do n = 1,size(S_flds)
fldname = trim(S_flds(n))
call addfld_from(compatm, trim(fldname))
call addfld_to(compice, trim(fldname))
end do
deallocate(S_flds)
end if

! ---------------------------------------------------------------------
! to ice: ocean fields
! ---------------------------------------------------------------------
if (coastal_attr%ocn_present .and. coastal_attr%ice_present) then
Copy link
Collaborator

Choose a reason for hiding this comment

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

@SmithJos13 Same in here. Please make sure to use same length for strings in the array.

allocate(S_flds(8))
S_flds = (/'So_u ', & ! ocn_current_zonal
'So_v ', & ! ocn_current_merid
'So_t ', & ! SST
'So_s ', & ! SSS
'So_h ', & ! depth of ml
'So_dhdx', & ! tilt-x
'So_dhdy', & ! tilt-y
'Fioo_q '/) ! heat flux
do n = 1,size(S_flds)
fldname = trim(S_flds(n))
call addfld_from(compocn, trim(fldname))
call addfld_to(compice, trim(fldname))
end do
deallocate(S_flds)
end if

! ---------------------------------------------------------------------
! to ocean: ice fields
! ---------------------------------------------------------------------
if (coastal_attr%ocn_present .and. coastal_attr%ice_present) then
allocate(S_flds(13))
S_flds = (/'Si_ifrac ', & ! Ice area fraction aice
'Si_vice ', & ! Ice volume
'Si_vsno ', & ! Snow volume
'Si_uvel ', & ! Ice u-velocity
'Si_vvel ', & ! Ice v-velocity
'Fioi_meltw', & ! Fresh water flux due to melting/freeze
'Fioi_melth', & ! Ice-to-ocean heat flux at base of ice
'Fioi_taux ', & ! Ice-to-ocean surface stress in x-dir
'Fioi_tauy ', & ! Ice-to-ocean surface stress in y-dir
'Fioi_salt ', & ! Salinity flux due to melting/freeze
'Fioi_swpen', & ! Penatrive SW radiation flux
'Si_frzmlt ', & ! Energy used to create ice (all energy sst-tfrz)
'Si_CdnIO ' /) ! ice drag coeff

do n = 1,size(S_flds)
fldname = trim(S_flds(n))
call addfld_from(compice, trim(fldname))
call addfld_to(compocn, trim(fldname))
end do
deallocate(S_flds)
end if



call ESMF_LogWrite(trim(subname)//": done", ESMF_LOGMSG_INFO)

end subroutine esmFldsExchange_coastal_advt
Expand Down Expand Up @@ -458,8 +556,161 @@ subroutine esmFldsExchange_coastal_init(gcomp, phase, rc)
end do
deallocate(S_flds)
end if


!======================================================================
! BEGIN FIELDS TO ICE (compice)
!======================================================================
! ---------------------------------------------------------------------
! To ice from atm
! ---------------------------------------------------------------------
! ----------------------------------------
! | Atmospheric Fields: |
! ----------------------------------------
! - zonal wind height 10m [m/s]
! - merid wind height 10m [m/s]
! - lowest atmospheric height [m] (defualt in CICE is 10m see model comp)
! - Temperature at 10m [k]
! - Specific Humidity [kg/kg]
! - Pressure at 10m [Pa]
! - Rainfall rate [kg/m/m/s]
! - Snowfall rate [kg/m/m/s]
! - Net shortwave rad [W/m/m] Other bands are derived from this
! - Net longwave rad [W/m/m]
! ---------------------------------------
if (coastal_attr%atm_present .and. coastal_attr%ice_present) then
allocate(S_flds(14))
S_flds = (/'Sa_u ', & ! inst_zonal_wind_height10m
'Sa_v ', & ! inst_merid_wind_height10m
'Sa_z ', & ! lowest atmospheric height
'Sa_tbot ', & ! tenperature at lowest atm level
'Sa_shum ', & ! Specific Humidity
'Sa_pbot ', & ! pressure bottom
'Faxa_rain ', & ! Rain
'Faxa_snow ', & ! Snow
'Faxa_swvdr', & ! Short-wave
'Faxa_swvdf', & ! Short-wave
'Faxa_swndr', & ! Short-wave
'Faxa_swndf', & ! Short-wave
'Faxa_swnet', & ! Short-wave net
'Faxa_lwdn '/) ! long-wave
do n = 1,size(S_flds)
fldname = trim(S_flds(n))
if (fldchk(is_local%wrap%FBExp(compice),trim(fldname),rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compatm,compatm),trim(fldname),rc=rc) &
) then
call addmap_from(compatm, trim(fldname), compice, &
mapnstod_consf, coastal_attr%mapnorm, coastal_attr%atm2ice_smap) !!mapnstod_consf conservative interp
call addmrg_to(compice, trim(fldname), &
mrg_from=compatm, mrg_fld=trim(fldname), mrg_type='copy')
end if
end do
deallocate(S_flds)
end if

! ---------------------------------------------------------------------
! To ice from ocn fields
! ---------------------------------------------------------------------
! ----------------------------------------
! | Oceanic fields: |
! ----------------------------------------
! - zonal current [m/s]
! - merid current [m/s]
! - Sea Surface temperature [K]
! - Sea surface salinity [psu. (g/kg)]
! - Mixed layer depth [m]
! - Zonal sea surface tilt [1]
! - Merid sea surface tilt [1]
! - deep ocean heatflux [W/m/m]
! ---------------------------------------

if (coastal_attr%ocn_present .and. coastal_attr%ice_present) then
allocate(S_flds(8))
S_flds = (/'So_u ', & ! ocn_current_zonal
'So_v ', & ! ocn_current_merid
'So_t ', & ! SST
'So_s ', & ! SSS
'So_h ', & ! depth of ml
'So_dhdx', & ! tilt-x
'So_dhdy', & ! tilt-y
'Fioo_qi'/) ! heat flux

call ESMF_LogWrite(trim(subname)//": done", ESMF_LOGMSG_INFO)
do n = 1,size(S_flds)
fldname = trim(S_flds(n))
if (fldchk(is_local%wrap%FBExp(compice),trim(fldname),rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compocn,compocn),trim(fldname),rc=rc) &
) then
call addmap_from(compocn, trim(fldname), compice, &
mapbilnr_nstod, coastal_attr%mapnorm, coastal_attr%ocn2ice_smap)
call addmrg_to(compice, trim(fldname), &
mrg_from=compocn, mrg_fld=trim(fldname), mrg_type='copy')
end if
end do
deallocate(S_flds)
end if

!======================================================================
! END FIELDS TO ICE (compice)
!======================================================================

!======================================================================
! BEGIN FIELDS FROM ICE (compice)
!======================================================================
! ---------------------------------------------------------------------
! To ocn from ice fields
! ---------------------------------------------------------------------
! ----------------------------------------
! | Ice fields: |
! ----------------------------------------
! - Ice area fraction [1]
! - Ice volume [m^3]
! - Snow volume [m^3]
! - Ice merid vel. [m/s]
! - Ice Zonal vel. [m/s]
! - Fresh water flux [kg/m/m/s]
! - Heat flux at base of ice [W/m/m]
! - Ice-to-Ocn merid stress [N/m/m]
! - Ice-to-Ocn zonal stress [N/m/m]
! - Salinity flux [kg/m/m/s]
! - Shortwave pen. rad [W/m/m]
! - Freeze melt potential [W/m/m] (Internal energy mixed layer)
! - Ice ocean drag [1] (Computed by ice component)

if (coastal_attr%ocn_present .and. coastal_attr%ice_present) then
allocate(S_flds(13))
S_flds = (/'Si_ifrac ', & ! Ice area fraction aice
'Si_vice ', & ! Ice volume
'Si_vsno ', & ! Snow volume
'Si_uvel ', & ! Ice u-velocity
'Si_vvel ', & ! Ice v-velocity
'Fioi_meltw', & ! Fresh water flux due to melting/freeze
'Fioi_melth', & ! Ice-to-ocean heat flux at base of ice
'Fioi_taux ', & ! Ice-to-ocean surface stress in x-dir
'Fioi_tauy ', & ! Ice-to-ocean surface stress in y-dir
'Fioi_salt ', & ! Salinity flux due to melting/freeze
'Fioi_swpen', & ! Penatrive SW radiation flux
'Si_frzmlt ', & ! Energy used to create ice (all energy sst-tfrz)
'Si_CdnIO ' /) ! ice drag

call ESMF_LogWrite(trim(subname)//": done", ESMF_LOGMSG_INFO)
do n = 1,size(S_flds)
fldname = trim(S_flds(n))
if (fldchk(is_local%wrap%FBExp(compocn),trim(fldname),rc=rc) .and. &
fldchk(is_local%wrap%FBImp(compice,compice),trim(fldname),rc=rc) &
) then
call addmap_from(compice, trim(fldname), compocn, &
mapnstod_consf, coastal_attr%mapnorm, coastal_attr%ice2ocn_smap)
call addmrg_to(compocn, trim(fldname), &
mrg_from=compice, mrg_fld=trim(fldname), mrg_type='copy')
end if
end do
deallocate(S_flds)
end if

!======================================================================
! END FIELDS FROM ICE (compice)
!======================================================================

end subroutine esmFldsExchange_coastal_init

Expand Down Expand Up @@ -513,6 +764,13 @@ subroutine esmFldsExchange_coastal_attr(gcomp, coastal_attr, rc)
if (trim(cvalue) /= 'swav') coastal_attr%wav_present = .true.
end if

call NUOPC_CompAttributeGet(gcomp, name='ICE_model', &
value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
if (trim(cvalue) /= 'sice') coastal_attr%ice_present = .true.
end if

!----------------------------------------------------------
! Normalization type
!----------------------------------------------------------
Expand Down Expand Up @@ -592,6 +850,33 @@ subroutine esmFldsExchange_coastal_attr(gcomp, coastal_attr, rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
end if

! to ice
call NUOPC_CompAttributeGet(gcomp, name='atm2ice_smapname', &
isPresent=isPresent, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (isPresent) then
call NUOPC_CompAttributeGet(gcomp, name='atm2ice_smapname', &
value=coastal_attr%atm2ice_smap, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
end if
call NUOPC_CompAttributeGet(gcomp, name='ocn2ice_smapname', &
isPresent=isPresent, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (isPresent) then
call NUOPC_CompAttributeGet(gcomp, name='ocn2ice_smapname', &
value=coastal_attr%ocn2ice_smap, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
end if

call NUOPC_CompAttributeGet(gcomp, name='ice2ocn_smapname', &
isPresent=isPresent, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (isPresent) then
call NUOPC_CompAttributeGet(gcomp, name='ice2ocn_smapname', &
value=coastal_attr%ice2ocn_smap, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
end if

! Log Attribute Settings
if (btest(verbosity,16)) then
write(cvalue,"(I0)") verbosity
Expand Down