Skip to content

Commit bb38235

Browse files
committed
feat(amr): support acoustic sources with a static block - source acts on the coarse grid (fine advance skips coarse-index spatials), startup abort on support/block overlap; golden 65C375B4
1 parent cafdaab commit bb38235

7 files changed

Lines changed: 284 additions & 11 deletions

File tree

src/simulation/m_acoustic_src.fpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,25 @@ contains
455455
call s_mpi_abort('Fatal Error: Inconsistent allocation of source_spatials')
456456
end if
457457

458+
! The AMR fine advance skips the acoustic source (the spatials above are coarse-grid
459+
! cell indices), so a static fine block overlapping the support would silently drop
460+
! the source inside the block - abort instead. Emitted waves still enter the block
461+
! through the coarse/fine coupling; only the support itself must stay coarse-only.
462+
if (amr) then
463+
do j = 1, count
464+
if (int(source_spatials(ai)%coord(1, &
465+
& j)) + start_idx(1) >= amr_block_beg(1) .and. int(source_spatials(ai)%coord(1, &
466+
& j)) + start_idx(1) <= amr_block_end(1) .and. (n_glb == 0 .or. (int(source_spatials(ai)%coord(2, &
467+
& j)) + start_idx(2) >= amr_block_beg(2) .and. int(source_spatials(ai)%coord(2, &
468+
& j)) + start_idx(2) <= amr_block_end(2))) .and. (p_glb == 0 .or. (int(source_spatials(ai)%coord(3, &
469+
& j)) + start_idx(3) >= amr_block_beg(3) .and. int(source_spatials(ai)%coord(3, &
470+
& j)) + start_idx(3) <= amr_block_end(3)))) then
471+
call s_mpi_abort('amr with acoustic_source: the source support overlaps the static fine block; ' &
472+
& // 'the source acts on the coarse grid only - move the source or the block apart')
473+
end if
474+
end do
475+
end if
476+
458477
if (count > 0) then
459478
$:GPU_UPDATE(device='[source_spatials(ai)%coord]')
460479
$:GPU_UPDATE(device='[source_spatials(ai)%val]')

src/simulation/m_amr.fpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ module m_amr
7474
!> Saved coarse-level global state for swap/restore
7575
integer :: sw_m, sw_n, sw_p
7676
type(int_bounds_info) :: sw_idwint(3), sw_idwbuff(3)
77+
logical :: sw_acoustic_source
7778
real(wp), allocatable :: sw_x_cb(:), sw_x_cc(:), sw_dx(:)
7879
real(wp), allocatable :: sw_y_cb(:), sw_y_cc(:), sw_dy(:)
7980
real(wp), allocatable :: sw_z_cb(:), sw_z_cc(:), sw_dz(:)
@@ -800,6 +801,10 @@ contains
800801
801802
sw_m = m; sw_n = n; sw_p = p
802803
sw_idwint = idwint; sw_idwbuff = idwbuff
804+
! the acoustic source's precomputed spatials are coarse-grid cell indices: applying them on
805+
! the fine block would inject at wrong cells (or out of bounds). The support is guaranteed
806+
! not to overlap the block (checked at startup), so the fine RHS correctly skips the source.
807+
sw_acoustic_source = acoustic_source; acoustic_source = .false.
803808
m = amr_slots(amr_cur)%m; n = amr_slots(amr_cur)%n; p = amr_slots(amr_cur)%p
804809
idwint(1)%beg = 0; idwint(1)%end = m
805810
idwint(2)%beg = 0; idwint(2)%end = n
@@ -872,6 +877,7 @@ contains
872877
873878
m = sw_m; n = sw_n; p = sw_p
874879
idwint = sw_idwint; idwbuff = sw_idwbuff
880+
acoustic_source = sw_acoustic_source
875881
! restore full coarse coords from bounce buffers
876882
x_cb = sw_x_cb; x_cc = sw_x_cc; dx = sw_dx
877883
if (n_glb > 0) then; y_cb = sw_y_cb; y_cc = sw_y_cc; dy = sw_dy; end if

src/simulation/m_checker.fpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,11 @@ contains
116116
@:PROHIBIT(active_box, "amr is incompatible with active_box (unvalidated combination)")
117117
@:PROHIBIT(hybrid_weno, "amr is incompatible with hybrid_weno (unvalidated combination)")
118118
@:PROHIBIT(hybrid_riemann, "amr is incompatible with hybrid_riemann (unvalidated combination)")
119-
@:PROHIBIT(acoustic_source, &
120-
& "amr is incompatible with acoustic_source (dt-dependent RHS source; unvalidated with the fine-level advance)")
119+
! acoustic sources act on the coarse grid only (their spatial support is precomputed as
120+
! coarse cell indices); a startup check aborts if the support overlaps the static block.
121+
! Dynamic regrid stays gated: new blocks could appear anywhere, including on the source.
122+
@:PROHIBIT(acoustic_source .and. amr_regrid_int > 0, &
123+
& "amr with acoustic_source requires a static block (amr_regrid_int = 0): the source support is precomputed on the coarse grid and must not overlap a fine block")
121124
@:PROHIBIT(any(amr_block_beg(1:num_dims) < 0), "amr_block_beg must be >= 0")
122125
@:PROHIBIT(amr_block_end(1) > m_glb .or. (num_dims >= 2 .and. amr_block_end(2) > n_glb) .or. (num_dims >= 3 &
123126
& .and. amr_block_end(3) > p_glb), "amr_block_end must be <= global cell max per axis")

tests/65C375B4/golden-metadata.txt

Lines changed: 193 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)