@@ -659,6 +659,7 @@ contains
659659
660660 ! Generic loop iterators
661661 integer :: i, j, k
662+ integer :: il, ir, jl, jr, kl, kr
662663 real (wp) :: radius
663664 real (wp), dimension (1 :3 ) :: center
664665
@@ -672,15 +673,26 @@ contains
672673 center(3) = patch_ib(patch_id)%z_centroid
673674 radius = patch_ib(patch_id)%radius
674675
676+ il = -gp_layers
677+ jl = -gp_layers
678+ kl = -gp_layers
679+ ir = m + gp_layers
680+ jr = n + gp_layers
681+ kr = p + gp_layers
682+ call get_bounding_indices(center(1) - radius, center(1) + radius, x_cc, il, ir)
683+ call get_bounding_indices(center(2) - radius, center(2) + radius, y_cc, jl, jr)
684+ call get_bounding_indices(center(3) - radius, center(3) + radius, z_cc, kl, kr)
685+
675686 ! Checking whether the sphere covers a particular cell in the domain
676687 ! and verifying whether the current patch has permission to write to
677688 ! that cell. If both queries check out, the primitive variables of
678689 ! the current patch are assigned to this cell.
679690 $:GPU_PARALLEL_LOOP(private=' [i,j,k,cart_y,cart_z]' ,&
680691 & copyin=' [patch_id,center,radius]' , collapse=3)
681- do k = -gp_layers, p+gp_layers
682- do j = -gp_layers, n+gp_layers
683- do i = -gp_layers, m+gp_layers
692+ do k = kl-1, kr+1
693+ do j = jl-1, jr+1
694+ do i = il-1, ir+1
695+ ! do i = -gp_layers, m+gp_layers
684696 if (grid_geometry == 3) then
685697 call s_convert_cylindrical_to_cartesian_coord(y_cc(j), z_cc(k))
686698 else
@@ -1058,6 +1070,46 @@ contains
10581070
10591071 end subroutine s_convert_cylindrical_to_spherical_coord
10601072
1073+ subroutine get_bounding_indices(left_bound, right_bound, cell_centers, left_index, right_index)
1074+
1075+ real(wp), intent(in) :: left_bound, right_bound
1076+ integer, intent(inout) :: left_index, right_index
1077+ real(wp), dimension(-buff_size:), intent(in) :: cell_centers
1078+
1079+ integer :: itr_left, itr_middle, itr_right
1080+
1081+ itr_left = left_index
1082+ itr_right = right_index
1083+
1084+ do while (itr_left + 1 < itr_right)
1085+ itr_middle = (itr_left + itr_right) / 2
1086+ if (cell_centers(itr_middle) < left_bound) then
1087+ itr_left = itr_middle
1088+ else if (cell_centers(itr_middle) > left_bound) then
1089+ itr_right = itr_middle
1090+ else
1091+ itr_left = itr_middle
1092+ exit
1093+ end if
1094+ end do
1095+ left_index = itr_left
1096+
1097+ itr_right = right_index
1098+ do while (itr_left + 1 < itr_right)
1099+ itr_middle = (itr_left + itr_right) / 2
1100+ if (cell_centers(itr_middle) < right_bound) then
1101+ itr_left = itr_middle
1102+ else if (cell_centers(itr_middle) > right_bound) then
1103+ itr_right = itr_middle
1104+ else
1105+ itr_right = itr_middle
1106+ exit
1107+ end if
1108+ end do
1109+ right_index = itr_right
1110+
1111+ end subroutine get_bounding_indices
1112+
10611113 !> Archimedes spiral function
10621114 !! @param myth Angle
10631115 !! @param offset Thickness
0 commit comments