Skip to content

Commit

Permalink
Latest NUOPC caps (CICE-Consortium#500)
Browse files Browse the repository at this point in the history
* updated orbital calculations needed for cesm

* fixed problems in updated orbital calculations needed for cesm

* update CICE6 to support coupling with UFS

* put in changes so that both ufsatm and cesm requirements for potential temperature and density are satisfied

* update icepack submodule

* Revert "update icepack submodule"

This reverts commit e70d1ab.

* update comp_ice.backend with temporary ice_timers fix

* Fix threading problem in init_bgc

* Fix additional OMP problems

* changes for coldstart running

* Move the forapps directory

* remove cesmcoupled ifdefs

* Fix logging issues for NUOPC

* removal of many cpp-ifdefs

* fix compile errors

* fixes to get cesm working

* fixed white space issue

* Add restart_coszen namelist option

* Update NUOPC cap to work with latest CICE6 master

* nuopc,cmeps or s2s build updates

* fixes for dbug_flag

* Update nuopc2 to latest CICE master

* Fix some merge problems

* Fix dbug variable

* Manual merge of UFS changes

Co-authored-by: Mariana Vertenstein <mvertens@ucar.edu>
Co-authored-by: apcraig <anthony.p.craig@gmail.com>
Co-authored-by: Denise Worthen <denise.worthen@noaa.gov>
  • Loading branch information
4 people authored Aug 12, 2020
1 parent 12d16ed commit eb77517
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 50 deletions.
8 changes: 7 additions & 1 deletion cicecore/drivers/nuopc/cmeps/CICE_RunMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ subroutine coupling_prep (iblk)
alvdf_ai, alidf_ai, alvdr_ai, alidr_ai, fhocn_ai, &
fresh_ai, fsalt_ai, fsalt, &
fswthru_ai, fhocn, fswthru, scale_factor, snowfrac, &
fswthru_vdr, fswthru_vdf, fswthru_idr, fswthru_idf, &
swvdr, swidr, swvdf, swidf, Tf, Tair, Qa, strairxT, strairyT, &
fsens, flat, fswabs, flwout, evap, Tref, Qref, &
scale_fluxes, frzmlt_init, frzmlt, Uref, wind
Expand Down Expand Up @@ -543,7 +544,12 @@ subroutine coupling_prep (iblk)
evap (:,:,iblk), &
Tref (:,:,iblk), Qref (:,:,iblk), &
fresh (:,:,iblk), fsalt (:,:,iblk), &
fhocn (:,:,iblk), fswthru (:,:,iblk), &
fhocn (:,:,iblk), &
fswthru (:,:,iblk), &
fswthru_vdr(:,:,iblk), &
fswthru_vdf(:,:,iblk), &
fswthru_idr(:,:,iblk), &
fswthru_idf(:,:,iblk), &
faero_ocn(:,:,:,iblk), &
alvdr (:,:,iblk), alidr (:,:,iblk), &
alvdf (:,:,iblk), alidf (:,:,iblk), &
Expand Down
48 changes: 45 additions & 3 deletions cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module ice_comp_nuopc
character(len=*),parameter :: shr_cal_noleap = 'NO_LEAP'
character(len=*),parameter :: shr_cal_gregorian = 'GREGORIAN'

integer , parameter :: dbug = 10
integer :: dbug = 0
integer , parameter :: debug_import = 0 ! internal debug level
integer , parameter :: debug_export = 0 ! internal debug level
character(*), parameter :: modName = "(ice_comp_nuopc)"
Expand Down Expand Up @@ -236,6 +236,14 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
endif

call NUOPC_CompAttributeGet(gcomp, name='dbug_flag', value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) dbug
end if
write(logmsg,'(i6)') dbug
call ESMF_LogWrite('CICE_cap: dbug = '//trim(logmsg), ESMF_LOGMSG_INFO)

call ice_advertise_fields(gcomp, importState, exportState, flds_scalar_name, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

Expand Down Expand Up @@ -539,6 +547,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
!----------------------------------------------------------------------------

call icepack_query_parameters(ktherm_out=ktherm)
call icepack_query_parameters(tfrz_option_out=tfrz_option)
call icepack_warnings_flush(nu_diag)
if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
file=__FILE__, line=__LINE__)
Expand Down Expand Up @@ -602,13 +611,15 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
write(nu_diag,*) trim(subname),' cice calendar_type = ',trim(calendar_type)
endif

#ifdef CESMCOUPLED
if (calendar_type == "GREGORIAN" .or. &
calendar_type == "Gregorian" .or. &
calendar_type == "gregorian") then
call time2sec(iyear-(year_init-1),month,mday,time)
else
call time2sec(iyear-year_init,month,mday,time)
endif
#endif
time = time+start_tod
end if

Expand Down Expand Up @@ -874,8 +885,8 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
! diagnostics
!--------------------------------

if (dbug > 1) then
call State_diagnose(exportState,subname//':ES',rc=rc)
if (dbug > 0) then
call state_diagnose(exportState,subname//':ES',rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
endif

Expand Down Expand Up @@ -905,8 +916,10 @@ subroutine ModelAdvance(gcomp, rc)
! Local variables
type(ESMF_Clock) :: clock
type(ESMF_Alarm) :: alarm
type(ESMF_Time) :: startTime
type(ESMF_Time) :: currTime
type(ESMF_Time) :: nextTime
type(ESMF_TimeInterval) :: timeStep
type(ESMF_State) :: importState, exportState
character(ESMF_MAXSTR) :: cvalue
real(dbl_kind) :: eccen, obliqr, lambm0, mvelpp
Expand All @@ -928,11 +941,31 @@ subroutine ModelAdvance(gcomp, rc)
logical :: isPresent, isSet
character(*) , parameter :: F00 = "('(ice_comp_nuopc) ',2a,i8,d21.14)"
character(len=*),parameter :: subname=trim(modName)//':(ModelAdvance) '
character(char_len_long) :: msgString
!--------------------------------

rc = ESMF_SUCCESS
if (dbug > 5) call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO)

! query the Component for its clock, importState and exportState
call ESMF_GridCompGet(gcomp, clock=clock, importState=importState, &
exportState=exportState, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call ESMF_ClockPrint(clock, options="currTime", &
preString="------>Advancing ICE from: ", unit=msgString, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_LogWrite(subname//trim(msgString), ESMF_LOGMSG_INFO)

call ESMF_ClockGet(clock, startTime=startTime, currTime=currTime, &
timeStep=timeStep, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call ESMF_TimePrint(currTime + timeStep, &
preString="--------------------------------> to: ", unit=msgString, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_LogWrite(trim(msgString), ESMF_LOGMSG_INFO)

!--------------------------------
! Turn on timers
!--------------------------------
Expand Down Expand Up @@ -1050,6 +1083,10 @@ subroutine ModelAdvance(gcomp, rc)
idate, sec, nu_diag, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
if (dbug > 0) then
call state_diagnose(importState,subname//':IS',rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

!--------------------------------
! Advance cice and timestep update
Expand All @@ -1067,11 +1104,16 @@ subroutine ModelAdvance(gcomp, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call t_stopf ('cice_run_export')

! write Debug output
if (debug_export > 0 .and. my_task==master_task) then
call State_fldDebug(exportState, flds_scalar_name, 'cice_export:', &
idate, sec, nu_diag, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
if (dbug > 0) then
call state_diagnose(exportState,subname//':ES',rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

! reset shr logging to my original values
call shr_file_setLogUnit (shrlogunit)
Expand Down
65 changes: 29 additions & 36 deletions cicecore/drivers/nuopc/cmeps/ice_import_export.F90
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ module ice_import_export
use ice_flux , only : strairxt, strairyt, strocnxt, strocnyt
use ice_flux , only : alvdr, alidr, alvdf, alidf, Tref, Qref, Uref
use ice_flux , only : flat, fsens, flwout, evap, fswabs, fhocn, fswthru
#if (defined NEWCODE)
use ice_flux , only : fswthru_vdr, fswthru_vdf, fswthru_idr, fswthru_idf
use ice_flux , only : send_i2x_per_cat, fswthrun_ai
use ice_flux , only : faero_atm, faero_ocn
use ice_flux , only : fiso_atm, fiso_ocn, fiso_rain, fiso_evap
use ice_flux , only : Qa_iso, Qref_iso, HDO_ocn, H2_18O_ocn, H2_16O_ocn
#endif
use ice_flux_bgc , only : faero_atm, faero_ocn
use ice_flux_bgc , only : fiso_atm, fiso_ocn, fiso_evap
use ice_flux_bgc , only : Qa_iso, Qref_iso, HDO_ocn, H2_18O_ocn, H2_16O_ocn
use ice_flux , only : fresh, fsalt, zlvl, uatm, vatm, potT, Tair, Qa
use ice_flux , only : rhoa, swvdr, swvdf, swidr, swidf, flw, frain
use ice_flux , only : fsnow, uocn, vocn, sst, ss_tltx, ss_tlty, frzmlt
Expand All @@ -35,6 +33,7 @@ module ice_import_export
use icepack_intfc , only : icepack_warnings_flush, icepack_warnings_aborted
use icepack_intfc , only : icepack_query_parameters, icepack_query_tracer_flags
use icepack_intfc , only : icepack_liquidus_temperature
use icepack_intfc , only : icepack_sea_freezing_temperature
use cice_wrapper_mod , only : t_startf, t_stopf, t_barrierf
#ifdef CESMCOUPLED
use shr_frz_mod , only : shr_frz_freezetemp
Expand Down Expand Up @@ -87,7 +86,7 @@ module ice_import_export
type (fld_list_type) :: fldsFrIce(fldsMax)
type(ESMF_GeomType_Flag) :: geomtype

integer , parameter :: dbug = 10 ! i/o debug messages
integer , parameter :: io_dbug = 10 ! i/o debug messages
character(*), parameter :: u_FILE_u = &
__FILE__

Expand Down Expand Up @@ -115,7 +114,7 @@ subroutine ice_advertise_fields(gcomp, importState, exportState, flds_scalar_nam
!-------------------------------------------------------------------------------

rc = ESMF_SUCCESS
if (dbug > 5) call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO)
if (io_dbug > 5) call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO)

! Determine if the following attributes are sent by the driver and if so read them in
flds_wiso = .false.
Expand All @@ -126,15 +125,13 @@ subroutine ice_advertise_fields(gcomp, importState, exportState, flds_scalar_nam
call ESMF_LogWrite('flds_wiso = '// trim(cvalue), ESMF_LOGMSG_INFO)
end if

#if (defined NEWCODE)
flds_i2o_per_cat = .false.
call NUOPC_CompAttributeGet(gcomp, name='flds_i2o_per_cat', value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) send_i2x_per_cat
call ESMF_LogWrite('flds_i2o_per_cat = '// trim(cvalue), ESMF_LOGMSG_INFO)
end if
#endif

!-----------------
! advertise import fields
Expand Down Expand Up @@ -207,14 +204,12 @@ subroutine ice_advertise_fields(gcomp, importState, exportState, flds_scalar_nam
call fldlist_add(fldsFrIce_num, fldsFrIce, 'inst_ice_vis_dif_albedo' )
call fldlist_add(fldsFrIce_num, fldsFrIce, 'inst_ice_ir_dif_albedo' )

#if (defined NEWCODE)
! the following are advertised but might not be connected if they are not present
! in the cmeps esmFldsExchange_xxx_mod.F90 that is model specific
if (send_i2x_per_cat) then
call fldlist_add(fldsFrIce_num, fldsFrIce, 'ice_fraction_n', &
ungridded_lbound=1, ungridded_ubound=ncat)
end if
#endif

! ice/atm fluxes computed by ice
call fldlist_add(fldsFrIce_num, fldsFrIce, 'stress_on_air_ice_zonal' )
Expand All @@ -233,12 +228,10 @@ subroutine ice_advertise_fields(gcomp, importState, exportState, flds_scalar_nam
call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_sw_pen_to_ocn_ir_dir_flx' )
call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_sw_pen_to_ocn_ir_dif_flx' )

#if (defined NEWCODE)
if (send_i2x_per_cat) then
call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_sw_pen_to_ocn_ifrac_n', &
ungridded_lbound=1, ungridded_ubound=ncat)
end if
#endif
call fldlist_add(fldsFrIce_num , fldsFrIce, 'mean_fresh_water_to_ocean_rate' )
call fldlist_add(fldsFrIce_num , fldsFrIce, 'mean_salt_rate' )
call fldlist_add(fldsFrIce_num , fldsFrIce, 'stress_on_ocn_ice_zonal' )
Expand All @@ -253,8 +246,8 @@ subroutine ice_advertise_fields(gcomp, importState, exportState, flds_scalar_nam
if (flds_wiso) then
call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_fresh_water_to_ocean_rate_wiso', &
ungridded_lbound=1, ungridded_ubound=3)
!call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_evap_rate_atm_into_ice_wiso', &
! ungridded_lbound=1, ungridded_ubound=3)
call fldlist_add(fldsFrIce_num, fldsFrIce, 'mean_evap_rate_atm_into_ice_wiso', &
ungridded_lbound=1, ungridded_ubound=3)
call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_qref_wiso', &
ungridded_lbound=1, ungridded_ubound=3)
end if
Expand All @@ -265,7 +258,7 @@ subroutine ice_advertise_fields(gcomp, importState, exportState, flds_scalar_nam
if (ChkErr(rc,__LINE__,u_FILE_u)) return
enddo

if (dbug > 5) call ESMF_LogWrite(subname//' done', ESMF_LOGMSG_INFO)
if (io_dbug > 5) call ESMF_LogWrite(subname//' done', ESMF_LOGMSG_INFO)

end subroutine ice_advertise_fields

Expand Down Expand Up @@ -361,12 +354,22 @@ subroutine ice_import( importState, rc )
real (kind=dbl_kind),allocatable :: aflds(:,:,:,:)
real (kind=dbl_kind) :: workx, worky
real (kind=dbl_kind) :: MIN_RAIN_TEMP, MAX_SNOW_TEMP
real (kind=dbl_kind) :: tffresh
real (kind=dbl_kind) :: Tffresh
real (kind=dbl_kind) :: inst_pres_height_lowest
character(len=char_len) :: tfrz_option
integer(int_kind) :: ktherm
character(len=*), parameter :: subname = 'ice_import'
character(len=1024) :: msgString
!-----------------------------------------------------

call icepack_query_parameters(Tffresh_out=Tffresh)
call icepack_query_parameters(tfrz_option_out=tfrz_option)
call icepack_query_parameters(ktherm_out=ktherm)
if (io_dbug > 5) then
write(msgString,'(A,i8)')trim(subname)//' tfrz_option = ' &
// trim(tfrz_option)//', ktherm = ',ktherm
call ESMF_LogWrite(trim(msgString), ESMF_LOGMSG_INFO)
end if
! call icepack_query_parameters(tfrz_option_out=tfrz_option, &
! modal_aero_out=modal_aero, z_tracers_out=z_tracers, skl_bgc_out=skl_bgc, &
! Tffresh_out=Tffresh)
Expand Down Expand Up @@ -568,7 +571,6 @@ subroutine ice_import( importState, rc )
! Get aerosols from mediator
!-------------------------------------------------------

#if (defined NEWCODE)
if (State_FldChk(importState, 'Faxa_bcph')) then
! the following indices are based on what the atmosphere is sending
! bcphidry ungridded_index=1
Expand Down Expand Up @@ -604,7 +606,6 @@ subroutine ice_import( importState, rc )
call state_getimport(importState, 'Faxa_dstdry', output=faero_atm, index=3, do_sum=.true., ungridded_index=4, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
#endif

!-------------------------------------------------------
! Water isotopes from the mediator
Expand All @@ -614,7 +615,6 @@ subroutine ice_import( importState, rc )
! 18O => ungridded_index=2
! HDO => ungridded_index=3

#if (defined NEWCODE)
if (State_FldChk(importState, 'shum_wiso')) then
call state_getimport(importState, 'inst_spec_humid_height_lowest_wiso', output=Qa_iso, index=1, ungridded_index=3, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
Expand All @@ -623,12 +623,12 @@ subroutine ice_import( importState, rc )
call state_getimport(importState, 'inst_spec_humid_height_lowest_wiso', output=Qa_iso, index=3, ungridded_index=2, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call state_getimport(importState, 'mean_prec_rate_wiso', output=fiso_rain, index=1, ungridded_index=3, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call state_getimport(importState, 'mean_prec_rate_wiso', output=fiso_rain, index=2, ungridded_index=1, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call state_getimport(importState, 'mean_prec_rate_wiso', output=fiso_rain, index=3, ungridded_index=2, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
! call state_getimport(importState, 'mean_prec_rate_wiso', output=fiso_rain, index=1, ungridded_index=3, rc=rc)
! if (ChkErr(rc,__LINE__,u_FILE_u)) return
! call state_getimport(importState, 'mean_prec_rate_wiso', output=fiso_rain, index=2, ungridded_index=1, rc=rc)
! if (ChkErr(rc,__LINE__,u_FILE_u)) return
! call state_getimport(importState, 'mean_prec_rate_wiso', output=fiso_rain, index=3, ungridded_index=2, rc=rc)
! if (ChkErr(rc,__LINE__,u_FILE_u)) return

call state_getimport(importState, 'mean_fprec_rate_wiso', output=fiso_atm, index=1, ungridded_index=3, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
Expand All @@ -644,7 +644,6 @@ subroutine ice_import( importState, rc )
call state_getimport(importState, 'So_roce_wiso', output=H2_18O_ocn, ungridded_index=2, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
#endif

!-----------------------------------------------------------------
! rotate zonal/meridional vectors to local coordinates
Expand Down Expand Up @@ -697,8 +696,7 @@ subroutine ice_import( importState, rc )
do iblk = 1, nblocks
do j = 1,ny_block
do i = 1,nx_block
!TODO: tcx should this be icepack_sea_freezing_temperature?
Tf (i,j,iblk) = icepack_liquidus_temperature(sss(i,j,iblk))
Tf(i,j,iblk) = icepack_sea_freezing_temperature(sss(i,j,iblk))
end do
end do
end do
Expand Down Expand Up @@ -773,12 +771,12 @@ subroutine ice_export( exportState, rc )
real (kind=dbl_kind) :: tauyo (nx_block,ny_block,max_blocks) ! ice/ocean stress
real (kind=dbl_kind) :: ailohi(nx_block,ny_block,max_blocks) ! fractional ice area
real (kind=dbl_kind), allocatable :: tempfld(:,:,:)
real (kind=dbl_kind) :: tffresh
real (kind=dbl_kind) :: Tffresh
character(len=*),parameter :: subname = 'ice_export'
!-----------------------------------------------------

rc = ESMF_SUCCESS
if (dbug > 5) call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO)
if (io_dbug > 5) call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO)

call icepack_query_parameters(Tffresh_out=Tffresh)
! call icepack_query_parameters(tfrz_option_out=tfrz_option, &
Expand Down Expand Up @@ -907,7 +905,6 @@ subroutine ice_export( exportState, rc )
! ----

! surface temperature of ice covered portion (degK)
!call state_setexport(exportState, 'sea_ice_temperature', input=Tsrf , lmask=tmask, ifrac=ailohi, rc=rc)
call state_setexport(exportState, 'sea_ice_surface_temperature', input=Tsrf , lmask=tmask, ifrac=ailohi, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

Expand Down Expand Up @@ -1005,7 +1002,6 @@ subroutine ice_export( exportState, rc )
call state_setexport(exportState, 'mean_sw_pen_to_ocn' , input=fswthru, lmask=tmask, ifrac=ailohi, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

#if (defined NEWCODE)
! flux of vis dir shortwave through ice to ocean
call state_setexport(exportState, 'mean_sw_pen_to_ocn_vis_dir_flx' , input=fswthru_vdr, lmask=tmask, ifrac=ailohi, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
Expand All @@ -1021,7 +1017,6 @@ subroutine ice_export( exportState, rc )
! flux of ir dif shortwave through ice to ocean
call state_setexport(exportState, 'mean_sw_pen_to_ocn_ir_dif_flx' , input=fswthru_idf, lmask=tmask, ifrac=ailohi, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
#endif

! heat exchange with ocean
call state_setexport(exportState, 'net_heat_flx_to_ocn' , input=fhocn, lmask=tmask, ifrac=ailohi, rc=rc)
Expand All @@ -1043,7 +1038,6 @@ subroutine ice_export( exportState, rc )
call state_setexport(exportState, 'stress_on_ocn_ice_merid' , input=tauyo, lmask=tmask, ifrac=ailohi, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

#if (defined NEWCODE)
! ------
! optional aerosol fluxes to ocean
! ------
Expand Down Expand Up @@ -1134,7 +1128,6 @@ subroutine ice_export( exportState, rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end do
end if
#endif

end subroutine ice_export

Expand Down
Loading

0 comments on commit eb77517

Please sign in to comment.