From 9c6b5b653ef416f3ca0469039556f3495f91f0e6 Mon Sep 17 00:00:00 2001 From: Mehdi Ataei Date: Tue, 22 Oct 2024 03:16:55 -0400 Subject: [PATCH] Removed the example and shorten the description --- README.md | 119 +----------------------------------------------------- 1 file changed, 1 insertion(+), 118 deletions(-) diff --git a/README.md b/README.md index 6fafda5..749f7cd 100644 --- a/README.md +++ b/README.md @@ -25,124 +25,7 @@ pip install git+https://github.com/Autodesk/XLB.git The changelog for the releases can be found [here](https://github.com/Autodesk/XLB/blob/main/CHANGELOG.md). -## Running a Basic Example: Lid-Driven Cavity Simulation - -```python -import xlb -from xlb.compute_backend import ComputeBackend -from xlb.precision_policy import PrecisionPolicy -from xlb.helper import create_nse_fields, initialize_eq, check_bc_overlaps -from xlb.operator.boundary_masker import IndicesBoundaryMasker -from xlb.operator.stepper import IncompressibleNavierStokesStepper -from xlb.operator.boundary_condition import HalfwayBounceBackBC, EquilibriumBC -from xlb.velocity_set import D2Q9 -import numpy as np - -class LidDrivenCavity2D: - def __init__(self, omega, grid_shape, velocity_set, backend, precision_policy): - # Initialize the backend for the XLB library with specified settings - xlb.init( - velocity_set=velocity_set, - default_backend=backend, - default_precision_policy=precision_policy, - ) - - # Store the grid shape and other configurations - self.grid_shape = grid_shape - self.velocity_set = velocity_set - self.backend = backend - self.precision_policy = precision_policy - - # Create fields for the simulation (e.g., grid, distribution functions, masks) - self.grid, self.f_0, self.f_1, self.missing_mask, self.bc_mask = create_nse_fields(grid_shape) - self.stepper = None - self.boundary_conditions = [] - - # Set up the simulation by initializing boundary conditions, maskers, fields, and the stepper - self._setup(omega) - - def _setup(self, omega): - # Set up the boundary conditions, boundary masker, initialize fields, and create the stepper - self.setup_boundary_conditions() - self.setup_boundary_masker() - self.initialize_fields() - self.setup_stepper(omega) - - def define_boundary_indices(self): - # Define the indices of the boundary regions of the grid - box = self.grid.bounding_box_indices() # Get the bounding box indices of the grid - box_no_edge = self.grid.bounding_box_indices(remove_edges=True) # Get bounding box indices without the edges - - # Define lid and walls for boundary conditions - lid = box_no_edge["top"] # Top boundary represents the moving lid - 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() # Combine and remove duplicate indices for walls - return lid, walls - - def setup_boundary_conditions(self): - # Define the boundary indices for the lid and the walls - lid, walls = self.define_boundary_indices() - - # Set up boundary conditions for the lid and the walls - bc_top = EquilibriumBC(rho=1.0, u=(0.02, 0.0), indices=lid) # Lid moves with a velocity of (0.02, 0.0) - bc_walls = HalfwayBounceBackBC(indices=walls) # Walls use a halfway bounce-back boundary condition - - # Store the boundary conditions in a list - self.boundary_conditions = [bc_walls, bc_top] - - def setup_boundary_masker(self): - # Check the boundary condition list for duplicate indices before creating the boundary mask - check_bc_overlaps(self.boundary_conditions, self.velocity_set.d, self.backend) - - # Create a boundary masker to generate masks for the boundary and missing populations - indices_boundary_masker = IndicesBoundaryMasker( - velocity_set=self.velocity_set, - precision_policy=self.precision_policy, - compute_backend=self.backend, - ) - - # Apply the boundary masker to create the boundary condition mask and the missing mask - self.bc_mask, self.missing_mask = indices_boundary_masker(self.boundary_conditions, self.bc_mask, self.missing_mask) - - def initialize_fields(self): - # Initialize the equilibrium distribution function for the fluid based on initial conditions - self.f_0 = initialize_eq(self.f_0, self.grid, self.velocity_set, self.precision_policy, self.backend) - - def setup_stepper(self, omega): - # Create the time-stepping object for solving the incompressible Navier-Stokes equations - self.stepper = IncompressibleNavierStokesStepper(omega, boundary_conditions=self.boundary_conditions) - - def run(self, num_steps, post_process_interval=100): - # Run the simulation for a given number of steps - for i in range(num_steps): - # Perform one step of the simulation: swap distribution functions between f_0 and f_1 - 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 # Swap references for next step - - # Periodically perform post-processing or at the final step - if i % post_process_interval == 0 or i == num_steps - 1: - self.post_process(i) - - def post_process(self, i): - # Placeholder for post-processing logic (e.g., saving output, visualizations) - print(f"Post-processing at timestep {i}") - -# Define simulation parameters -# The grid size, backend, precision, velocity set, and relaxation factor (omega) are defined here -grid_size = 500 -grid_shape = (grid_size, grid_size) -# Select the compute backend between Warp or JAX -backend = ComputeBackend.WARP -precision_policy = PrecisionPolicy.FP32FP32 -velocity_set = D2Q9(precision_policy=precision_policy, backend=backend) -omega = 1.6 - -# Create an instance of the LidDrivenCavity2D class and run the simulation -simulation = LidDrivenCavity2D(omega, grid_shape, velocity_set, backend, precision_policy) -simulation.run(num_steps=5000, post_process_interval=1000) -``` - -For more examples please refer to the [examples](https://github.com/Autodesk/XLB/tree/main/examples) folder. +For examples to get you started please refer to the [examples](https://github.com/Autodesk/XLB/tree/main/examples) folder. ## Accompanying Paper