Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions examples/2D_ibm_circle_periodic/case.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
import json
import math
import numpy as np

gam_a = 1.4

# sphere diameter
D = 0.1

# circle density
rho_c = 200

# domain length
L = 10 * D

# mach number
M = 1.2

# reynolds number
Re = 400.0

# pressure
P = 101325

# density
rho = 1.0

# fluid velocity
v1 = M * np.sqrt(gam_a * P / rho)

# dynamic viscosity
mu = rho * v1 * D / Re

dt = 1.0e-06
Nt = 5000
t_save = 20

# to fully resolve requires 40-60 cells across circle diameter
Nx = 511
Ny = Nx
Nz = 0

# immersed boundary dictionary
ib_dict = {}
ib_dict.update(
{
f"patch_ib({1})%geometry": 2,
f"patch_ib({1})%x_centroid": 0.5 * L,
f"patch_ib({1})%y_centroid": 0.5 * L,
f"patch_ib({1})%radius": D / 2,
f"patch_ib({1})%slip": "F",
f"patch_ib({1})%moving_ibm": 0,
f"patch_ib({1})%mass": rho_c * np.pi * (D / 2.0) ** 2,
}
)

# Configuring case dictionary
case_dict = {
# Logistics
"run_time_info": "T",
# Computational Domain Parameters
# x direction
"x_domain%beg": -5.0 * D,
"x_domain%end": 5.0 * D,
# y direction
"y_domain%beg": -5.0 * D,
"y_domain%end": 5.0 * D,
"cyl_coord": "F",
"m": Nx,
"n": Ny,
"p": Nz,
"dt": dt,
"t_step_start": 0,
"t_step_stop": Nt,
"t_step_save": t_save,
# Simulation Algorithm Parameters
# Only one patch is necessary for one fluid
"num_patches": 1,
# Use the 5 equation model
"model_eqns": 2,
# 6 equations model does not need the K \div(u) term
"alt_soundspeed": "F",
# One fluids: air
"num_fluids": 1,
# time step
"mpp_lim": "F",
# Correct errors when computing speed of sound
"mixture_err": "T",
# Use TVD RK3 for time marching
"time_stepper": 3,
# Reconstruct the primitive variables to minimize spurious
# Use WENO5
"weno_order": 5,
"weno_eps": 1.0e-14,
"weno_Re_flux": "T",
"weno_avg": "T",
"avg_state": 2,
"mapped_weno": "T",
"null_weights": "F",
"mp_weno": "T",
"riemann_solver": 2,
"wave_speeds": 1,
# periodic bc
"bc_x%beg": -1,
"bc_x%end": -1,
"bc_y%beg": -1,
"bc_y%end": -1,
# Set IB to True and add 1 patch for every sphere
"ib": "T",
"num_ibs": 1,
"viscous": "T",
# Formatted Database Files Structure Parameters
"format": 1,
"precision": 2,
"prim_vars_wrt": "T",
"E_wrt": "T",
"parallel_io": "T",
# Patch: square filled with air
"patch_icpp(1)%geometry": 3,
# Uniform properties, centroid is at the center of the domain
"patch_icpp(1)%x_centroid": 0.0,
"patch_icpp(1)%y_centroid": 0.0,
"patch_icpp(1)%length_x": 10 * D,
"patch_icpp(1)%length_y": 10 * D,
# Specify the patch primitive variables
"patch_icpp(1)%vel(1)": v1,
"patch_icpp(1)%vel(2)": 0.0,
"patch_icpp(1)%pres": P,
"patch_icpp(1)%alpha_rho(1)": rho,
"patch_icpp(1)%alpha(1)": 1.0e00,
# Fluids Physical Parameters
"fluid_pp(1)%gamma": 1.0e00 / (gam_a - 1.0e00), # 2.50(Not 1.40)
"fluid_pp(1)%pi_inf": 0,
"fluid_pp(1)%Re(1)": 1.0 / mu,
# ibs wrap around domain
"periodic_ibs": "T",
}

