-
Notifications
You must be signed in to change notification settings - Fork 132
Periodic Immersed Boundary Wrapping for Circular and Spherical Geometries #1117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
conraddelgado
wants to merge
13
commits into
MFlowCode:master
Choose a base branch
from
conraddelgado:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,041
−73
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8906810
periodic ib wrapping for spheres
conraddelgado 837b18b
periodic ib wrap for circle geometry + tests
conraddelgado 3441ef4
Merge branch 'MFlowCode:master' into master
conraddelgado 6338eea
formatting
conraddelgado 1aa4b08
Merge branch 'master' of github.com:conraddelgado/periodic_ibs
conraddelgado 8571caf
regenerate test data, gpu update
conraddelgado 85903b3
formatting
conraddelgado 067a337
r2 on GPU
conraddelgado 19341ab
Merge branch 'master' into master
sbryngelson f6b7d1e
refactor periodic centroid projection into a single subroutine
conraddelgado 6c3975a
Merge branch 'master' of github.com:conraddelgado/periodic_ibs
conraddelgado 4ab107d
moved domain_glb to global_parameters
conraddelgado d371d40
Merge branch 'master' into master
conraddelgado File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||||||
conraddelgado marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| # 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, | ||||||
conraddelgado marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| } | ||||||
| ) | ||||||
|
|
||||||
| # 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, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The value assigned to the velocity entry is a NumPy scalar ( Severity Level: Major
|
||||||
| "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.
conraddelgado marked this conversation as resolved.
Show resolved
Hide resolved
conraddelgado marked this conversation as resolved.
Show resolved
Hide resolved
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.