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

UFS-dev PR#69 #103

Merged
merged 8 commits into from
Jan 11, 2024
Merged
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
20 changes: 10 additions & 10 deletions atmos_model.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2923,19 +2923,19 @@ subroutine setup_exportdata(rc)
call block_data_copy(datar82d, GFS_data(nb)%coupling%v10mi_cpl, Atm_block, nb, rc=localrc)
! Instantaneous Zonal compt of momentum flux (N/m**2)
case ('inst_zonal_moment_flx')
call block_data_copy(datar82d, GFS_data(nb)%coupling%dusfci_cpl, Atm_block, nb, rc=localrc)
call block_data_copy(datar82d, GFS_data(nb)%coupling%dusfci_cpl, Atm_block, nb, -one, spval, rc=localrc)
! Instantaneous Merid compt of momentum flux (N/m**2)
case ('inst_merid_moment_flx')
call block_data_copy(datar82d, GFS_data(nb)%coupling%dvsfci_cpl, Atm_block, nb, rc=localrc)
call block_data_copy(datar82d, GFS_data(nb)%coupling%dvsfci_cpl, Atm_block, nb, -one, spval, rc=localrc)
! Instantaneous Sensible heat flux (W/m**2)
case ('inst_sensi_heat_flx')
call block_data_copy(datar82d, GFS_data(nb)%coupling%dtsfci_cpl, Atm_block, nb, rc=localrc)
call block_data_copy(datar82d, GFS_data(nb)%coupling%dtsfci_cpl, Atm_block, nb, -one, spval, rc=localrc)
! Instantaneous Latent heat flux (W/m**2)
case ('inst_laten_heat_flx')
call block_data_copy(datar82d, GFS_data(nb)%coupling%dqsfci_cpl, Atm_block, nb, rc=localrc)
call block_data_copy(datar82d, GFS_data(nb)%coupling%dqsfci_cpl, Atm_block, nb, -one, spval, rc=localrc)
! Instantaneous Evap flux (kg/m**2/s)
case ('inst_evap_rate')
call block_data_copy(datar82d, GFS_data(nb)%coupling%dqsfci_cpl, Atm_block, nb, revap, spval, rc=localrc)
call block_data_copy(datar82d, GFS_data(nb)%coupling%dqsfci_cpl, Atm_block, nb, -revap, spval, rc=localrc)
! Instantaneous Downward long wave radiation flux (W/m**2)
case ('inst_down_lw_flx')
call block_data_copy(datar82d, GFS_data(nb)%coupling%dlwsfci_cpl, Atm_block, nb, rc=localrc)
Expand Down Expand Up @@ -2993,19 +2993,19 @@ subroutine setup_exportdata(rc)
!--- Mean quantities
! MEAN Zonal compt of momentum flux (N/m**2)
case ('mean_zonal_moment_flx_atm')
call block_data_copy(datar82d, GFS_data(nb)%coupling%dusfc_cpl, Atm_block, nb, rtime, spval, rc=localrc)
call block_data_copy(datar82d, GFS_data(nb)%coupling%dusfc_cpl, Atm_block, nb, -rtime, spval, rc=localrc)
! MEAN Merid compt of momentum flux (N/m**2)
case ('mean_merid_moment_flx_atm')
call block_data_copy(datar82d, GFS_data(nb)%coupling%dvsfc_cpl, Atm_block, nb, rtime, spval, rc=localrc)
call block_data_copy(datar82d, GFS_data(nb)%coupling%dvsfc_cpl, Atm_block, nb, -rtime, spval, rc=localrc)
! MEAN Sensible heat flux (W/m**2)
case ('mean_sensi_heat_flx')
call block_data_copy(datar82d, GFS_data(nb)%coupling%dtsfc_cpl, Atm_block, nb, rtime, spval, rc=localrc)
call block_data_copy(datar82d, GFS_data(nb)%coupling%dtsfc_cpl, Atm_block, nb, -rtime, spval, rc=localrc)
! MEAN Latent heat flux (W/m**2)
case ('mean_laten_heat_flx')
call block_data_copy(datar82d, GFS_data(nb)%coupling%dqsfc_cpl, Atm_block, nb, rtime, spval, rc=localrc)
call block_data_copy(datar82d, GFS_data(nb)%coupling%dqsfc_cpl, Atm_block, nb, -rtime, spval, rc=localrc)
! MEAN Evap rate (kg/m**2/s)
case ('mean_evap_rate')
call block_data_copy(datar82d, GFS_data(nb)%coupling%dqsfc_cpl, Atm_block, nb, rtime*revap, rc=localrc)
call block_data_copy(datar82d, GFS_data(nb)%coupling%dqsfc_cpl, Atm_block, nb, -rtime*revap, spval, rc=localrc)
! MEAN Downward LW heat flux (W/m**2)
case ('mean_down_lw_flx')
call block_data_copy(datar82d, GFS_data(nb)%coupling%dlwsfc_cpl, Atm_block, nb, rtime, spval, rc=localrc)
Expand Down
2 changes: 1 addition & 1 deletion ccpp/physics
23 changes: 15 additions & 8 deletions fv3_cap.F90
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ subroutine InitializeAdvertise(gcomp, rc)
integer :: wrttasks_per_group_from_parent, wrtLocalPet, num_threads
character(len=64) :: rh_filename
logical :: use_saved_routehandles, rh_file_exist
logical :: fieldbundle_is_restart = .false.
logical :: fieldbundle_uses_redist = .false.