case_dict.update(ib_dict)

print(json.dumps(case_dict))
150 changes: 150 additions & 0 deletions examples/3D_ibm_sphere_periodic/case.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import json
import math
import numpy as np

gam_a = 1.4

# sphere diameter
D = 0.1

# sphere density
rho_s = 200

# domain length
L = 10 * D

# mach number
M = 1.2

# reynolds number
Re = 400.0

# pressure
P = 101325

# density
rho = 1.0

# fluid velocity
v1 = M * np.sqrt(gam_a * P / rho)

# dynamic viscosity
mu = rho * v1 * D / Re

dt = 2.0e-06
Nt = 2000
t_save = Nt // 250

# to fully resolve requires 40-60 cells across sphere diameter
Nx = 127
Ny = Nx
Nz = Ny

# immersed boundary dictionary
ib_dict = {}
ib_dict.update(
{
f"patch_ib({1})%geometry": 8,
f"patch_ib({1})%x_centroid": 0.5 * L,
f"patch_ib({1})%y_centroid": 0.5 * L,
f"patch_ib({1})%z_centroid": 0.5 * L,
f"patch_ib({1})%radius": D / 2,
f"patch_ib({1})%slip": "F",
f"patch_ib({1})%moving_ibm": 0,
f"patch_ib({1})%mass": rho_s * 4.0 / 3.0 * np.pi * (D / 2.0) ** 3,
}
)

