Skip to content

Commit 222d08c

Browse files
committed
Merge remote-tracking branch 'upstream/master' into ExtrusionV3
2 parents 275b77c + ebde16c commit 222d08c

14 files changed

Lines changed: 499 additions & 102 deletions

File tree

docs/documentation/case.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ MPI topology is automatically optimized to maximize the parallel efficiency for
197197

198198
The Table lists the patch parameters.
199199
The parameters define the geometries and physical parameters of fluid components (patch) in the domain at initial condition.
200-
Note that the domain must be fully filled with patche(s).
200+
Note that the domain must be fully filled with patches.
201201
The code outputs error messages when an empty region is left in the domain.
202202

203203
- `tau_e(i)` is the `i`-th component of the elastic stress tensor, ordered as `tau_xx`, `tau_xy`, `tau_yy`, `tau_xz`, `tau_yz`, and `tau_zz`. 1D simulation requires `tau(1)`, 2D `tau(1:3)`, and 3D `tau(1:6)`.
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
"""
2+
Case file to demonstrate and test the periodic collision of immersed boundaries.
3+
This file was generated by Conrad Delgado as a minimum reproducer to prevent regression
4+
of periodic immersed boundaries.
5+
"""
6+
7+
import json
8+
import math
9+
10+
import numpy as np
11+
12+
gam_a = 1.4
13+
14+
# particle diameter
15+
D = 0.1
16+
R = D / 2.0
17+
18+
# particle params
19+
rho_s = 10.0
20+
vol_s = 4.0 / 3.0 * np.pi * R**3
21+
mass_s = rho_s * vol_s
22+
N_s = 2
23+
24+
# fluid params
25+
M = 2.0
26+
Re = 500.0
27+
P = 101325
28+
rho = 1.225
29+
v1 = M * np.sqrt(gam_a * P / rho)
30+
mu = rho * v1 * D / Re
31+
32+
# timestep
33+
dt = 1.0e-05
34+
Nt = 50
35+
t_save = 5
36+
37+
# grid
38+
Nx = 31
39+
Ny = 63
40+
Nz = 31
41+
42+
# immersed boundary dictionary
43+
ib_dict = {}
44+
ib_dict.update(
45+
{
46+
f"patch_ib({1})%geometry": 8,
47+
f"patch_ib({1})%x_centroid": 0.0,
48+
f"patch_ib({1})%y_centroid": -2.1 * D,
49+
f"patch_ib({1})%z_centroid": 0.0,
50+
f"patch_ib({1})%vel(2)": -100.0,
51+
f"patch_ib({1})%radius": D / 2,
52+
f"patch_ib({1})%slip": "F",
53+
f"patch_ib({1})%moving_ibm": 2,
54+
f"patch_ib({1})%mass": mass_s,
55+
f"patch_ib({2})%geometry": 8,
56+
f"patch_ib({2})%x_centroid": 0.0,
57+
f"patch_ib({2})%y_centroid": 1.8 * D,
58+
f"patch_ib({2})%z_centroid": 0.0,
59+
f"patch_ib({2})%vel(2)": +100.0,
60+
f"patch_ib({2})%radius": D / 2,
61+
f"patch_ib({2})%slip": "F",
62+
f"patch_ib({2})%moving_ibm": 2,
63+
f"patch_ib({2})%mass": mass_s,
64+
}
65+
)
66+
67+
# Configuring case dictionary
68+
case_dict = {
69+
# Logistics
70+
"run_time_info": "T",
71+
# Computational Domain Parameters
72+
# x direction
73+
"x_domain%beg": -1.25 * D,
74+
"x_domain%end": 1.25 * D,
75+
# y direction
76+
"y_domain%beg": -2.5 * D,
77+
"y_domain%end": 2.5 * D,
78+
# z direction
79+
"z_domain%beg": -1.25 * D,
80+
"z_domain%end": 1.25 * D,
81+
"cyl_coord": "F",
82+
"m": Nx,
83+
"n": Ny,
84+
"p": Nz,
85+
"dt": dt,
86+
"t_step_start": 0,
87+
"t_step_stop": Nt,
88+
"t_step_save": t_save,
89+
# Simulation Algorithm Parameters
90+
# Only one patches are necessary, the air tube
91+
"num_patches": 1,
92+
# Use the 5 equation model
93+
"model_eqns": 2,
94+
# 6 equations model does not need the K \div(u) term
95+
"alt_soundspeed": "F",
96+
# One fluids: air
97+
"num_fluids": 1,
98+
# time step
99+
"mpp_lim": "F",
100+
# Correct errors when computing speed of sound
101+
"mixture_err": "T",
102+
# Use TVD RK3 for time marching
103+
"time_stepper": 3,
104+
# Reconstruct the primitive variables to minimize spurious
105+
# Use WENO5
106+
"weno_order": 5,
107+
"weno_eps": 1.0e-16,
108+
"weno_Re_flux": "T",
109+
"weno_avg": "T",
110+
"avg_state": 2,
111+
"null_weights": "F",
112+
"mp_weno": "T",
113+
"riemann_solver": 2,
114+
"wave_speeds": 1,
115+
# periodic bc
116+
"bc_x%beg": -3,
117+
"bc_x%end": -3,
118+
"bc_y%beg": -1,
119+
"bc_y%end": -1,
120+
"bc_z%beg": -3,
121+
"bc_z%end": -3,
122+
# Set IB to True and add 1 patch
123+
"ib": "T",
124+
"num_ibs": N_s,
125+
"viscous": "T",
126+
# Formatted Database Files Structure Parameters
127+
"format": 1,
128+
"precision": 2,
129+
"prim_vars_wrt": "T",
130+
"E_wrt": "T",
131+
"parallel_io": "T",
132+
"ib_state_wrt": "T",
133+
"fd_order": 4,
134+
# Patch: Constant Tube filled with air
135+
# Specify the cylindrical air tube grid geometry
136+
"patch_icpp(1)%geometry": 9,
137+
"patch_icpp(1)%x_centroid": 0.0,
138+
# Uniform medium density, centroid is at the center of the domain
139+
"patch_icpp(1)%y_centroid": 0.0,
140+
"patch_icpp(1)%z_centroid": 0.0,
141+
"patch_icpp(1)%length_x": 2.5 * D,
142+
"patch_icpp(1)%length_y": 5.0 * D,
143+
"patch_icpp(1)%length_z": 2.5 * D,
144+
# Specify the patch primitive variables
145+
"patch_icpp(1)%vel(1)": 0.0e00,
146+
"patch_icpp(1)%vel(2)": 0.0e00,
147+
"patch_icpp(1)%vel(3)": 0.0e00,
148+
"patch_icpp(1)%pres": P,
149+
"patch_icpp(1)%alpha_rho(1)": rho,
150+
"patch_icpp(1)%alpha(1)": 1.0e00,
151+
# Patch: Sphere Immersed Boundary
152+
# Fluids Physical Parameters
153+
"fluid_pp(1)%gamma": 1.0e00 / (gam_a - 1.0e00), # 2.50(Not 1.40)
154+
"fluid_pp(1)%pi_inf": 0,
155+
"fluid_pp(1)%Re(1)": 1.0 / mu,
156+
"collision_model": 1, # soft-sphere collision model
157+
"ib_coefficient_of_friction": 0.1,
158+
"collision_time": 20.0 * dt,
159+
"coefficient_of_restitution": 0.9, # almost perfectly elastic
160+
}
161+
162+
case_dict.update(ib_dict)
163+
164+
print(json.dumps(case_dict))

