@@ -85,7 +85,7 @@ contains
8585 $:GPU_PARALLEL_LOOP(private= ' [i]' )
8686 do i = 1 , num_ibs
8787 if (patch_ib(i)%moving_ibm /= 0 ) then
88- call s_compute_moment_of_inertia(i , patch_ib(i)%angular_vel)
88+ call s_compute_moment_of_inertia(patch_ib(i) , patch_ib(i)%angular_vel)
8989 end if
9090 call s_update_ib_rotation_matrix(i)
9191 end do
@@ -1108,25 +1108,25 @@ contains
11081108 end subroutine s_compute_centroid_offset
11091109
11101110 !> Computes the moment of inertia for an immersed boundary
1111- subroutine s_compute_moment_of_inertia (ib_idx , axis )
1111+ subroutine s_compute_moment_of_inertia (patch , moment )
11121112
11131113 $:GPU_ROUTINE(parallelism= ' [seq]' )
11141114
1115- real (wp ), dimension ( 3 ), intent (in ) :: axis !< the axis about which we compute the moment. Only required in 3D .
1116- integer , intent (in ) :: ib_idx
1117- real (wp) :: moment, distance_to_axis, cell_volume
1118- real (wp), dimension (3 ) :: position, closest_point_along_axis, vector_to_axis, normal_axis
1119- integer :: i, j, k, count, ib_marker
1115+ type(ib_patch_parameters ), intent (in ) :: patch
1116+ real (wp), dimension ( 3 ), intent (out ) :: moment
1117+ real (wp) :: distance_to_axis, cell_volume
1118+ real (wp), dimension (3 ) :: position, closest_point_along_axis, vector_to_axis, normal_axis
1119+ integer :: i, j, k, count, ib_marker
11201120
11211121 ! if the IB is in 2D or a 3D sphere, we can compute this exactly
1122- if (patch_ib(ib_idx) %geometry == 2 ) then ! circle
1123- patch_ib(ib_idx)% moment = 0.5_wp * patch_ib(ib_idx) %mass* (patch_ib(ib_idx) %radius)** 2
1124- else if (patch_ib(ib_idx) %geometry == 3 ) then ! rectangle
1125- patch_ib(ib_idx)% moment = patch_ib(ib_idx) %mass* (patch_ib(ib_idx) %length_x** 2 + patch_ib(ib_idx) %length_y** 2 )/ 6._wp
1126- else if (patch_ib(ib_idx) %geometry == 6 ) then ! ellipse
1127- patch_ib(ib_idx)% moment = 0.0625_wp * patch_ib(ib_idx) %mass* (patch_ib(ib_idx) %length_x** 2 + patch_ib(ib_idx) %length_y** 2 )
1128- else if (patch_ib(ib_idx) %geometry == 8 ) then ! sphere
1129- patch_ib(ib_idx)% moment = 0.4 * patch_ib(ib_idx) %mass* (patch_ib(ib_idx) %radius)** 2
1122+ if (patch %geometry == 2 ) then ! circle
1123+ moment = 0.5_wp * patch %mass* (patch %radius)** 2
1124+ else if (patch %geometry == 3 ) then ! rectangle
1125+ moment = patch %mass* (patch %length_x** 2 + patch %length_y** 2 )/ 6._wp
1126+ else if (patch %geometry == 6 ) then ! ellipse
1127+ moment = 0.0625_wp * patch %mass* (patch %length_x** 2 + patch %length_y** 2 )
1128+ else if (patch %geometry == 8 ) then ! sphere
1129+ moment = 0.4 * patch %mass* (patch %radius)** 2
11301130 else ! we do not have an analytic moment of inertia calculation and need to approximate it directly via a sum
11311131 count = 0
11321132 moment = 0._wp
@@ -1136,16 +1136,16 @@ contains
11361136 cell_volume = cell_volume* (z_cc(1 ) - z_cc(0 ))
11371137 end if
11381138
1139- ib_marker = patch_ib(ib_idx) %gbl_patch_id
1139+ ib_marker = patch %gbl_patch_id
11401140
11411141 if (p == 0 ) then
11421142 normal_axis = [0 , 0 , 1 ]
1143- else if (sqrt (sum (axis ** 2 )) < sgm_eps) then
1143+ else if (sqrt (sum (moment ** 2 )) < sgm_eps) then
11441144 ! if the object is not actually rotating at this time, return a dummy value and exit
1145- patch_ib(ib_idx)% moment = 1._wp
1145+ moment = 1._wp
11461146 return
11471147 else
1148- normal_axis = axis / sqrt (sum (axis ** 2 ))
1148+ normal_axis = moment / sqrt (sum (moment ** 2 ))
11491149 end if
11501150
11511151 do i = 0 , m
@@ -1156,11 +1156,9 @@ contains
11561156
11571157 ! get the position in local coordinates so that the axis passes through 0 , 0 , 0
11581158 if (num_dims < 3 ) then
1159- position = [x_cc(i), y_cc(j), 0._wp ] - [patch_ib(ib_idx)%x_centroid, patch_ib(ib_idx)%y_centroid, &
1160- & 0._wp ]
1159+ position = [x_cc(i), y_cc(j), 0._wp ] - [patch%x_centroid, patch%y_centroid, 0._wp ]
11611160 else
1162- position = [x_cc(i), y_cc(j), z_cc(k)] - [patch_ib(ib_idx)%x_centroid, &
1163- & patch_ib(ib_idx)%y_centroid, patch_ib(ib_idx)%z_centroid]
1161+ position = [x_cc(i), y_cc(j), z_cc(k)] - [patch%x_centroid, patch%y_centroid, patch%z_centroid]
11641162 end if
11651163
11661164 ! project the position along the axis to find the closest distance to the rotation axis
@@ -1176,7 +1174,7 @@ contains
11761174 end do
11771175
11781176 ! write the final moment assuming the points are all uniform density
1179- patch_ib(ib_idx)% moment = moment* patch_ib(ib_idx) %mass/ (count* cell_volume)
1177+ moment = moment* patch %mass/ (count* cell_volume)
11801178 end if
11811179
11821180 end subroutine s_compute_moment_of_inertia
0 commit comments