# Configuring case dictionary
case_dict = {
# Logistics
"run_time_info": "T",
# Computational Domain Parameters
# x direction
"x_domain%beg": -5.0 * D,
"x_domain%end": 5.0 * D,
# y direction
"y_domain%beg": -5.0 * D,
"y_domain%end": 5.0 * D,
# z direction
"z_domain%beg": -5.0 * D,
"z_domain%end": 5.0 * D,
"cyl_coord": "F",
"m": Nx,
"n": Ny,
"p": Nz,
"dt": dt,
"t_step_start": 0,
"t_step_stop": Nt,
"t_step_save": t_save,
# Simulation Algorithm Parameters
# Only one patch is necessary for one fluid
"num_patches": 1,
# Use the 5 equation model
"model_eqns": 2,
# 6 equations model does not need the K \div(u) term
"alt_soundspeed": "F",
# One fluids: air
"num_fluids": 1,
# time step
"mpp_lim": "F",
# Correct errors when computing speed of sound
"mixture_err": "T",
# Use TVD RK3 for time marching
"time_stepper": 3,
# Reconstruct the primitive variables to minimize spurious
# Use WENO5
"weno_order": 5,
"weno_eps": 1.0e-14,
"weno_Re_flux": "T",
"weno_avg": "T",
"avg_state": 2,
"mapped_weno": "T",
"null_weights": "F",
"mp_weno": "T",
"riemann_solver": 2,
"wave_speeds": 1,
# periodic bc
"bc_x%beg": -1,
"bc_x%end": -1,
"bc_y%beg": -1,
"bc_y%end": -1,
"bc_z%beg": -1,
"bc_z%end": -1,
# Set IB to True and add 1 patch for every sphere
"ib": "T",
"num_ibs": 1,
"viscous": "T",
# Formatted Database Files Structure Parameters
"format": 1,
"precision": 2,
"prim_vars_wrt": "T",
"E_wrt": "T",
"parallel_io": "T",
# Patch: cube filled with air
"patch_icpp(1)%geometry": 9,
# Uniform properties, centroid is at the center of the domain
"patch_icpp(1)%x_centroid": 0.0,
"patch_icpp(1)%y_centroid": 0.0,
"patch_icpp(1)%z_centroid": 0.0,
"patch_icpp(1)%length_x": 10 * D,
"patch_icpp(1)%length_y": 10 * D,
"patch_icpp(1)%length_z": 10 * D,
# Specify the patch primitive variables
"patch_icpp(1)%vel(1)": v1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: The value assigned to the velocity entry is a NumPy scalar (v1 is created via np.sqrt), which json.dumps cannot serialize and will raise a TypeError; casting it to a native Python float before inserting into the dictionary avoids this runtime failure. [type error]

Severity Level: Major ⚠️
- ❌ Example script fails to output JSON configuration.
- ❌ Running example terminated with TypeError traceback.
- ⚠️ Prevents straightforward reproduction of periodic-IB example.
- ⚠️ Does not alter core solver algorithms or binaries.
Suggested change
"patch_icpp(1)%vel(1)": v1,
"patch_icpp(1)%vel(1)": float(v1),
Steps of Reproduction ✅
1. Run the example script directly: execute `python
examples/3D_ibm_sphere_periodic/case.py`. The module's top-level code runs and builds
`case_dict` (file `examples/3D_ibm_sphere_periodic/case.py` lines 1-150).

2. During module execution the velocity is computed at
`examples/3D_ibm_sphere_periodic/case.py:29` where `v1 = M * np.sqrt(gam_a * P / rho)`
(NumPy returns a numpy scalar).

3. That numpy scalar `v1` is inserted into `case_dict` under the key
`"patch_icpp(1)%vel(1)"` at `examples/3D_ibm_sphere_periodic/case.py:134`.

4. The final statement `print(json.dumps(case_dict))` at
`examples/3D_ibm_sphere_periodic/case.py:150` calls `json.dumps`; JSON encoder encounters
the numpy scalar at the velocity key and raises TypeError (e.g., "Object of type float64
is not JSON serializable"), aborting the script.
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** examples/3D_ibm_sphere_periodic/case.py
**Line:** 134:134
**Comment:**
	*Type Error: The value assigned to the velocity entry is a NumPy scalar (`v1` is created via `np.sqrt`), which `json.dumps` cannot serialize and will raise a TypeError; casting it to a native Python float before inserting into the dictionary avoids this runtime failure.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.

"patch_icpp(1)%vel(2)": 0.0e00,
"patch_icpp(1)%vel(3)": 0.0e00,
"patch_icpp(1)%pres": P,
"patch_icpp(1)%alpha_rho(1)": rho,
"patch_icpp(1)%alpha(1)": 1.0e00,
# Fluids Physical Parameters
"fluid_pp(1)%gamma": 1.0e00 / (gam_a - 1.0e00), # 2.50(Not 1.40)
"fluid_pp(1)%pi_inf": 0,
"fluid_pp(1)%Re(1)": 1.0 / mu,
# ibs wrap around domain
"periodic_ibs": "T",
}

case_dict.update(ib_dict)

print(json.dumps(case_dict))
2 changes: 2 additions & 0 deletions src/post_process/m_global_parameters.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ module m_global_parameters
!! Starting cell-center index of local processor in global grid

integer :: num_ibs !< Number of immersed boundaries
logical :: periodic_ibs !< Periodically wrap immersed boundaries around domain

#ifdef MFC_MPI

Expand Down Expand Up @@ -541,6 +542,7 @@ contains

! IBM
num_ibs = dflt_int
periodic_ibs = .false.

! Output partial domain
output_partial_domain = .false.
Expand Down
2 changes: 1 addition & 1 deletion src/post_process/m_mpi_proxy.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ contains
& 'adv_n', 'ib', 'cfl_adap_dt', 'cfl_const_dt', 'cfl_dt', &
& 'surface_tension', 'hyperelasticity', 'bubbles_lagrange', &
& 'output_partial_domain', 'relativity', 'cont_damage', 'bc_io', &
& 'down_sample','fft_wrt', 'hyper_cleaning' ]
& 'down_sample','fft_wrt', 'hyper_cleaning', 'periodic_ibs' ]
call MPI_BCAST(${VAR}$, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD, ierr)
#:endfor

