Skip to content

Commit e80952b

Browse files
Ran test case and everything appears to be working
1 parent c04cfae commit e80952b

File tree

6 files changed

+58
-50
lines changed

6 files changed

+58
-50
lines changed

src/common/m_derived_types.fpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ module m_derived_types
296296
real(wp), dimension(1:3) :: angles
297297
real(wp), dimension(1:3) :: step_angles
298298
real(wp), dimension(1:3, 1:3) :: rotation_matrix !< matrix that converts from IB reference frame to fluid reference frame
299+
real(wp), dimension(1:3, 1:3) :: rotation_matrix_inverse !< matrix that converts from fluid reference frame to IB reference frame
299300

300301
real(wp) :: c, p, t, m
301302

src/common/m_ib_patches.fpp

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module m_ib_patches
2727

2828
implicit none
2929

30-
private; public :: s_apply_ib_patches
30+
private; public :: s_apply_ib_patches, s_update_ib_rotation_matrix
3131

3232
real(wp) :: x_centroid, y_centroid, z_centroid
3333
real(wp) :: length_x, length_y, length_z
@@ -546,7 +546,7 @@ contains
546546
do j = 0, n
547547
do i = 0, m
548548
! get the x and y coodinates in the local IB frame
549-
xy_local = [x_cc(i) - x_centroid, y_cc(j) - y_centroid]
549+
xy_local = [x_cc(i) - x_centroid, y_cc(j) - y_centroid, 0._wp]
550550
xy_local = matmul(inverse_rotation, xy_local)
551551
if (x_boundary%beg <= xy_local(1) .and. &
552552
x_boundary%end >= xy_local(1) .and. &
@@ -993,6 +993,51 @@ contains
993993
994994
end subroutine s_ib_model
995995
996+
!> Subroutine that computes a rotation matrix for converting to the rotating frame of the boundary
997+
subroutine s_update_ib_rotation_matrix(patch_id)
998+
999+
integer, intent(in) :: patch_id
1000+
integer :: i
1001+
1002+
real(wp), dimension(3, 3, 3) :: rotation
1003+
real(wp) :: angle
1004+
1005+
! construct the x, y, and z rotation matrices
1006+
if (num_dims == 3) then
1007+
! also compute the x and y axes in 3D
1008+
angle = patch_ib(patch_id)%angles(1)
1009+
rotation(1, 1, :) = [1._wp, 0._wp , 0._wp ]
1010+
rotation(1, 2, :) = [0._wp, cos(angle), -sin(angle)]
1011+
rotation(1, 3, :) = [0._wp, sin(angle), cos(angle) ]
1012+
1013+
angle = patch_ib(patch_id)%angles(2)
1014+
rotation(2, 1, :) = [cos(angle) , 0._wp, sin(angle)]
1015+
rotation(2, 2, :) = [0._wp , 1._wp, 0._wp ]
1016+
rotation(2, 3, :) = [-sin(angle), 0._wp, cos(angle)]
1017+
1018+
! apply the y rotation to the x rotation
1019+
patch_ib(patch_id)%rotation_matrix(:, :) = matmul(rotation(1, :, :), rotation(2, :, :))
1020+
patch_ib(patch_id)%rotation_matrix_inverse(:, :) = matmul(transpose(rotation(2, :, :)), transpose(rotation(1, :, :)))
1021+
end if
1022+
1023+
! z component first, since it applies in 2D and 3D
1024+
angle = patch_ib(patch_id)%angles(3)
1025+
rotation(3, 1, :) = [cos(angle), -sin(angle), 0._wp]
1026+
rotation(3, 2, :) = [sin(angle), cos(angle) , 0._wp]
1027+
rotation(3, 3, :) = [0._wp , 0._wp , 1._wp]
1028+
1029+
if (num_dims == 3) then
1030+
! apply the z rotation to the xy rotation in 3D
1031+
patch_ib(patch_id)%rotation_matrix(:, :) = matmul(patch_ib(patch_id)%rotation_matrix(:, :), rotation(3, :, :))
1032+
patch_ib(patch_id)%rotation_matrix_inverse(:, :) = matmul(transpose(rotation(3, :, :)), patch_ib(patch_id)%rotation_matrix_inverse(:, :))
1033+
else
1034+
! write out only the z rotation in 2D
1035+
patch_ib(patch_id)%rotation_matrix(:, :) = rotation(3, :, :)
1036+
patch_ib(patch_id)%rotation_matrix_inverse(:, :) = transpose(rotation(3, :, :))
1037+
end if
1038+
1039+
end subroutine s_update_ib_rotation_matrix
1040+
9961041
subroutine s_convert_cylindrical_to_cartesian_coord(cyl_y, cyl_z)
9971042
$:GPU_ROUTINE(parallelism='[seq]')
9981043

src/pre_process/m_global_parameters.fpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@ contains
550550
patch_ib(i)%rotation_matrix(1, 1) = 1._wp
551551
patch_ib(i)%rotation_matrix(2, 2) = 1._wp
552552
patch_ib(i)%rotation_matrix(3, 3) = 1._wp
553+
patch_ib(i)%rotation_matrix_inverse = patch_ib(i)%rotation_matrix
553554
end do
554555

555556
! Fluids physical parameters

src/pre_process/m_initial_condition.fpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ contains
180180
!! primitive variables are converted to conservative ones.
181181
impure subroutine s_generate_initial_condition
182182

183+
integer :: i
184+
183185
! Converting the conservative variables to the primitive ones given
184186
! preexisting initial condition data files were read in on start-up
185187
if (old_ic) then
@@ -190,6 +192,9 @@ contains
190192
end if
191193

192194
if (ib) then
195+
do i = 1, num_ibs
196+
! call s_update_ib_rotation_matrix(i)
197+
end do
193198
call s_apply_ib_patches(ib_markers%sf, levelset, levelset_norm)
194199
end if
195200
call s_apply_icpp_patches(patch_id_fp, q_prim_vf)

src/simulation/m_ibm.fpp

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -905,50 +905,6 @@ contains
905905

906906
end subroutine s_interpolate_image_point
907907

908-
!> Subroutine that computes a rotation matrix for converting to the rotating frame of the boundary
909-
impure subroutine s_update_ib_rotation_matrix(patch_id)
910-
911-
integer, intent(in) :: patch_id
912-
integer :: i
913-
914-
real(wp), dimension(3, 3, 3) :: rotation
915-
real(wp) :: angle
916-
917-
! construct the x, y, and z rotation matrices
918-
if (num_dims == 3) then
919-
! also compute the x and y axes in 3D
920-
angle = patch_ib(patch_id)%angles(1)
921-
rotation(1, 1, :) = [1._wp, 0._wp , 0._wp ]
922-
rotation(1, 2, :) = [0._wp, cos(angle), -sin(angle)]
923-
rotation(1, 3, :) = [0._wp, sin(angle), cos(angle) ]
924-
925-
angle = patch_ib(patch_id)%angles(2)
926-
rotation(2, 1, :) = [cos(angle) , 0._wp, sin(angle)]
927-
rotation(2, 2, :) = [0._wp , 1._wp, 0._wp ]
928-
rotation(2, 3, :) = [-sin(angle), 0._wp, cos(angle)]
929-
930-
! apply the y rotation to the x rotation
931-
patch_ib(patch_id)%rotation_matrix(:, :) = matmul(rotation(1, :, :), rotation(2, :, :))
932-
patch_ib(patch_id)%rotation_matrix_inverse(:, :) = matmul(tranpose(rotation(2, :, :)), transpose(rotation(1, :, :)))
933-
end if
934-
! z component first, since it applies in 2D and 3D
935-
angle = patch_ib(patch_id)%angles(3)
936-
rotation(3, 1, :) = [cos(angle), -sin(angle), 0._wp]
937-
rotation(3, 2, :) = [sin(angle), cos(angle) , 0._wp]
938-
rotation(3, 3, :) = [0._wp , 0._wp , 1._wp]
939-
940-
if (num_dims == 3) then
941-
! apply the z rotation to the xy rotation in 3D
942-
patch_ib(patch_id)%rotation_matrix(:, :) = matmul(patch_ib(patch_id)%rotation_matrix(:, :), rotation(3, :, :))
943-
patch_ib(patch_id)%rotation_matrix_inverse(:, :) = matmul(transpose(rotation(3, :, :)), patch_ib(patch_id)%rotation_matrix_inverse(:, :))
944-
else
945-
! write out only the z rotation in 2D
946-
patch_ib(patch_id)%rotation_matrix(:, :) = rotation(3, :, :)
947-
patch_ib(patch_id)%rotation_matrix_inverse(:, :) = transpose(rotation(3, :, :))
948-
end if
949-
950-
end subroutine s_update_ib_rotation_matrix
951-
952908
!> Resets the current indexes of immersed boundaries and replaces them after updating
953909
!> the position of each moving immersed boundary
954910
impure subroutine s_update_mib(num_ibs, levelset, levelset_norm)
@@ -964,8 +920,8 @@ contains
964920

965921
! recalulcate the rotation matrix based upon the new angles
966922
do i = 1, num_ibs
967-
if patch_ib(i)%moving_ibm call s_update_ib_rotation_matrix(i)
968-
end if
923+
if (patch_ib(i)%moving_ibm .ne. 0) call s_update_ib_rotation_matrix(i)
924+
end do
969925

970926
! recompute the new ib_patch locations and broadcast them.
971927
call s_apply_ib_patches(ib_markers%sf(0:m, 0:n, 0:p), levelset, levelset_norm)

src/simulation/m_time_steppers.fpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ contains
836836
if (patch_ib(i)%moving_ibm == 1) then
837837
do j = 1, 3
838838
patch_ib(i)%vel(j) = (patch_ib(i)%vel(j) + patch_ib(i)%step_vel(j) + 0.0*dt)/2._wp
839-
patch_ib(i)%angular_vel(j) = (patch_ib(i)%angular_vel(j) + patch_ib(i)%angular_step_vel(j) + 0.0*dt)/2._wp
839+
patch_ib(i)%angular_vel(j) = (patch_ib(i)%angular_vel(j) + patch_ib(i)%step_angular_vel(j) + 0.0*dt)/2._wp
840840
841841
patch_ib(i)%angles(j) = (patch_ib(i)%angles(j) + patch_ib(i)%step_angles(j) + patch_ib(i)%step_angular_vel(j)*dt)/2._wp
842842
end do
@@ -1235,7 +1235,7 @@ contains
12351235
patch_ib(i)%vel(j) = (2._wp*patch_ib(i)%vel(j) + patch_ib(i)%step_vel(j) + 0.0*dt)/3._wp
12361236
patch_ib(i)%angular_vel(j) = (2._wp*patch_ib(i)%angular_vel(j) + patch_ib(i)%step_angular_vel(j) + 0.0*dt)/3._wp
12371237
1238-
patch_ib(i)%angles(j) = (2._wp*patch_ib(i)%angles(j) + patch_ib(i)%step_angles(j) + patch_ib(i)%angular_vel(j)*dt)/3._wp
1238+
patch_ib(i)%angles(j) = (2._wp*patch_ib(i)%angles(j) + patch_ib(i)%step_angles(j) + 2._wp*patch_ib(i)%angular_vel(j)*dt)/3._wp
12391239
end do
12401240
12411241
patch_ib(i)%x_centroid = (2._wp*patch_ib(i)%x_centroid + patch_ib(i)%step_x_centroid + 2._wp*patch_ib(i)%vel(1)*dt)/3._wp

0 commit comments

Comments
 (0)