Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wave-ice coupling to nuopc/cmeps driver #782

Merged
merged 133 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
133 commits
Select commit Hold shift + click to select a range
0338d04
Merge pull request #1 from CICE-Consortium/master
DeniseWorthen Feb 25, 2020
99470ed
Merge pull request #2 from CICE-Consortium/master
DeniseWorthen Mar 7, 2020
71d2ded
Merge pull request #3 from CICE-Consortium/master
DeniseWorthen Apr 2, 2020
d46d691
merge latest master (#4)
DeniseWorthen Apr 22, 2020
183218a
updated orbital calculations needed for cesm
Apr 23, 2020
10e7c20
fixed problems in updated orbital calculations needed for cesm
Apr 29, 2020
ce8e5a9
update CICE6 to support coupling with UFS
apcraig May 10, 2020
8f0b5ee
Merge pull request #2 from apcraig/ufs01
dabail10 May 10, 2020
7ac0e3d
Merge pull request #1 from ESCOMP/nuopc
DeniseWorthen May 12, 2020
80c9e6e
Merge branch 'master' of https://github.com/CICE-Consortium/CICE into…
dabail10 May 19, 2020
53715ea
put in changes so that both ufsatm and cesm requirements for potentia…
May 25, 2020
7e43703
Merge pull request #3 from mvertens/mvertens/nuopc
dabail10 May 26, 2020
397e588
Merge remote-tracking branch 'upstream/master'
DeniseWorthen Jun 2, 2020
3bb3694
Convergence on ustar for CICE. (#452) (#5)
DeniseWorthen Jun 5, 2020
f41f1e9
Merge remote-tracking branch 'upstream/nuopc' into HEAD
DeniseWorthen Jun 22, 2020
e70d1ab
update icepack submodule
DeniseWorthen Jun 22, 2020
308a1d4
Revert "update icepack submodule"
DeniseWorthen Jun 22, 2020
7848fdf
Merge branch 'master' of https://github.com/CICE-Consortium/CICE into…
dabail10 Jun 24, 2020
6982ee4
Merge remote-tracking branch 'upstream/nuopc' into HEAD
DeniseWorthen Jun 25, 2020
089f60f
update comp_ice.backend with temporary ice_timers fix
DeniseWorthen Jun 25, 2020
6affdcf
Merge branch 'master' of https://github.com/CICE-Consortium/CICE into…
dabail10 Jun 29, 2020
b5a6058
Merge branch 'master' of https://github.com/CICE-Consortium/CICE into…
dabail10 Jul 1, 2020
415df0e
Merge branch 'nuopc' of https://github.com/ESCOMP/CICE into nuopc
dabail10 Jul 1, 2020
b4da8a6
Merge branch 'master' of https://github.com/CICE-Consortium/CICE into…
dabail10 Jul 1, 2020
239c7de
Merge branch 'nuopc' of https://github.com/ESCOMP/CICE into nuopc
dabail10 Jul 1, 2020
ad03424
Fix threading problem in init_bgc
dabail10 Jul 1, 2020
73e7774
Fix additional OMP problems
dabail10 Jul 1, 2020
46fcfba
changes for coldstart running
DeniseWorthen Jul 2, 2020
c762336
Move the forapps directory
dabail10 Jul 2, 2020
6bccf71
remove cesmcoupled ifdefs
DeniseWorthen Jul 2, 2020
902e883
Fix logging issues for NUOPC
dabail10 Jul 2, 2020
178693a
Merge branch 'nuopc' of https://github.com/ESCOMP/CICE into nuopc
dabail10 Jul 2, 2020
b4afd2e
removal of many cpp-ifdefs
Jul 4, 2020
3a1b88b
fix compile errors
DeniseWorthen Jul 4, 2020
41855fd
fixes to get cesm working
Jul 4, 2020
aea1aa8
update to latest nuopc changes
Jul 4, 2020
e4c989c
Merge branch 'master' of https://github.com/CICE-Consortium/CICE into…
dabail10 Jul 6, 2020
30a81cc
fixed white space issue
Jul 7, 2020
8ebdda9
Merge pull request #4 from mvertens/nuopc
dabail10 Jul 7, 2020
27dd3b7
Add restart_coszen namelist option
dabail10 Jul 7, 2020
50bf856
Merge remote-tracking branch 'upstream/master'
DeniseWorthen Jul 7, 2020
6b4a277
Merge branch 'nuopc' into coszen
dabail10 Jul 7, 2020
93f0e86
Merge pull request #5 from ESCOMP/coszen
dabail10 Jul 7, 2020
f92bef3
update icepack submodule
DeniseWorthen Jul 7, 2020
4e8cc79
Merge remote-tracking branch 'upstream/nuopc' into emc/develop
DeniseWorthen Jul 7, 2020
8ff4ee0
change Orion to orion in backend
DeniseWorthen Jul 7, 2020
916c6af
add -link_mpi=dbg to debug flags (#8)
DeniseWorthen Jul 14, 2020
9bdb9ad
Merge remote-tracking branch 'CICE-Consortium/master' into emc/develop
DeniseWorthen Jul 15, 2020
8f37bfc
cice6 compile (#6)
MinsukJi-NOAA Jul 17, 2020
86b8dab
Merge remote-tracking branch 'upstream/emc/develop' into HEAD
DeniseWorthen Jul 17, 2020
c084de4
Merge remote-tracking branch 'upstream/master' into emc/develop
DeniseWorthen Jul 17, 2020
88cc2fd
Merge remote-tracking branch 'upstream/master' into emc/develop
DeniseWorthen Aug 5, 2020
bdf1a1f
changes for consistency w/ current emc-cice5 (#13)
DeniseWorthen Aug 12, 2020
5ecde75
Merge remote-tracking branch 'upstream/emc/develop' into emc/develop
DeniseWorthen Aug 12, 2020
d81a834
Fixcommit (#14)
DeniseWorthen Aug 13, 2020
4d7ba5b
Merge remote-tracking branch 'upstream/master' into emc/develop
DeniseWorthen Aug 13, 2020
5dcfca8
Merge remote-tracking branch 'upstream/emc/develop' into emc/develop
DeniseWorthen Aug 13, 2020
285985c
Update CICE6 for integration to S2S
DeniseWorthen Aug 31, 2020
6d30789
Merge remote-tracking branch 'upstream/emc/develop' into emc/develop
DeniseWorthen Aug 31, 2020
8129aab
Merge remote-tracking branch 'consortium/master' into emc/develop
DeniseWorthen Aug 31, 2020
ac617cd
Support TACC stampede (#19)
MinsukJi-NOAA Oct 8, 2020
23cdee7
Merge remote-tracking branch 'upstream/emc/develop' into emc/develop
DeniseWorthen Oct 8, 2020
1e4f42b
update icepack
DeniseWorthen Oct 30, 2020
2515f77
Merge remote-tracking branch 'consortium/master' into feature/updcice
DeniseWorthen Oct 30, 2020
41afe74
add ice_dyn_vp module to CICE_InitMod
DeniseWorthen Oct 30, 2020
2a0f332
update gitmodules, update icepack
DeniseWorthen Nov 10, 2020
f773ef3
Update CICE to consortium master (#23)
DeniseWorthen Nov 10, 2020
840e931
Merge remote-tracking branch 'upstream/emc/develop' into emc/develop
DeniseWorthen Nov 10, 2020
1e4d393
Merge remote-tracking branch 'upstream/emc/develop' into feature/updcice
DeniseWorthen Mar 14, 2021
66546ae
Merge remote-tracking branch 'Consortium/master' into feature/updcice
DeniseWorthen Mar 14, 2021
2eca569
update icepack
DeniseWorthen Apr 5, 2021
b52e91c
Merge remote-tracking branch 'upstream/emc/develop' into emc/develop
DeniseWorthen Apr 5, 2021
51db2f9
Merge remote-tracking branch 'Consortium/master' into feature/updcice
DeniseWorthen Jun 1, 2021
d8fb6d9
switch icepack branches
DeniseWorthen Jun 2, 2021
9a76541
update icepack
DeniseWorthen Jun 4, 2021
519d339
Update CICE to latest Consortium master (#26)
DeniseWorthen Jun 4, 2021
74e7b58
Merge remote-tracking branch 'upstream/emc/develop' into emc/develop
DeniseWorthen Jun 5, 2021
9d88d92
add cice changes for zlvs (#29)
DeniseWorthen Jun 10, 2021
d1f2d15
Merge remote-tracking branch 'upstream/emc/develop' into emc/develop
DeniseWorthen Jun 11, 2021
0c39047
Merge branch 'emc/develop' into feature/updcice
DeniseWorthen Jun 24, 2021
f3b2652
update icepack and pointer
DeniseWorthen Jun 24, 2021
9057817
Merge remote-tracking branch 'Consortium/master' into feature/updcice
DeniseWorthen Jun 24, 2021
1721728
Merge remote-tracking branch 'Consortium/master' into feature/updcice
DeniseWorthen Jul 2, 2021
55586f7
update icepack and revert gitmodules
DeniseWorthen Jul 20, 2021
441f693
Fix history features
apcraig Aug 10, 2021
15763d8
revert set_nml.histall
apcraig Aug 10, 2021
b3364a6
fix implementation error
apcraig Aug 11, 2021
96d5851
update model log output in ice_init
apcraig Aug 11, 2021
7b5c2b4
Fix QC issues
apcraig Aug 12, 2021
c5794b4
Update testing
apcraig Aug 13, 2021
eaa3c3a
update documentation
apcraig Aug 13, 2021
e31ce7e
reset calchk to 100000 years
apcraig Aug 13, 2021
83068c7
update evp1d test
apcraig Aug 13, 2021
3fd897e
Merge branch 'master' of https://github.com/cice-consortium/cice into…
apcraig Aug 13, 2021
4373d3d
update icepack
DeniseWorthen Aug 15, 2021
71f4fe6
Merge remote-tracking branch 'TCraig/tmB' into feature/updcice
DeniseWorthen Aug 15, 2021
aeb473a
Merge remote-tracking branch 'Consortium/master' into feature/updcice
DeniseWorthen Aug 20, 2021
aade124
update icepack
DeniseWorthen Aug 20, 2021
7f089d0
add memory profiling (#36)
DeniseWorthen Aug 23, 2021
397b4bd
Merge branch 'NOAA-EMC:emc/develop' into feature/updcice
DeniseWorthen Aug 26, 2021
a1b3375
update icepack
DeniseWorthen Aug 31, 2021
7d2139c
Merge remote-tracking branch 'Consortium/master' into feature/updcice
DeniseWorthen Aug 31, 2021
cd021b5
Merge remote-tracking branch 'Consortium/master' into feature/updcice
DeniseWorthen Sep 1, 2021
5cb78cd
fix rhoa when lowest_temp is 0.0
DeniseWorthen Sep 15, 2021
d0a45a2
update icepack submodule
DeniseWorthen Sep 16, 2021
2540695
Update CICE for latest Consortium master (#38)
DeniseWorthen Sep 16, 2021
8a88024
Merge branch 'NOAA-EMC:emc/develop' into feature/updcice
DeniseWorthen Sep 20, 2021
d95bd51
Use CICE-Consortium/Icepack master (#40)
DeniseWorthen Oct 1, 2021
d83c67b
Merge branch 'NOAA-EMC:emc/develop' into feature/updcice
DeniseWorthen Oct 12, 2021
8d4a3c6
recreate cap update branch (#42)
DeniseWorthen Nov 22, 2021
55bf9f4
Merge remote-tracking branch 'Consortium/main' into feature/updcice
DeniseWorthen Nov 29, 2021
7a0b65e
Merge branch 'emc/develop' into feature/updcice
DeniseWorthen Nov 30, 2021
abbebab
remove 2 extraneous lines
DeniseWorthen Nov 30, 2021
8ff0fb2
duplicate gitmodule style for icepack
DeniseWorthen Nov 30, 2021
27dfd1b
Update CICE to latest Consortium/main (#45)
DeniseWorthen Feb 24, 2022
c660075
Update CICE to Consortium/main (#48)
DeniseWorthen May 10, 2022
4b28dfe
Merge remote-tracking branch 'Consortium/main' into feature/addCgrid
DeniseWorthen May 14, 2022
247dc1d
fix comment, fix env for orion and hera
DeniseWorthen May 14, 2022
dd158e2
replace save_init with step_prep in CICE_RunMod
DeniseWorthen May 14, 2022
ae50efe
fixes for cgrid repro
DeniseWorthen May 22, 2022
cbc6046
remove added haloupdates
DeniseWorthen May 24, 2022
ab95d2d
Merge remote-tracking branch 'Consortium/main' into feature/addCgridf…
DeniseWorthen Jun 2, 2022
a38df37
Merge remote-tracking branch 'Consortium/main' into feature/addCgridf…
DeniseWorthen Jun 13, 2022
2d5487a
change F->S for ocean velocities and tilts
DeniseWorthen Jun 13, 2022
26498db
fix debug failure when grid_ice=C
DeniseWorthen Jun 20, 2022
9e2dd69
respond to review comments
DeniseWorthen Jun 22, 2022
cc0f89c
remove inserted whitespace for uvelE,N and vvelE,N
DeniseWorthen Jun 22, 2022
73cc18c
Merge remote-tracking branch 'Consortium/main' into feature/addCgridf…
DeniseWorthen Jun 23, 2022
1f70caf
Merge remote-tracking branch 'Consortium/main' into feature/updcice
DeniseWorthen Aug 20, 2022
968a0ed
Add wave-cice coupling; update to Consortium main (#51)
DeniseWorthen Aug 30, 2022
d6d081a
Merge branch 'emc/develop' into feature/updcice
DeniseWorthen Nov 2, 2022
2e68b9e
Merge remote-tracking branch 'Consortium/main' into feature/updcice
DeniseWorthen Nov 2, 2022
b893ee9
add initializationsin ice_state
DeniseWorthen Nov 2, 2022
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
6 changes: 6 additions & 0 deletions cicecore/cicedynB/general/ice_state.F90
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ subroutine alloc_state
n_trcr_strata = 0
nt_strata = 0
trcr_base = c0
aicen = c0
aicen_init = c0
Copy link
Contributor

Choose a reason for hiding this comment

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

For completeness, we should probably add vsnon/vsnon_init and vicen/vicen_init.

Copy link
Contributor Author

@DeniseWorthen DeniseWorthen Nov 2, 2022

Choose a reason for hiding this comment

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

I can add these initializations. I had meant to test whether they might have fixed a similar issue I had when I looked at the tr_snow updates which were made (?) earlier this year.

vicen = c0
vicen_init = c0
vsnon = c0
vsnon_init = c0

end subroutine alloc_state

Expand Down
9 changes: 8 additions & 1 deletion cicecore/drivers/nuopc/cmeps/CICE_InitMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ subroutine cice_init2()
use ice_calendar , only: dt, dt_dyn, istep, istep1, write_ic, init_calendar, calendar
use ice_communicate , only: my_task, master_task
use ice_diagnostics , only: init_diags
use ice_domain_size , only: ncat, nfsd
use ice_domain_size , only: ncat, nfsd, nfreq
use ice_dyn_eap , only: init_eap, alloc_dyn_eap
use ice_dyn_shared , only: kdyn, init_dyn
use ice_dyn_vp , only: init_vp
Expand All @@ -94,10 +94,12 @@ subroutine cice_init2()
use ice_restoring , only: ice_HaloRestore_init
use ice_timers , only: timer_total, init_ice_timers, ice_timer_start
use ice_transport_driver , only: init_transport
use ice_arrays_column , only: wavefreq, dwavefreq

logical(kind=log_kind) :: tr_aero, tr_zaero, skl_bgc, z_tracers
logical(kind=log_kind) :: tr_iso, tr_fsd, wave_spec, tr_snow
character(len=char_len) :: snw_aging_table
real(kind=dbl_kind), dimension(25) :: wave_spectrum_profile ! hardwire for now
character(len=*), parameter :: subname = '(cice_init2)'
!----------------------------------------------------

Expand Down Expand Up @@ -177,6 +179,11 @@ subroutine cice_init2()
endif
endif

if (wave_spec) then
call icepack_init_wave(nfreq=nfreq, &
wave_spectrum_profile=wave_spectrum_profile, wavefreq=wavefreq, dwavefreq=dwavefreq)
end if

! Initialize shortwave components using swdn from previous timestep
! if restarting. These components will be scaled to current forcing
! in prep_radiation.
Expand Down
22 changes: 11 additions & 11 deletions cicecore/drivers/nuopc/cmeps/ice_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module ice_comp_nuopc
use ice_calendar , only : force_restart_now, write_ic
use ice_calendar , only : idate, mday, mmonth, myear, year_init
use ice_calendar , only : msec, dt, calendar, calendar_type, nextsw_cday, istep
use ice_calendar , only : ice_calendar_noleap, ice_calendar_gregorian
Copy link
Contributor

Choose a reason for hiding this comment

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

We had made this change in our cap already.

use ice_kinds_mod , only : dbl_kind, int_kind, char_len, char_len_long
use ice_fileunits , only : nu_diag, nu_diag_set, inst_index, inst_name
use ice_fileunits , only : inst_suffix, release_all_fileunits, flush_fileunit
Expand Down Expand Up @@ -80,9 +81,6 @@ module ice_comp_nuopc
character(len=*) , parameter :: orb_variable_year = 'variable_year'
character(len=*) , parameter :: orb_fixed_parameters = 'fixed_parameters'

character(len=*),parameter :: shr_cal_noleap = 'NO_LEAP'
character(len=*),parameter :: shr_cal_gregorian = 'GREGORIAN'

type(ESMF_Mesh) :: ice_mesh

integer :: nthrds ! Number of threads to use in this component
Expand Down Expand Up @@ -216,7 +214,6 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
type(ESMF_Time) :: stopTime ! Stop time
type(ESMF_Time) :: refTime ! Ref time
type(ESMF_TimeInterval) :: timeStep ! Model timestep
type(ESMF_Calendar) :: esmf_calendar ! esmf calendar
type(ESMF_CalKind_Flag) :: esmf_caltype ! esmf calendar type
integer :: start_ymd ! Start date (YYYYMMDD)
integer :: start_tod ! start time of day (s)
Expand Down Expand Up @@ -339,7 +336,8 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
call get_component_instance(gcomp, inst_suffix, inst_index, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

inst_name = "ICE"//trim(inst_suffix)
! inst_name = "ICE"//trim(inst_suffix)
inst_name = "ICE"

!----------------------------------------------------------------------------
! start cice timers
Expand Down Expand Up @@ -470,9 +468,9 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
call ESMF_TimeGet( currTime, calkindflag=esmf_caltype, rc=rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (esmf_caltype == ESMF_CALKIND_NOLEAP) then
calendar_type = shr_cal_noleap
calendar_type = ice_calendar_noleap
else if (esmf_caltype == ESMF_CALKIND_GREGORIAN) then
calendar_type = shr_cal_gregorian
calendar_type = ice_calendar_gregorian
else
call abort_ice( subname//'ERROR:: bad calendar for ESMF' )
end if
Expand Down Expand Up @@ -581,9 +579,11 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
end if
call icepack_query_parameters( tfrz_option_out=tfrz_option)
if (tfrz_option_driver /= tfrz_option) then
write(errmsg,'(a)') trim(subname)//'error: tfrz_option from driver '//trim(tfrz_option_driver)//&
' must be the same as tfrz_option from cice namelist '//trim(tfrz_option)
call abort_ice(trim(errmsg))
write(errmsg,'(a)') trim(subname)//'WARNING: tfrz_option from driver '//trim(tfrz_option_driver)//&
' is overwriting tfrz_option from cice namelist '//trim(tfrz_option)
write(nu_diag,*) trim(errmsg)
call icepack_warnings_flush(nu_diag)
call icepack_init_parameters(tfrz_option_in=tfrz_option_driver)
endif
Copy link
Contributor

Choose a reason for hiding this comment

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

We also have this in our version.


! Flux convergence tolerance - always use the driver attribute value
Expand All @@ -594,7 +594,7 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
read(cvalue,*) atmiter_conv_driver
call icepack_query_parameters( atmiter_conv_out=atmiter_conv)
if (atmiter_conv_driver /= atmiter_conv) then
write(errmsg,'(a,d13.5,a,d13.5)') trim(subname)//'warning: atmiter_ from driver ',&
write(errmsg,'(a,d13.5,a,d13.5)') trim(subname)//'WARNING: atmiter_ from driver ',&
atmiter_conv_driver,' is overwritting atmiter_conv from cice namelist ',atmiter_conv
write(nu_diag,*) trim(errmsg)
call icepack_warnings_flush(nu_diag)
Expand Down
112 changes: 104 additions & 8 deletions cicecore/drivers/nuopc/cmeps/ice_import_export.F90
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ module ice_import_export
use ESMF
use NUOPC
use NUOPC_Model
use ice_kinds_mod , only : int_kind, dbl_kind, char_len, log_kind
use ice_kinds_mod , only : int_kind, dbl_kind, char_len, char_len_long, log_kind
use ice_constants , only : c0, c1, spval_dbl, radius
use ice_constants , only : field_loc_center, field_type_scalar, field_type_vector
use ice_blocks , only : block, get_block, nx_block, ny_block
use ice_domain , only : nblocks, blocks_ice, halo_info, distrb_info
use ice_domain_size , only : nx_global, ny_global, block_size_x, block_size_y, max_blocks, ncat
use ice_domain_size , only : nfreq, nfsd
use ice_exit , only : abort_ice
use ice_flux , only : strairxT, strairyT, strocnxT_iavg, strocnyT_iavg
use ice_flux , only : alvdr, alidr, alvdf, alidf, Tref, Qref, Uref
Expand All @@ -23,9 +24,10 @@ module ice_import_export
use ice_flux , only : fsnow, uocn, vocn, sst, ss_tltx, ss_tlty, frzmlt
use ice_flux , only : send_i2x_per_cat
use ice_flux , only : sss, Tf, wind, fsw
use ice_state , only : vice, vsno, aice, aicen_init, trcr
use ice_arrays_column , only : floe_rad_c, wave_spectrum
use ice_state , only : vice, vsno, aice, aicen_init, trcr, trcrn
use ice_grid , only : tlon, tlat, tarea, tmask, anglet, hm
use ice_grid , only : grid_type, grid_average_X2Y
use ice_grid , only : grid_type
use ice_mesh_mod , only : ocn_gridcell_frac
use ice_boundary , only : ice_HaloUpdate
use ice_fileunits , only : nu_diag, flush_fileunit
Expand All @@ -34,8 +36,10 @@ module ice_import_export
use ice_shr_methods , only : chkerr, state_reset
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_query_tracer_indices
use icepack_intfc , only : icepack_liquidus_temperature
use icepack_intfc , only : icepack_sea_freezing_temperature
use icepack_parameters , only : puny, c2
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 @@ -112,6 +116,7 @@ subroutine ice_advertise_fields(gcomp, importState, exportState, flds_scalar_nam
character(char_len) :: stdname
character(char_len) :: cvalue
logical :: flds_wiso ! use case
logical :: flds_wave ! use case
logical :: isPresent, isSet
character(len=*), parameter :: subname='(ice_import_export:ice_advertise_fields)'
!-------------------------------------------------------------------------------
Expand Down Expand Up @@ -148,6 +153,17 @@ subroutine ice_advertise_fields(gcomp, importState, exportState, flds_scalar_nam
write(nu_diag,*)'flds_wiso = ',flds_wiso
end if

flds_wave = .false.
call NUOPC_CompAttributeGet(gcomp, name='wav_coupling_to_cice', value=cvalue, &
isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
read(cvalue,*) flds_wave
end if
if (my_task == master_task) then
write(nu_diag,*)'flds_wave = ',flds_wave
end if

!-----------------
! advertise import fields
!-----------------
Expand Down Expand Up @@ -192,6 +208,14 @@ subroutine ice_advertise_fields(gcomp, importState, exportState, flds_scalar_nam
! from atm - dry dust deposition fluxes (4 sizes)
call fldlist_add(fldsToIce_num, fldsToIce, 'Faxa_dstdry', ungridded_lbound=1, ungridded_ubound=4)

! the following are advertised but might not be connected if they are not advertised in the
! in the cmeps esmFldsExchange_xxx_mod.F90 that is model specific
! from wave
if (flds_wave) then
call fldlist_add(fldsToIce_num, fldsToIce, 'Sw_elevation_spectrum', ungridded_lbound=1, &
ungridded_ubound=25)
end if

do n = 1,fldsToIce_num
call NUOPC_Advertise(importState, standardName=fldsToIce(n)%stdname, &
TransferOfferGeomObject='will provide', rc=rc)
Expand Down Expand Up @@ -225,6 +249,10 @@ subroutine ice_advertise_fields(gcomp, importState, exportState, flds_scalar_nam
call fldlist_add(fldsFrIce_num, fldsFrIce, 'ice_fraction_n', &
ungridded_lbound=1, ungridded_ubound=ncat)
end if
if (flds_wave) then
call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_thick' )
call fldlist_add(fldsFrIce_num, fldsFrIce, 'Si_floediam' )
end if

! ice/atm fluxes computed by ice
call fldlist_add(fldsFrIce_num, fldsFrIce, 'stress_on_air_ice_zonal' )
Expand Down Expand Up @@ -292,7 +320,7 @@ subroutine ice_realize_fields(gcomp, mesh, flds_scalar_name, flds_scalar_num, rc
type(ESMF_State) :: exportState
type(ESMF_Field) :: lfield
integer :: numOwnedElements
integer :: i, j, iblk, n
integer :: i, j, iblk, n, k
integer :: ilo, ihi, jlo, jhi ! beginning and end of physical domain
type(block) :: this_block ! block information for current block
real(dbl_kind), allocatable :: mesh_areas(:)
Expand Down Expand Up @@ -403,11 +431,10 @@ subroutine ice_import( importState, rc )
! local variables
integer,parameter :: nflds=16
integer,parameter :: nfldv=6
integer :: i, j, iblk, n
integer :: i, j, iblk, n, k
integer :: ilo, ihi, jlo, jhi !beginning and end of physical domain
type(block) :: this_block ! block information for current block
real (kind=dbl_kind),allocatable :: aflds(:,:,:,:)
real (kind=dbl_kind), dimension(nx_block,ny_block,max_blocks) :: work
real (kind=dbl_kind) :: workx, worky
real (kind=dbl_kind) :: MIN_RAIN_TEMP, MAX_SNOW_TEMP
real (kind=dbl_kind) :: Tffresh
Expand Down Expand Up @@ -559,6 +586,29 @@ subroutine ice_import( importState, rc )
end do
!$OMP END PARALLEL DO

! import wave elevation spectrum from wave (frequencies 1-25, assume that nfreq is 25)
if (State_FldChk(importState, 'Sw_elevation_spectrum')) then
if (nfreq /= 25) then
call abort_ice(trim(subname)//": ERROR nfreq not equal to 25 ")
end if
call state_getfldptr(importState, 'Sw_elevation_spectrum', fldptr=dataPtr2d, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
do k = 1,nfreq
n = 0
do iblk = 1, nblocks
this_block = get_block(blocks_ice(iblk),iblk)
ilo = this_block%ilo; ihi = this_block%ihi
jlo = this_block%jlo; jhi = this_block%jhi
do j = jlo, jhi
do i = ilo, ihi
n = n+1
wave_spectrum(i,j,k,iblk) = dataPtr2d(k,n)
end do
end do
end do
end do
end if

if ( State_fldChk(importState, 'Sa_ptem') .and. State_fldchk(importState,'air_density_height_lowest')) then
!$OMP PARALLEL DO PRIVATE(iblk,i,j)
do iblk = 1, nblocks
Expand Down Expand Up @@ -845,7 +895,7 @@ subroutine ice_export( exportState, rc )

! local variables
type(block) :: this_block ! block information for current block
integer :: i, j, iblk, n ! incides
integer :: i, j, iblk, n, k ! indices
integer :: n2 ! thickness category index
integer :: ilo, ihi, jlo, jhi ! beginning and end of physical domain
real (kind=dbl_kind) :: workx, worky ! tmps for converting grid
Expand All @@ -859,7 +909,11 @@ subroutine ice_export( exportState, rc )
real (kind=dbl_kind) :: tauxo (nx_block,ny_block,max_blocks) ! ice/ocean stress
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) :: floediam(nx_block,ny_block,max_blocks)
real (kind=dbl_kind) :: floethick(nx_block,ny_block,max_blocks) ! ice thickness
real (kind=dbl_kind) :: Tffresh
logical (kind=log_kind) :: tr_fsd
integer (kind=int_kind) :: nt_fsd
real (kind=dbl_kind), allocatable :: tempfld(:,:,:)
real (kind=dbl_kind), pointer :: dataptr_ifrac_n(:,:)
real (kind=dbl_kind), pointer :: dataptr_swpen_n(:,:)
Expand All @@ -877,6 +931,9 @@ subroutine ice_export( exportState, rc )
! tr_FY_out=tr_FY, tr_pond_out=tr_pond, tr_lvl_out=tr_lvl, &
! tr_zaero_out=tr_zaero, tr_bgc_Nit_out=tr_bgc_Nit)

call icepack_query_tracer_indices(nt_fsd_out=nt_fsd)
call icepack_query_tracer_flags(tr_fsd_out=tr_fsd)

call icepack_warnings_flush(nu_diag)
if (icepack_warnings_aborted()) call abort_ice(error_message=subname, &
file=u_FILE_u, line=__LINE__)
Expand All @@ -890,8 +947,10 @@ subroutine ice_export( exportState, rc )
tauya(:,:,:) = c0
tauxo(:,:,:) = c0
tauyo(:,:,:) = c0
floediam(:,:,:) = c0
floethick(:,:,:) = c0

!$OMP PARALLEL DO PRIVATE(iblk,i,j,workx,worky, this_block, ilo, ihi, jlo, jhi)
!$OMP PARALLEL DO PRIVATE(iblk,i,j,k,workx,worky, this_block, ilo, ihi, jlo, jhi)
do iblk = 1, nblocks
this_block = get_block(blocks_ice(iblk),iblk)
ilo = this_block%ilo
Expand All @@ -904,6 +963,27 @@ subroutine ice_export( exportState, rc )
! ice fraction
ailohi(i,j,iblk) = min(aice(i,j,iblk), c1)

if (tr_fsd) then
! floe thickness (m)
if (aice(i,j,iblk) > puny) then
floethick(i,j,iblk) = vice(i,j,iblk) / aice(i,j,iblk)
else
floethick(i,j,iblk) = c0
end if

! floe diameter (m)
workx = c0
worky = c0
do n = 1, ncat
do k = 1, nfsd
workx = workx + floe_rad_c(k) * aicen_init(i,j,n,iblk) * trcrn(i,j,nt_fsd+k-1,n,iblk)
worky = worky + aicen_init(i,j,n,iblk) * trcrn(i,j,nt_fsd+k-1,n,iblk)
end do
end do
if (worky > c0) workx = c2*workx / worky
floediam(i,j,iblk) = MAX(c2*floe_rad_c(1),workx)
endif

! surface temperature
Tsrf(i,j,iblk) = Tffresh + trcr(i,j,1,iblk) !Kelvin (original ???)

Expand Down Expand Up @@ -1054,6 +1134,22 @@ subroutine ice_export( exportState, rc )
call state_setexport(exportState, 'Si_snowh' , input=tempfld , lmask=tmask, ifrac=ailohi, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

! ------
! optional floe diameter and ice thickness to wave
! ------

! Sea ice thickness (m)
if (State_FldChk(exportState, 'Si_thick')) then
call state_setexport(exportState, 'Si_thick' , input=floethick , lmask=tmask, ifrac=ailohi, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

! Sea ice floe diameter (m)
if (State_FldChk(exportState, 'Si_floediam')) then
call state_setexport(exportState, 'Si_floediam' , input=floediam , lmask=tmask, ifrac=ailohi, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if

! ------
! ice/atm fluxes computed by ice
! ------
Expand Down