Skip to content

Commit

Permalink
Latest movmtn mods - vorticity source
Browse files Browse the repository at this point in the history
  • Loading branch information
JulioTBacmeister committed Jan 15, 2025
1 parent 04f41af commit f998687
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 22 deletions.
42 changes: 31 additions & 11 deletions src/dynamics/se/dp_coupling.F90
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ subroutine d_p_coupling(phys_state, phys_tend, pbuf2d, dyn_out)

use gravity_waves_sources, only: gws_src_fnct
use dyn_comp, only: frontgf_idx, frontga_idx, vort4gw_idx
use phys_control, only: use_gw_front, use_gw_front_igw
use phys_control, only: use_gw_front, use_gw_front_igw, use_gw_movmtn_pbl
use hycoef, only: hyai, ps0
use fvm_mapping, only: dyn2phys_vector, dyn2phys_all_vars
use se_dyn_time_mod, only: timelevel_qdp
Expand Down Expand Up @@ -85,7 +85,7 @@ subroutine d_p_coupling(phys_state, phys_tend, pbuf2d, dyn_out)
real (kind=r8), allocatable :: frontgf_phys(:,:,:)
real (kind=r8), allocatable :: frontga_phys(:,:,:)

!++jtb 12/31/24
!++jtb 01/14/25
! Vorticity
real (kind=r8), allocatable :: vort4gw(:,:,:) ! temp arrays to hold vorticity
real (kind=r8), allocatable :: vort4gw_phys(:,:,:)
Expand Down Expand Up @@ -148,13 +148,16 @@ subroutine d_p_coupling(phys_state, phys_tend, pbuf2d, dyn_out)
if (ierr /= 0) call endrun("dp_coupling: Allocate of frontgf failed.")
allocate(frontga(nphys_pts,pver,nelemd), stat=ierr)
if (ierr /= 0) call endrun("dp_coupling: Allocate of frontga failed.")
!++jtb
end if
if (use_gw_movmtn_pbl) then
!++jtb 01/14/25
allocate(vort4gw(nphys_pts,pver,nelemd), stat=ierr)
if (ierr /= 0) call endrun("dp_coupling: Allocate of vort4gw failed.")
end if

!++jtb 01/14/25
if (iam < par%nprocs) then
if (use_gw_front .or. use_gw_front_igw) then
if (use_gw_front .or. use_gw_front_igw .or. use_gw_movmtn_pbl ) then
call gws_src_fnct(elem, tl_f, tl_qdp_np0, frontgf, frontga, vort4gw, nphys)
end if

Expand Down Expand Up @@ -220,7 +223,9 @@ subroutine d_p_coupling(phys_state, phys_tend, pbuf2d, dyn_out)
if (use_gw_front .or. use_gw_front_igw) then
frontgf(:,:,:) = 0._r8
frontga(:,:,:) = 0._r8
!++jtb
end if
if (use_gw_movmtn_pbl) then
!++jtb 01/14/25
vort4gw(:,:,:) = 0._r8
end if

