Skip to content

Commit 8681b59

Browse files
Further model space reduction to improve search
1 parent faaa0a7 commit 8681b59

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

src/common/m_model.fpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ contains
598598
real(wp) :: fraction
599599
type(t_ray) :: ray
600600
type(t_triangle) :: tri
601-
integer :: i, j, k, q, nInOrOut, nHits
601+
integer :: i, j, k, q, nInOrOut, nHits, spc
602602

603603
! cast 26 rays from the point and count the number at leave the boundary
604604
nInOrOut = 0

src/simulation/m_ib_patches.fpp

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,10 @@ contains
890890
real(wp) :: eta, threshold, corner_distance
891891
real(wp), dimension(1:3) :: point, local_point, offset
892892
real(wp), dimension(1:3) :: center, xyz_local
893-
real(wp), dimension(1:3, 1:3) :: inverse_rotation
893+
real(wp), dimension(1:3, 1:3) :: inverse_rotation, rotation
894+
integer :: cx, cy, cz
895+
real(wp) :: lx(2), ly(2), lz(2)
896+
real(wp), dimension(1:3) :: bbox_min, bbox_max, local_corner, world_corner
894897
895898
center = 0._wp
896899
center(1) = patch_ib(patch_id)%x_centroid
@@ -900,21 +903,45 @@ contains
900903
offset(:) = patch_ib(patch_id)%centroid_offset(:)
901904
spc = patch_ib(patch_id)%model_spc
902905
threshold = patch_ib(patch_id)%model_threshold
906+
rotation(:, :) = patch_ib(patch_id)%rotation_matrix(:, :)
903907
904908
il = -gp_layers
905909
jl = -gp_layers
906910
kl = -gp_layers
907911
ir = m + gp_layers
908912
jr = n + gp_layers
909913
kr = p + gp_layers
910-
corner_distance = 0._wp
911-
do i = 1, 3
912-
corner_distance = corner_distance + maxval(abs(stl_bounding_boxes(patch_id, i, 1:3)))**2 ! distance to rim of cylinder
914+
915+
! Local-space bounding box extents (min=1, max=2 in the third index)
916+
lx(1) = stl_bounding_boxes(patch_id, 1, 1) + offset(1)
917+
lx(2) = stl_bounding_boxes(patch_id, 1, 3) + offset(1)
918+
ly(1) = stl_bounding_boxes(patch_id, 2, 1) + offset(2)
919+
ly(2) = stl_bounding_boxes(patch_id, 2, 3) + offset(2)
920+
lz(1) = stl_bounding_boxes(patch_id, 3, 1) + offset(3)
921+
lz(2) = stl_bounding_boxes(patch_id, 3, 3) + offset(3)
922+
923+
bbox_min = 1e12
924+
bbox_max = -1e12
925+
! Enumerate all 8 corners of the local bounding box,
926+
! rotate to world space, track world-space AABB
927+
do cx = 1, 2
928+
do cy = 1, 2
929+
do cz = 1, 2
930+
local_corner = [lx(cx), ly(cy), lz(cz)]
931+
world_corner = matmul(rotation, local_corner) + center
932+
bbox_min(1) = min(bbox_min(1), world_corner(1))
933+
bbox_min(2) = min(bbox_min(2), world_corner(2))
934+
bbox_min(3) = min(bbox_min(3), world_corner(3))
935+
bbox_max(1) = max(bbox_max(1), world_corner(1))
936+
bbox_max(2) = max(bbox_max(2), world_corner(2))
937+
bbox_max(3) = max(bbox_max(3), world_corner(3))
938+
end do
939+
end do
913940
end do
914-
corner_distance = sqrt(corner_distance)
915-
call get_bounding_indices(center(1) - corner_distance, center(1) + corner_distance, x_cc, il, ir)
916-
call get_bounding_indices(center(2) - corner_distance, center(2) + corner_distance, y_cc, jl, jr)
917-
call get_bounding_indices(center(3) - corner_distance, center(3) + corner_distance, z_cc, kl, kr)
941+
942+
call get_bounding_indices(bbox_min(1), bbox_max(1), x_cc, il, ir)
943+
call get_bounding_indices(bbox_min(2), bbox_max(2), y_cc, jl, jr)
944+
call get_bounding_indices(bbox_min(3), bbox_max(3), z_cc, kl, kr)
918945
919946
$:GPU_PARALLEL_LOOP(private='[i,j,k, xyz_local, eta]',&
920947
& copyin='[patch_id,center,inverse_rotation, offset, spc, threshold]', collapse=3)

0 commit comments

Comments
 (0)