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

Bring additional changes to support UFS Coastal App #1255

Closed
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ set(UFS_CAP "" CACHE STRING "Valid options are ${valid_caps}")
set(NETCDF ON CACHE BOOL "Build NetCDF programs (requires NetCDF)")
set(ENDIAN "BIG" CACHE STRING "Endianness of unformatted output files. Valid values are 'BIG', 'LITTLE', 'NATIVE'.")
set(EXCLUDE_FIND "" CACHE STRING "Don't try and search for these libraries (assumd to be handled by the compiler/wrapper)")
set(BUILD_TOOLS OFF CACHE BOOL "Build WW3 tools")

# make sure all "exclude_find" entries are lower case
list(TRANSFORM EXCLUDE_FIND TOLOWER)
Expand Down
2 changes: 1 addition & 1 deletion model/bin/switch_meshcap_pdlib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NCO PDLIB SCOTCH NOGRB DIST MPI PR3 UQ FLX0 SEED ST4 STAB0 NL1 BT1 DB1 MLIM FLD2 TR0 BS0 RWND WNX1 WNT1 CRX1 CRT1 O0 O1 O2 O3 O4 O5 O6 O7 O14 O15 IC0 IS0 REF0
NCO PDLIB SCOTCH SCRIP SCRIPNC NOGRB DIST MPI PR3 UQ FLX0 SEED ST4 STAB0 NL1 BT1 DB1 MLIM FLD2 TR0 BS0 RWND WNX1 WNT1 CRX1 CRT1 O0 O1 O2 O3 O4 O5 O6 O7 O14 O15 IC0 IS0 REF0
4 changes: 3 additions & 1 deletion model/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ if(UFS_CAP)
target_sources(ww3_lib PRIVATE ${cap_src})
target_link_libraries(ww3_lib PUBLIC esmf)
# Don't build executables when building WW3 ESMF library
set(programs "")
if (NOT BUILD_TOOLS)
set(programs "")
endif()
endif()

