Skip to content

Commit

Permalink
Fixing the syntax error in Warp when bc list is empty. When empty, pe…
Browse files Browse the repository at this point in the history
…rf is really bad, otherwise normal.
  • Loading branch information
hsalehipour committed Aug 30, 2024
1 parent f16c4b9 commit 2a3e6c6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/cfd/flow_past_sphere_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def post_process(self, i):

fields = {"u_magnitude": u_magnitude, "u_x": u[0], "u_y": u[1], "u_z": u[2], "rho": rho[0]}

save_fields_vtk(fields, timestep=i)
# save_fields_vtk(fields, timestep=i)
save_image(fields["u_magnitude"][:, self.grid_shape[1] // 2, :], timestep=i)


Expand Down
16 changes: 12 additions & 4 deletions xlb/operator/stepper/nse_stepper.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from xlb.operator.macroscopic import Macroscopic
from xlb.operator.stepper import Stepper
from xlb.operator.boundary_condition.boundary_condition import ImplementationStep
from xlb.operator.boundary_condition import DoNothingBC as DummyBC


class IncompressibleNavierStokesStepper(Stepper):
Expand Down Expand Up @@ -378,17 +379,24 @@ def warp_implementation(self, f_0, f_1, boundary_map, missing_mask, timestep):
setattr(bc_struct, "id_" + bc_name, bc_to_id[bc_name])
active_bc_list.append("id_" + bc_name)

# Setting the Struct attributes and active BC classes based on the BC class names
bc_fallback = self.boundary_conditions[0]
# TODO: what if self.boundary_conditions is an empty list e.g. when we have periodic BC all around!
# Check if boundary_conditions is an empty list (e.g. all periodic and no BC)
# TODO: There is a huge issue here with perf. when boundary_conditions list
# is empty and is initialized with a dummy BC. If it is not empty, no perf
# loss ocurrs. The following code at least prevents syntax error for periodic examples.
if self.boundary_conditions:
bc_dummy = self.boundary_conditions[0]
else:
bc_dummy = DummyBC()

# Setting the Struct attributes for inactive BC classes
for var in vars(bc_struct):
if var not in active_bc_list and not var.startswith("_"):
# set unassigned boundaries to the maximum integer in uint8
setattr(bc_struct, var, 255)

# Assing a fall-back BC for inactive BCs. This is just to ensure Warp codegen does not
# produce error when a particular BC is not used in an example.
setattr(self, var.replace("id_", ""), bc_fallback)
setattr(self, var.replace("id_", ""), bc_dummy)

# Launch the warp kernel
wp.launch(
Expand Down

0 comments on commit 2a3e6c6

Please sign in to comment.