@@ -459,11 +459,14 @@ contains
459459 real(wp) :: radius
460460 real(wp) :: x_centroid, y_centroid, z_centroid
461461 real(wp) :: length_x, length_y, length_z
462- real(wp), dimension(3) :: pos_vec, centroid_vec, dist_sides_vec, dist_surface_vec
462+ real(wp), dimension(3) :: centroid_vec, dist_sides_vec, dist_surface_vec
463463 real(wp) :: dist_side, dist_surface, side_pos
464464 type(bounds_info) :: boundary
465465 integer :: i, j, k !< Loop index variables
466466
467+ real(wp), dimension(1:3) :: xyz_local !< x and y coordinates in local IB frame
468+ real(wp), dimension(1:3, 1:3) :: rotation, inverse_rotation
469+
467470 radius = patch_ib(ib_patch_id)%radius
468471 x_centroid = patch_ib(ib_patch_id)%x_centroid
469472 y_centroid = patch_ib(ib_patch_id)%y_centroid
@@ -472,36 +475,42 @@ contains
472475 length_y = patch_ib(ib_patch_id)%length_y
473476 length_z = patch_ib(ib_patch_id)%length_z
474477
478+ inverse_rotation(:, :) = patch_ib(ib_patch_id)%rotation_matrix_inverse(:, :)
479+ rotation(:, :) = patch_ib(ib_patch_id)%rotation_matrix(:, :)
480+
475481 if (.not. f_approx_equal(length_x, 0._wp)) then
476- boundary%beg = x_centroid - 0.5_wp*length_x
477- boundary%end = x_centroid + 0.5_wp*length_x
482+ boundary%beg = - 0.5_wp*length_x
483+ boundary%end = 0.5_wp*length_x
478484 dist_sides_vec = (/1, 0, 0/)
479485 dist_surface_vec = (/0, 1, 1/)
480486 else if (.not. f_approx_equal(length_y, 0._wp)) then
481- boundary%beg = y_centroid - 0.5_wp*length_y
482- boundary%end = y_centroid + 0.5_wp*length_y
487+ boundary%beg = - 0.5_wp*length_y
488+ boundary%end = 0.5_wp*length_y
483489 dist_sides_vec = (/0, 1, 0/)
484490 dist_surface_vec = (/1, 0, 1/)
485491 else if (.not. f_approx_equal(length_z, 0._wp)) then
486- boundary%beg = z_centroid - 0.5_wp*length_z
487- boundary%end = z_centroid + 0.5_wp*length_z
492+ boundary%beg = - 0.5_wp*length_z
493+ boundary%end = 0.5_wp*length_z
488494 dist_sides_vec = (/0, 0, 1/)
489495 dist_surface_vec = (/1, 1, 0/)
490496 end if
491497
492498 do i = 0, m
493499 do j = 0, n
494500 do k = 0, p
495- pos_vec = [x_cc(i), y_cc(j), z_cc(k)]
496- centroid_vec = [x_centroid, y_centroid, z_centroid]
497- side_pos = dot_product(pos_vec, dist_sides_vec)
501+ xyz_local = [x_cc(i) - x_centroid, cart_y - y_centroid, cart_z - z_centroid] ! get coordinate frame centered on IB
502+ xyz_local = matmul(inverse_rotation, xyz_local) ! rotate the frame into the IB' s coordiantes
503+
504+ ! get distance to flat edge of cylinder
505+ side_pos = dot_product (xyz_local, dist_sides_vec)
498506 dist_side = min (abs (side_pos - boundary%beg), &
499507 abs (boundary%end - side_pos))
500-
501- dist_surface = norm2((pos_vec - centroid_vec) *dist_surface_vec) &
508+ ! get distance to curved side of cylinder
509+ dist_surface = norm2(xyz_local * dist_surface_vec) &
502510 - radius
503511
504512 if (dist_side < abs (dist_surface)) then
513+ ! if the closest edge is flat
505514 levelset%sf(i, j, k, ib_patch_id) = - dist_side
506515 if (f_approx_equal(dist_side, abs (side_pos - boundary%beg))) then
507516 levelset_norm%sf(i, j, k, ib_patch_id, :) = - dist_sides_vec
@@ -512,11 +521,13 @@ contains
512521 levelset%sf(i, j, k, ib_patch_id) = dist_surface
513522
514523 levelset_norm%sf(i, j, k, ib_patch_id, :) = &
515- (pos_vec - centroid_vec) *dist_surface_vec
524+ xyz_local * dist_surface_vec
516525 levelset_norm%sf(i, j, k, ib_patch_id, :) = &
517526 levelset_norm%sf(i, j, k, ib_patch_id, :)/ &
518527 norm2(levelset_norm%sf(i, j, k, ib_patch_id, :))
519528 end if
529+ levelset_norm%sf(i, j, k, ib_patch_id, :) = &
530+ matmul (rotation, levelset_norm%sf(i, j, k, ib_patch_id, :))
520531 end do
521532 end do
522533 end do
0 commit comments