src/common/m_global_parameters_common.fpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,11 @@ module m_global_parameters_common
109109

110110
!> @name Processor coordinates and parallel-IO addressing (identical declaration across all three targets)
111111
!> @{
112-
integer, allocatable, dimension(:) :: proc_coords !< Processor coordinates in MPI_CART_COMM
113-
integer, allocatable, dimension(:) :: start_idx !< Starting cell-center index of local processor in global grid
112+
integer, allocatable, dimension(:) :: proc_coords !< Processor coordinates in MPI_CART_COMM
113+
integer, allocatable, dimension(:) :: start_idx !< Starting cell-center index of local processor in global grid
114+
integer :: num_procs_x = 1 !< Number of MPI ranks in x-direction
115+
integer :: num_procs_y = 1 !< Number of MPI ranks in y-direction
116+
integer :: num_procs_z = 1 !< Number of MPI ranks in z-direction
114117
!> @}
115118

116119
!> @name MPI info for parallel IO with Lustre file systems (identical across all three targets)

src/common/m_mpi_common.fpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,6 @@ contains
10211021
subroutine s_mpi_decompose_computational_domain
10221022

10231023
#ifdef MFC_MPI
1024-
integer :: num_procs_x, num_procs_y, num_procs_z !< Optimal number of processors in the x-, y- and z-directions
10251024
!> Non-optimal number of processors in the x-, y- and z-directions
10261025
real(wp) :: tmp_num_procs_x, tmp_num_procs_y, tmp_num_procs_z
10271026
real(wp) :: fct_min !< Processor factorization (fct) minimization parameter

