Skip to content

Commit 0c221ae

Browse files
Added atomic updates and some code structure
1 parent 7c70fd4 commit 0c221ae

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/simulation/m_ibm.fpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,23 +1016,30 @@ contains
10161016
do k = 0, p
10171017
ib_idx = ib_markers%sf(i, j, k)
10181018
if (ib_idx /= 0) then ! only need to compute the gradient for cells inside a IB
1019-
if (patch_ib(ib_idx)%moving_ibm == 2) then
1019+
if (patch_ib(ib_idx)%moving_ibm == 2) then ! make sure that this IB has 2-way coupling enabled
10201020
if (num_dims == 3) then
10211021
radial_vector = [x_cc(i), y_cc(j), z_cc(k)] - [patch_ib(ib_idx)%x_centroid, patch_ib(ib_idx)%y_centroid, patch_ib(ib_idx)%z_centroid] ! get the vector pointing to the grid cell
10221022
else
10231023
radial_vector = [x_cc(i), y_cc(j), 0._wp] - [patch_ib(ib_idx)%x_centroid, patch_ib(ib_idx)%y_centroid, 0._wp] ! get the vector pointing to the grid cell
10241024
end if
1025+
1026+
! use a finite difference to compute the 2D components of the gradient of the pressure and cell volume
10251027
pressure_divergence(1) = (pressure(i + 1, j, k) - pressure(i - 1, j, k))/(2._wp*x_cc(i))
10261028
pressure_divergence(2) = (pressure(i, j + 1, k) - pressure(i, j - 1, k))/(2._wp*y_cc(j))
10271029
cell_volume = x_cc(i)*y_cc(j)
1030+
1031+
! add the 3D component, if we are working in 3 dimensions
10281032
if (num_dims == 3) then
10291033
pressure_divergence(3) = (pressure(i, j, k + 1) - pressure(i, j, k - 1))/(2._wp*z_cc(k))
10301034
cell_volume = cell_volume*z_cc(k)
10311035
else
10321036
pressure_divergence(3) = 0._wp
10331037
end if
10341038
1039+
! Update the force values atmoically to prevent race conditions
1040+
$:GPU_ATOMIC(atomic='update')
10351041
forces(ib_idx, :) = forces(ib_idx, :) - (pressure_divergence*cell_volume)
1042+
$:GPU_ATOMIC(atomic='update')
10361043
torques(ib_idx, :) = torques(ib_idx, :) + (cross_product(radial_vector, pressure_divergence)*cell_volume)
10371044
end if
10381045
end if
@@ -1051,8 +1058,6 @@ contains
10511058
patch_ib(i)%torque(:) = matmul(patch_ib(i)%rotation_matrix_inverse, torques(i, :)) ! torques must be computed in the local coordinates of the IB
10521059
end do
10531060
1054-
print *, patch_ib(1)%force(1:2)
1055-
10561061
end subroutine s_compute_ib_forces
10571062
10581063
!> Subroutine to deallocate memory reserved for the IBM module

0 commit comments

Comments
 (0)