Skip to content

Commit

Permalink
add more zm feilds; some clean up
Browse files Browse the repository at this point in the history
	new file:   cime_config/testdefs/testmods_dirs/cam/outfrq9s_esmf_zm/shell_commands
	new file:   cime_config/testdefs/testmods_dirs/cam/outfrq9s_esmf_zm/user_nl_cam
	new file:   cime_config/testdefs/testmods_dirs/cam/outfrq9s_esmf_zm/user_nl_clm

	modified:   src/utils/esmf_zm_mod.F90
	modified:   src/utils/zm_test_mod.F90
  • Loading branch information
fvitt committed Dec 6, 2024
1 parent ae4793f commit 1aad42b
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./xmlchange ROF_NCPL=\$ATM_NCPL
./xmlchange GLC_NCPL=\$ATM_NCPL
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mfilt=1,1,1,1,1,1,1,1,1,1
ndens=1,1,1,1,1,1,1,1,1,1
nhtfrq=9,9,9,9,9,9,9,9,9,9
write_nstep0=.true.
inithist='ENDOFRUN'

cam_physics_mesh = '$ATM_DOMAIN_MESH'
fincl2 = 'T_emsfzm', 'U_emsfzm', 'V_emsfzm','PS_emsfzm'
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
!----------------------------------------------------------------------------------
! Users should add all user specific namelist changes below in the form of
! namelist_var = new_namelist_value
!
! Include namelist variables for drv_flds_in ONLY if -megan and/or -drydep options
! are set in the CLM_NAMELIST_OPTS env variable.
!
! EXCEPTIONS:
! Set use_cndv by the compset you use and the CLM_BLDNML_OPTS -dynamic_vegetation setting
! Set use_vichydro by the compset you use and the CLM_BLDNML_OPTS -vichydro setting
! Set use_cn by the compset you use and CLM_BLDNML_OPTS -bgc setting
! Set use_crop by the compset you use and CLM_BLDNML_OPTS -crop setting
! Set spinup_state by the CLM_BLDNML_OPTS -bgc_spinup setting
! Set irrigate by the CLM_BLDNML_OPTS -irrig setting
! Set dtime with L_NCPL option
! Set fatmlndfrc with LND_DOMAIN_PATH/LND_DOMAIN_FILE options
! Set finidat with RUN_REFCASE/RUN_REFDATE/RUN_REFTOD options for hybrid or branch cases
! (includes $inst_string for multi-ensemble cases)
! Set glc_grid with CISM_GRID option
! Set glc_smb with GLC_SMB option
! Set maxpatch_glcmec with GLC_NEC option
! Set glc_do_dynglacier with GLC_TWO_WAY_COUPLING env variable
!----------------------------------------------------------------------------------
hist_nhtfrq = 9
hist_mfilt = 1
hist_ndens = 1

34 changes: 8 additions & 26 deletions src/utils/esmf_zm_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,13 @@ function esmf_zm_calc_2d(physfld) result(zmfld)
real(ESMF_KIND_R8), pointer :: physptr(:)
real(ESMF_KIND_R8), pointer :: lonlatptr(:,:)

real(r8) :: lonlat_fld(lon_beg:lon_end,lat_beg:lat_end)

character(len=*), parameter :: subname = 'esmf_zm_calc_2d: '

real(r8) :: arr(mynlons,1)
real(r8) :: arr(lon_beg:lon_end,1)
real(r8) :: gsum(1)

! regrid to lat/lon