src/post_process/m_start_up.fpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ module m_start_up
4141
complex(c_double_complex), allocatable :: data_cmplx(:,:,:), data_cmplx_y(:,:,:), data_cmplx_z(:,:,:)
4242
real(wp), allocatable, dimension(:,:,:) :: En_real
4343
real(wp), allocatable, dimension(:) :: En
44-
integer :: num_procs_x, num_procs_y, num_procs_z
4544
integer :: Nx, Ny, Nz, Nxloc, Nyloc, Nyloc2, Nzloc, Nf
4645
integer :: ierr
4746
integer :: MPI_COMM_CART, MPI_COMM_CART12, MPI_COMM_CART13

src/simulation/m_collisions.fpp

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ module m_collisions
2020
implicit none
2121

2222
private; public :: s_apply_collision_forces, s_initialize_collisions_module, s_finalize_collisions_module, &
23-
& f_local_rank_owns_location, f_neighborhood_ranks_own_location
23+
& f_local_rank_owns_location, f_neighborhood_ranks_own_location, ib_gbl_idx_lookup
2424
! overlap distances for computing collisions
2525
integer, allocatable, dimension(:,:) :: collision_lookup
2626
real(wp), allocatable, dimension(:,:) :: wall_overlap_distances
2727
real(wp) :: spring_stiffness, damping_parameter
2828
$:GPU_DECLARE(create='[spring_stiffness, damping_parameter]')
2929
$:GPU_DECLARE(create='[collision_lookup, wall_overlap_distances]')
3030

31+
integer, dimension(:), allocatable :: ib_gbl_idx_lookup
32+
$:GPU_DECLARE(create='[ib_gbl_idx_lookup]')
33+
3134
contains
3235

3336
subroutine s_initialize_collisions_module()
@@ -99,6 +102,9 @@ contains
99102
encoded_pid2 = collision_lookup(i, 4)
100103
call s_decode_patch_periodicity(encoded_pid1, pid1, xp1, yp1, zp1)
101104
call s_decode_patch_periodicity(encoded_pid2, pid2, xp2, yp2, zp2)
105+
pid1 = collision_lookup(i, 1)
106+
pid2 = collision_lookup(i, 2)
107+
102108
! call s_get_neighborhood_idx(pid1, pid1) ! global patch ID -> local index call s_get_neighborhood_idx(pid2, pid2)
103109
if (pid1 <= 0 .or. pid2 <= 0) cycle
104110

@@ -291,6 +297,8 @@ contains
291297
! get the decoded pairs for checking if they exist, using ii,jj,kk as dummy indices
292298
call s_decode_patch_periodicity(raw_pairs(pair_idx, 1), decoded_pairs(1), ii, jj, kk)
293299
call s_decode_patch_periodicity(raw_pairs(pair_idx, 2), decoded_pairs(2), ii, jj, kk)
300+
decoded_pairs(1) = ib_gbl_idx_lookup(decoded_pairs(1))
301+
decoded_pairs(2) = ib_gbl_idx_lookup(decoded_pairs(2))
294302

295303
! skip self-collisions (an IB cannot collide with its own periodic image)
296304
if (decoded_pairs(1) == decoded_pairs(2)) cycle
@@ -329,34 +337,46 @@ contains
329337
subroutine s_detect_ib_collisions_n2(num_considered_collisions)
330338

331339
integer, intent(out) :: num_considered_collisions
332-
integer :: pid1, pid2, encoded_pid1, encoded_pid2, current_collisions
340+
integer :: pid1, pid2, encoded_pid2, current_collisions
341+
integer :: xp_lower, xp_upper, yp_lower, yp_upper, zp_lower, zp_upper, xp, yp, zp
333342
real(wp), dimension(3) :: centroid_1, centroid_2, distance_vec
334343

335344
num_considered_collisions = 0
336345

