Skip to content

Commit 007949d

Browse files
Updated patch_IB rotation values
1 parent ce5f071 commit 007949d

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

src/common/m_ib_patches.fpp

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,8 @@ contains
635635
integer, dimension(0:m, 0:n, 0:p), intent(inout) :: ib_markers_sf
636636
637637
integer :: i, j, k !< Generic loop iterators
638+
real(wp), dimension(1:3) :: xyz_local !< x and y coordinates in local IB frame
639+
real(wp), dimension(1:3, 1:3) :: inverse_rotation
638640
639641
! Transferring the cuboid's centroid and length information
640642
x_centroid = patch_ib(patch_id)%x_centroid
@@ -643,15 +645,16 @@ contains
643645
length_x = patch_ib(patch_id)%length_x
644646
length_y = patch_ib(patch_id)%length_y
645647
length_z = patch_ib(patch_id)%length_z
648+
inverse_rotation(:, :) = patch_ib(patch_id)%rotation_matrix_inverse(:, :)
646649

647650
! Computing the beginning and the end x-, y- and z-coordinates of
648651
! the cuboid based on its centroid and lengths
649-
x_boundary%beg = x_centroid - 0.5_wp*length_x
650-
x_boundary%end = x_centroid + 0.5_wp*length_x
651-
y_boundary%beg = y_centroid - 0.5_wp*length_y
652-
y_boundary%end = y_centroid + 0.5_wp*length_y
653-
z_boundary%beg = z_centroid - 0.5_wp*length_z
654-
z_boundary%end = z_centroid + 0.5_wp*length_z
652+
x_boundary%beg = -0.5_wp*length_x
653+
x_boundary%end = 0.5_wp*length_x
654+
y_boundary%beg = -0.5_wp*length_y
655+
y_boundary%end = 0.5_wp*length_y
656+
z_boundary%beg = -0.5_wp*length_z
657+
z_boundary%end = 0.5_wp*length_z
655658

656659
! Since the cuboidal patch does not allow for its boundaries to get
657660
! smoothed out, the pseudo volume fraction is set to 1 to make sure
@@ -668,18 +671,21 @@ contains
668671
do i = 0, m
669672

670673
if (grid_geometry == 3) then
674+
! TODO :: This does not work and is not covered by any tests. This should be fixed
671675
call s_convert_cylindrical_to_cartesian_coord(y_cc(j), z_cc(k))
672676
else
673677
cart_y = y_cc(j)
674678
cart_z = z_cc(k)
675679
end if
680+
xyz_local = [x_cc(i) - x_centroid, cart_y - y_centroid, cart_z - z_centroid] ! get coordinate frame centered on IB
681+
xyz_local = matmul(inverse_rotation, xy_local) ! rotate the frame into the IB's coordiantes
676682
677-
if (x_boundary%beg <= x_cc(i) .and. &
678-
x_boundary%end >= x_cc(i) .and. &
679-
y_boundary%beg <= cart_y .and. &
680-
y_boundary%end >= cart_y .and. &
681-
z_boundary%beg <= cart_z .and. &
682-
z_boundary%end >= cart_z) then
683+
if (x_boundary%beg <= xyz_local(1) .and. &
684+
x_boundary%end >= xyz_local(1) .and. &
685+
y_boundary%beg <= xyz_local(2) .and. &
686+
y_boundary%end >= xyz_local(2) .and. &
687+
z_boundary%beg <= xyz_local(3) .and. &
688+
z_boundary%end >= xyz_local(3)) then
683689
684690
! Updating the patch identities bookkeeping variable
685691
ib_markers_sf(i, j, k) = patch_id
@@ -748,24 +754,26 @@ contains
748754
cart_y = y_cc(j)
749755
cart_z = z_cc(k)
750756
end if
757+
xyz_local = [x_cc(i) - x_centroid, cart_y - y_centroid, cart_z - z_centroid] ! get coordinate frame centered on IB
758+
xyz_local = matmul(inverse_rotation, xy_local) ! rotate the frame into the IB's coordiantes
751759
752760
if (((.not. f_is_default(length_x) .and. &
753-
(cart_y - y_centroid)**2 &
754-
+ (cart_z - z_centroid)**2 <= radius**2 .and. &
755-
x_boundary%beg <= x_cc(i) .and. &
756-
x_boundary%end >= x_cc(i)) &
761+
xyz_local(2)**2 &
762+
+ xyz_local(3)**2 <= radius**2 .and. &
763+
x_boundary%beg <= xyz_local(1) .and. &
764+
x_boundary%end >= xyz_local(1)) &
757765
.or. &
758766
(.not. f_is_default(length_y) .and. &
759-
(x_cc(i) - x_centroid)**2 &
760-
+ (cart_z - z_centroid)**2 <= radius**2 .and. &
761-
y_boundary%beg <= cart_y .and. &
762-
y_boundary%end >= cart_y) &
767+
xyz_local(1)**2 &
768+
+ xyz_local(3)**2 <= radius**2 .and. &
769+
y_boundary%beg <= xyz_local(2) .and. &
770+
y_boundary%end >= xyz_local(2)) &
763771
.or. &
764772
(.not. f_is_default(length_z) .and. &
765-
(x_cc(i) - x_centroid)**2 &
766-
+ (cart_y - y_centroid)**2 <= radius**2 .and. &
767-
z_boundary%beg <= cart_z .and. &
768-
z_boundary%end >= cart_z))) then
773+
xyz_local(1)**2 &
774+
+ xyz_local(2)**2 <= radius**2 .and. &
775+
z_boundary%beg <= xyz_local(3) .and. &
776+
z_boundary%end >= xyz_local(3)))) then
769777
770778
! Updating the patch identities bookkeeping variable
771779
ib_markers_sf(i, j, k) = patch_id

0 commit comments

Comments
 (0)