@@ -743,6 +743,7 @@ subroutine phys_init( phys_state, phys_tend, pbuf2d, cam_in, cam_out )
743743 use tracers, only: tracers_init
744744 use aoa_tracers, only: aoa_tracers_init
745745 use rayleigh_friction, only: rayleigh_friction_init
746+ use rayleigh_friction_cam, only: rf_nl_k0, rf_nl_krange, rf_nl_tau0
746747 use vertical_diffusion, only: vertical_diffusion_init
747748 use phys_debug_util, only: phys_debug_init
748749 use rad_constituents, only: rad_cnst_init
@@ -791,6 +792,11 @@ subroutine phys_init( phys_state, phys_tend, pbuf2d, cam_in, cam_out )
791792 ! temperature, water vapor, cloud
792793 ! ice, cloud liquid, U, V
793794 integer :: history_budget_histfile_num ! output history file number for budget fields
795+
796+ ! Needed for rayleigh friction
797+ character (len= 512 ) errmsg
798+ integer errflg
799+
794800 !- ----------------------------------------------------------------------
795801
796802 call physics_type_alloc(phys_state, phys_tend, begchunk, endchunk, pcols)
@@ -879,7 +885,9 @@ subroutine phys_init( phys_state, phys_tend, pbuf2d, cam_in, cam_out )
879885
880886 call gw_init()
881887
882- call rayleigh_friction_init()
888+ call rayleigh_friction_init(pver, rf_nl_tau0, rf_nl_krange, rf_nl_k0, masterproc, &
889+ iulog, errmsg, errflg)
890+ if (errflg /= 0 ) call endrun(errmsg)
883891
884892 call vertical_diffusion_init(pbuf2d)
885893
@@ -1360,11 +1368,11 @@ subroutine tphysac (ztodt, cam_in, &
13601368 use cam_diagnostics, only: diag_phys_tend_writeout
13611369 use gw_drag, only: gw_tend
13621370 use vertical_diffusion, only: vertical_diffusion_tend
1363- use rayleigh_friction, only: rayleigh_friction_tend
1371+ use rayleigh_friction, only: rayleigh_friction_run
13641372 use constituents, only: cnst_get_ind
13651373 use physics_types, only: physics_state, physics_tend, physics_ptend, physics_update, &
13661374 physics_dme_adjust, set_dry_to_wet, physics_state_check, &
1367- dyn_te_idx
1375+ dyn_te_idx, physics_ptend_init
13681376 use waccmx_phys_intr, only: waccmx_phys_mspd_tend ! WACCM-X major diffusion
13691377 use waccmx_phys_intr, only: waccmx_phys_ion_elec_temp_tend ! WACCM-X
13701378 use aoa_tracers, only: aoa_tracers_timestep_tend
@@ -1456,6 +1464,10 @@ subroutine tphysac (ztodt, cam_in, &
14561464 ! For aerosol budget diagnostics
14571465 type (carma_diags_t), pointer :: carma_diags_obj
14581466
1467+ ! For rayleigh friction CCPP calls
1468+ character (len= 512 ) errmsg
1469+ integer errflg
1470+
14591471 !- ----------------------------------------------------------------------
14601472 carma_diags_obj = > carma_diags_t()
14611473 if (.not. associated (carma_diags_obj)) then
@@ -1676,14 +1688,39 @@ subroutine tphysac (ztodt, cam_in, &
16761688 ! Rayleigh friction calculation
16771689 ! ===================================================
16781690 call t_startf(' rayleigh_friction' )
1679- call rayleigh_friction_tend( ztodt, state, ptend)
1691+ if (trim (cam_take_snapshot_before) == " rayleigh_friction_tend" ) then
1692+ call cam_snapshot_all_outfld_tphysac(cam_snapshot_before_num, state, tend, cam_in, cam_out, pbuf,&
1693+ fh2o, surfric, obklen, flx_heat)
1694+ end if
1695+
1696+ call physics_ptend_init(ptend, state% psetcols, ' rayleigh friction' , ls= .true. , lu= .true. , lv= .true. )
1697+
1698+ ! Initialize ptend variables to zero
1699+ ! REMOVECAM - no longer need these when CAM is retired and pcols no longer exists
1700+ ptend% u(:,:) = 0._r8
1701+ ptend% v(:,:) = 0._r8
1702+ ptend% s(:,:) = 0._r8
1703+ ! REMOVECAM_END
1704+
1705+ call rayleigh_friction_run(pver, ztodt, state% u(:ncol,:), state% v(:ncol,:), ptend% u(:ncol,:),&
1706+ ptend% v(:ncol,:), ptend% s(:ncol,:), errmsg, errflg)
1707+ if (errflg /= 0 ) call endrun(errmsg)
1708+
1709+ if ( (trim (cam_take_snapshot_after) == " rayleigh_friction_tend" ) .and. &
1710+ (trim (cam_take_snapshot_before) == trim (cam_take_snapshot_after))) then
1711+ call cam_snapshot_ptend_outfld(ptend, lchnk)
1712+ end if
16801713 if ( ptend% lu ) then
16811714 call outfld( ' UTEND_RAYLEIGH' , ptend% u, pcols, lchnk)
16821715 end if
16831716 if ( ptend% lv ) then
16841717 call outfld( ' VTEND_RAYLEIGH' , ptend% v, pcols, lchnk)
16851718 end if
16861719 call physics_update(state, ptend, ztodt, tend)
1720+ if (trim (cam_take_snapshot_after) == " rayleigh_friction_tend" ) then
1721+ call cam_snapshot_all_outfld_tphysac(cam_snapshot_after_num, state, tend, cam_in, cam_out, pbuf,&
1722+ fh2o, surfric, obklen, flx_heat)
1723+ end if
16871724 call t_stopf(' rayleigh_friction' )
16881725
16891726 if (do_clubb_sgs) then
0 commit comments