Skip to content

Commit 77c1432

Browse files
All levelsets updated for GPU compute
1 parent 240c588 commit 77c1432

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

src/common/m_compute_levelset.fpp

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -457,22 +457,23 @@ contains
457457
integer, intent(IN) :: ib_patch_id
458458
459459
real(wp) :: radius, dist
460-
real(wp) :: x_centroid, y_centroid, z_centroid
461-
real(wp), dimension(3) :: dist_vec
460+
real(wp), dimension(3) :: dist_vec, center
462461
463462
integer :: i, j, k !< Loop index variables
464463
465464
radius = patch_ib(ib_patch_id)%radius
466-
x_centroid = patch_ib(ib_patch_id)%x_centroid
467-
y_centroid = patch_ib(ib_patch_id)%y_centroid
468-
z_centroid = patch_ib(ib_patch_id)%z_centroid
465+
center(1) = patch_ib(ib_patch_id)%x_centroid
466+
center(2) = patch_ib(ib_patch_id)%y_centroid
467+
center(3) = patch_ib(ib_patch_id)%z_centroid
469468
469+
$:GPU_PARALLEL_LOOP(private='[i,j,k,dist_vec,dist]', copy='[levelset,levelset_norm]',&
470+
& copyin='[ib_patch_id,center,radius]', collapse=3)
470471
do i = 0, m
471472
do j = 0, n
472473
do k = 0, p
473-
dist_vec(1) = x_cc(i) - x_centroid
474-
dist_vec(2) = y_cc(j) - y_centroid
475-
dist_vec(3) = z_cc(k) - z_centroid
474+
dist_vec(1) = x_cc(i) - center(1)
475+
dist_vec(2) = y_cc(j) - center(2)
476+
dist_vec(3) = z_cc(k) - center(3)
476477
dist = sqrt(sum(dist_vec**2))
477478
levelset%sf(i, j, k, ib_patch_id) = dist - radius
478479
if (f_approx_equal(dist, 0._wp)) then
@@ -494,62 +495,62 @@ contains
494495
integer, intent(IN) :: ib_patch_id
495496
496497
real(wp) :: radius
497-
real(wp) :: x_centroid, y_centroid, z_centroid
498-
real(wp) :: length_x, length_y, length_z
499-
real(wp), dimension(3) :: centroid_vec, dist_sides_vec, dist_surface_vec
498+
real(wp), dimension(3) :: centroid_vec, dist_sides_vec, dist_surface_vec, length
499+
real(wp), dimension(2) :: boundary
500500
real(wp) :: dist_side, dist_surface, side_pos
501-
type(bounds_info) :: boundary
502501
integer :: i, j, k !< Loop index variables
503502
504-
real(wp), dimension(1:3) :: xyz_local !< x and y coordinates in local IB frame
503+
real(wp), dimension(1:3) :: xyz_local, center !< x and y coordinates in local IB frame
505504
real(wp), dimension(1:3, 1:3) :: rotation, inverse_rotation
506505
507506
radius = patch_ib(ib_patch_id)%radius
508-
x_centroid = patch_ib(ib_patch_id)%x_centroid
509-
y_centroid = patch_ib(ib_patch_id)%y_centroid
510-
z_centroid = patch_ib(ib_patch_id)%z_centroid
511-
length_x = patch_ib(ib_patch_id)%length_x
512-
length_y = patch_ib(ib_patch_id)%length_y
513-
length_z = patch_ib(ib_patch_id)%length_z
507+
center(1) = patch_ib(ib_patch_id)%x_centroid
508+
center(2) = patch_ib(ib_patch_id)%y_centroid
509+
center(3) = patch_ib(ib_patch_id)%z_centroid
510+
length(1) = patch_ib(ib_patch_id)%length_x
511+
length(2) = patch_ib(ib_patch_id)%length_y
512+
length(3) = patch_ib(ib_patch_id)%length_z
514513
515514
inverse_rotation(:, :) = patch_ib(ib_patch_id)%rotation_matrix_inverse(:, :)
516515
rotation(:, :) = patch_ib(ib_patch_id)%rotation_matrix(:, :)
517516
518517
if (.not. f_approx_equal(length_x, 0._wp)) then
519-
boundary%beg = -0.5_wp*length_x
520-
boundary%end = 0.5_wp*length_x
518+
boundary(1) = -0.5_wp*length(1)
519+
boundary(2) = 0.5_wp*length(1)
521520
dist_sides_vec = (/1, 0, 0/)
522521
dist_surface_vec = (/0, 1, 1/)
523522
else if (.not. f_approx_equal(length_y, 0._wp)) then
524-
boundary%beg = -0.5_wp*length_y
525-
boundary%end = 0.5_wp*length_y
523+
boundary(1) = -0.5_wp*length(2)
524+
boundary(2) = 0.5_wp*length(2)
526525
dist_sides_vec = (/0, 1, 0/)
527526
dist_surface_vec = (/1, 0, 1/)
528527
else if (.not. f_approx_equal(length_z, 0._wp)) then
529-
boundary%beg = -0.5_wp*length_z
530-
boundary%end = 0.5_wp*length_z
528+
boundary(1) = -0.5_wp*length(3)
529+
boundary(2) = 0.5_wp*length(3)
531530
dist_sides_vec = (/0, 0, 1/)
532531
dist_surface_vec = (/1, 1, 0/)
533532
end if
534533
534+
$:GPU_PARALLEL_LOOP(private='[i,j,k,dist_vec,side_pos,dist_side,dist_surface,xyz_local]', copy='[levelset,levelset_norm]',&
535+
& copyin='[ib_patch_id,center,radius,inverse_rotation,rotation,dist_sides_vec,dist_surface_vec]', collapse=3)
535536
do i = 0, m
536537
do j = 0, n
537538
do k = 0, p
538-
xyz_local = [x_cc(i) - x_centroid, y_cc(j) - y_centroid, z_cc(k) - z_centroid] ! get coordinate frame centered on IB
539+
xyz_local = [x_cc(i), y_cc(j), z_cc(k)] - center ! get coordinate frame centered on IB
539540
xyz_local = matmul(inverse_rotation, xyz_local) ! rotate the frame into the IB's coordinates
540541

541542
! get distance to flat edge of cylinder
542543
side_pos = dot_product(xyz_local, dist_sides_vec)
543-
dist_side = min(abs(side_pos - boundary%beg), &
544-
abs(boundary%end - side_pos))
544+
dist_side = min(abs(side_pos - boundary(1)), &
545+
abs(boundary(2) - side_pos))
545546
! get distance to curved side of cylinder
546547
dist_surface = norm2(xyz_local*dist_surface_vec) &
547548
- radius
548549

549550
if (dist_side < abs(dist_surface)) then
550551
! if the closest edge is flat
551552
levelset%sf(i, j, k, ib_patch_id) = -dist_side
552-
if (f_approx_equal(dist_side, abs(side_pos - boundary%beg))) then
553+
if (f_approx_equal(dist_side, abs(side_pos - boundary(1)))) then
553554
levelset_norm%sf(i, j, k, ib_patch_id, :) = -dist_sides_vec
554555
else
555556
levelset_norm%sf(i, j, k, ib_patch_id, :) = dist_sides_vec

0 commit comments

Comments
 (0)