Skip to content

Commit 85889c0

Browse files
Bindary search for IB index region beginning for reduced IB marker compute
1 parent 5d885bb commit 85889c0

2 files changed

Lines changed: 61 additions & 4 deletions

File tree

src/simulation/m_ib_patches.fpp

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

src/simulation/m_ibm.fpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ contains
992992
993993
integer :: i, ierr
994994
995-
call nvtxStartRange("UPDATE-MIB")
995+
call nvtxStartRange("UPDATE-MIBM")
996996
997997
! Clears the existing immersed boundary indices
998998
ib_markers%sf = 0._wp
@@ -1057,6 +1057,9 @@ contains
10571057
#:else
10581058
real(wp), dimension(num_fluids) :: dynamic_viscosities
10591059
#:endif
1060+
1061+
call nvtxStartRange("COMPUTE-IB-FORCES")
1062+
10601063
forces = 0._wp
10611064
torques = 0._wp
10621065
@@ -1187,6 +1190,8 @@ contains
11871190
patch_ib(i)%torque(:) = matmul(patch_ib(i)%rotation_matrix_inverse, torques(i, :)) ! torques must be converted to the local coordinates of the IB
11881191
end do
11891192
1193+
call nvtxEndRange
1194+
11901195
end subroutine s_compute_ib_forces
11911196
11921197
!> Subroutine to deallocate memory reserved for the IBM module

0 commit comments

Comments
 (0)