def test_compute_local_grid_size(self) -> None: cgm = ChunkedGridManager(self.X, self.Y) cgm._rank_grid_size = (2, 4) anses = [(3, 2), (3, 2), (3, 1), (3, 1), (2, 2), (2, 2), (2, 1), (2, 1)] for ans, rank_loc in zip(anses, self.rank_locs): cgm._rank_loc = rank_loc val = cgm._compute_local_grid_size(self.X, self.Y) assert val == ans
def test_is_boundary(self) -> None: cgm = ChunkedGridManager(self.X, self.Y) cgm._x_local_range = (0, 2) cgm._y_local_range = (0, 3) s_dirs = ['LEFT', 'RIGHT', 'TOP', 'BOTTOM'] for s_dir in s_dirs: dir = getattr(DirectionIndicators, s_dir) ans = (DirectionIndicators.LEFT == dir or DirectionIndicators.BOTTOM == dir) val = cgm.is_boundary(dir) assert ans == val
def test_global_to_local(self) -> None: cgm = ChunkedGridManager(self.X, self.Y) cgm._x_local_range = (2, 4) cgm._y_local_range = (3, 4) val = cgm.global_to_local(2, 3) assert val == (0, 0) val = cgm.global_to_local(2, 4) assert val == (0, 1) val = cgm.global_to_local(3, 3) assert val == (1, 0) val = cgm.global_to_local(3, 4) assert val == (1, 1) val = cgm.global_to_local(4, 3) assert val == (2, 0) val = cgm.global_to_local(4, 4) assert val == (2, 1)
def main(init_density: np.ndarray, init_velocity: np.ndarray, grid_manager: ChunkedGridManager, lattice_grid_shape: Tuple[int, int], total_time_steps: int, omega: float, wall_vel: np.ndarray) -> None: X, Y = grid_manager.local_grid_size field = LatticeBoltzmannMethod(X, Y, omega=omega, init_vel=init_velocity, init_density=init_density, grid_manager=grid_manager) rigid_boundary_locations = [ getattr(DirectionIndicators, dir) for dir in ['TOP', 'LEFT', 'RIGHT'] if grid_manager.is_boundary(getattr(DirectionIndicators, dir)) ] moving_wall, rigid_wall = None, None if grid_manager.is_boundary(DirectionIndicators.BOTTOM): moving_wall = MovingWall( field, boundary_locations=[DirectionIndicators.BOTTOM], wall_vel=wall_vel) if len(rigid_boundary_locations) >= 1: rigid_wall = RigidWall(field, boundary_locations=rigid_boundary_locations) def boundary_handling_func(field: LatticeBoltzmannMethod) -> None: if rigid_wall is not None: rigid_wall.boundary_handling(field) if moving_wall is not None: moving_wall.boundary_handling(field) field.local_equilibrium_pdf_update() for t in trange(total_time_steps): field.lattice_boltzmann_step(boundary_handling=boundary_handling_func) x_file, y_file = field.save_velocity_field(dir_name='test_run', file_name='v', index=total_time_steps) if field.grid_manager.rank == 0: visualize_velocity_field_mpi(x_file, y_file)
def test_compute_rank_grid_size(self) -> None: cgm = ChunkedGridManager(self.X, self.Y) cgm._size = 8 assert cgm._compute_rank_grid_size(2, 4) == (2, 4) assert cgm._compute_rank_grid_size(4, 2) == (4, 2) cgm._size = 42 assert cgm._compute_rank_grid_size(2, 4) == (6, 7) assert cgm._compute_rank_grid_size(4, 2) == (7, 6)
def test_compute_local_range(self) -> None: cgm = ChunkedGridManager(self.X, self.Y) cgm._rank_grid_size = (2, 4) anses = [((0, 2), (0, 1)), ((0, 2), (2, 3)), ((0, 2), (4, 4)), ((0, 2), (5, 5)), ((3, 4), (0, 1)), ((3, 4), (2, 3)), ((3, 4), (4, 4)), ((3, 4), (5, 5))] for ans, rank_loc in zip(anses, self.rank_locs): cgm._rank_loc = rank_loc cgm._local_grid_size = cgm._compute_local_grid_size(self.X, self.Y) val = cgm._compute_local_range(self.X, self.Y) assert val == ans
field.local_equilibrium_pdf_update() for t in trange(total_time_steps): field.lattice_boltzmann_step(boundary_handling=boundary_handling_func) x_file, y_file = field.save_velocity_field(dir_name='test_run', file_name='v', index=total_time_steps) if field.grid_manager.rank == 0: visualize_velocity_field_mpi(x_file, y_file) if __name__ == '__main__': # Reynolds = 300 * wall_vel / viscosity # 0.03 < viscosity < inf viscosity = 1. / 30. kwargs = ExperimentVariables(omega=1. / (3. * viscosity + 0.5), total_time_steps=1000, wall_vel=np.array([.3, 0]), lattice_grid_shape=(100, 100)) X, Y = kwargs.lattice_grid_shape grid_manager = ChunkedGridManager(X, Y) buffer_grid_size = grid_manager.buffer_grid_size density, vel = np.ones(buffer_grid_size), np.zeros((*buffer_grid_size, 2)) main(init_density=density, init_velocity=vel, grid_manager=grid_manager, **kwargs)
def test_compute_buffer_grid_size(self) -> None: cgm = ChunkedGridManager(self.X, self.Y) dx, dy = cgm.local_grid_size val = cgm._compute_buffer_grid_size() assert val == (dx, dy)