Skip to content

Commit 03883dc

Browse files
committed
Fixed IBM force and added visualization
1 parent 2e63f76 commit 03883dc

File tree

8 files changed

+1015
-424
lines changed

8 files changed

+1015
-424
lines changed

.gitignore

+9-1
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,12 @@ checkpoints/*
154154
# Ignore Python packaging build directories
155155
dist/
156156
build/
157-
*.egg-info/
157+
*.egg-info/
158+
159+
# USD files
160+
*.usd
161+
*.usda
162+
*.usdc
163+
*.usd.gz
164+
*.usd.zip
165+
*.usd.bz2

examples/cfd/flow_past_sphere_ibm.py

-242
This file was deleted.

examples/ibm/drone.py examples/ibm/uav.py

+26-32
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,6 @@ def save_usd_vorticity(
166166
usd_mesh.GetDisplayColorAttr().Set(colors.numpy().tolist(), time=timestep // post_process_interval)
167167
UsdGeom.Primvar(usd_mesh.GetDisplayColorAttr()).SetInterpolation("vertex")
168168

169-
# usd_stage.SetStartTimeCode(0)
170-
# usd_stage.SetEndTimeCode(timestep)
171-
# usd_stage.SetTimeCodesPerSecond(24)
172-
173-
# usd_stage.Save()
174-
175169
print(f"Vorticity visualization at timestep {timestep}:")
176170
print(f" Number of vertices: {len(vertices)}")
177171
print(f" Number of triangles: {tri_count}")
@@ -252,9 +246,9 @@ def save_usd_q_criterion(timestep, bc_mask, f_current, grid_shape, usd_mesh, q_c
252246
print(f" Vorticity range: [{vorticity_min:.6f}, {vorticity_max:.6f}]")
253247

254248

255-
# -------------------------- Function to Save Drone Body and Blades to USD --------------------------
256-
def save_usd_drone_and_blades(
257-
timestep, post_process_interval, vertices_wp, num_body_vertices, body_faces_np, blades_faces_np, usd_drone_body, usd_drone_blades, usd_stage
249+
# -------------------------- Function to Save UAV Body and Blades to USD --------------------------
250+
def save_usd_uav_and_blades(
251+
timestep, post_process_interval, vertices_wp, num_body_vertices, body_faces_np, blades_faces_np, usd_uav_body, usd_uav_blades, usd_stage
258252
):
259253
# Get vertices and adjust for boundary condition offset
260254
body_vertices = vertices_wp.numpy()[:num_body_vertices]
@@ -265,20 +259,20 @@ def save_usd_drone_and_blades(
265259
blades_vertices = blades_vertices - 20
266260

267261
# Process body mesh
268-
drone_body_tri_count = len(body_faces_np)
269-
usd_drone_body.GetPointsAttr().Set(body_vertices.tolist(), time=timestep // post_process_interval)
270-
usd_drone_body.GetFaceVertexCountsAttr().Set(Vt.IntArray([3] * drone_body_tri_count), time=timestep // post_process_interval)
271-
usd_drone_body.GetFaceVertexIndicesAttr().Set(Vt.IntArray(body_faces_np.flatten().tolist()), time=timestep // post_process_interval)
262+
uav_body_tri_count = len(body_faces_np)
263+
usd_uav_body.GetPointsAttr().Set(body_vertices.tolist(), time=timestep // post_process_interval)
264+
usd_uav_body.GetFaceVertexCountsAttr().Set(Vt.IntArray([3] * uav_body_tri_count), time=timestep // post_process_interval)
265+
usd_uav_body.GetFaceVertexIndicesAttr().Set(Vt.IntArray(body_faces_np.flatten().tolist()), time=timestep // post_process_interval)
272266

273267
# Process blades mesh
274268
# Rebase blade face indices to the local blade vertex array
275269
blades_faces_np_corrected = blades_faces_np - num_body_vertices
276-
drone_blades_tri_count = len(blades_faces_np_corrected)
277-
usd_drone_blades.GetPointsAttr().Set(blades_vertices.tolist(), time=timestep // post_process_interval)
278-
usd_drone_blades.GetFaceVertexCountsAttr().Set(Vt.IntArray([3] * drone_blades_tri_count), time=timestep // post_process_interval)
279-
usd_drone_blades.GetFaceVertexIndicesAttr().Set(Vt.IntArray(blades_faces_np_corrected.flatten().tolist()), time=timestep // post_process_interval)
270+
uav_blades_tri_count = len(blades_faces_np_corrected)
271+
usd_uav_blades.GetPointsAttr().Set(blades_vertices.tolist(), time=timestep // post_process_interval)
272+
usd_uav_blades.GetFaceVertexCountsAttr().Set(Vt.IntArray([3] * uav_blades_tri_count), time=timestep // post_process_interval)
273+
usd_uav_blades.GetFaceVertexIndicesAttr().Set(Vt.IntArray(blades_faces_np_corrected.flatten().tolist()), time=timestep // post_process_interval)
280274

281-
print(f"Drone body and blades USD updated at timestep {timestep}")
275+
print(f"UAV body and blades USD updated at timestep {timestep}")
282276

283277

284278
# -------------------------- Mesh Loading and IBM Setup --------------------------
@@ -404,7 +398,6 @@ def setup_stepper(grid, boundary_conditions, lbm_omega):
404398
)
405399

406400

407-
# -------------------------- Post-Processing (Extended with USD Output using Q Criterion) --------------------------
408401
def post_process(
409402
i,
410403
post_process_interval,
@@ -480,7 +473,7 @@ def post_process(
480473

481474

482475
# -------------------------- Simulation Parameters --------------------------
483-
grid_shape = (100, 200, 200)
476+
grid_shape = (512, 512, 512)
484477
u_max = 0.01
485478
num_steps = 100000
486479
post_process_interval = 100
@@ -523,8 +516,8 @@ def post_process(
523516
usd_file = os.path.join(usd_output_directory, "output.usd")
524517
usd_stage = Usd.Stage.CreateNew(usd_file)
525518
usd_mesh = UsdGeom.Mesh.Define(usd_stage, "/World/FluidField")
526-
usd_drone_body = UsdGeom.Mesh.Define(usd_stage, "/World/DroneBody")
527-
usd_drone_blades = UsdGeom.Mesh.Define(usd_stage, "/World/DroneBlades")
519+
usd_uav_body = UsdGeom.Mesh.Define(usd_stage, "/World/UAVBody")
520+
usd_uav_blades = UsdGeom.Mesh.Define(usd_stage, "/World/UAVBlades")
528521

529522
mesh_data = load_and_prepare_meshes(grid_shape)
530523
vertices_wp = mesh_data["vertices_wp"]
@@ -611,26 +604,27 @@ def rotate_blades(
611604

612605

613606
start_time = time.time()
614-
progress_bar = tqdm(range(num_steps), desc="Simulation Progress", unit="steps")
615607

616-
for i in progress_bar:
617-
f_0, f_1 = stepper(
608+
for i in range(num_steps):
609+
f_0, f_1, lag_forces = stepper(
618610
f_0,
619611
f_1,
620612
vertices_wp,
621613
vertex_areas_wp,
622614
velocities_wp,
623-
rotate_blades,
624615
bc_mask,
625616
missing_mask,
626617
omega,
627618
i,
628619
)
629620
f_0, f_1 = f_1, f_0
630621

631-
if (i + 1) % print_interval == 0:
632-
elapsed_time = time.time() - start_time
633-
progress_bar.set_postfix({"Time elapsed": f"{elapsed_time:.2f}s"})
622+
# Update solid velocities and positions
623+
wp.launch(
624+
kernel=rotate_blades,
625+
dim=vertices_wp.shape[0],
626+
inputs=[i, lag_forces, vertices_wp, velocities_wp],
627+
)
634628

635629
if i % post_process_interval == 0 or i == num_steps - 1:
636630
post_process(
@@ -649,15 +643,15 @@ def rotate_blades(
649643
vorticity_operator,
650644
usd_stage,
651645
)
652-
save_usd_drone_and_blades(
646+
save_usd_uav_and_blades(
653647
i,
654648
post_process_interval,
655649
vertices_wp,
656650
num_body_vertices,
657651
body_faces_np,
658652
blades_faces_np,
659-
usd_drone_body,
660-
usd_drone_blades,
653+
usd_uav_body,
654+
usd_uav_blades,
661655
usd_stage,
662656
)
663657

0 commit comments

Comments
 (0)