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

Rayleigh Friction to CCPP #1245

Open
wants to merge 8 commits into
base: cam_development
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions bld/build-namelist
Original file line number Diff line number Diff line change
Expand Up @@ -5174,6 +5174,7 @@ sub check_snapshot_settings {
"'qbo_relax'", "'iondrag_calc_section'",
"'physics_dme_adjust'"));
push (@validList_bc, ("'dadadj_tend'", "'convect_deep_tend'",
"'rayleigh_friction_tend'",
"'convect_diagnostics_calc'"));
} else {
# CAM physpkg
Expand All @@ -5188,6 +5189,7 @@ sub check_snapshot_settings {
"'qbo_relax'", "'iondrag_calc_section'",
"'physics_dme_adjust'"));
push (@validList_bc, ("'dadadj_tend'", "'convect_deep_tend'",
"'rayleigh_friction_tend'",
"'convect_shallow_tend'"));
if ($microphys =~ /^mg/) {
if ($clubb_sgs =~ /$TRUE/io) {
Expand Down
1 change: 1 addition & 0 deletions bld/configure
Original file line number Diff line number Diff line change
Expand Up @@ -2343,6 +2343,7 @@ sub write_filepath
print $fh "$camsrcdir/src/atmos_phys/schemes/dry_adiabatic_adjust\n";
print $fh "$camsrcdir/src/atmos_phys/schemes/check_energy\n";
print $fh "$camsrcdir/src/atmos_phys/schemes/utilities\n";
print $fh "$camsrcdir/src/atmos_phys/schemes/rayleigh_friction\n";

# Dynamics package and test utilities
print $fh "$camsrcdir/src/dynamics/$dyn\n";
Expand Down
4 changes: 2 additions & 2 deletions bld/namelist_files/namelist_definition.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5556,15 +5556,15 @@ Default:
</entry>

<entry id="cam_take_snapshot_before" type="char*32" category="diagnostics"
group="phys_ctl_nl" valid_values="chem_emissions,aoa_tracers_timestep_tend,co2_cycle_set_ptend,chem_timestep_tend,vertical_diffusion_section,aero_model_drydep,gw_tend,qbo_relax,iondrag_calc_section,physics_dme_adjust,physics_dme_adjust,dadadj_tend,convect_deep_tend,convect_shallow_tend,convect_diagnostics_calc,macrop_driver_tend,clubb_tend_cam,microp_section,microp_driver_tend_subcol,aero_model_wetdep,radiation_tend,held_suarez_tend,kessler_tend,thatcher_jablonowski_precip_tend,user_set" >
group="phys_ctl_nl" valid_values="chem_emissions,aoa_tracers_timestep_tend,co2_cycle_set_ptend,chem_timestep_tend,vertical_diffusion_section,aero_model_drydep,gw_tend,qbo_relax,iondrag_calc_section,physics_dme_adjust,physics_dme_adjust,dadadj_tend,convect_deep_tend,convect_shallow_tend,convect_diagnostics_calc,macrop_driver_tend,clubb_tend_cam,microp_section,microp_driver_tend_subcol,aero_model_wetdep,radiation_tend,held_suarez_tend,kessler_tend,thatcher_jablonowski_precip_tend,rayleigh_friction_tend,user_set" >
Name of parameterization to take snapshot before running
user_set is used when a user inserts a call to cam_snapshot_all_outfld
using cam_snapshot_before_num as the first argument.
Default: Unused
</entry>

<entry id="cam_take_snapshot_after" type="char*32" category="diagnostics"
group="phys_ctl_nl" valid_values="chem_emissions,aoa_tracers_timestep_tend,co2_cycle_set_ptend,chem_timestep_tend,vertical_diffusion_section,aero_model_drydep,gw_tend,qbo_relax,iondrag_calc_section,physics_dme_adjust,physics_dme_adjust,dadadj_tend,convect_deep_tend,convect_shallow_tend,convect_diagnostics_calc,macrop_driver_tend,clubb_tend_cam,microp_section,microp_driver_tend_subcol,aero_model_wetdep,radiation_tend,held_suarez_tend,kessler_tend,thatcher_jablonowski_precip_tend,user_set" >
group="phys_ctl_nl" valid_values="chem_emissions,aoa_tracers_timestep_tend,co2_cycle_set_ptend,chem_timestep_tend,vertical_diffusion_section,aero_model_drydep,gw_tend,qbo_relax,iondrag_calc_section,physics_dme_adjust,physics_dme_adjust,dadadj_tend,convect_deep_tend,convect_shallow_tend,convect_diagnostics_calc,macrop_driver_tend,clubb_tend_cam,microp_section,microp_driver_tend_subcol,aero_model_wetdep,radiation_tend,held_suarez_tend,kessler_tend,thatcher_jablonowski_precip_tend,rayleigh_friction_tend,user_set" >
Name of parameterization to take snapshot after running
user_set is used when a user inserts a call to cam_snapshot_all_outfld
using cam_snapshot_after_num as the first argument.
Expand Down
2 changes: 1 addition & 1 deletion src/control/runtime_opts.F90
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ subroutine read_namelist(nlfilename, single_column, scmlat, scmlon)
use aircraft_emit, only: aircraft_emit_readnl
use cospsimulator_intr, only: cospsimulator_intr_readnl
use vertical_diffusion, only: vd_readnl
use rayleigh_friction, only: rayleigh_friction_readnl
use rayleigh_friction_cam, only: rayleigh_friction_readnl

use cam_diagnostics, only: diag_readnl
use radheat, only: radheat_readnl
Expand Down
20 changes: 16 additions & 4 deletions src/physics/cam/physpkg.F90
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ subroutine phys_init( phys_state, phys_tend, pbuf2d, cam_in, cam_out )
use spcam_drivers, only: spcam_init
use tracers, only: tracers_init
use aoa_tracers, only: aoa_tracers_init
use rayleigh_friction, only: rayleigh_friction_init
use rayleigh_friction_cam, only: rayleigh_friction_initO
use pbl_utils, only: pbl_utils_init
use vertical_diffusion, only: vertical_diffusion_init
use phys_debug_util, only: phys_debug_init
Expand Down Expand Up @@ -879,7 +879,7 @@ subroutine phys_init( phys_state, phys_tend, pbuf2d, cam_in, cam_out )

call gw_init()

call rayleigh_friction_init()
call rayleigh_friction_initO()

call pbl_utils_init(gravit, karman, cpair, rair, zvir)
call vertical_diffusion_init(pbuf2d)
Expand Down Expand Up @@ -1377,7 +1377,7 @@ subroutine tphysac (ztodt, cam_in, &
use cam_diagnostics, only: diag_phys_tend_writeout
use gw_drag, only: gw_tend
use vertical_diffusion, only: vertical_diffusion_tend
use rayleigh_friction, only: rayleigh_friction_tend
use rayleigh_friction_cam, only: rayleigh_friction_tendO
use constituents, only: cnst_get_ind
use physics_types, only: physics_state, physics_tend, physics_ptend, physics_update, &
physics_dme_adjust, set_dry_to_wet, physics_state_check, &
Expand Down Expand Up @@ -1667,14 +1667,26 @@ subroutine tphysac (ztodt, cam_in, &
! Rayleigh friction calculation
!===================================================
call t_startf('rayleigh_friction')
call rayleigh_friction_tend( ztodt, state, ptend)
if (trim(cam_take_snapshot_before) == "rayleigh_friction_tend") then
call cam_snapshot_all_outfld_tphysac(cam_snapshot_before_num, state, tend, cam_in, cam_out, pbuf,&
fh2o, surfric, obklen, flx_heat)
end if
call rayleigh_friction_tendO( ztodt, state, ptend)
if ( (trim(cam_take_snapshot_after) == "rayleigh_friction_tend") .and. &
(trim(cam_take_snapshot_before) == trim(cam_take_snapshot_after))) then
call cam_snapshot_ptend_outfld(ptend, lchnk)
end if
if ( ptend%lu ) then
call outfld( 'UTEND_RAYLEIGH', ptend%u, pcols, lchnk)
end if
if ( ptend%lv ) then
call outfld( 'VTEND_RAYLEIGH', ptend%v, pcols, lchnk)
end if
call physics_update(state, ptend, ztodt, tend)
if (trim(cam_take_snapshot_after) == "rayleigh_friction_tend") then
call cam_snapshot_all_outfld_tphysac(cam_snapshot_after_num, state, tend, cam_in, cam_out, pbuf,&
fh2o, surfric, obklen, flx_heat)
end if
call t_stopf('rayleigh_friction')

if (do_clubb_sgs) then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,29 @@

module rayleigh_friction
module rayleigh_friction_cam

!---------------------------------------------------------------------------------
! Module to apply rayleigh friction in region of model top.
! We specify a decay rate profile that is largest at the model top and
! drops off vertically using a hyperbolic tangent profile.
! We compute the tendencies in u and v using an Euler backward scheme.
! We then apply the negative of the kinetic energy tendency to "s", the dry
! static energy.
!
! calling sequence:
!
! rayleigh_friction_init initializes rayleigh friction constants
! rayleigh_friction_tend computes rayleigh friction tendencies
! This contains the residual code required to read namelists for the
! Rayliegh Friction scheme. All of the functional code (the init and run subroutines)
! has been moved to ncar_ccpp code.
!
!---------------------------Code history--------------------------------
! This is a new routine written by Art Mirin in collaboration with Phil Rasch.
! Initial coding for this version: Art Mirin, May 2007.
!---------------------------------------------------------------------------------

use shr_kind_mod, only: r8 => shr_kind_r8
use ppgrid, only: pver
use spmd_utils, only: masterproc
use phys_control, only: use_simple_phys
use cam_logfile, only: iulog
use cam_abortutils, only: endrun
use shr_kind_mod, only: r8 => shr_kind_r8
use ppgrid, only: pver
use spmd_utils, only: masterproc
use phys_control, only: use_simple_phys
use cam_logfile, only: iulog
use cam_abortutils, only: endrun
use rayleigh_friction, only: rayleigh_friction_init, rayleigh_friction_run

implicit none
private
save

! Public interfaces
public :: &
rayleigh_friction_readnl, &! read namelist
rayleigh_friction_init, &! Initialization
rayleigh_friction_tend ! Computation of tendencies
rayleigh_friction_readnl, & ! read namelist
rayleigh_friction_initO, & ! Initialization
rayleigh_friction_tendO ! Computation of tendencies

! Namelist variables
integer :: rayk0 = 2 ! vertical level at which rayleigh friction term is centered
Expand All @@ -48,11 +37,6 @@ module rayleigh_friction
real (r8) :: otau0 ! inverse of tau0
real (r8) :: otau(pver) ! inverse decay time versus vertical level

! We apply a profile of the form otau0 * [1 + tanh (x)] / 2 , where
! x = (k0 - k) / krange. The default is for x to equal 2 at k=1, meaning
! krange = (k0 - 1) / 2. The default is applied when raykrange is set to 0.
! If otau0 = 0, no term is applied.

!===============================================================================
contains
!===============================================================================
Expand Down Expand Up @@ -108,47 +92,23 @@ subroutine rayleigh_friction_readnl(nlfile)

end subroutine rayleigh_friction_readnl

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

subroutine rayleigh_friction_init()
subroutine rayleigh_friction_initO()

!---------------------------Local storage-------------------------------
real (r8) x
integer k

!-----------------------------------------------------------------------
! Compute tau array
!-----------------------------------------------------------------------

krange = raykrange
if (raykrange .eq. 0._r8) krange = (rayk0 - 1) / 2._r8
character(len=512) errmsg
integer errflg

tau0 = (86400._r8) * raytau0 ! convert to seconds
otau0 = 0._r8
if (tau0 .ne. 0._r8) otau0 = 1._r8/tau0
call rayleigh_friction_init(pver, raytau0, raykrange, rayk0, masterproc, iulog, errmsg, errflg)
if (errflg /= 0) call endrun(errmsg)

do k = 1, pver
x = (rayk0 - k) / krange
otau(k) = otau0 * (1 + tanh(x)) / (2._r8)
enddo

if (masterproc) then
if (tau0 > 0._r8) then
write (iulog,*) 'Rayleigh friction - krange = ', krange
write (iulog,*) 'Rayleigh friction - otau0 = ', otau0
write (iulog,*) 'Rayleigh friction decay rate profile'
do k = 1, pver
write (iulog,*) ' k = ', k, ' otau = ', otau(k)
enddo
end if
end if

end subroutine rayleigh_friction_init
end subroutine rayleigh_friction_initO

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

subroutine rayleigh_friction_tend( &
ztodt ,state ,ptend )
subroutine rayleigh_friction_tendO( &
ztodt ,state ,ptend )

!-----------------------------------------------------------------------
! compute tendencies for rayleigh friction
Expand All @@ -160,32 +120,19 @@ subroutine rayleigh_friction_tend( &
type(physics_state), intent(in) :: state ! physics state variables

type(physics_ptend), intent(out):: ptend ! individual parameterization tendencies

!---------------------------Local storage-------------------------------
integer :: ncol ! number of atmospheric columns
integer :: k ! level
real(r8) :: rztodt ! 1./ztodt
real(r8) :: c1, c2, c3 ! temporary variables
!-----------------------------------------------------------------------
!---------------------------Local storage-------------------------------
character(len=512) errmsg
integer errflg
integer ncol ! number of atmospheric columns
real(r8) rztodt ! 1./ztodt

call physics_ptend_init(ptend, state%psetcols, 'rayleigh friction', ls=.true., lu=.true., lv=.true.)

if (otau0 .eq. 0._r8) return

rztodt = 1._r8/ztodt
ncol = state%ncol

! u, v and s are modified by rayleigh friction

do k = 1, pver
c2 = 1._r8 / (1._r8 + otau(k)*ztodt)
c1 = -otau(k) * c2
c3 = 0.5_r8 * (1._r8 - c2*c2) * rztodt
ptend%u(:ncol,k) = c1 * state%u(:ncol,k)
ptend%v(:ncol,k) = c1 * state%v(:ncol,k)
ptend%s(:ncol,k) = c3 * (state%u(:ncol,k)**2 + state%v(:ncol,k)**2)
enddo
call rayleigh_friction_run(ncol, pver, ztodt, state%u, state%v, ptend%u, ptend%v, ptend%s, errmsg, errflg)
if (errflg /= 0) call endrun(errmsg)

end subroutine rayleigh_friction_tend
end subroutine rayleigh_friction_tendO

end module rayleigh_friction
end module rayleigh_friction_cam
20 changes: 16 additions & 4 deletions src/physics/cam7/physpkg.F90
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ subroutine phys_init( phys_state, phys_tend, pbuf2d, cam_in, cam_out )
use conv_water, only: conv_water_init
use tracers, only: tracers_init
use aoa_tracers, only: aoa_tracers_init
use rayleigh_friction, only: rayleigh_friction_init
use rayleigh_friction_cam, only: rayleigh_friction_initO
use pbl_utils, only: pbl_utils_init
use vertical_diffusion, only: vertical_diffusion_init
use phys_debug_util, only: phys_debug_init
Expand Down Expand Up @@ -877,7 +877,7 @@ subroutine phys_init( phys_state, phys_tend, pbuf2d, cam_in, cam_out )

call gw_init()

call rayleigh_friction_init()
call rayleigh_friction_initO()

call pbl_utils_init(gravit, karman, cpair, rair, zvir)
call vertical_diffusion_init(pbuf2d)
Expand Down Expand Up @@ -1358,7 +1358,7 @@ subroutine tphysac (ztodt, cam_in, &
use cam_diagnostics, only: diag_phys_tend_writeout
use gw_drag, only: gw_tend
use vertical_diffusion, only: vertical_diffusion_tend
use rayleigh_friction, only: rayleigh_friction_tend
use rayleigh_friction_cam, only: rayleigh_friction_tendO
use physics_types, only: physics_dme_adjust, set_dry_to_wet, physics_state_check, &
dyn_te_idx
use waccmx_phys_intr, only: waccmx_phys_mspd_tend ! WACCM-X major diffusion
Expand Down Expand Up @@ -2164,14 +2164,26 @@ subroutine tphysac (ztodt, cam_in, &
! Rayleigh friction calculation
!===================================================
call t_startf('rayleigh_friction')
call rayleigh_friction_tend( ztodt, state, ptend)
if (trim(cam_take_snapshot_before) == "rayleigh_friction_tend") then
call cam_snapshot_all_outfld_tphysac(cam_snapshot_before_num, state, tend, cam_in, cam_out, pbuf, &
fh2o, surfric, obklen, flx_heat, cmfmc, dlf, det_s, det_ice, net_flx)
end if
call rayleigh_friction_tendO( ztodt, state, ptend)
if ( (trim(cam_take_snapshot_after) == "rayleigh_friction_tend") .and. &
(trim(cam_take_snapshot_before) == trim(cam_take_snapshot_after))) then
call cam_snapshot_ptend_outfld(ptend, lchnk)
end if
if ( ptend%lu ) then
call outfld( 'UTEND_RAYLEIGH', ptend%u, pcols, lchnk)
end if
if ( ptend%lv ) then
call outfld( 'VTEND_RAYLEIGH', ptend%v, pcols, lchnk)
end if
call physics_update(state, ptend, ztodt, tend)
if (trim(cam_take_snapshot_after) == "rayleigh_friction_tend") then
call cam_snapshot_all_outfld_tphysac(cam_snapshot_after_num, state, tend, cam_in, cam_out, pbuf, &
fh2o, surfric, obklen, flx_heat, cmfmc, dlf, det_s, det_ice, net_flx)
end if
call t_stopf('rayleigh_friction')

if (do_clubb_sgs) then
Expand Down