@@ -24,7 +24,8 @@ module m_compute_levelset
2424 s_rectangle_levelset, &
2525 s_cuboid_levelset, &
2626 s_sphere_levelset, &
27- s_ellipse_levelset
27+ s_ellipse_levelset, &
28+ s_periodic_project_center
2829
2930contains
3031
@@ -47,21 +48,10 @@ contains
4748 center(1 , 1 ) = patch_ib(ib_patch_id)%x_centroid
4849 center(2 , 1 ) = patch_ib(ib_patch_id)%y_centroid
4950
50- if (periodic_ibs) then ! periodically wrap spheres around domain
51- if ((center(1 , 1 ) - domain_glb(1 , 1 )) <= radius) then
52- center(1 , 2 ) = domain_glb(1 , 2 ) + (center(1 , 1 ) - domain_glb(1 , 1 ))
53- else if ((domain_glb(1 , 2 ) - center(1 , 1 )) <= radius) then
54- center(1 , 2 ) = domain_glb(1 , 1 ) - (domain_glb(1 , 2 ) - center(1 , 1 ))
55- else
56- center(1 , 2 ) = center(1 , 1 )
57- end if
58- if ((center(2 , 1 ) - domain_glb(2 , 1 )) <= radius) then
59- center(2 , 2 ) = domain_glb(2 , 2 ) + (center(2 , 1 ) - domain_glb(2 , 1 ))
60- else if ((domain_glb(2 , 2 ) - center(2 , 1 )) <= radius) then
61- center(2 , 2 ) = domain_glb(2 , 1 ) - (domain_glb(2 , 2 ) - center(2 , 1 ))
62- else
63- center(2 , 2 ) = center(2 , 1 )
64- end if
51+ if (periodic_ibs) then ! periodically wrap circles around domain
52+ do i = 1 , 2
53+ call s_periodic_project_center(center(i, :), domain_glb(i, :), radius)
54+ end do
6555 end if
6656
6757 $:GPU_PARALLEL_LOOP(private= ' [i,j,ix,iy,dist_vec,dist,dist_vec_temp,dist_temp]' , &
@@ -71,22 +61,23 @@ contains
7161 dist_vec(1 ) = x_cc(i) - center(1 , 1 )
7262 dist_vec(2 ) = y_cc(j) - center(2 , 1 )
7363 dist_vec(3 ) = 0._wp
74- dist = sqrt ( sum (dist_vec** 2 ) )
64+ dist = sum (dist_vec** 2 )
7565 if (periodic_ibs) then
7666 ! check all permutations of periodically projected ib to find minimum distance
7767 do ix = 1 , 2
7868 do iy = 1 , 2
7969 dist_vec_temp(1 ) = x_cc(i) - center(1 , ix)
8070 dist_vec_temp(2 ) = y_cc(j) - center(2 , iy)
8171 dist_vec_temp(3 ) = 0._wp
82- dist_temp = sqrt ( sum (dist_vec_temp** 2 ) )
72+ dist_temp = sum (dist_vec_temp** 2 )
8373 if (dist_temp < dist) then
8474 dist = dist_temp
8575 dist_vec = dist_vec_temp
8676 end if
8777 end do
8878 end do
8979 end if
80+ dist = sqrt (dist)
9081 levelset%sf(i, j, 0 , ib_patch_id) = dist - radius
9182 if (f_approx_equal(dist, 0._wp )) then
9283 levelset_norm%sf(i, j, 0 , ib_patch_id, :) = 0
@@ -558,27 +549,9 @@ contains
558549 center(3, 1) = patch_ib(ib_patch_id)%z_centroid
559550
560551 if (periodic_ibs) then ! periodically wrap spheres around domain
561- if ((center(1, 1) - domain_glb(1, 1)) <= radius) then
562- center(1, 2) = domain_glb(1, 2) + (center(1, 1) - domain_glb(1, 1))
563- else if ((domain_glb(1, 2) - center(1, 1)) <= radius) then
564- center(1, 2) = domain_glb(1, 1) - (domain_glb(1, 2) - center(1, 1))
565- else
566- center(1, 2) = center(1, 1)
567- end if
568- if ((center(2, 1) - domain_glb(2, 1)) <= radius) then
569- center(2, 2) = domain_glb(2, 2) + (center(2, 1) - domain_glb(2, 1))
570- else if ((domain_glb(2, 2) - center(2, 1)) <= radius) then
571- center(2, 2) = domain_glb(2, 1) - (domain_glb(2, 2) - center(2, 1))
572- else
573- center(2, 2) = center(2, 1)
574- end if
575- if ((center(3, 1) - domain_glb(3, 1)) <= radius) then
576- center(3, 2) = domain_glb(3, 2) + (center(3, 1) - domain_glb(3, 1))
577- else if ((domain_glb(3, 2) - center(3, 1)) <= radius) then
578- center(3, 2) = domain_glb(3, 1) - (domain_glb(3, 2) - center(3, 1))
579- else
580- center(3, 2) = center(3, 1)
581- end if
552+ do i = 1, 3
553+ call s_periodic_project_center(center(i, :), domain_glb(i, :), radius)
554+ end do
582555 end if
583556
584557 $:GPU_PARALLEL_LOOP(private=' [i,j,k,ix,iy,iz,dist_vec,dist,dist_vec_temp,dist_temp]' , &
@@ -589,7 +562,7 @@ contains
589562 dist_vec(1) = x_cc(i) - center(1, 1)
590563 dist_vec(2) = y_cc(j) - center(2, 1)
591564 dist_vec(3) = z_cc(k) - center(3, 1)
592- dist = sqrt( sum(dist_vec**2) )
565+ dist = sum(dist_vec**2)
593566 if (periodic_ibs) then
594567 ! check all permutations of periodically projected ib to find minimum distance
595568 do ix = 1, 2
@@ -598,7 +571,7 @@ contains
598571 dist_vec_temp(1) = x_cc(i) - center(1, ix)
599572 dist_vec_temp(2) = y_cc(j) - center(2, iy)
600573 dist_vec_temp(3) = z_cc(k) - center(3, iz)
601- dist_temp = sqrt( sum(dist_vec_temp**2) )
574+ dist_temp = sum(dist_vec_temp**2)
602575 if (dist_temp < dist) then
603576 dist = dist_temp
604577 dist_vec = dist_vec_temp
@@ -607,6 +580,7 @@ contains
607580 end do
608581 end do
609582 end if
583+ dist = sqrt(dist)
610584 levelset%sf(i, j, k, ib_patch_id) = dist - radius
611585 if (f_approx_equal(dist, 0._wp)) then
612586 levelset_norm%sf(i, j, k, ib_patch_id, :) = (/1, 0, 0/)
@@ -700,4 +674,19 @@ contains
700674
701675 end subroutine s_cylinder_levelset
702676
677+ subroutine s_periodic_project_center (center , domain_glb , radius )
678+ real (wp), dimension (2 ), intent (inout ) :: center
679+ real (wp), dimension (2 ), intent (in ) :: domain_glb
680+ real (wp), intent (in ) :: radius
681+
682+ if ((center(1 ) - domain_glb(1 )) <= radius) then
683+ center(2 ) = domain_glb(2 ) + (center(1 ) - domain_glb(1 ))
684+ else if ((domain_glb(2 ) - center(1 )) <= radius) then
685+ center(2 ) = domain_glb(1 ) - (domain_glb(2 ) - center(1 ))
686+ else
687+ center(2 ) = center(1 )
688+ end if
689+
690+ end subroutine s_periodic_project_center
691+
703692end module m_compute_levelset
0 commit comments