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))
Loading
Loading