@@ -291,7 +291,7 @@ contains
291291 ! compute the linear velocity of the ghost point due to rotation
292292 radial_vector = physical_loc - [patch_ib(patch_id)%x_centroid, &
293293 patch_ib(patch_id)%y_centroid, patch_ib(patch_id)%z_centroid]
294- rotation_velocity = cross_product (matmul (patch_ib(patch_id)%rotation_matrix, patch_ib(patch_id)%angular_vel), radial_vector)
294+ call s_cross_product (matmul (patch_ib(patch_id)%rotation_matrix, patch_ib(patch_id)%angular_vel), radial_vector, rotation_velocity )
295295
296296 ! add only the component of the IB' s motion that is normal to the surface
297297 vel_g = vel_g + sum((patch_ib(patch_id)%vel + rotation_velocity)*norm)*norm
@@ -305,7 +305,7 @@ contains
305305 radial_vector = physical_loc - [patch_ib(patch_id)%x_centroid, &
306306 patch_ib(patch_id)%y_centroid, patch_ib(patch_id)%z_centroid]
307307 ! convert the angular velocity from the inertial reference frame to the fluids frame, then convert to linear velocity
308- rotation_velocity = cross_product (matmul(patch_ib(patch_id)%rotation_matrix, patch_ib(patch_id)%angular_vel), radial_vector)
308+ call s_cross_product (matmul(patch_ib(patch_id)%rotation_matrix, patch_ib(patch_id)%angular_vel), radial_vector, rotation_velocity )
309309 do q = 1, 3
310310 ! if mibm is 1 or 2, then the boundary may be moving
311311 vel_g(q) = patch_ib(patch_id)%vel(q) ! add the linear velocity
@@ -999,18 +999,21 @@ contains
999999 ! by Archana Sridhar and Jesse Capecelatro
10001000 subroutine s_compute_ib_forces(pressure)
10011001
1002- real(wp), dimension(0:m, 0:n, 0:p), intent(in) :: pressure
1002+ ! real(wp), dimension(idwbuff(1)%beg:idwbuff(1)%end, &
1003+ ! idwbuff(2)%beg:idwbuff(2)%end, &
1004+ ! idwbuff(3)%beg:idwbuff(3)%end), intent(in) :: pressure
1005+ type(scalar_field), intent(in) :: pressure
10031006
10041007 integer :: i, j, k, l, ib_idx
10051008 real(wp), dimension(num_ibs, 3) :: forces, torques
1006- real(wp), dimension(1:3) :: pressure_divergence, radial_vector, temp_torque_vector
1009+ real(wp), dimension(1:3) :: pressure_divergence, radial_vector, local_torque_contribution
10071010 real(wp) :: cell_volume, dx, dy, dz
10081011
10091012 forces = 0._wp
10101013 torques = 0._wp
10111014
10121015 ! TODO :: This is currently only valid inviscid, and needs to be extended to add viscocity
1013- $:GPU_PARALLEL_LOOP(private=' [ib_idx,radial_vector,pressure_divergence,cell_volume,temp_torque_vector , dx, dy, dz]' , copy=' [forces,torques]' , copyin=' [ib_markers]' , collapse=3)
1016+ $:GPU_PARALLEL_LOOP(private=' [ib_idx,radial_vector,pressure_divergence,cell_volume,local_torque_contribution , dx, dy, dz]' , copy=' [forces,torques]' , copyin=' [ib_markers,patch_ib ]' , collapse=3)
10141017 do i = 0, m
10151018 do j = 0, n
10161019 do k = 0, p
@@ -1027,26 +1030,27 @@ contains
10271030 dy = y_cc(j + 1) - y_cc(j)
10281031
10291032 ! use a finite difference to compute the 2D components of the gradient of the pressure and cell volume
1030- pressure_divergence(1) = (pressure(i + 1, j, k) - pressure(i - 1, j, k))/(2._wp*dx)
1031- pressure_divergence(2) = (pressure(i, j + 1, k) - pressure(i, j - 1, k))/(2._wp*dy)
1033+ pressure_divergence(1) = (pressure%sf (i + 1, j, k) - pressure%sf (i - 1, j, k))/(2._wp*dx)
1034+ pressure_divergence(2) = (pressure%sf (i, j + 1, k) - pressure%sf (i, j - 1, k))/(2._wp*dy)
10321035 cell_volume = dx*dy
10331036
10341037 ! add the 3D component, if we are working in 3 dimensions
10351038 if (num_dims == 3) then
10361039 dz = z_cc(k + 1) - z_cc(k)
1037- pressure_divergence(3) = (pressure(i, j, k + 1) - pressure(i, j, k - 1))/(2._wp*dz)
1040+ pressure_divergence(3) = (pressure%sf (i, j, k + 1) - pressure%sf (i, j, k - 1))/(2._wp*dz)
10381041 cell_volume = cell_volume*dz
10391042 else
10401043 pressure_divergence(3) = 0._wp
10411044 end if
10421045
10431046 ! Update the force values atomically to prevent race conditions
1044- temp_torque_vector = cross_product(radial_vector, pressure_divergence)*cell_volume ! separate out to make atomics safe
1047+ call s_cross_product(radial_vector, pressure_divergence, local_torque_contribution) ! separate out to make atomics safe
1048+ local_torque_contribution = local_torque_contribution*cell_volume
10451049 do l = 1, 3
10461050 $:GPU_ATOMIC(atomic=' update' )
10471051 forces(ib_idx, l) = forces(ib_idx, l) - (pressure_divergence(l)*cell_volume)
10481052 $:GPU_ATOMIC(atomic=' update' )
1049- torques(ib_idx, l) = torques(ib_idx, l) - temp_torque_vector (l)
1053+ torques(ib_idx, l) = torques(ib_idx, l) - local_torque_contribution (l)
10501054 end do
10511055 end if
10521056 end if
@@ -1147,13 +1151,14 @@ contains
11471151
11481152 end subroutine s_compute_moment_of_inertia
11491153
1150- function cross_product(a, b) result(c)
1154+ subroutine s_cross_product(a, b, c)
1155+ $:GPU_ROUTINE(parallelism=' [seq]' )
11511156 real(wp), intent(in) :: a(3), b(3)
1152- real(wp) :: c(3)
1157+ real(wp), intent(out) :: c(3)
11531158
11541159 c(1) = a(2)*b(3) - a(3)*b(2)
11551160 c(2) = a(3)*b(1) - a(1)*b(3)
11561161 c(3) = a(1)*b(2) - a(2)*b(1)
1157- end function cross_product
1162+ end subroutine s_cross_product
11581163
11591164end module m_ibm
0 commit comments