Skip to content

Commit 0210fbb

Browse files
author
Daniel Vickers
committed
Optimized particle bed instantitation
1 parent dc433b6 commit 0210fbb

5 files changed

Lines changed: 32 additions & 11 deletions

File tree

src/common/m_model.fpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ contains
983983
dx_local = minval(dx); dy_local = minval(dy)
984984
if (p /= 0) dz_local = minval(dz)
985985

986-
num_gbl_ibs = num_ibs
986+
@:ALLOCATE(models(num_ibs))
987987
allocate (stl_bounding_boxes(num_ibs,1:3,1:3))
988988

989989
do patch_id = 1, num_ibs

src/simulation/m_collisions.fpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ contains
3939
spring_stiffness = (pi**2 + log(e)**2)/(collision_time**2)
4040
$:GPU_UPDATE(device='[damping_parameter, spring_stiffness]')
4141

42-
@:ALLOCATE(collision_lookup(num_ibs * 8, 4))
43-
@:ALLOCATE(wall_overlap_distances(num_ibs, 6))
42+
@:ALLOCATE(collision_lookup(num_local_ibs_max * 27 * 8, 4))
43+
@:ALLOCATE(wall_overlap_distances(num_local_ibs_max*27, 6))
4444

4545
wall_overlap_distances = 0
4646
$:GPU_UPDATE(device='[wall_overlap_distances]')

src/simulation/m_ibm.fpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ contains
6060
@:ALLOCATE(ib_markers%sf(-buff_size:m+buff_size, -buff_size:n+buff_size, 0:0))
6161
end if
6262

63-
@:ALLOCATE(models(num_ibs))
64-
6563
@:ACC_SETUP_SFs(ib_markers)
6664

6765
$:GPU_ENTER_DATA(copyin='[num_gps]')
@@ -1034,6 +1032,7 @@ contains
10341032
end do
10351033
$:END_GPU_PARALLEL_LOOP()
10361034

1035+
if (proc_rank == 0) print *, "s_apply_collision_forces"
10371036
call s_apply_collision_forces(ghost_points, num_gps, ib_markers, forces, torques)
10381037

10391038
! reduce the forces across local neighborhood ranks

src/simulation/m_particle_bed.fpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ contains
2222
impure subroutine s_generate_particle_beds()
2323

2424
integer :: b, ib_idx, geom
25-
integer :: n_placed
25+
integer :: n_placed, n_total_placed
2626
integer(8) :: n_attempts, max_attempts
2727
real(wp) :: xmin, xmax, ymin, ymax, zmin, zmax, min_dist
2828
real(wp) :: rx, ry, rz, dist
29+
real(wp) :: t_start, t_end
2930
integer :: seed
3031
logical :: overlaps
3132
real(wp), allocatable :: placed(:,:)
@@ -38,6 +39,9 @@ contains
3839

3940
if (num_particle_beds == 0) return
4041

42+
call cpu_time(t_start)
43+
n_total_placed = 0
44+
4145
do b = 1, num_particle_beds
4246
xmin = particle_bed(b)%x_centroid - 0.5_wp*particle_bed(b)%length_x
4347
xmax = particle_bed(b)%x_centroid + 0.5_wp*particle_bed(b)%length_x
@@ -58,7 +62,7 @@ contains
5862
dz_hi = 1
5963
end if
6064

61-
max_attempts = int(particle_bed(b)%num_particles, 8)*10000_8
65+
max_attempts = int(particle_bed(b)%num_particles, 8)*1000_8
6266
n_placed = 0
6367
n_attempts = 0
6468
seed = particle_bed(b)%seed
@@ -135,20 +139,33 @@ contains
135139
patch_ib(ib_idx)%x_centroid = rx
136140
patch_ib(ib_idx)%y_centroid = ry
137141
patch_ib(ib_idx)%z_centroid = rz
142+
patch_ib(ib_idx)%angles(1) = 0._wp
143+
patch_ib(ib_idx)%angles(2) = 0._wp
144+
patch_ib(ib_idx)%angles(3) = 0._wp
145+
patch_ib(ib_idx)%vel(1) = 0._wp
146+
patch_ib(ib_idx)%vel(2) = 0._wp
147+
patch_ib(ib_idx)%vel(3) = 0._wp
148+
patch_ib(ib_idx)%angular_vel(1) = 0._wp
149+
patch_ib(ib_idx)%angular_vel(2) = 0._wp
150+
patch_ib(ib_idx)%angular_vel(3) = 0._wp
138151
patch_ib(ib_idx)%radius = particle_bed(b)%radius
139152
patch_ib(ib_idx)%mass = particle_bed(b)%mass
140153
patch_ib(ib_idx)%moving_ibm = particle_bed(b)%moving_ibm
141154
end if
142155
end do
143156

144157
if (n_placed < particle_bed(b)%num_particles) then
145-
print '("WARNING: particle_bed(",I0,"): placed ",I0," of ",I0," particles after ",I0," attempts")', &
146-
b, n_placed, particle_bed(b)%num_particles, n_attempts
158+
print *, "Error :: Failed to place all IBs ib particle bed"
159+
stop
147160
end if
148161

162+
n_total_placed = n_total_placed + n_placed
149163
deallocate (placed, hash_head, chain_next)
150164
end do
151165

166+
call cpu_time(t_end)
167+
if (proc_rank == 0) print '(a,i0,a,f0.3,a)', 'Particle beds placed ', n_total_placed, ' particles in ', t_end - t_start, ' seconds.'
168+
152169
end subroutine s_generate_particle_beds
153170

154171
!> Xorshift PRNG. Advances seed in-place and returns a value in [0, 1).

src/simulation/m_start_up.fpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,9 @@ contains
922922
call s_read_ib_restart_data(n_start)
923923
else if (t_step_start > 0) then
924924
call s_read_ib_restart_data(t_step_start)
925+
else
926+
! particle bed generated on first tiem step
927+
call s_generate_particle_beds()
925928
end if
926929
call s_instantiate_STL_models()
927930
call s_reduce_ib_patch_array()
@@ -1005,7 +1008,6 @@ contains
10051008
call s_assign_default_values_to_user_inputs()
10061009
call s_read_input_file()
10071010
call s_check_input_file()
1008-
call s_generate_particle_beds()
10091011

10101012
print '(" Simulating a ", A, " ", I0, "x", I0, "x", I0, " case on ", I0, " rank(s) ", A, ".")', &
10111013
#:if not MFC_CASE_OPTIMIZATION
@@ -1217,7 +1219,6 @@ contains
12171219
logical :: is_in_neighborhood, is_local
12181220

12191221
! do all set up for moving immersed boundaries
1220-
12211222
moving_immersed_boundary_flag = .false.
12221223
do i = 1, num_ibs
12231224
if (patch_ib(i)%moving_ibm /= 0) then
@@ -1289,6 +1290,8 @@ contains
12891290
integer, dimension(4) :: buf4, rbuf4
12901291
integer, dimension(2) :: buf2, rbuf2
12911292

1293+
if (proc_rank == 0) print *, "Entering compute_ib_neighbor_ranks"
1294+
12921295
ax = ib_neighborhood_radius
12931296

12941297
if (allocated(ib_neighbor_ranks)) deallocate (ib_neighbor_ranks)
@@ -1432,6 +1435,8 @@ contains
14321435
end if
14331436
#endif
14341437
1438+
if (proc_rank == 0) print *, "Exiting compute_ib_neighbor_ranks"
1439+
14351440
end subroutine s_compute_ib_neighbor_ranks
14361441
14371442
subroutine get_neighbor_bounds()

0 commit comments

Comments
 (0)