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

CCPP'ize dadadj #1026

Open
wants to merge 8 commits into
base: cam_development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions Externals_CAM.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ tag = ALI_ARMS_v1.0.1
required = True

[atmos_phys]
tag = atmos_phys0_02_006
branch = dadadj
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just adding the usual reminder to point to a tag once ESCOMP/atmospheric_physics#91 has been approved and merged.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks. Will do. Nice to know the order these things need to be done.

protocol = git
repo_url = https://github.com/ESCOMP/atmospheric_physics
repo_url = https://github.com/jtruesdal/atmospheric_physics
required = True
local_path = src/atmos_phys

Expand Down
1 change: 1 addition & 0 deletions bld/configure
Original file line number Diff line number Diff line change
Expand Up @@ -2304,6 +2304,7 @@ sub write_filepath

#Add the CCPP'ized subdirectories
print $fh "$camsrcdir/src/atmos_phys/zhang_mcfarlane\n";
print $fh "$camsrcdir/src/atmos_phys/dry_adiabatic_adjust\n";

# Dynamics package and test utilities
print $fh "$camsrcdir/src/dynamics/$dyn\n";
Expand Down
2 changes: 1 addition & 1 deletion src/control/cam_snapshot_common.F90
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module cam_snapshot_common
type (snapshot_type) :: tend_snapshot(6)
type (snapshot_type) :: cam_in_snapshot(30)
type (snapshot_type) :: cam_out_snapshot(30)
type (snapshot_type_nd) :: pbuf_snapshot(250)
type (snapshot_type_nd) :: pbuf_snapshot(300)

contains

Expand Down
174 changes: 0 additions & 174 deletions src/physics/cam/dadadj.F90

This file was deleted.

103 changes: 60 additions & 43 deletions src/physics/cam/dadadj_cam.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module dadadj_cam

! CAM interfaces for the dry adiabatic adjustment parameterization

use shr_kind_mod, only: r8=>shr_kind_r8, cs=>shr_kind_cs
use shr_kind_mod, only: r8=>shr_kind_r8, cs=>shr_kind_cs, cm=>shr_kind_cm
use ppgrid, only: pcols, pver, pverp
use constituents, only: pcnst
use air_composition, only: cappav, cpairv
Expand All @@ -17,15 +17,15 @@ module dadadj_cam
use namelist_utils, only: find_group_name
use units, only: getunit, freeunit

use dadadj, only: dadadj_initial, dadadj_calc
use dadadj, only: dadadj_init, dadadj_run

implicit none
private
save

public :: &
dadadj_readnl, &
dadadj_init, &
dadadj_cam_init, &
dadadj_tend

! Namelist variables
Expand All @@ -42,8 +42,10 @@ subroutine dadadj_readnl(filein)

namelist /dadadj_nl/ dadadj_nlvdry, dadadj_niter

integer :: unitn, ierr
character(len=*), parameter :: sub='dadadj_readnl'
integer :: unitn, ierr
integer :: errflg ! CCPP physics scheme error flag
character(len=512) :: errmsg ! CCPP physics scheme error message
character(len=*), parameter :: sub='dadadj_readnl'
!------------------------------------------------------------------

! Read namelist
Expand All @@ -67,26 +69,29 @@ subroutine dadadj_readnl(filein)
call mpibcast(dadadj_niter, 1, mpi_integer, masterprocid, mpicom)
#endif

