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

cam6_4_021: CCPP'ize dadadj #1026

Merged
merged 16 commits into from
Aug 17, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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 .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@

[submodule "atmos_phys"]
path = src/atmos_phys
url = https://github.com/ESCOMP/atmospheric_physics
fxtag = atmos_phys0_02_006
url = https://github.com/jtruesdal/atmospheric_physics
fxtag = dadadj
cacraigucar marked this conversation as resolved.
Show resolved Hide resolved
fxrequired = AlwaysRequired
fxDONOTUSEurl = https://github.com/ESCOMP/atmospheric_physics

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)
cacraigucar marked this conversation as resolved.
Show resolved Hide resolved

end subroutine dadadj_tend

Expand Down
Loading