set_property(SOURCE w3initmd.F90
Expand Down
16 changes: 14 additions & 2 deletions model/src/wav_comp_nuopc.F90
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module wav_comp_nuopc
use w3odatmd , only : runtype, use_user_histname, user_histfname, use_user_restname, user_restfname
use w3odatmd , only : user_netcdf_grdout
use w3odatmd , only : time_origin, calendar_name, elapsed_secs
use wav_shr_mod , only : casename, multigrid, inst_suffix, inst_index, unstr_mesh
use wav_shr_mod , only : casename, multigrid, inst_suffix, inst_index, unstr_mesh, standalone
use wav_wrapper_mod , only : ufs_settimer, ufs_logtimer, ufs_file_setlogunit, wtime
#ifndef W3_CESMCOUPLED
use wmwavemd , only : wmwave
Expand Down Expand Up @@ -379,10 +379,22 @@ subroutine InitializeAdvertise(gcomp, importState, exportState, clock, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) runtimelog=(trim(cvalue)=="true")
write(logmsg,*) runtimelog
call ESMF_LogWrite('WW3_cap:RunTimeLog = '//trim(logmsg), ESMF_LOGMSG_INFO)
call ESMF_LogWrite(trim(subname)//': RunTimeLog = '//trim(logmsg), ESMF_LOGMSG_INFO)
if (runtimelog) then
call ufs_file_setLogUnit('./log.ww3.timer',nu_timer,runtimelog)
end if

! Determine if this is standalone run
call NUOPC_CompAttributeGet(gcomp, name="standalone", value=cvalue, isPresent=isPresent, isSet=isSet, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (isPresent .and. isSet) then
if (trim(cvalue) == '.true.' .or. trim(cvalue) == 'true') then
standalone = .true.
end if
end if
write(logmsg,'(A,l)') trim(subname)//': Standalone setting is ', standalone
call ESMF_LogWrite(trim(logmsg), ESMF_LOGMSG_INFO)

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

Expand Down
42 changes: 31 additions & 11 deletions model/src/wav_import_export.F90
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module wav_import_export
use wav_shr_mod , only : chkerr
use wav_shr_mod , only : state_diagnose, state_reset, state_getfldptr, state_fldchk
use wav_shr_mod , only : wav_coupling_to_cice, nwav_elev_spectrum, merge_import, dbug_flag, multigrid, unstr_mesh
use wav_shr_mod , only : standalone
use constants , only : grav, tpi, dwat, dair
use w3parall , only : init_get_isea

Expand Down Expand Up @@ -145,6 +146,9 @@ subroutine advertise_fields(importState, ExportState, flds_scalar_name, rc)
call fldlist_add(fldsFrWav_num, fldsFrWav, 'Sw_vstokes')
else
call fldlist_add(fldsFrWav_num, fldsFrWav, 'Sw_z0')
call fldlist_add(fldsFrWav_num, fldsFrWav, 'Sw_wavsuu')
call fldlist_add(fldsFrWav_num, fldsFrWav, 'Sw_wavsuv')
call fldlist_add(fldsFrWav_num, fldsFrWav, 'Sw_wavsvv')
end if
call fldlist_add(fldsFrWav_num, fldsFrWav, 'Sw_pstokes_x', ungridded_lbound=1, ungridded_ubound=3)
call fldlist_add(fldsFrWav_num, fldsFrWav, 'Sw_pstokes_y', ungridded_lbound=1, ungridded_ubound=3)
Expand Down Expand Up @@ -378,12 +382,14 @@ subroutine import_fields( gcomp, time0, timen, rc )
TW0 = time0 ! times for atm wind/temp fields.
TWN = timen

if (merge_import) then
if (merge_import .or. standalone) then
! set mask using u-wind field if merge_import; assume all import fields
! will have same missing overlap region
! import_mask memory will be allocate in set_importmask
call set_importmask(importState, clock, trim(uwnd), vm, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (merge_import) then
call set_importmask(importState, clock, trim(uwnd), vm, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
allocate(wxdata(nsea))
allocate(wydata(nsea))
call readfromfile('WND', wxdata, wydata, time0, timen, rc)
Expand All @@ -393,8 +399,10 @@ subroutine import_fields( gcomp, time0, timen, rc )
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call check_globaldata(gcomp, 'wydata', wydata, nsea, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call check_globaldata(gcomp, 'import_mask', import_mask, nsea, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
if (merge_import) then
call check_globaldata(gcomp, 'import_mask', import_mask, nsea, rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
end if
end if
end if

Expand All @@ -415,6 +423,12 @@ subroutine import_fields( gcomp, time0, timen, rc )
call FillGlobalInput(global_data, WX0)
call FillGlobalInput(global_data, WXN)
end if
else
if (standalone) then
call ESMF_LogWrite(trim(subname)//' no connected uwnd field. reading data from wind.ww3.', ESMF_LOGMSG_INFO)
call FillGlobalInput(wxdata, WX0)
call FillGlobalInput(wxdata, WXN)
end if
end if

! atm v wind
Expand All @@ -435,6 +449,12 @@ subroutine import_fields( gcomp, time0, timen, rc )
call FillGlobalInput(global_data, WY0)
call FillGlobalInput(global_data, WYN)
end if
else
if (standalone) then
call ESMF_LogWrite(trim(subname)//' no connected vwnd field. reading data from wind.ww3.', ESMF_LOGMSG_INFO)
call FillGlobalInput(wydata, WY0)
call FillGlobalInput(wydata, WYN)
end if
end if

! air temp - ocn temp
Expand Down Expand Up @@ -753,14 +773,14 @@ subroutine export_fields (gcomp, rc)
call CalcBotcur( va, wbcuru, wbcurv, wbcurp)
end if

if ( state_fldchk(exportState, 'wavsuu') .and. &
state_fldchk(exportState, 'wavsuv') .and. &
state_fldchk(exportState, 'wavsvv')) then
call state_getfldptr(exportState, 'sxxn', sxxn, rc=rc)
if ( state_fldchk(exportState, 'Sw_wavsuu') .and. &
state_fldchk(exportState, 'Sw_wavsuv') .and. &
state_fldchk(exportState, 'Sw_wavsvv')) then
call state_getfldptr(exportState, 'Sw_wavsuu', sxxn, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call state_getfldptr(exportState, 'sxyn', sxyn, rc=rc)
call state_getfldptr(exportState, 'Sw_wavsuv', sxyn, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call state_getfldptr(exportState, 'syyn', syyn, rc=rc)
call state_getfldptr(exportState, 'Sw_wavsvv', syyn, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return
call CalcRadstr2D( va, sxxn, sxyn, syyn)
end if
Expand Down
31 changes: 20 additions & 11 deletions model/src/wav_shr_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module wav_shr_mod
use ESMF , only : ESMF_Time, ESMF_TimeGet, ESMF_TimeSet
use ESMF , only : ESMF_TimeInterval, ESMF_TimeIntervalSet, ESMF_TimeIntervalGet
use ESMF , only : ESMF_VM, ESMF_VMGet, ESMF_VMBroadcast, ESMF_VMGetCurrent
use ESMF , only : ESMF_FieldStatus_Flag, ESMF_FIELDSTATUS_COMPLETE
use NUOPC , only : NUOPC_CompAttributeGet
use NUOPC_Model , only : NUOPC_ModelGet
use wav_kind_mod , only : r8 => shr_kind_r8, i8 => shr_kind_i8, cl=>shr_kind_cl, cs=>shr_kind_cs
Expand Down Expand Up @@ -75,6 +76,8 @@ module wav_shr_mod
!! be merged with a field provided from a file
logical , public :: multigrid = .false. !< @public logical to control whether wave model is run
!! as multigrid
logical , public :: standalone = .false. !< @public logical to control whether wave model is run
!! in standalone mode - read fields from file

interface ymd2date
module procedure ymd2date_int
Expand Down Expand Up @@ -484,6 +487,7 @@ subroutine state_reset(State, reset_value, rc)
! local variables
integer :: i,j,n
type(ESMF_Field) :: lfield
type(ESMF_FieldStatus_Flag) :: lstatus
integer :: fieldCount
integer :: lrank
character(ESMF_MAXSTR), allocatable :: lfieldnamelist(:)
Expand All @@ -505,19 +509,24 @@ subroutine state_reset(State, reset_value, rc)
call ESMF_StateGet(State, itemName=trim(lfieldnamelist(n)), field=lfield, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

call field_getfldptr(lfield, fldptr1=fldptr1, fldptr2=fldptr2, rank=lrank, rc=rc)
call ESMF_FieldGet(lfield, status=lstatus, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (lrank == 0) then
! no local data
elseif (lrank == 1) then
fldptr1 = reset_value
elseif (lrank == 2) then
fldptr2 = reset_value
else
call ESMF_LogWrite(trim(subname)//": ERROR in rank "//trim(lfieldnamelist(n)), ESMF_LOGMSG_ERROR)
rc = ESMF_FAILURE
return
if (lstatus == ESMF_FIELDSTATUS_COMPLETE) then
call field_getfldptr(lfield, fldptr1=fldptr1, fldptr2=fldptr2, rank=lrank, rc=rc)
if (ChkErr(rc,__LINE__,u_FILE_u)) return

if (lrank == 0) then
! no local data
elseif (lrank == 1) then
fldptr1 = reset_value
elseif (lrank == 2) then
fldptr2 = reset_value
else
call ESMF_LogWrite(trim(subname)//": ERROR in rank "//trim(lfieldnamelist(n)), ESMF_LOGMSG_ERROR)
rc = ESMF_FAILURE
return
endif
endif
enddo

Expand Down
Loading