@@ -437,7 +437,7 @@ contains
437437
438438 real (wp) :: Right, Left, Bottom, Top, Front, Back
439439 real (wp) :: min_dist
440- real (wp) :: side_dists( 6 )
440+ real (wp) :: dist_left, dist_right, dist_bottom, dist_top, dist_back, dist_front
441441
442442 real (wp), dimension (3 ) :: center
443443 real (wp) :: length_x, length_y, length_z
@@ -473,13 +473,15 @@ contains
473473 xyz_local = [x_cc(i), y_cc(j), z_cc(k)] - center ! get coordinate frame centered on IB
474474 xyz_local = matmul (inverse_rotation, xyz_local) ! rotate the frame into the IB' s coordinate
475475
476- side_dists(1) = Left - xyz_local(1)
477- side_dists(2) = xyz_local(1) - Right
478- side_dists(3) = Bottom - xyz_local(2)
479- side_dists(4) = xyz_local(2) - Top
480- side_dists(5) = Back - xyz_local(3)
481- side_dists(6) = xyz_local(3) - Front
482- min_dist = minval(abs(side_dists))
476+ dist_left = Left - xyz_local(1)
477+ dist_right = xyz_local(1) - Right
478+ dist_bottom = Bottom - xyz_local(2)
479+ dist_top = xyz_local(2) - Top
480+ dist_back = Back - xyz_local(3)
481+ dist_front = xyz_local(3) - Front
482+
483+ min_dist = min(abs(dist_left), abs(dist_right), abs(dist_bottom), &
484+ abs(dist_top), abs(dist_back), abs(dist_front))
483485
484486 ! TODO :: The way that this is written, it looks like we will
485487 ! trigger at the first size that is close to the minimum distance,
@@ -488,43 +490,41 @@ contains
488490 ! leading to undesired behavior. This should be resolved
489491 ! and this code should be cleaned up. It also means that
490492 ! rotating the box 90 degrees will cause tests to fail.
493+
491494 dist_vec = 0._wp
492- if (f_approx_equal(min_dist, abs(side_dists(1)))) then
493- gp%levelset = side_dists(1)
494- if (.not. f_approx_equal(side_dists(1), 0._wp)) then
495- dist_vec(1) = side_dists(1)/abs(side_dists(1))
496- end if
497495
498- else if (f_approx_equal(min_dist, abs(side_dists(2) ))) then
499- gp%levelset = side_dists(2)
500- if (.not. f_approx_equal(side_dists(2) , 0._wp)) then
501- dist_vec(1) = -side_dists(2) /abs(side_dists(2) )
496+ if (f_approx_equal(min_dist, abs(dist_left ))) then
497+ gp%levelset = dist_left
498+ if (.not. f_approx_equal(dist_left , 0._wp)) then
499+ dist_vec(1) = dist_left /abs(dist_left )
502500 end if
503-
504- else if (f_approx_equal(min_dist, abs(side_dists(3)))) then
505- gp%levelset = side_dists(3)
506- if (.not. f_approx_equal(side_dists(3), 0._wp)) then
507- dist_vec(2) = side_dists(3)/abs(side_dists(3))
501+ else if (f_approx_equal(min_dist, abs(dist_right))) then
502+ gp%levelset = dist_right
503+ if (.not. f_approx_equal(dist_right, 0._wp)) then
504+ dist_vec(1) = -dist_right/abs(dist_right)
508505 end if
509-
510- else if (f_approx_equal(min_dist, abs(side_dists(4)))) then
511- gp%levelset = side_dists(4)
512- if (.not. f_approx_equal(side_dists(4), 0._wp)) then
513- dist_vec(2) = -side_dists(4)/abs(side_dists(4))
506+ else if (f_approx_equal(min_dist, abs(dist_bottom))) then
507+ gp%levelset = dist_bottom
508+ if (.not. f_approx_equal(dist_bottom, 0._wp)) then
509+ dist_vec(2) = dist_bottom/abs(dist_bottom)
514510 end if
515-
516- else if (f_approx_equal(min_dist, abs(side_dists(5)))) then
517- gp%levelset = side_dists(5)
518- if (.not. f_approx_equal(side_dists(5), 0._wp)) then
519- dist_vec(3) = side_dists(5)/abs(side_dists(5))
511+ else if (f_approx_equal(min_dist, abs(dist_top))) then
512+ gp%levelset = dist_top
513+ if (.not. f_approx_equal(dist_top, 0._wp)) then
514+ dist_vec(2) = -dist_top/abs(dist_top)
520515 end if
521-
522- else if (f_approx_equal(min_dist, abs(side_dists(6)))) then
523- gp%levelset = side_dists(6)
524- if (.not. f_approx_equal(side_dists(6), 0._wp)) then
525- dist_vec(3) = -side_dists(6)/abs(side_dists(6))
516+ else if (f_approx_equal(min_dist, abs(dist_back))) then
517+ gp%levelset = dist_back
518+ if (.not. f_approx_equal(dist_back, 0._wp)) then
519+ dist_vec(3) = dist_back/abs(dist_back)
520+ end if
521+ else if (f_approx_equal(min_dist, abs(dist_front))) then
522+ gp%levelset = dist_front
523+ if (.not. f_approx_equal(dist_front, 0._wp)) then
524+ dist_vec(3) = -dist_front/abs(dist_front)
526525 end if
527526 end if
527+
528528 gp%levelset_norm = matmul(rotation, dist_vec)
529529
530530 end subroutine s_cuboid_levelset
0 commit comments