Skip to content

Commit

Permalink
addressing PR reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
hsalehipour committed Oct 18, 2024
1 parent 8f869d2 commit cee77b9
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 83 deletions.
25 changes: 3 additions & 22 deletions examples/cfd/flow_past_sphere_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def _setup(self, omega):

def define_boundary_indices(self):
box = self.grid.bounding_box_indices()
box_noedge = self.grid.bounding_box_indices(remove_edges=True)
inlet = box_noedge["left"]
outlet = box_noedge["right"]
box_no_edge = self.grid.bounding_box_indices(remove_edges=True)
inlet = box_no_edge["left"]
outlet = box_no_edge["right"]
walls = [box["bottom"][i] + box["top"][i] + box["front"][i] + box["back"][i] for i in range(self.velocity_set.d)]
walls = np.unique(np.array(walls), axis=-1).tolist()

Expand Down Expand Up @@ -101,8 +101,6 @@ def run(self, num_steps, post_process_interval=100):
self.f_0, self.f_1 = self.stepper(self.f_0, self.f_1, self.bc_mask, self.missing_mask, i)
self.f_0, self.f_1 = self.f_1, self.f_0

if i == 0:
self.check_boundary_mask()
if i % post_process_interval == 0 or i == num_steps - 1:
self.post_process(i)
end_time = time.time()
Expand Down Expand Up @@ -132,23 +130,6 @@ def post_process(self, i):

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

def check_boundary_mask(self):
# Write the results. We'll use JAX backend for the post-processing
if not isinstance(self.f_0, jnp.ndarray):
bmask = wp.to_jax(self.bc_mask)[0]
else:
bmask = self.bc_mask[0]

