Skip to content

Commit a70fe62

Browse files
Formatting, collision N_2 fixes, and example update
1 parent d132c7e commit a70fe62

5 files changed

Lines changed: 41 additions & 42 deletions

File tree

examples/2D_mibm_particle_bed/case.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
collision_time = 20.0 * dt
2828

2929
# Particle bed parameters
30-
bed_x = -0.5
30+
bed_x = 0.5
3131
bed_y = 0.0
32-
bed_lx = 1.
32+
bed_lx = 2.0
3333
bed_ly = 3.5
3434
particle_radius = 0.15
3535
particle_mass = 0.25
36-
particle_min_spacing = 0.02
36+
particle_min_spacing = 0.05
3737

3838
print(
3939
json.dumps(
@@ -46,8 +46,8 @@
4646
"y_domain%beg": -domain_size * 0.5,
4747
"y_domain%end": domain_size * 0.5,
4848
"cyl_coord": "F",
49-
"m": 512,
50-
"n": 512,
49+
"m": 256,
50+
"n": 256,
5151
"p": 0,
5252
"dt": dt,
5353
"t_step_start": 0,

src/simulation/m_collisions.fpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ contains
354354

355355
collision_lookup(current_collisions, 1) = pid1
356356
collision_lookup(current_collisions, 2) = pid2
357+
collision_lookup(current_collisions, 3) = pid1
358+
collision_lookup(current_collisions, 4) = pid2
357359
end if
358360
end do
359361
end do

src/simulation/m_global_parameters.fpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,18 @@ module m_global_parameters
356356

357357
type particle_bed_parameters
358358
real(wp) :: x_centroid, y_centroid, z_centroid !< Center of the particle bed region
359-
real(wp) :: length_x, length_y, length_z !< Dimensions of the particle bed region
360-
integer :: num_particles !< Number of particles to generate
361-
real(wp) :: radius !< Particle radius
362-
real(wp) :: mass !< Particle mass
363-
real(wp) :: min_spacing !< Minimum surface-to-surface gap (particle centers are 2*radius + min_spacing apart)
364-
integer :: moving_ibm !< Motion flag: 0=static, 1=moving (forces), 2=forced path
365-
integer :: seed !< Random seed for reproducible placement
359+
real(wp) :: length_x, length_y, length_z !< Dimensions of the particle bed region
360+
integer :: num_particles !< Number of particles to generate
361+
real(wp) :: radius !< Particle radius
362+
real(wp) :: mass !< Particle mass
363+
real(wp) :: min_spacing !< Minimum surface-to-surface gap (particle centers are 2*radius + min_spacing apart)
364+
integer :: moving_ibm !< Motion flag: 0=static, 1=moving (forces), 2=forced path
365+
integer :: seed !< Random seed for reproducible placement
366366
end type particle_bed_parameters
367367

368-
integer :: num_particle_beds !< Number of particle bed specifications
368+
integer :: num_particle_beds !< Number of particle bed specifications
369369
type(particle_bed_parameters), dimension(num_particle_beds_max) :: particle_bed !< Particle bed specifications
370-
integer, allocatable, dimension(:,:,:) :: ib_neighbor_ranks !< MPI ranks of neighborhood domains, indexed (-N:N,-N:N,-N:N)
370+
integer, allocatable, dimension(:,:,:) :: ib_neighbor_ranks !< MPI ranks of neighborhood domains, indexed (-N:N,-N:N,-N:N)
371371
type(vec3_dt), allocatable, dimension(:) :: airfoil_grid_u, airfoil_grid_l
372372
integer :: Np
373373

src/simulation/m_particle_bed.fpp

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,23 @@ module m_particle_bed
1616

1717
contains
1818

19-
!> Generate all particle beds and append the resulting particles to patch_ib.
20-
!! Called on rank 0 only, before s_mpi_bcast_user_inputs.
21-
!! Uses a spatial hash grid (cell size = min_dist) so each candidate requires
22-
!! only 3^dim distance checks on average instead of O(n).
19+
!> Generate all particle beds and append the resulting particles to patch_ib. Called on rank 0 only, before
20+
!! s_mpi_bcast_user_inputs. Uses a spatial hash grid (cell size = min_dist) so each candidate requires only 3^dim distance
21+
!! checks on average instead of O(n).
2322
impure subroutine s_generate_particle_beds()
2423

25-
integer :: b, ib_idx, geom
26-
integer :: n_placed, n_attempts, max_attempts
27-
real(wp) :: xmin, xmax, ymin, ymax, zmin, zmax, min_dist
28-
real(wp) :: rx, ry, rz, dist
29-
integer :: seed
30-
logical :: overlaps
31-
real(wp), allocatable :: placed(:, :)
24+
integer :: b, ib_idx, geom
25+
integer :: n_placed, n_attempts, max_attempts
26+
real(wp) :: xmin, xmax, ymin, ymax, zmin, zmax, min_dist
27+
real(wp) :: rx, ry, rz, dist
28+
integer :: seed
29+
logical :: overlaps
30+
real(wp), allocatable :: placed(:,:)
3231

3332
! Spatial hash grid
34-
integer :: hash_size, slot
35-
integer :: bx, by, bz, nbx, nby, nbz
36-
integer :: dx_b, dy_b, dz_b, dz_lo, dz_hi, j
33+
integer :: hash_size, slot
34+
integer :: bx, by, bz, nbx, nby, nbz
35+
integer :: dx_b, dy_b, dz_b, dz_lo, dz_hi, j
3736
integer, allocatable :: hash_head(:), chain_next(:)
3837

3938
if (num_particle_beds == 0) return
@@ -66,8 +65,8 @@ contains
6665

6766
allocate (placed(3, particle_bed(b)%num_particles))
6867

69-
! Hash table: 4x overprovisioned for ~25% load factor, minimum 16 buckets.
70-
! chain_next(i) links placed particle i to the previous occupant of its bucket.
68+
! Hash table: 4x overprovisioned for ~25% load factor, minimum 16 buckets. chain_next(i) links placed particle i to the
69+
! previous occupant of its bucket.
7170
hash_size = max(16, 4*particle_bed(b)%num_particles)
7271
allocate (hash_head(hash_size))
7372
allocate (chain_next(particle_bed(b)%num_particles))
@@ -90,7 +89,7 @@ contains
9089
bz = 0
9190
if (p /= 0) bz = int(floor(rz/min_dist))
9291

93-
! Check 3x3(x3) neighboring bins O(1) average via hash lookup
92+
! Check 3x3(x3) neighboring bins - O(1) average via hash lookup
9493
overlaps = .false.
9594
outer: do dx_b = -1, 1
9695
do dy_b = -1, 1
@@ -104,8 +103,7 @@ contains
104103
if (p == 0) then
105104
dist = sqrt((rx - placed(1, j))**2 + (ry - placed(2, j))**2)
106105
else
107-
dist = sqrt((rx - placed(1, j))**2 + (ry - placed(2, j))**2 &
108-
+ (rz - placed(3, j))**2)
106+
dist = sqrt((rx - placed(1, j))**2 + (ry - placed(2, j))**2 + (rz - placed(3, j))**2)
109107
end if
110108
if (dist < min_dist) then
111109
overlaps = .true.
@@ -143,8 +141,8 @@ contains
143141
end do
144142

145143
if (n_placed < particle_bed(b)%num_particles) then
146-
print '("WARNING: particle_bed(",I0,"): placed ",I0," of ",I0," particles after ",I0," attempts")', &
147-
b, n_placed, particle_bed(b)%num_particles, n_attempts
144+
print '("WARNING: particle_bed(",I0,"): placed ",I0," of ",I0," particles after ",I0," attempts")', b, n_placed, &
145+
& particle_bed(b)%num_particles, n_attempts
148146
end if
149147

150148
deallocate (placed, hash_head, chain_next)
@@ -156,7 +154,7 @@ contains
156154
function f_xorshift(seed) result(rval)
157155

158156
integer, intent(inout) :: seed
159-
real(wp) :: rval
157+
real(wp) :: rval
160158

161159
seed = ieor(seed, ishft(seed, 13))
162160
seed = ieor(seed, ishft(seed, -17))
@@ -166,14 +164,13 @@ contains
166164

167165
end function f_xorshift
168166

169-
!> Hash bin coordinates to a 1-indexed slot in [1, hash_size].
170-
!! Uses large prime multipliers to spread bins across buckets.
171-
!! Hash collisions are benign: the distance check catches false neighbours.
167+
!> Hash bin coordinates to a 1-indexed slot in [1, hash_size]. Uses large prime multipliers to spread bins across buckets. Hash
168+
!! collisions are benign: the distance check catches false neighbours.
172169
function f_bin_hash(bx, by, bz, hash_size) result(slot)
173170

174171
integer, intent(in) :: bx, by, bz, hash_size
175-
integer :: slot
176-
integer(8) :: key
172+
integer :: slot
173+
integer(8) :: key
177174

178175
key = ieor(ieor(int(bx, 8)*73856093_8, int(by, 8)*19349663_8), int(bz, 8)*83492791_8)
179176
slot = int(mod(abs(key), int(hash_size, 8))) + 1

src/simulation/m_start_up.fpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ contains
10071007
call s_check_input_file()
10081008
call s_generate_particle_beds()
10091009

1010-
print '(" Simulating a ", A, " ", I0, "x", I0, "x", I0, " case on ", I0, " rank(s) ", A, ".")',&
1010+
print '(" Simulating a ", A, " ", I0, "x", I0, "x", I0, " case on ", I0, " rank(s) ", A, ".")', &
10111011
#:if not MFC_CASE_OPTIMIZATION
10121012
"regular", &
10131013
#:else

0 commit comments

Comments
 (0)