Skip to content

Commit

Permalink
Enable prescribed ice for UFS (CICE-Consortium#964)
Browse files Browse the repository at this point in the history
Prescribed ice CICE was enclosed by #ifdef CESMCOUPLED in CMEPS driver. This allows use of prescribed ice CICE in ufs-weather-model with CDEPS calls to input (sea ice concentration) from file. Starting as cherry-picked as in UFS but dependency on CDEPS likely needs to be optional at compile time. This is needed for History conflicts between CICE-Consortium and emc/develop #84

* Enable prescribed ice for UFS (#80)

* Remove #ifdef CESMCOUPLED from cicecore/drivers/nuopc/cmeps/CICE_RunMod.F90

* Remove #ifdef CESMCOUPLED from cicecore/drivers/nuopc/cmeps/ice_prescribed_mod.F90

* Testing changing stream_taxmode from cycle to extend

* Change include mpif.h to use mpi in ice_prescribed_mod.F90

* Call dshr_pio_init from ice_prescribed_init

* Call ice_prescribed_run after ice_prescribed_init

* Incorporate ice_prescribed_nml in ice_prescribed_mod.F90

* write stream_taxmode to log. typo in ice_prescribed_mod.F90.

* Remove CESMCOUPLED so models initialize ice_prescribed at end of ice_prescribed_init

* Change indent for #ifndef for gnu debug

* Only call ice_prescribed_run in ice_prescribed_init #ifndef CESMCOUPLED

* Note CDEPS dependency in cicecore/drivers/nuopc/cmeps/ice_prescribed_mod.F90

* Remove stub prescribed ice code
  • Loading branch information
NickSzapiro-NOAA committed Sep 25, 2024
1 parent 8c0eff0 commit cba8703
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
2 changes: 0 additions & 2 deletions cicecore/drivers/nuopc/cmeps/CICE_RunMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,12 @@ subroutine ice_step
call init_history_bgc
call ice_timer_stop(timer_diags) ! diagnostics/history

#ifdef CESMCOUPLED
if (prescribed_ice) then ! read prescribed ice
call t_barrierf('cice_run_presc_BARRIER',MPI_COMM_ICE)
call t_startf ('cice_run_presc')
call ice_prescribed_run(idate, msec)
call t_stopf ('cice_run_presc')
endif
#endif

call step_prep

Expand Down
2 changes: 1 addition & 1 deletion cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
! Prescribed ice initialization
!-----------------------------------------------------------------

call ice_prescribed_init(clock, ice_mesh, rc)
call ice_prescribed_init(gcomp, clock, ice_mesh, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

#ifdef CESMCOUPLED
Expand Down
59 changes: 31 additions & 28 deletions cicecore/drivers/nuopc/cmeps/ice_prescribed_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,20 @@ module ice_prescribed_mod
! prescribed. Air/ice fluxes are computed to get surface temperature,
! Ice/ocean fluxes are set to zero, and ice dynamics are not calculated.
! Regridding and data cycling capabilities are included.

! Note (8/8/2024): This code is dependent on CDEPS (to input ice data).
! In the interests of cleaner code, drivers/nuopc/cmeps now is too.
! If problematic, please see https://github.com/CICE-Consortium/CICE/pull/964 for alternatives.

use ESMF, only : ESMF_Clock, ESMF_Mesh, ESMF_SUCCESS, ESMF_FAILURE
use ESMF, only : ESMF_GridComp, ESMF_Clock, ESMF_Mesh, ESMF_SUCCESS, ESMF_FAILURE
use ESMF, only : ESMF_LogFoundError, ESMF_LOGERR_PASSTHRU, ESMF_Finalize, ESMF_END_ABORT

#ifndef CESMCOUPLED

use ice_kinds_mod
implicit none
private ! except
public :: ice_prescribed_init ! initialize input data stream
logical(kind=log_kind), parameter, public :: prescribed_ice = .false. ! true if prescribed ice
contains
! This is a stub routine for now
subroutine ice_prescribed_init(clock, mesh, rc)
type(ESMF_Clock) , intent(in) :: clock
type(ESMF_Mesh) , intent(in) :: mesh
integer , intent(out) :: rc
! do nothing
rc = ESMF_SUCCESS
end subroutine ice_prescribed_init

#else

use ice_kinds_mod
use shr_nl_mod , only : shr_nl_find_group_name
use dshr_strdata_mod , only : shr_strdata_type, shr_strdata_print
use dshr_strdata_mod , only : shr_strdata_init_from_inline, shr_strdata_advance
use dshr_methods_mod , only : dshr_fldbun_getfldptr
use dshr_mod , only : dshr_pio_init
use ice_broadcast
use ice_communicate , only : my_task, master_task, MPI_COMM_ICE
use ice_fileunits
Expand All @@ -43,7 +29,7 @@ end subroutine ice_prescribed_init
use ice_blocks , only : nx_block, ny_block, block, get_block
use ice_domain , only : nblocks, distrb_info, blocks_ice
use ice_grid , only : TLAT, TLON, hm, tmask, tarea, grid_type, ocn_gridcell_frac
use ice_calendar , only : idate, calendar_type
use ice_calendar , only : idate, msec, calendar_type
use ice_arrays_column , only : hin_max
use ice_read_write
use ice_exit , only: abort_ice
Expand Down Expand Up @@ -74,13 +60,17 @@ end subroutine ice_prescribed_init
contains
!===============================================================================

subroutine ice_prescribed_init(clock, mesh, rc)
subroutine ice_prescribed_init(gcomp, clock, mesh, rc)

! Prescribed ice initialization

include 'mpif.h'
#ifndef SERIAL_REMOVE_MPI
!TODO: add 1d character array to cicecore/cicedyn/infrastructure/comm/mpi/ice_broadcast.F90
use mpi ! MPI Fortran module
#endif

! input/output parameters
type(ESMF_GridComp) , intent(in) :: gcomp
type(ESMF_Clock) , intent(in) :: clock
type(ESMF_Mesh) , intent(in) :: mesh
integer , intent(out) :: rc
Expand All @@ -93,6 +83,7 @@ subroutine ice_prescribed_init(clock, mesh, rc)
character(len=char_len_long) :: stream_dataFiles(nFilesMaximum)
character(len=char_len_long) :: stream_varname
character(len=char_len_long) :: stream_mapalgo
character(len=char_len_long) :: stream_taxmode
integer(kind=int_kind) :: stream_yearfirst ! first year in stream to use
integer(kind=int_kind) :: stream_yearlast ! last year in stream to use
integer(kind=int_kind) :: stream_yearalign ! align stream_year_first
Expand All @@ -110,6 +101,7 @@ subroutine ice_prescribed_init(clock, mesh, rc)
stream_varname , &
stream_datafiles, &
stream_mapalgo, &
stream_taxmode, &
stream_yearalign, &
stream_yearfirst , &
stream_yearlast
Expand All @@ -125,6 +117,7 @@ subroutine ice_prescribed_init(clock, mesh, rc)
stream_meshfile = ' '
stream_datafiles(:) = ' '
stream_mapalgo = 'bilinear'
stream_taxmode = 'cycle'

! read namelist on master task
if (my_task == master_task) then
Expand Down Expand Up @@ -155,6 +148,7 @@ subroutine ice_prescribed_init(clock, mesh, rc)
call broadcast_scalar(stream_yearlast , master_task)
call broadcast_scalar(stream_meshfile , master_task)
call broadcast_scalar(stream_mapalgo , master_task)
call broadcast_scalar(stream_taxmode , master_task)
call broadcast_scalar(stream_varname , master_task)
call mpi_bcast(stream_dataFiles, len(stream_datafiles(1))*NFilesMaximum, MPI_CHARACTER, 0, MPI_COMM_ICE, ierr)

Expand All @@ -172,12 +166,18 @@ subroutine ice_prescribed_init(clock, mesh, rc)
write(nu_diag,F00) ' stream_meshfile = ',trim(stream_meshfile)
write(nu_diag,F00) ' stream_varname = ',trim(stream_varname)
write(nu_diag,F00) ' stream_mapalgo = ',trim(stream_mapalgo)
write(nu_diag,F00) ' stream_taxmode = ',trim(stream_taxmode)
do n = 1,nFile
write(nu_diag,F00) ' stream_datafiles = ',trim(stream_dataFiles(n))
end do
write(nu_diag,*) ' '
endif

#ifndef CESMCOUPLED
!CESM does this elsewhere
call dshr_pio_init(gcomp, sdat, nu_diag, rc)
#endif

! initialize sdat
call shr_strdata_init_from_inline(sdat, &
my_task = my_task, &
Expand All @@ -189,13 +189,13 @@ subroutine ice_prescribed_init(clock, mesh, rc)
stream_lev_dimname = 'null', &
stream_mapalgo = trim(stream_mapalgo), &
stream_filenames = stream_datafiles(1:nfile), &
stream_fldlistFile = (/'ice_cov'/), &
stream_fldListModel = (/'ice_cov'/), &
stream_fldlistFile = (/trim(stream_varname)/), &
stream_fldListModel = (/trim(stream_varname)/), &
stream_yearFirst = stream_yearFirst, &
stream_yearLast = stream_yearLast, &
stream_yearAlign = stream_yearAlign , &
stream_offset = 0, &
stream_taxmode = 'cycle', &
stream_taxmode = trim(stream_taxmode), &
stream_dtlimit = 1.5_dbl_kind, &
stream_tintalgo = 'linear', &
rc = rc)
Expand All @@ -211,6 +211,11 @@ subroutine ice_prescribed_init(clock, mesh, rc)
hin_max(1) = 999._dbl_kind
end if

#ifndef CESMCOUPLED
! If need initial cice values for coupling
call ice_prescribed_run(idate, msec)
#endif

end if ! end of if prescribed ice mode

end subroutine ice_prescribed_init
Expand Down Expand Up @@ -489,6 +494,4 @@ subroutine ice_prescribed_phys()

end subroutine ice_prescribed_phys

#endif

end module ice_prescribed_mod

0 comments on commit cba8703

Please sign in to comment.