Skip to content

Commit 102c3f1

Browse files
committed
fix MPI decomposition
1 parent 4c67385 commit 102c3f1

5 files changed

Lines changed: 53 additions & 34 deletions

File tree

src/simulation/m_muscl.fpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module m_muscl
1616

1717
use m_mpi_proxy
1818
use m_helper
19+
use m_thinc, only: s_thinc_compression
1920

2021
private; public :: s_initialize_muscl_module, s_muscl, s_finalize_muscl_module
2122

@@ -210,6 +211,15 @@ contains
210211
#:endfor
211212
end if
212213

214+
if (int_comp > 0 .and. v_size >= advxe) then
215+
#:for MUSCL_DIR, XYZ in [(1, 'x'), (2, 'y'), (3, 'z')]
216+
if (muscl_dir == ${MUSCL_DIR}$) then
217+
call s_thinc_compression(v_rs_ws_${XYZ}$_muscl, vL_rs_vf_x, vL_rs_vf_y, vL_rs_vf_z, vR_rs_vf_x, vR_rs_vf_y, &
218+
& vR_rs_vf_z, muscl_dir, is1_muscl, is2_muscl, is3_muscl)
219+
end if
220+
#:endfor
221+
end if
222+
213223
end subroutine s_muscl
214224

215225
!> Reshape cell-averaged variable data into direction-local work arrays for MUSCL reconstruction

src/simulation/m_rhs.fpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,12 +1665,6 @@ contains
16651665
call s_${SCHEME}$ (v_vf(iv%beg:iv%end), vL_x(:,:,:,iv%beg:iv%end), vL_y(:,:,:,:), vL_z(:,:,:,:), vR_x(:,:,:, &
16661666
& iv%beg:iv%end), vR_y(:,:,:,:), vR_z(:,:,:,:), recon_dir, is1, is2, is3)
16671667
end if
1668-
1669-
if (int_comp > 0 .and. iv%beg <= advxb .and. iv%end >= advxe) then
1670-
call nvtxStartRange("RHS-RECONSTRUCTION-COMPRESSION")
1671-
call s_thinc_compression(q_prim_qp%vf, vL_x, vL_y, vL_z, vR_x, vR_y, vR_z, recon_dir, is1, is2, is3)
1672-
call nvtxEndRange()
1673-
end if
16741668
end if
16751669
#:endfor
16761670

src/simulation/m_thinc.fpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

src/simulation/m_weno.fpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module m_weno
1313
! $:USE_GPU_MODULE()
1414

1515
use m_mpi_proxy
16+
use m_thinc, only: s_thinc_compression
1617

1718
private; public :: s_initialize_weno_module, s_initialize_weno, s_finalize_weno_module, s_weno
1819

@@ -1373,6 +1374,15 @@ contains
13731374
#:endif
13741375
end if
13751376

1377+
if (int_comp > 0 .and. v_size >= advxe) then
1378+
#:for WENO_DIR, XYZ in [(1, 'x'), (2, 'y'), (3, 'z')]
1379+
if (weno_dir == ${WENO_DIR}$) then
1380+
call s_thinc_compression(v_rs_ws_${XYZ}$, vL_rs_vf_x, vL_rs_vf_y, vL_rs_vf_z, vR_rs_vf_x, vR_rs_vf_y, &
1381+
& vR_rs_vf_z, weno_dir, is1_weno, is2_weno, is3_weno)
1382+
end if
1383+
#:endfor
1384+
end if
1385+
13761386
end subroutine s_weno
13771387

13781388
!> Set up the WENO reconstruction for a given direction

toolchain/mfc/case_validator.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ def check_weno(self):
346346
self.prohibit(n is not None and n > 0 and n + 1 < weno_order, f"For 2D simulation, n must be at least weno_order - 1 (= {weno_order - 1})")
347347
self.prohibit(p is not None and p > 0 and p + 1 < weno_order, f"For 3D simulation, p must be at least weno_order - 1 (= {weno_order - 1})")
348348

349+
int_comp = self.get("int_comp", 0)
350+
self.prohibit(weno_order == 1 and int_comp > 0, "int_comp requires weno_order > 1")
351+
349352
def check_muscl(self):
350353
"""Check constraints regarding MUSCL order"""
351354
recon_type = self.get("recon_type", 1)
@@ -370,6 +373,8 @@ def check_muscl(self):
370373
self.prohibit(n is not None and n > 0 and n + 1 < muscl_order, f"For 2D simulation, n must be at least muscl_order - 1 (= {muscl_order - 1})")
371374
self.prohibit(p is not None and p > 0 and p + 1 < muscl_order, f"For 3D simulation, p must be at least muscl_order - 1 (= {muscl_order - 1})")
372375

376+
self.prohibit(muscl_order == 1 and int_comp > 0, "int_comp requires muscl_order > 1")
377+
373378
def check_boundary_conditions(self):
374379
"""Checks constraints on boundary conditions"""
375380
cyl_coord = self.get("cyl_coord", "F") == "T"

0 commit comments

Comments
 (0)