call dadadj_initial(dadadj_nlvdry, dadadj_niter)
call dadadj_init(dadadj_nlvdry, dadadj_niter, pver, errmsg, errflg)
if (errflg /=0) then
call endrun('dadadj_readnl: Error returned from dadadj_init: '//trim(errmsg))
end if

if (masterproc .and. .not. use_simple_phys) then
write(iulog,*)'Dry adiabatic adjustment applied to top N layers; N=', &
dadadj_nlvdry
dadadj_nlvdry
write(iulog,*)'Dry adiabatic adjustment number of iterations for convergence =', &
dadadj_niter
dadadj_niter
end if

end subroutine dadadj_readnl


!===============================================================================

subroutine dadadj_init()
subroutine dadadj_cam_init()
use cam_history, only: addfld

call addfld('DADADJ_PD', (/ 'lev' /), 'A', 'probability', 'dry adiabatic adjustment probability')

end subroutine dadadj_init
end subroutine dadadj_cam_init


!===============================================================================
Expand All @@ -98,39 +103,51 @@ subroutine dadadj_tend(dt, state, ptend)
type(physics_state), intent(in) :: state ! Physics state variables
type(physics_ptend), intent(out) :: ptend ! parameterization tendencies

logical :: lq(pcnst)
real(r8) :: dadpdf(pcols, pver)
integer :: ncol, lchnk, icol_err
character(len=128) :: errstring ! Error string

ncol = state%ncol
lchnk = state%lchnk
lq(:) = .FALSE.
lq(1) = .TRUE.
call physics_ptend_init(ptend, state%psetcols, 'dadadj', ls=.true., lq=lq)

! use the ptend components for temporary storate and copy state info for input to
! dadadj_calc which directly updates the temperature and moisture input arrays.

ptend%s(:ncol,:pver) = state%t(:ncol,:pver)
ptend%q(:ncol,:pver,1) = state%q(:ncol,:pver,1)

call dadadj_calc( &
ncol, state%pmid, state%pint, state%pdel, cappav(:,:,lchnk), ptend%s, &
ptend%q(:,:,1), dadpdf, icol_err)

call outfld('DADADJ_PD', dadpdf(:ncol,:), ncol, lchnk)

if (icol_err > 0) then
! error exit
write(errstring, *) &
'dadadj_calc: No convergence in column at lat,lon:', &
state%lat(icol_err)*180._r8/pi, state%lon(icol_err)*180._r8/pi
call handle_errmsg(errstring, subname="dadadj_tend")
end if

ptend%s(:ncol,:) = (ptend%s(:ncol,:) - state%t(:ncol,:) )/dt * cpairv(:ncol,:,lchnk)
ptend%q(:ncol,:,1) = (ptend%q(:ncol,:,1) - state%q(:ncol,:,1))/dt
character(len=512) :: errstring ! Error string
character(len=512) :: errmsg ! CCPP physics scheme error message
character(len=64) :: scheme_name! CCPP physics scheme name (not used in CAM)
integer :: icol_err
integer :: lchnk
integer :: ncol
integer :: errflg ! CCPP physics scheme error flag
logical :: lq(pcnst)
real(r8) :: dadpdf(pcols, pver)

!------------------------------------------------------------------
ncol = state%ncol
lchnk = state%lchnk
lq(:) = .FALSE.
lq(1) = .TRUE.
call physics_ptend_init(ptend, state%psetcols, 'dadadj', ls=.true., lq=lq)

!REMOVECAM - no longer need these when CAM is retired and pcols no longer exists
dadpdf = 0._r8
ptend%s = 0._r8
ptend%q = 0._r8
!REMOVECAM_END

! dadadj_run returns t tend, we are passing the ptend%s array to receive the t tendency and will convert it to s
! before it is returned to CAM..
call dadadj_run( &
ncol, dt, state%pmid(:ncol,:), state%pint(:ncol,:), state%pdel(:ncol,:), state%t(:ncol,:), state%q(:ncol,:,1), cappav(:ncol,:,lchnk), &
ptend%s(:ncol,:), ptend%q(:ncol,:,1), dadpdf(:ncol,:), scheme_name, errmsg, errflg)

! error exit
if (errflg /= 0) then
! If this is a Convergence error then output lat lon of problem column using column index (errflg)
if(index('Convergence', errmsg) /= 0)then
write(errstring, *) trim(adjustl(errmsg)),' lat:',state%lat(errflg)*180._r8/pi,' lon:', &
state%lon(errflg)*180._r8/pi
else
errstring=trim(errmsg)
end if
call endrun('Error dadadj_tend:'//trim(errstring))
end if

call outfld('DADADJ_PD', dadpdf(:ncol,:), ncol, lchnk)

! convert the t tendency to an s tendency for cam
ptend%s(:ncol,:) = ptend%s(:ncol,:) * cpairv(:ncol,:,lchnk)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@nusbaume - Just wanting to confirm our definition of tendency_of_air_temperature? Is it without out the cpairv adjustment? If so, we may want to augment the conversion document to indicate the ptend%s special adjustment?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, tendency_of_air_temperature is basically the change in state%t (or air temperature), while ptend%s is technically the tendency_of_dry_air_enthalpy_at_constant_pressure, which in CAM we use to calculate the change state%t in physics_update by dividing by cpairv. So in other words:

ptend%t = ptend%s / cpairv

or in standard name lingo:

tendency_of_air_temperature = tendency_of_dry_air_enthalpy_at_constant_pressure / composition_dependent_specific_heat_of_dry_air_at_constant_pressure

Hopefully that makes sense? If not just let me know. Regardless I can say that I am pretty sure this new CAM code is correct as-is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed the SIMA dadadj parameterization to return a %s tendency instead of a temperature tendency and then used the appropriate update call in the suite definition files. This conversion line is no longer needed and ptend%s is passed through to the physics_update routine.


end subroutine dadadj_tend

Expand Down
4 changes: 2 additions & 2 deletions src/physics/cam/physpkg.F90
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ subroutine phys_init( phys_state, phys_tend, pbuf2d, cam_in, cam_out )
use sslt_rebin, only: sslt_rebin_init
use tropopause, only: tropopause_init
use solar_data, only: solar_data_init
use dadadj_cam, only: dadadj_init
use dadadj_cam, only: dadadj_cam_init
use cam_abortutils, only: endrun
use nudging, only: Nudge_Model, nudging_init
use cam_snapshot, only: cam_snapshot_init
Expand Down Expand Up @@ -952,7 +952,7 @@ subroutine phys_init( phys_state, phys_tend, pbuf2d, cam_in, cam_out )
#endif
call sslt_rebin_init()
call tropopause_init()
call dadadj_init()
call dadadj_cam_init()

prec_dp_idx = pbuf_get_index('PREC_DP')
snow_dp_idx = pbuf_get_index('SNOW_DP')
Expand Down
4 changes: 2 additions & 2 deletions src/physics/cam_dev/physpkg.F90
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ subroutine phys_init( phys_state, phys_tend, pbuf2d, cam_in, cam_out )
use clubb_intr, only: clubb_ini_cam
use tropopause, only: tropopause_init
use solar_data, only: solar_data_init
use dadadj_cam, only: dadadj_init
use dadadj_cam, only: dadadj_cam_init
use cam_abortutils, only: endrun
use nudging, only: Nudge_Model, nudging_init
use cam_snapshot, only: cam_snapshot_init
Expand Down Expand Up @@ -920,7 +920,7 @@ subroutine phys_init( phys_state, phys_tend, pbuf2d, cam_in, cam_out )
call metdata_phys_init()
#endif
call tropopause_init()
call dadadj_init()
call dadadj_cam_init()

prec_dp_idx = pbuf_get_index('PREC_DP')
snow_dp_idx = pbuf_get_index('SNOW_DP')
Expand Down