@@ -34,21 +34,23 @@ contains
3434 integer , intent (IN ) :: ib_patch_id
3535
3636 real (wp) :: radius, dist
37- real (wp) :: x_centroid, y_centroid
37+ real (wp), dimension ( 2 ) :: center
3838 real (wp), dimension (3 ) :: dist_vec
3939
4040 integer :: i, j !< Loop index variables
4141
4242 radius = patch_ib(ib_patch_id)%radius
43- x_centroid = patch_ib(ib_patch_id)%x_centroid
44- y_centroid = patch_ib(ib_patch_id)%y_centroid
43+ center( 1 ) = patch_ib(ib_patch_id)%x_centroid
44+ center( 2 ) = patch_ib(ib_patch_id)%y_centroid
4545
46+ $:GPU_PARALLEL_LOOP(private= ' [i,j,dist_vec,dist]' , copy= ' [levelset,levelset_norm]' ,&
47+ & copyin= ' [ib_patch_id,center,radius]' , collapse= 2 )
4648 do i = 0 , m
4749 do j = 0 , n
4850
49- dist_vec(1 ) = x_cc(i) - x_centroid
50- dist_vec(2 ) = y_cc(j) - y_centroid
51- dist_vec(3 ) = 0
51+ dist_vec(1 ) = x_cc(i) - center( 1 )
52+ dist_vec(2 ) = y_cc(j) - center( 2 )
53+ dist_vec(3 ) = 0._wp
5254 dist = sqrt (sum (dist_vec** 2 ))
5355 levelset%sf(i, j, 0 , ib_patch_id) = dist - radius
5456 if (f_approx_equal(dist, 0._wp )) then
@@ -156,31 +158,33 @@ contains
156158
157159 real(wp) :: dist, dist_surf, dist_side, global_dist
158160 integer :: global_id
159- real(wp) :: x_centroid, y_centroid, z_centroid, lz, z_max, z_min
161+ real(wp) :: lz, z_max, z_min
160162 real(wp), dimension(3) :: dist_vec
161163
162- real(wp), dimension(1:3) :: xyz_local !< x, y, z coordinates in local IB frame
164+ real(wp), dimension(1:3) :: xyz_local, center !< x, y, z coordinates in local IB frame
163165 real(wp), dimension(1:3, 1:3) :: rotation, inverse_rotation
164166
165167 real(wp) :: length_z
166168
167169 integer :: i, j, k, l !< Loop index variables
168170
169- x_centroid = patch_ib(ib_patch_id)%x_centroid
170- y_centroid = patch_ib(ib_patch_id)%y_centroid
171- z_centroid = patch_ib(ib_patch_id)%z_centroid
171+ center(1) = patch_ib(ib_patch_id)%x_centroid
172+ center(2) = patch_ib(ib_patch_id)%y_centroid
173+ center(3) = patch_ib(ib_patch_id)%z_centroid
172174 lz = patch_ib(ib_patch_id)%length_z
173175 inverse_rotation(:, :) = patch_ib(ib_patch_id)%rotation_matrix_inverse(:, :)
174176 rotation(:, :) = patch_ib(ib_patch_id)%rotation_matrix(:, :)
175177
176- z_max = z_centroid + lz/2
177- z_min = z_centroid - lz/2
178+ z_max = center(3) + lz/2
179+ z_min = center(3) - lz/2
178180
181+ $:GPU_PARALLEL_LOOP(private=' [i,j,l,xyz_local,k,dist_vec,dist,global_dist,global_id,dist_side,dist_surf]' , copy=' [levelset,levelset_norm]' ,&
182+ & copyin=' [ib_patch_id,center,rotation,inverse_rotation,airfoil_grid_u,airfoil_grid_l,z_min,z_max]' , collapse=3)
179183 do l = 0, p
180184 do j = 0, n
181185 do i = 0, m
182186
183- xyz_local = [x_cc(i) - x_centroid , y_cc(j) - y_centroid , z_cc(l) - z_centroid ] ! get coordinate frame centered on IB
187+ xyz_local = [x_cc(i) - center(1) , y_cc(j) - center(2) , z_cc(l) - center(3) ] ! get coordinate frame centered on IB
184188 xyz_local = matmul(inverse_rotation, xyz_local) ! rotate the frame into the IB' s coordinates
185189
186190 if (xyz_local(2 ) >= y_centroid) then
@@ -263,18 +267,18 @@ contains
263267 real (wp) :: min_dist
264268 real (wp) :: side_dists(4 )
265269
266- real (wp) :: x_centroid, y_centroid
267270 real (wp) :: length_x, length_y
268271 real (wp), dimension (1 :3 ) :: xy_local !< x and y coordinates in local IB frame
272+ real (wp), dimension (2 ) :: center !< x and y coordinates in local IB frame
269273 real (wp), dimension (1 :3 , 1 :3 ) :: rotation, inverse_rotation
270274
271275 integer :: i, j, k !< Loop index variables
272276 integer :: idx !< Shortest path direction indicator
273277
274278 length_x = patch_ib(ib_patch_id)%length_x
275279 length_y = patch_ib(ib_patch_id)%length_y
276- x_centroid = patch_ib(ib_patch_id)%x_centroid
277- y_centroid = patch_ib(ib_patch_id)%y_centroid
280+ center( 1 ) = patch_ib(ib_patch_id)%x_centroid
281+ center( 2 ) = patch_ib(ib_patch_id)%y_centroid
278282 inverse_rotation(:, :) = patch_ib(ib_patch_id)%rotation_matrix_inverse(:, :)
279283 rotation(:, :) = patch_ib(ib_patch_id)%rotation_matrix(:, :)
280284
@@ -283,9 +287,11 @@ contains
283287 bottom_left(1 ) = - length_x/ 2
284288 bottom_left(2 ) = - length_y/ 2
285289
290+ $:GPU_PARALLEL_LOOP(private= ' [i,j,k,min_dist,idx,side_dists,xy_local]' , copy= ' [levelset,levelset_norm]' ,&
291+ & copyin= ' [ib_patch_id,center,bottom_left,top_right,initial_distance_buffer,inverse_rotation,rotation]' , collapse= 2 )
286292 do i = 0 , m
287293 do j = 0 , n
288- xy_local = [x_cc(i) - x_centroid , y_cc(j) - y_centroid , 0._wp ]
294+ xy_local = [x_cc(i) - center( 1 ) , y_cc(j) - center( 2 ) , 0._wp ]
289295 xy_local = matmul (inverse_rotation, xy_local)
290296
291297 if ((xy_local(1 ) > bottom_left(1 ) .and. xy_local(1 ) < top_right(1 )) .or. &
@@ -336,41 +342,41 @@ contains
336342
337343 integer , intent (IN ) :: ib_patch_id
338344 real (wp) :: Right, Left, Bottom, Top, Front, Back
339- real (wp) :: x, y, z, min_dist
345+ real (wp) :: min_dist
340346 real (wp) :: side_dists(6 )
341347
342- real (wp) :: x_centroid, y_centroid, z_centroid
348+ real (wp), dimension ( 3 ) :: center
343349 real (wp) :: length_x, length_y, length_z
344350 real (wp), dimension (1 :3 ) :: xyz_local !< x and y coordinates in local IB frame
345351 real (wp), dimension (1 :3 , 1 :3 ) :: rotation, inverse_rotation
346352
347- integer :: i, j, k, l, idx !< Loop index variables
353+ integer :: i, j, k !< Loop index variables
348354
349355 length_x = patch_ib(ib_patch_id)%length_x
350356 length_y = patch_ib(ib_patch_id)%length_y
351357 length_z = patch_ib(ib_patch_id)%length_z
352358
353- x_centroid = patch_ib(ib_patch_id)%x_centroid
354- y_centroid = patch_ib(ib_patch_id)%y_centroid
355- z_centroid = patch_ib(ib_patch_id)%z_centroid
359+ center( 1 ) = patch_ib(ib_patch_id)%x_centroid
360+ center( 2 ) = patch_ib(ib_patch_id)%y_centroid
361+ center( 3 ) = patch_ib(ib_patch_id)%z_centroid
356362
357363 inverse_rotation(:, :) = patch_ib(ib_patch_id)%rotation_matrix_inverse(:, :)
358364 rotation(:, :) = patch_ib(ib_patch_id)%rotation_matrix(:, :)
359365
360366 Right = length_x/ 2
361367 Left = - length_x/ 2
362-
363368 Top = length_y/ 2
364369 Bottom = - length_y/ 2
365-
366370 Front = length_z/ 2
367371 Back = - length_z/ 2
368372
373+ $:GPU_PARALLEL_LOOP(private= ' [i,j,k,min_dist,side_dists,xyz_local]' , copy= ' [levelset,levelset_norm]' ,&
374+ & copyin= ' [ib_patch_id,center,inverse_rotation,rotation,Right,Left,Top,Bottom,Front,Back]' , collapse= 3 )
369375 do i = 0 , m
370376 do j = 0 , n
371377 do k = 0 , p
372378
373- xyz_local = [x_cc(i) - x_centroid , y_cc(j) - y_centroid , z_cc(k) - z_centroid] ! get coordinate frame centered on IB
379+ xyz_local = [x_cc(i), y_cc(j), z_cc(k)] - center ! get coordinate frame centered on IB
374380 xyz_local = matmul (inverse_rotation, xyz_local) ! rotate the frame into the IB' s coordinate
375381
376382 if ((xyz_local(1) > Left .and. xyz_local(1) < Right) .or. &
@@ -390,8 +396,8 @@ contains
390396 ! meaning corners where side_dists are the same will
391397 ! trigger on what may not actually be the minimum,
392398 ! leading to undesired behavior. This should be resolved
393- ! and this code should be cleaned up. I verified this behavior
394- ! with tests.
399+ ! and this code should be cleaned up. It also means that
400+ ! rotating the box 90 degrees will cause tests to fail .
395401 levelset_norm%sf(i, j, k, ib_patch_id, :) = 0._wp
396402 if (f_approx_equal(min_dist, abs(side_dists(1)))) then
397403 levelset%sf(i, j, k, ib_patch_id) = side_dists(1)
0 commit comments