Skip to content

Commit

Permalink
New rf interface to use ccpp code
Browse files Browse the repository at this point in the history
  • Loading branch information
Katetc committed Jan 13, 2025
1 parent 5c2bf28 commit 58d3800
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 88 deletions.
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
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
8 changes: 4 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 @@ -1671,7 +1671,7 @@ subroutine tphysac (ztodt, cam_in, &
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_tend( ztodt, state, ptend)
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)
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,21 @@ 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

0 comments on commit 58d3800

Please sign in to comment.