call ESMF_FieldGet(physfld_2d, localDe=0, farrayPtr=physptr, rc=rc)
call check_esmf_error(rc, subname//'ESMF_FieldGet physptr')

Expand All @@ -486,21 +486,12 @@ function esmf_zm_calc_2d(physfld) result(zmfld)
call ESMF_FieldGet(lonlatfld_2d, localDe=0, farrayPtr=lonlatptr, rc=rc)
call check_esmf_error(rc, subname//'ESMF_FieldGet lonlatptr')

do ilat = lat_beg, lat_end
do ilon = lon_beg, lon_end
lonlat_fld(ilon,ilat) = lonlatptr(ilon,ilat)
end do
end do

! zonal mean
zmfld = huge(1._r8)

do ilat = lat_beg, lat_end
arr(1:mynlons,1) = lonlat_fld(lon_beg:lon_end,ilat)
arr(lon_beg:lon_end,1) = lonlatptr(lon_beg:lon_end,ilat)
call shr_reprosum_calc(arr, gsum, mynlons, mynlons, 1, gbl_count=nlons, commid=rows_comm)

zmfld(ilat) = gsum(1)/nlons

end do

end function esmf_zm_calc_2d
Expand All @@ -518,14 +509,15 @@ function esmf_zm_calc_3d(physfld) result(zmfld)
real(ESMF_KIND_R8), pointer :: physptr(:,:)
real(ESMF_KIND_R8), pointer :: lonlatptr(:,:,:)

real(r8) :: lonlat_fld(lon_beg:lon_end,lat_beg:lat_end,1:pver)
real(r8) :: arr(lon_beg:lon_end,pver)
real(r8) :: gsum(pver)

character(len=*), parameter :: subname = 'esmf_zm_calc_3d: '

integer :: k

! regrid to lat/lon

call ESMF_FieldGet(physfld_3d, localDe=0, farrayPtr=physptr, rc=rc)
call check_esmf_error(rc, subname//'ESMF_FieldGet physptr')

Expand All @@ -547,22 +539,12 @@ function esmf_zm_calc_3d(physfld) result(zmfld)
call ESMF_FieldGet(lonlatfld_3d, localDe=0, farrayPtr=lonlatptr, rc=rc)
call check_esmf_error(rc, subname//'ESMF_FieldGet lonlatptr')

do ilat = lat_beg, lat_end
do ilon = lon_beg, lon_end
do ilev = 1,pver
lonlat_fld(ilon,ilat,ilev) = lonlatptr(ilon,ilat,ilev)
end do
end do
end do

zmfld = -huge(1._r8)
! zonal mean

do ilat = lat_beg, lat_end
arr(lon_beg:lon_end,:) = lonlat_fld(lon_beg:lon_end,ilat,:)
arr(lon_beg:lon_end,:) = lonlatptr(lon_beg:lon_end,ilat,:)
call shr_reprosum_calc(arr, gsum, mynlons, mynlons, pver, gbl_count=nlons, commid=rows_comm)

zmfld(ilat,:) = gsum(:)/nlons

end do

end function esmf_zm_calc_3d
Expand Down
32 changes: 20 additions & 12 deletions src/utils/zm_test_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ end subroutine zm_test_reg
subroutine zm_test_init()

call addfld ('T_emsfzm', (/'lev'/), 'A', 'K', 'Zonal-Mean temperature', gridname='esmf_zonal_mean' )
call addfld ('U_emsfzm', (/'lev'/), 'A', 'm s-1', 'Zonal-Mean zonal wind', gridname='esmf_zonal_mean' )
call addfld ('V_emsfzm', (/'lev'/), 'A', 'm s-1', 'Zonal-Mean meridianal wind', gridname='esmf_zonal_mean' )
call addfld ('PS_emsfzm', horiz_only, 'A','Pa', 'Zonal-Mean srf press', gridname='esmf_zonal_mean' )

end subroutine zm_test_init
Expand All @@ -70,35 +72,41 @@ end subroutine zm_test_init
!------------------------------------------------------------------------------
subroutine zm_test_run(phys_state)

use time_manager, only: get_nstep

type(physics_state), intent(in) :: phys_state(begchunk:endchunk)

real(r8) :: physfld(pver,pcols,begchunk:endchunk)
real(r8) :: tfld(pver,pcols,begchunk:endchunk)
real(r8) :: ufld(pver,pcols,begchunk:endchunk)
real(r8) :: vfld(pver,pcols,begchunk:endchunk)
real(r8) :: psfld(pcols,begchunk:endchunk)

integer :: lchnk, ncol, icol, nstep, j
integer :: lchnk, ncol, icol

real(r8) :: temp_zm(lat_beg:lat_end,pver)
real(r8) :: t_zm(lat_beg:lat_end,pver)
real(r8) :: u_zm(lat_beg:lat_end,pver)
real(r8) :: v_zm(lat_beg:lat_end,pver)
real(r8) :: ps_zm(lat_beg:lat_end)

do lchnk = begchunk, endchunk
ncol = get_ncols_p(lchnk)
do icol = 1,ncol
physfld(:pver,icol,lchnk) = phys_state(lchnk)%t(icol,:pver)
tfld(:pver,icol,lchnk) = phys_state(lchnk)%t(icol,:pver)
ufld(:pver,icol,lchnk) = phys_state(lchnk)%u(icol,:pver)
vfld(:pver,icol,lchnk) = phys_state(lchnk)%v(icol,:pver)
psfld(icol,lchnk) = phys_state(lchnk)%ps(icol)
end do
end do

temp_zm = esmf_zm_calc_3d(physfld)

nstep = get_nstep()
t_zm = esmf_zm_calc_3d(tfld)
u_zm = esmf_zm_calc_3d(ufld)
v_zm = esmf_zm_calc_3d(vfld)

ps_zm = esmf_zm_calc_2d(psfld)

do j = lat_beg, lat_end
call outfld('PS_emsfzm',ps_zm(j),1,j)
call outfld('T_emsfzm',temp_zm(j,:),1,j)
do icol = lat_beg, lat_end
call outfld('PS_emsfzm',ps_zm(icol),1,icol)
call outfld('T_emsfzm',t_zm(icol,:),1,icol)
call outfld('U_emsfzm',u_zm(icol,:),1,icol)
call outfld('V_emsfzm',v_zm(icol,:),1,icol)
end do

end subroutine zm_test_run
Expand Down

0 comments on commit 1aad42b

Please sign in to comment.