@@ -205,7 +205,7 @@ contains
205205 if (int_comp == 2 ) then
206206 @:ALLOCATE(mthinc_nhat(1 :3 , idwbuff(1 )%beg:idwbuff(1 )%end, idwbuff(2 )%beg:idwbuff(2 )%end, &
207207 & idwbuff(3 )%beg:idwbuff(3 )%end))
208- @:ALLOCATE(mthinc_d( idwbuff(1 )%beg:idwbuff(1 )%end, idwbuff(2 )%beg:idwbuff(2 )%end, idwbuff(3 )%beg:idwbuff(3 )%end))
208+ @:ALLOCATE(mthinc_d(idwbuff(1 )%beg:idwbuff(1 )%end, idwbuff(2 )%beg:idwbuff(2 )%end, idwbuff(3 )%beg:idwbuff(3 )%end))
209209 end if
210210
211211 end subroutine s_initialize_thinc_module
@@ -218,6 +218,7 @@ contains
218218 type(scalar_field), dimension (:), intent (in ) :: v_vf
219219 integer :: j, k, l
220220 real (wp) :: nr_x, nr_y, nr_z, nmag, ac
221+ type(int_bounds_info), dimension (3 ) :: id_norm
221222
222223 ! Zero arrays so boundary cells default to invalid (skipped)
223224
@@ -234,12 +235,22 @@ contains
234235 end do
235236 $:END_GPU_PARALLEL_LOOP()
236237
238+ id_norm(1 )%beg = idwbuff(1 )%beg + 1 ; id_norm(1 )%end = idwbuff(1 )%end - 1
239+ id_norm(2 )%beg = 0 ; id_norm(2 )%end = 0
240+ id_norm(3 )%beg = 0 ; id_norm(3 )%end = 0
241+ if (n > 0 ) then
242+ id_norm(2 )%beg = idwbuff(2 )%beg + 1 ; id_norm(2 )%end = idwbuff(2 )%end - 1
243+ end if
244+ if (p > 0 ) then
245+ id_norm(3 )%beg = idwbuff(3 )%beg + 1 ; id_norm(3 )%end = idwbuff(3 )%end - 1
246+ end if
247+
237248 ! Compute unit normal and solve for d at interior cells where central differences are valid. Only shrink bounds in active
238249 ! dimensions (n>0 , p>0 ).
239- $:GPU_PARALLEL_LOOP(collapse= 3 , private= ' [j, k, l, nr_x, nr_y, nr_z, nmag, ac]' )
240- do l = idwbuff (3 )%beg + min ( 1 , p), idwbuff (3 )%end - min ( 1 , p)
241- do k = idwbuff (2 )%beg + min ( 1 , n), idwbuff (2 )%end - min ( 1 , n)
242- do j = idwbuff (1 )%beg + 1 , idwbuff (1 )%end - 1
250+ $:GPU_PARALLEL_LOOP(collapse= 3 , private= ' [j, k, l, nr_x, nr_y, nr_z, nmag, ac]' , copyin = ' [id_norm] ' )
251+ do l = id_norm (3 )%beg, id_norm (3 )%end
252+ do k = id_norm (2 )%beg, id_norm (2 )%end
253+ do j = id_norm (1 )%beg, id_norm (1 )%end
243254 ac = v_vf(advxb)%sf(j, k, l)
244255
245256 if (ac >= ic_eps .and. ac <= 1._wp - ic_eps) then
@@ -283,10 +294,10 @@ contains
283294 !!
284295 !! THINC: 1D tanh profile with constant sharpness ic_beta. MTHINC: Multi- dimensional tanh profile using precomputed unit normal
285296 !! and interface position d; face values are obtained by integrating the profile over the cell face with Gauss quadrature.
286- subroutine s_thinc_compression (v_vf , vL_rs_vf_x , vL_rs_vf_y , vL_rs_vf_z , vR_rs_vf_x , vR_rs_vf_y , vR_rs_vf_z , recon_dir , &
297+ subroutine s_thinc_compression (v_rs_ws , vL_rs_vf_x , vL_rs_vf_y , vL_rs_vf_z , vR_rs_vf_x , vR_rs_vf_y , vR_rs_vf_z , recon_dir , &
287298 & is1_d , is2_d , is3_d )
288299
289- type(scalar_field ), dimension (:), intent (in ) :: v_vf
300+ real (wp ), dimension (idwbuff( 1 )%beg:,idwbuff( 2 )%beg:,idwbuff( 3 )%beg:, 1 :), intent (in ) :: v_rs_ws
290301 real (wp), dimension (idwbuff(1 )%beg:,idwbuff(2 )%beg:,idwbuff(3 )%beg:,1 :), intent (inout ) :: vL_rs_vf_x, vL_rs_vf_y, &
291302 & vL_rs_vf_z, vR_rs_vf_x, vR_rs_vf_y, vR_rs_vf_z
292303 integer , intent (in ) :: recon_dir
@@ -304,22 +315,11 @@ contains
304315 do l = is3_d%beg, is3_d%end
305316 do k = is2_d%beg, is2_d%end
306317 do j = is1_d%beg, is1_d%end
307- ! Read cell- averaged volume fractions from physical (x,y,z) space. The mapping from reshaped (j,k,l) to
308- ! physical depends on recon_dir: dir= 1 (x): (x,y,z) = (j,k,l) dir= 2 (y): (x,y,z) = (k,j,l) dir= 3 (z):
309- ! (x,y,z) = (l,k,j)
310- #:if REC_DIR == 1
311- aCL = v_vf(advxb)%sf(j - 1 , k, l)
312- aC = v_vf(advxb)%sf(j, k, l)
313- aCR = v_vf(advxb)%sf(j + 1 , k, l)
314- #:elif REC_DIR == 2
315- aCL = v_vf(advxb)%sf(k, j - 1 , l)
316- aC = v_vf(advxb)%sf(k, j, l)
317- aCR = v_vf(advxb)%sf(k, j + 1 , l)
318- #:else
319- aCL = v_vf(advxb)%sf(l, k, j - 1 )
320- aC = v_vf(advxb)%sf(l, k, j)
321- aCR = v_vf(advxb)%sf(l, k, j + 1 )
322- #:endif
318+ ! Read cell- averaged volume fractions from the reshaped cell- center workspace array. The first spatial
319+ ! index is always the reconstruction direction, so no per- direction index swizzling is needed.
320+ aCL = v_rs_ws(j - 1 , k, l, advxb)
321+ aC = v_rs_ws(j, k, l, advxb)
322+ aCR = v_rs_ws(j + 1 , k, l, advxb)
323323
324324 if (aC >= ic_eps .and. aC <= 1._wp - ic_eps) then
325325 if (int_comp == 2 .and. n > 0 ) then
@@ -342,8 +342,8 @@ contains
342342 ! Skip if no valid normal was computed
343343 if (nh1* nh1 + nh2* nh2 + nh3* nh3 > 5e-1_wp ) then
344344 ! Pure fluid densities from cell- averaged values. Safe: aC is bounded by [ic_eps, 1 - ic_eps].
345- rho1 = v_vf(contxb)%sf(ix, iy, iz )/ aC
346- rho2 = v_vf(contxe)%sf(ix, iy, iz )/ (1._wp - aC)
345+ rho1 = v_rs_ws(j, k, l, contxb )/ aC
346+ rho2 = v_rs_ws(j, k, l, contxe )/ (1._wp - aC)
347347
348348 ! Left face (face_pos = - 0.5 )
349349 aTHINC = f_mthinc_face_average(nh1, nh2, nh3, d_local, ic_beta, ${REC_DIR}$, - 5e-1_wp , &
@@ -386,9 +386,9 @@ contains
386386 B = exp (sgn* beta_eff* (2._wp * C - 1._wp ))
387387 A = (B/ cosh (beta_eff) - 1._wp )/ tanh (beta_eff)
388388
389- ! Save original density ratios before THINC overwrites them
390- rho_b = vL_rs_vf_${XYZ}$ (j, k, l, contxb)/ vL_rs_vf_${XYZ}$ (j, k, l, advxb)
391- rho_e = vL_rs_vf_${XYZ}$ (j, k, l, contxe)/ (1._wp - vL_rs_vf_${XYZ}$ (j, k, l, advxb) )
389+ ! Pure fluid densities from cell - averaged values
390+ rho_b = v_rs_ws (j, k, l, contxb)/ aC
391+ rho_e = v_rs_ws (j, k, l, contxe)/ (1._wp - aC )
392392
393393 ! Left reconstruction
394394 aTHINC = qmin + 5e-1_wp * qmax* (1._wp + sgn* A)
0 commit comments