pure function weno_face_conc_x(nx, ny, nz, tr, wet_T, cc, jj, kk, d, &
avail_up, avail_down, rung_max, cfl) result(conc)
!! Swept-average WENO donor concentration at a zonal face. `cc` is
!! the donor cell (i-index), `d = +1` (u>0, downwind toward +i) or
!! `d = -1` (u<0, downwind toward -i). Gathers the mirrored/clamped
!! stencil in downwind-positive order and dispatches to the coastal
!! swept-average face helper at the highest feasible rung.
!$acc routine seq
integer, intent(in) :: nx, ny, nz, cc, jj, kk, d, avail_up, avail_down, rung_max
real(wp), intent(in) :: tr(nx, ny, nz), wet_T(nx, ny)
real(wp), intent(in) :: cfl
real(wp) :: conc
integer :: rung, ip, im
real(wp) :: q0, qp1, qp2, qp3, qp4, qm1, qm2, qm3, qm4
rung = recon_rung_for_face(avail_up, avail_down, rung_max)
q0 = tr(cc, jj, kk)
if (rung <= 0) then
conc = q0 ! donor cell (0th order)
return
end if
ip = min(max(cc + d, 1), nx)
im = min(max(cc - d, 1), nx)
qp1 = ppm_mirror_h(tr(ip, jj, kk), q0, wet_T(ip, jj))
qm1 = ppm_mirror_h(tr(im, jj, kk), q0, wet_T(im, jj))
if (rung == 1) then
conc = plm_face_swept(qm1, q0, qp1, cfl)
return
end if
ip = min(max(cc + 2*d, 1), nx)
im = min(max(cc - 2*d, 1), nx)
qp2 = ppm_mirror_h(tr(ip, jj, kk), qp1, wet_T(ip, jj))
qm2 = ppm_mirror_h(tr(im, jj, kk), qm1, wet_T(im, jj))
if (rung == 2) then
conc = weno5_face_swept(qm2, qm1, q0, qp1, qp2, cfl)
return
end if
ip = min(max(cc + 3*d, 1), nx)
im = min(max(cc - 3*d, 1), nx)
qp3 = ppm_mirror_h(tr(ip, jj, kk), qp2, wet_T(ip, jj))
qm3 = ppm_mirror_h(tr(im, jj, kk), qm2, wet_T(im, jj))
if (rung == 3) then
conc = weno7_face_swept(qm3, qm2, qm1, q0, qp1, qp2, qp3, cfl)
return
end if
ip = min(max(cc + 4*d, 1), nx)
im = min(max(cc - 4*d, 1), nx)
qp4 = ppm_mirror_h(tr(ip, jj, kk), qp3, wet_T(ip, jj))
qm4 = ppm_mirror_h(tr(im, jj, kk), qm3, wet_T(im, jj))
conc = weno9_face_swept(qm4, qm3, qm2, qm1, q0, qp1, qp2, qp3, qp4, cfl)
end function weno_face_conc_x