Expand Down
2 changes: 1 addition & 1 deletion src/post_process/m_start_up.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ contains
lag_rad_wrt, lag_rvel_wrt, lag_r0_wrt, lag_rmax_wrt, &
lag_rmin_wrt, lag_dphidt_wrt, lag_pres_wrt, lag_mv_wrt, &
lag_mg_wrt, lag_betaT_wrt, lag_betaC_wrt, &
alpha_rho_e_wrt
alpha_rho_e_wrt, periodic_ibs

! Inquiring the status of the post_process.inp file
file_loc = 'post_process.inp'
Expand Down
19 changes: 19 additions & 0 deletions src/pre_process/m_global_parameters.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ module m_global_parameters
logical :: ib !< Turn immersed boundaries on
integer :: num_ibs !< Number of immersed boundaries
integer :: Np
logical :: periodic_ibs !< Periodically wrap immersed boundaries around domain

type(ib_patch_parameters), dimension(num_patches_max) :: patch_ib

Expand Down Expand Up @@ -300,6 +301,9 @@ module m_global_parameters
logical :: fft_wrt
logical :: dummy !< AMDFlang workaround: keep a dummy logical to avoid a compiler case-optimization bug when a parameter+GPU-kernel conditional is false

!< global domain bounds
real(wp), allocatable, dimension(:, :) :: domain_glb

contains

!> Assigns default values to user inputs prior to reading
Expand Down Expand Up @@ -541,6 +545,7 @@ contains
! Immersed Boundaries
ib = .false.
num_ibs = dflt_int
periodic_ibs = .false.

do i = 1, num_patches_max
patch_ib(i)%geometry = dflt_int
Expand Down Expand Up @@ -969,6 +974,18 @@ contains
allocate (logic_grid(0:m, 0:n, 0:p))
end if

allocate (domain_glb(num_dims, 2))
domain_glb(1, 1) = x_domain%beg
domain_glb(1, 2) = x_domain%end
if (n > 0) then ! 2D
domain_glb(2, 1) = y_domain%beg
domain_glb(2, 2) = y_domain%end
if (p > 0) then ! 3D
domain_glb(3, 1) = z_domain%beg
domain_glb(3, 2) = z_domain%end
end if
end if

end subroutine s_initialize_global_parameters_module

impure subroutine s_initialize_parallel_io
Expand Down Expand Up @@ -1024,6 +1041,8 @@ contains

deallocate (proc_coords)

deallocate (domain_glb)

#ifdef MFC_MPI

if (parallel_io) then
Expand Down
3 changes: 2 additions & 1 deletion src/pre_process/m_mpi_proxy.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ contains
& 'cfl_const_dt', 'cfl_dt', 'surface_tension', &
& 'hyperelasticity', 'pre_stress', 'elliptic_smoothing', 'viscous',&
& 'bubbles_lagrange', 'bc_io', 'mhd', 'relativity', 'cont_damage', &
& 'igr', 'down_sample', 'simplex_perturb','fft_wrt', 'hyper_cleaning' ]
& 'igr', 'down_sample', 'simplex_perturb','fft_wrt', 'hyper_cleaning', &
& 'periodic_ibs' ]
call MPI_BCAST(${VAR}$, 1, MPI_LOGICAL, 0, MPI_COMM_WORLD, ierr)
#:endfor
call MPI_BCAST(fluid_rho(1), num_fluids_max, MPI_LOGICAL, 0, MPI_COMM_WORLD, ierr)
Expand Down
2 changes: 1 addition & 1 deletion src/pre_process/m_start_up.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ contains
viscous, bubbles_lagrange, num_bc_patches, &
patch_bc, Bx0, relativity, cont_damage, igr, igr_order, &
down_sample, recon_type, muscl_order, hyper_cleaning, &
simplex_perturb, simplex_params, fft_wrt
simplex_perturb, simplex_params, fft_wrt, periodic_ibs

! Inquiring the status of the pre_process.inp file
file_loc = 'pre_process.inp'
Expand Down
Loading
Loading