Skip to content

Commit bc32128

Browse files
committed
merge: AMR patch-slot infrastructure (SP12a T1) into PR branch
2 parents 3c6e77d + 931470d commit bc32128

8 files changed

Lines changed: 385 additions & 310 deletions

File tree

docs/documentation/case.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ To restart the simulation from $k$-th time step, see @ref running "Restarting Ca
683683
| `amr_tag_eps` | Real | Relative density-gradient threshold for AMR refinement tagging (default 0.1) |
684684
| `amr_buf` | Integer | Coarse-cell padding around tagged cells when regridding (default 3) |
685685
| `amr_subcycle` | Logical | Advance the coarse level at the case dt and the fine level at dt/2 (two substeps; Berger-Colella refluxing). Requires `amr`; incompatible with `cfl_dt`. |
686+
| `amr_max_patches` | Integer | Number of fixed refined-patch slots preallocated (each max-patch sized; ~N x device memory); must be >= 1 (default 4) |
686687
| `hybrid_weno` | Logical | Use linear-optimal reconstruction in smooth cells, full WENO only at flagged discontinuities (requires WENO reconstruction) |
687688
| `hybrid_weno_eps` | Real | Smoothness threshold for hybrid WENO shock flagging; must be > 0 (default 1e-2) |
688689
| `hybrid_riemann` | Logical | Use a cheap central/Rusanov flux in smooth cells, full HLLC only at flagged discontinuities (requires HLLC, 5eq/6eq) |
@@ -823,6 +824,14 @@ Accumulated fine-level fluxes are applied back to the coarse level (reflux corre
823824
after each coarse step.
824825
`amr_subcycle` is incompatible with `cfl_dt` (variable time step) and requires `amr = T`.
825826

827+
**Patch slots.**
828+
`amr_max_patches` (default 4) sets the number of fixed refined-patch slots preallocated
829+
for the run. Each slot is sized to the maximum patch extent, so `N` slots require roughly
830+
`N` times the device memory of a single patch; the goal is the compute win of refining
831+
separated features independently, and memory efficiency (compact per-patch pools) is a
832+
follow-up. The current release populates a single slot; multi-patch clustering is
833+
forthcoming.
834+
826835
**Restart.**
827836
Each save step writes a fine-level AMR restart file alongside the level-0 restart data
828837
(whose format is unchanged): the current — possibly regridded — patch box and the fine
@@ -847,6 +856,7 @@ visualization output is future work.
847856
| `amr_tag_eps` | Real | Normalized density-gradient threshold for refinement tagging; must be > 0 when `amr_regrid_int > 0` (default 0.1) |
848857
| `amr_buf` | Integer | Coarse-cell padding around tagged cells; must be >= 1 when `amr_regrid_int > 0` (default 3) |
849858
| `amr_subcycle` | Logical | Advance fine level at dt/2 (two substeps per coarse step) with Berger–Colella refluxing |
859+
| `amr_max_patches` | Integer | Number of fixed refined-patch slots preallocated (each max-patch sized; ~N x device memory); must be >= 1 (default 4) |
850860

851861
### 8. Acoustic Source {#sec-acoustic-source}
852862

src/simulation/m_amr.fpp

Lines changed: 228 additions & 208 deletions
Large diffs are not rendered by default.

src/simulation/m_amr_registers.fpp

Lines changed: 110 additions & 87 deletions
Large diffs are not rendered by default.

src/simulation/m_global_parameters.fpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ module m_global_parameters
289289
!! level covers exactly this intersection: local fine index 0 = patch-global fine index 2*(amr_isect_lo - amr_region_lo).
290290
integer :: amr_isect_lo(3) = 0, amr_isect_hi(3) = 0
291291
292+
!> Number of currently-active AMR fine-patch slots (T1: forced to 1) and the working slot index selecting which slot the
293+
!! per-patch machinery (advance/reflux/restrict/regrid/IO) operates on. Read by m_amr and m_amr_registers (mirrors, no
294+
!! use-cycle).
295+
integer :: amr_num_patches = 1, amr_cur = 1
296+
292297
contains
293298
294299
!> Assigns default values to the user inputs before reading them in. This enables for an easier consistency check of these
@@ -462,6 +467,7 @@ contains
462467
amr_tag_eps = 0.1_wp
463468
amr_buf = 3
464469
amr_subcycle = .false.
470+
amr_max_patches = 4
465471
hybrid_smooth_flux = 2
466472
partition_tile_size = 8
467473
many_ib_patch_parallelism = .false.

src/simulation/m_time_steppers.fpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,19 @@ contains
499499
end if
500500

501501
! AMR fine-level stage advance (interleaved, non-subcycled): q_cons_ts(1)%vf still holds
502-
! the coarse stage-entry state here (the stage-1 backup and RK update below have not run yet)
503-
if (amr .and. .not. amr_subcycle) call s_advance_amr_fine_stage(s, rk_coef(s,:), q_cons_ts(1)%vf, bc_type, q_T_sf, &
504-
& pb_ts(1)%sf, rhs_pb, mv_ts(1)%sf, rhs_mv, t_step, time_avg)
505-
! freg slices of rank-boundary patch faces move to the outside rank (ALL ranks call; no-op at np=1)
506-
if (amr .and. .not. amr_subcycle) call s_mpi_sendrecv_amr_reflux_faces()
507-
if (amr .and. .not. amr_subcycle) call s_amr_apply_reflux(rhs_vf) ! coarse update sees the fine flux at c/f faces
502+
! the coarse stage-entry state here (the stage-1 backup and RK update below have not run yet).
503+
! Each active patch slot is advanced + refluxed in turn (T1: one slot); amr_cur is reset to 1
504+
! afterwards so the next stage's coarse RHS captures creg into slot 1.
505+
if (amr .and. .not. amr_subcycle) then
506+
do amr_cur = 1, amr_num_patches
507+
call s_advance_amr_fine_stage(s, rk_coef(s,:), q_cons_ts(1)%vf, bc_type, q_T_sf, pb_ts(1)%sf, rhs_pb, &
508+
& mv_ts(1)%sf, rhs_mv, t_step, time_avg)
509+
! freg slices of rank-boundary patch faces move to the outside rank (ALL ranks call; no-op at np=1)
510+
call s_mpi_sendrecv_amr_reflux_faces()
511+
call s_amr_apply_reflux(rhs_vf) ! coarse update sees the fine flux at c/f faces
512+
end do
513+
amr_cur = 1
514+
end if
508515
509516
if (bubbles_lagrange .and. .not. adap_dt) call s_update_lagrange_tdv_rk(stage=s)
510517
if (ab_active) then
@@ -591,15 +598,19 @@ contains
591598
! Berger-Colella state reflux on the first coarse cells outside the patch
592599
if (amr) then
593600
! ghost lerp sources, restriction target, and state-reflux target are all device-resident:
594-
! the substep/restriction/reflux machinery runs as device kernels (M2)
595-
if (amr_subcycle) then
596-
call s_advance_amr_fine_substeps(q_cons_ts(stor)%vf, q_cons_ts(1)%vf, rk_coef, bc_type, q_T_sf, pb_ts(1)%sf, &
597-
& rhs_pb, mv_ts(1)%sf, rhs_mv, t_step, time_avg)
598-
end if
599-
call s_restrict_fine_to_coarse(q_cons_ts(1)%vf)
600-
! freg slices of rank-boundary patch faces move to the outside rank (ALL ranks call; no-op at np=1)
601-
if (amr_subcycle) call s_mpi_sendrecv_amr_reflux_faces()
602-
if (amr_subcycle) call s_amr_apply_reflux_state(q_cons_ts(1)%vf)
601+
! the substep/restriction/reflux machinery runs as device kernels (M2). Each active patch slot
602+
! (T1: one) is subcycled, restricted, and state-refluxed in turn; amr_cur resets to 1 afterwards.
603+
do amr_cur = 1, amr_num_patches
604+
if (amr_subcycle) then
605+
call s_advance_amr_fine_substeps(q_cons_ts(stor)%vf, q_cons_ts(1)%vf, rk_coef, bc_type, q_T_sf, pb_ts(1)%sf, &
606+
& rhs_pb, mv_ts(1)%sf, rhs_mv, t_step, time_avg)
607+
end if
608+
call s_restrict_fine_to_coarse(q_cons_ts(1)%vf)
609+
! freg slices of rank-boundary patch faces move to the outside rank (ALL ranks call; no-op at np=1)
610+
if (amr_subcycle) call s_mpi_sendrecv_amr_reflux_faces()
611+
if (amr_subcycle) call s_amr_apply_reflux_state(q_cons_ts(1)%vf)
612+
end do
613+
amr_cur = 1
603614
end if
604615
605616
#ifdef MFC_DEBUG

toolchain/mfc/case_validator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,9 @@ def check_amr(self):
13701370
acoustic_source = self.get("acoustic_source", "F") == "T"
13711371
amr_tag_eps = self.get("amr_tag_eps")
13721372
amr_buf = self.get("amr_buf")
1373+
amr_max_patches = self.get("amr_max_patches")
13731374

1375+
self.prohibit(amr_max_patches is not None and amr_max_patches < 1, "amr_max_patches must be >= 1")
13741376
self.prohibit(recon_type is not None and recon_type != 1, "amr requires WENO reconstruction (recon_type = 1)")
13751377
self.prohibit(time_stepper is not None and time_stepper != 3, "amr requires time_stepper = 3 (SSP-RK3)")
13761378
self.prohibit(model_eqns is not None and model_eqns != 2, "amr requires model_eqns = 2 (5-equation)")

toolchain/mfc/params/definitions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ def _load():
678678
_r("amr_tag_eps", REAL)
679679
_r("amr_buf", INT)
680680
_r("amr_subcycle", LOG)
681+
_r("amr_max_patches", INT)
681682
_r("hybrid_weno_eps", REAL, {"output"})
682683
_r("hybrid_smooth_flux", INT, {"output"})
683684
_r("partition_tile_size", INT, {"output"})
@@ -1363,6 +1364,7 @@ def _nv(targets: set, *names: str) -> None:
13631364
"amr_tag_eps",
13641365
"amr_buf",
13651366
"amr_subcycle",
1367+
"amr_max_patches",
13661368
"alf_factor",
13671369
"num_igr_iters",
13681370
"num_igr_warm_start_iters",

toolchain/mfc/params/descriptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"amr_tag_eps": "Relative density-gradient threshold for AMR refinement tagging",
124124
"amr_buf": "Coarse-cell padding around tagged cells when regridding",
125125
"amr_subcycle": "Advance the coarse level at the case dt and the fine level at dt/2 (two substeps; Berger-Colella refluxing)",
126+
"amr_max_patches": "Number of fixed refined-patch slots preallocated for multi-patch AMR (each sized max-patch; N slots ~ N x device memory)",
126127
"hybrid_weno": "Use linear-optimal reconstruction in smooth cells, full WENO only at flagged discontinuities",
127128
"hybrid_weno_eps": "Smoothness threshold for hybrid WENO shock flagging (must be > 0)",
128129
"hybrid_riemann": "Use a cheap central/Rusanov flux in smooth cells, full HLLC only at flagged discontinuities (requires HLLC, 5eq/6eq)",

0 commit comments

Comments
 (0)