337-
$:GPU_PARALLEL_LOOP(private='[pid1, pid2, centroid_1, centroid_2, distance_vec, current_collisions]', &
338-
& copy='[num_considered_collisions]')
346+
call s_get_periodicities(xp_lower, xp_upper, yp_lower, yp_upper, zp_lower, zp_upper)
347+
348+
$:GPU_PARALLEL_LOOP(private='[pid1, pid2, encoded_pid2, centroid_1, centroid_2, xp, yp, zp, distance_vec, &
349+
& current_collisions]', copyin='[xp_lower, xp_upper, yp_lower, yp_upper, zp_lower, zp_upper]', copy='[num_considered_collisions]')
339350
do pid1 = 1, num_ibs - 1
351+
centroid_1 = [patch_ib(pid1)%x_centroid, patch_ib(pid1)%y_centroid, 0._wp]
352+
if (num_dims == 3) centroid_1(3) = patch_ib(pid1)%z_centroid
340353
do pid2 = pid1 + 1, num_ibs
341-
centroid_1 = [patch_ib(pid1)%x_centroid, patch_ib(pid1)%y_centroid, 0._wp]
342-
centroid_2 = [patch_ib(pid2)%x_centroid, patch_ib(pid2)%y_centroid, 0._wp]
343-
if (num_dims == 3) then
344-
centroid_1(3) = patch_ib(pid1)%z_centroid
345-
centroid_2(3) = patch_ib(pid2)%z_centroid
346-
end if
347-
distance_vec = centroid_2 - centroid_1
348-
349-
if (norm2(distance_vec) < patch_ib(pid1)%radius + patch_ib(pid2)%radius) then
350-
$:GPU_ATOMIC(atomic='capture')
351-
num_considered_collisions = num_considered_collisions + 1
352-
current_collisions = num_considered_collisions
353-
$:END_GPU_ATOMIC_CAPTURE()
354-
355-
collision_lookup(current_collisions, 1) = pid1
356-
collision_lookup(current_collisions, 2) = pid2
357-
collision_lookup(current_collisions, 3) = pid1
358-
collision_lookup(current_collisions, 4) = pid2
359-
end if
354+
periodic_search: do xp = xp_lower, xp_upper
355+
do yp = yp_lower, yp_upper
356+
do zp = zp_lower, zp_upper
357+
centroid_2(1) = patch_ib(pid2)%x_centroid + real(xp, wp)*(x_domain%end - x_domain%beg)
358+
centroid_2(2) = patch_ib(pid2)%y_centroid + real(yp, wp)*(y_domain%end - y_domain%beg)
359+
if (num_dims == 3) centroid_2(3) = patch_ib(pid2)%z_centroid + real(zp, &
360+
& wp)*(z_domain%end - z_domain%beg)
361+
distance_vec = centroid_2 - centroid_1
362+
363+
if (norm2(distance_vec) < patch_ib(pid1)%radius + patch_ib(pid2)%radius) then
364+
$:GPU_ATOMIC(atomic='capture')
365+
num_considered_collisions = num_considered_collisions + 1
366+
current_collisions = num_considered_collisions
367+
$:END_GPU_ATOMIC_CAPTURE()
368+
369+
call s_encode_patch_periodicity(patch_ib(pid2)%gbl_patch_id, xp, yp, zp, encoded_pid2)
370+
371+
collision_lookup(current_collisions, 1) = pid1
372+
collision_lookup(current_collisions, 2) = pid2
373+
collision_lookup(current_collisions, 3) = patch_ib(pid1)%gbl_patch_id
374+
collision_lookup(current_collisions, 4) = encoded_pid2
375+
exit periodic_search
376+
end if
377+
end do
378+
end do
379+
end do periodic_search
360380
end do
361381
end do
362382
$:END_GPU_PARALLEL_LOOP()

src/simulation/m_derived_variables.fpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ module m_derived_variables
2121
private; public :: s_initialize_derived_variables_module, s_initialize_derived_variables, s_compute_derived_variables, &
2222
& s_finalize_derived_variables_module
2323

24-
! fd_coeff_x, fd_coeff_y, fd_coeff_z: declared in m_global_parameters so m_viscous can see them too
25-
2624
! @name Variables for computing acceleration
2725
!> @{
2826
real(wp), public, allocatable, dimension(:,:,:) :: accel_mag

src/simulation/m_ib_patches.fpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module m_ib_patches
2323
implicit none
2424

2525
private; public :: s_apply_ib_patches, s_update_ib_rotation_matrix, s_instantiate_STL_models, s_decode_patch_periodicity, &
26-
& s_initialize_ib_airfoils
26+
& s_encode_patch_periodicity, s_initialize_ib_airfoils, s_get_periodicities
2727

2828
contains
2929

@@ -48,8 +48,9 @@ contains
4848
real(wp), dimension(3) :: center, xyz_local, length
4949
real(wp) :: radius, eta
5050

51-
! 3D Patch Geometries
51+
$:GPU_UPDATE(host='[patch_ib(1:num_ibs)]')
5252

53+
! 3D Patch Geometries
5354
if (num_dims == 3) then
5455
call s_get_periodicities(xp_lower, xp_upper, yp_lower, yp_upper, zp_lower, zp_upper)
5556
do xp = xp_lower, xp_upper
@@ -678,14 +679,17 @@ contains
678679
#:endfor
679680
680681
! z only if 3D
681-
if (present(zp_lower) .and. p /= 0) then
682+
if (present(zp_lower) .and. num_dims == 3) then
682683
if (ib_bc_z%beg == BC_PERIODIC) then
683684
zp_lower = -1
684685
zp_upper = 1
685686
else
686687
zp_lower = 0
687688
zp_upper = 0
688689
end if
690+
else if (present(zp_lower)) then
691+
zp_lower = 0
692+
zp_upper = 0
689693
end if
690694
691695
end subroutine s_get_periodicities

0 commit comments

Comments
 (0)