def test_extrapolation_outflow_initialization_by_copy(): stencil = LBStencil(Stencil.D2Q9) domain_size = (1, 5) streaming_pattern = 'esotwist' zeroth_timestep = 'even' pdf_acc = AccessPdfValues(stencil, streaming_pattern=streaming_pattern, timestep=zeroth_timestep, streaming_dir='out') dh = create_data_handling(domain_size, default_target=Target.CPU) lb_method = create_lb_method(stencil=stencil) pdf_field = dh.add_array('f', values_per_cell=stencil.Q) dh.fill(pdf_field.name, np.nan, ghost_layers=True) pdf_arr = dh.cpu_arrays[pdf_field.name] bh = LatticeBoltzmannBoundaryHandling(lb_method, dh, pdf_field.name, streaming_pattern=streaming_pattern, target=Target.CPU) for y in range(1, 6): for j in range(stencil.Q): pdf_acc.write_pdf(pdf_arr, (1, y), j, j) normal_dir = (1, 0) outflow = ExtrapolationOutflow(normal_dir, lb_method, streaming_pattern=streaming_pattern, zeroth_timestep=zeroth_timestep) boundary_slice = get_ghost_region_slice(normal_dir) bh.set_boundary(outflow, boundary_slice) bh.prepare() blocks = list(dh.iterate()) index_list = blocks[0][ bh._index_array_name].boundary_object_to_index_list[outflow] assert len(index_list) == 13 for entry in index_list: direction = stencil[entry["dir"]] inv_dir = stencil.index(inverse_direction(direction)) assert entry[f'pdf'] == inv_dir assert entry[f'pdf_nd'] == inv_dir
def test_extrapolation_outflow_initialization_by_callback(): stencil = LBStencil(Stencil.D2Q9) domain_size = (1, 5) streaming_pattern = 'esotwist' zeroth_timestep = 'even' dh = create_data_handling(domain_size, default_target=Target.CPU) lb_method = create_lb_method(stencil=stencil) pdf_field = dh.add_array('f', values_per_cell=stencil.Q) dh.fill(pdf_field.name, np.nan, ghost_layers=True) bh = LatticeBoltzmannBoundaryHandling(lb_method, dh, pdf_field.name, streaming_pattern=streaming_pattern, target=Target.CPU) normal_dir = (1, 0) outflow = ExtrapolationOutflow(normal_direction=normal_dir, lb_method=lb_method, streaming_pattern=streaming_pattern, zeroth_timestep=zeroth_timestep, initial_density=lambda x, y: 1, initial_velocity=lambda x, y: (0, 0)) boundary_slice = get_ghost_region_slice(normal_dir) bh.set_boundary(outflow, boundary_slice) bh.prepare() weights = [w.evalf() for w in lb_method.weights] blocks = list(dh.iterate()) index_list = blocks[0][ bh._index_array_name].boundary_object_to_index_list[outflow] assert len(index_list) == 13 for entry in index_list: direction = stencil[entry["dir"]] inv_dir = stencil.index(inverse_direction(direction)) assert entry[f'pdf_nd'] == weights[inv_dir]
def test_free_slip_index_list(): stencil = LBStencil(Stencil.D2Q9) dh = create_data_handling(domain_size=(4, 4), periodicity=(False, False)) src = dh.add_array('src', values_per_cell=len(stencil), alignment=True) dh.fill('src', 0.0, ghost_layers=True) lbm_config = LBMConfig(stencil=stencil, method=Method.SRT, relaxation_rate=1.8) method = create_lb_method(lbm_config=lbm_config) bh = LatticeBoltzmannBoundaryHandling(method, dh, 'src', name="bh") free_slip = FreeSlip(stencil=stencil) add_box_boundary(bh, free_slip) bh.prepare() for b in dh.iterate(): for b_obj, idx_arr in b[ bh._index_array_name].boundary_object_to_index_list.items(): index_array = idx_arr # normal directions normal_west = (1, 0) normal_east = (-1, 0) normal_south = (0, 1) normal_north = (0, -1) normal_south_west = (1, 1) normal_north_west = (1, -1) normal_south_east = (-1, 1) normal_north_east = (-1, -1) for cell in index_array: direction = stencil[cell[2]] inv_dir = inverse_direction(direction) boundary_cell = (cell[0] + direction[0], cell[1] + direction[1]) normal = (cell[3], cell[4]) # the data is written on the inverse direction of the fluid cell near the boundary # the data is read from the mirrored direction of the inverse direction where the mirror axis is the normal assert cell[5] == stencil.index(mirror_stencil(list(inv_dir), normal)) if boundary_cell[0] == 0 and 0 < boundary_cell[1] < 5: assert normal == normal_west if boundary_cell[0] == 5 and 0 < boundary_cell[1] < 5: assert normal == normal_east if 0 < boundary_cell[0] < 5 and boundary_cell[1] == 0: assert normal == normal_south if 0 < boundary_cell[0] < 5 and boundary_cell[1] == 5: assert normal == normal_north if boundary_cell == (0, 0): assert cell[2] == cell[5] assert normal == normal_south_west if boundary_cell == (5, 0): assert cell[2] == cell[5] assert normal == normal_south_east if boundary_cell == (0, 5): assert cell[2] == cell[5] assert normal == normal_north_west if boundary_cell == (5, 5): assert cell[2] == cell[5] assert normal == normal_north_east