Expand All @@ -240,7 +245,9 @@ subroutine d_p_coupling(phys_state, phys_tend, pbuf2d, dyn_out)
if (use_gw_front .or. use_gw_front_igw) then
allocate(frontgf_phys(pcols, pver, begchunk:endchunk))
allocate(frontga_phys(pcols, pver, begchunk:endchunk))
!++jtb 12/31/24
end if
if (use_gw_movmtn_pbl) then
!++jtb 01/14/25
allocate(vort4gw_phys(pcols, pver, begchunk:endchunk))
end if
!$omp parallel do num_threads(max_num_threads) private (col_ind, lchnk, icol, ie, blk_ind, ilyr, m)
Expand All @@ -259,7 +266,9 @@ subroutine d_p_coupling(phys_state, phys_tend, pbuf2d, dyn_out)
if (use_gw_front .or. use_gw_front_igw) then
frontgf_phys(icol, ilyr, lchnk) = frontgf(blk_ind(1), ilyr, ie)
frontga_phys(icol, ilyr, lchnk) = frontga(blk_ind(1), ilyr, ie)
!++jtb 12/31/24
end if
if (use_gw_movmtn_pbl) then
!++jtb 01/14/25
vort4gw_phys(icol, ilyr, lchnk) = vort4gw(blk_ind(1), ilyr, ie)
end if
end do
Expand All @@ -270,26 +279,37 @@ subroutine d_p_coupling(phys_state, phys_tend, pbuf2d, dyn_out)
end do
end do
end do
!++jtb 12/31/24
if (use_gw_front .or. use_gw_front_igw) then
!$omp parallel do num_threads(max_num_threads) private (lchnk, ncols, icol, ilyr, pbuf_chnk, pbuf_frontgf, pbuf_frontga, pbuf_vort4gw)
do lchnk = begchunk, endchunk
ncols = get_ncols_p(lchnk)
pbuf_chnk => pbuf_get_chunk(pbuf2d, lchnk)
call pbuf_get_field(pbuf_chnk, frontgf_idx, pbuf_frontgf)
call pbuf_get_field(pbuf_chnk, frontga_idx, pbuf_frontga)
call pbuf_get_field(pbuf_chnk, vort4gw_idx, pbuf_vort4gw)
do icol = 1, ncols
do ilyr = 1, pver
pbuf_frontgf(icol, ilyr) = frontgf_phys(icol, ilyr, lchnk)
pbuf_frontga(icol, ilyr) = frontga_phys(icol, ilyr, lchnk)
pbuf_vort4gw(icol, ilyr) = vort4gw_phys(icol, ilyr, lchnk)
end do
end do
end do
deallocate(frontgf_phys)
deallocate(frontga_phys)
!++jtb 12/31/24
end if
!++jtb 01/14/25
if (use_gw_movmtn_pbl) then
!$omp parallel do num_threads(max_num_threads) private (lchnk, ncols, icol, ilyr, pbuf_chnk, pbuf_frontgf, pbuf_frontga, pbuf_vort4gw)
do lchnk = begchunk, endchunk
ncols = get_ncols_p(lchnk)
pbuf_chnk => pbuf_get_chunk(pbuf2d, lchnk)
call pbuf_get_field(pbuf_chnk, vort4gw_idx, pbuf_vort4gw)
do icol = 1, ncols
do ilyr = 1, pver
pbuf_vort4gw(icol, ilyr) = vort4gw_phys(icol, ilyr, lchnk)
end do
end do
end do
!++jtb 01/14/25
deallocate(vort4gw_phys)
end if

Expand Down
8 changes: 5 additions & 3 deletions src/dynamics/se/dyn_comp.F90
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module dyn_comp
cnst_is_a_water_species
use cam_control_mod, only: initial_run
use cam_initfiles, only: initial_file_get_id, topo_file_get_id, pertlim
use phys_control, only: use_gw_front, use_gw_front_igw
use phys_control, only: use_gw_front, use_gw_front_igw, use_gw_movmtn_pbl
use dyn_grid, only: ini_grid_name, timelevel, hvcoord, edgebuf, &
ini_grid_hdim_name

Expand Down Expand Up @@ -573,6 +573,8 @@ subroutine dyn_register()
frontgf_idx)
call pbuf_add_field("FRONTGA", "global", dtype_r8, (/pcols,pver/), &
frontga_idx)
end if
if (use_gw_movmtn_pbl) then
call pbuf_add_field("VORT4GW", "global", dtype_r8, (/pcols,pver/), &
vort4gw_idx)
end if
Expand Down Expand Up @@ -879,8 +881,8 @@ subroutine dyn_init(dyn_in, dyn_out)
call get_loop_ranges(hybrid, ibeg=nets, iend=nete)
call prim_init2(elem, fvm, hybrid, nets, nete, TimeLevel, hvcoord)
!$OMP END PARALLEL

if (use_gw_front .or. use_gw_front_igw) call gws_init(elem)
!++jtb 01/14/25
if (use_gw_front .or. use_gw_front_igw .or. use_gw_movmtn_pbl) call gws_init(elem)
end if ! iam < par%nprocs

call addfld ('nu_kmvis', (/ 'lev' /), 'A', '', 'Molecular viscosity Laplacian coefficient' , gridname='GLL')
Expand Down
11 changes: 6 additions & 5 deletions src/dynamics/se/gravity_waves_sources.F90
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module gravity_waves_sources
private :: compute_frontogenesis
private :: compute_vorticity_4gw

