Skip to content

Commit

Permalink
NUOPC/CMEPS cap updates (#670)
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

* fixes to get CESM B1850 compset working

* refactored ice_prescribed_mod.F90 to work with cdeps rather than the mct data models

* Fix use_restart_time

* changes for creating masks at runtime

* added ice_mesh_mod

* implemented area correction factors as option

* more cleanup

* Fix dragio

* Fix mushy bug

* updates to nuopc cap to resolve inconsistency between driver inputs and cice namelists

* changed error message

* added icepack_warnings_flush

* updates to get ice categories working

* updates to have F compset almost working with cice6 - still problems in polar regions - need to resolve 253K/cice6 versus 273K/cice5 differences

* changed tolerance of mesh/grid comparison

* added issues raised in PR

* Update CESM-CICE sync with new time manager

* Add back in latlongrid

* Add new advanced snow physics to driver

* Fix restart issue with land blocks

* Update mesh check in cap

* fix scam problems

* reintroduced imesh_eps check

* Put dragio in the namelist instead

* Remove redundant code

* Fix some indents

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 Dec 8, 2021
1 parent ddc1cfc commit 4c9024c
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 97 deletions.
2 changes: 2 additions & 0 deletions cicecore/cicedynB/infrastructure/io/io_pio2/ice_restart.F90
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ subroutine read_restart_field(nu,nrec,work,atype,vname,ndim3,diag, &
! if (ndim3 == ncat .and. ncat>1) then
if (ndim3 == ncat .and. ndims == 3) then
call pio_read_darray(File, vardesc, iodesc3d_ncat, work, status)
where (work == PIO_FILL_DOUBLE) work = c0
if (present(field_loc)) then
do n=1,ndim3
call ice_HaloUpdate (work(:,:,n,:), halo_info, &
Expand All @@ -737,6 +738,7 @@ subroutine read_restart_field(nu,nrec,work,atype,vname,ndim3,diag, &
! elseif (ndim3 == 1) then
elseif (ndim3 == 1 .and. ndims == 2) then
call pio_read_darray(File, vardesc, iodesc2d, work, status)
where (work == PIO_FILL_DOUBLE) work = c0
if (present(field_loc)) then
call ice_HaloUpdate (work(:,:,1,:), halo_info, &
field_loc, field_type)
Expand Down
6 changes: 1 addition & 5 deletions cicecore/drivers/nuopc/cmeps/CICE_InitMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ subroutine cice_init2()
use ice_dyn_vp , only: init_vp
use ice_flux , only: init_coupler_flux, init_history_therm
use ice_flux , only: init_history_dyn, init_flux_atm, init_flux_ocn
use ice_forcing , only: init_forcing_ocn, init_snowtable
use ice_forcing , only: init_snowtable
use ice_forcing_bgc , only: get_forcing_bgc, get_atm_bgc
use ice_forcing_bgc , only: faero_default, faero_optics, alloc_forcing_bgc, fiso_default
use ice_history , only: init_hist, accum_hist
Expand Down Expand Up @@ -139,9 +139,6 @@ subroutine cice_init2()

call calendar() ! determine the initial date

!TODO: - why is this being called when you are using CMEPS?
call init_forcing_ocn(dt) ! initialize sss and sst from data

call init_state ! initialize the ice state
call init_transport ! initialize horizontal transport
call ice_HaloRestore_init ! restored boundary conditions
Expand Down Expand Up @@ -388,7 +385,6 @@ subroutine init_restart()
call init_fsd(trcrn(:,:,nt_fsd:nt_fsd+nfsd-1,:,:))
endif
endif

! isotopes
if (tr_iso) then
if (trim(runtype) == 'continue') restart_iso = .true.
Expand Down
20 changes: 10 additions & 10 deletions cicecore/drivers/nuopc/cmeps/CICE_RunMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ subroutine CICE_Run
tr_iso, tr_aero, tr_zaero, skl_bgc, z_tracers, wave_spec, tr_fsd
character(len=*), parameter :: subname = '(CICE_Run)'

!--------------------------------------------------------------------
! initialize error code and step timer
!--------------------------------------------------------------------
!--------------------------------------------------------------------
! initialize error code and step timer
!--------------------------------------------------------------------

call ice_timer_start(timer_step) ! start timing entire run

Expand All @@ -73,13 +73,13 @@ subroutine CICE_Run
if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
file=__FILE__, line=__LINE__)

!--------------------------------------------------------------------
! timestep loop
!--------------------------------------------------------------------
!--------------------------------------------------------------------
! timestep loop
!--------------------------------------------------------------------

call ice_timer_start(timer_couple) ! atm/ocn coupling

call advance_timestep() ! advance timestep and update calendar data
call advance_timestep() ! advance timestep and update calendar data

if (z_tracers) call get_atm_bgc ! biogeochemistry

Expand All @@ -90,9 +90,9 @@ subroutine CICE_Run

call ice_step

!--------------------------------------------------------------------
! end of timestep loop
!--------------------------------------------------------------------
!--------------------------------------------------------------------
! end of timestep loop
!--------------------------------------------------------------------

call ice_timer_stop(timer_step) ! end timestepping loop timer

Expand Down
188 changes: 112 additions & 76 deletions cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
integer :: ilo, ihi, jlo, jhi ! beginning and end of physical domain
character(len=char_len_long) :: diag_filename = 'unset'
character(len=char_len_long) :: logmsg
character(len=char_len_long) :: single_column_lnd_domainfile
real(dbl_kind) :: scol_lon
real(dbl_kind) :: scol_lat
real(dbl_kind) :: scol_spval
character(len=*), parameter :: subname=trim(modName)//':(InitializeAdvertise) '
!--------------------------------

Expand Down Expand Up @@ -376,8 +380,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
depressT_in = 0.054_dbl_kind, &
Tocnfrz_in = -34.0_dbl_kind*0.054_dbl_kind, &
pi_in = SHR_CONST_PI, &
snowpatch_in = 0.005_dbl_kind, &
dragio_in = 0.00536_dbl_kind)
snowpatch_in = 0.005_dbl_kind)

call icepack_warnings_flush(nu_diag)
if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
Expand Down Expand Up @@ -506,12 +509,67 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
! First cice initialization phase - before initializing grid info
!----------------------------------------------------------------------------

#ifdef CESMCOUPLED
! Determine if single column

call NUOPC_CompAttributeGet(gcomp, name='scol_lon', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) scmlon
call NUOPC_CompAttributeGet(gcomp, name='scol_lat', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) scmlat
call NUOPC_CompAttributeGet(gcomp, name='scol_spval', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) scol_spval

if (scmlon > scol_spval .and. scmlat > scol_spval) then
call NUOPC_CompAttributeGet(gcomp, name='single_column_lnd_domainfile', &
value=single_column_lnd_domainfile, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (trim(single_column_lnd_domainfile) /= 'UNSET') then
single_column = .true.
else
call abort_ice('single_column_domainfile cannot be null for single column mode')
end if
call NUOPC_CompAttributeGet(gcomp, name='scol_ocnmask', value=cvalue, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) scol_mask
call NUOPC_CompAttributeGet(gcomp, name='scol_ocnfrac', value=cvalue, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) scol_frac
call NUOPC_CompAttributeGet(gcomp, name='scol_ni', value=cvalue, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) scol_ni
call NUOPC_CompAttributeGet(gcomp, name='scol_nj', value=cvalue, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) scol_nj

call ice_mesh_create_scolumn(scmlon, scmlat, ice_mesh, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

scol_valid = (scol_mask == 1)
if (.not. scol_valid) then
write(6,*)'DEBUG: i am here'
! Advertise fields
call ice_advertise_fields(gcomp, importState, exportState, flds_scalar_name, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call t_stopf ('cice_init_total')

! *******************
! *** RETURN HERE ***
! *******************
RETURN
end if
end if

! Read the cice namelist as part of the call to cice_init1
! Note that if single_column is true and scol_valid is not - will never get here

call t_startf ('cice_init1')
call cice_init1
call t_stopf ('cice_init1')

#ifdef CESMCOUPLED
! Form of ocean freezing temperature
! 'minus1p8' = -1.8 C
! 'linear_salt' = -depressT * sss
Expand Down Expand Up @@ -559,13 +617,20 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
' must be the same as natmiter from cice namelist ',natmiter
call abort_ice(trim(errmsg))
endif

#else

! Read the cice namelist as part of the call to cice_init1
call t_startf ('cice_init1')
call cice_init1
call t_stopf ('cice_init1')

#endif

!----------------------------------------------------------------------------
! Initialize grid info
!----------------------------------------------------------------------------

! Initialize cice mesh and mask if appropriate

if (single_column .and. scol_valid) then
call ice_mesh_init_tlon_tlat_area_hm()
else
Expand Down Expand Up @@ -750,82 +815,43 @@ subroutine InitializeRealize(gcomp, importState, exportState, clock, rc)
if (dbug > 5) call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO)

#ifdef CESMCOUPLED
call NUOPC_CompAttributeGet(gcomp, name='scol_lon', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) scmlon
call NUOPC_CompAttributeGet(gcomp, name='scol_lat', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) scmlat
call NUOPC_CompAttributeGet(gcomp, name='scol_spval', value=cvalue, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) scol_spval

if (scmlon > scol_spval .and. scmlat > scol_spval) then
call NUOPC_CompAttributeGet(gcomp, name='single_column_lnd_domainfile', &
value=single_column_lnd_domainfile, rc=rc)
! if single column is not valid - set all export state fields to zero and return
if (single_column .and. .not. scol_valid) then
write(nu_diag,'(a)')' (ice_comp_nuopc) single column mode point does not contain any ocn/ice '&
//' - setting all export data to 0'
call ice_realize_fields(gcomp, mesh=ice_mesh, &
flds_scalar_name=flds_scalar_name, flds_scalar_num=flds_scalar_num, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (trim(single_column_lnd_domainfile) /= 'UNSET') then
single_column = .true.
else
call abort_ice('single_column_domainfile cannot be null for single column mode')
end if
call NUOPC_CompAttributeGet(gcomp, name='scol_ocnmask', value=cvalue, rc=rc)
call ESMF_StateGet(exportState, itemCount=fieldCount, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) scol_mask
call NUOPC_CompAttributeGet(gcomp, name='scol_ocnfrac', value=cvalue, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) scol_frac
call NUOPC_CompAttributeGet(gcomp, name='scol_ni', value=cvalue, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) scol_ni
call NUOPC_CompAttributeGet(gcomp, name='scol_nj', value=cvalue, rc=rc)
allocate(lfieldnamelist(fieldCount))
call ESMF_StateGet(exportState, itemNameList=lfieldnamelist, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
read(cvalue,*) scol_nj

call ice_mesh_create_scolumn(scmlon, scmlat, ice_mesh, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

scol_valid = (scol_mask == 1)
if (.not. scol_valid) then
! if single column is not valid - set all export state fields to zero and return
write(nu_diag,'(a)')' (ice_comp_nuopc) single column mode point does not contain any ocn/ice '&
//' - setting all export data to 0'
call ice_realize_fields(gcomp, mesh=ice_mesh, &
flds_scalar_name=flds_scalar_name, flds_scalar_num=flds_scalar_num, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call ESMF_StateGet(exportState, itemCount=fieldCount, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
allocate(lfieldnamelist(fieldCount))
call ESMF_StateGet(exportState, itemNameList=lfieldnamelist, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
do n = 1, fieldCount
if (trim(lfieldnamelist(n)) /= flds_scalar_name) then
call ESMF_StateGet(exportState, itemName=trim(lfieldnamelist(n)), field=lfield, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_FieldGet(lfield, rank=rank, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (rank == 2) then
call ESMF_FieldGet(lfield, farrayPtr=fldptr2d, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
fldptr2d(:,:) = 0._dbl_kind
else
call ESMF_FieldGet(lfield, farrayPtr=fldptr1d, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
fldptr1d(:) = 0._dbl_kind
end if
do n = 1, fieldCount
if (trim(lfieldnamelist(n)) /= flds_scalar_name) then
call ESMF_StateGet(exportState, itemName=trim(lfieldnamelist(n)), field=lfield, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
call ESMF_FieldGet(lfield, rank=rank, rc=rc)
if (chkerr(rc,__LINE__,u_FILE_u)) return
if (rank == 2) then
call ESMF_FieldGet(lfield, farrayPtr=fldptr2d, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
fldptr2d(:,:) = 0._dbl_kind
else
call ESMF_FieldGet(lfield, farrayPtr=fldptr1d, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
fldptr1d(:) = 0._dbl_kind
end if
enddo
deallocate(lfieldnamelist)
! *******************
! *** RETURN HERE ***
! *******************
RETURN
else
write(nu_diag,'(a,3(f10.5,2x))')' (ice_comp_nuopc) single column mode lon/lat/frac is ',&
scmlon,scmlat,scol_frac
end if
end if
enddo
deallocate(lfieldnamelist)
! *******************
! *** RETURN HERE ***
! *******************
RETURN
else
single_column = .false.
write(nu_diag,'(a,3(f10.5,2x))')' (ice_comp_nuopc) single column mode lon/lat/frac is ',&
scmlon,scmlat,scol_frac
end if
#endif

Expand Down Expand Up @@ -915,6 +941,16 @@ subroutine ModelAdvance(gcomp, rc)
!--------------------------------

rc = ESMF_SUCCESS

call ESMF_LogWrite(subname//' called', ESMF_LOGMSG_INFO)

if (single_column .and. .not. scol_valid) then
! *******************
! *** RETURN HERE ***
! *******************
RETURN
end if

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

! query the Component for its clock, importState and exportState
Expand Down
4 changes: 3 additions & 1 deletion cicecore/drivers/nuopc/cmeps/ice_import_export.F90
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ subroutine ice_advertise_fields(gcomp, importState, exportState, flds_scalar_nam
write(nu_diag,*)'send_i2x_per_cat = ',send_i2x_per_cat
end if
if (.not.send_i2x_per_cat) then
deallocate(fswthrun_ai)
if (allocated(fswthrun_ai)) then
deallocate(fswthrun_ai)
end if
end if

! Determine if the following attributes are sent by the driver and if so read them in
Expand Down
7 changes: 2 additions & 5 deletions cicecore/drivers/nuopc/cmeps/ice_mesh_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -639,16 +639,13 @@ subroutine ice_mesh_check(gcomp, ice_mesh, rc)
diff_lon = abs(mod(lonMesh(n) - tmplon,360.0))
if (diff_lon > eps_imesh ) then
write(6,100)n,lonMesh(n),tmplon, diff_lon
call abort_ice(error_message=subname, &
file=__FILE__, line=__LINE__)
!call abort_ice(error_message=subname, file=__FILE__, line=__LINE__)
end if
diff_lat = abs(latMesh(n) - lat(n))
if (diff_lat > eps_imesh) then
write(6,101)n,latMesh(n),lat(n), diff_lat
call abort_ice(error_message=subname, &
file=__FILE__, line=__LINE__)
!call abort_ice(error_message=subname, file=__FILE__, line=__LINE__)
end if

enddo
enddo
enddo
Expand Down

0 comments on commit 4c9024c

Please sign in to comment.