Skip to content

Commit

Permalink
dadadj ccpp updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jtruesdal committed Apr 30, 2024
1 parent eaa6435 commit 5d10dfd
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 222 deletions.
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/dadadj\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.

98 changes: 55 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,46 @@ 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)

if (errflg /= 0) then
! error exit
write(errstring, *) errmsg,' at lat,lon:', &
state%lat(errflg)*180._r8/pi, state%lon(errflg)*180._r8/pi
call endrun('dadadj_tend: Error returned from dadadj_run: '//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)

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

0 comments on commit 5d10dfd

Please sign in to comment.