type (EdgeBuffer_t) :: edge3
type (EdgeBuffer_t) :: edge3,edge1
type (derivative_t) :: deriv
real(r8) :: psurf_ref

Expand All @@ -44,6 +44,7 @@ subroutine gws_init(elem)

! Set up variables similar to dyn_comp and prim_driver_mod initializations
call initEdgeBuffer(par, edge3, elem, 3*nlev,nthreads=1)
call initEdgeBuffer(par, edge1, elem, nlev,nthreads=1)

psurf_ref = hypi(plev+1)

Expand All @@ -66,7 +67,7 @@ subroutine gws_src_fnct(elem, tl, tlq, frontgf, frontga, vort4gw, nphys)

!++jtb (12/31/24)
real (kind=r8), intent(out) :: vort4gw(nphys*nphys,pver,nelemd)
!!real (kind=r8) :: vort4gw(nphys*nphys,pver,nelemd)
!!real (kind=r8) :: vort4gw(nphys*nphys,pver,nelemd) phl remove


! Local variables
Expand Down Expand Up @@ -164,11 +165,11 @@ subroutine compute_vorticity_4gw(vort4gw,tl,tlq,elem,ederiv,hybrid,nets,nete,nph
vort_gll(:,:,k,ie) = vort_gll(:,:,k,ie)*elem(ie)%spheremp(:,:)
end do
! pack ++jtb no idea what these routines are doing
call edgeVpack(edge3, vort_gll(:,:,:,ie),nlev,0,ie)
call edgeVpack(edge1, vort_gll(:,:,:,ie),nlev,0,ie)
enddo
call bndry_exchange(hybrid,edge3,location='compute_vorticity_4gw')
call bndry_exchange(hybrid,edge1,location='compute_vorticity_4gw')
do ie=nets,nete
call edgeVunpack(edge3, vort_gll(:,:,:,ie),nlev,0,ie)
call edgeVunpack(edge1, vort_gll(:,:,:,ie),nlev,0,ie)
! apply inverse mass matrix,
do k=1,nlev
vort_gll(:,:,k,ie) = vort_gll(:,:,k,ie)*elem(ie)%rspheremp(:,:)
Expand Down
8 changes: 6 additions & 2 deletions src/physics/cam/gw_drag.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ subroutine gw_tend(state, pbuf, dt, ptend, cam_in, flx_heat)
use gw_front, only: gw_cm_src
use gw_convect, only: gw_beres_src
use gw_movmtn, only: gw_movmtn_src

use dycore, only: dycore_is
!------------------------------Arguments--------------------------------
type(physics_state), intent(in) :: state ! physics state structure
type(physics_buffer_desc), pointer :: pbuf(:) ! Physics buffer
Expand Down Expand Up @@ -1799,7 +1799,11 @@ subroutine gw_tend(state, pbuf, dt, ptend, cam_in, flx_heat)
! Vorticity from SE dycore. This needs to be either
! generalized to other dycores or protected with some
! endrun if dycore != SE
call pbuf_get_field(pbuf, vort4gw_idx, vort4gw)
if (dycore_is('SE')) then
call pbuf_get_field(pbuf, vort4gw_idx, vort4gw)
else
call endrun( 'gw_drag: vort4gw only with SE')
end if

xpwp_clubb(:ncol,:) = sqrt( upwp_clubb_gw(:ncol,:)**2 + vpwp_clubb_gw(:ncol,:)**2 )

Expand Down
2 changes: 1 addition & 1 deletion src/physics/cam/gw_movmtn.F90
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ subroutine vorticity_flux_src (vorticity , ncol, pverx, alpha_gw_movmtn, vort_sr
real(r8) :: scale_factor
integer :: k, nlayers

steering_level = pverx - 10 !++ ?????
steering_level = pverx - 20 !++ ?????
scale_factor = 1.e4 ! scales vorticity amp to u'w' in CLUBB
!-----------------------------------
! Simple average over layers.
Expand Down

0 comments on commit f998687

Please sign in to comment.