# save_fields_vtk(fields, timestep=i)
save_image(bmask[0, :, :], prefix="00_left")
save_image(bmask[self.grid_shape[0] - 1, :, :], prefix="00_right")
save_image(bmask[:, :, self.grid_shape[2] - 1], prefix="00_top")
save_image(bmask[:, :, 0], prefix="00_bottom")
save_image(bmask[:, 0, :], prefix="00_front")
save_image(bmask[:, self.grid_shape[1] - 1, :], prefix="00_back")
save_image(bmask[:, self.grid_shape[1] // 2, :], prefix="00_middle")


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions examples/cfd/lid_driven_cavity_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def _setup(self, omega):

def define_boundary_indices(self):
box = self.grid.bounding_box_indices()
box_noedge = self.grid.bounding_box_indices(remove_edges=True)
lid = box_noedge["top"]
box_no_edge = self.grid.bounding_box_indices(remove_edges=True)
lid = box_no_edge["top"]
walls = [box["bottom"][i] + box["left"][i] + box["right"][i] for i in range(self.velocity_set.d)]
walls = np.unique(np.array(walls), axis=-1).tolist()
return lid, walls
Expand Down
6 changes: 3 additions & 3 deletions examples/cfd/windtunnel_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def voxelize_stl(self, stl_filename, length_lbm_unit):

def define_boundary_indices(self):
box = self.grid.bounding_box_indices()
box_noedge = self.grid.bounding_box_indices(remove_edges=True)
inlet = box_noedge["left"]
outlet = box_noedge["right"]
box_no_edge = self.grid.bounding_box_indices(remove_edges=True)
inlet = box_no_edge["left"]
outlet = box_no_edge["right"]
walls = [box["bottom"][i] + box["top"][i] + box["front"][i] + box["back"][i] for i in range(self.velocity_set.d)]
walls = np.unique(np.array(walls), axis=-1).tolist()

Expand Down
4 changes: 2 additions & 2 deletions examples/performance/mlups_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def create_grid_and_fields(cube_edge):

def define_boundary_indices(grid):
box = grid.bounding_box_indices()
box_noedge = grid.bounding_box_indices(remove_edges=True)
lid = box_noedge["top"]
box_no_edge = grid.bounding_box_indices(remove_edges=True)
lid = box_no_edge["top"]
walls = [box["bottom"][i] + box["left"][i] + box["right"][i] + box["front"][i] + box["back"][i] for i in range(len(grid.shape))]
return lid, walls

Expand Down
2 changes: 1 addition & 1 deletion xlb/distribute/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .distribute import distribute as distribute
from .distribute import distribute
4 changes: 2 additions & 2 deletions xlb/experimental/ooc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from xlb.experimental.ooc.out_of_core import OOCmap as OOCmap
from xlb.experimental.ooc.ooc_array import OOCArray as OOCArray
from xlb.experimental.ooc.out_of_core import OOCmap
from xlb.experimental.ooc.ooc_array import OOCArray
6 changes: 3 additions & 3 deletions xlb/helper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from xlb.helper.nse_solver import create_nse_fields as create_nse_fields
from xlb.helper.initializers import initialize_eq as initialize_eq
from xlb.helper.check_boundary_overlaps import check_bc_overlaps as check_bc_overlaps
from xlb.helper.nse_solver import create_nse_fields
from xlb.helper.initializers import initialize_eq
from xlb.helper.check_boundary_overlaps import check_bc_overlaps
2 changes: 2 additions & 0 deletions xlb/helper/check_boundary_overlaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def check_bc_overlaps(bclist, dim, backend):
if index_arr.shape[-1] != len(bc.indices[0]):
if backend == ComputeBackend.WARP:
raise ValueError(f"Boundary condition {bc.__class__.__name__} has duplicate indices!")
print(f"WARNING: there are duplicate indices in {bc.__class__.__name__} and hence the order in bc list matters!")
for d in range(dim):
index_list[d] += bc.indices[d]

Expand All @@ -20,3 +21,4 @@ def check_bc_overlaps(bclist, dim, backend):
if index_arr.shape[-1] != len(index_list[0]):
if backend == ComputeBackend.WARP:
raise ValueError("Boundary condition list containes duplicate indices!")
print("WARNING: there are duplicate indices in the boundary condition list and hence the order in this list matters!")
4 changes: 2 additions & 2 deletions xlb/operator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from xlb.operator.operator import Operator as Operator
from xlb.operator.parallel_operator import ParallelOperator as ParallelOperator
from xlb.operator.operator import Operator
from xlb.operator.parallel_operator import ParallelOperator
22 changes: 10 additions & 12 deletions xlb/operator/boundary_condition/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
from xlb.operator.boundary_condition.boundary_condition import BoundaryCondition as BoundaryCondition
from xlb.operator.boundary_condition.boundary_condition_registry import (
BoundaryConditionRegistry as BoundaryConditionRegistry,
)
from xlb.operator.boundary_condition.bc_equilibrium import EquilibriumBC as EquilibriumBC
from xlb.operator.boundary_condition.bc_do_nothing import DoNothingBC as DoNothingBC
from xlb.operator.boundary_condition.bc_halfway_bounce_back import HalfwayBounceBackBC as HalfwayBounceBackBC
from xlb.operator.boundary_condition.bc_fullway_bounce_back import FullwayBounceBackBC as FullwayBounceBackBC
from xlb.operator.boundary_condition.bc_zouhe import ZouHeBC as ZouHeBC
from xlb.operator.boundary_condition.bc_regularized import RegularizedBC as RegularizedBC
from xlb.operator.boundary_condition.bc_extrapolation_outflow import ExtrapolationOutflowBC as ExtrapolationOutflowBC
from xlb.operator.boundary_condition.bc_grads_approximation import GradsApproximationBC as GradsApproximationBC
from xlb.operator.boundary_condition.boundary_condition import BoundaryCondition
from xlb.operator.boundary_condition.boundary_condition_registry import BoundaryConditionRegistry
from xlb.operator.boundary_condition.bc_equilibrium import EquilibriumBC
from xlb.operator.boundary_condition.bc_do_nothing import DoNothingBC
from xlb.operator.boundary_condition.bc_halfway_bounce_back import HalfwayBounceBackBC
from xlb.operator.boundary_condition.bc_fullway_bounce_back import FullwayBounceBackBC
from xlb.operator.boundary_condition.bc_zouhe import ZouHeBC
from xlb.operator.boundary_condition.bc_regularized import RegularizedBC
from xlb.operator.boundary_condition.bc_extrapolation_outflow import ExtrapolationOutflowBC
from xlb.operator.boundary_condition.bc_grads_approximation import GradsApproximationBC
12 changes: 3 additions & 9 deletions xlb/operator/boundary_masker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
from xlb.operator.boundary_masker.indices_boundary_masker import (
IndicesBoundaryMasker as IndicesBoundaryMasker,
)
from xlb.operator.boundary_masker.mesh_boundary_masker import (
MeshBoundaryMasker as MeshBoundaryMasker,
)
from xlb.operator.boundary_masker.mesh_distance_boundary_masker import (
MeshDistanceBoundaryMasker as MeshDistanceBoundaryMasker,
)
from xlb.operator.boundary_masker.indices_boundary_masker import IndicesBoundaryMasker
from xlb.operator.boundary_masker.mesh_boundary_masker import MeshBoundaryMasker
from xlb.operator.boundary_masker.mesh_distance_boundary_masker import MeshDistanceBoundaryMasker
8 changes: 4 additions & 4 deletions xlb/operator/collision/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from xlb.operator.collision.collision import Collision as Collision
from xlb.operator.collision.bgk import BGK as BGK
from xlb.operator.collision.kbc import KBC as KBC
from xlb.operator.collision.forced_collision import ForcedCollision as ForcedCollision
from xlb.operator.collision.collision import Collision
from xlb.operator.collision.bgk import BGK
from xlb.operator.collision.kbc import KBC
from xlb.operator.collision.forced_collision import ForcedCollision
5 changes: 1 addition & 4 deletions xlb/operator/equilibrium/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
from xlb.operator.equilibrium.quadratic_equilibrium import (
Equilibrium as Equilibrium,
QuadraticEquilibrium as QuadraticEquilibrium,
)
from xlb.operator.equilibrium.quadratic_equilibrium import Equilibrium, QuadraticEquilibrium
4 changes: 2 additions & 2 deletions xlb/operator/force/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from xlb.operator.force.momentum_transfer import MomentumTransfer as MomentumTransfer
from xlb.operator.force.exact_difference_force import ExactDifference as ExactDifference
from xlb.operator.force.momentum_transfer import MomentumTransfer
from xlb.operator.force.exact_difference_force import ExactDifference
2 changes: 1 addition & 1 deletion xlb/operator/precision_caster/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from xlb.operator.precision_caster.precision_caster import PrecisionCaster as PrecisionCaster
from xlb.operator.precision_caster.precision_caster import PrecisionCaster
4 changes: 2 additions & 2 deletions xlb/operator/stepper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from xlb.operator.stepper.stepper import Stepper as Stepper
from xlb.operator.stepper.nse_stepper import IncompressibleNavierStokesStepper as IncompressibleNavierStokesStepper
from xlb.operator.stepper.stepper import Stepper
from xlb.operator.stepper.nse_stepper import IncompressibleNavierStokesStepper
2 changes: 1 addition & 1 deletion xlb/operator/stream/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from xlb.operator.stream.stream import Stream as Stream
from xlb.operator.stream.stream import Stream
14 changes: 7 additions & 7 deletions xlb/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from .utils import (
downsample_field as downsample_field,
save_image as save_image,
save_fields_vtk as save_fields_vtk,
save_BCs_vtk as save_BCs_vtk,
rotate_geometry as rotate_geometry,
voxelize_stl as voxelize_stl,
axangle2mat as axangle2mat,
downsample_field,
save_image,
save_fields_vtk,
save_BCs_vtk,
rotate_geometry,
voxelize_stl,
axangle2mat,
)
8 changes: 4 additions & 4 deletions xlb/velocity_set/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from xlb.velocity_set.velocity_set import VelocitySet as VelocitySet
from xlb.velocity_set.d2q9 import D2Q9 as D2Q9
from xlb.velocity_set.d3q19 import D3Q19 as D3Q19
from xlb.velocity_set.d3q27 import D3Q27 as D3Q27
from xlb.velocity_set.velocity_set import VelocitySet
from xlb.velocity_set.d2q9 import D2Q9
from xlb.velocity_set.d3q19 import D3Q19
from xlb.velocity_set.d3q27 import D3Q27

0 comments on commit cee77b9

Please sign in to comment.