integer :: sloc
type(ESMF_StaggerLoc) :: staggerloc
Expand Down Expand Up @@ -698,11 +698,12 @@ subroutine InitializeAdvertise(gcomp, rc)
if(mype == 0) print *,'af get wrtfb=',"output_"//trim(fcstItemNameList(j)),' rc=',rc
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

fieldbundle_is_restart = .false.
fieldbundle_uses_redist = .false.
! if (fcstItemNameList(j)(1:8) == "restart_" .or. fcstItemNameList(j)(1:18) == "cubed_sphere_grid_") then
if (fcstItemNameList(j)(1:8) == "restart_") then
! restart output forecast bundles, no need to set regridmethod
! Redist will be used instead of Regrid
fieldbundle_is_restart = .true.
fieldbundle_uses_redist = .true.
else
! history output forecast bundles
! determine regridmethod
Expand Down Expand Up @@ -739,7 +740,7 @@ subroutine InitializeAdvertise(gcomp, rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
else
! this is a Store() for the first wrtComp -> must do the Store()
if (fieldbundle_is_restart) then
if (fieldbundle_uses_redist) then
call ESMF_TraceRegionEnter("ESMF_FieldBundleRedistStore()", rc=rc)
call ESMF_FieldBundleRedistStore(fcstFB(j), wrtFB(j,1), &
routehandle=routehandle(j,1), &
Expand Down Expand Up @@ -1097,6 +1098,7 @@ subroutine ModelAdvance_phase2(gcomp, rc)
character(240) :: msgString

type(ESMF_Clock) :: clock, clock_out
integer :: fieldCount

!-----------------------------------------------------------------------------

Expand Down Expand Up @@ -1147,12 +1149,17 @@ subroutine ModelAdvance_phase2(gcomp, rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
endif

! execute the routehandle from fcstFB -> wrtFB (either Regrid() or Redist())
call ESMF_FieldBundleSMM(fcstFB(j), wrtFB(j,n_group), &
routehandle=routehandle(j, n_group), &
termorderflag=(/ESMF_TERMORDER_SRCSEQ/), rc=rc)
! execute the routehandle from fcstFB -> wrtFB (either Regrid() or Redist()), only if there are fields in the bundle
call ESMF_FieldBundleGet(fcstFB(j), fieldCount=fieldCount, rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

if (fieldCount > 0) then
call ESMF_FieldBundleSMM(fcstFB(j), wrtFB(j,n_group), &
routehandle=routehandle(j, n_group), &
termorderflag=(/ESMF_TERMORDER_SRCSEQ/), rc=rc)
if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return
end if

enddo

call ESMF_VMEpochExit(rc=rc)
Expand Down
58 changes: 27 additions & 31 deletions io/module_write_netcdf.F90
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module module_write_netcdf
use netcdf
use module_fv3_io_def,only : ideflate, nbits, &
ichunk2d,jchunk2d,ichunk3d,jchunk3d,kchunk3d, &
output_grid,dx,dy,lon1,lat1,lon2,lat2, &
dx,dy,lon1,lat1,lon2,lat2, &
time_unlimited
use mpi

Expand Down Expand Up @@ -95,6 +95,7 @@ subroutine write_netcdf(wrtfb, filename, &
integer, dimension(:), allocatable :: deToTileMap, localDeToDeMap
logical :: do_io
integer :: par_access
character(len=ESMF_MAXSTR) :: output_grid_name
!
is_cubed_sphere = .false.
tileCount = 0
Expand All @@ -106,13 +107,15 @@ subroutine write_netcdf(wrtfb, filename, &
do_io = par .or. (mype==0)

call ESMF_FieldBundleGet(wrtfb, fieldCount=fieldCount, rc=rc); ESMF_ERR_RETURN(rc)
call ESMF_AttributeGet(wrtfb, convention="NetCDF", purpose="FV3", &
name='grid', value=output_grid_name, rc=rc); ESMF_ERR_RETURN(rc)

allocate(compress_err(fieldCount)); compress_err=-999.
allocate(fldlev(fieldCount)) ; fldlev = 0
allocate(fcstField(fieldCount))
allocate(varids(fieldCount))

call ESMF_FieldBundleGet(wrtfb, fieldList=fcstField, grid=wrtGrid, &
call ESMF_FieldBundleGet(wrtfb, fieldList=fcstField, grid=wrtgrid, &
! itemorderflag=ESMF_ITEMORDER_ADDORDER, &
rc=rc); ESMF_ERR_RETURN(rc)

Expand Down Expand Up @@ -162,6 +165,10 @@ subroutine write_netcdf(wrtfb, filename, &
start_i = 1
start_j = 1
end if
if (is_cubed_sphere) then
start_i = mod(start_i, im)
start_j = mod(start_j, jm)
end if
end if

if (fieldDimCount > gridDimCount) then
Expand Down Expand Up @@ -240,21 +247,18 @@ subroutine write_netcdf(wrtfb, filename, &
ncerr = nf90_put_att(ncid, timeiso_varid, "_Encoding", "UTF-8"); NC_ERR_STOP(ncerr)

! coordinate variable attributes based on output_grid type
if (trim(output_grid(grid_id)) == 'gaussian_grid' .or. &
trim(output_grid(grid_id)) == 'global_latlon' .or. &
trim(output_grid(grid_id)) == 'regional_latlon' .or. &
trim(output_grid(grid_id)) == 'regional_latlon_moving') then
if (trim(output_grid_name) == 'gaussian' .or. &
trim(output_grid_name) == 'latlon') then
ncerr = nf90_put_att(ncid, im_varid, "long_name", "T-cell longitude"); NC_ERR_STOP(ncerr)
ncerr = nf90_put_att(ncid, im_varid, "units", "degrees_E"); NC_ERR_STOP(ncerr)
ncerr = nf90_put_att(ncid, jm_varid, "long_name", "T-cell latiitude"); NC_ERR_STOP(ncerr)
ncerr = nf90_put_att(ncid, jm_varid, "units", "degrees_N"); NC_ERR_STOP(ncerr)
else if (trim(output_grid(grid_id)) == 'rotated_latlon' .or. &
trim(output_grid(grid_id)) == 'rotated_latlon_moving') then
else if (trim(output_grid_name) == 'rotated_latlon') then
ncerr = nf90_put_att(ncid, im_varid, "long_name", "rotated T-cell longiitude"); NC_ERR_STOP(ncerr)
ncerr = nf90_put_att(ncid, im_varid, "units", "degrees"); NC_ERR_STOP(ncerr)
ncerr = nf90_put_att(ncid, jm_varid, "long_name", "rotated T-cell latiitude"); NC_ERR_STOP(ncerr)
ncerr = nf90_put_att(ncid, jm_varid, "units", "degrees"); NC_ERR_STOP(ncerr)
else if (trim(output_grid(grid_id)) == 'lambert_conformal') then
else if (trim(output_grid_name) == 'lambert_conformal') then
ncerr = nf90_put_att(ncid, im_varid, "long_name", "x-coordinate of projection"); NC_ERR_STOP(ncerr)
ncerr = nf90_put_att(ncid, im_varid, "units", "meters"); NC_ERR_STOP(ncerr)
ncerr = nf90_put_att(ncid, jm_varid, "long_name", "y-coordinate of projection"); NC_ERR_STOP(ncerr)
Expand Down Expand Up @@ -466,10 +470,10 @@ subroutine write_netcdf(wrtfb, filename, &

! write lon (lon_varid)
if (par) then
call ESMF_GridGetCoord(wrtGrid, coordDim=1, farrayPtr=array_r8, rc=rc); ESMF_ERR_RETURN(rc)
call ESMF_GridGetCoord(wrtgrid, coordDim=1, farrayPtr=array_r8, rc=rc); ESMF_ERR_RETURN(rc)
ncerr = nf90_put_var(ncid, lon_varid, values=array_r8, start=start_idx); NC_ERR_STOP(ncerr)
else
call ESMF_GridGetCoord(wrtGrid, coordDim=1, array=array, rc=rc); ESMF_ERR_RETURN(rc)
call ESMF_GridGetCoord(wrtgrid, coordDim=1, array=array, rc=rc); ESMF_ERR_RETURN(rc)
if (is_cubed_sphere) then
do t=1,tileCount
call ESMF_ArrayGather(array, array_r8_cube(:,:,t), rootPet=0, tile=t, rc=rc); ESMF_ERR_RETURN(rc)
Expand All @@ -491,39 +495,35 @@ subroutine write_netcdf(wrtfb, filename, &
! write grid_xt (im_varid)
if (do_io) then
allocate (x(im))
if (trim(output_grid(grid_id)) == 'gaussian_grid' .or. &
trim(output_grid(grid_id)) == 'global_latlon' .or. &
trim(output_grid(grid_id)) == 'regional_latlon' .or. &
trim(output_grid(grid_id)) == 'regional_latlon_moving') then
if (trim(output_grid_name) == 'gaussian' .or. trim(output_grid_name) == 'latlon') then
ncerr = nf90_put_var(ncid, im_varid, values=array_r8(:,jstart), start=[istart], count=[iend-istart+1]); NC_ERR_STOP(ncerr)
else if (trim(output_grid(grid_id)) == 'rotated_latlon' .or. &
trim(output_grid(grid_id)) == 'rotated_latlon_moving') then
else if (trim(output_grid_name) == 'rotated_latlon') then
do i=1,im
x(i) = lon1(grid_id) + (lon2(grid_id)-lon1(grid_id))/(im-1) * (i-1)
end do
ncerr = nf90_put_var(ncid, im_varid, values=x); NC_ERR_STOP(ncerr)
else if (trim(output_grid(grid_id)) == 'lambert_conformal') then
else if (trim(output_grid_name) == 'lambert_conformal') then
do i=1,im
x(i) = dx(grid_id) * (i-1)
end do
ncerr = nf90_put_var(ncid, im_varid, values=x); NC_ERR_STOP(ncerr)
else if (trim(output_grid(grid_id)) == 'cubed_sphere_grid') then
else if (trim(output_grid_name) == 'cubed_sphere') then
do i=1,im
x(i) = i
end do
ncerr = nf90_put_var(ncid, im_varid, values=x); NC_ERR_STOP(ncerr)
else
if (mype==0) write(0,*)'unknown output_grid ', trim(output_grid(grid_id))
if (mype==0) write(0,*)'unknown output_grid ', trim(output_grid_name)
call ESMF_Finalize(endflag=ESMF_END_ABORT)
end if
end if

! write lat (lat_varid)
if (par) then
call ESMF_GridGetCoord(wrtGrid, coordDim=2, farrayPtr=array_r8, rc=rc); ESMF_ERR_RETURN(rc)
call ESMF_GridGetCoord(wrtgrid, coordDim=2, farrayPtr=array_r8, rc=rc); ESMF_ERR_RETURN(rc)
ncerr = nf90_put_var(ncid, lat_varid, values=array_r8, start=start_idx); NC_ERR_STOP(ncerr)
else
call ESMF_GridGetCoord(wrtGrid, coordDim=2, array=array, rc=rc); ESMF_ERR_RETURN(rc)
call ESMF_GridGetCoord(wrtgrid, coordDim=2, array=array, rc=rc); ESMF_ERR_RETURN(rc)
if (is_cubed_sphere) then
do t=1,tileCount
call ESMF_ArrayGather(array, array_r8_cube(:,:,t), rootPet=0, tile=t, rc=rc); ESMF_ERR_RETURN(rc)
Expand All @@ -542,29 +542,25 @@ subroutine write_netcdf(wrtfb, filename, &
! write grid_yt (jm_varid)
if (do_io) then
allocate (y(jm))
if (trim(output_grid(grid_id)) == 'gaussian_grid' .or. &
trim(output_grid(grid_id)) == 'global_latlon' .or. &
trim(output_grid(grid_id)) == 'regional_latlon' .or. &
trim(output_grid(grid_id)) == 'regional_latlon_moving') then
if (trim(output_grid_name) == 'gaussian' .or. trim(output_grid_name) == 'latlon') then
ncerr = nf90_put_var(ncid, jm_varid, values=array_r8(istart,:), start=[jstart], count=[jend-jstart+1]); NC_ERR_STOP(ncerr)
else if (trim(output_grid(grid_id)) == 'rotated_latlon' .or. &
trim(output_grid(grid_id)) == 'rotated_latlon_moving') then
else if (trim(output_grid_name) == 'rotated_latlon') then
do j=1,jm
y(j) = lat1(grid_id) + (lat2(grid_id)-lat1(grid_id))/(jm-1) * (j-1)
end do
ncerr = nf90_put_var(ncid, jm_varid, values=y); NC_ERR_STOP(ncerr)
else if (trim(output_grid(grid_id)) == 'lambert_conformal') then
else if (trim(output_grid_name) == 'lambert_conformal') then
do j=1,jm
y(j) = dy(grid_id) * (j-1)
end do
ncerr = nf90_put_var(ncid, jm_varid, values=y); NC_ERR_STOP(ncerr)
else if (trim(output_grid(grid_id)) == 'cubed_sphere_grid') then
else if (trim(output_grid_name) == 'cubed_sphere') then
do j=1,jm
y(j) = j
end do
ncerr = nf90_put_var(ncid, jm_varid, values=y); NC_ERR_STOP(ncerr)
else
if (mype==0) write(0,*)'unknown output_grid ', trim(output_grid(grid_id))
if (mype==0) write(0,*)'unknown output_grid ', trim(output_grid_name)
call ESMF_Finalize(endflag=ESMF_END_ABORT)
end if
end if
Expand Down
Loading