@@ -445,7 +445,7 @@ contains
445445 type(integer_field), intent (inout ) :: ib_markers
446446
447447 real (wp) :: lz, z_max, z_min, f, ca_in, pa, ma, ta, xa, yt, xu, yu, xl, yl, xc, yc, dycdxc, sin_c, cos_c
448- integer :: i, j, k, l
448+ integer :: i, j, k, l, il, ir, jl, jr, ll, lr
449449 integer :: Np1, Np2
450450
451451 real (wp), dimension (1 :3 ) :: xyz_local, center, offset !< x, y, z coordinates in local IB frame
@@ -527,11 +527,23 @@ contains
527527 $:GPU_UPDATE(device= ' [airfoil_grid_l,airfoil_grid_u]' )
528528 end if
529529
530+ ! find the indices to the left and right of the IB in i, j, k
531+ il = - gp_layers
532+ jl = - gp_layers
533+ ll = - gp_layers
534+ ir = m + gp_layers
535+ jr = n + gp_layers
536+ lr = p + gp_layers
537+ ! maximum distance any marker can be from the center is the legnth of the airfoil
538+ call get_bounding_indices(center(1 ) - ca_in, center(1 ) + ca_in, x_cc, il, ir)
539+ call get_bounding_indices(center(2 ) - ca_in, center(2 ) + ca_in, y_cc, jl, jr)
540+ call get_bounding_indices(center(3 ) - ca_in, center(3 ) + ca_in, z_cc, ll, lr)
541+
530542 $:GPU_PARALLEL_LOOP(private= ' [i,j,l,xyz_local,k,f]' ,&
531543 & copyin= ' [patch_id,center,inverse_rotation,offset,ma,ca_in,airfoil_grid_u,airfoil_grid_l,z_min,z_max]' , collapse= 3 )
532- do l = - gp_layers, p + gp_layers
533- do j = - gp_layers, n + gp_layers
534- do i = - gp_layers, m + gp_layers
544+ do l = ll, lr
545+ do j = jl, jr
546+ do i = il, ir
535547 xyz_local = [x_cc(i) - center(1 ), y_cc(j) - center(2 ), z_cc(l) - center(3 )] ! get coordinate frame centered on IB
536548 xyz_local = matmul (inverse_rotation, xyz_local) ! rotate the frame into the IB' s coordinates
537549 xyz_local = xyz_local - offset ! airfoils are a patch that require a centroid offset
@@ -728,9 +740,10 @@ contains
728740 integer, intent(in) :: patch_id
729741 type(integer_field), intent(inout) :: ib_markers
730742
731- integer :: i, j, k !< Generic loop iterators
743+ integer :: i, j, k, ir, il, jr, jl, kr, kl !< Generic loop iterators
732744 real(wp), dimension(1:3) :: xyz_local, center, length !< x and y coordinates in local IB frame
733745 real(wp), dimension(1:3, 1:3) :: inverse_rotation
746+ real(wp) :: corner_distance
734747
735748 ! Transferring the cuboid' s centroid and length information
736749 center(1 ) = patch_ib(patch_id)%x_centroid
@@ -741,15 +754,27 @@ contains
741754 length(3 ) = patch_ib(patch_id)%length_z
742755 inverse_rotation(:, :) = patch_ib(patch_id)%rotation_matrix_inverse(:, :)
743756
757+ ! find the indices to the left and right of the IB in i, j, k
758+ il = - gp_layers
759+ jl = - gp_layers
760+ kl = - gp_layers
761+ ir = m + gp_layers
762+ jr = n + gp_layers
763+ kr = p + gp_layers
764+ corner_distance = sqrt (dot_product (length, length))/ 2._wp ! maximum distance any marker can be from the center
765+ call get_bounding_indices(center(1 ) - corner_distance, center(1 ) + corner_distance, x_cc, il, ir)
766+ call get_bounding_indices(center(2 ) - corner_distance, center(2 ) + corner_distance, y_cc, jl, jr)
767+ call get_bounding_indices(center(3 ) - corner_distance, center(3 ) + corner_distance, z_cc, kl, kr)
768+
744769 ! Checking whether the cuboid covers a particular cell in the domain
745770 ! and verifying whether the current patch has permission to write to
746771 ! to that cell. If both queries check out , the primitive variables
747772 ! of the current patch are assigned to this cell.
748773 $:GPU_PARALLEL_LOOP(private= ' [i,j,k,xyz_local,cart_y,cart_z]' ,&
749774 & copyin= ' [patch_id,center,length,inverse_rotation]' , collapse= 3 )
750- do k = - gp_layers, p + gp_layers
751- do j = - gp_layers, n + gp_layers
752- do i = - gp_layers, m + gp_layers
775+ do k = kl, kr
776+ do j = jl, jr
777+ do i = il, ir
753778
754779 if (grid_geometry == 3 ) then
755780 ! TODO :: This does not work and is not covered by any tests. This should be fixed
@@ -794,10 +819,11 @@ contains
794819 integer , intent (in ) :: patch_id
795820 type(integer_field), intent (inout ) :: ib_markers
796821
797- integer :: i, j, k !< Generic loop iterators
822+ integer :: i, j, k, il, ir, jl, jr, kl, kr !< Generic loop iterators
798823 real (wp) :: radius
799824 real (wp), dimension (1 :3 ) :: xyz_local, center, length !< x and y coordinates in local IB frame
800825 real (wp), dimension (1 :3 , 1 :3 ) :: inverse_rotation
826+ real (wp) :: corner_distance
801827
802828 ! Transferring the cylindrical patch' s centroid, length, radius,
803829 ! smoothing patch identity and smoothing coefficient information
@@ -811,6 +837,17 @@ contains
811837 radius = patch_ib(patch_id)%radius
812838 inverse_rotation(:, :) = patch_ib(patch_id)%rotation_matrix_inverse(:, :)
813839
840+ il = -gp_layers
841+ jl = -gp_layers
842+ kl = -gp_layers
843+ ir = m + gp_layers
844+ jr = n + gp_layers
845+ kr = p + gp_layers
846+ corner_distance = sqrt(radius**2 + maxval(length)**2) ! distance to rim of cylinder
847+ call get_bounding_indices(center(1) - corner_distance, center(1) + corner_distance, x_cc, il, ir)
848+ call get_bounding_indices(center(2) - corner_distance, center(2) + corner_distance, y_cc, jl, jr)
849+ call get_bounding_indices(center(3) - corner_distance, center(3) + corner_distance, z_cc, kl, kr)
850+
814851 ! Checking whether the cylinder covers a particular cell in the
815852 ! domain and verifying whether the current patch has the permission
816853 ! to write to that cell. If both queries check out, the primitive
0 commit comments